?? login.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;
namespace Library
{
/// <summary>
/// Login 的摘要說明。
/// </summary>
public class LoginForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.TextBox textUserID;
private System.Windows.Forms.TextBox textUserPassword;
private System.Windows.Forms.Button btnOk;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private System.Windows.Forms.Label lblUser;
private System.Windows.Forms.Label lblPassword;
private System.Windows.Forms.Label lbltitle;
/// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public LoginForm()
{
//
// 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.lblUser = new System.Windows.Forms.Label();
this.lblPassword = new System.Windows.Forms.Label();
this.btnCancel = new System.Windows.Forms.Button();
this.textUserID = new System.Windows.Forms.TextBox();
this.textUserPassword = new System.Windows.Forms.TextBox();
this.btnOk = new System.Windows.Forms.Button();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.lbltitle = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lblUser
//
this.lblUser.Font = new System.Drawing.Font("宋體", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.lblUser.Location = new System.Drawing.Point(40, 56);
this.lblUser.Name = "lblUser";
this.lblUser.Size = new System.Drawing.Size(72, 23);
this.lblUser.TabIndex = 1;
this.lblUser.Text = "用戶名:";
//
// lblPassword
//
this.lblPassword.Font = new System.Drawing.Font("宋體", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.lblPassword.Location = new System.Drawing.Point(40, 104);
this.lblPassword.Name = "lblPassword";
this.lblPassword.Size = new System.Drawing.Size(72, 23);
this.lblPassword.TabIndex = 2;
this.lblPassword.Text = "密 碼:";
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(144, 152);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(64, 24);
this.btnCancel.TabIndex = 3;
this.btnCancel.Text = "重置";
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// textUserID
//
this.textUserID.Location = new System.Drawing.Point(112, 56);
this.textUserID.Name = "textUserID";
this.textUserID.Size = new System.Drawing.Size(96, 21);
this.textUserID.TabIndex = 0;
this.textUserID.Text = "";
//
// textUserPassword
//
this.textUserPassword.Location = new System.Drawing.Point(112, 104);
this.textUserPassword.Name = "textUserPassword";
this.textUserPassword.PasswordChar = '*';
this.textUserPassword.Size = new System.Drawing.Size(96, 21);
this.textUserPassword.TabIndex = 1;
this.textUserPassword.Text = "";
//
// btnOk
//
this.btnOk.Location = new System.Drawing.Point(40, 152);
this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size(64, 24);
this.btnOk.TabIndex = 6;
this.btnOk.Text = "登錄";
this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=WJD;packet size=4096;integrated security=SSPI;data source=WJD;pers" +
"ist security info=False;initial catalog=BookManagement";
//
// lbltitle
//
this.lbltitle.Font = new System.Drawing.Font("隸書", 21.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.lbltitle.ForeColor = System.Drawing.Color.Blue;
this.lbltitle.Location = new System.Drawing.Point(56, 8);
this.lbltitle.Name = "lbltitle";
this.lbltitle.Size = new System.Drawing.Size(136, 32);
this.lbltitle.TabIndex = 8;
this.lbltitle.Text = "登 錄";
this.lbltitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// LoginForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.LightGray;
this.ClientSize = new System.Drawing.Size(250, 194);
this.Controls.Add(this.lbltitle);
this.Controls.Add(this.btnOk);
this.Controls.Add(this.textUserPassword);
this.Controls.Add(this.textUserID);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.lblPassword);
this.Controls.Add(this.lblUser);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "LoginForm";
this.Text = "圖書出租管理系統";
this.Load += new System.EventHandler(this.Login_Load);
this.ResumeLayout(false);
}
#endregion
static void Main()
{
Application.Run(new LoginForm());
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
this.textUserID.Text="";
this.textUserPassword.Text="";
}
private void btnOk_Click(object sender, System.EventArgs e)
{
if(UserCheck(this.textUserID.Text,this.textUserPassword.Text)=="system")
{
this.Visible=false;
Form mainform=new MainForm(this.textUserID.Text,"system");
mainform.ShowDialog();
this.Close();
}
else if(UserCheck(this.textUserID.Text,this.textUserPassword.Text)=="user")
{
this.Visible=false;
Form mainform=new MainForm(this.textUserID.Text,"user");
mainform.ShowDialog();
this.Close();
}
else
{
if(MessageBox.Show("輸入用戶密碼有誤,是否重新登陸","輸入有誤",MessageBoxButtons.OKCancel,MessageBoxIcon.Question)==DialogResult.OK)
{
this.textUserID.Clear();
this.textUserPassword.Clear();
//this.textUserID.();
}
else
{
this.Close();
}
}
}
string UserCheck(string username,string userpassword)
{
string txtSql,usersort;
usersort="nobody";
txtSql = "SELECT * FROM [User]";
SqlCommand checkuser=new SqlCommand(txtSql,this.sqlConnection1);
try
{
this.sqlConnection1.Open();
SqlDataReader sqlreader=checkuser.ExecuteReader();
while(sqlreader.Read())
{
if((sqlreader[0].ToString().Trim()==username)&&(sqlreader[1].ToString().Trim()==userpassword))
{
usersort=sqlreader[2].ToString().Trim();
break;
}
}
}
catch(Exception e)
{
//Console.WriteLine(e.ToString());
MessageBox.Show(e.ToString());
}
sqlConnection1.Close();
//return "nobody";
return usersort;
}
private void Login_Load(object sender, System.EventArgs e)
{
//this.sqlConnection1.Open();
//this.sqlDataAdapter1.Fill(this.dataSetUser1);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -