protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { //获取父id string orgId = Request.QueryString["orgId"]; if (!string.IsNullOrEmpty(orgId)) { this.hidOrgId.Value = orgId; } else { YMessageBox.show(this, "未设置组织机构id!"); } //获取id string strId = Request.QueryString["id"]; if (!string.IsNullOrEmpty(strId)) { this.hidUserId.Value = strId; this.txtUserLogName.Disabled = true; //获取配置文件路径。 string configFile = AppDomain.CurrentDomain.BaseDirectory.ToString() + SystemConfig.databaseConfigFileName; //创建操作对象 OrgOperater orgOper = OrgOperater.createOrgOperater(configFile, SystemConfig.databaseConfigNodeName, SystemConfig.configFileKey); if (orgOper != null) { ////获取用户信息 UserInfo user = orgOper.getUser(Convert.ToInt32(strId)); if (user != null) { this.txtUserLogName.Value = user.logName; this.txtUserName.Value = user.name; this.txtUserOrder.Value = user.order.ToString(); } else { YMessageBox.show(this, "获取机构信息失败!错误信息[" + orgOper.errorMessage + "]"); return; } } else { YMessageBox.show(this, "创建数据库操作对象失败!"); return; } } } }
protected void butLogin_Click(object sender, EventArgs e) { //用户登陆 try { //校验数据 if (string.IsNullOrEmpty(this.txtUserName.Value)) { //用户名不能为空 YMessageBox.show(this, "用户名不能为空,请输入用户名后重新登录!"); return; } //获取配置文件路径。 string configFile = AppDomain.CurrentDomain.BaseDirectory.ToString() + SystemConfig.databaseConfigFileName; //获取数据库实例。 YDataBase orgDb = YDataBaseConfigFile.createDataBase(configFile, SystemConfig.databaseConfigNodeName, SystemConfig.configFileKey); if (orgDb != null) { //获取用户 OrgOperater orgOper = new OrgOperater(); orgOper.orgDataBase = orgDb; //用户密码二次加密 MD5Encrypt md5Encrypt = new MD5Encrypt(); UserInfo logUser = orgOper.getUser(this.txtUserName.Value, md5Encrypt.GetMD5(this.passUserPassword.Value)); if (logUser != null && logUser.id > 0) { //验证成功,跳转主页 FormsAuthentication.RedirectFromLoginPage(logUser.id.ToString(), false); Session.Add("UserInfo", logUser); } else { //验证失败 YMessageBox.show(this, "用户验证失败,请核对用户名和密码后重新登录!"); } } } catch (Exception ex) { YMessageBox.show(this, "用户登陆异常!异常消息[" + ex.Message + "]"); } }