xj qian
2024-07-11 91f1a3b5e0319c5b77a8811217d8f218641b18fb
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
þÿ#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"
 
extern int about();
extern int openportW(wchar_t*);
extern int closeport();
extern int sendcommandW(wchar_t*);
extern int printerfontW(wchar_t*, wchar_t*, wchar_t*, wchar_t*, wchar_t*, wchar_t*, wchar_t*);
extern int windowsfontW(wchar_t*, wchar_t*, wchar_t*, wchar_t*, wchar_t*, wchar_t*, wchar_t*, wchar_t*);
extern int printlabelW(wchar_t*, wchar_t*);
extern int barcodeW(wchar_t*, wchar_t*, wchar_t*, wchar_t*, wchar_t*, wchar_t*, wchar_t*, wchar_t*, wchar_t*);
extern int clearbuffer();
extern int setup(char*, char*, char*, char*, char*, char*, char*);
 
using xml = KXMLDOMDocument;
class __declspec(dllexport) InstoreSample3Win : public xframe
{
public:
    InstoreSample3Win(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
public:
    static InstoreSample3Win* CreateInstance(void* implPtr, void* hWnd)
    {
        return  new InstoreSample3Win(implPtr, (HWND)hWnd);
    }
public:
    xdwgrid    dw_list;
    xdwtable dw_arg;
 
    xnode    m_agentNode;    //Agent Condition
    xstring    Printer;
#if 0
    static stdcall int WideCharToMultiByte(
        int CodePage,            // code page
        int dwFlags,            // performance and mapping flags
        xstring lpWideCharStr,    // wide-character xstring
        int cchWideChar,          // number of chars in xstring.
        astring lpMultiByteStr,     // buffer for new xstring
        int cbMultiByte,          // size of buffer
        astring lpDefaultChar,     // default for unmappable chars
        int lpUsedDefaultChar  // set when default char used 
    ) native from "kernel32.dll" alias "WideCharToMultiByte";
    static stdcall int MessageBoxA(int hWnd, astring title, astring caption, int button) native from "user32.dll" alias "MessageBoxA";
 
    static stdcall int Set_Darkness(int darkness)native from "WINPPLA.DLL" alias "Set_Darkness";
    static stdcall int CreatePrn(int selection, astring FileName)native from "WINPPLA.DLL" alias "CreatePrn";
    static stdcall int Print_Out(int width1, int height1, int copies, int amount)native from "WINPPLA.DLL" alias "Print_Out";
    static stdcall int Prn_Text(int x1, int y1, int ori, int font, int typee, int hor_factor, int ver_factor, char mode, int numeric, astring data)native from "WINPPLA.DLL" alias "Prn_Text";
    static stdcall int Prn_Barcode(int x1, int y1, int ori, char typee, int narrow, int width1, int height1, char mode, int numeric, astring data)native from "WINPPLA.DLL" alias "Prn_Barcode";
    static stdcall void ClosePrn() native from "WINPPLA.DLL" alias "ClosePrn";
    static stdcall void Feed_Label() native from "WINPPLA.DLL" alias "Feed_Label";
 
    static stdcall int Z_Set_Darkness(int darkness)native from "WINPPLZ.DLL" alias "Z_Set_Darkness";
    static stdcall int Z_CreatePrn(int selection, astring FileName)native from "WINPPLZ.DLL" alias "Z_CreatePrn";
    static stdcall int Z_Print_Out(int copies, int amount)native from "WINPPLZ.DLL" alias "Z_Print_Out";
    static stdcall void Z_ClosePrn() native from "WINPPLZ.DLL" alias "Z_ClosePrn";
    static stdcall int Z_Prn_Text(int x, int y, int ori, char font, int height, int width, int increase, astring data)native from "WINPPLZ.DLL" alias "Z_Prn_Text";
    static stdcall int Z_Prn_Barcode(int x, int y, int ori, int narrow, int width, int height, char typee, int increase, astring data, char p1, char p2, char     p3, char p4, char p5)native from "WINPPLZ.DLL" alias "Z_Prn_Barcode";
    static stdcall int Z_Set_Unit(char m)native from "WINPPLZ.DLL" alias "Z_Set_Unit";
    static stdcall int Z_Clear_Memory()native from "WINPPLZ.DLL" alias "Z_Clear_Memory";
 
    /************************************** TSC bSSpg:**********************************************/
    static stdcall int  openport(astring a) native from "tsclib.dll" alias "openport";
    static stdcall int  closeport() from "tsclib.dll" alias "closeport";
    static stdcall int  setup(astring a, astring b, astring c, astring d, astring e, astring f, astring g) from "tsclib.dll"  alias "setup";
    static stdcall int  clearbuffer() from "tsclib.dll" alias "clearbuffer";
    static stdcall int  barcode(astring ss1, astring ss2, astring ss3, astring ss4, astring ss5, astring ss6, astring ss7, astring ss8, astring ss9) from "tsclib.dll" alias "barcode";
    static stdcall int  printlabel(astring ss1, astring ss2) from "tsclib.dll" alias "printlabel";
    static stdcall int  windowsfont(int a, int b, int c, int d, int e, int f, astring g, astring h)from "tsclib.dll" alias "windowsfont";
    static stdcall int  printerfont(astring a, astring b, astring c, astring d, astring e, astring f, astring g) from "tsclib.dll" alias "printerfont";
    static stdcall int  sendcommand(astring command) from "TSCLIB.DLL" alias "sendcommand";
 
    astring s2a(xstring str)
    {
        astring astr;
        int len = WideCharToMultiByte(0, 0, str, -1, cast(0 as astring), 0, cast(0 as astring), 0);
        astr = new byte[len];
        WideCharToMultiByte(0, 0, str, -1, astr, len, cast(0 as astring), 0);
        return astr;
    }
#endif
 
    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, int param)
    {
        //‘Ín]åQwga
        SetAgent();
        return 1;
    }
 
