LiFan
2024-07-08 97e2acb59314e2ca4bee55abc9571c1c5045f73d
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
#include <wobject/xstring.hpp>
#include <xcontrol/xtreeview.hpp>
#include <xcontrol/xdwgrid.hpp>
 
#include "vbusiness/vframe/listwin.vframe.vbusiness.hpp"
#include "viewobject/view.base.hpp"
 
using xml = KXMLDOMDocument;
    class __declspec(dllexport) UpdateVatNotifyWin : public xframe
    {
    public:
        xdwgrid    dw_list;
        xdwgrid    dw_item;
        xdwgrid    dw_goods;
        xnode    m_agentNode;    //Agent Condition
 
    public:
        UpdateVatNotifyWin(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
    public:
        static UpdateVatNotifyWin* CreateInstance(void* implPtr, void* hWnd)
        {
            UpdateVatNotifyWin* pWin = new UpdateVatNotifyWin(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 param)
        {
            //ÖØÖù¤¾ßÌõ
            //SetAgent();
            return 1;
        }
 
        int OnSave()
        {
            xml x ;
            
            dw_list.AcceptText();
            dw_list.DwUpdateAllToEx(x);
            xaserverarg arg;
            arg.AddArg(L"content", x.xml());
 
            trace(x.xml());
            //return 1;
            if (xurl::get(L"/sale/data/VATNotify/base/update", arg.GetString(), x) != 1)
            {
                xstring error = x.text();
                alert(L"err:" + error);
                return 1;
            }
            xstring str = x.documentElement().getAttribute(L"text");
            if (str == L"true")
            {
                dw_list.ResetUpdateStatus();
                alert(L"±£´æ³É¹¦!");
            }
            else
            {
                alert(L"±£´æÊ§°Ü!");
            }
            return 1;
        }
 
        //ÃüÁî·¢²¼º¯Êý
        int OnCmdDispatch(xstring comdid)
        {
            if (comdid == L"xmReplaceRow")
            {
                return OnReplaceRow();
            }
            if (comdid == L"xmReplaceSupplier")
            {
                return OnReplaceSupplier();
            }
            else if (comdid == L"xmAddRow")
            {
                return OnAddRow();
            }
            else if (comdid == L"xmSave")
            {
                return OnSave();
            }
            else if (comdid == L"xmDeleteRow")
            {
                return OnDeleteRow();
            }
            if (comdid == L"xmClose")
            {
                CloseWindow();
                return 1;
            }
            return 0;
        }
 
        int OnDeleteRow()
        {
            if (dw_list.GetRowCount() == dw_item.GetRowCount())
            {
                int res = MessageBox(GetHWND(), L"Äã¿ÉÒÔÓÃÌæ»»Íê³ÉÏàÓ¦µÄ²Ù×÷£¬»¹¼ÌÐøÉ¾³ýÂð?", L"Ìáʾ", 4);
                if (res != 6) return 1;
            }
            else
            {
                int res1 = MessageBox(GetHWND(), L"È·ÈÏɾ³ý¶ÔÓ¦µÄÐÐ?", L"Ìáʾ", 4);
                if (res1 != 6) return 1;
            }
            dw_list.DeleteRow(0);
            dw_list.Redraw();
            return 1;
        }
 
        int OnAddRow()
        {
            if (dw_item.GetRow() < 1) return 1;
            int ll_row1 = dw_item.GetRow();
            dw_list.InsertRow(0);
            int ll_row = dw_list.GetRowCount();
 
            KXMLDOMElement e = dw_item.GetRowElement(ll_row1);
            dw_list.SetItemString(ll_row, L"SupplierID", dw_item.GetItemString(ll_row1, L"SupplierID"));
            dw_list.SetItemDisplayString(ll_row, L"SupplierID", dw_item.GetItemDisplayString(ll_row1, L"SupplierID"));
            dw_list.SetItemString(ll_row, L"CQuantity", dw_item.GetItemString(ll_row1, L"CustQuantity"));
            dw_list.SetItemString(ll_row, L"Amount", dw_item.GetItemString(ll_row1, L"Amount"));
            dw_list.SetItemString(ll_row, L"ClassifyID", dw_item.GetItemString(ll_row1, L"ClassifyID"));
            dw_list.SetItemDisplayString(ll_row, L"ClassifyID", dw_item.GetItemDisplayString(ll_row1, L"ClassifyID"));
            dw_list.SetItemString(ll_row, L"CName", dw_item.GetItemDisplayString(ll_row1, L"ClassifyID"));
            if (e.selectSingleNode(L"Quantity")) dw_list.SetItemString(ll_row, L"Quantity", e.selectSingleNode(L"Quantity").text());
            if (e.selectSingleNode(L"CreatorID"))    dw_list.SetItemString(ll_row, L"CreatorID", e.selectSingleNode(L"CreatorID").text());
            if (e.selectSingleNode(L"CreateDate"))    dw_list.SetItemString(ll_row, L"CreateDate", e.selectSingleNode(L"CreateDate").text());
            if (e.selectSingleNode(L"ModifierID"))    dw_list.SetItemString(ll_row, L"ModifierID", e.selectSingleNode(L"ModifierID").text());
            if (e.selectSingleNode(L"ModifyDate"))    dw_list.SetItemString(ll_row, L"ModifyDate", e.selectSingleNode(L"ModifyDate").text());
            if (e.selectSingleNode(L"VATRate"))    dw_list.SetItemString(ll_row, L"VATRate", e.selectSingleNode(L"VATRate").text());
            if (e.selectSingleNode(L"VATRefundRate"))    dw_list.SetItemString(ll_row, L"VATRefundRate", e.selectSingleNode(L"VATRefundRate").text());
            if (e.selectSingleNode(L"CustomUOM"))    dw_list.SetItemString(ll_row, L"CQtyUnit", e.selectSingleNode(L"CustomUOM").text());
            if (e.selectSingleNode(L"IsFinish"))    dw_list.SetItemString(ll_row, L"IsFinish", e.selectSingleNode(L"IsFinish").text());
            if (e.selectSingleNode(L"Type"))    dw_list.SetItemString(ll_row, L"Type", e.selectSingleNode(L"Type").text());
            if (e.selectSingleNode(L"InvoiceNo"))    dw_list.SetItemString(ll_row, L"InvoiceNo", e.selectSingleNode(L"InvoiceNo").text());
            dw_list.Redraw();
            dw_item.SetItemString(ll_row1, L"Relation", xstring(ll_row));
            dw_item.Redraw();
            return 1;
        }
 
        int OnReplaceSupplier()
        {
            int ll_row = dw_list.GetRow();
            int ll_row1 = dw_item.GetRow();
 
            if (ll_row < 1 || ll_row1 < 1)
            {
                alert(L"ûÓвÙ×÷!");
                return 1;
            }
            xstring SupplierID1 = dw_item.GetItemString(ll_row1, L"SupplierID");
            dw_list.SetItemString(ll_row, L"SupplierID", SupplierID1);
            dw_list.SetItemDisplayString(ll_row, L"SupplierID", dw_item.GetItemDisplayString(ll_row1, L"SupplierID"));
            dw_list.Redraw();
            return 1;
        }
 
        int OnReplaceRow()
        {
            int ll_row = dw_list.GetRow();
            int ll_row1 = dw_item.GetRow();
            if (ll_row < 1 || ll_row1 < 1)
            {
                alert(L"ûÓвÙ×÷!");
                return 1;
            }
 
            bool updateSupplier = false;
            bool updatePrice = false;
            bool updateClassifyID = false;
            xstring SupplierID = dw_list.GetItemString(ll_row, L"SupplierID");
            xstring CQuantity = dw_list.GetItemString(ll_row, L"CQuantity");
            xstring Amount = dw_list.GetItemString(ll_row, L"Amount");
            xstring ClassifyID = dw_list.GetItemString(ll_row, L"ClassifyID");
 
            xstring SupplierID1 = dw_item.GetItemString(ll_row1, L"SupplierID");
            xstring CQuantity1 = dw_item.GetItemString(ll_row1, L"CustQuantity");
            xstring Amount1 = dw_item.GetItemString(ll_row1, L"Amount");
            xstring ClassifyID1 = dw_item.GetItemString(ll_row1, L"ClassifyID");
 
            if (SupplierID != SupplierID1) updateSupplier = true;
            if (CQuantity != CQuantity1) updatePrice = true;
            if (Amount != Amount1) updatePrice = true;
            if (ClassifyID != ClassifyID1) updateClassifyID = true;
 
            if (updateSupplier && updatePrice && updateClassifyID)
            {
                int res = MessageBox(GetHWND(), L"ÉÏÏÂÊý¾Ý±¨¹ØÆ·Ãû¡¢¼Û¸ñ¡¢¹¤³§È«²»Ò»Ö£¬ÊÇ·ñÒªÇ¿ÖÆÌæ»»?", L"Ìáʾ", 4);
                if (res != 6) return 1;
            }
            if (updateSupplier)
            {
                dw_list.SetItemString(ll_row, L"SupplierID", SupplierID1);
                dw_list.SetItemDisplayString(ll_row, L"SupplierID", dw_item.GetItemDisplayString(ll_row1, L"SupplierID"));
            }
            if (updatePrice)
            {
                dw_list.SetItemString(ll_row, L"CQuantity", CQuantity1);
                dw_list.SetItemString(ll_row, L"Amount", Amount1);
            }
            if (updateClassifyID)
            {
                dw_list.SetItemString(ll_row, L"ClassifyID", ClassifyID);
                dw_list.SetItemDisplayString(ll_row, L"ClassifyID", dw_item.GetItemDisplayString(ll_row1, L"ClassifyID"));
                dw_list.SetItemString(ll_row, L"CName", dw_item.GetItemDisplayString(ll_row1, L"ClassifyID"));
            }
            dw_list.Redraw();
            dw_item.SetItemString(ll_row1, L"Relation",xstring(ll_row));
            dw_item.Redraw();
            return 1;
        }
 
        //ÃüÁî´¦Àíʼþ
        int OnXCommand(TEvent* evt, LPARAM param)
        {
            return OnCmdDispatch(evt->xcommand.pStrID);
        }
 
        int OnAttachEvent()
        {
            //°ó¶¨¹¤¾ßÌõµã»÷ʼþ
            AttachEvent(L"WM_XCOMMAND", (FEvent)&UpdateVatNotifyWin::OnXCommand);
            //»ñÈ¡½¹µãʼþ£¬ÓÃÓÚÖØÖù¤¾ßÌõ
            AttachEvent(L"WM_SETFOCUS", (FEvent)&UpdateVatNotifyWin::OnSetFocus);
            AttachEvent(L"dw_item", L"DWV_ROWFOCUSCHANGED", (FEvent)&UpdateVatNotifyWin::OnRowChanged);
            return 1;
        }
 
        int RetrieveCustomSource(xstring classifyID, xstring supplierID)
        {
            xml x ;
            
            xaserverarg arg ;
            
            if (GetWinParam())
            {
                int pArg = GetArg();
                
            }
            else
                arg.AddArg(L"invoiceno", L"15HDLD0720");
 
            arg.AddArg(L"ClassifyID", classifyID);
            arg.AddArg(L"SupplierID", supplierID);
            if (getUrl(L"/sale/data/VATNotify/pref/CustomSource", arg.GetString(), x) != 1)
            {
                trace(x.text());
                return -1;
            }
            else
            {
                dw_goods.Retrieve(x);
                dw_goods.Redraw();
            }
        }
 
        int OnRowChanged(TEvent* evt, LPARAM p)
        {
            DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
            int row = hdr.row;
 
            if (row < 1) return 1;
            KXMLDOMElement e = dw_item.GetRowElement(row);
            xstring classifyID = e.selectSingleNode(L"ClassifyID").text();
            xstring supplierID = e.selectSingleNode(L"SupplierID").text();
            e.Release();
            RetrieveCustomSource(classifyID, supplierID);
 
            return 1;
        }
 
        int  OnRetrieve()
        {
            xml x ;
            
            xaserverarg arg;
            
            if (GetWinParam())
            {
                int pArg = GetArg();
                
            }
            else
                arg.AddArg(L"invoiceno", L"15HDLD0720");
            if (getUrl(L"/sale/data/VATNotify/entity/base/miss", arg.GetString(), x) != 1)
            {
                trace(x.text());
                //return -1;
            }
            else
            {
                //alert(x.xml);
                dw_list.Retrieve(x);
                dw_list.Redraw();
            }
 
            if (getUrl(L"/sale/data/VATNotify/pref/GdnInvoice", arg.GetString(), x) != 1)
            {
                trace(x.text());
                return -1;
            }
            else
            {
                dw_item.Retrieve(x);
                dw_item.Redraw();
                dw_item.SetReadOnly(true);
                if (dw_item.GetRowCount() > 0)
                {
                    KXMLDOMElement e = dw_item.GetRowElement(1);
                    xstring classifyID = e.selectSingleNode(L"ClassifyID").text();
                    xstring supplierID = e.selectSingleNode(L"SupplierID").text();
                    e.Release();
                    trace(L"!" + classifyID + L" " + supplierID);
                    RetrieveCustomSource(classifyID, supplierID);
                }
            }
 
            return 1;
        }
 
        int onload()
        {
            SetArg();
            dw_list = GetControl(L"dw_list");
            dw_list.openUrl(L"/sale/view/VATNotify/template/VATNotify/item");
            dw_item = GetControl(L"dw_item");
            dw_item.openUrl(L"/sale/view/VATNotify/template/VATNotify/DItem");
            dw_goods = GetControl(L"dw_goods");
            dw_goods.openUrl(L"/sale/view/VATNotify/template/VATNotify/DItem1");
 
 
            OnRetrieve();
            OnAttachEvent();
 
            return 1;
        }
 
        int onloaded()
        {
            //SetAgent();            
 
            return 1;
        }
    };