public static void ProcessingCompleted(string auditMessage) { try { //check to see if there are any elements in the mE array and if so, send via email in digest format int ub = mEIndex; string outMessage = ""; if (ub > 0) { for (int i = 0; i < ub; i += 1) { if (mE[i].Length != 0 && mE[i] != null) { outMessage = outMessage + "ERROR #" + (i + 1) + Environment.NewLine + mE[i] + Environment.NewLine + Environment.NewLine; } } SendMail.MailMessage(outMessage, "Configure One XML Mapping Errors"); } Array.Clear(mE, 0, mE.Length); DatabaseFactory.WriteAuditRecord(auditMessage, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, "PROCESSING COMPLETED"); } catch (Exception ex5) { Triggers.logEvent = ex5.Message + " -> " + ex5.Source + " -> " + ex5.InnerException; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Warning, 234); } //process validation framework error messages, if any try { if (!string.IsNullOrEmpty(ValidationMessages)) { string frameworkMessage = ValidationMessages; SendMail.MailMessage(frameworkMessage, "Configure One Validation Errors"); } } catch (Exception ex6) { Triggers.logEvent = ex6.Message + " -> " + ex6.Source + " -> " + ex6.InnerException; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Warning, 234); } }
public static void CallConfigureOne(string key, string payload, string url) { //Timing vars DateTime startTime = DateTime.Now; DateTime endTime = DateTime.Now; TimeSpan ts = endTime.Subtract(startTime); decimal elapsedTimeMS = ts.Milliseconds; decimal elapsedTimeSeconds = ts.Seconds; DateTime totalTimeStart = DateTime.Now; DateTime totalTimeStop = DateTime.Now; string logEvent = "CALLING C1 WEBSERVICE"; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); string sURL = url; HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(sURL.ToString()); objRequest.Method = "POST"; objRequest.ContentType = "text/xml"; objRequest.Headers.Add("SOAPAction", key); objRequest.Timeout = 120000; objRequest.ReadWriteTimeout = 120000; objRequest.Credentials = new NetworkCredential(DatabaseFactory.ws_uname, DatabaseFactory.ws_password); logEvent = "WS creds: " + DatabaseFactory.ws_uname + ", " + DatabaseFactory.ws_password; if (DatabaseFactory.debugLogging) { System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); } string xmlPayload = payload; logEvent = "Payload: " + xmlPayload; if (DatabaseFactory.debugLogging) { System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); } logEvent = "URL: " + url; if (DatabaseFactory.debugLogging) { System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); } StringBuilder data = new StringBuilder(); data.Append(xmlPayload); byte[] byteData = Encoding.UTF8.GetBytes(data.ToString()); // Sending our request to Apache AXIS in a byte array objRequest.ContentLength = byteData.Length; using (Stream postStream = objRequest.GetRequestStream()) { postStream.Write(byteData, 0, byteData.Length); } XmlDocument xmlResult = new XmlDocument(); string result = ""; try { startTime = DateTime.Now; //return response from AXIS (if any) using (HttpWebResponse response = objRequest.GetResponse() as HttpWebResponse) { StreamReader reader = new StreamReader(response.GetResponseStream()); result = reader.ReadToEnd(); reader.Close(); response.Close(); } try { xmlResult.LoadXml(result); logEvent = "Order Retrieved"; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); } catch (Exception ex2) { logEvent = "ERROR LOADING XML FROM WEB SERVICE: " + ex2.Message; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, logEvent, System.Diagnostics.EventLogEntryType.Error, 234); return; } // *** LOG TIME endTime = DateTime.Now; ts = endTime.Subtract(startTime); elapsedTimeMS = ts.Milliseconds; elapsedTimeSeconds = ts.Seconds; logEvent = "DEBUG: XML Order data returned from ConfigureOne in: " + Convert.ToString(elapsedTimeMS) + "ms / " + Convert.ToString(elapsedTimeSeconds) + " s"; if (DatabaseFactory.debugLogging) { System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); } startTime = DateTime.Now; logEvent = "About to output XML file"; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); //Save XML output to object for further handling using (var stringWriter = new StringWriter()) using (var xmlTextWriter = XmlWriter.Create(stringWriter)) { xmlResult.WriteTo(xmlTextWriter); xmlTextWriter.Flush(); string xmlOut = stringWriter.GetStringBuilder().ToString(); Triggers.wsReturn = System.Xml.Linq.XDocument.Parse(xmlOut).ToString(); } logEvent = "XML output. Starting staging"; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); if (Triggers.caller == "ORDER") { StagingUtilities.MapXMLToSQL(xmlResult); } if (!StagingUtilities.foundSite) { return; } //order_site not in the XML, processing must be aborted if (Triggers.forceStop == 1) { return; } // *** LOG TIME endTime = DateTime.Now; ts = endTime.Subtract(startTime); elapsedTimeMS = ts.Milliseconds; elapsedTimeSeconds = ts.Seconds; logEvent = "DEBUG: XML data mapped to staging tables in: " + Convert.ToString(elapsedTimeMS) + "ms / " + Convert.ToString(elapsedTimeSeconds) + " s"; if (DatabaseFactory.debugLogging) { System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); } Triggers.caller = ""; } catch (WebException wex1) { logEvent = "ERROR RETURNED FROM C1 WEBSERVICE: " + wex1.Message + " : " + wex1.Response.ToString(); System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, logEvent, System.Diagnostics.EventLogEntryType.Error, 234); return; } if (Triggers.forceStop == 1) { return; } logEvent = "Calling IMPORT of staging data to Syteline"; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); startTime = DateTime.Now; //run the C1-to-SL map as an async task Action MapToSytelineAsync = new Action(MapToSyteline); MapToSytelineAsync.BeginInvoke(new AsyncCallback(MapResult => { (MapResult.AsyncState as Action).EndInvoke(MapResult); }), MapToSytelineAsync); //administrative HALT to give SP's time to process all coitem records Thread.Sleep(2500); //Iteratively check for SL order# 60 times (one minute) for (int r = 0; r < 60; r += 1) { SPOrderNumber = DatabaseFactory.RetrieveSLCO(Triggers.pubOrderNumber); SPPUBOrderNumber = SPOrderNumber; if (SPOrderNumber != "") { break; } Thread.Sleep(1000); } //Final attempt to retrieve the SL order# (if not found, default to using the C1 order# and notify user): if (SPOrderNumber == "") { SPOrderNumber = string.IsNullOrEmpty(DatabaseFactory.RetrieveSLCO(Triggers.pubOrderNumber)) ? Triggers.pubOrderNumber : DatabaseFactory.RetrieveSLCO(Triggers.pubOrderNumber); SPPUBOrderNumber = SPOrderNumber; } if (SPOrderNumber == Triggers.pubOrderNumber) { SendMail.MailMessage("Syteline Order# Could Not Be Retrieved After 60 seconds. GR_CfgImportSp stored procedure may have timed out or failed. Documents Will Be Copied Using ConfigureOne Order# and there will be no coitem folder structure available.", "No Syteline Order# For Order: " + Triggers.pubOrderNumber); } logEvent = "Order created in Syteline is: " + SPOrderNumber; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); logEvent = "Writing XML output file..."; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); OutputXMLToFile(Triggers.wsReturn); //so file will be there for the worker-thread //If we have a good SL order#, we now need to check for existence of at least one coitem; iteratively check 60 times (one minute) int colines = 0; if (SPOrderNumber != Triggers.pubOrderNumber) { try { for (int r = 0; r < 60; r += 1) { colines = DatabaseFactory.CoLines(SPOrderNumber); logEvent = "SECONDS = " + r.ToString() + " -> Coitem line count returned: " + colines; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); if (colines > 0) { break; } System.Threading.Thread.Sleep(1000); } if (colines == 0) { logEvent = "After 60 seconds Syteline order# " + SPOrderNumber + " still has no coitem records created. This may indicate a problem or timeout occurred before GR_CfgImportSp could finish its processing."; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); } } catch (Exception cor) { logEvent = "ERROR: " + cor.Message; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, logEvent, System.Diagnostics.EventLogEntryType.Error, 234); } } //start downloading and copying drawing files on separate thread so main thread can return control to CLR xmlResultParm = xmlResult; urlParm = url; Action DrawingsAsync = new Action(StartCopy); DrawingsAsync.BeginInvoke(new AsyncCallback(MTresult => { (MTresult.AsyncState as Action).EndInvoke(MTresult); }), DrawingsAsync); // *** LOG TIME endTime = DateTime.Now; ts = endTime.Subtract(startTime); elapsedTimeMS = ts.Milliseconds; elapsedTimeSeconds = ts.Seconds; logEvent = "DEBUG: Staging tables mapped to Syteline in: " + Convert.ToString(elapsedTimeMS) + "ms / " + Convert.ToString(elapsedTimeSeconds) + " s"; if (DatabaseFactory.debugLogging) { System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); } // *** LOG TOTAL TIME totalTimeStop = DateTime.Now; ts = totalTimeStop.Subtract(totalTimeStart); elapsedTimeMS = ts.Milliseconds; elapsedTimeSeconds = ts.Seconds; logEvent = "DEBUG: Total execution: " + Convert.ToString(elapsedTimeMS) + "ms / " + Convert.ToString(elapsedTimeSeconds) + " s"; if (DatabaseFactory.debugLogging) { System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); } }
public static void MapXMLToSQL(XmlDocument xmldoc) { zCfgCO co = new zCfgCO(); zCfgCOitem coitem = new zCfgCOitem(); zCfgItem citem = new zCfgItem(); zCfgParmVal cfg = new zCfgParmVal(); zCfgBOM bom = new zCfgBOM(); zCfgRoute route = new zCfgRoute(); zCfgCO.ClearCO(ref co); zCfgCOitem.ClearCOItem(ref coitem); zCfgItem.ClearItem(ref citem); zCfgParmVal.ClearParmVal(ref cfg); zCfgRoute.ClearRoute(ref route); zCfgBOM.ClearBOM(ref bom); //Set validator objects based on the accessors coValidator = co; coitemValidator = coitem; citemValidator = citem; parmvalValidator = cfg; routeValidator = route; bomValidator = bom; Audit.ValidationMessages = ""; Audit.resetmE = true; //reset the mE array in case we have any mapping errors to report for this cycle var nsmgr = new XmlNamespaceManager(xmldoc.NameTable); nsmgr.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform"); nsmgr.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/"); nsmgr.AddNamespace("c1", "http://ws.configureone.com"); //*** Determine what site we are working with and re-set the connection string accordingly, else default and abort foundSite = true; XmlNodeList xnlsite = xmldoc.GetElementsByTagName("Input"); foreach (XmlNode node in xnlsite) { XmlNode nodeSite = node.SelectSingleNode("//c1:Input[@name='ORDER_SITE']", nsmgr); try { dbSite = nodeSite.ChildNodes[0].Attributes["name"].InnerXml; } catch (Exception exSite) { Triggers.logEvent = "ERROR occurred: " + exSite.Message; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Error, 234); } dbSite = nodeSite.ChildNodes[0].Attributes["name"].InnerXml; if (dbSite == null) { foundSite = false; } //foundSite &= dbSite != null; switch (foundSite == true) { case true: string rplConnectionString = DatabaseFactory.connectionString; int csPos = rplConnectionString.IndexOf("SL_", StringComparison.CurrentCulture); csPos += 3; DatabaseFactory.connectionString = rplConnectionString.Substring(0, csPos) + dbSite + rplConnectionString.Substring(csPos + 4, rplConnectionString.Length - (csPos + 4)); break; default: //prepare to log the no-site and abort break; } } Triggers.logEvent = "Site: " + dbSite; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Information, 234); if (!foundSite) { Triggers.logEvent = "ORDER_SITE was not found in XML for order# " + Triggers.pubOrderNumber + ". Processing aborted."; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Error, 234); SendMail.MailMessage(Triggers.logEvent, "MISSING ORDER_SITE For Order: " + Triggers.pubOrderNumber); return; } Triggers.logEvent = "Execute SP Pre-cache on site: " + dbSite; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Information, 234); DatabaseFactory.ExecutePreCache(); try { //Pre-staging activities XmlNode xnode = xmldoc.SelectSingleNode("//c1:ORDER_NUM", nsmgr); co.CO_Num = xnode.InnerText; coitem.CO_Num = xnode.InnerText; cfg.CO_Num = xnode.InnerText; citem.CO_Num = xnode.InnerText; bom.CO_Num = xnode.InnerText; globalOrderNum = co.CO_Num; globalOrderLineNum = 0; co.WebUserName = ""; co.WebOrderDate = System.DateTime.Now; switch (string.IsNullOrEmpty(co.CO_Num)) { case true: Triggers.logEvent = "ORDER NUMBER NOT FOUND: " + co.CO_Num; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Information, 234); return; default: //Remove any pre-existing records in SQL for this order DatabaseFactory.CleanupOrder(co.CO_Num); break; } } catch (Exception odderr) { Triggers.logEvent = "ERROR before map: " + odderr.Message; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Information, 234); } Triggers.logEvent = "MAPPING XML TO STAGING TABLES"; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Information, 234); //build CO header co.Identifier = LoadFromXML(xmldoc, "//c1:ID", nsmgr); co.CORefNum = LoadFromXML(xmldoc, "//c1:ORDER_REF_NUM", nsmgr); co.CustName = LoadFromXML(xmldoc, "//c1:CUST_NAME", nsmgr); co.CustRefNum = LoadFromXML(xmldoc, "//c1:CUST_REF_NUM", nsmgr); co.AccountNum = LoadFromXML(xmldoc, "//c1:ACCOUNT_NUM", nsmgr); //co.ErpReferenceNum = LoadFromXML(xmldoc, "//c1:ERP_REFERENCE_NUM", nsmgr); co.PaymentTerms = LoadFromXML(xmldoc, "//c1:PAYMENT_TERMS", nsmgr); co.ShipVia = LoadFromXML(xmldoc, "//c1:SHIP_VIA", nsmgr); co.ShippingTerms = LoadFromXML(xmldoc, "//c1:SHIPPING_TERMS", nsmgr); co.BillToContactName = LoadFromXML(xmldoc, "//c1:BILL_TO_CONTACT_NAME", nsmgr); co.BillToAddressLine1 = LoadFromXML(xmldoc, "//c1:BILL_TO_ADDRESS_LINE_1", nsmgr); co.BillToAddressLine2 = LoadFromXML(xmldoc, "//c1:BILL_TO_ADDRESS_LINE_2", nsmgr); co.BillToAddressLine3 = LoadFromXML(xmldoc, "//c1:BILL_TO_ADDRESS_LINE_3", nsmgr); co.BillToCity = LoadFromXML(xmldoc, "//c1:BILL_TO_CITY", nsmgr); co.BillToState = LoadFromXML(xmldoc, "//c1:BILL_TO_STATE", nsmgr); co.BillToCountry = LoadFromXML(xmldoc, "//c1:BILL_TO_COUNTRY", nsmgr); co.BillToPostalCode = LoadFromXML(xmldoc, "//c1:BILL_TO_POSTAL_CODE", nsmgr); co.BillToPhoneNumber = LoadFromXML(xmldoc, "//c1:BILL_TO_PHONE_NUMBER", nsmgr); co.BillToFaxNumber = LoadFromXML(xmldoc, "//c1:BILL_TO_FAX_NUMBER", nsmgr); co.BillToEmailAddress = LoadFromXML(xmldoc, "//c1:BILL_TO_EMAIL_ADDRESS", nsmgr); co.BillToRefNum = LoadFromXML(xmldoc, "//c1:BILL_TO_ERP_CONTACT_REF_NUM", nsmgr); co.ShipToContactName = LoadFromXML(xmldoc, "//c1:SHIP_TO_CONTACT_NAME", nsmgr); co.ShipToAddressLine1 = LoadFromXML(xmldoc, "//c1:SHIP_TO_ADDRESS_LINE_1", nsmgr); co.ShipToAddressLine2 = LoadFromXML(xmldoc, "//c1:SHIP_TO_ADDRESS_LINE_2", nsmgr); co.ShipToAddressLine3 = LoadFromXML(xmldoc, "//c1:SHIP_TO_ADDRESS_LINE_3", nsmgr); co.ShipToCity = LoadFromXML(xmldoc, "//c1:SHIP_TO_CITY", nsmgr); co.ShipToState = LoadFromXML(xmldoc, "//c1:SHIP_TO_STATE", nsmgr); co.ShipToCountry = DatabaseFactory.RetrieveISOCountry(LoadFromXML(xmldoc, "//c1:SHIP_TO_COUNTRY", nsmgr)); co.ShipToPostalCode = LoadFromXML(xmldoc, "//c1:SHIP_TO_POSTAL_CODE", nsmgr); co.ShipToPhoneNumber = LoadFromXML(xmldoc, "//c1:SHIP_TO_PHONE_NUMBER", nsmgr); co.ShipToFaxNumber = LoadFromXML(xmldoc, "//c1:SHIP_TO_FAX_NUMBER", nsmgr); co.ShipToEmailAddress = LoadFromXML(xmldoc, "//c1:SHIP_TO_EMAIL_ADDRESS", nsmgr); co.ShipToRefNum = LoadFromXML(xmldoc, "//c1:SHIP_TO_ERP_CONTACT_REF_NUM", nsmgr); //See if customer is on hold and if so, log and abort string custSeq = ""; int sPos = co.ShipToRefNum.IndexOf("-", StringComparison.CurrentCulture); custSeq = co.ShipToRefNum.Substring(sPos + 1, (co.ShipToRefNum.Length - (sPos + 1))); Triggers.logEvent = "Ship-To: " + custSeq; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Information, 234); string customerHoldReason = ""; Triggers.logEvent = "Checking customer ON-HOLD status..."; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Information, 234); try { customerHoldReason = DatabaseFactory.CustomerOnHold(co.CustRefNum, custSeq); } catch (Exception ex9) { Triggers.logEvent = "ERROR: " + ex9.Message + ". Processing Aborted"; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Information, 234); SendMail.MailMessage(Triggers.logEvent, "C1 Processing Aborted"); Triggers.forceStop = 1; return; } if (customerHoldReason != "") { Triggers.forceStop = 1; Triggers.logEvent = "Processing Aborted (" + co.CO_Num + "). Customer " + co.ShipToRefNum + " Is On Hold: " + customerHoldReason; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Information, 234); SendMail.MailMessage(Triggers.logEvent, "C1 Processing Aborted"); Triggers.forceStop = 1; return; } try { co.PriorityLevel = Convert.ToInt16(LoadFromXML(xmldoc, "//c1:PRIORITY_LEVEL", nsmgr)); } catch (Exception exPL) { co.PriorityLevel = 0; //there is no priority_level in the XML Triggers.logEvent = "There is no PRIORITY_LEVEL in the XML. Defaulting PRIORITY_LEVEL to 0"; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Warning, 234); } co.QuoteNbr = LoadFromXML(xmldoc, "//c1:SERIAL_NUMBER", nsmgr); co.WebUserName = LoadFromXML(xmldoc, "//c1:CREATED_BY_USER_ID", nsmgr); co.WebOrderDate = System.DateTime.Now; //Look for PURCHASE ORDER in INPUTS, load into CO and COITEM XmlNode nodePO = xmldoc.SelectSingleNode("//c1:Input[@name='PURCHASE_ORDER']", nsmgr); co.CustPO = string.IsNullOrEmpty(nodePO.ChildNodes[0].Attributes["name"].InnerXml) ? " " : nodePO.ChildNodes[0].Attributes["name"].InnerXml; coitem.CustPO = string.IsNullOrEmpty(nodePO.ChildNodes[0].Attributes["name"].InnerXml) ? " " : nodePO.ChildNodes[0].Attributes["name"].InnerXml; //Look for FREIGHT ACCOUNT#, load into CO XmlNode nodeFA = xmldoc.SelectSingleNode("//c1:Input[@name='FREIGHT_ACCT']", nsmgr); co.FreightAcct = nodeFA.ChildNodes[0].Attributes["name"].InnerXml.Length == 0 ? " " : nodeFA.ChildNodes[0].Attributes["name"].InnerXml; //Look for FREIGHT TERMS in INPUTS, load into CO XmlNode nodeFT = xmldoc.SelectSingleNode("//c1:Input[@name='FREIGHT_TERMS']", nsmgr); co.FreightTerms = nodeFT.ChildNodes[0].Attributes["name"].InnerXml.Length == 0 ? " " : nodeFT.ChildNodes[0].Attributes["name"].InnerXml; co.OrderHeaderNotes = " "; //Look for Order Header Notes, load into CO try { XmlNode nodeOHN = xmldoc.SelectSingleNode("//c1:Input[@name='ORDER_HEADER_NOTES']", nsmgr); co.OrderHeaderNotes = nodeOHN.ChildNodes[0].Attributes["name"].InnerXml.Length == 0 ? " " : nodeOHN.ChildNodes[0].Attributes["name"].InnerXml; co.OrderHeaderNotes = co.OrderHeaderNotes.Replace("&", "&"); } catch (Exception lnex) { Triggers.logEvent = "Order_Note error: " + lnex.Message; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Warning, 234); } //Retrieve due date co.DueDate = DateTime.Now; XmlNode nodedd = xmldoc.SelectSingleNode("//c1:Input[@name='DUE_DATE']", nsmgr); co.DueDate = nodedd.ChildNodes[0].Attributes["name"].InnerXml.Length == 0 ? DateTime.Now : Convert.ToDateTime(nodedd.ChildNodes[0].Attributes["name"].InnerXml); coitem.DueDate = co.DueDate; //Look for REQUEST DATE in INPUTS, load into CO co.RequestDate = DateTime.Now; XmlNode noderd = xmldoc.SelectSingleNode("//c1:Input[@name='REQUEST_DATE']", nsmgr); co.RequestDate = noderd.ChildNodes[0].Attributes["name"].InnerXml.Length == 0 ? DateTime.Now : Convert.ToDateTime(noderd.ChildNodes[0].Attributes["name"].InnerXml); //Look for Destination_country in INPUTS, load into CO co.DestinationCountry = " "; XmlNode nodeDC = xmldoc.SelectSingleNode("//c1:Input[@name='DESTINATION_COUNTRY']", nsmgr); co.DestinationCountry = nodeDC.ChildNodes[0].Attributes["name"].InnerXml.Length == 0 ? " " : DatabaseFactory.RetrieveISOCountry(nodeDC.ChildNodes[0].Attributes["name"].InnerXml.Substring(0, 2)); //Dropship data co.DropShipName = " "; co.DropShipAddress1 = " "; co.DropShipAddress2 = " "; co.DropShipAddress3 = " "; co.DropShipAddress4 = " "; co.DropShipCity = " "; co.DropShipState = " "; co.DropShipZip = " "; co.DropShipCountry = " "; co.DropShipContact = " "; co.DropShipPhone = " "; co.DropShipEmail = " "; XmlNodeList xnlds = xmldoc.GetElementsByTagName("Input"); foreach (XmlNode nodeds in xnlds) { XmlNode nodeDRS = nodeds.SelectSingleNode("//c1:Input[@name='DROP_SHIP_NAME']", nsmgr); co.DropShipName = string.IsNullOrEmpty(nodeDRS.ChildNodes[0].Attributes["name"].InnerXml) ? " " : nodeDRS.ChildNodes[0].Attributes["name"].InnerXml; nodeDRS = nodeds.SelectSingleNode("//c1:Input[@name='DROP_SHIP_ADDRESS_1']", nsmgr); co.DropShipAddress1 = string.IsNullOrEmpty(nodeDRS.ChildNodes[0].Attributes["name"].InnerXml) ? " " : nodeDRS.ChildNodes[0].Attributes["name"].InnerXml; nodeDRS = nodeds.SelectSingleNode("//c1:Input[@name='DROP_SHIP_ADDRESS_2']", nsmgr); co.DropShipAddress2 = string.IsNullOrEmpty(nodeDRS.ChildNodes[0].Attributes["name"].InnerXml) ? " " : nodeDRS.ChildNodes[0].Attributes["name"].InnerXml; nodeDRS = nodeds.SelectSingleNode("//c1:Input[@name='DROP_SHIP_ADDRESS_3']", nsmgr); co.DropShipAddress3 = string.IsNullOrEmpty(nodeDRS.ChildNodes[0].Attributes["name"].InnerXml) ? " " : nodeDRS.ChildNodes[0].Attributes["name"].InnerXml; nodeDRS = nodeds.SelectSingleNode("//c1:Input[@name='DROP_SHIP_ADDRESS_4']", nsmgr); co.DropShipAddress4 = string.IsNullOrEmpty(nodeDRS.ChildNodes[0].Attributes["name"].InnerXml) ? " " : nodeDRS.ChildNodes[0].Attributes["name"].InnerXml; nodeDRS = nodeds.SelectSingleNode("//c1:Input[@name='PROJECT']", nsmgr); co.Project = string.IsNullOrEmpty(nodeDRS.ChildNodes[0].Attributes["name"].InnerXml) ? " " : nodeDRS.ChildNodes[0].Attributes["name"].InnerXml; nodeDRS = nodeds.SelectSingleNode("//c1:Input[@name='END_USER']", nsmgr); co.EndUser = string.IsNullOrEmpty(nodeDRS.ChildNodes[0].Attributes["name"].InnerXml) ? " " : nodeDRS.ChildNodes[0].Attributes["name"].InnerXml; nodeDRS = nodeds.SelectSingleNode("//c1:Input[@name='ENGINEER']", nsmgr); co.Engineer = string.IsNullOrEmpty(nodeDRS.ChildNodes[0].Attributes["name"].InnerXml) ? " " : nodeDRS.ChildNodes[0].Attributes["name"].InnerXml; //evaluate CITY and then CIty if the former fails, as some XML is loaded improperly with mixed-case for City try { nodeDRS = nodeds.SelectSingleNode("//c1:Input[@name='DROP_SHIP_CITY']", nsmgr); co.DropShipCity = string.IsNullOrEmpty(nodeDRS.ChildNodes[0].Attributes["name"].InnerXml) ? " " : nodeDRS.ChildNodes[0].Attributes["name"].InnerXml; } catch (Exception dd1) { try { nodeDRS = nodeds.SelectSingleNode("//c1:Input[@name='DROP_SHIP_CIty']", nsmgr); co.DropShipCity = string.IsNullOrEmpty(nodeDRS.ChildNodes[0].Attributes["name"].InnerXml) ? " " : nodeDRS.ChildNodes[0].Attributes["name"].InnerXml; } catch (Exception dd2) { co.DropShipCity = " "; } } nodeDRS = nodeds.SelectSingleNode("//c1:Input[@name='DROP_SHIP_STATE']", nsmgr); co.DropShipState = string.IsNullOrEmpty(nodeDRS.ChildNodes[0].Attributes["name"].InnerXml) ? " " : nodeDRS.ChildNodes[0].Attributes["name"].InnerXml; nodeDRS = nodeds.SelectSingleNode("//c1:Input[@name='DROP_SHIP_ZIP_CODE']", nsmgr); co.DropShipZip = string.IsNullOrEmpty(nodeDRS.ChildNodes[0].Attributes["name"].InnerXml) ? " " : nodeDRS.ChildNodes[0].Attributes["name"].InnerXml; nodeDRS = nodeds.SelectSingleNode("//c1:Input[@name='DROP_SHIP_COUNTRY']", nsmgr); co.DropShipCountry = string.IsNullOrEmpty(nodeDRS.ChildNodes[0].Attributes["name"].InnerXml) ? " " : DatabaseFactory.RetrieveISOCountry(nodeDRS.ChildNodes[0].Attributes["name"].InnerXml); nodeDRS = nodeds.SelectSingleNode("//c1:Input[@name='DROP_SHIP_CONTACT']", nsmgr); co.DropShipContact = string.IsNullOrEmpty(nodeDRS.ChildNodes[0].Attributes["name"].InnerXml) ? " " : nodeDRS.ChildNodes[0].Attributes["name"].InnerXml; nodeDRS = nodeds.SelectSingleNode("//c1:Input[@name='DROP_SHIP_PHONE']", nsmgr); co.DropShipPhone = string.IsNullOrEmpty(nodeDRS.ChildNodes[0].Attributes["name"].InnerXml) ? " " : nodeDRS.ChildNodes[0].Attributes["name"].InnerXml; nodeDRS = nodeds.SelectSingleNode("//c1:Input[@name='DROP_SHIP_EMAIL']", nsmgr); co.DropShipEmail = string.IsNullOrEmpty(nodeDRS.ChildNodes[0].Attributes["name"].InnerXml) ? " " : nodeDRS.ChildNodes[0].Attributes["name"].InnerXml; break; } //Replace & in any dropship fields with & co.DropShipName = co.DropShipName.Replace("&", "&"); co.DropShipAddress1 = co.DropShipAddress1.Replace("&", "&"); co.DropShipAddress2 = co.DropShipAddress2.Replace("&", "&"); co.DropShipAddress3 = co.DropShipAddress3.Replace("&", "&"); co.DropShipAddress4 = co.DropShipAddress4.Replace("&", "&"); co.DropShipContact = co.DropShipContact.Replace("&", "&"); //build COITEM records, per line XmlNodeList xnl = xmldoc.GetElementsByTagName("Detail"); foreach (XmlNode node in xnl) { XmlNode nodertv = node.SelectSingleNode("c1:ORDER_LINE_NUM", nsmgr); coitem.CO_Line = Convert.ToInt16(nodertv.ChildNodes[0].InnerText); System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Error, 234); nodertv = node.SelectSingleNode("c1:SERIAL_NUM", nsmgr); coitem.Serial = string.IsNullOrEmpty(nodertv.ChildNodes[0].InnerText) ? " " : nodertv.ChildNodes[0].InnerText; Triggers.logEvent = "Processing line# " + coitem.CO_Line.ToString(); System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Information, 234); try { nodertv = node.SelectSingleNode("c1:ITEM_NUM", nsmgr); coitem.Item = string.IsNullOrEmpty(nodertv.ChildNodes[0].InnerText) ? " " : nodertv.ChildNodes[0].InnerText; nodertv = node.SelectSingleNode("c1:SMARTPART_NUM", nsmgr); coitem.Smartpart = string.IsNullOrEmpty(nodertv.ChildNodes[0].InnerText) ? " " : nodertv.ChildNodes[0].InnerText; } catch (Exception c11) { coitem.Item = " "; coitem.Smartpart = " "; } if (coitem.Item == "") { coitem.Item = " "; } if (coitem.Smartpart == "") { coitem.Smartpart = " "; } try { nodertv = node.SelectSingleNode("c1:DESCRIPTION", nsmgr); string chkPercent = string.IsNullOrEmpty(nodertv.ChildNodes[0].InnerText) ? " " : nodertv.ChildNodes[0].InnerText; coitem.Desc = chkPercent.Replace("%", "[%]"); coitem.Desc = string.IsNullOrEmpty(nodertv.ChildNodes[0].InnerText) ? " " : nodertv.ChildNodes[0].InnerText; nodertv = node.SelectSingleNode("c1:TYPE", nsmgr); coitem.ConfigType = string.IsNullOrEmpty(nodertv.ChildNodes[0].InnerText) ? " " : nodertv.ChildNodes[0].Value; nodertv = node.SelectSingleNode("c1:UNIT_PRICE", nsmgr); coitem.UnitPrice = Convert.ToDecimal(nodertv.ChildNodes[0].InnerText); nodertv = node.SelectSingleNode("c1:UNIT_COST", nsmgr); try { coitem.UnitCost = Convert.ToDecimal(nodertv.ChildNodes[0].InnerText); } catch (Exception costex) { coitem.UnitCost = 0; Triggers.logEvent = "COITEM (LINE# " + coitem.CO_Line + ") - Unit Cost invalid: " + costex.Message + Environment.NewLine + Environment.NewLine + " (Incoming value was: " + nodertv.ChildNodes[0].InnerText + " Defaulting to 0)"; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Warning, 234); } nodertv = node.SelectSingleNode("c1:DISCOUNT_AMT", nsmgr); try { coitem.Discount = Convert.ToDecimal(nodertv.ChildNodes[0].InnerText); } catch (Exception exdiscount) { coitem.Discount = 0; Triggers.logEvent = "COITEM (LINE# " + coitem.CO_Line + ") - Discount value invalid: " + exdiscount.Message + Environment.NewLine + Environment.NewLine + " (Incoming value was: " + nodertv.ChildNodes[0].InnerText + " Defaulting to 0)"; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Warning, 234); } nodertv = node.SelectSingleNode("c1:QUANTITY", nsmgr); try { coitem.QTY = Convert.ToDecimal(nodertv.ChildNodes[0].InnerText); } catch (Exception extQty) { coitem.Discount = 0; Triggers.logEvent = "COITEM (LINE# " + coitem.CO_Line + ") - Quantity value invalid: " + extQty.Message + Environment.NewLine + Environment.NewLine + " (Incoming value was: " + nodertv.ChildNodes[0].InnerText + " Defaulting to 1)"; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Warning, 234); } coitem.PriorityLevel = co.PriorityLevel; globalOrderLineNum = coitem.CO_Line; coitem.OrderLineNotes = " "; } catch (Exception ciex) { Triggers.logEvent = "COITEM Error: " + ciex.Message; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Error, 234); return; } //Look for Line Notes, load into COItem try { nodertv = node.SelectSingleNode("c1:Input[@name='LINE_NOTES']", nsmgr); coitem.OrderLineNotes = nodertv.ChildNodes[0].Attributes["name"].InnerXml.Length == 0 ? " " : nodertv.ChildNodes[0].Attributes["name"].InnerXml; coitem.OrderLineNotes = coitem.OrderLineNotes.Replace("&", "&"); } catch (Exception exrtv) { Triggers.logEvent = "Line_Note error: " + exrtv.Message; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Warning, 234); } if (coitem.ConfigType == "K") { Triggers.logEvent = "WARNING: Config Type Is: " + coitem.ConfigType + " On C1 Order#: " + co.CO_Num + ". Ignoring line# " + coitem.CO_Line; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Warning, 234); SendMail.MailMessage(Triggers.logEvent, "Config-Type Warning"); continue; //we cannot process a type K; notify, ignore this line and continue with the next detail node if any exist } //output coitem record COItemValidator civ = new COItemValidator(); civ.ValidateCOItem(); DatabaseFactory.WriteRecordCOItem(ref coitem); //*** Everything else here builds on the COITEM *** var detailParent = node.SelectSingleNode("."); //ensure we traverse ONLY children of this node (Detail) as the new parent (root) element XmlDocument detailDoc = new XmlDocument(); detailDoc.LoadXml(detailParent.OuterXml); //iterate through Inputs for the line (none of these have static variable names or attributes) XmlNodeList xnli = detailDoc.GetElementsByTagName("Input"); foreach (XmlNode nodei in xnli) { cfg.CO_Line = coitem.CO_Line; cfg.CName = nodei.ChildNodes[2].InnerText.Replace(" ", "_"); cfg.CValue = nodei.ChildNodes[0].InnerText; cfg.CType = nodei.ChildNodes[1].InnerText; cfg.CLabel = nodei.ChildNodes[2].InnerText; cfg.PriorityLevel = co.PriorityLevel; //output cfg (parmval) record DatabaseFactory.WriteRecordCfg(ref cfg); } //Look for SHIP_VIA in INPUTS co.ShipVia = " "; XmlNodeList xnlisv = xmldoc.GetElementsByTagName("Input"); foreach (XmlNode nodeisv in xnlisv) { if (nodeisv.ChildNodes[2].InnerText == "SHIP_VIA") { co.ShipVia = nodeisv.ChildNodes[0].Attributes["name"].Value; } } if (co.ShipVia.Length == 0) { co.ShipVia = " "; } //item-master for the line we are working with int recordSequence = 1; XmlNodeList xnlim = detailDoc.GetElementsByTagName("ItemMaster"); citem.CO_Line = coitem.CO_Line; string cost = ""; string price = ""; string sell = ""; string weight = ""; citem.IM_VAR1 = ""; citem.IM_VAR2 = ""; citem.IM_VAR3 = ""; citem.IM_VAR4 = ""; citem.IM_VAR5 = ""; //Build nodelist of ItemMaster nodes and a second nodelist within of its childnodes so we can reference those elements by name instead of index foreach (XmlNode nodeim in xnlim) { foreach (XmlNode childIM in nodeim.ChildNodes) { switch (childIM.Name) { case "SMARTPART_NUM": citem.Smartpart = childIM.InnerText; break; case "ITEM_NUM": citem.Item = childIM.InnerText; break; case "DESCRIPTION": citem.Desc = childIM.InnerText; break; case "COST": cost = childIM.InnerText; break; case "PRICE": price = childIM.InnerText; break; case "SELL_PRICE": sell = childIM.InnerText; break; case "WEIGHT": weight = childIM.InnerText; break; case "UOM": citem.UnitOfMeasure = childIM.InnerText; break; case "PRIORITY_LEVEL": citem.PriorityLevel = Convert.ToInt16(childIM.InnerText); break; case "VAR_1": citem.IM_VAR1 = string.IsNullOrEmpty(childIM.InnerText) ? " " : childIM.InnerText; break; case "VAR_2": citem.IM_VAR2 = string.IsNullOrEmpty(childIM.InnerText) ? " " : childIM.InnerText; break; case "VAR_3": citem.IM_VAR3 = string.IsNullOrEmpty(childIM.InnerText) ? " " : childIM.InnerText; break; case "VAR_4": citem.IM_VAR4 = string.IsNullOrEmpty(childIM.InnerText) ? " " : childIM.InnerText; break; case "VAR_5": citem.IM_VAR5 = string.IsNullOrEmpty(childIM.InnerText) ? " " : childIM.InnerText; break; default: //do nothing break; } citem.ItemCost = Convert.ToDecimal(string.IsNullOrEmpty(cost) ? "0" : cost); citem.ItemPrice = Convert.ToDecimal(string.IsNullOrEmpty(price) ? "0" : price); citem.ItemSellPrice = Convert.ToDecimal(string.IsNullOrEmpty(sell) ? "0" : sell); citem.ItemWeight = Convert.ToDecimal(string.IsNullOrEmpty(weight) ? "0" : weight); citem.Sequence = recordSequence; } recordSequence += 1; //output citem ItemValidator ci = new ItemValidator(); ci.ValidateCitem(); DatabaseFactory.WriteRecordCItem(ref citem); cost = ""; price = ""; sell = ""; weight = ""; citem.IM_VAR1 = ""; citem.IM_VAR2 = ""; citem.IM_VAR3 = ""; citem.IM_VAR4 = ""; citem.IM_VAR5 = ""; } //BOM records (Must load in this manner, as none of these have static variable names or attributes) recordSequence = 0; XmlNodeList xnlb = detailDoc.GetElementsByTagName("Bom"); bom.CO_Line = coitem.CO_Line; foreach (XmlNode nodeib in xnlb) { recordSequence += 1; bom.Sequence = recordSequence; bom.RecordSequence = recordSequence; var parent = nodeib.SelectSingleNode(".."); string parentID = parent.ChildNodes[0].InnerText; bom.Parent = parentID == "1" ? null : parentID; bom.Identifier = nodeib.ChildNodes[0].InnerText; bom.Item = nodeib.ChildNodes[1].InnerText; bom.Smartpart = nodeib.ChildNodes[2].InnerText; bom.UnitPrice = Convert.ToDecimal(string.IsNullOrEmpty(nodeib.ChildNodes[3].InnerText) ? "0" : nodeib.ChildNodes[3].InnerText); bom.UnitCost = Convert.ToDecimal(string.IsNullOrEmpty(nodeib.ChildNodes[4].InnerText) ? "0" : nodeib.ChildNodes[4].InnerText); bom.Discount = Convert.ToDecimal(string.IsNullOrEmpty(nodeib.ChildNodes[5].InnerText) ? "0" : nodeib.ChildNodes[5].InnerText); bom.QTY = Convert.ToDecimal(string.IsNullOrEmpty(nodeib.ChildNodes[6].InnerText) ? "0" : nodeib.ChildNodes[6].InnerText); //Search the ItemMaster XML records for the matching smartpart_num and retrieve its priority level for this BOM record bool foundchild = false; bool imdone = false; foreach (XmlNode nodeIMPL in xnlim) { if (imdone == true) { break; } foreach (XmlNode childIMPL in nodeIMPL.ChildNodes) { if (imdone == true) { break; } if (childIMPL.InnerText == bom.Smartpart) { foundchild = true; } if (foundchild == true) { if (childIMPL.Name == "PRIORITY_LEVEL") { bom.PriorityLevel = Convert.ToInt16(childIMPL.InnerText); imdone = true; } } } } //output BOM record DatabaseFactory.WriteRecordBOM(ref bom); } //Routing - Output only if the Routing tag contains a nodelist count greater than 0 Triggers.logEvent = "STARTING ROUTING LOGIC"; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Information, 234); int routebomSeq = 0; bool UseRouteBOM = false; route.CO_Num = coitem.CO_Num; route.CO_Line = coitem.CO_Line; XmlNodeList xnlr = detailDoc.GetElementsByTagName("Routing"); if (xnlr.Count > 0) { UseRouteBOM = true; foreach (XmlNode nodecr in xnlr) { XmlNode nodecrtg = nodecr.SelectSingleNode("c1:SMARTPART_NUM", nsmgr); route.SmartpartNum = nodecrtg.ChildNodes[0].InnerText; nodecrtg = nodecr.SelectSingleNode("c1:ITEM_NUM", nsmgr); route.ItemNum = nodecrtg.ChildNodes[0].InnerText; nodecrtg = nodecr.SelectSingleNode("c1:BOM_ID", nsmgr); route.BOM_ID = nodecrtg.ChildNodes[0].InnerText; //isolate OPERATION elements from Routing and process XmlDocument routeOP = new XmlDocument(); routeOP.LoadXml(nodecr.OuterXml); XmlNodeList xnlOperation = routeOP.GetElementsByTagName("Operation"); foreach (XmlNode nodeol in xnlOperation) { XmlNode operationParentTL = nodeol.SelectSingleNode("."); //current operation becomes our new parent (.. to .) XmlDocument operationDocumentTL = new XmlDocument(); operationDocumentTL.LoadXml(operationParentTL.OuterXml); XmlNodeList xnlOP = operationDocumentTL.GetElementsByTagName("OperationParam"); foreach (XmlNode nodeParamChild in xnlOP) { if (nodeParamChild.ChildNodes[0].InnerText == "LABOR_HRS") { route.Labor_Hours = Convert.ToDouble(nodeParamChild.ChildNodes[2].InnerText); } if (nodeParamChild.ChildNodes[0].InnerText == "SETUP_HRS") { route.Setup_Hours = Convert.ToDouble(nodeParamChild.ChildNodes[2].InnerText); } if (nodeParamChild.ChildNodes[0].InnerText == "WC") { route.WC = nodeParamChild.ChildNodes[2].InnerText; } if (nodeParamChild.ChildNodes[0].InnerText == "NOTES") { route.Notes = nodeParamChild.ChildNodes[2].InnerText; } if (nodeParamChild.ChildNodes[0].InnerText == "MACH_NAME") { route.Machine_Name = nodeParamChild.ChildNodes[2].InnerText; } } XmlNode nodeOpItem = nodeol.SelectSingleNode("c1:OPER_NUM", nsmgr); route.OPERATION = Convert.ToInt16(nodeOpItem.ChildNodes[0].InnerText); nodeOpItem = nodeol.SelectSingleNode("c1:DESCRIPTION", nsmgr); route.Description = nodeOpItem.ChildNodes[0].InnerText; //set current operation as new parent and look ONLY for its OperationInput tags var operationParent = nodeol.SelectSingleNode("."); //ensure we traverse ONLY descendants of this node (Operation) as the new parent XmlDocument operationDoc = new XmlDocument(); operationDoc.LoadXml(operationParent.OuterXml); XmlNodeList xnlOperationInputs = operationDoc.GetElementsByTagName("OperationInput"); foreach (XmlNode nodeOpInput in xnlOperationInputs) { XmlNode nodeoin = nodeOpInput.SelectSingleNode("c1:SMARTPART_NUM", nsmgr); route.MatlSmartpartNum = nodeOpInput.ChildNodes[0].InnerText; route.MatlItemNum = nodeOpInput.ChildNodes[1].InnerText; route.MatlQty = Convert.ToDecimal(nodeOpInput.ChildNodes[2].InnerText); //write to gr_cfgroutebom routebomSeq += 1; route.Seq = routebomSeq; DatabaseFactory.WriteRecordCfgRoute(ref route); } } } } Triggers.logEvent = "RESEQUENCING BOM RECORDS FOR ORDER: " + bom.CO_Num + " LINE: " + bom.CO_Line; System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Information, 234); DatabaseFactory.ResequenceBOM(bom.CO_Num, bom.CO_Line); //If we used routeBOM, dump the old-process BOM records //if (UseRouteBOM) { DatabaseFactory.DeleteBOM(co.CORefNum); } //this may be reinstated in the future } COValidator cv = new COValidator(); cv.ValidateCO(); DatabaseFactory.WriteRecordCO(ref co); //deferred write }
public static void C1Order() { if (!System.Diagnostics.EventLog.SourceExists("C1ORDER")) { System.Diagnostics.EventLog.CreateEventSource( "C1ORDER", "Application"); } logEvent = "TRIGGER - GR_CFG_QUEUE : INCOMING ORDER"; if (DatabaseFactory.debugLogging) { System.Diagnostics.EventLog.WriteEntry(logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); } switch (C1Dictionaries.webmethods.ContainsKey("getOrder")) { case false: C1Dictionaries.LoadWMDictionary(); C1Dictionaries.LoadDBFLengthDictionary(); break; default: //dictionary already loaded break; } string orderNum; orderValue = ""; string qRowPointerValue = ""; SqlTriggerContext triggContext = SqlContext.TriggerContext; SqlParameter orderNumber = new SqlParameter("@order_num", System.Data.SqlDbType.NVarChar); SqlParameter qRowPointer = new SqlParameter("@RowPointer", System.Data.SqlDbType.NVarChar); switch (triggContext.TriggerAction == TriggerAction.Insert) { case true: using (SqlConnection conn = new SqlConnection("context connection=true")) { conn.Open(); SqlCommand sqlComm = new SqlCommand(); sqlComm.CommandTimeout = 1800; SqlPipe sqlP = SqlContext.Pipe; sqlComm.Connection = conn; sqlComm.CommandText = "SELECT order_num, RowPointer from INSERTED"; orderNumber.Value = sqlComm.ExecuteScalar().ToString(); orderValue = orderNumber.Value.ToString(); sqlComm.CommandText = "SELECT RowPointer from INSERTED"; qRowPointer.Value = sqlComm.ExecuteScalar().ToString(); qRowPointerValue = qRowPointer.Value.ToString(); conn.Close(); logEvent = "INCOMING C1 ORDER NUMBER: " + orderValue; System.Diagnostics.EventLog.WriteEntry(logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); } break; default: return; } //Determine whether incoming order is production or dev/test string incomingOrder = orderValue.Substring(0, 1); dbEnvironment = "DEV"; if (incomingOrder != "D") { dbEnvironment = "PROD"; } string useMethod = ""; if (Triggers.dbEnvironment == "PROD" && DatabaseFactory.dbprotect != "YES") { key = "getOrderPROD"; } if (C1Dictionaries.webmethods.ContainsKey(key)) { useMethod = C1Dictionaries.webmethods[key]; key = "getOrder"; C1URL = useMethod; } DatabaseFactory dbf = new DatabaseFactory(); dbf.SetConnectionString(); caller = "ORDER"; orderNum = orderValue; pubOrderNumber = orderNum; logEvent = "Connection String (Initial): " + DatabaseFactory.connectionString; if (DatabaseFactory.debugLogging) { System.Diagnostics.EventLog.WriteEntry(logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); } //Check if this order has already been completely processed: if (DatabaseFactory.OrderCompleted(orderNum)) { logEvent = "Order# " + orderNum + " has already been completed. Further processing aborted"; System.Diagnostics.EventLog.WriteEntry(logSource, logEvent, System.Diagnostics.EventLogEntryType.Warning, 234); SendMail.MailMessage(logEvent, "Aborted Status-C Order"); return; //abort } //Ensure the mE array is initialized in case it is never addressed again before an array.clear is attempted Audit.mE = new string[50]; Audit.mEIndex = 0; xmlPayload = "<soap:Envelope xmlns:xsi=" + (char)34 + "http://www.w3.org/2001/XMLSchema-instance" + (char)34 + " xmlns:xsd=" + (char)34 + "http://www.w3.org/2001/XMLSchema" + (char)34 + " xmlns:soap=" + (char)34 + "http://schemas.xmlsoap.org/soap/envelope/" + (char)34 + ">" + "<soap:Body><" + key + " xmlns=" + (char)34 + "http://ws.configureone.com" + (char)34 + "><orderNum>" + orderNum + "</orderNum></" + key + "></soap:Body></soap:Envelope>"; AsOf = DateTime.Now; forceStop = 0; //Begin order-processing as an async task and allow trigger to reset Action ProcessXMLAsync = new Action(BeginProcessing); ProcessXMLAsync.BeginInvoke(new AsyncCallback(MTresult => { (MTresult.AsyncState as Action).EndInvoke(MTresult); }), ProcessXMLAsync); //Hold trigger context open for up to 60 seconds waiting for order# so portal can display to user for (int r = 0; r < 60; r += 1) { if (DatabaseFactory.OrderExists(orderNum)) { logEvent = "SL Order found within " + itr.ToString() + " seconds"; System.Diagnostics.EventLog.WriteEntry(logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); break; } System.Threading.Thread.Sleep(1000); itr = r + 1; } if (forceStop == 1) { return; } logEvent = "Trigger context decoupled/resetting... (" + orderNum + ")"; System.Diagnostics.EventLog.WriteEntry(logSource, logEvent, System.Diagnostics.EventLogEntryType.Information, 234); try { System.Threading.Thread.Sleep(10000); } catch (Exception tt1) { //disregard, as any error would likely be a thread-abort by the trigger logEvent = "Error occurred (can be ignored) during the 10-second window after trigger-decouple: " + tt1.Message; System.Diagnostics.EventLog.WriteEntry(logSource, logEvent, System.Diagnostics.EventLogEntryType.Warning, 234); } }