Beispiel #1
0
        private void bntEditCustomer_Click(object sender, RoutedEventArgs e)
        {
            if (isManager)
            {
                //Kiểm tra xem discount này đã được áp dụng vào hóa đơn nào chưa
                var discountVM = DiscountDataGrid.SelectedItem as ViewModel;
                var x          = (from p in dc.DetailReceipts where p.idDiscount == discountVM.id select p).ToList();
                if (x.Count > 0)
                {
                    MessageBox.Show("Ưu đãi này đã được áp dụng trong hóa đơn nên không thể chỉnh sửa\n");
                }
                else
                {
                    dialogDiscount.IsOpen = true;
                    setupDialog();
                    btnSaveDiscount.Visibility = Visibility.Visible;
                    btnAddDiscount.Visibility  = Visibility.Collapsed;
                    //fill data in dialog
                    nameDiscountTxt.Text    = discountVM.nameDiscount;
                    startDate.SelectedDate  = discountVM.startDate;
                    endDate.SelectedDate    = discountVM.endDate;
                    percentDiscountTxt.Text = discountVM.percentageDiscount.ToString();

                    CategoryDb typeProcut = (from p in dc.CategoryDbs where p.id == discountVM.idProduct select p).Single();
                    comboBoxTypeProduct.SelectedItem = typeProcut;
                    Score_TypeCustomer typeCustomer = (from p in dc.Score_TypeCustomers where p.id == discountVM.idTypeCustomer select p).Single();
                    comboBoxTypeCustomer.SelectedItem = typeCustomer;
                }
            }
        }
Beispiel #2
0
        public VMs()
        {
            DataClasses1DataContext dc       = new DataClasses1DataContext(Properties.Settings.Default.ManagementProjectConnectionString);
            List <DiscountDb>       modelsDb = dc.DiscountDbs.ToList();

            models = new List <ViewModel>();

            int n = modelsDb.Count;

            for (int i = 0; i < n; i++)
            {
                DiscountDb model = modelsDb[i];

                CategoryDb         product         = (from p in dc.CategoryDbs where p.id == model.idProduct select p).Single();
                String             nameProduct     = product.nameType;
                Score_TypeCustomer typeCustomer    = (from p in dc.Score_TypeCustomers where p.id == model.idTypeCustomer select p).Single();
                string             nameTypeProduct = typeCustomer.nameTypeCustomer;

                if (DateTime.Compare(model.endDate, DateTime.Now) < 0) //discount is out of date
                {
                    modelsDb[i].statusDiscount = 0;
                    dc.SubmitChanges();
                }
                string status = modelsDb[i].statusDiscount == 1 ? "Đang áp dụng" : "Hết hạn";
                int    order  = i + 1;

                if (nameProduct != null && nameProduct != null)
                {
                    ViewModel newItem = new ViewModel(model, nameProduct, nameTypeProduct, status, order);
                    models.Add(newItem);
                }
            }
        }
Beispiel #3
0
        private void bntSaveDiscount_Click(object sender, RoutedEventArgs e)
        {
            if (checkInput())
            {
                var discountVM = DiscountDataGrid.SelectedItem as ViewModel;
                var modelDb    = (from p in dc.DiscountDbs where p.id == discountVM.id select p).Single();

                modelDb.nameDiscount = nameDiscountTxt.Text;
                modelDb.startDate    = (DateTime)startDate.SelectedDate;
                modelDb.endDate      = (DateTime)endDate.SelectedDate;
                CategoryDb productInput = comboBoxTypeProduct.SelectedValue as CategoryDb;
                modelDb.idProduct = productInput.id;
                Score_TypeCustomer customerInput = comboBoxTypeCustomer.SelectedValue as Score_TypeCustomer;
                modelDb.idTypeCustomer = customerInput.id;
                int percentageInput = Convert.ToInt32(percentDiscountTxt.Text);
                modelDb.percentageDiscount = percentageInput;
                modelDb.statusDiscount     = 1;

                try
                {
                    dc.SubmitChanges();
                    reloadData();
                    dialogDiscount.IsOpen = false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Beispiel #4
0
        private void btnAddDiscount_Click(object sender, RoutedEventArgs e)
        {
            if (checkInput())
            {
                string             nameDiscountInput = nameDiscountTxt.Text;
                DateTime           startDateInput    = (DateTime)startDate.SelectedDate;
                DateTime           endDateInput      = (DateTime)endDate.SelectedDate;
                CategoryDb         productInput      = comboBoxTypeProduct.SelectedValue as CategoryDb;
                Score_TypeCustomer customerInput     = comboBoxTypeCustomer.SelectedValue as Score_TypeCustomer;
                int percentageInput = Convert.ToInt32(percentDiscountTxt.Text);

                DiscountDb newDiscount = new DiscountDb(nameDiscountInput, productInput.id, customerInput.id, 1, startDateInput, endDateInput, percentageInput);
                dc.DiscountDbs.InsertOnSubmit(newDiscount);
                try
                {
                    dc.SubmitChanges();
                    reloadData();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Lỗi", ex.Message);
                }
                dialogDiscount.IsOpen = false;
            }
        }
Beispiel #5
0
        public ProductVMs(List <ProductDb> modelDb)
        {
            DataClasses1DataContext dc = new DataClasses1DataContext(Properties.Settings.Default.ManagementProjectConnectionString);

            models = new List <ProductViewModel>();

            int n = modelDb.Count;

            for (int i = 0; i < n; i++)
            {
                ProductDb  model        = modelDb[i];
                CategoryDb x            = (from p in dc.CategoryDbs where p.id == model.category select p).Single();
                String     nameCategory = x.nameType;
                models.Add(new ProductViewModel(model, i + 1, nameCategory));
            }
        }
Beispiel #6
0
        private void bntAddProduct_Click(object sender, RoutedEventArgs e)
        {
            //Kiểm tra tính hợp lệ
            if (checkInputNewProduct())
            {
                string     name        = nameProductTxt.Text;
                string     unit        = unitTxt.Text;
                long       priceImport = Convert.ToInt64(priceImprotTxt.Text);
                long       priceSell   = Convert.ToInt64(priceSellTxt.Text);
                int        bonusScore  = Convert.ToInt32(bonusScoreTxt.Text);
                CategoryDb category    = comboBoxCategory.SelectedItem as CategoryDb;

                ProductDb newProduct = new ProductDb(name, unit, priceImport, priceSell, bonusScore, category.id);

                dc.ProductDbs.InsertOnSubmit(newProduct);

                try
                {
                    dc.SubmitChanges();
                }
                catch (Exception except)
                {
                    MessageBox.Show("Không thể thêm sản phẩm", except.Message);
                    return;
                }
                //retrieve it to add into size_product table
                ProductDb product = (from p in dc.ProductDbs
                                     where p.nameProduct == name && p.unit == unit && p.priceImport == priceImport &&
                                     p.priceSell == priceSell && p.bonusScore == bonusScore && p.category == category.id
                                     select p).Single();
                addSizeProduct(product.id);

                reloadData();
                resetDialogAddProduct();
                dialogAddProduct.IsOpen = false;
            }
            else
            {
                //do nothing
            }
        }
Beispiel #7
0
        public ProductSizeQuantityVMs()
        {
            DataClasses1DataContext dc = new DataClasses1DataContext(Properties.Settings.Default.ManagementProjectConnectionString);

            modelsView = new List <ProductSizeQuantityViewModel>();
            sumProduct = 0;

            List <ProductDb> modelDataProduct = dc.ProductDbs.ToList();

            int n = modelDataProduct.Count;

            for (int i = 0; i < n; i++)
            {
                ProductDb  model        = modelDataProduct[i];
                CategoryDb x            = (from p in dc.CategoryDbs where p.id == model.category select p).Single();
                String     nameCategory = x.nameType;
                int[]      arr          = addSizeQuantity(model.id);
                sumProduct += arr.Sum();
                modelsView.Add(new ProductSizeQuantityViewModel(model.id, nameCategory, model.nameProduct, arr, i + 1));
            }
        }
Beispiel #8
0
        private void btnDetail_Click(object sender, RoutedEventArgs e)
        {
            var discountVM = DiscountDataGrid.SelectedItem as ViewModel;

            dialogDiscount.IsOpen = true;
            setupDialog();
            btnSaveDiscount.Visibility = Visibility.Visible;
            btnAddDiscount.Visibility  = Visibility.Collapsed;
            //fill data in dialog
            nameDiscountTxt.Text    = discountVM.nameDiscount;
            startDate.SelectedDate  = discountVM.startDate;
            endDate.SelectedDate    = discountVM.endDate;
            percentDiscountTxt.Text = discountVM.percentageDiscount.ToString();

            CategoryDb typeProcut = (from p in dc.CategoryDbs where p.id == discountVM.idProduct select p).Single();

            comboBoxTypeProduct.SelectedItem = typeProcut;
            Score_TypeCustomer typeCustomer = (from p in dc.Score_TypeCustomers where p.id == discountVM.idTypeCustomer select p).Single();

            comboBoxTypeCustomer.SelectedItem = typeCustomer;

            btnAddDiscount.Visibility  = Visibility.Hidden;
            btnSaveDiscount.Visibility = Visibility.Collapsed;
        }