public void AssignManger(Imanager manager) { Manager = manager; }
public static void Act(Imanager me) { me.Manage(); }
private void Login() { this.Invoke(new Action(() => { btnSubmit.Text = "登录中..."; btnSubmit.Enabled = false; })); bool isLogin = false; string strUserName = this.txtUserName.Text.Trim(); string strPassword = this.txtPassword.Text.Trim(); string strError = "登录失败"; if (string.IsNullOrWhiteSpace(strUserName) || string.IsNullOrWhiteSpace(strPassword)) { strError += ":登录名及密码不允许为空。"; Logger.Error(strError, MethodBase.GetCurrentMethod());//记录日志 MessageBox.Show(strError, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } strError = "登录失败"; try { Imanager <User> manager = Tools.DynamicCreateClass <Imanager <User> >("UserManager"); if (manager == null) { strError += ":创建用户管理实例异常。"; Logger.Error(strError, MethodBase.GetCurrentMethod());//记录日志 MessageBox.Show(strError, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } UserList = manager.Load(); if (UserList.Count > 0) { var result = (from u in UserList where u.LoginName == strUserName select u).ToList(); if (result != null && result.Count > 0) { if (TripleDES.EncryptPassword(strPassword) == result[0].Password) { this.ThisUser = result[0]; isLogin = true; } else { strError += ":密码错误。"; } } else { strError += ":系统不存在该用户。"; } } else { strError += ":系统用户表无数据信息。"; } } catch (Exception ex) { strError += string.Format(":{0}。", ex.Message); } if (isLogin) { Logger.Info("用户 " + ThisUser.ChineseName + " 成功登陆系统。", MethodBase.GetCurrentMethod(), this.ThisUser.UserID); this.DialogResult = DialogResult.OK; //返回一个登录成功的对话框状态 //this.Invoke(new Action(() => { this.Close(); })); } else { Logger.Error(strError, MethodBase.GetCurrentMethod());//记录日志 MessageBox.Show(strError, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Invoke(new Action(() => { btnSubmit.Text = "登录"; btnSubmit.Enabled = true; })); } }