예제 #1
0
파일: GoodsForm.cs 프로젝트: nburd/economy
 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();
 }
예제 #2
0
파일: GoodsForm.cs 프로젝트: nburd/economy
 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();
         }
     }
 }