Ejemplo n.º 1
0
        public NewProductPage(Detail_Product product)
        {
            InitializeComponent();
            isEdit                  = true;
            imgProduct.Tag          = product.Image_Path;
            Title.Content           = "Edit product";
            ProductName.Text        = product.NameProduct;
            ProductId.Text          = product.ID_Product;
            ProductDescription.Text = product.Description_Pro;
            ProductPrice.Text       = product.Original_Price.ToString();
            ProductCapital.Text     = "0";
            var t = db.Input_Form.FirstOrDefault(x => x.ID_Product == product.ID_Product);

            ProductDate.Text          = t.Input_Date.ToString();
            ProductInitialAmount.Text = "0";
            if (product.Image_Path != null)
            {
                BitmapImage source = new BitmapImage(new Uri(product.Image_Path));
                imgProduct.Source = source;
            }
            Thread getTypes = new Thread(delegate()
            {
                MANAGEMENT_STORE_Entities db = new MANAGEMENT_STORE_Entities();
                var TypeProduct = new ObservableCollection <string>(db.Type_product.Select(x => x.Type_Product1));
                var Supplier    = new ObservableCollection <string>(db.Supplier.Select(x => x.Name_Sup));
                Dispatcher.Invoke(() =>
                {
                    comboProductTypes.ItemsSource = TypeProduct;
                    comboboxSupplier.ItemsSource  = Supplier;
                });
                Type_product target = db.Type_product.Find(product.ID_TypeProduct);
                for (int i = 0; i < TypeProduct.Count; i++)
                {
                    if (TypeProduct[i] == target.Type_Product1)
                    {
                        Dispatcher.Invoke(() =>
                        {
                            comboProductTypes.SelectedIndex = i;
                        });
                        break;
                    }
                }

                Supplier target1 = db.Supplier.Find(product.ID_Supplier);
                for (int i = 0; i < Supplier.Count; i++)
                {
                    if (Supplier[i] == target1.Name_Sup)
                    {
                        Dispatcher.Invoke(() =>
                        {
                            comboboxSupplier.SelectedIndex = i;
                        });
                        break;
                    }
                }
            });

            getTypes.Start();
        }
