예제 #1
0
        private void uxInsertButton_Click(object sender, EventArgs e)
        {
            repo = new SqlPersonRepository("Data Source = mssql.cs.ksu.edu; " +
                                           "Initial Catalog=phyo;" +
                                           "User id=username;" +
                                           "Password=password;");

            string name = uxPersonName.Text;
            string DOB  = dateTimePicker1.Value.Date.ToString("yyyy-MM-dd ");

            string death;

            if (uxDeathCheckBox.Checked)
            {
                death = dateTimePicker2.Value.Date.ToString("yyyy-MM-dd");
            }
            else
            {
                death = "NULL";
            }

            if (uxInsertButton.Text == "Insert")
            {
                try
                {
                    var createdPerson = repo.CeatePerson(name, DOB, death);
                    MessageBox.Show("The data has been successfully added.");
                }
                catch (Exception exception)
                {
                    MessageBox.Show("Data failed to be inserted." + exception);
                }
            }
            else
            {
                var updatePerson = repo.UpdatePerson(PersonId, name, DOB, death);
                MessageBox.Show("The data has been successfully updated.");
            }



            //Show all people
            dataGridView1.DataSource = repo.RetrievePersons();
        }