728 lines
		
	
	
		
			24 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			728 lines
		
	
	
		
			24 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| 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 log4net;
 | |
| using VEPROMS.CSLA.Library;
 | |
| using Volian.Controls.Library;
 | |
| using C1.Win.C1FlexGrid;
 | |
| using System.Data.SqlClient;
 | |
| 
 | |
| namespace ConvertLocalAlarms
 | |
| {
 | |
| 	public partial class frmConvertLocalAlarms : Form
 | |
| 	{
 | |
| 		public frmConvertLocalAlarms()
 | |
| 		{
 | |
| 			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;
 | |
| 				ProcessTxt();
 | |
| 			}
 | |
| 		}
 | |
| 		private void ProcessTxtFile(string fileName)
 | |
| 		{
 | |
| 			//FileInfo fi = new FileInfo(fileName);
 | |
| 			//StreamReader sr = fi.OpenText();
 | |
| 			//ProcessHeader(sr);
 | |
| 			//ProcTextAll = tbPROMS.Text = sr.ReadToEnd();
 | |
| 			//HasSpecialCharacters(ProcTextAll);
 | |
| 			//sr.Close();
 | |
| 			//SaveTree(ProcTextAll, ProcNumber, ProcTitle);
 | |
| 			FileInfo fi = new FileInfo(fileName);
 | |
| 			FileStream sr = fi.OpenRead();
 | |
| 			byte[] buffer = new byte[fi.Length];
 | |
| 			sr.Read(buffer, 0, (int) fi.Length);
 | |
| 			string str = Encoding.UTF7.GetString(buffer).Replace("\x95", "\u2022");
 | |
| 			ProcessHeader(str);
 | |
| 			int headercount = str.IndexOf("Setpoint");
 | |
| 			headercount = str.IndexOf("\r\n", headercount);
 | |
| 			ProcTextAll = tbPROMS.Text = str.Substring(headercount + 2);
 | |
| 			sr.Close();
 | |
| 			SaveTree(ProcTextAll, ProcNumber, ProcTitle);
 | |
| 		}
 | |
| 		Regex regHeader = new Regex("([ A-Z.a-z]+) = '([^']+)'.*", RegexOptions.Compiled);
 | |
| 		private void ProcessHeader(string str)
 | |
| 		{
 | |
| 			ProcNumber="";
 | |
| 			ProcTitle="";
 | |
| 			int offset = 0;
 | |
| 			int linelength = 0;
 | |
| 			for (int i = 0; i < 5; i++)
 | |
| 			{
 | |
| 				linelength = str.IndexOf("\r\n",offset)-offset;
 | |
| 				string txt = str.Substring(offset,linelength);
 | |
| 				offset += linelength + 2;
 | |
| 				Match m = regHeader.Match(txt);
 | |
| 				switch (i)
 | |
| 				{
 | |
| 					case 0:
 | |
| 						break;
 | |
| 					case 1:
 | |
| 						if(m.Groups[1].Value == "Alarm") ProcTitle = m.Groups[2].Value;
 | |
| 						break;
 | |
| 					case 2:
 | |
| 						if(m.Groups[1].Value == "AlarmID") ProcNumber = m.Groups[2].Value;
 | |
| 						break;
 | |
| 					case 3:
 | |
| 						break;
 | |
| 					case 4:
 | |
| 						break;
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 		private void ProcessTxt()
 | |
| 		{
 | |
| 			ProcessTxtFile(tbFileName.Text);
 | |
| 		}
 | |
| 		//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);
 | |
| 		//	//XmlNode xn = xDoc.DocumentElement.LastChild.LastChild.LastChild;
 | |
| 		//	//string html = GetHtml(xn);
 | |
| 		//	//tbXML.Text = html;
 | |
| 		//}
 | |
| 		//private static string GetHtml(XmlNode xn)
 | |
| 		//{
 | |
| 		//	XmlNode pr = xn.PreviousSibling;
 | |
| 		//	XmlAttribute xa;
 | |
| 		//	string html = xn.Attributes["content"].Value;
 | |
| 		//	while (pr != null && pr.Name == "NoteInstruction")
 | |
| 		//	{
 | |
| 		//		html = MergeHTML(pr.Attributes["content"].Value, html);
 | |
| 		//		pr = pr.PreviousSibling;
 | |
| 		//	}
 | |
| 		//	return html;
 | |
| 		//}
 | |
| 
 | |
| 		//private static string MergeHTML(string part1, string part2)
 | |
| 		//{
 | |
| 		//	part1 = part1.Replace("</body></html","");
 | |
| 		//	part2 = part2.Substring(part2.IndexOf("<p"));
 | |
| 		//	return part1 + part2;
 | |
| 		//}
 | |
| 		//private string _HtmlPrefix = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">";
 | |
| 		//public string HtmlPrefix
 | |
| 		//{
 | |
| 		//	get { return _HtmlPrefix; }
 | |
| 		//	set { _HtmlPrefix = value; }
 | |
| 		//}
 | |
| 		//private void XMLChanged(string xml)
 | |
| 		//{
 | |
| 		//	Application.DoEvents();
 | |
| 		//	xml = "<?xml version='1.0' encoding='UTF-8'?>\n" + xml;
 | |
| 		//	xml = xml.Replace(HtmlPrefix, "");
 | |
| 		//	//xml = xml.Replace("\x09", "[Tab]");
 | |
| 		//	//xml = xml.Replace("text-indent:0px;\">", "text-indent:0px;\">\r\n");
 | |
| 		//	//xml = xml.Replace(" \x09", "\r\n	");
 | |
| 		//	//xml = xml.Replace("\x09", "	");
 | |
| 		//	xml = Regex.Replace(xml, "<br /></span>", "<br /> </span>");
 | |
| 		//	xml = Regex.Replace(xml, "</span><br />", "</span><br /> ");
 | |
| 		//	xml = Regex.Replace(xml, "\\<span [^<>]+\\>", "");
 | |
| 		//	xml = Regex.Replace(xml, "\\</span *\\>", "");
 | |
| 		//	xml = Regex.Replace(xml, "\\</p\\>[ \r\n]+\\<p [^<>]+\\>", "<br />\r\n");
 | |
| 		//	xml = Regex.Replace(xml, "\\<p [^<>]+\\>", "<br />\r\n");
 | |
| 		//	xml = Regex.Replace(xml, @"<br />[ \t\r\n]+\[", @"\line [");
 | |
| 		//	xml = Regex.Replace(xml, "\\</p *\\>", "");
 | |
| 		//	xml = Regex.Replace(xml, @"\]\t{4,5}", "]\r\n");
 | |
| 		//	xml = Regex.Replace(xml, "<br ?/>\t+(?![[\\u2022])", " ");
 | |
| 		//	xml = Regex.Replace(xml, "<br ?/>\t+(?![[\\u2022])", " ");
 | |
| 		//	xml = Regex.Replace(xml, "\t\t+", " ");
 | |
| 		//	xml = Regex.Replace(xml, "<br />", "\r\n");
 | |
| 		//	xml = Regex.Replace(xml, "\r\n +", "\r\n");
 | |
| 		//	xml = Regex.Replace(xml, "(\r\n){2,}", "\r\n");
 | |
| 		//	//aml = Regex.Replace(xml,"
 | |
| 		//	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);
 | |
| 		//	//FileInfo fi = new FileInfo("C:\\Temp\\Alarm.xml");
 | |
| 		//	//StreamWriter sw = fi.CreateText();
 | |
| 		//	//sw.Write(xml);
 | |
| 		//	//sw.Close();
 | |
| 		//	//XmlDocument xDoc2 = new XmlDocument();
 | |
| 		//	//// Lookfor special characters
 | |
| 		//	////FindSpecialCharacters(xml);
 | |
| 		//	//xDoc2.Load(fi.FullName);
 | |
| 		//	XmlNode xn3 = xDoc2.ChildNodes[1].ChildNodes[1].ChildNodes[0];
 | |
| 		//	string prcSerialNoFldName = GetProcInfo(xn3, 0, 0, 0);
 | |
| 		//	string prcSerialNoValue = GetProcInfo(xn3, 0, 1, 0);
 | |
| 		//	SerialNo = int.Parse(prcSerialNoValue);
 | |
| 		//	string prcTitleFldName = GetProcInfo(xn3, 1, 0, 0);
 | |
| 		//	string prcTitleValue = GetProcInfo(xn3, 1, 1, 0);
 | |
| 		//	string prcNumberFldName = GetProcInfo(xn3, 2, 0, 0);
 | |
| 		//	string prcNumberValue = GetProcInfo(xn3, 2, 1, 0);
 | |
| 		//	string prcSourceFldName = GetProcInfo(xn3, 3, 0, 0);
 | |
| 		//	string prcSourceValue = GetProcInfo(xn3, 3, 1, 0);
 | |
| 		//	string prcSetpointFldName = GetProcInfo(xn3, 4, 0, 0);
 | |
| 		//	string prcSetpointValue = GetProcInfo(xn3, 4, 1, 0);
 | |
| 		//	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 = 1; i < xDoc2.ChildNodes[1].ChildNodes[1].ChildNodes.Count; i++)
 | |
| 		//	{
 | |
| 		//		XmlNode xn2 = xDoc2.ChildNodes[1].ChildNodes[1].ChildNodes[i];
 | |
| 		//		sbAllText.Append(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;
 | |
| 		private void SaveTree(string text, string procNumber, string procTitle)
 | |
| 		{
 | |
| 			tv.Nodes.Clear();
 | |
| 			MemoryStream ms = GetMemoryStream(text);
 | |
| 			using (TextReader tr = new StreamReader(ms))
 | |
| 			{
 | |
| 				Dictionary<int, TreeNode> lookup = new Dictionary<int, TreeNode>();
 | |
| 				lookup.Add(0, tv.Nodes.Add(string.Format("{0} - {1}", procNumber, procTitle)));
 | |
| 				int level = 0;
 | |
| 				int lastLevel = 0;
 | |
| 				int lastIndent = 0;
 | |
| 				int extra = 0;
 | |
| 				string lastTab = "";
 | |
| 				Queue<string> enQueue = null;
 | |
| 				Queue<string> deQueue = null;
 | |
| 				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 == "NOTE")
 | |
| 							enQueue = new Queue<string>();
 | |
| 						if (lineText.StartsWith("<NOTE>"))
 | |
| 						{
 | |
| 							enQueue = new Queue<string>();
 | |
| 							enQueue.Enqueue("NOTE");
 | |
| 						}
 | |
| 						lineText = lineText.Replace("<NOTE>", "");
 | |
| 					}
 | |
| 					// Strip XML Tags
 | |
| 					lineText = Regex.Replace(lineText, "<[^<>]+>", "");
 | |
| 					if (lineText.Replace("\t", "") != "")
 | |
| 					{
 | |
| 						Match m = Regex.Match(lineText, @"^(\t*)([1-9][0-9]*\.0|[1-9][0-9]*\.[1-9][0-9]*|[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*|\u2022)([\t ]+)([^\u2022]*)$", RegexOptions.Multiline);
 | |
| 						string tab = m.Groups[2].Value;
 | |
| 						int indent = m.Groups[1].Value.Length;
 | |
| 						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 = 1 + tab.Length - tab.Replace(".","").Length;
 | |
| 							if (deQueue == null && enQueue != null)
 | |
| 							{
 | |
| 								deQueue = enQueue;
 | |
| 								enQueue = null;
 | |
| 							}
 | |
| 						}
 | |
| 						else if (tab == "") // Paragraph
 | |
| 						{
 | |
| 							if (Regex.IsMatch(lineText, "(NOTE|NOTES|CAUTION|CAUTIONS)")) extra = 0;
 | |
| 							level = lastLevel + 1;
 | |
| 						}
 | |
| 						else if (tab == "\u2022")//bullet
 | |
| 							level = indent + 2;
 | |
| 						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 (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);
 | |
| 						}
 | |
| 						else
 | |
| 						{
 | |
| 							enQueue.Enqueue(lineText);
 | |
| 						}
 | |
| 						lastTab = tab;
 | |
| 						lastLevel = level;
 | |
| 						lastIndent = indent;
 | |
| 					}
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 		//private ItemInfo FindPrevious(SortedDictionary<int, ItemInfo> 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)
 | |
| 		//{
 | |
| 		//	return xn3.ChildNodes[p1].ChildNodes[p2].ChildNodes[p3].Value.Trim("\r\n ".ToCharArray());
 | |
| 		//}
 | |
| 		//private bool _UpdateHTML = true;
 | |
| 		//public bool UpdateHTML
 | |
| 		//{
 | |
| 		//	get { return _UpdateHTML; }
 | |
| 		//	set { _UpdateHTML = value; }
 | |
| 		//}
 | |
| 		private string IndentifySpecialCharacters(string txt)
 | |
| 		{
 | |
| 			StringBuilder sb = new StringBuilder();
 | |
| 			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)
 | |
| 		{
 | |
| 			ProcessTxt();
 | |
| 		}
 | |
| 		//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("<table"))
 | |
| 		//			fNext = fColor = Color.PaleGreen;
 | |
| 		//		else if (fmt == "</table>")
 | |
| 		//			fNext = Color.PaleTurquoise;
 | |
| 		//		else if (fmt == "<br />")
 | |
| 		//			fColor = Color.PeachPuff;
 | |
| 		//		else if (fmt == "</p>")
 | |
| 		//			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 double GetMyOrder(Csla.SortedBindingList<FolderInfo> 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 void tmr_Tick(object sender, EventArgs e)
 | |
| 		{
 | |
| 			tmr.Enabled = false;
 | |
| 			// If timer on the its ready to proccess
 | |
| 					int idnew = 0;			
 | |
| 			string str = AutoFolder;
 | |
| 			if (str != null && str.Length > 5)
 | |
| 			{
 | |
| 				
 | |
| 				DirectoryInfo di = new DirectoryInfo(str);
 | |
| 				DocVersionInfo dvi = DocVersionInfo.Get((int)cmbDocVersion.SelectedValue);
 | |
| 				VEPROMS.CSLA.Library.FolderInfo grandParent = dvi.ActiveParent.ActiveParent as FolderInfo;
 | |
| 				using (VEPROMS.CSLA.Library.Folder flder = MakeFolder(str, grandParent))
 | |
| 				{
 | |
| 					ROFstInfo fst = dvi.DocVersionAssociations[0].MyROFst;
 | |
| 					flder.ManualOrder = 0;
 | |
| 					double myOrder = GetMyOrder(grandParent.SortedChildFolders, str); 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;
 | |
| 					}
 | |
| 				}
 | |
| 
 | |
| 				ProcessFolder(di, DocVersionInfo.Get(idnew));
 | |
| 			}
 | |
| 			this.Close();
 | |
| 		}
 | |
| 
 | |
| 		private static Folder MakeFolder(string str, VEPROMS.CSLA.Library.FolderInfo grandParent)
 | |
| 		{
 | |
| 			int num = 0;
 | |
| 			foreach(FolderInfo chld in grandParent.ChildFolders)
 | |
| 			{
 | |
| 				if(chld.Name.StartsWith(str))
 | |
| 				{
 | |
| 					if(chld.Name.StartsWith(str + "."))
 | |
| 					{
 | |
| 						string str2=chld.Name.Substring(str.Length+1);
 | |
| 						num = Math.Max(int.Parse(str2)+1,num);
 | |
| 					}
 | |
| 					else num=1;
 | |
| 				}
 | |
| 			}
 | |
| 			return Folder.MakeFolder(grandParent.Get(), null, str+(num==0?"":"." + num.ToString()), str, str.Substring(12, 2), null, 1, null);
 | |
| 		}
 | |
| 
 | |
| 		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 void frmConvertAlarms_Load(object sender, EventArgs e)
 | |
| 		{
 | |
| 			_MyFlexGrid = new VlnFlexGrid();
 | |
| 			LoadSettings();
 | |
| 			SetEventHandlers();
 | |
| 			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)
 | |
| 		{
 | |
| 		}
 | |
| 
 | |
| 		//private void rtbXML_SelectionChanged(object sender, EventArgs e)
 | |
| 		//{
 | |
| 		//}
 | |
| 		//private void tbXML_TextChanged(object sender, EventArgs e)
 | |
| 		//{
 | |
| 		//	if (UpdateHTML)
 | |
| 		//	{
 | |
| 		//		htmlChanged(tbXML.Text);
 | |
| 		//		XMLChanged(tbXML.Text);
 | |
| 		//		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)
 | |
| 		{
 | |
| 			DocVersionInfo dvi = DocVersionInfo.Get((int)cmbDocVersion.SelectedValue);
 | |
| 			try
 | |
| 			{
 | |
| 				SaveProcedure(ProcTextAll, ProcNumber, ProcTitle, dvi);
 | |
| 			}
 | |
| 			catch (Exception ex)
 | |
| 			{
 | |
| 				Console.WriteLine("Error: {0}.{1} {2} {3}",dvi.MyFolder.Name,ProcNumber, ex.GetType().Name, ex.Message);
 | |
| 			}
 | |
| 		}
 | |
| 		//SortedDictionary<int, ItemInfo> dicSerialNo;
 | |
| 		private void btnAll_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			//dicSerialNo = new SortedDictionary<int, ItemInfo>();
 | |
| 			FileInfo fi = new FileInfo(tbFileName.Text);
 | |
| 			DirectoryInfo di = fi.Directory;
 | |
| 			// Loop through list
 | |
| 			DocVersionInfo dvi = DocVersionInfo.Get((int)cmbDocVersion.SelectedValue);
 | |
| 			ProcessFolder(di,dvi);
 | |
| 		}
 | |
