LiFan
2024-06-25 dd1ed0f649448d9e9a82406e23c095d5518933a7
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
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
#include <wobject/xstring.hpp>
#include <xcontrol/xtreeview.hpp>
#include <xcontrol/xdwgrid.hpp>
#include <xcontrol/xlayersheet.hpp>
 
#include "vbusiness/vframe/maint.vframe.vbusiness.hpp"
#include "viewobject/view.base.hpp"
 
using xml = KXMLDOMDocument;
class __declspec(dllexport) maintCustomerv3 : public maint
{
public:
    xlayersheet xsheet;        
    xlayersheet m_layer;                
    xdwtable    dw_detail;
    xdwtable dw_power;
    xdwtable dw_require;
    xdwtable dw_jzfx;
    xdwtable dw_visit;
    
    xdwtable dw_Meetings;
    xdwtable dw_MeetingsEx;
    
    xdwgrid    dw_account;
    
 
    int                iLayer;//页面Index    
    int APP=1;            
    HWND     CustomerGoodsHWND;
 
    xstring userno;
    xstring ApplyStatus;
    /*struct PUser
    {
        xstring id;
        xstring no;
        xstring name;
    };*/
 
public:
    maintCustomerv3(void* implPtr, HWND hWnd) :maint(implPtr, hWnd) {}
public:
    static maintCustomerv3* CreateInstance(void* implPtr, void* hWnd)
    {
        maintCustomerv3* pWin = new maintCustomerv3(implPtr, (HWND)hWnd);
        return pWin;
    }
 
    xstring GetGuid()
    {
        return publiccode::GetGuid();            
    }    
    
    int ViewUpdate(int pr,xstring updateItem,xaserverarg  arg)
    {
        if(updateItem==L"update")
        {
        
            dw_detail.ResetUpdateStatus();                                
        }    
        return 1;
    }    
 
    xstring GetEntityData(LPARAM pr)
    {
        xml x;
        
        dw_detail.DwUpdateAllTo(x);
        
        KXMLDOMElement e=x.documentElement();
        
        xml x1 ;
        
        dw_visit.DwUpdateAllTo(x1);
        KXMLDOMElement e1=x1.documentElement();
        KXMLDOMNodeList  oNodeList = e1.selectNodes(L"//Customer/*");
        int i=0;
        for (i=0; i<oNodeList.length(); i++) 
        {
          KXMLDOMElement Item = oNodeList.item(i);
          e.appendChild(Item);
       }
       
       xml x2= new xml;
        
        dw_Meetings.DwUpdateAllTo(x2);
        KXMLDOMElement e2=x2.documentElement();
        KXMLDOMNodeList  oNodeList2 = e2.selectNodes(L"//Customer/*");
        int i2=0;
        for (i2=0; i2<oNodeList2.length(); i2++) 
        {
          KXMLDOMElement Item2 = oNodeList2.item(i2);
          e.appendChild(Item2);
       }
       
       xml x3= new xml;
        
        dw_MeetingsEx.DwUpdateAllTo(x3);
        KXMLDOMElement e3=x3.documentElement();
        KXMLDOMNodeList  oNodeList3 = e3.selectNodes(L"//Customer/*");
        int i3=0;
        for (i3=0; i3<oNodeList3.length(); i3++) 
        {
          KXMLDOMElement Item3 = oNodeList3.item(i3);
          e.appendChild(Item3);
       }
       
       trace(e.xml());
        return e.xml();
    }
    
    int OnInit()
    {
        userno = xaserver::GetUserNo();
        //PUser User = publiccode::GetUserInfo();
        dw_detail.SetItemString(1,L"SalesPersonID",xaserver::GetUserId());
        dw_detail.SetItemDisplayString(1,L"SalesPersonID",publiccode::GetUser().name);
        dw_detail.SetItemString(1,L"CreatorID",xaserver::GetUserId());
        dw_detail.SetItemDisplayString(1,L"CreatorID",publiccode::GetUser().name);
        dw_detail.SetItemString(1,L"CreateDate",publiccode::GetCurrentDate());
        dw_detail.SetItemString(1,L"ModifyDate",publiccode::GetCurrentDate());
        dw_detail.SetItemString(1,L"Status",L"1");
        dw_detail.SetItemString(1,L"PAStatus",L"1"); //地址状态
        dw_detail.SetItemString(1,L"PrimaryFlag",L"Y"); //主地址
        dw_detail.SetItemString(1,L"Type",L"1"); //客户为 1
        dw_detail.SetItemString(1,L"IdentifyAddressFlag",L"Y"); //没必要,暂时留着
        
        xstring sdate = publiccode::GetCurrentDate();    
        dw_detail.SetItemString(1,L"ApplyDate",sdate);
        dw_detail.SetItemString(1,L"ApplyStatus",L"新建");
        dw_detail.SetItemString(1,L"Level",L"");            
        
        //dw_detail.SetItemDisplayString(1,L"客户资料",L"客户资料附件");
        dw_detail.SetItemString(1,L"客户资料",L"客户资料附件");
        xstring guid = publiccode::GetGuid();
        dw_detail.SetGuid(1,guid);
        dw_detail.Redraw();
        return 1;
    }
    
    xstring GetPartyID(xstring sName,xstring sType)
    {
        xml x1=new xml;
        
        xaserverarg arg;
        arg.setNativePointer(arg.CreateInstance());        
        arg.AddArg(L"sname", sName);
        arg.AddArg(L"type",sType);    
        if(xurl::get(L"/sale/data/"+GetEntityName(1)+L"/pref/searchname",arg.GetString(),x1)!=1)
        {
            xstring error = x1.text();
            //alert(L"/sale/data/"+GetEntityName(1)+L"/pref/searchname");
            return L"";
        }
        xstring sID=L"";
        if(x1.selectSingleNode(L"root/PartyID"))
            sID = x1.selectSingleNode(L"root/PartyID").text();
        return sID+xstring(L"");
    }
 
