using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data ;
using System.Data.OleDb;
/*****************************
编写:李洪喜
日期:2003.09.20
功能:系统登录模块*////////////////////////////
namespace ERM
{
/// <summary>
/// FrmLogin 的摘要说明。
/// </summary>
public class FrmLogin : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.TextBox txtOperator;
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.Button btnSure;
private System.Windows.Forms.Button btnCancel;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.DateTimePicker dTPicker1; private ERM.FrmDaoHang secdh;
public FrmLogin(ERM.FrmDaoHang dh)
{
//
// Windows 窗体设计器支持所必需的
//
secdh = dh;
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
//
int s=0; //计算密码输入次数,如s>3 then 退出
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FrmLogin));
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.txtOperator = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.txtPassword = new System.Windows.Forms.TextBox();
this.btnSure = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.dTPicker1 = new System.Windows.Forms.DateTimePicker();
this.SuspendLayout();
//
// pictureBox2
//
this.pictureBox2.Dock = System.Windows.Forms.DockStyle.Top;
this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));
this.pictureBox2.Location = new System.Drawing.Point(0, 0);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(410, 96);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox2.TabIndex = 9;
this.pictureBox2.TabStop = false;
//
// label4
//
this.label4.BackColor = System.Drawing.Color.Transparent;
this.label4.Font = new System.Drawing.Font("楷体_GB2312", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label4.ForeColor = System.Drawing.SystemColors.HotTrack;
this.label4.Location = new System.Drawing.Point(0, 0);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(208, 24);
this.label4.TabIndex = 10;
this.label4.Text = "企业资源管理系统";
//
// label5
//
this.label5.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label5.ForeColor = System.Drawing.SystemColors.Highlight;
this.label5.Location = new System.Drawing.Point(256, 80);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(160, 12);
this.label5.TabIndex = 11;
this.label5.Text = "威海迪沙药业集团有限公司";
//
// txtOperator
//
this.txtOperator.Location = new System.Drawing.Point(152, 136);
this.txtOperator.Name = "txtOperator";
this.txtOperator.Size = new System.Drawing.Size(232, 21);
this.txtOperator.TabIndex = 1;
this.txtOperator.Text = "";
this.txtOperator.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtOperator_KeyPress);
this.txtOperator.Enter += new System.EventHandler(this.txtOperator_Enter);
//
// label3
//
this.label3.BackColor = System.Drawing.Color.Transparent;
this.label3.Location = new System.Drawing.Point(88, 168);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(88, 16);
this.label3.TabIndex = 14;
this.label3.Text = "口 令:";
//
// label2
//
this.label2.BackColor = System.Drawing.Color.Transparent;
this.label2.Location = new System.Drawing.Point(88, 144);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(88, 16);
this.label2.TabIndex = 13;
this.label2.Text = "操 作 员:";
//
// label1
//
this.label1.BackColor = System.Drawing.Color.Transparent;
this.label1.Location = new System.Drawing.Point(88, 120);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(88, 16);
this.label1.TabIndex = 12;
this.label1.Text = "财务日期:";
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.Color.Transparent;
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data ;
using System.Data.OleDb;
/*****************************
编写:李洪喜
日期:2003.09.20
功能:系统登录模块*////////////////////////////
namespace ERM
{
/// <summary>
/// FrmLogin 的摘要说明。
/// </summary>
public class FrmLogin : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.TextBox txtOperator;
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.Button btnSure;
private System.Windows.Forms.Button btnCancel;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.DateTimePicker dTPicker1; private ERM.FrmDaoHang secdh;
public FrmLogin(ERM.FrmDaoHang dh)
{
//
// Windows 窗体设计器支持所必需的
//
secdh = dh;
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
//
int s=0; //计算密码输入次数,如s>3 then 退出
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FrmLogin));
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.txtOperator = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.txtPassword = new System.Windows.Forms.TextBox();
this.btnSure = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.dTPicker1 = new System.Windows.Forms.DateTimePicker();
this.SuspendLayout();
//
// pictureBox2
//
this.pictureBox2.Dock = System.Windows.Forms.DockStyle.Top;
this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));
this.pictureBox2.Location = new System.Drawing.Point(0, 0);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(410, 96);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox2.TabIndex = 9;
this.pictureBox2.TabStop = false;
//
// label4
//
this.label4.BackColor = System.Drawing.Color.Transparent;
this.label4.Font = new System.Drawing.Font("楷体_GB2312", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label4.ForeColor = System.Drawing.SystemColors.HotTrack;
this.label4.Location = new System.Drawing.Point(0, 0);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(208, 24);
this.label4.TabIndex = 10;
this.label4.Text = "企业资源管理系统";
//
// label5
//
this.label5.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label5.ForeColor = System.Drawing.SystemColors.Highlight;
this.label5.Location = new System.Drawing.Point(256, 80);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(160, 12);
this.label5.TabIndex = 11;
this.label5.Text = "威海迪沙药业集团有限公司";
//
// txtOperator
//
this.txtOperator.Location = new System.Drawing.Point(152, 136);
this.txtOperator.Name = "txtOperator";
this.txtOperator.Size = new System.Drawing.Size(232, 21);
this.txtOperator.TabIndex = 1;
this.txtOperator.Text = "";
this.txtOperator.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtOperator_KeyPress);
this.txtOperator.Enter += new System.EventHandler(this.txtOperator_Enter);
//
// label3
//
this.label3.BackColor = System.Drawing.Color.Transparent;
this.label3.Location = new System.Drawing.Point(88, 168);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(88, 16);
this.label3.TabIndex = 14;
this.label3.Text = "口 令:";
//
// label2
//
this.label2.BackColor = System.Drawing.Color.Transparent;
this.label2.Location = new System.Drawing.Point(88, 144);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(88, 16);
this.label2.TabIndex = 13;
this.label2.Text = "操 作 员:";
//
// label1
//
this.label1.BackColor = System.Drawing.Color.Transparent;
this.label1.Location = new System.Drawing.Point(88, 120);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(88, 16);
this.label1.TabIndex = 12;
this.label1.Text = "财务日期:";
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.Color.Transparent;
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(16, 112);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(58, 47);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 17;
this.pictureBox1.TabStop = false;
//
// txtPassword
//
this.txtPassword.Location = new System.Drawing.Point(152, 160);
this.txtPassword.Name = "txtPassword";
this.txtPassword.PasswordChar = '*';
this.txtPassword.Size = new System.Drawing.Size(232, 21);
this.txtPassword.TabIndex = 2;
this.txtPassword.Text = "";
this.txtPassword.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtPassword_KeyPress);
//
// btnSure
//
this.btnSure.BackColor = System.Drawing.Color.AliceBlue;
this.btnSure.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnSure.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnSure.Location = new System.Drawing.Point(184, 192);
this.btnSure.Name = "btnSure";
this.btnSure.Size = new System.Drawing.Size(80, 24);
this.btnSure.TabIndex = 3;
this.btnSure.Text = "确 定";
this.btnSure.Click += new System.EventHandler(this.btnSure_Click);
//
// btnCancel
//
this.btnCancel.BackColor = System.Drawing.Color.AliceBlue;
this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnCancel.Location = new System.Drawing.Point(288, 192);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(80, 24);
this.btnCancel.TabIndex = 5;
this.btnCancel.Text = "取 消";
this.btnCancel.Click += new System.EventHandler(this.button2_Click);
//
// dTPicker1
//
this.dTPicker1.CustomFormat = "YYYYMMDD";
this.dTPicker1.Format = System.Windows.Forms.DateTimePickerFormat.Short;
this.dTPicker1.Location = new System.Drawing.Point(152, 112);
this.dTPicker1.Name = "dTPicker1";
this.dTPicker1.Size = new System.Drawing.Size(232, 21);
this.dTPicker1.TabIndex = 3;
//
// FrmLogin
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(410, 239);
this.ControlBox = false;
this.Controls.Add(this.dTPicker1);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnSure);
this.Controls.Add(this.txtPassword);
this.Controls.Add(this.txtOperator);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.pictureBox2);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "FrmLogin";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "系统登录";
this.TopMost = true;
this.TransparencyKey = System.Drawing.Color.WhiteSmoke;
this.Load += new System.EventHandler(this.FrmLogin_Load);
this.ResumeLayout(false); }
#endregion private System.Data.DataSet myds ;
private System.Data.OleDb.OleDbDataAdapter myda;
private System.Data.OleDb.OleDbCommandBuilder mycmdb;
private System.Windows.Forms.BindingManagerBase mybind ;
private string sql;
private void FrmLogin_Load(object sender, System.EventArgs e)
{
//设置label控件背景透明
this.label4.Parent =this.pictureBox2;
this.label5.Parent =this.pictureBox2;
//提取上一次登录用户
this.sql = "select * from LOGINUSER";
try
{ string strx="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=desktop.mdb;Persist Security Info=False";
OleDbConnection Conn =new OleDbConnection(strx);
this.myds = new DataSet();
this.myda = new OleDbDataAdapter(sql,Conn);
this.myda.Fill(this.myds,"user");
this.mybind=this.BindingContext[this.myds,"user"];
this.mycmdb= new OleDbCommandBuilder(this.myda);
if (this.mybind.Count>0)
{
txtOperator.Text = this.myds.Tables["user"].Rows[0]["user_bh"].ToString();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
txtPassword.Focus();
} private void button2_Click(object sender, System.EventArgs e)
{
secdh.Show();
this.Close();
} private void txtOperator_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar ==(char)13)
SendKeys.Send("{TAB}");
} private void txtPassword_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar ==(char)13)
btnSure.Focus();
//SendKeys.Send("{TAB}");
} private void dateTimePicker1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar ==(char)13)
SendKeys.Send("{TAB}");
}
private void btnSure_Click(object sender, System.EventArgs e)
{
//确定按钮触发
string sOperatorID=this.txtOperator.Text;
if (sOperatorID =="")
{
this.txtOperator.Focus();
return;
}
string stxtpassword=this.txtPassword.Text ; //获取密码值
string sqlstr; //sql
try
{
sqlstr= "select * from SYS_Operators where OperatorID='"+ sOperatorID +"'";
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(sqlstr, PubClass.AdoConnect());
try
{
da.Fill(ds,"A");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
string sPassword=ds.Tables["A"].Rows[0]["PassWord"].ToString();
if (sPassword==stxtpassword)
{
Cursor.Current =Cursors.WaitCursor; //new Cursor("MyWait.cur");
//赋值公用参数
ERM.PubClass.PubsUserID =sOperatorID;
ERM.PubClass.PubsPassword = stxtpassword;
ERM.PubClass.login_bz = "1";
ERM.PubClass.PubsUserName =ds.Tables["A"].Rows[0]["OperatorName"].ToString();
if (this.dTPicker1.Value.Month.ToString().Length <2)
{
ERM.PubClass.PubsCWRQ=this.dTPicker1.Value.Year.ToString() +"0"+this.dTPicker1.Value.Month.ToString() +this.dTPicker1.Value.Day.ToString();
if (this.dTPicker1.Value.Day.ToString().Length <2)
{
ERM.PubClass.PubsCWRQ=this.dTPicker1.Value.Year.ToString() +"0"+this.dTPicker1.Value.Month.ToString() +"0"+this.dTPicker1.Value.Day.ToString();
}
else
{
ERM.PubClass.PubsCWRQ=this.dTPicker1.Value.Year.ToString() +"0"+this.dTPicker1.Value.Month.ToString() +this.dTPicker1.Value.Day.ToString();
}
}
else
{
ERM.PubClass.PubsCWRQ=this.dTPicker1.Value.Year.ToString() +this.dTPicker1.Value.Month.ToString() +this.dTPicker1.Value.Day.ToString();
if (this.dTPicker1.Value.Day.ToString().Length <2)
{
ERM.PubClass.PubsCWRQ=this.dTPicker1.Value.Year.ToString() +this.dTPicker1.Value.Month.ToString() +"0"+this.dTPicker1.Value.Day.ToString();
}
else
{
ERM.PubClass.PubsCWRQ=this.dTPicker1.Value.Year.ToString() +this.dTPicker1.Value.Month.ToString() +this.dTPicker1.Value.Day.ToString();
}
}
try
{
if (this.mybind.Count>0)
{
this.myds.Tables["user"].Rows[0]["user_bh"]=this.txtOperator.Text;
this.myds.Tables["user"].Rows[0]["user_name"]=ERM.PubClass.PubsUserName;
this.myds.Tables["user"].Rows[0]["user_logindate"]=System.DateTime.Now;
this.mybind.EndCurrentEdit();
this.myda.Update(this.myds,"user");
}
else
{
System.Data.DataRow mydr = this.myds.Tables["user"].NewRow();
mydr["user_bh"] = ERM.PubClass.PubsUserID;
mydr["user_name"] = ERM.PubClass.PubsUserName;
mydr["user_logindate"]= System.DateTime.Now;
this.myds.Tables["user"].Rows.Add(mydr);
this.mybind.EndCurrentEdit();
this.myda.Update(this.myds,"user");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
this.Close();
Form2 frm =new Form2(secdh);
frm.Show ();
Cursor.Current =Cursors.Default;
//
} else
{
s=s+1;
this.txtPassword.Text ="";
this.txtPassword.Focus();
if (s>2 )
{
ERM.PubClass.AdoConnect().Close() ;
this.Close();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"可能是数据联接有问题!");
}
} private void txtOperator_Enter(object sender, System.EventArgs e)
{
this.txtOperator.Select(0,this.txtOperator.Text.Length);
}
}
}
这是我程序的登录窗口.
使用了一个ACCESS文件,保留登录信息.
where usercode=@usercode
and userpassword=@userpassword";
scpub.CommandType = CommandType.StoredProcedure;
scpub.Parameters.Clear();
scpub.Parameters.Add("@usercode", SqlDbType.VarChar, 20).Value = usercode;
scpub.Parameters.Add("@userpassword", SqlDbType.VarChar, 20).Value = userpassword;
scpub.Connection.Close();
scpub.Connection.Open();
SqlDataReader myread = scpub.ExecuteReader();
myread.Read();
if((int)myread.GetValue(0) == 1)
{
UserCode = usercode;
UserName = myread.GetString(2);
IsAuthenticated = true;
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(usercode, false, 40);//建立用户加密凭据并设置超时时间
EncTicket = FormsAuthentication.Encrypt(ticket);
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, EncTicket));
Session["UserCode"] = this.TextUserCode.Value;
myread.Close();
scpub.Connection.Close();
Response.Redirect("WebForm1.aspx",true);
}
SqlConnection cnn=new SqlConnection(cnnstring) //cnnstring为数据库连接字符串
cnn.Open();
SqlCommand cm=new SqlCommand(cmdStr, cnn);
SqlDataAdapter da=new SqlDataAdapter(cm);
DataSet ds=new DataSet();
da.Fill(ds);
return ds;if(ds.Tables[0].Rows.Count!=0)
{
证明登陆成功
}
Else
{
登陆失败
}