📄 employeelogin.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.SqlClient;//访问数据库
using System.Data;//这也是
namespace AssetManagement//zheng ge gong cheng de ming ming kongjian,
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private string EmployeeNo;//用户号
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private bool check = false;
private MainForm1 mf;//主窗体,放在开头是为了只调用出一个主窗体;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public string GetEmployeeNo//在其他窗体获得用户登陆的用户号的属性;
{
get
{
return EmployeeNo;
}
set
{
EmployeeNo = value;
}
}
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()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(96, 112);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(112, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(96, 160);
this.textBox2.Name = "textBox2";
this.textBox2.PasswordChar = '*';
this.textBox2.Size = new System.Drawing.Size(112, 21);
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
//
// button1
//
this.button1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button1.Location = new System.Drawing.Point(88, 216);
this.button1.Name = "button1";
this.button1.TabIndex = 2;
this.button1.Text = "确定";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button2.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button2.Location = new System.Drawing.Point(216, 216);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 24);
this.button2.TabIndex = 3;
this.button2.Text = "取消";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label1
//
this.label1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.Location = new System.Drawing.Point(8, 112);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 24);
this.label1.TabIndex = 4;
this.label1.Text = "用户号";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label1.Click += new System.EventHandler(this.label1_Click);
//
// label2
//
this.label2.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label2.Location = new System.Drawing.Point(8, 160);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(80, 23);
this.label2.TabIndex = 5;
this.label2.Text = "密码";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label3
//
this.label3.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.label3.Font = new System.Drawing.Font("楷体_GB2312", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label3.Image = ((System.Drawing.Image)(resources.GetObject("label3.Image")));
this.label3.Location = new System.Drawing.Point(-8, 0);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(352, 80);
this.label3.TabIndex = 6;
this.label3.Text = "资产管理系统";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label4
//
this.label4.Location = new System.Drawing.Point(224, 112);
this.label4.Name = "label4";
this.label4.TabIndex = 7;
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// Form1
//
this.AcceptButton = this.button1;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.CancelButton = this.button2;
this.ClientSize = new System.Drawing.Size(338, 256);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "系统登录";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());//程序入口
}
private void label1_Click(object sender, System.EventArgs e)
{
}
//mainForm main1 = new mainForm(textBox1.Text);
private void button1_Click(object sender, System.EventArgs e)
{
//this.AcceptButton = this.button1;
this.GetEmployeeNo = textBox1.Text.Trim().ToUpper();
//mainForm main1 = new mainForm(this.GetEmployeeNo);
employee em = new employee();//这在类文件中有;
mf = new MainForm1(this.GetEmployeeNo);//这是将用户号调到主窗体中
//mf.Show();
em.Open();
int s = em.employeeLogin((textBox1.Text.Trim().ToUpper()).ToString(),(textBox2.Text).ToString());
if (s==1)
{
if (!mf.IsDisposed)
{
this.Visible = false;
mf.Show();
mf.ReturnClick +=new AssetManagement.MainForm1.ReturnHandler(mf_ReturnClick);
mf.Focus();
//this.Enabled = true;
}
else
{
mf = new MainForm1(textBox1.Text.Trim().ToUpper());
this.Visible = false;
mf.Show();
mf.ReturnClick +=new AssetManagement.MainForm1.ReturnHandler(mf_ReturnClick);
}
}
else
{
if (this.textBox1.Text.Trim() == "")
{
MessageBox.Show("请输入用户号!");
this.textBox1.Focus();
}
else
{
if (this.textBox2.Text.Trim() == "")
{
MessageBox.Show("请输入密码!");
this.textBox2.Focus();
}
else
{
if (!check)
{
MessageBox.Show("用户号错误!");
this.textBox2.Text = "";
this.textBox1.Text = "";
this.textBox1.Focus();
}
else
{
MessageBox.Show("密码不正确!");
this.textBox2.Text = "";
this.textBox2.Focus();
}
}
}
}
em.Close();
}
private void button2_Click(object sender, System.EventArgs e)
{
//this.CancelButton = button2;
this.Close();
}
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
if (this.textBox1.Text.Trim().Length > 8)
{
MessageBox.Show("输入数据无效!");
this.label4.Text = "";
this.textBox1.Text = "";
this.textBox1.Focus();
}
else
{
Connection s = new Connection();
SqlConnection conn = new SqlConnection(s.getConnectionString);
conn.Open();
string str = "select * from employee";
SqlCommand cmd = new SqlCommand(str,conn);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
if (this.textBox1.Text.Trim().ToUpper() == Convert.ToString(dr["employeeNo"]))
{
this.label4.Text = Convert.ToString(dr["employeeName"]);
check = true;
break;
}
check = false;
}
dr.Close();
conn.Close();
}
if (!check)
{
this.label4.Text = "";
}
}
private void textBox2_TextChanged(object sender, System.EventArgs e)
{
if (this.textBox1.Text.Trim().Length > 20)
{
MessageBox.Show("输入长度不能超过20位!");
this.textBox1.Text = "";
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private void mf_ReturnClick()
{
this.Visible = true;
this.textBox1.Text = "";
this.textBox1.Focus();
this.textBox2.Text = "";
mf.getdispose(false);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -