示例#1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (txtSiteName.Text.Equals("") || txtURL.Text.Equals(""))
            {
                MessageBox.Show("You must specify values for both Site anem and URL", "Add Site");
            }
            else
            {
                // Create a new SiteRow object
                websitesDataSet.SiteRow newSite = websitesDataSet.Site.NewSiteRow();

                // Set field values for this new site
                newSite.SiteName   = txtSiteName.Text;
                newSite.URL        = txtURL.Text;
                newSite.CategoryID = Convert.ToInt32(categoryNameComboBox.SelectedValue);

                // Add the row to the database
                websitesDataSet.Site.AddSiteRow(newSite);

                // Update the siteTableAdapter object
                siteTableAdapter.Update(newSite);
                MessageBox.Show(txtSiteName.Text + " site added to " + categoryNameComboBox.Text + " category.", "Add Site");
                Close();
            }
        }
        private void btnRemoveSite_Click(object sender, EventArgs e)
        {
            DialogResult answer = MessageBox.Show("You are about to delete the " +
                                                  siteNameListBox.Text + " site.  OK?",
                                                  "Delete Site", MessageBoxButtons.OKCancel);

            if (answer == DialogResult.Cancel)
            {
                MessageBox.Show("Nothing deleted", "Delete Site");
            }
            else
            {
                // Store site name for use in the message box later
                String delName = siteNameListBox.Text;

                // Store SiteID for cleaner code
                int oldSiteID = Convert.ToInt32(siteNameListBox.SelectedValue);

                // Delete the Site
                // Search for the record by SiteID and assign this record to a SiteRow object
                websitesDataSet.SiteRow delSite = websitesDataSet.Site.FindBySiteID(oldSiteID);

                delSite.Delete();
                siteTableAdapter.Update(delSite);

                FilterData();

                MessageBox.Show(delName + " site deleted", "Delete Site");
            }
        }