Exemplo n.º 1
0
 /// <summary>
 /// 通过对象删除记录
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public bool Del( TbSysUser item)
 {
     bool res = false;
     using (var connection = DataBase.GetOpenConnection())
     {
         res = connection.Delete< TbSysUser>(item);
     }
     return res;
 }
Exemplo n.º 2
0
 /// <summary>
 /// 通过ID删除记录
 /// </summary>
 /// <param name="id">需要删除的对象的ID</param>
 /// <returns></returns>
 public bool Del(int id)
 {
     bool res = false;
     TbSysUser item = new TbSysUser();
     using (var connection = DataBase.GetOpenConnection())
     {
         item = GetByID(id);
         res = connection.Delete<TbSysUser>(item);
     }
     return res;
 }
Exemplo n.º 3
0
        /// <summary>
        /// 同时对user和userRole进行添加
        /// </summary>
        /// <param name="item1"></param>
        /// <param name="RoleIds"></param>
        /// <returns></returns>
        public int AddUserAndUserRole(TbSysUser User, string RoleIds)
        {
            try
            {
                string SRoleNames = "";  //用于保存拥有的角色
                string[] IRoleIds = RoleIds.Split(new char[] { ',' });//拆分角色Id;
                TbSysUserRole UserRole = new TbSysUserRole();//userRole添加的对象
                foreach (var ID in IRoleIds)
                {
                    UserRole.IRoleId = int.Parse(ID);
                    SRoleNames = srDao.GetByID(int.Parse(ID)).SRoleName + "," + SRoleNames;
                }
                //清除多余的分隔符','
                SRoleNames = SRoleNames.Substring(0, SRoleNames.Length - 1);

                User.SRoleName = SRoleNames;
                User.SPassword = Utitil.MD5(User.SPassword);   //对用户的密码在客户端进行MD5加密
                User.SOtherPassword = Utitil.MD5(User.SOtherPassword);

                User.DCreateDate = DateTime.Now;//创建时间
                User.DLastLoginDate = DateTime.Now;//默认最后登录时间为创建时间

                suDao.Insert(User);//插入

                UserRole.IUserId = User.Id;
                foreach (string id in IRoleIds)
                {
                    UserRole.IRoleId = int.Parse(id);
                    sysUserRoleDao.Insert(UserRole);
                }
                return 0;
            }
            catch (Exception ex)
            {

                return 0;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 更新用户角色
        /// </summary>
        /// <param name="item"></param>
        /// <param name="RoleIds"></param>
        /// <returns></returns>
        public int PutUserAndUserRole(TbSysUser item, string RoleIds)
        {
            try
            {
                TbSysUser tempuser = new SysUserDAO().GetByID(item.Id);
                if (tempuser != null)
                {
                    item.DCreateDate = tempuser.DCreateDate;    //更新时不更新用户的创建时间
                }

                //在对密码进行加密前先验证客户端传过来的密码是否非空
                if (!String.IsNullOrEmpty(item.SPassword))
                {
                    item.SPassword = Utitil.MD5(item.SPassword);  //对密码进行md5加密

                    //使用了更新密码功能
                    LogWriter.Default.WriteWarning("使用了管理员更新密码功能,ip:" + Utitil.getIP()
                        + ",更改的用户名" + item.SUserName + ",当前用户id:" + SysUserInfo.GetUserID());

                }
                else
                {
                    item.SPassword = tempuser.SPassword;  //在未更改密码的情况下,使用原密码
                }

                if (!String.IsNullOrEmpty(item.SOtherPassword))
                {
                    item.SOtherPassword = Utitil.MD5(item.SOtherPassword);  //对密码进行md5加密

                    //使用了更新密码功能
                    LogWriter.Default.WriteWarning("使用了管理员更新第二密码功能,ip:" + Utitil.getIP()
                        + ",更改的用户名" + item.SUserName + ",当前用户id:" + SysUserInfo.GetUserID());

                }
                else
                {
                    item.SOtherPassword = tempuser.SOtherPassword;  //在未更改密码的情况下,使用原密码
                }

                if (!string.IsNullOrEmpty(RoleIds))
                {
                    string[] IRoleIds;
                    string SRoleName = "";
                    IRoleIds = RoleIds.Split(new char[] { ',' });//拆分角色Id;
                    TbSysUserRole UserRole = new TbSysUserRole();//userRole添加的对象
                    UserRole.IUserId = item.Id;
                    IList<TbSysUserRole> OldUserRole = sysUserRoleDao.GetByPage("IUserId =" + item.Id, 0, int.MaxValue);//找到以前拥有的所有角色
                    if (OldUserRole.Count > 0)
                    {
                        sysUserRoleDao.Del(OldUserRole);  //通过对象集的方法删除
                    }

                    //添加user新的角色
                    foreach (string id in IRoleIds)
                    {
                        UserRole.IRoleId = int.Parse(id);
                        SRoleName = srDao.GetByID(int.Parse(id)).SRoleName + "," + SRoleName;//拼装角色字符串
                        if (sysUserRoleDao.Insert(UserRole) == 0)
                            return 0;//添加失败
                    }
                    SRoleName = SRoleName.Substring(0, SRoleName.Length - 1);
                    item.SRoleName = SRoleName;
                }
                suDao.Update(item);
                return 1;
            }
            catch (Exception ex)
            {

                return 0;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取需要更新的用户角色
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult GetUserAndUserRole(int id)
        {
            TbSysUser user = suDao.GetByID(id);//获取当前用户

            //修正把密码发送到客户端的问题
            TbSysUser tempUser = new TbSysUser();  //新建一个对象
            ClassValueCopier.Copy(tempUser, user);
            tempUser.SPassword = "";  //把系统后台用户的密码置空

            UserAndUserRole item = new UserAndUserRole();
            if (!string.IsNullOrEmpty(item.IPart.ToString()))
            {
                int partId = (int)item.IPart;
                TbSysPart tempPart = syspartDAO.GetByID(partId);
                if (tempPart != null)
                {
                    item.SPartName = tempPart.SPartName;
                }

            }
            ClassValueCopier.Copy(item, tempUser);
            return Json(item, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 6
0
 /// <summary>
 /// 插入一个对象
 /// </summary>
 /// <param name="item">需要插入的对象</param>
 /// <returns></returns>
 public int Insert(TbSysUser item)
 {
     int id = 0;
     using (var connection = DataBase.GetOpenConnection())
     {
         id = (int)connection.Insert<TbSysUser>(item);
     }
     return id;
 }