    int OnItemChanged(TEvent* evt, int p)
    {    
        DWNMHDR* hdr = (DWNMHDR*)evt->notify.pnmh;
        xstring colname = hdr->colname;
        xstring coldata = hdr->data;
        int row = hdr->row;
    
 
        //根据国别显示地区代码
        if (colname == L"CountryCode")
        {
            xaserverarg arg ;
            arg.setNativePointer(arg.CreateInstance());
            arg.AddArg(L"countryCode",coldata);
            xml x;
        
            if (getUrl(L"/sale/data/"+GetEntityName(1)+L"/pref/areacode",arg.GetString(),x)==1)
            {
                xstring sareacode = L"";
                xstring sareaname = L"";
                if(x.selectSingleNode(L"//AreaCode"))
                {
                    sareacode = x.selectSingleNode(L"//AreaCode").text();
                    sareaname = x.selectSingleNode(L"//AreaName").text();
                }
                dw_detail.SetItemString(1,L"AreaCode",sareacode);
                dw_detail.SetItemDisplayString(1,L"AreaCode",sareaname);
                dw_detail.Redraw();
            }
        }
        
        //只能选一个主联系人
        if (colname == L"PrimaryFlag" && coldata == L"Y")
        {
            xdwtable dw_pc;
            dw_pc = dw_detail.FindDwTable(L"item1");
            if (dw_pc)
            {
                int i;
                for (i=1;i <= dw_pc.GetRowCount();i++)
                {
                    if (i != row)
                    {
                        dw_pc.SetItemString(i,L"PrimaryFlag",L"N");
                        dw_pc.SetItemDisplayString(i,L"PrimaryFlag",L"");
                        
                    }
                }
            }
        }
 
        //客户名相同。
        if (colname == L"Name")
        {
        //alert(coldata);
        /*    xstring sguid = GetPartyID(coldata,colname);
            if (sguid != L"")
            {
                alert(L"客户名称与系统已有客户重复,请于管理员联系解决!");
            }*/
            //alert(L"ccc");
        }
    
        //客户简称
        if (colname == L"ShortName")
        {
            xstring sguid1 = GetPartyID(coldata,colname);
            //trace(sguid1);
            if (sguid1 != L"")
            {
                alert(L"客户简称重复,请改用其他简称!");
            }
        }
        //根据客户来源填写客户备注
        /*if (colname == L"Source")
        {
            if(coldata==L"025")
                alert(L"来源备注对应填写客户如何知道我们公司");
            if(coldata==L"017" || coldata==L"018")
                alert(L"来源备注对应填写哪个客户介绍的");
            if(coldata==L"019")
                alert(L"来源备注对应填写哪个海外办事处或者联络点介绍");
            if(coldata==L"020")
                alert(L"来源备注对应填写哪个门店介绍");
            if(coldata==L"021")
                alert(L"来源备注对应填写谁介绍");
            if(coldata==L"026")
                alert(L"来源备注对应填写谁考察市场争取到的客户");
            if(coldata==L"028")
                alert(L"来源备注对应填写国外展会名称");
            if(coldata==L"034")
                alert(L"来源备注对应填写谁的代理业务");
            if(coldata==L"001" || coldata==L"002" )
                alert(L"来源备注对应填写客户如何知道我们公司");
            if(coldata==L"0052" || coldata==L"0053" || coldata==L"0054" || coldata==L"0055" || coldata==L"0051")
                dw_detail.SetItemString(1,L"SourceRemark",L"阿里巴巴");
            if(coldata==L"0161" || coldata==L"0162" )
                dw_detail.SetItemString(1,L"SourceRemark",L"环球资源");
            if(coldata==L"0061" || coldata==L"0062" )
                dw_detail.SetItemString(1,L"SourceRemark",L"中国制造网");
            if(coldata==L"022" || coldata==L"023"  || coldata==L"037"  || coldata==L"038"  || coldata==L"039"  || coldata==L"040"  || coldata==L"007"  || coldata==L"024" )
                dw_detail.SetItemString(1,L"SourceRemark",L"MH网站");                            
        }*/
        //联系人Title选择。
        if (colname == L"Title")
        {
            xdwtable dw_PartyContact;
            dw_PartyContact = dw_detail.FindDwTable(L"PartyContact");    
            if(coldata==L"MR")
                dw_PartyContact.SetItemString(dw_PartyContact.GetRow(),L"Gender",L"男");
            else if(coldata==L"MS" || coldata==L"MADAM" || coldata==L"MRS" )
                dw_PartyContact.SetItemString(dw_PartyContact.GetRow(),L"Gender",L"女");
            else
                dw_PartyContact.SetItemString(dw_PartyContact.GetRow(),L"Gender",L"");                        
                
        }
        if (colname==L"SalesPersonID"  && coldata != L"")//设置人员归属
        {
            trace(L"asdasd");
            xstring ls_deptname,ls_teamname,ls_groupname,ls_unitname;
            ls_deptname =  publiccode::GetUser(coldata).deptname;
            ls_teamname = publiccode::GetUser(coldata).teamname;
            ls_groupname =  publiccode::GetUser(coldata).groupname;
            ls_unitname = publiccode::GetUser(coldata).unitname;
            trace(ls_unitname);
            dw_detail.SetItemString(1,L"OrgName",ls_deptname+xstring(ls_teamname)+ xstring(ls_groupname)+ xstring(ls_unitname) );
        }
        //根据生日自动设置年龄。
        /*if (colname == L"Birthday")
        {
            xdwtable dw_PartyContact1;
            dw_PartyContact1 =dw_detail.FindDwTable(L"PC_OtherInfo");            
            xml xx = new xml;
            xx.setNativePointer(xml ::CreateInstance());
            xaserverarg argnew = new xaserverarg;
            argnew.setNativePointer(argnew.CreateInstance());    
            xstring     agesql;
            agesql =  L"select Dbo.GetAge( '{$Birthday}',getdate()) for xml PATH('root'),ELEMENTS XSINIL";
            argnew.AddArg(L"sql",agesql);                
            argnew.AddArg(L"Birthday",coldata);
            if (getSql(argnew.GetString(),xx) == 1)
            {
                KXMLDOMElement AgeEle=xx.documentElement;
                dw_PartyContact1.SetItemString(1,L"Age",AgeEle.text());
            }                                                        
        }*/
        return 1;
    }
    
