protected void btnDeleteAddress_Click(object sender, ImageClickEventArgs e) { ArenaImageButton button = (ArenaImageButton)sender; PersonAddress pa; Person person; int personID, addressType; // // Grab the information from the ID that we will use later. // personID = Convert.ToInt32(button.ID.Split(new char[] { '_' })[1]); addressType = Convert.ToInt32(button.ID.Split(new char[] { '_' })[3]); // // Find the person and address record and remove it. // person = new Person(personID); pa = person.Addresses.FindByType(addressType); person.Addresses.Remove(pa); person.SaveAddresses(person.OrganizationID, CurrentUser.Identity.Name); LoadFamilyAddresses(family_id); }
private void LoadFamilyAddresses(int family_id) { Family family = new Family(family_id); // // Make sure we are in a known valid state. // while (tblPeople.Rows.Count > 2) { tblPeople.Rows.RemoveAt(1); } foreach (FamilyMember fm in family.FamilyMembers) { PersonAddressCollection pac = new PersonAddressCollection(); bool first = true; TableRow row = null; TableCell cell = null; Literal lt; // // Sort addresses by primary and then all the rest (in order of lookup), I don't // know a better way to do this. // foreach (PersonAddress address in fm.Addresses) { if (address.Primary) { pac.Add(address); } } foreach (PersonAddress address in fm.Addresses) { if (!address.Primary) { pac.Add(address); } } if (pac.Count == 0) { pac.Add(new PersonAddress()); } foreach (PersonAddress address in pac) { ArenaCheckBox cb; row = new TableRow(); tblPeople.Rows.AddAt(tblPeople.Rows.Count - 1, row); // // Add in the checkbox + name if applicable. // cell = new TableCell(); row.Cells.Add(cell); if (first == true) { cb = new ArenaCheckBox(); cell.Controls.Add(cb); cb.ID = "cbPerson_" + fm.PersonID.ToString(); cb.Text = fm.NickName; cb.CssClass = "personName"; if (fm.RecordStatus == Arena.Enums.RecordStatus.Inactive) { cb.Text += " (Inactive)"; row.CssClass += " inactive"; } else if (fm.RecordStatus == Arena.Enums.RecordStatus.Pending) { cb.Text += " (Pending)"; row.CssClass += " pending"; } cb.Checked = false; } first = false; if (address.AddressID != -1) { // // Add in the address type. // cell = new TableCell(); row.Cells.Add(cell); DropDownList ddlType = new DropDownList(); cell.Controls.Add(ddlType); ddlType.ID = "ddlType_" + fm.PersonID.ToString() + "_" + address.AddressID.ToString() + "_" + address.AddressType.LookupID.ToString(); foreach (Lookup lookup in new LookupType(new Guid("9B4BE12C-C105-4F80-8254-8639B27D7640")).Values) { ddlType.Items.Add(new ListItem(lookup.Value, lookup.LookupID.ToString())); } ddlType.SelectedValue = address.AddressType.LookupID.ToString(); lt = new Literal(); cell.Controls.Add(lt); lt.Text = "<span id=\"" + ddlType.ClientID + "_error\" class=\"errorText\" style=\"display: none;\"> *</span>"; // // Add in the Address itself. // cell = new TableCell(); row.Cells.Add(cell); Literal ltAddress = new Literal(); cell.Controls.Add(ltAddress); ltAddress.Text = address.Address.ToString(); // // Add in the primary checkbox. // cell = new TableCell(); row.Cells.Add(cell); cell.CssClass = "button"; cb = new ArenaCheckBox(); cell.Controls.Add(cb); cb.ID = "cbPrimary_" + fm.PersonID.ToString() + "_" + address.AddressID.ToString() + "_" + address.AddressType.LookupID.ToString(); cb.Attributes.Add("cbPrimary", fm.PersonID.ToString()); cb.Checked = address.Primary; // // Add in the Edit button. // cell = new TableCell(); row.Cells.Add(cell); cell.CssClass = "button"; ArenaImageButton image = new ArenaImageButton(); cell.Controls.Add(image); image.ID = "btnEdit_" + fm.PersonID.ToString() + "_" + address.AddressID.ToString() + "_" + address.AddressType.LookupID.ToString(); image.OnClientClick = ClientEditAddressScript(fm, address) + "return false;"; image.ImageUrl = "~/images/edit.gif"; // // Add in the Delete button. // cell = new TableCell(); row.Cells.Add(cell); cell.CssClass = "button"; image = new ArenaImageButton(); cell.Controls.Add(image); image.ID = "btnDelete_" + fm.PersonID.ToString() + "_" + address.AddressID.ToString() + "_" + address.AddressType.LookupID.ToString(); image.Click += new ImageClickEventHandler(btnDeleteAddress_Click); image.OnClientClick = "return confirm('Are you sure you want to remove " + fm.NickName.Replace("'", "\\'") + "\\'s " + address.AddressType.Value.Replace("'", "\\'") + "?');"; image.ImageUrl = "~/images/delete.gif"; } else { cell = new TableCell(); row.Cells.Add(cell); cell.ColumnSpan = 5; } } if (row != null) { row = new TableRow(); tblPeople.Rows.AddAt(tblPeople.Rows.Count - 1, row); cell = new TableCell(); row.Cells.Add(cell); cell.ColumnSpan = 6; row.CssClass = "spacer"; } } }