LiFan
2024-07-08 82d21bb5c6d0dedc5599a5cf61d19c7eee1f7ef5
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
þÿ#include <wobject/xstring.hpp>
#include <xcontrol/xtreeview.hpp>
#include <xcontrol/xdwgrid.hpp>
 
#include "vbusiness/vframe/listwin.vframe.vbusiness.hpp"
#include "viewobject/view.base.hpp"
#include "vbusiness/vframe/frame.vframe.vbusiness.hpp"
 
using xml = KXMLDOMDocument;
    class __declspec(dllexport) InsertPOWin : public xframe
    {
    public:
        //xdwgrid    dw_list;
        xdwgrid    dw_list;
        xnode    m_agentNode;    //Agent Condition
        MaintPaperCardPOWin lw_obj;
 
    public:
        InsertPOWin(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
    public:
        static InsertPOWin* CreateInstance(void* implPtr, void* hWnd)
        {
            InsertPOWin* pWin = new InsertPOWin(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;
        }
 
        //q&p¹oÀm;YtQýep
        int OnSetFocus(TEvent* evt, int param)
        {
            //‘Ín]åQwga
            SetAgent();
            return 1;
        }
        int OnSave()
        {
            xml x1 ;
            xml x ;
            xml xp ;
            lw_obj.dw_polist.DwUpdateAllToEx(xp);
            lw_obj.dw_paper.DwUpdateAllTo(x);
            lw_obj.dw_process.DwUpdateAllTo(x1);
 
            xstring val = xp.xml();
            xstring val0 = x.xml();
            xstring val1 = x1.xml();
            val = L"<data>" + val + val0 + val1 + L"</data>";
            trace(val);
            xaserverarg arg;
            arg.setNativePointer(arg.CreateInstance());
            arg.AddArg(L"content", val);
            if (xurl::get(L"/sale/data/PurchaseOrder/update/polistex", arg.GetString(), x) != 1)
            {
                xstring error = x.text();
                alert(error);
                return 1;
            }
            else
            {
                xstring str = x.documentElement().getAttribute(L"text");
                if (str == L"true")
                {
                    lw_obj.dw_polist.ResetUpdateStatus();
                    //dw_list.ResetUpdateStatus();
                    //dw_list1.ResetUpdateStatus();
                    lw_obj.dw_paper.ResetUpdateStatus();
                    lw_obj.dw_process.ResetUpdateStatus();
                    alert(L"OÝ[XbRŸ!");
                }
                else
                {
                    alert(L"OÝ[XY1%!");
                }
                //alert(x.GetXml());
            }
            return 1;
        }
 
        int InsertPo()
        {
            xdwtable dw_pitem = lw_obj.dw_process.FindDwTable(L"PItem");
            xdwgrid  dw_polist = lw_obj.dw_polist;
            int row1 = dw_pitem.GetRow();
            int row2 = dw_list.GetRow();
            dw_pitem.SetItemString(row1, L"PONo", dw_list.GetItemString(row2, L"PONo"));
            dw_pitem.SetItemString(row1, L"POID", dw_list.GetRowElement(row2).getAttribute(L"guid"));
            for (int row = 1; row <= dw_polist.GetRowCount(); row++)
            {
                xstring POID1 = dw_polist.GetRowElement(row).getAttribute(L"guid");
                xstring POID2 = dw_pitem.GetItemString(row1, L"POID");
                if (POID1 == POID2)
                {
                    double amount = dw_polist.GetItemDouble(row, L"Amount") + dw_pitem.GetItemDouble(row1, L"BuyAmount");
                    dw_polist.SetItemDouble(row, L"Amount", amount);
                }
            }
            OnSave();
            return 1;
        }
 
        //T}NäSÑ^Qýep
        int OnCmdDispatch(xstring comdid)
        {
            if (comdid == L"xmClose")
            {
                CloseWindow();
                return 1;
            }
            else if (comdid == L"xmInsert")
            {
                InsertPo();
                return 1;
            }
            return 0;
        }
 
        //T}NäYtN‹Nö
        int OnXCommand(TEvent* evt, LPARAM p)
        {
            return OnCmdDispatch(evt->xcommand.pStrID);
        }
 
        int OnAttachEvent()
        {
            //~Ñ[š]åQwgap¹QûN‹Nö
            AttachEvent(L"WM_XCOMMAND", (FEvent)&InsertPOWin::OnXCommand);
            //ƒ·SÖq&p¹N‹Nöÿ u(NŽ‘Ín]åQwga
            AttachEvent(L"WM_SETFOCUS", (FEvent)&InsertPOWin::OnSetFocus);
            return 1;
        }
 
        /*
        int  OnRetrieve()
        {
            xml x ;
            
            xaserverarg arg;
            arg.setNativePointer(arg.CreateInstance());
            arg.AddArg(L"xxx",L"xxx");
            if (getUrl(L"",arg.GetString(),x)!=1)
            {
                trace(x.text());
                return -1;
            }else
            {
                //dw_list.Retrieve(x);
                //dw_list.Redraw();
            }
            return 1;
        }
        */
        int Initial()
        {
            lw_obj = GetArg();
            xdwgrid  dw_polist = lw_obj.dw_polist;
            xdwtable dw_pitem = lw_obj.dw_process.FindDwTable(L"PItem");
            for (int row = 1; row <= dw_polist.GetRowCount(); row++)
            {
 
                xstring posupplier = dw_polist.GetItemString(row, L"SupplierID");
                xstring poitemsupplier = dw_pitem.GetItemString(row, L"SupplierID");
                xstring PONo = dw_pitem.GetItemString(row, L"PONo");
                KXMLDOMElement ele = dw_polist.GetRowElement(row);
                xstring guid = ele.getAttribute(L"guid");
                if (PONo == L"")
                {
                    if (posupplier == poitemsupplier)
                    {
                        int row1 = dw_list.InsertRow(0);
                        KXMLDOMElement ele1 = dw_list.GetRowElement(row1);
                        ele1.setAttribute(L"guid", guid);
                        dw_list.SetItemDisplayString(row1, L"SupplierID", dw_polist.GetItemDisplayString(row, L"SupplierID"));
                        if (dw_polist.GetItemString(row, L"POType"))dw_list.SetItemString(row1, L"POType", dw_polist.GetItemString(row, L"POType"));
                        if (dw_polist.GetItemString(row, L"PONo"))dw_list.SetItemString(row1, L"PONo", dw_polist.GetItemString(row, L"PONo"));
                        if (dw_polist.GetItemString(row, L"PODate"))dw_list.SetItemString(row1, L"PODate", dw_polist.GetItemString(row, L"PODate"));
                        if (dw_polist.GetItemString(row, L"Amount"))dw_list.SetItemString(row1, L"Amount", dw_polist.GetItemString(row, L"Amount"));
                        if (dw_polist.GetItemString(row, L"CurrencyCode"))dw_list.SetItemString(row1, L"CurrencyCode", dw_polist.GetItemString(row, L"CurrencyCode"));
                        if (dw_polist.GetItemString(row, L"DeliveryDate"))dw_list.SetItemString(row1, L"DeliveryDate", dw_polist.GetItemString(row, L"DeliveryDate"));
                        if (dw_polist.GetItemDisplayString(row, L"CreatorID"))dw_list.SetItemDisplayString(row1, L"CreatorID", dw_polist.GetItemDisplayString(row, L"CreatorID"));
                        if (dw_polist.GetItemString(row, L"Status"))dw_list.SetItemString(row1, L"Status", dw_polist.GetItemString(row, L"Status"));
                        if (dw_polist.GetItemString(row, L"SOID"))dw_list.SetItemString(row1, L"SOID", dw_polist.GetItemString(row, L"SOID"));
                    }
                }
            }
            return 1;
        }
 
        int onload()
        {
            SetArg();
            dw_list = GetControl(L"dw_list");
            dw_list.openUrl(L"/sale/view/PurchaseOrder/template/purchaseorder/polist");
            dw_list.SetColumnState(L"SOID", false);
            OnAttachEvent();
            if (GetWinParam()) Initial();
            return 1;
        }
 
        int onloaded()
        {
            SetAgent();
 
            return 1;
        }
    };