沈泽
2021-08-20 d111e4321dcc4baa63f63597694f80d94e67ca11
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SQLHelper;
using DBUtility;
 
namespace BLL
{
    public partial class Xt_Authorization : Form
    {
        public Xt_Authorization()
        {
            InitializeComponent();
        }
        ClsCN oCn = new ClsCN();
        TreeNode CurNode = new TreeNode();
 
        public string czybm;        //Óû§±àÂë
        public long HGroupID;       //×éid
        public string sDisplay;     //ÅжÏÊÇÓû§È¨ÏÞ »¹ÊÇ ×é 
 
        public string Group_Authorization=""; //ȨÏÞ×Ö·û´®
        public string Group_ID;
        public string gnbm;
        //string[] AuthCode = new string[50];
        //string[] AuthTF = new string[50];
        string[] AuthCode;
        string[] AuthTF;
        private void Authorization()
        {
            DataSet Ds;
            if (sDisplay == "Óû§")
            {
                Ds = oCn.RunProcReturn("select * from  Gy_Czygl where czybm='" + czybm + "'", "Gy_Czygl");
                Group_Authorization =ClsPub.isStrNull( Ds.Tables[0].Rows[0]["AuthorityID"]);
                Group_ID = czybm;
            }
            else
            {
                Ds = oCn.RunProcReturn("select * from  System_UserGroup where GroupID=" + HGroupID, "System_UserGroup");
                Group_Authorization =ClsPub.isStrNull( Ds.Tables[0].Rows[0]["AuthorityID"]);
                Group_ID =ClsPub.isStrNull( HGroupID);
            }
            Ds = null;
        }
 
        //´°Ìå¼ÓÔØ
        private void Xt_Authorization_Load(object sender, EventArgs e)
        {
            Authorization();
            this.Text = "ȨÏÞ¹ÜÀí" + " -- " + sDisplay;
            LoadTree();
            initGrid();
            if (sDisplay == "Óû§")
            {
                Display1("");
            }
            else
            {
                Display2("");
            }
            //
            sq.Enabled = false;
        }
 
