Пример #1
0
        // add product
        public void FuncAddProduct(tblChiTietHoaDonNhapHang invoiceDetail)
        {
            db.tblChiTietHoaDonNhapHangs.Add(invoiceDetail);
            var product = db.tblHangHoas.Find(invoiceDetail.MaHangHoa);

            product.SoLuong += (int)invoiceDetail.SoLuong;
            var invoice = db.tblHoaDonNhapHangs.Find(invoiceDetail.MaHoaDonNhap);

            invoice.SoTien += +invoiceDetail.TongTien;
            db.SaveChanges();
        }
Пример #2
0
 public void FuncDeleteProduct(List <string> listIdProduct, string idInvoice)
 {
     foreach (string idProduct in listIdProduct)
     {
         tblChiTietHoaDonNhapHang invoiceDetail = db.tblChiTietHoaDonNhapHangs.Where(p => p.MaHangHoa == idProduct &&
                                                                                     p.MaHoaDonNhap == idInvoice).SingleOrDefault();
         var product = db.tblHangHoas.Find(idProduct);
         product.SoLuong -= (int)invoiceDetail.SoLuong;
         var invoice = db.tblHoaDonNhapHangs.Find(idInvoice);
         invoice.SoTien -= (double)invoiceDetail.TongTien;
         db.tblChiTietHoaDonNhapHangs.Remove(invoiceDetail);
         db.SaveChanges();
     }
 }
Пример #3
0
        // add product for invoice
        private void btnAddProductForInvoice_Click(object sender, EventArgs e)
        {
            idProduct       = dgvProduct.SelectedRows[0].Cells["MaHangHoa"].Value.ToString();
            quantityProduct = Convert.ToInt32(txtQuantity.Text.Trim());
            productPrice    = Convert.ToDouble(dgvProduct.SelectedRows[0].Cells[3].Value.ToString());
            discount        = Convert.ToInt32(txtDiscount.Text.Trim());
            switch (isListSale)
            {
            case true:
                if (quantityProduct > Convert.ToInt32(dgvProduct.SelectedRows[0].Cells["SoLuong"].Value.ToString()))
                {
                    lbSTATUS.Text = "KHÔNG ĐỦ SL";
                }
                else
                {
                    lbSTATUS.Text = "";

                    if (BLL_LISTSALEINVOICE.Instance.isHasProductInInvoice(idInvoice, idProduct))
                    {
                        MessageBox.Show("Hàng hóa đã tồn tại trong hóa đơn!", "Trùng hàng hóa",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        tblChiTietHoaDonBanHang invoiceDetail = new tblChiTietHoaDonBanHang();
                        invoiceDetail.MaHoaDonBan = idInvoice;
                        invoiceDetail.MaHangHoa   = idProduct;
                        invoiceDetail.SoLuong     = quantityProduct;
                        invoiceDetail.DonGia      = productPrice;
                        invoiceDetail.GiamGia     = discount;
                        invoiceDetail.TongTien    = productPrice * quantityProduct - productPrice * quantityProduct
                                                    * discount / 100;
                        BLL_LISTSALEINVOICE.Instance.FuncAddProduct(invoiceDetail);
                        DialogResult answer = MessageBox.Show("Thêm thành công hàng hóa. Bạn có muốn tiếp tục thêm?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (answer == DialogResult.Yes)
                        {
                            LoadProduct();
                        }
                        else
                        {
                            d(idInvoice);
                            this.Close();
                        }
                    }
                }
                break;

            case false:
                if (BLL_LISTIMPORTINVOICE.Instance.isHasProductInInvoice(idInvoice, idProduct))
                {
                    MessageBox.Show("Hàng hóa đã tồn tại trong hóa đơn!", "Trùng hàng hóa",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    tblChiTietHoaDonNhapHang invoicedetail = new tblChiTietHoaDonNhapHang();
                    invoicedetail.MaHoaDonNhap = idInvoice;
                    invoicedetail.MaHangHoa    = idProduct;
                    invoicedetail.SoLuong      = quantityProduct;
                    invoicedetail.GiaNhap      = productPrice;
                    invoicedetail.TongTien     = productPrice * quantityProduct;
                    BLL_LISTIMPORTINVOICE.Instance.FuncAddProduct(invoicedetail);
                    DialogResult answer = MessageBox.Show("Thêm thành công hàng hóa. Bạn có muốn tiếp tục thêm?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (answer == DialogResult.Yes)
                    {
                        LoadProduct();
                    }
                    else
                    {
                        d(idInvoice);
                        this.Close();
                    }
                }
                break;

            default:
                break;
            }
        }