Example #1
0
 public static void ClearCO(ref zCfgCO co)
 {
     co.BillToAddressLine1 = "";
     co.BillToAddressLine2 = "";
     co.BillToAddressLine3 = "";
     co.BillToCity         = "";
     co.BillToContactName  = "";
     co.BillToCountry      = "";
     co.BillToEmailAddress = "";
     co.BillToFaxNumber    = "";
     co.BillToPhoneNumber  = "";
     co.BillToPostalCode   = "";
     co.BillToRefNum       = "";
     co.BillToState        = "";
     co.ShipToAddressLine1 = "";
     co.ShipToAddressLine2 = "";
     co.ShipToAddressLine3 = "";
     co.ShipToAddressLine4 = "";
     co.ShipToCity         = "";
     co.ShipToContactName  = "";
     co.ShipToCountry      = "";
     co.ShipToEmailAddress = "";
     co.ShipToFaxNumber    = "";
     co.ShipToPhoneNumber  = "";
     co.ShipToPostalCode   = "";
     co.ShipToRefNum       = "";
     co.ShipToState        = "";
     co.DropShipAddress1   = "";
     co.DropShipAddress2   = "";
     co.DropShipAddress3   = "";
     co.DropShipAddress4   = "";
     co.DropShipCity       = "";
     co.DropShipContact    = "";
     co.DropShipCountry    = "";
     co.DropShipEmail      = "";
     co.DropShipName       = "";
     co.DropShipPhone      = "";
     co.DropShipState      = "";
     co.DropShipZip        = "";
     co.CustPO             = "";
     co.Project            = "";
     co.WebUserName        = "";
     co.Engineer           = "";
     co.EndUser            = "";
     co.ShippingTerms      = "";
     co.ShipVia            = "";
     co.FreightAcct        = "";
     co.FreightTerms       = "";
     co.ErpReferenceNum    = "";
     co.CustName           = "";
     co.PaymentTerms       = "";
     co.DestinationCountry = "";
     co.OrderHeaderNotes   = "";
     co.QuoteNbr           = "";
 }
