yxj
2025-04-02 bee71e87f2b06265e44c27723d15bff52f1d2dbd
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
namespace Pub_Control
{
    public partial class frmBillQueryCondition_Base : Form
    {
        public frmBillQueryCondition_Base()
        {
            InitializeComponent();
        }
        const int IDCol = 0;
        const int BracketLCol = 1;
        const int FieldNameCol = 2;
        const int ControlCol = 3;
        const int ConditionCol = 4;
        const int BracketRCol = 5;
        const int RelationCol = 6;
        //gridorder 
        const Int16 OrFieldNameCol = 0;
        const Int16 OrDescCol = 1;
        //gridfield
        const Int16 FiNoCol = 0;
        const Int16 FiFieldNameCol = 1; //字段名
        const Int16 FiShowCol = 2;      //是否显示列
        const Int16 FiDuiQiCol = 3; //对齐方式列
        const Int16 FiDecCol = 4;  //小数列
        //
        public string SqlStr="";
        public string FieldsArray = "";
        private string mvarViewName="";
        private int CopyRow=0;
        private string CopyField="";
        private string CopyDataType = "";
        private bool Copyed;
        public Form oFrm;
        public string ViewName;
        public string ModName;
        public bool bFst;
        Pub_Class.ClsSqlHelper oCn = new Pub_Class.ClsSqlHelper();
        Clsxt_ICSchemeMain oItem = new Clsxt_ICSchemeMain();
        public Pub_Class.ClsPub.Enum_BillStatus BillStatus;
        //是否需要显示 记账和红蓝单
        //当前选中方案ID
        Int64 HInterID=0;
 
 
        //初始化 2个GRID和一个LIST  将视图加载到GRID
        public void SetViewName(string sViewName,bool b)
        {
            string[] tArray;
            DataSet Ds=new DataSet();
            int j;
            if( Pub_Class.ClsPub.isStrNull(sViewName).Length==0)
            {
                return;
            } 
            mvarViewName = sViewName;
            //得到视图 字段信息
            Ds=oCn.RunProcReturn("select column_name,data_type from information_schema.columns where table_name ='" + ViewName.Trim() + "' order by  ORDINAL_POSITION", "information");
            //清空
            grdCondition.RowCount = 1;
            grdField.RowCount = 1;
            grdOrder.RowCount = 1;
            lstOrder.Items.Clear();
            //
            for(int i=0;i<Ds.Tables[0].Rows.Count;i++)
            {
                //grid1
                grdCondition.RowCount = i+1;
                grdCondition.Rows[i].Cells[FieldNameCol].Value= Ds.Tables[0].Rows[i]["column_name"].ToString().Trim();
                grdCondition.Rows[i].Cells[IDCol].Value=Ds.Tables[0].Rows[i]["data_type"].ToString().Trim();
                //
                DataGridViewComboBoxCell sCellRel = new DataGridViewComboBoxCell();
                sCellRel.FlatStyle = FlatStyle.System;
                sCellRel.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                sCellRel.DropDownWidth = 10; 
                sCellRel.Items.Add("并且");
                sCellRel.Items.Add("或者");
                grdCondition.Rows[i].Cells[RelationCol] = sCellRel;
                grdCondition.Rows[i].Cells[RelationCol].Value = "并且";
 
                //
                DataGridViewComboBoxCell sCellCom = new DataGridViewComboBoxCell();
                sCellCom.FlatStyle = FlatStyle.System;
                sCellCom.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                sCellCom.DropDownWidth =10;
                sCellCom.Items.Add(" ");
                sCellCom.Items.Add("=");
                sCellCom.Items.Add(">");
                sCellCom.Items.Add(">=");
                sCellCom.Items.Add("<");
                sCellCom.Items.Add("<=");
                sCellCom.Items.Add("<>");
                sCellCom.Items.Add("包含");
                sCellCom.Items.Add("左包含");
                sCellCom.Items.Add("右包含");
                sCellCom.Items.Add("不包含");
                grdCondition.Rows[i].Cells[ControlCol] = sCellCom;
                //对齐列
                //grdfield
                grdField.RowCount = i + 1;
                DataGridViewComboBoxCell sCellDQ = new DataGridViewComboBoxCell();
                sCellDQ.FlatStyle = FlatStyle.System;
                sCellDQ.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
                sCellDQ.DropDownWidth = 10;
                sCellDQ.Items.Add("左对齐");
                sCellDQ.Items.Add("居中");
                sCellDQ.Items.Add("右对齐");
                grdField.Rows[i].Cells[FiDuiQiCol] = sCellDQ;
                
                grdField.Rows[i].Cells[FiNoCol].Value=Convert.ToString(grdField.RowCount - 1);
                grdField.Rows[i].Cells[FiFieldNameCol].Value=Ds.Tables[0].Rows[i]["column_name"].ToString().Trim();
                grdField.Rows[i].Cells[FiShowCol].Value = "1";
                grdField.Rows[i].Cells[FiDuiQiCol].Value = "左对齐";
                grdField.Rows[i].Cells[FiDecCol].Value = "";
                //
                DataGridViewCheckBoxCell sCell = new DataGridViewCheckBoxCell();
                sCell.ThreeState = false;
                sCell.Value = 1; 
                grdField.Rows[i].Cells[FiShowCol] = sCell;
                //
                if (Ds.Tables[0].Rows[i]["column_name"].ToString().Trim().ToUpper().Substring(0, 1) == "H")//H开头的列隐藏
                {
                    grdCondition.Rows[i].Visible=false;
                    grdField.Rows[i].Visible = false;
                }
                else
                {
                    //gridorder  lstorder
                    lstOrder.Items.Add(Ds.Tables[0].Rows[i]["column_name"].ToString().Trim());
                }
            }
            //加载方案
            if (!b)
            {
                Sub_GetSchemeInfo();
            }
            //
 
        }
 
 
        //读取方案信息
        private void Sub_GetSchemeInfo()  //Lock
        {
            //当前选中方案,若没有选中则为 默认方案,若不存在默认方案则自动新增
            if (HInterID == 0)
            {
                if (oItem.ShowDefault(this.ModName))
                {
                    HInterID = oItem.HInterID;
                }
                else//不存在则 生成默认方案
                {
                    return; 
                }
            }
            if (!oItem.ShowBill(HInterID, ref Pub_Class.ClsPub.sExeReturnInfo))
                return;
            foreach (Clsxt_ICSchemeSub oSub in oItem.DetailColl)
            {
                //循环控件,找到则赋值
                foreach (Control ct in this.tabPage1.Controls)
                {
                    if (oSub.HKey.Trim().ToLower() == ct.Name.Trim().ToLower())
                    {
                        if (ct.Name.Trim().ToLower().Substring(0, 3) == "txt" || ct.Name.Trim().ToLower().Substring(0, 3) == "cmb" ) 
                        {
                            ct.Text = oSub.HValue.Trim();
                        }
                    }
                }
                foreach (Control ct in this.panel8.Controls)
                {
                    if (oSub.HKey.Trim().ToLower() == ct.Name.Trim().ToLower())
                    {
                        if (ct.Name.Trim().ToLower().Substring(0, 3) == "txt" || ct.Name.Trim().ToLower().Substring(0, 3) == "cmb")
                        {
                            ct.Text = oSub.HValue.Trim();
                        }
                    }
                }
                foreach (Control ct in this.panel9.Controls)
                {
                    if (oSub.HKey.Trim().ToLower() == ct.Name.Trim().ToLower())
                    {
                        if (ct.Name.Trim().ToLower().Substring(0, 3) == "txt" || ct.Name.Trim().ToLower().Substring(0, 3) == "cmb")
                        {
                            ct.Text = oSub.HValue.Trim();
                        }
                    }
                }
            }
            //得到3个GRID
            try
            {
                Pub_Class.ClsSqlHelper oCn2 = new Pub_Class.ClsSqlHelper();
                DataSet DSet;
                for (int i = 0; i < grdCondition.RowCount; i++)
                {
                    DSet = oCn2.RunProcReturn("select * from Xt_grdCondition where HInterID=" + HInterID.ToString() + " and HRow=" + i, "Xt_grdCondition");
                    if (Pub_Class.ClsPub.isInt(DSet.Tables[0].Rows.Count) != 0)
                    {
                        grdCondition.Rows[i].Cells[0].Value = DSet.Tables[0].Rows[0]["HIDCol"];
                        grdCondition.Rows[i].Cells[1].Value = DSet.Tables[0].Rows[0]["HBracketLCol"];
                        grdCondition.Rows[i].Cells[2].Value = DSet.Tables[0].Rows[0]["HFieldNameCol"];
                        grdCondition.Rows[i].Cells[3].Value = DSet.Tables[0].Rows[0]["HControlCol"];
                        grdCondition.Rows[i].Cells[4].Value = DSet.Tables[0].Rows[0]["HConditionCol"];
                        grdCondition.Rows[i].Cells[5].Value = DSet.Tables[0].Rows[0]["HBracketRCol"];
                        grdCondition.Rows[i].Cells[6].Value = DSet.Tables[0].Rows[0]["HRelationCol"];
                        if (DSet.Tables[0].Rows[0]["HFieldNameCol"].ToString().Trim().ToUpper().Substring(0, 1) == "H")//H开头的列隐藏
                        {
                            grdCondition.Rows[i].Visible = false;
                        }
                        else
                        {
                            grdCondition.Rows[i].Visible = true;
                        }
                    }
                }
                DSet = null;
                for (int i = 0; i < grdField.RowCount; i++)
                {
                    DSet = oCn2.RunProcReturn("select * from Xt_grdField where HInterID=" + HInterID.ToString() + " and HRow=" + i, "Xt_grdField");
                    if (Pub_Class.ClsPub.isInt(DSet.Tables[0].Rows.Count) != 0)
                    {
                        grdField.Rows[i].Cells[0].Value = DSet.Tables[0].Rows[0]["HFiFieldName"];
                        grdField.Rows[i].Cells[1].Value = DSet.Tables[0].Rows[0]["HFiNo"];
                        grdField.Rows[i].Cells[2].Value = Pub_Class.ClsPub.isBool(DSet.Tables[0].Rows[0]["HFiShow"]);
                        if (Pub_Class.ClsPub.isStrNull(DSet.Tables[0].Rows[0]["HFiDuiQi"]) == "")
                        {
                            grdField.Rows[i].Cells[3].Value = "左对齐";
                        }
                        else
                        {
                            grdField.Rows[i].Cells[3].Value = DSet.Tables[0].Rows[0]["HFiDuiQi"];
                        }
                        if (Pub_Class.ClsPub.isInt(DSet.Tables[0].Rows[0]["HDec"]) < 0 || Pub_Class.ClsPub.isInt(DSet.Tables[0].Rows[0]["HDec"]) >9)
                        {
                            grdField.Rows[i].Cells[4].Value = "";
                        }
                        else
                        {
                            grdField.Rows[i].Cells[4].Value = Pub_Class.ClsPub.isInt(DSet.Tables[0].Rows[0]["HDec"]);
                        }
                        if (DSet.Tables[0].Rows[0]["HFiNo"].ToString().Trim().ToUpper().Substring(0, 1) == "H")//H开头的列隐藏
                        {
                            grdField.Rows[i].Visible = false;
                        }
                        else
                        {
                            grdField.Rows[i].Visible = true;
                        }
                    }
                }
                oCn2.CnClose();
                oCn2.CnDispose();
            }
            catch (Exception e)
            {
                return;
            }
        }
        
