static void AddData(UserDefinedTableController udtController, DataSet ds) { if (ds.Tables[DataSetTableName.Data] != null) { for (var rowNr = 0; rowNr <= ds.Tables[DataSetTableName.Data].Rows.Count - 1; rowNr++) { udtController.UpdateRow(ds, rowNr, isDataToImport: true); } } }
string ImportModule(int moduleId, string fileName, string folder, string delimiter) { var strMessage = ""; var mc = new ModuleController(); var moduleInfo = mc.GetModule(moduleId, TabId, false); if (Path.GetExtension(fileName).ToUpper() == ".CSV" && moduleInfo != null) { var udtController = new UserDefinedTableController(ModuleContext); var file = FileManager.Instance.GetFile(PortalId, Path.Combine(folder, fileName)); using (var stream = FileManager.Instance.GetFileContent(file)) { // Open the stream and read it back. using (var reader = new TextFieldParser(stream)) { reader.TextFieldType = FieldType.Delimited; reader.SetDelimiters(delimiter); DataSet ds = null; DataTable dataTable = null; string colChangedBy = null; string colChangedAt = null; string colCreatedBy = null; string colCreatedAt = null; var obligateDataTypesCount = DataType.SystemDataTypes().Count; try { while (!reader.EndOfData) { var linecsv = reader.ReadFields(); if (dataTable == null) { ds = CreateFields(linecsv, udtController); dataTable = ds.Tables[DataSetTableName.Data]; colChangedBy = udtController.ColumnNameByDataType(ds, DataTypeNames.UDT_DataType_ChangedBy); colChangedAt = udtController.ColumnNameByDataType(ds, DataTypeNames.UDT_DataType_ChangedAt); colCreatedBy = udtController.ColumnNameByDataType(ds, DataTypeNames.UDT_DataType_CreatedBy); colCreatedAt = udtController.ColumnNameByDataType(ds, DataTypeNames.UDT_DataType_CreatedAt); } else { var insertTime = DateTime.Now.ToString("s"); var newRow = dataTable.NewRow(); newRow[DataTableColumn.RowId] = -1; newRow[colChangedBy] = UserInfo.Username; newRow[colCreatedBy] = UserInfo.Username; newRow[colChangedAt] = insertTime; newRow[colCreatedAt] = insertTime; dataTable.Rows.Add(FillRow(linecsv, newRow, obligateDataTypesCount)); } } if (ds != null) { for (var rowNr = 0; rowNr <= dataTable.Rows.Count - 1; rowNr++) { udtController.UpdateRow(ds, rowNr, isDataToImport: true); } mc.UpdateModuleSetting(moduleId, SettingName.ListOrForm, "List"); } } catch (Exception ex) { strMessage = string.Format(Localization.GetString("importError", LocalResourceFile), ex.Message); } } } } return(strMessage); }
string ImportModule(int moduleId, string fileName, string folder, string delimiter) { var strMessage = ""; var mc = new ModuleController(); var moduleInfo = mc.GetModule(moduleId, TabId, false); if (Path.GetExtension(fileName).ToUpper() == ".CSV" && moduleInfo != null) { var udtController = new UserDefinedTableController(ModuleContext ); var file = FileManager.Instance.GetFile(PortalId, Path.Combine(folder, fileName)); using (var stream = FileManager.Instance.GetFileContent(file)) { // Open the stream and read it back. using (var reader = new TextFieldParser(stream)) { reader.TextFieldType = FieldType.Delimited; reader.SetDelimiters(delimiter); DataSet ds = null; DataTable dataTable = null; string colChangedBy = null; string colChangedAt = null; string colCreatedBy = null; string colCreatedAt = null; var obligateDataTypesCount = DataType.SystemDataTypes().Count; try { while (!reader.EndOfData) { var linecsv = reader.ReadFields(); if (dataTable == null) { ds = CreateFields(linecsv, udtController); dataTable = ds.Tables[DataSetTableName.Data]; colChangedBy = udtController.ColumnNameByDataType(ds, DataTypeNames.UDT_DataType_ChangedBy); colChangedAt = udtController.ColumnNameByDataType(ds, DataTypeNames.UDT_DataType_ChangedAt); colCreatedBy = udtController.ColumnNameByDataType(ds, DataTypeNames.UDT_DataType_CreatedBy); colCreatedAt = udtController.ColumnNameByDataType(ds, DataTypeNames.UDT_DataType_CreatedAt); } else { var insertTime = DateTime.Now.ToString("s"); var newRow = dataTable.NewRow(); newRow[DataTableColumn.RowId] = -1; newRow[colChangedBy] = UserInfo.Username; newRow[colCreatedBy] = UserInfo.Username; newRow[colChangedAt] = insertTime; newRow[colCreatedAt] = insertTime; dataTable.Rows.Add(FillRow(linecsv, newRow, obligateDataTypesCount)); } } if (ds != null) { for (var rowNr = 0; rowNr <= dataTable.Rows.Count - 1; rowNr++) { udtController.UpdateRow(ds, rowNr, isDataToImport: true); } mc.UpdateModuleSetting(moduleId, SettingName.ListOrForm, "List"); } } catch (Exception ex) { strMessage = string.Format(Localization.GetString("importError", LocalResourceFile), ex.Message); } } } } return strMessage; }