Create an application in Visual Studio (C#) with a class named PersonEntry. The
ID: 3689451 • Letter: C
Question
Create an application in Visual Studio (C#) with a class named PersonEntry. The PersonEntry class should have properties for a person's name, e-mail address, and phone number. Also, create a text file that contains the names, e-mail addresses, and phone numbers for at least five people. When the application starts, it should read the data from the file and create a PersonEntry object for each person's data. The PersonEntry objects should be added to a List, and each person's name should be displayed in a list box on the application's main form. When the user selects a name from the list box, a second form should appear displaying that person's name, e-mail address, and phone number.
Explanation / Answer
first code
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace ProgramEntry
{
class PersonEntry
{
string _name;
string _email;
string _phone;
public PersonEntry()
{
_name = "";
_email = "";
_phone = "";
}
public string PersonName
{
get
{
return _name;
}
set
{
_name = value;
}
}
public string PersonEmail
{
get
{
return _email;
}
set
{
_email = value;
}
}
public string PersonPhone
{
get
{
return _phone;
}
set
{
_phone = value;
}
}
}
}
second code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
namespace ProgramEntry
{
public partial class ListMainForm : Form
{
List<PersonEntry> nameList = new List<PersonEntry>();
public ListMainForm()
{
InitializeComponent();
}
private void ListMainForm_Load(object sender, EventArgs e)
{
namesListBox.Items.Clear();
}
private void getNamesButton_Click(object sender, EventArgs e)
{
Readfile();
DisplayNameList();
}
private void Readfile()
{
try
{
StreamReader inputFile;
string line;
char[] deliminator = { ';' };
inputFile = File.OpenText(("PhEmailDatList.txt"));
while (!inputFile.EndOfStream)
{
PersonEntry entry = new PersonEntry();
line = inputFile.ReadLine();
string[] tokens = line.Split(deliminator);
entry.PersonName = tokens[0];
entry.PersonEmail = tokens[1];
entry.PersonPhone = tokens[2];
nameList.Add(entry);
}
}
catch (Exception ex)
{
MessageBox.Show("The error message is ” + " " + ex.Message);
}
}
private void DisplayNameList()
{
foreach (PersonEntry nameDisplay in nameList)
{
namesListBox.Items.Add(nameDisplay.PersonName);
}
}
public void namesListBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (namesListBox.SelectedIndex != -1)
{
string name = nameList[namesListBox.SelectedIndex].PersonName;
string email = nameList[namesListBox.SelectedIndex].PersonEmail;
string phone = nameList[namesListBox.SelectedIndex].PersonPhone;
DetailForm f2 = new DetailForm(name, email, phone);
f2.ShowDialog();
}
else
{
MessageBox.Show("what u r going to do");
}
}
}
}
Third 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.IO;
using System.Diagnostics;
namespace ProgramEntry
{
public partial class DetailForm : Form
{
public DetailForm(string NameDet, string EmailDet, string PhoneDet)
{
InitializeComponent();
nameDetLabel.Text = NameDetail;
emailDetLabel.Text = EmailDetail;
phoneDetLabel.Text = PhoneDetail;
}
public void DetailForm_Load(object sender, EventArgs e)
{
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.