Skip to content

Commit 7f6844e

Browse files
committed
Fixed some bugs
1 parent 5e8b7e4 commit 7f6844e

File tree

6 files changed

+99
-298
lines changed

6 files changed

+99
-298
lines changed

SchemaMapperDLL/Classes/Converters/BaseImport.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ public abstract class BaseImport
88

99
#region declaration
1010
public string FilePath { get; set; }
11-
public bool RemoveEmptyColumns { get; set; }
1211
public DataSet Maindataset { get; set; }
1312
public bool HasHeader { get; set; }
1413
public int RowsToSkip { get; set; }

SchemaMapperDLL/Classes/Converters/MsAccessImport.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public override DataSet FillAllTables(string Tablename)
5252
{
5353
daGetDataFromSheet.Fill(dtTable);
5454
}
55-
55+
dtTable.PrimaryKey = null;
5656
Maindataset.Tables.Add(dtTable);
5757
}
5858
}
@@ -105,7 +105,7 @@ public DataTable GetTableByName(string Tablename)
105105

106106
daGetDataFromSheet.Fill(dtTable);
107107
}
108-
108+
dtTable.PrimaryKey = null;
109109
return dtTable;
110110
}
111111
}
@@ -153,11 +153,13 @@ public DataTable GetTableByNamewithPaging(string Tablename, int v_PagingStartRec
153153
{
154154
if (dCol.DataType != typeof(System.String))
155155
dCol.DataType = typeof(System.String);
156+
156157
}
157158

158159
r_result = daGetDataFromSheet.Fill(v_PagingStartRecord, v_PagingInterval, dtTable);
159160
}
160161

162+
dtTable.PrimaryKey = null;
161163
return dtTable;
162164
}
163165
}
@@ -194,9 +196,11 @@ public override void BuildConnectionString()
194196

195197
public void Dispose()
196198
{
199+
if (SchemaTable != null)
200+
SchemaTable.Dispose();
197201

198-
SchemaTable.Dispose();
199-
Maindataset.Dispose();
202+
if (Maindataset != null)
203+
Maindataset.Dispose();
200204

201205
}
202206

SchemaMapperDLL/Classes/Converters/MsExcelImport.cs

Lines changed: 1 addition & 260 deletions
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,11 @@ public override void BuildConnectionString()
538538

539539
public MsExcelImport() : base() { }
540540

541-
public MsExcelImport(string v_strFilePath, string v_RangeSpecifications,
542-
bool v_RemoveEmptyColumns = false) : base()
541+
public MsExcelImport(string v_strFilePath, string v_RangeSpecifications = "") : base()
543542
{
544543

545544
m_SheetsSpecifications.AddRange(v_RangeSpecifications.Split('|'));
546545
FilePath = v_strFilePath;
547-
RemoveEmptyColumns = v_RemoveEmptyColumns;
548546
}
549547

550548

@@ -617,263 +615,6 @@ public List<string> GetSheets()
617615
#endregion
618616

619617

