private void btnNextStep_Click(object sender, EventArgs e) { string userName = txtUser.Text.Trim(); string password = txtPassword.Text.Trim(); if (string.IsNullOrWhiteSpace(userName)) { //MessageBox.Show("请输入用户名。", "提示信息"); MessageBox.Show(ResourceCulture.GetString("GeneralMsg_EmptyUser"), ResourceCulture.GetString("GeneralTitle_Prompt")); return; } else if (string.IsNullOrWhiteSpace(password)) { //MessageBox.Show("请输入密码信息。", "提示信息"); MessageBox.Show(ResourceCulture.GetString("GeneralMsg_EmptyPwd"), ResourceCulture.GetString("GeneralTitle_Prompt")); return; } try { //UserBLL userBll = new UserBLL(); BDOSecurityPortalModel.UserProfile userProfile = new BDOSecurityPortalModel.UserProfile(); string loginUserId = string.Empty; string loginMessage = string.Empty; bool loginResult = EoopService.LoginVerify(userName, password, out loginUserId, out loginMessage); if (!loginResult) { MessageBox.Show(loginMessage, ResourceCulture.GetString("LoginMsg_Title")); return; } this.Hide(); PersonalAssets bindStep2Form = new PersonalAssets(loginUserId, userName, password); bindStep2Form.ShowDialog(); this.Close(); } catch (Exception ex) { string exMessage = ResourceCulture.GetString("GeneralMsg_AppException"); if (Program.ReleaseType == "DEBUG") { exMessage = ex.Message + ex.StackTrace; } MessageBox.Show(exMessage, ResourceCulture.GetString("LoginMsg_Title")); } }
public PersonalAssets(string userId, string userName, string password, Property bindAsset = null) { try { InitializeComponent(); #region 国际化 labelBindStep2.Text = ResourceCulture.GetString("BindStep2"); btnLastStep.Text = ResourceCulture.GetString("LastStep"); btnNext.Text = ResourceCulture.GetString("NextStep"); #endregion UserID = userId; UserName = userName; Password = password; PropertyList = EoopService.GetUserAssetList(userName); foreach (Property property in PropertyList) { cbxAsset.Items.Add(property.ComboDisplay); } if (bindAsset != null) { cbxAsset.SelectedText = bindAsset.ComboDisplay; } } catch (Exception ex) { string exMessage = ResourceCulture.GetString("GeneralMsg_AppException"); if (Program.ReleaseType == "DEBUG") { exMessage = ex.Message + ex.StackTrace; } MessageBox.Show(exMessage, ResourceCulture.GetString("GeneralTitle_Prompt")); } }
private void btnChangePassword_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtUserName.Text.Trim())) { MessageBox.Show(ResourceCulture.GetString("GeneralMsg_EmptyUser"), ResourceCulture.GetString("GeneralTitle_Prompt")); return; } if (string.IsNullOrEmpty(txtOldPwd.Text.Trim())) { MessageBox.Show(ResourceCulture.GetString("GeneralMsg_EmptyPwd"), ResourceCulture.GetString("GeneralTitle_Prompt")); return; } if (string.IsNullOrEmpty(txtNewPwd.Text.Trim())) { MessageBox.Show(ResourceCulture.GetString("ResetPwd_EmptyNewPwd"), ResourceCulture.GetString("GeneralTitle_Prompt")); return; } if (string.IsNullOrEmpty(txtConfirmPwd.Text.Trim())) { MessageBox.Show(ResourceCulture.GetString("ResetPwd_EmptyConfirm"), ResourceCulture.GetString("GeneralTitle_Prompt")); return; } if (!string.IsNullOrEmpty(Password) && txtOldPwd.Text != Password) { MessageBox.Show(ResourceCulture.GetString("ResetPwd_PwdNotMatch"), ResourceCulture.GetString("GeneralTitle_Prompt")); return; } if (txtNewPwd.Text != txtConfirmPwd.Text) { MessageBox.Show(ResourceCulture.GetString("ResetPwd_PwdNotMatch"), ResourceCulture.GetString("GeneralTitle_Prompt")); return; } string userName = txtUserName.Text; string oldPassword = txtOldPwd.Text; string newPassword = txtConfirmPwd.Text; string message = string.Empty; try { bool result = EoopService.ResetPassword(userName, oldPassword, newPassword, out message); if (!result) { MessageBox.Show(message, ResourceCulture.GetString("GeneralTitle_Prompt")); return; } MessageBox.Show(ResourceCulture.GetString("ResetPwd_ResetSuccess"), ResourceCulture.GetString("GeneralTitle_Prompt")); this.Close(); foreach (Form openForm in Application.OpenForms) { if (openForm.Name == "Login") { openForm.WindowState = FormWindowState.Normal; openForm.Show(); break; } } } catch (Exception ex) { string exMessage = ResourceCulture.GetString("GeneralMsg_AppException"); if (Program.ReleaseType == "DEBUG") { exMessage = ex.Message + ex.StackTrace; } MessageBox.Show(exMessage, ResourceCulture.GetString("GeneralTitle_Prompt")); } }
private void btnComplete_Click(object sender, EventArgs e) { string authorNO = txtAuthorNO.Text.Trim(); if (string.IsNullOrWhiteSpace(authorNO)) { MessageBox.Show(ResourceCulture.GetString("BindMsg_EmptAuthorNO"), ResourceCulture.GetString("GeneralTitle_Prompt")); return; } try { #region 显示 Loading 等待 showMaskPanel.Visible = true; this.Refresh(); #endregion string slKeyId = string.Empty; string slKeyCode = string.Empty; string message = string.Empty; safeNetTool.safeNetBiz safetBiz = new safeNetTool.safeNetBiz(); bool installSafeNetResult = safetBiz.installSafeNet(authorNO, out slKeyId, out message); if (!installSafeNetResult) { showMaskPanel.Visible = false; this.Refresh(); MessageBox.Show(message, ResourceCulture.GetString("GeneralTitle_Prompt")); return; } //获取密锁锁号 List <string> slKeyCodes = (new safeNetTool.safeNetBiz()).getSlCode(); slKeyCode = slKeyCodes.Count > 0 ? slKeyCodes[0] : string.Empty; bool bindResult = EoopService.BindUserAsset(slKeyCode, BindAsset.id, 1); if (!bindResult) { showMaskPanel.Visible = false; this.Refresh(); //MessageBox.Show("资产绑定失败,请重新绑定。", "提示信息"); MessageBox.Show(ResourceCulture.GetString("BindMsg_BindFailed"), ResourceCulture.GetString("GeneralTitle_Prompt")); return; } MainForm mainForm = new MainForm(UserID, UserName, Password, Language, slKeyCode); foreach (Form openForm in Application.OpenForms) { openForm.Hide(); } mainForm.WindowState = FormWindowState.Maximized; mainForm.ShowDialog(); this.Close(); } catch (Exception ex) { showMaskPanel.Hide(); string exMessage = ResourceCulture.GetString("GeneralMsg_AppException"); if (Program.ReleaseType == "DEBUG") { exMessage = ex.Message + ex.StackTrace; } MessageBox.Show(exMessage, ResourceCulture.GetString("GeneralTitle_Prompt")); } }
/// <summary> /// 登录按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLogin_Click(object sender, EventArgs e) { #region 检测网络连接是否正常 if (!CommonService.IsConnectInternet()) { string productName = ResourceCulture.GetString("AppName"); //Application.ProductName string exMsg = string.Format(ResourceCulture.GetString("GeneralMsg_NetworkOffline"), Application.ProductName); MessageBox.Show(exMsg, productName, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } #endregion //string userName = this.cbxUserName.Text.Trim(); string userName = this.txtUserName.Text.Trim(); string password = this.txtPassword.Text.Trim(); if (string.IsNullOrWhiteSpace(userName)) { MessageBox.Show(ResourceCulture.GetString("GeneralMsg_EmptyUser"), ResourceCulture.GetString("GeneralTitle_Prompt")); return; } else if (string.IsNullOrWhiteSpace(password)) { MessageBox.Show(ResourceCulture.GetString("GeneralMsg_EmptyPwd"), ResourceCulture.GetString("GeneralTitle_Prompt")); return; } bool loginResult = false; //登录结果 string loginUserId = string.Empty; //登录用户对应 OA 系统用户 id string loginMessage = string.Empty; //登录结果提示信息 try { #region LDAP 登录&OA验证&初始密码验证 loginResult = EoopService.LoginVerify(userName, password, out loginUserId, out loginMessage); if (!loginResult) { MessageBox.Show(loginMessage, ResourceCulture.GetString("GeneralTitle_Prompt")); return; } if (loginResult && !string.IsNullOrEmpty(loginMessage) && loginMessage.Trim() == "1")//默认密码登录,强制更新密码 { this.Hide(); ChangePassword changePwdForm = new ChangePassword(DefaultLanguage, userName, password, true); changePwdForm.ShowDialog(); return; } #endregion #region OA 系统验证登录用户信息 List <HrmResource> loginHrmUsers = EoopService.GetHrmResource(userName); if (loginHrmUsers.Count != 1)//"AD 人事系统登录用户({userName}不存在/不唯一"; { string showMsg = loginHrmUsers.Count == 0 ? string.Format(ResourceCulture.GetString("LoginMsg_NotExistUser"), userName) : string.Format(ResourceCulture.GetString("LoginMsg_NotUniqueUser"), userName); MessageBox.Show(showMsg, ResourceCulture.GetString("GeneralTitle_Prompt")); return; } LoginHrmUser = loginHrmUsers[0]; #endregion #region OA 系统验证资产用户信息 //string loginId = CurrentAsset != null ? CurrentAsset.loginid : ""; //List<HrmResource> thisHrmUsers = EoopService.GetHrmResource(loginId); //if (thisHrmUsers.Count != 1)//"AD 人事系统登录用户({userName}不存在/不唯一"; //{ // string showMsg = thisHrmUsers.Count == 0 ? string.Format(ResourceCulture.GetString("LoginMsg_NotExistAssetUser"), userName) : string.Format(ResourceCulture.GetString("LoginMsg_NotUniqueAssetUser"), userName); // MessageBox.Show(showMsg, ResourceCulture.GetString("GeneralTitle_Prompt")); // return; //} //CurrentAssetHrmUser = thisHrmUsers.Count > 0 ? thisHrmUsers[0] : new HrmResource(); #endregion #region 判断用户是否可使用该资产登录 if (CurrentAsset.tinyintfield2.Trim() != "1")//非公共资产 { List <Property> loginUserPropertyList = EoopService.GetUserAssetList(userName); if (loginUserPropertyList == null || loginUserPropertyList.Where(p => p.id == CurrentAsset.id).Count() == 0)//非为资产本人登录 { //同一用户组判断 var groupMembers = EoopService.GetGroupMembers(CurrentAssetHrmUser.userId, LoginHrmUser.loginid); var departRoles = EoopService.GetDepartRoleMapping(LoginHrmUser.departmentid); if (groupMembers.Count == 0 && departRoles.Count == 0)//非资产所属用户组用户登录 { MessageBox.Show(ResourceCulture.GetString("LoginMsg_NotSameGroup"), ResourceCulture.GetString("LoginMsg_Title")); return; } } } #endregion #region 记住用户 & 记住密码 #region 注释代码:记住多个用户 //List<LogUser> userList = new List<LogUser>(); //using (FileStream fStream = new FileStream("data.bin", FileMode.OpenOrCreate, FileAccess.ReadWrite)) //{ // BinaryFormatter bFormat = new BinaryFormatter(); // List<LogUser> users = fStream.Length > 0 ? bFormat.Deserialize(fStream) as List<LogUser> : new List<LogUser>(); // if (chxUser.Checked) // { // LogUser user = new LogUser(); // user.Username = userName; // user.Password = chxPassword.Checked ? password : ""; //如果单击了记住密码的功能则在文件中保存密码,否则不在文件中保存密码 // var containsUsers = users.Where(u => u.Username == userName); // if (containsUsers != null && containsUsers.Count() > 0) //选在集合中是否存在用户名 // { // int index = users.IndexOf(containsUsers.SingleOrDefault()); // users.RemoveAt(index); // } // users.Add(user); // } // else // { // var containsUsers = users.Where(u => u.Username == userName); // if (containsUsers != null && containsUsers.Count() > 0) //选在集合中是否存在用户名 // { // int index = users.IndexOf(containsUsers.SingleOrDefault()); // users.RemoveAt(index); // } // } // userList = users; //} //using (FileStream fStream = new FileStream("data.bin", FileMode.Open, FileAccess.ReadWrite)) //{ // BinaryFormatter bFormat = new BinaryFormatter(); // bFormat.Serialize(fStream, userList); //要先将User类先设为可以序列化(即在类的前面加[Serializable]) //} #endregion #region 记录最近一次登录用户 /*using (FileStream fStream = new FileStream(Application.StartupPath + @"\data.bin", FileMode.Create)) * { * BinaryFormatter bFormat = new BinaryFormatter(); * List<LogUser> users = fStream.Length > 0 ? bFormat.Deserialize(fStream) as List<LogUser> : new List<LogUser>(); * if (chxUser.Checked) * { * LogUser user = new LogUser(); * user.Username = userName; * user.Password = chxPassword.Checked ? password : ""; //如果单击了记住密码的功能则在文件中保存密码,否则不在文件中保存密码 * var containsUsers = users.Where(u => u.Username == userName); * if (containsUsers != null && containsUsers.Count() > 0) //选在集合中是否存在用户名 * { * int index = users.IndexOf(containsUsers.SingleOrDefault()); * users.RemoveAt(index); * } * users.Add(user); * } * else * { * var containsUsers = users.Where(u => u.Username == userName); * if (containsUsers != null && containsUsers.Count() > 0) //选在集合中是否存在用户名 * { * int index = users.IndexOf(containsUsers.SingleOrDefault()); * users.RemoveAt(index); * } * } * * bFormat.Serialize(fStream, users); //要先将User类先设为可以序列化(即在类的前面加[Serializable]) * }*/ if (chxUser.Checked) { Properties.Settings.Default.UserName = userName; Properties.Settings.Default.Password = password; } else { Properties.Settings.Default.UserName = ""; Properties.Settings.Default.Password = ""; } Properties.Settings.Default.Save(); #endregion #endregion #region 登录,进入程序主界面 MainForm //if (!Cef.IsInitialized) //{ // Cef.RunMessageLoop(); // Cef.Shutdown(); //} MainForm mainForm = new MainForm(loginUserId, userName, password, DefaultLanguage, CurrentSLCode, CurrentSLCodeList, CurrentAsset, LoginHrmUser); this.Hide(); mainForm.WindowState = FormWindowState.Maximized; mainForm.Show(); //初始化 CefSharp 浏览器内核组件 InitializeCefSharp(DefaultLanguage); txtPassword.Text = string.Empty; chxUser.Checked = false; chxPassword.Checked = false; #endregion } catch (Exception ex) { string exMessage = ResourceCulture.GetString("GeneralMsg_AppException"); if (Program.ReleaseType == "DEBUG") { exMessage = ex.Message + ex.StackTrace; } MessageBox.Show(exMessage, ResourceCulture.GetString("LoginMsg_Title")); } }
/// <summary> /// 窗体初始化 /// </summary> public Login() { try { InitializeComponent(); //初始化窗体信息 InitializeFormInfo(); #region 验证:锁号 & 资产 & 资产绑定 List <string> slCodeList = new List <string>(); #region 获取资产软锁锁号信息 try { slCodeList = (new safeNetBiz()).getSlCode(); } catch { } #endregion #if DEBUG //slCodeList.Clear(); //slCodeList.Add("256451793977733503"); #endif if (slCodeList.Count == 0)//未生成锁号,需进入资产绑定授权界面 { GotoBindAsset(); return; } List <UserSLCodes> userSlCodeList = new List <UserSLCodes>(); foreach (var slcode in slCodeList) { UserSLCodes userSLCodes = EoopService.GetUserSLCodes(slcode); if (userSLCodes != null) { userSlCodeList.Add(userSLCodes); } } //已生成锁号,未绑定资产(锁号未启用,请联系技术部) if (userSlCodeList.Count == 0) { MessageBox.Show(ResourceCulture.GetString("LoginMsg_Disable"), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); FormDisabled(); return; } //检测到软锁已绑定多台资产,请联系信息技术部。 if (userSlCodeList.Where(u => u.propertyId == userSlCodeList[0].propertyId).Count() != userSlCodeList.Count) { MessageBox.Show(ResourceCulture.GetString("LoginMsg_MultipleAsset"), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); FormDisabled(); return; } string propertyId = userSlCodeList[0].propertyId; string slCode = userSlCodeList[0].slCode; Property currentAsset = EoopService.GetUserAsset(propertyId); if (currentAsset == null) { //锁号未启用,请联系信息技术部。 MessageBox.Show(ResourceCulture.GetString("LoginMsg_Disable"), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); FormDisabled(); return; } #endregion CurrentSLCodeList = slCodeList; CurrentAsset = currentAsset; CurrentSLCode = slCodeList[0]; string loginId = CurrentAsset != null ? CurrentAsset.loginid : ""; List <HrmResource> thisHrmUsers = EoopService.GetHrmResource(loginId); if (thisHrmUsers.Count != 1)//AD 人事系统登录用户不存在/不唯一 { string showMsg = thisHrmUsers.Count == 0 ? ResourceCulture.GetString("LoginMsg_NotExistAssetUser") : ResourceCulture.GetString("LoginMsg_NotUniqueAssetUser"); MessageBox.Show(showMsg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); ApplicationExit(); return; } CurrentAssetHrmUser = thisHrmUsers.Count > 0 ? thisHrmUsers[0] : new HrmResource(); #region 读取配置文件: 绑定记住的用户名和密码 if (cbxUserName.Items.Count > 0) { cbxUserName.Items.Clear(); } //数据序列化异常,更换存储方式 neo 2017年4月19日9:55:43 /*using (FileStream fStream = new FileStream(Application.StartupPath + @"\data.bin", FileMode.OpenOrCreate)) * { * if (fStream.Length > 0) * { * BinaryFormatter bf = new BinaryFormatter(); * List<LogUser> users = bf.Deserialize(fStream) as List<LogUser>; * #region 下拉框 - 记住密码 * * //foreach (LogUser user in users) * //{ * // this.cbxUserName.Items.Add(user.Username); * //} * //if (!string.IsNullOrWhiteSpace(cbxUserName.Text)) * //{ * // var user = users.Where(u => u.Username == cbxUserName.Text).SingleOrDefault(); * // if (user != null) * // { * // this.txtPassword.Text = user.Password; * // this.chxUser.Checked = true; * // this.chxPassword.Checked = !string.IsNullOrEmpty(user.Password); * // } * //} * #endregion * #region 输入框 - 记住密码 * * foreach (LogUser user in users) * { * this.txtUserName.Text = !string.IsNullOrWhiteSpace(user.Username) ? user.Username : string.Empty; * this.txtPassword.Text = !string.IsNullOrEmpty(user.Password) ? user.Password : string.Empty; * this.chxUser.Checked = !string.IsNullOrWhiteSpace(user.Username); * this.chxPassword.Checked = !string.IsNullOrEmpty(user.Password); * } * #endregion * } * }*/ string username = Properties.Settings.Default.UserName; string password = Properties.Settings.Default.Password; this.txtUserName.Text = !string.IsNullOrWhiteSpace(username) ? username : string.Empty; this.txtPassword.Text = !string.IsNullOrEmpty(password) ? password : string.Empty; this.chxUser.Checked = !string.IsNullOrWhiteSpace(username); this.chxPassword.Checked = !string.IsNullOrEmpty(password); #region 设置默认(第一个)登录用户 //if (this.cbxUserName.Items.Count > 0) //{ // this.cbxUserName.SelectedIndex = this.cbxUserName.Items.Count - 1; //} #endregion #endregion } catch (Exception ex) { string exMessage = ResourceCulture.GetString("GeneralMsg_AppException"); if (Program.ReleaseType == "DEBUG") { exMessage = ex.Message + ex.StackTrace; } MessageBox.Show(exMessage, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); FormDisabled(); } }