Esempio n. 1
0
 public static void LoginUser(UserInformation _oUser)
 {
     if (null == _oUser)
         return;
     HttpContext.Current.Session[SYSTEM_SESSIONKEY_USERNAME] = _oUser.UserName;
     HttpContext.Current.Session[SYSTEM_SESSIONKEY_USERID] = _oUser.Id;
 }
Esempio n. 2
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);
 }
Esempio 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);
        }
Esempio n. 4
0
 public static int Save(UserInformation _Entity)
 {
     int result;
     if (null == _Entity)
     {
         result = -1;
     }
     else
     {
         result = EntityAccess<UserInformation>.Access.Save(_Entity);
     }
     return result;
 }
Esempio n. 5
0
 public static UserInformation Get(string _strUserName)
 {
     UserInformation oGet = new UserInformation();
     oGet.UserName = _strUserName;
     UserInformation[] alist = EntityAccess<UserInformation>.Access.List(oGet);
     UserInformation result;
     if (alist == null || alist.Length == 0)
     {
         result = null;
     }
     else
     {
         if (alist.Length > 1)
         {
             throw new Exception(string.Format("{0}(UserName:{1}) exist mutil records!", EntityAccess<UserInformation>.Meta.EntityName, _strUserName));
         }
         result = alist[0];
     }
     return result;
 }
Esempio n. 6
0
 public static bool ExistUser(string _strUserName, string _strPassword)
 {
     bool result;
     if (string.IsNullOrEmpty(_strUserName) || string.IsNullOrEmpty(_strPassword))
     {
         result = false;
     }
     else
     {
         UserInformation oExist = new UserInformation();
         oExist.UserName = _strUserName;
         oExist.Password = CryptUtil.MD5Encrypt(_strPassword);
         int nCount = EntityAccess<UserInformation>.Access.Count(oExist);
         if (nCount > 1)
         {
             throw new Exception(string.Format("{0}(UserName:{1}) exist mutil records!", EntityAccess<UserInformation>.Meta.EntityName, _strUserName));
         }
         result = (nCount == 1);
     }
     return result;
 }