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) { } } }