/// <summary> /// This is the Event Handler for OpenSavedOrderButton /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenSavedOrderButton_Click(object sender, EventArgs e) { // configure the file dialog StartFormOpenFileDialog.FileName = ""; //Default filename when a user doesnt change the name StartFormOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); // default directory // open the file dialog var result = StartFormOpenFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { try { // open the stream for reading using (StreamReader inputStream = new StreamReader( File.Open(StartFormOpenFileDialog.FileName, FileMode.Open))) { // reading everything from your Student.txt file Program.product.productID = Convert.ToInt16(inputStream.ReadLine()); Program.product.condition = inputStream.ReadLine(); Program.product.cost = Convert.ToDecimal(inputStream.ReadLine()); Program.product.platform = inputStream.ReadLine(); Program.product.OS = inputStream.ReadLine(); Program.product.manufacturer = inputStream.ReadLine(); Program.product.model = inputStream.ReadLine(); Program.product.RAM_size = inputStream.ReadLine(); Program.product.screensize = inputStream.ReadLine(); Program.product.HDD_size = inputStream.ReadLine(); Program.product.CPU_brand = inputStream.ReadLine(); Program.product.CPU_number = inputStream.ReadLine(); Program.product.GPU_Type = inputStream.ReadLine(); Program.product.CPU_type = inputStream.ReadLine(); Program.product.CPU_speed = inputStream.ReadLine(); Program.product.webcam = inputStream.ReadLine(); Program.product.resolution = inputStream.ReadLine(); //cleanup inputStream.Close(); inputStream.Dispose(); } // this opens the productInfo form this.Hide(); Program.productInfoForm.Show(); } catch (IOException exception) { Debug.WriteLine("ERROR: " + exception.Message); MessageBox.Show("ERROR: " + exception.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (FormatException exception) { Debug.WriteLine("ERROR: " + exception.Message); MessageBox.Show("ERROR: " + exception.Message + "\n\nPlease select the appropriate file type", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void OpenSavedButton_Click(object sender, EventArgs e) { // configure the file dialog StartFormOpenFileDialog.FileName = "Product.txt"; StartFormOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); StartFormOpenFileDialog.Filter = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*"; // open the file dialog var result = StartFormOpenFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { try { // Open the streawm for reading using (StreamReader inputStream = new StreamReader( File.Open(StartFormOpenFileDialog.FileName, FileMode.Open))) { // read from the file Program.product.productID = short.Parse(inputStream.ReadLine()); Program.product.condition = inputStream.ReadLine(); Program.product.cost = Math.Round(decimal.Parse(inputStream.ReadLine()), 2); Program.product.OS = inputStream.ReadLine(); Program.product.manufacturer = inputStream.ReadLine(); Program.product.RAM_type = inputStream.ReadLine(); Program.product.RAM_size = inputStream.ReadLine(); Program.product.CPU_brand = inputStream.ReadLine(); Program.product.CPU_number = inputStream.ReadLine(); Program.product.GPU_Type = inputStream.ReadLine(); Program.product.CPU_type = inputStream.ReadLine(); Program.product.CPU_speed = inputStream.ReadLine(); Program.product.webcam = inputStream.ReadLine(); // cleanup inputStream.Close(); inputStream.Dispose(); } } catch (IOException exception) { //Debug.WriteLine("ERROR: " + exception.Message); MessageBox.Show("ERROR: " + exception.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (FormatException exception) { //Debug.WriteLine("ERROR: " + exception.Message); MessageBox.Show("ERROR: " + exception.Message + "\n\nPlease select the appropriate file type", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Hide(); Program.productInfoForm.Show(); } }
/// <summary> /// This Button Click Event opens file dialog and loads the proper user defined text file, then it proceed to open the product info form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void LoadOrderButton_Click(object sender, EventArgs e) { //configure the file dialog StartFormOpenFileDialog.FileName = "Product.txt"; StartFormOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); StartFormOpenFileDialog.Filter = "Text Files (*.txt)|*.txt| All Files{*.*)|*.*"; //open the file dialog var result = StartFormOpenFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { try { //Open the stream for reading using (StreamReader inputStream = new StreamReader(File.Open(StartFormOpenFileDialog.FileName, FileMode.Open))) { //Read from file Program.product.productID = short.Parse(inputStream.ReadLine()); Program.product.cost = decimal.Parse(inputStream.ReadLine()); Program.product.model = inputStream.ReadLine(); Program.product.RAM_type = inputStream.ReadLine(); Program.product.RAM_size = inputStream.ReadLine(); Program.product.displaytype = inputStream.ReadLine(); Program.product.screensize = inputStream.ReadLine(); Program.product.resolution = inputStream.ReadLine(); Program.product.CPU_Class = inputStream.ReadLine(); Program.product.CPU_brand = inputStream.ReadLine(); Program.product.CPU_type = inputStream.ReadLine(); Program.product.CPU_speed = inputStream.ReadLine(); Program.product.condition = inputStream.ReadLine(); Program.product.OS = inputStream.ReadLine(); Program.product.platform = inputStream.ReadLine(); Program.product.HDD_size = inputStream.ReadLine(); Program.product.GPU_Type = inputStream.ReadLine(); Program.product.optical_drive = inputStream.ReadLine(); Program.product.Audio_type = inputStream.ReadLine(); Program.product.LAN = inputStream.ReadLine(); Program.product.WIFI = inputStream.ReadLine(); Program.product.width = inputStream.ReadLine(); Program.product.height = inputStream.ReadLine(); Program.product.depth = inputStream.ReadLine(); Program.product.weight = inputStream.ReadLine(); Program.product.moust_type = inputStream.ReadLine(); Program.product.power = inputStream.ReadLine(); Program.product.webcam = inputStream.ReadLine(); Program.product.manufacturer = inputStream.ReadLine(); Program.product.CPU_number = inputStream.ReadLine(); //Clean up inputStream.Close(); inputStream.Dispose(); } } catch (IOException exception) { MessageBox.Show("ERROR" + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } this.Hide(); Program.Forms[FormNames.PRODUCTINFO_FORM].Show(); }