private static void buildSalesRequest(string[,] sales, IMsgSetRequest requestSet)
    {
        //Walk sales array and build SalesReceiptAdd xmls
        int length = sales.GetLength(0);

        string[,] items = new string[length, 3];
        int itemRow = 0;

        for (int x = 0; x < length; x++)
        {
            string orderNumber      = (sales[x, 0] != null) ? sales[x, 0] : "";
            string customerFullName = (sales[x, 1] != null) ? sales[x, 1] : "";
            string itemFullName     = (sales[x, 2] != null) ? sales[x, 2] : "";
            string itemRate         = (sales[x, 3] != null) ? sales[x, 3] : "";
            string quantityOrdered  = (sales[x, 4] != null) ? sales[x, 4] : "";

            items[itemRow, 0] = itemFullName;
            items[itemRow, 1] = itemRate;
            items[itemRow, 2] = quantityOrdered;

            //Peek into the next orderNumber.
            if (x + 1 < length && sales[x + 1, 0] == orderNumber)
            {
                itemRow++;
                continue;
            }
            string[,] lineItems = UtilityManager.CompactThisTwoDimensionalArray(items);

            ISalesReceiptAdd SalesReceiptAdd = requestSet.AppendSalesReceiptAddRq();
            SalesReceiptAdd.RefNumber.SetValue(orderNumber);
            SalesReceiptAdd.CustomerRef.FullName.SetValue(customerFullName);

            //Walk items array and build the SalesReceiptAddRq xml
            for (int r = 0; r < lineItems.GetLength(0); r++)
            {
                itemFullName    = lineItems[r, 0];
                itemRate        = lineItems[r, 1];
                quantityOrdered = lineItems[r, 2];
                ISalesReceiptLineAdd SalesReceiptLine = SalesReceiptAdd.ORSalesReceiptLineAddList.Append().SalesReceiptLineAdd;
                SalesReceiptLine.ItemRef.FullName.SetValue(itemFullName);
                SalesReceiptLine.ORRatePriceLevel.Rate.SetValue(Convert.ToDouble(itemRate));
                SalesReceiptLine.Quantity.SetValue(Convert.ToDouble(quantityOrdered));
            }
            lineItems = UtilityManager.ResetThisTwoDimensionalArray(lineItems);
            itemRow   = 0;
        }
    }
        private IMsgSetRequest Build_AddSalesReciept()
        {
            QBSessionManager sessionManager = new QBSessionManager();

            sessionManager.OpenConnection("", "Quickbooks Input Tool");
            sessionManager.BeginSession("", ENOpenMode.omDontCare);

            IMsgSetRequest requestMsgSet = getLatestMsgSetRequest(sessionManager);

            requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
            ISalesReceiptAdd salesRecieptAdd = requestMsgSet.AppendSalesReceiptAddRq();

            if (locationDropdown.Text != "")
            {
                salesRecieptAdd.CustomerRef.FullName.SetValue(locationDropdown.Text);
            }
            else
            {
                consoleOutput.AppendText("\r\nPlease select a customer");
                return(null);
            }

            if (fileStream != null)
            {
                try
                {
                    using (var fs = File.OpenRead(fileStream.ToString()))
                        using (var reader = new StreamReader(fs))
                        {
                            List <string> items = new List <string>();
                            List <string> qtys  = new List <string>();


                            while (!reader.EndOfStream)
                            {
                                var line   = reader.ReadLine();
                                var values = line.Split(',');
                                items.Add(values[0]);
                                qtys.Add(values[4]);
                            }
                            for (int i = 1; i < items.Count; i++)
                            {
                                if (getItemInfo(items[i]) != "")
                                {
                                    addBottleReturn(items[i]);
                                    IORSalesReceiptLineAdd salesRecieptLine = salesRecieptAdd.ORSalesReceiptLineAddList.Append();
                                    salesRecieptLine.SalesReceiptLineAdd.ItemRef.FullName.SetValue(getItemInfo(items[i]));
                                    salesRecieptLine.SalesReceiptLineAdd.Quantity.SetValue(Convert.ToDouble(qtys[i]));
                                    //salesRecieptLine.SalesReceiptLineAdd.ClassRef.FullName.SetValue("RETAIL STORE"); //Redstone only
                                }
                                else
                                {
                                    consoleOutput.AppendText("\r\nError finding " + items[i] + " in Quickbooks");
                                }
                            }
                            if (numLargeBottles != 0)
                            {
                                if (getItemInfo("BOTTLE DEPOSIT 20") != "")
                                {
                                    consoleOutput.AppendText("\r\nNumber of 20 cent bottles added: " + numLargeBottles);
                                    IORSalesReceiptLineAdd salesRecieptLine = salesRecieptAdd.ORSalesReceiptLineAddList.Append();
                                    salesRecieptLine.SalesReceiptLineAdd.ItemRef.FullName.SetValue(getItemInfo("BOTTLE DEPOSIT 20"));
                                    salesRecieptLine.SalesReceiptLineAdd.Quantity.SetValue(Convert.ToDouble(numLargeBottles));
                                    //salesRecieptLine.SalesReceiptLineAdd.ClassRef.FullName.SetValue("RETAIL STORE"); //Redstone only
                                }
                                else
                                {
                                    consoleOutput.AppendText("\r\nError finding BOTTLE DEPOSIT 20 in Quickbooks");
                                }
                            }
                            if (numSmallBottles != 0)
                            {
                                if (getItemInfo("BOTTLE DEPOSIT 10") != "")
                                {
                                    consoleOutput.AppendText("\r\nNumber of 10 cent bottles added: " + numLargeBottles);
                                    IORSalesReceiptLineAdd salesRecieptLine = salesRecieptAdd.ORSalesReceiptLineAddList.Append();
                                    salesRecieptLine.SalesReceiptLineAdd.ItemRef.FullName.SetValue(getItemInfo("BOTTLE DEPOSIT 10"));
                                    salesRecieptLine.SalesReceiptLineAdd.Quantity.SetValue(Convert.ToDouble(numSmallBottles));
                                    //salesRecieptLine.SalesReceiptLineAdd.ClassRef.FullName.SetValue("RETAIL STORE"); //Redstone only
                                }
                                else
                                {
                                    consoleOutput.AppendText("\r\nError finding BOTTLE DEPOSIT 10 in Quickbooks");
                                }
                            }
                        }
                }
                catch (Exception ex)
                {
                    consoleOutput.AppendText("\r\n" + ex);
                }
            }
            else
            {
                consoleOutput.AppendText("\r\nPlease select a file first");
                return(null);
            }
            try
            {
                IMsgSetResponse responseSet = sessionManager.DoRequests(requestMsgSet);
                consoleOutput.AppendText("\r\n" + responseSet.ToXMLString());
            }
            catch (Exception e)
            {
                consoleOutput.AppendText("\r\n this error " + e);
            }

            notFoundItems.ForEach(delegate(String item)
            {
                consoleOutput.AppendText("\r\n" + item + " was not found in Quickbooks");
            });
            groupItems.ForEach(delegate(String item)
            {
                consoleOutput.AppendText("\r\n" + item + " is a group item, it needs to be entered manually");
            });
            return(requestMsgSet);
        }