//=========数据绑定 #region 数据绑定 /// <summary> /// 数据绑定 /// 创建人:林以恒 /// 2015年7月6日14:09:00 /// </summary> private void LoadData() { if (!Request.QueryString["id"].IsNum()) { return; } string id = Request.QueryString["id"]; var query = new DapperExQuery <T_ADMIN>().AndWhere(n => n.ID, OperationMethod.Equal, Int32.Parse(id)); var adminUser = _adminUserBll.GetEntity(query); tbxA_NAME.Text = adminUser.A_NAME; tbxA_CHINESE_NAME.Text = adminUser.A_TRUE_NAME; tbxPassword.Text = adminUser.PASSWORD; tbxCfm_Password.Text = adminUser.PASSWORD; tbxPhone.Text = adminUser.A_PHONE; if (adminUser.A_GENDER == 1) { rbtnFirst.Checked = true; } else { rbtnSecond.Checked = true; } //tbxAD_REMARK.Text = T_ADMIN_ROLES.AD_REMARK.ToString(); }
/// <summary> /// 右侧角色对应用户的数据绑定 /// 创建 毛枫 2015-4-17 /// </summary> private void BindGrid2() { string R_CODE = FineUITable.GetSelectedDataKeyCode(Grid1); if (R_CODE == "") { Grid2.RecordCount = 0; Grid2.DataSource = null; Grid2.DataBind(); } else { // 过滤选中角色下的所有用户 long allcount = 0; var query = new DapperExQuery <T_ADMIN_ROLES>().AndWhere(n => n.R_CODE, OperationMethod.Equal, R_CODE); int PageIndex = Grid2.PageIndex + 1; int PageSize = Grid2.PageSize; List <T_ADMIN_ROLES> qs = T_ADMIN_ROLES_BLL.GetListByPage(query, "", PageIndex, PageSize, out allcount); List <T_ADMIN> q = new List <T_ADMIN>(); foreach (T_ADMIN_ROLES t in qs) { var query1 = new DapperExQuery <T_ADMIN>().AndWhere(n => n.A_CODE, OperationMethod.Equal, t.A_CODE); T_ADMIN T_ADMIN = new T_ADMIN(); T_ADMIN = T_ADMIN_BLL.GetEntity(query1); q.Add(T_ADMIN); } //获取总记录数 Grid2.RecordCount = Int32.Parse(allcount.ToString()); Grid2.DataSource = q; Grid2.DataBind(); } }
/// <summary> /// 私有方法:从数据库中判断用户是否登录 /// 创建 毛枫 2015-4-21 /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <returns></returns> private static T_ADMIN IsLoginFromSql(string username, string password) { T_ADMIN_BLL T_ADMIN_BLL = new T_ADMIN_BLL(); var query = new DapperExQuery <T_ADMIN>().AndWhere(n => n.A_NAME, OperationMethod.Equal, username) .AndWhere(n => n.PASSWORD, OperationMethod.Equal, EncryptUtil.Md5Encode(password.Trim(), 16)); var admin = T_ADMIN_BLL.GetEntity(query); return(admin); }
/// <summary> /// 保存修改 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_OnClick(object sender, EventArgs e) { string message = ""; T_ADMIN_BLL T_ADMIN_BLL = new T_ADMIN_BLL(); try { //①获取当前登录用户 AdminUserModel adminInfo = AdminwebUserManager.GetCurrentAdminUser(); //②判断当前登录用户原密码 var query = new DapperExQuery <T_ADMIN>().AndWhere(n => n.A_CODE, OperationMethod.Equal, adminInfo.A_CODE) .AndWhere(n => n.PASSWORD, OperationMethod.Equal, EncryptUtil.Md5Encode(tbxOriPassword.Text.Trim(), 16)); var entity = T_ADMIN_BLL.GetEntity(query); if (entity != null) { //③判断确认密码是否等于密码 if (tbxPassword.Text == tbxCfm_Password.Text) { //④保存新密码 entity.PASSWORD = EncryptUtil.Md5Encode(tbxPassword.Text.Trim(), 16); if (new T_ADMIN_BLL().Update(entity)) { message = "修改成功"; updateWindow.Hidden = true; } else { message = "修改失败"; } } else { message = "确认密码错误"; } } else { message = "用户密码错误,请输入原密码"; } } catch (Exception ex) { message = ex.ToString(); } Alert.Show(message); }
/// <summary> /// 添加角色对应的用户 /// 创建 2015-4-17 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSaveClose_Click(object sender, EventArgs e) { SyncSelectedRowIndexArrayToHiddenField(); string str = ""; // 排除已经属于本角色的用户 int roleID = 0; if (Request.QueryString[requestStr].IsNum()) { roleID = Int32.Parse(Request.QueryString[requestStr]); T_ROLES T_ROLES = new T_ROLES(); var queryrole = new DapperExQuery <T_ROLES>().AndWhere(n => n.ID, OperationMethod.Equal, roleID); T_ROLES = T_ROLES_BLL.GetEntity(queryrole); var r_code = T_ROLES.R_CODE; // 从每个选中的行中获取ID(在Grid1中定义的DataKeyNames) List <int> userids = FineUITable.GetSelectedDataKeyIDs(Grid1); foreach (int userID in userids) { var queryAdmin = new DapperExQuery <T_ADMIN>().AndWhere(n => n.ID, OperationMethod.Equal, userID); T_ADMIN T_ADMIN = new Model.T_ADMIN(); T_ADMIN = T_ADMIN_BLL.GetEntity(queryAdmin); T_ADMIN_ROLES T_ADMIN_ROLES = new T_ADMIN_ROLES(); T_ADMIN_ROLES.R_CODE = r_code; T_ADMIN_ROLES.A_CODE = T_ADMIN.A_CODE; T_ADMIN_ROLES.CREATE_TIME = DateTime.Parse("2015-10-9"); T_ADMIN_ROLES.CREATE_USER = ""; T_ADMIN_ROLES.CREATE_USER_NAME = ""; if (T_ADMIN_ROLES_BLL.Add(T_ADMIN_ROLES)) { str = "添加成功!"; } else { str = "添加失败!"; } } //DB.SaveChanges(); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); Alert.Show("str"); } }
/// <summary> /// 私有方法:从数据库中判断用户是否登录 /// 创建 毛枫 2015-4-21 /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <returns></returns> private static T_ADMIN IsLoginFromSql(string username, string password) { T_ADMIN_BLL T_ADMIN_BLL = new T_ADMIN_BLL(); var query = new DapperExQuery<T_ADMIN>().AndWhere(n => n.A_NAME, OperationMethod.Equal, username) .AndWhere(n => n.PASSWORD, OperationMethod.Equal, EncryptUtil.Md5Encode(password.Trim(), 16)); var admin = T_ADMIN_BLL.GetEntity(query); return admin; }
/// <summary> /// 保存修改 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_OnClick(object sender, EventArgs e) { string message = ""; T_ADMIN_BLL T_ADMIN_BLL = new T_ADMIN_BLL(); try { //①获取当前登录用户 AdminUserModel adminInfo = AdminwebUserManager.GetCurrentAdminUser(); //②判断当前登录用户原密码 var query = new DapperExQuery<T_ADMIN>().AndWhere(n => n.A_CODE, OperationMethod.Equal, adminInfo.A_CODE) .AndWhere(n => n.PASSWORD, OperationMethod.Equal, EncryptUtil.Md5Encode(tbxOriPassword.Text.Trim(), 16)); var entity = T_ADMIN_BLL.GetEntity(query); if (entity != null) { //③判断确认密码是否等于密码 if (tbxPassword.Text == tbxCfm_Password.Text) { //④保存新密码 entity.PASSWORD = EncryptUtil.Md5Encode(tbxPassword.Text.Trim(), 16); if (new T_ADMIN_BLL().Update(entity)) { message = "修改成功"; updateWindow.Hidden = true; } else { message = "修改失败"; } } else { message = "确认密码错误"; } } else { message = "用户密码错误,请输入原密码"; } } catch (Exception ex) { message = ex.ToString(); } Alert.Show(message); }