Ejemplo n.º 2
0
        //Save edit or delete new type
        private void BtnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (IconDelete.Kind == MaterialDesignThemes.Wpf.PackIconKind.DeleteCircle)
            {
                Dialog a = new Dialog()
                {
                    Message = "Are you sure to delete this Type product?"
                };
                a.Owner = Window.GetWindow(this);
                if (a.ShowDialog() == false)
                {
                    return;
                }
                Type_product pro = listProductType.SelectedItem as Type_product;
                manage.DeleteTypeProduct(pro.ID);
                listProductType.ItemsSource   = new ObservableCollection <Type_product>(manage.Load_ProductType());
                listProductType.SelectedIndex = -1;
                //xóa các textbox
                txbDescrip.Clear();
                txbIdtype.Clear();
                txbNameType.Clear();
                btnDelete.IsEnabled      = false;
                btnEditProduct.IsEnabled = false;

                if (refreshCombobox != null)
                {
                    refreshCombobox.Invoke(true);
                }
            }

            if (IconDelete.Kind == MaterialDesignThemes.Wpf.PackIconKind.ContentSave)
            {
                if (CheckInput())
                {
                    Dialog b = new Dialog()
                    {
                        Message = "Are you sure to add this type product?"
                    };
                    b.Owner = Window.GetWindow(this);
                    if (b.ShowDialog() == true)
                    {
                        btnAdd.IsEnabled = true;
                        manage.AddNewTypeproduct(txbIdtype.Text, txbNameType.Text);
                        listProductType.ItemsSource = new ObservableCollection <Type_product>(manage.Load_ProductType());
                        IconDelete.Kind             = MaterialDesignThemes.Wpf.PackIconKind.DeleteCircle;
                        btnDelete.ToolTip           = "Delete product";
                        IconEdit.Kind = MaterialDesignThemes.Wpf.PackIconKind.Edit;
                        listProductType.SelectedIndex = listProductType.Items.Count - 1;
                        listProductType.IsEnabled     = true;
                        TextboxSet(false);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public ObservableCollection <Type_product> getTypeList()
        {
            var temp = db.Type_product;
            ObservableCollection <Type_product> listTmp = new ObservableCollection <Type_product>();

            foreach (Type_product item in temp)
            {
                Type_product tempItem = (Type_product)item;
                listTmp.Add(tempItem);
            }
            return(listTmp);
        }
Ejemplo n.º 4
0
        private void ListProductType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (listProductType.SelectedItem == null)
            {
                return;
            }

            Type_product a = listProductType.SelectedItem as Type_product;

            txbIdtype.Text   = a.ID;
            txbNameType.Text = a.Type_Product1;
            txbDescrip.Text  = "null";

            btnDelete.IsEnabled      = true;
            btnEditProduct.IsEnabled = true;
        }
Ejemplo n.º 5
0
        public bool DeleteTypeProduct(string id)
        {
            try
            {
                Type_product a = new Type_product();
                a.ID = id;
                db.Type_product.Attach(a);
                db.Type_product.Remove(a);

                db.SaveChanges();
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 6
0
        public bool  AddNewTypeproduct(string ID, string name)
        {
            Type_product a = new Type_product();

            a.ID             = ID;
            a.Type_Product1  = name;
            a.Num_Of_Product = 0;
            try
            {
                db.Type_product.Add(a);
                db.SaveChanges();
            }
            catch (Exception e)
            {
                return(false);
            }
            return(true);
        }
        public void Import(ObservableCollection <ImportProduct> Data)
        {
            MANAGEMENT_STORE_Entities db = new MANAGEMENT_STORE_Entities();

            if (Data != null)
            {
                for (int i = 0; i < Data.Count; i++)
                {
                    try
                    {
                        dbProduct.AddProduct(false, Data[i].ID, Data[i].Type, Data[i].Supplier, Data[i].input_time, Data[i].Name, Data[i].Orig_price, Data[i].Initial_amount, Data[i].Descrip, Data[i].Image_path);
                        // Tăng số sản phẩm của loại sản phẩm
                        Type_product type = db.Type_product.Find(Data[i].ID_Type);
                        type.Num_Of_Product++;
                        db.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        continue; // Không xảy ra lỗi trùng mã vì đã xử lý trước
                    }
                }
                Refresh(true);
            }
        }
Ejemplo n.º 8
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Left = Owner.Left + Owner.Width / 2 - Width / 2;
            Top  = this.Owner.Top + Owner.Height / 2 - Height / 2;

            Thread thread = new Thread(delegate()
            {
                // Mở Excel và đọc
                Workbook workbook   = new Workbook(filename);
                Worksheet worksheet = workbook.Worksheets[0];
                var db = new MANAGEMENT_STORE_Entities();
                db.Configuration.ValidateOnSaveEnabled = false;
                // Nếu import loại sản phẩm
                if (worksheet.Name.Equals("Product Type"))
                {
                    productTypes = new ObservableCollection <Type_product>();

                    // Bắt đầu từ hàng thứ 2
                    int i = 2;
                    while (worksheet.Cells[$"B{i}"].Value != null)
                    {
                        // Nếu dữ liệu đã tồn tại thì thôi
                        if (db.Type_product.FirstOrDefault(x => x.ID == worksheet.Cells[$"B{i}"].Value.ToString()) != null)
                        {
                            i++;
                            continue;
                        }

                        // Kiểm tra tên, ngày có trống không
                        if (worksheet.Cells[$"A{i}"].Value == null ||
                            worksheet.Cells[$"C{i}"].Value == null)
                        {
                            i++;
                            continue;
                        }

                        // Tới đây được tức có dữ liệu đã đúng
                        Type_product type = new Type_product()
                        {
                            Type_Product1  = worksheet.Cells[$"A{i}"].Value.ToString(),
                            ID             = worksheet.Cells[$"B{i}"].Value.ToString(),
                            Num_Of_Product = Int32.Parse(worksheet.Cells[$"B{i}"].Value.ToString())
                        };
                        productTypes.Add(type);
                        i++;
                    }

                    // Cập nhật UI
                    Dispatcher.Invoke(() =>
                    {
                        listData.ItemsSource = productTypes;
                    });
                }
                // Nếu import sản phẩm
                else if (worksheet.Name.Equals("Product"))
                {
                    import = new ObservableCollection <ImportProduct>();

                    // Bắt đầu từ hàng thứ 2
                    int i = 2;
                    while (worksheet.Cells[$"B{i}"].Value != null)
                    {
                        // Nếu dữ liệu đã tồn tại thì thôi
                        string t = worksheet.Cells[$"B{i}"].Value.ToString();
                        if (db.Detail_Product.FirstOrDefault(x => x.ID_Product == t) != null)
                        {
                            i++;
                            continue;
                        }

                        // Nếu loại sản phẩm không tồn tại thì thôi
                        t = worksheet.Cells[$"J{i}"].Value.ToString();
                        if (db.Type_product.FirstOrDefault(x => x.ID == t) == null)
                        {
                            i++;
                            continue;
                        }

                        t = worksheet.Cells[$"I{i}"].Value.ToString();
                        if (db.Supplier.FirstOrDefault(x => x.ID_sup == t) == null)
                        {
                            i++;
                            continue;
                        }

                        // Kiểm tra các cột khác có trống không (trừ MÔ TẢ, LOẠI SP và ẢNH SP)
                        if (worksheet.Cells[$"A{i}"].Value == null ||
                            worksheet.Cells[$"C{i}"].Value == null ||
                            worksheet.Cells[$"D{i}"].Value == null ||
                            worksheet.Cells[$"E{i}"].Value == null ||
                            worksheet.Cells[$"F{i}"].Value == null ||
                            worksheet.Cells[$"G{i}"].Value == null ||
                            worksheet.Cells[$"K{i}"].Value == null)
                        {
                            i++;
                            continue;
                        }

                        // Kiểm tra ngày có đúng định dạng không
                        string date       = worksheet.Cells[$"D{i}"].Value.ToString();
                        DateTime dateTime = new DateTime();
                        try
                        {
                            dateTime = DateTime.Parse(date);
                        }
                        catch (Exception ex)
                        {
                            i++;
                            continue;
                        }

                        // Tới đây được tức có dữ liệu đã đúng
                        try
                        {
                            Detail_Product product = new Detail_Product()
                            {
                                NameProduct     = worksheet.Cells[$"A{i}"].Value.ToString(),
                                ID_Product      = worksheet.Cells[$"B{i}"].Value.ToString(),
                                Original_Price  = Int32.Parse(worksheet.Cells[$"C{i}"].Value.ToString()),
                                Amount_Current  = int.Parse(worksheet.Cells[$"F{i}"].Value.ToString()),
                                Description_Pro = worksheet.Cells[$"H{i}"].Value == null ? null : worksheet.Cells[$"H{i}"].Value.ToString(),
                                ID_TypeProduct  = worksheet.Cells[$"J{i}"].Value.ToString(),
                                Image_Path      = worksheet.Cells[$"K{i}"].Value == null ? null : worksheet.Cells[$"K{i}"].Value.ToString(),
                                ID_Supplier     = worksheet.Cells[$"I{i}"].Value.ToString()
                            };

                            DateTime time      = DateTime.Parse(worksheet.Cells[$"D{i}"].Value.ToString());
                            int Capital        = Int32.Parse(worksheet.Cells[$"G{i}"].Value.ToString());
                            int Amount_Initial = int.Parse(worksheet.Cells[$"F{i}"].Value.ToString());
                            ImportProduct a    = new ImportProduct()
                            {
                                Name           = product.NameProduct.ToString(),
                                ID             = product.ID_Product,
                                Curr_amount    = Int32.Parse(product.Amount_Current.ToString()),
                                Orig_price     = Int32.Parse(product.Original_Price.ToString()),
                                Supplier       = db.Supplier.Find(product.ID_Supplier).Name_Sup,
                                Type           = db.Type_product.Find(product.ID_TypeProduct).Type_Product1,
                                Descrip        = product.Description_Pro,
                                ID_Type        = product.ID_TypeProduct,
                                ID_Supp        = product.ID_Supplier,
                                Image_path     = product.Image_Path,
                                input_time     = time,
                                capital        = Capital,
                                Initial_amount = Amount_Initial
                            };
                            import.Add(a);
                        }
                        catch (Exception) { }
                        i++;
                        continue;
                    }

                    // Cập nhật UI
                    Dispatcher.Invoke(() =>
                    {
                        listData.ItemsSource = import;
                    });
                }

                // Nếu không có dữ liệu nào có thể import thì thông báo
                Dispatcher.Invoke(() =>
                {
                    if (listData.Items.Count == 0)
                    {
                        emptyAnnounce.Visibility = Visibility.Visible;
                    }
                    ProgressBar.IsEnabled  = false;
                    ProgressBar.Visibility = Visibility.Hidden;
                });
            });

            thread.Start();
        }
Ejemplo n.º 9
0
        public void AddProduct(bool isEdit, string ID, string typeName, string Name_sup, DateTime dateTime, string Name, int Price, int amount_init, string descr, string img_Path)
        {
            Detail_Product product = new Detail_Product();

            product.ID_Product      = ID;
            product.NameProduct     = Name;
            product.Original_Price  = Price;
            product.Image_Path      = img_Path == null ? null : img_Path;
            product.Description_Pro = descr.Length == 0 ? null : descr;
            product.Amount_Current  = amount_init;
            Supplier supp = db.Supplier.FirstOrDefault(x => x.Name_Sup == Name_sup);

            if (supp != null)
            {
                product.ID_Supplier = supp.ID_sup;
            }

            //Thêm thông tin vào Input_form cho sản phẩm
            Type_product type = db.Type_product.FirstOrDefault(x => x.Type_Product1 == typeName);

            if (type != null)
            {
                product.ID_TypeProduct = type.ID;
            }
            else
            {
                product.ID_Product = "sdf";
            }

            // Nếu sửa
            if (isEdit)
            {
                Input_Form input_ = db.Input_Form.SingleOrDefault(x => x.ID_Product == ID);
                input_.Input_Date = dateTime;
                input_.ID_Sup     = supp.ID_sup;

                var oldProduct = db.Detail_Product.FirstOrDefault(x => x.ID_Product == ID);
                oldProduct.NameProduct     = product.NameProduct;
                oldProduct.Original_Price  = product.Original_Price;
                oldProduct.Description_Pro = product.Description_Pro;
                oldProduct.Image_Path      = product.Image_Path;
                oldProduct.Amount_Current += product.Amount_Current; // Thêm lượng mới nhập vào cả tồn kho ban đầu và tồn kho hiện tại
                if (oldProduct.ID_TypeProduct != type.ID)            // Nếu có thay đổi mã sản phẩm
                {
                    type.Num_Of_Product++;                           // Tăng mã mới
                    Type_product oldType = db.Type_product.Find(oldProduct.ID_TypeProduct);
                    oldType.Num_Of_Product--;                        // Giảm mã cũ
                    oldProduct.ID_TypeProduct = product.ID_TypeProduct;
                }
            }

            // Nếu thêm
            else     // Nếu thêm
            {
                Input_Form input = new Input_Form();
                input.ID_Product = ID;
                input.ID_Sup     = supp.ID_sup;
                input.Input_Date = dateTime;
                input.Amount     = amount_init;
                //Tao id tự động cho Input
                ObservableCollection <Input_Form> Input = new ObservableCollection <Input_Form>(db.Input_Form);
                int    count = Input.Count();
                string s1    = Input[count - 1].ID_Input;
                int    s2    = Convert.ToInt32(s1.Remove(0, 2));

                if (s2 + 1 < 10)
                {
                    input.ID_Input = "Ip00" + (s2 + 1).ToString();
                }
                else
                {
                    input.ID_Input = "Ip0" + (s2 + 1).ToString();
                }
                db.Input_Form.Add(input);
                db.Detail_Product.Add(product);
                type.Num_Of_Product += product.Amount_Current;
            }
            db.SaveChanges();


            //db.SaveChanges();
        }
Ejemplo n.º 10
0
        private void BtnEditProduct_Click(object sender, RoutedEventArgs e)
        {
            if (IconEdit.Kind == MaterialDesignThemes.Wpf.PackIconKind.Edit)
            {
                txbDescrip.IsEnabled      = txbNameType.IsEnabled = true;
                txbIdtype.IsEnabled       = false;
                IconEdit.Kind             = MaterialDesignThemes.Wpf.PackIconKind.ContentSave;
                btnEditProduct.ToolTip    = "Save change";
                btnAdd.IsEnabled          = false;
                listProductType.IsEnabled = false;

                IconDelete.Kind   = MaterialDesignThemes.Wpf.PackIconKind.Cancel;
                btnDelete.ToolTip = "Cancel change";
            }
            else
            if (IconEdit.Kind == MaterialDesignThemes.Wpf.PackIconKind.ContentSave)
            {
                Dialog a = new Dialog()
                {
                    Message = "Are you sure to save ?"
                };
                a.Owner = Window.GetWindow(this);
                if (a.ShowDialog() == true)
                {
                    Type_product pro = listProductType.SelectedItem as Type_product;
                    manage.EditProduct(pro.ID, txbNameType.Text);
                    listProductType.ItemsSource = new ObservableCollection <Type_product>(manage.Load_ProductType());
                    IconDelete.Kind             = MaterialDesignThemes.Wpf.PackIconKind.DeleteCircle;
                    btnDelete.ToolTip           = "Delete product";
                    listProductType.IsEnabled   = true;
                    IconEdit.Kind                 = MaterialDesignThemes.Wpf.PackIconKind.Edit;
                    btnEditProduct.ToolTip        = "Edit product";
                    listProductType.SelectedIndex = listProductType.Items.Count - 1;
                    txbDescrip.IsEnabled          = txbIdtype.IsEnabled = txbNameType.IsEnabled = false;
                    btnAdd.IsEnabled              = true;

                    if (refreshCombobox != null)
                    {
                        refreshCombobox.Invoke(true);
                    }
                }
            }
            else
            if (IconEdit.Kind == MaterialDesignThemes.Wpf.PackIconKind.Cancel)
            {
                Dialog a = new Dialog()
                {
                    Message = "Are you sure to cancel ?"
                };
                a.Owner = Window.GetWindow(this);
                if (a.ShowDialog() == true)
                {
                    txbDescrip.IsEnabled          = txbIdtype.IsEnabled = txbNameType.IsEnabled = false;
                    listProductType.IsEnabled     = true;
                    IconDelete.Kind               = MaterialDesignThemes.Wpf.PackIconKind.DeleteCircle;
                    btnDelete.ToolTip             = "Delete product";
                    btnDelete.IsEnabled           = false;
                    btnAdd.IsEnabled              = true;
                    IconEdit.Kind                 = MaterialDesignThemes.Wpf.PackIconKind.Edit;
                    btnEditProduct.ToolTip        = "Edit product";
                    btnEditProduct.IsEnabled      = false;
                    listProductType.SelectedIndex = -1;
                }
                else
                {
                    txbIdtype.Focus();
                }
            }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Left = Owner.Left + Owner.Width / 2 - Width / 2;
            Top  = this.Owner.Top + Owner.Height / 2 - Height / 2;

            Thread thread = new Thread(delegate()
            {
                // Mở Excel và đọc
                Workbook workbook   = new Workbook(filename);
                Worksheet worksheet = workbook.Worksheets[0];
                // Nếu import loại sản phẩm
                if (worksheet.Name.Equals("Type Product"))
                {
                    productTypes = new ObservableCollection <Type_product>();

                    // Bắt đầu từ hàng thứ 2
                    int i = 2;
                    while (worksheet.Cells[$"B{i}"].Value != null)
                    {
                        // Nếu dữ liệu đã tồn tại thì thôi
                        if (manage.getType(worksheet.Cells[$"B{i}"].Value.ToString()) != null)
                        {
                            i++;
                            continue;
                        }

                        // Kiểm tra tên, ngày có trống không
                        if (worksheet.Cells[$"A{i}"].Value == null ||
                            worksheet.Cells[$"C{i}"].Value == null)
                        {
                            i++;
                            continue;
                        }

                        // Tới đây được tức có dữ liệu đã đúng
                        Type_product type = new Type_product()
                        {
                            Type_Product1  = worksheet.Cells[$"A{i}"].Value.ToString(),
                            ID             = worksheet.Cells[$"B{i}"].Value.ToString(),
                            Num_Of_Product = Int32.Parse(worksheet.Cells[$"C{i}"].Value.ToString())
                        };
                        productTypes.Add(type);
                        i++;
                    }

                    // Cập nhật UI
                    Dispatcher.Invoke(() =>
                    {
                        listData.ItemsSource = productTypes;
                    });
                }
                // Nếu import sản phẩm

                // Nếu không có dữ liệu nào có thể import thì thông báo
                Dispatcher.Invoke(() =>
                {
                    if (listData.Items.Count == 0)
                    {
                        emptyAnnounce.Visibility = Visibility.Visible;
                    }
                    ProgressBar.IsEnabled  = false;
                    ProgressBar.Visibility = Visibility.Hidden;
                });
            });

            thread.Start();
        }