    int OnAddRow()
    {
        xdwtable dw_obj;                
        xdwtable dw_contact;
        dw_contact = dw_detail.GetCurTable();
        xstring sDwname = dw_contact.GetDwName();
        if(sDwname.find(L"item") >=0 ) sDwname = dw_contact.GetParent().GetDwName();
        if(sDwname==L"PartyContact") 
        {
            int iRowPc = dw_contact.InsertRow(0);
        }
        else if(sDwname==L"PartyAddress") 
        {
            int iRowPad = dw_contact.InsertRow(0);
        }
        else if(sDwname==L"PartyBankAccount") 
        {
            int iRowPba = dw_contact.InsertRow(0);
        }        
        int h=m_layer.GetSheetIndex();
        int nindex = h+1;
        //alert(nindex.toString());
        if(nindex==5)
        {    
            dw_obj=GetControl(L"dw_jzfx");
            xdwtable dw = dw_obj.GetCurTable();    
            int row = dw.InsertRow(1, 0);
            dw.SetItemString(row,L"SeqNo",xstring(row));                
        }
        if(nindex==4)
        {    
            dw_obj=GetControl(L"dw_visit");        
            xdwtable dw1 = dw_obj.GetCurTable();                
            int row1 = dw1.InsertRow(0);    
        }
        if(nindex==3)
        {    
            dw_obj=GetControl(L"dw_MeetingsEx");        
            xdwtable dw3 = dw_obj.GetCurTable();                
            int row3 = dw3.InsertRow(0);    
        }
        
        if(nindex==2)
        {    
            dw_obj=GetControl(L"dw_Meetings");        
            xdwtable dw2 = dw_obj.GetCurTable();                
            int row2 = dw2.InsertRow(0);    
        }
        return 0;
    }
    
    int OnInsertRow()
    {
        xdwtable dw_obj;                        
        xdwtable dw_contact;
        dw_contact = dw_detail.GetCurTable();
        xstring sDwname = dw_contact.GetDwName();
        if(sDwname.find(L"item") >=0 ) sDwname = dw_contact.GetParent().GetDwName();
        if(sDwname==L"PartyContact") 
        {
            int iRowPc = dw_contact.InsertRow(dw_contact.GetRow());
        }
        else if(sDwname==L"PartyAddress") 
        {
            int iRowPad = dw_contact.InsertRow(dw_contact.GetRow());
        }
        else if(sDwname==L"PartyBankAccount") 
        {
            int iRowPba = dw_contact.InsertRow(dw_contact.GetRow());
        }
        int h=m_layer.GetSheetIndex();
        int nindex = h+1;
        if(nindex==5)
        {    
            dw_obj=GetControl(L"dw_jzfx");
            xdwtable dw = dw_obj.FindDwTable(L"CustomerJzfx");        
            int row = dw.InsertRow(1,dw.GetRow());
            //dw.SetGuid(row,publiccode::GetGuid());
        }
        if(nindex==4)
        {    
            dw_obj=GetControl(L"dw_visit");
            xdwtable dw1 =dw_obj.GetCurTable();    
            int row1 = dw1.InsertRow(dw1.GetRow());    
        }
        if(nindex==3)
        {    
            dw_obj=GetControl(L"dw_MeetingsEx");
            xdwtable dw3 =dw_obj.GetCurTable();    
            int row3 = dw3.InsertRow(dw3.GetRow());    
        }        
        if(nindex==2)
        {    
            dw_obj=GetControl(L"dw_Meetings");
            xdwtable dw2 =dw_obj.GetCurTable();    
            int row2 = dw2.InsertRow(dw2.GetRow());    
        }
        return 0;
    }
    
    int OnDeleteRow()
    {
        xdwtable dw_obj;                    
        xdwtable dw_contact;
        dw_contact = dw_detail.GetCurTable();
        xstring sDwname = dw_contact.GetDwName();
        if(sDwname.find(L"item") >=0 ) sDwname = dw_contact.GetParent().GetDwName();
        if(sDwname==L"PartyContact" ||sDwname==L"PartyAddress" ||sDwname==L"PartyBankAccount" ) 
        {
            int row = dw_contact.GetRow();
            dw_contact.DeleteRow(row);
        }
        int h=m_layer.GetSheetIndex();
        int nindex = h+1;
        if(nindex==5)
        {    
            dw_obj=GetControl(L"dw_jzfx");
            xdwtable dw = dw_obj.GetCurTable();            
            int row1 = dw.GetRow();
            if(dw.GetRowCount() >1)
                dw.DeleteRow(row1);            
        }
        if(nindex==4)
        {    
            dw_obj=GetControl(L"dw_visit");
            xdwtable dw1 = dw_obj.GetCurTable();            
            int row2 = dw1.GetRow();
            dw1.DeleteRow(row2);        
        }
        if(nindex==3)
        {    
            dw_obj=GetControl(L"dw_MeetingsEx");
            xdwtable dw4 = dw_obj.GetCurTable();            
            int row4 = dw4.GetRow();
            dw4.DeleteRow(row4);        
        }    
        if(nindex==2)
        {    
            dw_obj=GetControl(L"dw_Meetings");
            xdwtable dw3 = dw_obj.GetCurTable();            
            int row3 = dw3.GetRow();
            dw3.DeleteRow(row3);        
        }    
        return 0;
    }
    
    int OnDetailRow()
    {
        trace(L"detail");
        return 0;
    }
 
