LiFan
10 天以前 63eebabbfee1bc84850b36967ecac5116a28b73f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#include <wobject/xstring.hpp>
#include <xcontrol/xtreeview.hpp>
#include <xcontrol/xdwgrid.hpp>
#include <wobject/xdouble.hpp>
#include <xcontrol/xlayersheet.hpp>
 
#include "vbusiness/vframe/listwin.vframe.vbusiness.hpp"
#include "viewobject/view.base.hpp"
 
using xml = KXMLDOMDocument;
class __declspec(dllexport) SKUItem : public xframe
{
public:
    xtreeview    tv_1;
    xdwgrid    dw_list;
    xstring     m_type;
    xstring CategoryID;
    xnode    m_agentNode;    //Agent Condition
    xstring    m_agentCond;    //Agent Node
    xstring m_searchtxt;
public:
    SKUItem(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
public:
    static SKUItem* CreateInstance(void* implPtr, void* hWnd)
    {
        SKUItem* pWin = new SKUItem(implPtr, (HWND)hWnd);
        return pWin;
    }
    int SetAgent()
    {
        xstring xfNodeAgentArea = L"agentarea";
        xnode anode = GetAgentNode(xfNodeAgentArea);
        if (m_agentNode)
        {
            SetAgentNode(anode, m_agentNode);
        }
        else
        {
            KXMLDOMElement xframeElement = GetElement();
            KXMLDOMElement agent = xframeElement.selectSingleNode(L"agent/" + xfNodeAgentArea + L"[1]/*");
            if (agent)
            {
                xstring s = agent.xml();
                m_agentNode = SetAgentNode(anode, s);
            }
        }
        return 1;
    }
 
    //½¹µã¼¤»î´¦Àíº¯Êý
    int OnSetFocus(TEvent* evt, LPARAM p)
    {
        SetAgent();
 
        //ÖØÖù¤¾ßÌõ
        return 1;
    }
 
    int  OnReTrieve()
    {
        xstring query = L"[SKUItem.tree.xq]";
        xml x;
 
        xaserverarg arg;
 
        arg.AddArg(L"parentID", CategoryID);
        arg.AddArg(L"query", L"");
        if (xaserver::ExecXQuery(GetServerUrl(), query, arg.GetString(), x) != 1)
        {
            trace(x.text());
            return -1;
        }
        else
        {
            dw_list.openUrl(L"ÆäËûÉèÖÃ.vface/template/other/SKUItem");
            dw_list.Retrieve(x);
            dw_list.Redraw();
        }
        return 1;
    }
 
    int OnTreeSelChanged(TEvent* evt, LPARAM p)
    {
        NMTREEVIEW& nmtv = *(NMTREEVIEW*)evt->notify.pnmh;
        HTREEITEM sitem = nmtv.itemNew.hItem;
 
        HCURSOR hCursor = xutil::SetCursorWait();
        dw_list.AcceptText();
        xml z;
 
        z.loadXML(L"<root/>");
        dw_list.Retrieve(z);
        dw_list.Redraw();
        dw_list.ResetUpdateStatus();
 
        KXMLDOMElement ele = tv_1.GetItemData(sitem);
        if (!ele.selectSingleNode(L"ID")) return 0;
        CategoryID = ele.selectSingleNode(L"ID").text();
        //trace(CategoryID);
        m_searchtxt = L"";
 
        OnReTrieve();
        xutil::RestoreCursor(hCursor);
        return 1;
    }
 
    int CreateSubTree(HTREEITEM pitem)
    {
        KXMLDOMElement sitemdata = tv_1.GetItemData(pitem);
        xstring sHasChild = sitemdata.selectSingleNode(L"@HasChild").text();//sitemdata.getAttribute(L"HasChild");    
        //trace(sHasChild);
        xstring pid = sitemdata.selectSingleNode(L"ID").text();
        //trace(sHasChild+L"sdaga"+pid);
        if (sHasChild == L"1") {//Êý¾ÝÓÐ×ӽڵ㠠      
            HTREEITEM citem = tv_1.GetChildItem(pitem);
            //alert(xstring(citem));
            if (citem == 0) {//Ê÷ÊÓͼÓÐ×Ó½Úµã
                xml x;
 
                xaserverarg arg;
 
                arg.AddArg(L"parentID", pid);
                arg.AddArg(L"query", L"");
                if (xaserver::ExecXQuery(GetServerUrl(), L"[SKUItem.tree.xq]", arg.GetString(), x) != 1)
                {
                    trace(x.xml());
                    return 0;
                }
                //trace(x.xml());
                auto list = x.selectNodes(L"root/SKUItem");
                int i = 0, s = list.length();
                KXMLDOMElement xitem;
                KXMLDOMNode d;
                for (i = 0; i < s; i++) {
                    xitem = list.item(s - i - 1);
                    //if(i==0)xitem.setAttribute(L"HasChild",L"1");
                    xstring Name = xitem.selectSingleNode(L"ItemName").text();
                    HTREEITEM kitem = tv_1.InsertItem(pitem, 0, Name, xitem, 15);
                    //int kitem=tv_1.InsertChildItem(tv_1.GetId(), pitem,Name,xitem,15);    
                    xstring HasChild = xitem.selectSingleNode(L"@HasChild").text();//item.getAttribute(L"HasChild");    
                    //trace(HasChild, kitem);
                    if (HasChild == L"1")
                        tv_1.SetItemChild1(kitem, 1);
                }
            }
        }
        return 1;
    }
    int CreateRootTree() {
        xstring id = L"00000000-0000-0000-0000-000000000000";
        xml x;
 
        x.loadXML(L"<SKUItem HasChild='1' ><ID>" + id + L"</ID></SKUItem>");
        HTREEITEM hroot = tv_1.InsertItem(L"²úÆ·ÏîÄ¿·ÖÀà", x.documentElement(), 17);
        //trace(hroot);
        CreateSubTree(hroot);
        tv_1.ExpandItemEx(hroot);
        CategoryID = id;
        OnReTrieve();
        return 1;
    }
    int OnTreeExpanding(TEvent* evt, int p)
    {
        NMTREEVIEW& nmtv = *(NMTREEVIEW*)evt->notify.pnmh;
 
        HTREEITEM sitem = nmtv.itemNew.hItem;
        CreateSubTree(sitem);
        return 1;
    }
    int afterSave() {
        HTREEITEM hitem = tv_1.GetSelectedItem();
        if (hitem == 0)
            hitem = tv_1.GetRootItem();
        int rows = dw_list.GetRowCount();
        KXMLDOMElement ele = tv_1.GetItemData(hitem);
 
        HTREEITEM firstChild = tv_1.GetChildItem(hitem);
        while (firstChild) {
            tv_1.DeleteItem(firstChild);
            firstChild = tv_1.GetChildItem(hitem);
        }
        if (rows > 0)
        {
            tv_1.SetItemChild1(hitem, 1);
            ele.setAttribute(L"HasChild", L"1");
            //trace(ele.xml);
            tv_1.SetItemData(hitem, ele);
        }
        else
        {
            tv_1.SetItemChild1(hitem, 0);
            ele.setAttribute(L"HasChild", L"0");
            //trace(ele.xml);
            tv_1.SetItemData(hitem, ele);
        }
        CreateSubTree(hitem);
        if (tv_1.GetRootItem() == hitem)
            tv_1.ExpandItemEx(hitem);
 
        dw_list.ResetUpdateStatus();
        return 0;
    }
    int OnSave()
    {
        xml x;
 
        dw_list.AcceptText();
        dw_list.DwUpdateAllToEx(x);
        trace(x.xml());
        xaserverarg arg;
 
        arg.AddArg(L"content", x.xml());
        arg.AddArg(L"dbmap", L"SKUItem.dbmap");
        if (xaserver::ExecXAction(GetServerUrl(), L"[onSave.xa]", arg.GetString(), x) != 1)
        {
            trace(x.documentElement().text());
            alert(L"±£´æÊ§°Ü");
        }
        else {
            alert(L"±£´æ³É¹¦");
        }
        dw_list.ResetUpdateStatus();
        dw_list.Redraw();
        afterSave();
        return 1;
    }
    int OnSetValue(int row) {
        dw_list.SetItemString(row, L"PID", CategoryID);
        dw_list.SetItemString(row, L"ID", publiccode::GetGuid());
        return 1;
    }
    int OnAddRow()
    {
        int row = dw_list.InsertRow(0);
        int rows = dw_list.GetRowCount();
        OnSetValue(rows);
        dw_list.SetRow(dw_list.GetRowCount());
        //trace(row.toString());
        return 1;
    }
 
    int OnInsertRow()
    {
        int row = dw_list.GetRow();
        if (row<0 || row>dw_list.GetRowCount()) return 0;
        dw_list.InsertRow(row);
        OnSetValue(row);
        dw_list.SetRow(row);
        return 1;
    }
 
    int OnDeleteRow()
    {
        int row = dw_list.GetRow();
        if (row<0 || row>dw_list.GetRowCount()) return 0;
        dw_list.DeleteRow(row);
        return 1;
    }
 
 
    //ÃüÁî·¢²¼º¯Êý
    int OnCmdDispatch(xstring comdid)
    {
        if (comdid == L"Save")  OnSave();
        else if (comdid == L"AddRow") OnAddRow();
        else if (comdid == L"InsertRow") OnInsertRow();
        else if (comdid == L"DeleteRow") OnDeleteRow();
        return 0;
    }
 
    //ÃüÁî´¦Àíʼþ
    int OnXCommand(TEvent* evt, LPARAM param)
    {
        return OnCmdDispatch(evt->xcommand.pStrID);
    }
 
    int OnAttachEvent()
    {
        //°ó¶¨¹¤¾ßÌõµã»÷ʼþ
        AttachEvent(L"WM_XCOMMAND", (FEvent)&SKUItem::OnXCommand);
        //»ñÈ¡½¹µãʼþ£¬ÓÃÓÚÖØÖù¤¾ßÌõ
        AttachEvent(L"WM_SETFOCUS", (FEvent)&SKUItem::OnSetFocus);
        //»ñµÃÊ÷µÄÑ¡Ôñʼþ
        AttachEvent(L"tv_1", L"TVN_SELCHANGED", (FEvent)&SKUItem::OnTreeSelChanged);
        AttachEvent(L"tv_1", L"TVN_ITEMEXPANDING", (FEvent)&SKUItem::OnTreeExpanding);
        return 1;
    }
 
    int OnInitial()
    {
        SetAgent();
        OnAttachEvent();
        return 1;
    }
 
    int onload()
    {
        m_type = L"all";
        tv_1 = GetControl(L"tv_1");
        dw_list = GetControl(L"dw_list");
        dw_list.openUrl(L"ÆäËûÉèÖÃ.vface/template/other/SKUItem");
 
        OnInitial();
        CreateRootTree();
 
        return 1;
    }
};