Beispiel #1
0
        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) { }
        }
Beispiel #2
0
        private void RemoveProduct_ContextMenu_Click(object sender, EventArgs e)
        {
            // remove dòng hiện tại trong datagridview
            int index = dtgvShowProduct.SelectedRows[0].Index;

            int ProductID = int.Parse(dtgvShowProduct.Rows[index].Cells["ProductID"].Value.ToString());

            int TotalCost = MySupportMethods.StrCurrencyToInt(txbTotalCost.Text);

            int productPrice = int.Parse(dtgvShowProduct.Rows[index].Cells["ProductPriceSale"].Value.ToString());

            int productQuantity = int.Parse(dtgvShowProduct.Rows[index].Cells["ProductQuantity"].Value.ToString());

            txbTotalCost.Text = MySupportMethods.StrMoneyToStrCurrency((TotalCost - productPrice * productQuantity).ToString());

            dtgvShowProduct.Rows.RemoveAt(index);

            // xóa sản phẩm trong cart
            Cart.RemoveProduct(ProductID);
        }
Beispiel #3
0
        private void DecreaseQuantity_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());
                if (Quantity > 1)
                {
                    Quantity--;

                    // cập nhật trong cart
                    Cart.DecreaseProductQuantityChosen(ProductID);

                    // update số lượng
                    dtgvShowProduct.SelectedRows[0].Cells["ProductQuantity"].Value = Quantity;

                    // lấy giá 1 sản phẩm được giảm giá
                    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 chỉ còn 1 cái!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex) { }
        }
Beispiel #4
0
        public UC_ViewProduct(int ID, string Name, int Price, Byte[] arrByteImage)
        {
            InitializeComponent();

            picImageProduct.SizeMode = PictureBoxSizeMode.CenterImage;

            _ProductID   = ID;
            _ProductName = Name;
            _Price       = Price;

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream(arrByteImage))
            {
                _Img = Image.FromStream(ms);
            }

            lbProductName.Text  = _ProductName;
            lbProductPrice.Text = MySupportMethods.StrMoneyToStrCurrency(_Price.ToString());
            //lbProductPrice.Text = _Price.ToString();
            picImageProduct.Image = MySupportMethods.ResizeImage(_Img, _Img.Width * 150 / _Img.Height, 150);

            // tìm khuyến mãi hiện tại có phần trăm lớn nhất
            // update giá
            BUS_KhuyenMai bus_Promotion = new BUS_KhuyenMai();

            DataTable dtPromotions = bus_Promotion.BUS_GetAllPromotionNow(DateTime.Now);

            if (dtPromotions == null)
            {
                MessageBox.Show("Có lỗi trong quá trình load dữ liệu!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (dtPromotions.Rows.Count == 0)
            {
                // không có giảm giá
                lbProductPriceDiscount.Text    = lbProductPrice.Text;
                lbProductPriceDiscount.Visible = false;

                lbProductPrice.Font = new Font(lbProductPrice.Font, FontStyle.Regular);
            }
            else
            {
                //  nếu có khuyến mãi
                DTO_Promotion promotion = new DTO_Promotion()
                {
                    PromotionID          = (int)dtPromotions.Rows[0]["ID_KHUYENMAI"],
                    PromotionName        = dtPromotions.Rows[0]["TENKHUYENMAI"].ToString(),
                    PromotionPercent     = (int)dtPromotions.Rows[0]["PHANTRAM"],
                    PromotionMaxDiscount = (int)dtPromotions.Rows[0]["TIENTOIDA"],
                    PromotionBeginDate   = (DateTime)dtPromotions.Rows[0]["NGAYBATDAU"],
                    PromotionEndDate     = (DateTime)dtPromotions.Rows[0]["NGAYKETTHUC"],
                };

                if (DateTime.Now >= promotion.PromotionBeginDate && DateTime.Now <= promotion.PromotionEndDate)
                {
                    lbProductPriceDiscount.Visible = true;

                    lbProductPrice.Font = new Font(lbProductPrice.Font, FontStyle.Strikeout);

                    // remove tất cả các dấu chấm phân cách
                    int productPrice = MySupportMethods.StrCurrencyToInt(lbProductPrice.Text);

                    lbProductPriceDiscount.Text = MySupportMethods.StrMoneyToStrCurrency(promotion.CalcDiscount(productPrice).ToString());
                }
            }
        }
Beispiel #5
0
        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;
            }
        }
Beispiel #6
0
        private void UC_KhuyenMai_Load(object sender, EventArgs e)
        {
            dtgvPromotion.Rows.Clear();

            // bật tắt các button
            BtnAddPromotion.Enabled    = true;
            BtnDeletePromotion.Enabled = false;
            BtnEditPromotion.Enabled   = false;

            // load danh sách các khuyến mãi chưa bị xóa vào datagridview

            DataTable dtPromotion = bus_Promotion.BUS_GetAllPromotionNotDeleted();

            if (dtPromotion == null)
            {
                MessageBox.Show("Có lỗi xảy ra trong khi load dữ liệu!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            foreach (DataRow row in dtPromotion.Rows)
            {
                dtgvPromotion.Rows.Add();
                int Index = dtgvPromotion.Rows.Count - 1;
                dtgvPromotion.Rows[Index].Cells["PromotionID"].Value = (int)row["ID_KHUYENMAI"];

                dtgvPromotion.Rows[Index].Cells["PromotionName"].Value = $"{row["TENKHUYENMAI"]} "
                                                                         + $"giảm giá {row["PHANTRAM"]}% tối đa {MySupportMethods.StrMoneyToStrCurrency(row["TIENTOIDA"].ToString())} đồng";

                dtgvPromotion.Rows[Index].Cells["PromotionPercent"].Value = (int)row["PHANTRAM"];

                dtgvPromotion.Rows[Index].Cells["PromotionMaxDiscount"].Value = (int)row["TIENTOIDA"];

                dtgvPromotion.Rows[Index].Cells["StartDay"].Value = (DateTime)row["NGAYBATDAU"];

                dtgvPromotion.Rows[Index].Cells["EndDay"].Value = (DateTime)row["NGAYKETTHUC"];
                // tính toán ngày còn lại

                DateTime now = DateTime.Now;
                if ((DateTime)dtgvPromotion.Rows[Index].Cells["EndDay"].Value < now)
                {
                    dtgvPromotion.Rows[Index].Cells["RemainDay"].Value = (int)0;
                }
                else
                {
                    dtgvPromotion.Rows[Index].Cells["RemainDay"].Value = (int)((DateTime)row["NGAYKETTHUC"] - now).TotalDays;
                }
            }

            // resize columns
            //dtgvPromotion.Columns["RemainDay"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader;
        }