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

📄 frmteapassword.cs

📁 学生类:Student 教师类:Teacher 主任:AdminTeacher 班主任:MasterTeacher 授课老师: PrelectTeacher 班级类:classTeam 班
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using BusinessRule;
using DataAccess;


namespace Forms
{
	/// <summary>
	/// frmTeaPassWord 的摘要说明。
	/// </summary>
	public class frmTeaPassWord : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label lblTeaID;
		private System.Windows.Forms.Label lblTeacherID;
		private System.Windows.Forms.Label lblOldTeaPassWord;
		private System.Windows.Forms.TextBox txtOld;
		private System.Windows.Forms.TextBox txtNew1;
		private System.Windows.Forms.Label lblNewPassWord1;
		private System.Windows.Forms.TextBox txtNew2;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Button btnChance;
		private System.Windows.Forms.Button btnCancel;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		private AdminTeacher Ateacher = null;
		private PrelectTeacher Pteacher = null;
		private MasterTeacher Mteacher = null;

		public frmTeaPassWord()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			Post.EventSendLoginedID +=new DataAccess.Post.SendMsgDelegate(Post_EventSendLoginedID);
			this.lblTeacherID.Text = frmMain.UserID.ToString();
		}

		/// <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.lblTeaID = new System.Windows.Forms.Label();
			this.lblTeacherID = new System.Windows.Forms.Label();
			this.lblOldTeaPassWord = new System.Windows.Forms.Label();
			this.txtOld = new System.Windows.Forms.TextBox();
			this.txtNew1 = new System.Windows.Forms.TextBox();
			this.lblNewPassWord1 = new System.Windows.Forms.Label();
			this.txtNew2 = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.btnChance = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// lblTeaID
			// 
			this.lblTeaID.AutoSize = true;
			this.lblTeaID.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblTeaID.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.lblTeaID.Location = new System.Drawing.Point(29, 48);
			this.lblTeaID.Name = "lblTeaID";
			this.lblTeaID.Size = new System.Drawing.Size(63, 19);
			this.lblTeaID.TabIndex = 0;
			this.lblTeaID.Text = "教师编号";
			// 
			// lblTeacherID
			// 
			this.lblTeacherID.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.lblTeacherID.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.lblTeacherID.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblTeacherID.Location = new System.Drawing.Point(136, 44);
			this.lblTeacherID.Name = "lblTeacherID";
			this.lblTeacherID.Size = new System.Drawing.Size(144, 32);
			this.lblTeacherID.TabIndex = 1;
			// 
			// lblOldTeaPassWord
			// 
			this.lblOldTeaPassWord.AutoSize = true;
			this.lblOldTeaPassWord.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblOldTeaPassWord.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.lblOldTeaPassWord.Location = new System.Drawing.Point(38, 98);
			this.lblOldTeaPassWord.Name = "lblOldTeaPassWord";
			this.lblOldTeaPassWord.Size = new System.Drawing.Size(48, 19);
			this.lblOldTeaPassWord.TabIndex = 2;
			this.lblOldTeaPassWord.Text = "原密码";
			// 
			// txtOld
			// 
			this.txtOld.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.txtOld.Location = new System.Drawing.Point(136, 96);
			this.txtOld.Name = "txtOld";
			this.txtOld.PasswordChar = '*';
			this.txtOld.Size = new System.Drawing.Size(168, 29);
			this.txtOld.TabIndex = 0;
			this.txtOld.Text = "";
			this.txtOld.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtOld_KeyPress);
			// 
			// txtNew1
			// 
			this.txtNew1.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.txtNew1.Location = new System.Drawing.Point(136, 146);
			this.txtNew1.Name = "txtNew1";
			this.txtNew1.PasswordChar = '*';
			this.txtNew1.Size = new System.Drawing.Size(168, 29);
			this.txtNew1.TabIndex = 3;
			this.txtNew1.Text = "";
			this.txtNew1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtNew1_KeyPress);
			// 
			// lblNewPassWord1
			// 
			this.lblNewPassWord1.AutoSize = true;
			this.lblNewPassWord1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblNewPassWord1.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.lblNewPassWord1.Location = new System.Drawing.Point(38, 148);
			this.lblNewPassWord1.Name = "lblNewPassWord1";
			this.lblNewPassWord1.Size = new System.Drawing.Size(48, 19);
			this.lblNewPassWord1.TabIndex = 4;
			this.lblNewPassWord1.Text = "新密码";
			// 
			// txtNew2
			// 
			this.txtNew2.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.txtNew2.Location = new System.Drawing.Point(136, 196);
			this.txtNew2.Name = "txtNew2";
			this.txtNew2.PasswordChar = '*';
			this.txtNew2.Size = new System.Drawing.Size(168, 29);
			this.txtNew2.TabIndex = 5;
			this.txtNew2.Text = "";
			this.txtNew2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtNew2_KeyPress);
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label2.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.label2.Location = new System.Drawing.Point(48, 198);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(34, 19);
			this.label2.TabIndex = 6;
			this.label2.Text = "确认";
			// 
			// btnChance
			// 
			this.btnChance.Font = new System.Drawing.Font("隶书", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.btnChance.Location = new System.Drawing.Point(88, 248);
			this.btnChance.Name = "btnChance";
			this.btnChance.Size = new System.Drawing.Size(80, 32);
			this.btnChance.TabIndex = 7;
			this.btnChance.Text = "修改(&C)";
			this.btnChance.Click += new System.EventHandler(this.btnChance_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.Font = new System.Drawing.Font("隶书", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.btnCancel.Location = new System.Drawing.Point(200, 248);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(80, 32);
			this.btnCancel.TabIndex = 8;
			this.btnCancel.Text = "取消(&E)";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// frmTeaPassWord
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
			this.ClientSize = new System.Drawing.Size(368, 301);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnChance);
			this.Controls.Add(this.txtNew2);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.txtNew1);
			this.Controls.Add(this.lblNewPassWord1);
			this.Controls.Add(this.txtOld);
			this.Controls.Add(this.lblOldTeaPassWord);
			this.Controls.Add(this.lblTeaID);
			this.Controls.Add(this.lblTeacherID);
			this.Font = new System.Drawing.Font("宋体", 7.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.Name = "frmTeaPassWord";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "教师密码修改";
			this.Load += new System.EventHandler(this.frmTeaPassWord_Load);
			this.ResumeLayout(false);

		}
		#endregion

		//订阅“邮递员”
		private void Post_EventSendLoginedID(object obj, object teacher, string formName)
		{
			if(teacher.GetType().ToString().Equals("BusinessRule.AdminTeacher"))
			{
				this.Ateacher = (AdminTeacher)teacher;
			}
			else if(teacher.GetType().ToString().Equals("BusinessRule.MasterTeacher"))
			{
				this.Mteacher = (MasterTeacher)teacher;
			}
			else
			{
				this.Pteacher = (PrelectTeacher)teacher;
			}
			Post.EventSendLoginedID -=new DataAccess.Post.SendMsgDelegate(Post_EventSendLoginedID);
		}

		//获得实例化好的用户实例
		public Teacher User
		{
			get
			{
				if(Ateacher != null)
				{
					return Ateacher;
				}
				else if(Mteacher != null)
				{
					return Mteacher;
				}
				else
				{
					return Pteacher;
				}
			}
		}

		//“修改”按钮
		private void btnChance_Click(object sender, System.EventArgs e)
		{
			string old = txtOld.Text.Trim();
			string new1 = txtNew1.Text.Trim();
			string new2 = txtNew2.Text.Trim();

			if(!this.User.CheckUp(frmMain.UserID,old))
			{
				MessageBox.Show("密码不匹配!","密码错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
				TxtBoxClear();
			}
			else if(!new1.Equals(new2))
			{
				MessageBox.Show("密码确认错误","错误",MessageBoxButtons.OK ,MessageBoxIcon.Error);
				TxtBoxClear();
			}
			else if((new1 == String.Empty || new2 == String.Empty) && 
				MessageBox.Show("请确认\n\n密码为空?","密码为空?" ,MessageBoxButtons.OKCancel,MessageBoxIcon.Question)
				== DialogResult.Cancel)
			{
				return;
			}
			else
			{
				try
				{
					this.User.NewPassWord(new1);
					MessageBox.Show("密码修改成功","成功",MessageBoxButtons.OK,MessageBoxIcon.Information);
					this.Close();
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.Message,"错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
				}
			}
		}


		//“取消”按键
		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		//清空所有密码框
		private void TxtBoxClear()
		{
			this.txtOld.Text = "";
			this.txtNew1.Text = "";
			this.txtNew2.Text = "";
			this.txtOld.Focus();
		}

		

		//所有文本框,支持直接回车调用修改密码程序
		private void txtOld_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if(e.KeyChar == (char)13 )
			{
				btnChance_Click(sender,e);
			}
		}
		private void txtNew1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if(e.KeyChar == (char)13 )
			{
				btnChance_Click(sender,e);
			}
		}
		private void txtNew2_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if(e.KeyChar == (char)13 )
			{
				btnChance_Click(sender,e);
			}
		}

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

		
	}
}

⌨️ 快捷键说明

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