Ejemplo n.º 1
0
        private void BtnAddImage_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlgOpen = new OpenFileDialog();

            dlgOpen.Filter = "Images(.jpg,.png)|*.png;*.jpg";

            if (dlgOpen.ShowDialog() == DialogResult.OK)
            {
                string filePath = dlgOpen.FileName;

                Image img = new Bitmap(filePath);

                Picimage.Image = MySupportMethods.ResizeImage(img, img.Width * 280 / img.Height, 280);
            }
        }
Ejemplo n.º 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());
                }
            }
        }
Ejemplo n.º 3
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;
            }
        }