| 
 | |
| 		private void ProcessFolder(DirectoryInfo di, DocVersionInfo dvi)
 | |
| 		{
 | |
| 			runOne = false;
 | |
| 			// Get List of files
 | |
| 			//DocVersionInfo dvi = DocVersionInfo.Get((int)cmbDocVersion.SelectedValue);
 | |
| 			foreach (FileInfo f in di.GetFiles("*.txt"))
 | |
| 			{
 | |
| 				if (f.Name.StartsWith("AlarmData") == false && f.Name.Length > 14)
 | |
| 				{
 | |
| 					tsslStatus.Text = f.Name;
 | |
| 					Application.DoEvents();
 | |
| 					// Process each file
 | |
| 					try
 | |
| 					{
 | |
| 						ProcessTxtFile(f.FullName);
 | |
| 						// Convert each file
 | |
| 						//SaveProcedure(ProcTextAll, ProcNumber, ProcTitle, SerialNo);
 | |
| 						SaveProcedure(ProcTextAll, ProcNumber, ProcTitle, dvi);
 | |
| 					}
 | |
| 					catch (Exception ex)
 | |
| 					{
 | |
| 						Console.WriteLine("Error: {0}.{1} {2} {3}", di.Name, f.Name, ex.GetType().Name, ex.Message);
 | |
| 					}
 | |
| 
 | |
| 					//SaveProcedure(ProcTextAll, ProcNumber, ProcTitle, dvi);
 | |
| 				}
 | |
| 			}
 | |
| 			runOne = true;
 | |
| 		}
 | |
| 
 | |
| 		private void statusStrip1_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			if (tbPROMS.SelectedText != "")
 | |
| 			{
 | |
| 				tsslStatus.Text = string.Format("Selection = '{0}'", IndentifySpecialCharacters(tbPROMS.SelectedText));
 | |
| 				Clipboard.Clear();
 | |
| 				Clipboard.SetText(IndentifySpecialCharacters(tbPROMS.SelectedText));
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
 | |
| 		{
 | |
| 			if (tbPROMS.SelectedText != "")
 | |
| 			{
 | |
| 				tsslStatus.Text = string.Format("Selection = '{0}'", IndentifySpecialCharacters(tbPROMS.SelectedText));
 | |
| 				Clipboard.Clear();
 | |
| 				Clipboard.SetText(IndentifySpecialCharacters(tbPROMS.SelectedText));
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| }
 |