?? loginform.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;
namespace DataServer
{
/// <summary>
/// LoginForm 的摘要說明。
/// </summary>
public class LoginForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btn_ok;
private System.Windows.Forms.Button btn_close;
private System.Windows.Forms.TextBox tb_login;
private System.Windows.Forms.TextBox tb_passwd;
private System.Windows.Forms.Label lb_login;
private System.Windows.Forms.Label lb_passwd;
/// <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.btn_ok = new System.Windows.Forms.Button();
this.btn_close = new System.Windows.Forms.Button();
this.lb_login = new System.Windows.Forms.Label();
this.lb_passwd = new System.Windows.Forms.Label();
this.tb_login = new System.Windows.Forms.TextBox();
this.tb_passwd = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// btn_ok
//
this.btn_ok.Location = new System.Drawing.Point(48, 128);
this.btn_ok.Name = "btn_ok";
this.btn_ok.Size = new System.Drawing.Size(72, 24);
this.btn_ok.TabIndex = 3;
this.btn_ok.Text = "OK(&O)";
this.btn_ok.Click += new System.EventHandler(this.btn_ok_Click);
//
// btn_close
//
this.btn_close.Location = new System.Drawing.Point(144, 128);
this.btn_close.Name = "btn_close";
this.btn_close.Size = new System.Drawing.Size(72, 24);
this.btn_close.TabIndex = 4;
this.btn_close.Text = "Close(&C)";
this.btn_close.Click += new System.EventHandler(this.btn_close_Click);
//
// lb_login
//
this.lb_login.Location = new System.Drawing.Point(32, 32);
this.lb_login.Name = "lb_login";
this.lb_login.Size = new System.Drawing.Size(48, 16);
this.lb_login.TabIndex = 2;
this.lb_login.Text = "LogID:";
//
// lb_passwd
//
this.lb_passwd.Location = new System.Drawing.Point(32, 80);
this.lb_passwd.Name = "lb_passwd";
this.lb_passwd.Size = new System.Drawing.Size(48, 16);
this.lb_passwd.TabIndex = 3;
this.lb_passwd.Text = "PassWD:";
//
// tb_login
//
this.tb_login.Location = new System.Drawing.Point(80, 24);
this.tb_login.Name = "tb_login";
this.tb_login.Size = new System.Drawing.Size(152, 21);
this.tb_login.TabIndex = 1;
this.tb_login.Text = "0000";
//
// tb_passwd
//
this.tb_passwd.Location = new System.Drawing.Point(80, 72);
this.tb_passwd.Name = "tb_passwd";
this.tb_passwd.Size = new System.Drawing.Size(152, 21);
this.tb_passwd.TabIndex = 2;
this.tb_passwd.Text = "";
//
// LoginForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(264, 165);
this.Controls.Add(this.tb_passwd);
this.Controls.Add(this.tb_login);
this.Controls.Add(this.lb_passwd);
this.Controls.Add(this.lb_login);
this.Controls.Add(this.btn_close);
this.Controls.Add(this.btn_ok);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "LoginForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "LoginForm";
this.Load += new System.EventHandler(this.LoginForm_Load);
this.ResumeLayout(false);
}
#endregion
private void btn_ok_Click(object sender, System.EventArgs e)
{
string strSql ="select * from code_operator where oper_code = @oper_code and pwd = @pwd";
SqlCommand command = new SqlCommand(strSql,DBConnect.Instance().cn);
command.Parameters.Add("@oper_code",SqlDbType.VarChar ,20) ;
command.Parameters["@oper_code"].Value = tb_login.Text ;
command.Parameters.Add("@pwd",SqlDbType.VarChar ,20) ;
command.Parameters["@pwd"].Value = tb_passwd.Text ;
SqlDataAdapter sda = new SqlDataAdapter(command) ;
try
{
DataSet dsUser = new DataSet() ;
sda.Fill(dsUser) ;
if (dsUser.Tables[0].Rows.Count == 0)
{
MessageBox.Show("用戶名或密碼出錯!");
return;
}
}
catch(Exception)
{
MessageBox.Show("系統登陸出錯!");
return;
}
DialogResult = DialogResult.OK;
return;
}
private void btn_close_Click(object sender, System.EventArgs e)
{
DialogResult = DialogResult.Cancel;
return;
}
private void LoginForm_Load(object sender, System.EventArgs e)
{
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -