Example #1
0
        protected void btnSave_ServerClick(object sender, EventArgs e)
        {
            string strUserName = txt_UserName.Value.Trim();
            string strNickName = txt_NickName.Value.Trim();
            string strPassword = txt_Password.Value.Trim();
            string strPasswordSecond = txt_PasswordSecond.Value.Trim();
            if ("" == strUserName || "" == strNickName || "" == strPassword || "" == strPasswordSecond)
                return;
            if(UserItem.ExistUser(strUserName))
            {
                PageUtil.PageAlert(this.Page, "该用户名已存在!");
                return;
            }
            if (!strPassword.Equals(strPasswordSecond))
            {
                PageUtil.PageAlert(this.Page, "密码和确认密码不一致!");
                return;
            }
            if (lb_RoleSelect.Items.Count == 0)
            {
                PageUtil.PageAlert(this.Page, "请选择角色!");
                return;
            }
            UserItem addItem = new UserItem();
            addItem.UserName = strUserName;
            addItem.NickName = strNickName;
            addItem.Password = Util.MD5Encrypt(strPassword);
            addItem.Gender = rb_GenderMale.Checked ? "男" : "女";
            string strTel = txt_Tel.Value.Trim();
            if ("" != strTel)
                addItem.Tel = txt_Tel.Value.Trim();
            string strEmail = txt_Email.Value.Trim();
            if ("" != strEmail)
                addItem.Email = txt_Email.Value.Trim();
            int nNewId = UserItem.Save(addItem);
            if (nNewId <= 0)
                return;

            UserRoleItem[] alUserRoles = UserRoleItem.GetUserRoles(nNewId);
            Hashtable htExistRoles = new Hashtable();
            if (null != alUserRoles)
            {
                foreach (UserRoleItem item in alUserRoles)
                    htExistRoles[item.RoleItemId + ""] = 1;
            }
            foreach (ListItem item in lb_RoleSelect.Items)
            {
                if (htExistRoles.ContainsKey(item.Value))
                    continue;
                UserRoleItem addUserRole = new UserRoleItem();
                addUserRole.RoleItemId = int.Parse(item.Value);
                addUserRole.UserItemId = nNewId;
                UserRoleItem.Save(addUserRole);
            }
            PageUtil.PageAlert(this.Page, "保存成功!");
        }
Example #2
0
 public static UserRoleItem Get(int __nId)
 {
     if (__nId <= 0)
         return null;
     string strFilter = "Id=" + __nId;
     UserRoleItem uItem = new UserRoleItem();
     UserRoleItem[] alist = (UserRoleItem[])HEntityCommon.HEntity(uItem).EntityList(strFilter);
     if (null == alist || alist.Length == 0)
         return null;
     if (alist.Length > 1)
         throw new Exception(string.Format("{0}-{1}:{2} exist mutil records", uItem.GetTableName(), uItem.GetKeyName(), __nId));
     return alist[0];
 }
Example #3
0
 public static int Save(UserRoleItem _saveObj)
 {
     if (null == _saveObj)
         return -1;
     return HEntityCommon.HEntity(_saveObj).EntitySave();
 }