Пример #1
0
        private void button_constFees_add_Click(object sender, RoutedEventArgs e)
        {
            BoolHelper   bh  = new BoolHelper();
            ConstFeesAdd cfa = new ConstFeesAdd(Flats.ToList(), bh);
            ConstFees    cf  = new ConstFees();

            cfa.DataContext = cf;
            cfa.ShowDialog();

            if (bh.BoolHelp)
            {
                try
                {
                    dbContext.ConstFees.Add(cf);
                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            ConstFees = new ObservableCollection <ConstFees>(dbContext.ConstFees.ToList());
            dataGrid_constFees.ItemsSource = null;
            dataGrid_constFees.ItemsSource = ConstFees;
        }
Пример #2
0
        private void button_constFees_modify_Click(object sender, RoutedEventArgs e)
        {
            if (dataGrid_constFees.SelectedIndex == -1)
            {
                return;
            }

            BoolHelper   bh  = new BoolHelper();
            ConstFeesAdd cfa = new ConstFeesAdd(Flats.ToList(), bh);
            ConstFees    cf  = ConstFees[dataGrid_constFees.SelectedIndex];
            ConstFees    cfc = cf.ShallowCopy();

            cfa.DataContext = cf;

            cfa.ShowDialog();

            if (bh.BoolHelp)
            {
                try
                {
                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                cf = cfc.ShallowCopy();
                dbContext.ConstFees.AddOrUpdate(cf);
                dbContext.SaveChanges();
            }

            dataGrid_constFees.ItemsSource = null;
            dataGrid_constFees.ItemsSource = ConstFees;
        }