public frmWarehousing(int ProductID) { InitializeComponent(); this._ProductID = ProductID; // get product name DataTable dt = bus_Product.BUS_GetBasicInfo_Products(this._ProductID); if (dt == null) { MessageBox.Show("Có lỗi xẩy ra trong quá trình load dữ liệu!\nVui lòng tải lại dữ liệu.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } if (dt.Rows.Count > 0) { txbProductName.Text = dt.Rows[0]["TENSP"].ToString(); } else { MessageBox.Show("Có lỗi xẩy ra trong quá trình load dữ liệu!\nVui lòng tải lại dữ liệu.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } }
private void IncreaseQuantity_ContextMenu_Click(object sender, EventArgs e) { try { int ProductID = int.Parse(dtgvShowProduct.SelectedRows[0].Cells["ProductID"].Value.ToString()); int Quantity = int.Parse(dtgvShowProduct.SelectedRows[0].Cells["ProductQuantity"].Value.ToString()); // get được số lượng còn lại của sản phẩm này trong kho BUS_SanPham bus_Products = new BUS_SanPham(); DataTable dtProduct = bus_Products.BUS_GetBasicInfo_Products(ProductID); if (dtProduct == null) { return; } if (dtProduct.Rows.Count > 0) { Quantity++; int MaxProductQuantity = (int)dtProduct.Rows[0]["SoLuong"]; if (Quantity > MaxProductQuantity) { MessageBox.Show("Số lượng sản phẩm chọn lớn hơn số lượng còn lại trong kho!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { // cập nhật trong cart Cart.IncreaseProductQuantityChosen(ProductID); // update số lượng dtgvShowProduct.SelectedRows[0].Cells["ProductQuantity"].Value = Quantity; // lấy giá 1 sản phẩm int productPriceAfterSale = (int)dtgvShowProduct.SelectedRows[0].Cells["ProductPriceSale"].Value; // update giá tiền int TotalPrice = Quantity * productPriceAfterSale; dtgvShowProduct.SelectedRows[0].Cells["ProductTotalCost"].Value = TotalPrice; // update tổng tiền txbTotalCost.Text = MySupportMethods.StrMoneyToStrCurrency((MySupportMethods.StrCurrencyToInt(txbTotalCost.Text) + productPriceAfterSale).ToString()); } } else { MessageBox.Show($"Sản phẩm có mã số {ProductID} không tồn tại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } catch (Exception ex) { } }
public void ReloadForm() { //dtpkDateSell.Value = DateTime.Now; if (IsSelling == true) { // xóa dữ liệu trong datagridview dtgvShowProduct.Rows.Clear(); // load du lieu tu Cart vao datagridview Dictionary <int, int> listProductID = Cart.GetListProductID(); BUS_SanPham bus_Product = new BUS_SanPham(); try { int TotalCostForAll = 0; foreach (var key in listProductID.Keys) { DataTable dtProductInfo = bus_Product.BUS_GetBasicInfo_Products(key); if (dtProductInfo == null) { return; } if (dtProductInfo.Rows.Count > 0) { // lấy ảnh Image img; using (System.IO.MemoryStream ms = new System.IO.MemoryStream((Byte[])dtProductInfo.Rows[0]["HinhAnh"])) { img = Image.FromStream(ms); } Image ImgResize = MySupportMethods.ResizeImage(img, img.Width * 100 / img.Height, 100); // lấy tên string ProductName = dtProductInfo.Rows[0]["TenSP"].ToString(); // lấy đơn giá int ProductPrice = int.Parse(dtProductInfo.Rows[0]["DonGia"].ToString()); // lấy số lượng int ProductQuantityChosen = listProductID[key]; // đơn giá khuyến mãi int ProductPriceSale = ProductPrice; // lấy giá sau khuyến mãi foreach (var promo in listPromotion) { ProductPriceSale = promo.CalcDiscount(ProductPriceSale); } // tổng tiền int TotalCost = ProductPriceSale * ProductQuantityChosen; // thêm row vào datagridview dtgvShowProduct.Rows.Add(ImgResize, key, ProductName, ProductQuantityChosen, ProductPrice, ProductPriceSale, TotalCost); TotalCostForAll += TotalCost; // cập nhật tổng tiền txbTotalCost.Text = MySupportMethods.StrMoneyToStrCurrency(TotalCostForAll.ToString()); } else { MessageBox.Show($"Sản phẩm có mã số {key} không tồn tại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } } catch (Exception ex) { } } else { //dtpkDateSell.Value = DateTime.Now; } }