620-
//public void ImportExcelTablesToTemplateDatatables(string v_ExportPath)
621-
//{
622-
// string strSheetname = string.Empty;
623-
// BuildConnectionString();
624-
// bool TableNameFilterAccepted = false;
625-
626-
// try
627-
// {
628-
// using (OleDbConnection OleDBCon = new OleDbConnection(ConnectionString))
629-
// {
630-
// if (OleDBCon.State != ConnectionState.Open)
631-
// OleDBCon.Open();
632-
633-
// SchemaTable = OleDBCon.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
634-
635-
// foreach (DataRow schRow in SchemaTable.Rows)
636-
// {
637-
// strSheetname = schRow["TABLE_NAME"].ToString().Trim('\'');
638-
639-
// if (!strSheetname.EndsWith("_") && strSheetname.EndsWith("$"))
640-
// {
641-
642-
// // Filter
643-
// if (!string.IsNullOrEmpty(TableNameFilter))
644-
// {
645-
// if (TableNameFilter.StartsWith("%") && TableNameFilter.EndsWith("%"))
646-
// {
647-
// if (!strSheetname.TrimEnd('$').Contains(TableNameFilter.Trim('%')))
648-
// continue;
649-
// }
650-
// else if (TableNameFilter.StartsWith("%"))
651-
// {
652-
// if (!strSheetname.TrimEnd('$').StartsWith(TableNameFilter.Trim('%')))
653-
// continue;
654-
// }
655-
// else if (TableNameFilter.EndsWith("%"))
656-
// {
657-
// if (!strSheetname.TrimEnd('$').EndsWith(TableNameFilter.Trim('%')))
658-
// continue;
659-
// }
660-
// else if (!strSheetname.TrimEnd('$').Equals(TableNameFilter))
661-
// continue;
662-
// }
663-
664-
// try
665-
// {
666-
// TableNameFilterAccepted = true;
667-
668-
// string strcommand = string.Empty;
669-
670-
// if (m_SheetsSpecifications.Where(x => x.StartsWith(strSheetname)).Count() > 0)
671-
// strcommand = "SELECT * , \"" + strSheetname + "\" AS [Sys_Sheetname] FROM [" + m_SheetsSpecifications.Where(x => x.StartsWith(strSheetname)).FirstOrDefault() + "]";
672-
// else
673-
// strcommand = "SELECT * , \"" + strSheetname + "\" AS [Sys_Sheetname] FROM [" + strSheetname + "]";
674-
675-
// using (OleDbCommand cmd = new OleDbCommand(strcommand, OleDBCon))
676-
// {
677-
// DataTable dtTable = new DataTable(RemoveUnusedChars(strSheetname));
678-
679-
680-
// cmd.CommandType = CommandType.Text;
681-
682-
// using (OleDbDataAdapter daGetDataFromSheet = new OleDbDataAdapter(cmd))
683-
// {
684-
// try
685-
// {
686-
// daGetDataFromSheet.FillSchema(dtTable, SchemaType.Source);
687-
// }
688-
// catch (Exception ex)
689-
// {
690-
// if (ex.Message == "Too many fields defined.")
691-
// {
692-
// try
693-
// {
694-
// cmd.CommandText = "SELECT * FROM [" + strSheetname + "A1:IU65536]";
695-
696-
// daGetDataFromSheet.FillSchema(dtTable, SchemaType.Source);
697-
// }
698-
// catch (Exception exc)
699-
// {
700-
// continue;
701-
// }
702-
// }
703-
// else
704-
// // Deleted Sheet
705-
// continue;
706-
// }
707-
708-
// foreach (DataColumn dCol in dtTable.Columns)
709-
// {
710-
// if (dCol.DataType != typeof(System.String))
711-
// dCol.DataType = typeof(System.String);
712-
// }
713-
714-
715-
// int result = 1;
716-
// int intPaggingIndex = 0;
717-
// string[] strHeader = { };
718-
719-
// while (result > 0)
720-
// {
721-
// if (intPaggingIndex == 0)
722-
// {
723-
// result = daGetDataFromSheet.Fill(intPaggingIndex, PaggingInterval, dtTable);
724-
725-
// if (result == 0)
726-
// {
727-
// dtTable.Dispose();
728-
// continue;
729-
// }
730-
731-
// if (dtTable.Rows.Count <= RowsToSkip)
732-
// continue;
733-
734-
// if (RowsToSkip > 0)
735-
// {
736-
// List<DataRow> lstRows = dtTable.Select().Take(RowsToSkip).ToList();
737-
738-
// string strExtraFieldsString = string.Empty;
739-
740-
// foreach (DataRow drRow in lstRows)
741-
// {
742-
// if (string.IsNullOrEmpty(strExtraFieldsString))
743-
// strExtraFieldsString += string.Join(Constants.vbNewLine, drRow.ItemArray.Where(x => x.ToString() != strSheetname).ToArray());
744-
// else
745-
// strExtraFieldsString += Constants.vbNewLine + string.Join(Constants.vbNewLine, drRow.ItemArray.Where(x => x.ToString() != strSheetname).ToArray());
746-
// }
747-
748-
// if (!string.IsNullOrEmpty(strExtraFieldsString))
749-
// {
750-
// DataColumn dcCol = new DataColumn("Sys_ExtraFields");
751-
// dcCol.MaxLength = 4000;
752-
// dcCol.DefaultValue = strExtraFieldsString;
753-
// dtTable.Columns.Add(dcCol);
754-
// }
755-
756-
757-
// dtTable = dtTable.Select().Skip(RowsToSkip).CopyToDataTable();
758-
// }
759-
760-
// if (HasHeader && dtTable.Rows.Count > 0)
761-
// {
762-
// strHeader = dtTable.Rows[0].ItemArray.Select(x => Information.IsDBNull(x) ? "" : x.ToString()).ToArray();
763-
764-
// int intCount = 0;
765-
766-
// foreach (DataColumn dCol in dtTable.Columns)
767-
// {
768-
// if (!dCol.ColumnName.StartsWith("Sys_"))
769-
// {
770-
// string strColumnname = "";
771-
772-
// strColumnname = strHeader[intCount] == "" ? "F" + (intCount) : GetColumnName(strHeader[intCount].Trim(), dtTable);
773-
774-
// if (dtTable.Columns.IndexOf(strColumnname) > -1 && strHeader[intCount].ToString() != "")
775-
// dCol.ColumnName = strColumnname + "_" + intCount.ToString();
776-
// else
777-
// dCol.ColumnName = strColumnname;
778-
// }
779-
780-
// intCount += 1;
781-
// }
782-
783-
// dtTable.Rows[0].Delete();
784-
// dtTable.AcceptChanges();
785-
// }
786-
787-
// foreach (DataColumn dCol in dtTable.Columns)
788-
// {
789-
// if (dCol.ColumnName.Contains("'"))
790-
// dCol.ColumnName = dCol.ColumnName.Replace("'", "");
791-
// }
792-
// }
793-
// else
794-
// {
795-
// DataTable dtTemp = new DataTable("dtTemp");
796-
797-
// result = daGetDataFromSheet.Fill(intPaggingIndex, PaggingInterval, dtTemp);
798-
799-
// if (result == 0)
800-
// {
801-
// dtTable.Dispose();
802-
// continue;
803-
// }
804-
805-
// if (HasHeader && dtTemp.Rows.Count > 0)
806-
// {
807-
// int intCount = 0;
808-
809-
// foreach (DataColumn dCol in dtTemp.Columns)
810-
// {
811-
// if (!dCol.ColumnName.StartsWith("Sys_"))
812-
// {
813-
// string strColumnname = "";
814-
815-
// strColumnname = strHeader[intCount].ToString() == "" ? "F" + (intCount) : GetColumnName(strHeader[intCount].Trim(), dtTemp);
816-
817-
// if (dtTemp.Columns.IndexOf(strColumnname) > -1 && strHeader[intCount].ToString() != "")
818-
// dCol.ColumnName = strColumnname + "_" + intCount.ToString();
819-
// else
820-
// dCol.ColumnName = strColumnname;
821-
// }
822-
823-
// intCount += 1;
824-
// }
825-
826-
// dtTemp.AcceptChanges();
827-
// }
828-
829-
// dtTable.Merge(dtTemp);
830-
// }
831-
832-
833-
834-
// if (dtTable.Rows.Count == 0 && intPaggingIndex > 0)
835-
// continue;
836-
837-
// intPaggingIndex += PaggingInterval;
838-
839-
// //using (TableConverter tcConverter = new TableConverter(FilePath, ConfigClass, importLogId, uInput))
840-
// //{
841-
// // using (DataTable TempTable = tcConverter.ChangeTableStructureUsingColumnsMapping(dtTable, ConfigClass.dsMain.Tbl_ColumnsMapping, RemoveEmptyColumns, TemplateID, true))
842-
// // {
843-
// // tcConverter.ExportTablesAsXml(TempTable, v_ExportPath);
844-
// // dtTable.Rows.Clear();
845-
// // }
846-
// //}
847-
// }
848-
// }
849-
// }
850-
// }
851-
// catch (Exception ex)
852-
// {
853-
// throw new Exception(ex.Message + Constants.vbNewLine + string.Format("Sheet:{0}.File:F{1}", strSheetname, FilePath));
854-
// }
855-
856-
// if (m_MultipleSheet == false)
857-
// break;
858-
// }
859-
// }
860-
861-
// OleDBCon.Close();
862-
863-
// if (!TableNameFilterAccepted)
864-
// throw new Exception("Specified table name not found");
865-
// }
866-
// }
867-
// catch (Exception ex)
868-
// {
869-
// throw new Exception(ex.Message, ex);
870-
// }
871-
//}
872-
873-
874-
875-
876-
877618
public void Dispose()
878619
{
879620

SchemaMapperDLL/Classes/FileCleaners/MsExcelCleaner.cs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ private int ParseColHeaderToIndex(string colAdress)
467467
#region declarations
468468

469469
private string m_strFolderPath = string.Empty;
470-
private bool m_RemoveEmptyRowsAndColumns = false;
471470
private ExcelCleanOperationType m_ExcelCleanOperationType = ExcelCleanOperationType.GetUsedRange;
472471
private Application m_XlApp;
473472
private int m_CleanRange = 0;
@@ -595,31 +594,26 @@ public string CleanExcel(string strPath)
595594

596595
m_XlWrkSheet.UsedRange.UnMerge();
597596

598-
if (m_RemoveEmptyRowsAndColumns)
599-
{
600-
601-
if (m_ExcelCleanOperationType != ExcelCleanOperationType.CleanExcel)
602-
{
603597

604-
int MaxRow = 1;
605-
int MaxCol = 1;
598+
if (m_ExcelCleanOperationType != ExcelCleanOperationType.CleanExcel)
599+
{
606600

601+
int MaxRow = 1;
602+
int MaxCol = 1;
607603

608-
strResult += GetUsedRangeString(ref m_XlWrkSheet, ref MaxRow, ref MaxCol, m_CleanRange) + "|";
609604

610-
}
611-
else
612-
{
605+
strResult += GetUsedRangeString(ref m_XlWrkSheet, ref MaxRow, ref MaxCol, m_CleanRange) + "|";
613606

614-
RemoveEmptyRowsAndColumns(ref m_XlWrkSheet, m_CleanRange);
607+
}
608+
else
609+
{
615610

611+
RemoveEmptyRowsAndColumns(ref m_XlWrkSheet, m_CleanRange);
616612

617-
}
618613

619614
}
620615

621616

622-
623617
}
624618

625619
xlWbs.Save();
@@ -641,12 +635,11 @@ public string CleanExcel(string strPath)
641635

642636
#region constructors
643637

644-
public MsExcelCleaner(int v_Range = 10000, bool RemoveEmptyRowsAndColumns = false, ExcelCleanOperationType ExcelCleanOperationType = ExcelCleanOperationType.GetUsedRange)
638+
public MsExcelCleaner(int v_Range = 10000, ExcelCleanOperationType ExcelCleanOperationType = ExcelCleanOperationType.GetUsedRange)
645639
{
646640

647641
m_CleanRange = v_Range;
648642
currentCleaninngRange = v_Range;
649-
m_RemoveEmptyRowsAndColumns = RemoveEmptyRowsAndColumns;
650643
m_ExcelCleanOperationType = ExcelCleanOperationType;
651644

652645
m_XlApp = new Application();

0 commit comments

Comments
 (0)