public void AddProductionLine(ProductionLine plNewLine)
        {
            Array.Resize<Control>(ref aProductionLines, aProductionLines.Length + 1);

            aProductionLines[aProductionLines.Length - 1] = plNewLine;

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

            plNewLine.Left = 1;

            plNewLine.TabIndex = 50 + aProductionLines.Length;
            plNewLine.TabStop = true;

            plNewLine.iLineIndex = aProductionLines.Length - 1;
            plNewLine.Name = "plNewLine_" + (aProductionLines.Length - 1).ToString();

            this.pnlDetails.Controls.Add(plNewLine);
            plNewLine.BringToFront();
            iLineRowIndex++;
        }
        private void MakeLineReadOnly(ref ProductionLine plLine)
        {
            plLine.txtStockIssueNum.ReadOnly = true;
            plLine.txtRawBatchNum.ReadOnly = true;
            plLine.txtRawCode.ReadOnly = true;

            plLine.txtProdBatch.ReadOnly = true;
            plLine.txtProdCode.ReadOnly = true;
            plLine.txtDescription.ReadOnly = true;
            plLine.txtUnit.ReadOnly = true;
            plLine.txtQuantity.ReadOnly = true;
        }
        private void DBLoadProductionDocLines(string sPDocNumber)
        {
            //Clear All Current Lines
            for (int iLines = 0; iLines < aProductionLines.Length; iLines++)
            {
                ProductionLine plThisline = (((ProductionLine)aProductionLines[iLines]));
                this.pnlDetails.Controls.Remove(plThisline);
            }

            //Reset Controls
            iLineRowIndex = 0;
            aProductionLines = new Control[0];

            string sStockIssueNum = "";
            string sRawBatchNum = "";
            string sRawItemCode = "";

            string sPLineBatchNum = "";
            string sPLineItemCode = "";
            string sPLineDesc = "";
            string sPLineUnit = "";

            decimal dPLineQty = 0;

            if (txtNumber.Text != "*NEW*")
            {
                string sSql = "";

                using (PsqlConnection liqConn = new PsqlConnection(Connect.sConnStr))
                {
                    liqConn.Open();

                    sSql = "SELECT * FROM SOLPRODL";
                    sSql += " WHERE DocNumber = '" +sPDocNumber + "'";

                    PsqlDataReader rdInvtReader = Connect.getDataCommand(sSql, liqConn).ExecuteReader();

                    if (rdInvtReader.HasRows)
                    {
                        while (rdInvtReader.Read())
                        {
                            //Assign Values
                            sStockIssueNum = rdInvtReader["StockIssueNum"].ToString();
                            sRawBatchNum = rdInvtReader["RawBatchNumber"].ToString();
                            sRawItemCode = rdInvtReader["RawItemCode"].ToString();

                            sPLineBatchNum = rdInvtReader["PBatchNumber"].ToString();
                            sPLineItemCode = rdInvtReader["PItemCode"].ToString();
                            sPLineDesc = rdInvtReader["PDescription"].ToString();
                            sPLineUnit = rdInvtReader["PUnit"].ToString();

                            dPLineQty = Convert.ToDecimal(rdInvtReader["PQty"].ToString());

                            ProductionLine plNewLine = new ProductionLine();

                            plNewLine.txtStockIssueNum.Text = sStockIssueNum;
                            plNewLine.txtRawBatchNum.Text = sRawBatchNum;
                            plNewLine.txtRawCode.Text = sRawItemCode;

                            plNewLine.txtProdBatch.Text = sPLineBatchNum;
                            plNewLine.txtProdCode.Text = sPLineItemCode;
                            plNewLine.txtDescription.Text = sPLineDesc;
                            plNewLine.txtUnit.Text = sPLineUnit;
                            plNewLine.txtQuantity.Text = dPLineQty.ToString("N2");

                            MakeLineReadOnly(ref plNewLine);

                            AddProductionLine(plNewLine);

                        }

                        rdInvtReader.Close();
                    }

                    liqConn.Close();
                }
            }
        }
        public void focusNextLine(int iLineIndex)
        {
            if ((iLineIndex >= aProductionLines.Length && txtNumber.Text == "*NEW*") || (iLineIndex >= aProductionLines.Length && txtNumber.Text == ""))
            {
                if (txtNumber.Text == "")
                    txtNumber.Text = "*NEW*";

                ProductionLine plNewLine = new ProductionLine();
                AddProductionLine(plNewLine);
            }

            if (iLineIndex < aProductionLines.Length)
            {
                ProductionLine plNewLine = (ProductionLine)aProductionLines[iLineIndex];
                plNewLine.txtStockIssueNum.Focus();
            }
        }
        public void DeleteProductionLine(ProductionLine slDeletedLine, bool bDeleteLastLine)
        {
            bool bDeleteControl = false;
            for (int iLines = 0; iLines < aProductionLines.Length; iLines++)
            {
                ProductionLine plThisline = (((ProductionLine)aProductionLines[iLines]));

                if (iLines != aProductionLines.Length - 1 || bDeleteLastLine) //Don't delete last row
                {
                    if (slDeletedLine.Name == plThisline.Name)
                    {
                        bDeleteControl = true;
                        this.pnlDetails.Controls.Remove(slDeletedLine);

                        if (iLines != aProductionLines.Length - 1)
                        {
                            (((ProductionLine)aProductionLines[iLines + 1])).txtStockIssueNum.Focus(); //focus next line
                        }
                    }

                    if (bDeleteControl && iLines != aProductionLines.Length - 1) //resize the line array
                    {
                        aProductionLines[iLines] = aProductionLines[iLines + 1]; //move all the controls one up in the list
                        (((ProductionLine)aProductionLines[iLines + 1])).Location = new Point((((ProductionLine)aProductionLines[iLines + 1])).Location.X, (((ProductionLine)aProductionLines[iLines + 1])).Location.Y - 20); //move location of control to new position
                        (((ProductionLine)aProductionLines[iLines + 1])).iLineIndex--; //sync the lineindex of the control array
                    }
                }
            }
        }