Esempio n. 1
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);
                }
            }
        }
Esempio n. 2
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;
                }
            }
        }
Esempio n. 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);
                }
            }
        }
Esempio n. 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;
            }
        }
Esempio n. 5
0
        public CustomerVMs(List <CustomerDb> modelsDb)
        {
            models = new List <CustomerViewModel>();
            DataClasses1DataContext dc = new DataClasses1DataContext(Properties.Settings.Default.ManagementProjectConnectionString);
            int n = modelsDb.Count;

            for (int i = 0; i < n; i++)
            {
                CustomerDb         model            = modelsDb[i];
                Score_TypeCustomer x                = (from p in dc.Score_TypeCustomers where p.id == model.typeCustomer select p).Single();
                string             nameTypeCustomer = x.nameTypeCustomer;

                if (nameTypeCustomer == null)
                {
                    nameTypeCustomer = "";
                }

                models.Add(new CustomerViewModel(model, i + 1, nameTypeCustomer));
            }
        }
Esempio n. 6
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;
        }