Example #1
0
        /// <summary>
        /// 获取公司组织机构
        /// </summary>
        /// <returns></returns>
        public ActionResult GetCompany()
        {
            //IBLL.IORG_DepartmentBLL m_BLL = new BLL.ORG_DepartmentBLL();

            using (SysEntities db = new SysEntities())
            {
                var query = db.ORG_Department.Where(o => true);

                string menuID = "9"; //Request["menuID"].ToString();
                string where = "";
                if (menuID != "")
                {
                    #region  权限配置
                    int departmentScope = base.MenuDepartmentScopeAuthority(menuID);
                    if (departmentScope == (int)Common.DepartmentScopeAuthority.无限制)//
                    {
                        /*****组织机构—菜单表“DepartmentAuthority(是否拥有部门业务权限配置功能)”字段为“Y”时才有如下逻辑判断
                         *
                         *不管“DepartmentAuthority”是否为“Y”,都写上以下判断逻辑,程序也没有问题
                         *
                         */
                        string departments = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19";// base.MenuDepartmentAuthority(menuID);
                        //query = from a in query
                        //        where (a.ID > 0 && departments.Split(',').Contains(a.ID))
                        //        select g.Key.BH;
                        string[] departs    = departments.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        int[]    newDeparts = Array.ConvertAll <string, int>(departs, s => int.Parse(s));
                        query = from a in db.ORG_Department
                                select a;
                        query = query.Where(a => newDeparts.Contains(a.ID));
                        //if (!string.IsNullOrEmpty(departments))
                        //{

                        //    where += " and b.ID in (" + departments + ")";

                        //}
                        //else//查询所有部门数据
                        //{

                        //}
                    }
                    else if (departmentScope == (int)Common.DepartmentScopeAuthority.本机构及下属机构)//本机构及下属机构
                    {
                        //    //当前用户直属机构

                        //查询本机构及下属机构所有部门数据
                        var branch = db.ORG_Department.FirstOrDefault(o => o.ID == LoginInfo.BranchID);

                        query = from a in db.ORG_Department
                                where a.XYBZ == "Y" && a.LeftValue >= branch.LeftValue && a.RightValue <= branch.RightValue
                                select a;
                    }
                    else if (departmentScope == (int)Common.DepartmentScopeAuthority.本机构) //本机构
                    {
                        //    //查询本机构所有部门数据

                        query = from a in db.ORG_Department
                                where a.XYBZ == "Y" && a.BranchID == LoginInfo.BranchID
                                select a;
                    }
                    else if (departmentScope == (int)Common.DepartmentScopeAuthority.本部门及其下属部门)//本部门及其下属部门
                    {
                        //当前用户所属部门
                        ORG_Department department = db.ORG_Department.FirstOrDefault(o => o.ID == LoginInfo.DepartmentID);
                        //查询本部门及下属部门所有部门数据
                        query = from a in db.ORG_Department
                                where a.XYBZ == "Y" && a.LeftValue >= department.LeftValue && a.RightValue <= department.RightValue
                                select a;
                    }
                    else if (departmentScope == (int)Common.DepartmentScopeAuthority.本部门) //本部门
                    {
                        //    //查询本部门所有用户数据
                        query = from a in db.ORG_Department.Where(o => o.XYBZ == "Y" && o.BranchID == LoginInfo.DepartmentID)
                                select a;
                    }
                    else if (departmentScope == (int)Common.DepartmentScopeAuthority.本人) //本人
                    {
                        query = null;
                    }
                    #endregion
                }

                //var data = new ActionResult
                //{
                //    rows = query.Select(s => new
                //    {
                //        ID = s.ID,
                //        Name = s.CompanyName,
                //        ParentID = s.ParentID
                //    })
                //};

                string content = Newtonsoft.Json.JsonConvert.SerializeObject(query.ToList());
                content = content.Replace("Checked", "checked");
                return(Content(content));
            }

            //string backColumn = "ID,DepartmentName,ParentID,DepartmentType";
            //DataTable dt = bll.ExecuteTable("ORG_Department b", where, backColumn);
            //ViewBag.Json = Newtonsoft.Json.JsonConvert.SerializeObject(dt);
        }