    int Adjust()
    {
        xstring str;
        for (int i = 1; i <= dw_list.GetRowCount(); i++)
        {
            str = dw_list.GetItemString(i, L"DeveloperID");
            if (dw_list.GetItemString(i, L"BarCode") != L"")
                if (str == L"")
                {
                    if (i > 1)
                    {
                        if (dw_list.GetItemString(i - 1, L"DeveloperID") != L"")
                        {
                            dw_list.SetItemDisplayString(i, L"DeveloperID", dw_list.GetItemDisplayString(i - 1, L"DeveloperID"));
                            dw_list.ItemChangeTo(i, L"DeveloperID", dw_list.GetItemString(i - 1, L"DeveloperID"));
                        }
                    }
                }
        }
        return 1;
    }
 
    int OnSave()
    {
        Adjust();
 
        //if(dw_list.GetRowCount() < 1) return 1;
        if (dw_list.GetItemString(dw_list.GetRowCount(), L"BarCode") == L"") dw_list.DeleteRow(dw_list.GetRowCount());
 
        xml x;
        dw_list.DwUpdateAllToEx(x);
 
        //xsedit xc = GetControl(L"frame:vdata");
        //if(xc)xc.LoadContent(xdoc.xml,L".xml");
        //trace(xdoc.xml);
        xaserverarg arg ;
        arg.AddArg(L"content", x.xml());
        //if(
        if (xurl::get(L"/sale/data/Sample/maint/update/base", arg.GetString(), x) != 1)
        {
            xstring error = x.text();
            alert(L"err:" + error);
            return 1;
        }
        else
        {
            xstring str = x.documentElement().getAttribute(L"text");
            if (str == L"false")
            {
                alert(L"OÝ[XY1%!");
                return 1;
            }
            dw_list.ResetUpdateStatus();
            alert(L"OÝ[XbRŸÿ");
        }
        return 1;
    }
 
    //Rg
    int OnAnalysis()
    {
        HCURSOR hCursor = xutil::SetCursorWait();
        xstring str = dw_list.DataAnalysis(L"");
        xaserverarg arg ;
        arg.AddArg(L"html", str);
        arg.SetParam(L"obj",dw_list);
        OpenWindow(L"dev:xpage[data.vanalysis.vx]",arg);
        xutil::RestoreCursor(hCursor);
        return 1;
    }
 
    //T}NäSÑ^Qýep
    int OnCmdDispatch(xstring comdid)
    {
        if (comdid == L"xmAddRow")
        {
            dw_list.InsertRow(0);
            rowinitial(dw_list.GetRowCount());
            dw_list.SetRow(dw_list.GetRowCount());
            dw_list.ShowRowTo(dw_list.GetRowCount());
 
            //dw_list.SetCol(L"BarCode");
            return 1;
        }
        else if (comdid == L"xmDeleteRow")
        {
            dw_list.DeleteRow(0);
            return 1;
        }
        else if (comdid == L"xmPrint")
        {
            OnPrint();
            return 1;
        }
        else if (comdid == L"xmSave")
        {
            OnSave();
            return 1;
        }
        else if (comdid == L"xmRetrieve")
        {
            OnRetrieve();
            return 1;
        }
        else if (comdid == L"xmAnalysis")
        {
            OnAnalysis();
        }
        else if (comdid == L"xmAutoRow")
        {
            OnAutoRow();
        }
        return 0;
    }
 
    xstring GetSpendingCheck(int row)
    {
        xstring spendingStr = L"";
        xstring str;
        xstring barcode1 = dw_list.GetItemString(row, L"BarCode");
        xstring DeveloperID = dw_list.GetItemString(row, L"DeveloperID");
        for (int i = 1; i <= dw_list.GetRowCount(); i++)        
        {
            KXMLDOMElement e = dw_list.GetRowElement(i);
            str = e.getAttribute(L"update.modify");
            if (str == L"1")
            {
                if (dw_list.GetItemString(i, L"DeveloperID") != DeveloperID) continue;
                if (dw_list.GetItemString(i, L"BarCode") != barcode1) continue;
 
                spendingStr += e.xml();
            }
        }
        return spendingStr;
    }
 
