xj qian
2024-07-11 1bb041847d2d4a6a490d991126dd8ae6d83d1179
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
þÿ#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"
 
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
    string    Printer;
 
    static stdcall int WideCharToMultiByte(
        int CodePage,            // code page
        int dwFlags,            // performance and mapping flags
        string lpWideCharStr,    // wide-character string
        int cchWideChar,          // number of chars in string.
        astring lpMultiByteStr,     // buffer for new string
        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(string 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;
    }
 
    int SetAgent()
    {
        string xfNodeAgentArea = "agentarea";
        xnode anode = GetAgentNode(xfNodeAgentArea);
        if (m_agentNode)
        {
            SetAgentNodeContent(anode, m_agentNode);
        }
        else
        {
            msxml::IXMLDOMElement xframeElement = GetElement();
            msxml::IXMLDOMElement agent = xframeElement.selectSingleNode("agent/" + xfNodeAgentArea + "[1]/*");
            if (agent)
            {
                string s = agent.xml;
                m_agentNode = SetAgentNodeContent(anode, s);
            }
        }
        return 1;
    }
 
    //q&p¹oÀm;YtQýep
    int OnSetFocus(ref TEvent evt, int param)
    {
        //‘Ín]åQwga
        SetAgent();
        return 1;
    }
 
    int Adjust()
    {
        string str;
        for (int i = 1; i <= dw_list.GetRowCount(); i++)
        {
            str = dw_list.GetItemString(i, "DeveloperID");
            if (dw_list.GetItemString(i, "BarCode") != "")
                if (str == "")
                {
                    if (i > 1)
                    {
                        if (dw_list.GetItemString(i - 1, "DeveloperID") != "")
                        {
                            dw_list.SetItemDisplayString(i, "DeveloperID", dw_list.GetItemDisplayString(i - 1, "DeveloperID"));
                            dw_list.ItemChangeTo(i, "DeveloperID", dw_list.GetItemString(i - 1, "DeveloperID"));
                        }
                    }
                }
        }
        return 1;
    }
 
    int OnSave()
    {
        Adjust();
 
        //if(dw_list.GetRowCount() < 1) return 1;
        if (dw_list.GetItemString(dw_list.GetRowCount(), "BarCode") == "") dw_list.DeleteRow(dw_list.GetRowCount());
 
        xml x = new xml;
        x.setNativePointer(x.CreateInstance());
        msxml::IXMLDOMDocument xdoc = x.GetXmlDoc();
        dw_list.DwUpdateAllToEx(xdoc);
 
        //xsedit xc = GetControl("frame:vdata");
        //if(xc)xc.LoadContent(xdoc.xml,".xml");
        //trace(xdoc.xml);
        xaserverarg arg = new xaserverarg;
        arg.setNativePointer(arg.CreateInstance());
        arg.AddArg("content", xdoc.xml);
        //if(
        if (url::get("/sale/data/Sample/maint/update/base", arg.GetString(), x) != 1)
        {
            string error = x.GetXmlDoc().text;
            alert("err:" + error);
            return 1;
        }
        else
        {
            string str = x.GetXmlDoc().documentElement.getAttribute("text");
            if (str == "false")
            {
                alert("OÝ[XY1%!");
                return 1;
            }
            dw_list.ResetUpdateStatus();
            alert("OÝ[XbRŸÿ");
        }
        return 1;
    }
 
    //Rg
    int OnAnalysis()
    {
        int hCursor = xutil::SetCursorWait();
        string str = dw_list.DataAnalysis("");
        xaserverarg arg = new xaserverarg;
        arg.setNativePointer(arg.CreateInstance());
        arg.AddArg("html", str);
        int obj = cast(dw_list as int);
        arg.AddArg("obj", obj.toString());
        OpenWindow("dev:xpage[data.vanalysis.vx]", cast(arg as int));
        xutil::RestoreCursor(hCursor);
        return 1;
    }
 
    //T}NäSÑ^Qýep
    int OnCmdDispatch(string comdid)
    {
        if (comdid == "xmAddRow")
        {
            dw_list.InsertRow(0);
            rowinitial(dw_list.GetRowCount());
            dw_list.SetRow(dw_list.GetRowCount());
            dw_list.ShowRowTo(dw_list.GetRowCount());
 
            //dw_list.SetCol("BarCode");
            return 1;
        }
        else if (comdid == "xmDeleteRow")
        {
            dw_list.DeleteRow(0);
            return 1;
        }
        else if (comdid == "xmPrint")
        {
            OnPrint();
            return 1;
        }
        else if (comdid == "xmSave")
        {
            OnSave();
            return 1;
        }
        else if (comdid == "xmRetrieve")
        {
            OnRetrieve();
            return 1;
        }
        else if (comdid == "xmAnalysis")
        {
            OnAnalysis();
        }
        else if (comdid == "xmAutoRow")
        {
            OnAutoRow();
        }
        return 0;
    }
 
    string GetSpendingCheck(int row)
    {
        string spendingStr = "";
        string str;
        string barcode1 = dw_list.GetItemString(row, "BarCode");
        string DeveloperID = dw_list.GetItemString(row, "DeveloperID");
        for (int i = 1; i <= dw_list.GetRowCount(); i++)
        {
            msxml::IXMLDOMElement e = dw_list.GetRowElement(i);
            str = e.GetAttribute("update.modify");
            if (str == "1")
            {
                if (dw_list.GetItemString(i, "DeveloperID") != DeveloperID) continue;
                if (dw_list.GetItemString(i, "BarCode") != barcode1) continue;
 
                spendingStr += e.xml;
            }
        }
        return spendingStr;
    }
 
    int OnClicked(ref TNotifyEvent evt, int p)
    {
        ref DWNMHDR hdr = cast(evt.pnmh as ref DWNMHDR);
        char ch;
        int row = hdr.row;
        string col = hdr.colname;
        //string data = hdr.data;
 
        if (row < 1) return 1;
        if (row > dw_list.GetRowCount()) return 1;
 
        if (col == "Offset")
        {
            string val = dw_list.GetItemString(row, col);
            if (val == "Y")
            {
                if (win32::MessageBox(GetHWND(), "f/T&xn[šSÖmˆ[ùQ²!", "cÐy:", 1) == 2)  return 1;
 
                dw_list.SetItemString(row, col, "N");
                dw_list.SetItemString(row, "OffsetOutStoreID", "");
            }
            else
            {
                string spendingStr = GetSpendingCheck(row);
                if (spendingStr != "") spendingStr = "<data>" + spendingStr + "</data>";
 
                string DeveloperID = dw_list.GetItemString(row, "DeveloperID");
                if (DeveloperID == "")
                {
                    for (int i = row - 1; i >= 1; i--)
                    {
                        DeveloperID = dw_list.GetItemString(i, "DeveloperID");
                        if (DeveloperID != "")break;
                    }
                }
                xaserverarg arg = new xaserverarg;
                arg.setNativePointer(arg.CreateInstance());
                arg.AddArg("BarcodeNo", dw_list.GetItemString(row, "BarCode"));
                arg.AddArg("LastDate", dw_list.GetItemString(row, "CreateDate"));
                arg.AddArg("DeveloperID", DeveloperID);
                arg.AddArg("Quantity", dw_list.GetItemString(row, "Quantity"));
                arg.AddArg("SpendingStr", spendingStr);
                OpenWindow("dev:xpage[CheckOut.instore.Sample.vx]", cast(arg as int));
                if (arg.GetArgString("process") == "ok")
                {
                    dw_list.SetItemString(row, "OffsetOutStoreID", arg.GetArgString("SampleOutstoreID"));
                    dw_list.SetItemString(row, col, "Y");
                }
            }
            dw_list.Redraw();
        }
 
        if (win32::GetKeyState(0x11/*VK_CONTROL*/) & 0x8000)
        {
            dw_list.SetReadOnly(false);
            return 1;
        }
 
        return 1;
    }
 
    int OnItemChanged(ref TNotifyEvent evt, int p)
    {
        ref DWNMHDR  hdr = trust(evt.pnmh as ref DWNMHDR);
        string colname = hdr.colname;
        string value = hdr.data;
        int row = hdr.row;
 
        string dwname = "dw_list";
        if (colname == "BarCode")
        {
            if (value.find("0") == 0)
            {
                value = value.mid(1, 32);
                dw_list.SetItemString(row, "BarCode", value);
            }
        }
 
        /*
        if(colname != "DeveloperID" && row > 1 )
        {
            string developer = dw_list.GetItemString(row,"DeveloperID");
            if(developer =="")
            {
                developer = dw_list.GetItemString(row - 1,"DeveloperID");
                if(developer !="")
                {
                    dw_list.SetItemString(row,"DeveloperID",developer);
                    dw_list.SetItemDisplayString(row,"DeveloperID",
                        dw_list.GetItemDisplayString(row - 1,"DeveloperID"));
                    dw_list.ItemChangeTo(row,"DeveloperID",developer);
                }
            }
        }
        */
 
        if (value != "")
        {
            msxml::IXMLDOMNodeList nlist = GetElement().selectNodes("//*[@name='" + dwname + "']/trans[@for='" + colname + "']");
            if (nlist.length > 0) ViewObject::TransData(nlist, dw_list, hdr.row, colname, value);
        }
 
        if ((colname == "BarCode" || colname == "GoodsNo" || colname == "Quantity") && value != "")
        {
            string goodsno = dw_list.GetItemString(row, "GoodsNo");
            string qunatity = dw_list.GetItemString(row, "Quantity");
            string barcode1 = dw_list.GetItemString(row, "BarCode");
 
            int balance = qunatity.toInt() + getBalanceEx(barcode1) + getSumBalanceEx(row, barcode1);
            dw_list.SetItemString(row, "QtyStocked", balance.toString());
            dw_list.Redraw();
 
            if (row == dw_list.GetRowCount())
            {
                win32::PostMessage(GetHWND(), 0x401, "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();
 
    }
 
    int OnPrint_ppla(int sRow, int eRow, string 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 != "*") count = PrintNumber.toInt();
 
        astring agoodsno;
        astring abarcode;
        astring emptystr = s2a("");
 
        for (i = sRow; i <= eRow; i++)
        {
            int cx = count;
            if (cx == 0) cx = dw_list.GetItemInt(i, "Quantity");
            string goodsno = dw_list.GetItemString(i, "GoodsNo");
            string barcode1 = dw_list.GetItemString(i, "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, string 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 != "*") count = PrintNumber.toInt();
 
        astring agoodsno;
        astring abarcode;
        astring emptystr = s2a("");
 
        int li_rate = 8;
 
        for (int i = sRow; i <= eRow; i++)
        {
            int cx = count;
            if (cx == 0) cx = dw_list.GetItemInt(i, "Quantity");
            string goodsno = dw_list.GetItemString(i, "GoodsNo");
            string barcode1 = dw_list.GetItemString(i, "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, string 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 != "*") count = PrintNumber.toInt();
 
        //astring s38=s2a("38");
        //astring s17=s2a("17");
        astring s38 = s2a("40");
        astring s17 = s2a("20");
        astring s3 = s2a("3");
        astring s10 = s2a("10");
 
        astring s116 = s2a("116");
        astring s140 = s2a("140");
        astring s16 = s2a("16");
        astring s24 = s2a("24");
        astring s1 = s2a("1");
        astring s0 = s2a("0");
        astring s2 = s2a("2");
 
        astring s25 = s2a("25");
        astring s48 = s2a("48");
        astring s64 = s2a("64");
 
        astring s2d9 = s2a("2.9");
        astring s5d8 = s2a("5.8");
 
        astring cutter = s2a("SET CUTTER OFF");
        astring direction = s2a("DIRECTION 1");
        astring t4502 = s2a("TSC TTP-244 Pro");//s2a("Bar Code Printer T-4502E");
        astring agoodsno;
        astring abarcode;
 
        string 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, "Quantity");
            string goodsno = dw_list.GetItemString(i, "GoodsNo");
            string barcode1 = dw_list.GetItemString(i, "BarCode");
            sdate = dw_list.GetItemString(i, "InstoreDate");
            sdate = sdate.left(10);
            adate = s2a(sdate);
 
            //trace("\r\n---"+cx.toString());
            agoodsno = s2a(goodsno);
            abarcode = s2a(barcode1);
 
            acount = s2a(cx.toString());
            //for(int k=1;k<=cx;k++)
            //{
                //trace("\r\n---"+k.toString());
                //setup(s2a("38"),s2a("17"),s2a("3"),s2a("10"),s2a("0"),s2a("2"),s2a("0"));
                //sendcommand(s2a("SET CUTTER OFF"));
                //sendcommand(s2a("DIRECTION 1"));
                //clearbuffer();
                /*Šªf: Spˆhj_cNäR0hx¼Spˆhj_
                //SÃex: Šs}0cNäŠËSÀTSPL*/
                //printerfont(s2a("16")/*x*/,s2a("24")/*y*/,s2a("2")/*font*/,s2a("0")/*rote*/,s2a("1")/*ratex*/,s2a("1")/*ratey*/,s2a(goodsno));
                ////printerfont(s2a("178")/*x*/,s2a("24")/*y*/,s2a("2")/*font*/,s2a("0")/*rote*/,s2a("1")/*ratex*/,s2a("1")/*ratey*/,s2a("1"));
                //barcode(s2a("16")/*x*/,s2a("48")/*y*/,s2a("25")/*code*/,s2a("64")/*height*/,s2a("0")/*text*/,s2a("0")/*rote*/,s2a("2.9")/*barn*/,s2a("5.8")/*barw*/,s2a(barcode1));
                //printerfont(s2a("64")/*x*/,s2a("116")/*y*/,s2a("2")/*font*/,s2a("0")/*rote*/,s2a("1")/*ratex*/,s2a("1")/*ratey*/,s2a(barcode1));
                //printlabel(s2a("1"),s2a("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("178")/*x*/,s2a("24")/*y*/,s2a("2")/*font*/,s2a("0")/*rote*/,s2a("1")/*ratex*/,s2a("1")/*ratey*/,s2a("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(string Printer, int sRow, int eRow, string PrintNumber)
    {
        int prn = 1;
        if (Printer.find("T-4502E") >= 0)
            return OnPrint_4502(sRow, eRow, PrintNumber);
        else if (Printer.find("TSC") >= 0)
            return OnPrint_4502(sRow, eRow, PrintNumber);
        else if (Printer.find("PPLA") >= 0)
        {
            if (Printer.find("PRN3") >= 0) prn = 3;
            if (Printer.find("PRN2") >= 0) prn = 2;
            return OnPrint_ppla(sRow, eRow, PrintNumber, prn);
        }
        else if (Printer.find("PPLZ") >= 0)
        {
            if (Printer.find("PRN3") >= 0) prn = 3;
            if (Printer.find("PRN2") >= 0) prn = 2;
            return OnPrint_pplz(sRow, eRow, PrintNumber, prn);
        }
        return 1;
    }
 
    int OnPrint()
    {
        xaserverarg arg = new xaserverarg;
        arg.setNativePointer(arg.CreateInstance());
        arg.AddArg("Printer", Printer);
        arg.AddArg("PrintNumber", "*");
        arg.AddArg("PrintRowFrom", dw_list.GetRow().toString());
        arg.AddArg("PrintRowLast", dw_list.GetRow().toString());
        OpenWindow("dev:xpage[SampleBarcodePrint.vx]", cast(arg as int));
 
        if (arg.GetArgString("process") == "ok")
        {
            Printer = arg.GetArgString("Printer");
            string PrintNumber = arg.GetArgString("PrintNumber");
            string rowFrom = arg.GetArgString("PrintRowFrom");
            string rowLast = arg.GetArgString("PrintRowLast");
            OnPrint(Printer, rowFrom.toInt(), rowLast.toInt(), PrintNumber);
        }
        return 1;
    }
 
    int OnCombboChange(ref TCommandEvent evt, int lParam)
    {
        int h = xcombobox::GetCurSel(GetControl("datetype").GetId());
        if (h < 0) return 0;
 
        xcombobox::GetLBText(GetControl("datetype").GetId(), h);
 
        return 1;
    }
 
    //T}NäYtN‹Nö
    int OnXCommand(ref TXCommandEvent evt, int param)
    {
        return OnCmdDispatch(evt.pStrID);
    }
 
    int OnRowChanged(ref TNotifyEvent evt, int p)
    {
        ref DWNMHDR  hdr = trust(evt.pnmh as ref DWNMHDR);
        int row = hdr.row;
 
        if (row < 1) return 1;
        if (row > dw_list.GetRowCount()) return 1;
 
        msxml::IXMLDOMElement e = dw_list.GetRowElement(row);
        string str = e.getAttribute("update.new");
        if (str == "1")
            dw_list.SetReadOnly(false);
        else
        {
            if (win32::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("WM_XCOMMAND", OnXCommand);
        //ƒ·SÖq&p¹N‹Nöÿ u(NŽ‘Ín]åQwga
        AttachEvent("WM_SETFOCUS", OnSetFocus);
        AttachEvent("dw_list", "DWV_ITEMCHANGED", OnItemChanged);
        AttachEvent("dw_list", "DWV_ROWFOCUSCHANGED", OnRowChanged);
        //
        AttachEvent("datetype", "CBN_SELCHANGE", OnCombboChange);  //TO list
        AttachEvent("dw_list", "DWV_CLICKED", OnClicked);
    }
 
    int  OnRetrieve()
    {
        xml x = new xml;
        x.setNativePointer(xml::CreateInstance());
        xaserverarg arg = new xaserverarg;
        arg.setNativePointer(arg.CreateInstance());
        arg.AddArg("pageindex", "1");
        arg.AddArg("pagenumber", "");
 
        string queryText = "";
        if (GetControl("goodsno").GetText() != "")
        {
            string value = GetControl("goodsno").GetText();
            value = value.replace("'", "''");
            queryText += "<item name='GoodsNo' op='like' value='" + value + "%'/>";
        }
        string datetype = GetControl("datetype").GetText();
 
        //string sdate1 = GetControl("sdate").GetText();
        //string edate1 = GetControl("edate").GetText();
 
        string sdate = dw_arg.GetItemString(1, "startDate");
        string edate = dw_arg.GetItemString(1, "endDate");
 
        if (datetype == "^tNý")
        {
            if (sdate != "")
                queryText += "<item name='datepart(year,InstoreDate)' op='=' value='" + sdate.left(4) + "'/>";
        }
        else if (datetype == "gNý")
        {
            if (sdate != "")
                queryText += "<item name='datediff(month,InstoreDate,&apos;" + sdate.left(4) + "/" + sdate.mid(5, 2) + "/01&apos;)' op='=' value='0'/>";
        }
        else if (datetype == "eåg")
        {
            if (sdate != "")
                queryText += "<item name='datediff(day,InstoreDate,&apos;" + sdate.left(10) + "&apos;)' op='=' value='0'/>";
        }
        else if (datetype == "^tNýƒVô")
        {
            if (sdate != "")
                queryText += "<item name='datepart(year,InstoreDate)' op='&gt;=' value='" + sdate.left(4) + "'/>";
            if (edate != "")
                queryText += "<item name='datepart(year,InstoreDate)' op='&lt;=' value='" + edate.left(4) + "'/>";
        }
        else if (datetype == "gNýƒVô")
        {
            if (sdate != "")
                queryText += "<item name='datediff(month,InstoreDate,&apos;" + sdate.left(4) + "/" + sdate.mid(6, 2) + "/01&apos;)' op='&lt;=' value='0'/>";
            if (edate != "")
                queryText += "<item name='datediff(month,InstoreDate,&apos;" + edate.left(4) + "/" + edate.mid(6, 2) + "/01&apos;)' op='&gt;=' value='0'/>";
        }
        else if (datetype == "eågƒVô")
        {
            if (sdate != "")
                queryText += "<item name='datediff(day,InstoreDate,&apos;" + sdate.left(10) + "&apos;)' op='&lt;=' value='0'/>";
            if (edate != "")
                queryText += "<item name='datediff(day,InstoreDate,&apos;" + edate.left(10) + "&apos;)' op='&gt;=' value='0'/>";
        }
 
        arg.AddArg("QueryTxt", "<items join='and'>" + queryText + "</items>");
 
        trace("<items join='and'>" + queryText + "</items>");
        //trace(arg.GetArgString("QueryTxt"));
        if (getUrl("/sale/data/Sample/entity/list", arg.GetString(), x) != 1)
        {
            trace(x.GetXmlDoc().text);
            return -1;
        }
        else
        {
            dw_list.Retrieve(x);
            dw_list.Redraw();
        }
        return 1;
    }
 
    int onload()
    {
        dw_list = GetControl("dw_list");
        dw_list.openUrl("/sale/view/Sample/template/Sample/list");
 
        dw_arg = GetControl("dw_arg");
        dw_arg.openUrl("/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("CreateDate", false);
 
        string sdate = publiccode::GetCurrentDate();
        GetControl("sdate").SetText(sdate.left(10));
        dw_arg.SetItemString(1, "startDate", sdate.left(10));
 
        Printer = "";
        OnAttachEvent();
 
 
        return 1;
    }
 
    int getBalanceEx(string barcode1)
    {
        int ttl = 0;
        xml x = ViewObject::RetrieveData("/sale/data/Sample/entity/balance/barcode", "barcode", barcode1);
        if (x)
        {
            string val;
            val = x.GetXmlDoc().documentElement.GetAttribute("value");
            ttl = val.toInt();
        }
        return ttl;
    }
 
    int getBalance(string goodsno)
    {
        int ttl = 0;
        xml x = ViewObject::RetrieveData("/sale/data/Sample/entity/balance", "GoodsNo", goodsno);
        if (x)
        {
            string val;
            val = x.GetXmlDoc().documentElement.GetAttribute("value");
            ttl = val.toInt();
        }
        return ttl;
    }
 
    int getSumBalance(int row, string goodsno)
    {
        int ttl = 0;
        for (int crow = 1; crow < row; crow++)
        {
            msxml::IXMLDOMElement ele = dw_list.GetRowElement(crow);
            string str = ele.GetAttribute("update.new");
            if (str == "1")
            {
                if (dw_list.GetItemString(crow, "GoodsNo") == goodsno)
                    ttl += dw_list.GetItemInt(crow, "Quantity");
            }
        }
        return ttl;
    }
 
    int getSumBalanceEx(int row, string barcode1)
    {
        int ttl = 0;
        for (int crow = 1; crow < row; crow++)
        {
            msxml::IXMLDOMElement ele = dw_list.GetRowElement(crow);
            string str = ele.GetAttribute("update.new");
            if (str == "1")
            {
                if (dw_list.GetItemString(crow, "BarCode") == barcode1)
                    ttl += dw_list.GetItemInt(crow, "Quantity");
            }
        }
        return ttl;
    }
 
    int rowinitial(int row)
    {
        string sdate = publiccode::GetCurrentDate();
        dw_list.SetItemString(row, "CreateDate", sdate);
        string suserid = publiccode::GetUser().id;
        string susername = publiccode::GetUser().name;
        dw_list.SetItemString(row, "CreatorID", suserid);
        dw_list.SetItemDisplayString(row, "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;
    }
};