📄 popedom.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace WindowsApplication
{
/// <summary>
/// popedom 的摘要说明。
/// </summary>
public class popedom : System.Windows.Forms.Form
{
#region 变量定义...
private bool blCheck=true;//要在CheckListBox中选中选项,所有定义一个变量来判断...
private string userType="";//定义用户类型变量....
private string userPopedomCheckListBox="";//要在CheckListBox中选中一个项的变量定义...
private string InsertPopedomSql="";//插入字符串...
private int w;//接收返回值....
#endregion
#region 控件声明...
private System.Windows.Forms.Label label1;
private System.Windows.Forms.CheckedListBox checkListBox;
private System.Windows.Forms.DataGrid dataGrid;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
#endregion
#region 构造函数
public popedom()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion
#region 数据库变量定义...
private ConnectionData conn=new ConnectionData();
private string searchPopedomNameSql="select distinct 权限名称 from System_PopedomTable";
private System.Data.DataSet searchPopedomNameSet=new System.Data.DataSet();
private System.Data.DataTable searchPopedomNameTable=new System.Data.DataTable();
private string searchUserNameSql="select distinct 用户类型 from System_UserTable where 用户名称<>'adminstrator'";
private System.Data.DataTable searchUserNameTable=new System.Data.DataTable();
private System.Data.DataSet searchUserNameSet=new System.Data.DataSet();
private System.Data.DataTable userPopedomTable=new System.Data.DataTable();
private System.Data.DataSet userPopedomSet=new System.Data.DataSet();
private string userPopedomSql="";
private string userSelected="";
#endregion
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(popedom));
this.label1 = new System.Windows.Forms.Label();
this.checkListBox = new System.Windows.Forms.CheckedListBox();
this.dataGrid = new System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.dataGrid)).BeginInit();
this.SuspendLayout();
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(128)), ((System.Byte)(255)));
this.label1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.label1.Font = new System.Drawing.Font("宋体", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label1.Location = new System.Drawing.Point(0, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(354, 32);
this.label1.TabIndex = 0;
this.label1.Text = "权限管理";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// checkListBox
//
this.checkListBox.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.checkListBox.BackColor = System.Drawing.Color.White;
this.checkListBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.checkListBox.CheckOnClick = true;
this.checkListBox.Cursor = System.Windows.Forms.Cursors.Hand;
this.checkListBox.HorizontalScrollbar = true;
this.checkListBox.Location = new System.Drawing.Point(0, 32);
this.checkListBox.Name = "checkListBox";
this.checkListBox.ScrollAlwaysVisible = true;
this.checkListBox.Size = new System.Drawing.Size(144, 274);
this.checkListBox.Sorted = true;
this.checkListBox.TabIndex = 1;
this.checkListBox.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.checkListBox_ItemCheck);
//
// dataGrid
//
this.dataGrid.AlternatingBackColor = System.Drawing.Color.GhostWhite;
this.dataGrid.BackColor = System.Drawing.Color.GhostWhite;
this.dataGrid.BackgroundColor = System.Drawing.Color.Lavender;
this.dataGrid.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.dataGrid.CaptionBackColor = System.Drawing.Color.RoyalBlue;
this.dataGrid.CaptionForeColor = System.Drawing.Color.White;
this.dataGrid.CaptionVisible = false;
this.dataGrid.DataMember = "";
this.dataGrid.FlatMode = true;
this.dataGrid.Font = new System.Drawing.Font("Tahoma", 8F);
this.dataGrid.ForeColor = System.Drawing.Color.MidnightBlue;
this.dataGrid.GridLineColor = System.Drawing.Color.RoyalBlue;
this.dataGrid.HeaderBackColor = System.Drawing.Color.MidnightBlue;
this.dataGrid.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
this.dataGrid.HeaderForeColor = System.Drawing.Color.Lavender;
this.dataGrid.LinkColor = System.Drawing.Color.Teal;
this.dataGrid.Location = new System.Drawing.Point(144, 32);
this.dataGrid.Name = "dataGrid";
this.dataGrid.ParentRowsBackColor = System.Drawing.Color.Lavender;
this.dataGrid.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
this.dataGrid.ReadOnly = true;
this.dataGrid.SelectionBackColor = System.Drawing.Color.Teal;
this.dataGrid.SelectionForeColor = System.Drawing.Color.PaleGreen;
this.dataGrid.Size = new System.Drawing.Size(216, 272);
this.dataGrid.TabIndex = 2;
this.dataGrid.MouseUp += new System.Windows.Forms.MouseEventHandler(this.dataGrid_MouseUp);
//
// popedom
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.Info;
this.ClientSize = new System.Drawing.Size(354, 301);
this.Controls.Add(this.dataGrid);
this.Controls.Add(this.checkListBox);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "popedom";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "popedom";
this.Load += new System.EventHandler(this.popedom_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid)).EndInit();
this.ResumeLayout(false);
}
#endregion
#region 事件初始化...
private void popedom_Load(object sender, System.EventArgs e)
{
try
{
#region 向CheckListBox加入(权限名称)数据...
searchPopedomNameSet=conn.ExcuteDataSetResult(searchPopedomNameSql,"System_PopedomTable");
searchPopedomNameTable=searchPopedomNameSet.Tables[0];
for (int i=0;i<searchPopedomNameTable.Rows.Count;i++)
{
this.checkListBox.Items.Add(searchPopedomNameTable.Rows[i][0].ToString());
}
#endregion
#region 向DataGrid中加入(用户名称)数据
searchUserNameSet=conn.ExcuteDataSetResult(searchUserNameSql,"System_UserTable");
searchUserNameTable=searchUserNameSet.Tables[0];
dataGrid.DataSource=searchUserNameTable;
#endregion
#region 当开始运行此窗体时,选中第一个用户的用户权限对应起来....
userSelected=this.dataGrid[0,0].ToString();
userPopedomSql="select 权限名称 from System_PopedomTable where 用户类型='"+userSelected+"'";
userPopedomSet=conn.ExcuteDataSetResult(userPopedomSql,"System_PopedomTable");
userPopedomTable=userPopedomSet.Tables[0];
for(int j=0;j<userPopedomTable.Rows.Count;j++)
{
for(int u=0;u<this.checkListBox.Items.Count;u++)
{
if(this.checkListBox.Items[u].ToString().Equals(userPopedomTable.Rows[j][0].ToString()))
{
this.checkListBox.SetItemChecked(u,true);
}
}
}
#endregion
}
catch(Exception ele)
{
MessageBox.Show(this,ele.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
#endregion
#region CHECKLISTBOX事件...
private void checkListBox_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
{
try
{
if(this.blCheck.Equals(false))
{
if(e.CurrentValue.ToString().Equals("Unchecked"))
{
userPopedomCheckListBox=this.checkListBox.SelectedItem.ToString();
userType=this.dataGrid[this.dataGrid.CurrentCell.RowNumber,0].ToString();
InsertPopedomSql="Insert into System_PopedomTable(用户类型,权限名称) Values('"+userType+"','"+userPopedomCheckListBox+"')";
w=conn.ExcuteStrSql(InsertPopedomSql);
if(w>0)
{
MessageBox.Show(this,"用户权限修改成功!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
MessageBox.Show(this,"用户权限修改失败!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
else if(e.CurrentValue.ToString().Equals("Checked"))
{
userPopedomCheckListBox=this.checkListBox.SelectedItem.ToString();
userType=this.dataGrid[this.dataGrid.CurrentCell.RowNumber,0].ToString();
InsertPopedomSql="update System_PopedomTable set 用户类型=null where 权限名称='"+userPopedomCheckListBox+"'";
w=conn.ExcuteStrSql(InsertPopedomSql);
if(w>0)
{
MessageBox.Show(this,"用户权限删除成功!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
MessageBox.Show(this,"用户权限删除失败!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
}
catch(Exception ele)
{
MessageBox.Show(this,ele.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
#endregion
#region DataGrid 鼠标按下事件...
private void dataGrid_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
try
{
if(this.dataGrid.CurrentCell.RowNumber>=this.searchUserNameSet.Tables[0].Rows.Count)
{
return;
}
blCheck=true;
this.checkListBox.Enabled=true;
for(int h=0;h<this.checkListBox.Items.Count;h++)
{
this.checkListBox.SetItemChecked(h,false);
}
userSelected=this.dataGrid[0,0].ToString();
userPopedomSql="select 权限名称 from System_PopedomTable where 用户类型='"+userSelected+"'";
userPopedomSet=conn.ExcuteDataSetResult(userPopedomSql,"System_PopedomTable");
userPopedomTable=userPopedomSet.Tables[0];
for(int j=0;j<userPopedomTable.Rows.Count;j++)
{
for(int u=0;u<this.checkListBox.Items.Count;u++)
{
if(this.checkListBox.Items[u].ToString().Equals(userPopedomTable.Rows[j][0].ToString()))
{
this.checkListBox.SetItemChecked(u,true);
}
}
}
blCheck=false;
}
catch(Exception exse)
{
MessageBox.Show(this,exse.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -