public ActionResult GetData(int page, int rows, string search, string sidx, string sord)
        {
            string Name       = Request["name"] == null ? "" : Request["name"].ToString();
            string filters    = Request["filters"] == null ? "" : Request["filters"].ToString();
            string filter     = Request["filter"] == null ? "" : Request["filter"].ToString();
            string ModuleName = Request["m"] == null ? "" : Request["m"].ToString();
            string NameSpace  = Request["n"] == null ? "" : Request["n"].ToString();


            string filtersSql   = string.Empty;
            string mapSqlFilter = string.Empty;

            if (!string.IsNullOrEmpty(filters))
            {
                filtersSql = BulidJqGridSearch.BuildSearch(filters);
            }
            Bll_Sys_Config_Refer       configRefer     = new Bll_Sys_Config_Refer();
            Bll_Sys_Config_Field_Refer configReferList = new Bll_Sys_Config_Field_Refer();
            Sys_Config_Refer           model           = configRefer.GetListByCode(" AND  R_ModuleName='"
                                                                                   + ModuleName + "'")[0];
            var          referList    = configReferList.GetListByCode(" AND  D_ModuleName='" + ModuleName + "'").Where(o => !string.IsNullOrEmpty(o.D_DictKey));
            Bll_Bse_Dict DictInstance = new Bll_Bse_Dict();


            DataTable dt = new DataTable();

            if (!string.IsNullOrEmpty(model.R_SQL))
            {
                if (!string.IsNullOrEmpty(filter))
                {
                    model.R_SQL = model.R_SQL + filter;
                }
                if (!string.IsNullOrEmpty(filtersSql))
                {
                    model.R_SQL = model.R_SQL + " AND " + filtersSql;
                }
                dt = configRefer.ListBySql(model.R_SQL);
            }
            else
            {
                string _filtersql = !String.IsNullOrEmpty(model.R_FilterSql) ? model.R_FilterSql : "";
                _filtersql = _filtersql + filter;

                //#region  特殊映射处理
                //if (ModuleName=="HR_StuffModule")
                //{
                //    //读取映射配置表中公司配置
                //    Bll_Comm comm = new Bll_Comm();
                //    string mapFilter = "";
                //    var mapModel = comm.CommMap(ModuleName, "Company");
                //    if (mapModel!=null)
                //    {
                //        var deptList = comm.GetChildListDeptNon(comm.CommMap(ModuleName, "Company").Map_Object);
                //        if (deptList.Count()>0)
                //        {
                //            foreach (var item in deptList)
                //            {

                //            }
                //            for (int i = 0; i < deptList.Count;i++ )
                //            {
                //                if (i==(deptList.Count-1))
                //                {
                //                    mapFilter += "'" + deptList[i].Dept_Code+"'";
                //                }
                //                else
                //                {
                //                    mapFilter += "'" + deptList[i].Dept_Code+ "',";
                //                }
                //            }
                //            mapFilter.TrimEnd(',');
                //        }
                //        mapSqlFilter = " Stuff_DepCode in(" + mapFilter + ")";
                //    }
                //}
                //#endregion

                //为空时不初始化
                //if (!string.IsNullOrEmpty(filter))
                //{
                //    dt = configRefer.ListDataByCode(Name, _filtersql, filtersSql + mapSqlFilter);
                //}
                dt = configRefer.ListDataByCode(Name, _filtersql, filtersSql + mapSqlFilter);
            }

            DataTable newdt = DataTablePage.GetPagedTable(dt, page, rows);

            #region 字典进行转换
            //对字典进行转换

            for (int i = 0; i < newdt.Rows.Count; i++)
            {
                foreach (var item in referList.ToList())
                {
                    var value      = newdt.Rows[i][item.D_Index] != null ? newdt.Rows[i][item.D_Index].ToString() : "";
                    var DictResult = DictInstance.GetListByCode(" AND Dict_Code='" + value
                                                                + "' AND Dict_Key='" + item.D_DictKey + "' ");
                    if (DictResult.Count > 0)
                    {
                        newdt.Rows[i][item.D_Index] = DictResult.FirstOrDefault().Dict_Name;
                    }
                }
            }

            #endregion

            var json = DataTablePage.JsonForJqgrid(newdt, page, rows, dt.Rows.Count);
            return(JavaScript(json));
        }
Example #2
0
        public DataTable GetPagedTable(DataTable dt, int PageIndex, int PageSize, string moduleCode)
        {
            if (PageIndex == 0)
            {
                return(null);
            }
            DataTable newdt = dt.Clone();

            #region 获取字典相关信息
            //获取列表字段的配置信息
            Bll_Sys_Config_Fieled    filedInstance = new Bll_Sys_Config_Fieled();
            Bll_Bse_Dict             DictInstance  = new Bll_Bse_Dict();
            List <Sys_Config_Fieled> listField     = filedInstance.GetListByCode(" AND D_ModuleCode='" + moduleCode + "'");
            string dictKeyList = "''";
            foreach (var field in listField)
            {
                if (!string.IsNullOrEmpty(field.D_DictKey))
                {
                    dictKeyList += ",'" + field.D_DictKey + "'";
                }
            }
            //获取配置信息中所有的字典表关键字里拥有的字典信息
            List <Bse_Dict> listDictionary = DictInstance.GetListByCode("  and (dict_key in (" + dictKeyList + "))");

            #endregion

            //newdt.Clear();
            int rowbegin = (PageIndex - 1) * PageSize;
            int rowend   = PageIndex * PageSize;

            if (rowbegin >= dt.Rows.Count)//如果开始列数大于所拥有的列数
            {
                rowbegin = 0;
            }

            if (rowend > dt.Rows.Count)
            {
                rowend = dt.Rows.Count;
            }
            for (int i = rowbegin; i <= rowend - 1; i++)
            {
                DataRow newdr = newdt.NewRow();
                DataRow dr    = dt.Rows[i];
                foreach (DataColumn column in dt.Columns)
                {
                    newdr[column.ColumnName] = dr[column.ColumnName];
                    //更新字典信息
                    var field = listField.Where(o => o.D_Index == column.ColumnName).FirstOrDefault();
                    if (field != null && !string.IsNullOrEmpty(field.D_DictKey))
                    {
                        Bse_Dict dict = listDictionary.Where(o => o.Dict_Code == dr[column.ColumnName].ToString()).FirstOrDefault();
                        if (dict != null)
                        {
                            newdr[column.ColumnName] = dict.Dict_Name;
                        }
                    }

                    //对编码进行转换
                    //if (field!=null && !string.IsNullOrEmpty(field.D_UDEF1))
                    //{
                    //    string[] Converts = field.D_UDEF1.Split(',');
                    //    if (Converts.Count()==3)
                    //    {
                    //        if (dr[column.ColumnName]!=null && !string.IsNullOrEmpty(dr[column.ColumnName].ToString()))
                    //        {
                    //            var data = instance.ListDataByCode(Converts[0], Converts[1] + "='" + dr[column.ColumnName].ToString() + "'");
                    //            if (data.Rows.Count>0)
                    //            {
                    //                newdr[column.ColumnName] = data.Rows[0][Converts[2]].ToString();
                    //            }
                    //        }
                    //    }
                    //}
                }
                newdt.Rows.Add(newdr);
            }
            return(newdt);
        }
Example #3
0
        public ActionResult List(string id, int page, int rows, string search, string sidx, string sord)
        {
            string filters    = Request["filters"] == null ? "" : Request["filters"].ToString();
            string filtersSql = "";

            if (!string.IsNullOrEmpty(filters))
            {
                filtersSql = BulidJqGridSearch.BuildSearch(filters);
            }

            //string
            List <Bse_Employee> list = new List <Bse_Employee>();

            if (string.IsNullOrEmpty(id))
            {
                if (!string.IsNullOrEmpty(filtersSql))
                {
                    list = hrInstance.GetListByCode(" AND " + filtersSql);
                }
                else
                {
                    list = hrInstance.GetAll();
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(filtersSql))
                {
                    list = hrInstance.GetStuffByDept(id, " AND " + filtersSql);
                }
                else
                {
                    list = hrInstance.GetStuffByDept(id);
                }
            }

            Bll_Bse_Dict dictInstance = new Bll_Bse_Dict();

            //字典替换
            foreach (var listmodel in list)
            {
                switch (listmodel.Emp_Gendar)
                {
                case "G001": { listmodel.Emp_Gendar = "男"; break; }

                case "G002": { listmodel.Emp_Gendar = "女"; break; }
                }

                if (!string.IsNullOrEmpty(listmodel.Emp_Title))
                {
                    var _model = dictInstance.GetModel(" and dict_key='STUFFTITLE' and dict_code='" + listmodel.Emp_Title + "'");
                    listmodel.Emp_Title = _model != null ? _model.Dict_Name : "";
                }

                if (!string.IsNullOrEmpty(listmodel.Emp_Duty))
                {
                    var _model = dictInstance.GetModel(" and dict_key='STUFFDUTYTYPE' and dict_code='" + listmodel.Emp_Duty + "'");
                    listmodel.Emp_Duty = _model != null ? _model.Dict_Name : "";
                }
            }
            var model  = list.AsQueryable <Bse_Employee>();
            var result = JsonConvert.SerializeObject(model.ToJqGridData(page, rows, null, search, null), new JsonDateConverter("yyyy-MM-dd"));


            return(JavaScript(result));
        }