?? frmlogin.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace AdminGoods
{
/// <summary>
/// Form1 的摘要說明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
public System.Windows.Forms.TextBox txtUsername;
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button btOK;
private System.Windows.Forms.Button btExit;
/// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1( )
{
//
// 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.txtUsername = new System.Windows.Forms.TextBox();
this.txtPassword = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.btOK = new System.Windows.Forms.Button();
this.btExit = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// txtUsername
//
this.txtUsername.Location = new System.Drawing.Point(112, 24);
this.txtUsername.Name = "txtUsername";
this.txtUsername.Size = new System.Drawing.Size(136, 21);
this.txtUsername.TabIndex = 0;
this.txtUsername.Text = "";
//
// txtPassword
//
this.txtPassword.Location = new System.Drawing.Point(112, 64);
this.txtPassword.Name = "txtPassword";
this.txtPassword.PasswordChar = '*';
this.txtPassword.Size = new System.Drawing.Size(136, 21);
this.txtPassword.TabIndex = 1;
this.txtPassword.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(88, 16);
this.label1.TabIndex = 2;
this.label1.Text = "username";
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 64);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(88, 16);
this.label2.TabIndex = 3;
this.label2.Text = "password";
//
// btOK
//
this.btOK.Location = new System.Drawing.Point(64, 112);
this.btOK.Name = "btOK";
this.btOK.Size = new System.Drawing.Size(80, 24);
this.btOK.TabIndex = 4;
this.btOK.Text = "Login";
this.btOK.Click += new System.EventHandler(this.btOK_Click);
//
// btExit
//
this.btExit.Location = new System.Drawing.Point(176, 112);
this.btExit.Name = "btExit";
this.btExit.Size = new System.Drawing.Size(80, 24);
this.btExit.TabIndex = 5;
this.btExit.Text = "Exit";
this.btExit.Click += new System.EventHandler(this.btExit_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 149);
this.Controls.Add(this.btExit);
this.Controls.Add(this.btOK);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtPassword);
this.Controls.Add(this.txtUsername);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 應用程序的主入口點。
/// </summary>
private void btOK_Click(object sender, System.EventArgs e)
{
string username = this.txtUsername.Text.Trim().ToString();
string password = this.txtPassword.Text.Trim().ToString();
if( this.LoginCheck( username , password ) )
{
MessageBox.Show(this,"登陸成功!");
this.Close();
}
else
{
MessageBox.Show(this,"登陸失敗!");
return;
}
}
private bool LoginCheck(string username,string password)
{
bool login = false;
Database db = new Database();
try
{
System.Data.SqlClient.SqlConnection conn = db.openConn();
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandText = "select * from worker where username = '" + username + "' and password = '" + password + "' ";
cmd.Connection = conn;
System.Data.SqlClient.SqlDataReader rs = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
while(rs.Read())
{
login =true;
}
}
catch(Exception ex)
{
string msg = ex.Message ;
}
finally
{
db.closeConn ();
}
return login;
}
private void btExit_Click(object sender, System.EventArgs e)
{
this.txtUsername .Text = "null";
this.Close();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -