This is just part of a C# windows form Application. When the user enters their information, checks the check box to save info and hits the payment button the information is saved to a .txt file. When user enters last name and clicks autofill if name is found in file it will auto fill the boxes but i'm having issues with this part. For some reason it skips the firstname box and enters the last name in the first name box the card number in the last name box, etc,etc. What am I doing wrong?
my Code:
private void Submitbutton_Click(object sender, EventArgs
e)
{
if (BillcheckBox.Checked && CreditradioButton.Checked ==
true)
{
StreamWriter stream_writer = new
StreamWriter("PaymentInfo.txt");
stream_writer.WriteLine(FirstNametextBox.Text);
stream_writer.WriteLine(LastNametextBox.Text);
stream_writer.WriteLine(CardtextBox.Text);
stream_writer.WriteLine(MonthcomboBox.Text);
stream_writer.WriteLine(YearcomboBox.Text);
//Closes the file
stream_writer.Close();
// Clears the Controls.
FirstNametextBox.Clear();
LastNametextBox.Clear();
CardtextBox.Clear();
MonthcomboBox.SelectedItem = null;
YearcomboBox.SelectedItem = null;
MessageBox.Show("Thank You for your purchase! Your billing information has been saved!");
}
if (CreditradioButton.Checked == true)
{
MessageBox.Show("Thank You for your purchase! You're billing
information was not saved.");
}
if (CashradioButton.Checked == true)
{
//Enter order amount
double order = Convert.ToDouble(OrdertextBox.Text);
//Enter cash recieved
double cash = Convert.ToDouble(CashtextBox.Text);
//Calculates total
Outputlabel.Text = String.Format("${0:0.00}", order - cash);
MessageBox.Show("Thank You for your purchase! ");
//Clears controls
OrdertextBox.Clear();
CashtextBox.Clear();
Outputlabel.Text = "";
}
}
private void AutoFillbutton_Click(object sender, EventArgs e)
{
string line;
string name;
name = LastNametextBox.Text;
StreamReader stream_reader = new StreamReader("PaymentInfo.Txt");
while ((line = stream_reader.ReadLine()) != null)
{
if (line.Contains(name))
{
FirstNametextBox.Text = stream_reader.ReadLine();
LastNametextBox.Text = stream_reader.ReadLine();
CardtextBox.Text = stream_reader.ReadLine();
MonthcomboBox.Text = stream_reader.ReadLine();
YearcomboBox.Text = stream_reader.ReadLine();
}
}
}
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Below are the observations
When writing into the File :
When reading data from the File :
Solution :
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.
This is just part of a C# windows form Application. When the user enters their information, checks the check box to save info and hits the payment button the information is saved to a .txt file. When...