Example #2
0
        /// <summary>
        /// 待审核企业列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="rows"></param>
        /// <param name="companyName"></param>
        /// <param name="UserID_ZR"></param>
        /// <param name="UserID_XS"></param>
        /// <param name="auditType"></param>
        /// <param name="operateStatus"></param>
        /// <param name="companyCode"></param>
        /// <returns></returns>
        public Common.ClientResult.DataResult GetAuditCompanyListForQuality(int page, int rows, string companyName, int?UserID_ZR, int?UserID_XS, int?auditType, int?operateStatus, string companyCode, int departmentScope, string departments, int branchID, int departmentID, int userID)
        {
            using (db)
            {
                List <CRM_CompanyAuditView> queryList = new List <CRM_CompanyAuditView>();
                var query = repository.GetAuditCompanyListForQuality(db, companyName, UserID_ZR, UserID_XS, auditType, operateStatus, companyCode);

                if (departmentScope == (int)DepartmentScopeAuthority.无限制)//无限制
                {
                    if (!string.IsNullOrEmpty(departments))
                    {
                        var people = from a in db.ORG_User
                                     where departments.Split(',').Contains(a.ORG_Department_ID.ToString())
                                     select a;

                        query = (from a in query join b in people on a.CreateUserID equals b.ID select a).Union(
                            from a in query join c in people on a.UserID_XS equals c.ID select a).Union(
                            from a in query join c in people on a.UserID_ZR equals c.ID select a);
                    }
                }
                else if (departmentScope == (int)DepartmentScopeAuthority.本机构及下属机构)//本机构及下属机构
                {
                    //查询本机构及下属机构所有部门数据
                    var branch = db.ORG_Department.FirstOrDefault(o => o.ID == branchID);

                    query = from a in query
                            join b in db.ORG_Department on a.BranchID equals b.ID
                            where b.XYBZ == "Y" && b.LeftValue >= branch.LeftValue && b.RightValue <= branch.RightValue
                            select a;
                }
                else if (departmentScope == (int)DepartmentScopeAuthority.本机构) //本机构
                {
                    query = from a in query
                            where a.BranchID == branchID
                            select a;
                }
                else if (departmentScope == (int)DepartmentScopeAuthority.本部门及其下属部门)//本部门及其下属部门
                {
                    //当前用户所属部门
                    ORG_Department department = db.ORG_Department.FirstOrDefault(o => o.ID == departmentID);

                    //查询本部门及下属部门所有部门数据
                    var people = from a in db.ORG_User
                                 join b in db.ORG_Department on a.ORG_Department_ID equals b.ID
                                 where a.XYBZ == "Y" && b.XYBZ == "Y" && b.LeftValue >= department.LeftValue && b.RightValue <= department.RightValue
                                 select a;

                    query = (from a in query join b in people on a.CreateUserID equals b.ID select a).Union(
                        from a in query join c in people on a.UserID_XS equals c.ID select a).Union(
                        from a in query join c in people on a.UserID_ZR equals c.ID select a);
                }
                else if (departmentScope == (int)DepartmentScopeAuthority.本部门) //本部门
                {
                    //查询本部门所有用户数据
                    var people = from a in db.ORG_User.Where(o => o.XYBZ == "Y")
                                 join b in db.ORG_Department.Where(o => o.XYBZ == "Y" && o.ID == departmentID) on a.ORG_Department_ID equals b.ID
                                 select a;

                    query = (from a in query join b in people on a.CreateUserID equals b.ID select a).Union(
                        from a in query join c in people on a.UserID_XS equals c.ID select a).Union(
                        from a in query join c in people on a.UserID_ZR equals c.ID select a);
                }
                else if (departmentScope == (int)DepartmentScopeAuthority.本人) //本人
                {
                    query = query.Where(c => c.CreateUserID == userID || c.UserID_XS == userID || c.UserID_ZR == userID);
                }

                if (query.Count() > 0)
                {
                    query = from a in query
                            join b in db.ORG_User on a.UserID_ZR equals b.ID into tmpzr
                            from zr in tmpzr.DefaultIfEmpty()
                            join c in db.ORG_User on a.UserID_XS equals c.ID into tmpxs
                            from xs in tmpxs.DefaultIfEmpty()
                            orderby a.CreateTime descending
                            select new CRM_CompanyAuditView
                    {
                        AuditType      = a.AuditType,
                        AuditTypeName  = a.AuditTypeName,
                        ID             = a.ID,
                        MainTableID    = a.MainTableID,
                        CityID         = a.CityID,
                        CompanyID      = a.CompanyID,
                        CompanyCode    = a.CompanyCode,
                        CompanyName    = a.CompanyName,
                        UserID_ZR      = a.UserID_ZR,
                        UserID_XS      = a.UserID_XS,
                        CreateUserID   = a.CreateUserID,
                        CreateUserName = a.CreateUserName,
                        CreateTime     = a.CreateTime,
                        OperateStatus  = a.OperateStatus,
                        BranchID       = a.BranchID,
                        UserID_XS_Name = xs.RName ?? "",
                        UserID_ZR_Name = zr.RName ?? ""
                    };


                    if (page <= 1)
                    {
                        queryList = query.Take(rows).ToList();
                    }
                    else
                    {
                        queryList = query.Skip((page - 1) * rows).Take(rows).ToList();
                    }
                }

                var data = new Common.ClientResult.DataResult
                {
                    total = query.Count(),
                    rows  = queryList
                };

                return(data);
            }
        }