    int OnPreSave()
    {
        xml xxx ;
        
        dw_detail.DwUpdateAllTo(xxx);
        trace(xxx.xml());
        //return 0;
        
        //客户名称
        xstring sName;
        sName = dw_detail.GetItemString(1,L"Name");
        if (sName == L"")
        {
            alert(L"客户名称不能为空!");
            return 0;
        }
        
        xstring sShortName = dw_detail.GetItemString(1,L"ShortName");
        if (sShortName == L"")
        {
            alert(L"客户简称不能为空!");
            return 0;
        }
        xstring Level = dw_detail.GetItemString(1,L"Level");
        /*if (Level == L"")
        {
            alert(L"客户等级不能为空!");
            return 0;
        }*/
        
        /*
        if(dw_detail.GetItemString(1,L"Address")==L"")
        {
            alert(L"客户地址不能为空!");
            return 0;
        }
        
        if(dw_detail.GetItemString(1,L"Source")==L"")
        {
            alert(L"客户来源不能为空!");
            return 0;
        }
        if(dw_detail.GetItemString(1,L"CountryCode")==L"")
        {
            alert(L"客户国别不能为空!");
            return 0;
        }
        if(dw_detail.GetItemString(1,L"TEL")==L"")
        {
            alert(L"公司电话不能为空!");
            return 0;
        }*/
        //客户简称不能重复
        /*
        xstring sPartyID = GetPartyID(sShortName,L"ShortName");
        if (sPartyID != L"")
        {
            alert(L"此客户简称已经存在!");
        }
        */
        
        //客户代码
        xstring sPartyNo;
        sPartyNo = dw_detail.GetItemString(1,L"PartyNo");
        if (sPartyNo == L"" )
        {
            //alert(L"客户代码不能为空!");
            //return 0;
            
            xstring sNo = publiccode::GetIdentityNo(L"Party1");
            if (sNo == L"")
                sNo == L"1000";
            dw_detail.SetItemString(1,L"PartyNo",sNo);
            
        }    
 
        //成立时间YearEstablished
        //雇员数量Employees
        //xstring sYearEstablished = dw_detail.GetItemString(1,L"YearEstablished");
        //xstring sEmployees = dw_detail.GetItemString(1,L"Employees");
        //sYearEstablished.toInt();
            
        
        //联系人姓名Name-PCName,设置状态
        xdwtable dw_PartyContact;
        dw_PartyContact = dw_detail.FindDwTable(L"PartyContact");
        xdwtable PC_OtherInfo;
        PC_OtherInfo = dw_detail.FindDwTable(L"PC_OtherInfo");                    
        int countflag=0;                    
        if (dw_PartyContact)
        {
            int i;
            for (i=1;i <= dw_PartyContact.GetRowCount();i++)
            {
                xstring sPCName = dw_PartyContact.GetItemString(i,L"Name");
                if (sPCName == L"" )        
                {
                    xstring sPCTitle = dw_PartyContact.GetItemString(i,L"Title");
                    if (sPCTitle == L"") sPCTitle = L"";
                    xstring sPCJobTitle = dw_PartyContact.GetItemString(i,L"JobTitle");
                    if (sPCJobTitle == L"") sPCJobTitle = L"";
                    xstring sPCGender = dw_PartyContact.GetItemString(i,L"Gender");
                    if (sPCGender == L"") sPCGender = L"";
                    xstring sPCMobile = dw_PartyContact.GetItemString(i,L"Mobile");
                    if (sPCMobile == L"") sPCMobile = L"";
                    xstring sPCTEL = dw_PartyContact.GetItemString(i,L"TEL");
                    if (sPCTEL == L"") sPCTEL = L"";
                    xstring sPCEmail = dw_PartyContact.GetItemString(i,L"Email");
                    if (sPCEmail == L"") sPCEmail = L"";
                    xstring sAll = sPCTitle + sPCJobTitle + sPCGender + sPCMobile + sPCTEL + sPCEmail;
                    /*if (sAll != L"")
                    {
                        alert(L"联系人姓名不能为空");
                        return 0;
                    }*/
                }
                else
                {
                    xstring aStatus;
                    aStatus = dw_PartyContact.GetItemString(i,L"Status");
                    if (aStatus==L"")
                    {
                        dw_PartyContact.SetItemString(i,L"Status",L"1");
                    }                
                }
                if(dw_PartyContact.GetItemString(i,L"ContactID")==L"")
                {    
                    dw_PartyContact.SetItemString(i,L"ContactID",GetGuid());                            
                }                            
                xstring sFlag = dw_PartyContact.GetItemString(i,L"PrimaryFlag");
                if(sFlag==L"Y")
                {                    
                    countflag ++;
 
                    dw_PartyContact.SetItemString(i,L"PrimaryFlag",L"Y");                                
                    PC_OtherInfo.SetItemString(1,L"ContactID",dw_PartyContact.GetItemString(i,L"ContactID"));    
                
                }
                
            }
            if(countflag==0 && dw_PartyContact.GetItemString(1,L"Name") !=L"")
            {    
                dw_PartyContact.SetItemString(1,L"PrimaryFlag",L"Y");
                PC_OtherInfo.SetItemString(1,L"ContactID",dw_PartyContact.GetItemString(1,L"ContactID"));                        
            }                                    
        }
 
        //银行帐号BankName-BankName;BankAccountNo-PBABankAccountNo ; 设置状态
        xdwtable dw_PartyBankAccount;
        dw_PartyBankAccount =dw_detail.FindDwTable(L"PartyBankAccount");
        if (dw_PartyBankAccount)
        {
            int j;
            for (j=1;j <= dw_PartyBankAccount.GetRowCount();j++)
            {
                xstring sPBABankName = dw_PartyBankAccount.GetItemString(j,L"BankName");
                xstring sPBABankAccountNo = dw_PartyBankAccount.GetItemString(j,L"BankAccountNo");
                if (sPBABankName == L"") sPBABankName = L"";
                if (sPBABankAccountNo == L"") sPBABankAccountNo = L"";
                xstring sPBAAll = sPBABankName + sPBABankAccountNo;
                if (sPBAAll != L"")
                {
                    /*if (sPBABankName == L"")
                    {
                        alert(L"银行名称不能为空");
                        return 0;
                    }
                    if (sPBABankAccountNo == L"")
                    {
                        alert(L"银行账户不能为空");
                        return 0;
                    }*/
                    dw_PartyBankAccount.SetItemString(j,L"Status",L"1");
                }
            }
        }
    
        //地址,设置状态
        xdwtable dw_PartyAddress;
        dw_PartyAddress =dw_detail.FindDwTable(L"PartyAddress");
        if (dw_PartyAddress)
        {
            int k;
            for (k=1;k <= dw_PartyAddress.GetRowCount();k++)
            {
                xstring sPADAddressName = dw_PartyAddress.GetItemString(k,L"AddressName");
                xstring sPADAddress = dw_PartyAddress.GetItemString(k,L"Address");
                if (sPADAddressName == L"") sPADAddressName = L"";
                if (sPADAddress == L"") sPADAddress = L"";
                xstring sPADAll = sPADAddressName + sPADAddress;
                if (sPADAll != L"")
                {
                    dw_PartyAddress.SetItemString(k,L"Status",L"1");
                    dw_PartyAddress.SetItemString(k,L"IdentifyAddressFlag",L"N");
                }
            }    
        }
        return 1;
    }
    