        //
        private bool Sub_DeleteSchemeInfo()
        {
            if (lvScheme.FocusedItem == null)
            {
                return false;
            }
            if (lvScheme.FocusedItem.Text == "默认方案")
            {
                MessageBox.Show("不能删除默认方案!");
                return false;
            }
            Int64 sInterID = Pub_Class.ClsPub.isLong(lvScheme.FocusedItem.Tag);
            if (sInterID != 0)
            {
                oItem.DeleteBillMain(sInterID);
                lvScheme.Items.RemoveAt(lvScheme.FocusedItem.Index);
                return true;
            }
            return false;
        }
 
        //保存方案
        private bool Sub_SaveSchemeInfo()  //Lock
        {
            
            if (HInterID == 0)
            {
                if (oItem.ShowDefault(this.ViewName))//保存当前选中方案,若没有选中则为 默认方案
                {
                    HInterID = oItem.HInterID;
                    BillStatus =Pub_Class.ClsPub.Enum_BillStatus.BillStatus_Modify;
                }
                else//不存在则 生成默认方案
                {
                    BillStatus = Pub_Class.ClsPub.Enum_BillStatus.BillStatus_AddNew;
                }
            }
            else
            {
                BillStatus = Pub_Class.ClsPub.Enum_BillStatus.BillStatus_Modify;
            }
            //加载到类
            oItem.HBillName = ModName;
            oItem.HBillType = oItem.MvarItemKey;
            oItem.HStopflag = false;
            oItem.HUserCode = Pub_Class.ClsPub.CurUserName;
            //
            oItem.DetailColl.Clear();
            foreach (Control ct in this.tabPage1.Controls)
            {
                Clsxt_ICSchemeSub oSub = new Clsxt_ICSchemeSub();
                if (ct.Name.Trim().ToLower().Substring(0, 3) == "txt" || ct.Name.Trim().ToLower().Substring(0, 3) == "cmb" )
                {
                    oSub.HKey = ct.Name.Trim();
                    oSub.HValue = ct.Text.Trim();
                    oSub.HInterID = this.HInterID;
                    oItem.DetailColl.Add(oSub);
                }
            }
            foreach (Control ct in this.panel8.Controls)
            {
                Clsxt_ICSchemeSub oSub = new Clsxt_ICSchemeSub();
                if (ct.Name.Trim().ToLower().Substring(0, 3) == "txt" || ct.Name.Trim().ToLower().Substring(0, 3) == "cmb")
                {
                    oSub.HKey = ct.Name.Trim();
                    oSub.HValue = ct.Text.Trim();
                    oSub.HInterID = this.HInterID;
                    oItem.DetailColl.Add(oSub);
                }
            }
            foreach (Control ct in this.panel9.Controls)
            {
                Clsxt_ICSchemeSub oSub = new Clsxt_ICSchemeSub();
                if (ct.Name.Trim().ToLower().Substring(0, 3) == "cmb")
                {
                    oSub.HKey = ct.Name.Trim();
                    oSub.HValue = ct.Text.Trim();
                    oSub.HInterID = this.HInterID;
                    oItem.DetailColl.Add(oSub);
                }
            }
            //
            
            if (lvScheme.FocusedItem == null)
            {
                oItem.HName = "默认方案";
            }
            else
            {
                oItem.HName = lvScheme.FocusedItem.Text;
            }
            if (BillStatus == Pub_Class.ClsPub.Enum_BillStatus.BillStatus_Modify)
            {
                if (!oItem.ModifyBill(HInterID, ref  Pub_Class.ClsPub.sExeReturnInfo))
                    return false;
            }
            else if (BillStatus == Pub_Class.ClsPub.Enum_BillStatus.BillStatus_AddNew)
            {
 
                if (!oItem.AddBill(ref Pub_Class.ClsPub.sExeReturnInfo, HInterID))
                    return false;
                else
                    HInterID = oItem.HInterID;
            }
            else
            {
                return false;
            }
            //保存3个GRID
            try
            {
                Pub_Class.ClsSqlHelper oCn1 = new Pub_Class.ClsSqlHelper();
                oCn1.RunProc("delete Xt_grdCondition where   HInterID=" + HInterID.ToString());
                for (int i = 0; i < grdCondition.RowCount; i++)
                {
                   
                    oCn1.RunProc("Insert Into Xt_grdCondition   " +
                    "(HInterID,HUserID,HBillName,HRow,HIDCol,HBracketLCol,HFieldNameCol,HControlCol" +
                    ",HConditionCol,HBracketRCol,HRelationCol" +
                    ") " +
                    " values(" + HInterID.ToString() + ",'" + Pub_Class.ClsPub.CurUserName + "','" + ViewName.Trim() + "'," + i +
                    ",'" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[0].Value) + "'" +
                    ",'" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[1].Value) + "'" +
                    ",'" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[2].Value) + "'" +
                    ",'" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[3].Value) + "'" +
                    ",'" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[4].Value).Replace("'", "''") + "'" +
                    ",'" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[5].Value).Replace("'", "''") + "'" +
                    ",'" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[6].Value) + "')");
                }
                oCn1.RunProc("delete Xt_grdField where HinterID=" + HInterID.ToString());
                for (int i = 0; i < grdField.RowCount; i++)
                {
 
                    oCn1.RunProc("Insert Into Xt_grdField  " +
                    "(HInterID,HUserID,HBillName,HRow,HFiFieldName,HFiNo,HFiShow,HFiDuiQi" +
                    ") " +
                    " values("+HInterID.ToString()+",'" + Pub_Class.ClsPub.CurUserName + "','" + ViewName.Trim() + "'," + i +
                    ",'" + Pub_Class.ClsPub.isStrNull(grdField.Rows[i].Cells[0].Value) + "'" +
                    ",'" + Pub_Class.ClsPub.isStrNull(grdField.Rows[i].Cells[1].Value) + "'" +
                    "," + Convert.ToString(Pub_Class.ClsPub.isBool(grdField.Rows[i].Cells[2].Value) ? 1 : 0) + 
                    ",'"+Pub_Class.ClsPub.isStrNull(grdField.Rows[i].Cells[3].Value)+"'"+
                    ")");
                }
                oCn1.CnClose();
                oCn1.CnDispose();
                return true;
            }
            catch (Exception e)
            {
                Pub_Class.ClsPub.sExeReturnInfo = Pub_Class.ClsPub.sExeReturnInfo + e.Message;
                return false;
            }
 
        }
 
 
        //取消 
        private void cmdCancel_Click(object sender, EventArgs e)
        {
            this.Tag = "CANCEL";
            //Sub_SaveSchemeInfo();
            this.Visible = false;
        }
 
 
        private string GetShowItem()//Lock
        {
            string sSql = "";
            for (int i = 0; i < grdField.RowCount; i++)
            {
                if (grdField.Rows[i].Visible == false || Pub_Class.ClsPub.isBool(grdField.Rows[i].Cells[FiShowCol].Value) != false)
                {
                    sSql = sSql + ",[" + Pub_Class.ClsPub.isStrNull(grdField.Rows[i].Cells[FiFieldNameCol].Value) + "]";
                }
            }
            if (sSql.Trim() == "")
            {
                return "*";
            }
            else
            {
                return sSql.Trim().Substring(1, sSql.Trim().Length - 1);
            }
        }
 
 
        //得到过滤条件和排序条件
        private bool GetSql()//Lock
        {
            string tSql = "";
            string tFilter = "";
            string sEngCondi = "";
            string sLinkCondi = "";
            FieldsArray = tSql;
            //得到显示项目
            string HeadSql = "";
            HeadSql=GetShowItem();
            //
            long ShowCount = 0;
            if (Pub_Class.ClsPub.isLong(txtHShowCount.Text) < 1)
            {
                ShowCount = 1;
            }
            else
            {
                ShowCount = Pub_Class.ClsPub.isLong(txtHShowCount.Text);
            }
            //
            tSql = "select Top " + ShowCount.ToString() + " " + HeadSql + " from " + mvarViewName.Trim() + " Where 1=1 ";
            for (int i = 0; i < grdCondition.RowCount; i++)
            {
                sEngCondi = CHStoENG(Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[3].Value));
                sLinkCondi = CHStoENG(Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[6].Value));  // and or
                if (sEngCondi.Trim().Length != 0)
                {
                    switch (sEngCondi.Trim().ToUpper())
                    {
                        case "LIKE":
                            tFilter = tFilter + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[1].Value) + " [" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[2].Value) + "] " + " LIKE '%" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[4].Value).Trim().Replace("'", "''") + "%' " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[5].Value) + " " + sLinkCondi.Trim() + " ";
                            break;
                        case "NOLIKE":
                            tFilter = tFilter + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[1].Value) + " [" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[2].Value) + "] " + " NOT LIKE '%" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[4].Value).Trim().Replace("'", "''") + "%' " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[5].Value) + " " + sLinkCondi.Trim() + " ";
                            break;
                        case "LIKEL":
                            tFilter = tFilter + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[1].Value) + " [" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[2].Value) + "] " + " LIKE '" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[4].Value).Trim().Replace("'", "''") + "%' " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[5].Value) + " " + sLinkCondi.Trim() + " ";
                            break;
                        case "LIKER":
                            tFilter = tFilter + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[1].Value) + " [" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[2].Value) + "] " + " LIKE '%" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[4].Value).Trim().Replace("'", "''") + "' " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[5].Value) + " " + sLinkCondi.Trim() + " ";
                            break;
                        default:
                            switch (Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[0].Value).Trim().ToUpper())
                            {
                                case "BIT":
                                    tFilter = tFilter + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[1].Value) + " [" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[2].Value) + "] " + sEngCondi + " " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[4].Value).Trim() + "  " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[5].Value) + " " + sLinkCondi.Trim() + " ";
                                    break;
                                case "MONEY":
                                    tFilter = tFilter + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[1].Value) + " [" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[2].Value) + "] " + sEngCondi + "" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[4].Value) + " " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[5].Value) + " " + sLinkCondi.Trim() + " ";
                                    break;
                                case "DECIMAL":
                                    tFilter = tFilter + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[1].Value) + " [" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[2].Value) + "] " + sEngCondi + "" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[4].Value) + " " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[5].Value) + " " + sLinkCondi.Trim() + " ";
                                    break;
                                default:
                                    tFilter = tFilter + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[1].Value) + " [" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[2].Value) + "] " + sEngCondi + "'" + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[4].Value) + "' " + Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[5].Value) + " " + sLinkCondi.Trim() + " ";
                                    break;
                            }
                            break;
                    }
                }
                else
                {
                    if (Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[1].Value).Trim().Length != 0 || Pub_Class.ClsPub.isStrNull(grdCondition.Rows[i].Cells[5].Value).Trim().Length != 0)
                    {
                        MessageBox.Show("第" + i.ToString() + "行没有条件,不应该有括号出现,请取消此括号!", "提示");
                        return false;
                    }
                }
            }
            if (tFilter.Trim().Length != 0)
            {
                tFilter = tFilter.Substring(0, tFilter.Trim().Length - 3);
                SqlStr = tSql + " AND " + tFilter;
            }
            else
            {
                SqlStr = tSql;
            }
            //审核
            if (cmbCheck.Text.Trim() != "全部")
            {
                if (cmbCheck.Text.ToString() == "已审")
                {
                    SqlStr = SqlStr + " AND 审核人<>''";
                }
                else
                {
                    SqlStr = SqlStr + " AND 审核人=''";
                }
            }
            
            //关闭
            if (cmbClose.Text.Trim() != "全部")
            {
                if (cmbClose.Text.ToString() == "已关闭")
                {
                    SqlStr = SqlStr + " AND 关闭人<>''";
                }
                else
                {
                    SqlStr = SqlStr + " AND 关闭人=''";
                }
            }
           
 
            //作废
            if (cmbDelete.Text.Trim() != "全部")
            {
                if (cmbDelete.Text.ToString() == "作废")
                {
                    SqlStr = SqlStr + " AND 作废人<>''";
                }
                else
                {
                    SqlStr = SqlStr + " AND 作废人=''";
                }
            }
            //时间
            if(cmbTime.Text.Trim()!="全部")
            {
                if (cmbTime.Text.Trim() == "本日")
                {
                    SqlStr = SqlStr +  " AND DATEDIFF(dd, 日期, getdate())=0 ";
                }
                else if (cmbTime.Text.Trim() == "本周")
                {
                    SqlStr = SqlStr + " AND DATEDIFF(week,日期,getdate())=0 ";
                }
                else if (cmbTime.Text.Trim() == "本期")
                {
                    SqlStr = SqlStr + " AND DATEDIFF(month,日期,getdate())=0 ";
                }
                else if (cmbTime.Text.Trim() == "上一周")
                {
                    SqlStr = SqlStr + " AND 日期 between convert(varchar(10),dateadd(d,-7,getdate()),120) and  convert(varchar(10),getdate(),120) ";
                }
                else if (cmbTime.Text.Trim() == "下一周")
                {
                    SqlStr = SqlStr + " AND 日期 between convert(varchar(10),getdate(),120)  and  convert(varchar(10),dateadd(d,7,getdate()),120) ";
                }
                else
                {
 
                }
            }
 
            return true;
        }
        //确认
        private void cmdOk_Click(object sender, EventArgs e)
        {
            Sub_SaveSchemeInfo();
            if (GetSql())
            {
                this.Tag = "OK";
                this.Visible=false;
            }
        }
        //初始化网格
        private void initGrid()
        {
             //
 
            grdCondition.RowTemplate.Height = 18;
            grdCondition.RowTemplate.MinimumHeight = 18;
            grdCondition.ColumnHeadersHeight = 35;
            grdCondition.RowHeadersVisible = false;
            grdCondition.ColumnHeadersVisible = true;
            grdCondition.ColumnCount = 7;
            grdCondition.RowCount = 1;
            grdCondition.EnableHeadersVisualStyles = false;
            grdCondition.AllowUserToAddRows = false;             //是否允许自增--否
            grdCondition.AllowUserToDeleteRows = false;          //是否允许删除--否 
            grdCondition.AllowUserToResizeColumns = true;         //允许调整列宽--是
            grdCondition.AllowUserToResizeRows = false;           //允许调整行高--否
            grdCondition.AllowUserToOrderColumns = false;
            grdCondition.GridColor = Color.LightGray;
            grdCondition.Columns[BracketLCol].HeaderText = "左括号";
            grdCondition.Columns[FieldNameCol].HeaderText = "字段名称";
            grdCondition.Columns[ControlCol].HeaderText = "比较关系";
            grdCondition.Columns[ConditionCol].HeaderText = "数值";
            grdCondition.Columns[BracketRCol].HeaderText = "右括号";
            grdCondition.Columns[RelationCol].HeaderText = "逻辑";
            //
            grdCondition.EditMode = DataGridViewEditMode.EditOnEnter;      //编辑模式
            grdCondition.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
            grdCondition.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            grdCondition.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; //允许用户调整列宽
            grdCondition.Columns[IDCol].Visible = false;
            
            grdCondition.Columns[BracketLCol].Width = 50;
            grdCondition.Columns[FieldNameCol].Width = 120;
            grdCondition.Columns[ControlCol].Width = 60;
            grdCondition.Columns[ConditionCol].Width = 90;
            grdCondition.Columns[BracketRCol].Width = 50;
            grdCondition.Columns[RelationCol].Width = 50;
            for (int i = 0; i < grdCondition.ColumnCount; i++)
            {
                grdCondition.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
            }
            //grdCondition.set_ColWidth(BracketLCol, 700);
            //grdCondition.set_ColWidth(FieldNameCol, 1500);
            //grdCondition.set_ColWidth(ControlCol, 800);
            //grdCondition.set_ColWidth(ConditionCol, 1500);
            //grdCondition.set_ColWidth(BracketRCol, 800);
            //grdCondition.set_ColWidth(RelationCol, 500); 
 
            //grdorder
            //grdOrder.Cols =2;
            //grdOrder.Rows = 1;
            //grdOrder.set_TextMatrix(0, OrFieldNameCol, "排序字段");
            //grdOrder.set_TextMatrix(0, OrDescCol, "升降序");
            //grdOrder.set_ColComboList(OrDescCol, "升序|降序");
            //grdOrder.Editable = VSFlex7.EditableSettings.flexEDKbdMouse;
            //grdOrder.set_FixedAlignment(-1, VSFlex7.AlignmentSettings.flexAlignCenterCenter);
            //grdOrder.ExtendLastCol = false;
            //grdOrder.RowHeightMin = 280;
            //grdOrder.set_RowHeight(0, 450);
            //grdOrder.set_ColWidth(OrFieldNameCol, 1500);
            //grdOrder.set_ColWidth(OrDescCol, 1500);
 
            //grdfield  
            //
            grdField.RowTemplate.Height = 18;
            grdField.RowTemplate.MinimumHeight = 18;
            grdField.ColumnHeadersHeight = 35;
            grdField.RowHeadersVisible = false;
            grdField.ColumnHeadersVisible = true;
            grdField.ColumnCount = 5;
            grdField.RowCount = 1;
            grdField.Columns[FiFieldNameCol].HeaderText = "字段名称";
            grdField.Columns[FiNoCol].HeaderText = "序号";
            grdField.Columns[FiShowCol].HeaderText = "显示";
            grdField.Columns[FiDuiQiCol].HeaderText = "对齐方式";
            grdField.EnableHeadersVisualStyles = false;
            grdField.AllowUserToAddRows = false;             //是否允许自增--否
            grdField.AllowUserToDeleteRows = false;          //是否允许删除--否 
            grdField.AllowUserToResizeColumns = true;         //允许调整列宽--是
            grdField.AllowUserToResizeRows = false;           //允许调整行高--否
            grdField.AllowUserToOrderColumns = false;
            grdField.GridColor = Color.LightGray;
            //
            grdField.ReadOnly = false;
            grdField.EditMode = DataGridViewEditMode.EditOnEnter;      //编辑模式
            grdField.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            grdField.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            grdField.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; //允许用户调整列宽
            //
            grdField.Columns[FiFieldNameCol].Width = 150;
            grdField.Columns[FiNoCol].Width = 50;
            grdField.Columns[FiShowCol].Width = 100;
            for (int i = 0; i < grdField.ColumnCount; i++)
            {
                grdField.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
            }
             
 
 
        }
 
        //将中文转为英文
        private string CHStoENG(string sCHS)
        {
            switch (sCHS)
            {
                case "包含":
                    return "LIKE";
                case "左包含":
                    return "LIKEL";
                case "右包含":
                    return "LIKER";
                case "不包含":
                    return "NOLIKE";
                case "并且":
                    return "AND";
                case "或者":
                    return "OR";
                default:
                    return sCHS;
 
            }
        }
       
        
        //初始化
        private void frmBillQueryCondition_Base_Load(object sender, EventArgs e)
        {
            this.cmbCheck.Text = "全部";
            this.cmbClose.Text = "全部";
            this.cmbDelete.Text = "全部";
            this.cmbTime.Text = "全部";
            this.cmbHComplete.Text = "是";
            tabControl1.TabPages.Remove(tabPage2);
            initGrid();
        }
        //初始化2
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            //加载方案
            SetScheme();
            //
            SetViewName(ViewName,false);
            //
            if (bFst)
            {
                //当第一次加载时,判断是否默认方案
                if (cmbDefault.Text == "是")
                {
                    cmdOk_Click(sender, e);
                }
            }
        }
    //  
 
        //获取 方案项目
        private void SetScheme()
        {
            lvScheme.Items.Clear();
            ListViewItem oSub = new ListViewItem();
            oSub.Tag = 0;
            oSub.Text = "默认方案";
            oSub.ImageIndex = 0;
            lvScheme.Items.Add(oSub);
            //
            if (oItem.GetBillList(this.ModName, ref Pub_Class.ClsPub.sExeReturnInfo))
            {
                foreach (Clsxt_ICSchemeMain oMain in oItem.MainColl)
                {
                    ListViewItem oSub2 = new ListViewItem();
                    oSub2.Tag = oMain.HInterID;
                    oSub2.Text = oMain.HName;
                    oSub2.ImageIndex = 0;
                    lvScheme.Items.Add(oSub2);
                }
            }
 
            //
        }
 
        //加括号
        private void cmdBracket_Click(object sender, EventArgs e)
        {
            int BRow = -1, ERow = 0;
            if (grdCondition.SelectedCells == null || grdCondition.SelectedCells.Count==0)
            {
                 
                return;
            }
            //找最大行,最小行
            for (int i = 0; i < grdCondition.SelectedCells.Count; i++)
            {
                if (grdCondition.SelectedCells[i].RowIndex > ERow)
                {
                    ERow = grdCondition.SelectedCells[i].RowIndex;
                }
                if (BRow == -1)
                {
                    BRow = grdCondition.SelectedCells[i].RowIndex;
                }
                else
                {
                    if (grdCondition.SelectedCells[i].RowIndex < BRow)
                    {
                        BRow = grdCondition.SelectedCells[i].RowIndex;
                    }
                }
            }
            //
            if (BRow != -1)
            {
                grdCondition.Rows[BRow].Cells[BracketLCol].Value = Pub_Class.ClsPub.isStrNull(grdCondition.Rows[BRow].Cells[BracketLCol].Value) + "(";
                grdCondition.Rows[ERow].Cells[BracketRCol].Value = Pub_Class.ClsPub.isStrNull(grdCondition.Rows[ERow].Cells[BracketRCol].Value) + ")";
            }
        }
        //减括号
        private void cmdUNBracket_Click(object sender, EventArgs e)
        {
            int BRow = -1, ERow = 0;
            if (grdCondition.SelectedCells == null || grdCondition.SelectedCells.Count == 0)
            {
 
                return;
            }
            //找最大行,最小行
            for (int i = 0; i < grdCondition.SelectedCells.Count; i++)
            {
                if (grdCondition.SelectedCells[i].RowIndex > ERow)
                {
                    ERow = grdCondition.SelectedCells[i].RowIndex;
                }
                if (BRow == -1)
                {
                    BRow = grdCondition.SelectedCells[i].RowIndex;
                }
                else
                {
                    if (grdCondition.SelectedCells[i].RowIndex < BRow)
                    {
                        BRow = grdCondition.SelectedCells[i].RowIndex;
                    }
                }
            }
            //
            if(Pub_Class.ClsPub.isStrNull(grdCondition.Rows[BRow].Cells[BracketLCol].Value)!="" && Pub_Class.ClsPub.isStrNull(grdCondition.Rows[ERow].Cells[BracketRCol].Value)!="" )
            {
                string s;
                s = Pub_Class.ClsPub.isStrNull(grdCondition.Rows[BRow].Cells[BracketLCol].Value);
                grdCondition.Rows[BRow].Cells[BracketLCol].Value = s.Substring(0, s.Length - 1);
                s = "";
                s = Pub_Class.ClsPub.isStrNull(grdCondition.Rows[ERow].Cells[BracketRCol].Value);
                grdCondition.Rows[ERow].Cells[BracketRCol].Value = s.Substring(0, s.Length - 1);
            }
            else
            {
                if (Pub_Class.ClsPub.isStrNull(grdCondition.Rows[BRow].Cells[BracketLCol].Value) == "")
                {
                    MessageBox.Show("选择的第一行没有括号!", "提示");
                }
                else
                {
                    MessageBox.Show("选择的最后一行没有括号!", "提示");
                }
            }
        }
        //复制
        private void cmdCopy_Click(object sender, EventArgs e)
        {
            if (grdCondition.CurrentRow!=null)
            {
                CopyField =Pub_Class.ClsPub.isStrNull(grdCondition.Rows[grdCondition.CurrentRow.Index].Cells[FieldNameCol].Value);
                CopyDataType = Pub_Class.ClsPub.isStrNull(grdCondition.Rows[grdCondition.CurrentRow.Index].Cells[IDCol].Value);
                cmdPaste.Enabled = true;
            }
        }
        //黏贴
        private void cmdPaste_Click(object sender, EventArgs e)
        {
            grdCondition.Rows.Insert(grdCondition.CurrentRow.Index,1);
            //
            grdCondition.Rows[grdCondition.CurrentRow.Index-1].Cells[IDCol].Value=CopyDataType;
            grdCondition.Rows[grdCondition.CurrentRow.Index-1].Cells[FieldNameCol].Value= CopyField;
            //
            DataGridViewComboBoxCell sCellRel = new DataGridViewComboBoxCell();
            sCellRel.FlatStyle = FlatStyle.System;
            sCellRel.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
            sCellRel.DropDownWidth = 10;
            sCellRel.Items.Add("并且");
            sCellRel.Items.Add("或者");
            grdCondition.Rows[grdCondition.CurrentRow.Index - 1].Cells[RelationCol] = sCellRel;
            grdCondition.Rows[grdCondition.CurrentRow.Index - 1].Cells[RelationCol].Value = "并且";
            //
            DataGridViewComboBoxCell sCellCom = new DataGridViewComboBoxCell();
            sCellCom.FlatStyle = FlatStyle.System;
            sCellCom.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
            sCellCom.DropDownWidth = 10;
            sCellCom.Items.Add(" ");
            sCellCom.Items.Add("=");
            sCellCom.Items.Add(">");
            sCellCom.Items.Add(">=");
            sCellCom.Items.Add("<");
            sCellCom.Items.Add("<=");
            sCellCom.Items.Add("<>");
            sCellCom.Items.Add("包含");
            sCellCom.Items.Add("左包含");
            sCellCom.Items.Add("右包含");
            sCellCom.Items.Add("不包含");
            grdCondition.Rows[grdCondition.CurrentRow.Index - 1].Cells[ControlCol] = sCellCom;
            //
        }
        //删除
        private void cmdDelete_Click(object sender, EventArgs e)
        {
            if (grdCondition.CurrentRow!=null)
            {
                //if (ClsPub.isStrNull(grdCondition.get_TextMatrix(grdCondition.Row, BracketLCol)) != ""
                //    || ClsPub.isStrNull(grdCondition.get_TextMatrix(grdCondition.Row, BracketRCol)) != "")
                //{
                //    MessageBox.Show("被删除行不能有括号!", "提示");
                //    return;
                //}
                grdCondition.Rows.RemoveAt(grdCondition.CurrentRow.Index);
            }
        }
        //恢复
        private void cmdRestore_Click(object sender, EventArgs e)
        {
            SetViewName(ViewName,true);
        }
 
        private void bc_Click(object sender, EventArgs e)
        {
            if (lvScheme.FocusedItem == null)
            {
                MessageBox.Show("没有选中方案!");
                return;
            }
            if (MessageBox.Show("确定要保存当前方案到数据库?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
            {
                return;
            }
            Int64 sInterID = 0;
            sInterID = Pub_Class.ClsPub.isLong(lvScheme.FocusedItem.Tag);
            if (sInterID == 0)
            {
                MessageBox.Show("错误的方案!");
                return;
            }
            HInterID = sInterID;
            Sub_SaveSchemeInfo();
        }
 
        private void sc_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要删除当前项目?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
            {
                return;
            }
            Sub_DeleteSchemeInfo();
        }
 
        //private void grdField_BeforeEdit(object sender, AxVSFlex7._IVSFlexGridEvents_BeforeEditEvent e)
        //{
        //    if (e.col != FiShowCol)
        //    {
        //        e.cancel = true;
        //    }
        //}
 
   
 
        private void cmdAllSelect_Click(object sender, EventArgs e)
        { 
            for (int i = 0; i < grdField.RowCount; i++)
            {
                grdField.Rows[i].Cells[FiShowCol].Value = true;
            }
        }
 
        private void cmdAllClear_Click(object sender, EventArgs e)
        { 
            for (int i = 0; i < grdField.RowCount; i++)
            {
                grdField.Rows[i].Cells[FiShowCol].Value = false;
            }
        }
        //加载到GRID
        private void LoadToGrid()
        {
            //if (lstOrder.SelectedIndex >= 0)
            //{
            //    //是否存在
            //    string sSelectItem = "";
            //    sSelectItem=lstOrder.Items[lstOrder.SelectedIndex].ToString();
            //    for (int i = grdOrder.FixedRows; i < grdOrder.Rows; i++)
            //    {
            //        if (ClsPub.isStrNull(grdOrder.get_TextMatrix(i, OrFieldNameCol)) == sSelectItem)
            //        {
            //            MessageBox.Show("您选择的项目已存在!");
            //            return;
            //        }
            //    }
            //    //加载到GRID
            //    grdOrder.AddItem("");
            //    grdOrder.set_TextMatrix(grdOrder.Rows - 1, OrFieldNameCol, sSelectItem);
            //    grdOrder.set_TextMatrix(grdOrder.Rows - 1, OrDescCol, "升序");
            //    grdOrder.set_ColComboList(OrDescCol, "升序|降序");
            //}
        }
        //
        private void cmdAddNew_Click(object sender, EventArgs e)
        {
            LoadToGrid();
        }
 
        private void lstOrder_DoubleClick(object sender, EventArgs e)
        {
            LoadToGrid();
        }
 
        private void cmdDel_Click(object sender, EventArgs e)
        {
            if (grdOrder.CurrentRow!=null)
            {
                grdOrder.Rows.RemoveAt(grdOrder.CurrentRow.Index); 
            }
        }
 
         
        private void grdCondition_KeyDown(object sender, KeyEventArgs e)
        {
            Sub_GridKeyView(e.KeyValue, grdCondition.CurrentRow.Index, grdCondition.CurrentCell.ColumnIndex, grdCondition, EditingControl);
        }
 
        private void grdField_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
 
            if (grdField.CurrentCell.ColumnIndex != FiShowCol && grdField.CurrentCell.ColumnIndex != FiDuiQiCol)
            {
                e.Cancel = true;
            }
            else
            {
                //
            }
        }
 
        private void grdCondition_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            if (grdCondition.CurrentCell.ColumnIndex != ControlCol && grdCondition.CurrentCell.ColumnIndex != ConditionCol && grdCondition.CurrentCell.ColumnIndex != RelationCol)
            {
                e.Cancel = true;
            }
            else
            {
                //
            }
        }
 
        DataGridViewTextBoxEditingControl EditingControl;
        private void EditingControl_KeyDown(object sender, KeyEventArgs e)
        {
            //业务处理 
            Sub_GridKeyView(e.KeyValue, grdCondition.CurrentRow.Index, grdCondition.CurrentCell.ColumnIndex, grdCondition, EditingControl);
        }
 
        private void grdCondition_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (grdCondition.CurrentCell != null)
            {
                if (e.Control is DataGridViewTextBoxEditingControl)
                {
                    this.EditingControl = (DataGridViewTextBoxEditingControl)e.Control;
                    //增加委托处理 
                    this.EditingControl.KeyDown += new KeyEventHandler(this.EditingControl_KeyDown);
                }
 
            }
        }
 
        private void grdCondition_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (this.EditingControl != null)
            {
                EditingControl.KeyDown -= new KeyEventHandler(this.EditingControl_KeyDown);
                this.EditingControl = null;
            }
        }
 
       
 
        public virtual void Sub_GridKeyView(int sKeyCode, int sRow, int sCol, DataGridView grdCondition,DataGridViewTextBoxEditingControl oEdit)
        {
            //
        }
 
        private void cmdUp2_Click(object sender, EventArgs e)
        {
            if (grdField.CurrentRow == null)
                return;
            if (grdField.CurrentRow.Index > 0)
            {
 
            }
        }
 
        private void cmdDown2_Click(object sender, EventArgs e)
        {
 
        }
 
        private void cmdUp_Click(object sender, EventArgs e)
        {
 
        }
 
        private void cmdDown_Click(object sender, EventArgs e)
        {
 
        }
 
        frm_SetName ofrmDlg = new frm_SetName();
 
        //新增方案 
        private void xz_Click(object sender, EventArgs e)
        {
            //弹出框 设置方案名字
            ofrmDlg.ShowDialog();
            if (ofrmDlg.isOk)
            {
               
                string s = "";
                Int64 sInterID=0;
                s = ofrmDlg.txtHName.Text;
                //判断方案名是否重复
                for (int i = 0; i < lvScheme.Items.Count; i++)
                {
                    if (s.Trim() == lvScheme.Items[i].Text.Trim())
                    {
                        MessageBox.Show("已存在相同的方案名,请重新录入!");
                        return;
                    }
                }
                // 
                sInterID = Pub_Class.ClsPub.CreateBillID("0001", ref Pub_Class.ClsPub.sExeReturnInfo); //获取新ID
                if (s.Trim() != "" && sInterID !=0)
                {
                    ListViewItem oSub = new ListViewItem();
                    oSub.Tag = sInterID;
                    oSub.Text = s;
                    oSub.ImageIndex = 0;
                    lvScheme.Items.Add(oSub);
                }
            }
        }
 
        //选择方案 改变时 
        private void lvScheme_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lvScheme.FocusedItem == null)
            {
                return;
            }
            Int64 sInterID = 0;
            sInterID = Pub_Class.ClsPub.isLong(lvScheme.FocusedItem.Tag);
            HInterID = sInterID;
            SetViewName(ViewName, false); 
        }
    }
}