Esempio n. 1
0
        /// <summary>
        /// 设置用户部门(单个用户)
        /// </summary>
        /// <param name="userId">用户主键</param>
        /// <param name="depIds">部门id,多个用逗号隔开</param>
        public bool SetDepartmentSingle(int userId, string depIds)
        {
            DataTable dt_user_dep_old = new DepartmentBLL().GetDepartmentByUserId(userId);  //用户之前拥有的部门
            List <UserDepartmentEntity> dep_addList    = new List <UserDepartmentEntity>(); //需要插入部门的sql语句集合
            List <UserDepartmentEntity> dep_deleteList = new List <UserDepartmentEntity>(); //需要删除部门的sql语句集合

            string[] str_dep = depIds.Trim(',').Split(',');                                 //传过来用户勾选的部门(有去勾的也有新勾选的)

            UserDepartmentEntity userdepdelete = null;
            UserDepartmentEntity userdepadd    = null;

            for (int i = 0; i < dt_user_dep_old.Rows.Count; i++)
            {
                //等于-1说明用户去掉勾选了某个部门 需要删除
                if (Array.IndexOf(str_dep, dt_user_dep_old.Rows[i]["departmentid"].ToString()) == -1)
                {
                    userdepdelete = new UserDepartmentEntity();
                    userdepdelete.DepartmentId = Convert.ToInt32(dt_user_dep_old.Rows[i]["departmentid"].ToString());
                    userdepdelete.UserId       = userId;
                    dep_deleteList.Add(userdepdelete);
                }
            }

            if (!string.IsNullOrEmpty(depIds))
            {
                for (int j = 0; j < str_dep.Length; j++)
                {
                    //等于0那么原来的部门没有 是用户新勾选的
                    if (dt_user_dep_old.Select("departmentid = '" + str_dep[j] + "'").Length == 0)
                    {
                        userdepadd              = new UserDepartmentEntity();
                        userdepadd.UserId       = userId;
                        userdepadd.DepartmentId = Convert.ToInt32(str_dep[j]);
                        dep_addList.Add(userdepadd);
                    }
                }
            }
            if (dep_addList.Count == 0 && dep_deleteList.Count == 0)
            {
                return(true);
            }
            else
            {
                return(dal.SetDepartmentSingle(dep_addList, dep_deleteList));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="columns">要取的列名(逗号分开)</param>
        /// <param name="order">排序</param>
        /// <param name="pageSize">每页大小</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="where">查询条件</param>
        /// <param name="totalCount">总记录数</param>
        public string GetPager(string tableName, string columns, string order, int pageSize, int pageIndex, string where, out int totalCount)
        {
            DataTable dt = AchieveCommon.SqlPagerHelper.GetPager(tableName, columns, order, pageSize, pageIndex, where, out totalCount);

            dt.Columns.Add(new DataColumn("UserRoleId"));
            dt.Columns.Add(new DataColumn("UserRole"));
            dt.Columns.Add(new DataColumn("UserDepartmentId"));
            dt.Columns.Add(new DataColumn("UserDepartment"));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataTable dtrole       = new AchieveBLL.RoleBLL().GetRoleByUserId(Convert.ToInt32(dt.Rows[i]["ID"]));
                DataTable dtdepartment = new DepartmentBLL().GetDepartmentByUserId(Convert.ToInt32(dt.Rows[i]["ID"]));
                dt.Rows[i]["UserRoleId"]       = AchieveCommon.JsonHelper.ColumnToJson(dtrole, 0);
                dt.Rows[i]["UserRole"]         = AchieveCommon.JsonHelper.ColumnToJson(dtrole, 1);
                dt.Rows[i]["UserDepartmentId"] = AchieveCommon.JsonHelper.ColumnToJson(dtdepartment, 0);
                dt.Rows[i]["UserDepartment"]   = AchieveCommon.JsonHelper.ColumnToJson(dtdepartment, 1);
            }
            return(AchieveCommon.JsonHelper.ToJson(dt));
        }