Ejemplo n.º 1
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            Potrawy recipe = new Potrawy();

            recipe.NazwaPotrawy  = NameTextBox.Text;
            recipe.Skladniki     = IngTextBox.Text;
            recipe.Przygotowanie = PrepTextBox.Text;

            try
            {
                using (var dbCtx = new KitchenEntities1())
                {
                    dbCtx.Entry(recipe).State = EntityState.Added;
                    dbCtx.SaveChanges();

                    Skladniki ingridient = new Skladniki();
                    string[]  ingr       = System.Text.RegularExpressions.Regex.Split(recipe.Skladniki, "\r\n");

                    ingridient.IdPotrawy = recipe.IdPotrawy;
                    foreach (string i in ingr)
                    {
                        ingridient.Skladnik           = i;
                        dbCtx.Entry(ingridient).State = EntityState.Added;
                        dbCtx.SaveChanges();
                    }
                }
                this.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Added failed");
            }
        }
Ejemplo n.º 2
0
        public EditWindow(Potrawy p, KitchenEntities1 dataEntities)
        {
            InitializeComponent();
            this.p           = p;
            NameTextBox.Text = p.NazwaPotrawy;
            IngTextBox.Text  = p.Skladniki;
            PrepTextBox.Text = p.Przygotowanie;
            IdLabel.Content  = "" + p.IdPotrawy;

            this.dataEntities = dataEntities;
        }
Ejemplo n.º 3
0
        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Potrawy recipeRow = new Potrawy();
                //int dataGridSelection = DataGrid.SelectedIndex + 1;
                //recipeRow.IdPotrawy = dataGridSelection;
                using (var dataEntities = new KitchenEntities1())
                {
                    var              original = dataEntities.Potrawy.Find(GetSelectedId());
                    string           msgtext  = "Do you really want to delete that row?";
                    string           txt      = "Deleting row";
                    MessageBoxButton button   = MessageBoxButton.YesNoCancel;
                    MessageBoxResult result   = MessageBox.Show(msgtext, txt, button);
                    switch (result)
                    {
                    case MessageBoxResult.Yes:
                        original.NazwaPotrawy  = "NULL";
                        original.Skladniki     = "NULL";
                        original.Przygotowanie = "NULL";

                        dataEntities.Entry(original).State = EntityState.Modified;
                        dataEntities.SaveChanges();

                        dataEntities.Database.ExecuteSqlCommand("DELETE FROM Skladniki WHERE IdPotrawy=" + original.IdPotrawy);

                        Window_Loaded(sender, e);
                        break;

                    case MessageBoxResult.No:
                        break;

                    case MessageBoxResult.Cancel:
                        break;
                    }
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
                return;
            }
        }
Ejemplo n.º 4
0
 private void EditButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         Potrawy recipeRow = new Potrawy();
         using (var dataEntities = new KitchenEntities1())
         {
             var original  = dataEntities.Potrawy.Find(GetSelectedId());
             var newWindow = new EditWindow(original, dataEntities);
             newWindow.ShowDialog();
         }
         Window_Loaded(sender, e);
     }
     catch (Exception Ex)
     {
         MessageBox.Show(Ex.Message);
         return;
     }
 }