private void btnAdd_Click(object sender, EventArgs e) { try { // validate input data if (string.IsNullOrEmpty(txtFriendlyName.Text.Trim()) || string.IsNullOrEmpty(txtIdentity.Text.Trim())) { MessageBox.Show("Cannot insert empty text"); return; } switch (_formMode) { case GenericEnums.FormMode.Add: Contact contact = new Contact(0, txtFriendlyName.Text.Trim(), txtIdentity.Text.Trim()); _contactsUpdated.BeginInvoke(sender, new ContactsEventArgs { UpdatedContact = contact, Operation = GenericEnums.ContactsOperation.Add }, null, null); break; case GenericEnums.FormMode.Update: Contact contact2 = new Contact(_contactNo, txtFriendlyName.Text.Trim(), txtIdentity.Text.Trim()); _contactsUpdated.Invoke(sender, new ContactsEventArgs { UpdatedContact = contact2, Operation = GenericEnums.ContactsOperation.Update } //, null, null ); break; } } catch (Exception ex) { Tools.Instance.Logger.LogError(ex.ToString()); } finally { this.Close(); } }
private void btnUpdate_Click(object sender, EventArgs e) { try { DataGridViewRow selectedRow = dgvContacts.SelectedRows[0]; ContactBase contact = new Contact(int.Parse(selectedRow.Cells["ContactNo"].Value.ToString()), selectedRow.Cells["FriendlyName"].Value.ToString(), selectedRow.Cells["Identity"].Value.ToString()); FormContact formContact = new FormContact(GenericEnums.FormMode.Update, contact, _onContactsUpdated); formContact.ShowDialog(this); } catch (Exception ex) { Tools.Instance.Logger.LogError(ex.ToString()); } }
private void dgvContacts_CellEnter(object sender, DataGridViewCellEventArgs e) { try { if (dgvContacts.SelectedRows != null && dgvContacts.SelectedRows.Count > 0) { DataGridViewRow selectedRow = dgvContacts.SelectedRows[0]; try { Contact contact = new Contact(int.Parse(selectedRow.Cells["ContactNo"].Value.ToString()), selectedRow.Cells["FriendlyName"].Value.ToString(), selectedRow.Cells["Identity"].Value.ToString()); _onSelectedContactChanged.Invoke(this, new ContactsEventArgs() { UpdatedContact = contact }); } catch { _onSelectedContactChanged.Invoke(this, new ContactsEventArgs() { UpdatedContact = null }); } } } catch (Exception ex) { Tools.Instance.Logger.LogError(ex.ToString()); } }
private void btnRemove_Click(object sender, EventArgs e) { try { DataGridViewRow selectedRow = dgvContacts.SelectedRows[0]; Contact contact = new Contact(int.Parse(selectedRow.Cells["ContactNo"].Value.ToString()), selectedRow.Cells["FriendlyName"].Value.ToString(), selectedRow.Cells["Identity"].Value.ToString()); // pass the removed contact no as argument _onContactsUpdated.Invoke(this, new ContactsEventArgs() { UpdatedContact = contact, Operation = GenericEnums.ContactsOperation.Remove }); _onContactsUpdated.BeginInvoke(this, new ContactsEventArgs() { Operation = GenericEnums.ContactsOperation.Load }, null, null ); } catch (Exception ex) { Tools.Instance.Logger.LogError(ex.ToString()); } }