コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: KNMentor/MediaCalc
        private void button_users_add_Click(object sender, RoutedEventArgs e)
        {
            BoolHelper bh  = new BoolHelper();
            UserAdd    cfa = new UserAdd(bh);
            User       cf  = new User();

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

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

            Users = new ObservableCollection <User>(dbContext.Users.ToList());
            dataGrid_users.ItemsSource = null;
            dataGrid_users.ItemsSource = Users;
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: KNMentor/MediaCalc
        private void button_users_modify_Click(object sender, RoutedEventArgs e)
        {
            if (dataGrid_users.SelectedIndex == -1)
            {
                return;
            }

            BoolHelper bh  = new BoolHelper();
            UserAdd    cfa = new UserAdd(bh);
            User       cf  = Users[dataGrid_users.SelectedIndex];
            User       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.Users.AddOrUpdate(cf);
                dbContext.SaveChanges();
            }

            dataGrid_users.ItemsSource = null;
            dataGrid_users.ItemsSource = Users;
        }