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

📄 frmedituser.cs

📁 一个学籍管理系统 以在某高校投入使用了
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace prjClass
{
	/// <summary>
	/// frmEditUser 的摘要说明。
	/// </summary>
	public class frmEditUser : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Panel panel2;
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.Button button4;
		private System.Windows.Forms.TextBox txtName;
		Class1 c = new Class1();
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmEditUser()
		{
			//
			// 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.panel1 = new System.Windows.Forms.Panel();
			this.button4 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.panel2 = new System.Windows.Forms.Panel();
			this.button1 = new System.Windows.Forms.Button();
			this.txtName = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.panel1.SuspendLayout();
			this.panel2.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			this.SuspendLayout();
			// 
			// panel1
			// 
			this.panel1.Controls.Add(this.button4);
			this.panel1.Controls.Add(this.button3);
			this.panel1.Controls.Add(this.button2);
			this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.panel1.Location = new System.Drawing.Point(0, 293);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(552, 48);
			this.panel1.TabIndex = 0;
			// 
			// button4
			// 
			this.button4.Location = new System.Drawing.Point(400, 16);
			this.button4.Name = "button4";
			this.button4.TabIndex = 5;
			this.button4.Text = "取消";
			this.button4.Click += new System.EventHandler(this.button4_Click);
			// 
			// button3
			// 
			this.button3.Location = new System.Drawing.Point(248, 16);
			this.button3.Name = "button3";
			this.button3.TabIndex = 4;
			this.button3.Text = "修改";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(88, 16);
			this.button2.Name = "button2";
			this.button2.TabIndex = 3;
			this.button2.Text = "删除";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// panel2
			// 
			this.panel2.Controls.Add(this.button1);
			this.panel2.Controls.Add(this.txtName);
			this.panel2.Controls.Add(this.label1);
			this.panel2.Dock = System.Windows.Forms.DockStyle.Top;
			this.panel2.Location = new System.Drawing.Point(0, 0);
			this.panel2.Name = "panel2";
			this.panel2.Size = new System.Drawing.Size(552, 48);
			this.panel2.TabIndex = 1;
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(368, 16);
			this.button1.Name = "button1";
			this.button1.TabIndex = 2;
			this.button1.Text = "查询";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// txtName
			// 
			this.txtName.Location = new System.Drawing.Point(120, 16);
			this.txtName.Name = "txtName";
			this.txtName.TabIndex = 1;
			this.txtName.Text = "";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(24, 16);
			this.label1.Name = "label1";
			this.label1.TabIndex = 0;
			this.label1.Text = "管理员名称";
			// 
			// dataGrid1
			// 
			this.dataGrid1.DataMember = "";
			this.dataGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(0, 48);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.ReadOnly = true;
			this.dataGrid1.Size = new System.Drawing.Size(552, 245);
			this.dataGrid1.TabIndex = 2;
			this.dataGrid1.GotFocus += new System.EventHandler(this.dataGrid1_GotFocus);
			this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);
			// 
			// frmEditUser
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(552, 341);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.panel2);
			this.Controls.Add(this.panel1);
			this.Name = "frmEditUser";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "frmEditUser";
			this.Load += new System.EventHandler(this.frmEditUser_Load);
			this.panel1.ResumeLayout(false);
			this.panel2.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void frmEditUser_Load(object sender, System.EventArgs e)
		{
			SetBookTableStyle();
			this.LoadData("select * from Class..UserInfo");
		}
		
		/// <summary>
		/// Lend表的DataGrid样式设定 
		/// </summary>
		private void SetBookTableStyle()
		{
			DataGridTableStyle dgs = new DataGridTableStyle();
			dgs.MappingName="UserInfo";
			this.dataGrid1.TableStyles.Add(dgs);

			DataGridColumnStyle dgs1 = new DataGridTextBoxColumn();
			dgs1.HeaderText="用户名";
			dgs1.MappingName="UserID";
			dgs1.Width=100;

			DataGridColumnStyle dgs2 = new DataGridTextBoxColumn();
			dgs2.HeaderText="密码";
			dgs2.MappingName="UserPwd";
			dgs2.Width=100;

			DataGridColumnStyle dgs3 = new DataGridTextBoxColumn();
			dgs3.MappingName="UserPur";
			dgs3.HeaderText="权限";
			dgs3.Width=100;

			dgs.GridColumnStyles.Add(dgs1);
			dgs.GridColumnStyles.Add(dgs2);
			dgs.GridColumnStyles.Add(dgs3);
		}
		/// <summary>
		/// 向DataGrid里加载数据的方法
		/// </summary>
		/// <param name="Sql"></param>
		private void LoadData(string Sql)
		{
			DataAccess da = new DataAccess();
			string tablename = "UserInfo";
			DataTable dt = da.ExecuteDataTable(Sql,tablename);
			this.dataGrid1.DataSource=dt;
		}
		private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
		{
			this.txtName.Text = this.dataGrid1[this.dataGrid1.CurrentRowIndex,0].ToString();
		}

		private void dataGrid1_GotFocus(object sender, EventArgs e)
		{
			this.txtName.Text=this.dataGrid1[this.dataGrid1.CurrentRowIndex,0].ToString();
		}

		private void button4_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			if(this.txtName.Text=="")
			{
				MessageBox.Show("请填写用户名称","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
			}
			else
			{
				LoadData("select * from Class..UserInfo where UserID = '"+this.txtName.Text+"'");
			}
		}

		
		private void button2_Click(object sender, System.EventArgs e)
		{
			string Sql = "select * from Class..UserInfo where UserID = '"+this.txtName.Text+"'";
			string SqlDel = "delete from Class..UserInfo where UserID = '"+this.txtName.Text+"'";
			if(this.txtName.Text=="")
			{
				MessageBox.Show("请填写用户名称","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
			}
			else if(c.IsExits(Sql)==false)
			{
				MessageBox.Show("该用户不存在","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
			}
			else
			{
				if(MessageBox.Show("确认删除","提示信息!",MessageBoxButtons.OKCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2)==DialogResult.OK)
				{
					c.EditData(SqlDel);
					this.LoadData("select * from Class..UserInfo");
					this.txtName.Text="";
				}
			}
		}

		private void button3_Click(object sender, System.EventArgs e)
		{
			string Sql = "select * from Class..UserInfo where UserID = '"+this.txtName.Text+"'";
			if(this.txtName.Text=="")
			{
				MessageBox.Show("请填写用户名称","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
			}
			else if(c.IsExits(Sql)==false)
			{
				MessageBox.Show("该用户不存在","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
			}
			else
			{
				frmUpdate f = new frmUpdate(this.txtName.Text);
				f.UpdateEvent+=new UpdatHandler(f_UpdateEvent);
				f.ShowDialog();
			}
		}

		private void f_UpdateEvent()
		{
			this.LoadData("select * from Class..UserInfo");
		}
	}
}

⌨️ 快捷键说明

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