LiFan
2025-04-24 9b3b2eb20b09e13da837a28f16e552ba70a090c4
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
þÿ#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"
#include "viewobject/saleorder.view.hpp"
using xml = KXMLDOMDocument;
    class __declspec(dllexport)HabitPOWin : public xframe
    {
    public:
        xdwtable     dw_nopaper;
        xdwtable     dw_paper;
        xdwtable     dw_nopaper1;
        xdwtable     dw_paper1;
        xnode    m_agentNode;    //Agent Condition
 
    public:
        HabitPOWin(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
    public:
        static HabitPOWin* CreateInstance(void* implPtr, void* hWnd)
        {
            HabitPOWin* pWin = new HabitPOWin(implPtr, (HWND)hWnd);
            return pWin;
        }
        int SetAgent()
        {
            return 1;
 
            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;
        }
 
        //T}NäSÑ^Qýep
        int OnCmdDispatch(xstring comdid)
        {
            if (comdid == L"xmCancel")
            {
                CloseWindow();
                return 1;
            }
            else if (comdid == L"xmApply")
            {
                return OnOk();
            }
            return 0;
        }
 
        //T}NäYtN‹Nö
        int OnXCommand(TEvent* evt, LPARAM p)
        {
            return OnCmdDispatch(evt->xcommand.pStrID);
        }
 
        int SureItem(xdwtable dw_dest, xdwgrid dw_src, int drow, int srow, xstring colname, bool display = false, bool changed = false)
        {
            if (dw_dest.GetItemString(drow, colname) != dw_src.GetItemString(srow, colname))
            {
                if (changed)
                    dw_dest.ItemChangeTo(drow, colname, dw_src.GetItemString(srow, colname));
                else
                    dw_dest.SetItemString(drow, colname, dw_src.GetItemString(srow, colname));
                if (display)
                    dw_dest.SetItemDisplayString(drow, colname, dw_src.GetItemDisplayString(srow, colname));
            }
            return 1;
        }
 
        int OnUse(xdwtable dw_src, xdwtable dw_dest)
        {
            xdwtable dw_item = dw_src.FindDwTable(L"Item"); // R ]å^ú‹®
            xdwtable dw_pitem = dw_src.FindDwTable(L"PItem");
            for (int i = 1; i <= dw_item.GetRowCount(); i++)
            {
                xstring state = dw_item.GetItemString(i, L"Used");
                if (state == L"Y")
                {
                    int pRow = dw_pitem.GetGroupStartRow(i);
                    xstring skuno = dw_item.GetItemString(i, L"SKUNo");
                    //xstring PurchaseType = dw_pitem.GetItemDisplayString(pRow,L"PurchaseType");
                    //xstring scheme = dw_pitem.GetItemDisplayString(pRow,L"BOMSchemeID");
 
                    xdwtable dw_item1 = dw_dest.FindDwTable(L"Item"); //QúÐ'n
                    xdwtable dw_pitem1 = dw_dest.FindDwTable(L"PItem");
 
                    int k = 1;
                    for (k = 1; k <= dw_item1.GetRowCount(); k++)
                    {
                        if (dw_item1.GetItemString(k, L"GoodsNo").trim() == dw_item.GetItemString(i, L"GoodsNo").trim())
                        {
                            if (dw_item1.GetItemString(k, L"CustomerItemNo").trim() == dw_item.GetItemString(i, L"CustomerItemNo").trim())
                            {
                                break;
                            }
                        }
                    }
                    if (k > dw_item1.GetRowCount())
                    {
                        continue;
                        //dw_item1.InsertRow(0);
                    }
 
                    if (dw_item1.GetItemString(k, L"GoodsNo") == L"")
                    {
                        dw_item1.SetItemString(k, L"GoodsNo", dw_item.GetItemString(i, L"GoodsNo"));
                        dw_item1.SetItemString(k, L"CName", dw_item.GetItemString(i, L"CName"));
                        dw_item1.SetItemString(k, L"CustomerItemNo", dw_item.GetItemString(i, L"CustomerItemNo"));
                        dw_item1.SetItemString(k, L"BOMPart", dw_item.GetItemString(i, L"BOMPart"));
                    }
 
                    int r = dw_pitem1.GetGroupStartRow(k);
                    int rc = dw_pitem1.GetGroupRowCount(k);
                    int srow = dw_pitem.GetGroupStartRow(i);
                    for (int m = 1; m <= dw_pitem.GetGroupRowCount(i); m++)
                    {
                        if (m > rc)
                        {
                            dw_pitem1.InsertGroupRow(k, 0);
                            rc++;
                            //dw_pitem1.SetItemString(r + m - 1, L"BuyQuantity", dw_pitem1.GetItemString(r + m - 2,L"BuyQuantity"));
                        }
                        if (dw_pitem.GetItemString(srow + m - 1, L"BOMRate") == L"")
                            dw_pitem1.ItemChangeTo(r + m - 1, L"BOMRate", L"1:1");
                        else
                            dw_pitem1.ItemChangeTo(r + m - 1, L"BOMRate", dw_pitem.GetItemString(srow + m - 1, L"BOMRate"));
                        dw_pitem1.SetItemString(r + m - 1, L"Material", dw_pitem.GetItemString(srow + m - 1, L"Material"));
                        dw_pitem1.SetItemDisplayString(r + m - 1, L"Material", dw_pitem.GetItemDisplayString(srow + m - 1, L"Material"));
                        dw_pitem1.SetItemString(r + m - 1, L"PaperCardPacking", dw_pitem.GetItemString(srow + m - 1, L"PaperCardPacking"));
                        dw_pitem1.SetItemDisplayString(r + m - 1, L"PaperCardPacking", dw_pitem.GetItemDisplayString(srow + m - 1, L"PaperCardPacking"));
                        dw_pitem1.SetItemString(r + m - 1, L"BuySize", dw_pitem.GetItemString(srow + m - 1, L"BuySize"));
                        dw_pitem1.SetItemString(r + m - 1, L"SupplierID", dw_pitem.GetItemString(srow + m - 1, L"SupplierID"));
                        dw_pitem1.SetItemDisplayString(r + m - 1, L"SupplierID", dw_pitem.GetItemDisplayString(srow + m - 1, L"SupplierID"));
                        dw_pitem1.SetItemString(r + m - 1, L"DeliveryAddr", dw_pitem.GetItemString(srow + m - 1, L"DeliveryAddr"));
                        dw_pitem1.SetItemString(r + m - 1, L"StandUnitPrice", dw_pitem.GetItemString(srow + m - 1, L"StandUnitPrice"));
                        dw_pitem1.SetItemString(r + m - 1, L"UnitPriceRate", dw_pitem.GetItemString(srow + m - 1, L"UnitPriceRate"));
                        dw_pitem1.SetItemString(r + m - 1, L"PackUnitPrice", dw_pitem.GetItemString(srow + m - 1, L"PackUnitPrice"));
                        dw_pitem1.ItemChangeTo(r + m - 1, L"BuyUnitPrice", dw_pitem.GetItemString(srow + m - 1, L"BuyUnitPrice"));
                        dw_pitem1.SetItemString(r + m - 1, L"BOMPart", dw_pitem.GetItemString(srow + m - 1, L"BOMPart"));
                        dw_pitem1.SetItemString(r + m - 1, L"ItemID", dw_pitem.GetItemString(srow + m - 1, L"ItemID"));
                        dw_pitem1.SetItemString(r + m - 1, L"HasVATInvoice", dw_pitem.GetItemString(srow + m - 1, L"HasVATInvoice"));
                        dw_pitem1.SetItemString(r + m - 1, L"TechNote", dw_pitem.GetItemString(srow + m - 1, L"TechNote"));
                        dw_pitem1.SetItemString(r + m - 1, L"TestNote", dw_pitem.GetItemString(srow + m - 1, L"TestNote"));
                        dw_pitem1.SetItemString(r + m - 1, L"PackingMethod", dw_pitem.GetItemString(srow + m - 1, L"PackingMethod"));
                        dw_pitem1.SetItemString(r + m - 1, L"Remarks", dw_pitem.GetItemString(srow + m - 1, L"Remarks"));
                        dw_pitem1.SetItemString(r + m - 1, L"MouldBelong", dw_pitem.GetItemString(srow + m - 1, L"MouldBelong"));
                        dw_pitem1.SetItemString(r + m - 1, L"PrenatalSamplingTime", dw_pitem.GetItemString(srow + m - 1, L"PrenatalSamplingTime"));
                        dw_pitem1.SetItemString(r + m - 1, L"OpeningCompletionTime", dw_pitem.GetItemString(srow + m - 1, L"OpeningCompletionTime"));
                        dw_pitem1.SetItemString(r + m - 1, L"DeliveryDate", dw_pitem.GetItemString(srow + m - 1, L"DeliveryDate"));
                        dw_pitem1.SetItemString(r + m - 1, L"SampleNumber", dw_pitem.GetItemString(srow + m - 1, L"SampleNumber"));
                    }
                }
            }
            dw_dest.Redraw();
            return 1;
        }
 
        int OnOk() //OÝ[X
        {
            OnUse(dw_paper, dw_paper1);
 
            OnUse(dw_nopaper, dw_nopaper1);
 
            CloseWindow();
 
            return 1;
        }
 
 
        int OnAttachEvent()
        {
            //~Ñ[š]åQwgap¹QûN‹Nö
            AttachEvent(L"WM_XCOMMAND", (FEvent)&HabitPOWin::OnXCommand);
            //ƒ·SÖq&p¹N‹Nöÿ u(NŽ‘Ín]åQwga
            AttachEvent(L"WM_SETFOCUS", (FEvent)&HabitPOWin::OnSetFocus);
            return 1;
        }
 
 
        int onload()
        {
            SetArg();
            dw_nopaper = GetControl(L"dw_nopaper");
            dw_nopaper.openUrl(L"/sale/view/PurchaseOrder/template/item/nopapercardex/habit");
            dw_nopaper.SetRowSelectorWidth(0);
 
            dw_paper = GetControl(L"dw_paper");
            dw_paper.openUrl(L"/sale/view/PurchaseOrder/template/item/papercardex/habit");
            dw_paper.SetRowSelectorWidth(0);
 
            OnAttachEvent();
            SetAgent();
 
            xaserverarg arg = GetArg();
            xstring SONo = arg.GetArgString(L"SONo");
            xstring SOID = SaleOrderView::GetSOID(SONo);
            arg.AddArg(L"SOID", SOID);
            xml x = ViewObject::RetrieveData(L"/sale/data/PurchaseOrder/so/poitemlist/papercard/habit", L"SOID", SOID);
            if (x) dw_paper.Retrieve(x);
 
            x = ViewObject::RetrieveData(L"/sale/data/PurchaseOrder/so/poitemlist/nopapercard/habit", L"SOID", SOID);
            if (x) dw_nopaper.Retrieve(x);
 
            dw_paper1 = arg.GetControl(L"dw_paper");
            dw_nopaper1 = arg.GetControl(L"dw_nopaper");
 
            return 1;
        }
 
        int onloaded()
        {
 
            return 1;
        }
    };