📄 login.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data ;
using System.Data .SqlClient ;
namespace RoomManage
{
/// <summary>
/// login 的摘要说明。
/// </summary>
public class login : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button button3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public login()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
static void Main()
{
login log=new login ();
log.ShowDialog ();
Application.Run (new main (cc,ss));
}
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.label2 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label3 = new System.Windows.Forms.Label();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.Location = new System.Drawing.Point(16, 23);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 23);
this.label1.TabIndex = 0;
this.label1.Text = "操作员:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label2
//
this.label2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label2.Location = new System.Drawing.Point(16, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 23);
this.label2.TabIndex = 1;
this.label2.Text = "密 码:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(80, 57);
this.textBox2.Name = "textBox2";
this.textBox2.PasswordChar = '*';
this.textBox2.Size = new System.Drawing.Size(120, 21);
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
//
// button1
//
this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button1.Location = new System.Drawing.Point(16, 112);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(56, 23);
this.button1.TabIndex = 2;
this.button1.Text = "登陆";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button2.Location = new System.Drawing.Point(96, 112);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(56, 23);
this.button2.TabIndex = 3;
this.button2.Text = "退出";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.Location = new System.Drawing.Point(80, 24);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 20);
this.comboBox1.TabIndex = 8;
this.comboBox1.DropDown += new System.EventHandler(this.comboBox1_DropDown);
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// label3
//
this.label3.ForeColor = System.Drawing.Color.Red;
this.label3.Location = new System.Drawing.Point(16, 88);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(128, 23);
this.label3.TabIndex = 7;
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// button3
//
this.button3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button3.Location = new System.Drawing.Point(176, 112);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(56, 23);
this.button3.TabIndex = 4;
this.button3.Text = "取消";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// login
//
this.AutoScale = false;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(240, 141);
this.ControlBox = false;
this.Controls.Add(this.button3);
this.Controls.Add(this.label3);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(248, 168);
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(248, 168);
this.Name = "login";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "系统登陆";
this.TopMost = true;
this.Load += new System.EventHandler(this.login_Load);
this.ResumeLayout(false);
}
#endregion
DataConn dc=new DataConn();
public static char cc='0';//传递权限级别
public static string ss="";//传递操作员姓名
private void login_Load(object sender, System.EventArgs e)
{
this.AcceptButton=this.button1 ;//使每次按下回车键时总是激发button1
this.textBox2 .Text ="";
}
private void button2_Click(object sender, System.EventArgs e)
{
this.label3 .Text ="";
dc.exit();
}
private void button1_Click(object sender, System.EventArgs e)
{
this.label3 .Text ="";
string str=dc.connstr ;
SqlConnection conn=new SqlConnection (str);
string sql="select 权限级别 from tabpurview where 操作员姓名='"+this.comboBox1 .Text +"' and 密码='"+this.textBox2 .Text+"'";
SqlCommand cmd=new SqlCommand(sql,conn);
conn.Open ();
SqlDataReader dr= cmd.ExecuteReader();
try
{
if(dr.Read())
{
cc=Convert.ToChar(dr["权限级别"]);
ss=this.comboBox1 .Text ;
this.Close ();
}
else
{
this.label3 .Text ="密码有误!";
}
}
catch(SqlException ee)
{
MessageBox.Show (ee.Message,"错误!");
}
finally
{
dr.Close ();
conn.Close ();
cmd.Dispose ();
}
}
private void button3_Click(object sender, System.EventArgs e)
{
this.Close ();
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.textBox2 .Text ="";
}
private void comboBox1_DropDown(object sender, System.EventArgs e)
{
string str=dc.connstr ;
SqlConnection conn=new SqlConnection (str);
string sql="select * from tabpurview";
SqlDataAdapter adapter=new SqlDataAdapter (sql,conn);
DataSet dataset=new DataSet ();
try
{
adapter.Fill (dataset,"tabpurview");
this.comboBox1 .DisplayMember="操作员姓名";
this.comboBox1 .DataSource =dataset.Tables ["tabpurview"];
}
catch(SqlException ee)
{
MessageBox.Show (ee.Message,"错误!");
}
finally
{
conn.Dispose ();
adapter.Dispose ();
dataset.Dispose ();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -