public void AddCustomerInvLine(CustomerInvoiceLine clNewLine)
        {
            Array.Resize<Control>(ref aCustomerInvLines, aCustomerInvLines.Length + 1);

            aCustomerInvLines[aCustomerInvLines.Length - 1] = clNewLine;

            //JR13
            if (iLineRowIndex < 14)
                clNewLine.Top = 22 + ((iLineRowIndex) * 20);
            else
                clNewLine.Top = 268;

            clNewLine.Left = 1;

            clNewLine.TabIndex = 50 + aCustomerInvLines.Length;
            clNewLine.TabStop = true;

            clNewLine.iLineIndex = aCustomerInvLines.Length - 1;
            clNewLine.Name = "clNewLine_" + (aCustomerInvLines.Length - 1).ToString();

            this.pnlDetails.Controls.Add(clNewLine);
            clNewLine.BringToFront();

            iLineRowIndex++;
        }
        private void DBLoadLine(string sDocNumber, string sStore, string sBatchNumber, string sCode, string sDescription, string sUnit, string sQty, string sExcPrice, string sDiscount, string sTaxType)
        {
            CustomerInvoiceLine clNewLine = new CustomerInvoiceLine();

            clNewLine.bDoCalculation = false; //Do totals only after the control has been loaded.
            clNewLine.txtStore.Text = sStore.Trim();

            clNewLine.txtBatchNum.Text = sBatchNumber;
            clNewLine.txtCode.Text = sCode.Trim();
            clNewLine.txtDescription.Text = sDescription.Trim().Substring(0, sDescription.Trim().IndexOf("~"));
            clNewLine.txtUnit.Text = sUnit.Trim();
            clNewLine.txtQuantity.Text = sQty.Trim();

            clNewLine.txtExcPrice.Text = (Convert.ToDouble(sExcPrice.Trim())).ToString("N2");
            clNewLine.txtDiscount.Text = sDiscount.Trim();
            clNewLine.txtTaxType.Text = sTaxType.Trim();

            if (sTaxType == "0")
            {
                clNewLine.txtNet.BackColor = Color.Yellow;
            }
            else
            {
                clNewLine.txtNet.BackColor = Color.White;
            }

            double dTotalExDiscount = Convert.ToDouble(clNewLine.txtQuantity.Text.Replace(",", "")) * Convert.ToDouble(clNewLine.txtExcPrice.Text.Replace(",", ""));

            clNewLine.txtNet.Text = (dTotalExDiscount - (dTotalExDiscount * (Convert.ToDouble(clNewLine.txtDiscount.Text.Replace(",", "")) / 100))).ToString("N2");

            clNewLine.bDoCalculation = true;
            AddCustomerInvLine(clNewLine);
        }
        private string BuildInvoiceLinesNormal(CustomerInvoiceLine clThisLine, int iLines)
        {
            string sLine = "";

            string sQuantity = Convert.ToDecimal(clThisLine.txtQuantity.Text.Replace(",", "").Trim()).ToString();

            sLine += "|"; //Cost Price
            sLine += sQuantity + "|"; //Line Quantity
            sLine += clThisLine.txtExcPrice.Text.Replace(",", "").Trim() + "|"; //Exclusive Price Per Unit

            //*********** Inclusive Price Per Unit **********
            if (clThisLine.txtTaxType.Text == "0")
                sLine += (Convert.ToDouble(clThisLine.txtExcPrice.Text)).ToString().Replace(",", "") + "|";
            else if (clThisLine.txtTaxType.Text == "1")
                sLine += (Convert.ToDouble(clThisLine.txtExcPrice.Text) * 1.14).ToString().Replace(",", "") + "|";
            else
                sLine += (Convert.ToDouble(clThisLine.txtExcPrice.Text)).ToString().Replace(",", "") + "|"; //Other tax types will pass a 0 tax value through
            //***********************************************

            sLine += clThisLine.txtUnit.Text.Trim() + "|"; //Unit
            sLine += clThisLine.txtTaxType.Text.PadLeft(2, "0".ToCharArray()[0]) + "|"; //Tax Type

            sLine += "0|"; //Discount Type
            sLine += clThisLine.txtDiscount.Text.Replace(".", "").Replace(",", "") + "|"; //Discount %
            sLine += clThisLine.txtCode.Text.Trim() + "|"; //Code
            sLine += clThisLine.txtDescription.Text.Trim() + "~" + iLines + "|"; //Description

            sLine += "4|"; //Line Type
            sLine += clThisLine.txtStore.Text.Trim() + "|"; //Line Type
            sLine += "|"; //CostCode

            return sLine;
        }
        private string BuildInvoiceLinesComment(CustomerInvoiceLine clThisLine)
        {
            string sLine = "";

            string sDescription = clThisLine.txtDescription.Text;

            sLine = "|"; //Cost Price
            sLine += "|"; //Line Quantity
            sLine += "|"; //Exclusive Price Per Unit
            sLine += "|"; //Inclusive Price Per Unit
            sLine += "|"; //Unit
            sLine += "|"; //Tax Type
            sLine += "|"; //Discount Type
            sLine += "|"; //Discount %
            sLine += "'|"; //Code
            sLine += sDescription + "|"; //Description
            sLine += "7|"; //Line Type
            sLine += "|"; //Line Type
            sLine += "|"; //CostCode

            return sLine;
        }
        public void focusNextLine(int iLineIndex)
        {
            if ((iLineIndex >= aCustomerInvLines.Length && txtNumber.Text == "*NEW*") || (iLineIndex >= aCustomerInvLines.Length && txtNumber.Text.Trim() == ""))
            {
                if (txtNumber.Text.Trim() == "")
                    txtNumber.Text = "*NEW*";

                CustomerInvoiceLine clNewLine = new CustomerInvoiceLine();
                AddCustomerInvLine(clNewLine);
            }

            if (iLineIndex < aCustomerInvLines.Length)
            {
                CustomerInvoiceLine clNewLine = (CustomerInvoiceLine)aCustomerInvLines[iLineIndex];
                clNewLine.txtBatchNum.Focus();
            }
        }
        public void DeleteCustomerInvLine(CustomerInvoiceLine clDeletedLine, bool bDeleteLastLine)
        {
            bool bDeleteControl = false;

            for (int iLines = 0; iLines < aCustomerInvLines.Length; iLines++)
            {
                CustomerInvoiceLine clThisline = (((CustomerInvoiceLine)aCustomerInvLines[iLines]));

                if (iLines != aCustomerInvLines.Length - 1 || bDeleteLastLine) //Never Delete Last Line
                {
                    if (clThisline.Name == clThisline.Name)
                    {
                        bDeleteControl = true;

                        this.pnlDetails.Controls.Remove(clThisline);
                        if (iLines != aCustomerInvLines.Length - 1)
                        {
                            (((CustomerInvoiceLine)aCustomerInvLines[iLines + 1])).txtCode.Focus(); //focus next line
                        }
                    }

                    if (bDeleteControl && iLines != aCustomerInvLines.Length - 1) //resize the line array
                    {
                        aCustomerInvLines[iLines] = aCustomerInvLines[iLines + 1]; //move controls one up in the list

                        (((CustomerInvoiceLine)aCustomerInvLines[iLines + 1])).Location = new Point((((CustomerInvoiceLine)aCustomerInvLines[iLines + 1])).Location.X, (((CustomerInvoiceLine)aCustomerInvLines[iLines + 1])).Location.Y - 20); //move location of control to new position
                        (((CustomerInvoiceLine)aCustomerInvLines[iLines + 1])).iLineIndex--; //sync the lineindex of the control array
                    }
                }
            }

            AddTotals();

            if (bDeleteControl) //update the line array
            {
                Array.Resize<Control>(ref aCustomerInvLines, aCustomerInvLines.Length - 1);
                iLineRowIndex--;
            }
        }