示例#1
0
        private void bntEditCustomer_Click(object sender, RoutedEventArgs e)
        {
            int row = CustomerDataGrid.SelectedIndex;

            if (row != -1)
            {
                dialogCustomer.IsOpen      = true;
                btnSaveCustomer.Visibility = Visibility.Visible;
                btnAddCustomer.Visibility  = Visibility.Collapsed;

                CustomerDb customer = CustomerDataGrid.SelectedItem as CustomerDb;
                nameCustomerTxt.Text = customer.nameCustomer;
                phoneNumberTxt.Text  = customer.phoneNumber;
                dateOB.SelectedDate  = customer.dateOfBirth;
            }
        }
示例#2
0
        public DetailReceiptViewModel(CustomerDb customer, ProductDb product, int quantity, int sizeOrder, DateTime date, int order)
        {
            DataClasses1DataContext dc = new DataClasses1DataContext(Properties.Settings.Default.ManagementProjectConnectionString);

            nameProduct          = product.nameProduct;
            this.quantity        = quantity;
            this.unitPriceSell   = product.priceSell;
            this.unitBonusScore  = product.bonusScore;
            this.sumScore        = quantity * (int)unitBonusScore;
            this.order           = order;
            this.size            = sizeOrder;
            this.stringUnitPrice = Unity.formatMoney((long)unitPriceSell);
            this.idProduct       = product.id;
            this.idTypeProduct   = product.category;

            //get discount, idTypeCustomer=1 mean all customer, idProduct=6 means all type product
            var discount = (from p in dc.DiscountDbs
                            where p.statusDiscount == 1 && date >= p.startDate && date <= p.endDate &&
                            (p.idTypeCustomer == 1 || p.idTypeCustomer == customer.typeCustomer) &&
                            (p.idProduct == 6 || p.idProduct == product.category)
                            orderby p.percentageDiscount descending
                            select p).ToList();

            if (discount.Count == 0)
            {
                this.idDiscount         = -1;
                this.nameDiscount       = "(Không có)";
                this.discountString     = "0%";
                this.persentageDiscount = 0;
            }
            else //chọn ưu đãi cao nhất
            {
                this.idDiscount         = discount[0].id;
                this.nameDiscount       = discount[0].nameDiscount;
                this.discountString     = discount[0].percentageDiscount + "%";
                this.persentageDiscount = discount[0].percentageDiscount;
            }
            var x = (long)(quantity * (long)unitPriceSell) * (100.0 - persentageDiscount) / 100.0;

            this.sumMoney = (long)x;
            var y = sumMoney - product.priceImport * quantity;

            this.interest = (long)y;

            this.stringSumMoney = Unity.formatMoney(sumMoney);
        }
示例#3
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));
            }
        }
示例#4
0
        public DetailReceiptViewModel(DetailReceipt model, int order) : base(model)
        {
            DataClasses1DataContext dc = new DataClasses1DataContext(Properties.Settings.Default.ManagementProjectConnectionString);

            CustomerDb customer = (from p in dc.CustomerDbs where p.id == this.idCustomer select p).Single();
            ProductDb  product  = (from p in dc.ProductDbs where p.id == this.idProduct select p).Single();

            nameProduct = product.nameProduct;

            this.unitPriceSell   = product.priceSell;
            this.unitBonusScore  = product.bonusScore;
            this.sumScore        = quantity * (int)unitBonusScore;
            this.order           = order;
            this.stringUnitPrice = Unity.formatMoney((long)unitPriceSell);
            this.idProduct       = product.id;
            this.idTypeProduct   = product.category;

            //get discount, idTypeCustomer=1 mean all customer, idProduct=6 means all type product
            if (this.idDiscount == -1)
            {
                this.nameDiscount = "(Không có)";
            }
            else
            {
                var discount = (from p in dc.DiscountDbs where p.id == this.idDiscount select p).Single();

                this.nameDiscount   = discount.nameDiscount;
                this.discountString = discount.percentageDiscount + "%";
            }

            var x = (long)(quantity * (long)unitPriceSell) * (100.0 - persentageDiscount) / 100.0;

            this.sumMoney = (long)x;
            var y = sumMoney - product.priceImport * quantity;

            this.interest = (long)y;

            this.stringSumMoney = Unity.formatMoney(sumMoney);
        }
示例#5
0
        private void btnAddCustomer_Click(object sender, RoutedEventArgs e)
        {
            string messageError = "";

            if (!checkInput())
            {
                MessageBox.Show("Lỗi", "Nhập dữ liệu sai");
            }
            else
            {
                String name        = nameCustomerTxt.Text;
                String phoneNumer  = phoneNumberTxt.Text;
                var    dateOfBirth = dateOB.SelectedDate.Value.Date;

                CustomerDb newCustomer = new CustomerDb(name, phoneNumer, dateOfBirth);
                dc.CustomerDbs.InsertOnSubmit(newCustomer);
                try
                {
                    dc.SubmitChanges();
                }
                catch (Exception except)
                {
                    //error
                    messageError = "Lưu dữ liệu không thành công";
                    MessageBox.Show("Lỗi", except.Message);
                }
            }

            if (!messageError.Equals(""))
            {
                MessageBox.Show("Lỗi", messageError);
            }
            else
            {
                MessageBox.Show("Thành công", "Lưu thành công");
                dialogCustomer.IsOpen = false;
                reloadData();
            }
        }