Exemplo n.º 1
0
 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();
 }
Exemplo n.º 2
0
 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();
         }
     }
 }