Ejemplo n.º 1
0
 protected void btn_Add_ServerClick(object sender, EventArgs e)
 {
     int nAdd = TypeUtil.ParseInt(txt_AddNumber.Value, 0);
     if (nAdd <= 0)
     {
         PageUtil.PageAlert(this.Page, "请填写要新增的用户数量");
         return;
     }
     Server.ScriptTimeout = nAdd;
     int nId = EntityAccess<UserInformation>.Access.Count();
     nAdd += nId;
     DateTime dtBegin = DateTime.Now;
     int nRoleId = TypeUtil.ParseInt(sel_Role.SelectedValue, -1);
     bool bSelectRole = nRoleId >= 1;
     for (int i = nId; i < nAdd; i++)
     {
         UserInformation oUser = new UserInformation();
         oUser.UserName = "******" + i;
         oUser.Password = "******";
         oUser.Age = 18;
         oUser.Gender = 1;
         oUser.NickName = "胡伊欢下属" + i;
         oUser.QQ = "814822671";
         oUser.PostCode = "471000";
         oUser.MSN = "5749230583";
         oUser.Email = "*****@*****.**";
         oUser.CardID = "410489189508043674";
         int nAddId = UserInformation.Save(oUser);
         if (nAddId >= 1 && bSelectRole)
         {
             SystemUserRole oUserRole = new SystemUserRole();
             oUserRole.RoleId = nRoleId;
             oUserRole.UserId = nAddId;
             SystemUserRole.Save(oUserRole);
         }
     }
     lbl_Message.InnerHtml = string.Format("<br />新增完成,当前系统用户数量 <b>{0}</b> 个。", EntityAccess<UserInformation>.Access.Count());
     TimeSpan tsDuring = new TimeSpan(DateTime.Now.Ticks - dtBegin.Ticks);
     lbl_Message.InnerHtml += string.Format("<br />共用时 <b>{0}</b>s。", tsDuring.TotalSeconds);
 }
Ejemplo n.º 2
0
 protected void btnSave_ServerClick(object sender, EventArgs e)
 {
     if (lb_RoleSelect.Items.Count == 0)
     {
         PageUtil.PageAlert(this.Page, "请先选择角色后保存!");
         return;
     }
     if (alIds.Length == 0)
         return;
     foreach (int nId in alIds)
     {
         UserInformation addItem = UserInformation.Get(nId);
         if (null == addItem)
             continue;
         SystemUserRole[] alUserRoles = SystemUserRole.GetUserRoles(nId);
         Hashtable htExistRoles = new Hashtable();
         if (null != alUserRoles)
         {
             foreach (SystemUserRole item in alUserRoles)
                 htExistRoles[item.RoleId + ""] = item.Id;
         }
         foreach (string strKey in htExistRoles.Keys)
         {
             if (null == lb_RoleSelect.Items.FindByValue(strKey))
                 SystemUserRole.Delete((int)htExistRoles[strKey]);
         }
         foreach (ListItem item in lb_RoleSelect.Items)
         {
             if (htExistRoles.ContainsKey(item.Value))
                 continue;
             SystemUserRole addUserRole = new SystemUserRole();
             addUserRole.RoleId = int.Parse(item.Value);
             addUserRole.UserId = nId;
             SystemUserRole.Save(addUserRole);
         }
     }
     PageUtil.PageAlert(this.Page, "设置成功!");
 }
Ejemplo n.º 3
0
        protected void btnSave_ServerClick(object sender, EventArgs e)
        {
            string strUserName = txt_UserName.Value.Trim();
            string strNickName = txt_NickName.Value.Trim();
            if ("" == strUserName || "" == strNickName)
                return;
            if(nId <= 0 && UserInformation.ExistUser(strUserName))
            {
                PageUtil.PageAlert(this.Page, "该用户名已存在!");
                return;
            }
            if (lb_RoleSelect.Items.Count == 0)
            {
                PageUtil.PageAlert(this.Page, "请选择角色!");
                return;
            }
            UserInformation addItem = UserInformation.Get(nId);
            if (null == addItem)
            {
                addItem = new UserInformation();
                addItem.UserName = strUserName;
                addItem.Password = CryptUtil.MD5Encrypt(UserInformation.CONST_STR_DEFAULTPASSWORD);
            }
            PageUtil.PageFillEntity<UserInformation>(tab_baseInformation, addItem);
            string strPassword = txt_Password.Value.Trim();
            if (!strPassword.IsNullOrEmpty())
            {
                addItem.Password = CryptUtil.MD5Encrypt(strPassword);
            }
            addItem.Gender = rb_GenderMale.Checked ? 1 : 2;
            addItem.Remark = txt_Remark.Value;
            int nNewId = UserInformation.Save(addItem);
            if (nNewId <= 0)
            {
                PageUtil.PageAlert(this.Page, "保存失败!");
                return;
            }

            SystemUserRole[] alUserRoles = SystemUserRole.GetUserRoles(nNewId);
            Hashtable htExistRoles = new Hashtable();
            if (null != alUserRoles)
            {
                foreach (SystemUserRole item in alUserRoles)
                    htExistRoles[item.RoleId + ""] = item.Id;
            }
            foreach (string strKey in htExistRoles.Keys)
            {
                if (null == lb_RoleSelect.Items.FindByValue(strKey))
                    SystemUserRole.Delete((int)htExistRoles[strKey]);
            }
            foreach (ListItem item in lb_RoleSelect.Items)
            {
                if (htExistRoles.ContainsKey(item.Value))
                    continue;
                SystemUserRole addUserRole = new SystemUserRole();
                addUserRole.RoleId = int.Parse(item.Value);
                addUserRole.UserId = nNewId;
                SystemUserRole.Save(addUserRole);
            }
            PageUtil.PageAlert(this.Page, "保存成功!");
            PageUtil.PageClosePopupWindow(this.Page, true);
        }
Ejemplo n.º 4
0
 public static int Save(SystemUserRole _Entity)
 {
     int result;
     if (null == _Entity)
     {
         result = -1;
     }
     else
     {
         result = EntityAccess<SystemUserRole>.Access.Save(_Entity);
     }
     return result;
 }