コード例 #1
0
        private void DoSelect()
        {
            // 角色 根据公司,部门找到配置的HR,然后具有查看权限
            string where = string.Empty, Company = string.Empty;
            string sql = @"select B.WorkNo,A.*,A.CorpName+'/'+A.DeptName As Org from FL_Culture..EmpVoiceAskQuestion As A
                        left join FL_PortalHR..SysUser As B
                        on A.CreateId=B.UserID
                        where 1=1 and Category<>''  ";

            sql = sql.Replace("FL_PortalHR", Global.AimPortalDB);

            //公司权限
            CommPowerSplit ps = new CommPowerSplit();

            if (!ps.IsEmpVoiceRole(UserInfo.UserID, UserInfo.LoginName))
            {
                //获取人员部门
                var    UsrEnt = SysUser.Find(UserInfo.UserID);
                string SQL    = @"with GetTree
                                as
                                (
	                                select * from HR_OA_MiddleDB..fld_bmml where pk_deptdoc='{0}'
	                                union all
	                                select A.*
	                                from HR_OA_MiddleDB..fld_bmml As A 
	                                join GetTree as B 
	                                on  A.pk_deptdoc=B.pk_fathedept
                                )
	                           select deptname+',' as [text()] from getTree FOR XML PATH('') "    ;
                SQL = SQL.Replace("HR_OA_MiddleDB", Global.HR_OA_MiddleDB);
                SQL = string.Format(SQL, UsrEnt.Pk_deptdoc);
                string DeptPathStr = DataHelper.QueryValue(SQL).ToString();
                DeptPathStr = string.IsNullOrEmpty(DeptPathStr) ? "" : DeptPathStr;


                //找到配置的HR专员(HRUsrId)
                SQL = @"select top 1 *,
                                case when patindex('%'+DeptName+'%','{1}')=0  then 100
                                     else  patindex('%'+DeptName+'%','{1}') 
                                end  As SortIndex 
                                from FL_Culture..SysApproveConfig As A
                                where A.CompanyId='{0}' and HRUsrId is not null
                                and ( HRUsrId='{2}' or HRManagerId='{2}'  ) order by SortIndex";

                // 判断公司登陆
                UserContextInfo UC = new UserContextInfo();
                Company = UC.GetUserCurrentCorpId(UserInfo.UserID);

                SQL = string.Format(SQL, Company, DeptPathStr, UserInfo.UserID);

                DataTable dt = DataHelper.QueryDataTable(SQL);
                if (dt.Rows.Count > 0)
                {
                    where += "  and  CorpId= '" + Company + "' ";
                }
                else
                {
                    where += "  and  1<>1 ";
                }
            }
            //分类
            if (!string.IsNullOrEmpty(nodeName) && (nodeName != "所有分类") && nodeName != "null")
            {
                sql += " and Category='" + nodeName + "' ";
            }
            sql += where;

            string qry = "";

            foreach (CommonSearchCriterionItem item in SearchCriterion.Searches.Searches)
            {
                if (!String.IsNullOrEmpty(item.Value.ToString()))
                {
                    switch (item.PropertyName)
                    {
                    case "StartTime":
                        qry += " and CreateTime>='" + item.Value + "' ";
                        break;

                    case "EndTime":
                        qry += " and CreateTime<='" + (item.Value.ToString()).Replace(" 0:00:00", " 23:59:59") + "' ";
                        break;

                    default:
                        qry += " and " + item.PropertyName + " like '%" + item.Value + "%' ";
                        break;
                    }
                }
            }
            sql += qry;
            SearchCriterion.SetOrder(EmpVoiceAskQuestion.Prop_CreateTime);
            OrderCriterionItem oci1 = new OrderCriterionItem(EmpVoiceAskQuestion.Prop_CreateTime);

            SearchCriterion.Orders.Add(oci1);
            this.PageState.Add("DataList", GetPageData(sql, SearchCriterion));
        }