Question

Visual Studios Help

Windows Forms App (NET Framework) Visual C#

Exercise Create a form named Vendo any specified vendor, as follows: Read each vendor record from the Vendor.txt file (Figure

Text file named Vendor.txt (vendor#, name, street, city, state, zip, phone):


1,FCC,445 12th Street SW, Washington,DC,20554,888-225-5322
2, U.S, Copyright Office, 101 Independence Ave, Washington, DC, 20559,202-707-3000
3,CDC,1600 Clifton Road,Atlanta,GA,30333,800-323-4636
4,White House, 1600 Pennsylvania Avenue NW, Washington,DC,20500,202-456-1111
5,Labor Statistics,Postal Sq Bldg,2 Mass Ave,Washington,DC,20212,800-877-8339
6,AMTRAK,60 Massachusetts Avenue NE,Washington,DC,20002,800-523-6590
7,U.S. Air Force,1690 Air Force Pentagon,Washington,DC,20330-1670,800-423-8723
8,National Guard,111 South George Mason Dr,Arlington,VA,22204,800-864-6264
9,Office of Govt Ethics,1201 New York Ave,Washington,DC,20005,202-482-9300
10,IRS,1111 Constitution Ave NW,Washington,DC,20224,800-829-1040

Windows Forms App (NET Framework) Visual C#
Exercise Create a form named Vendo any specified vendor, as follows: Read each vendor record from the Vendor.txt file (Figure 9-26). Add the name as the ke number as the value into a Dictionary named vendorPhones. Add the name to a sorted ComboBox. When the user selects a vendor name from the ComboBox, find and display the name and corresponding rsDictionaryl that allows the user to find and display the phone number for the key, and the phone phone number in a ListBox.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new Windows Forms Application in C# is created using Visual Studio 2017 with name "VendorsApplication".This application contains a form with name "VendorsDictionary1.cs".Below are the files associated with form1.

1.VendorsDictionary1.cs[Design]

Vendor Details Select Vendor Find Details

2.VendorsDictionary1.Designer.cs

3.VendorsDictionary1.cs

//namespace
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;
//application namespace
namespace VendorsApplication
{
public partial class VendorsDictionary1 : Form
{
public VendorsDictionary1()
{
InitializeComponent();
}
//creating dictionary
Dictionary<string, string> vendorsPhones = new Dictionary<string, string>();
//form load event
private void VendorList_Load(object sender, EventArgs e)
{

//creating object of StreamReader class
StreamReader streamReader = new StreamReader("Vendor.txt");
//declaring variable to read each line
string line = "";
//declaring array
string[] recordArray = new string[7];
while((line=streamReader.ReadLine())!=null)
{
recordArray = line.Split(',');//split line into array based on ,
//add name as key and phone as value in the dictionary
vendorsPhones.Add(recordArray[1], recordArray[6]);
//add vendor name in the combobox
cmbVendors.Items.Add(recordArray[1]);
}

}
//find button click
private void btnFind_Click(object sender, EventArgs e)
{
//getting selected vendor name from cobobox
string vendorname = cmbVendors.SelectedItem.ToString();
lstVendor.Items.Clear();//clear vendor listbox
foreach (var item in vendorsPhones)
{
//checking item key as vendor name
if(item.Key== vendorname)
{
//if key is found , then add key and value in the listbox
lstVendor.Items.Add(item.Key + " : " + item.Value);
}
}
}
}
}

======================================================

Output : Run application using F5 and will get the screen as shown below

Screen 1 :

Vendor Details Select Vendor Find Details

Screen 2 :Screen showing vendor names in combobox

Vendor Details Select Vendor FCC U.S FirCDC White House Labor Statistics AMTRAK U.S. Air Force National Guard Office of Govt

Screen 3 :Screen showing vendor name and phone number

Vendor Details White House Select Vendor Find Details White House: 202-456-1111

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
Visual Studios Help Text file named Vendor.txt (vendor#, name, street, city, state, zip, phone): 1,FCC,445 12th Street SW, Washington,DC,20554,888-225-5322 2, U.S, Copyright Office, 101 Independenc...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT