Задание
Цель работы - разработать систему учета товаров на складе
Функционал программы
Функционал:
- Создание поставщиков
- Добавление товаров на склад, секцию
- Поиск товара по складу, секции, описанию товара
- Изменение товара (склад, секция, описание товара)
- Удаление товара
Использованные технологии:
- C# + WPF;
- Entity Framework
Фрагмент программного кода
private ApplicationDbContexts Dbcontext { get; set; } private BaseFormWindows BaseFormWindow { get; set; } private ProductServices ProductServices { get; set; } public Users User { get; set; } private delegate void DelGridStorageProduct_MouseUpFocus(object sender, MouseButtonEventArgs e); private event DelGridStorageProduct_MouseUpFocus DelGridStorageProductUpdate_MouseUp; public StorageSectionWindow(Users User, int StorageId) { InitializeComponent(); Dbcontext = new ApplicationDbContexts(); BaseFormWindow = new BaseFormWindows(); ProductServices = new ProductServices(); this.User = User; DelGridStorageProductUpdate_MouseUp -= GridStorageProductUpdate_MouseUpFocus; TextNameOrg.Content = User.Employees.Organization.Name; TextInn.Content = User.Employees.Organization.Inn; TextKpp.Content = User.Employees.Organization.KPP; EmpName.Content = User.Employees.Name; EmpMiddleName.Content = User.Employees.MiddleName; EmpLastName.Content = User.Employees.LastName; BoxName.Content = "Номер склада " + StorageId.ToString(); Dbcontext.StorageSections.Where(t => t.StorageId == StorageId).ToList(); // загружаем данные GridStorageSection.ItemsSource = Dbcontext.StorageSections.Local.ToBindingList(); // устанавливаем привязку к кэшу } private void Button_Click(object sender, RoutedEventArgs e) => Close(); private void GridStorage_SelectionChanged(object sender, SelectionChangedEventArgs e) { } private void GridStorage_MouseUp(object sender, MouseButtonEventArgs e) { DataGrid data = (DataGrid)sender; var cell = data.SelectedCells; if (cell.Count != 0) { var CelllStorageNumber = data.SelectedCells[0]; // Получаем итем var Namber = (CelllStorageNumber.Column.GetCellContent(CelllStorageNumber.Item) as TextBlock).Text; //Содержимое итема SearchSection.Text = Namber; Section_Load(int.Parse(Namber)); } else { MessageBox.Show("Позиция не выбрана"); } } private void Section_Load(int Namber) { var product = from products in Dbcontext.Products join section in Dbcontext.StorageSections on products.StorageSectionId equals section.Id join suppliers in Dbcontext.Suppliers on products.SupplierId equals suppliers.Id where section.Id == Namber select new { suppliers.FullName, products.Id, section.NameNumber, products.Name, products.Count, products.UnitOfMeasurement, products.Price, }; GridStorageProduct.ItemsSource = product.ToList(); // устанавливаем привязку к кэшу SelectProduct.Text = ""; DelGridStorageProductUpdate_MouseUp -= GridStorageProductUpdate_MouseUpFocus; } private void AddProducn_Click(object sender, RoutedEventArgs e) { CreateProduct CreateProduct = new CreateProduct(User); CreateProduct.Show(); } private void Button_Click_1(object sender, RoutedEventArgs e) { } private void Button_Click_2(object sender, RoutedEventArgs e) { var product = from products in Dbcontext.Products join section in Dbcontext.StorageSections on products.StorageSectionId equals section.Id join suppliers in Dbcontext.Suppliers on products.SupplierId equals suppliers.Id where section.Id == int.Parse(SearchSection.Text) select new { suppliers.FullName, products.Id, section.NameNumber, products.Name, products.Count, products.UnitOfMeasurement, products.Price, }; GridStorageProduct.ItemsSource = product.ToList(); // устанавливаем привязку к кэшу } private void Button_Click_3(object sender, RoutedEventArgs e) { if (SearchSection.Text != null) { SectionSupplierPorduct_Load(int.Parse(SearchSection.Text), SearchSupplier.Text, SearchProduct.Text, SearchPrice.Text); } else { MessageBox.Show("Секция не выбрана"); } } private void SectionSupplierPorduct_Load(int SectionNumber, string SearchSupplier, string SearchProduct,string SearchPrice) { var product = from products in Dbcontext.Products join section in Dbcontext.StorageSections on products.StorageSectionId equals section.Id join suppliers in Dbcontext.Suppliers on products.SupplierId equals suppliers.Id where section.Id == SectionNumber && (suppliers.Name.Contains(SearchSupplier) && products.Name.Contains(SearchProduct) && products.Price.ToString().Contains(SearchPrice)) select new { suppliers.FullName, products.Id, section.NameNumber, products.Name, products.Count, products.UnitOfMeasurement, products.Price }; GridStorageProduct.ItemsSource = product.ToList(); // устанавливаем привязку к кэшу } private void GridStorageProduct_MouseUp(object sender, MouseButtonEventArgs e) { DataGrid data = (DataGrid)sender; var cell = data.SelectedCells; if (cell.Count != 0) { var CelllSectionNumber = data.SelectedCells[1]; // Получаем итем var Namber = (CelllSectionNumber.Column.GetCellContent(CelllSectionNumber.Item) as TextBlock).Text; //Содержимое итема SelectProduct.Text = Namber; DelGridStorageProductUpdate_MouseUp -= GridStorageProductUpdate_MouseUpFocus; DelGridStorageProductUpdate_MouseUp += GridStorageProductUpdate_MouseUpFocus; if (DelGridStorageProductUpdate_MouseUp != null) { DelGridStorageProductUpdate_MouseUp.Invoke(this, e); } } else { MessageBox.Show("Позиция не выбрана"); } }
Скриншот архива с проектом
Пояснения по запуску программы
При первом запуске программы будет создаватся один раз база данных без содержания данных. В классе ApplicationDbContexts находится закомментированные sql запросы для добавления первоначальных данных.
IndexHome123