private void btnSave_Click(object sender, EventArgs e) { if (sender is Button button) { var textbox = GetTextBox(button.Name[button.Name.Length - 1]); if (textbox == null) { return; } // check for unique number if (textbox.Name.Equals("txtNumber") && IsDuplicate(txtNumber.Text)) { button.Visible = true; textbox.ReadOnly = false; return; } foreach (var contactSet in Contacts.Values) { var contact = contactSet.FirstOrDefault( c => c.TelephoneNumber == SelectedContact.TelephoneNumber); if (contact != null) { contactSet.Remove(contact); isEdited = true; break; } } if (isEdited) { var contact = new ContactEntry() { FirstName = txtFirstName.Text.Trim(), LastName = txtLastName.Text.Trim(), TelephoneNumber = txtNumber.Text.Trim(), Email = txtEmail.Text.Trim(), ImageBase64 = SelectedContact.ImageBase64 }; var key = contact.FirstName[0]; if (Contacts.ContainsKey(key)) { Contacts[key].Add(contact); } else { Contacts[key] = new HashSet <ContactEntry>(ContactEntry.TelephoneComparer); Contacts[key].Add(contact); } } button.Visible = false; textbox.ReadOnly = true; btnSent.Enabled = true; btnSendSMS.Enabled = true; btnDelete.Enabled = true; btnPick.Enabled = true; } }
public SentMessages(ContactEntry contact) { InitializeComponent(); this.Contact = contact; Display(); }