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

📄 updaterole.cs

📁 c#+SQL Server 中小型信息系统开发实例精选书上代码
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace StudentManagementsystem
{
	/// <summary>
	/// UpdateRole 的摘要说明。
	/// </summary>
	public class UpdateRole : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox UserName;
		private System.Windows.Forms.TextBox Psw;
		private System.Windows.Forms.Button NewUserOk;
		private System.Windows.Forms.Button NewUserCanl;
		private System.Windows.Forms.ComboBox RoleItem;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		/// 
		private string NewRoleStrConn;
		private SqlConnection NewRoleConn;
		private SqlCommand NewRoleComd;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox2;

		private System.ComponentModel.Container components = null;

		public UpdateRole()
		{
			//
			// 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.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.UserName = new System.Windows.Forms.TextBox();
			this.Psw = new System.Windows.Forms.TextBox();
			this.NewUserOk = new System.Windows.Forms.Button();
			this.NewUserCanl = new System.Windows.Forms.Button();
			this.RoleItem = new System.Windows.Forms.ComboBox();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(32, 32);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(56, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "用户名:";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(32, 56);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(56, 16);
			this.label2.TabIndex = 1;
			this.label2.Text = "密  码:";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(32, 80);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(56, 16);
			this.label3.TabIndex = 2;
			this.label3.Text = "职  务:";
			// 
			// UserName
			// 
			this.UserName.Location = new System.Drawing.Point(96, 32);
			this.UserName.Name = "UserName";
			this.UserName.Size = new System.Drawing.Size(104, 21);
			this.UserName.TabIndex = 3;
			this.UserName.Text = "";
			// 
			// Psw
			// 
			this.Psw.Location = new System.Drawing.Point(96, 56);
			this.Psw.Name = "Psw";
			this.Psw.Size = new System.Drawing.Size(104, 21);
			this.Psw.TabIndex = 4;
			this.Psw.Text = "";
			// 
			// NewUserOk
			// 
			this.NewUserOk.Location = new System.Drawing.Point(32, 128);
			this.NewUserOk.Name = "NewUserOk";
			this.NewUserOk.Size = new System.Drawing.Size(72, 24);
			this.NewUserOk.TabIndex = 6;
			this.NewUserOk.Text = "确认";
			this.NewUserOk.Click += new System.EventHandler(this.NewUserOk_Click);
			// 
			// NewUserCanl
			// 
			this.NewUserCanl.Location = new System.Drawing.Point(120, 128);
			this.NewUserCanl.Name = "NewUserCanl";
			this.NewUserCanl.Size = new System.Drawing.Size(72, 24);
			this.NewUserCanl.TabIndex = 7;
			this.NewUserCanl.Text = "退出";
			this.NewUserCanl.Click += new System.EventHandler(this.NewUserCanl_Click);
			// 
			// RoleItem
			// 
			this.RoleItem.Cursor = System.Windows.Forms.Cursors.Cross;
			this.RoleItem.Items.AddRange(new object[] {
														  "教务秘书",
														  "院长"});
			this.RoleItem.Location = new System.Drawing.Point(96, 80);
			this.RoleItem.Name = "RoleItem";
			this.RoleItem.Size = new System.Drawing.Size(104, 20);
			this.RoleItem.TabIndex = 8;
			// 
			// groupBox1
			// 
			this.groupBox1.Location = new System.Drawing.Point(16, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.TabIndex = 9;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "录入";
			// 
			// groupBox2
			// 
			this.groupBox2.Location = new System.Drawing.Point(16, 112);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(200, 48);
			this.groupBox2.TabIndex = 10;
			this.groupBox2.TabStop = false;
			// 
			// UpdateRole
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(232, 173);
			this.Controls.Add(this.RoleItem);
			this.Controls.Add(this.NewUserCanl);
			this.Controls.Add(this.NewUserOk);
			this.Controls.Add(this.Psw);
			this.Controls.Add(this.UserName);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.groupBox2);
			this.Name = "UpdateRole";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "权限管理";
			this.ResumeLayout(false);

		}
		#endregion

		private void NewUserCanl_Click(object sender, System.EventArgs e)
		{
			if(MessageBox.Show("您确认要退出?","确认",MessageBoxButtons.YesNo)==DialogResult.Yes)
				this.Close();
		}

		private void NewUserOk_Click(object sender, System.EventArgs e)
		{
			try
			{
				string SqlStr="insert into syuser(Use_name,Password,Use_role)values"+"( "+"'"+this.UserName.Text.ToString().Trim()+"'"+","+"'"+this.Psw.Text.ToString().Trim()+"'"+","+"'"+this.RoleItem.SelectedItem.ToString().Trim()+"'"+")";
				NewRoleStrConn="workstation id=localhost;Integrated Security=SSPI;database=StuMagSys";
				NewRoleConn=new SqlConnection(NewRoleStrConn);

				NewRoleConn.Open();
				NewRoleComd=new SqlCommand(SqlStr,NewRoleConn);
				int Succnum=NewRoleComd.ExecuteNonQuery();
				if(Succnum>0) MessageBox.Show("录入成功");
			}
			catch
			{
				MessageBox.Show("必须选择一个角色!","错误");
			}
		}
	}
}

⌨️ 快捷键说明

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