コード例 #1
0
ファイル: UserGroupBll.cs プロジェクト: gofixiao/SCM
        /// <summary>
        /// 新建用户组
        /// </summary>
        /// <param name="dal"></param>
        /// <param name="userGroup"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public static bool Create(IDal dal, CUserGroup userGroup,string user)
        {
            int i;
            dal.BeginTran();
            dal.Execute(
                "INSERT INTO tUserGroup( GroupCode ,GroupName ,BuildUser ,EditUser,GroupType) VALUES  ( @GroupCode , @GroupName,@BuildUser,@EditUser,@GroupType)",
                out i,
                dal.CreateParameter("@GroupCode", userGroup.GroupCode.Trim()),
                dal.CreateParameter("@GroupName", userGroup.GroupName.Trim()),
                dal.CreateParameter("@GroupType", (short) (userGroup.GroupType)),
                dal.CreateParameter("@BuildUser", user),
                dal.CreateParameter("@EditUser", user)
                );

            if (i == 0)return false;
            var dt = dal.Select("SELECT Id FROM tUserGroup WHERE GroupCode =@GroupCode", out i,
                dal.CreateParameter("@GroupCode", userGroup.GroupCode));
            if (i == 0) return false;
            userGroup.Id = Convert.ToInt16(dt.Rows[0]["Id"]);

            foreach (var fun in userGroup.GroupFun)
            {
                fun.GroupCode = userGroup.GroupCode;
                UserGroupFunBll.Create(dal, fun, user);
            }
            dal.CommitTran();
            userGroup.Fun = UserGroupFunBll.CountGroupFun(dal, userGroup.GroupCode);
            userGroup.People = UserBll.CountPeople(dal, userGroup.GroupCode);
            return true;
        }
コード例 #2
0
ファイル: UserGroupBll.cs プロジェクト: gofixiao/SCM
        /// <summary>
        /// 删除用户组
        /// </summary>
        /// <param name="dal"></param>
        /// <param name="id"></param>
        /// <param name="hisUserGroup"></param>
        /// <returns></returns>
        public static bool Delete(IDal dal, int id ,out CUserGroup hisUserGroup)
        {
            int i;
            hisUserGroup = Get(dal, id);
            if (hisUserGroup == null) return false;

            dal.BeginTran();
            dal.Execute("UPDATE tUser SET GroupCode=null WHERE GroupCode=@GroupCode",out i,
                dal.CreateParameter("@GroupCode",hisUserGroup.GroupCode));
            dal.Execute("DELETE FROM tUserGroupFun WHERE GroupCode=@GroupCode",out i,
                dal.CreateParameter("@GroupCode",hisUserGroup.GroupCode));
            dal.Execute("DELETE FROM tUserGroup WHERE Id=@Id",out i,
                dal.CreateParameter("@Id",id));
            dal.CommitTran();
            return true;
        }
コード例 #3
0
 // PUT api/usergroupapi/5
 public CUserGroup Put(int id, CUserGroup value)
 {
     var user = (CSign)HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]];
     if (user == null)
     {
         throw new HttpResponseException(new SiginFailureMessage());
     }
     using (var dal = DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0))
     {
         bool ok;
         try
         {
             dal.Open();
             ok=UserGroupBll.Update(dal, value,string.Format("{0}-{1}", user.UserCode, user.UserName));
         }
         catch(Exception ex)
         {
             LogBll.Write(dal,new CLog
             {
                 LogUser = string.Format("{0}-{1}", user.UserCode, user.UserName),
                 LogContent = string.Format("{0}#{1}", "UserGroup.Put", ex.Message),
                 LogType = LogType.系统异常
             });
             throw new HttpResponseException(new SystemExceptionMessage());
         }
         if (!ok)
         {
             LogBll.Write(dal,new CLog
             {
                 LogUser = string.Format("{0}-{1}", user.UserCode, user.UserName),
                 LogContent = string.Format("修改用户组{0}-{1}", value.GroupCode, value.GroupName),
                 LogType = LogType.操作失败
             });
             throw new HttpResponseException(new DealFailureMessage());
         }
         LogBll.Write(dal,new CLog
         {
             LogUser = string.Format("{0}-{1}", user.UserCode, user.UserName),
             LogContent = string.Format("修改用户组{0}-{1}", value.GroupCode, value.GroupName),
             LogType = LogType.操作成功
         });
         dal.Close();
         return value;
     }
 }
コード例 #4
0
ファイル: UserGroupBll.cs プロジェクト: gofixiao/SCM
        /// <summary>
        /// 修改用户组
        /// </summary>
        /// <param name="dal"></param>
        /// <param name="userGroup"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public static bool Update(IDal dal, CUserGroup userGroup,string user)
        {
            int i;
            dal.BeginTran();
            dal.Execute("UPDATE tUserGroup SET GroupName=@GroupName,EditUser=@EditUser,EditDate=GETDATE(),GroupType=@GroupType WHERE Id=@Id", out i,
                dal.CreateParameter("@GroupName",userGroup.GroupName.Trim()),
                dal.CreateParameter("@EditUser",user),
                dal.CreateParameter("@Id",userGroup.Id),
                dal.CreateParameter("@GroupType",userGroup.GroupType));
            if (i == 0) return false;

            foreach (var fun in userGroup.GroupFun)
            {
                UserGroupFunBll.Update(dal, fun, user);
            }
            dal.CommitTran();
            userGroup.Fun = UserGroupFunBll.CountGroupFun(dal, userGroup.GroupCode);
            userGroup.People = UserBll.CountPeople(dal, userGroup.GroupCode);
            return true;
        }