private void btnSave_Click(object sender, EventArgs e) { try { int port = Convert.ToInt32(txtPort.Text); } catch (Exception) { Global.ShowSysInfo("端口号必须为整数!"); return; } string ip = txtIp.Text.Replace(" ", ""); if (ip == "127.0.0.1") { ip = "(local)"; } else { if (txtPort.Text != "1433") { ip += "," + txtPort.Text; } } string newconn = ConnetionString.Substring(0, ConnetionString.IndexOf('=') + 1) + ip + ConnetionString.Substring(ConnetionString.IndexOf(';')); string sConnection = ConfigurationManager.AppSettings["ConnectionString"]; Publics.UpdateConfig(Application.ExecutablePath, sConnection, Crypto.EncryptString(newconn)); ConfigurationManager.RefreshSection("appSettings"); DialogResult = DialogResult.OK; this.Close(); }
private void btnLogin_Click(object sender, EventArgs e) { try { if (String.IsNullOrEmpty(txtManID.Text)) { MessageBox.Show("用户名不能为空!", PublicConsts.PC_Tip); txtManID.Focus(); return; } if (String.IsNullOrEmpty(txtPassword.Text)) { MessageBox.Show("密码不能为空!", PublicConsts.PC_Tip); txtPassword.Focus(); return; } SysOnline so = SqlBaseProvider.GetSysOnline(txtManID.Text); if (!String.IsNullOrEmpty(so.ManID)) { MessageBox.Show("您的用户名已经登陆,不能重复登录!", PublicConsts.PC_Tip); txtManID.Focus(); return; } UserCache uc = SqlBaseProvider.GetLoginInfo(txtManID.Text, String.Empty, String.Empty); if (String.IsNullOrEmpty(uc.Company.CoID) || String.IsNullOrEmpty(uc.Dept.DeptID) || String.IsNullOrEmpty(uc.Man.ManID)) { MessageBox.Show("您的员工资料不正确,不能登录本系统!", PublicConsts.PC_Tip); txtManID.Focus(); return; } if (Crypto.MD5Crypto(txtPassword.Text) != uc.Man.OperPassword) { MessageBox.Show("密码输入错误,请核实!", PublicConsts.PC_Tip); txtPassword.Focus(); txtPassword.Text = String.Empty; return; } //Program.ManInfo = uc; if (uc.Man.IsFirst) { MessageBox.Show("您的用户名第一次登录本系统,请修改原始密码后重新登录!", PublicConsts.PC_Tip); txtPassword.Text = String.Empty; this.DialogResult = DialogResult.Yes; } else { SysRegister sr = SqlBaseProvider.GetSysRegister(Publics.GetRegisterNumber(Program.CpuInfo)); short ml = SqlBaseProvider.GetSetManLevel(); if (uc.Man.IsLock) { Global.ShowSysInfo("您的用户名被锁定,不能登录系统!" + StringHelper.WriteEnter(1) + "请与部门负责人或者系统管理员联系进行解锁!"); txtManID.Focus(); this.DialogResult = DialogResult.Cancel; return; } so.ManID = txtManID.Text; so.RegID = sr.RegID; SqlBaseProvider.LoginSysOnline(so, DataProviderAction.Create); Publics.UpdateConfig(Application.ExecutablePath, "IsRememberMe", chbRemember.Checked.ToString()); Publics.UpdateConfig(Application.ExecutablePath, "RememberUser", txtManID.Text); ConfigurationManager.RefreshSection("appSettings"); uc.Register = sr; Program.ManInfo = uc; this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show(ex.Message, PublicConsts.PC_Tip); return; } }