private static void WalkCustomerTypeAddRs(string response)
        {
            //Parse the response XML string into an XmlDocument
            XmlDocument responseXmlDoc = new XmlDocument();

            responseXmlDoc.LoadXml(response);

            //Get the response for our request
            XmlNodeList CustomerTypeAddRsList = responseXmlDoc.GetElementsByTagName("CustomerTypeAddRs");

            if (CustomerTypeAddRsList.Count == 1) //Should always be true since we only did one request in this sample
            {
                XmlNode responseNode = CustomerTypeAddRsList.Item(0);
                //Check the status code, info, and severity
                XmlAttributeCollection rsAttributes = responseNode.Attributes;
                string statusCode     = rsAttributes.GetNamedItem("statusCode").Value;
                string statusSeverity = rsAttributes.GetNamedItem("statusSeverity").Value;
                string statusMessage  = rsAttributes.GetNamedItem("statusMessage").Value;

                // Check status and log any errors
                QBUtils.CheckStatus(statusCode, statusSeverity, statusMessage);

                //status code = 0 all OK, > 0 is warning
                if (Convert.ToInt32(statusCode) >= 0)
                {
                    XmlNodeList CustomerTypeRetList = responseNode.SelectNodes("//CustomerTypeRet");//XPath Query
                    for (int i = 0; i < CustomerTypeRetList.Count; i++)
                    {
                        XmlNode CustomerTypeRet = CustomerTypeRetList.Item(i);
                        WalkCustomerTypeRetForAdd(CustomerTypeRet);
                    }
                }
            }
        }