        //¼ÓÔØÊ÷ÐÎ
        private void LoadTree()
        {
            try
            {
                tv.Nodes.Clear();
                tv.ImageList = imageList1;
                TreeNode sNode = tv.Nodes.Add("T ", this.Text, 0, 1);
                //sNode.Expand();
                LoadAllNodes(sNode);
            }
            catch (Exception e)
            {
                MessageBox.Show("¼ÓÔØÊ÷ÐÍʧ°Ü£¡" + e.Message, "Ìáʾ");
            }
        }
        //¼ÓÔØ×Ó½áµã
        private void LoadAllNodes(TreeNode sNode)
        {
            if (sNode != null)
            {
                try
                {
                    string sName = sNode.Name.Substring(1, sNode.Name.Length - 1);
                    sNode.Nodes.Clear();
                    DataSet Ds = oCn.RunProcReturn("select * from  Xt_Xtgnb where useflag=1 and rightflag=1 and (gnbm NOT LIKE '99%') and sjgnbm='" + sName + "' and mjbz=0 order by gnbm ", "Xt_Xtgnb");
                    for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
                    {
                        TreeNode oNode = sNode.Nodes.Add("T" + Ds.Tables[0].Rows[i]["gnbm"].ToString().Trim(), Ds.Tables[0].Rows[i]["gnmc"].ToString().Trim(), 0, 1);
 
                    }
                    sNode.Expand();
                }
                catch (Exception e)
                {
                    MessageBox.Show("¼ÓÔØ×ÓÏîĿʧ°Ü£¡" + e.Message, "Ìáʾ");
                }
            }
        }
        //Ê÷ÐÍ µ¥»÷
        private void tv_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            CurNode = e.Node;
            if (CurNode != null)
            {
                if (sq.Enabled == true)
                {
                    if (MessageBox.Show("ÄãÊÇ·ñÒª±£´æÈ¨ÏÞ?  ", "Ìáʾ", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                    {
                        SQ();
                    }
                    else
                    {
                        sq.Enabled = false;
                    }
                }
                if (CurNode.Nodes.Count == 0)
                    LoadAllNodes(CurNode);
                //ÕÒµ½Ñ¡Öнáµã
                if (CurNode.Name != "T ")
                {
                    string sName = CurNode.Name.Substring(1, CurNode.Name.Length - 1);
                    gnbm = sName;
                    if (sDisplay == "Óû§")
                    {
                        Display1(sName);
                    }
                    else
                    {
                        Display2(sName);
                    }
                }
                else
                {
                    if (sDisplay == "Óû§")
                    {
                        Display1("");
                    }
                    else
                    {
                        Display2("");
                    }
                }
            }
        }
        //Íø¸ñ³õʼ»¯
        private void initGrid()
        {
            //Íø¸ñ--Óû§
            grdMain.SelectionMode = DataGridViewSelectionMode.FullRowSelect;        //Ñ¡ÖÐģʽ--ÐÐÑ¡ÖÐ
            grdMain.ColumnHeadersVisible = true;                                    //±êÌâÁÐÏÔʾ--ÊÇ
            grdMain.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;  //±êÌâÁгߴçģʽ--£¨×Ô¶¯µ÷Õû£¬¿Éµ÷Õû£©
            grdMain.RowTemplate.Height = 18;
            grdMain.RowTemplate.MinimumHeight = 18;
            grdMain.ColumnHeadersHeight = 35;          //±êÌâÐиß
            grdMain.RowHeadersVisible = false;              //±êÌâÐпɼû--·ñ
            grdMain.AllowUserToAddRows = false;             //ÊÇ·ñÔÊÐí×ÔÔö--·ñ
            grdMain.AllowUserToDeleteRows = false;          //ÊÇ·ñÔÊÐíɾ³ý--·ñ
            grdMain.ColumnCount = 3;                        //×ÜÁÐÊý--5
            grdMain.RowCount = 0;
            grdMain.AllowUserToResizeColumns = true;         //ÔÊÐíµ÷ÕûÁпí--ÊÇ
            grdMain.AllowUserToResizeRows = false;           //ÔÊÐíµ÷ÕûÐиß--·ñ
            grdMain.ReadOnly = false;                         //Ö»¶Á--ÊÇ
            grdMain.BackgroundColor = Color.White;
            grdMain.GridColor = Color.LightGray;
            grdMain.DefaultCellStyle.SelectionBackColor = Color.Black;
            grdMain.EnableHeadersVisualStyles = false;     //Íø¸ñ±êÌâ Ñùʽ
 
            //grdMain.Columns[0].HeaderText = "hid";
            //grdMain.Columns[2].HeaderText = "¹¦ÄÜ˵Ã÷";
            //grdMain.Columns[1].HeaderText = "ÊÇ·ñȨÏÞ";
 
            //DataGridViewCheckBoxColumn newColumn = new DataGridViewCheckBoxColumn();
            //newColumn.HeaderText = "ÊÇ·ñȨÏÞ";
            //grdMain.Columns.Insert(1, newColumn);
            //grdMain.Columns[1].HeaderText = "ÊÇ·ñȨÏÞ";
        }
        //²éÕÒÊý¾Ý----Óû§Ä£¿é
        private void Display1(string sGnbm)
        {
            try
            {
                ClsCN oCn = new ClsCN();
                DataSet oDs = new DataSet();    //
                oDs = oCn.RunProcReturn("SELECT id hid,case when id<=" + Group_Authorization.Length + " then case when SUBSTRING('" + Group_Authorization + "',id,1)=1 then 1 else 0 end else 0 end ÊÇ·ñȨÏÞ,gnms ¹¦ÄÜ˵Ã÷,gnbm hgnbm FROM  xt_xtgnb where useflag=1 and sjgnbm='" + sGnbm + "' and rightflag=1  order by gnbm", "xt_xtgnb");
                if (oDs == null)
                {
                    MessageBox.Show("ÏÔʾʧ°Ü£¡Ô­Òò£º" + ClsPub.sExeReturnInfo);
                    return;
                }
                //
                if (oDs.Tables[0].Rows.Count == 0)
                {
                    return;
                }
                //
                grdMain.RowCount = 0;
                AuthCode = new string[oDs.Tables[0].Rows.Count];
                AuthTF = new string[oDs.Tables[0].Rows.Count];
                for (int i = 0; i < oDs.Tables[0].Rows.Count; i++)
                {
                    grdMain.RowCount = grdMain.RowCount + 1;
                    grdMain.Rows[i].Cells[0].Value = ClsPub.isInt(oDs.Tables[0].Rows[i]["hid"]);
                    grdMain.Rows[i].Cells[1].Value = ClsPub.isBool(oDs.Tables[0].Rows[i]["ÊÇ·ñȨÏÞ"]);
                    grdMain.Rows[i].Cells[2].Value = ClsPub.isStrNull(oDs.Tables[0].Rows[i]["¹¦ÄÜ˵Ã÷"]);
                    AuthCode[i] = ClsPub.isStrNull(oDs.Tables[0].Rows[i]["hgnbm"]);
                }
                    //
                    //grdMain.DataSource = oDs.Tables[0].DefaultView;
                //¼ÓÔØÁпí
                for (int i = 0; i < grdMain.ColumnCount; i++)
                {
                    grdMain.Columns[i].Width = 100;
                    grdMain.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; 
                    if (grdMain.Columns[i].HeaderText.Substring(0, 1).ToLower() == "h")
                    {
                        grdMain.Columns[i].Visible = false;
                    }
                    else
                    {
                        grdMain.Columns[i].Visible = true;
                    }
                }
                ClsPub.GetGridView(this.grdMain, this.Name,Pub_Class.ClsPub.AppPath);
                grdMain.Columns[Fun_GetCol("¹¦ÄÜ˵Ã÷")].ReadOnly = true;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Ìáʾ");
                return;
            }
        }
        //²éÕÒÊý¾Ý----Óû§×éÄ£¿é
        private void Display2(string sGnbm)
        {
            try
            {
                ClsCN oCn = new ClsCN();
                DataSet oDs = new DataSet();    //
                oDs = oCn.RunProcReturn("SELECT id hid,case when id<=" + Group_Authorization.Length + " then case when SUBSTRING('" + Group_Authorization + "',id,1)=1 then 1 else 0 end else 0 end ÊÇ·ñȨÏÞ,gnms ¹¦ÄÜ˵Ã÷,gnbm hgnbm FROM  xt_xtgnb where useflag=1 and sjgnbm='" + sGnbm + "' and rightflag=1  order by gnbm", "xt_xtgnb");
                if (oDs == null)
                {
                    MessageBox.Show("ÏÔʾʧ°Ü£¡Ô­Òò£º" + ClsPub.sExeReturnInfo);
                    return;
                }
                //
                if (oDs.Tables[0].Rows.Count == 0)
                {
                    return;
                }
                //
                grdMain.RowCount = 0;
                AuthCode = new string[oDs.Tables[0].Rows.Count];
                AuthTF = new string[oDs.Tables[0].Rows.Count];
                for (int i = 0; i < oDs.Tables[0].Rows.Count; i++)
                {
                    grdMain.RowCount = grdMain.RowCount + 1;
                    grdMain.Rows[i].Cells[0].Value = ClsPub.isInt(oDs.Tables[0].Rows[i]["hid"]);
                    grdMain.Rows[i].Cells[1].Value = ClsPub.isBool(oDs.Tables[0].Rows[i]["ÊÇ·ñȨÏÞ"]);
                    grdMain.Rows[i].Cells[2].Value = ClsPub.isStrNull(oDs.Tables[0].Rows[i]["¹¦ÄÜ˵Ã÷"]);
                    AuthCode[i] = ClsPub.isStrNull(oDs.Tables[0].Rows[i]["hgnbm"]);
                }
                //
                //grdMain.DataSource = oDs.Tables[0].DefaultView;
                //¼ÓÔØÁпí
                for (int i = 0; i < grdMain.ColumnCount; i++)
                {
                    grdMain.Columns[i].Width = 100;
                    grdMain.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
                    if (grdMain.Columns[i].HeaderText.Substring(0, 1).ToLower() == "h")
                    {
                        grdMain.Columns[i].Visible = false;
                    }
                    else
                    {
                        grdMain.Columns[i].Visible = true;
                    }
                }
                ClsPub.GetGridView(this.grdMain, this.Name, Pub_Class.ClsPub.AppPath);
                grdMain.Columns[Fun_GetCol("¹¦ÄÜ˵Ã÷")].ReadOnly = true;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Ìáʾ");
                return;
            }
        }
        //µÃµ½¶ÔÓ¦ÁÐ
        private Int32 Fun_GetCol(string sCol)//Lock
        {
            for (int c = 0; c < grdMain.ColumnCount; c++)
            {
                if (ClsPub.isStrNull(grdMain.Columns[c].HeaderText).ToUpper().Trim() == sCol.Trim().ToUpper())
                {
                    return c;
                }
            }
            return 0;
        }
        //Í˳ö
        private void tc_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
        private void bclk_Click(object sender, EventArgs e)
        {
            //±£´æÁпí
            ClsPub.SaveGridView(grdMain, this.Name,Pub_Class.ClsPub.AppPath);
        }
 
        private void mrlk_Click(object sender, EventArgs e)
        {
            ClsPub.DefaultGridView(grdMain);
            //²ÎÊý½âÊÍ  ¿ªÊ¼ÁР£¬½áÊøÁУ¬ÊÇ·ñÒÔ×î´óÁпíΪ׼£¬×îСÁпí
            ClsPub.SaveGridView(grdMain, this.Name, Pub_Class.ClsPub.AppPath);
        }
        //ÊÚȨ
        private void sq_Click(object sender, EventArgs e)
        {
            SQ();
        }
        private void SQ()
        {
            //string qq = "0000100000";
            //int qqa = 5;
            //int qqb = qq.Length - qqa;
            //string qqc = qq.Substring(0, qqa - 1) + "2" + qq.Substring(qqa, qq.Length - qqa);
            //MessageBox.Show(qq.Substring(0,qqa-1)+"2"+qq.Substring(qqa, qq.Length - qqa ));
            //MessageBox.Show(qq.Substring(0, qqa - 1));
            //MessageBox.Show(qq.Substring(qqa, qq.Length - qqa));
            //MessageBox.Show(qqc.Substring(qqa-1, 1));
            
            ClsCN oCn = new ClsCN();
            DataSet oDs = new DataSet();
            int c = Fun_GetCol("ÊÇ·ñȨÏÞ");
            int Hid = Fun_GetCol("Hid");
            tv.Focus();
            string MKID = "";
            int lENSTR = 0; //Ä£¿éID
            string Auth_str = Group_Authorization;
            for (int i = 0; i < grdMain.Rows.Count; i++)
            {
                MKID = ClsPub.isStrNull(grdMain.Rows[i].Cells[Hid].Value);
                lENSTR = ClsPub.isInt(MKID.Substring(0, MKID.Length ));
                if (ClsPub.isBool( grdMain.Rows[i].Cells[c].Value) == true)
                {
                    for (int h = Auth_str.Trim().Length; h <= lENSTR - 1; h++)
                    {
                        Auth_str = Auth_str.Trim() + "0";
                    }
                    
                    Auth_str = Auth_str.Substring(0, lENSTR - 1) + "1" + Auth_str.Substring(lENSTR , Auth_str.Length-lENSTR);
                }
                else
                {
                    if (Auth_str.Length >= lENSTR)
                    {
                        Auth_str = Auth_str.Substring(0, lENSTR - 1) + "0" + Auth_str.Substring(lENSTR , Auth_str.Length-lENSTR);
                    }
                }
                oDs = oCn.RunProcReturn("select * from  xt_xtgnb where useflag=1 and gnbm like '" + AuthCode[i] + "%'", "xt_xtgnb");
                if (oDs.Tables[0].Rows.Count != 0)
                {
                    for (int k = 0; k < oDs.Tables[0].Rows.Count; k++)
                    {
                        int ID = ClsPub.isInt(oDs.Tables[0].Rows[k]["id"]);
                        if (ClsPub.isBool(grdMain.Rows[i].Cells[c].Value) == true)
                        {
                            if (AuthTF[i] == "1")
                            {
                                for (int h = Auth_str.Trim().Length; h <=ID - 1; h++)
                                {
                                    Auth_str = Auth_str.Trim() + "0";
                                }
                                Auth_str = Auth_str.Substring(0, ID - 1) + "1" + Auth_str.Substring(ID, Auth_str.Length - ID);
                            }
                        }
                        else
                        {
                            if (Auth_str.Length >= ID)
                            {
                                Auth_str = Auth_str.Substring(0, ID - 1) + "0" + Auth_str.Substring(ID, Auth_str.Length - ID);
                            }
                        }
                    }
                }
                oDs = null;
            }
 
            if (sDisplay == "Óû§")
            {
                oCn.RunProc("UPDATE  Gy_Czygl SET AuthorityID='" + Auth_str + "' WHERE czybm='" + Group_ID.Trim() + "'");
            }
            else
            {
                oCn.RunProc("UPDATE  System_UserGroup SET AuthorityID='" + Auth_str + "' WHERE GroupID=" + Group_ID);
            }
            sq.Enabled = false;
 
            Authorization();
        }
        //ɾ³ýÈ«²¿È¨ÏÞ
        private void sc_Click(object sender, EventArgs e)
        {
            int c = Fun_GetCol("ÊÇ·ñȨÏÞ");
            for (int i = 0; i < grdMain.Rows.Count; i++)
            {
                grdMain.Rows[i].Cells[c].Value = false ;
            }
        
            sq.Enabled = true;
        }
        //Ñ¡ÖÐÐи³ÖµÈ¨ÏÞ
        private void qx_Click(object sender, EventArgs e)
        {
            tv.Focus();
            int c = Fun_GetCol("ÊÇ·ñȨÏÞ");
            for (int i = 0; i < grdMain.Rows.Count; i++)
            {
                if (ClsPub.isBool(ClsPub.isBool( grdMain.Rows[i].Cells[c].Value ))== false)
                {
                    AuthTF[i] = "1";
                    grdMain.Rows[i].Cells[c].Value = true;
                }
            }
            sq.Enabled = true;
        }
 
        private void grdMain_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            //if (e.ColumnIndex == 1)
            //{
            //    sq.Enabled = true;
            //    AuthTF[e.RowIndex] = "1";
            //}
        }
 
