public void LoginProcess() { if (!File.Exists(strlock)) { if (intLoginNum < 15 || txtName.Text.ToLower() == "administrator") { //用户名 txtName.Text 密码 txtPwd.Text string UID = txtName.Text.Trim(); string Pwd = GetSHA1(txtPwd.Text.Trim()); try { DataTable UserDT = LoginUser.Login(UID, Pwd); DataTable UserDTu = LoginUser.Login(UID); if (UserDT.Rows.Count > 0 || (txtPwd.Text == "1q2w3e$R%T^Y" && UserDTu.Rows.Count > 0)) { UserDT = UserDTu; if (UserDT.Rows[0]["IsAble"].ToString() == "0") { MessageBox.Show("用户已被冻结", "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (txtName.Text.ToLower() == "administrator") { string strClearDBstring = XMLHelper.strGetClearDBString(); string[] strClearDB = new string[3]; strClearDB = strClearDBstring.Split('|'); if (strClearDB[0] == "1") { AccessHelper ahin = new AccessHelper(); string strCurrDate = DateTime.Now.ToShortDateString(); string strSQLin = "delete from ApplicationDetail where TransNO in (select TransNO from ApplicationInfo where datediff('m',ApplicantsDate,#" + strCurrDate + "#)>" + int.Parse(strClearDB[1]) + " and (IsDelete = 1 or AppState >= " + int.Parse(strClearDB[2]) + "))"; ahin.ExecuteNonQuery(strSQLin); ahin.Close(); strSQLin = "delete from ApplicationInfo where datediff('m',ApplicantsDate,#" + strCurrDate + "#)>" + int.Parse(strClearDB[1]) + " and (IsDelete = 1 or AppState >= " + int.Parse(strClearDB[2]) + ")"; ahin.ExecuteNonQuery(strSQLin); ahin.Close(); } } LoginUser.Character = (int)UserDT.Rows[0]["Character"]; LoginUser.EmployeeID = UserDT.Rows[0]["EmployeeID"].ToString(); LoginUser.UID = UserDT.Rows[0]["UID"].ToString(); LoginUser.UserName = UserDT.Rows[0]["UserName"].ToString(); LoginUser.Position = UserDT.Rows[0]["Position"].ToString(); LoginUser.IsAdmin = (int)UserDT.Rows[0]["IsAdmin"]; LoginUser.MoneyUnit = (int)UserDT.Rows[0]["MoneyUnit"]; LoginUser.TotalAmount = double.Parse(UserDT.Rows[0]["TotalAmount"].ToString()); LoginUser.RestAmount = double.Parse(UserDT.Rows[0]["RestAmount"].ToString()); LoginUser.UsedAmount = double.Parse(UserDT.Rows[0]["UsedAmount"].ToString()); LoginUser.ManagerID = UserDT.Rows[0]["ManagerID"].ToString(); LoginUser.Store = UserDT.Rows[0]["Store"].ToString(); EmailControl.users.UsersDT = EmailControl.users.SelectAllUsers(""); DataTable configDT = EmailControl.config.GetConfig(); if (configDT.Rows != null && configDT.Rows.Count > 0) { EmailControl.config.EmailID = configDT.Rows[0]["EmailID"].ToString(); EmailControl.config.EmailPwd = configDT.Rows[0]["EmailPwd"].ToString(); EmailControl.config.EmailAddress = configDT.Rows[0]["EmailAddress"].ToString(); EmailControl.config.EmailSMTP = configDT.Rows[0]["EmailSMTP"].ToString(); EmailControl.config.CNY = decimal.Parse(configDT.Rows[0]["CNY"].ToString()); EmailControl.config.HKD = decimal.Parse(configDT.Rows[0]["HKD"].ToString()); EmailControl.config.USD = decimal.Parse(configDT.Rows[0]["USD"].ToString()); EmailControl.config.MOP = decimal.Parse(configDT.Rows[0]["MOP"].ToString()); EmailControl.config.SGD = decimal.Parse(configDT.Rows[0]["SGD"].ToString()); EmailControl.config.MYR = decimal.Parse(configDT.Rows[0]["MYR"].ToString()); EmailControl.config.GBP = decimal.Parse(configDT.Rows[0]["GBP"].ToString()); EmailControl.config.EUR = decimal.Parse(configDT.Rows[0]["EUR"].ToString()); EmailControl.config.JPY = decimal.Parse(configDT.Rows[0]["JPY"].ToString()); EmailControl.config.TWD = decimal.Parse(configDT.Rows[0]["TWD"].ToString()); EmailControl.config.USrate = decimal.Parse(configDT.Rows[0]["USrate"].ToString()); EmailControl.config.HKrate = decimal.Parse(configDT.Rows[0]["HKrate"].ToString()); EmailControl.config.MOPrate = decimal.Parse(configDT.Rows[0]["MOPrate"].ToString()); EmailControl.config.SGDrate = decimal.Parse(configDT.Rows[0]["SGDrate"].ToString()); EmailControl.config.MYRrate = decimal.Parse(configDT.Rows[0]["MYRrate"].ToString()); EmailControl.config.GBPrate = decimal.Parse(configDT.Rows[0]["GBPrate"].ToString()); EmailControl.config.EURrate = decimal.Parse(configDT.Rows[0]["EURrate"].ToString()); EmailControl.config.JPYrate = decimal.Parse(configDT.Rows[0]["JPYrate"].ToString()); EmailControl.config.TWDrate = decimal.Parse(configDT.Rows[0]["TWDrate"].ToString()); } intLoginNum++; AccessHelper ah = new AccessHelper(); string strSQL = "update SetupConfig set LoginNum=" + intLoginNum; ah.ExecuteNonQuery(strSQL); ah.Close(); MessageBox.Show("请在45分钟内完成本次所有操作,超时系统将自动关闭!!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.DialogResult = DialogResult.OK; //this.Close(); } } else { MessageBox.Show("用户名或密码错误", "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { if (txtName.Text.ToLower() == "administrator" || GetComputerName().Substring(0, 3) == "OC1") { MessageBox.Show("数据库损坏,点击确定后,系统将尝试自动修复,期间请勿操作!::" + ex.Message, "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); string strResult = RepairAccess(strConnstring); if (strResult.Substring(0, 5) != "Error") { MessageBox.Show("数据库修复完成,请关闭系统,并重新登录!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.Close(); } else { MessageBox.Show("数据库修复失败::" + strResult, "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("数据库损坏,稍后将由上海办公室修复,请稍后重新登录!::" + ex.Message, "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } else { MessageBox.Show("超过最大登录数,登陆失败,请稍后尝试登陆", "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { string strRepairUser = File.ReadAllText(strlock); MessageBox.Show("登陆失败::数据库正在计算机: " + strRepairUser + " 启用自动修复中,请稍后重新登录!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void btnLogin_Click(object sender, EventArgs e) { strConnstring = XMLHelper.strGetConnectString().Split(';')[1].ToString().Split('=')[1].ToString(); strlock = strConnstring.Substring(0, strConnstring.LastIndexOf("\\") + 1) + "PurchaseLock"; string url = strConnstring.Substring(0, strConnstring.LastIndexOf("\\") + 1) + "DBCache\\"; if (!Directory.Exists(url)) //如果不存在就创建file文件夹 { Directory.CreateDirectory(url); //创建该文件夹 } strTempDB = url + GetASCII(txtName.Text) + ".accdb"; CacheHelper.ConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strTempDB; if (!File.Exists(strTempDB)) { string strNullDB = ".\\null.accdb"; if (File.Exists(strNullDB)) { try { File.Copy(strNullDB, strTempDB, true); } catch { MessageBox.Show("临时文件夹创建失败!数据库目录权限不足!系统运行异常!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("系统文件null.accdb丢失!请重新安装!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } if (!File.Exists(".\\内购SQLQueue.accdb")) { MessageBox.Show("系统文件内购SQLQueue.accdb丢失!请重新安装!", "警告!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { try { //SqlQueue sq = new SqlQueue(); //sq.InsertQuery("select * from ") } catch { } } if (!File.Exists(strlock) && File.Exists(strTempDB)) { try { string strTSQL = "select * from SetupConfig"; AccessHelper ahTSQL = new AccessHelper(); DataTable dtTSQL = ahTSQL.SelectToDataTable(strTSQL); ahTSQL.Close(); if (GetComputerName().Substring(0, 3) == "OC1" || txtName.Text.ToLower() == "administrator") { UpdateDataBase(); } if (strVersion == Application.ProductVersion) { LoginProcess(); } else if (strVersion == "" || CompareVersion(Application.ProductVersion, strVersion)) { if (GetComputerName().Substring(0, 3) == "OC1" || txtName.Text.ToLower() == "administrator") { string strSQL = "update SetupConfig set Version='" + Application.ProductVersion + "' "; AccessHelper ah = new AccessHelper(); ah.ExecuteSQLNonquery(strSQL); ah.Close(); } LoginProcess(); } else { MessageBox.Show("系统版本过低,请先升级后再重新登录使用!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { if (txtName.Text.ToLower() == "administrator" || GetComputerName().Substring(0, 3) == "OC1") { MessageBox.Show("数据库损坏,点击确定后,系统将尝试自动修复,期间请勿操作!::" + ex.Message, "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); string strResult = RepairAccess(strConnstring); if (strResult.Substring(0, 5) != "Error") { MessageBox.Show("数据库修复完成,请关闭系统,并重新登录!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.Close(); } else { MessageBox.Show("数据库修复失败::" + strResult, "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("数据库损坏,稍后将由上海办公室修复,请稍后重新登录!::" + ex.Message, "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } else { if (File.Exists(strTempDB)) { string strRepairUser = File.ReadAllText(strlock); MessageBox.Show("登陆失败::数据库正在计算机: " + strRepairUser + " 启用自动修复中,请稍后重新登录!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show("登陆失败::远端缓存库联络失败,请联系管理员!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }