private void LoginEventHandler(object sender, LoginEventArgs e) { bool isRegister = bllUser.IsUserRegister(e.RoleID, e.UserName, e.Password); string roleName = "一般用户"; if (e.RoleID == 5) { roleName = "管理员"; } else if (e.RoleID == 6) { roleName = "系统管理员"; } string loginInfo = null; if (isRegister) { loginInfo = string.Format("用户:{0},角色:{1},登录系统,结果:成功!", e.UserName, roleName); } else { loginInfo = string.Format("用户:{0},角色:{1},登录系统,结果:失败!", e.UserName, e.RoleID); } LogModel logModel = new LogModel(); logModel.logCategory = EnumLogCategory.管理层日志.ToString(); logModel.logType = EnumLogType.提示.ToString(); logModel.logContent = loginInfo; logModel.logTime = System.DateTime.Now; logBll.Add(logModel); if (e.IsChangeUser == false) { if (isRegister == true) { this.View.HideLoginForm(); this.View.ShowMainForm(e.RoleID); } else { this.View.ShowDialog("登录失败!用户权限、用户名或密码错误!"); } } else { if (isRegister == true) { MainPresenter mainPre = (MainPresenter)this.View.GetPresenter(typeof(MainPresenter)); if (mainPre != null) { mainPre.View.ShowView(); mainPre.View.OnSetLimit(e.RoleID); this.View.HideLoginForm(); } } else { this.View.ShowDialog("登录失败!用户权限、用户名或密码错误!"); } } }
//protected override void OnViewSet() //{ // string jxDB = ConfigurationManager.AppSettings["JXDataBase"]; // string jxDBUserPwd = ConfigurationManager.AppSettings["JXDataBaseUserPwd"]; // jxDBUserPwd = EncAndDec.Decode(jxDBUserPwd, "zwx", "xwz"); // if (string.IsNullOrEmpty(jxDBUserPwd)) // { // return; // } // PubConstant.ConnectionString = jxDB + jxDBUserPwd; // //PubConstant.ConnectionString = jxDB + "Persist Security info = True;Initial Catalog=ECAMSDatabase;User ID=sa;Password=123456;"; // this.View.eventBindRoleData += BindRoleDataEventHandler; // this.View.eventLogin += LoginEventHandler; //} #endregion #region 实现ILoginView事件方法 public void Login(LoginUserModel userModel) { bool isRegister = false; if (userModel.RoleID == 3) { isRegister = true; } else { isRegister = bllUser.IsUserRegister(userModel.RoleID, userModel.UserName, userModel.Password); } //string roleName = userModel.RoleName; string loginInfo = null; if (isRegister) { loginInfo = string.Format("用户:{0},登录系统,结果:成功!", userModel.UserName); } else { loginInfo = string.Format("用户:{0},角色:{1},登录系统,结果:失败!", userModel.UserName, userModel.UserName); } if (userModel.IsChangeUser == false) { if (isRegister == true) { this.View.HideLoginForm(); this.View.ShowMainForm(userModel.RoleID, userModel.UserName); } else { this.View.ShowMessage("登录失败!用户权限、用户名或密码错误!", "信息提示"); } } else { if (isRegister == true) { //MainPresenter mainPre = (MainPresenter)this.View.GetPresenter(typeof(MainPresenter)); //if (mainPre != null) //{ // mainPre.View.ShowView(); // mainPre.SetLimit(userModel.RoleID); // this.View.HideLoginForm(); //} } else { this.View.ShowMessage("登录失败!用户权限、用户名或密码错误!", "信息提示"); } } }