Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am having a problem with creating a revert command for C#. This is the problem: If you have opened a specific file, or if

I am having a problem with creating a revert command for C#.

This is the problem:

If you have opened a specific file, or if you have recently saved a file, then you need to maintain a copy of the ice cream details in memory, and then if you change the details (without saving), and click Revert, the details will go back to what they were before you changed them. To do this, you must use a List collection object or an array. It could be as simple as maintaining the option (ice cream flavor, syrup, nuts, cherries, and toppings) values in a list of strings. You must ensure that this in-memory revert list is updated whenever the user opens another file, or saves the current ice cream order.

I have the following code:

namespace Project3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

private void Form1_Load(object sender, EventArgs e) { flavorComboBox.SelectedIndex = 0; syrupComboBox.SelectedIndex = 0; }

private void openToolStripMenuItem_Click(object sender, EventArgs e) { Stream myStream = null; OpenFileDialog openFileDialog1 = new OpenFileDialog();

openFileDialog1.Filter = "Order Files(*.icorder)|*.icorder|All Files (*.*)|*.*";

openFileDialog1.RestoreDirectory = true;

if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { if ((myStream = openFileDialog1.OpenFile()) != null) { using (myStream) { StreamReader getInfo = new StreamReader(openFileDialog1.OpenFile()); { string info = "";

while (getInfo.Peek() != -1) { info += getInfo.ReadLine(); info += " "; }

char[] delims = { ' ', ' ', ' ' };

string[] data = info.Split(' ');

flavorComboBox.Text = data[0]; syrupComboBox.Text = data[1];

if (data[2] == "yes") nutsCheckBox.Checked = true; else nutsCheckBox.Checked = false; if (data[3] == "yes") cherriesCheckBox.Checked = true; else cherriesCheckBox.Checked = false; if (data[4] == "yes") sprinklesCheckBox.Checked = true; else sprinklesCheckBox.Checked = false;

} } } } catch (Exception ex) { MessageBox.Show("Error opening data file " + ex.Message); } }

}//end open

private void saveToolStripMenuItem_Click(object sender, EventArgs e) { var saveFile = new SaveFileDialog(); saveFile.Filter = "Order Files(*.icorder) | *.icorder | All Files(*.*) | *.* "; if (saveFile.ShowDialog() == DialogResult.OK) { int i = 0; using (var item = new StreamWriter(saveFile.FileName))

{ item.WriteLine(flavorComboBox.Text); item.WriteLine(syrupComboBox.Text);

if (nutsCheckBox.Checked == true)

item.WriteLine("yes"); else item.WriteLine("no"); if (cherriesCheckBox.Checked == true) item.WriteLine("yes"); else item.WriteLine("no"); if (sprinklesCheckBox.Checked == true) item.WriteLine("yes"); else item.WriteLine("no"); i++; } } }//end save

private void revertToolStripMenuItem_Click(object sender, EventArgs e) { //THIS IS WHERE IM STUCK!!!!!!!!!!!!!!!!!!!!!!!!!!!!

}//end revert

private void closeToolStripMenuItem_Click(object sender, EventArgs e) { this.Close();

}//end close

private void flavorComboBox_SelectedIndexChanged(object sender, EventArgs e) {

if (flavorComboBox.Text == "Vanilla") {

flavorPictureBox.Image = new Bitmap("images\\vanillaCream.jpg"); }

if (flavorComboBox.Text == "Chocolate") {

flavorPictureBox.Image = new Bitmap("images\\chocCream.jpg"); } if (flavorComboBox.Text == "Strawberry") {

flavorPictureBox.Image = new Bitmap("images\\strawCream.jpg"); } }//end flavorcombo

private void syrupComboBox_SelectedIndexChanged(object sender, EventArgs e) {

if (syrupComboBox.Text == "Chocolate") {

syrupPictureBox.Image = new Bitmap("images\\chocolate.jpg"); }

if (syrupComboBox.Text == "Caramel") {

syrupPictureBox.Image = new Bitmap("images\\caramel.jpg"); } if (syrupComboBox.Text == "Butterscotch") {

syrupPictureBox.Image = new Bitmap("images\\butterscotch.jpg"); } }//end syrupcombo } }

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

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions