コード例 #1
0
        private void ButtonEdit_Click(object sender, RoutedEventArgs e)
        {
            GetAll_CountryCodes_Record selected_record = dataGrid.SelectedItem as GetAll_CountryCodes_Record;

            if (selected_record == null)
            {
                return;
            }

            EditCountryViewModel edit_model = new EditCountryViewModel
            {
                Mode          = EditCountryViewModel.ModelMode.Edit,
                CountryCodeID = selected_record.CountryCodeID
            };

            EditCountryWindow window = new EditCountryWindow(edit_model);

            window.Owner = this;
            window.ShowDialog();

            if (window.DialogResult == false)
            {
                return;
            }

            // Refresh the country name is the DataGrid.
            selected_record.Name = edit_model.Name;
        }
コード例 #2
0
        public EditCountryWindow(EditCountryViewModel view_model)
        {
            ViewModel = view_model;

            InitializeComponent();

            if (ViewModel.Mode == EditCountryViewModel.ModelMode.Edit)
            {
                PriKey_CountryCodes_Recordset prikey = new PriKey_CountryCodes_Recordset();

                prikey.ExecSql(ViewModel.CountryCodeID);

                if (prikey.RecordCount != 1)
                {
                    throw new Exception($"Country {ViewModel.CountryCodeID} not found.");
                }

                ViewModel.CountryCodeID = prikey.CountryCodeID;
                ViewModel.Name          = prikey.Name;

                textblockTitle.Text  = $"Edit country {prikey.CountryCodeID}";
                textboxID.IsReadOnly = true; // you cannot edit a primary key code
            }
            else // new
            {
                ViewModel.CountryCodeID = "";
                ViewModel.Name          = "";

                textblockTitle.Text = "New country";
            }
        }
コード例 #3
0
        private void ButtonNew_Click(object sender, RoutedEventArgs e)
        {
            EditCountryViewModel edit_model = new EditCountryViewModel
            {
                Mode = EditCountryViewModel.ModelMode.New
            };

            EditCountryWindow window = new EditCountryWindow(edit_model);

            window.Owner = this;
            window.ShowDialog();

            if (window.DialogResult == false)
            {
                return;
            }

            // Add the new country code to the DataGrid. This is just to give visual feedback to
            // the user. The changes to the recordset will not be send to the database by calling SaveChanges()
            var grid_record = ViewModel.CountriesRS.NewRecord();

            grid_record.CountryCodeID = edit_model.CountryCodeID;
            grid_record.Name          = edit_model.Name;

            ViewModel.CountriesRS.Append(grid_record);

            dataGrid.SelectedItem = grid_record;
            dataGrid.ScrollIntoView(grid_record);
        }