📄 classid.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>
/// ClassID 的摘要说明。
/// </summary>
public class ClassID : System.Windows.Forms.Form
{
public static string UserID,result;
private DataSet ds=new DataSet();
private string sendStrSQL="select * from 用户";
private DataTable myTable;
private DataRow myRow;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Button btnConfirm;
private System.Windows.Forms.TextBox txtPsw;
private System.Windows.Forms.TextBox txtName;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public ClassID()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
LinkDataBase link=new LinkDataBase();
string sendTableName="用户";
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 = 16;
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 = 15;
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 = 12;
this.txtPsw.Text = "";
//
// txtName
//
this.txtName.Location = new System.Drawing.Point(150, 34);
this.txtName.Name = "txtName";
this.txtName.TabIndex = 11;
this.txtName.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(46, 72);
this.label2.Name = "label2";
this.label2.TabIndex = 14;
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 = 13;
this.label1.Text = "用户名";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// ClassID
//
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 = "ClassID";
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[1].ToString().Trim()&&this.txtPsw.Text.Trim()==myRow[2].ToString().Trim())
{
MainFrm.lg=true;
UserID=myRow[4].ToString().Trim();
result=this.GetClassName();
this.Close();
return;
}
}
MessageBox.Show("用户名或密码错误");
return;
}
private string GetClassName()
{
string StrSQL="workstation id=localhost;Integrated Security=SSPI;database=stu01";
SqlConnection conn=new SqlConnection(StrSQL);
conn.Open();
SqlCommand cmd=conn.CreateCommand();
cmd.CommandText="select 班级名称 from 班级 where(班级编号='"+UserID.Trim()+"')";
object result=cmd.ExecuteScalar();
return result.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 + -