    int DoUpdate(bool showSuccess = true)
    {
        int rec =OnPreSave();
        if (rec != 1)    return 0;
        ProcessFlowAction(L"action:bill.update",1);
        return 1;
    }
                
    int CustomerModify()//跳到客户修改界面
    {
        //trace(L"asdsad");
        xaserverarg& arg = *new xaserverarg;
        arg.setNativePointer(arg.CreateInstance());    
        arg.AddArg(L"EntityID", maint::m_EntityID);
        openUrl(L"/sale/view/"+GetEntityName(1)+L"/worknode/customermodify/open", &arg);
        //CloseWindow();
        return 1;
    }
    int OnComdidSplit(xstring str){
        if(str.find(L"|", 0)<0)
            return -1;
        CustomerGoodsHWND = (HWND)str.mid(str.find(L"|",0) + 1, str.length()).toInt64();
    }    
 
            
    int OnShare()
    {
        xaserverarg& arg = *new xaserverarg;
        arg.setNativePointer(arg.CreateInstance());    
        int row = dw_detail.GetRow();
        if(row < 1) return 0;
        xstring PartyID = dw_detail.GetItemString(row,L"PartyID");
        arg.AddArg(L"EntityID",PartyID);
        arg.AddArg(L"EntityName", L"客户共享");
        OpenWindow(L"dev:xpage[UserGroupShare.vx]", (LPARAM) & arg);
        return 1;
    }
    
    int OnShareMessage()
    {
        xaserverarg& arg = *new xaserverarg;
        arg.setNativePointer(arg.CreateInstance());    
        int row = dw_detail.GetRow();
        if(row < 1) return 0;
        xstring PartyID = dw_detail.GetItemString(row,L"PartyID");
        arg.AddArg(L"PartyID",PartyID);
        OpenWindow(L"dev:xpage[XmShare.Custumer.v3.vx]", (LPARAM)&arg);
        
    return 1;
    }
        
    int PreOnCmdDispatch(xstring comdid)
    {
        if (comdid == L"cb_save")
        {    
            SendMessageW(CustomerGoodsHWND,0x401, (WPARAM)L"cb_save", 0);                     
        }
        else if (comdid == L"cb_copy")
        {    
            SendMessageW(CustomerGoodsHWND,0x401, (WPARAM)L"cb_copy", 0);
        }
        else if (comdid == L"cb_delete")
        {    
            SendMessageW(CustomerGoodsHWND,0x401, (WPARAM)L"cb_delete", 0);
        }
        else if (comdid == L"cb_reflash")
        {    
            SendMessageW(CustomerGoodsHWND,0x401, (WPARAM)L"cb_reflash", 0);
        }
        else if(comdid == L"cb_add")
        {    
            SendMessageW(CustomerGoodsHWND,0x401, (WPARAM)L"cb_add", 0);
        }
        else if(comdid == L"cb_import")
        {    
            SendMessageW(CustomerGoodsHWND,0x401, (WPARAM)L"cb_import",0);
        }                
        else if (comdid == L"action:bill.row.add") return OnAddRow();
        else if (comdid == L"action:bill.row.insert") return OnInsertRow();
        else if (comdid == L"action:bill.row.delete") return OnDeleteRow();
        else if (comdid == L"action:bill.row.detail") return OnDetailRow();
        else if (comdid == L"action:bill.SourceRemark") return OnSourceRemark();
        
        else if (comdid == L"action:bill.update")
        {
             return OnPreSave();
        }
        else if (comdid == L"action:customermodify") return CustomerModify();
        else if(comdid.find(L"|",0)){
            OnComdidSplit(comdid);
        }
        if(comdid==L"action:XmShare") 
        {
                OnShare();
                return 0;
        }
        if(comdid==L"action:XmShareMessage") 
        {
                OnShareMessage();
                return 0;
        }
    //    else if (comdid.find(L"action:",0) >= 0) return OnAction(comdid);
        return -1;    
    }
    
    int PostOnCmdDispatch(xstring comdid)
    {
        if (comdid == L"action:bill.update")
        {
            dw_detail.ResetUpdateStatus();
            dw_visit.ResetUpdateStatus();
            dw_Meetings.ResetUpdateStatus();
            dw_MeetingsEx.ResetUpdateStatus();
        }
        
        return 1;
    }
    //选择tab页面
    int OnSelectedSheet(TEvent* evt,int p)
    {
        iLayer = m_layer.GetSheetIndex();
        if (iLayer == 0)
            SetAgent(L"maint",maint::m_EntityID);
        else if (iLayer == 1)
        {            
            int cc=APP;
            cc=cc +1;
            APP=cc;
            if(cc==2)
            {    
                xsheet.DeleteSheet(1);
                xstring xp = L"<xframe src='dev:xpage[CustomerGoodsVd.vx]' />";
                xaserverarg& arg = * new xaserverarg;
                arg.setNativePointer(arg.CreateInstance());
                arg.AddArg(L"CustomerID",m_EntityID);
                arg.AddArg(L"FROM", L"Customer");                    
                arg.AddArg(L"CustomerName", dw_detail.GetItemString(1,L"Name"));                
                arg.AddArg(L"config", L"客户产品.vface/config/CustomerGoodsVdVd/view");
                //arg.AddArg(L"CustomerHWND",GetHWND().toString());
                arg.SetParam(L"CustomerHWND", (LPARAM)GetHWND());
 
                int nIndex = xsheet.InsertSheet(-1, L"客户ID货号库", xp, (void *) &arg);
                xsheet.SelectSheet(nIndex);                                
            }
            //win32::SendMessage(CustomerGoodsHWND.toInt(),0x401, L"SetFocus", nil);     
        
        }                
        return 1;
    }
            
    int OnSourceRemark()
    {
        xstring name = L"客户管理";
        xml x = ViewObject::RetrieveData(L"/sale/data/TradeFinance3/GetSetUpRemarks",L"Type",name);
        KXMLDOMNodeList items = x.selectNodes(L"data/Item");
        KXMLDOMNode t = items.item(0);
        xstring Content=L"";
        if(t.selectSingleNode(L"Content"))
        {
            Content=t.selectSingleNode(L"Content").text();
        }
        xaserverarg& arg1 = * new xaserverarg;
        arg1.setNativePointer(arg1.CreateInstance());    
        arg1.AddArg(L"value",Content);
        OpenWindow(L"dev:xpage[memo.edit.new.vx]",(LPARAM) & arg1);
 
        return 1;
    }
    
            
    int OnItemClick(TEvent* evt,int p)
    {
        xdwtable dw = dw_detail.FindDwTable(L"item1",0);
        xdwtable dw1 = dw_detail.FindDwTable(L"item2",0);
        xdwtable dw2 = dw_detail.FindDwTable(L"item3",0);
        int start=dw_detail.GetCellRowFromRowColumn(1,dw_detail.GetColumnIndex(L"Website"));
        int m,n,k;
        m=dw.GetRowCount();
        n=dw1.GetRowCount();
        k=dw2.GetRowCount();                
        if(dw.GetRowCount()==0)                    
        {
            m=dw.GetRowCount() +1;                
        }
        if(dw1.GetRowCount()==0)                    
        {
            n=dw1.GetRowCount() +1;                
        }
        if(dw2.GetRowCount()==0)                    
        {
            k=dw2.GetRowCount() +1;                
        }                
        DWNMHDR* hdr = (DWNMHDR*)evt->notify.pnmh;
        xstring value = hdr->data;
        
 
        //alert(value);
        xaserverarg& arg=* new xaserverarg;
                        
        if(value == L"主要联系人其它信息")
        {                    
            dw_detail.ExpandCellRow(start +m +5,start +m+7);
        }
        else if(value == L"其它地址")
        {    
            dw_detail.ExpandCellRow(start +m+9,start +m+9+n);
            //dw_base.ExpandMarginRow(-22,-20);
        }
        else if(value == L"银行信息")
        {    
            dw_detail.ExpandCellRow(start +m+11+n,start +m+11+n+k);
            //dw_base.ExpandMarginRow(-22,-20);
        }
        else if(value == L"业务概述")
        {        
            dw_detail.ExpandCellRow(start +m+13+n+k,start +m+13+n+k+2);
            //dw_base.ExpandMarginRow(-22,-20);
        }
        else if(value == L"客户授信")
        {    
            dw_detail.ExpandCellRow(start +m+15+n+k +2,start +m+15+n+k +2+1);    
            //dw_base.ExpandMarginRow(-22,-20);
        }
        if(value == L"客户资料附件")
        {    
            
            if(userno == L"admin" || userno == L"00601" || userno == L"00701")
             {
                //alert(dw_detail.GetGuid(1));
                arg.AddArg(L"entityid",dw_detail.GetGuid(1));
                
                OpenWindow(L"dev:xpage[maint.Document.Customer.v3.vx]", (LPARAM) & arg);
                return 1;
            }
        }
        if(value == L"客户基本信息")
        {    
            xaserverarg& arg1 = *new xaserverarg;    
            xstring str = dw_detail.GetItemString(1,L"BasicInformation");
            arg1.AddArg(L"value",str);
            OpenWindow(L"dev:xpage[memo.edit.new.vx]", (LPARAM)&arg1);
            if(arg1.GetArgString(L"comdid")==L"xmOK")
            {
                str = arg1.GetArgString(L"value");
                dw_detail.AcceptText();
                dw_detail.SetItemString(1,L"BasicInformation",str);
            }
            return 1;
            
        }
        return 1;
    }        
    
    int OnItemClickEx(TEvent* evt, int pr)
    {
        xdwtable dw = dw_visit.FindDwTable(L"item",0);
    
        
        DWNMHDR* hdr = (DWNMHDR*)evt->notify.pnmh;
        xstring colname = hdr->colname;
        xstring value = hdr->data;
        int row = hdr->row;
        //alert(value);
        xaserverarg& arg=*new xaserverarg;
        arg.setNativePointer(arg.CreateInstance());                    
        
        if(value == L"上传")
        {
            if(dw.GetGuid(dw.GetRow())==L"")
            {
                alert(L"保存后在上传!");
                return 1;
            }
            
            arg.AddArg(L"entityid",dw.GetGuid(dw.GetRow()));
            
            OpenWindow(L"dev:xpage[maint.Document.Customer.v3.vx]", (LPARAM)&arg);
            return 1;
        }
        return 1;
    }    
    
    int OnItemClickExS(TEvent* evt,int p)
    {
        xdwtable dw = dw_Meetings.FindDwTable(L"item",0);
    
        
        DWNMHDR* hdr = (DWNMHDR*)evt->notify.pnmh;
        xstring colname = hdr->colname;
        xstring value = hdr->data;
        int row = hdr->row;
        //alert(value);
        xaserverarg& arg=*new xaserverarg;
                        
        
        if(value == L"附件上传")
        {
            if(dw.GetGuid(dw.GetRow())==L"")
            {
                alert(L"保存后在上传!");
                return 1;
            }
            
            arg.AddArg(L"entityid",dw.GetGuid(dw.GetRow()));
            
            OpenWindow(L"dev:xpage[maint.Document.Customer.v3.vx]", (LPARAM)&arg);
            return 1;
        }
            
        if(value == L"人员")
        {
            xaserverarg& arg2 =* new xaserverarg;
                
            
            xaserverarg& parg2 = *(xaserverarg*)GetParam();
 
            OpenWindow(L"dev:xpage[UserGroupPersonSelect.vx]", (LPARAM)&arg2);
            
            if(arg2.GetArgString(L"comdid")==L"xmOk")
            {
                xstring data = arg2.GetArgString(L"data");
                xml x2;
                
                x2.loadXML(data);
                KXMLDOMNodeList nodes = x2.selectNodes(L"/root/item");
                trace(x2.xml());
                
                int len = nodes.length();
            
                xstring Names = L"";
                for(int i=0;i<len; i++)
                {
                    KXMLDOMElement t= nodes.item(i);
                    
                    if(t.getAttribute(L"Name"))
                    {
                        xstring Name = t.getAttribute(L"Name");
                        if(Names==L"") 
                            Names = Name;
                        else if(Names.find(Name) < 0) Names+=L",L"+Name;
                    }
                }
                dw.SetItemString(dw.GetRow(),L"CMPersonnel",Names);
                        
            }
            return 1;
        }
            
        return 1;
    }
    
    int OnItemClickExSS(TEvent* evt,int p)
    {
        xdwtable dw = dw_MeetingsEx.FindDwTable(L"item",0);
    
        
        DWNMHDR* hdr = (DWNMHDR*)evt->notify.pnmh;
        xstring colname = hdr->colname;
        xstring value = hdr->data;
        int row = hdr->row;
        //alert(value);
        xaserverarg& arg=*new xaserverarg;
                        
        
        if(value == L"附件上传")
        {
            if(dw.GetGuid(dw.GetRow())==L"")
            {
                alert(L"保存后在上传!");
                return 1;
            }
            
            arg.AddArg(L"entityid",dw.GetGuid(dw.GetRow()));
            
            OpenWindow(L"dev:xpage[maint.Document.Customer.v3.vx]",(LPARAM)&arg);
            return 1;
        }
            
        if(value == L"人员")
        {
            xaserverarg& arg2 = *new xaserverarg;
            
            xaserverarg parg2 = *(xaserverarg*)GetParam();
            OpenWindow(L"dev:xpage[UserGroupPersonSelectEx.vx]", (LPARAM)&arg2);
            
            if(arg2.GetArgString(L"comdid")==L"xmOk")
            {
                xstring data = arg2.GetArgString(L"data");
                xml x2;
                
                x2.loadXML(data);
                KXMLDOMNodeList nodes = x2.selectNodes(L"/root/item");
                trace(x2.xml());
                
                int len = nodes.length();
            
                xstring Names = L"";
                for(int i=0;i<len; i++)
                {
                    KXMLDOMElement t= nodes.item(i);
                    
                    if(t.getAttribute(L"Name"))
                    {
                        xstring Name = t.getAttribute(L"Name");
                        if(Names==L"") 
                            Names = Name;
                        else if(Names.find(Name) < 0) Names+=L",L"+Name;
                    }
                }
                dw.SetItemString(dw.GetRow(),L"CMPersonnel",Names);
            }
            return 1;
        }
            
        return 1;
    }
                        
    int PostOnAttachEvent()
    {
        AttachEvent(L"dw_detail",L"DWV_ITEMCHANGED", (FEvent)&maintCustomerv3::OnItemChanged);
        //AttachEvent(L"tab_1",L"LYSN_SELECTEDSHEET",(FEvent)&maintCustomerv3::OnSelectedSheet);                
        AttachEvent(L"dw_detail",L"DWV_CLICKED", (FEvent)&maintCustomerv3::OnItemClick);
        AttachEvent(L"dw_visit",L"DWV_CLICKED", (FEvent)&maintCustomerv3::OnItemClickEx);
        AttachEvent(L"dw_Meetings",L"DWV_CLICKED", (FEvent)&maintCustomerv3::OnItemClickExS);
        AttachEvent(L"dw_MeetingsEx",L"DWV_CLICKED", (FEvent)&maintCustomerv3::OnItemClickExSS);
        return 1;
    }
    
    int onload()
    {
        maint::onload();            
    }
    
