xj qian
2025-04-07 ea03be1b12fccb6b4ee4667b06d827a6ed9f0721
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
þÿ
#include <wobject/xstring.hpp>
#include <xcontrol/xtreeview.hpp>
#include <xcontrol/xdwgrid.hpp>
#include <xcontrol/xexcel.hpp>
#include <adt/xarray.hpp>
 
#include "vbusiness/vframe/listwin.vframe.vbusiness.hpp"
#include "viewobject/view.base.hpp"
 
using xml = KXMLDOMDocument;
class __declspec(dllexport) SalaryslipImp : public xframe
{
public:
    xexcel    excel;
    xdwgrid dw_list;
    xstring filename;
    xnode    m_agentNode;    //Agent Condition
 
public:
    SalaryslipImp(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
public:
    static SalaryslipImp* CreateInstance(void* implPtr, void* hWnd)
    {
        SalaryslipImp* pWin = new SalaryslipImp(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, LPARAM param)
    {
        //‘Ín]åQwga
        SetAgent();
        return 1;
    }
 
    int OnDeleteRow()
    {
        dw_list.DeleteRow(0);
        return 1;
    }
 
    int OnInsertRow()
    {
        int row = dw_list.InsertRow(0);
        xstring sdate = publiccode::GetCurrentDate();
        dw_list.SetItemString(row, L"CreateDate", sdate);
        xstring suserid = publiccode::GetUser().id;
        xstring susername = publiccode::GetUser().name;
        dw_list.SetItemString(row, L"CreatorID", suserid);
        dw_list.SetItemDisplayString(row, L"CreatorID", susername);
 
        return 1;
    }
 
 
    int OnTran()
    {
        return 1;
 
        //get head
        xstring head = L"";
        xstring val = L"";
        int cols = excel.GetValidColumn();
        for (int col = 1; col <= cols; ++col)
        {
            val = excel.GetCellString(1, col);
            val = val.trim();
            if (val == L"")continue;
            if (val.find(L"(") >= 0) val = val.left(val.find(L"("));
            if (val.find(L"ÿ") >= 0) val = val.left(val.find(L"ÿ"));
            if (val.find(L"[") >= 0) val = val.left(val.find(L"["));
            if (val.find(L"0") >= 0) val = val.left(val.find(L"0"));
            if (val.find(L"/") >= 0) val = val.left(val.find(L"/"));
            if (val.find(L"\r") >= 0) val = val.left(val.find(L"\r"));
            if (val.find(L"\n") >= 0) val = val.left(val.find(L"\n"));
            if (head == L"") head = val; else head += L"," + val;
        }
 
        xml x;
 
        xaserverarg arg;
        arg.AddArg(L"head", head);
        //alert(head);
        if (getUrl(L"/sale/data/AR/match/bank", arg.GetString(), x) != 1)return 1;
        KXMLDOMNode n = x.selectSingleNode(L"data/Bank");
        if (!n)
        {
            alert(L"g*S9‘MR0Tv„lQe|{W‹ÿ ‹÷QH‘MnepcnlcbOá`o");
            return 1;
        }
 
        KXMLDOMNodeList items = n.selectNodes(L"Item");
        int len = items.length();
        xarray<int> indexs;
        xarray<xstring> columns;
        xstring bank = n.selectSingleNode(L"@name").text();
        for (int i = 0; i < len; i++)
        {
            KXMLDOMElement e = items.item(i);
            xstring str = e.getAttribute(L"index");
            indexs.push_back(str.toInt());
            columns.push_back(e.selectSingleNode(L"DataColumn").text());
        }
 
        if (MessageBox(GetHWND(), L"f/T&}Qe" + bank + L"epcn!", L"cÐy:", 1) == 2)  return 1;
 
        //clear data
        for (int m = dw_list.GetRowCount(); m > 0; m--)    dw_list.DeleteRow(m);
 
 
        //‹ûSÖ[¢b7lcbOá`o
        xml xc;
 
        if (getUrl(L"/sale/data/AR/tran/customer", L"", xc) != 1)
        {
            trace(xc.text());
            return -1;
        }
 
        HCURSOR  hCursor = xutil::SetCursorWait();
        KXMLDOMDocument xdoc = xc;
 
        int rows = excel.GetValidRow();
        for (int row = 2; row <= rows; ++row)
        {
            val = excel.GetCellString(row, indexs.item(0));
            if (val.trim() == L"") continue;
            int curRow = dw_list.InsertRow(0);
 
            //init
            xstring sdate = publiccode::GetCurrentDate();
            dw_list.SetItemString(curRow, L"CreateDate", sdate);
            dw_list.SetItemString(curRow, L"SEDate", sdate);
            xstring suserid = publiccode::GetUser().id;
            xstring susername = publiccode::GetUser().name;
            dw_list.SetItemString(curRow, L"CreatorID", suserid);
            dw_list.SetItemDisplayString(curRow, L"CreatorID", susername);
 
            for (int k = 0; k < indexs.length(); k++)
            {
                val = excel.GetCellString(row, indexs.item(k));
                if (columns.item(k) == L"CustomerID")
                {
                    if (xdoc)
                    {
                        KXMLDOMNode n1 = xdoc.selectSingleNode(L"/data/Item[contains(\"" + val + L"\",RawColumn)]");
                        if (n1)
                        {
                            //alert(n1.xml);
                            if (n1.selectSingleNode(L"DataColumn"))dw_list.SetItemString(curRow, columns.item(k).c_str(), n1.selectSingleNode(L"DataColumn").text());
                            if (n1.selectSingleNode(L"DataColumn/@_displaystring"))dw_list.SetItemDisplayString(curRow, columns.item(k).c_str(), n1.selectSingleNode(L"DataColumn/@_displaystring").text());
                        }
                    }
                }
                else
                    dw_list.SetItemString(curRow, columns.item(k).c_str(), val);
            }
        }
        xutil::RestoreCursor(hCursor);
        alert(L"lcb[Œb!");
 
        return 1;
    }
 
    int OnSaveData()
    {
        return 1;
 
        xml x;
 
        dw_list.AcceptText();
        dw_list.DwUpdateAllToEx(x);
        xaserverarg arg;
 
        arg.AddArg(L"content", x.xml());
 
        //trace(x.xml());
        if (xurl::get(L"/sale/data/AR/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"OÝ[XbRŸ!");
        }
        else
        {
            alert(L"OÝ[XY1%!");
        }
        return 1;
    }
 
 
    int SendCtrlCmd(xcontrol xc, xstring cmd)
    {
        SendMessage(xc.GetHWND(), 0x401, (WPARAM)cmd.c_str(), 0);
        return 1;
    }
 
 
 
    //T}NäSÑ^Qýep
    int OnCmdDispatch(xstring comdid)
    {
 
        if (comdid == L"xmAddRow")
        {
            return OnInsertRow();
        }
        else if (comdid == L"xmDeleteRow")
        {
            return OnDeleteRow();
        }
        else if (comdid == L"xmSave")
        {
            return OnSaveData();
        }
    
        else if (comdid == L"xmTrans")
        {
            OpenWindow(L"dev:xpage[ExchangeColumnTran.vx]");
            return 1;
        }
        else if (comdid == L"xmClient")
        {
            OpenWindow(L"dev:xpage[CustomerTran.AR.vx]");
            return 1;
        }
        else if (comdid == L"xmBank")
        {
            OpenWindow(L"dev:xpage[ExchangeBankTran.vx]");
            return 1;
        }
        else if (comdid == L"xmTran")
        {
            return OnTran();
        }
        return 0;
    }
 
    //T}NäYtN‹Nö
    int OnXCommand(TEvent* evt, LPARAM param)
    {
        return OnCmdDispatch(evt->xcommand.pStrID);
    }
 
    int OnAttachEvent()
    {
        //~Ñ[š]åQwgap¹QûN‹Nö
        AttachEvent(L"WM_XCOMMAND", (FEvent)&SalaryslipImp::OnXCommand);
        //ƒ·SÖq&p¹N‹Nöÿ u(NŽ‘Ín]åQwga
        AttachEvent(L"WM_SETFOCUS", (FEvent)&SalaryslipImp::OnSetFocus);
        return 1;
    }
 
 
 
    int onload()
    {
        dw_list = GetControl(L"dw_list");
        dw_list.openUrl(L"/sale/view/AR/template/listex");
        OnAttachEvent();
 
 
        filename = L"";
 
        SetArg();
        xaserverarg arg = GetArg();
        if (arg)
        {
            xstring file = arg.GetArgString(L"file");
            if (!excel.GetNativePtr())
            {
                alert(L"N €ýÞc¥Excel");
                return 1;
            }
 
            excel.OpenDocument(file);
            excel.put_Visible(true);
 
            int rows = excel.GetValidRow();
            int cols = excel.GetValidColumn();
            //BSTR val = excel.GetCellString(1, 1);
            //SysFreeString(val);
            //excel.Quit();
        }
 
 
        return 1;
    }
 
    int onloaded()
    {
        SetAgent();
 
        return 1;
    }
};