LiFan
2025-04-30 35b0dc24898d3beb4edb1bc958d30a18a0749625
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
þÿ
#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"
#include <win32/xfile.hpp>
 
#include <map>
#include <string>
#include <vector>
 
using xml = KXMLDOMDocument;
class __declspec(dllexport) SalaryslipImpView : public xframe
{
public:
    xdwgrid dw_list;
    xnode    m_agentNode;    //Agent Condition
    xstring path;
    std::map<std::wstring, std::wstring> mapHead;
public:
    SalaryslipImpView(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
public:
    static SalaryslipImpView* CreateInstance(void* implPtr, void* hWnd)
    {
        SalaryslipImpView* pWin = new SalaryslipImpView(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 GetHeadRow(xexcel& excel)
    {
        int cols = excel.GetValidColumn();
        int rows = excel.GetValidRow();
 
        int countColumn = 5;
        int count = 0;
        int headrow = 0;
        xstring val;
        for (int row = 1; row <= rows; row++)
        {
            count = 0;
            for (int col = 1; col <= cols; col++)
            {
                val = excel.GetCellString(row, col);
                if (val != L"")count++;
                if (count > countColumn)break;
            }
            if (count > countColumn)
            {
                headrow = row;
                break;
            }
        }
        return headrow;
    }
 
    int OnTran(xexcel&    excel)
    {
        //get head
        xstring head = L"";
        xstring headcols = L"";
 
        xstring val = L"";
 
        int cols = excel.GetValidColumn();
        int rows = excel.GetValidRow();
 
        int headrow = GetHeadRow(excel);
        if (headrow < 1)
        {
            alert(L"g*b~R0Tv„h˜˜Y4");
            return 1;
        }
 
        for (int col = 1; col <= cols; ++col)
        {
            val = excel.GetCellString(headrow, 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;
            if (headcols == L"") headcols = xstring(col); else headcols += L"," + xstring(col);
        }
 
        xml x;
        xaserverarg arg;
        arg.AddArg(L"path", path);
        arg.AddArg(L"head", head);
        arg.AddArg(L"columns", headcols);
        //alert(head);
        if (getUrl(L"/sale/data/Thing/content/matchhead", arg.GetString(), x) != 1)return 1;
        const wchar_t* str = x.xml();
        KXMLDOMNode n = x.selectSingleNode(L"data/Type");
        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();
        std::vector<int> indexs;
        std::vector<std::wstring> columnheads;
        std::vector<std::wstring> 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");
 
            const wchar_t* colhead = e.selectSingleNode(L"DataColumn").text();
            if (mapHead.find(colhead) != mapHead.end())
            {
                indexs.push_back(str.toInt());
                columnheads.push_back(colhead);
                columns.push_back(mapHead[colhead]);
            }
        }
 
        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);
        dw_list.Reset();
 
 
        //‹û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;
 
        xstring names=L"";
        xstring rownos = L"";
        for (int row = headrow + 1; row <= rows; row++)
        {
            val = excel.GetCellString(row, indexs[0]);
            if (val.trim() == L"T‹¡")break;
            int curRow = dw_list.InsertRow(0);
            if (rownos == L"")
                rownos = xstring(curRow);
            else
                rownos += L","+ xstring(curRow);
 
            //init
            xstring sdate = publiccode::GetCurrentDate();
            dw_list.SetItemString(curRow, L"CreateDate", 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);
            dw_list.SetItemString(curRow, L"SalaryslipID", publiccode::GetGuid());
            for (int k = 0; k < indexs.size(); k++)
            {
                val = excel.GetCellString(row, indexs[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*/
                if (columnheads[k] == L"TX]å")
                {
                    if (names == L"")
                        names = val;
                    else
                        names +=(xstring) L"," + val;
                    dw_list.SetItemDisplayString(curRow, columns[k].c_str(), val);
                }else
                    dw_list.SetItemString(curRow, columns[k].c_str(), val);
            }
        }
        ViewObject::RetrieveData(L"GetPersonsInfo");
        xml x1 = ViewObject::RetrieveData(L"/sale/data/expense3/GetPersonsInfo", L"names", names, L"rows", rownos);
        KXMLDOMNodeList itemp = x1.selectNodes(L"data/Item");
        const wchar_t* str1 = x1.xml();
        int cnt = itemp.length();
        for (int i = 0; i < cnt; i++)
        {
            KXMLDOMNode tp = itemp.item(i);
            xstring rowno = tp.selectSingleNode(L"row").text();
            int row = rowno.toInt();
            if (rowno != L"")
            {
                if (tp.selectSingleNode(L"SpecialDeductFeeAmout"))
                {
                    /*double SpecialDeductFeeAmoutEx = 0.00;
                    xstring SpecialDeductFeeAmout = ;
                    SpecialDeductFeeAmoutEx =SpecialDeductFeeAmout.toDouble();*/
                    dw_list.SetItemString(row, L"SpecialDeductFee", tp.selectSingleNode(L"SpecialDeductFeeAmout").text());
                }
                if (tp.selectSingleNode(L"DeptName"))
                {
                    dw_list.SetItemString(row, L"DeptName", tp.selectSingleNode(L"DeptName").text());
                    dw_list.SetItemDisplayString(row, L"DeptName", tp.selectSingleNode(L"DeptName").text());
                }
                if (tp.selectSingleNode(L"GroupName"))
                {
                    dw_list.SetItemString(row, L"GroupName", tp.selectSingleNode(L"GroupName").text());
                    dw_list.SetItemDisplayString(row, L"GroupName", tp.selectSingleNode(L"GroupName").text());
                }
                dw_list.SetItemString(row, L"PersonID", tp.selectSingleNode(L"PersonID").text());
            }
        }
        //GetPersonsInfo
        xutil::RestoreCursor(hCursor);
        dw_list.Redraw();
        alert(L"lcb[Œb!");
 
        return 1;
    }
 
    int OnSaveData()
    {
        xml x;
 
        dw_list.AcceptText();
        dw_list.DwUpdateAllToEx(x);
        xaserverarg arg;
 
        xstring    content =  x.xml();
        arg.AddArg(L"content", content);
 
        //trace(x.xml());
        if (xurl::get(L"/sale/data/expense3/update/salaryslip/imp", 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;
    }
 
    xstring GetOpenFileName(xstring initFileName, const string filter, xstring ext)
    {
        //xstring path = GetOpenFileName(L"",
        //        "JPEG e‡Nö(*.jpg)\0*.jpg;*.jpeg;*.png;*.gif;*.bmp\0Qhèe‡Nö(*.*)\0*.*\0",
        //        "jpg");        
 
        wchar_t  szFileName[4096];
        wchar_t szPath[4096];
        szFileName[0] = 0;
        szPath[0] = 0;
 
        if (initFileName != L"")
        {
            int len = initFileName.length();
            const wchar_t* tmp = initFileName.c_str();
            for (int i = 0; i < len + 1; i++)
            {
                szPath[i] = tmp[i];
            }
        }
 
        int     nFilterIndex = 1;
        OPENFILENAMEW ofn;
 
        ofn.lStructSize = sizeof(ofn);
        ofn.hwndOwner = 0;
        ofn.hInstance = 0;
        ofn.lpstrFilter = filter;
        //"JPEG e‡Nö(*.jpg)\0*.jpg;*.jpeg;*.png;*.gif;*.bmp\0Qhèe‡Nö(*.*)\0*.*\0";
        ofn.lpstrCustomFilter = 0;
        ofn.nMaxCustFilter = 0;
        ofn.nFilterIndex = nFilterIndex;
        ofn.lpstrFile = szPath;
        ofn.nMaxFile = 4096;
        ofn.lpstrFileTitle = szFileName;
        ofn.nMaxFileTitle = 4096;
        ofn.lpstrTitle = L"‹÷c[še‡NöT ";
        ofn.lpstrDefExt = ext;
        //"jpg";
        ofn.lpstrInitialDir = 0;
        ofn.Flags = 0x00001000/*OFN_FILEMUSTEXIST*/ | 0x00080000 /*OFN_EXPLORER*/;
        ofn.lCustData = 0;
        ofn.lpfnHook = 0;
        ofn.lpTemplateName = 0;
 
        ofn.nFileOffset = 0;
        ofn.nFileExtension = 0;
 
        //debugbreak();
        if (xfile::GetOpenFileName(ofn))
        {
            return szPath;
        }
        else
            return L"";
    }
 
    int OnImport()
    {
        xexcel excel;
        if (!excel.getNativePointer())
        {
            alert("N €ýÞc¥u5[Pˆhh<");
            return 1;
        }
        xstring file = GetOpenFileName(L"", L"Excel1e‡Nö(*.xlsx)\0*.xlsx;*.xls\0Excel97e‡Nö(*.xls)\0*.xls\0PDFe‡Nö(*.pdf)\0*.pdf\0",
            L"xlsx");
        if (file != L"")
        {
            excel.OpenDocument(file);
            //excel.put_Visible(true);
 
            OnTran(excel);
            excel.Quit();
        }
 
 
        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"xmImport")
        {
            return OnImport();
        }
        else if (comdid == L"xmSave")
        {
            return OnSaveData();
        }
    
        else if (comdid == L"xmTrans")
        {
            xaserverarg arg;
            arg.AddArg(L"path", path);
            OpenWindow(L"dev:xpage[column.trans.vx]",arg);
            return 1;
        }
        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)&SalaryslipImpView::OnXCommand);
        //ƒ·SÖq&p¹N‹Nöÿ u(NŽ‘Ín]åQwga
        AttachEvent(L"WM_SETFOCUS", (FEvent)&SalaryslipImpView::OnSetFocus);
        return 1;
    }
 
    int SetHeadMap(xml& x)
    {
        KXMLDOMElement columns = x.selectSingleNode(L"//cells/row[@rowindex='5']");
        KXMLDOMElement heads = x.selectSingleNode(L"//cells/row[@rowindex='3']");
 
        KXMLDOMNodeList nodes = columns.selectNodes(L"cell[@column]");
        long lens = nodes.length();
        for (int i = 0; i < lens; i++)
        {
            KXMLDOMElement ele = nodes.item(i);
            xstring column = ele.getAttribute(L"column");
            xstring colindex = ele.getAttribute(L"colindex");
            KXMLDOMNode node = heads.selectSingleNode(L"cell[@colindex = '" + colindex + L"']/text");
            if (node)
            {
                xstring head = node.text();
                mapHead[head.c_str()] = column.c_str();
            }
        }
 
        return 1;
    }
 
    int onload()
    {
        path = L"salaryslip/trans/head";
 
        dw_list = GetControl(L"dw_list");
 
        xml x;
        if (xurl::get(L"/sale/view/expense3/Salaryslip/list", L"", x) == 1)
        {
            dw_list.SetDataObject(x);
            SetHeadMap(x);
        }
        //dw_list.openUrl(L"/sale/view/expense3/Salaryslip/list");
 
        OnAttachEvent();
 
        return 1;
    }
 
    int onloaded()
    {
        SetAgent();
        OnImport();
 
        return 1;
    }
};