1
yangle
2023-05-26 301e6a60651ad026c3d9773e7bf6d9c76e936ca5
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
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 frmHlpInfo_View : Form
    {
        public frmHlpInfo_View()
        {
            InitializeComponent();
        }
        public string  WherePart;
        public string sTitle;
        public string sBill;
        public string sView;
        TreeNode CurNode=new TreeNode();
        public  Pub_Class.ClsPub.Enum_OKTag OKTag;
        Pub_Class.ClsSqlHelper oCn = new Pub_Class.ClsSqlHelper();
 
        private void frmHlpInfo_View_Load(object sender, EventArgs e)
        {
            initGrid();
            LoadTree();
        }
        //初始化GRID
        private void initGrid()
        {
            grdShow.SelectionMode = DataGridViewSelectionMode.FullRowSelect;        //选中模式--行选中
            grdShow.ColumnHeadersVisible = true;                                    //标题列显示--是
            grdShow.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;  //标题列尺寸模式--(自动调整,可调整)
            grdShow.RowTemplate.Height = 18;
            grdShow.RowTemplate.MinimumHeight = 18;
            grdShow.ColumnHeadersHeight = 35;          //标题行高
            grdShow.RowHeadersVisible = false;              //标题行可见--否
            grdShow.AllowUserToAddRows = false;             //是否允许自增--否
            grdShow.AllowUserToDeleteRows = false;          //是否允许删除--否
            //grdShow.ColumnCount = 0;                        //总列数--5
            //grdShow.RowCount = 0;
            grdShow.AllowUserToResizeColumns = true;         //允许调整列宽--是
            grdShow.AllowUserToResizeRows = false;           //允许调整行高--否
            grdShow.ReadOnly = true;                         //只读--是
            grdShow.BackgroundColor = Color.White;
            grdShow.GridColor = Color.LightGray;
            grdShow.DefaultCellStyle.SelectionBackColor = Color.Black;
            grdShow.EnableHeadersVisualStyles = false;     //网格标题 样式
            grdShow.ColumnHeadersDefaultCellStyle.BackColor = Color.LightGray;
            grdShow.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;//网格内容 对齐方式
            Pub_Class.ClsPub.GetGridView(grdShow, this.Name + this.sTitle, Pub_Class.ClsPub.AppPath);
        }
         
        //双击 GRID
        private void grdShow_DblClick(object sender, EventArgs e)
        {
            if (grdShow.CurrentCell == null)
            {
                return;
            }
            //if (AllowRow())
                BackData();
        }
        //时间TIMER
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            this.Text = sTitle;
        }
        //返回
        private void BackData()
        {
            OKTag = Pub_Class.ClsPub.Enum_OKTag.OKTag_OK;
            this.Visible = false;
        }
        //退出
        private void tc_Click(object sender, EventArgs e)
        {
            OKTag = Pub_Class.ClsPub.Enum_OKTag.OKTag_Cancel;
            this.Visible = false;
        }
        //返回按钮
        private void fh_Click(object sender, EventArgs e)
        {
            BackData();
        }
        //单击树形
        private void tvProcess_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            CurNode = e.Node;
            if (CurNode != null)
            {
                if (CurNode.Nodes.Count == 0)
                {
                    LoadAllNodes(CurNode);
                }
                QueryItem();
            }
        }
        //加载树型
        private void LoadTree()
        {
            try
            {
                tvTree.Nodes.Clear();
                tvTree.ImageList = imageList1;
                TreeNode sNode = tvTree.Nodes.Add("T0", this.Text, 0, 1);
                LoadAllNodes(sNode);
            }
            catch (Exception e)
            {
                MessageBox.Show(this,"加载树型失败!" + e.Message,"提示");
            }
        }
        //加载子项目
        private void LoadAllNodes(TreeNode sNode)
        {
            if (sNode != null)
            {
                try
                {
                    long sName = Convert.ToInt64(sNode.Name.Substring(1, sNode.Name.Length - 1));
                    sNode.Nodes.Clear();
                    DataSet Ds = oCn.RunProcReturn("select HItemID,HNumber,HName from " + sBill + " where   HParentID='" + sName + "'", sBill);
                    for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
                    {
                        TreeNode oNode = sNode.Nodes.Add("T" + Ds.Tables[0].Rows[i]["HItemID"].ToString(), Ds.Tables[0].Rows[i]["HNumber"].ToString() + "-" + Ds.Tables[0].Rows[i]["HName"].ToString(), 0, 1);
                    }
                    sNode.Expand();
                }
                catch (Exception e)
                {
                    //MessageBox.Show("加载子项目失败!" + e.Message);
                }
            }
        }
        
        //保存列宽
        private void frmHlpInfo_View_FormClosing(object sender, FormClosingEventArgs e)
        {
            //Pub_Class.ClsPub.SaveGridView(grdShow, sTitle, Pub_Class.ClsPub.AppPath);
        }
 
        public Int32 Fun_GetCol(string sCol, DataGridView grdMain)
        {
            for (int c = 0; c < grdMain.ColumnCount; c++)
            {
                if (Pub_Class.ClsPub.isStrNull(grdMain.Columns[c].HeaderText).ToUpper().Trim() == sCol.Trim().ToUpper())
                {
                    return c;
                }
            }
            return 0;
        }
 
        //过滤项目
        private void QueryItem()
        {
            
            
            string sTreeCode;
            //得到树型  代码
            try
            {
                CurrencyManager cm = (CurrencyManager)BindingContext[grdShow.DataSource];
                cm.SuspendBinding();
                //
                int Col;
                if (lblFindCol.Text.Trim()!="")
                    Col = Fun_GetCol(lblFindCol.Text.Trim(),grdShow);
                else
                    Col = 1;
                //
                if (CurNode != null)
                {
                    char c = Convert.ToChar("-");
                    string[] s = CurNode.Text.Split(c);
                    if (s.Length > 1)
                    {
                        sTreeCode = s[0].Trim().ToUpper();
                    }
                    else
                    {
                        sTreeCode = "";//选中 最大结点的时候
                    }
                }
                else
                {
                    sTreeCode = "";
                }
                int j = sTreeCode.Length;
                //显示全部
                for (int i = 0; i < grdShow.Rows.Count; i++)
                {
                    grdShow.Rows[i].Visible = true;
                    if (grdShow.Rows[i].Cells[Col].Value.ToString().Length < j)  //如果长度比 匹配项 小 就先隐藏
                    {
                        grdShow.Rows[i].Visible = false;
                    }
                    else
                    {
                        if (sTreeCode != "")
                        { 
                            if (Pub_Class.ClsPub.isStrNull(grdShow.Rows[i].Cells[1].Value.ToString()) != "")
                            {
                                if (grdShow.Rows[i].Cells[1].Value.ToString().ToUpper().Trim() != sTreeCode.ToUpper().Trim())
                                {
                                    if (grdShow.Rows[i].Cells[1].Value.ToString().ToUpper().Trim().Contains(sTreeCode+"."))
                                    {
                                        grdShow.Rows[i].Visible = true;
                                    }
                                    else
                                    {
                                        grdShow.Rows[i].Visible = false;
                                    }
                                }
                                else
                                {
                                    grdShow.Rows[i].Visible = true;
                                }
                            }
                        }
                        else
                        {
                            grdShow.Rows[i].Visible = true;
                        }
                        //txt
                        if (txtFindInfo.Text.Trim() != "")
                        {
                            string txtCode = txtFindInfo.Text.Trim().ToUpper();
 
                            if (Pub_Class.ClsPub.isStrNull(grdShow.Rows[i].Cells[Col].Value.ToString()) != "")
                            {
                                if (grdShow.Rows[i].Cells[Col].Value.ToString().ToUpper().Trim().Contains(txtCode))
                                {
                                    grdShow.Rows[i].Visible = true;
                                }
                                else
                                {
                                    grdShow.Rows[i].Visible = false;
                                }
                            }
                            else
                            {
                                grdShow.Rows[i].Visible = false;
                            }
                        }
                        //else
                        //{
                        //    grdShow.Rows[i].Visible = true;
                        //}
                    }
 
                }
                cm.ResumeBinding();
                Pub_Class.ClsPub.GetGridView(grdShow, this.Name + this.sTitle, Pub_Class.ClsPub.AppPath);
            }
            catch (Exception e)
            {
                return;
            }
        }
 
 
        private void txtFindInfo_TextChanged(object sender, EventArgs e)
        { 
             QueryItem();
        }
 
        private void chkMH_CheckedChanged(object sender, EventArgs e)
        {
            QueryItem();
        }
 
        private void cx_Click(object sender, EventArgs e)
        {
            QueryItem();
        }
 
        private void grdShow_DoubleClick(object sender, EventArgs e)
        {
            if (grdShow.CurrentCell == null)
            {
                return;
            }
            BackData();
        }
 
        private void grdShow_Click(object sender, EventArgs e)
        {
            if (grdShow.CurrentCell == null)
            {
                return;
            }
            if (grdShow.CurrentCell!=null)
            {
                lblFindCol.Text = grdShow.Columns[grdShow.CurrentCell.ColumnIndex].HeaderText;
            }
            else
            {
                lblFindCol.Text = grdShow.Columns[1].HeaderText;
            }
        }
 
        
 
        private void txtFindInfo_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode ==Keys.Enter)
            {
                QueryItem();
            }
        }
 
        private void yc_Click(object sender, EventArgs e)
        {
            Gy_GridView_Hide oHide = new Gy_GridView_Hide();
            oHide.KeyItem = this.Name + sBill;
            oHide.oGrd = grdShow;
            oHide.ShowDialog();
            //
            Pub_Class.ClsPub.HideGridView(grdShow, Name + sBill, Pub_Class.ClsPub.AppPath);//设置隐藏列
        }
 
        private void bclk_Click(object sender, EventArgs e)
        {
            Pub_Class.ClsPub.SaveGridView(grdShow, this.Name + this.sTitle, Pub_Class.ClsPub.AppPath);
        }
 
         
        
    }
}