using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WestinghouseROImport { public partial class frmROImport : Form { public string MyStatus { get { return tsslStatus.Text; } set { tsslStatus.Text = value; Application.DoEvents(); } } public frmROImport() { InitializeComponent(); } private string _STPDBRecID = ""; public string STPDBRecID { get { return _STPDBRecID; } set { _STPDBRecID = value; } } private void clearOldSetpointData_Click(object sender, EventArgs e) { int count = ClearSetpointData(); MessageBox.Show(string.Format("{0} setpoint records deleted", count), "Purge", MessageBoxButtons.OK, MessageBoxIcon.Information); } private int ClearSetpointData() { STPTableAdapter.Fill(this.rOMasterDataSet.RO000002); DataTable dto = STPTableAdapter.GetData(); List deleteList = new List(); foreach (DataRow dr in dto.Rows) { if (int.Parse(dr["RecType"].ToString()) == 3) // Remove Grouping { if (dr["ParentID"].ToString() != "00000000") { deleteList.Add(dr); } else { STPDBRecID = dr["RecID"].ToString(); } } if (int.Parse(dr["RecType"].ToString()) == 5) // Remove ROs { deleteList.Add(dr); } } int count = deleteList.Count; while (deleteList.Count > 0) { DataRow dr = deleteList[0]; dr.Delete(); STPTableAdapter.Update(dr); deleteList.RemoveAt(0); } return count; } private Dictionary _SetpointParameters; public Dictionary SetpointParameters { get { return _SetpointParameters; } set { _SetpointParameters = value; } } private DataRow _DrCount; public DataRow DrCount { get { return _DrCount; } set { _DrCount = value; } } private void importSetpointData_Click(object sender, EventArgs e) { DateTime dtStart = DateTime.Now; ClearSetpointData(); STPTableAdapter.Fill(this.rOMasterDataSet.RO000002); STPImportTableAdapter.Fill(this.rOImportDataSet.ImportSTP_qry); DataTable dto = STPTableAdapter.GetData(); DrCount = dto.Rows[0]; DataTable dti = STPImportTableAdapter.GetData(); SetpointParameters = new Dictionary(); foreach (DataRow dr in dti.Rows) { // Parameter Name Value Description //Console.WriteLine("Parameter = '{0}', Name = '{1}', Value = '{2}', Description = '{3}'", // dr["Parameter"], dr["Name"], dr["Value"], dr["Description"]); MyStatus = dr["Name"].ToString(); AddSetpoint(dr["Parameter"].ToString(), dr["Name"].ToString(), dr["Value"].ToString(), dr["Description"].ToString()); } STPTableAdapter.Update(DrCount); DateTime dtEnd = DateTime.Now; MyStatus = string.Format("{0} Setpoint ROs added in {1} seconds", dti.Rows.Count,TimeSpan.FromTicks(dtEnd.Ticks - dtStart.Ticks).TotalSeconds); MessageBox.Show(string.Format("{0} ROs added", dti.Rows.Count), "ROs Loaded", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void AddSetpoint(string parameter, string id, string value, string description) { string parentid = AddSetpointParameter(parameter); string recid = GetNextSTPRecID(); string rovalue = BuildSTPROValue(id, value, description); STPTableAdapter.Insert(recid, 5, parentid, id, DateTimeStamp, rovalue); } public string DateTimeStamp { get {return DateTime.Now.ToString("yyyyMMddHHmm");} } private string GetNextSTPRecID() { string nextRec = DrCount["Info"].ToString(); nextRec = string.Format("{0:x08}", Convert.ToInt32(nextRec,16) + 1); DrCount["Info"] = nextRec; //STPTableAdapter.Update(DrCount); //Console.WriteLine("ID = {0}", nextRec); return nextRec; } private string BuildSTPROValue(string id, string value, string description) { value = FixSpecialCharacters(value); description = FixSpecialCharacters(description); return string.Format("{1}{0}{2}" ,id,value,description); } private string FixSpecialCharacters(string str) { string str2 = str.Trim(); StringBuilder sb = new StringBuilder(); foreach (char c in str2) { switch (c) { case '"': sb.Append("""); break; case '&': sb.Append("&"); break; case '<': sb.Append("<"); break; case '>': sb.Append(">"); break; case '\xA0': sb.Append(' '); break; case '\x1E': sb.Append('-'); break; case '\xB0': sb.Append(c); break; case '\u2013': sb.Append('-'); break; default: if (c < ' ' || c > '\x7F') { sb.Append(string.Format("[x{0:X}]", (int)c)); } else sb.Append(c); break; } } return sb.ToString(); } private string AddSetpointParameter(string parameter) { if (!SetpointParameters.ContainsKey(parameter)) { string recid = GetNextSTPRecID(); string paramValue = BuildSTPParam(parameter); STPTableAdapter.Insert(recid, 3, STPDBRecID, null, DateTimeStamp, paramValue); SetpointParameters.Add(parameter, recid); } return SetpointParameters[parameter]; } private string BuildSTPParam(string parameter) { return string.Format("{0}", parameter); } private void clearOldMELData_Click(object sender, EventArgs e) { // Clear Old MEL Data int count = ClearMELData(); MessageBox.Show(string.Format("{0} MEL records deleted", count), "Purge", MessageBoxButtons.OK, MessageBoxIcon.Information); } private string MELDBRecID; private int ClearMELData() { MELTableAdapter.Fill(this.rOMasterDataSet.RO000003); DataTable dto = MELTableAdapter.GetData(); List deleteList = new List(); foreach (DataRow dr in dto.Rows) { if (int.Parse(dr["RecType"].ToString()) == 3) // Remove Grouping { if (dr["ParentID"].ToString() != "00000000") { deleteList.Add(dr); } else { MELDBRecID = dr["RecID"].ToString(); } } if (int.Parse(dr["RecType"].ToString()) == 5) // Remove ROs { deleteList.Add(dr); } } int count = deleteList.Count; while (deleteList.Count > 0) { DataRow dr = deleteList[0]; dr.Delete(); MELTableAdapter.Update(dr); deleteList.RemoveAt(0); } return count; } Dictionary _MELSystems; public Dictionary MELSystems { get { return _MELSystems; } set { _MELSystems = value; } } Dictionary _MELSysComp; public Dictionary MELSysComps { get { return _MELSysComp; } set { _MELSysComp = value; } } private void importMELData_Click(object sender, EventArgs e) { DateTime dtStart = DateTime.Now; ClearMELData(); MELTableAdapter.Fill(this.rOMasterDataSet.RO000003); MELImportTableAdapter.Fill(this.rOImportDataSet.ImportMEL_qry); DataTable dto = MELTableAdapter.GetData(); DrCount = dto.Rows[0]; DataTable dti = MELImportTableAdapter.GetData(); MELSystems = new Dictionary(); MELSysComps = new Dictionary(); int recsAdded = 0; DateTime justASecHoney = DateTime.Now + TimeSpan.FromSeconds(10); int lastAdded = 0; DateTime lastTime = DateTime.Now; foreach (DataRow dr in dti.Rows) { recsAdded++; // Parameter Name Value Description //Console.WriteLine("Parameter = '{0}', Name = '{1}', Value = '{2}', Description = '{3}'", // dr["Parameter"], dr["Name"], dr["Value"], dr["Description"]); MyStatus = dr["FullName"].ToString(); AddMEL(dr["SystemID"].ToString(), dr["SystemDesc"].ToString(), dr["ComponentID"].ToString(), dr["CompDesc"].ToString() , dr["FullName"].ToString(), dr["ShortName"].ToString(), dr["Room"].ToString(), dr["Description"].ToString(), dr["CommonDesc"].ToString()); DateTime tNow = DateTime.Now; if (tNow > justASecHoney) { int remaining = dti.Rows.Count - recsAdded; TimeSpan elapsed = tNow - lastTime; TimeSpan total = tNow - dtStart; int processed = recsAdded - lastAdded; lastTime = tNow; lastAdded = recsAdded; DateTime eta1 = tNow + TimeSpan.FromTicks(elapsed.Ticks * remaining / processed); DateTime eta2 = tNow + TimeSpan.FromTicks(total.Ticks * remaining / recsAdded); AddStatusText("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", tNow.ToString("HH:mm:ss"), processed, recsAdded, remaining, eta1.ToString("HH:mm:ss"), eta2.ToString("HH:mm:ss")); justASecHoney += TimeSpan.FromSeconds(10); } } AddStatusText("{0}\t{1}\t{2}\t{3}", DateTime.Now.ToString("HH:mm:ss"), recsAdded - lastAdded, recsAdded, 0); MELTableAdapter.Update(DrCount); DateTime dtEnd = DateTime.Now; MyStatus = string.Format("{0} MEL ROs added in {1} seconds", dti.Rows.Count, TimeSpan.FromTicks(dtEnd.Ticks - dtStart.Ticks).TotalSeconds); MessageBox.Show(string.Format("{0} MEL ROs added", dti.Rows.Count), "ROs Loaded", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void AddMEL(string systemID, string systemDesc, string ComponentID, string CompDesc, string FullName, string ShortName, string Room, string Description, string CommonDesc) { string parentid = AddMELSystemComponent(systemID,systemDesc,ComponentID,CompDesc); string recid = GetNextMELRecID(); string rovalue = BuildMELROValue(FullName,ShortName,Room,Description,CommonDesc); MELTableAdapter.Insert(recid, 5, parentid, FullName, DateTimeStamp, rovalue); } private string BuildMELROValue(string FullName, string ShortName, string Room, string Description, string CommonDesc) { FullName = FixSpecialCharacters(FullName); ShortName = FixSpecialCharacters(ShortName); Room = FixSpecialCharacters(Room); Description = FixSpecialCharacters(Description); CommonDesc = FixSpecialCharacters(CommonDesc); return string.Format("{1}{0}" + "{3}{2}",FullName,ShortName,Room,Description, CommonDesc); // ComonDesc will not load because it has no token {4} } private string GetNextMELRecID() { string nextRec = DrCount["Info"].ToString(); nextRec = string.Format("{0:x08}", Convert.ToInt32(nextRec, 16) + 1); DrCount["Info"] = nextRec; //MELTableAdapter.Update(DrCount); //Console.WriteLine("ID = {0}", nextRec); return nextRec; } private string AddMELSystemComponent(string systemID, string systemDesc, string ComponentID, string CompDesc) { string key = systemID + "|" + ComponentID; if (!MELSysComps.ContainsKey(key)) { string sysRecID = AddMELSystem(systemID, systemDesc); string recid = GetNextMELRecID(); string compValue = BuildMELComponent(ComponentID,CompDesc); MELTableAdapter.Insert(recid, 3, sysRecID, null, DateTimeStamp, compValue); MELSysComps.Add(key, recid); } return MELSysComps[key]; } private string BuildMELComponent(string ComponentID, string CompDesc) { ComponentID = FixSpecialCharacters(ComponentID); CompDesc = FixSpecialCharacters(CompDesc); return string.Format("{1}" + "{0}", ComponentID, CompDesc); } private string AddMELSystem(string systemID, string systemDesc) { if (!MELSystems.ContainsKey(systemID)) { string recid = GetNextMELRecID(); string sysValue = BuildMELSystem(systemID,systemDesc); MELTableAdapter.Insert(recid, 3, MELDBRecID, null, DateTimeStamp, sysValue); MELSystems.Add(systemID, recid); } return MELSystems[systemID]; } private string BuildMELSystem(string systemID, string systemDesc) { systemID = FixSpecialCharacters(systemID); systemDesc = FixSpecialCharacters(systemDesc); return string.Format("{1}{0}", systemID, systemID); } private void AddStatusText(string format, params object []args) { tbStatus.Select(tbStatus.TextLength, 0); tbStatus.SelectedText=string.Format(format, args) + "\r\n"; } private void clearOldARPData_Click(object sender, EventArgs e) { ClearARPData(); } private string ARPDBRecID; private int ClearARPData() { ARPTableAdapter.Fill(this.rOMasterDataSet.RO000004); DataTable dto = ARPTableAdapter.GetData(); List deleteList = new List(); foreach (DataRow dr in dto.Rows) { if (int.Parse(dr["RecType"].ToString()) == 3) // Remove Grouping { if (dr["ParentID"].ToString() != "00000000") { deleteList.Add(dr); } else { ARPDBRecID = dr["RecID"].ToString(); } } if (int.Parse(dr["RecType"].ToString()) == 5) // Remove ROs { deleteList.Add(dr); } } int count = deleteList.Count; while (deleteList.Count > 0) { DataRow dr = deleteList[0]; dr.Delete(); ARPTableAdapter.Update(dr); deleteList.RemoveAt(0); } return count; } private Dictionary _ARPDocuments; public Dictionary ARPDocuments { get { return _ARPDocuments; } set { _ARPDocuments = value; } } private Dictionary _ARPSystems; public Dictionary ARPSystems { get { return _ARPSystems; } set { _ARPSystems = value; } } private void importARPData_Click(object sender, EventArgs e) { ARPImportTableAdapter.Fill(this.rOImportDataSet.ImportARP_tbl); DateTime dtStart = DateTime.Now; ClearARPData(); ARPTableAdapter.Fill(this.rOMasterDataSet.RO000004); ARPImportTableAdapter.Fill(this.rOImportDataSet.ImportARP_tbl); DataTable dto = ARPTableAdapter.GetData(); DrCount = dto.Rows[0]; DataTable dti = ARPImportTableAdapter.GetData(); ARPDocuments = new Dictionary(); ARPSystems = new Dictionary(); int recsAdded = 0; DateTime justASecHoney = DateTime.Now + TimeSpan.FromSeconds(10); int lastAdded = 0; DateTime lastTime = DateTime.Now; foreach (DataRow dr in dti.Rows) { recsAdded++; // Parameter Name Value Description //Console.WriteLine("Parameter = '{0}', Name = '{1}', Value = '{2}', Description = '{3}'", // dr["Parameter"], dr["Name"], dr["Value"], dr["Description"]); MyStatus = dr["Alarm"].ToString(); AddARP(dr["Document"].ToString(), dr["Alarm"].ToString(), dr["PointName"].ToString(), dr["Type"].ToString() , dr["Value"].ToString(), dr["Description"].ToString(), dr["SystemID"].ToString(), dr["SysTitle"].ToString()); DateTime tNow = DateTime.Now; if (tNow > justASecHoney) { int remaining = dti.Rows.Count - recsAdded; TimeSpan elapsed = tNow - lastTime; TimeSpan total = tNow - dtStart; int processed = recsAdded - lastAdded; lastTime = tNow; lastAdded = recsAdded; DateTime eta1 = tNow + TimeSpan.FromTicks(elapsed.Ticks * remaining / processed); DateTime eta2 = tNow + TimeSpan.FromTicks(total.Ticks * remaining / recsAdded); AddStatusText("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", tNow.ToString("HH:mm:ss"), processed, recsAdded, remaining, eta1.ToString("HH:mm:ss"), eta2.ToString("HH:mm:ss")); justASecHoney += TimeSpan.FromSeconds(10); } } AddStatusText("{0}\t{1}\t{2}\t{3}", DateTime.Now.ToString("HH:mm:ss"), recsAdded - lastAdded, recsAdded, 0); ARPTableAdapter.Update(DrCount); DateTime dtEnd = DateTime.Now; MyStatus = string.Format("{0} ARP ROs added in {1} seconds", dti.Rows.Count, TimeSpan.FromTicks(dtEnd.Ticks - dtStart.Ticks).TotalSeconds); MessageBox.Show(string.Format("{0} ARP ROs added", dti.Rows.Count), "ROs Loaded", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void AddARP(string document, string alarm, string pointName, string type, string value, string description, string systemID, string systemTitle) { string parentid = AddARPDocumentSystem(document,systemID,systemTitle); string recid = GetNextARPRecID(); string rovalue = BuildARPROValue(alarm, pointName, type, value, description, systemID); ARPTableAdapter.Insert(recid, 5, parentid, alarm, DateTimeStamp, rovalue); } private string BuildARPROValue(string alarm, string pointName, string type, string value, string description, string systemID) { alarm = FixSpecialCharacters(alarm); pointName = FixSpecialCharacters(pointName); type = FixSpecialCharacters(type); value = FixSpecialCharacters(value); description = FixSpecialCharacters(description); systemID = FixSpecialCharacters(systemID); return string.Format("{0}{1}{2}" + "{3}{4}{5}", alarm,pointName,type,value,description,systemID); } private string GetNextARPRecID() { string nextRec = DrCount["Info"].ToString(); nextRec = string.Format("{0:x08}", Convert.ToInt32(nextRec, 16) + 1); DrCount["Info"] = nextRec; return nextRec; } private string AddARPDocumentSystem(string document, string systemID, string systemTitle) { if (!ARPDocuments.ContainsKey(document)) { string recid = GetNextARPRecID(); string documentValue = BuildARPDocument(document); ARPTableAdapter.Insert(recid, 3, ARPDBRecID, null, DateTimeStamp, documentValue); ARPDocuments.Add(document, recid); } if(document != "None") return ARPDocuments[document]; string parentID = ARPDocuments[document]; if (!ARPSystems.ContainsKey(systemID)) { string recid = GetNextARPRecID(); string documentValue = BuildARPSystem(systemID,systemTitle); ARPTableAdapter.Insert(recid, 3, parentID , null, DateTimeStamp, documentValue); ARPSystems.Add(systemID, recid); } return ARPSystems[systemID]; } private string BuildARPSystem(string systemID, string systemTitle) { systemID = FixSpecialCharacters(systemID); systemTitle = FixSpecialCharacters(systemTitle); return string.Format("{1}{0}", systemID, systemTitle); } private string BuildARPDocument(string document) { if(document != "None") return string.Format("{0}", document); else return string.Format("{0}",document); } private void updateToCPPSetpoints_Click(object sender, EventArgs e) { Dictionary parentCount = new Dictionary(); Dictionary parentDictionary = new Dictionary(); Dictionary roDictionary = new Dictionary(); ROMasterDataSet.RO000002DataTable dto = STPTableAdapter.GetData(); BuildSTPDictionaries(dto, parentCount, parentDictionary, roDictionary); STPCPPImportTableAdapter.Fill(this.rOCPPImportDataSet.ImportSTP_qry); ROCPPImportDataSet.ImportSTP_qryDataTable dti = STPCPPImportTableAdapter.GetData(); int updateCount = 0; int updatePCount = 0; foreach (DataRow dr in dti.Rows) { string accPageID = dr["Name"].ToString().Trim(); if (roDictionary.ContainsKey(accPageID)) { DataRow dro = roDictionary[accPageID]; roDictionary.Remove(accPageID); string info = BuildSTPROValue(dr["Name"].ToString(), dr["Value"].ToString(), dr["Description"].ToString()); string infoOld = dro["Info"].ToString(); if (info != infoOld) { dro["Info"] = info; dro["ModDateTime"] = DateTimeStamp; STPTableAdapter.Update(dro); MyStatus = "Updating " + accPageID; AddStatusText("Updating {0}", accPageID); updateCount++; } } else { //if dro is null because accpageid does not exist, need to add including figuring out parent status and adding parent if it does not exist //get parent for new ro //see if parent exists MessageBox.Show("oh oh, new ro exists"); } } MyStatus = string.Format("{0} ROs Updated", updateCount); AddStatusText("RO Rows Updated: {0}", updateCount); // What has not been processed updateCount = 0; foreach (string key in roDictionary.Keys) { DataRow dr = roDictionary[key]; string parentID = dr["ParentID"].ToString().Trim(); dr.Delete(); STPTableAdapter.Update(dr); MyStatus = string.Format("Deleting {0}", key); AddStatusText("Deleting {0}", key); updateCount++; parentCount[parentID]--; if (parentCount[parentID] == 0) { DataRow drp = parentDictionary[parentID]; string grandparentID = drp["ParentID"].ToString().Trim(); drp.Delete(); STPTableAdapter.Update(drp); MyStatus = string.Format("Deleting Parent {0}", parentID); AddStatusText("Deleting Parent {0}", parentID); updatePCount++; parentCount[grandparentID]--; if (parentCount[grandparentID] == 0) { DataRow drgp = parentDictionary[grandparentID]; drgp.Delete(); STPTableAdapter.Update(drgp); MyStatus = string.Format("Deleting GrandParent {0}", grandparentID); AddStatusText("Deleting GrandParent {0}", grandparentID); updatePCount++; } } } MyStatus = string.Format("{0} ROs Deleted, {1} RO Parent/GrandParent Ros Deleted", updateCount, updatePCount); AddStatusText("RO Rows Deleted: {0}, RO Parent/GrandParent Rows Deleted {1}", updateCount, updatePCount); } private void BuildSTPDictionaries(ROMasterDataSet.RO000002DataTable dto, Dictionary parentCount, Dictionary parentRow, Dictionary dataRow) { foreach (DataRow dr in dto.Rows) { if (int.Parse(dr["RecType"].ToString()) == 3) // Remove Grouping { if (dr["ParentID"].ToString() != "00000000") { parentRow.Add(dr["RecID"].ToString().Trim(), dr); AddToParentCount(parentCount, dr["ParentID"].ToString().Trim()); } } if (int.Parse(dr["RecType"].ToString()) == 5) // Remove ROs { string accPageID = dr["AccPageID"].ToString().Trim(); dataRow.Add(accPageID, dr); AddToParentCount(parentCount, dr["ParentID"].ToString().Trim()); } } } private void BuildARPDictionaries(ROMasterDataSet.RO000004DataTable dto, Dictionary parentCount, Dictionary parentRow, Dictionary dataRow) { foreach (DataRow dr in dto.Rows) { if (int.Parse(dr["RecType"].ToString()) == 3) // Remove Grouping { if (dr["ParentID"].ToString() != "00000000") { parentRow.Add(dr["RecID"].ToString().Trim(), dr); AddToParentCount(parentCount, dr["ParentID"].ToString().Trim()); } } if (int.Parse(dr["RecType"].ToString()) == 5) // Remove ROs { string accPageID = dr["AccPageID"].ToString().Trim(); dataRow.Add(accPageID, dr); AddToParentCount(parentCount, dr["ParentID"].ToString().Trim()); } } } private void AddToParentCount(Dictionary parentCount, string parentID) { if (!parentCount.ContainsKey(parentID)) parentCount.Add(parentID, 0); parentCount[parentID]++; } private void BuildMELDictionaries(ROMasterDataSet.RO000003DataTable dto, Dictionary parentCount, Dictionary parentRow, Dictionary dataRow) { foreach (DataRow dr in dto.Rows) { if (int.Parse(dr["RecType"].ToString()) == 3) // Remove Grouping { if (dr["ParentID"].ToString() != "00000000") { parentRow.Add(dr["RecID"].ToString().Trim(), dr); AddToParentCount(parentCount, dr["ParentID"].ToString().Trim()); } } if (int.Parse(dr["RecType"].ToString()) == 5) // Remove ROs { string accPageID = dr["AccPageID"].ToString().Trim(); dataRow.Add(accPageID, dr); AddToParentCount(parentCount, dr["ParentID"].ToString().Trim()); } } } private void updateToCPPEquipment_Click(object sender, EventArgs e) { Dictionary parentCount = new Dictionary(); Dictionary parentDictionary = new Dictionary(); Dictionary roDictionary = new Dictionary(); ROMasterDataSet.RO000003DataTable dto = MELTableAdapter.GetData(); BuildMELDictionaries(dto, parentCount, parentDictionary, roDictionary); MELCPPImportTableAdapter.Fill(this.rOCPPImportDataSet.ImportMEL_qry); ROCPPImportDataSet.ImportMEL_qryDataTable dti = MELCPPImportTableAdapter.GetData(); int updateCount = 0; int updatePCount = 0; foreach (DataRow dr in dti.Rows) { string accPageID = dr["FullName"].ToString().Trim(); if (roDictionary.ContainsKey(accPageID)) { DataRow dro = roDictionary[accPageID]; roDictionary.Remove(accPageID); string info = BuildMELROValue(dr["Fullname"].ToString(), dr["ShortName"].ToString(), dr["Room"].ToString(), dr["Description"].ToString(), dr["CommonDesc"].ToString()); string infoOld = dro["Info"].ToString(); if (info != infoOld) { dro["Info"] = info; dro["ModDateTime"] = DateTimeStamp; MELTableAdapter.Update(dro); MyStatus = "Updating " + accPageID; AddStatusText("Updating {0}", accPageID); updateCount++; } } else { //if dro is null because accpageid does not exist, need to add including figuring out parent status and adding parent if it does not exist //get parent for new ro //see if parent exists AddStatusText("********** new mel item '{0}' **********", accPageID); } } MyStatus = string.Format("{0} ROs Updated", updateCount); AddStatusText("RO Rows Updated: {0}", updateCount); // What has not been processed updateCount = 0; foreach (string key in roDictionary.Keys) { if (key == "CCS-EJ-PLV200") System.Threading.Thread.Sleep(1000); DataRow dr = roDictionary[key]; string parentID = dr["ParentID"].ToString().Trim(); dr.Delete(); MELTableAdapter.Update(dr); MyStatus = string.Format("Deleting {0}", key); AddStatusText("Deleting '{0}'", key); updateCount++; parentCount[parentID]--; if (parentCount[parentID] == 0) { DataRow drp = parentDictionary[parentID]; string grandparentID = drp["ParentID"].ToString().Trim(); drp.Delete(); MELTableAdapter.Update(drp); MyStatus = string.Format("Deleting Parent {0}", parentID); AddStatusText("Deleting Parent {0}", parentID); updatePCount++; parentCount[grandparentID]--; if (parentCount[grandparentID] == 0) { DataRow drgp = parentDictionary[grandparentID]; drgp.Delete(); MELTableAdapter.Update(drgp); MyStatus = string.Format("Deleting GrandParent {0}", grandparentID); AddStatusText("Deleting GrandParent {0}", grandparentID); updatePCount++; } } } MyStatus = string.Format("{0} ROs Deleted, {1} RO Parent/GrandParent Ros Deleted", updateCount, updatePCount); AddStatusText("RO Rows Deleted: {0}, RO Parent/GrandParent Rows Deleted {1}", updateCount, updatePCount); } private void updateToCPPAlarms_Click(object sender, EventArgs e) { Dictionary parentCount = new Dictionary(); Dictionary parentDictionary = new Dictionary(); Dictionary roDictionary = new Dictionary(); ROMasterDataSet.RO000004DataTable dto = ARPTableAdapter.GetData(); BuildARPDictionaries(dto, parentCount, parentDictionary, roDictionary); //why is this not a query versus a table ARPCPPImportTableAdapter.Fill(this.rOCPPImportDataSet.ImportARP_tbl); ROCPPImportDataSet.ImportARP_tblDataTable dti = ARPCPPImportTableAdapter.GetData(); int updateCount = 0; int updatePCount = 0; int addCount = 0; foreach (DataRow dr in dti.Rows) { string accPageID = dr["Alarm"].ToString().Trim(); if (roDictionary.ContainsKey(accPageID)) { DataRow dro = roDictionary[accPageID]; roDictionary.Remove(accPageID); string info = BuildARPROValue(dr["Alarm"].ToString(), dr["PointName"].ToString(), dr["Type"].ToString(), dr["Value"].ToString(), dr["Description"].ToString(), dr["SystemID"].ToString()); string infoOld = dro["Info"].ToString(); if (info != infoOld) { dro["Info"] = info; dro["ModDateTime"] = DateTimeStamp; ARPTableAdapter.Update(dro); MyStatus = "Updating " + accPageID; AddStatusText("Updating {0}", accPageID); updateCount++; } } else { //if dro is null because accpageid does not exist, need to add including figuring out parent status and adding parent if it does not exist //get parent for new ro //see if parent exists AddStatusText("********** new arp item '{0}' **********", accPageID); addCount++; } } MyStatus = string.Format("{0} ROs Updated", updateCount); AddStatusText("RO Rows Updated: {0}", updateCount); AddStatusText("RO Rows Added: {0}", addCount); // What has not been processed updateCount = 0; foreach (string key in roDictionary.Keys) { DataRow dr = roDictionary[key]; string parentID = dr["ParentID"].ToString().Trim(); dr.Delete(); ARPTableAdapter.Update(dr); MyStatus = string.Format("Deleting {0}", key); AddStatusText("Deleting '{0}'", key); updateCount++; parentCount[parentID]--; if (parentCount[parentID] == 0) { DataRow drp = parentDictionary[parentID]; string grandparentID = drp["ParentID"].ToString().Trim(); drp.Delete(); ARPTableAdapter.Update(drp); MyStatus = string.Format("Deleting Parent {0}", parentID); AddStatusText("Deleting Parent {0}", parentID); updatePCount++; parentCount[grandparentID]--; if (parentCount[grandparentID] == 0) { DataRow drgp = parentDictionary[grandparentID]; drgp.Delete(); ARPTableAdapter.Update(drgp); MyStatus = string.Format("Deleting GrandParent {0}", grandparentID); AddStatusText("Deleting GrandParent {0}", grandparentID); updatePCount++; } } } MyStatus = string.Format("{0} ROs Deleted, {1} RO Parent/GrandParent Ros Deleted", updateCount, updatePCount); AddStatusText("RO Rows Deleted: {0}, RO Parent/GrandParent Rows Deleted {1}", updateCount, updatePCount); } } }