示例#1
0
        private void btnSave_Click_1(object sender, RoutedEventArgs e)
        {
            if (checkInputNewProduct())
            {
                var selecteModel = ProductDataGrid.SelectedItem as ProductViewModel;


                ProductDb model = (from p in dc.ProductDbs where p.id == selecteModel.id select p).Single();
                model.nameProduct = nameProductTxt.Text;
                model.priceSell   = Convert.ToInt64(priceSellTxt.Text);
                model.priceImport = Convert.ToInt64(priceImprotTxt.Text);
                model.bonusScore  = Convert.ToInt32(bonusScoreTxt.Text);
                model.unit        = unitTxt.Text;
                try
                {
                    dc.SubmitChanges();
                    dialogAddProduct.IsOpen = false;
                    reloadData();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
示例#2
0
 public ProductViewModel(ProductDb model, int order, string nameCategory) : base(model)
 {
     this.order             = order;
     this.nameCategory      = nameCategory;
     this.stringPriceImport = Unity.formatMoney((long)model.priceImport);
     this.stringPriceSell   = Unity.formatMoney((long)model.priceSell);
 }
示例#3
0
 public ProductDb(ProductDb model)
 {
     this.nameProduct = model.nameProduct;
     this.unit        = model.unit;
     this.priceImport = model.priceImport;
     this.priceSell   = model.priceSell;
     this.bonusScore  = model.bonusScore;
     this.category    = model.category;
     this.id          = model.id;
     this.sumQuantity = model.sumQuantity;
 }
示例#4
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));
            }
        }
示例#5
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);
        }
示例#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
            }
        }
示例#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));
            }
        }
示例#8
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);
        }
示例#9
0
        //Delete
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (!isManager)
            {
                return;
            }

            var indexRow = ProductDataGrid.SelectedIndex;

            if (indexRow != -1)
            {
                ProductDb productRow  = ProductDataGrid.SelectedItem as ProductDb;
                var       productInDb = (from p in dc.ProductDbs where p.id == productRow.id select p).Single();
                //kiem tra xem trong chi tiet hoa don co du lieu nao lien quan den san pham nay hay khong
                var detailReceipt = (from p in dc.DetailReceipts where p.idProduct == productInDb.id select p).ToList();

                if (productInDb.sumQuantity > 0)
                {
                    MessageBox.Show("Sản phẩm này còn " + productInDb.sumQuantity + " " + (productInDb.unit).ToLower()
                                    + " nên không thể xóa\n");
                }
                else if (detailReceipt.Count > 0)
                {
                    MessageBox.Show("Không thể xóa sản phẩm này vì có dữ liệu liên quan trong các hóa đơn\n");
                }
                else
                {
                    MessageBoxButton mesBox = MessageBoxButton.YesNo;
                    MessageBoxResult result = MessageBox.Show("Bạn có thật sư muốn xóa sản phẩm " + productRow.nameProduct,
                                                              "Xác nhận", mesBox, MessageBoxImage.Question);
                    if (result == MessageBoxResult.Yes)
                    {
                        try
                        {
                            //xóa sản phẩm trong bảng size
                            var x = (from p in dc.Size36_Products
                                     where p.idProduct == productInDb.id
                                     select p).ToList();
                            if (x.Count > 0)
                            {
                                dc.Size36_Products.DeleteOnSubmit(x[0]);
                            }
                            var x1 = (from p in dc.Size37_Products
                                      where p.idProduct == productInDb.id
                                      select p).ToList();
                            if (x1.Count > 0)
                            {
                                dc.Size37_Products.DeleteOnSubmit(x1[0]);
                            }
                            var x2 = (from p in dc.Size38_Products
                                      where p.idProduct == productInDb.id
                                      select p).ToList();
                            if (x2.Count > 0)
                            {
                                dc.Size38_Products.DeleteOnSubmit(x2[0]);
                            }
                            var x3 = (from p in dc.Size39_Products
                                      where p.idProduct == productInDb.id
                                      select p).ToList();
                            if (x3.Count > 0)
                            {
                                dc.Size39_Products.DeleteOnSubmit(x3[0]);
                            }
                            var x4 = (from p in dc.Size40_Products
                                      where p.idProduct == productInDb.id
                                      select p).ToList();
                            if (x4.Count > 0)
                            {
                                dc.Size40_Products.DeleteOnSubmit(x4[0]);
                            }
                            var x5 = (from p in dc.Size41_Products
                                      where p.idProduct == productInDb.id
                                      select p).ToList();
                            if (x5.Count > 0)
                            {
                                dc.Size41_Products.DeleteOnSubmit(x5[0]);
                            }
                            var x6 = (from p in dc.Size42_Products
                                      where p.idProduct == productInDb.id
                                      select p).ToList();
                            if (x6.Count > 0)
                            {
                                dc.Size42_Products.DeleteOnSubmit(x6[0]);
                            }


                            //xóa sản phẩm trong bảng ProductDbs
                            dc.ProductDbs.DeleteOnSubmit(productInDb);

                            dc.SubmitChanges();
                            reloadData();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Xóa không thành công");
                        }
                    }
                    else
                    {
                        //do nothing
                    }
                }
            }
        }