using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Xml; using System.Xml.Linq; using System.Xml.Xsl; using System.IO; using VEPROMS.CSLA.Library; namespace Volian.Controls.Library { // This dialog is used when the imported UCF is different than one existing in the database. It allows the user to // select whether to overwrite, copy, etc. See the user interface project/dlgExportImport.cs for the options. public partial class dlgUCFImportOptions : Form { ListExistingFC; ListImportedFC; private bool _Initializing = false; public E_UCFImportOptions UCFImportOptionsCase = E_UCFImportOptions.LoadOnlyImported; public dlgUCFImportOptions(List name, List existingFC, List importedFC, E_UCFImportOptions defImpOpt, string xmlpath) { _Initializing = true; InitializeComponent(); InitializeFNamesCombo(name); ExistingFC = existingFC; ImportedFC = importedFC; cmbFNames.SelectedIndex = 0; // this displays the web browser differences for first name in the combo box. // initialize the import of UCF option radio buttons: UCFImportOptionsCase = defImpOpt; rbSetOnly.Visible = !xmlpath.ToLower().Contains("folder"); if (defImpOpt == E_UCFImportOptions.Ignore) { sBtnLoad.Value = false; grPnlLoad.Enabled = false; grPnlUse.Enabled = false; } else if (defImpOpt == E_UCFImportOptions.LoadNotUsed) { sBtnLoad.Value = true; grPnlLoad.Enabled = true; cbUse.Checked = false; grPnlUse.Enabled = false; } else if (defImpOpt == E_UCFImportOptions.LoadOnlyImported) { sBtnLoad.Value = true; grPnlLoad.Enabled = true; cbUse.Checked = true; grPnlUse.Enabled = true; rbOnlyImported.Checked = true; } else if (defImpOpt == E_UCFImportOptions.LoadUseAll) { sBtnLoad.Value = true; grPnlLoad.Enabled = true; cbUse.Checked = true; grPnlUse.Enabled = true; rbAll.Checked = true; } else if (defImpOpt == E_UCFImportOptions.LoadForSetOnly) { sBtnLoad.Value = true; grPnlLoad.Enabled = true; cbUse.Checked = true; grPnlUse.Enabled = true; rbSetOnly.Checked = true; } _Initializing = false; return; } private void InitializeFNamesCombo(List name) { foreach (string str in name) cmbFNames.Items.Add(str); } private void DisplayXmlDiff(string existingFC, string importedFC) { XmlDocument xd = new XmlDocument(); xd.LoadXml(existingFC); XmlNodeList xnl = xd.GetElementsByTagName("FormatConfig"); if (xnl != null && xnl.Count > 0) AddAttribute(xnl[0], "Version", "Existing"); string sXSLSummary = System.IO.File.ReadAllText(Application.StartupPath + "\\" + "UCFImpDetails.xsl"); StringWriter sw = new StringWriter(); StringWriter xsw = new StringWriter(); using (XmlReader xrt = XmlReader.Create(new StringReader(sXSLSummary))) { XmlTextWriter tx = new XmlTextWriter(xsw); xd.WriteTo(tx); string tmp = sw.ToString(); tmp = xd.InnerXml; using (XmlReader xri = XmlReader.Create(new StringReader(tmp))) { using (XmlWriter xwo = XmlWriter.Create(sw)) { XslCompiledTransform xsl = new XslCompiledTransform(); xsl.Load(xrt); xsl.Transform(xri, xwo); // Perform Transform } wbBrwsExisting.DocumentText = sw.ToString(); } } StringWriter sw1 = new StringWriter(); StringWriter xsw1 = new StringWriter(); XmlDocument xd1 = new XmlDocument(); xd1.LoadXml(importedFC); xnl = xd1.GetElementsByTagName("FormatConfig"); if (xnl != null && xnl.Count > 0) AddAttribute(xnl[0], "Version", "Importing"); using (XmlReader xrt = XmlReader.Create(new StringReader(sXSLSummary))) { XmlTextWriter tx = new XmlTextWriter(xsw1); xd1.WriteTo(tx); string tmp = xd1.InnerXml; using (XmlReader xri = XmlReader.Create(new StringReader(tmp))) { using (XmlWriter xwo = XmlWriter.Create(sw1)) { XslCompiledTransform xsl = new XslCompiledTransform(); xsl.Load(xrt); xsl.Transform(xri, xwo); // Perform Transform } wbBrwsImporting.DocumentText = sw1.ToString(); } } } private void AddAttribute(XmlNode xn, string name, string value) { XmlAttribute xa = xn.OwnerDocument.CreateAttribute(name); xa.Value = value.ToString(); xn.Attributes.Append(xa); } private void btnOk_Click(object sender, EventArgs e) { if (!sBtnLoad.Value) UCFImportOptionsCase = E_UCFImportOptions.Ignore; else if (!cbUse.Checked) UCFImportOptionsCase = E_UCFImportOptions.LoadNotUsed; else if (rbOnlyImported.Checked) UCFImportOptionsCase = E_UCFImportOptions.LoadOnlyImported; else if (rbAll.Checked) UCFImportOptionsCase = E_UCFImportOptions.LoadUseAll; else if (rbSetOnly.Checked) UCFImportOptionsCase = E_UCFImportOptions.LoadForSetOnly; this.Close(); } private void sBtnLoad_ValueChanged(object sender, EventArgs e) // Import options for UCF Change: Load switch button { if (_Initializing) return; if (sBtnLoad.Value) { grPnlLoad.Enabled = true; // Import the ucf change. let user select whether to use it. grPnlUse.Enabled = false; cbUse.Checked = false; } else { grPnlLoad.Enabled = false; // Don't import the ucf change. grPnlUse.Enabled = false; } } private void cbUse_CheckedChanged(object sender, EventArgs e) // Import options for UCF Change: use checkbox { if (_Initializing) return; if (cbUse.Checked) grPnlUse.Enabled = true; // Use the change. enable the load group & select for imported only else grPnlUse.Enabled = false; // Don't use the change. } private void cmbFNames_SelectedIndexChanged(object sender, EventArgs e) { int indx = cmbFNames.SelectedIndex; string existingFC = ExistingFC[indx]; string importedFC = ImportedFC[indx]; DisplayXmlDiff(existingFC, importedFC); } } }