Example #1
0
        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            DTO_Discount row = (Discount)dgDiscount.SelectedItem;

            if (DateTime.Compare(DateTime.ParseExact(row.EndDate, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture), DateTime.Now.Date) < 0)
            {
                MessageBox.Show("Không thể sửa ưu đãi đã diễn ra");
            }
            else
            {
                System.Windows.Media.Effects.BlurEffect objBlur = new System.Windows.Media.Effects.BlurEffect();
                ((MainWindow)App.Current.MainWindow).Opacity = 0.5;
                ((MainWindow)App.Current.MainWindow).Effect  = objBlur;
                Window window = new Window
                {
                    ResizeMode  = ResizeMode.NoResize,
                    WindowStyle = WindowStyle.None,
                    Title       = "Sửa ưu đãi",
                    Content     = new PopupDiscountEdit(row.DiscountID, row.DiscountName, row.StartDate, row.EndDate, row.DiscountValue.ToString(), _context),
                    Width       = 460,
                    Height      = 505,
                    Left        = (Application.Current.MainWindow.Left + Application.Current.MainWindow.Width - 460) / 2,
                    Top         = (Application.Current.MainWindow.Top + Application.Current.MainWindow.Height - 500) / 2,
                };
                window.ShowDialog();
                ((MainWindow)App.Current.MainWindow).Opacity = 1;
                ((MainWindow)App.Current.MainWindow).Effect  = null;
                loadData();
            }
        }
Example #2
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            DTO_Discount row = (DTO_Discount)dgDiscount.SelectedItem;

            System.Windows.Media.Effects.BlurEffect objBlur = new System.Windows.Media.Effects.BlurEffect();
            ((MainWindow)App.Current.MainWindow).Opacity = 0.5;
            ((MainWindow)App.Current.MainWindow).Effect  = objBlur;
            Window window = new Window
            {
                ResizeMode            = ResizeMode.NoResize,
                WindowStyle           = WindowStyle.None,
                Title                 = "Xóa ưu đãi",
                Content               = new PopupDeleteConfirm(row, _context),
                Width                 = 420,
                Height                = 210,
                WindowStartupLocation = WindowStartupLocation.CenterScreen
            };

            window.ShowDialog();
            ((MainWindow)App.Current.MainWindow).Opacity = 1;
            ((MainWindow)App.Current.MainWindow).Effect  = null;
            setNumPage();
            if (maxNumpage < int.Parse(tbNumPage.Text))
            {
                tbNumPage.Text = (int.Parse(tbNumPage.Text) - 1).ToString();
            }
            loadData();
        }
