frmLogin
来源:互联网 发布:微信商城开发源码 编辑:程序博客网 时间:2024/06/04 17:41
using System;
using System.Drawing;
using System.Collections;
using System.Configuration;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using HR.BLL;
using HR.SystemFramework.Common;
using HR.Model.Common;
namespace HR.Win
{
/// <summary>
/// frmLogin 的摘要描述。
/// </summary>
public class frmLogin : System.Windows.Forms.Form
{
private ArrayList arCompany;
private int isFalse=0;//錯誤次數
private System.Windows.Forms.Label labUserID;
private System.Windows.Forms.Label userPassword;
private System.Windows.Forms.Label Company;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.TextBox txtUserID;
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.ComboBox cboCompany;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel;
private System.ComponentModel.IContainer components = null;
public frmLogin()
{
//
// Windows Form 設計工具支援的必要項
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 呼叫之後加入任何建構函式程式碼
//
}
/// <summary>
/// 清除任何使用中的資源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form 設計工具產生的程式碼
/// <summary>
/// 此為設計工具支援所必須的方法 - 請勿使用程式碼編輯器修改
/// 這個方法的內容。
/// </summary>
private void InitializeComponent()
{
this.labUserID = new System.Windows.Forms.Label();
this.userPassword = new System.Windows.Forms.Label();
this.Company = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.txtUserID = new System.Windows.Forms.TextBox();
this.txtPassword = new System.Windows.Forms.TextBox();
this.cboCompany = new System.Windows.Forms.ComboBox();
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// labUserID
//
this.labUserID.Location = new System.Drawing.Point(128, 32);
this.labUserID.Name = "labUserID";
this.labUserID.Size = new System.Drawing.Size(48, 23);
this.labUserID.TabIndex = 0;
this.labUserID.Text = "帳號";
//
// userPassword
//
this.userPassword.Location = new System.Drawing.Point(128, 64);
this.userPassword.Name = "userPassword";
this.userPassword.Size = new System.Drawing.Size(40, 23);
this.userPassword.TabIndex = 1;
this.userPassword.Text = "密碼";
//
// Company
//
this.Company.Location = new System.Drawing.Point(128, 96);
this.Company.Name = "Company";
this.Company.Size = new System.Drawing.Size(48, 23);
this.Company.TabIndex = 2;
this.Company.Text = "公司";
//
// pictureBox1
//
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox1.Location = new System.Drawing.Point(16, 32);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(100, 88);
this.pictureBox1.TabIndex = 3;
this.pictureBox1.TabStop = false;
//
// txtUserID
//
this.txtUserID.Location = new System.Drawing.Point(176, 32);
this.txtUserID.MaxLength = 20;
this.txtUserID.Name = "txtUserID";
this.txtUserID.Size = new System.Drawing.Size(128, 27);
this.txtUserID.TabIndex = 4;
this.txtUserID.Text = "";
this.txtUserID.TextChanged += new System.EventHandler(this.txtUserID_TextChanged);
//
// txtPassword
//
this.txtPassword.Location = new System.Drawing.Point(176, 64);
this.txtPassword.MaxLength = 20;
this.txtPassword.Name = "txtPassword";
this.txtPassword.PasswordChar = '*';
this.txtPassword.Size = new System.Drawing.Size(128, 27);
this.txtPassword.TabIndex = 5;
this.txtPassword.Text = "";
//
// cboCompany
//
this.cboCompany.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboCompany.Location = new System.Drawing.Point(176, 96);
this.cboCompany.Name = "cboCompany";
this.cboCompany.Size = new System.Drawing.Size(128, 24);
this.cboCompany.TabIndex = 6;
//
// btnOK
//
this.btnOK.Enabled = false;
this.btnOK.Location = new System.Drawing.Point(144, 144);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(75, 32);
this.btnOK.TabIndex = 7;
this.btnOK.Text = "確認";
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// btnCancel
//
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(232, 144);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 32);
this.btnCancel.TabIndex = 8;
this.btnCancel.Text = "取消";
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// frmLogin
//
this.AcceptButton = this.btnOK;
this.AutoScaleBaseSize = new System.Drawing.Size(7, 20);
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(328, 197);
this.ControlBox = false;
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOK);
this.Controls.Add(this.cboCompany);
this.Controls.Add(this.txtPassword);
this.Controls.Add(this.txtUserID);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.Company);
this.Controls.Add(this.userPassword);
this.Controls.Add(this.labUserID);
this.Font = new System.Drawing.Font("新細明體", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(136)));
this.Name = "frmLogin";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "帳號登錄";
this.Load += new System.EventHandler(this.frmLogin_Load);
this.ResumeLayout(false);
}
#endregion
private void txtUserID_TextChanged(object sender, System.EventArgs e)
{
btnOK.Enabled = (txtUserID.Text.Trim().Length !=0);
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
private void btnOK_Click(object sender, System.EventArgs e)
{
SqlParameter[] parms = new SqlParameter[]
{
new SqlParameter("@UserID",SqlDbType.NVarChar,20,"UserID")
};
string[] condtion = new string[]{txtUserID.Text.Trim().ToString()};
int[] txtIndex = {1,2,3};
string[] txtValue = new string[3];
Login login = new Login();
if(login.GetInfo("Pr_GetUser",parms,condtion,txtValue,txtIndex,ActionTable.SYS))
{
HR.Model.Common.LoginInfo.userLoginInfo.userID = txtUserID.Text.Trim().ToString();
HR.Model.Common.LoginInfo.userLoginInfo.userName = txtValue[0];
HR.Model.Common.LoginInfo.userLoginInfo.userPassword = txtValue[1];
HR.Model.Common.LoginInfo.userLoginInfo.multiCompany = txtValue[2];
object[] companyInfo = (object[])arCompany[cboCompany.SelectedIndex];
HR.Model.Common.LoginInfo.userLoginInfo.companyID = companyInfo[0].ToString().Trim();
HR.Model.Common.LoginInfo.userLoginInfo.companyName = companyInfo[1].ToString().Trim();
HR.Model.Common.LoginInfo.userLoginInfo.companyDbName = companyInfo[2].ToString().Trim();
if(Mima.PasswordString(txtPassword.Text.Trim().ToString()) == HR.Model.Common.LoginInfo.userLoginInfo.userPassword &&
HR.Model.Common.LoginInfo.userLoginInfo.multiCompany.IndexOf(HR.Model.Common.LoginInfo.userLoginInfo.companyID) !=-1)
{
bool isFound = false;
string strConnection = string.Empty;
foreach(string conItem in ConfigurationSettings.AppSettings.Keys)
{
strConnection = ConfigurationSettings.AppSettings[conItem];
if(strConnection.IndexOf(";database=" + HR.Model.Common.LoginInfo.userLoginInfo.companyDbName +";") !=-1)
{
isFound = true;
break;
}
}
if(!isFound)
{
if(!isExit())
{
MessageBox.Show(this,"資料庫連接字串錯誤!",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
else
{
HR.Model.Common.LoginInfo.userLoginInfo.companyConnstring = strConnection;
DialogResult = DialogResult.OK;
}
}
else
{
if(!isExit())
{
MessageBox.Show(this,"帳號或密碼錯誤!",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
else
{
if(!isExit())
{
MessageBox.Show(this,"帳號或密碼錯誤!",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
private bool isExit()
{
bool isExitting = false;
isFalse++;
if(isFalse >3)
{
MessageBox.Show(this,"您輸入的錯誤次數超過三次,系統即將關閉!",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Error);
DialogResult = DialogResult.Cancel;
isExitting = true;
}
return isExitting;
}
private void frmLogin_Load(object sender, System.EventArgs e)
{
Login login = new Login();
arCompany = login.GetCompanyData();
foreach(object[] companyInfo in arCompany)
cboCompany.Items.Add(companyInfo[1].ToString());
cboCompany.SelectedIndex = 0;
}
}
}
- frmLogin
- FrmLogin登录窗体
- 机房收费系统:(一)窗体模式 frmLogin.Show vbModal
- 在“Resources”参数中指定了项“obj\x86\Debug\frmLogin.frmLogin.resources”多次。“Resources”参数不支持重复项。
- 创建一个登录窗体(frmLogin)、一个主窗体(frmMain)、两个子窗体(frm子窗体1、frm子窗体2)。
- SAP BOM的读取逻辑
- 终于决定开自己的blog
- vb.net2005中回调功能的简单实现
- uC/OS-II 初级程序员指南
- MainClass
- frmLogin
- webwork+freemarker+hibernate开发样版图像管理系统
- 消除过期的对象引用
- 项目经理10大成功态度
- 序
- 将过长的字符串用省略号表示
- 如何提高读取BSEG的性能(sap已清项和未清项的提取)
- 模板方法模式(Template Mothod Pattern)
- -128的补码