    int onloaded()
    {    
        APP=1;    
        maint::onloaded();
        
        
        m_layer = GetControl(L"tab_1");        
        dw_detail = GetControl(L"dw_detail");
        dw_detail.SetColHeaderHeight(16);                
        dw_power = GetControl(L"dw_power");
        dw_require =GetControl(L"dw_require");
        dw_jzfx = GetControl(L"dw_jzfx");
        dw_visit = GetControl(L"dw_visit");
        dw_Meetings = GetControl(L"dw_Meetings");
        dw_MeetingsEx = GetControl(L"dw_MeetingsEx");
        //添加客户产品附页
        xsheet = GetControl(L"tab_1");
        //xstring xp = L"<xframe src='dev:xpage[CustomerGoodsVd.vx]' />";
        /*xaserverarg arg = new xaserverarg;
        arg.setNativePointer(arg.CreateInstance());
        arg.AddArg(L"CustomerID", this.m_EntityID);
        arg.AddArg(L"CustomerName", dw_detail.GetItemString(1,L"Name"));                
        arg.AddArg(L"config", L"客户产品.vface/config/CustomerGoodsNewVd/view");
        arg.AddArg(L"CustomerHWND",this.GetHWND().toString());
        //trace(this.m_EntityID);
        int p =arg.__nativept;*/
        //int nIndex = xsheet.InsertSheet(-1, L"客户ID货号库", xp, 0);
        //xsheet.SelectSheet(nIndex);            
        //xsheet.SelectSheet(0);                    
        //默认收缩
        /*xdwtable dw = new xdwtable;
        dw.setNativePointer(dw_detail.FindDwTable(L"PartyAddress",0));
        xdwtable dw1 = new xdwtable;
        dw1.setNativePointer(dw_detail.FindDwTable(L"PartyBankAccount",0));
        xdwtable dw2 = new xdwtable;
        dw2.setNativePointer(dw_detail.FindDwTable(L"PartyContact",0));                        
        int start=dw_detail.GetCellRowFromRowColumn(1,dw_detail.GetColumnIndex(L"Website"));
        dw_detail.ExpandCellRow(start + dw2.GetRowCount() +3,start +dw2.GetRowCount()+5);
        int start1=dw_detail.GetCellRowFromRowColumn(1,dw_detail.GetColumnIndex(L"Website"));            
        dw_detail.ExpandCellRow(start1 + dw2.GetRowCount() +7,start1 + dw2.GetRowCount() +7 +dw.GetRowCount());
        int start2=dw_detail.GetCellRowFromRowColumn(1,dw_detail.GetColumnIndex(L"Website"));    
        dw_detail.ExpandCellRow(start2 + dw2.GetRowCount() +9 +dw.GetRowCount(),start2 + dw2.GetRowCount() +9 +dw.GetRowCount() +dw1.GetRowCount());
        int start3=dw_detail.GetCellRowFromRowColumn(1,dw_detail.GetColumnIndex(L"YearEstablished"));            
        dw_detail.ExpandCellRow(start3,start3 +2);
        int start4=dw_detail.GetCellRowFromRowColumn(1,dw_detail.GetColumnIndex(L"CompanyCredit"));            
        dw_detail.ExpandCellRow(start4,start4 +1);    */    
 
        //默认收缩
        xdwtable dw = dw_detail.FindDwTable(L"item1",0);
        xdwtable dw1 = dw_detail.FindDwTable(L"item2",0);
        xdwtable dw2 = dw_detail.FindDwTable(L"item3",0);
        int m,n,k;
        m=dw.GetRowCount();
        n=dw1.GetRowCount();
        k=dw2.GetRowCount();                
        if(dw.GetRowCount()==0)                    
        {
            m=dw.GetRowCount() +1;                
        }
        if(dw1.GetRowCount()==0)                    
        {
            n=dw1.GetRowCount() +1;                
        }
        if(dw2.GetRowCount()==0)                    
        {
            k=dw2.GetRowCount() +1;                
        }
        //trace(dw2.GetRowCount());
        
        int start=dw_detail.GetCellRowFromRowColumn(1,dw_detail.GetColumnIndex(L"Website"));
        dw_detail.ExpandCellRow(start +m +5,start +m+7);
        //trace(start +k +3);                
        dw_detail.ExpandCellRow(start +m+9,start +m+9+n);
        //trace(start +k+7);        
        dw_detail.ExpandCellRow(start +m+11+n,start +m+11+n+k);
        //trace(start +k+10+m);            
        dw_detail.ExpandCellRow(start +m+13+n+k,start +m+13+n+k+2);
        //trace(start +k+14+m+n);                        
        dw_detail.ExpandCellRow(start +m+15+n+k +2,start +m+15+n+k +2+1);
        //trace(start +k+16+m+n +2);        
        
        if (!maint::m_EntityID)
        {
            OnInit();
        }else
        {
            //xstring userno = publiccode::getUserNo();
            userno = xaserver::GetUserNo();
            if(userno !=L"00601" && userno !=L"admin" && userno !=L"00701")
            {
                dw_detail.SetColumnProp(L"SalesPersonID",L"cellprotect",L"1");
                
            }
        }
        
        
        if (GetParam())
        {
            int iArgs = GetParam();
            xaserverarg& args = *new xaserverarg;
            
            //alert(args.GetString());
            xstring CustomerGood = args.GetArgString(L"CustomerGood");
            ApplyStatus= args.GetArgString(L"CustomerGood");
            if(CustomerGood==L"Y")
            {    
                xsheet.DeleteSheet(0);
                xstring xp = L"<xframe src='dev:xpage[CustomerGoodsVd.vx]' />";
                xaserverarg& arg = *new xaserverarg;
                arg.setNativePointer(arg.CreateInstance());
                arg.AddArg(L"CustomerID", m_EntityID);
                arg.AddArg(L"FROM", L"Customer");                    
                arg.AddArg(L"CustomerName", dw_detail.GetItemString(1,L"Name"));                
                arg.AddArg(L"config", L"客户产品.vface/config/CustomerGoodsVdVd/view");
                //arg.AddArg(L"CustomerHWND",GetHWND().toString());
                arg.SetParam(L"CustomerHWND", (LPARAM)GetHWND());
 
                int nIndex = xsheet.InsertSheet(-1, L"客户ID货号库", xp, (void*)&arg);
                xsheet.SelectSheet(nIndex);
                //xsheet.SetSheetState(0, 0);            
            }
            
            
            ApplyStatus=dw_detail.GetItemString(1,L"ApplyStatus");
            
            if(userno !=L"00601" && userno !=L"admin" && userno !=L"00701")
            {
                if(ApplyStatus ==L"财务已审核")
                {
                    dw_detail.SetReadOnly(true);    
                }
            }
            
            
            dw_detail.SetEditUpperMode(true);
            dw_visit.SetEditUpperMode(true);
            dw_Meetings.SetEditUpperMode(true);
            dw_MeetingsEx.SetEditUpperMode(true);
        }
        return 1;
    }        
};