using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; using System.Xml; using System.Text.RegularExpressions; using VEPROMS.CSLA.Library; using log4net; using Volian.Controls.Library; using C1.Win.C1FlexGrid; using System.Data.SqlClient; namespace ConvertAlarms { public partial class frmConvertAlarms : Form { public frmConvertAlarms() { InitializeComponent(); } private void SetDatabaseConnection() { Database.VEPROMS_Connection = string.Format("Data Source={0};Initial Catalog={1};Integrated Security=True", tbServer.Text, cmbDatabase.SelectedText); } private void btnBrowse_Click(object sender, EventArgs e) { FileInfo fi = new FileInfo(tbFileName.Text); ofd.InitialDirectory = fi.DirectoryName; ofd.FileName = fi.Name; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { tbFileName.Text = ofd.FileName; ProcessXML(); } } private void ProcessXML() { string fileName = tbFileName.Text; ProcessXmlFile(fileName); } private void ProcessXmlFile(string fileName) { UpdateHTML = false; tbXML.Clear(); UpdateHTML = true; XmlDocument xDoc = new XmlDocument(); xDoc.Load(fileName); XmlElement xe1 = xDoc.DocumentElement; XmlElement xe2 = xe1.ChildNodes[0] as XmlElement; XmlElement xe3 = xe2.ChildNodes[0] as XmlElement; XmlElement xe4 = (xe1.ChildNodes[1] as XmlElement).ChildNodes[0] as XmlElement; RelatedFunction = xe3.Attributes["relatedFunction"].Value; PNSNo = xe3.Attributes["PNSNo"].Value; ShortName = xe3.Attributes["shortName"].Value; FullName = xe3.Attributes["fullName"].Value; RevisionNumber = xe3.Attributes["revisionNumber"].Value; Priority = xe3.Attributes["priority"].Value; Number = xe3.Attributes["number"].Value; Responsibility = xe4.Attributes["implementor"].Value; ApSystem = GetSystem(xe3); XmlNode xn = xDoc.DocumentElement.LastChild.LastChild.LastChild; string html = GetHtml(xn); tbXML.Text = html; } private static string _RelatedFunction; public static string RelatedFunction { get { return _RelatedFunction; } set { _RelatedFunction = value; } } private static string _PNSNo; public static string PNSNo { get { return _PNSNo; } set { _PNSNo = value; } } private static string _fullName; public static string FullName { get { return _fullName; } set { _fullName = value; } } private static string _Number; public static string Number { get { return frmConvertAlarms._Number; } set { frmConvertAlarms._Number = value; } } private static string _RevisionNumber; public static string RevisionNumber { get { return frmConvertAlarms._RevisionNumber; } set { frmConvertAlarms._RevisionNumber = value; } } private static string _Priority; public static string Priority { get { return frmConvertAlarms._Priority; } set { frmConvertAlarms._Priority = value; } } private static string Responsibility; public static string Responsibility1 { get { return frmConvertAlarms.Responsibility; } set { frmConvertAlarms.Responsibility = value; } } private static string _shortName; public static string ShortName { get { return _shortName; } set { _shortName = value; } } private static string _system; public static string ApSystem { get { return _system; } set { _system = value; } } private static string _MyFileName; public static string MyFileName { get { return frmConvertAlarms._MyFileName; } set { frmConvertAlarms._MyFileName = value; } } private static string GetHtml(XmlNode xn) { XmlNode pr = xn.PreviousSibling; int i = 0; string html = xn.Attributes["content"].Value; //Console.WriteLine(@"{0} ""{1}""", i++, html); if (xn != pr) { while (pr != null && pr.Name == "NoteInstruction") { string html2 = pr.Attributes["content"].Value; //Console.WriteLine(@"{0} ""{1}""", i++, html2); html = MergeHTML(html2, html); //Console.WriteLine(@"{0} ""{1}""", -1, html); pr = pr.PreviousSibling; } } return html; } private static string MergeHTML(string part1, string part2) { part1 = part1.Replace("]*>", "", RegexOptions.Singleline); //part2 = part2.Substring(part2.IndexOf(""; public string HtmlPrefix { get { return _HtmlPrefix; } set { _HtmlPrefix = value; } } private string prcSerialNoFldName; private string prcSerialNoValue; private string prcTitleFldName; private string prcTitleValue; private string prcNumberFldName; private string prcNumberValue; private string prcSourceFldName; private string prcSourceValue; private string prcSetpointFldName; private string prcSetpointValue; //private Regex myReg01 = new Regex("
", RegexOptions.Compiled); //private Regex myReg02 = new Regex("
", RegexOptions.Compiled); //private Regex myReg03 = new Regex("]+>", RegexOptions.Compiled); //private Regex myReg04 = new Regex("", RegexOptions.Compiled); //private Regex myReg05 = new Regex("

[ \r\n]+

]+>", RegexOptions.Compiled); //private Regex myReg06 = new Regex("

]+>", RegexOptions.Compiled); ////private Regex myReg07 = new Regex(@"
+(?=\w)", RegexOptions.Compiled); //private Regex myReg08 = new Regex(@"
[ \r\n]*\t +", RegexOptions.Compiled); //private Regex myReg09 = new Regex(@"
[ \t\r\n]+\[", RegexOptions.Compiled); //private Regex myReg10 = new Regex("

", RegexOptions.Compiled); //private Regex myReg11 = new Regex(@"] *\t{4,10}", RegexOptions.Compiled); //private Regex myReg12 = new Regex("
\t+(?=None)", RegexOptions.Compiled); //private Regex myReg13 = new Regex("
\t+(?![[\\u2022]|[1-9])", RegexOptions.Compiled); //private Regex myReg14 = new Regex("
", RegexOptions.Compiled); //private Regex myReg15 = new Regex("\t\t+", RegexOptions.Compiled); //private Regex myReg16 = new Regex("\r\n +", RegexOptions.Compiled); //private Regex myReg17 = new Regex("(\r\n){2,}", RegexOptions.Compiled); //private Regex myReg18 = new Regex("]+>", RegexOptions.Compiled); ////private Regex myReg19 = new Regex("(?[^<>]*]*>[^<>]*]*>[^<>]*

(NOTE|CAUTION|WARNING)([^<>]+?)

[^<>]*[^<>]*[^<>]*
", RegexOptions.Compiled & RegexOptions.Singleline ); //private Regex myReg22 = new Regex("\\.\\.\\.+", RegexOptions.Compiled); private void XMLChanged(string xml) { Application.DoEvents(); xml = "\n" + xml; xml = xml.Replace(HtmlPrefix, ""); //xml = myReg01.Replace(xml, "
"); //xml = myReg02.Replace(xml, "
"); //xml = myReg03.Replace(xml, "");// Remove Style Span start //xml = myReg04.Replace(xml, "");// //xml = myReg05.Replace(xml, "
\r\n"); //xml = myReg06.Replace(xml, "
\r\n

"); ////xml = myReg07.Replace(xml, " ");//New //xml = myReg08.Replace(xml, " ");//New //xml = myReg09.Replace(xml, @"\line ["); //xml = myReg10.Replace(xml, "

"); //xml = myReg11.Replace(xml, "]\r\n"); //xml = myReg12.Replace(xml, "\r\n\t"); //xml = myReg13.Replace(xml, " "); //xml = myReg14.Replace(xml, "\r\n"); //xml = myReg15.Replace(xml, " "); //xml = myReg16.Replace(xml, "\r\n"); //xml = myReg17.Replace(xml, "\r\n"); //xml = myReg18.Replace(xml, ""); ////xml = myReg19.Replace(xml, "{SPACE}"); //xml = myReg20.Replace(xml, " "); //xml = myReg21.Replace(xml, "

\r\n$1$2\r\n

"); //xml = myReg22.Replace(xml, ""); //Remove multiple periods xml = Regex.Replace(xml, "
", "
"); xml = Regex.Replace(xml, "
", "
"); xml = Regex.Replace(xml, "]+>", "");// Remove Style Span start xml = Regex.Replace(xml, "", "");// xml = Regex.Replace(xml, "

[ \r\n]+

]+>", "
\r\n"); xml = Regex.Replace(xml, "

]+>", "
\r\n

