Exemplo n.º 1
0
        //modify one citizen
        private void CitizenModifyClick(object sender, RoutedEventArgs e)
        {
            DataManager ins = DataManager.createInstance();
            Citizen c = (Citizen)this.CitizenList.SelectedItem;
            if (c == null)
            {
                System.Windows.MessageBox.Show("请选择后再修改", "提示", System.Windows.MessageBoxButton.OK);
                return;
            }

            addCitizen cw = new addCitizen(true, c);
            cw.Owner = this;

            if (cw.ShowDialog() ?? false)
            {
                ObservableCollection<Citizen> cns = (ObservableCollection<Citizen>)this.CitizenList.ItemsSource;
                int index = cns.IndexOf(c);
                cns.Remove(c);

                c = (Citizen)cw.ModifyC;
                cns.Insert(index, c);
                //this.CitizenList.ItemsSource
            }
        }
Exemplo n.º 2
0
        //add one citizen
        private void CitizenAddClick(object sender, RoutedEventArgs e)
        {
            addCitizen cw = new addCitizen(false, new Citizen());
            cw.Owner = this;

            if (cw.ShowDialog() ?? false)
            {
                ObservableCollection<Citizen> cns = (ObservableCollection<Citizen>)this.CitizenList.ItemsSource;

                if (cns == null)
                {
                    cns = new ObservableCollection<Citizen>();
                }

                Citizen c = (Citizen)cw.ModifyC;
                cns.Add(c);
                this.CitizenList.ItemsSource = cns;
            }
        }