예제 #1
0
 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();
 }
예제 #2
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();
 }