Example #2
0
        public static int DBFieldLenCO(string field, ref zCfgCO co)
        {
            int fieldlength = (!fieldLengths.ContainsKey(field)) ? 15 : fieldLengths[field];

            switch (field)
            {
            case "CO:bill_to_phone_number": switch (co.BillToPhoneNumber.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.BillToPhoneNumber.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.BillToPhoneNumber); break;

                default: fieldlength = co.BillToPhoneNumber.Length; break;
                }
                break;

            case "CO:ship_via": switch (co.ShipVia.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.ShipVia.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.ShipVia); break;

                default: fieldlength = co.ShipVia.Length; break;
                }
                break;

            case "CO:shipping_terms": switch (co.ShippingTerms.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.ShippingTerms.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.ShippingTerms); break;

                default: fieldlength = co.ShippingTerms.Length; break;
                }
                break;

            case "CO:bill_to_fax_number": switch (co.BillToFaxNumber.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.BillToFaxNumber.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.BillToFaxNumber); break;

                default: fieldlength = co.BillToFaxNumber.Length; break;
                }
                break;

            case "CO:dropship_address1": switch (co.DropShipAddress1.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.DropShipAddress1.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.DropShipAddress1); break;

                default: fieldlength = co.DropShipAddress1.Length; break;
                }
                break;

            case "CO:dropship_address2": switch (co.DropShipAddress2.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.DropShipAddress2.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.DropShipAddress2); break;

                default: fieldlength = co.DropShipAddress2.Length; break;
                }
                break;

            case "CO:dropship_address3": switch (co.DropShipAddress3.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.DropShipAddress3.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.DropShipAddress3); break;

                default: fieldlength = co.DropShipAddress3.Length; break;
                }
                break;

            case "CO:dropship_address4": switch (co.DropShipAddress4.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.DropShipAddress4.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.DropShipAddress4); break;

                default: fieldlength = co.DropShipAddress4.Length; break;
                }
                break;

            case "CO:dropship_city": switch (co.DropShipCity.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.DropShipCity.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.DropShipCity); break;

                default: fieldlength = co.DropShipCity.Length; break;
                }
                break;

            case "CO:dropship_state": switch (co.DropShipState.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.DropShipState.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.DropShipState); break;

                default: fieldlength = co.DropShipState.Length; break;
                }
                break;

            case "CO:dropship_zip": switch (co.DropShipZip.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.DropShipZip.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.DropShipZip); break;

                default: fieldlength = co.DropShipZip.Length; break;
                }
                break;

            case "CO:dropship_name": switch (co.DropShipName.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.DropShipName.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.DropShipName); break;

                default: fieldlength = co.DropShipName.Length; break;
                }
                break;

            case "CO:dropship_contact": switch (co.DropShipContact.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.DropShipContact.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.DropShipContact); break;

                default: fieldlength = co.DropShipContact.Length; break;
                }
                break;

            case "CO:dropship_country": switch (co.DropShipCountry.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.DropShipCountry.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.DropShipCountry); break;

                default: fieldlength = co.DropShipCountry.Length; break;
                }
                break;

            case "CO:dropship_phone": switch (co.DropShipPhone.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.DropShipPhone.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.DropShipPhone); break;

                default: fieldlength = co.DropShipPhone.Length; break;
                }
                break;

            case "CO:CustPO": switch (co.CustPO.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.CustPO.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.CustPO); break;

                default: fieldlength = co.CustPO.Length; break;
                }
                break;

            case "CO:ship_address_line_4": switch (co.ShipToAddressLine4.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.ShipToAddressLine4.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.ShipToAddressLine4); break;

                default: fieldlength = co.ShipToAddressLine4.Length; break;
                }
                break;

            case "CO:freight_terms": switch (co.FreightTerms.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.FreightTerms.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.FreightTerms); break;

                default: fieldlength = co.FreightTerms.Length; break;
                }
                break;

            case "CO:freight_acct": switch (co.FreightAcct.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.FreightAcct.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.FreightAcct); break;

                default: fieldlength = co.FreightAcct.Length; break;
                }
                break;

            case "CO:dropship_email": switch (co.DropShipEmail.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.DropShipEmail.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.DropShipEmail); break;

                default: fieldlength = co.DropShipEmail.Length; break;
                }
                break;

            case "CO:bill_to_contact_name": switch (co.BillToContactName.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.BillToContactName.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.BillToContactName); break;

                default: fieldlength = co.BillToContactName.Length; break;
                }
                break;

            case "CO:bill_address_line_1": switch (co.BillToAddressLine1.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.BillToAddressLine1.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.BillToAddressLine1); break;

                default: fieldlength = co.BillToAddressLine1.Length; break;
                }
                break;

            case "CO:bill_address_line_2": switch (co.BillToAddressLine2.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.BillToAddressLine2.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.BillToAddressLine2); break;

                default: fieldlength = co.BillToAddressLine2.Length; break;
                }
                break;

            case "CO:bill_address_line_3": switch (co.BillToAddressLine3.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.BillToAddressLine3.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.BillToAddressLine3); break;

                default: fieldlength = co.BillToAddressLine3.Length; break;
                }
                break;

            case "CO:bill_to_city": switch (co.BillToCity.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.BillToCity.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.BillToCity); break;

                default: fieldlength = co.BillToCity.Length; break;
                }
                break;

            case "CO:bill_to_state": switch (co.BillToState.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.BillToState.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.BillToState); break;

                default: fieldlength = co.BillToState.Length; break;
                }
                break;

            case "CO:bill_to_country": switch (co.BillToCountry.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.BillToCountry.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.BillToCountry); break;

                default: fieldlength = co.BillToCountry.Length; break;
                }
                break;

            case "CO:bill_to_postal_code": switch (co.BillToPostalCode.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.BillToPostalCode.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.BillToPostalCode); break;

                default: fieldlength = co.BillToPostalCode.Length; break;
                }
                break;

            case "CO:bill_to_email_address": switch (co.BillToEmailAddress.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.BillToEmailAddress.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.BillToEmailAddress); break;

                default: fieldlength = co.BillToEmailAddress.Length; break;
                }
                break;

            case "CO:ship_to_contact_name": switch (co.ShipToContactName.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.ShipToContactName.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.ShipToContactName); break;

                default: fieldlength = co.ShipToContactName.Length; break;
                }
                break;

            case "CO:ship_address_line_1": switch (co.ShipToAddressLine1.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.ShipToAddressLine1.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.ShipToAddressLine1); break;

                default: fieldlength = co.ShipToAddressLine1.Length; break;
                }
                break;

            case "CO:ship_address_line_2": switch (co.ShipToAddressLine2.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.ShipToAddressLine2.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.ShipToAddressLine2); break;

                default: fieldlength = co.ShipToAddressLine2.Length; break;
                }
                break;

            case "CO:ship_address_line_3": switch (co.ShipToAddressLine3.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.ShipToAddressLine3.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.ShipToAddressLine3); break;

                default: fieldlength = co.ShipToAddressLine3.Length; break;
                }
                break;

            case "CO:ship_to_city": switch (co.ShipToCity.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.ShipToCity.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.ShipToCity); break;

                default: fieldlength = co.ShipToCity.Length; break;
                }
                break;

            case "CO:ship_to_state": switch (co.ShipToState.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.ShipToState.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.ShipToState); break;

                default: fieldlength = co.ShipToState.Length; break;
                }
                break;

            case "CO:ship_to_country": switch (co.ShipToCountry.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.ShipToCountry.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.ShipToCountry); break;

                default: fieldlength = co.ShipToCountry.Length; break;
                }
                break;

            case "CO:ship_to_postal_code": switch (co.ShipToPostalCode.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.ShipToPostalCode.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.ShipToPostalCode); break;

                default: fieldlength = co.ShipToPostalCode.Length; break;
                }
                break;

            case "CO:ship_to_email_address": switch (co.ShipToEmailAddress.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.ShipToEmailAddress.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.ShipToEmailAddress); break;

                default: fieldlength = co.ShipToEmailAddress.Length; break;
                }
                break;

            case "CO:ship_to_fax_number": switch (co.ShipToFaxNumber.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.ShipToFaxNumber.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.ShipToFaxNumber); break;

                default: fieldlength = co.ShipToFaxNumber.Length; break;
                }
                break;

            case "CO:ship_to_phone_number": switch (co.ShipToPhoneNumber.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.ShipToPhoneNumber.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.ShipToPhoneNumber); break;

                default: fieldlength = co.ShipToPhoneNumber.Length; break;
                }
                break;

            case "CO:destination_country": switch (co.DestinationCountry.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.DestinationCountry.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.DestinationCountry); break;

                default: fieldlength = co.DestinationCountry.Length; break;
                }
                break;

            case "CO:ORDER_HEADER_NOTES": switch (co.OrderHeaderNotes.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.OrderHeaderNotes.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.OrderHeaderNotes); break;

                default: fieldlength = co.OrderHeaderNotes.Length; break;
                }
                break;

            case "CO:project": switch (co.Project.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.Project.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.Project); break;

                default: fieldlength = co.Project.Length; break;
                }
                break;

            case "CO:end_user": switch (co.EndUser.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.EndUser.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.EndUser); break;

                default: fieldlength = co.EndUser.Length; break;
                }
                break;

            case "CO:engineer": switch (co.Engineer.Length >= fieldlength)
                {
                case true: Audit.SetTruncate(field, co.Engineer.Length, fieldlength, StagingUtilities.globalOrderNum, StagingUtilities.globalOrderLineNum, co.Engineer); break;

                default: fieldlength = co.Engineer.Length; break;
                }
                break;
            }

            return(fieldlength);
        }
