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

📄 登陆窗.cs

📁 简单的教师录入成绩系统
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace 教师网上录入成绩
{
	/// <summary>
	/// 登陆窗 的摘要说明。
	/// </summary>
	public class 登陆窗 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;

		private string connectionString = "workstation id=localhost;Integrated Security=SSPI;database=jiaoshi";
		private System.Data.SqlClient.SqlConnection myConnection;
		private System.Data.DataTable myTable;
		private System.Data.DataRow myRow;
		private System.Data.DataSet ds = new System.Data.DataSet();
		private System.Data.SqlClient.SqlDataAdapter da;
		private string StrSQL = "SELECT * from 教师基本信息";
		private string tempTableName ="教师";
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public 登陆窗()
		{
			//
			// 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.textBox1 = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(48, 64);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(56, 24);
			this.label1.TabIndex = 0;
			this.label1.Text = "教师号";
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(144, 64);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(88, 21);
			this.textBox1.TabIndex = 1;
			this.textBox1.Text = "";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(48, 120);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(64, 16);
			this.label2.TabIndex = 2;
			this.label2.Text = "密码";
			// 
			// textBox2
			// 
			this.textBox2.Location = new System.Drawing.Point(144, 120);
			this.textBox2.Name = "textBox2";
			this.textBox2.PasswordChar = '*';
			this.textBox2.Size = new System.Drawing.Size(88, 21);
			this.textBox2.TabIndex = 3;
			this.textBox2.Text = "";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(40, 192);
			this.button1.Name = "button1";
			this.button1.TabIndex = 4;
			this.button1.Text = "登陆";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(152, 192);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(80, 24);
			this.button2.TabIndex = 5;
			this.button2.Text = "取消";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// 登陆窗
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(292, 253);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.textBox2);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.label1);
			this.Name = "登陆窗";
			this.Text = "登陆窗";
			this.Load += new System.EventHandler(this.登陆窗_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void 登陆窗_Load(object sender, System.EventArgs e)
		{
			this.myConnection = new System.Data.SqlClient.SqlConnection(connectionString);
			this.da = new System.Data.SqlClient.SqlDataAdapter(this.StrSQL,this.myConnection);
			this.ds.Clear();
			try
			{
				this.da.Fill(ds,tempTableName);
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
			this.myTable = ds.Tables[0];
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			for (int i=0;i<myTable.Rows.Count;i++)
			{
				this.myRow = myTable.Rows[i];
				//只有当输入的用户名和密码同时对应上数据库中记录时,才能通过校验
				if (myRow[0].ToString().Trim()==this.textBox1.Text.ToString().Trim() && myRow[7].ToString().Trim()==this.textBox2.Text.ToString().Trim())
				{					
					TeacAddGrade ii = new TeacAddGrade();
					ii.Show();
					
					this.Close();//关闭窗体

					return;
				}
			}
			MessageBox.Show( "您输入的用户号或密码不正确!");
			return;
		
		}

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

⌨️ 快捷键说明

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