/// <summary> /// 列属性 /// </summary> /// <param name="columnList"></param> /// <param name="defaultColumnList"></param> /// <returns></returns> private List <ColumnProperty> GetColumnProperty(IEnumerable <FapColumn> columnList) { List <ColumnProperty> columnProperty = new List <ColumnProperty>(); int index = 0; foreach (var column in columnList) { string sheetName = "C_" + column.Id; if (column.CtrlType == FapColumn.CTRL_TYPE_REFERENCE) { sheetName = "R_" + column.Id; } if ((column.CtrlType == FapColumn.CTRL_TYPE_COMBOBOX || column.CtrlType == FapColumn.CTRL_TYPE_REFERENCE) && this.DictionaryToExport.ContainsKey(sheetName)) { DictionarySheetData dictionarySheetData = this.DictionaryToExport[sheetName]; ColumnProperty cp = new ColumnProperty(); cp.ColumnHeader = column.ColComment; cp.ColumnIndex = index; cp.ConstraintName = sheetName; // Get30String("C_" + refTable); cp.ConstraintReference = dictionarySheetData.DictionaryExcelRangeAddress; //!$A1:$A3 columnProperty.Add(cp); } index++; } return(columnProperty); }
/// <summary> /// 获取编码类型的字典数据 /// </summary> /// <param name="column"></param> /// <param name="dictionaryToExport"></param> /// <returns></returns> protected void GetCodeDictionaryData(FapColumn column, Dictionary <string, DictionarySheetData> dictionaryToExport) { //string code = Get30String("C_" + refTable); string code = "C_" + column.Id; if (!dictionaryToExport.ContainsKey(code)) { IEnumerable <FapDict> dicData = _dataAccessor.Dictionarys(column.ComboxSource); if (dicData != null && dicData.Count() > 0) { DictionarySheetData dictionarySheetData = new DictionarySheetData(); dictionarySheetData.SheetName = code; dictionarySheetData.Data = new List <DictionaryRowData>(); foreach (var item in dicData) { DictionaryRowData dictionaryRowData = new DictionaryRowData(); dictionaryRowData.KeyData = new CellData() { Data = item.Code, Type = CellDataType.STRING }; dictionaryRowData.ValueData = new CellData() { Data = item.Name, Type = CellDataType.STRING }; dictionarySheetData.Data.Add(dictionaryRowData); } dictionaryToExport.Add(code, dictionarySheetData); } } }
/// <summary> /// 将字典表数据导入到Excel页中 /// </summary> /// <param name="workbook"></param> /// <param name="sheetName"></param> /// <param name="dictionaryData"></param> private void ExportDictionarySheet(IWorkbook workbook, string sheetName, DictionarySheetData dictionaryData) { if (workbook == null) { return; } if (string.IsNullOrWhiteSpace(sheetName)) { sheetName = UUIDUtils.Fid; } ISheet sheet = workbook.CreateSheet(sheetName); int rowCount = 0; if (dictionaryData == null || dictionaryData.Data == null || dictionaryData.Data.Count == 0) { return; } foreach (var row in dictionaryData.Data) { this.WriteDictionaryRowData(workbook, sheet, row, ref rowCount); totalToFinish++; if (OnProcessDictionary != null) { OnProcessDictionary(sheet.SheetName, row, totalToFinish); } } }
/// <summary> /// 列属性 /// </summary> /// <param name="columnList"></param> /// <param name="defaultColumnList"></param> /// <returns></returns> private List <ColumnProperty> GetColumnProperty(List <FapColumn> columnList) { List <ColumnProperty> columnProperty = new List <ColumnProperty>(); int index = 0; foreach (var column in columnList) { string sheetName = "C_" + column.Id; if (column.CtrlType == FapColumn.CTRL_TYPE_REFERENCE) { sheetName = "R_" + column.Id; } if (!ExcelUtils.DefaultFieldNameList.Contains(column.ColName)) { if (column.CtrlType == FapColumn.CTRL_TYPE_COMBOBOX && this.DictionaryToExport.ContainsKey(sheetName)) { string refTable = column.RefTable; //string sheetName = Get30String("C_" + refTable); DictionarySheetData dictionarySheetData = this.DictionaryToExport[sheetName]; ColumnProperty cp = new ColumnProperty(); cp.ColumnHeader = column.ColComment; cp.ColumnIndex = index; cp.ConstraintName = sheetName; // Get30String("C_" + refTable); cp.ConstraintReference = dictionarySheetData.DictionaryExcelRangeAddress; //!$A1:$A3 columnProperty.Add(cp); } else if (column.CtrlType == FapColumn.CTRL_TYPE_REFERENCE && this.DictionaryToExport.ContainsKey(sheetName)) { string refTable = column.RefTable; string refID = column.RefID; string refName = column.RefName; //string sheetName = Get30String("R_" + refTable + refID + refName); DictionarySheetData dictionarySheetData = this.DictionaryToExport[sheetName]; ColumnProperty cp = new ColumnProperty(); cp.ColumnHeader = column.ColComment; cp.ColumnIndex = index; cp.ConstraintName = sheetName; // Get30String("R_" + refTable + refID + refName); cp.ConstraintReference = dictionarySheetData.DictionaryExcelRangeAddress; //!$A1:$A3 columnProperty.Add(cp); } index++; } } return(columnProperty); }
/// <summary> /// 获取引用类型的字典数据 /// </summary> /// <param name="column"></param> /// <param name="dictionaryToExport"></param> /// <returns></returns> protected void GetReferenceDictionaryData(FapColumn column, Dictionary <string, DictionarySheetData> dictionaryToExport) { string refTable = column.RefTable; string refID = column.RefID; string refCode = column.RefCode; string refName = column.RefName; string refCondition = column.RefCondition; if (refCondition.IsPresent()) { //去掉权限 refCondition = refCondition.Replace(FapDbConstants.EmployeeNoPower, ""); } if (!(refCondition.IsPresent() && refCondition.IndexOf("$") < 0)) { //去掉参数条件 refCondition = ""; } string code = "R_" + column.Id; //Get30String("R_" + refTable + refID + refName); if (!dictionaryToExport.ContainsKey(code)) { if (refCode.IsMissing()) { refCode = "Id"; } string refWhere = refCondition.IsMissing() ? "" : " where " + refCondition; string sql = string.Format("SELECT {0} AS FID, {1} AS CODE,{2} AS NAME FROM {3} {4}", refID, refCode, refName, refTable, refWhere); IEnumerable <FapDict> dicData = _dataAccessor.Query <FapDict>(sql); if (!RefTableCache.ContainsKey(refTable)) { RefTableCache.Add(refTable, dicData); } if (dicData != null && dicData.Count() > 0) { DictionarySheetData dictionarySheetData = new DictionarySheetData(); dictionarySheetData.SheetName = code; dictionarySheetData.Data = new List <DictionaryRowData>(); var groupDict = dicData.GroupBy(d => d.Name); foreach (var dict in groupDict) { if (dict.Count() > 1) { var dicts = dict.ToList(); foreach (var item in dicts) { DictionaryRowData dictionaryRowData = new DictionaryRowData(); dictionaryRowData.KeyData = new CellData() { Data = item.Fid, Type = CellDataType.STRING }; dictionaryRowData.ValueData = new CellData() { Data = item.Name + "(" + item.Code + ")", Type = CellDataType.STRING }; dictionarySheetData.Data.Add(dictionaryRowData); } } else { var item = dict.First(); DictionaryRowData dictionaryRowData = new DictionaryRowData(); dictionaryRowData.KeyData = new CellData() { Data = item.Fid, Type = CellDataType.STRING }; dictionaryRowData.ValueData = new CellData() { Data = item.Name, Type = CellDataType.STRING }; dictionarySheetData.Data.Add(dictionaryRowData); } } dictionaryToExport.Add(code, dictionarySheetData); } } }