Example #3
0
        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
        }
Example #4
0
        public static void WriteRecordCO(ref zCfgCO co)
        {
            try
            {
                GR_CfgCOTableAdapter tbl = new GR_CfgCOTableAdapter();
                tbl.Connection.ConnectionString = connectionString;

                tbl.Insert(
                    co.Identifier,
                    co.CO_Num,
                    co.CORefNum,
                    co.CustName,
                    co.CustRefNum,
                    co.AccountNum,
                    co.ErpReferenceNum,
                    co.Project,
                    co.PaymentTerms,
                    co.ShipVia,
                    co.ShippingTerms,
                    co.BillToContactName,
                    co.BillToAddressLine1,
                    co.BillToAddressLine2,
                    co.BillToAddressLine3,
                    co.BillToCity,
                    co.BillToState,
                    co.BillToCountry,
                    co.BillToPostalCode,
                    co.BillToPhoneNumber,
                    co.BillToFaxNumber,
                    co.BillToEmailAddress,
                    co.BillToRefNum,
                    co.ShipToContactName,
                    co.ShipToAddressLine1,
                    co.ShipToAddressLine2,
                    co.ShipToAddressLine3,
                    co.ShipToCity,
                    co.ShipToState,
                    co.ShipToCountry,
                    co.ShipToPostalCode,
                    co.ShipToPhoneNumber,
                    co.ShipToFaxNumber,
                    co.ShipToEmailAddress,
                    co.ShipToRefNum,
                    co.PriorityLevel,
                    null,
                    null,
                    co.DueDate,
                    co.CustPO,
                    co.DropShipAddress4,
                    co.FreightTerms,
                    co.FreightAcct,
                    co.QuoteNbr,
                    co.WebUserName,
                    co.WebOrderDate,
                    co.DropShipAddress1,
                    co.DropShipAddress2,
                    co.DropShipAddress3,
                    co.DropShipAddress4,
                    co.DropShipCity,
                    co.DropShipState,
                    co.DropShipZip,
                    co.DropShipName,
                    co.DropShipContact,
                    co.DropShipCountry,
                    co.DropShipPhone,
                    co.DropShipEmail,
                    co.RequestDate,
                    co.DestinationCountry,
                    co.OrderHeaderNotes,
                    co.EndUser,
                    co.Engineer);
            }
            catch (Exception coex)
            {
                Triggers.logEvent = "ERROR WRITING GR_CFGCO: " + coex.Message;
                System.Diagnostics.EventLog.WriteEntry(Triggers.logSource, Triggers.logEvent, System.Diagnostics.EventLogEntryType.Error, 234);
            }
        }