示例#1
0
        private void btnSaveOwner_Click(object sender, EventArgs e)
        {
            lblOwnerID.Text = null;
            //Create a new row that the variables will be added into
            DataRow newOwnerRow = DM.dtOwner.NewRow();

            //If any of the text areas are empty then do not write data and return
            if ((txtAddLastName.Text == "") || (txtAddFirstName.Text == "") ||
                (txtAddStreetAddress.Text == "") || (txtAddSuburb.Text == "") || (txtAddPhoneNumber.Text == ""))
            {
                MessageBox.Show("You must enter a value for each of the text fields.", "Error");
            }
            else
            {
                newOwnerRow["LastName"]      = txtAddLastName.Text;
                newOwnerRow["FirstName"]     = txtAddFirstName.Text;
                newOwnerRow["StreetAddress"] = txtAddStreetAddress.Text;
                newOwnerRow["Suburb"]        = txtAddSuburb.Text;
                newOwnerRow["PhoneNumber"]   = txtAddPhoneNumber.Text;

                //Add the new row to the Table
                DM.dtOwner.Rows.Add(newOwnerRow);
                DM.UpdateOwner();
                //Give the user a success message
                MessageBox.Show("Owner added successfully.", "Success");
            }
            return;
        }
        private void btnSaveChanges_Click(object sender, EventArgs e)
        {
            DataRow updateOwnerRow = DM.dtOwner.Rows[currencyManager.Position];

            if ((txtUpdateLastName.Text == "") || (txtUpdateFirstName.Text == "") || (txtUpdateStreetAddress.Text == "") || (txtUpdateSuburb.Text == "") || (txtUpdatePhoneNumber.Text == ""))
            {
                MessageBox.Show("You must type a valid Last Name, First Name, Street Address, Suburb and Phone Number", "Error");
                return;
            }
            else
            {
                updateOwnerRow["LastName"]      = txtUpdateLastName.Text;
                updateOwnerRow["FirstName"]     = txtUpdateFirstName.Text;
                updateOwnerRow["StreetAddress"] = txtUpdateStreetAddress.Text;
                updateOwnerRow["Suburb"]        = txtUpdateSuburb.Text;
                updateOwnerRow["PhoneNumber"]   = txtUpdatePhoneNumber.Text;
                currencyManager.EndCurrentEdit();
                DM.UpdateOwner();
                MessageBox.Show("Owner updated successfully", "Success");
                return;
            }
        }