📄 login.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace HrSalary.user
{
/// <summary>
/// login 的摘要说明。
/// </summary>
public class login : System.Windows.Forms.Form
{
public int loginflag=0;
public string displaystyle="";
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.ColorDialog colorDialog1;
private System.Windows.Forms.Label label2;
private OleDbConnection dbCon = 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()
{
this.label1 = new System.Windows.Forms.Label();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label3 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.colorDialog1 = new System.Windows.Forms.ColorDialog();
this.label2 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.BackColor = System.Drawing.Color.Transparent;
this.label1.Font = new System.Drawing.Font("华文行楷", 21.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.ForeColor = System.Drawing.Color.Blue;
this.label1.Location = new System.Drawing.Point(24, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(256, 32);
this.label1.TabIndex = 0;
this.label1.Text = "Hr工资管理系统";
//
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.Location = new System.Drawing.Point(88, 72);
this.comboBox1.MaxDropDownItems = 5;
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 20);
this.comboBox1.TabIndex = 1;
//
// label3
//
this.label3.BackColor = System.Drawing.Color.Transparent;
this.label3.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label3.ForeColor = System.Drawing.Color.Blue;
this.label3.Location = new System.Drawing.Point(40, 112);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(56, 23);
this.label3.TabIndex = 3;
this.label3.Text = "密码";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(88, 104);
this.textBox1.Name = "textBox1";
this.textBox1.PasswordChar = '*';
this.textBox1.Size = new System.Drawing.Size(120, 21);
this.textBox1.TabIndex = 4;
this.textBox1.Text = "";
//
// button1
//
this.button1.BackColor = System.Drawing.Color.Transparent;
this.button1.ForeColor = System.Drawing.Color.Blue;
this.button1.Location = new System.Drawing.Point(48, 144);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(80, 24);
this.button1.TabIndex = 5;
this.button1.Text = "登陆";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.BackColor = System.Drawing.Color.Transparent;
this.button2.ForeColor = System.Drawing.Color.Blue;
this.button2.Location = new System.Drawing.Point(136, 144);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(80, 24);
this.button2.TabIndex = 6;
this.button2.Text = "取消";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label2
//
this.label2.BackColor = System.Drawing.Color.Transparent;
this.label2.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label2.ForeColor = System.Drawing.Color.Blue;
this.label2.Location = new System.Drawing.Point(40, 72);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 23);
this.label2.TabIndex = 2;
this.label2.Text = "用户";
//
// login
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.AliceBlue;
this.ClientSize = new System.Drawing.Size(264, 181);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label3);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.label2);
this.ForeColor = System.Drawing.SystemColors.InfoText;
this.Name = "login";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "登陆";
this.Load += new System.EventHandler(this.login_load);
this.ResumeLayout(false);
}
#endregion
private void login_load(object sender, System.EventArgs e)
{
if(dbCon==null) dbCon = MainForm.getConnection();
OleDbCommand cmd = dbCon.CreateCommand();
cmd.CommandText = "select name from a_user";
//取出系统的所有用户名
//显示在下拉列表,这样用户登录的时候
//选择用户名就可以了,不用再输入用户名了
OleDbDataReader reader = cmd.ExecuteReader();
int flag = 0;
while(reader.Read())
{
this.comboBox1.Items.Add(reader.GetString(0));
flag++;
}
if(flag>0)//如果系统存在用户,则默认选中第一个用户
this.comboBox1.SelectedIndex = 0;
reader.Close();
cmd.Dispose();
}
//单击[登录]按钮的事件处理
private void button1_Click(object sender, System.EventArgs e)
{
try
{
string sql="select passwd,staff,salary from a_user where name='"+this.comboBox1.Text +"'";
if(dbCon==null) dbCon = MainForm.getConnection();
OleDbCommand cmd = dbCon.CreateCommand();
cmd.CommandText =sql;
OleDbDataReader reader = cmd.ExecuteReader();
if(!reader.Read())
{
MessageBox.Show("无此用户,请重试!");
reader.Close();
cmd.Dispose();
return;
}
else
{
if(!reader.GetString(0).Equals (this.textBox1.Text.ToString()))
{
MessageBox.Show("\n密码错误,请重试!");
reader.Close();
cmd.Dispose();
return;
}
Menu mainmenu=((MainForm)(this.MdiParent)).getMainMenu();
if(reader.GetBoolean(1))
mainmenu.MenuItems[1].Visible=true;
mainmenu.MenuItems[0].Visible=true;
mainmenu.MenuItems[2].Visible=true;
if(this.comboBox1.Text.Equals("系统管理员"))
{
mainmenu.MenuItems[3].Visible=true;
for(int i=0;i<3;i++)
mainmenu.MenuItems[3].MenuItems[i].Visible=true;
}
else
{
}
reader.Close();
cmd.Dispose();
this.Close();
}
}
catch(Exception ee)
{
MessageBox.Show("\n"+ee.ToString());
}
}
//单击取消按钮
private void button2_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -