LiFan
2025-04-29 6c8c9ddaeb2bc6245a374c9354296bcfc2d96c06
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
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
ÿþ#include <guiddef.h>
#include <exdisp.h>        // Defines of stuff like IWebBrowser2. This is an include file with Visual C 6 and above
#include <mshtml.h>        // Defines of stuff like IHTMLDocument2. This is an include file with Visual C 6 and above
#include <mshtmhst.h>    // Defines of stuff like IDocHostUIHandler. This is an include file with Visual C 6 and above
#include <Shlwapi.h>
#include <Windows.h>
#include <comutil.h>
 
#undef _XWIN
 
#include <wobject/xstring.hpp>
#include <xcontrol/xtreeview.hpp>
#include <xcontrol/xdwgrid.hpp>
#include <win32/xfile.hpp>
#include <xcontrol/xexcel.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) ShipmentNewSample3 : public xframe
{
public:
    ShipmentNewSample3(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
public:
    static ShipmentNewSample3* CreateInstance(void* implPtr, void* hWnd)
    {
        return  new ShipmentNewSample3(implPtr, (HWND)hWnd);
    }
public:
        xdwgrid    dw_list;
        xdwtable dw_arg;
        xnode    m_agentNode;    //Agent Condition
 
        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;mYtýQpe
        int OnSetFocus(TEvent* evt, LPARAM param)
        {
            //͑nå]wQag
            SetAgent();
            return 1;
        }
        
            
            
        int OnLookImage(xstring skuid,xstring CustomerID,xstring CustomerItemNo)
        {
            HCURSOR hCursor = xutil::SetCursorWait();
            xaserverarg arg ;
            arg.AddArg(L"guid",skuid);
            arg.AddArg(L"CustomerID",CustomerID);
            arg.AddArg(L"CustomerItemNo",CustomerItemNo);
            OpenWindow(L"dev:xpage[ViewPicturesEx.vx]",arg);
            xutil::RestoreCursor(hCursor);
            return 1;
        }    
                    
        int OnPrint()
        {
            
            xaserverarg arg;
                
            arg.AddArg(L"EntityName",L"Quote",L"");
            arg.AddArg(L"EntityID",L"",L"");
            arg.AddArg(L"EntityNo",L"22JR0089",L"");
            
            openUrl(L"/sale/view/view.base/xpage/Template/PrintViewEx", arg);
            return 1;
        }
        
        xstring GetMySaveFileName(xstring initFileName, xstring filter, xstring ext)
        {
            wchar_t  szFileName[255] = { 0 };
            wchar_t  szPath[255] = { 0 };
 
            if (initFileName != L"")
            {
                int len = initFileName.length();
                const wchar_t* tmp = initFileName;
                for (int i = 0; i < len + 1; i++)
                {
                    //szFileName[i] = tmp[i];
                    szPath[i] = tmp[i];
                }
            }
 
            int     nFilterIndex = 1;
            OPENFILENAMEW ofn = { 0 };
            //::ZeroMemory(&ofn,sizeof(OPENFILENAMEW))
            //ofn.lStructSize = 88;//sizeof(ofn);
            ofn.lStructSize = sizeof(ofn);
            ofn.hwndOwner = GetHWND();
            ofn.hInstance = 0;
            ofn.lpstrFilter = filter;
            //"JPEG ‡eöN(*.jpg)\0*.jpg;*.jpeg;*.png;*.gif;*.bmp\0hQ萇eöN(*.*)\0*.*\0";
            ofn.lpstrCustomFilter = 0;
            ofn.nMaxCustFilter = 0;
            ofn.nFilterIndex = nFilterIndex;
            ofn.lpstrFile = szPath;
            ofn.nMaxFile = 255;
            ofn.lpstrFileTitle = szFileName;
            ofn.nMaxFileTitle = 255;
            ofn.lpstrTitle = L"÷‹cš[‡eöN T";
            ofn.lpstrDefExt = ext;
            //"jpg";
            ofn.lpstrInitialDir = 0;
            ofn.Flags = 0x00000010/*OFN_SHOWHELP*/ | 0x00001000/*OFN_FILEMUSTEXIST*/;
            ofn.lCustData = 0;
            ofn.lpfnHook = 0;
            ofn.lpTemplateName = 0;
 
            //debugbreak();
            if (xfile::GetSaveFileName(ofn))
            {
                return szPath;
            }
            else
            {
                return L"";
            }
        }
 
        xstring GetModulePath()
        {
            wchar_t str[255];
            GetModuleFileName(0, str, 255);
            PathRemoveFileSpec(str);
            return str;
        }
        xstring GetModuleTmpPath()
        {
            wchar_t str[255];
            GetModuleFileName(0, str, 255);
            PathRemoveFileSpec(str);
            xstring tmp = (xstring)str + L"\\Temp";
            xaserver::CreateDirectory(tmp);
            return tmp;
        }
 
        xstring getfilePath()
        {
            xstring path = GetModulePath() + L"\\resource\\image";
            return path;
        }
 
        xstring replaceInnerElement(xstring html)
        {
            xstring str = html;
            if (str.find(L"[$element:") < 0) return str;
 
            int len = 0;
            int pos = 0;
            int pos1 = 0;
            xstring pre = L"";
            xstring left = L"";
            xstring right = L"";
            xstring tag = L"";
 
            len = ((xstring)L"[$element:").length();
            while (true)
            {
                pos = str.find(L"[$element:");
                if (pos < 0) break;
                left = str.left(pos);
                right = str.mid(pos + len, 999999);
 
                pos1 = right.find(L"]");
                if (pos1 >= 0)
                {
                    tag = right.left(pos1);
                    if (tag.right(1) == L"$") tag = tag.left(tag.length() - 1);
                    pre = pre + left + L"<" + tag + L">";
                    str = right.mid(pos1 + 1, 999999);
                }
                else
                {
                    pre = pre + left + L"<";
                    str = right;
                }
            }
 
            str = pre + str;
            pre = L"";
            len = ((xstring)L"[/$element:").length();
            while (true)
            {
                pos = str.find(L"[/$element:");
                if (pos < 0) break;
                left = str.left(pos);
                right = str.mid(pos + len, 999999);
                pos1 = right.find(L"]");
                if (pos1 >= 0)
                {
                    tag = right.left(pos1);
                    if (tag.right(1) == L"$") tag = tag.left(tag.length() - 1);
                    pre = pre + left + L"</" + tag + L">";
                    str = right.mid(pos1 + 1, 999999);
                }
                else
                {
                    pre = pre + left + L"</";
                    str = right;
                }
            }
            str = pre + str;
            return str;
        }
 
        xstring adjustXsl(xstring str, xstring localPath)
        {
            //if(str.find("%")>=0)  str = str.replace("%","");
            if (str.find(L"[$path]/rpttemplate") >= 0) str = str.replace(L"[$path]/rpttemplate", localPath);
            str = replaceInnerElement(str);
            return str;
        }
 
        xstring DownLoadSKUNoPic(xstring serverUrl, xstring SKUNo, xstring CustomerID = L"", xstring CustomerItemNo = L"")
        {
            xml x;
            xaserverarg arg;
            arg.AddArg(L"SKUNo", SKUNo);
 
            xstring src = L"/sale/data/ProductLibrary3/pref/picture/imagelistSKUNo";
            if (CustomerID != L"")
            {
                arg.AddArg(L"CustomerID", CustomerID);
                arg.AddArg(L"CustomerItemNo", CustomerItemNo);
                src = L"/sale/data/ProductLibrary3/pref/picture/customer/imagelistSKUNo";
            }
            //trace("SKUNo="+SKUNo);//‰    gU\:yþVGrågâ‹agöN…QÅ_š[‰skuno
            if (xurl::get(src, arg.GetString(), x) != 1)
            {
                trace(L"error for download skuno pic!");
                return L"";
            }
 
            xstring spath = L"";
            xstring path = GetModuleTmpPath();
            xstring ext = L"jpg";
            if (x.selectSingleNode(L"//FileExt[1]"))
            {
                ext = x.selectSingleNode(L"//FileExt[1]").text();
            }
            else if (CustomerID != L"")
            {
                src = L"/sale/data/ProductLibrary3/pref/picture/imagelistSKUNo";
                if (xurl::get(src, arg.GetString(), x) != 1)
                {
                    trace(L"error for download skuno pic!");
                    return L"";
                }
                if (x.selectSingleNode(L"//FileExt[1]"))
                    ext = x.selectSingleNode(L"//FileExt[1]").text();
            }
 
            xstring filename = SKUNo + L"." + ext;
            if (x.selectSingleNode(L"//PicPath[1]"))
                spath = x.selectSingleNode(L"//PicPath[1]").text();
            if (spath != L"")
            {
                xaserver::DownLoadFile(serverUrl, spath, L"", path + L"/" + filename);
            }
            return L"file://" + path + L"/" + filename;
        }
 
        xstring DownLoadPaperPic(xstring guid, xstring serverUrl)
        {
 
            xstring path = GetModuleTmpPath();
            xstring ext = L"jpg";
            xstring filename = guid + L"." + ext;
            xstring str = guid.mid(0, 2);
            xstring spath = L"/business/products/chanpin/" + str + L"/" + guid + L".jpg";
            xaserver::DownLoadFile(serverUrl, spath, L"", path + L"/" + filename);
            return L"file://" + path + L"/" + filename;
        }
 
        xstring GetHtml(xdwgrid dw_obj, xstring xslPath, xstring serverUrl)
        {
            HCURSOR hCursor = xutil::SetCursorWait();
 
            xml m_dataset;
            dw_obj.DwUpdateAllTo(m_dataset);
 
            xstring argstr = L"<args><arg name='xsl' value='/business/" + xslPath + L"' type=''/></args>";
            xml xsl;
            if (xurl::get(L"/sale/data/SysPrintTemplate/getxsl", argstr, xsl) != 1)
            {
                alert(L"penc!jg•ï‹!");
                return L"";
            }
 
            xstring xslStr = xsl.xml();
            xslStr = xslStr.replace(L"data/row", L"data");
            xslStr = xslStr.replace(L"//ÁT T1/ĉ<hy˜1", L"Item");
 
            xstring sdate = publiccode::GetCurrentDate();
 
            xslStr = xslStr.replace(L"<xsl:value-of select=\"CreateDate\"/>", sdate);
            xslStr = adjustXsl(xslStr, getfilePath());
            trace(L"-----" + xslStr + L"-------");
            xsl.loadXML(xslStr);
 
            xstring htmlStr = m_dataset.transformNode(xsl);
 
            xstring aspace = htmlStr.replace(L"[zz]", L"&nbsp;", 0);
            aspace = aspace.replace(L"[line]", L"<br/>", 0);
            xstring scontent = aspace.replace(L"<?xml version=\"1.0\"?>", L"", 0);
 
            xstring head = L"";
            xstring tail = scontent;
 
            int pos = tail.find(L"src=\"item-picture:");
            while (pos > 0)
            {
                int spos = pos + ((xstring)L"src=\"item-picture:").length();
                int pos1 = tail.find(L"\"", spos + 1);
                xstring skuno = tail.mid(spos, pos1 - spos).trim();
                xstring CustomerID = L"";
                xstring CustomerItemNo = L"";
                if (skuno.find(L",") > 0)
                {
                    CustomerID = skuno.left(skuno.find(L",")).trim();
                    skuno = skuno.mid(skuno.find(L",") + 1, 256).trim();
                }
                if (skuno.find(L",") > 0)
                {
                    CustomerItemNo = skuno.left(skuno.find(L",")).trim();
                    skuno = skuno.mid(skuno.find(L",") + 1, 256).trim();
                }
                xstring src = DownLoadSKUNoPic(serverUrl, skuno, CustomerID, CustomerItemNo);
                head += tail.left(pos) + L"src=\"" + src;
                tail = tail.mid(pos1, 999999999);
                pos = tail.find(L"src=\"item-picture:");
            }
            scontent = head + tail;
 
            head = L"";
            tail = scontent;
            int position = tail.find(L"src=\"paper-picture:");
            while (position > 0)
            {
                int sposition = position + ((xstring)L"src=\"paper-picture:").length();
                int position1 = tail.find(L"\"", sposition + 1);
                xstring guid = tail.mid(sposition, position1 - sposition).trim();
                xstring src2 = DownLoadPaperPic(guid, serverUrl);
                head += tail.left(position) + L"src=\"" + src2;
                tail = tail.mid(position1, 999999999);
                position = tail.find(L"src=\"paper-picture:");
            }
            scontent = head + tail;
 
            //scontent = adjustXsl(scontent,sPath);
            htmlStr = scontent;
 
 
            /*
            string xcontent = htmlStr.replace("[zz]"," ",0);
            int pos0 = xcontent.find("<xml");
            int pos2 = xcontent.find("</xml>");
            if(pos0>=0)
            {
                string str = xcontent.left(pos0)+ xcontent.mid(pos2+6,9999999);
                xcontent = str;
            }*/
 
            return htmlStr;
        }
        int OnExport(HWND hWnd, xstring htmlStr)
        {
            xstring pre = L"eQ“^°eÁTß~¡‹hˆ";
            xstring file = GetMySaveFileName(pre + L".xlsx",
                L"Excel‡eöN(*.xlsx)\0*.xlsx;*.xls\0Excel97‡eöN(*.xls)\0*.xls\0PDF‡eöN(*.pdf)\0*.pdf\0",
                L"xlsx");
            if (file == L"") return 1;
 
            if (PathFileExists(file))
            {
                int res = MessageBox(GetHWND(), L"‡eöNò]Ï~X[(W ÿ/f&T†‰Öv?", L"Ðc:y", 4);
                if (res != 6) return 1;
            }
 
            xutil::SaveToFile(file, htmlStr, L"", L"", (LPTSTR)L"");
 
            return 1;
        }
 
        int OntoExcel(xstring htmlStr) //l:NExcel
        {
            xexcel excel;
 
            xstring gid = publiccode::GetGuid();
            xstring pre = L"eQ“^°eÁTß~¡‹hˆ";
            xstring filename = pre + L".htm";
            xstring filenameex = pre + L".xlsx";
            xutil::SaveToFile(GetModuleTmpPath() + L"\\" + filename, htmlStr, L"", L"", (LPTSTR)L"");
            excel.OpenDocument(GetModuleTmpPath() + L"\\" + filename);
            //excel.put_Visible(true);
            //excel.TransShape();
            if (PathFileExists(GetModuleTmpPath() + L"\\" + filenameex))
                DeleteFile(GetModuleTmpPath() + L"\\" + filenameex);
            excel.SaveToFile(GetModuleTmpPath() + L"\\" + filenameex);
            excel.put_Visible(true);
 
            return 1;
        }
 
        //}TäNÑS^ýQpe
        int OnCmdDispatch(xstring comdid)
        {
            HCURSOR hCursor =  0;
            if (comdid == L"xmRefresh")
            {
                OnRetrieve();
            }
            if(comdid==L"xmLookImage")
            {
                int row = dw_list.GetRow();
                xstring skuid =dw_list.GetGuid(row);
                xstring CustomerID =dw_list.GetItemString(row,L"CustomerID");
                xstring CustomerItemNo =dw_list.GetItemString(row,L"CustomerItemNo");
                OnLookImage(skuid,CustomerID,CustomerItemNo);
                return 1;
            }
            if(comdid==L"xmAnalysis")
            {
                hCursor = xutil::SetCursorWait();
                xstring str = dw_list.DataAnalysis(L"");
                xaserverarg arg;
                                        
                arg.AddArg(L"html", str);
            
                OpenWindow(L"dev:xpage[data.vanalysis.vx]", arg);
                xutil::RestoreCursor(hCursor); 
                return 1;
            }
 
            else if(comdid==L"xmExcel")
            {
                OntoExcel(GetHtml(dw_list,L"rpttemplate/Quote/4544F98B-60D1-4787-8092-DFE5ED930560.xsl",GetServerUrl()));
                return 1;
            }
            else if(comdid==L"xmSaveAs")
            {
                /*xstring file = exporter.GetSaveFileName(L"eQ“^°eÁTß~¡‹hˆ"+L".xlsx",
                "Excel‡eöN(*.xlsx)\0*.xlsx;*.xls\0Excel97‡eöN(*.xls)\0*.xls\0PDF‡eöN(*.pdf)\0*.pdf\0",
                "xlsx");
                */
                
                //dw_list.SaveAs(L""); 
                xstring htmlStr = GetHtml(dw_list,L"rpttemplate/Quote/4544F98B-60D1-4787-8092-DFE5ED930560.xsl",GetServerUrl());
                OnExport(GetHWND(), htmlStr);
                
                return 1;
            }
 
            else if(comdid==L"xmPrint")
            {
                OnPrint();
                return 1;
            }
            
            return 0;
        }
        
        //æ‰ÑS Ÿh»y_Ttran‹NöN ÿÇåg~bÐg*NÂSpe—_0Rù[”^„vR            
        int OnBaseItemChanged(TEvent* evt, int p)
        {
            DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
            xstring colname=hdr.colname;
            xstring value = hdr.data;
            
            xstring dwname = L"dw_list";
            if(value != L"")
            {
                KXMLDOMNodeList nlist = GetElement().selectNodes(L"//*[@name='"+dwname+L"']/trans[@for='"+colname+L"']");
                ViewObject::TransData(nlist, dw_list, hdr.row, colname, value);
            }
            return 1;
        }
            
        
        //}TäNYt‹NöN
            int OnXCommand(TEvent* evt, LPARAM param)
            {
                return OnCmdDispatch(evt->xcommand.pStrID);
            }
        
        int OnAttachEvent()
        {
            //Ñ~š[å]wQag¹pûQ‹NöN
            AttachEvent(L"WM_XCOMMAND", (FEvent)&ShipmentNewSample3::OnXCommand);
            //·ƒÖS&q¹p‹NöN ÿ(uŽN͑nå]wQag
            AttachEvent(L"WM_SETFOCUS", (FEvent)&ShipmentNewSample3::OnSetFocus);
            AttachEvent(L"dw_list",L"DWV_ITEMCHANGED", (FEvent)&ShipmentNewSample3::OnBaseItemChanged);
            return 1;
        }
            
        xstring GetQueryArg()
        {
            dw_arg.AcceptText();
            xml x ;
            
            dw_arg.DwUpdateAllTo(x);
            return x.xml();
        }    
        
        int  OnRetrieve()
        {
            xml x ;
            
            xaserverarg arg ;
                
            arg.AddArg(L"QueryTxt",xcontrol(GetControl(L"search")).GetText());
            arg.AddArg(L"QueryArg",GetQueryArg());
            trace(GetQueryArg());
            if (getUrl(L"/sale/data/Sample/entity/ShipmentNewLsit",arg.GetString(),x)!=1)
            {
                alert(x.xml());
                trace(x.text());
                return -1;
            }else    
            {
                
                dw_list.Retrieve(x);
                dw_list.Redraw();
            }
            dw_list.SetSelectionMode(1);
            dw_list.SetReadOnly(true);
            return 1;
        }
    
        int onload()
        {
            dw_list = GetControl(L"dw_list");
            dw_list.openUrl(L"/sale/view/Sample/template/Sample/–™!kúQ'°eÁT");
            dw_list.SetColumnState(L"SKUNo",false);
            dw_list.SetColumnState(L"CustomerID",false);
            dw_list.SetColumnState(L"CustomerItemNo",false);
            dw_list.SetColumnState(L"SKUNoEx",false);
            
            dw_arg = GetControl(L"dw_arg");
            dw_arg.openUrl(L"/sale/view/AR/template/queryarg");
            dw_arg.SetColHeaderHeight(0);
            dw_arg.SetRowSelectorWidth(0);
            dw_arg.SetHScrollState(false);
            dw_arg.SetVScrollState(false);
            dw_arg.SetItemString(1,L"DateType",L",gt^");
            
            OnRetrieve();
        
            OnAttachEvent();    
            
            return 1;
        }
        
        int onloaded()
        {
            SetAgent();
            return 1;
        }        
    };