⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 powermanager.cs

📁 工资结算系统 拥有权限控制 临时工资表 自动导入导出Excel 以及邮件群发功能
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;

namespace HrSalary.user
{
	/// <summary>
	/// PrivilegeManager 的摘要说明。
	/// </summary>
	public class PowerManager : System.Windows.Forms.Form
	{
		/// <summary>
		/// 必需的设计器变量。
		private OleDbConnection dbCon = null;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.ComboBox comboBox1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.CheckBox checkBox1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button3;
		bool  flagComoboxAdd=true;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.CheckBox checkBox2;               //comobox1初始化标志
		/// </summary>
		private System.ComponentModel.Container components = null;

		public PowerManager()
		{
			//
			// 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.button3 = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.button2 = new System.Windows.Forms.Button();
			this.button1 = new System.Windows.Forms.Button();
			this.label2 = new System.Windows.Forms.Label();
			this.comboBox1 = new System.Windows.Forms.ComboBox();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.checkBox1 = new System.Windows.Forms.CheckBox();
			this.checkBox2 = new System.Windows.Forms.CheckBox();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.BackColor = System.Drawing.Color.AliceBlue;
			this.groupBox1.Controls.Add(this.button3);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.button2);
			this.groupBox1.Controls.Add(this.button1);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.comboBox1);
			this.groupBox1.Controls.Add(this.groupBox2);
			this.groupBox1.Controls.Add(this.groupBox3);
			this.groupBox1.Location = new System.Drawing.Point(8, 0);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(408, 272);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			// 
			// button3
			// 
			this.button3.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.button3.Location = new System.Drawing.Point(296, 88);
			this.button3.Name = "button3";
			this.button3.Size = new System.Drawing.Size(88, 23);
			this.button3.TabIndex = 6;
			this.button3.Text = "删除用户";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(32, 32);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(100, 16);
			this.label1.TabIndex = 1;
			this.label1.Text = "选定用户:";
			// 
			// button2
			// 
			this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.button2.Location = new System.Drawing.Point(296, 40);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(88, 23);
			this.button2.TabIndex = 5;
			this.button2.Text = "添加用户";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// button1
			// 
			this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.button1.Location = new System.Drawing.Point(296, 136);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(88, 23);
			this.button1.TabIndex = 4;
			this.button1.Text = "修改权限";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(24, 120);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(100, 16);
			this.label2.TabIndex = 3;
			this.label2.Text = "选定对应权限:";
			// 
			// comboBox1
			// 
			this.comboBox1.BackColor = System.Drawing.Color.White;
			this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.comboBox1.Location = new System.Drawing.Point(80, 56);
			this.comboBox1.MaxDropDownItems = 15;
			this.comboBox1.Name = "comboBox1";
			this.comboBox1.Size = new System.Drawing.Size(160, 20);
			this.comboBox1.TabIndex = 2;
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.checkBox1);
			this.groupBox2.Controls.Add(this.checkBox2);
			this.groupBox2.Location = new System.Drawing.Point(72, 144);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(168, 96);
			this.groupBox2.TabIndex = 0;
			this.groupBox2.TabStop = false;
			// 
			// checkBox1
			// 
			this.checkBox1.Location = new System.Drawing.Point(32, 24);
			this.checkBox1.Name = "checkBox1";
			this.checkBox1.Size = new System.Drawing.Size(128, 24);
			this.checkBox1.TabIndex = 0;
			this.checkBox1.Text = "员工信息管理";
			// 
			// checkBox2
			// 
			this.checkBox2.Location = new System.Drawing.Point(32, 56);
			this.checkBox2.Name = "checkBox2";
			this.checkBox2.TabIndex = 2;
			this.checkBox2.Text = "工资管理";
			// 
			// groupBox3
			// 
			this.groupBox3.Location = new System.Drawing.Point(8, 8);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(264, 256);
			this.groupBox3.TabIndex = 7;
			this.groupBox3.TabStop = false;
			// 
			// PowerManager
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.Color.SeaShell;
			this.ClientSize = new System.Drawing.Size(424, 278);
			this.Controls.Add(this.groupBox1);
			this.Name = "PowerManager";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "用户管理";
			this.Load += new System.EventHandler(this.PowerManager_Load);
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void PowerManager_Load(object sender, System.EventArgs e)
		{
			
			this.comboBox1_renew();	
				this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
		
			flagComoboxAdd=false;
			
			
		}
		private void  comboBox1_renew()
		{
			this.comboBox1.Items.Clear();
			if(dbCon==null) dbCon = MainForm.getConnection();
			OleDbCommand cmd = dbCon.CreateCommand();
			cmd.CommandText = "select name,staff,salary from a_user where status=0";
			OleDbDataReader reader = cmd.ExecuteReader();
			int flag = 0;
			try
			{
					while(reader.Read())
				{
					if(reader.GetString(0).Equals("系统管理员"))
						continue;
					else
					{   
						this.comboBox1.Items.Add(reader.GetString(0));	
						flag++;
						if(flag==1)
						{
								flagComoboxAdd=true;
							this.comboBox1.SelectedIndex = 0;
							this.checkBox1.Checked=reader.GetBoolean(1);
							this.checkBox2.Checked=reader.GetBoolean(2);
						
						}
					}
				}
				if(flag==0)
				{
					this.checkBox1.Checked=false;
					this.checkBox2.Checked=false;
				}
			}
			catch(Exception ee)
			{
				MessageBox.Show(ee.ToString());
			}	
				
			reader.Close();
			cmd.Dispose();
			
		}
		
				 private  bool comboBox1_CheckError(string caption)
				 {   
					 string  comboBox1Text=this.comboBox1.Text;
					 int count=this.comboBox1.Items.Count;
					 int i=0;
					 for(i=0;i<count;i++)
						 if(comboBox1Text.Equals(this.comboBox1.Items[i].ToString()))
						 {
							 this.comboBox1.SelectedIndex=i;
							 break;
						 }
					 if(i>=count)
					 {
						 MessageBox.Show(caption);//"您不能删除用户!!!"
						 return(true);
					 }
					 return(false);
				 }
	
		private void button1_Click(object sender, System.EventArgs e)
		{
			 if(comboBox1_CheckError("无此用户,您不能设置用户权限!!!")) return;
			try
			{
				bool check1,check2;
				if(this.checkBox1.Checked)
					check1=true;
				else
					check1=false;
				if(this.checkBox2.Checked)
					check2=true;
				else
					check2=false;
												 
				
				if(dbCon==null) dbCon = MainForm.getConnection();
				OleDbCommand cmd = dbCon.CreateCommand();
				cmd.CommandText = "update a_user set staff="+check1+",salary="+check2+" where status=0 and name='"+this.comboBox1.SelectedItem.ToString()+"'";
				int result = cmd.ExecuteNonQuery();
				if(result==1)
				{
					MessageBox.Show("用户权限设置成功!");
					cmd.Dispose();
				   
				}
				else
					MessageBox.Show("用户权限设置不成功,请重试!");
				
				
			}
			catch(Exception ee)
			{
				MessageBox.Show(ee.ToString());
			}          
     
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			user.UserModify  a_useradd=new UserModify();			
			a_useradd.ShowDialog();	
			this.comboBox1_renew();
			
		}

		private void button3_Click(object sender, System.EventArgs e)
		{ 
			 if(comboBox1_CheckError("无此用户,您不能删除!!!"))  return;
			if (MessageBox.Show ("确实要删除"+this.comboBox1.Text.ToString()+"吗?", "删除用户框",
				MessageBoxButtons.YesNo, MessageBoxIcon.Question)
				== DialogResult.Yes) 
			{
				try
				{
					if(dbCon==null) dbCon = MainForm.getConnection();
					OleDbCommand cmd = dbCon.CreateCommand();
					cmd.CommandText = "delete  from a_user where  name='"+this.comboBox1.Text+"'";
					int result = cmd.ExecuteNonQuery();
					if(result==1)					     
					MessageBox.Show("用户删除成功!");						
					cmd.Dispose();					
				}
				catch(Exception ee)
				{
					MessageBox.Show(ee.ToString());
				}				
				this.comboBox1_renew();
			}
		}

		private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
		{			
			try
			{
				if(!flagComoboxAdd) 
				{ 
					if(comboBox1_CheckError("无用户!!!")) return;
					
					if(dbCon==null) dbCon = MainForm.getConnection();
					OleDbCommand cmd0 = dbCon.CreateCommand();
					cmd0.CommandText = "select name,workercheck,salarycheck from a_user where name='"+this.comboBox1.SelectedItem.ToString()+"'";
				
					OleDbDataReader reader0= cmd0.ExecuteReader();
					while(reader0.Read())
					{						
						this.checkBox1.Checked=reader0.GetBoolean(1);
						this.checkBox2.Checked=reader0.GetBoolean(2);
					}
					reader0.Close();
					cmd0.Dispose();	
				}
				else
					flagComoboxAdd=false;
				
			}
			catch(Exception ee)
			{
				MessageBox.Show(ee.ToString());
			}		
				
		
		}

		

		
	
	}	

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -