void CalculatePagingInfo() { var db = new MyShopEntities(); var _selectedCategoryIndex = categoriesComboBox.SelectedItem as Category; var products = db.Categories.Find(_selectedCategoryIndex.Category_Id).Products; var query = from product in products select product.Product_Id; var count = query.Count(); _pagingInfo = new PagingInfo() { RowsPerPage = rowsPerPage, TotalItems = count, TotalPages = count / rowsPerPage + (((count % rowsPerPage) == 0) ? 0 : 1), CurrentPage = 1 }; comboBoxPaging.ItemsSource = _pagingInfo.Pages; comboBoxPaging.SelectedIndex = 0; statusLabel.Content = $"Tổng sản phẩm: {count} "; }
void UpdateProductView() { var db = new MyShopEntities(); var products = db.Products; var orderdetails = db.OrderDetails; var query = from orderdetail in orderdetails group orderdetail by orderdetail.ProductId into orderGroup join p in products on orderGroup.Key equals p.Product_Id orderby orderGroup.Sum(o => o.Quantity) descending select new { ProductName = p.Product_Name, Thumbnail = p.Photos.FirstOrDefault().Data, Price = p.Price, Count = orderGroup.Sum(o => o.Quantity), }; // Gan du lieu cho list view de o cuoi cung // Dua theo trang hien tai var take = 7; productsListView.ItemsSource = query.Take(take).ToList(); }
/// <summary> /// Tính toán số trang của một category /// </summary> void CalculatePagingInfo() { var db = new MyShopEntities(); var _selectedCategoryIndex = categoriesComboBox.SelectedItem as Category; var products = db.Categories.Find(_selectedCategoryIndex.Category_Id).Products; var keyword = searchTextBox.Text; var query = from product in products where product.Product_Name.ToLower() .Contains(keyword.ToLower()) select product.Product_Id; // Tinh toan thong tin phan trang var count = query.Count(); _pagingInfo = new PagingInfo() { RowsPerPage = rowsPerPage, TotalItems = count, TotalPages = count / rowsPerPage + (((count % rowsPerPage) == 0) ? 0 : 1), CurrentPage = 1 }; comboBoxPaging.ItemsSource = _pagingInfo.Pages; comboBoxPaging.SelectedIndex = 0; statusLabel.Content = $"Tổng sản phẩm: {count} "; }
/// <summary> /// Cập nhật lại danh sách sản phẩm /// </summary> void UpdateProductView() { var db = new MyShopEntities(); var _selectedCategoryIndex = categoriesComboBox.SelectedItem as Category; var products = db.Categories.Find(_selectedCategoryIndex.Category_Id).Products; var keyword = searchTextBox.Text; var query = from product in products where product.Product_Name.ToLower() .Contains(keyword.ToLower()) //&& product.Price <= _filterInfo.Value select new { product.Product_Id, ProductName = product.Product_Name, Thumbnail = product.Photos.First().Data, product.Price }; // Gan du lieu cho list view de o cuoi cung // Dua theo trang hien tai var skip = (_pagingInfo.CurrentPage - 1) * _pagingInfo.RowsPerPage; var take = _pagingInfo.RowsPerPage; productsListView.ItemsSource = query.Skip(skip).Take(take); }
private void productsListView_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { statusLabel.Content = "Detail product"; var db = new MyShopEntities(); dynamic itemProduct = (sender as ListView).SelectedItem; if (itemProduct != null) { // lấy sản phẩm trong database var product = db.Products.Find(itemProduct.Product_Id); // nếu Pick sản phẩm để tạo hóa đơn if (PickProductId != null) { PickProductId.Invoke(product); homeProduct.Children.Clear(); } else { var screen = new DetailProductScreen(product); screen.RefreshProductList = refresh; homeProduct.Children.Add(screen); } } }
private void mucGia_CheckedChanged(object sender, RoutedEventArgs e) { var db = new MyShopEntities(); var selectedCategory = categoriesComboBox.SelectedItem as Category; if (tatCa_Checkbox.IsChecked == true) { minPrice = int.MinValue; maxPrice = int.MaxValue; } else if (mucGia1_Checkbox.IsChecked == true) { minPrice = int.MinValue; maxPrice = 100000; } else if (mucGia2_Checkbox.IsChecked == true) { minPrice = 100000; maxPrice = 150000; } else if (mucGia3_Checkbox.IsChecked == true) { minPrice = 150000; maxPrice = 200000; } else if (mucGia4_Checkbox.IsChecked == true) { minPrice = 200000; maxPrice = int.MaxValue; } CalculatePagingInfo(db, selectedCategory); UpdateProductView(db, selectedCategory); }
public void CalculatePagingInfo(MyShopEntities db, Category selectedCategory) { ICollection <Product> products = db.Categories.Find(selectedCategory.Category_Id).Products; var keyword = searchTextBox.Text; var query = from product in products where product.Product_Name.ToLower() .Contains(keyword.ToLower()) && (product.Price >= minPrice && product.Price <= maxPrice) select product; var count = query.Count(); // Tinh toan thong tin phan trang _pagingInfo = new PagingInfo() { RowsPerPage = rowsPerPage, TotalItems = count, TotalPages = count / rowsPerPage + (((count % rowsPerPage) == 0) ? 0 : 1), CurrentPage = 1 }; comboBoxPaging.ItemsSource = _pagingInfo.Pages; comboBoxPaging.SelectedIndex = 0; statusLabel.Content = $"Tổng sản phẩm: {count} "; }
/// <summary> /// refesh lại comboBox category /// </summary> /// <param name="Data"></param> public void RefreshComboBox(bool Data) { if (Data) // Nếu có chỉnh sửa danh sách loại sản phẩm thì refresh comboBox { int oldIndex = ProductTypeComboxBox.SelectedIndex; // Get và hiển thị danh sách loại sản phẩm Thread getCategories = new Thread(delegate() { var db = new MyShopEntities(); var category = new ObservableCollection <Category>(db.Categories.ToList()); Dispatcher.Invoke(() => { //gán lên comboBox category ProductTypeComboxBox.ItemsSource = category; if (oldIndex > 0) { ProductTypeComboxBox.SelectedIndex = oldIndex; } // Cập nhật tiếp trang ở trước if (RefreshProductList != null) { RefreshProductList.Invoke(true); } }); }); getCategories.Start(); } }
public static MyShopEntities getInstance() { if (_conn == null) { _conn = new MyShopEntities(); } return(_conn); }
private void NumberBuy_TextChanged(object sender, TextChangedEventArgs e) { if (numberBuyTextBox.Text.Length > 0) { //Mở nút thêm btnAddToListProduct.Visibility = Visibility.Visible; // Kiểm tra còn đủ hàng hay không var db = new MyShopEntities(); var curProduct = db.Products.Find(product.Product_Id); int number = 0; // Số lượng mua int.TryParse(numberBuyTextBox.Text, out number); if (curProduct.Quantity < number) // Nếu số lượng không đủ thì thông báo { var dialogError = new Messenge() { Message = "Not enough quantity!" }; dialogError.Sounds(); dialogError.time = 2000; dialogError.Owner = Window.GetWindow(this); dialogError.ShowDialog(); numberBuyTextBox.Clear(); //Tắt nút thêm btnAddToListProduct.Visibility = Visibility.Hidden; return; } // Lấy số lượng người dùng muốn mua int NumberBuy = 0; int.TryParse(numberBuyTextBox.Text, out NumberBuy); // Phát sinh giá gốc double value = 0; value = (double)product.Price; originalPriceTextbox.Text = value.ToString("N0"); //Sự kiện khuyến mãi (Chưa có) float eventPromotion = 0; sellPriceTextBox.Text = (value - value * eventPromotion / 100).ToString("N0"); //tổng tiền totalTextBox.Text = (value * NumberBuy).ToString("N0"); } else { btnAddToListProduct.Visibility = Visibility.Hidden; originalPriceTextbox.Clear(); sellPriceTextBox.Clear(); totalTextBox.Clear(); } // Tính tiền trả lại + tiền sẽ thu nếu giao hàng CountExchange(null, null); CountMoneyWillGet(null, null); }
private void status_Checkbox_Unchecked(object sender, RoutedEventArgs e) { var db = new MyShopEntities(); var selectedCategory = categoriesComboBox.SelectedItem as Category; quantity = int.MaxValue; CalculatePagingInfo(db, selectedCategory); UpdateProductView(db, selectedCategory); }
/// <summary> /// Refresh lại order khi chưa sửa /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnRefresh_Click(object sender, RoutedEventArgs e) { var db = new MyShopEntities(); var order = db.Purchases.Find(_purchaseID); customerPhoneTextBox.Text = order.CustomerTel; //số điện thoại khách hàng CustomerNameTextBox.Text = order.Customer.Fullname; // tên khách hàng //load tất cả sản phẩm trong được order vào list foreach (var o in order.OrderDetails) { _listProduct.Add(new ProductViewModel() { Product_Id = o.Product.Product_Id, ProductName = o.Product.Product_Name, Price = decimal.Parse(o.Price.ToString()), Quantity = int.Parse(o.Quantity.ToString()), Total = decimal.Parse(o.Total.ToString()) }); } listProducts.ItemsSource = _listProduct; //Kiểm tra xem là có thanh toán tại shop hay là qua online (thanh toán gián tiếp) if (order.AtStore == true) { //Mở nút check at home rdoGoToShop.IsChecked = true; editMoneyTaken.Text = ((double)order.MoneyTaken).ToString("N0") ?? null; editMoneyExchange.Text = ((double)order.MoneyExchange).ToString("N0") ?? null; } else { //Nút check thanh toán online rdoShip.IsChecked = true; editAddress.Text = order.DeliveryAdress; editDeposit.Text = (decimal.Parse(order.Deposit.ToString())).ToString("N0"); editShipCost.Text = (decimal.Parse(order.Ship.ToString())).ToString("N0"); editMoneyWillGet.Text = (decimal.Parse(order.MoneyWillGet.ToString())).ToString("N0"); } //Tổng tiền của tất cả sản phẩm trong order sumTotalOfProduct.Text = $"{((double)order.OrderDetails.Sum(x => x.Total)).ToString("N0")} đ"; //Nếu textbox có tên sản phẩm thì xóa đi if (editProductId != null) { editProductId.Clear(); } }
private void status_CheckedChanged(object sender, RoutedEventArgs e) { var db = new MyShopEntities(); var selectedCategory = categoriesComboBox.SelectedItem as Category; if (status_Checkbox.IsChecked == true) { quantity = 10; } CalculatePagingInfo(db, selectedCategory); UpdateProductView(db, selectedCategory); }
private async void UserControl_Initialized(object sender, EventArgs e) { statusLabel.Content = "Application is ready"; var db = new MyShopEntities(); await Task.Run(() => { Thread.Sleep(1000); }); categoriesComboBox.ItemsSource = db.Categories.ToList(); categoriesComboBox.SelectedIndex = 0; }
public NewProductScreen(Product product) { InitializeComponent(); isEditProduct = true; var image = product.Photos.First().Data; //Thông tin UI Title.Content = "EDIT PRODUCT"; producIDTextBox.Text = product.Product_Id.ToString(); //id producIDTextBox.IsEnabled = false; // tắt sửa id productNameTextBox.Text = product.Product_Name; //tên sản phẩm storeCodeTextBox.Text = product.SKU; // mã kho productPriceTextbox.Text = product.Price.ToString(); //giá productQuantityTextbox.Text = product.Quantity.ToString(); //số lượng //Kiểm tra mô tả if (product.Description != null) { productDescriptionTextBox.Text = product.Description; } //image imgProduct.Source = LoadImage(product.Photos.First().Data); imgProduct.Tag = LoadImage(product.Photos.First().Data); Thread catThread = new Thread(delegate() { var db = new MyShopEntities(); var _catID = db.Categories.Find(product.CatId); var category = new ObservableCollection <Category>(db.Categories.ToList()); Dispatcher.Invoke(() => { ProductTypeComboxBox.ItemsSource = category; //tìm loại sản phẩm tương ứng for (int i = 0; i < category.Count; i++) { if (category[i].Category_Id.Equals(_catID.Category_Id)) { ProductTypeComboxBox.SelectedIndex = i; break; } } }); }); catThread.Start(); }
/// <summary> /// xóa sản phẩm khỏi database /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnDeleteProduct_Click(object sender, RoutedEventArgs e) { // Hiện thông báo xác nhận var dialog = new Dialog() { Message = "Delete this product, Are you sure?" }; dialog.Owner = Window.GetWindow(this); if (dialog.ShowDialog() == false) { return; } //thao tác dưới cơ sở dữ liệu var db = new MyShopEntities(); try { //xóa product sẽ xóa luôn ảnh của product //Tìm hình ảnh của product để xóa var imageProductFromDatabase = db.Photos.Find(_product.Product_Id); db.Photos.Remove(imageProductFromDatabase); db.SaveChanges(); //tìm product theo id để xóa var productFromDatabase = db.Products.Find(_product.Product_Id); db.Products.Remove(productFromDatabase); db.SaveChanges();//cập nhật // cập nhật giao diện if (RefreshProductList != null) { RefreshProductList.Invoke(true); //tắt nút edit btnEditProduct.IsEnabled = false; //gán content = deleted và tắt nút false btnDeleteProduct.Content = "Deleted"; btnDeleteProduct.IsEnabled = false; } } catch { } }
/// <summary> /// Tìm xem khách hàng này có trong CSDL không /// </summary> private void customerPhoneTextBox_TextChanged(object sender, TextChangedEventArgs e) { var telCustomer = customerPhoneTextBox.Text; var db = new MyShopEntities(); customer = db.Customers.Find(telCustomer);//Tìm số điện thoại trong CSDL //Tìm thấy tên khách hàng theo số điện thoại if (customer != null) { CustomerNameTextBox.Text = customer.Fullname;//Lấy tên tương ướng với SDT } else { CustomerNameTextBox.Clear(); } }
public void UpdateProductView(MyShopEntities db, Category selectedCategory) { ICollection <Product> products = db.Categories.Find(selectedCategory.Category_Id).Products; var query = (from product in products where product.Quantity < quantity select new { product.Product_Id, ProductName = product.Product_Name, Thumbnail = product.Photos.First().Data, product.Price, product.Quantity }); var skip = (_pagingInfo.CurrentPage - 1) * _pagingInfo.RowsPerPage; var take = _pagingInfo.RowsPerPage; productsListView.ItemsSource = query.Skip(skip).Take(take); }
public void UpdateProductView(MyShopEntities db, Category selectedCategory) { ICollection <Product> products = db.Categories.Find(selectedCategory.Category_Id).Products; var keyword = searchTextBox.Text; var query = (from product in products where product.Product_Name.ToLower().Contains(keyword.ToLower()) && (product.Price >= minPrice && product.Price <= maxPrice) select new { product.Product_Id, ProductName = product.Product_Name, Thumbnail = product.Photos.First().Data, product.Price }); var skip = (_pagingInfo.CurrentPage - 1) * _pagingInfo.RowsPerPage; var take = _pagingInfo.RowsPerPage; productsListView.ItemsSource = query.Skip(skip).Take(take); }
public NewProductScreen() { InitializeComponent(); //Lấy và hiển thị danh sách sản phẩm Thread catThread = new Thread(delegate() { var db = new MyShopEntities(); var category = new ObservableCollection <Category>(db.Categories.ToList()); Dispatcher.Invoke(() => { producIDTextBox.Text = "Auto"; producIDTextBox.IsEnabled = false; ProductTypeComboxBox.ItemsSource = category; }); }); catThread.Start(); }
public CategoryScreen() { InitializeComponent(); // Get và hiển thị danh sách loại sản phẩm Thread getCategories = new Thread(delegate() { // Get và hiển thị danh sách loại sản phẩm var db = new MyShopEntities(); // ObservableCollection có implements INotifyCollectionChanged interface _categories = new ObservableCollection <Category>(db.Categories); // Đặt Item Source cho List View Dispatcher.Invoke(() => { listCategories.ItemsSource = _categories; progressBarLoadCategories.IsEnabled = false; progressBarLoadCategories.Visibility = Visibility.Hidden; }); }); getCategories.Start(); }
void UpdateProductView() { var db = new MyShopEntities(); var _selectedCategoryIndex = categoriesComboBox.SelectedItem as Category; var products = db.Categories.Find(_selectedCategoryIndex.Category_Id).Products; var query = from product in products where product.Quantity < quantity select new { product.Product_Id, ProductName = product.Product_Name, Thumbnail = product.Photos.First().Data, product.Price, product.Quantity }; // Gan du lieu cho list view de o cuoi cung // Dua theo trang hien tai var skip = (_pagingInfo.CurrentPage - 1) * _pagingInfo.RowsPerPage; var take = _pagingInfo.RowsPerPage; productsListView.ItemsSource = query.Skip(skip).Take(take); }
/// <summary> /// Làm mới thông tin /// </summary> public void refresh(bool Data) { var image = _product.Photos.First().Data; if (Data) // Nếu vừa sửa xong { // Lấy lại đối tượng mới var db = new MyShopEntities(); _product = db.Products.Find(_product.Product_Id); // Làm mới danh sách ở trang trước (delegate 2 cấp) if (RefreshProductList != null) { RefreshProductList.Invoke(true); } } // Đưa thông tin lên UI productNameTextBox.Text = _product.Product_Name; //producIDTextBox.Text = _product.Product_Id; productPriceTextbox.Text = _product.Price.ToString(); // editProductType.Text = product.ProductType; if (_product.Description != null) { productDescriptionTextBox.Text = _product.Description; } productQuantityTextbox.Text = _product.Quantity.ToString(); //image if (image != null) { imgProduct.Source = LoadImage(_product.Photos.First().Data); } producCategoryTextBox.Text = _product.Category.Category_Name; }
public void CalculatePagingInfo(MyShopEntities db, Category selectedCategory) { ICollection <Product> products = db.Categories.Find(selectedCategory.Category_Id).Products; var query = from product in products where product.Quantity < quantity select product; var count = query.Count(); // Tinh toan thong tin phan trang _pagingInfo = new PagingInfo() { RowsPerPage = rowsPerPage, TotalItems = count, TotalPages = count / rowsPerPage + (((count % rowsPerPage) == 0) ? 0 : 1), CurrentPage = 1 }; comboBoxPaging.ItemsSource = _pagingInfo.Pages; comboBoxPaging.SelectedIndex = 0; statusLabel.Content = $"Tổng sản phẩm: {count} "; }
private async void UserControl_Initialized(object sender, EventArgs e) { progressBar.IsIndeterminate = true; statusLabel.Content = "Application is ready"; _filterInfo = new FilterEntity() { Value = 8000000 }; var db = new MyShopEntities(); await Task.Run(() => { Thread.Sleep(2000); }); progressBar.IsIndeterminate = false; categoriesComboBox.ItemsSource = db.Categories.ToList(); categoriesComboBox.SelectedIndex = 0; filterPanel.DataContext = _filterInfo; }
/// <summary> /// Xóa một loại sản phẩm, nếu loại sản phẩm không có sản phẩm => Xóa /// nếu có sẽ hỏi người dùng xóa hay không /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnDeleteCategory_Click(object sender, RoutedEventArgs e) { if (btnDeleteCategory.Content.Equals("Cancel")) { // không cho phép chỉnh sửa các TextBox categoryIdTextBox.IsEnabled = false; categoryNameTextBox.IsEnabled = false; categoryDescriptionTextBox.IsEnabled = false; // Làm sạch các TextBox nếu vừa định Thêm mới if (btnUpdateCategory.Tag.Equals("Add")) { categoryIdTextBox.Clear(); categoryNameTextBox.Clear(); categoryDescriptionTextBox.Clear(); // Tắt luôn hai button Sửa và Xóa (nếu vừa định Sửa thì thôi) btnUpdateCategory.IsEnabled = false; btnDeleteCategory.IsEnabled = false; } // Reset dữ liệu cũ nếu vừa định Sửa else { // Lấy đối tượng ProductType tương ứng var productType = listCategories.SelectedItem as Category; categoryNameTextBox.Text = productType.Category_Name; //editProductTypeId.Text = productType.Id; categoryDescriptionTextBox.Text = productType.Description; } // Reset nội dung 2 button Sửa và Xóa btnUpdateCategory.Content = "Edit"; btnDeleteCategory.Content = "Delete"; btnAddCategory.IsEnabled = true; // Bật lại List View listCategories.IsEnabled = true; } else { // Hiện thông báo xác nhận var dialog = new Dialog() { Message = "Delete the selected category?" }; dialog.Owner = Window.GetWindow(this); if (dialog.ShowDialog() == false) { return; } // Lấy đối tượng từ List View var selectedItem = listCategories.SelectedItem as Category; // Tìm đối tượng tương ứng trong CSDL và xóa var db = new MyShopEntities(); try { var type = db.Categories.Where(x => x.Category_Id == selectedItem.Category_Id).FirstOrDefault(); db.Categories.Remove(type); db.SaveChanges(); // Cập nhật _categories.RemoveAt(listCategories.SelectedIndex); listCategories.ItemsSource = null; listCategories.ItemsSource = _categories; } catch (Exception ex) { // Nếu bắt ngoại lệ (khóa ngoại) tức đang có sản phẩm thuộc loại muốn xóa var showDialogError = new Dialog() { Message = "Product existence in Categories" + "\nDelete all?" }; showDialogError.Sounds(); showDialogError.Owner = Window.GetWindow(this); // Nếu user đồng ý, thì xóa hết sản phẩm tương ứng if (showDialogError.ShowDialog() == true) { //Trước tiên phải xóa image của sản phẩm ở bảng Photo db.Photos.RemoveRange(db.Photos.Where(x => x.Product.CatId == selectedItem.Category_Id).ToList()); // Tìm danh sách sản phẩm tương ứng sao đó RemoveRange db.Products.RemoveRange(db.Products.Where(x => x.CatId == selectedItem.Category_Id).ToList()); // Sau cùng mới xóa loại sản phẩm db.Categories.Remove(db.Categories.Where(x => x.Category_Id == selectedItem.Category_Id).FirstOrDefault()); // Cập nhật lên List View _categories.Remove(selectedItem); listCategories.ItemsSource = null; listCategories.ItemsSource = _categories; db.SaveChanges(); } else { return; } } // Xóa xong thì tắt 2 nút Sửa và Xóa + làm sạch TextBox btnUpdateCategory.IsEnabled = false; btnDeleteCategory.IsEnabled = false; categoryIdTextBox.Clear(); categoryNameTextBox.Clear(); categoryDescriptionTextBox.Clear(); // Cập nhật combobox ở trang trước, nếu là chọn category if (RefreshCategoriesList != null) { RefreshCategoriesList.Invoke(true); } } }
public CategoryDAO() { conn = dbConnection.getInstance(); }
public OrderProductDAO() { conn = dbConnection.getInstance(); }
public ClientDAO() { conn = dbConnection.getInstance(); }
public OrderStatusDAO() { conn = dbConnection.getInstance(); }