Esempio n. 1
0
        private void miUpdate_Click(object sender, RoutedEventArgs e)
        {
            if (lstViewCar.SelectedItems.Count != 1)
            {
                MessageBox.Show("Please choose one item to update", "Information");
                return;
            }

            try
            {
                int           index         = lstViewCar.SelectedIndex;
                AddEditDialog addEditDialog = new AddEditDialog((Car)lstViewCar.SelectedItem);
                addEditDialog.Owner = this;

                addEditDialog.AddNewCarCallback += (m, en, f) => { model = m; engine = en; fuel = f; };
                bool?result = addEditDialog.ShowDialog();   // this line must be stay after the assignment, otherwise value is not assigned

                if (result == true)
                {
                    carList.ElementAt(index).MakeModel  = model;
                    carList.ElementAt(index).EngineSize = engine;
                    carList.ElementAt(index).FuelType   = fuel;
                }
            }
            catch (DataInvalidException ex)
            {
                MessageBox.Show(ex.Message, "Error Information");
            }
        }
Esempio n. 2
0
        private void CommandBinding_AddNewCar(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                AddEditDialog addEditDialog = new AddEditDialog(null);
                addEditDialog.Owner = this;

                addEditDialog.AddNewCarCallback += (m, en, f) => { model = m; engine = en; fuel = f; };
                bool?result = addEditDialog.ShowDialog();   // this line must be stay after the assignment, otherwise value is not assigned

                if (result == true)
                {
                    carList.Add(new Car(model, engine, fuel));
                }
            }
            catch (DataInvalidException ex)
            {
                MessageBox.Show(ex.Message, "Error Information");
            }
            lstViewCar.SelectedIndex = lstViewCar.Items.Count - 1;//for status bar selection change
        }