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

📄 用户管理.cs

📁 管理学院机房计费系统,VISUAL STUDIO .NET 2003 c# 语言实现,SQL SERVER 2000数据库. 现运行正常.
💻 CS
📖 第 1 页 / 共 2 页
字号:
			// 
			// textBox3
			// 
			this.textBox3.Location = new System.Drawing.Point(120, 32);
			this.textBox3.Name = "textBox3";
			this.textBox3.PasswordChar = '*';
			this.textBox3.Size = new System.Drawing.Size(136, 26);
			this.textBox3.TabIndex = 1;
			this.textBox3.Text = "";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(24, 32);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(56, 23);
			this.label4.TabIndex = 0;
			this.label4.Text = "旧密码";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.dataGrid1);
			this.groupBox2.Controls.Add(this.button10);
			this.groupBox2.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.groupBox2.Location = new System.Drawing.Point(16, 32);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(368, 360);
			this.groupBox2.TabIndex = 4;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "用户列表";
			// 
			// sqlDataAdapter1
			// 
			this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
			this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
			this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
			this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
																									  new System.Data.Common.DataTableMapping("Table", "操作员表", new System.Data.Common.DataColumnMapping[] {
																																																			  new System.Data.Common.DataColumnMapping("ID", "ID"),
																																																			  new System.Data.Common.DataColumnMapping("姓名", "姓名"),
																																																			  new System.Data.Common.DataColumnMapping("权限", "权限")})});
			this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
			// 
			// sqlDeleteCommand1
			// 
			this.sqlDeleteCommand1.CommandText = "DELETE FROM 操作员表 WHERE (ID = @Original_ID) AND (姓名 = @Original_姓名 OR @Original_姓名" +
				" IS NULL AND 姓名 IS NULL) AND (权限 = @Original_权限 OR @Original_权限 IS NULL AND 权限 I" +
				"S NULL)";
			this.sqlDeleteCommand1.Connection = this.sqlConnection2;
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ID", 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));
			// 
			// sqlConnection2
			// 
			this.sqlConnection2.ConnectionString = "workstation id=XU;packet size=4096;integrated security=SSPI;data source=XU;persis" +
				"t security info=False;initial catalog=jifei";
			// 
			// sqlInsertCommand1
			// 
			this.sqlInsertCommand1.CommandText = "INSERT INTO 操作员表(姓名, 权限) VALUES (@姓名, @权限); SELECT ID, 姓名, 权限 FROM 操作员表 WHERE (ID" +
				" = @@IDENTITY)";
			this.sqlInsertCommand1.Connection = this.sqlConnection2;
			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 ID, 姓名, 权限 FROM 操作员表";
			this.sqlSelectCommand1.Connection = this.sqlConnection2;
			// 
			// sqlUpdateCommand1
			// 
			this.sqlUpdateCommand1.CommandText = "UPDATE 操作员表 SET 姓名 = @姓名, 权限 = @权限 WHERE (ID = @Original_ID) AND (姓名 = @Original_" +
				"姓名 OR @Original_姓名 IS NULL AND 姓名 IS NULL) AND (权限 = @Original_权限 OR @Original_权" +
				"限 IS NULL AND 权限 IS NULL); SELECT ID, 姓名, 权限 FROM 操作员表 WHERE (ID = @ID)";
			this.sqlUpdateCommand1.Connection = this.sqlConnection2;
			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_ID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ID", 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("@ID", System.Data.SqlDbType.Int, 4, "ID"));
			// 
			// sqlConnection1
			// 
			this.sqlConnection1.ConnectionString = "workstation id=XU;packet size=4096;integrated security=SSPI;data source=XU;persis" +
				"t security info=False;initial catalog=jifei";
			// 
			// 用户管理
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(692, 416);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.添加新用户);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
			this.MaximizeBox = false;
			this.Name = "用户管理";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "用户管理";
			this.Load += new System.EventHandler(this.用户管理_Load);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.添加新用户.ResumeLayout(false);
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void 用户管理_Load(object sender, System.EventArgs e)
		{
			this.comboBox1.SelectedIndex=0;
			this.sqlDataAdapter1.Fill(this.sds,"操作员表");
			this.dataGrid1.SetDataBinding(this.sds,"操作员表");
			this.dataGrid1.Refresh();
			
			if(frmMain.strTeacherPower=="操作员")
			{
				this.groupBox2.Enabled=false;
				this.添加新用户.Enabled=false;
				this.dataGrid1.Visible=false;
			}
		}

		private void groupBox5_Enter(object sender, System.EventArgs e)
		{
		
		}

		private void button10_Click(object sender, System.EventArgs e)
		{
			try
			{
				this.sqlDataAdapter1.Update(sds,"操作员表");
				MessageBox.Show("修改成功!","用户管理",MessageBoxButtons.OK,MessageBoxIcon.Information);
			}
			catch(SqlException)
			{
				MessageBox.Show("修改无效,请检查输入!","用户管理",MessageBoxButtons.OK,MessageBoxIcon.Error);
			}
			finally
			{
				
				//this.sqlConnection2.Close();
			}
			this.dataGrid1.Refresh();
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			if(this.textBox1.Text!="" & this.textBox2.Text!="")
			{
				string sql="insert into 操作员表 (姓名,密码,权限) values ('"+ this.textBox1.Text +"','"+ this.textBox2.Text +"','"+ this.comboBox1.Text +"')";
				SqlCommand cmdTjyh=new SqlCommand(sql,this.sqlConnection1);
				try
				{
					this.sqlConnection1.Open();
					cmdTjyh.ExecuteNonQuery();
					MessageBox.Show("添加成功!","添加用户",MessageBoxButtons.OK,MessageBoxIcon.Information);
				}
				catch(SqlException exe)
				{
					MessageBox.Show("添加失败!","添加用户",MessageBoxButtons.OK,MessageBoxIcon.Error);
				}
				finally
				{
					this.sqlConnection1.Close();
					sds.Tables["操作员表"].Clear();
					this.sqlDataAdapter1.Fill(sds,"操作员表");
					this.dataGrid1.SetDataBinding(sds,"操作员表");
					this.dataGrid1.Refresh();
					this.textBox2.Clear();
					this.textBox1.Clear();
				}
			}
			else
			{
				MessageBox.Show("请输入完整信息!","添加用户",MessageBoxButtons.OK,MessageBoxIcon.Error);
			}
								
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			string strPass="";
			string sql="select 密码 from 操作员表 where 姓名='"+ frmMain.strTeacher +"'";
			SqlCommand cmd=new SqlCommand(sql,this.sqlConnection1);
			this.sqlConnection1.Open();

			SqlDataReader reader=cmd.ExecuteReader();
			try
			{	
				reader.Read();
				strPass=reader.GetString(0);
				
			}

			catch(SqlException exe)
			{
				reader.Close();
				this.sqlConnection1.Close();
				MessageBox.Show("数据库错误!","修改密码",MessageBoxButtons.OK,MessageBoxIcon.Error);
				goto finish;
			}
			finally
			{
				reader.Close();
				this.sqlConnection1.Close();
			}



			if(strPass==this.textBox3.Text & this.textBox4.Text!="")
			{
				sql="update 操作员表 set 密码='"+ this.textBox4.Text +"' where 姓名='"+ frmMain.strTeacher +"'";
				SqlCommand cmdXgmm=new SqlCommand(sql,this.sqlConnection1);
				this.sqlConnection1.Open();
				try
				{
					cmdXgmm.ExecuteNonQuery();
					MessageBox.Show("密码修改成功!","修改密码",MessageBoxButtons.OK,MessageBoxIcon.Information);
				}
				catch(SqlException exe)
				{
					MessageBox.Show("数据库错误,更新失败!","修改密码",MessageBoxButtons.OK,MessageBoxIcon.Error);
				}
				finally
				{
				  this.sqlConnection1.Close();
				}
			}
			else
			{
				MessageBox.Show("原始密码错误或新密码为空,密码修改失败!","修改密码",MessageBoxButtons.OK,MessageBoxIcon.Error);
			}

			finish:
				this.textBox3.Clear();
				this.textBox4.Clear();
				sds.Tables["操作员表"].Clear();
				this.sqlDataAdapter1.Fill(sds,"操作员表");
				this.dataGrid1.SetDataBinding(sds,"操作员表");

		}
	}
}

⌨️ 快捷键说明

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