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 <= intCount - 1; 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

}

} }

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

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions

Question

L01 Differentiate between glia and neurons.

Answered: 1 week ago