📄 login.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using SupDataBase;
using System.Data.SqlClient;
using System.Data;
using AppSuperMarket;
namespace WindowsApplication1
{
/// <summary>
/// Login 的摘要说明。
/// </summary>
public class Login : System.Windows.Forms.Form
{
private System.Windows.Forms.Button m_bntComfirm;
private System.Windows.Forms.Button m_bntCancel;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox m_txtUserName;
private System.Windows.Forms.TextBox m_txtPassword;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Login()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this.Visible = false;
//
// 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.m_bntComfirm = new System.Windows.Forms.Button();
this.m_bntCancel = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.m_txtUserName = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.m_txtPassword = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// m_bntComfirm
//
this.m_bntComfirm.DialogResult = System.Windows.Forms.DialogResult.OK;
this.m_bntComfirm.Location = new System.Drawing.Point(64, 112);
this.m_bntComfirm.Name = "m_bntComfirm";
this.m_bntComfirm.Size = new System.Drawing.Size(64, 23);
this.m_bntComfirm.TabIndex = 0;
this.m_bntComfirm.Text = "确认";
this.m_bntComfirm.Click += new System.EventHandler(this.m_bntComfirm_Click);
//
// m_bntCancel
//
this.m_bntCancel.Location = new System.Drawing.Point(176, 112);
this.m_bntCancel.Name = "m_bntCancel";
this.m_bntCancel.Size = new System.Drawing.Size(64, 23);
this.m_bntCancel.TabIndex = 1;
this.m_bntCancel.Text = "退出";
this.m_bntCancel.Click += new System.EventHandler(this.m_bntCancel_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(56, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 23);
this.label1.TabIndex = 2;
this.label1.Text = "用户名";
//
// m_txtUserName
//
this.m_txtUserName.Location = new System.Drawing.Point(136, 32);
this.m_txtUserName.Name = "m_txtUserName";
this.m_txtUserName.Size = new System.Drawing.Size(104, 21);
this.m_txtUserName.TabIndex = 3;
this.m_txtUserName.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(56, 80);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(40, 16);
this.label2.TabIndex = 4;
this.label2.Text = "密码";
//
// m_txtPassword
//
this.m_txtPassword.Location = new System.Drawing.Point(136, 72);
this.m_txtPassword.Name = "m_txtPassword";
this.m_txtPassword.PasswordChar = '*';
this.m_txtPassword.Size = new System.Drawing.Size(104, 21);
this.m_txtPassword.TabIndex = 5;
this.m_txtPassword.Text = "";
//
// Login
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(328, 166);
this.Controls.Add(this.m_txtPassword);
this.Controls.Add(this.m_txtUserName);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.m_bntCancel);
this.Controls.Add(this.m_bntComfirm);
this.MaximizeBox = false;
this.Name = "Login";
this.Text = "登录";
this.Load += new System.EventHandler(this.Login_Load);
this.Closed += new System.EventHandler(this.Login_Closed);
this.ResumeLayout(false);
}
#endregion
private void m_bntComfirm_Click(object sender, System.EventArgs e)
{
string username = this.m_txtUserName.Text.Replace("'","");
string pwd = this.m_txtPassword.Text.Replace("'","");
username.Trim();
pwd.Trim();
string sql = "select * from Employee where UserName='"+ username + "' and Password='" + pwd+"'";
try
{
SqlConnection conn = DBUtil.GetConnection();
SqlCommand command = new SqlCommand ("",conn);
command.Connection.Open();
command.CommandText = sql;
SqlDataReader reader = command.ExecuteReader();
if(reader.Read())
{
int employeeid = System.Convert.ToInt32(reader["EmployeeID"].ToString());
int priority = System.Convert.ToInt32(reader["Priority"].ToString());
username = reader["UserName"].ToString();
DBUtil.SetEmployeeID(employeeid);
DBUtil.SetPriority(priority);
DBUtil.SetUserName(username);
DBUtil.SetLoginStatus(true);
this.Close();
//MainForm mainform = new MainForm();
//mainform.Show();
}
else {
MessageBox.Show("用户名密码或错误!");
conn.Close();
return;
}
conn.Close();
}
catch(SqlException ex)
{
MessageBox.Show("用户名密码或错误!");
m_txtPassword.Text="";
return;
}
}
private void m_bntCancel_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void Login_Closed(object sender, System.EventArgs e)
{
}
private void Login_Load(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -