コード例 #1
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                ContactsBL contactsBL = new ContactsBL();
                int        id         = int.Parse(ddlContacts.SelectedValue);
                if (contactsBL.DeleteContact(id) == true)
                {
                    PopulateDDL();
                    ClearForm();
                    lblMessage.Text = "Contact deletion successful";
                }
                else
                {
                    lblMessage.Text = "Contact deletion failed";

                    foreach (ValidationError ve in contactsBL.ValidationErrors)
                    {
                        lblMessage.Text = ve.Description.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
            }
        }
コード例 #2
0
    protected void ContactDataView_CustomCallback(object sender, CallbackEventArgsBase e)
    {
        if (string.IsNullOrEmpty(e.Parameter))
        {
            return;
        }
        var args = e.Parameter.Split('|');

        if (args[0] == "Delete" && args.Length == 2)
        {
            int id;
            if (!int.TryParse(args[1], out id))
            {
                return;
            }
            ContactsBL bl = new ContactsBL();
            bl.DeleteContact(id);
            BindDataView();
        }
        if (args[0] == "SaveContact")
        {
            var name     = ContactNameEditor.Text;
            var email    = ContactEmailEditor.Text;
            var address  = ContactAddressEditor.Text;
            var country  = ContactCountryEditor.Text;
            var city     = ContactCityEditor.Text;
            var phone    = ContactPhoneEditor.Text;
            var photoUrl = Utils.GetUploadedPhotoUrl(args[2]);
            int id;
            if (args.Length == 4 && args[1] == "Edit" && int.TryParse(args[3], out id))
            {
                ContactsBL bl = new ContactsBL();
                bl.UpdateContact(id, name, email, address, country, city, phone, photoUrl);
            }
            else if (args.Length == 3 && args[1] == "New")
            {
                ContactsBL bl = new ContactsBL();
                bl.AddContact(name, email, address, country, city, photoUrl, photoUrl);
            }

            BindDataView();
        }
    }
コード例 #3
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         ContactsBL contactsBL = new ContactsBL();
         int        id         = int.Parse(txtContactID.Text);
         if (contactsBL.DeleteContact(id) == true)
         {
             PopulateDGV();
             ClearForm();
             MessageBox.Show("Contact deletion successful");
         }
         else
         {
             MessageBox.Show("Contact deletion failed");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }