lifan
18 小时以前 cd64beb3e891e11f673b75250cf99daad5ca1d38
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
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
ÿþ#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"
 
 
#include <wobject/xdouble.hpp>
#include <xcontrol/xlayersheet.hpp>
#include <xcontrol/xdatetimepick.hpp>
#include "xcontrol/xshtml.hpp"
#include <xcontrol/ximageview.hpp>
#include "viewobject/productlibrary.view.hpp"
 
using xml = KXMLDOMDocument;
    class __declspec(dllexport) UserProductApply :  public xframe
    {
    public:
        UserProductApply(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
    public:
        static UserProductApply* CreateInstance(void* implPtr, void* hWnd)
        {
            return  new UserProductApply(implPtr, (HWND)hWnd);
        }
    public:
        xdwgrid    dw_list;
        xdwtable dw_arg;
        KXMLDOMElement imageElement;
        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;
        }
 
        xstring GetQueryArg()
        {
            dw_arg.AcceptText();
            xml x;
 
            dw_arg.DwUpdateAllTo(x);
            return x.xml();
        }
 
                
        int OnRetrieve()
        {
            xml x;
            xcontrol query = GetControl(L"sle_search");
            xstring keyword = query.GetText();
            //alert(keyword);
            
            xaserverarg arg ;
            
            arg.AddArg(L"keyword",keyword);
            arg.AddArg(L"QueryArg", GetQueryArg());
            if(xurl::get(L"/sale/data/ProductLibrary3/data/list/applylist", arg.GetString(),x)!=1) 
            {
                xstring error = x.text();
                trace(error);
            }
            else
            {
                dw_list.Retrieve(x);
            }
            
            for(int i=1;i<=dw_list.GetColumnCount();i++)
            {
                //trace(dw_list.GetColumnName(i));
                if(dw_list.GetColumnName(i)!=L"GoodsNo"  &&
                    dw_list.GetColumnName(i)!=L"EName" &&
                    dw_list.GetColumnName(i)!=L"CName"&&
                    dw_list.GetColumnName(i)!=L"Packing") 
                    dw_list.SetReadOnlyColumn(i);
            }
            dw_list.Redraw();
            return 1;
        }
                
        xml  GetGoodsPropList(xstring guid)
        {
            xml x;
            
            xaserverarg arg ;
            
            arg.AddArg(L"guid", guid);    
            if(xurl::get(L"/sale/data/SO/goods/goodsprop/list", arg.GetString(),x)!=1)
            {
                xstring error = x.text();
                alert(error);
            }
                return x;
        }
            
        xml  GetGoodsPropListEx(xstring guid)
        {
            xml x;
            
            xstring fields=L"<data>";
            //fields +=L"<field name='HighestPrice' label='gؚ÷N'/>";
            //fields +=L"<field name='LowestPrice' label='gNO÷N'/>";
            
            //fields +=L"<field name='BulkPrice' label='ce'÷N'/>";
            //fields +=L"<field name='CardPrice' label='¸~aS÷N'/>";
            //fields +=L"<field name='BuyPrice' label='Ǒ-÷N'/>";
            //fields +=L"<field name='SupplierID' label=''n'/>";
            
            fields +=L"<field name='Packing' label='Sň¹e_'/>";
            fields +=L"<field name='PackingRate' label='Ïk±{peϑ'/>";
            fields +=L"<field name='VolumeDesc1' label='Sň:\x'/>";
            fields +=L"<field name='GWPerPkg' label='Ûk͑'/>";
            fields +=L"<field name='NWPerPkg' label='ÀQ͑'/>";
            //fields +=L"<field name='DeveloperID' label='_ÑSºNXT'/>";
            fields +=L"<field name='AttributeValue_1' label='§NÁT^\'`'/>";
            //fields +=L"<field name='Remark' label='Yèl'/>";
            
            fields += L"</data>";
            x.loadXML(fields);
            
            return x;
        }
 
        xstring makeHtml(int row)
        {
            xstring id = dw_list.GetGuid(row);
            
            xml x = GetGoodsPropList(id);
            xml x1 = GetGoodsPropListEx(id);
            
            xstring html = L"<html><style> .text{ font-weight:400} .label { font-weight:400;}</style><body style='margin:2;background-color:#ccdccc none #f0f0f0 none'>";
            html += L"<div ><span style='font-weight:700;width:50;font-size:10pt'  >÷S:</span><span  style='width:90;font-size:10pt'>" + dw_list.GetItemString(row, L"SKUNo") +
                L"</span> <span style='font-weight:700;width:50;font-size:10pt' >{|y˜:</span><span  style='width:90;font-size:10pt'>" + dw_list.GetItemString(row, L"RefNo") +
                L"</span></div>";
            html += L"<div ><span style='font-weight:700;width:50;font-size:10pt'  >lQøS‹W÷S:</span><span  style='width:90;font-size:10pt'>" + dw_list.GetItemString(row, L"GoodsNo") +
                L"</span></div>";
            html += L"<div ><span style='font-weight:700;width:50;font-size:10pt'  >ÁT T:</span><span  style='width:90;font-size:10pt'>" + dw_list.GetItemString(row, L"CName") +
                L"</span></div>";
            if (dw_list.GetItemString(row, L"CSpec") != L"")
                html += L"<div ><span style='font-weight:700;width:50;font-size:10pt'  >ĉ<h:</span><span  style='width:90;font-size:10pt'>" + dw_list.GetItemString(row, L"CSpec") +
                L"</span></div>";
            
            KXMLDOMNodeList fieldsEx = x1.selectNodes(L"data/field");
            xstring ls_detail=L"";
            xstring ls_item =L"";
            xstring name;
            xstring label;
            int len = fieldsEx.length();
            int i= 0;
            
            for(i=0;i<len; true)
            {
                int cnt  = 0;
                ls_item = L"";
                while(cnt < 2)
                {
                    name = fieldsEx.item(i).selectSingleNode(L"@name").text();
                    label  = fieldsEx.item(i).selectSingleNode(L"@label").text();
                    ls_item += L"<td>" + label + L"</td>" + L"<td style='text-align:center'>" + dw_list.GetItemString(row,name.c_str()) + L"</td>" ;
                    cnt++;
                    i++;
                    if(i ==len)break;
                }
                ls_detail += L"<tr>" + ls_item + L"</tr>";
            }
            html += (xstring) L"<div style='margin-left:8px;margin-right:16px;'>" +
                        +L"<table><colgroup span='1' width='70'/><colgroup span='1' width='120'/><colgroup span='1' width='70'/><colgroup span='1' width='120'/>" 
                        + ls_detail
                        +L"</table>"
                        +L"</div>" ;
                        
            xstring ls_star=L"";
            KXMLDOMNodeList fields  = x.selectNodes(L"data/field");
            len = fields.length();
            
            ls_detail = L"";
            if(len > 0) 
                html +=  L"<div ><span style='font-weight:700;width:50;font-size:10pt'  >€b/g‰Bl:</span></div>" ;
            for(i=0;i<len; true)
            {
                ls_item=L"";
                
                int count = 0;
                while(count < 2)
                {
                    name = fields.item(i).selectSingleNode(L"@name").text();
                    label  = fields.item(i).selectSingleNode(L"@label").text();
                    if(name==L"QualityTerm" || name==L"PackTerm" || label==L"(Ï‘" || label==L"Sň(Ï‘" || label==L"€b/g‰Bl")
                    {
                        i++;
                        if(i >= len)count = 2;
                        continue;
                    }
                    else if(dw_list.GetItemString(row,name.c_str())==L"")
                    {
                        KXMLDOMNodeList options = fields.item(i).selectNodes(L"item");
                        int tlen = options.length();
                        xstring terms = L"" ;
                        for(int k=0; k<tlen; k++)
                        {
                            if(options.item(k).text())
                            {
                                if(k>0) terms += L", L";
                                terms += L"[" + (xstring)options.item(k).text() +L"]";
                            }
                        }
                        ls_star += L"<div ><span style='font-weight:700;width:50;font-size:10pt'  >" + label +L"*:</span><span  style='width:90;font-size:10pt'>" + terms + L"</span></div>" ;
                    }else
                    {
                        ls_item = L"<td>" + label + L"</td>" + L"<td>" + dw_list.GetItemString(row,name.c_str()) + L"</td>" ;
                        count++;
                    }
                    i++;
                    if(i >= len)count = 2;
                }
                ls_item = L"<tr>" + ls_item + L"</tr>";
                ls_detail += ls_item;
            }
            
            html += (xstring) L"<div style='margin-left:8px;margin-right:16px;'>" +
                        +L"<table><colgroup span='1' width='70'/><colgroup span='1' width='120'/><colgroup span='1' width='70'/><colgroup span='1' width='120'/>" 
                        + ls_detail
                        +L"</table>"
                        +L"</div>" ;
            if(dw_list.GetItemString(row,L"QualityTerm")!=L"")
            {
                html +=  L"<div style='height:12px'/>";
                html +=  L"<div ><span style='font-weight:700;width:50;font-size:10pt'  >(Ï‘:</span></div>" ;
                html +=  L"<div ><span style='margin-left:8px;margin-right:16px;font-weight:400;font-size:10pt'  >" + dw_list.GetItemString(row,L"QualityTerm") +  L"</span></div>" ;
            }
            
            if(dw_list.GetItemString(row,L"PackTerm")!=L"")
            {
                html +=  L"<div style='height:12px'/>";
                html +=  L"<div ><span style='font-weight:700;width:50;font-size:10pt'  >Sň(Ï‘:</span></div>" ;
                html +=  L"<div ><span style='margin-left:8px;margin-right:16px;font-weight:400;font-size:10pt' >" + dw_list.GetItemString(row,L"PackTerm") +  L"</span></div>" ;
            }
            
            if(dw_list.GetItemString(row,L"Remark")!=L"")
            {
                //html +=  L"<div style='height:12px'/>";
                html +=  L"<div ><span style='font-weight:700;width:50;font-size:10pt'  >Yèl:</span></div>" ;
                html +=  L"<div ><span style='margin-left:8px;margin-right:16px;font-weight:400;font-size:10pt' >" + dw_list.GetItemString(row,L"Remark") +  L"</span></div>" ;
            }
 
            html +=  L"<div style='height:24px'/>";
            
            //fhy˜
            html += ls_star;
 
            //>f:yþVGr    
            /*
            if (id != L"")
            {
                xml xp;
                
                xaserverarg arg_pic;
                    
                arg_pic.AddArg(L"SKUID",id);
                if(xurl::get(L"/sale/data/ProductLibrary3/pref/picture/imagelistSKU",arg_pic.GetString(),xp)!=1)
                {
                    trace(L"xxx",xp.xml());
                }else {
                    html +=  L"<div ><span style='font-weight:700;width:50;font-size:10pt'  >þVGr:</span>"    ;
                    KXMLDOMElement ep=  xp.selectSingleNode(L"ImageList");
                    if (ep)
                    {
                        if (ep.selectNodes(L"image")){
                            KXMLDOMNodeList  nlistp = ep.selectNodes(L"image");
                            int ip=0;
                            int lenp = nlistp.length();
                            for(ip=0;ip<lenp;ip++)
                            {
                                KXMLDOMElement xitemp = nlistp.item(ip);
                                xstring filename = xitemp.selectSingleNode(L"PicPath").text(); 
                                //trace(filename);
                                html +=  L"<control visible='layer' controlclass='ximage'  data='' src='http://192.168.7.241:7001" +  filename +L"'/>";
                            }
                        }
                    }
                    html +=  L"</div>";
                }
            }else {
                xstring picname = L"1FA9E331-F95C-4E51-B80C-73FB9B911D8D.jpg";//dw_list.GetItemString(row,L"ImgName"); //ItemID+L".jpg";
                xstring str = picname.mid(0,2);
                str = str.toUpper();
                xstring serversrc =L"http://192.168.7.241:1001/business/products/chanpin/"+str+L"/"+picname;
                html +=  L"<div ><span style='font-weight:700;width:50;font-size:10pt'  >þVGr:</span>";
                html +=  L"<control visible='layer' controlclass='ximage'  data='' src='"+ serversrc +L"'/></div>";
            }
            */
            html += L"</body></html>";
            //trace(html);
            return html;
        }
 
        int OnShowImage(xstring skuid)
        {
            ximageview im = GetControl(L"im1");
            //im.RemoveImage();
            im.Reset();
            
            xml xp;
            
            xaserverarg arg_pic;
                
            arg_pic.AddArg(L"SKUID",skuid);
            //alert(skuid);
            if(xurl::get(L"/sale/data/ProductLibrary3/pref/picture/imagelistSKU",arg_pic.GetString(),xp)!=1)
            {
                trace(xstring(L"xxx",xp.xml()));
            }else
            {
                //trace(skuid+L" "+xp.xml());
                imageElement = xp.documentElement();
                KXMLDOMNodeList  nlistp=  xp.selectNodes(L"ImageList/image");
                int lenp = nlistp.length();
                for(int ip=0;ip<lenp;ip++)
                {
                    KXMLDOMElement xitem = nlistp.item(ip);
                    xstring picname = xitem.selectSingleNode(L"PicPath").text(); 
                    xstring goodno = xitem.selectSingleNode(L"GoodsNo").text();     
                    if(picname == L"/business/products/Thumbs//")
                        picname = L"/business/products/Thumbs/00/00000000-0000-0000-0000-000000000000.jpg";
                    im.AddImages(picname, L"");
                }
                im.Redraw();
                //SendMessage(im.GetId(),0x000f,0,1);
                //InvalidateRect(im.GetId(),cast(0 as ref xrect),true);
            }
            return 1;
        }
                    
        int OnRowChanged(TEvent* evt, int p)
        {
            DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
            int row = hdr.row;
                
            xshtml xs = GetControl(L"html_detail");
            xstring html = makeHtml(row);
            xs.SetContent(html);
            xs.Redraw();
            
            xstring id = dw_list.GetItemString(row, L"SKUID");
            //alert(xstring(row));
            OnShowImage(id);
                    
            return 1;
        }
        
        int OnImgDBClicked(TEvent* evt, int p)
        {
            IMGNNMHDR& nmtv = *(IMGNNMHDR*)evt->notify.pnmh;
            xstring src = nmtv.path;    
            /*if(src.length()() > 60)
                src = src.right(44);
            else
                src=src.mid(src.find(L"Thumbs", 0)+6, 50);
            */
            xaserverarg arg ;
            
            //arg.AddArg(L"src",L"/business/products/chanpin"+src);    
            arg.AddArg(L"src",src);    
            
            //win::OpenWindow(L"dev:xpage[BigPicture.vx]",arg);    
            
            //int h = (L"/sale/view/ProductLibrary/xpage/bigpictureview", arg);    
            OpenWindow(L"dev:xpage[BigPictureView.Product3.vx]",arg);
            
            /*
            xwin x = new xwin;
            x.setNativePointer(h);
            m_winHwnd = x.GetHWND();
            
            xstring sh = doc.xml();
            int p = cast(sh as int);
            SendMessage(m_winHwnd, 0x401, p, 0);
            */
            return 1;
        }    
        
        int OnSave()
        {
            
            xstring error = L"";
            dw_list.AcceptText();
            if(dw_list.GetRowCount() < 1) return 0;
            xml x ;
            
            dw_list.DwUpdateAllToEx(x);
            xaserverarg arg ;
                
            
            
            xml x0 ;
            
            x0.loadXML(L"<data/>");
            KXMLDOMNodeList t = x.selectNodes(L"data/Item[(@update.new='1') or (@update.modify='1') or (@update.delete='1') ]");
            KXMLDOMElement e1= x0.documentElement();
            
            
            for(int i=0; i < t.length(); i++)
            {
                KXMLDOMElement e= t.item(i);
                e1.appendChild(e);
            }
        
            arg.AddArg(L"content",x0.xml());
                
            //trace(x.xml());
            if(xurl::get(L"/sale/data/ProductLibrary3/update/productex", arg.GetString(),x0)!=1)
            {
                error = x0.text();
                alert(error);
                return 1;
            }else
            {
                alert(L"ÝOX[bŸR");
                arg.AddArg(L"No",  dw_list.GetItemString(dw_list.GetRow(),L"SKUNo"));
                if(xurl::get(L"/sale/data/business/message/productApplyedMessage", arg.GetString(),x0)!=1) 
                {
                    error = x0.text();
                    trace(error);
                    return 0;
                }
            }
            return 1;
        }
        int OnMakeNewGoodsNo()
        {
            if(dw_list.GetItemString(dw_list.GetRow(),L"GoodsNo")!=L"") return 1;
            if(dw_list.GetRowCount()<1) return 1;
            xaserverarg arg ;
                
            arg.AddArg(L"EntityID", dw_list.GetGuid(dw_list.GetRow()));
            KXMLDOMElement e = dw_list.GetRowElement(dw_list.GetRow());
            arg.SetParam(L"data",e);
            arg.SetParam(L"dw",dw_list);
            arg.SetParam(L"HWND",GetHWND());
            OpenWindow(L"dev:xpage[ProductNewItem.vx]",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='" + 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/Item", 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());
        
            xsl.loadXML(xslStr);
 
            xstring htmlStr = m_dataset.transformNode(xsl);
            //alert(htmlStr);
            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"(u7b§NÁT'÷Snx¤‹ß~¡‹";
            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"(u7b§NÁT'÷Snx¤‹ß~¡‹";
            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)
        {
            if(comdid==L"xmCancel")
            {
                CloseWindow();
                return 1;
            }
            if(comdid==L"xmMakeGoodsNo")
            {
                return OnMakeNewGoodsNo();
            }
            if(comdid==L"xmProductView")
            {
                OpenWindow(L"dev:xpage[Product.SearchDlg.vx]",0);
                return 1;
            }
            if(comdid==L"xmRefresh")
            {
                return OnRetrieve();
            }
            if (comdid == L"xmExcel")
            {
                OntoExcel(GetHtml(dw_list, L"/developer/Projects/mherp.com.cn/MRïzV{eu/works/›O”^þ”/UserProductApplyEx.xdoc", GetServerUrl()));
                return 1;
            }
            if(comdid==L"xmDelete")
            {
            
                /*int row = listwin::dw_list.GetNextSelectRow(1);
            
                if (row < 1){
                    row = listwin::dw_list.GetRow();
                    if (row < 1) {
                        //win::MessageBox(GetHWND(),L"÷‹    -N‰ Rd–„vLˆÿ",L"Ðc:y",0);
                        return -1;
                    }
                }*/
                int row = dw_list.GetRow();
                xstring sguid = dw_list.GetItemString(dw_list.GetRow(),L"SKUID");
            
                //KXMLDOMElement e = listwin::dw_list.GetRowElement(dw_list.GetRow());
                
                xml skuid_x = ViewObject::RetrieveData(L"/sale/data/ProductLibrary3/ProductNumberone",L"SKUID", sguid);
                xstring  skuidEx=skuid_x.text() ;
                int  skuid1=skuidEx.toInt() ;
                if(skuid1)
                {
                    if(skuid1 >0)
                        {
                        alert(L"¢‹USò]    g§NÁT ÿ NAQ¸‹ Rd–ÿ");
                        return 0;
                    }
                }
                    
                
                int  MB_YESNO1 = 0x00000004;
                int  IDYES1 =  6;    
                if(MessageBox(GetHWND(),L"nx¤‹ Rd–Tÿ",L"Ðc:y",MB_YESNO1)!=IDYES1) return 1;
                xml x ;
                
                xaserverarg arg ;
                
                arg.AddArg(L"EntityID",sguid);    
                    trace(sguid);
                if (xurl::post(L"/sale/data/ProductLibrary3/delete/Product",arg.GetString(),x) != 1)
                {
                    xstring error = x.text();
                    trace(error);
                }
                else
                {
                    KXMLDOMElement msg = x.selectNodes(L"process").item(0);
                    xstring success = msg.selectSingleNode(L"@finished").text();
                    if(success == L"0")
                    {
                        alert(msg.selectSingleNode(L"@errInfo").text());
                    }else
                    {
                        MessageBox(GetHWND(),L" Rd–bŸRÿ",L"Ðc:y",0);
                        //listwin::dw_list.DeleteRow(row);
                        dw_list.DeleteRow(row);
                    }
                }
                return 0;
            }
            
            if(comdid==L"xmSave")     return OnSave();
                    
            return 0;
        }
        
        
        int OnItemChanged(TEvent* evt, int p)
        {
            DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
            xstring colname=hdr.colname;
            xstring value = hdr.data;
            int row = hdr.row;
            
            xstring GoodsNo=L"";
            if (colname==L"GoodsNo" )
            {
                GoodsNo =dw_list.GetItemString(row,L"GoodsNo"); 
                xml x1= ViewObject::RetrieveData(L"/sale/data/ProductLibrary3/GetGoodNo",L"str",GoodsNo);
                xstring Results1=x1.text();
                if(Results1 !=L"")
                {
                    alert(Results1);
                    dw_list.SetItemString(row,L"GoodsNo",L"");
                    return 0;
                }
            }
            dw_list.Redraw();
            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)&UserProductApply::OnXCommand);
            //·ƒÖS&q¹p‹NöN ÿ(uŽN͑nå]wQag
            AttachEvent(L"WM_SETFOCUS", (FEvent)&UserProductApply::OnSetFocus);
            AttachEvent(L"dw_list",L"DWV_ROWFOCUSCHANGED", (FEvent)&UserProductApply::OnRowChanged);
            AttachEvent(L"im1",L"IMG_LDBCLICK", (FEvent)&UserProductApply::OnImgDBClicked);
            AttachEvent(L"dw_list",L"DWV_ITEMCHANGED", (FEvent)&UserProductApply::OnItemChanged);
            return 1;
        }
        
        int onload()
        {
            dw_list = GetControl(L"dw_list");
            dw_list.SetDataObject(ProductLibraryView::GetMaintListForm3(L""));
            dw_list.SetEditUpperMode(true);
 
            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);
 
 
            OnAttachEvent();    
            
            dw_list.SetColumnState(L"EntityID",false);
            return 1;
        }
        
        int onloaded()
        {
            SetAgent();    
            
            OnRetrieve();
            
            
            return 1;
        }        
    };