public override OutputData DoAction(IInputData input) { string source = input.QueryString["Source"]; string path = Path.Combine(BaseAppSetting.Current.XmlPath, @"Import", source + ".xml"); ImportConfigXml config = new ImportConfigXml(); config.ReadXmlFromFile(path); string filePath = @"C:\Users\zll\Downloads\角色.xls"; var meta = config.Import.MetaData.CreateObject(input); Tk5ListMetaData data = meta as Tk5ListMetaData; var resolver = config.Import.Resolver.CreateObject(this); MetaDataTableResolver metaResolver = resolver as MetaDataTableResolver; TkDebug.AssertNotNull(metaResolver, "metaResolver", this); ImportError errResult = new ImportError(); var dataSet = ExcelImporter.ExcelImport(filePath, data, errResult); FieldErrorInfoCollection importResult = metaResolver.Import(dataSet, input); if (importResult.Count > 0) { var positions = (from item in importResult orderby item.Position descending select item.Position).Distinct(); foreach (var errorInfo in importResult) { DataRow errorRow = dataSet.Tables[errorInfo.TableName].Rows[errorInfo.Position]; ImportWarningItem errorItem = new ImportWarningItem(errorRow["OriginalRowNum"].Value <int>(), resolver.GetFieldInfo(errorInfo.NickName).DisplayName, (string)errorRow[errorInfo.NickName], errorInfo.Message); errResult.Add(errorItem); } foreach (var index in positions) { resolver.HostTable.Rows.RemoveAt(index); } } DataSet webReport = null; if (errResult.Count > 0) { byte[] dataFile = ExcelUtil.ExcelReport(filePath, data, errResult); webReport = ExcelUtil.DataSetReport(filePath, data, errResult); } return(OutputData.CreateObject(new ImportResultData(DataSet, webReport, errResult))); }
public override OutputData DoAction(IInputData input) { string source = input.QueryString["Source"]; string path = Path.Combine(BaseAppSetting.Current.XmlPath, @"Import", source + ".xml"); ImportConfigXml config = new ImportConfigXml(); config.ReadXmlFromFile(path); string filePath = @"C:\Users\zll\Downloads\角色.xls"; var meta = config.Import.MetaData.CreateObject(input); Tk5ListMetaData data = meta as Tk5ListMetaData; var resolver = config.Import.Resolver.CreateObject(this); MetaDataTableResolver metaResolver = resolver as MetaDataTableResolver; TkDebug.AssertNotNull(metaResolver, "metaResolver", this); ImportError errResult = new ImportError(); var dataSet = ExcelImporter.ExcelImport(filePath, data, errResult); FieldErrorInfoCollection importResult = metaResolver.Import(dataSet, input); if (importResult.Count > 0) { var positions = (from item in importResult orderby item.Position descending select item.Position).Distinct(); foreach (var errorInfo in importResult) { DataRow errorRow = dataSet.Tables[errorInfo.TableName].Rows[errorInfo.Position]; ImportWarningItem errorItem = new ImportWarningItem(errorRow["OriginalRowNum"].Value<int>(), resolver.GetFieldInfo(errorInfo.NickName).DisplayName, (string)errorRow[errorInfo.NickName], errorInfo.Message); errResult.Add(errorItem); } foreach (var index in positions) { resolver.HostTable.Rows.RemoveAt(index); } } DataSet webReport = null; if (errResult.Count > 0) { byte[] dataFile = ExcelUtil.ExcelReport(filePath, data, errResult); webReport = ExcelUtil.DataSetReport(filePath, data, errResult); } return OutputData.CreateObject(new ImportResultData(DataSet, webReport, errResult)); }
// 设置DataTable的值 private static void ReadColumn(DataRow dataRow, string columnName, Tk5FieldInfoEx fieldInfo, string strValue, int indexOfRow, ImportResultData result) { ImportWarningItem imResult = null; string asgValue = null; if (fieldInfo != null) { bool valueError = false; if (fieldInfo.Decoder != null && fieldInfo.Decoder.Type == DecoderType.CodeTable) { IEnumerable <IDecoderItem> data = ExcelUtil.GetDecoderItem(fieldInfo, null); if (string.IsNullOrEmpty(strValue)) { valueError = true; } else { foreach (IDecoderItem item in data) { if (item.Name == strValue) { asgValue = item.Value; valueError = true; break; } } } } else { if (fieldInfo.InternalControl != null && fieldInfo.InternalControl.SrcControl == ControlType.CheckBox) { if (strValue == "√") { asgValue = ((fieldInfo.Extension == null) ? "1" : fieldInfo.Extension.CheckValue); valueError = true; } if (strValue == "X" || string.IsNullOrEmpty(strValue)) { asgValue = ((fieldInfo.Extension == null) ? "0" : fieldInfo.Extension.UnCheckValue); valueError = true; } } else { asgValue = strValue; valueError = true; } } try { if (!valueError) { throw new Exception("value in the cell is invalid"); } else { dataRow[fieldInfo.NickName] = asgValue; } } catch (Exception ex) { imResult = new ImportWarningItem(indexOfRow, columnName, asgValue, ex.Message); } } //return imResult; }
// 设置DataTable的值 private static ImportWarningItem TablePadding(DataRow dataRow, string columnName, Dictionary<string, Tk5FieldInfoEx> dicOfInfo, string strValue, int indexOfRow) { ImportWarningItem imResult = null; Tk5FieldInfoEx fieldInfo = dicOfInfo[columnName]; string asgValue = null; if (fieldInfo != null) { bool valueError = false; if (fieldInfo.Decoder != null && fieldInfo.Decoder.Type == DecoderType.CodeTable) { IEnumerable<IDecoderItem> data = ExcelUtil.GetDecoderItem(fieldInfo); if (string.IsNullOrEmpty(strValue)) { valueError = true; } else { foreach (IDecoderItem item in data) { if (item.Name == strValue) { asgValue = item.Value; valueError = true; break; } } } } else { if (fieldInfo.InternalControl != null && fieldInfo.InternalControl.SrcControl == ControlType.CheckBox) { if (strValue == "√") { asgValue = ((fieldInfo.Extension == null) ? "1" : fieldInfo.Extension.CheckValue); valueError = true; } if (string.IsNullOrEmpty(strValue)) { asgValue = ((fieldInfo.Extension == null) ? "0" : fieldInfo.Extension.UnCheckValue); valueError = true; } } else { asgValue = strValue; valueError = true; } } try { if (!valueError) { throw new Exception("value in the cell is invalid"); } else dataRow[fieldInfo.NickName] = asgValue; } catch (Exception ex) { imResult = new ImportWarningItem(indexOfRow, columnName, asgValue, ex.Message); } } return imResult; }