Exemple #1
0
        //-----------------------------
        // CREATE RFQ BUTTON METHODS  |
        //-----------------------------
        private void btnCreateRFQ_Click(object sender, EventArgs e)
        {
            RFQ_CreateForm crfq = new RFQ_CreateForm();
            //Generating the RFQ No.
            //Search SQL for existing RFQs with "YYMM-%" (e.g. 1604-%). nthRFQ is +1 to the number of rows returned.
            string year           = DateTime.Now.ToString("yy"); //Last two digits of year (e.g. 2016 becomes 16)
            string month          = DateTime.Now.ToString("MM");
            int    rfqCount       = sql.GetRowCount("rfq_t", year, month);
            string generatedRFQNo = year + month + "-" + (rfqCount + 1).ToString("D3"); //D3 for padded zeroes and ensure there are 3 digits.

            crfq.RFQNo = generatedRFQNo;
            crfq.ShowDialog();        //Validation happens at RFQ_CreateForm.cs

            if (crfq.Cancel == false) //Meaning, will create the RFQ. If Cancel is true, nothing happens.
            {
                //---ADD the new Request for Price Quotation to the ArrayList
                rfqList.Add(new RFQ(crfq.RFQNo,
                                    crfq.RequestDate,
                                    crfq.PaymentTerms,
                                    crfq.DeliveryTerms,
                                    crfq.CustomerIDFK,
                                    crfq.SupplierIDFK,
                                    null)); //Null, since there's no PQ No. (Its value will only be set when its PQ has been created)

                //Save to rfq_t database
                RFQ newRFQ = (RFQ)rfqList[(rfqList.Count - 1)]; //Casting
                sql.InsertRFQ(newRFQ);

                for (int i = 0; i < crfq.RFQOrderLineList.Count; i++) //Go through newly created RFQs' OrderLines
                {
                    //Add to ArrayList
                    RFQ_OrderLine rol = (RFQ_OrderLine)crfq.RFQOrderLineList[i]; //Casting

                    /*rfqOrderLineList.Add(new RFQ_OrderLine(rol.RFQNo,
                     *                                     rol.PartNumber,
                     *                                     rol.Quantity)); --> No need; won't use*/
                    //Save to rfq_order_line_t database
                    sql.InsertRFQOrderLine(rol);

                    //MessageBox.Show("OrderLine added to comprehensive list: " + rol.RFQNo + ", " + rol.PartNumber + ", " + rol.Quantity);
                }

                //---DISPLAY the newly created RFQ in the Main Screen DGV
                dgvRFQ.Rows.Add(crfq.RFQNo, crfq.RequestDate, crfq.SupplierName, crfq.CustomerName);
                dgvRFQ.Sort(dgvRFQ.Columns["RFQNo"], ListSortDirection.Descending); //So that newly added row is on top

                //---OPEN THE RFQ Printout Print Preview
                RFQ_PrintScreen rfqps = new RFQ_PrintScreen();
                rfqps.RFQNo     = crfq.RFQNo; //For the Print Screen to use in its SQL statement
                rfqps.FirstTime = true;
                rfqps.ShowDialog();

                //---MESSAGEBOX FOR DEBUG PURPOSES

                /*MessageBox.Show("RFQ CREATED: " + crfq.RFQNo + ", " + crfq.RequestDate + ", " + crfq.PaymentTerms + ", " +
                 *              crfq.DeliveryTerms + ", " + "Customer " + crfq.CustomerIDFK + ", " + "Supplier " + crfq.SupplierIDFK + ", "
                 + "With " + crfq.RFQOrderLineList.Count + " Orderlines. Inserted to ArrayList index [" + (rfqList.Count - 1) + "]");
                 */
            }
        }