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

📄 addcourse.cs

📁 这是用SQL数据库做的学生信息管理系统。简明
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace 学生与成绩
{
	/// <summary>
	/// AddCourse 的摘要说明。
	/// </summary>
	public class AddCourse : System.Windows.Forms.Form
	{
		public static string UserID;
		private DataSet ds=new DataSet();
		private string sendStrSQL="select 用户名,密码 from 用户";
		private string sendTableName="用户";
		private DataTable myTable;
		private DataRow myRow;
		private System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.Button btnConfirm;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox txtPsw;
		private System.Windows.Forms.TextBox txtName;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public AddCourse()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			LinkDataBase link=new LinkDataBase();
			this.ds=link.SelectDataBase(sendStrSQL,sendTableName);
			myTable=ds.Tables[0];


			//
			// 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.btnCancel = new System.Windows.Forms.Button();
			this.btnConfirm = new System.Windows.Forms.Button();
			this.txtPsw = new System.Windows.Forms.TextBox();
			this.txtName = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// btnCancel
			// 
			this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnCancel.Location = new System.Drawing.Point(163, 128);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.TabIndex = 10;
			this.btnCancel.Text = "取消";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// btnConfirm
			// 
			this.btnConfirm.Location = new System.Drawing.Point(59, 128);
			this.btnConfirm.Name = "btnConfirm";
			this.btnConfirm.TabIndex = 9;
			this.btnConfirm.Text = "确定";
			this.btnConfirm.Click += new System.EventHandler(this.btnConfirm_Click);
			// 
			// txtPsw
			// 
			this.txtPsw.Location = new System.Drawing.Point(150, 72);
			this.txtPsw.Name = "txtPsw";
			this.txtPsw.PasswordChar = '*';
			this.txtPsw.TabIndex = 5;
			this.txtPsw.Text = "";
			// 
			// txtName
			// 
			this.txtName.Location = new System.Drawing.Point(150, 34);
			this.txtName.Name = "txtName";
			this.txtName.TabIndex = 0;
			this.txtName.Text = "";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(46, 72);
			this.label2.Name = "label2";
			this.label2.TabIndex = 7;
			this.label2.Text = "密码";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(46, 32);
			this.label1.Name = "label1";
			this.label1.TabIndex = 6;
			this.label1.Text = "用户名";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// AddCourse
			// 
			this.AcceptButton = this.btnConfirm;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.CancelButton = this.btnCancel;
			this.ClientSize = new System.Drawing.Size(296, 182);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnConfirm);
			this.Controls.Add(this.txtPsw);
			this.Controls.Add(this.txtName);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Name = "AddCourse";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "添加课程";
			this.ResumeLayout(false);

		}
		#endregion

		private void btnConfirm_Click(object sender, System.EventArgs e)
		{
			for(int i=0;i<myTable.Rows.Count;i++)
			{
				myRow=myTable.Rows[i];
				if(this.txtName.Text.Trim()==myRow[0].ToString().Trim()&&this.txtPsw.Text.Trim()==myRow[1].ToString().Trim())
				{
					MainFrm.lg=true;
					UserID=this.GetUserID();;
					this.Close();
					return;
				}
		
			}
			MessageBox.Show("用户名或密码不正确","提示");
			return;
		}
		private string GetUserID()
		{
			string StrConn="workstation id=localhost;Integrated Security=SSPI;database=stu01";
			SqlConnection conn=new SqlConnection(StrConn);
			conn.Open();
			SqlCommand cmd=conn.CreateCommand();
			cmd.CommandText="select 班级.班级名称 from 班级 inner join 用户 on 班级.班级编号=用户.编号 where(用户.用户名='"+this.txtName.Text.Trim()+"')";
			object UserID=cmd.ExecuteScalar();
			return UserID.ToString();
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			MainFrm.lg=false;
			this.Close();
		}

	}
}

⌨️ 快捷键说明

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