    int OnClicked(TEvent* evt, int p)
    {
        DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
        char ch;
        int row = hdr.row;
        xstring col = hdr.colname;
        //xstring data = hdr.data;
 
        if (row < 1) return 1;
        if (row > dw_list.GetRowCount()) return 1;
 
        if (col == L"Offset")
        {
            xstring val = dw_list.GetItemString(row, col.c_str());
            if (val == L"Y")
            {
                if (MessageBox(GetHWND(), L"f/T&xn[šSÖmˆ[ùQ²!", L"cÐy:", 1) == 2)  return 1;
 
                dw_list.SetItemString(row, col.c_str(), L"N");
                dw_list.SetItemString(row, L"OffsetOutStoreID", L"");
            }
            else
            {
                xstring spendingStr = GetSpendingCheck(row);
                if (spendingStr != L"") spendingStr = L"<data>" + spendingStr + L"</data>";
 
                xstring DeveloperID = dw_list.GetItemString(row, L"DeveloperID");
                if (DeveloperID == L"")
                {
                    for (int i = row - 1; i >= 1; i--)
                    {
                        DeveloperID = dw_list.GetItemString(i, L"DeveloperID");
                        if (DeveloperID != L"")break;
                    }
                }
                xaserverarg arg ;
                arg.AddArg(L"BarcodeNo", dw_list.GetItemString(row, L"BarCode"));
                arg.AddArg(L"LastDate", dw_list.GetItemString(row, L"CreateDate"));
                arg.AddArg(L"DeveloperID", DeveloperID);
                arg.AddArg(L"Quantity", dw_list.GetItemString(row, L"Quantity"));
                arg.AddArg(L"SpendingStr", spendingStr);
                OpenWindow(L"dev:xpage[CheckOut.instore.Sample.vx]", arg);
                if (arg.GetArgString(L"process") == L"ok")
                {
                    dw_list.SetItemString(row, L"OffsetOutStoreID", arg.GetArgString(L"SampleOutstoreID"));
                    dw_list.SetItemString(row, col.c_str(), L"Y");
                }
            }
            dw_list.Redraw();
        }
 
        if (GetKeyState(0x11/*VK_CONTROL*/) & 0x8000)
        {
            dw_list.SetReadOnly(false);
            return 1;
        }
 
        return 1;
    }
 
    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 dwname = L"dw_list";
        if (colname == L"BarCode")
        {
            if (value.find(L"0") == 0)
            {
                value = value.mid(1, 32);
                dw_list.SetItemString(row, L"BarCode", value);
            }
        }
 
        /*
        if(colname != L"DeveloperID" && row > 1 )
        {
            xstring developer = dw_list.GetItemString(row,L"DeveloperID");
            if(developer ==L"")
            {
                developer = dw_list.GetItemString(row - 1,L"DeveloperID");
                if(developer !=L"")
                {
                    dw_list.SetItemString(row,L"DeveloperID",developer);
                    dw_list.SetItemDisplayString(row,L"DeveloperID",
                        dw_list.GetItemDisplayString(row - 1,L"DeveloperID"));
                    dw_list.ItemChangeTo(row,L"DeveloperID",developer);
                }
            }
        }
        */
 
        if (value != L"")
        {
            KXMLDOMNodeList nlist = GetElement().selectNodes(L"//*[@name='" + dwname + L"']/trans[@for='" + colname + L"']");
            if (nlist.length() > 0) ViewObject::TransData(nlist, dw_list, hdr.row, colname, value);
        }
 
        if ((colname == L"BarCode" || colname == L"GoodsNo" || colname == L"Quantity") && value != L"")
        {
            xstring goodsno = dw_list.GetItemString(row, L"GoodsNo");
            xstring qunatity = dw_list.GetItemString(row, L"Quantity");
            xstring barcode1 = dw_list.GetItemString(row, L"BarCode");
 
            int balance = qunatity.toInt() + getBalanceEx(barcode1) + getSumBalanceEx(row, barcode1);
            dw_list.SetItemString(row, L"QtyStocked", xstring(balance));
            dw_list.Redraw();
 
            if (row == dw_list.GetRowCount())
            {
                PostMessage(GetHWND(), 0x401, (WPARAM)L"xmAutoRow", 0);
            }
        }
 
        return 1;
    }
 
    int OnAutoRow()
    {
 
        dw_list.InsertRow(0);
        rowinitial(dw_list.GetRowCount());
        dw_list.SetRow(dw_list.GetRowCount());
        dw_list.ShowRowTo(dw_list.GetRowCount());
        //dw_list.SetColumn(colname);
        dw_list.ShowEditor();
        return 1;
    }
 
