public Form1() { InitializeComponent(); source_version_ = new Form2(this); //Открываем ворд на фоне _app = new Microsoft.Office.Interop.Word.Application(); _app.Visible = false; _waitWindow = new WaitWndFun(); //Настраиваем расположение окна Screen screen = Screen.FromControl(this); this.StartPosition = FormStartPosition.Manual; this.Location = new Point(screen.WorkingArea.Width / 2 - this.Width / 2, screen.WorkingArea.Height / 2 - this.Height); }
private void mergeToOneFile() // function to merge to one file { WaitWndFun waitForm = new WaitWndFun(); waitForm.Show(); string destFile = lsFileNames[0]; destFile.Remove(destFile.IndexOf('.')); destFile += "_merged.accdb"; //get destination file name System.IO.File.Copy(lsFileNames[0], destFile, true); //get db connection for destination file MyAccessDBController destDbController = new MyAccessDBController(destFile); //clear all tables except selected table destDbController.dropAllTablesExceptSelectedTable(strTableName); List <string> mergedColumns = new List <string>(); Dictionary <string, OleDbType> columnDataTypes = new Dictionary <string, OleDbType>(); // get necessary columns which will be merged for (int i = 0; i < gridColumns.Rows.Count; i++) { //get column type string column = gridColumns.Rows[i].Cells[1].Value.ToString(); mergedColumns.Add(column); columnDataTypes[column] = destDbController.getColumnType(column, strTableName); } //delete all columns except multiple columns destDbController.dropNotNecessaryColumns(mergedColumns, strTableName); //clear all records destDbController.makeEmptyTable(strTableName); outputPane.AppendText("Destination File : " + destFile + Environment.NewLine + Environment.NewLine); int totalLines = 0; // merge records one by one foreach (string fileName in lsFileNames) { int copiedLines = 0, skippedLines = 0; MyAccessDBController dbController = new MyAccessDBController(fileName); OleDbDataReader reader = dbController.getRecordReader(mergedColumns, strTableName); while (reader.Read()) { List <KeyValuePair <string, object> > record = new List <KeyValuePair <string, object> >(); int iterIndex = 0; foreach (string column in mergedColumns) { record.Add(new KeyValuePair <string, object>(column, reader[column])); // add to value list } for (iterIndex = 0; iterIndex < record.Count; iterIndex++) { if (record[iterIndex].Key == strIterColumnName) { break; } } string quato = ""; switch (columnDataTypes[record[iterIndex].Key]) { case OleDbType.Char: case OleDbType.Binary: case OleDbType.WChar: case OleDbType.VarChar: case OleDbType.LongVarChar: case OleDbType.VarWChar: case OleDbType.LongVarWChar: case OleDbType.VarBinary: case OleDbType.LongVarBinary: quato = "\'"; break; } if (record[iterIndex].Value.ToString() == "") { continue; } if (!destDbController.isExistField(record[iterIndex].Value.ToString(), strIterColumnName, strTableName, quato)) { destDbController.insertRecord(record, strTableName); copiedLines++; } else { skippedLines++; } } outputPane.AppendText(copiedLines.ToString() + " lines are copied from " + fileName + Environment.NewLine); outputPane.AppendText(skippedLines.ToString() + " lines are skipped from " + fileName + Environment.NewLine); outputPane.AppendText(Environment.NewLine); totalLines += copiedLines; } waitForm.Close(); outputPane.AppendText(Environment.NewLine + "Total Lines: " + totalLines.ToString() + Environment.NewLine); MessageBox.Show("Merge Completed"); }