Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C# - Contact Phone List Complete the code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using

C# - Contact Phone List
Complete the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace Friends_Phone_List
{
public partial class frmContactList : Form
{
//Declare a string for a the Disk file name and assign it an empty value
string strDiskFileName = "";
public frmContactList()
{
InitializeComponent();
}
private void btnOpen_Click(object sender, EventArgs e)
{
//define a StreamReader variable and name it inputFile
string strInput;
//try
//{
//Use the Show Open dialog to allow the user to select/open a Contact List disk file
//The filename that is selected should be assigned to the field strDiskFileName
//Open the disk file using the OpenText method and passing strDisFileName as an argument
//clear list box of any items it may have
//Set up a while loop using the EndOfStream property
//Read disk record into strInput
//Add contact to list box control
//Close disk file
//}
//catch (Exception ex)
//{
// MessageBox.Show("Problems with disk file:" + Environment.NewLine + ex.Message, "Disk File", MessageBoxButtons.OK, MessageBoxIcon.Information);
//}
}
private void btnAddContact_Click(object sender, EventArgs e)
{
string strContact;
//Validate data
//Assign Contact name(30 chars) + Contact Phone + Phone Source(7 chars) to strContact
//Add contact to list box control using the string variable strContact
//clear Add contact controls (contact name, contact phone and phone source)
//set focus to contact name
}
private bool Validate_Contact()
{
// Contact name cannot be blank (empty)
if (txtContactName.Text == "")
{
MessageBox.Show("The contact name is required.", "Data Entry", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtContactName.Focus();
return false;
}
// Make sure the phone number follows this pattern (###) ###-####. Area code will be required as well
Match PhoneDigits = Regex.Match(txtContactPhone.Text, @"\([0-9][0-9][0-9]\) [0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]");
if (PhoneDigits.Success == false)
{
MessageBox.Show("The phone must have 10 digits when including the area code.", "Data Entry", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtContactPhone.Focus();
return false;
}
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnDeleteContact_Click(object sender, EventArgs e)
{
int intIndex;
//make sure a contact is selected, if a contact is not selected display an appropriate message
//using the MessageBox class and exit the method.
//get selected index of the contact that was chosen and assign it to intIndex
//remove contact from list box by calling the RemoveAt method passing in the selected index (intIndex)
//lstContactNumbers.Items.?;
}
private void btnSave_Click(object sender, EventArgs e)
{
//Declare StreamWriter variable and name it outputFile
int intCount, intloop;
string strOutput;
//Make sure there is at least one contact to save
if (lstContactNumbers.Items.Count==0)
{
MessageBox.Show("There are no contacts to save.", "Contact List", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (strDiskFileName=="") //If this is blank then a file was not opened, therefore, it is a new file that is to be saved.
{
sadSave.Title = "Save Contact List";
// Display Save As Dialog using if statement. Uncomment the following code and finish it
//if (sadSave.ShowDialog() == DialogResult.OK)
//{
// //assign Save As Dialog FileName to the field strDiskFileName
//}
//else
//{
// return; //Saving a disk file was cancelled
//}
}
//Open the disk file to be written over, not appended using the variable outputFile
//Get the number of contacts in the list
intCount = lstContactNumbers.Items.Count;
for (intloop = 0; intloop
{
//assign SelectedIndex of ListBox control to intloop
//assign Text property of ListBox control to string strOutput
//write out contact to disk file making sure a newline character is placed at the end of the record.
}
// close disk file
}
private void Set_Form_AcceptButton(object sender, EventArgs e)
{
// set the Form's AcceptButton to btnAddContact
}
}
}
image text in transcribed
You will finish cis 130-Assignment #3 fo the following application which allows a user to keep track of a contact list of important phones numbers: Contact name (last name, first name)Contact phone Phone source edd Unknown Alanson, Theresa Brovn, xelley (222) 222-2222 Cel 444) 444-4444 David Honet Open Contacts... Save Contacts Delete Contact Egit Follow these steps to complete the assignment: i. Select the ComboBox control (Phone source) and set the property DropDownStyle to DropDownList. This will force the user to select an item from the list. V/2. Set the MaxLength property for the contact name TextBox control to 30. 3. The Validate Contact method is missing code to make sure the user selects an item from the Phone source ComboBox control. This control is both a Textbox control and list box control. Test this after you have completed the code. 4. Anytime the Contact name TextBox control is changed or the Contact phone number or the phone source wirite Ca code to make sure the Add Contact button is the default button. Finish the one line of code for the following method: Set_Form Accept Button.This method should be called when the contact nane, phone or phone 5. Finish code for the Add Contact button click event.Comments are given to assist you with the logic. Test this after it 6. Finish code the Save Contacts button click event. Refer to the comments and again test the application when this 7. Finish cod 8. Finish code the Delete Contact button. source changes. is completed. logic is complete. exceptions during runtime e the Open Contacts click event procedure. Remember to uncomment the Try statement to catch any You will finish cis 130-Assignment #3 fo the following application which allows a user to keep track of a contact list of important phones numbers: Contact name (last name, first name)Contact phone Phone source edd Unknown Alanson, Theresa Brovn, xelley (222) 222-2222 Cel 444) 444-4444 David Honet Open Contacts... Save Contacts Delete Contact Egit Follow these steps to complete the assignment: i. Select the ComboBox control (Phone source) and set the property DropDownStyle to DropDownList. This will force the user to select an item from the list. V/2. Set the MaxLength property for the contact name TextBox control to 30. 3. The Validate Contact method is missing code to make sure the user selects an item from the Phone source ComboBox control. This control is both a Textbox control and list box control. Test this after you have completed the code. 4. Anytime the Contact name TextBox control is changed or the Contact phone number or the phone source wirite Ca code to make sure the Add Contact button is the default button. Finish the one line of code for the following method: Set_Form Accept Button.This method should be called when the contact nane, phone or phone 5. Finish code for the Add Contact button click event.Comments are given to assist you with the logic. Test this after it 6. Finish code the Save Contacts button click event. Refer to the comments and again test the application when this 7. Finish cod 8. Finish code the Delete Contact button. source changes. is completed. logic is complete. exceptions during runtime e the Open Contacts click event procedure. Remember to uncomment the Try statement to catch any

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions