Esempio n. 1
0
        private void button_flats_add_Click(object sender, RoutedEventArgs e)
        {
            BoolHelper bh = new BoolHelper();
            FlatAdd    la = new FlatAdd(bh);
            Flat       l  = new Flat();

            la.DataContext = l;
            la.ShowDialog();

            if (bh.BoolHelp)
            {
                try
                {
                    dbContext.Flats.Add(l);
                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            Flats = new ObservableCollection <Flat>(dbContext.Flats.ToList());
            dataGrid_flats.ItemsSource = null;
            dataGrid_flats.ItemsSource = Flats;
        }
Esempio n. 2
0
        private void button_flats_modify_Click(object sender, RoutedEventArgs e)
        {
            if (dataGrid_flats.SelectedIndex == -1)
            {
                return;
            }

            BoolHelper bh  = new BoolHelper();
            FlatAdd    la  = new FlatAdd(bh);
            Flat       l   = Flats[dataGrid_flats.SelectedIndex];
            Flat       lcf = l.ShallowCopy();

            la.DataContext = l;

            la.ShowDialog();

            if (bh.BoolHelp)
            {
                try
                {
                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                l = lcf.ShallowCopy();
                dbContext.Flats.AddOrUpdate(l);
                dbContext.SaveChanges();
            }

            dataGrid_flats.ItemsSource = null;
            dataGrid_flats.ItemsSource = Flats;
        }