private void purchaseDataGridViewCellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) return; if (e.ColumnIndex == 3) { IdPurchase = (int)(purchaseDataGridView[0, e.RowIndex].Value); ChekItemForm chekItemForm = new ChekItemForm(IdPurchase); chekItemForm.ShowDialog(this); } else if(e.ColumnIndex == 4) { var res = MessageBox.Show("Удалить?", "Удаление элемента", MessageBoxButtons.YesNo); if (res == DialogResult.No) return; else { IdPurchase = (int)(purchaseDataGridView[0, e.RowIndex].Value); using (var db = new Model.BudgetModel()) { var removePurchase = db.Purchases.Find(IdPurchase); var removeChekItems = db.Purchases.Find(IdPurchase).ChekItems.ToList(); foreach (var removeChekItem in removeChekItems) db.ChekItems.Remove(removeChekItem); db.Purchases.Remove(removePurchase); db.SaveChanges(); } } } UpdateDataGrid(); }
private void RenameToolStripMenuItemClick(object sender, EventArgs e) { using (var db = new Model.BudgetModel()) { var selectedItem = goodsItemListBox.SelectedItem as ListBoxItem; if (selectedItem == null) return; var selectedCategory = goodsItemComboBox.SelectedItem as ListBoxItem; var selectedGoodsItem = db.Goods.Find(selectedItem.Id); var selectedUnitOfMeasure = db.UnitOfMeasures.Find(selectedGoodsItem.UnitOfMeasure.Id); AddGoodsItemForm addGoodsForm = new AddGoodsItemForm( selectedCategory, selectedUnitOfMeasure, selectedGoodsItem.Name ); addGoodsForm.ShowDialog(this); if (string.IsNullOrWhiteSpace(addGoodsForm.Value)) return; else { selectedGoodsItem.Name = addGoodsForm.Value; selectedGoodsItem.Category = db.Categories.Find(addGoodsForm.SelectedCategory.Id); selectedGoodsItem.UnitOfMeasure = db.UnitOfMeasures.Find(addGoodsForm.SelectedUnitOfMeasure.Id); db.SaveChanges(); UpdateListBox(); } } }
private void purchaseButtonClick(object sender, EventArgs e) { using (var db = new Model.BudgetModel()) { var purchase = new Purchase(); purchase.DateTime = purchaseDateTimePicker.Value; var selectedSource = purchaseComboBox.SelectedItem as ListBoxItem; if (selectedSource == null) { MessageBox.Show("Выберите источник"); return; } purchase.Source = db.Sources.Find(selectedSource.Id); db.Purchases.Add(purchase); db.SaveChanges(); IdPurchase = purchase.Id; ChekItemForm chekItemForm = new ChekItemForm(IdPurchase); if (chekItemForm.ShowDialog(this) == DialogResult.OK) UpdateDataGrid(); else { db.Purchases.Remove(purchase); db.SaveChanges(); UpdateDataGrid(); } } }
private void RenameToolStripMenuItemClick(object sender, EventArgs e) { var selectedItem = unitOfMeasureListBox.SelectedItem as ComplexListBoxItem; if (selectedItem == null) return; using (var db = new Model.BudgetModel()) { var renameItem = db.UnitOfMeasures.Find(selectedItem.Id); AddItemForm addItemForm = new AddItemForm(selectedItem.Name); if (addItemForm.ShowDialog(this) == DialogResult.OK) if (string.IsNullOrWhiteSpace(addItemForm.Value)) { MessageBox.Show("Введите название"); return; } else { renameItem.Name = addItemForm.Value; addItemForm = new AddItemForm(selectedItem.ShortName); if (addItemForm.ShowDialog(this) == DialogResult.OK) if (string.IsNullOrWhiteSpace(addItemForm.Value)) { MessageBox.Show("Введите название"); return; } renameItem.ShortName = addItemForm.Value; db.SaveChanges(); } } UpdateListBox(); }
private void unitOfMeasureAddButtonClick(object sender, EventArgs e) { using (var db = new Model.BudgetModel()) { var unitOfMeasure = new UnitOfMeasure(); AddItemForm addItemForm = new AddItemForm("Введите полное название"); if (addItemForm.ShowDialog(this) == DialogResult.OK) if (string.IsNullOrWhiteSpace(addItemForm.Value) || addItemForm.Value == "Введите полное название") { MessageBox.Show("Введите название"); return; } else { unitOfMeasure.Name = addItemForm.Value; addItemForm = new AddItemForm("Введите сокращенное название"); if (addItemForm.ShowDialog(this) == DialogResult.OK) if (string.IsNullOrWhiteSpace(addItemForm.Value) || addItemForm.Value == "Введите сокращенное название") { MessageBox.Show("Введите название"); return; } else { unitOfMeasure.ShortName = addItemForm.Value; db.UnitOfMeasures.Add(unitOfMeasure); db.SaveChanges(); } } UpdateListBox(); } }
private void UpdateComboBoxCategory() { using (var db = new Model.BudgetModel()) { var categories = db.Categories.ToList(); foreach (var category in categories) { var item = new ListBoxItem(category.Id, category.Name); goodsItemComboBox.Items.Add(item); } } }
private void UpdateDataGrid() { purchaseDataGrid.ColumnWidth = DataGridLength.SizeToHeader; using (var db = new Model.BudgetModel()) { var purchases = db.Purchases.ToList(); foreach (var purchase in purchases) { if (purchase.ChekItems.ToList().Count == 0) db.Purchases.Remove(purchase); } db.SaveChanges(); purchaseDataGrid.ItemsSource = db.Purchases.Include("Source").ToList(); } }
private void UpdateListBox() { goodsItemListBox.Items.Clear(); using (var db = new Model.BudgetModel()) { var selectedCategory = goodsItemComboBox.SelectedItem as ListBoxItem; if (selectedCategory == null) return; var goods = db.Categories.Find(selectedCategory.Id).GoodsItems.ToList(); foreach (var goodsItem in goods) { var item = new ComplexListBoxItem(goodsItem.Id, goodsItem.Name, goodsItem.UnitOfMeasure.ShortName); goodsItemListBox.Items.Add(item); } } }
private void UpdateComboBox() { goodsComboBox.ItemsSource = null; goodsComboBox.Items.Clear(); using (var db = new Model.BudgetModel()) { var categories = db.Categories.ToList(); List<ListBoxItem> items = new List<ListBoxItem>(); foreach (var category in categories) { var item = new ListBoxItem(category.Id, category.Name); items.Add(item); } goodsComboBox.ItemsSource = items; } goodsComboBox.SelectedIndex = 1; }
private void UpdateComboBox() { purchaseCmbBox.ItemsSource = null; purchaseCmbBox.Items.Clear(); using (var db = new Model.BudgetModel()) { var sources = db.Sources.ToList(); List<ListBoxItem> items = new List<ListBoxItem>(); foreach (var source in sources) { var item = new ListBoxItem(source.Id, source.Name); items.Add(item); } purchaseCmbBox.ItemsSource = items; } purchaseDataTime.SelectedDate = DateTime.Today; }
private void DeleteToolStripMenuItemClick(object sender, EventArgs e) { var res = MessageBox.Show("Удалить?", "Удаление элемента", MessageBoxButtons.YesNo); if (res == DialogResult.No) return; else { var selectedItem = sourcesListBox.SelectedItem as ListBoxItem; if (selectedItem == null) return; using (var db = new Model.BudgetModel()) { var removeItem = db.Sources.Find(selectedItem.Id); db.Sources.Remove(removeItem); db.SaveChanges(); } } UpdateListBox(); }
private void RemoveMenuItemClick(object sender, RoutedEventArgs e) { var res = MessageBox.Show("Удалить?", "Удаление", MessageBoxButton.YesNo); if (res == MessageBoxResult.Yes) { using (var db = new Model.BudgetModel()) { var selectedItem = sourceLstBox.SelectedItem as ListBoxItem; if (selectedItem == null) return; var removeItem = db.Sources.Find(selectedItem.Id); db.Sources.Remove(removeItem); db.SaveChanges(); } UpdateListBox(); } else return; }
private void AddButtonClick(object sender, RoutedEventArgs e) { AddItemsWindow addItemsWindow = new AddItemsWindow(); addItemsWindow.ShowDialog(); using (var db = new Model.BudgetModel()) { var source = new Source(); if (string.IsNullOrWhiteSpace(addItemsWindow.Value)) MessageBox.Show("Введите название"); else { source.Name = addItemsWindow.Value; db.Sources.Add(source); db.SaveChanges(); UpdateListBox(); } } }
private void RenameMenuItemClick(object sender, RoutedEventArgs e) { using (var db = new Model.BudgetModel()) { var selectedItem = sourceLstBox.SelectedItem as ListBoxItem; if (selectedItem == null) return; AddItemsWindow addItemsWindow = new AddItemsWindow(selectedItem.Name); addItemsWindow.ShowDialog(); var renameItem = db.Sources.Find(selectedItem.Id); if (string.IsNullOrWhiteSpace(addItemsWindow.Value)) MessageBox.Show("Введите название"); else { renameItem.Name = addItemsWindow.Value; db.SaveChanges(); UpdateListBox(); } } }
private void FillForm() { using (var db = new Model.BudgetModel()) { var categories = db.Categories.ToList(); foreach (var category in categories) { var item = new ListBoxItem(category.Id, category.Name); addGoodsCategoryComboBox.Items.Add(item); } var unitOfMeasures = db.UnitOfMeasures.ToList(); foreach (var unitOfMeasure in unitOfMeasures) { var item = new ComplexListBoxItem(unitOfMeasure.Id, unitOfMeasure.Name, unitOfMeasure.ShortName); addGoodsUnitOfMeasureComboBox.Items.Add(item); } } }
private void UpdateListBox() { goodsLstBox.ItemsSource = null; goodsLstBox.Items.Clear(); using(var db = new Model.BudgetModel()) { var selectedCategory = goodsComboBox.SelectedItem as ListBoxItem; var goods = db.Categories.Find(selectedCategory.Id).GoodsItems.ToList(); List<ComplexListBoxItem> items = new List<ComplexListBoxItem>(); foreach (var goodsItem in goods) { var item = new ComplexListBoxItem(goodsItem.Id, goodsItem.Name, goodsItem.UnitOfMeasure.ShortName); items.Add(item); } goodsLstBox.ItemsSource = items; goodsLstBox.Items.SortDescriptions.Add(new System.ComponentModel.SortDescription("Name", System.ComponentModel.ListSortDirection.Ascending)); } }
private void AddButtonClick(object sender, RoutedEventArgs e) { var selectedItem = goodsComboBox.SelectedValue as ListBoxItem; AddGoodsWindow addGoodsWindow = new AddGoodsWindow(); if (selectedItem != null) addGoodsWindow = new AddGoodsWindow(selectedItem.Id); addGoodsWindow.ShowDialog(); if (string.IsNullOrWhiteSpace(addGoodsWindow.Value)) return; using (var db = new Model.BudgetModel()) { var goodsItem = new GoodsItem(); goodsItem.Name = addGoodsWindow.Value; goodsItem.Category = db.Categories.Find(addGoodsWindow.Category.Id); goodsItem.UnitOfMeasure = db.UnitOfMeasures.Find(addGoodsWindow.UnitOfMeasure.Id); db.Goods.Add(goodsItem); db.SaveChanges(); } UpdateListBox(); }
private void categoryAddButtonClick(object sender, EventArgs e) { AddItemForm addItemForm = new AddItemForm(); if(addItemForm.ShowDialog(this) == DialogResult.OK) { using (var db = new Model.BudgetModel()) { var category = new Category(); if (string.IsNullOrWhiteSpace(addItemForm.Value)) MessageBox.Show("Введите название"); else { category.Name = addItemForm.Value; db.Categories.Add(category); db.SaveChanges(); } } UpdateListBox(); } }
private void AddButtonClick(object sender, RoutedEventArgs e) { using (var db = new Model.BudgetModel()) { var purchase = new Purchase(); purchase.DateTime = purchaseDataTime.SelectedDate.Value; var selectedSource = purchaseCmbBox.SelectedItem as ListBoxItem; if (selectedSource == null) { MessageBox.Show("Выберите источник"); return; } purchase.Source = db.Sources.Find(selectedSource.Id); db.Purchases.Add(purchase); db.SaveChanges(); ChekItemWindow chekItemWindow = new ChekItemWindow(purchase.Id); chekItemWindow.ShowDialog(); } UpdateDataGrid(); }
private void goodsItemAddButtonClick(object sender, EventArgs e) { using (var db = new Model.BudgetModel()) { var selectedCategory = goodsItemComboBox.SelectedItem as ListBoxItem; AddGoodsItemForm addGoodsItemForm = new AddGoodsItemForm(); if (selectedCategory != null) addGoodsItemForm = new AddGoodsItemForm(selectedCategory); addGoodsItemForm.ShowDialog(this); var goods = new GoodsItem(); if (string.IsNullOrWhiteSpace(addGoodsItemForm.Value)) return; else { goods.Name = addGoodsItemForm.Value; goods.Category = db.Categories.Find(addGoodsItemForm.SelectedCategory.Id); goods.UnitOfMeasure = db.UnitOfMeasures.Find(addGoodsItemForm.SelectedUnitOfMeasure.Id); db.Goods.Add(goods); db.SaveChanges(); } } UpdateListBox(); }
private void sourceAddButtonClick(object sender, EventArgs e) { AddItemForm addItemForm = new AddItemForm(); if(addItemForm.ShowDialog(this) == DialogResult.OK) { using (var db = new Model.BudgetModel()) { var source = new Source(); if (string.IsNullOrWhiteSpace(addItemForm.Value)) MessageBox.Show("Введите название"); else { source.Name = addItemForm.Value; db.Sources.Add(source); try { db.SaveChanges(); } catch (DbUpdateException ex) { var sqlErrors = ex?.InnerException?.InnerException as SqlException; // 2601 - cannot insert duplicate key. if (sqlErrors.Number == 2601) { MessageBox.Show("Такое название уже существует."); } else { MessageBox.Show(ex.Message); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } UpdateListBox(); } }
private void RemoveButtonClick(object sender, RoutedEventArgs e) { var res = MessageBox.Show("Удалить?", "Удаление", MessageBoxButton.YesNo); if (res == MessageBoxResult.No) return; using (var db = new Model.BudgetModel()) { Purchase purchase = purchaseDataGrid.SelectedItem as Purchase; db.Purchases.Remove(db.Purchases.Find(purchase.Id)); db.SaveChanges(); UpdateDataGrid(); } }
private void RenameButtonClick(object sender, RoutedEventArgs e) { using (var db = new Model.BudgetModel()) { Purchase purchase = purchaseDataGrid.SelectedItem as Purchase; ChekItemWindow chekItemWindow = new ChekItemWindow(purchase.Id); chekItemWindow.ShowDialog(); } UpdateDataGrid(); }
private void UpdateListBox() { sourcesListBox.Items.Clear(); using (var db = new Model.BudgetModel()) { var sources = db.Sources.ToList(); foreach (var source in sources) { var item = new ListBoxItem(source.Id, source.Name); sourcesListBox.Items.Add(item); } } }
private void SaveButClick(object sender, RoutedEventArgs e) { using (var db = new Model.BudgetModel()) { Purchase purchase = purchaseDataGrid.SelectedItem as Purchase; var selectedPurchase = db.Purchases.Find(purchase.Id); selectedPurchase.DateTime = purchaseDataTime.SelectedDate.Value; var selectedSource = purchaseCmbBox.SelectedItem as ListBoxItem; selectedPurchase.Source = db.Sources.Find(selectedSource.Id); db.SaveChanges(); UpdateDataGrid(); saveBut.IsEnabled = false; addButton.IsEnabled = true; purchaseDataGrid.IsEnabled = true; } }
private void ChangeButtonClick(object sender, RoutedEventArgs e) { addButton.Visibility = Visibility.Hidden; cancelButton.Visibility = Visibility.Visible; saveBut.IsEnabled = true; using (var db = new Model.BudgetModel()) { Purchase purchase = purchaseDataGrid.SelectedItem as Purchase; purchaseDataGrid.IsEnabled = false; purchaseDataTime.SelectedDate = purchase.DateTime; for (int i = 0; i < purchaseCmbBox.Items.Count; i++) { var item = purchaseCmbBox.Items[i] as ListBoxItem; if (item.Id == purchase.Source.Id) { purchaseCmbBox.SelectedIndex = i; return; } } } }
private void RenameMenuItemClick(object sender, RoutedEventArgs e) { var selectedItem = goodsLstBox.SelectedValue as ListBoxItem; var selectedCategory = goodsComboBox.SelectedValue as ListBoxItem; if (selectedItem == null) return; using (var db = new Model.BudgetModel()) { var goodsItem = db.Goods.Find(selectedItem.Id); AddGoodsWindow addGoodsItem = new AddGoodsWindow( goodsItem.Category.Id, goodsItem.UnitOfMeasure.Id, goodsItem.Name ); addGoodsItem.ShowDialog(); if (addGoodsItem.Category == null || addGoodsItem.UnitOfMeasure == null || string.IsNullOrWhiteSpace(addGoodsItem.Value)) return; goodsItem.Name = addGoodsItem.Value; goodsItem.Category = db.Categories.Find(addGoodsItem.Category.Id); goodsItem.UnitOfMeasure = db.UnitOfMeasures.Find(addGoodsItem.UnitOfMeasure.Id); db.SaveChanges(); UpdateListBox(); } }
private void UpdateComboBoxs() { categoryCmbBox.ItemsSource = null; categoryCmbBox.Items.Clear(); using (var db = new Model.BudgetModel()) { var categories = db.Categories.ToList(); List<ListBoxItem> items = new List<ListBoxItem>(); foreach (var category in categories) { var item = new ListBoxItem(category.Id, category.Name); items.Add(item); } categoryCmbBox.ItemsSource = items; } unitOfMeasureCmbBox.ItemsSource = null; unitOfMeasureCmbBox.Items.Clear(); using (var db = new Model.BudgetModel()) { var unitOFMeasures = db.UnitOfMeasures.ToList(); List <ComplexListBoxItem>items = new List<ComplexListBoxItem>(); foreach (var unitOFMeasure in unitOFMeasures) { var item = new ComplexListBoxItem(unitOFMeasure.Id, unitOFMeasure.Name, unitOFMeasure.ShortName); items.Add(item); } unitOfMeasureCmbBox.ItemsSource = items; } }
private void UpdateDataGrid() { purchaseDataGridView.Rows.Clear(); using (var db = new Model.BudgetModel()) { var purchases = db.Purchases.ToList(); var renameButton = new DataGridViewButtonCell(); var removeButton = new DataGridViewButtonCell(); foreach (var purchase in purchases) { var chekItems = db.Purchases.Find(purchase.Id).ChekItems.ToList(); if (chekItems.Count == 0) { db.Purchases.Remove(purchase); db.SaveChanges(); } else purchaseDataGridView.Rows.Add( purchase.Id, purchase.DateTime, purchase.Source.Name, renameButton, removeButton ); } } }
private void UpdateComboBox() { using (var db = new Model.BudgetModel()) { var sources = db.Sources.ToList(); foreach(var source in sources) { var item = new ListBoxItem(source.Id, source.Name); purchaseComboBox.Items.Add(item); } purchaseComboBox.Text = "Выберите источник"; } }