示例#1
0
        private void btnCreatePO_Click(object sender, EventArgs e)
        {
            if (dgvPQSelected.Rows.Count == 0)
            {
                MessageBox.Show("Please include Price Quotation.", "Incomplete Fields", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            this.Close();

            PO_CreateForm pof = new PO_CreateForm();


            for (int i = 0; i < dgvPQSelected.RowCount; i++)
            {
                string          pqNo;
                DataGridViewRow row = dgvPQSelected.Rows[i];
                pqNo = (row.Cells["SelectedPQNo"].Value).ToString();                                                                                                                   //get the PQNo of the pq selected
                PQ p = sql.SelectPQDetails(pqNo);                                                                                                                                      //from the RFQNo taken, get its details
                selectedPQList.Add(new PQ(p.PQNo, p.PQDate, p.PQFromDate, p.PQToDate, p.PaymentTerms, p.DeliveryTerms, p.BillTo, p.ShipTo, p.InFavorOf, p.TotalAmount, p.CustomerID)); //put in an ArrayList the details taken
                pof.PQNo = pqNo;
                PQ_OrderLine pqol = sql.SelectPQOrderLine(pqNo);
                pqOrderLineList.Add(new PQ_OrderLine(pqol.PQNo, pqol.PartNumber, pqol.ReicUnitPrice, pqol.Quantity, pqol.ItemTotal));

                for (int j = 0; j < pqOrderLineList.Count; j++)
                {
                    Item item = sql.SelectItemDetails(pqol.PartNumber);
                    itemList.Add(new Item(item.PartNumber, item.ItemName, item.ItemDescription, item.SupplierUnitPrice, item.Markup, item.ReicUnitPrice, item.Moq, item.Uom, item.FromDateNoTime, item.ToDateNoTime, item.SupplierID));
                    Supplier s = sql.SelectSupplierDetails(item.SupplierID);
                    pof.SupplierName    = s.SupplierName;
                    pof.SupplierPerson  = s.SupplierPerson;
                    pof.SupplierNumber  = s.SupplierNumber;
                    pof.SupplierEmail   = s.SupplierEmail;
                    pof.SupplierAddress = s.SupplierAddress;

                    pof.SupplierID = item.SupplierID.ToString();

                    MessageBox.Show("umabot ka dito");
                }

                /*
                 * string year = DateTime.Now.ToString("yy");
                 * string month = DateTime.Now.ToString("MM");
                 * int pqCount = sql.GetRowCount("pq_t", year, month);
                 * string generatedPONo = year + month + "-" + (pqCount + 1).ToString("D3");
                 * pof.PONo = generatedPONo;
                 *
                 * pf.PaymentTerms = r.PaymentTerms;
                 * pf.DeliveryTerms = r.DeliveryTerms;
                 */
                Customer c = sql.SelectCustomerDetails(p.CustomerID); //to retrieve the details of Customer from MySqlDatabaseDriver
                pof.CustomerName = c.CustomerName;

                /* pf.CustomerPerson = c.CustomerPerson;
                 * pf.CustomerNumber = c.CustomerNumber;
                 * pf.CustomerEmail = c.CustomerEmail;
                 * pf.CustomerAddress = c.CustomerAddress;*/


                pof.ShowDialog();

                if (pof.Cancel == false)
                {//if save button were clicked, this will save the pq details in arrayList then in the database
                    string OrderDateNoTime    = pof.OrderDate.ToShortDateString();
                    string RequiredDateNoTime = pof.RequiredDate.ToShortDateString();

                    poList.Add(new PO(pof.PONo,
                                      OrderDateNoTime,
                                      RequiredDateNoTime,
                                      pof.OrderDesc,
                                      pof.PQNo,
                                      pof.PaymentTerms,
                                      pof.DeliveryTerms,
                                      double.Parse(pof.NetSubTotal),
                                      double.Parse(pof.DeliveryCosts),
                                      double.Parse(pof.OrderTotal),
                                      int.Parse(pof.SupplierID),
                                      pof.CustomerIDFK,
                                      null));


                    PO newPO = (PO)poList[(poList.Count - 1)];
                    sql.InsertPO(newPO);

                    for (int j = 0; j < pof.POOrderLineList.Count; j++)
                    {
                        PO_OrderLine pol = (PO_OrderLine)pof.POOrderLineList[j];
                        sql.InsertPOOrderLine(pol);
                        MessageBox.Show("OrderLine added to comprehensive list: " + pol.PONo + ", " + pol.PartNumber + ", " + pol.SupplierUnitPrice + "," + pol.Quantity + "," + pol.ItemTotal);
                    }
                }
            }
        }