?? 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 MKIms3
{
/// <summary>
/// Login 的摘要說明。
/// </summary>
public class Login : System.Windows.Forms.Form
{
private string u_name;
private string u_pass;
public delegate void SendMessLogin () ;
//定義委托類型
public event SendMessLogin SendLogin ;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label_U;
private System.Windows.Forms.Label label_p;
private System.Windows.Forms.TextBox txt_uname;
private System.Windows.Forms.TextBox txt_upass;
private System.Windows.Forms.Button btn_ok;
private System.Windows.Forms.Button btn_esc;
private System.Windows.Forms.ErrorProvider errP_user;
/// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public Login()
{
//
// 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()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Login));
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label_U = new System.Windows.Forms.Label();
this.label_p = new System.Windows.Forms.Label();
this.txt_uname = new System.Windows.Forms.TextBox();
this.txt_upass = new System.Windows.Forms.TextBox();
this.btn_ok = new System.Windows.Forms.Button();
this.btn_esc = new System.Windows.Forms.Button();
this.errP_user = new System.Windows.Forms.ErrorProvider();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Top;
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(386, 112);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// label_U
//
this.label_U.Location = new System.Drawing.Point(32, 121);
this.label_U.Name = "label_U";
this.label_U.Size = new System.Drawing.Size(56, 23);
this.label_U.TabIndex = 1;
this.label_U.Text = "用戶名:";
this.label_U.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label_p
//
this.label_p.Location = new System.Drawing.Point(200, 121);
this.label_p.Name = "label_p";
this.label_p.Size = new System.Drawing.Size(60, 23);
this.label_p.TabIndex = 2;
this.label_p.Text = "密 碼:";
this.label_p.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// txt_uname
//
this.txt_uname.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txt_uname.Location = new System.Drawing.Point(83, 120);
this.txt_uname.MaxLength = 10;
this.txt_uname.Name = "txt_uname";
this.txt_uname.TabIndex = 0;
this.txt_uname.Text = "";
//
// txt_upass
//
this.txt_upass.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txt_upass.Location = new System.Drawing.Point(256, 120);
this.txt_upass.MaxLength = 10;
this.txt_upass.Name = "txt_upass";
this.txt_upass.PasswordChar = '*';
this.txt_upass.TabIndex = 1;
this.txt_upass.Text = "";
//
// btn_ok
//
this.btn_ok.BackColor = System.Drawing.SystemColors.ActiveBorder;
this.btn_ok.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btn_ok.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_ok.Location = new System.Drawing.Point(168, 152);
this.btn_ok.Name = "btn_ok";
this.btn_ok.Size = new System.Drawing.Size(72, 24);
this.btn_ok.TabIndex = 2;
this.btn_ok.Text = "登陸系統";
this.btn_ok.Click += new System.EventHandler(this.btn_ok_Click);
//
// btn_esc
//
this.btn_esc.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btn_esc.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_esc.Location = new System.Drawing.Point(272, 151);
this.btn_esc.Name = "btn_esc";
this.btn_esc.Size = new System.Drawing.Size(72, 24);
this.btn_esc.TabIndex = 3;
this.btn_esc.Text = "退出登陸";
this.btn_esc.Click += new System.EventHandler(this.btn_esc_Click);
//
// errP_user
//
this.errP_user.ContainerControl = this;
//
// Login
//
this.AcceptButton = this.btn_ok;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.ActiveBorder;
this.CancelButton = this.btn_esc;
this.ClientSize = new System.Drawing.Size(386, 186);
this.Controls.Add(this.btn_esc);
this.Controls.Add(this.btn_ok);
this.Controls.Add(this.txt_upass);
this.Controls.Add(this.txt_uname);
this.Controls.Add(this.label_p);
this.Controls.Add(this.label_U);
this.Controls.Add(this.pictureBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Login";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "系統登陸";
this.TopMost = true;
this.Closing += new System.ComponentModel.CancelEventHandler(this.Login_Closing);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 單擊驗證用戶的身份
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_ok_Click(object sender, System.EventArgs e)
{
Splasher.Status="正在檢測用戶名和密碼......";
if(loing_first()==true)
{
this.Visible = false;
SendLogin();
}
}
private bool LoginCheck()
{
this.u_name = this.txt_uname.Text.Trim();
this.u_pass = this.txt_upass.Text.Trim();
DataBase myDB = new DataBase();
SqlDataReader myReader = null;
SqlParameter[] myParamers={new SqlParameter("@u_name",SqlDbType.Char,10)} ;
myParamers[0].Value = this.u_name;
myReader = myDB.RunProcedure("up_get_upass",myParamers);
if(myReader!=null)
{
if(myReader.Read())
{
if(myReader["u_pass"].ToString().Trim()==this.u_pass)
{
Splasher.Status = "用戶驗證通過,開始加載系統數據...";
App.u_name = myReader["u_name"].ToString();
if(myReader["u_flag"]==null)
{
App.u_flag = (int)flag.user;
}
else
{
App.u_flag = Convert.ToInt32(myReader["u_flag"]);
}
myReader.Close();
return true;
}
else
{
MessageBox.Show("對不起,密碼錯誤!","錯誤",MessageBoxButtons.OK,MessageBoxIcon.Warning);
myReader.Close();
return false;
}
}
else
{
MessageBox.Show("該用戶不存在,請檢查您的輸入是否有誤!","錯誤",MessageBoxButtons.OK,MessageBoxIcon.Warning);
myReader.Close();
return false;
}
}
else
{
return false;
}
}
/// <summary>
/// 開始登陸驗證前的數據檢查工作
/// </summary>
private bool loing_first()
{
if(u_name_isnull() || u_pass_isnull())
{
MessageBox.Show("對不起用戶名和密碼不能為空!","錯誤",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return false;
}
else
{
return LoginCheck();
}
}
/// <summary>
/// 檢測用戶名是否為空
/// </summary>
/// <returns></returns>
private bool u_name_isnull()
{
return (this.txt_uname.Text.Trim().Length==0);
}
/// <summary>
/// 檢測用戶密碼是否為空
/// </summary>
/// <returns></returns>
private bool u_pass_isnull()
{
return (this.txt_upass.Text.Trim().Length==0);
}
/// <summary>
/// 取消登陸,退出程序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_esc_Click(object sender, System.EventArgs e)
{
this.Close();
Application.Exit();
}
private void Login_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Application.Exit();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -