Example #1
0
        public bool checkmkm(string mkm, BUS_KhuyenMai busKM)
        {
            DataTable getmkm = busKM.GetDanhSachKM();

            foreach (DataRow row in getmkm.Rows)
            {
                if (string.Compare(mkm, row[0].ToString(), true) == 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Example #2
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());
                }
            }
        }
Example #3
0
        private void dtpkDateSell_ValueChanged(object sender, EventArgs e)
        {
            // xóa danh sách promotion
            listPromotion.Clear();
            // reload lại khuyến mãi
            txbPromotion.Text = "";

            BUS_KhuyenMai bus_Promotion = new BUS_KhuyenMai();

            DataTable dtPromotions = bus_Promotion.BUS_GetAllPromotionNow(dtpkDateSell.Value);

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

            if (dtPromotions.Rows.Count > 0)
            {
                foreach (DataRow row in dtPromotions.Rows)
                {
                    string temp = "";

                    if ((int)row["PHANTRAM"] > 0 && (int)row["TIENTOIDA"] > 0)
                    {
                        temp = $"{row["TENKHUYENMAI"].ToString()} giảm {(int)row["PHANTRAM"]}% tối đa {(int)row["TIENTOIDA"]} VND.";
                    }

                    if ((int)row["PHANTRAM"] > 0 && (int)row["TIENTOIDA"] == 0)
                    {
                        temp = $"{row["TENKHUYENMAI"].ToString()} giảm {(int)row["PHANTRAM"]}%.";
                    }
                    if ((int)row["PHANTRAM"] == 0 && (int)row["TIENTOIDA"] > 0)
                    {
                        temp = $"{row["TENKHUYENMAI"].ToString()} giảm {(int)row["TIENTOIDA"]} VND.";
                    }

                    txbPromotion.Text = txbPromotion.Text + temp + Environment.NewLine;

                    // thêm vào list promotions
                    DTO_Promotion promotion = new DTO_Promotion()
                    {
                        PromotionID          = (int)row["ID_KHUYENMAI"],
                        PromotionName        = row["TENKHUYENMAI"].ToString(),
                        PromotionPercent     = (int)row["PHANTRAM"],
                        PromotionMaxDiscount = (int)row["TIENTOIDA"],
                        PromotionBeginDate   = (DateTime)row["NGAYBATDAU"],
                        PromotionEndDate     = (DateTime)row["NGAYKETTHUC"]
                    };

                    listPromotion.Add(promotion);
                }
            }
            else
            {
                // nếu không có khuyến mãi
                listPromotion.Clear();
            }

            this.ReloadForm();

            //// update lại giá sau khi chọn lại sản phẩm nếu trong bảng sản phẩm có
            //if (dtgvShowProduct.Rows.Count >= 1)
            //{
            //    int TotalPriceForAll = 0;
            //    foreach(DataGridViewRow row in dtgvShowProduct.Rows)
            //    {
            //        // lấy giá gốc của sp
            //        int ProductPrice = (int)row.Cells["ProductPrice"].Value;

            //        // đơ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);
            //        }

            //        // update lại giá khuyến mãi
            //        row.Cells["ProductPriceSale"].Value = ProductPriceSale;

            //        // get số lượng
            //        int Quantity = int.Parse(row.Cells["ProductQuantity"].Value.ToString());

            //        // update giá tiền
            //        int TotalPrice = Quantity * ProductPriceSale;

            //        row.Cells["ProductTotalCost"].Value = TotalPrice;

            //        // update lại tổng tiền thanh toán
            //        TotalPriceForAll += TotalPrice;
            //    }

            //    txbTotalCost.Text = TotalPriceForAll.ToString();

            //}
        }