diff --git a/BookShop2023/Data/Queries/reset_ident.sql b/BookShop2023/Data/Queries/reset_ident.sql new file mode 100644 index 0000000..4b69ac1 --- /dev/null +++ b/BookShop2023/Data/Queries/reset_ident.sql @@ -0,0 +1,11 @@ +USE BookShop2023 +GO + +DELETE FROM Product; +DBCC CHECKIDENT ('Product', RESEED, 0); + +DELETE FROM Category; +DBCC CHECKIDENT ('Category', RESEED, 0); + +SELECT * FROM Category; +SELECT * FROM Product; \ No newline at end of file diff --git a/BookShop2023/Source/BookShop2023/DAO/CategoryDAO.cs b/BookShop2023/Source/BookShop2023/DAO/CategoryDAO.cs index 02c47c6..74d826a 100644 --- a/BookShop2023/Source/BookShop2023/DAO/CategoryDAO.cs +++ b/BookShop2023/Source/BookShop2023/DAO/CategoryDAO.cs @@ -61,15 +61,7 @@ public List getCategoryList() resultList.Add(category); } - // add all option for filter and display if has data - if (resultList.Count > 0) - { - resultList.Add(new Category() - { - ID = resultList[^1].ID + 1, - Name = "All" - }); - } + reader.Close(); return resultList; diff --git a/BookShop2023/Source/BookShop2023/MainWindow.xaml b/BookShop2023/Source/BookShop2023/MainWindow.xaml index 32f7adf..62c882b 100644 --- a/BookShop2023/Source/BookShop2023/MainWindow.xaml +++ b/BookShop2023/Source/BookShop2023/MainWindow.xaml @@ -31,7 +31,7 @@ diff --git a/BookShop2023/Source/BookShop2023/Views/AddProductScreen.xaml b/BookShop2023/Source/BookShop2023/Views/AddProductScreen.xaml index c485937..2977bda 100644 --- a/BookShop2023/Source/BookShop2023/Views/AddProductScreen.xaml +++ b/BookShop2023/Source/BookShop2023/Views/AddProductScreen.xaml @@ -5,8 +5,13 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:local="clr-namespace:ProjectMyShop.Views" + xmlns:local1="clr-namespace:ProjectMyShop.Converter" mc:Ignorable="d" Title="Thêm sản phẩm mới" Height="650" Width="800"> + + + + @@ -28,20 +33,31 @@ - + - - - + + - + - - + - - - + - - - - + - ? _categories = null; BindingList _products = new BindingList(); @@ -51,7 +51,7 @@ public ManageProduct() int _currentPage = 1; int _totalPages = 0; int _rowsPerPage = int.Parse(AppConfig.GetValue(AppConfig.NumberProductPerPage)); - + #endregion #region Features: search product with criterias: private void searchTextBox_TextChanged(object sender, TextChangedEventArgs e) @@ -75,6 +75,16 @@ private void Page_Loaded(object sender, RoutedEventArgs e) var ProductBUS = new ProductBUS(); _categories = catBUS.getCategoryList(); + // add all option for filter and display if has data + if (_categories.Count > 0) + { + _categories.Add(new Category() + { + ID = _categories[^1].ID + 1, + Name = "Tất cả" + }); + } + categoriesComboBox.ItemsSource = _categories; categoriesComboBox.SelectedIndex = _categories.Count - 1; @@ -89,11 +99,6 @@ private void Page_Loaded(object sender, RoutedEventArgs e) } #endregion - private void filterRangeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) - { - - - } #region load products @@ -115,7 +120,9 @@ void loadProducts() } + #endregion + #region Tính toán phân trang public void devidePaging() { int count = _ProductBus.loadAllProducts().Count; @@ -153,7 +160,7 @@ public void devidePaging() } #endregion - #region Xử lý sự kiện click menu item của sản phẩm trong listView + #region Xử lý sự kiện click menu item của sản phẩm trong listView | xem chi tiết, chỉnh sửa, xóa sản phẩm private void viewMenuItem_Click(object sender, RoutedEventArgs e) { var p = (Product)ProductsListView.SelectedItem; @@ -219,6 +226,7 @@ private void deleteMenuItem_Click(object sender, RoutedEventArgs e) } #endregion + #region Chuyển trang trước, trang sau khi click button private void previousButton_Click(object sender, RoutedEventArgs e) { if (pagingComboBox.SelectedIndex > 0) @@ -237,6 +245,7 @@ private void nextButton_Click(object sender, RoutedEventArgs e) } } + #endregion #region Import data private void ImportButton_Click(object sender, RoutedEventArgs e) @@ -280,6 +289,16 @@ private void ImportButton_Click(object sender, RoutedEventArgs e) } _categories = _cateBUS.getCategoryList(); + // add all option for filter and display if has data + if (_categories.Count > 0) + { + _categories.Add(new Category() + { + ID = _categories[^1].ID + 1, + Name = "Tất cả" + }); + } + Debug.WriteLine(_categories.Count); categoriesComboBox.ItemsSource = _categories; @@ -414,6 +433,7 @@ private void ImportButton_Click(object sender, RoutedEventArgs e) } #endregion + #region Thêm sản phẩm mới private void AddMenuItem_Click(object sender, RoutedEventArgs e) { var screen = new AddProductScreen(_categories!); @@ -422,22 +442,23 @@ private void AddMenuItem_Click(object sender, RoutedEventArgs e) { var newProduct = screen.newProduct; Debug.WriteLine(newProduct.Name); - var catIndex = screen.catIndex; - if(catIndex >= 0) - { + try { _ProductBus.addProduct(newProduct); loadProducts(); - } + MessageBox.Show($"Thêm sản phẩm thành công!", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Information); + } catch (Exception ex) { MessageBox.Show(screen, ex.Message); } - } + } } + #endregion + #region Lọc giá sản phẩm private void FilterButton_Click(object sender, RoutedEventArgs e) { // validate input @@ -475,12 +496,14 @@ private void FilterButton_Click(object sender, RoutedEventArgs e) MessageBox.Show("Invalid price input for filter !", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } + #endregion + #region Xử lý lọc theo thể loại sản phẩm private void categoriesComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { int id = categoriesComboBox.SelectedIndex; // MessageBox.Show("Category choose: " + _categories[id].Name ); - if (!_categories[id].Name.Equals("All")) + if (!_categories[id].Name.Equals("Tất cả")) { int catID = _categories[id].ID; _ProductBus.setFilterCat(catID); @@ -491,7 +514,9 @@ private void categoriesComboBox_SelectionChanged(object sender, SelectionChanged } loadProducts(); } + #endregion + #region Thay đổi trang xem : click pagingComboBox private void pagingComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { dynamic info = pagingComboBox.SelectedItem; @@ -519,6 +544,7 @@ private void pagingComboBox_SelectionChanged(object sender, SelectionChangedEven previousButton.IsEnabled = true; } } + #endregion #region Xử lý giao diện khi người dùng tương tác private void pagingComboBox_DropDownOpened(object sender, EventArgs e)