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.Bll_Sys_Config_Refer configRefer = new QX.BLL.Bll_Sys_Config_Refer(); BLL.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.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); }
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; }
// private Bll_HR_Department deptInstance = new Bll_HR_Department(); /// <summary> /// 同步公司物料类别 /// </summary> /// <param name="itype"></param> /// <param name="companycode"></param> /// <param name="deptCode"></param> /// <returns></returns> public bool SyncMaterialTypeFromDict(string itype, string companyCode) { bool result = false; List <WH_MaterialType> list = new List <WH_MaterialType>(); List <Bse_Dict> dictList = new List <Bse_Dict>(); List <string> Union = new List <string>(); List <string> InterSect = new List <string>(); if (!string.IsNullOrEmpty(companyCode) && !string.IsNullOrEmpty(itype)) { try { //dictList = dictInstance.GetListByCode(" AND Dict_Key!=Dict_Code AND Dict_PCode='" + itype + "'"); // Modify BY QB // Modify:同步字典中所有子类别 // Modify Date:2011-3-22 dictList = dictInstance.GetListByCode(" AND Dict_Key!=Dict_Code AND Dict_Key='" + itype + "'"); list = instance.GetListByCode(" AND MT_CompanyCode='" + companyCode + "' "); IEnumerable <string> listStrList = list.Select(o => o.MT_TCode); IEnumerable <string> dictStrList = dictList.Select(o => o.Dict_Code); //取Dict与MaterialType中的并集,并比对Maertitype中是否存在,不存在则插入数据, Union = dictStrList.Union(listStrList).ToList <string>(); //取交集 InterSect = dictStrList.Intersect(listStrList).ToList <string>(); //逻辑删除关系类别 foreach (var listItem in listStrList) { if (!InterSect.Contains(listItem)) { var typeModel = list.Where(o => o.MT_TCode == listItem); if (typeModel.Count() > 0) { typeModel.First().Stat = 1; instance.Update(typeModel.First()); } } } //更新和插入Type foreach (var item in Union) { var typeModel = list.Where(o => o.MT_TCode == item); var dictModel = dictList.Where(o => o.Dict_Code == item); if (typeModel.Count() > 0) { //更新 if (dictModel.First().Dict_Name != typeModel.First().MT_TName) { typeModel.First().MT_TName = dictModel.First().Dict_Name; typeModel.First().MT_TPCode = dictModel.First().Dict_PCode; typeModel.First().MT_Order = dictModel.First().Dict_Order; instance.Update(typeModel.First()); } } else { //插入 WH_MaterialType model = new WH_MaterialType(); model.MT_Code = Bll_Comm.GetTableKey("WH_MaterialType"); model.MT_TCode = dictModel.First().Dict_Code; if (!string.IsNullOrEmpty(dictModel.First().Dict_PCode) && dictModel.First().Dict_PCode != itype) { model.MT_TPCode = dictModel.First().Dict_PCode; } model.MT_TName = dictModel.First().Dict_Name; model.MT_Order = dictModel.First().Dict_Order; model.MT_CompanyCode = companyCode; var deptModel = deptInstance.GetModel(" AND Dept_Code='" + companyCode + "' "); model.MT_Company = deptModel != null ? deptModel.Dept_Name : ""; instance.Insert(model); } } result = true; } catch (System.Exception e) { throw; } } return(result); }