コード例 #1
0
        //when the register button is clicked
        private void RegisterButton_Click(object sender, RoutedEventArgs e)
        {
            if (RadioMale.IsChecked == false && RadioFemale.IsChecked == false && mode != "Edit")
            {
                MessageBox.Show("You have not selected a sex");
            }
            else if (RegisterNameInput.Text == "")
            {
                MessageBox.Show("You have not entered a name");
            }
            else if (RegisterWeightInput.Text == "")
            {
                MessageBox.Show("You have not entered a weight");
            }
            else
            {
                if (mode == "Edit") //this is where the database update function will be used
                {
                    weight = Convert.ToDouble(this.RegisterWeightInput.Text);
                    name = Convert.ToString(this.RegisterNameInput.Text);

                    var personname = from personTable in App._appViewModel.person
                                     where personTable.personID == tempPersonID
                                     select personTable;

                    App._appViewModel.UpdatePerson(tempPersonID, name, weight);
                }
                else
                {
                    weight = Convert.ToDouble(this.RegisterWeightInput.Text);
                    if (RadioMale.IsChecked == true)
                        sex = "Male";
                    else if (RadioFemale.IsChecked == true)
                        sex = "Female";

                    PersonData newPerson = new PersonData
                    {
                        personName = this.RegisterNameInput.Text,
                        personWeight = weight,
                        personSex = sex,
                        personID = tempPersonID

                    };

                    App._appViewModel.AddPerson(newPerson); //adds a new person to the database
                }
                this.NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            }
        }
コード例 #2
0
        //add a new person
        public void AddPerson(PersonData newPerson)
        {
            person.Add(newPerson);

            personDB.PersonDataTable.InsertOnSubmit(newPerson);
        }