Beispiel #1
0
        public static Hashtable getAccounts()
        {
            Hashtable list = new Hashtable();

            string xml = "<?xml version=\"1.0\" ?>";

            xml += "<?qbxml version=\"12.0\"?>";
            xml += "<QBXML>";
            xml += "<QBXMLMsgsRq onError=\"stopOnError\">";
            xml += "<AccountQueryRq requestID=\"13\">";
            xml += "</AccountQueryRq>";
            xml += "</QBXMLMsgsRq>";
            xml += "</QBXML>";

            if (Vars.qb != null && Vars.qb.isOpen())
            {
                var response = "";
                if (Vars.isLocalhost() == true)
                {
                    response = File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory + "/xml-debug/accounts.xml");
                }
                else
                {
                    response = Vars.qb.sendRequest(xml);
                }

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(response);
                XmlNodeList rets    = doc.SelectNodes("/QBXML/QBXMLMsgsRs/AccountQueryRs/AccountRet");
                string      message = string.Empty;

                foreach (XmlNode node in rets)
                {
                    Account ac = new Account();
                    ac.ListID                 = node["ListID"].InnerText;
                    ac.TimeCreated            = node["TimeCreated"].InnerText;
                    ac.EditSequence           = node["EditSequence"].InnerText;
                    ac.Name                   = node["Name"].InnerText;
                    ac.FullName               = node["FullName"].InnerText;
                    ac.IsActive               = (bool)(node["IsActive"].InnerText == "true");
                    ac.Sublevel               = node["Sublevel"].InnerText;
                    ac.AccountType            = node["AccountType"].InnerText;
                    ac.AccountNumber          = node["AccountNumber"].InnerText;
                    ac.Balance                = Convert.ToDecimal(node["Balance"].InnerText);
                    ac.TotalBalance           = Convert.ToDecimal(node["TotalBalance"].InnerText);
                    ac.CashFlowClassification = node["CashFlowClassification"].InnerText;
                    if (node.SelectNodes("CurrencyRef").Count > 0)
                    {
                        ac.CurrencyRef = new Currency();
                        if (node["CurrencyRef"]["ListID"] != null)
                        {
                            ac.CurrencyRef.ListID = node["CurrencyRef"]["ListID"].InnerText;
                        }
                        if (node["CurrencyRef"]["FullName"] != null)
                        {
                            ac.CurrencyRef.FullName = node["CurrencyRef"]["FullName"].InnerText;
                        }
                    }

                    //list.Add(node["AccountNumber"].InnerText, ac);
                    list[node["AccountNumber"].InnerText] = ac;
                }
            }

            return(list);
        }
Beispiel #2
0
        public static List <Vendor> getVendors()
        {
            List <Vendor> list = new List <Vendor>();
            //Hashtable list = new Hashtable();

            string xml = "";

            xml += "<?xml version=\"1.0\"?>";
            xml += "<?qbxml version=\"4.0\"?>";
            xml += "<QBXML>";
            xml += "<QBXMLMsgsRq onError=\"stopOnError\">";
            xml += "<VendorQueryRq requestID=\"12\">";
            xml += "<IncludeRetElement>ListID</IncludeRetElement>";
            xml += "<IncludeRetElement>Name</IncludeRetElement>";
            xml += "<IncludeRetElement>FirstName</IncludeRetElement>";
            xml += "<IncludeRetElement>CompanyName</IncludeRetElement>";
            xml += "<IncludeRetElement>IsActive</IncludeRetElement>";
            xml += "<IncludeRetElement>IsVendorEligibleFor1099</IncludeRetElement>";
            xml += "<IncludeRetElement>DataExtRet</IncludeRetElement>";
            xml += "<OwnerID>0</OwnerID>";
            xml += "</VendorQueryRq>";
            xml += "</QBXMLMsgsRq>";
            xml += "</QBXML>";

            if (Vars.qb != null && Vars.qb.isOpen())
            {
                //vendors.xml
                var response = "";
                if (Vars.isLocalhost() == true)
                {
                    response = File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory + "/xml-debug/vendors.xml");
                }
                else
                {
                    response = Vars.qb.sendRequest(xml);
                }

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(response);
                XmlNodeList rets    = doc.SelectNodes("/QBXML/QBXMLMsgsRs/VendorQueryRs/VendorRet");
                string      message = string.Empty;

                foreach (XmlNode node in rets)
                {
                    Vendor v = new Vendor();
                    v.ListID = node["ListID"].InnerText;
                    v.Name   = node["Name"].InnerText;
                    v.active = (bool)(node["IsActive"].InnerText == "true");
                    if (node.SelectNodes("FirstName").Count > 0)
                    {
                        v.FirstName = node["FirstName"].InnerText;
                    }

                    if (node.SelectNodes("CompanyName").Count > 0)
                    {
                        v.CompanyName = node["CompanyName"].InnerText;
                    }

                    v.IsVendorEligibleFor1099 = (bool)(node["IsVendorEligibleFor1099"].InnerText == "true");
                    //v.Balance = float.Parse(node["Balance"].InnerText);

                    XmlNodeList extras = node.SelectNodes("DataExtRet");
                    foreach (XmlNode ex in extras)
                    {
                        var name  = ex["DataExtName"].InnerText;
                        var value = ex["DataExtValue"].InnerText;
                        v.AddDataEx(name, value);
                    }

                    list.Add(v);
                }
            }

            return(list);
        }