"); // xml = Regex.Replace(xml, @"
+(?=\w)", " ");//New xml = Regex.Replace(xml, @"
[ \r\n]*\t (?! +[[\\u2022]| +[1-9]| +[A-Z][.])", " ");//New //xml = Regex.Replace(xml, @"
[ \r\n]*\t +", " ");//New xml = Regex.Replace(xml, @"
[ \t\r\n]+\[", @"\line ["); xml = Regex.Replace(xml, "

", "

"); xml = Regex.Replace(xml, @"] *\t{4,10}", "]\r\n"); xml = Regex.Replace(xml, "
\t+(?=None)", "\r\n\t"); xml = Regex.Replace(xml, "
\t+(?![[\\u2022]|[1-9]|[A-Z]\\.)", " "); xml = Regex.Replace(xml, "
", "\r\n"); xml = Regex.Replace(xml, "\t\t+", " "); xml = Regex.Replace(xml, "\r\n +", "\r\n"); xml = Regex.Replace(xml, "(\r\n){2,}", "\r\n"); xml = Regex.Replace(xml, "
]+>", "
"); //xml = Regex.Replace(xml, "(?[^<>]*]*>[^<>]*]*>[^<>]*

(NOTE|CAUTION|WARNING)([^<>]+?)

[^<>]*[^<>]*[^<>]*
", "\r\n$1$2\r\n", RegexOptions.Singleline); xml = Regex.Replace(xml, "\\.\\.\\.+", ""); //Remove multiple periods //xml = Regex.Replace(xml," //xml = xml.Replace(">", ""); Application.DoEvents(); byte[] bytes = Encoding.UTF8.GetBytes(xml); MemoryStream ms = new MemoryStream(); ms.Write(bytes, 0, bytes.Length); ms.Position = 0; XmlDocument xDoc2 = new XmlDocument(); xDoc2.Load(ms); int iStart = 1; XmlNode xn3 = xDoc2.ChildNodes[1].ChildNodes[1].ChildNodes[0]; if (!xn3.OuterXml.Contains("table")) { iStart = 2; xn3 = xDoc2.ChildNodes[1].ChildNodes[1].ChildNodes[1]; } prcSerialNoFldName = GetProcInfo(xn3, 0, 0, 0); prcSerialNoValue = GetProcInfo(xn3, 0, 1, 0); SerialNo = int.Parse(prcSerialNoValue); prcTitleFldName = GetProcInfo(xn3, 1, 0, 0); prcTitleValue = GetProcInfo(xn3, 1, 1, 0); prcNumberFldName = GetProcInfo(xn3, 2, 0, 0); prcNumberValue = GetProcInfo(xn3, 2, 1, 0); prcSourceFldName = GetProcInfo(xn3, 3, 0, 0); prcSourceValue = GetProcInfo(xn3, 3, 1, 0); prcSetpointFldName = GetProcInfo(xn3, 4, 0, 0); prcSetpointValue = GetProcInfo(xn3, 4, 1, 0); Console.WriteLine("\"FromProcedures\"\t\"{0}\"\t\"{1}\"\t\"{2}\"\t\"{3}\"\t\"{4}\"\t\"{5}\"\t\"{6}\"\t\"{7}\"\t\"{8}\"\t\"{9}\"\t\"{10}\"\t\"{11}\"\t\"{12}\"\t\"{13}\"\t\"{14}\"" , PNSNo.Replace("\r\n", ";CR;").Replace("\n", ";CR;").Replace("\r", ";CR;") , ApSystem.Replace("\r\n", ";CR;").Replace("\n", ";CR;").Replace("\r", ";CR;") , FullName.Replace("\r\n", ";CR;").Replace("\n", ";CR;").Replace("\r", ";CR;") , ShortName.Replace("\r\n", ";CR;").Replace("\n", ";CR;").Replace("\r", ";CR;") , RelatedFunction.Replace("\r\n", ";CR;").Replace("\n", ";CR;").Replace("\r", ";CR;") , "Rev" + RevisionNumber.Replace("\r\n", ";CR;").Replace("\n", ";CR;").Replace("\r", ";CR;") , Priority.Replace("\r\n", ";CR;").Replace("\n", ";CR;").Replace("\r", ";CR;") , Number.Replace("\r\n", ";CR;").Replace("\n", ";CR;").Replace("\r", ";CR;") , prcNumberValue.Replace("\r\n", ";CR;").Replace("\n", ";CR;").Replace("\r", ";CR;") , prcSerialNoValue.Replace("\r\n", ";CR;").Replace("\n", ";CR;").Replace("\r", ";CR;") , prcSetpointValue.Replace("\r\n", ";CR;").Replace("\n", ";CR;").Replace("\r", ";CR;") , prcSourceValue.Replace("\r\n", ";CR;").Replace("\n", ";CR;").Replace("\r", ";CR;") , prcTitleValue.Replace("\r\n", ";CR;").Replace("\n", ";CR;").Replace("\r", ";CR;") , Responsibility.Replace("\r\n", ";CR;").Replace("\n", ";CR;").Replace("\r", ";CR;") , MyFileName); ProcNumber = prcNumberValue; ProcTitle = prcTitleValue; // Skip First Node UpdateHTML = false; tbPROMS.Clear(); tbPROMS.AppendText(string.Format("{0} = '{1}'\r\n", prcSerialNoFldName, prcSerialNoValue)); tbPROMS.AppendText(string.Format("{0} = '{1}'\r\n", prcTitleFldName, prcTitleValue)); tbPROMS.AppendText(string.Format("{0} = '{1}'\r\n", prcNumberFldName, prcNumberValue)); tbPROMS.AppendText(string.Format("{0} = '{1}'\r\n", prcSourceFldName, prcSourceValue)); tbPROMS.AppendText(string.Format("{0} = '{1}'\r\n", prcSetpointFldName, prcSetpointValue)); StringBuilder sbAllText = new StringBuilder(); for (int i = iStart; i < xDoc2.ChildNodes[1].ChildNodes[1].ChildNodes.Count; i++) { XmlNode xn2 = xDoc2.ChildNodes[1].ChildNodes[1].ChildNodes[i]; if (xn2.OuterXml != ">\r\n" && xn2.OuterXml != "