#if 0
    int OnPrint_ppla(int sRow, int eRow, xstring PrintNumber, int prn = 1)
    {
        int i = 0;
        if (sRow > eRow) return 1;
        if (sRow < 0)  sRow = 1;
        if (eRow > dw_list.GetRowCount()) eRow = dw_list.GetRowCount();
        int count = 0;
 
        if (PrintNumber != L"*") count = PrintNumber.toInt();
 
        astring agoodsno;
        astring abarcode;
        astring emptystr = s2a(L"");
 
        for (i = sRow; i <= eRow; i++)
        {
            int cx = count;
            if (cx == 0) cx = dw_list.GetItemInt(i, L"Quantity");
            xstring goodsno = dw_list.GetItemString(i, L"GoodsNo");
            xstring barcode1 = dw_list.GetItemString(i, L"BarCode");
            agoodsno = s2a(goodsno);
            abarcode = s2a(barcode1);
 
            //debugbreak();
            CreatePrn(prn, emptystr);
            Set_Darkness(12);
            Prn_Barcode(13, 20, 1, 'd', 0, 0, 30, 'n', 1, abarcode);
            Prn_Text(13, 50, 1, 9, 2, 1, 1, 'n', 2, agoodsno);
            //Prn_Text(90, 50, 1, 9, 1, 1, 1, 'n', 2, as_qty)
            Prn_Text(30, 7, 1, 9, 2, 1, 1, 'n', 2, abarcode);
            //Prn_Text(150, 45, 1, 9, 0, 1, 1, 'n', 2,emptystr);
            Print_Out(1, 1, cx, 1);
 
            Feed_Label();
            ClosePrn();
 
            delete agoodsno;
            delete abarcode;
        }
        return 1;
    }
 
    int OnPrint_pplz(int sRow, int eRow, xstring PrintNumber, int prn = 1)
    {
        if (sRow > eRow) return 1;
        if (sRow < 0)  sRow = 1;
        if (eRow > dw_list.GetRowCount()) eRow = dw_list.GetRowCount();
        int count = 0;
        if (PrintNumber != L"*") count = PrintNumber.toInt();
 
        astring agoodsno;
        astring abarcode;
        astring emptystr = s2a(L"");
 
        int li_rate = 8;
 
        for (int i = sRow; i <= eRow; i++)
        {
            int cx = count;
            if (cx == 0) cx = dw_list.GetItemInt(i, L"Quantity");
            xstring goodsno = dw_list.GetItemString(i, L"GoodsNo");
            xstring barcode1 = dw_list.GetItemString(i, L"BarCode");
            agoodsno = s2a(goodsno);
            abarcode = s2a(barcode1);
 
            Z_CreatePrn(prn, emptystr);
            Z_Set_Darkness(12);
 
            Z_Set_Unit('M'); //kë|s 
            Z_Prn_Barcode(3, 4, 1, 2, 2, 7, '2', 0, abarcode, 'n', 'n', 'n', 'y', 'y');
            Z_Set_Unit('D'); //PÏ}  
            Z_Prn_Text(3 * li_rate, 1 * li_rate, 1, 'D', 18, 12, 0, agoodsno);
 
            //Z_Prn_Text(22*li_rate, 1*li_rate, 1,  'D',18,12,0, as_qty)
            Z_Prn_Text(8 * li_rate, 12 * li_rate, 1, 'D', 18, 12, 0, abarcode);
            Z_Print_Out(1, cx);
            Z_Clear_Memory();
 
            Z_ClosePrn();
        }
        return 1;
    }
 
    int OnPrint_4502(int sRow, int eRow, xstring PrintNumber)
    {
        if (sRow > eRow) return 1;
        if (sRow < 0)  sRow = 1;
        if (eRow > dw_list.GetRowCount()) eRow = dw_list.GetRowCount();
        int count = 0;
        if (PrintNumber != L"*") count = PrintNumber.toInt();
 
        //astring s38=s2a(L"38");
        //astring s17=s2a(L"17");
        astring s38 = s2a(L"40");
        astring s17 = s2a(L"20");
        astring s3 = s2a(L"3");
        astring s10 = s2a(L"10");
 
        astring s116 = s2a(L"116");
        astring s140 = s2a(L"140");
        astring s16 = s2a(L"16");
        astring s24 = s2a(L"24");
        astring s1 = s2a(L"1");
        astring s0 = s2a(L"0");
        astring s2 = s2a(L"2");
 
        astring s25 = s2a(L"25");
        astring s48 = s2a(L"48");
        astring s64 = s2a(L"64");
 
        astring s2d9 = s2a(L"2.9");
        astring s5d8 = s2a(L"5.8");
 
        astring cutter = s2a(L"SET CUTTER OFF");
        astring direction = s2a(L"DIRECTION 1");
        astring t4502 = s2a(L"TSC TTP-244 Pro");//s2a(L"Bar Code Printer T-4502E");
        astring agoodsno;
        astring abarcode;
 
        xstring sdate;
        astring adate;
 
        astring str = t4502;
        astring  acount;
 
        openport(str);
        for (int i = sRow; i <= eRow; i++)
        {
            int cx = count;
            if (cx == 0) cx = dw_list.GetItemInt(i, L"Quantity");
            xstring goodsno = dw_list.GetItemString(i, L"GoodsNo");
            xstring barcode1 = dw_list.GetItemString(i, L"BarCode");
            sdate = dw_list.GetItemString(i, L"InstoreDate");
            sdate = sdate.left(10);
            adate = s2a(sdate);
 
            //trace(L"\r\n---"+cx.toString());
            agoodsno = s2a(goodsno);
            abarcode = s2a(barcode1);
 
            acount = s2a(cx.toString());
            //for(int k=1;k<=cx;k++)
            //{
                //trace(L"\r\n---"+k.toString());
                //setup(s2a(L"38"),s2a(L"17"),s2a(L"3"),s2a(L"10"),s2a(L"0"),s2a(L"2"),s2a(L"0"));
                //sendcommand(s2a(L"SET CUTTER OFF"));
                //sendcommand(s2a(L"DIRECTION 1"));
                //clearbuffer();
                /*Šªf: Spˆhj_cNäR0hx¼Spˆhj_
                //SÃex: Šs}0cNäŠËSÀTSPL*/
                //printerfont(s2a(L"16")/*x*/,s2a(L"24")/*y*/,s2a(L"2")/*font*/,s2a(L"0")/*rote*/,s2a(L"1")/*ratex*/,s2a(L"1")/*ratey*/,s2a(goodsno));
                ////printerfont(s2a(L"178")/*x*/,s2a(L"24")/*y*/,s2a(L"2")/*font*/,s2a(L"0")/*rote*/,s2a(L"1")/*ratex*/,s2a(L"1")/*ratey*/,s2a(L"1"));
                //barcode(s2a(L"16")/*x*/,s2a(L"48")/*y*/,s2a(L"25")/*code*/,s2a(L"64")/*height*/,s2a(L"0")/*text*/,s2a(L"0")/*rote*/,s2a(L"2.9")/*barn*/,s2a(L"5.8")/*barw*/,s2a(barcode1));
                //printerfont(s2a(L"64")/*x*/,s2a(L"116")/*y*/,s2a(L"2")/*font*/,s2a(L"0")/*rote*/,s2a(L"1")/*ratex*/,s2a(L"1")/*ratey*/,s2a(barcode1));
                //printlabel(s2a(L"1"),s2a(L"1"));
 
            setup(s38, s17, s3, s10, s0, s2, s0);
            sendcommand(cutter);
            sendcommand(direction);
            clearbuffer();
            /*Šªf: Spˆhj_cNäR0hx¼Spˆhj_
            SÃex: Šs}0cNäŠËSÀTSPL*/
 
            printerfont(s16/*x*/, s24/*y*/, s2/*font*/, s0/*rote*/, s1/*ratex*/, s1/*ratey*/, agoodsno);
            //printerfont(s2a(L"178")/*x*/,s2a(L"24")/*y*/,s2a(L"2")/*font*/,s2a(L"0")/*rote*/,s2a(L"1")/*ratex*/,s2a(L"1")/*ratey*/,s2a(L"1"));
            barcode(s16/*x*/, s48/*y*/, s25/*code*/, s64/*height*/, s0/*text*/, s0/*rote*/, s2d9/*barn*/, s5d8/*barw*/, abarcode);
            printerfont(s64/*x*/, s116/*y*/, s2/*font*/, s0/*rote*/, s1/*ratex*/, s1/*ratey*/, abarcode);
            printerfont(s64/*x*/, s140/*y*/, s2/*font*/, s0/*rote*/, s1/*ratex*/, s1/*ratey*/, adate);
            printlabel(acount, s1);
            clearbuffer();
 
            /*Šªf: Spˆhj_cNäR0hx¼Spˆhj_
            SÃex: Šs}0cNäŠËSÀTSPL*/
            //}
            delete agoodsno;
            delete abarcode;
        }
        closeport();
 
        return 1;
    }
 
    int OnPrint(xstring Printer, int sRow, int eRow, xstring PrintNumber)
    {
        int prn = 1;
        if (Printer.find(L"T-4502E") >= 0)
            return OnPrint_4502(sRow, eRow, PrintNumber);
        else if (Printer.find(L"TSC") >= 0)
            return OnPrint_4502(sRow, eRow, PrintNumber);
        else if (Printer.find(L"PPLA") >= 0)
        {
            if (Printer.find(L"PRN3") >= 0) prn = 3;
            if (Printer.find(L"PRN2") >= 0) prn = 2;
            return OnPrint_ppla(sRow, eRow, PrintNumber, prn);
        }
        else if (Printer.find(L"PPLZ") >= 0)
        {
            if (Printer.find(L"PRN3") >= 0) prn = 3;
            if (Printer.find(L"PRN2") >= 0) prn = 2;
            return OnPrint_pplz(sRow, eRow, PrintNumber, prn);
        }
        return 1;
    }
