public ColumnMapping(ColumnMapping cm) { this.SourceColumn = cm.SourceColumn; this.TargetDatabaseType = cm.TargetDatabaseType; this.TargetColumn = cm.TargetColumn; this.TransformationCode = cm.TransformationCode; this.CustomInsertValue = cm.CustomInsertValue; this.CustomUpdateValue = cm.CustomUpdateValue; this.CustomDeleteValue = cm.CustomDeleteValue; this.ColumnCompareMethod = cm.ColumnCompareMethod; }
public ColumnMapping(string sourceColumn, ETargetDatabaseType databaseType, string targetColumn, ETransformationCode transformationType, string insertValue, string updateValue, string deleteValue, EColumnCompareMethod columnCompareMethod) { this.SourceColumn = sourceColumn; this.TargetDatabaseType = databaseType; this.TargetColumn = targetColumn; this.TransformationCode = transformationType; this.CustomInsertValue = insertValue; this.CustomUpdateValue = updateValue; this.CustomDeleteValue = deleteValue; this.ColumnCompareMethod = columnCompareMethod; }
public void ReadFile(string fileName) { XmlNode node; string src, tgt, val; StringBuilder sbLoadingErrors = new StringBuilder(); if (!File.Exists(fileName)) { MessageBox.Show("File does not exists!"); return; } if (!thePageNavigator1.GotoBeginning()) { return; } GlobalVariables.LoadedColumnMappings.Clear(); GlobalVariables.LoadedUserColumnsDefinitions.Clear(); src = tgt = val = string.Empty; //trfType = ETransformationType.SKIP; pageSourceConnection.rtbSrcConnStr.Text = string.Empty; pageSourceConnection.cbxSrcTableOrViewName.Text = string.Empty; pageTargetConnection.rtbTgtConnStr.Text = string.Empty; pageTargetConnection.cbxTgtTableOrViewName.Text = string.Empty; try { XmlDocument doc = new XmlDocument(); doc.Load(fileName); // Source Connection node = doc.DocumentElement.SelectSingleNode("/ScdMergeWizard/SourceConnection/ConnectionString"); if (node == null) { node = doc.DocumentElement.SelectSingleNode("/MERGER/SourceConnection/ConnectionString"); } if (node != null) { pageSourceConnection.rtbSrcConnStr.Text = node.InnerText; } else { sbLoadingErrors.AppendLine("Cannot read Source ConnectionString"); } node = doc.DocumentElement.SelectSingleNode("/ScdMergeWizard/SourceConnection/IsTableOrView"); if (node == null) { node = doc.DocumentElement.SelectSingleNode("/MERGER/SourceConnection/IsTableOrView"); } if (node != null) { pageSourceConnection.rbIsTableOrView.Checked = (node.InnerText == "True"); pageSourceConnection.rbIsCommandText.Checked = (node.InnerText != "True"); } else { sbLoadingErrors.AppendLine("Cannot read IsTableOrView"); } if (pageSourceConnection.rbIsTableOrView.Checked) { GlobalVariables.SourceConnection = DbHelper.CreateConnection(pageSourceConnection.rtbSrcConnStr.Text); pageSourceConnection.cbxSrcTableOrViewName.AddItems(DbHelper.GetTablesViewsAndSynonyms(GlobalVariables.SourceConnection)); } node = doc.DocumentElement.SelectSingleNode("/ScdMergeWizard/SourceConnection/TableOrViewName"); if (node == null) { node = doc.DocumentElement.SelectSingleNode("/MERGER/SourceConnection/TableOrView"); } if (node != null) { pageSourceConnection.cbxSrcTableOrViewName.Text = node.InnerText; } else { sbLoadingErrors.AppendLine("Cannot read Source TableOrViewName"); } node = doc.DocumentElement.SelectSingleNode("/ScdMergeWizard/SourceConnection/CommandText"); if (node == null) { node = doc.DocumentElement.SelectSingleNode("/MERGER/SourceConnection/CommandText"); } if (node != null) { pageSourceConnection.rtbCommandText.Text = node.InnerText.Replace("<![CDATA[", "").Replace("]]>", ""); } else { sbLoadingErrors.AppendLine("Cannot read CommandText"); } // Target Connection node = doc.DocumentElement.SelectSingleNode("/ScdMergeWizard/TargetConnection/ConnectionString"); if (node == null) { node = doc.DocumentElement.SelectSingleNode("/MERGER/TargetConnection/ConnectionString"); } if (node != null) { pageTargetConnection.rtbTgtConnStr.Text = node.InnerText; } else { sbLoadingErrors.AppendLine("Cannot read Target ConnectionString"); } GlobalVariables.TargetConnection = DbHelper.CreateConnection(pageTargetConnection.rtbTgtConnStr.Text); pageTargetConnection.cbxTgtTableOrViewName.AddItems(DbHelper.GetTablesViewsAndSynonyms(GlobalVariables.TargetConnection)); node = doc.DocumentElement.SelectSingleNode("/ScdMergeWizard/TargetConnection/TableOrViewName"); if (node == null) { node = doc.DocumentElement.SelectSingleNode("/MERGER/TargetConnection/TableOrView"); } if (node != null) { pageTargetConnection.cbxTgtTableOrViewName.Text = node.InnerText; } else { sbLoadingErrors.AppendLine("Cannot read TableOrViewName"); } // User Variables foreach (XmlNode n in doc.DocumentElement.SelectSingleNode("/ScdMergeWizard/UserVariables").ChildNodes) { MyUserVariable uv = new MyUserVariable(); node = doc.DocumentElement.SelectSingleNode(string.Format("/ScdMergeWizard/UserVariables/{0}/Name", n.Name)); uv.Name = node.InnerText; node = doc.DocumentElement.SelectSingleNode(string.Format("/ScdMergeWizard/UserVariables/{0}/DataType", n.Name)); uv.DataType = node.InnerText; node = doc.DocumentElement.SelectSingleNode(string.Format("/ScdMergeWizard/UserVariables/{0}/Value", n.Name)); uv.Definition = node.InnerText; GlobalVariables.LoadedUserColumnsDefinitions.Add(uv); } // Options node = doc.DocumentElement.SelectSingleNode("/ScdMergeWizard/Options/RecordsOnTargetNotFoundOnSourceMode"); if (node != null) { GlobalVariables.Options.RecordsOnTargetNotFoundOnSourceMode = (ERecordsOnTargetNotFoundOnSourceMode)Enum.Parse(typeof(ERecordsOnTargetNotFoundOnSourceMode), node.InnerText); } else { node = doc.DocumentElement.SelectSingleNode("/MERGER/Options/RecordsOnTargetNotFoundOnSourceEx"); if (node != null) { if (node.InnerText.Equals("UpdateDateTo")) { GlobalVariables.Options.RecordsOnTargetNotFoundOnSourceMode = ERecordsOnTargetNotFoundOnSourceMode.UpdateTargetField; } else if (node.InnerText.Equals("PhysicallyDelete")) { GlobalVariables.Options.RecordsOnTargetNotFoundOnSourceMode = ERecordsOnTargetNotFoundOnSourceMode.PhysicallyDelete; } else if (node.InnerText.Equals("DoNothing")) { GlobalVariables.Options.RecordsOnTargetNotFoundOnSourceMode = ERecordsOnTargetNotFoundOnSourceMode.DoNothing; } } else { sbLoadingErrors.AppendLine("Cannot read RecordsOnTargetNotFoundOnSourceMode"); } } node = doc.DocumentElement.SelectSingleNode("/ScdMergeWizard/Options/IgnoreDatabasePrefix"); if (node == null) { node = doc.DocumentElement.SelectSingleNode("/MERGER/Options/IgnoreDatabasePrefix"); } if (node != null) { GlobalVariables.Options.IgnoreDatabasePrefix = (node.InnerText == "True"); } else { sbLoadingErrors.AppendLine("Cannot read IgnoreDatabasePrefix"); } node = doc.DocumentElement.SelectSingleNode("/ScdMergeWizard/Options/ShowExtendedComments"); if (node == null) { node = doc.DocumentElement.SelectSingleNode("/MERGER/Options/ShowExtendedComments"); } if (node != null) { GlobalVariables.Options.ShowExtendedComments = (node.InnerText == "True"); } else { sbLoadingErrors.AppendLine("Cannot read ShowExtendedComments"); } node = doc.DocumentElement.SelectSingleNode("/ScdMergeWizard/Options/SCD2VersionNumberMode"); if (node != null) { GlobalVariables.Options.SCD2VersionNumberMode = (ESCD2VersionNumberMode)Enum.Parse(typeof(ESCD2VersionNumberMode), node.InnerText); } else { sbLoadingErrors.AppendLine("Cannot read VersionNumberResetOnSCD2"); } node = doc.DocumentElement.SelectSingleNode("/ScdMergeWizard/Options/SCD13UpdateMode"); if (node != null) { GlobalVariables.Options.SCD13UpdateMode = (ESCD13UpdateMode)Enum.Parse(typeof(ESCD13UpdateMode), node.InnerText); } else { sbLoadingErrors.AppendLine("Cannot read SCD13UpdateMode"); } node = doc.DocumentElement.SelectSingleNode("/ScdMergeWizard/Options/ComparisonMethod"); if (node != null) { GlobalVariables.Options.ComparisonMethod = (EComparisonMethod)Enum.Parse(typeof(EComparisonMethod), node.InnerText); } else { sbLoadingErrors.AppendLine("Cannot read ComparisonMethod"); } // Column Mappings node = doc.DocumentElement.SelectSingleNode("/ScdMergeWizard/ColumnMappings"); if (node != null) { foreach (XmlNode n in node.ChildNodes) { node = doc.DocumentElement.SelectSingleNode(string.Format("/ScdMergeWizard/ColumnMappings/{0}/SourceColumn", n.Name)); var srcc = node.InnerText; node = doc.DocumentElement.SelectSingleNode(string.Format("/ScdMergeWizard/ColumnMappings/{0}/TransformationType", n.Name)); var trfc = (ETransformationCode)Enum.Parse(typeof(ETransformationCode), node.InnerText); ETargetDatabaseType tgtdbt; node = doc.DocumentElement.SelectSingleNode(string.Format("/ScdMergeWizard/ColumnMappings/{0}/TargetDatabaseType", n.Name)); if (node != null) { tgtdbt = (ETargetDatabaseType)Enum.Parse(typeof(ETargetDatabaseType), node.InnerText); } else { tgtdbt = ETargetDatabaseType.TARGET; } node = doc.DocumentElement.SelectSingleNode(string.Format("/ScdMergeWizard/ColumnMappings/{0}/TargetColumn", n.Name)); var tgtc = node.InnerText; string val1c = string.Empty, val2c = string.Empty, cins = string.Empty, cupd = string.Empty, cdel = string.Empty; // Old version node = doc.DocumentElement.SelectSingleNode(string.Format("/ScdMergeWizard/ColumnMappings/{0}/Value1Column", n.Name)); if (node != null) { val1c = node.InnerText; } node = doc.DocumentElement.SelectSingleNode(string.Format("/ScdMergeWizard/ColumnMappings/{0}/Value2Column", n.Name)); if (node != null) { val2c = node.InnerText; } // New version node = doc.DocumentElement.SelectSingleNode(string.Format("/ScdMergeWizard/ColumnMappings/{0}/CustomInsertValue", n.Name)); if (node != null) { cins = node.InnerText; } node = doc.DocumentElement.SelectSingleNode(string.Format("/ScdMergeWizard/ColumnMappings/{0}/CustomUpdateValue", n.Name)); if (node != null) { cupd = node.InnerText; } node = doc.DocumentElement.SelectSingleNode(string.Format("/ScdMergeWizard/ColumnMappings/{0}/CustomDeleteValue", n.Name)); if (node != null) { cdel = node.InnerText; } EColumnCompareMethod ccm; node = doc.DocumentElement.SelectSingleNode(string.Format("/ScdMergeWizard/ColumnMappings/{0}/ColumnCompareMethod", n.Name)); if (node != null) { ccm = (EColumnCompareMethod)Enum.Parse(typeof(EColumnCompareMethod), node.InnerText); } else { ccm = EColumnCompareMethod.Default; } if (string.IsNullOrEmpty(cins) && !string.IsNullOrEmpty(val1c) && (trfc == ETransformationCode.SCD2_IS_ACTIVE || trfc == ETransformationCode.SCD3_PREVIOUS_VALUE || trfc == ETransformationCode.CREATED_DATE)) { cins = val1c; } if (string.IsNullOrEmpty(cupd) && !string.IsNullOrEmpty(val1c) && (trfc == ETransformationCode.SCD2_DATE_FROM || trfc == ETransformationCode.SCD2_DATE_TO || trfc == ETransformationCode.SCD3_DATE_FROM || trfc == ETransformationCode.MODIFIED_DATE)) { cupd = val1c; } if (string.IsNullOrEmpty(cdel) && !string.IsNullOrEmpty(val1c) && (trfc == ETransformationCode.DELETED_DATE || trfc == ETransformationCode.IS_DELETED)) { cdel = val1c; } if (string.IsNullOrEmpty(cins) && !string.IsNullOrEmpty(val2c) && (trfc == ETransformationCode.SCD2_DATE_FROM || trfc == ETransformationCode.SCD2_DATE_TO || trfc == ETransformationCode.SCD3_DATE_FROM || trfc == ETransformationCode.MODIFIED_DATE || trfc == ETransformationCode.DELETED_DATE || trfc == ETransformationCode.IS_DELETED)) { cins = val2c; } if (string.IsNullOrEmpty(cupd) && !string.IsNullOrEmpty(val2c) && (trfc == ETransformationCode.SCD2_IS_ACTIVE)) { cupd = val2c; } GlobalVariables.LoadedColumnMappings.Add(new ColumnMapping(srcc, tgtdbt, tgtc, trfc, cins, cupd, cdel, ccm)); } } else { node = doc.DocumentElement.SelectSingleNode("/MERGER/Mappings"); if (node != null) { foreach (XmlNode n in node.ChildNodes) { node = doc.DocumentElement.SelectSingleNode(string.Format("/MERGER/Mappings/{0}/Source", n.Name)); var srcc = node.InnerText; node = doc.DocumentElement.SelectSingleNode(string.Format("/MERGER/Mappings/{0}/Transformation", n.Name)); ETransformationCode tt = ETransformationCode.SKIP; try { tt = (ETransformationCode)Enum.Parse(typeof(ETransformationCode), node.InnerText); } catch { } var trfc = tt; node = doc.DocumentElement.SelectSingleNode(string.Format("/MERGER/Mappings/{0}/Target", n.Name)); var tgtc = node.InnerText; GlobalVariables.LoadedColumnMappings.Add(new ColumnMapping(srcc, ETargetDatabaseType.TARGET, tgtc, trfc, string.Empty, string.Empty, string.Empty, EColumnCompareMethod.Default)); } } else { sbLoadingErrors.AppendLine("Cannot load ColumnMappings"); } } RecentFilesManager.Add(fileName); loadRecentFiles(); GlobalVariables.IsProjectModified = false; } catch (Exception ex) { MyExceptionHandler.NewEx(ex); } FileName = fileName; }