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
        private void BtnPayment_Click(object sender, EventArgs e)
        {
            // thanh toán
            // kiểm tra các trường dữ liệu có bị rỗng hay không
            if (txbCustomerName.Text == "" || txbCustomerID.Text == "" || txbCustomerPhone.Text == "" || txbCustomerAddr.Text == "")
            {
                MessageBox.Show("Các trường dữ liệu không được để rỗng!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // kiểm tra gridview có sản phẩm nào chưa
            if (dtgvShowProduct.Rows.Count == 0)
            {
                MessageBox.Show("Không có sản phẩm nào trong giỏ hàng!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            // kiểm tra CMND và số điện thoại có kí tự "lạ" hay không
            if (MySupportMethods.isNumberic(txbCustomerID.Text) == false)
            {
                MessageBox.Show("Chứng minh nhân dân phải là chữ số!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (MySupportMethods.isNumberic(txbCustomerPhone.Text) == false)
            {
                MessageBox.Show("Số điện thoại phải là chữ số!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            DialogResult dlgRes = MessageBox.Show("Bạn có muốn thanh toán?", "Thông báo",
                                                  MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (dlgRes == DialogResult.Cancel)
            {
                return;
            }

            // đóng gói thông tin khách hàng
            DTO_Customer customer = new DTO_Customer()
            {
                CustomerName    = txbCustomerName.Text,
                CustomerID      = txbCustomerID.Text,
                CustomerPhone   = txbCustomerPhone.Text,
                CustomerAddress = txbCustomerAddr.Text
            };

            // đóng gói lại các sản phẩm được chọn
            List <DTO_ProductChosen> listProductChosen = new List <DTO_ProductChosen>();

            foreach (DataGridViewRow row in dtgvShowProduct.Rows)
            {
                DTO_ProductChosen temp = new DTO_ProductChosen()
                {
                    ProductID       = (int)row.Cells["ProductID"].Value,
                    ProductPrice    = (int)row.Cells["ProductPrice"].Value,
                    ProductQuantity = (int)row.Cells["ProductQuantity"].Value
                };

                listProductChosen.Add(temp);
            }

            BUS_BanHang bus_SellProducts = new BUS_BanHang();

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

            // lưu dữ liệu vào database.
            bool res = bus_SellProducts.BUS_InsertNewOrder(customer, listProductChosen, dtpkDateSell.Value, TotalPrice, listPromotion);

            if (res == false)
            {
                MessageBox.Show("Lập phiếu thanh toán thất bại!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("Lập phiếu thanh toán thành công!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            this.IsSelling = false;

            EmptyAllFields();

            TurnOnOffFieldsAnhButtons();
        }