protected override void OnDeserialize(QBXML qbxml) { Clear(); QBXMLMsgsRs rsMsgSet = (QBXMLMsgsRs)qbxml.Items[0]; if (rsMsgSet.Items != null) { //order doesn't "matter" here, but we preserve it foreach (var obj in rsMsgSet.Items) { if (obj is IRsMsg) { var rs = (IRsMsg)obj; if (rs.requestID == null) { rs.requestID = Guid.NewGuid().ToString(); } _rsMsgs.Add(rs); _ids.Add(rs.requestID, rs); } else { throw new NotImplementedException(); } } } }
public QBXMLMsgsRs Transmit <T>(object txx, out T resp) { QBXML req = new QBXML(); req.ItemsElementName = new ItemsChoiceType103[] { ItemsChoiceType103.QBXMLMsgsRq }; req.Items = new object[] { new QBXMLMsgsRq() }; QBXMLMsgsRq r = req.Items[0] as QBXMLMsgsRq; r.onError = QBXMLMsgsRqOnError.stopOnError; r.Items = new object[] { txx }; MemoryStream ms = new MemoryStream(); XmlTextWriter w = new XmlTextWriter(ms, null); w.WriteProcessingInstruction("xml", "version=\"1.0\""); w.WriteProcessingInstruction("qbxml", "version=\"11.0\""); ser.Serialize(w, req, ns); ms.Seek(0, SeekOrigin.Begin); StreamReader sr = new StreamReader(ms); string t = sr.ReadToEnd(); t = this.process.Transmit(t); QBXML ret = null; StringReader tr = new StringReader(t); ret = (QBXML)ser.Deserialize(tr); QBXMLMsgsRs rs = (ret.Items[0] as QBXMLMsgsRs); resp = (T)rs.Items[0]; return(rs); }
private void TransferTerms(XmlSerializer serializer, XmlSerializerNamespaces ns, QBXML qbxml, QBXMLMsgsRq qbMsgsRq) { MemoryStream ms; StreamReader sr; string xmlRequest; var termsrq = new TermsQueryRqType(); termsrq.requestID = "1"; qbMsgsRq.Items[0] = termsrq; qbxml.Items[0] = qbMsgsRq; ms = new MemoryStream(); serializer.Serialize(ms, qbxml, ns); ms.Seek(0, SeekOrigin.Begin); sr = new StreamReader(ms); xmlRequest = sr.ReadToEnd(); xmlRequest = xmlRequest.Replace("<?xml version=\"1.0\"?>", "<?xml version=\"1.0\"?><?qbxml version=\"4.0\"?>"); if (DEBUGMODE) { File.WriteAllText("c:\\QB\\TermsQBXML.xml", xmlRequest); } _Response = _Rp.ProcessRequest(_Ticket, xmlRequest); if (DEBUGMODE) { File.WriteAllText("c:\\QB\\Terms.xml", _Response); } QBXML rsXML = GetQbxml(serializer); if (rsXML?.Items?[0] is QBXMLMsgsRs) { QBXMLMsgsRs msgsrs = (QBXMLMsgsRs)rsXML.Items[0]; if (msgsrs?.Items?[0] is TermsQueryRsType) { TermsQueryRsType rs = (TermsQueryRsType)msgsrs.Items[0]; using (ApexDataDataContext dc = new ApexDataDataContext(_SqlConnBuilder.ConnectionString)) { foreach (var term in rs.Items) { if (term is StandardTermsRet) { StandardTermsRet qbTerm = (StandardTermsRet)term; if (!dc.VENDTERMs.Where(s => s.VendTerm1 == qbTerm.Name).Any()) { VENDTERM newTerm = new VENDTERM(); newTerm.VendTerm1 = qbTerm.Name; dc.VENDTERMs.InsertOnSubmit(newTerm); } } dc.SubmitChanges(); } } } } }
public QBXMLMsgsRs InvoiceMod(string ItemRefNumber, string refNumber) { InvoiceModRqType req = new InvoiceModRqType(); if (!string.IsNullOrEmpty(ItemRefNumber)) { req.InvoiceMod.TxnID = ItemRefNumber; } if (!string.IsNullOrEmpty(refNumber)) { req.InvoiceMod.RefNumber = refNumber; } InvoiceQueryRsType resp; QBXMLMsgsRs r = this.Transmit(req, out resp); return(r); }
public QBXMLMsgsRs InvoiceQuery(string ItemRefNumber, string refNumber) { InvoiceQueryRqType req = new InvoiceQueryRqType(); if (!string.IsNullOrEmpty(ItemRefNumber)) { req.TxnID = ItemRefNumber; } if (!string.IsNullOrEmpty(refNumber)) { req.RefNumber = refNumber; } req.IncludeLineItems = "true"; InvoiceQueryRsType resp; QBXMLMsgsRs r = this.Transmit(req, out resp); return(r); }
public QBXMLMsgsRs buildInvoiceAddRqXML(string customer, DateTime txnDate, string refNumber) { InvoiceAddRqType req = new InvoiceAddRqType(); req.InvoiceAdd = new InvoiceAdd(); req.InvoiceAdd.TemplateRef = new TemplateRef(); req.InvoiceAdd.TemplateRef.FullName = customer; req.InvoiceAdd.CustomerRef = new CustomerRef(); req.InvoiceAdd.CustomerRef.FullName = customer; req.InvoiceAdd.Other = "tttt"; if (txnDate != null) { req.InvoiceAdd.TxnDate = txnDate.ToString("yyyy-MM-dd"); } if (!string.IsNullOrEmpty(refNumber)) { req.InvoiceAdd.RefNumber = refNumber; } //string requestXML = ""; ////if (!validateInput()) return null; ////GET ALL INPUT INTO XML //XmlDocument xmlDoc = new XmlDocument(); //XmlElement qbXMLMsgsRq = buildRqEnvelope(xmlDoc, maxVersion); //qbXMLMsgsRq.SetAttribute("onError", "stopOnError"); //XmlElement InvoiceAddRq = xmlDoc.CreateElement("InvoiceAddRq"); //qbXMLMsgsRq.AppendChild(InvoiceAddRq); //XmlElement InvoiceAdd = xmlDoc.CreateElement("InvoiceAdd"); //InvoiceAddRq.AppendChild(InvoiceAdd); //// CustomerRef -> FullName //if (comboBox_Customer.Text != "") //{ // XmlElement Element_CustomerRef = xmlDoc.CreateElement("CustomerRef"); // InvoiceAdd.AppendChild(Element_CustomerRef); // XmlElement Element_CustomerRef_FullName = xmlDoc.CreateElement("FullName"); // Element_CustomerRef.AppendChild(Element_CustomerRef_FullName).InnerText = comboBox_Customer.Text; //} // RefNumber //if (textBox_RefNumber.Text != "") //{ // XmlElement Element_RefNumber = xmlDoc.CreateElement("RefNumber"); // InvoiceAdd.AppendChild(Element_RefNumber).InnerText = textBox_RefNumber.Text; //} // BillAddress /* * if (label_BillTo.Text != "") * { * string[] BillAddress = label_BillTo.Text.Split('\n'); * XmlElement Element_BillAddress = xmlDoc.CreateElement("BillAddress"); * InvoiceAdd.AppendChild(Element_BillAddress); * for (int i = 0; i < BillAddress.Length; i++) * { * if (BillAddress[i] != "" || BillAddress[i] != null) * { * XmlElement Element_Addr = xmlDoc.CreateElement("Addr" + (i + 1)); * Element_BillAddress.AppendChild(Element_Addr).InnerText = BillAddress[i]; * } * } * } * * // TermsRef -> FullName * bool termsAvailable = false; * if (comboBox_Terms.Text != "") * { * termsAvailable = true; * XmlElement Element_TermsRef = xmlDoc.CreateElement("TermsRef"); * InvoiceAdd.AppendChild(Element_TermsRef); * XmlElement Element_TermsRef_FullName = xmlDoc.CreateElement("FullName"); * Element_TermsRef.AppendChild(Element_TermsRef_FullName).InnerText = comboBox_Terms.Text; * } * * // DueDate * if (termsAvailable) * { * DateTime DT_DueDate = System.DateTime.Today; * double dueInDays = getDueInDays(); * DT_DueDate = DT_TxnDate.AddDays(dueInDays); * string DueDate = getDateString(DT_DueDate); * XmlElement Element_DueDate = xmlDoc.CreateElement("DueDate"); * InvoiceAdd.AppendChild(Element_DueDate).InnerText = DueDate; * } * * // CustomerMsgRef -> FullName * if (comboBox_CustomerMessage.Text != "") * { * XmlElement Element_CustomerMsgRef = xmlDoc.CreateElement("CustomerMsgRef"); * InvoiceAdd.AppendChild(Element_CustomerMsgRef); * XmlElement Element_CustomerMsgRef_FullName = xmlDoc.CreateElement("FullName"); * Element_CustomerMsgRef.AppendChild(Element_CustomerMsgRef_FullName).InnerText = comboBox_CustomerMessage.Text; * } * * // ExchangeRate * if (textBox_ExchangeRate.Text != "") * { * XmlElement Element_ExchangeRate = xmlDoc.CreateElement("ExchangeRate"); * InvoiceAdd.AppendChild(Element_ExchangeRate).InnerText = textBox_ExchangeRate.Text; * } */ //Line Items List <InvoiceLineAdd> lineItems = new List <InvoiceLineAdd>(); InvoiceLineAdd line = new InvoiceLineAdd(); // ItemRef line.ItemRef = new ItemRef(); line.ItemRef.FullName = "Labor"; line.Desc = "Test"; line.ClassRef = new ClassRef(); line.ClassRef.FullName = "Home Depot:Atlanta:Hard Surface"; line.Amount = "123456.78"; line.IsTaxable = "false"; lineItems.Add(line); line = new InvoiceLineAdd(); line.ItemRef = new ItemRef(); line.ItemRef.FullName = "Back Charge"; line.Desc = "Smith James"; line.ClassRef = new ClassRef(); line.ClassRef.FullName = "Home Depot:Atlanta:Hard Surface"; line.Amount = "-543.21"; line.IsTaxable = "false"; lineItems.Add(line); req.InvoiceAdd.Items = lineItems.ToArray();; //XmlElement Element_InvoiceLineAdd; //for (int x = 1; x < 6; x++) //{ // Element_InvoiceLineAdd = xmlDoc.CreateElement("InvoiceLineAdd"); // InvoiceAdd.AppendChild(Element_InvoiceLineAdd); // string[] lineItem = getLineItem(x); // if (lineItem[0] != "") // { // XmlElement Element_InvoiceLineAdd_ItemRef = xmlDoc.CreateElement("ItemRef"); // Element_InvoiceLineAdd.AppendChild(Element_InvoiceLineAdd_ItemRef); // XmlElement Element_InvoiceLineAdd_ItemRef_FullName = xmlDoc.CreateElement("FullName"); // Element_InvoiceLineAdd_ItemRef.AppendChild(Element_InvoiceLineAdd_ItemRef_FullName).InnerText = lineItem[0]; // } // if (lineItem[1] != "") // { // XmlElement Element_InvoiceLineAdd_Desc = xmlDoc.CreateElement("Desc"); // Element_InvoiceLineAdd.AppendChild(Element_InvoiceLineAdd_Desc).InnerText = lineItem[1]; // } // if (lineItem[2] != "") // { // XmlElement Element_InvoiceLineAdd_Quantity = xmlDoc.CreateElement("Quantity"); // Element_InvoiceLineAdd.AppendChild(Element_InvoiceLineAdd_Quantity).InnerText = lineItem[2]; // } // if (lineItem[3] != "") // { // XmlElement Element_InvoiceLineAdd_Rate = xmlDoc.CreateElement("Rate"); // Element_InvoiceLineAdd.AppendChild(Element_InvoiceLineAdd_Rate).InnerText = lineItem[3]; // } // if (lineItem[4] != "") // { // XmlElement Element_InvoiceLineAdd_Amount = xmlDoc.CreateElement("Amount"); // Element_InvoiceLineAdd.AppendChild(Element_InvoiceLineAdd_Amount).InnerText = lineItem[4]; // } //} //InvoiceAddRq.SetAttribute("requestID", "99"); //requestXML = xmlDoc.OuterXml; //return requestXML; InvoiceAddRsType resp; QBXMLMsgsRs r = this.Transmit(req, out resp); return(r); }
private void TransferJobs(XmlSerializer serializer, XmlSerializerNamespaces ns, QBXML qbxml, QBXMLMsgsRq qbMsgsRq) { MemoryStream ms; StreamReader sr; string xmlRequest; var custrq = new CustomerQueryRqType(); custrq.requestID = "1"; qbMsgsRq.Items = new object[1] { custrq }; qbxml.Items[0] = qbMsgsRq; ms = new MemoryStream(); serializer.Serialize(ms, qbxml, ns); ms.Seek(0, SeekOrigin.Begin); sr = new StreamReader(ms); xmlRequest = sr.ReadToEnd(); xmlRequest = xmlRequest.Replace("<?xml version=\"1.0\"?>", "<?xml version=\"1.0\"?><?qbxml version=\"4.0\"?>"); if (DEBUGMODE) { File.WriteAllText("c:\\QB\\CustQBXML.xml", xmlRequest); } _Response = _Rp.ProcessRequest(_Ticket, xmlRequest); if (DEBUGMODE) { File.WriteAllText("c:\\QB\\Customers.xml", _Response); } QBXML rsXML = GetQbxml(serializer); if (rsXML?.Items?[0] is QBXMLMsgsRs) { QBXMLMsgsRs msgsrs = (QBXMLMsgsRs)rsXML.Items[0]; if (msgsrs?.Items?[0] is CustomerQueryRsType) { CustomerQueryRsType rs = (CustomerQueryRsType)msgsrs.Items[0]; if (rs.statusCode != "0") { MessageBox.Show(rs.statusMessage); } else { for (int i = 0; i < rs.CustomerRet.Length; i++) { CustomerRet cr = rs.CustomerRet[i]; if (cr.Sublevel == "0") { continue; //don't process the top level customers; we only want the job records } Match m = _JobRegEx.Match(cr?.FullName); if (!m.Success) { continue; //this isn't a job number we can use } string qbJobID = m.Groups[1].Value; string qbJobName = m.Groups[2].Value; using (ApexDataDataContext dc = new ApexDataDataContext(_SqlConnBuilder.ConnectionString)) { Job job = null; QBJob qbjob; qbjob = dc.QBJobs.Where(s => s.ApexCompany == _ApexTargetCompany && s.ApexJobID == qbJobID && s.QBListID != cr.ListID) .FirstOrDefault(); if (qbjob != null) { MessageBox.Show($"Job {qbJobID} from {qbJobName} has already been assigned to {qbjob.QBJobName} and cannot be transferred.", "Duplicate job"); continue; } qbjob = dc.QBJobs.Where(s => s.ApexCompany == _ApexTargetCompany && s.QBListID == cr.ListID).SingleOrDefault(); if (qbjob != null) { if (qbjob.ApexJobID != qbJobID.PadLeft(12)) //we need to delete and treat as new { dc.QBJobs.DeleteOnSubmit(qbjob); QBJob qbjob2 = new QBJob(); qbjob2.QBListID = cr?.ListID; qbjob2.QBJobName = cr?.FullName; qbjob2.ApexJobID = qbJobID.PadLeft(12); qbjob2.ApexCompany = _ApexTargetCompany; dc.QBJobs.InsertOnSubmit(qbjob2); } else { qbjob.QBJobName = cr?.FullName; } } else { qbjob = new QBJob(); qbjob.QBListID = cr?.ListID; qbjob.QBJobName = cr?.FullName; qbjob.ApexJobID = qbJobID.PadLeft(12); qbjob.ApexCompany = _ApexTargetCompany; dc.QBJobs.InsertOnSubmit(qbjob); } job = dc.Jobs.Where(s => s.Job1 == qbjob.ApexJobID.PadLeft(12)).SingleOrDefault(); if (job != null) { SetJobFields(cr, qbJobName, job); } else { job = new Job(); //Start the new Apex job job.Job1 = qbJobID.PadLeft(12); job.Act = "A"; job.Schedule = "STD"; job.TaxDefault = "Y"; job.TaxRate = 0; job.POMsg = String.Empty; SetJobFields(cr, qbJobName, job); dc.Jobs.InsertOnSubmit(job); } dc.SubmitChanges(); } } } } } }
private void TransferVendors(XmlSerializer serializer, XmlSerializerNamespaces ns, QBXML qbxml, QBXMLMsgsRq qbMsgsRq) { MemoryStream ms; StreamReader sr; string xmlRequest; var vendrq = new VendorQueryRqType(); vendrq.requestID = "1"; qbMsgsRq.Items[0] = vendrq; qbxml.Items[0] = qbMsgsRq; ms = new MemoryStream(); serializer.Serialize(ms, qbxml, ns); ms.Seek(0, SeekOrigin.Begin); sr = new StreamReader(ms); xmlRequest = sr.ReadToEnd(); xmlRequest = xmlRequest.Replace("<?xml version=\"1.0\"?>", "<?xml version=\"1.0\"?><?qbxml version=\"4.0\"?>"); if (DEBUGMODE) { File.WriteAllText("c:\\QB\\VendQBXML.xml", xmlRequest); } _Response = _Rp.ProcessRequest(_Ticket, xmlRequest); if (DEBUGMODE) { File.WriteAllText("c:\\QB\\Vendors.xml", _Response); } QBXML rsXML = GetQbxml(serializer); if (rsXML?.Items?[0] is QBXMLMsgsRs) { QBXMLMsgsRs msgsrs = (QBXMLMsgsRs)rsXML.Items[0]; if (msgsrs?.Items?[0] is VendorQueryRsType) { VendorQueryRsType rs = (VendorQueryRsType)msgsrs.Items[0]; if (rs.statusCode != "0") { MessageBox.Show(rs.statusMessage); } else { for (int i = 0; i < rs.VendorRet.Length; i++) { VendorRet vr = rs.VendorRet[i]; using (ApexDataDataContext dc = new ApexDataDataContext(_SqlConnBuilder.ConnectionString)) { Vendor vendor = null; QBVendor qbvendor = dc.QBVendors .Where(s => s.ApexCompany == _ApexTargetCompany && s.QBListID == vr.ListID) .SingleOrDefault(); bool newRecord; if (qbvendor == null) //new vendor { newRecord = true; qbvendor = new QBVendor(); vendor = new Vendor(); string newVendorID = GetNextApexVendor(dc); //Set up the translation table qbvendor.QBListID = vr?.ListID; qbvendor.QBVendorName = vr?.Name; qbvendor.ApexVendorID = newVendorID.PadLeft(6); //pad it just in case we change the way we're numbering qbvendor.ApexCompany = _ApexTargetCompany; qbvendor.Terms = vr?.TermsRef?.FullName; //Start the new Apex vendor vendor.Vendor1 = newVendorID; vendor.AcctID = newVendorID; vendor.Name = LoadField(vr?.Name.ToUpper(), 25); } else { newRecord = false; qbvendor.Terms = vr?.TermsRef?.FullName; vendor = dc.Vendors.Where(s => s.Vendor1 == qbvendor.ApexVendorID).Single(); } vendor.Add1 = LoadField(vr?.VendorAddress?.Addr1, 25); vendor.Add2 = LoadField(vr?.VendorAddress?.Addr2, 25); vendor.City = LoadField(vr?.VendorAddress?.City, 15); vendor.State = LoadField(vr?.VendorAddress?.State, 4); vendor.Zip = LoadField(vr?.VendorAddress?.PostalCode, 15); vendor.EMail = LoadField(vr?.Email, 40); vendor.Attn = LoadField(vr?.Contact, 20); vendor.Phone = LoadField(vr?.Phone, 15); vendor.CompLevel = 0; vendor.Terms = LoadField(vr?.TermsRef?.FullName, 15); vendor.Company = _ApexTargetCompany; if (newRecord) { dc.QBVendors.InsertOnSubmit(qbvendor); dc.Vendors.InsertOnSubmit(vendor); } dc.SubmitChanges(); } } } } } }