private void genPackageID()
        {
            string  existPackage = null;
            Random  rnd          = new Random();
            string  id           = "PG" + rnd.Next(100000, 999999);
            Package p            = ppda.getOneProductPackageByID(id, Language.getLanguageCode(), conn);

            existPackage = p.getProductID();
            Package dp = ppda.getOneDeletedPackageByID(id, Language.getLanguageCode(), conn);

            existPackage = dp.getProductID();

            if (existPackage != null)
            {
                genPackageID();
            }
            else
            {
                packageIdTextBox.Text = id;
            }
        }
Exemple #2
0
        private void approvalButton_Click(object sender, EventArgs e)
        {
            bool qtyBelow50 = false;

            if (!qtyBelow50)
            {
                Package package = ppgda.getOneProductPackageByID(packageOl.getProductID(), Language.getLanguageCode(), conn);
                if (package.getQtyInStock() < 1)
                {
                    qtyBelow50 = true;
                }
            }

            if (!qtyBelow50)
            {
                Bottle bottle = pbda.getOneProductBottleByID(bottleOl.getProductID(), Language.getLanguageCode(), conn);
                if (bottle.getQtyInStock() < 1)
                {
                    qtyBelow50 = true;
                }
            }

            if (!qtyBelow50)
            {
                foreach (OrderLine perfumeOl in perfumeOlList)
                {
                    Perfume perfume = ppda.getOneProductPerfumeByID(perfumeOl.getProductID(), Language.getLanguageCode(), conn);
                    if (perfume.getQtyInStock() < 50)
                    {
                        qtyBelow50 = true;
                        break;
                    }
                }
            }

            if (qtyBelow50)
            {
                rejectButton_Click(null, null);
            }
            else
            {
                Package package = ppgda.getOneProductPackageByID(packageOl.getProductID(), Language.getLanguageCode(), conn);
                package.setQtyInStock(package.getQtyInStock() - 1);
                ppgda.update(package, conn);

                Bottle bottle = pbda.getOneProductBottleByID(bottleOl.getProductID(), Language.getLanguageCode(), conn);
                bottle.setQtyInStock(bottle.getQtyInStock() - 1);
                pbda.update(bottle, conn);

                foreach (OrderLine perfumeOl in perfumeOlList)
                {
                    Perfume perfume = ppda.getOneProductPerfumeByID(perfumeOl.getProductID(), Language.getLanguageCode(), conn);
                    perfume.setQtyInStock(perfume.getQtyInStock() - perfumeOl.getQty());
                    ppda.update(perfume, conn);
                }

                productCategoriesComboBox_SelectedIndexChanged(null, null);

                orderDetail.setApprovedDate(DateTime.Now.Date);
                orderDetail.setRejected(false);
                orderDetail.setApprovedByEmpID(staffID);

                if (oda.update(orderDetail, conn) > 0)
                {
                    MessageBox.Show(rs.GetString("orderApprovalMsg"));
                }
                else
                {
                    MessageBox.Show(rs.GetString("failToUpdateMsg"), rs.GetString("errorText"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }


            approvalButton.Enabled = false;
            rejectButton.Enabled   = false;

            showOrderDetail(orderDetail.getOrderID());

            for (int i = orderDataGridView.Rows.Count - 1; i >= 0; i--)
            {
                if (orderDataGridView.Rows[i].Cells["orderIdColumn"].Value.Equals(orderDetail.getOrderID()))
                {
                    orderDataGridView.Rows.Remove(orderDataGridView.Rows[i]);
                }
            }
        }