private void btnAdd_Click(object sender, EventArgs e) { if (txtFirstName.Text.Trim().Length == 0 || txtLastName.Text.Trim().Length == 0 || txtStreet.Text.Trim().Length == 0 || txtZip.Text.Trim().Length == 0) { MessageBox.Show("Please fill in all information", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Friend newfriend = new Friend() { FirstName = txtFirstName.Text, LastName = txtLastName.Text, Street = txtStreet.Text, State = cbStateAbbrevs.Text, Zip = Convert.ToInt32(txtZip.Text), }; Business.FriendCRUD friendCRUD = new Business.FriendCRUD(); friendCRUD.AddFriend(newfriend); MessageBox.Show("New friend was successfully added", "Successful Add", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); // Add new Friend to list box Fill_lstBoxFriends(); // Clear text boxes to be ready for next entry txtFirstName.Clear(); txtLastName.Clear(); txtStreet.Clear(); txtZip.Clear(); } }
private void btnDelete_Click(object sender, EventArgs e) { // Remove friend from listbox and list collection int selectedIndex = lstBoxFriends.SelectedIndex; Business.FriendCRUD fr = new Business.FriendCRUD(); try { Friend friend = lstBoxFriends.SelectedItem as Friend; fr.DeleteFriend(friend); Fill_lstBoxFriends(); FriendList.RemoveAt(selectedIndex); } catch { MessageBox.Show("Select a friend to delete", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnAdd_Click(object sender, EventArgs e) { if (txtFirstName.Text.Trim().Length == 0 || txtLastName.Text.Trim().Length == 0 || txtStreet.Text.Trim().Length == 0 || txtZip.Text.Trim().Length == 0) { MessageBox.Show("Please fill in all information", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Friend newfriend = new Friend() { FirstName = txtFirstName.Text, LastName = txtLastName.Text, Street = txtStreet.Text, State = cbStateAbbrevs.Text, Zip =Convert.ToInt32(txtZip.Text), }; Business.FriendCRUD friendCRUD = new Business.FriendCRUD(); friendCRUD.AddFriend(newfriend); MessageBox.Show("New friend was successfully added", "Successful Add", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); // Add new Friend to list box Fill_lstBoxFriends(); // Clear text boxes to be ready for next entry txtFirstName.Clear(); txtLastName.Clear(); txtStreet.Clear(); txtZip.Clear(); } }