") { sbAllText.Append("\r\n" + xn2.OuterXml); //Console.WriteLine("--{0}--|{1}|", i, IndentifySpecialCharacters(xn2.OuterXml)); } } tbPROMS.AppendText(sbAllText.ToString().Replace(" ", "\xB7")); //SaveTree(sbAllText.ToString(), prcNumberValue, prcTitleValue); ProcTextAll = sbAllText.ToString(); UpdateHTML = true; } String ProcTextAll; int SerialNo; String ProcNumber; String ProcTitle; TreeNode lastNode = null; private void SaveTree(string text, string procNumber, string procTitle) { tv.Nodes.Clear(); MemoryStream ms = GetMemoryStream(text); using (TextReader tr = new StreamReader(ms)) { Dictionary lookup = new Dictionary(); lookup.Add(0, tv.Nodes.Add(string.Format("{0} - {1}", procNumber, procTitle))); int level = 0; int lastLevel = 0; int lastIndent = 0; int extra = 0; bool textContinued = false; string lastTab = ""; Queue enQueue = null; Queue deQueue = null; bool isTable = false; while (tr.Peek() >= 0 || deQueue != null) { string lineText; if (deQueue != null) { extra = 1; lineText = deQueue.Dequeue(); if (deQueue.Count == 0) deQueue = null; } else { extra = 0; lineText = tr.ReadLine(); if (lineText.StartsWith("")) { while (!lineText.Contains("
")) { lineText += " " + tr.ReadLine(); lineText = Regex.Replace(lineText, ".*", ""); } XmlDocument xd = new XmlDocument(); xd.LoadXml(lineText); LoadTable2(xd.DocumentElement, null, 0); isTable = true; //StringBuilder sbxml= new StringBuilder(); //using(StringWriter sw = new StringWriter(sbxml)) // _MyFlexGrid.WriteXml(sw); //using(StringReader sr= new StringReader(sbxml.ToString())) // _MyFlexGrid.ReadXml(sr); //Application.DoEvents(); } else if (lineText == "NOTE" || lineText == "CAUTION" || lineText == "Warning") enQueue = new Queue(); } lineText = Regex.Replace(lineText, "<[^<>]+>", ""); textContinued = false; if (lineText.Replace("\t", "") != "") { Match m = Regex.Match(lineText, @"^(\t*)([1-9][0-9]*\.0|[1-9][0-9]*\.[1-9][0-9]*|\u2022|\u25CB)([\t ]+)([^\u2022]*)$", RegexOptions.Multiline); string tab = m.Groups[2].Value; int indent = m.Groups[1].Value.Length; //if (lineText.Contains("THEN·GO·TO·1N2-OP-EOP-XX-0002")) // Console.WriteLine("here"); if (isTable) { // do nothing } if (indent == 0 && tab.EndsWith(".0")) // High Level Step { level = 1; if (deQueue == null && enQueue != null) { deQueue = enQueue; enQueue = null; } } else if (Regex.IsMatch(tab, "[1-9][0-9]*[.0-9]*")) // Substep { level = 2; if (deQueue == null && enQueue != null) { deQueue = enQueue; enQueue = null; } } else if (tab == "") // Paragraph { if (Regex.IsMatch(lineText, "(NOTE|NOTES|CAUTION|CAUTIONS|WARNING|WARNINGS)")) extra = 0; else { lastNode.Text += " " + lineText.TrimStart("\r\n \t".ToCharArray()); //Console.WriteLine("maybe continue '{0}'", lineText); textContinued = true; } level = lastLevel + 1; } else if (tab == "\u2022")//bullet level = indent + 2; else if (tab == "\u25CB")//bullet level = indent + 3; if (level < lastLevel) while (level < lastLevel) lookup.Remove(lastLevel--); string txt = string.Format("{0}|{1}||{2}", m.Groups[1].Value, m.Groups[2].Value, m.Groups[4].Value); if (txt == "|||") txt = lineText; if (enQueue == null) { if (!textContinued && !isTable) { if (level > lookup.Count - extra) extra = 0; //if (level + extra - 1 == lookup.Count) // Console.WriteLine("Problems {0}, {1}", procNumber, txt); else if (lookup.Count <= level) lookup.Add(level + extra, lookup[level + extra - 1].Nodes.Add(txt)); else lookup[level + extra] = lookup[level + extra - 1].Nodes.Add(txt); lastNode = lookup[level + extra]; } } else { enQueue.Enqueue(lineText); } lastTab = tab; lastLevel = level; lastIndent = indent; } } } } private ItemInfo FindPrevious(SortedDictionary dicSerialNo, int serialNo) { ItemInfo lastItem = null; foreach (int serno in dicSerialNo.Keys) { if (serno > serialNo) return lastItem; lastItem = dicSerialNo[serno]; } return lastItem; } private bool runOne = true; private static MemoryStream GetMemoryStream(string text) { byte[] bytes = Encoding.UTF8.GetBytes(text); MemoryStream ms = new MemoryStream(bytes); ms.Position = 0; return ms; } private string GetProcInfo(XmlNode xn3, int p1, int p2, int p3) { if (xn3.OuterXml == "