Exemple #2
0
        public static void RemoveDeleted()
        {
            XmlDocument doc      = BuildDeletedRequest();
            string      response = QBUtils.DoRequest(doc);

            HandleDeletedResponse(response);
        }
        private static bool WalkDataExtModRs(string response)
        {
            //Parse the response XML string into an XmlDocument
            XmlDocument responseXmlDoc = new XmlDocument();

            responseXmlDoc.LoadXml(response);

            //Get the response for our request
            XmlNodeList DataExtModRsList = responseXmlDoc.GetElementsByTagName("DataExtModRs");

            if (DataExtModRsList.Count >= 5) //Should always be true since we update at least 5 elements in this request
            {
                XmlNode responseNode = DataExtModRsList.Item(0);
                //Check the status code, info, and severity
                XmlAttributeCollection rsAttributes = responseNode.Attributes;
                string statusCode     = rsAttributes.GetNamedItem("statusCode").Value;
                string statusSeverity = rsAttributes.GetNamedItem("statusSeverity").Value;
                string statusMessage  = rsAttributes.GetNamedItem("statusMessage").Value;

                // Check status and log any errors
                QBUtils.CheckStatus(statusCode, statusSeverity, statusMessage);

                //status code = 0 all OK, > 0 is warning
                if (Convert.ToInt32(statusCode) == 0)
                {
                    XmlNodeList DataExtRetList = responseNode.SelectNodes("//DataExtRet");//XPath Query
                    for (int i = 0; i < DataExtRetList.Count; i++)
                    {
                        XmlNode DataExtRet = DataExtRetList.Item(i);
                        WalkDataExtRet(DataExtRet);
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
        public static void UpdateAlreadyExistingWorkOrder(int woId)
        {
            RotoTrackDb db = new RotoTrackDb();
            WorkOrder   wo = db.WorkOrders.Find(woId);

            if (wo != null)
            {
                string response = QBUtils.DoRequest(CustomerDAL.BuildCustomerQueryByWorkorderNum(wo.WorkOrderNumber));
                string qbid     = CustomerDAL.GetQBIDFromResponse(response);
                string qbes     = CustomerDAL.GetQBEditSequenceFromResponse(response);
                if ((qbid != "") && (qbes != ""))
                {
                    wo.QBListId        = qbid;
                    wo.QBEditSequence  = qbes;
                    db.Entry(wo).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
        }
        private static void WalkVehicleMileageRetForAdd(XmlNode VehicleMileageRet)
        {
            if (VehicleMileageRet == null)
            {
                return;
            }

            RotoTrackDb db = new RotoTrackDb();

            //Get value of Notes--we should have the ServiceEntry GUID encoded in it as well.
            string seGUID = "";

            if (VehicleMileageRet.SelectSingleNode("./Notes") != null)
            {
                string Notes = VehicleMileageRet.SelectSingleNode("./Notes").InnerText;
                seGUID = QBUtils.GetGuidFromNotes(Notes);
            }

            string TxnID = "";

            if (VehicleMileageRet.SelectSingleNode("./TxnID") != null)
            {
                TxnID = VehicleMileageRet.SelectSingleNode("./TxnID").InnerText;
            }

            if (seGUID != "" && TxnID != "")
            {
                ServiceEntry se = null;
                if (db.ServiceEntries.Any(f => f.GUID == seGUID))
                {
                    se = db.ServiceEntries.First(f => f.GUID == seGUID);
                }
                if (se != null)
                {
                    se.QBListIdForMileage = TxnID;
                    db.Entry(se).State    = EntityState.Modified;
                    db.SaveChanges();
                }
            }
        }
        private static void WalkTimeTrackingRetForAdd(XmlNode TimeTrackingRet)
        {
            if (TimeTrackingRet == null)
            {
                return;
            }

            string       Duration = TimeTrackingRet.SelectSingleNode("./Duration").InnerText;
            HoursMinutes hrsMins  = GetHoursMinutesFromDuration(Duration);

            if (hrsMins == null)
            {
                return;
            }

            RotoTrackDb db = new RotoTrackDb();

            string TxnID             = "";
            string seGUID            = "";
            string ItemServiceListID = "";

            if (TimeTrackingRet.SelectSingleNode("./TxnID") != null)
            {
                TxnID = TimeTrackingRet.SelectSingleNode("./TxnID").InnerText;
            }
            if (TimeTrackingRet.SelectSingleNode("./Notes") != null)
            {
                string Notes = TimeTrackingRet.SelectSingleNode("./Notes").InnerText;
                seGUID = QBUtils.GetGuidFromNotes(Notes);
            }
            XmlNode ItemServiceRef = TimeTrackingRet.SelectSingleNode("./ItemServiceRef");

            if (ItemServiceRef != null)
            {
                if (ItemServiceRef.SelectSingleNode("./ListID") != null)
                {
                    ItemServiceListID = ItemServiceRef.SelectSingleNode("./ListID").InnerText;
                }
            }

            if (TxnID != null && seGUID != null && ItemServiceListID != null)
            {
                ServiceEntry se = null;
                if (db.ServiceEntries.Any(f => f.GUID == seGUID))
                {
                    se = db.ServiceEntries.First(f => f.GUID == seGUID);
                }
                if (se != null)
                {
                    ServiceDetail sd = db.ServiceDetails.Find(se.ServiceDetailId);
                    if (sd != null)
                    {
                        ServiceType regST = db.ServiceTypes.Find(sd.ServiceTypeId);
                        ServiceType otST  = db.ServiceTypes.Find(sd.OTServiceTypeId);
                        if (regST != null && otST != null)
                        {
                            // We always update the regular hours first, so if reg and OT both have the same service list ID, then we need to also check if we already
                            // wrote out the regular hours or not--else we will put both the reg and ot hours into regular hours since we match on reg hours first.
                            // I was going to also look at the actual hours and minutes, but if those are identical, too, then this reduces to the same problem we have
                            // solved here--we just have to assume reg hours are always written first, which they are.  Also, I don't want to compare on hours/minutes
                            // because that may fail due to rounding errors.
                            if (ItemServiceListID == regST.QBListId && se.QBListIdForRegularHours == null)
                            {
                                se.QBListIdForRegularHours = TxnID;
                                db.Entry(se).State         = EntityState.Modified;
                                db.SaveChanges();
                            }
                            else if (ItemServiceListID == otST.QBListId && se.QBListIdForOTHours == null)
                            {
                                se.QBListIdForOTHours = TxnID;
                                db.Entry(se).State    = EntityState.Modified;
                                db.SaveChanges();
                            }
                        }
                    }
                }
            }
        }