Example #3
0
        public DTO_Discount findDiscount(string ID)
        {
            string       sql = $"select * from discount where discountID ='" + ID + "'";
            DTO_Discount dto = new DTO_Discount();

            try
            {
                SQLiteCommand command = new SQLiteCommand(sql, getConnection());
                command.Connection.Open();
                SQLiteDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    dto.DiscountID    = ID;
                    dto.DiscountName  = reader["DiscountName"].ToString();
                    dto.StartDate     = reader["StartDate"].ToString();
                    dto.EndDate       = reader["EndDate"].ToString();
                    dto.DiscountValue = float.Parse(reader["DiscountValue"].ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(dto);
        }
Example #4
0
        public DTO_Discount GetCurrentDiscout()
        {
            DataTable    discountData = getAllDiscount();
            DTO_Discount result       = new DTO_Discount();

            foreach (DataRow row in discountData.Rows)
            {
                DateTime now = DateTime.Now.Date;
                try
                {
                    DateTime start = DateTime.ParseExact(row["StartDate"].ToString(), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture).Date;
                    if (now < start)
                    {
                        continue;
                    }
                    DateTime end = DateTime.ParseExact(row["EndDate"].ToString(), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture).Date;
                    if (now > end)
                    {
                        continue;
                    }
                    result = new DTO_Discount(row["DiscountID"].ToString(), row["DiscountName"].ToString(), row["StartDate"].ToString(), row["EndDate"].ToString(), float.Parse(row["DiscountValue"].ToString()), "");
                }
                catch
                {
                    continue;
                }
            }
            return(result);
        }
        private void btSave_Click(object sender, RoutedEventArgs e)
        {
            tbNameValidation.Text = tbDateValidation.Text = tbRateValidation.Text = "";
            tbDateValidation.HorizontalAlignment = HorizontalAlignment.Right;
            if (tbName.Text == "")
            {
                tbNameValidation.Text = "Tên ưu đãi không được để trống.";
                return;
            }

            if (tbStartDate.SelectedDate == null)
            {
                tbDateValidation.Text = "Ngày bắt đầu không được để trống.";
                tbDateValidation.HorizontalAlignment = HorizontalAlignment.Left;
                return;
            }

            if (DateTime.Compare((DateTime)tbStartDate.SelectedDate, DateTime.Now.Date) <= 0)
            {
                tbDateValidation.Text = "Ngày bắt đầu phải sau ngày hiện tại.";
                tbDateValidation.HorizontalAlignment = HorizontalAlignment.Left;
                return;
            }

            if (tbEndDate.SelectedDate == null)
            {
                tbDateValidation.Text = "Ngày kết thúc không được để trống.";
                return;
            }

            if (DateTime.Compare((DateTime)tbStartDate.SelectedDate, (DateTime)tbEndDate.SelectedDate) > 0)
            {
                tbDateValidation.Text = "Ngày kết thúc phải sau ngày bắt đầu.";
                return;
            }

            if (tbPrice.Text == "")
            {
                tbRateValidation.Text = "Mức ưu đãi không được để trống.";
                return;
            }

            DTO_Discount discount = new DTO_Discount();

            discount.DiscountID    = ID;
            discount.DiscountName  = tbName.Text;
            discount.DiscountValue = float.Parse(tbPrice.Text);
            discount.StartDate     = tbStartDate.SelectedDate.Value.ToString("dd/MM/yyyy");
            discount.EndDate       = tbEndDate.SelectedDate.Value.ToString("dd/MM/yyyy");
            if (busDiscount.editDiscount(discount) > 0)
            {
                MessageBox.Show($"Đã sửa ưu đãi {tbName.Text}");
                Window.GetWindow(this).Close();
            }
            else
            {
                MessageBox.Show($"Đã có lỗi trong quá trình sửa {tbName.Text}");
            }
        }
Example #6
0
 public PopupDeleteConfirm(DTO_Discount discount, MainWindow context)
 {
     InitializeComponent();
     ID              = discount.DiscountID;
     name            = discount.DiscountName;
     time            = DateTime.ParseExact(discount.StartDate, "dd/MM/yyyy", null);
     tblContent.Text = "Dữ liệu về " + discount.DiscountName + " sẽ bị xóa vĩnh viễn.\nBạn chắc chắn muốn xóa?";
     this._context   = context;
 }
 public PopupDiscountDetail(string ID)
 {
     InitializeComponent();
     bus = new BUS_Discount();
     dto = bus.findDiscount(ID);
     tbDiscountName.Text = dto.DiscountName;
     tbStartDate.Text    = dto.StartDate;
     tbEndDate.Text      = dto.EndDate;
     tbDiscountRate.Text = dto.DiscountValue.ToString();
     tbDescription.Text  = dto.Description;
 }
Example #8
0
        private void btnCash_Click(object sender, RoutedEventArgs e)
        {
            if (billItems.Count == 0)
            {
                ///
                return;
            }

            if (newReceiptID != "")
            {
                MessageBox.Show($"Hóa đơn này đã thanh toán, mã hóa đơn là {newReceiptID}!");
                return;
            }
            BUS_Discount busDiscount = new BUS_Discount();
            DTO_Discount curDiscount = busDiscount.GetCurrentDiscount();
            string       disID       = "";

            if (curDiscount.DiscountValue != 0)
            {
                disID = curDiscount.DiscountID;
            }
            DTO_Receipt newReceipt = new DTO_Receipt("", user, disID);

            BUS_Receipt busReceipt = new BUS_Receipt();

            newReceiptID = busReceipt.CreateReceipt(newReceipt);
            if (newReceiptID != "")
            {
                BUS_ReceiptDetail busReceiptDetail = new BUS_ReceiptDetail();
                bool result = true;
                foreach (BillItem item in billItems)
                {
                    DTO_ReceiptDetail newReceiptDetail = new DTO_ReceiptDetail(newReceiptID, item.id, item.amount, item.unitCost);
                    result = result & busReceiptDetail.CreateReceiptDetail(newReceiptDetail);
                }
                if (result)
                {
                    MessageBox.Show("Tạo hóa đơn thành công!");
                }
                else
                {
                    MessageBox.Show("Đã xảy ra lỗi trong quá trình tạo chi tiết hóa đơn!");
                }
            }
            else
            {
                MessageBox.Show("Đã xảy ra lỗi trong quá trình tạo hóa đơn!");
            }
        }
Example #9
0
        public int createNewDiscount(DTO_Discount dTO_Discount)
        {
            int    result = 0;
            string sql    = $"Insert into Discount (DiscountID, DiscountName, StartDate, EndDate, DiscountValue, Description) values ('" + createID() + "','" + dTO_Discount.DiscountName + "','" + dTO_Discount.StartDate + "','" + dTO_Discount.EndDate + "'," + dTO_Discount.DiscountValue + ",'" + dTO_Discount.Description + "');";

            try
            {
                SQLiteCommand sqlite = getConnection().CreateCommand();
                sqlite.CommandText = sql;
                sqlite.Connection.Open();
                result = sqlite.ExecuteNonQuery();
            }
            catch (Exception)
            {
                Console.WriteLine(sql);
            }
            return(result);
        }
Example #10
0
        public int editDiscount(DTO_Discount dTO_Discount)
        {
            string sql = $"Update Discount set Discountname = '" + dTO_Discount.DiscountName + "', StartDate = '" + dTO_Discount.StartDate + "', EndDate = '" + dTO_Discount.EndDate + "', DiscountValue = " + dTO_Discount.DiscountValue + ", Description = '" + dTO_Discount.Description + "' Where DiscountID = '" + dTO_Discount.DiscountID + "'";
            int    rs  = 0;

            try
            {
                SQLiteCommand sqlite = getConnection().CreateCommand();
                sqlite.CommandText = sql;
                sqlite.Connection.Open();
                rs = sqlite.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Console.WriteLine(sql);
            }
            return(rs);
        }
Example #11
0
        private void btnWatch_Click(object sender, RoutedEventArgs e)
        {
            DTO_Discount row     = (DTO_Discount)dgDiscount.SelectedItem;
            var          rowView = dgDiscount.SelectedItem;

            System.Windows.Media.Effects.BlurEffect objBlur = new System.Windows.Media.Effects.BlurEffect();
            ((MainWindow)App.Current.MainWindow).Opacity = 0.5;
            ((MainWindow)App.Current.MainWindow).Effect  = objBlur;
            Window window = new Window
            {
                ResizeMode            = ResizeMode.NoResize,
                WindowStyle           = WindowStyle.None,
                Title                 = "Chi tiết ưu đãi",
                Content               = new PopupDiscountDetail(row.DiscountID),
                Width                 = 460,
                Height                = 440,
                WindowStartupLocation = WindowStartupLocation.CenterScreen
            };

            window.ShowDialog();
            ((MainWindow)App.Current.MainWindow).Opacity = 1;
            ((MainWindow)App.Current.MainWindow).Effect  = null;
        }
Example #12
0
        public void LoadData()
        {
            tblockUsername.Text = user;
            newReceiptID        = "";
            menuItems           = new List <MenuBeverage>();
            menuItemsDisplay    = new List <MenuBeverage>();
            billItems           = new List <BillItem>();

            total    = 0;
            received = 0;
            discount = 0;

            tblockChange.Text         = "0 VNĐ";
            tblockDiscount.Text       = "0";
            tblockDiscountAmount.Text = "0 VNĐ";
            tblockPayAmount.Text      = "0 VNĐ";
            tblockTotal.Text          = "0 VNĐ";
            tboxAmountReceived.Text   = "0";

            BUS_Beverage busBev   = new BUS_Beverage();
            DataTable    BevsData = busBev.getAllBeverage();

            foreach (DataRow row in BevsData.Rows)
            {
                string id    = row["BeverageID"].ToString();
                string name  = row["BeverageName"].ToString();
                string type  = row["BeverageTypeName"].ToString();
                int    price = Int32.Parse(row["Price"].ToString());
                byte[] image = (byte[])row["Link"];
                bool   isOutOfStock;
                if (row["IsOutOfStock"].ToString() == "0")
                {
                    isOutOfStock = false;
                }
                else
                {
                    isOutOfStock = true;
                }
                menuItems.Add(new MenuBeverage(id, name, type, price, isOutOfStock, image));
                menuItemsDisplay.Add(new MenuBeverage(id, name, type, price, isOutOfStock, image));
            }

            filterButtons = new List <FilterButton>();
            filterButtons.Add(new FilterButton("Tất cả", "Tất cả"));

            DataTable BevTypesData = busBev.GetBeverageTypeInfo();

            foreach (DataRow row in BevTypesData.Rows)
            {
                string id   = row["BeverageTypeID"].ToString();
                string name = row["BeverageTypeName"].ToString();
                filterButtons.Add(new FilterButton(id, name));
            }

            ListViewMenu.ItemsSource = menuItemsDisplay;
            ListViewMenu.Items.Refresh();

            dgBill.ItemsSource = billItems;
            dgBill.Items.Refresh();

            ListFilterButton.ItemsSource = filterButtons;
            ListFilterButton.Items.Refresh();


            BUS_Discount busDiscount = new BUS_Discount();
            DTO_Discount curDiscount = busDiscount.GetCurrentDiscount();

            tblockDiscount.Text = curDiscount.DiscountValue.ToString() + " %";
            discount            = curDiscount.DiscountValue;
        }
Example #13
0
        public int editDiscount(DTO_Discount dto)
        {
            DAL_Discount dal = new DAL_Discount();

            return(dal.editDiscount(dto));
        }
Example #14
0
        public int createNewDiscount(DTO_Discount dto)
        {
            DAL_Discount dal = new DAL_Discount();

            return(dal.createNewDiscount(dto));
        }