北京安通林JIS系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

442 lines
14 KiB

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using Stone.Common;
using System.Collections.Generic;
namespace Stone.User
{
/// <summary>
/// FUser 的摘要说明。
/// </summary>
public class frmAuthority : System.Windows.Forms.Form
{
private GroupBox groupBox1;
private CheckedListBox lstAuthority;
private Button btnOK;
private Button btnClose;
private CheckBox chkAll;
private TreeView leftTree;
private Label label2;
private Label label1;
private CheckBox checkBox1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public frmAuthority()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.leftTree = new System.Windows.Forms.TreeView();
this.chkAll = new System.Windows.Forms.CheckBox();
this.btnClose = new System.Windows.Forms.Button();
this.lstAuthority = new System.Windows.Forms.CheckedListBox();
this.btnOK = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.checkBox1);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.leftTree);
this.groupBox1.Controls.Add(this.chkAll);
this.groupBox1.Controls.Add(this.btnClose);
this.groupBox1.Controls.Add(this.lstAuthority);
this.groupBox1.Controls.Add(this.btnOK);
this.groupBox1.Location = new System.Drawing.Point(12, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(534, 517);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(317, 19);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(96, 16);
this.checkBox1.TabIndex = 8;
this.checkBox1.Text = "全选模块权限";
this.checkBox1.UseVisualStyleBackColor = true;
this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(19, 358);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(41, 12);
this.label2.TabIndex = 7;
this.label2.Text = "小权限";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(19, 20);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(53, 12);
this.label1.TabIndex = 6;
this.label1.Text = "模块权限";
//
// leftTree
//
this.leftTree.Font = new System.Drawing.Font("宋体", 9F);
this.leftTree.HotTracking = true;
this.leftTree.ItemHeight = 24;
this.leftTree.Location = new System.Drawing.Point(19, 38);
this.leftTree.Name = "leftTree";
this.leftTree.Size = new System.Drawing.Size(394, 308);
this.leftTree.TabIndex = 5;
this.leftTree.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.leftTree_AfterCheck);
//
// chkAll
//
this.chkAll.AutoSize = true;
this.chkAll.Location = new System.Drawing.Point(329, 357);
this.chkAll.Name = "chkAll";
this.chkAll.Size = new System.Drawing.Size(84, 16);
this.chkAll.TabIndex = 4;
this.chkAll.Text = "全选小权限";
this.chkAll.UseVisualStyleBackColor = true;
this.chkAll.CheckedChanged += new System.EventHandler(this.chkAll_CheckedChanged);
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(433, 67);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(75, 23);
this.btnClose.TabIndex = 3;
this.btnClose.Text = "取消";
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// lstAuthority
//
this.lstAuthority.CheckOnClick = true;
this.lstAuthority.FormattingEnabled = true;
this.lstAuthority.Location = new System.Drawing.Point(19, 376);
this.lstAuthority.Name = "lstAuthority";
this.lstAuthority.Size = new System.Drawing.Size(394, 132);
this.lstAuthority.TabIndex = 1;
//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(433, 38);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(75, 23);
this.btnOK.TabIndex = 2;
this.btnOK.Text = "确定";
this.btnOK.UseVisualStyleBackColor = true;
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// frmAuthority
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(558, 541);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "frmAuthority";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "-权限管理";
this.Load += new System.EventHandler(this.FUser_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
public string Select_User_Name = "";
private void FUser_Load(object sender, EventArgs e)
{
this.Text = Select_User_Name + this.Text;
UpdateListView();
UpdateTreeView();
}
private void UpdateTreeView()
{
try
{
F_Authority.Init(this.leftTree, Select_User_Name);
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
}
private void UpdateListView()
{
try
{
DataSet dsData = F_UserInfo.GetAuthority();
this.lstAuthority.DataSource = dsData.Tables[0];
this.lstAuthority.DisplayMember = "Name";
this.lstAuthority.ValueMember = "ID";
DataSet dsList = F_UserInfo.GetAuthorityList(Select_User_Name);
foreach(DataRow drData in dsList.Tables[0].Rows)
{
for (int i = 0; i < this.lstAuthority.Items.Count; i++)
{
this.lstAuthority.SelectedIndex = i;
if (this.lstAuthority.SelectedValue.ToString() == drData["AuthorityID"].ToString())
{
this.lstAuthority.SetItemChecked(i, true);
}
}
}
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
/*
System.Data.SqlClient.SqlConnection sqlconn = new SqlConnection(UserInfo.sqlconnstring());
try
{
sqlconn.Open();
string sqlstring = "select Authority_ID, Authority_Name from t_UserAuthority";
SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlstring, sqlconn);
DataSet ds = new DataSet();
dataAdapter.Fill(ds, "newtable");
this.lstAuthority.DataSource = ds.Tables["newtable"];
this.lstAuthority.DisplayMember = "Authority_Name";
this.lstAuthority.ValueMember = "Authority_ID";
SqlCommand sqlcmd = sqlconn.CreateCommand();
sqlcmd.CommandText = "select Authority_Name from v_User where User_Name=@User_Name";
sqlcmd.Parameters.Clear();
sqlcmd.Parameters.Add(new SqlParameter("User_Name", Select_User_Name));
SqlDataReader dataread = sqlcmd.ExecuteReader();
this.lstAuthority.ClearSelected();
while (dataread.Read())
{
for(int i=0; i<this.lstAuthority.Items.Count; i++)
{
if (this.lstAuthority.GetItemText(this.lstAuthority.Items[i]) == dataread["Authority_Name"].ToString())
{
this.lstAuthority.SetItemChecked(i, true);
}
}
}
dataread.Close();
sqlcmd.Dispose();
sqlconn.Close();
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
*/
}
private void btnOK_Click(object sender, EventArgs e)
{
this.btnOK.Enabled = false;
this.btnOK.Update();
try
{
TreeCodes.Clear();
GetTreeCodes(leftTree.Nodes);
F_UserInfo.AddAuthorityTree(Select_User_Name, TreeCodes);
DataSet dsList = new DataSet();
dsList.Tables.Add(new DataTable());
dsList.Tables[0].Columns.Add("AuthorityID");
for (int i = 0; i < this.lstAuthority.Items.Count; i++)
{
if (this.lstAuthority.GetItemChecked(i))
{
this.lstAuthority.SelectedIndex = i;
DataRow drNew = dsList.Tables[0].NewRow();
drNew["AuthorityID"] = this.lstAuthority.SelectedValue.ToString();
dsList.Tables[0].Rows.Add(drNew);
}
}
F_UserInfo.AddAuthorityList(Select_User_Name, dsList);
this.Close();
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
finally
{
this.btnOK.Enabled = true;
Application.DoEvents();
}
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void chkAll_CheckedChanged(object sender, EventArgs e)
{
try
{
for (int i = 0; i < this.lstAuthority.Items.Count; i++)
{
this.lstAuthority.SetItemChecked(i, this.chkAll.Checked);
}
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
try
{
//leftTree.Nodes[0].Nodes//
SetAllCheck(leftTree.Nodes, this.checkBox1.Checked);
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
}
private void SetAllCheck(TreeNodeCollection nodes, bool check)
{
foreach (TreeNode node in nodes)
{
node.Checked = check;
if (node.Nodes.Count > 0)
{
SetAllCheck(node.Nodes, check);
}
}
}
private List<string> TreeCodes = new List<string>();
private void GetTreeCodes(TreeNodeCollection nodes)
{
foreach (TreeNode node in nodes)
{
if (node.Tag != null)
{
if (node.Checked)
{
TreeCodes.Add(node.Tag.ToString());
}
}
if (node.Nodes.Count > 0)
{
GetTreeCodes(node.Nodes);
}
}
}
private void leftTree_AfterCheck(object sender, TreeViewEventArgs e)
{
//当勾选的节点下面有子节点的时候,则勾选下面所有的子节点
try
{
SetAllCheck(e.Node.Nodes, e.Node.Checked);
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
}
}
}