usermanager.cs

来自「独立完成考勤管理软件加打卡系统(C#) 是打卡加管理系统软件 」· CS 代码 · 共 981 行 · 第 1/3 页

CS
981
字号
			this.textUserID.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(255)));
			this.textUserID.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textUserID.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.textUserID.Location = new System.Drawing.Point(80, 336);
			this.textUserID.Name = "textUserID";
			this.textUserID.Size = new System.Drawing.Size(88, 21);
			this.textUserID.TabIndex = 40;
			this.textUserID.Text = "";
			this.textUserID.MouseEnter += new System.EventHandler(this.textBox2_MouseEnter);
			this.textUserID.MouseLeave += new System.EventHandler(this.textBox2_MouseLeave);
			// 
			// label5
			// 
			this.label5.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label5.Location = new System.Drawing.Point(184, 336);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(72, 23);
			this.label5.TabIndex = 41;
			this.label5.Text = "用户类型:";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// userTypeComBox
			// 
			this.userTypeComBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.Simple;
			this.userTypeComBox.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.userTypeComBox.Items.AddRange(new object[] {
																"普通用户"});
			this.userTypeComBox.Location = new System.Drawing.Point(272, 336);
			this.userTypeComBox.Name = "userTypeComBox";
			this.userTypeComBox.Size = new System.Drawing.Size(104, 20);
			this.userTypeComBox.TabIndex = 42;
			this.userTypeComBox.MouseEnter += new System.EventHandler(this.userTypeComBox_MouseEnter);
			this.userTypeComBox.MouseLeave += new System.EventHandler(this.userTypeComBox_MouseLeave);
			// 
			// label6
			// 
			this.label6.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label6.Location = new System.Drawing.Point(576, 336);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(72, 23);
			this.label6.TabIndex = 44;
			this.label6.Text = "用户名称:";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label7
			// 
			this.label7.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label7.Location = new System.Drawing.Point(384, 336);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(72, 23);
			this.label7.TabIndex = 43;
			this.label7.Text = "密码:";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// textpassword
			// 
			this.textpassword.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(255)));
			this.textpassword.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textpassword.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.textpassword.Location = new System.Drawing.Point(456, 336);
			this.textpassword.Name = "textpassword";
			this.textpassword.Size = new System.Drawing.Size(104, 21);
			this.textpassword.TabIndex = 45;
			this.textpassword.Text = "";
			this.textpassword.MouseEnter += new System.EventHandler(this.textBox2_MouseEnter);
			this.textpassword.MouseLeave += new System.EventHandler(this.textBox2_MouseLeave);
			// 
			// userName
			// 
			this.userName.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(255)));
			this.userName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.userName.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.userName.Location = new System.Drawing.Point(656, 336);
			this.userName.Name = "userName";
			this.userName.Size = new System.Drawing.Size(104, 21);
			this.userName.TabIndex = 46;
			this.userName.Text = "";
			this.userName.MouseEnter += new System.EventHandler(this.textBox2_MouseEnter);
			this.userName.MouseLeave += new System.EventHandler(this.textBox2_MouseLeave);
			// 
			// sqlUserDataAdaper
			// 
			this.sqlUserDataAdaper.DeleteCommand = this.sqlDeleteCommand1;
			this.sqlUserDataAdaper.InsertCommand = this.sqlInsertCommand1;
			this.sqlUserDataAdaper.SelectCommand = this.sqlSelectCommand1;
			this.sqlUserDataAdaper.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
																										new System.Data.Common.DataTableMapping("Table", "System_UserTable", new System.Data.Common.DataColumnMapping[] {
																																																							new System.Data.Common.DataColumnMapping("用户号", "用户号"),
																																																							new System.Data.Common.DataColumnMapping("用户名称", "用户名称"),
																																																							new System.Data.Common.DataColumnMapping("密码", "密码"),
																																																							new System.Data.Common.DataColumnMapping("用户类型", "用户类型")})});
			this.sqlUserDataAdaper.UpdateCommand = this.sqlUpdateCommand1;
			// 
			// sqlDeleteCommand1
			// 
			this.sqlDeleteCommand1.CommandText = "DELETE FROM System_UserTable WHERE (用户号 = @Original_用户号) AND (密码 = @Original_密码) " +
				"AND (用户名称 = @Original_用户名称) AND (用户类型 = @Original_用户类型)";
			this.sqlDeleteCommand1.Connection = this.sqlConnection;
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_用户号", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "用户号", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_密码", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "密码", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_用户名称", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "用户名称", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_用户类型", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "用户类型", System.Data.DataRowVersion.Original, null));
			// 
			// sqlConnection
			// 
			this.sqlConnection.ConnectionString = "workstation id=localhost;integrated security=SSPI;database=SystemODBC";
			// 
			// sqlInsertCommand1
			// 
			this.sqlInsertCommand1.CommandText = "INSERT INTO System_UserTable(用户号, 用户名称, 密码, 用户类型) VALUES (@用户号, @用户名称, @密码, @用户类型" +
				"); SELECT 用户号, 用户名称, 密码, 用户类型 FROM System_UserTable WHERE (用户号 = @用户号)";
			this.sqlInsertCommand1.Connection = this.sqlConnection;
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@用户号", System.Data.SqlDbType.VarChar, 50, "用户号"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@用户名称", System.Data.SqlDbType.VarChar, 50, "用户名称"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@密码", System.Data.SqlDbType.VarChar, 50, "密码"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@用户类型", System.Data.SqlDbType.VarChar, 50, "用户类型"));
			// 
			// sqlSelectCommand1
			// 
			this.sqlSelectCommand1.CommandText = "SELECT 用户号, 用户名称, 密码, 用户类型 FROM System_UserTable WHERE (用户号 <> \'101\')";
			this.sqlSelectCommand1.Connection = this.sqlConnection;
			// 
			// sqlUpdateCommand1
			// 
			this.sqlUpdateCommand1.CommandText = "UPDATE System_UserTable SET 用户号 = @用户号, 用户名称 = @用户名称, 密码 = @密码, 用户类型 = @用户类型 WHER" +
				"E (用户号 = @Original_用户号) AND (密码 = @Original_密码) AND (用户名称 = @Original_用户名称) AND " +
				"(用户类型 = @Original_用户类型); SELECT 用户号, 用户名称, 密码, 用户类型 FROM System_UserTable WHERE " +
				"(用户号 = @用户号)";
			this.sqlUpdateCommand1.Connection = this.sqlConnection;
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@用户号", System.Data.SqlDbType.VarChar, 50, "用户号"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@用户名称", System.Data.SqlDbType.VarChar, 50, "用户名称"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@密码", System.Data.SqlDbType.VarChar, 50, "密码"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@用户类型", System.Data.SqlDbType.VarChar, 50, "用户类型"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_用户号", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "用户号", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_密码", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "密码", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_用户名称", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "用户名称", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_用户类型", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "用户类型", System.Data.DataRowVersion.Original, null));
			// 
			// userTableSet
			// 
			this.userTableSet.DataSetName = "UserTableSet";
			this.userTableSet.Locale = new System.Globalization.CultureInfo("zh-CN");
			// 
			// textBox1
			// 
			this.textBox1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(255)));
			this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textBox1.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.textBox1.Location = new System.Drawing.Point(456, 336);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(104, 23);
			this.textBox1.TabIndex = 47;
			this.textBox1.Text = "";
			// 
			// UserManager
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(9, 20);
			this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(255)));
			this.CancelButton = this.btnExit;
			this.ClientSize = new System.Drawing.Size(800, 375);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.userName);
			this.Controls.Add(this.textpassword);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.label7);
			this.Controls.Add(this.userTypeComBox);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.textUserID);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.btnExit);
			this.Controls.Add(this.btnEnd);
			this.Controls.Add(this.btnFirst);
			this.Controls.Add(this.btnNext);
			this.Controls.Add(this.btnLast);
			this.Controls.Add(this.btnModify);
			this.Controls.Add(this.btnSave);
			this.Controls.Add(this.btnDelete);
			this.Controls.Add(this.btnAdd);
			this.Controls.Add(this.dataGrid);
			this.Controls.Add(this.pictureBox1);
			this.Font = new System.Drawing.Font("宋体", 13F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "UserManager";
			this.Text = "UserManager";
			this.Load += new System.EventHandler(this.UserManager_Load);
			this.Controls.SetChildIndex(this.pictureBox1, 0);
			this.Controls.SetChildIndex(this.dataGrid, 0);
			this.Controls.SetChildIndex(this.titleLabel, 0);
			this.Controls.SetChildIndex(this.btnAdd, 0);
			this.Controls.SetChildIndex(this.btnDelete, 0);
			this.Controls.SetChildIndex(this.btnSave, 0);
			this.Controls.SetChildIndex(this.btnModify, 0);
			this.Controls.SetChildIndex(this.btnLast, 0);
			this.Controls.SetChildIndex(this.btnNext, 0);
			this.Controls.SetChildIndex(this.btnFirst, 0);
			this.Controls.SetChildIndex(this.btnEnd, 0);
			this.Controls.SetChildIndex(this.btnExit, 0);
			this.Controls.SetChildIndex(this.label4, 0);
			this.Controls.SetChildIndex(this.textUserID, 0);
			this.Controls.SetChildIndex(this.label5, 0);
			this.Controls.SetChildIndex(this.userTypeComBox, 0);
			this.Controls.SetChildIndex(this.label7, 0);
			this.Controls.SetChildIndex(this.label6, 0);
			this.Controls.SetChildIndex(this.textpassword, 0);
			this.Controls.SetChildIndex(this.userName, 0);
			this.Controls.SetChildIndex(this.textBox1, 0);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.userTableSet)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion
		#region  光标移动时变化...
		private void textBox2_MouseEnter(object sender, System.EventArgs e)
		{
		    TextBox text=(TextBox)sender;
			text.BackColor=Color.White;
		}

		private void textBox2_MouseLeave(object sender, System.EventArgs e)
		{
			TextBox text=(TextBox)sender;
			text.BackColor=Color.AliceBlue;
		}
		private void btnExit_MouseLeave(object sender, System.EventArgs e)
		{
			Button  button=(Button)sender;
			button.ForeColor=SystemColors.Highlight;
			button.FlatStyle=FlatStyle.Flat;
			button.Font=new Font ("宋体",9,FontStyle.Bold);
		}
		private void btnExit_MouseEnter(object sender, System.EventArgs e)
		{
			Button  button=(Button)sender;
			button.ForeColor=Color.SlateBlue;
			button.FlatStyle=FlatStyle.Standard;
			button.Font=new Font("楷体",9,FontStyle.Underline);
		}
		#endregion
		#region 事件初始化...
		private void UserManager_Load(object sender, System.EventArgs e)
		{
			try
			{
				#region 填充DataGrid结构框架
				this.sqlUserDataAdaper.Fill(this.userTableSet);
				userTable=this.userTableSet.Tables[0];
				this.dataGrid.DataSource=userTable;
				#endregion
				#region 绑定文本框数据
                BudingsFunction(userTable);
				#endregion
				#region 填充用户类型下拉表框
                //fillUserType(userTable);
				#endregion
				#region 初始化文本框为只读状态
                ReadText(false);
				#endregion
				#region 初始变量...
				tempTable=ExcuteSql(searchUserSql,"System_UserTable");
				#endregion
				#region SqlAdapter
//				this.sqlDataAdapter.InsertCommand=this.sqlInsertCom;
//				this.sqlDataAdapter.SelectCommand=this.sqlSelectCom;
//				this.sqlDataAdapter.UpdateCommand=this.sqlUpdateCom;
//				this.sqlDataAdapter.TableMappings.AddRange(new System.Data.Common.DataColumnMapping[]
//					{
//						new System.Data.Common.DataTableMapping("Table","System_UserTable",new System.Data.Common.DataColumnMapping[]
//						{
//							new System.Data.Common.DataColumnMapping("用户号","用户号"),
//					        new System.Data.Common.DataColumnMapping("用户名称","用户名称"),
//				            new System.Data.Common.DataColumnMapping("密码","密码"),
//						    new System.Data.Common.DataColumnMapping("用户类型","用户类型"),
//						});
//					});
//			    this.sqlInsertCom="insert into System_UserTable(用户号,用户名称,密码,用户类型) values(@用户号,@用户名称,@密码,@用户类型)";
//			    this.sqlInsertCom.Parameters.Add(new System.Data.SqlClient.SqlParameter("@用户号",System.Data.SqlDbType.VarChar,50,"用户号"));
//			    this.sqlInsertCom.Parameters.Add(new System.Data.SqlClient.SqlParameter("@用户名称",System.Data.SqlDbType.VarChar,50,"密码"));
//			    this.sqlInsertCom.Parameters.Add(new System.Data.SqlClient.SqlParameter("@密码",System.Data.SqlDbType.VarChar,50,"用户名称"));
//			    this.sqlInsertCom.Parameters.Add(new System.Data.SqlClient.SqlParameter("@用户类型",System.Data.SqlDbType.VarChar,50,"用户类型"));
				#endregion
			}
			catch(Exception ele)
			{
				MessageBox.Show(this,ele.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
			}
		}
		#endregion
		#region 非空函数
		private  bool CheckIsNotNull()
		{
			if(this.textUserID.Text.Equals(""))
			{
				MessageBox.Show(this,"用户号不能为空!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
				this.textUserID.Focus();
				ReadText(true);
				return true;
			}
			else if(this.userTypeComBox.Text.Equals(""))
			{
				MessageBox.Show(this,"用户类型不能为空!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
				this.userTypeComBox.Focus();
				ReadText(true);
				return true;
			}
			else if(this.textpassword.Text.Equals(""))
			{
				MessageBox.Show(this,"密码不能为空!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
				this.textpassword.Focus();
				ReadText(true);
				return true;
			}
			else if(this.userName.Text.Equals(""))
			{
				MessageBox.Show(this,"用户不能为空!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
				this.userName.Focus();
				ReadText(true);
				return true;
			}
			else 
			{
				try
				{
					userSet=conn.ExcuteDataSetResult(searchUserSql,"System_UserTable");
					userTable=userSet.Tables[0];
					for(int k=0;k<userTable.Rows.Count;k++)
					{

⌨️ 快捷键说明

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