コード例 #1
0
 private void AddButton_Click(object sender, RoutedEventArgs e)
 {
     using (MyDBContext db = new MyDBContext())
     {
         if (!String.IsNullOrWhiteSpace(NameBox.Text) &&
             !String.IsNullOrWhiteSpace(DescrBox.Text))
         {
             Dish_type dish_Type = new Dish_type
             {
                 ID          = db.Dish_Types.Count() + 1,
                 Name        = NameBox.Text,
                 Description = DescrBox.Text
             };
             if (EditID == -1)
             {
                 db.Dish_Types.Add(dish_Type);
             }
             else
             {
                 var result = db.Dish_Types.Find(EditID);
                 result.Name        = NameBox.Text;
                 result.Description = DescrBox.Text;
             }
         }
         else
         {
             MessageBox.Show("Заполнены не все поля");
         }
         db.SaveChanges();
         this.Close();
     }
 }
コード例 #2
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     using (MyDBContext db = new MyDBContext())
     {
         Dish_type EditType = db.Dish_Types.Find(this.EditID);
         if (EditID != -1)
         {
             AddButton.Content = "Сохранить";
             NameBox.Text      = EditType.Name;
             DescrBox.Text     = EditType.Description;
         }
     }
 }