") xn3 = xn3.NextSibling; return xn3.ChildNodes[p1].ChildNodes[p2].ChildNodes[p3].ChildNodes[0].Value.Trim("\r\n ".ToCharArray()); } private bool _UpdateHTML = true; public bool UpdateHTML { get { return _UpdateHTML; } set { _UpdateHTML = value; } } private string IndentifySpecialCharacters(string xml) { StringBuilder sb = new StringBuilder(); string txt = Regex.Replace(xml, "]+>", ""); foreach (char c in txt) { if (((int)c) < 32 || ((int)c) > 256) sb.Append(string.Format("[x{0:X4}]", (int)c)); else sb.Append(c == ' ' ? '\xb7' : c); } return sb.ToString(); } private void btnRun_Click(object sender, EventArgs e) { ProcessXML(); } Regex regColorCode = new Regex(@"(\<[^<>]+\>)([^<>]*)", RegexOptions.Singleline); Regex regColorCodeText = new Regex("(\t*)([^\t]*)", RegexOptions.Singleline); private void ColorCoded(string str) { rtbXML.Clear(); Color fColor = Color.PaleTurquoise; Color fNext = Color.PaleTurquoise; foreach (Match m in regColorCode.Matches(str)) { string fmt = m.Groups[1].Value; string txt = m.Groups[2].Value; if (fmt.StartsWith("") fNext = Color.PaleTurquoise; else if (fmt == "
") fColor = Color.PeachPuff; else if (fmt == "

