Beispiel #1
0
    /// <summary>
    /// The GetVendorsData.
    /// </summary>
    /// <param name="logsFile">The logsFile<see cref="StreamWriter"/>.</param>
    /// <returns>The <see cref="List{dynamic}"/>.</returns>
    public List <dynamic> GetVendorsData(StreamWriter logsFile)
    {
        IMsgSetRequest requestSet = SessionManager.Instance.CreateMsgSetRequest();

        requestSet.Attributes.OnError = ENRqOnError.roeStop;
        IVendorQuery    VendorQueryRq  = requestSet.AppendVendorQueryRq();
        IMsgSetResponse responeSet     = SessionManager.Instance.DoRequests(requestSet, logsFile);
        IResponseList   responseList   = responeSet.ResponseList;
        List <dynamic>  vendorsArray   = new List <dynamic>();
        var             vendor_name    = "";
        var             vendor_balance = "";
        var             account_number = "";

        try
        {
            for (int i = 0; i < responseList.Count; i++)
            {
                IResponse response = responseList.GetAt(i);
                if (response.StatusCode == 0)
                {
                    IVendorRetList vendorsList = (IVendorRetList)response.Detail;
                    Console.WriteLine("Number Of Records Being Fetched Are:\t" + vendorsList.Count + "\n");
                    for (int j = 0; j < vendorsList.Count; j++)
                    {
                        IVendorRet vendor = vendorsList.GetAt(j);
                        if (vendor.Name != null)
                        {
                            vendor_name = vendor.Name.GetValue();
                        }
                        else
                        {
                            vendor_name = "Name Not Defined...";
                        }
                        if (vendor.Balance != null)
                        {
                            vendor_balance = vendor.Balance.GetValue().ToString();
                        }
                        else
                        {
                            vendor_balance = "Balance Not Defined...";
                        }
                        if (vendor.AccountNumber != null)
                        {
                            account_number = vendor.AccountNumber.GetValue();
                        }
                        else
                        {
                            account_number = "Account Number Not Defined...";
                        }
                        vendorsArray.Add(new string[] { vendor_name, account_number, vendor_balance });
                    }
                }
            }
        }
        catch (Exception ex)
        {
            logsFile.WriteLine(DateTime.Now + "\tERROR\tError Message:\t" + ex.Message);
            logsFile.WriteLine();
            logsFile.WriteLine(DateTime.Now + "\tERROR\tError Message:\tStack Trace:\t" + ex.StackTrace);
            logsFile.WriteLine();
        }

        return(vendorsArray);
    }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //open a session to query all of the existing vendor names
            var qbVendors = new List <string>();

            QBSessionManager sessionManager2 = new QBSessionManager();

            sessionManager2.OpenConnection("appID", "Import To Quickbooks");
            sessionManager2.BeginSession("", ENOpenMode.omDontCare);
            IMsgSetRequest messageSet2 = sessionManager2.CreateMsgSetRequest("US", 7, 0);
            IVendorQuery   vendorQuery = messageSet2.AppendVendorQueryRq();

            vendorQuery.ORVendorListQuery.VendorListFilter.ActiveStatus.SetValue(ENActiveStatus.asActiveOnly);



            try
            {
                IMsgSetResponse responseSet = sessionManager2.DoRequests(messageSet2);
                sessionManager2.EndSession();
                sessionManager2.CloseConnection();

                IResponse      response;
                ENResponseType responseType;

                for (int i = 0; i < responseSet.ResponseList.Count; i++)
                {
                    response = responseSet.ResponseList.GetAt(i);
                    if (response.Detail == null)
                    {
                        continue;
                    }
                    responseType = (ENResponseType)response.Type.GetValue();

                    if (responseType == ENResponseType.rtVendorQueryRs)
                    {
                        IVendorRetList vendorList = (IVendorRetList)response.Detail;
                        for (int vendorIndex = 0; vendorIndex < vendorList.Count; vendorIndex++)
                        {
                            IVendorRet vendor = (IVendorRet)vendorList.GetAt(vendorIndex);

                            if (vendor != null && vendor.CompanyName != null)
                            {
                                qbVendors.Add(vendor.CompanyName.GetValue()); //add all existing vendor names to the list qbvendors
                            }
                        }
                    }
                }
            }
            catch (System.Runtime.InteropServices.COMException comEx) { }

            //call the open file and populate our array of objects used to add bills
            List <ExtractInfo> List1 = getFile();

            //create two lists with existing vendors and a list of vendors from the file
            List <string> vnames   = new List <string>();
            List <string> nameList = new List <string>();

            //find which vendors from the file are not already in quickbooks
            for (int i = 0; i < List1.Count; i++)
            {
                string newVendor = List1[i].vendorName;
                nameList.Add(newVendor);
            }
            foreach (string str in nameList)
            {
                if (!qbVendors.Contains(str))
                {
                    vnames.Add(str);//the list of vendors to be added to quickbooks
                }
            }
            for (int i = 0; i < vnames.Count; i++)
            {
                string add = vnames[i];
                vendorAdd(add);//add vendors into quickbooks if not already there
            }

            populateTextBoxes(List1);
            for (int i = 0; i < List1.Count; i++)
            {
                //Open session to communicate to quickbooks
                QBSessionManager sessionManager = new QBSessionManager();
                sessionManager.OpenConnection("appID", "Create Vendor");
                sessionManager.BeginSession("", ENOpenMode.omDontCare);
                IMsgSetRequest messageSet = sessionManager.CreateMsgSetRequest("US", 13, 0);

                //Add the info to bill(vendor name, invoice num, and dates
                addBillItems(List1, messageSet, i);


                //tell the program to execute the changes to the bill
                IMsgSetResponse responseSet = sessionManager.DoRequests(messageSet);

                //close the session and end connection
                sessionManager.EndSession();
                sessionManager.CloseConnection();

                //report errors if any
                for (int k = 0; k < responseSet.ResponseList.Count; k++)
                {
                    IResponse response = responseSet.ResponseList.GetAt(k);
                    var       code     = response.StatusCode;
                    string    code2    = code.ToString();

                    string code3 = response.StatusMessage;
                    if (response.StatusCode > 0)
                    {
                        MessageBox.Show(code3);
                    }
                }
            }
        }