black-goat-me
2023-04-24 a759f9bf2a09b7c4ba10b8afa4e421a8abf511b4
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
namespace PlanM
{
    public partial class Sc_ICBomBillMuiList : Form
    {
        private int HItemIDCol = 0;
        private int HNumberCol = 0;
        const string ViewName = "h_v_Sc_ICBomBillMuiList";
        const string ModName = "BOM多级展开";
        //权限
        public const string ModRightName = "Sc_ICBomBillMuiList";
        public const string ModRightNameEdit = ModRightName + "_Edit";
        public const string ModRightNameCheck = ModRightName + "_Check";
        //
        public long  HItemID;//项目ID
        public long HItemGroupID;
        SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
        //
        public long HBomID = 0;
        TreeNode CurNode = new TreeNode();
        //拆分字符
        char spChar =Convert.ToChar( "~");
       
        public Sc_ICBomBillMuiList()
        {
            InitializeComponent();
        }
 
 
        //以下代码基本不需要修改
        #region 固定代码
 
        private void wl_Click(object sender, EventArgs e)
        {
            LoadTree();
            DisplaySub();
            Display();
        }
        //窗体加载
        private void KF_ICInventory_Load(object sender, EventArgs e)
        {
            lblCaption.Text = ModName;
            this.Text = ModName;
            LoadTree();
            initGrid();
        }
        //退出模块
        private void tc_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //刷新
        private void xs_Click(object sender, EventArgs e)
        {
            DisplaySub();
            Display();
        }
        //查询
        private void cx_Click(object sender, EventArgs e)
        {
            DisplaySub();
            Display();
        }
        //得到对应列
        private Int32 Fun_GetCol(string sCol)
        {
            for (int c = 0; c < grdMain.ColumnCount; c++)
            {
                if (DBUtility.ClsPub.isStrNull(grdMain.Columns[c].HeaderText).ToUpper().Trim() == sCol.Trim().ToUpper())
                {
                    return c;
                }
            }
            return 0;
        }
 
        private Int32 Fun_GetColSub(string sCol)
        {
            for (int c = 0; c < grdSub.ColumnCount; c++)
            {
                if (DBUtility.ClsPub.isStrNull(grdSub.Columns[c].HeaderText).ToUpper().Trim() == sCol.Trim().ToUpper())
                {
                    return c;
                }
            }
            return 0;
        }
 
        private Int32 Fun_GetColTree(string sCol)
        {
            for (int c = 0; c < grdTree.ColumnCount; c++)
            {
                if (DBUtility.ClsPub.isStrNull(grdTree.Columns[c].HeaderText).ToUpper().Trim() == sCol.Trim().ToUpper())
                {
                    return c;
                }
            }
            return 0;
        }
        //树型 单击
        private void tv_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            CurNode = e.Node;
            if (CurNode != null)
            {
                if (CurNode.Nodes.Count == 0)
                {
                    LoadAllNodes(CurNode);
                }
                //找到选中结点
                DisplayTree();
                //Display();
                //DisplaySub();
            }
 
        }
        
      
       
        //选中行是否正常
        private bool AllowRow()
        {
            if (grdMain.CurrentRow.Index >= 0 && grdMain.CurrentRow.Index <= grdMain.RowCount - 1)
                return true;
            else
                return false;
        }
 
        private void bclk_Click(object sender, EventArgs e)
        {
            //保存列宽
            DBUtility.ClsPub.SaveGridView(grdMain, this.Name, DBUtility.ClsPub.AppPath);
            DBUtility.ClsPub.SaveGridView(grdSub, this.Name + "grdSub", DBUtility.ClsPub.AppPath);
            DBUtility.ClsPub.SaveGridView(grdTree, this.Name + "grdTree", DBUtility.ClsPub.AppPath);  
        }
 
        private void mrlk_Click(object sender, EventArgs e)
        {
            DBUtility.ClsPub.DefaultGridView(grdMain);
            DBUtility.ClsPub.DefaultGridView(grdSub);
            //参数解释  开始列 ,结束列,是否以最大列宽为准,最小列宽
            DBUtility.ClsPub.SaveGridView(grdMain, this.Name, DBUtility.ClsPub.AppPath);
            DBUtility.ClsPub.SaveGridView(grdSub, this.Name, DBUtility.ClsPub.AppPath);
        }
        //时间控件
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            DisplaySub();
            Display();
        }
       
        //初始化GRID
        private void initGrid()
        {
            //主表
            grdMain.RowTemplate.Height = 18;
            grdMain.RowTemplate.MinimumHeight = 18;
            grdMain.ColumnHeadersHeight = 25;
            grdMain.RowHeadersVisible = false;
            grdMain.ColumnHeadersVisible = true;
            grdMain.ColumnCount = 0;
            grdMain.RowCount = 0;
            //格式化
            //表格设置
            grdMain.RowsDefaultCellStyle.SelectionForeColor = Color.White;
            grdMain.RowsDefaultCellStyle.SelectionBackColor = Color.DarkCyan;
            grdMain.DefaultCellStyle.SelectionBackColor = Color.DarkCyan;
            grdMain.DefaultCellStyle.SelectionForeColor = Color.White;
            grdMain.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            grdMain.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            grdMain.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            grdMain.ReadOnly = true;
            grdMain.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; //允许用户调整列宽
            grdMain.EnableHeadersVisualStyles = false;     //网格标题 样式
            grdMain.AllowUserToAddRows = false;             //是否允许自增--否
            grdMain.AllowUserToDeleteRows = false;          //是否允许删除--否 
            grdMain.AllowUserToResizeColumns = true;         //允许调整列宽--是
            grdMain.AllowUserToResizeRows = false;           //允许调整行高--否
            grdMain.AllowUserToOrderColumns = true;         //允许 拖拽列
            grdMain.BackgroundColor = Color.White;
            grdMain.GridColor = Color.LightGray;             //网格线颜色
            grdMain.ShowCellToolTips = true;
            grdMain.CellBorderStyle = DataGridViewCellBorderStyle.Single;
            //grdMain.ColumnHeadersDefaultCellStyle.BackColor = Color.AliceBlue;
            //
            DBUtility.ClsPub.GetGridView(grdMain, this.Name, DBUtility.ClsPub.AppPath);//设置列宽
 
            //子表
            grdSub.RowTemplate.Height = 18;
            grdSub.RowTemplate.MinimumHeight = 18;
            grdSub.ColumnHeadersHeight = 25;
            grdSub.RowHeadersVisible = false;
            grdSub.ColumnHeadersVisible = true;
            grdSub.ColumnCount = 0;
            grdSub.RowCount = 0;
            //格式化
            //表格设置
            grdSub.RowsDefaultCellStyle.SelectionForeColor = Color.White;
            grdSub.RowsDefaultCellStyle.SelectionBackColor = Color.DarkCyan;
            grdSub.DefaultCellStyle.SelectionBackColor = Color.DarkCyan;
            grdSub.DefaultCellStyle.SelectionForeColor = Color.White;
            grdSub.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            grdSub.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            grdSub.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            grdSub.ReadOnly = true;
            grdSub.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; //允许用户调整列宽
            grdSub.EnableHeadersVisualStyles = false;     //网格标题 样式
            grdSub.AllowUserToAddRows = false;             //是否允许自增--否
            grdSub.AllowUserToDeleteRows = false;          //是否允许删除--否 
            grdSub.AllowUserToResizeColumns = true;         //允许调整列宽--是
            grdSub.AllowUserToResizeRows = false;           //允许调整行高--否
            grdSub.AllowUserToOrderColumns = true;         //允许 拖拽列
            grdSub.BackgroundColor = Color.White;
            grdSub.GridColor = Color.LightGray;             //网格线颜色
            grdSub.ShowCellToolTips = true;
            grdSub.CellBorderStyle = DataGridViewCellBorderStyle.Single;
            //grdSub.ColumnHeadersDefaultCellStyle.BackColor = Color.AliceBlue;
            //
            DBUtility.ClsPub.GetGridView(grdSub, this.Name + "grdSub", DBUtility.ClsPub.AppPath);//设置列宽
 
 
            //子表
            grdTree.RowTemplate.Height = 18;
            grdTree.RowTemplate.MinimumHeight = 18;
            grdTree.ColumnHeadersHeight = 25;
            grdTree.RowHeadersVisible = false;
            grdTree.ColumnHeadersVisible = true;
            grdTree.ColumnCount = 0;
            grdTree.RowCount = 0;
            //格式化
            //表格设置
            grdTree.RowsDefaultCellStyle.SelectionForeColor = Color.White;
            grdTree.RowsDefaultCellStyle.SelectionBackColor = Color.DarkCyan;
            grdTree.DefaultCellStyle.SelectionBackColor = Color.DarkCyan;
            grdTree.DefaultCellStyle.SelectionForeColor = Color.White;
            grdTree.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            grdTree.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            grdTree.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            grdTree.ReadOnly = true;
            grdTree.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; //允许用户调整列宽
            grdTree.EnableHeadersVisualStyles = false;     //网格标题 样式
            grdTree.AllowUserToAddRows = false;             //是否允许自增--否
            grdTree.AllowUserToDeleteRows = false;          //是否允许删除--否 
            grdTree.AllowUserToResizeColumns = true;         //允许调整列宽--是
            grdTree.AllowUserToResizeRows = false;           //允许调整行高--否
            grdTree.AllowUserToOrderColumns = true;         //允许 拖拽列
            grdTree.BackgroundColor = Color.White;
            grdTree.GridColor = Color.LightGray;             //网格线颜色
            grdTree.ShowCellToolTips = true;
            grdTree.CellBorderStyle = DataGridViewCellBorderStyle.Single;
            //grdTree.ColumnHeadersDefaultCellStyle.BackColor = Color.AliceBlue;
            //
            DBUtility.ClsPub.GetGridView(grdTree, this.Name + "grdTree", DBUtility.ClsPub.AppPath);//设置列宽
        }
        
       
        #endregion
 
        //显示列表
        private void Display()
        {
            SQLHelper.ClsCN SubCn = new SQLHelper.ClsCN();
            DataSet DSet ;
            string sSql = "";
            string sWhere = "";
            long HParentID = 0;
            //树形节点
            if (CurNode.Name != "")
            {
                HParentID = DBUtility.ClsPub.isLong(CurNode.Name.Trim().Substring(1, CurNode.Name.Trim().Length - 1));
            }
            HParentID = HBomID;
            //过滤条件
            sSql = "exec h_p_Gy_ICBomBillMui_Top " + HParentID.ToString();
            //执行SQL
            DSet = SubCn.RunProcReturn(sSql, "h_p_Gy_ICBomBillMui_Top");
            //生成首行标题
            if (DSet == null)
            {
                return;
            }
            //
            for (int i = 0; i < grdMain.ColumnCount; i++)
            {
                grdMain.Columns[i].Frozen = false;
            }
            //
            grdMain.DataSource = DSet.Tables[0].DefaultView;
            //设置合计列 new
            //string sTotalCol = "";
            //sTotalCol = ClsPub.GetTotalCols(DSet);
            //string[] sT;
            //sT = sTotalCol.Split(Convert.ToChar(","));
            //oSumGrid.BuildTotalCols(sT);
            //  
            //合计
            //grdMain.Rows.Add();
 
            //加载列宽,隐藏列
            for (int i = 0; i < grdMain.ColumnCount; i++)
            {
                grdMain.Columns[i].Width = 100;
                //if (frmCondition.cmbHComplete.Text == "否")
                //{
                //    grdMain.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
                //}
                //else
                //{
                    grdMain.Columns[i].SortMode = DataGridViewColumnSortMode.Automatic;
                //}
 
                if (grdMain.Columns[i].HeaderText.Substring(0, 1).ToLower() == "h")
                {
                    grdMain.Columns[i].Visible = false;
                }
                else
                {
                    grdMain.Columns[i].Visible = true;
                }
            }
            DBUtility.ClsPub.GetGridView(this.grdMain, this.Name, DBUtility.ClsPub.AppPath);
            //画线
            GraphLine();
            //冻结
            //int FrCol = ClsPub.isInt(frmCondition.txtFrozenCol.Text);
            //if (FrCol < grdMain.ColumnCount)
            //{
            //    grdMain.Columns[FrCol].Frozen = true;
            //}
            // new
            //Total();
        }
 
        //显示列表--子表
        private void DisplaySub()
        {
            SQLHelper.ClsCN SubCn = new SQLHelper.ClsCN();
            DataSet DSet;
            string sSql = "";
            string sWhere = "";
            long HParentID = 0;
            //树形节点
            if (CurNode.Name != "")
            {
                HParentID = DBUtility.ClsPub.isLong(CurNode.Name.Trim().Substring(1, CurNode.Name.Trim().Length - 1));
            }
            HParentID = HBomID;
            //过滤条件
            sSql = "exec h_p_Gy_ICBomBillMuiList " + HParentID.ToString();
            //执行SQL
            DSet = SubCn.RunProcReturn(sSql, "h_p_Gy_ICBomBillMuiList");
            //生成首行标题
            if (DSet == null)
            {
                return;
            }
            //
            for (int i = 0; i < grdSub.ColumnCount; i++)
            {
                grdSub.Columns[i].Frozen = false;
            }
            //
            grdSub.DataSource = DSet.Tables[0].DefaultView;
            //设置合计列 new
            //string sTotalCol = "";
            //sTotalCol = ClsPub.GetTotalCols(DSet);
            //string[] sT;
            //sT = sTotalCol.Split(Convert.ToChar(","));
            //oSumGrid.BuildTotalCols(sT);
            //  
            //合计
            //grdSub.Rows.Add();
 
            //加载列宽,隐藏列
            for (int i = 0; i < grdSub.ColumnCount; i++)
            {
                grdSub.Columns[i].Width = 100;
                //if (frmCondition.cmbHComplete.Text == "否")
                //{
                //    grdSub.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
                //}
                //else
                //{
                grdSub.Columns[i].SortMode = DataGridViewColumnSortMode.Automatic;
                //}
 
                if (grdSub.Columns[i].HeaderText.Substring(0, 1).ToLower() == "h")
                {
                    grdSub.Columns[i].Visible = false;
                }
                else
                {
                    grdSub.Columns[i].Visible = true;
                }
            }
            int HColourCol = Fun_GetColSub("HColor");
            //设置网格背景颜色
            for (int i = 0; i < grdSub.RowCount; i++)
            {
                if (DBUtility.ClsPub.isStrNull(grdSub.Rows[i].Cells[HColourCol].Value) == "蓝色")
                {
                    grdSub.Rows[i].DefaultCellStyle.BackColor = Color.Lavender;
                }
                if (DBUtility.ClsPub.isStrNull(grdSub.Rows[i].Cells[HColourCol].Value) == "粉色")
                {
                    grdSub.Rows[i].DefaultCellStyle.BackColor = Color.Pink;
                }
            }
            DBUtility.ClsPub.GetGridView(this.grdSub, this.Name + "grdSub", DBUtility.ClsPub.AppPath);
            //画线
            GraphLine();
            //冻结
            //int FrCol = ClsPub.isInt(frmCondition.txtFrozenCol.Text);
            //if (FrCol < grdSub.ColumnCount)
            //{
            //    grdSub.Columns[FrCol].Frozen = true;
            //}
            // new
            //Total();
            SetRowColor();
        }
 
        //显示列表
        private void DisplayTree()
        {
            SQLHelper.ClsCN SubCn = new SQLHelper.ClsCN();
            DataSet DSet;
            string sSql = "";
            string sWhere = "";
            long HParentID = 0;
            //树形节点
            if (CurNode.Name != "")
            {
                HParentID = DBUtility.ClsPub.isLong(CurNode.Name.Trim().Substring(1, CurNode.Name.Trim().Length - 1));
            }
 
            //过滤条件
            sSql = "select hinterid,BOM编号,hitemid,产品代码,产品名称,规格型号,hparentid,状态 from h_v_Gy_ICBomMainList where hparentid=" + HParentID.ToString() + " order by 产品代码";
            //执行SQL
            DSet = SubCn.RunProcReturn(sSql, "h_v_Gy_ICBomMainList");
            //生成首行标题
            if (DSet == null)
            {
                return;
            }
            //
            for (int i = 0; i < grdTree.ColumnCount; i++)
            {
                grdTree.Columns[i].Frozen = false;
            }
            //
            grdTree.DataSource = DSet.Tables[0].DefaultView;
            //设置合计列 new
            //string sTotalCol = "";
            //sTotalCol = ClsPub.GetTotalCols(DSet);
            //string[] sT;
            //sT = sTotalCol.Split(Convert.ToChar(","));
            //oSumGrid.BuildTotalCols(sT);
            //  
            //合计
            //grdTree.Rows.Add();
 
            //加载列宽,隐藏列
            for (int i = 0; i < grdTree.ColumnCount; i++)
            {
                grdTree.Columns[i].Width = 100;
                //if (frmCondition.cmbHComplete.Text == "否")
                //{
                //    grdTree.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
                //}
                //else
                //{
                grdTree.Columns[i].SortMode = DataGridViewColumnSortMode.Automatic;
                //}
 
                if (grdTree.Columns[i].HeaderText.Substring(0, 1).ToLower() == "h")
                {
                    grdTree.Columns[i].Visible = false;
                }
                else
                {
                    grdTree.Columns[i].Visible = true;
                }
            }
            DBUtility.ClsPub.GetGridView(this.grdTree, this.Name + "grdTree", DBUtility.ClsPub.AppPath);
            //画线
            //GraphLine();
            //冻结
            //int FrCol = ClsPub.isInt(frmCondition.txtFrozenCol.Text);
            //if (FrCol < grdTree.ColumnCount)
            //{
            //    grdTree.Columns[FrCol].Frozen = true;
            //}
            // new
            //Total();
        }
 
 
        //显示列表
        private void DisplayTree2()
        {
            SQLHelper.ClsCN SubCn = new SQLHelper.ClsCN();
            DataSet DSet;
            string sSql = "";
            string sWhere = " where 1=1 ";
            long HParentID = 0;
            if (txtHNumber.Text.Trim() != "")
            {
                sWhere = sWhere + " and 产品代码 like '%" + txtHNumber.Text.Trim() + "%'"; 
            }
            if (txtHName.Text.Trim() != "")
            {
                sWhere = sWhere + " and 产品名称 like '%" + txtHName.Text.Trim() + "%'";
            }
            if (txtHModel.Text.Trim() != "")
            {
                sWhere = sWhere + " and 规格型号 like '%" + txtHModel.Text.Trim() + "%'";
            }
            //过滤条件
            sSql = "select hinterid,BOM编号,hitemid,产品代码,产品名称,规格型号,hparentid,状态 from h_v_Gy_ICBomMainList " + sWhere + " order by 产品代码"; 
            //执行SQL
            DSet = SubCn.RunProcReturn(sSql, "h_v_Gy_ICBomMainList");
            //生成首行标题
            if (DSet == null || DSet.Tables[0].Rows.Count ==0)
            {
                MessageBox.Show("没有返回任何记录!");
                return;
            }
            //
            for (int i = 0; i < grdTree.ColumnCount; i++)
            {
                grdTree.Columns[i].Frozen = false;
            }
            //
            grdTree.DataSource = DSet.Tables[0].DefaultView;
            //加载列宽,隐藏列
            for (int i = 0; i < grdTree.ColumnCount; i++)
            {
                grdTree.Columns[i].Width = 100;
                grdTree.Columns[i].SortMode = DataGridViewColumnSortMode.Automatic;
 
                if (grdTree.Columns[i].HeaderText.Substring(0, 1).ToLower() == "h")
                {
                    grdTree.Columns[i].Visible = false;
                }
                else
                {
                    grdTree.Columns[i].Visible = true;
                }
            }
            DBUtility.ClsPub.GetGridView(this.grdTree, this.Name + "grdTree", DBUtility.ClsPub.AppPath);
        }
 
 
        private void SetRowColor()
        {
            for (int i = 0; i <= grdSub.Rows.Count - 1; i++)
            {
                if (DBUtility.ClsPub.isStrNull(grdSub.Rows[i].Cells[Fun_GetColSub("物料属性")].Value) == "自制" ||
                    DBUtility.ClsPub.isStrNull(grdSub.Rows[i].Cells[Fun_GetColSub("物料属性")].Value) == "委外加工")
                {
                    if (DBUtility.ClsPub.isStrNull(grdSub.Rows[i].Cells[Fun_GetColSub("HStatus")].Value) == "")
                    {
                        grdSub.Rows[i].DefaultCellStyle.ForeColor = Color.Red;
                    }
                    else
                    {
                        grdSub.Rows[i].DefaultCellStyle.ForeColor = Color.Black;
                    }
                }
            }
        }
 
        //划线
        private void GraphLine()
        {
            //找到主表ID和子表ID的 范围
            int MainIDCol = Fun_GetCol("hmaterid");
            int SubIDCol = Fun_GetCol("hsubid");
            long HMainID = 0;
            bool b = false;
            long n = 0;
            //循环所有行
            for (int i = 0; i < grdMain.RowCount; i++)
            {
                if (HMainID == 0)
                {
                    HMainID = DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[MainIDCol].Value);
                    n++;
                }
                else
                {
 
                    if (HMainID == DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[MainIDCol].Value))
                    {
                        //if (frmCondition.cmbHComplete.Text == "否")
                        //{
                        //    区域性清空
                        //    SetDataGrid(i, MainIDCol + 1, i, SubIDCol - 1, "");
 
                        //}
                    }
                    else
                    {
                        HMainID = DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[MainIDCol].Value);
                        b = !b;
                        n++;
                    }
                }
                if (b)
                {
                    grdMain.Rows[i].DefaultCellStyle.BackColor = Color.White;
                }
                else
                {
                    grdMain.Rows[i].DefaultCellStyle.BackColor = Color.Lavender;
                }
            }
            //显示
            //lbldj.Text = "查询出 " + n.ToString() + " 张单据";
            //lbljl.Text = "共有 " + grdMain.RowCount.ToString() + " 条记录";
        }
        //加载子结点
        private void LoadAllNodes(TreeNode sNode)
        {
            if (sNode != null)
            {
                try
                {
                    sNode.Nodes.Clear();
                    DataSet Ds = oCn.RunProcReturn("exec h_p_Gy_BOMGroup " + sNode.Name.Trim().Substring(1, sNode.Name.Trim().Length - 1), "h_p_Gy_BOMGroup");
                    for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
                    {
                        TreeNode oNode = sNode.Nodes.Add("T" + Ds.Tables[0].Rows[i]["FKey"].ToString(), Ds.Tables[0].Rows[i]["FText"].ToString(), 0, 1);
                    }
                    sNode.Expand();
                }
                catch (Exception e)
                {
                    MessageBox.Show("加载子项目失败!" + e.Message, "提示");
                }
            }
        }
        //加载树形
        private void LoadTree()
        {
            try
            {
                tv.Nodes.Clear();
                tv.ImageList = imageList1;
                TreeNode sNode = tv.Nodes.Add("T0", "BOM单", 0, 1);
                LoadAllNodes(sNode);
            }
            catch (Exception e)
            {
                MessageBox.Show("加载树型失败!" + e.Message, "提示");
            }
        }
 
        //合计 new
        private void Total()
        {
            if (grdMain.Rows.Count > 0 && grdMain.ColumnCount > 0)
            {
                //oSumGrid.SetGridsum();
                //oSumGrid.Total();
            }
        }
        //合计 new
        private void grdMain_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
        {
            //Total();
        }
        //合计 new
        private void grdMain_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            //Total();
        }
 
        private void cmdOK_Click(object sender, EventArgs e)
        {
            DataSet oDs = new DataSet();
            HBomID = 0;
            if (txtHNumber.Text.Trim() == "" & txtHName.Text.Trim() == "" & txtHModel.Text.Trim() == "")
            {
                MessageBox.Show("请至少输入一个过滤条件!");
                return;
            }
            DisplayTree2(); //显示 树形
            oDs = oCn.RunProcReturn("exec h_p_Gy_Sc_GetBomIDByInfo '" + txtHNumber.Text.Trim() + "','" + txtHName.Text.Trim() + "','" + txtHModel.Text.Trim() + "'", "gy_czygl");
            if (oDs.Tables[0].Rows.Count == 0 || oDs == null)
                return;
            HBomID = DBUtility.ClsPub.isLong(oDs.Tables[0].Rows[0][0]);
            //
            DisplaySub();
            Display();
        }
 
        private void grdTree_DoubleClick(object sender, EventArgs e)
        {
            if (grdTree.CurrentRow == null)
                return;
 
            HBomID = DBUtility.ClsPub.isLong(grdTree.Rows[grdTree.CurrentRow.Index].Cells[Fun_GetColTree("hinterid")].Value);
            //
            DisplaySub();
            Display();
        }
 
        private void gylx_Click(object sender, EventArgs e)
        {
            Gy_RoutingBill oFrm = new Gy_RoutingBill();
            oFrm.BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew;
            oFrm.ShowDialog();
        }
 
 
 
 
    }
}