#endif
 
 
    int OnPrint_4502(int sRow, int eRow, xstring PrintNumber)
    {
        if (sRow > eRow) return 1;
        if (sRow < 0)  sRow = 1;
        if (eRow > dw_list.GetRowCount()) eRow = dw_list.GetRowCount();
        int count = 0;
        if (PrintNumber != L"*") count = PrintNumber.toInt();
 
        wchar_t* cutter = (wchar_t*)L"SET CUTTER OFF";
        wchar_t* direction = (wchar_t*)L"DIRECTION 1";
        wchar_t* t4502 = (wchar*)L"TSC TTP-244 Pro";//(wchar_t*)L"Bar Code Printer T-4502E";
        wchar_t* str = t4502;
 
        openportW(str);
        for (int i = sRow; i <= eRow; i++)
        {
            int cx = count;
            if (cx == 0) cx = dw_list.GetItemInt(i, L"Quantity");
            xstring goodsno = dw_list.GetItemString(i, L"GoodsNo");
            xstring barcode = dw_list.GetItemString(i, L"BarCode");
            xstring sdate = dw_list.GetItemString(i, L"InstoreDate");
            sdate = sdate.left(10);
            //for(int k=1;k<=cx;k++)
            //{
                //trace(L"\r\n---"+k.toString());
                //setup(s2a(L"38"),s2a(L"17"),s2a(L"3"),s2a(L"10"),s2a(L"0"),s2a(L"2"),s2a(L"0"));
                //sendcommand(s2a(L"SET CUTTER OFF"));
                //sendcommand(s2a(L"DIRECTION 1"));
                //clearbuffer();
                /*Šªf: Spˆhj_cNäR0hx¼Spˆhj_
                //SÃex: Šs}0cNäŠËSÀTSPL*/
                //printerfont(s2a(L"16")/*x*/,s2a(L"24")/*y*/,s2a(L"2")/*font*/,s2a(L"0")/*rote*/,s2a(L"1")/*ratex*/,s2a(L"1")/*ratey*/,s2a(goodsno));
                ////printerfont(s2a(L"178")/*x*/,s2a(L"24")/*y*/,s2a(L"2")/*font*/,s2a(L"0")/*rote*/,s2a(L"1")/*ratex*/,s2a(L"1")/*ratey*/,s2a(L"1"));
                //barcode(s2a(L"16")/*x*/,s2a(L"48")/*y*/,s2a(L"25")/*code*/,s2a(L"64")/*height*/,s2a(L"0")/*text*/,s2a(L"0")/*rote*/,s2a(L"2.9")/*barn*/,s2a(L"5.8")/*barw*/,s2a(barcode1));
                //printerfont(s2a(L"64")/*x*/,s2a(L"116")/*y*/,s2a(L"2")/*font*/,s2a(L"0")/*rote*/,s2a(L"1")/*ratex*/,s2a(L"1")/*ratey*/,s2a(barcode1));
                //printlabel(s2a(L"1"),s2a(L"1"));
 
            setup((char*)"40", (char*)"20", (char*)"3", (char*)"10", (char*)"0", (char*)"2", (char*)"0");
            sendcommandW(cutter);
            sendcommandW(direction);
            clearbuffer();
            /*Šªf: Spˆhj_cNäR0hx¼Spˆhj_
            SÃex: Šs}0cNäŠËSÀTSPL*/
 
            printerfontW((wchar_t*)L"16"/*x*/, (wchar_t*)L"24"/*y*/, (wchar_t*)L"2"/*font*/, (wchar_t*)L"0"/*rote*/, (wchar_t*)L"1"/*ratex*/, (wchar_t*)L"1"/*ratey*/, (wchar_t*)goodsno.c_str());
            //printerfont(s2a(L"178")/*x*/,s2a(L"24")/*y*/,s2a(L"2")/*font*/,s2a(L"0")/*rote*/,s2a(L"1")/*ratex*/,s2a(L"1")/*ratey*/,s2a(L"1"));
            barcodeW((wchar_t*)L"16"/*x*/, (wchar_t*)L"48"/*y*/, (wchar_t*)L"25"/*code*/, (wchar_t*)L"64"/*height*/, (wchar_t*)L"0"/*text*/, (wchar_t*)L"0"/*rote*/, (wchar_t*)L"2.9"/*barn*/, (wchar_t*)L"5.8"/*barw*/, (wchar_t*)barcode.c_str());
            printerfontW((wchar_t*)L"64"/*x*/, (wchar_t*)L"116"/*y*/, (wchar_t*)L"2"/*font*/, (wchar_t*)L"0"/*rote*/, (wchar_t*)L"1"/*ratex*/, (wchar_t*)L"1"/*ratey*/, (wchar_t*)barcode.c_str());
            printerfontW((wchar_t*)L"64"/*x*/, (wchar_t*)L"140"/*y*/, (wchar_t*)L"2"/*font*/, (wchar_t*)L"0"/*rote*/, (wchar_t*)L"1"/*ratex*/, (wchar_t*)L"1"/*ratey*/, (wchar_t*)sdate.c_str());
            printlabelW((wchar_t*)xstring(cx).c_str(), (wchar_t*)L"1");
            clearbuffer();
 
            /*Šªf: Spˆhj_cNäR0hx¼Spˆhj_
            SÃex: Šs}0cNäŠËSÀTSPL*/
            //}
        }
        closeport();
 
        return 1;
    }
 
    int OnPrint(xstring Printer, int sRow, int eRow, xstring PrintNumber)
    {
        int prn = 1;
        OnPrint_4502(sRow, eRow, PrintNumber);
        /*if (Printer.find(L"T-4502E") >= 0)
            return OnPrint_4502(sRow, eRow, PrintNumber);
        else if (Printer.find(L"TSC") >= 0)
            return OnPrint_4502(sRow, eRow, PrintNumber);
        */
        return 1;
    }
 
    int OnPrint()
    {
        xaserverarg arg;
        arg.AddArg(L"Printer", Printer);
        arg.AddArg(L"PrintNumber", L"*");
        arg.AddArg(L"PrintRowFrom", xstring(dw_list.GetRow()));
        arg.AddArg(L"PrintRowLast", xstring(dw_list.GetRow()));
        OpenWindow(L"dev:xpage[SampleBarcodePrint.vx]",arg);
 
        if (arg.GetArgString(L"process") == L"ok")
        {
            Printer = arg.GetArgString(L"Printer");
            xstring PrintNumber = arg.GetArgString(L"PrintNumber");
            xstring rowFrom = arg.GetArgString(L"PrintRowFrom");
            xstring rowLast = arg.GetArgString(L"PrintRowLast");
            OnPrint(Printer, rowFrom.toInt(), rowLast.toInt(), PrintNumber);
        }
        return 1;
    }
 
    int OnCombboChange(TEvent* evt, LPARAM lParam)
    {
        int h = xcombobox::GetCurSel(GetControl(L"datetype")->GetHWND());
        if (h < 0) return 0;
 
        xcombobox::GetLBText(GetControl(L"datetype")->GetHWND(), h);
 
        return 1;
    }
 
    //T}NäYtN‹Nö
    int OnXCommand(TEvent* evt, int param)
    {
        return OnCmdDispatch(evt->xcommand.pStrID);
    }
 
    int OnRowChanged(TEvent* evt, int p)
    {
        DWNMHDR&  hdr = *(DWNMHDR*)evt->notify.pnmh;
        int row = hdr.row;
 
        if (row < 1) return 1;
        if (row > dw_list.GetRowCount()) return 1;
 
        KXMLDOMElement e = dw_list.GetRowElement(row);
        xstring str = e.getAttribute(L"update.new");
        if (str == L"1")
            dw_list.SetReadOnly(false);
        else
        {
            if (GetKeyState(0x11/*VK_CONTROL*/) & 0x8000)
            {
                dw_list.SetReadOnly(false);
                return 1;
            }
            dw_list.SetReadOnly(true);
            dw_list.AcceptText();
        }
        return 1;
    }
 
    int OnAttachEvent()
    {
        //~Ñ[š]åQwgap¹QûN‹Nö
        AttachEvent(L"WM_XCOMMAND", (FEvent)&InstoreSample3Win::OnXCommand);
        //ƒ·SÖq&p¹N‹Nöÿ u(NŽ‘Ín]åQwga
        AttachEvent(L"WM_SETFOCUS", (FEvent)&InstoreSample3Win::OnSetFocus);
        AttachEvent(L"dw_list", L"DWV_ITEMCHANGED", (FEvent)&InstoreSample3Win::OnItemChanged);
        AttachEvent(L"dw_list", L"DWV_ROWFOCUSCHANGED", (FEvent)&InstoreSample3Win::OnRowChanged);
        //
        AttachEvent(L"datetype", L"CBN_SELCHANGE", (FEvent)&InstoreSample3Win::OnCombboChange);  //TO list
        AttachEvent(L"dw_list", L"DWV_CLICKED", (FEvent)&InstoreSample3Win::OnClicked);
 
        return 1;
    }
 
    int  OnRetrieve()
    {
        xml x ;
        xaserverarg arg ;
        arg.AddArg(L"pageindex", L"1");
        arg.AddArg(L"pagenumber", L"");
 
        xstring queryText = L"";
        if (xcontrol(GetControl(L"goodsno")).GetText() != L"")
        {
            xstring value = xcontrol(GetControl(L"goodsno")).GetText();
            value = value.replace(L"'", L"''");
            queryText += L"<item name='GoodsNo' op='like' value='" + value + L"%'/>";
        }
        xstring datetype = xcontrol(GetControl(L"datetype")).GetText();
 
        //xstring sdate1 = GetControl(L"sdate").GetText();
        //xstring edate1 = GetControl(L"edate").GetText();
 
        xstring sdate = dw_arg.GetItemString(1, L"startDate");
        xstring edate = dw_arg.GetItemString(1, L"endDate");
 
        if (datetype == L"^tNý")
        {
            if (sdate != L"")
                queryText += L"<item name='datepart(year,InstoreDate)' op='=' value='" + sdate.left(4) + L"'/>";
        }
        else if (datetype == L"gNý")
        {
            if (sdate != L"")
                queryText += L"<item name='datediff(month,InstoreDate,&apos;" + sdate.left(4) + L"/" + sdate.mid(5, 2) + L"/01&apos;)' op='=' value='0'/>";
        }
        else if (datetype == L"eåg")
        {
            if (sdate != L"")
                queryText += L"<item name='datediff(day,InstoreDate,&apos;" + sdate.left(10) + L"&apos;)' op='=' value='0'/>";
        }
        else if (datetype == L"^tNýƒVô")
        {
            if (sdate != L"")
                queryText += L"<item name='datepart(year,InstoreDate)' op='&gt;=' value='" + sdate.left(4) + L"'/>";
            if (edate != L"")
                queryText += L"<item name='datepart(year,InstoreDate)' op='&lt;=' value='" + edate.left(4) + L"'/>";
        }
        else if (datetype == L"gNýƒVô")
        {
            if (sdate != L"")
                queryText += L"<item name='datediff(month,InstoreDate,&apos;" + sdate.left(4) + L"/" + sdate.mid(6, 2) + L"/01&apos;)' op='&lt;=' value='0'/>";
            if (edate != L"")
                queryText += L"<item name='datediff(month,InstoreDate,&apos;" + edate.left(4) + L"/" + edate.mid(6, 2) + L"/01&apos;)' op='&gt;=' value='0'/>";
        }
        else if (datetype == L"eågƒVô")
        {
            if (sdate != L"")
                queryText += L"<item name='datediff(day,InstoreDate,&apos;" + sdate.left(10) + L"&apos;)' op='&lt;=' value='0'/>";
            if (edate != L"")
                queryText += L"<item name='datediff(day,InstoreDate,&apos;" + edate.left(10) + L"&apos;)' op='&gt;=' value='0'/>";
        }
 
        arg.AddArg(L"QueryTxt", L"<items join='and'>" + queryText + L"</items>");
 
        trace(L"<items join='and'>" + queryText + L"</items>");
        //trace(arg.GetArgString(L"QueryTxt"));
        if (getUrl(L"/sale/data/Sample/entity/list", arg.GetString(), x) != 1)
        {
            trace(x.text());
            return -1;
        }
        else
        {
            dw_list.Retrieve(x);
            dw_list.Redraw();
        }
        return 1;
    }
 
    int onload()
    {
        dw_list = GetControl(L"dw_list");
        dw_list.openUrl(L"/sale/view/Sample/template/Sample/list");
 
        dw_arg = GetControl(L"dw_arg");
        dw_arg.openUrl(L"/sale/view/Sample/template/Sample/storeArg");
        dw_arg.SetColHeaderHeight(0);
        dw_arg.SetRowSelectorWidth(0);
        dw_arg.SetHScrollState(false);
        dw_arg.SetVScrollState(false);
 
        dw_list.SetColumnState(L"CreateDate", false);
 
        xstring sdate = publiccode::GetCurrentDate();
        xcontrol(GetControl(L"sdate")).SetText(sdate.left(10));
        dw_arg.SetItemString(1, L"startDate", sdate.left(10));
 
        Printer = L"";
        OnAttachEvent();
 
 
        return 1;
    }
 
    int getBalanceEx(xstring barcode1)
    {
        int ttl = 0;
        xml x = ViewObject::RetrieveData(L"/sale/data/Sample/entity/balance/barcode", L"barcode", barcode1);
        if (x)
        {
            xstring val;
            val = x.documentElement().getAttribute(L"value");
            ttl = val.toInt();
        }
        return ttl;
    }
 
    int getBalance(xstring goodsno)
    {
        int ttl = 0;
        xml x = ViewObject::RetrieveData(L"/sale/data/Sample/entity/balance", L"GoodsNo", goodsno);
        if (x)
        {
            xstring val;
            val = x.documentElement().getAttribute(L"value");
            ttl = val.toInt();
        }
        return ttl;
    }
 
    int getSumBalance(int row, xstring goodsno)
    {
        int ttl = 0;
        for (int crow = 1; crow < row; crow++)
        {
            KXMLDOMElement ele = dw_list.GetRowElement(crow);
            xstring str = ele.getAttribute(L"update.new");
            if (str == L"1")
            {
                if (dw_list.GetItemString(crow, L"GoodsNo") == goodsno)
                    ttl += dw_list.GetItemInt(crow, L"Quantity");
            }
        }
        return ttl;
    }
 
    int getSumBalanceEx(int row, xstring barcode1)
    {
        int ttl = 0;
        for (int crow = 1; crow < row; crow++)
        {
            KXMLDOMElement ele = dw_list.GetRowElement(crow);
            xstring str = ele.getAttribute(L"update.new");
            if (str == L"1")
            {
                if (dw_list.GetItemString(crow, L"BarCode") == barcode1)
                    ttl += dw_list.GetItemInt(crow, L"Quantity");
            }
        }
        return ttl;
    }
 
    int rowinitial(int row)
    {
        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);
 
        /*
        int WM_VSCROLL = 0x115;
        int pos = 100;
        int p = (pos<<16) | 5;
        win32::SendMessage(dw_list.GetId(),WM_VSCROLL ,p,0);
        */
 
        return 1;
    }
 
    int onloaded()
    {
        SetAgent();
        OnRetrieve();
        //dw_list.InsertRow(0);
        //dw_list.SetRow(dw_list.GetRowCount());
        //dw_list.ScrollToRow(dw_list.GetRowCount());
 
        return 1;
    }
};