") fColor = Color.LightPink; AddToXML(fmt, fColor); fColor = fNext; foreach (Match mm in regColorCodeText.Matches(txt)) { string tabs = mm.Groups[1].Value; string nontabs = mm.Groups[2].Value; AddToXML(tabs, Color.Khaki); AddToXML(nontabs, Color.Yellow); } } } private void AddToXML(string txt, Color fColor) { if (txt == "") return; rtbXML.SelectionStart = rtbXML.TextLength; rtbXML.SelectionBackColor = fColor; rtbXML.SelectedText = txt; } private void frmConvertAlarms_Load(object sender, EventArgs e) { LoadSettings(); SetEventHandlers(); _MyFlexGrid = new VlnFlexGrid(); tpGrid.Controls.Add(_MyFlexGrid); string str = AutoFolder; if (str != null && str.Length > 5) { tmr.Enabled = true; } } private void SetEventHandlers() { tbFileName.TextChanged += tbFileName_TextChanged; Move += frmConvertAlarms_Move; Resize += frmConvertAlarms_Resize; sc1.SplitterMoved += sc1_SplitterMoved; //sc2.SplitterMoved += sc2_SplitterMoved; tbServer.TextChanged += tbServer_TextChanged; cmbDatabase.TextChanged += cmbDatabase_TextChanged; cmbDatabase.Click += cmbDatabase_Click; cmbDocVersion.TextChanged += cmbDocVersion_TextChanged; //BuildTableCombo(); //BuildProcedureSetCombo(); } void cmbDatabase_Click(object sender, EventArgs e) { Properties.Settings.Default.Database = cmbDatabase.Text; Properties.Settings.Default.Save(); BuildProcedureSetCombo(); } private void BuildProcedureSetCombo() { DocVersionInfoList dvil = DocVersionInfoList.Get(); cmbDocVersion.DataSource = dvil; cmbDocVersion.DisplayMember = "SearchDVPath"; cmbDocVersion.ValueMember = "VersionId"; } private void cmbDocVersion_TextChanged(object sender, EventArgs e) { Properties.Settings.Default.ProcedureSet = (int)cmbDocVersion.SelectedValue; Properties.Settings.Default.Save(); } private void cmbDatabase_TextChanged(object sender, EventArgs e) { Properties.Settings.Default.Database = cmbDatabase.Text; Properties.Settings.Default.Save(); BuildProcedureSetCombo(); } private void tbServer_TextChanged(object sender, EventArgs e) { Properties.Settings.Default.SqlServer = tbServer.Text; Properties.Settings.Default.Save(); string db = cmbDatabase.Text; try { BuildDatabaseCombo(); } catch (Exception ex) { tsslStatus.Text = ex.Message; } } private void BuildDatabaseCombo() { string tmp = string.Format("Data Source={0};Initial Catalog={1};Integrated Security=True", tbServer.Text, "MASTER"); SqlConnection cn = new SqlConnection(tmp); cn.Open(); // SqlDataAdapter da = new SqlDataAdapter("select name from sysdatabases where name like 'VEP%' order by name", cn); //SqlDataAdapter da = new SqlDataAdapter("select name, case when object_id('[' + name + ']..Items') is null then 'Not PROMS' when object_id('[' + name + ']..Revisions') is not null then 'Approval' when object_id('[' + name + ']..ContentAudits') is not null then 'Change Manager' else 'Original' end functionality from sysdatabases where name not in ('master','model','msdb','tempdb') order by name", cn); SqlDataAdapter da = new SqlDataAdapter("select name, 'Approval' functionality from sysdatabases where name not in ('master','model','msdb','tempdb') order by name", cn); da.SelectCommand.CommandTimeout = 300; // 300 sec timeout DataSet ds = new DataSet(); try { da.Fill(ds); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.GetType().Name, ex.Message); throw (new Exception("Cannot Load Data List", ex)); } cn.Close(); //System.Windows.Forms.ContextMenuStrip cms = new System.Windows.Forms.ContextMenuStrip(); //cms.Items.Add("Choose Database"); //System.Windows.Forms.ToolStripMenuItem tsmi = cms.Items[0] as System.Windows.Forms.ToolStripMenuItem; //tsmi.BackColor = System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.ActiveCaption);// System.Drawing.Color.Pink; //tsmi.ForeColor = System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.ActiveCaptionText); //tsmi.Font = new System.Drawing.Font(tsmi.Font, System.Drawing.FontStyle.Bold); foreach (DataRow dr in ds.Tables[0].Rows) { if (dr["functionality"].ToString() == "Approval") cmbDatabase.Items.Add(dr["name"].ToString()); } } void frmConvertAlarms_Resize(object sender, EventArgs e) { Properties.Settings.Default.Size = Size; Properties.Settings.Default.Save(); } void frmConvertAlarms_Move(object sender, EventArgs e) { Properties.Settings.Default.Location = Location; Properties.Settings.Default.Save(); } void tbFileName_TextChanged(object sender, EventArgs e) { Properties.Settings.Default.FileName = tbFileName.Text; Properties.Settings.Default.Save(); } private void sc1_SplitterMoved(object sender, SplitterEventArgs e) { Properties.Settings.Default.Split1 = sc1.SplitterDistance; Properties.Settings.Default.Save(); } private void LoadSettings() { Size = Properties.Settings.Default.Size; Location = Properties.Settings.Default.Location; if (Properties.Settings.Default.FileName != null && Properties.Settings.Default.FileName != "") { FileInfo fi = new FileInfo(Properties.Settings.Default.FileName); tbFileName.Text = fi.FullName; } sc1.SplitterDistance = Properties.Settings.Default.Split1; tbServer.Text = Properties.Settings.Default.SqlServer; cmbDatabase.Text = Properties.Settings.Default.Database; try { BuildDatabaseCombo(); Database.VEPROMS_Connection = string.Format("Data Source={0};Initial Catalog={1};Integrated Security=True", tbServer.Text, cmbDatabase.Text); BuildProcedureSetCombo(); cmbDocVersion.SelectedValue = Properties.Settings.Default.ProcedureSet; } catch (Exception ex) { tsslStatus.Text = ex.Message; } } private void tsslStatus_Click(object sender, EventArgs e) { tsslStatus.Text = string.Format("Selection = '{0}'", IndentifySpecialCharacters(tbXML.SelectedText)); Clipboard.Clear(); if (tbXML.SelectedText != "") Clipboard.SetText(IndentifySpecialCharacters(tbXML.SelectedText)); } private void rtbXML_SelectionChanged(object sender, EventArgs e) { } private void tbXML_TextChanged(object sender, EventArgs e) { if (UpdateHTML) { if (AutoFolder == null) htmlChanged(tbXML.Text); XMLChanged(tbXML.Text); if (AutoFolder == null) ColorCoded(tbXML.Text); } } private bool _UpdateTbXML = true; public bool UpdateTbXML { get { return _UpdateTbXML; } set { _UpdateTbXML = value; } } private void rtbXML_TextChanged(object sender, EventArgs e) { //if (UpdateHTML) //{ // UpdateHTML = false; // htmlChanged(rtbXML.Text); // XMLChanged(rtbXML.Text); // tbXML.Text = rtbXML.Text; // UpdateHTML = true; //} } private void btnConvert_Click(object sender, EventArgs e) { //SaveProcedure(ProcTextAll, ProcNumber, ProcTitle,999999); DVI = DocVersionInfo.Get((int)cmbDocVersion.SelectedValue); SaveProcedure(ProcTextAll, ProcNumber, ProcTitle, tbFileName.Text); } string lastLine = ""; SortedDictionary dicSerialNo; int errorCount; private void btnAll_Click(object sender, EventArgs e) { DVI = DocVersionInfo.Get((int)cmbDocVersion.SelectedValue); string fileName = tbFileName.Text; ConvertFiles(fileName); } private void ConvertFiles(string fileName) { Application.DoEvents(); DateTime dtStart = DateTime.Now; errorCount = 0; dicSerialNo = new SortedDictionary(); runOne = false; // Get List of files FileInfo fi = new FileInfo(fileName); DirectoryInfo di = fi.Directory; // Loop through list FileInfo[] fs = di.GetFiles("*.xml"); tspb.Visible = true; tspb.Value = 0; tspb.Maximum = fs.Length; foreach (FileInfo f in fs) { //ResetSpecial(); MyFileName = f.FullName; tspb.Value++; tsslStatus.Text = f.Name; Application.DoEvents(); // Process each file try { ProcessXmlFile(f.FullName); // Convert each file //SaveProcedure(ProcTextAll, ProcNumber, ProcTitle, SerialNo); SaveProcedure(ProcTextAll, ProcNumber, ProcTitle, f.Name); } catch (Exception ex) { ++errorCount; Console.WriteLine("*** {0} - {1}\r\n*** Procedure {2}\r\n*** Text: {3}\r\n*** File Name:{4} ", ex.GetType().Name, ex.Message, ProcNumber, lastLine, f.Name); //break; } //break; one Procedure per set } runOne = true; tspb.Visible = false; tsslStatus.Text = "Done"; //MessageBox.Show(string.Format( // "{0} Errors\r\n{1} Procedures\r\n{2:F} Seconds", errorCount, // fs.Length, // TimeSpan.FromTicks(DateTime.Now.Ticks - dtStart.Ticks).TotalSeconds), // "Done with this set", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void statusStrip1_Click(object sender, EventArgs e) { if (rtbXML.SelectedText != "") { tsslStatus.Text = string.Format("Selection = '{0}'", IndentifySpecialCharacters(rtbXML.SelectedText)); Clipboard.Clear(); Clipboard.SetText(IndentifySpecialCharacters(rtbXML.SelectedText)); } } ROFSTLookup MyLookUp; private void tmr_Tick(object sender, EventArgs e) { tmr.Enabled = false; // If timer on the its ready to proccess string str = AutoFolder; if (str != null && str.Length > 5) { DirectoryInfo di = new DirectoryInfo(str); FileInfo fi = di.GetFiles("*.xml")[0]; DVI = GetDVI(fi.FullName); ConvertFiles(fi.FullName); } this.Close(); } private static string _AutoFolder = null; private static string AutoFolder { get { if (_AutoFolder == null) { _AutoFolder = System.Environment.CommandLine; _AutoFolder = _AutoFolder.Substring(_AutoFolder.IndexOf(@".exe"" ") + 6).Trim(" \t\r\n".ToCharArray()); } if (_AutoFolder.Length < 1) return null; return _AutoFolder; } } private DocVersionInfo GetDVI(string fileName) { XmlDocument xd = new XmlDocument(); xd.Load(fileName); XmlElement xe = xd.DocumentElement; while (xe.Name != "ident") xe = xe.ChildNodes[0] as XmlElement; string DVIFolderName = xe.Attributes["PNSNo"].Value; if (cmbDocVersion.SelectedValue != null) { DocVersionInfo dvi = DocVersionInfo.Get((int)(cmbDocVersion.SelectedValue)); int idnew; ROFstInfo fst = dvi.DocVersionAssociations[0].MyROFst; FolderInfo grandParent = dvi.ActiveParent.ActiveParent as FolderInfo; // Create a folder double myOrder = GetMyOrder(grandParent.SortedChildFolders, DVIFolderName); using (Folder flder = Folder.MakeFolder(grandParent.Get(), null, DVIFolderName, fileName, GetSystem(xe), null, myOrder, null)) { flder.ManualOrder = 0; flder.ManualOrder = myOrder; //Console.WriteLine("myOrder = {0}, flder = {1}", myOrder, flder.ManualOrder); flder.Save(); // create a a DocVersion using (DocVersion dv = DocVersion.MakeDocVersion(flder, "Working Draft", null, null, null, null)) { dv.DocVersionAssociations.Add(fst.Get()); dv.Save(); idnew = dv.VersionID; } } return DocVersionInfo.Get(idnew); } return null; } private double GetMyOrder(Csla.SortedBindingList myList, string DVIFolderName) { double lastNum = 0; // Console.WriteLine("--->>> FolderName {0} Insert Count {1}",DVIFolderName, myList.Count); foreach (FolderInfo myFolder in myList) { // Console.WriteLine("--->>> FolderName {0} Insert Name {1} Insert Order {2}",DVIFolderName, myFolder.Name, myFolder.ManualOrder); if (myFolder.Name.CompareTo(DVIFolderName) >= 0) return (lastNum + (double) myFolder.ManualOrder) / 2.0; lastNum = myFolder.ManualOrder ?? 1.0; } return lastNum + 1; } private string GetSystem(XmlElement xe) { XmlAttribute xa = xe.Attributes["system"]; if (xa is XmlAttribute) return xa.Value; return "N/A"; } } }