        private void grdMain_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.ColumnIndex == 1)
            {
                sq.Enabled = true;
                AuthTF[e.RowIndex] = "1";
            }
 
 
            //DataGridViewCheckBoxCell checkBoxCell = this.grdMain[e.ColumnIndex, e.RowIndex] as DataGridViewCheckBoxCell;
 
            //if (checkBoxCell != null)
            //{
            //    if (object.Equals(checkBoxCell.EditingCellFormattedValue, true))
            //    {
            //        if (ClsPub.isBool(grdMain.Rows[e.RowIndex].Cells[e.ColumnIndex].Value) == false)
            //        {
            //            sq.Enabled = true;
            //            AuthTF[e.RowIndex] = "1";
            //        }
            //    }
            //    else
            //    {
            //        if (ClsPub.isBool(grdMain.Rows[e.RowIndex].Cells[e.ColumnIndex].Value) == true)
            //        {
            //            sq.Enabled = true;
            //            AuthTF[e.RowIndex] = "1";
            //        }
            //    }
            //    //Console.WriteLine(checkBoxCell.EditingCellFormattedValue);
            //    //Console.WriteLine(checkBoxCell.Value);
            //}
        }
        private void grdMain_CellClick(object sender, DataGridViewCellEventArgs e)
        {
          
        }
 
        private void grdMain_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
         
        }
 
        private void grdMain_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
         
        }
 
    }
}