/// <summary> /// This is event handler for openToolStripMenuItem Click event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void openToolStripMenuItem_Click(object sender, EventArgs e) { // Configure the file dialog ProductOpenFileDialog.FileName = "Harware.txt"; ProductOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); ProductOpenFileDialog.Filter = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*"; var resultFile = ProductOpenFileDialog.ShowDialog(); if (resultFile != DialogResult.Cancel) { try { // this will opening file stream to read using (StreamReader input = new StreamReader(File.Open(ProductOpenFileDialog.FileName, FileMode.Open))) { Program.product.productID = short.Parse(input.ReadLine()); Program.product.cost = decimal.Parse(input.ReadLine()); Program.product.manufacturer = input.ReadLine(); Program.product.model = input.ReadLine(); Program.product.condition = input.ReadLine(); Program.product.platform = input.ReadLine(); Program.product.OS = input.ReadLine(); Program.product.RAM_size = input.ReadLine(); Program.product.screensize = input.ReadLine(); Program.product.HDD_size = input.ReadLine(); Program.product.CPU_brand = input.ReadLine(); Program.product.CPU_number = input.ReadLine(); Program.product.GPU_Type = input.ReadLine(); Program.product.CPU_type = input.ReadLine(); Program.product.CPU_speed = input.ReadLine(); Program.product.webcam = input.ReadLine(); // cleaning up! input.Close(); input.Dispose(); } } catch (IOException error) { // error when user select the wrong file MessageBox.Show($"ERROR: {error.Message}", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (FormatException errorFormat) { // this happens when the format of the file is wrong MessageBox.Show($"ERROR: {errorFormat.Message} \n\nPlease select the correct file type", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } // loads the new selection ProductInfoForm_Load(sender, e); }
/// <summary> /// This method will open up your saved files /// </summary> private void OpenFile() { // Configure the file dialog ProductOpenFileDialog.FileName = "Hardware.txt"; ProductOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); ProductOpenFileDialog.Filter = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*"; // Open the file dialog var resultFile = ProductOpenFileDialog.ShowDialog(); if (resultFile != DialogResult.Cancel) { try { // Open file stream to read using (StreamReader input = new StreamReader(File.Open(ProductOpenFileDialog.FileName, FileMode.Open))) { Program.product.productID = short.Parse(input.ReadLine()); Program.product.cost = decimal.Parse(input.ReadLine()); Program.product.manufacturer = input.ReadLine(); Program.product.model = input.ReadLine(); Program.product.condition = input.ReadLine(); Program.product.platform = input.ReadLine(); Program.product.OS = input.ReadLine(); Program.product.RAM_size = input.ReadLine(); Program.product.screensize = input.ReadLine(); Program.product.HDD_size = input.ReadLine(); Program.product.CPU_brand = input.ReadLine(); Program.product.CPU_number = input.ReadLine(); Program.product.GPU_Type = input.ReadLine(); Program.product.CPU_type = input.ReadLine(); Program.product.CPU_speed = input.ReadLine(); Program.product.webcam = input.ReadLine(); // cleaning it up input.Close(); input.Dispose(); } } catch (IOException error) { MessageBox.Show($"ERROR: {error.Message}", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (FormatException errorFormat) { MessageBox.Show($"ERROR: {errorFormat.Message} \n\nPlease select the correct file type", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// This method handles the Open Saved File from Product Info Form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenStripMenuItem_Click(object sender, EventArgs e) { //configure open file dialog ProductOpenFileDialog.FileName = "Product.txt"; ProductOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); ProductOpenFileDialog.Filter = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*"; //open the file dialog var result = ProductOpenFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { using (StreamReader inputStream = new StreamReader( File.Open(ProductOpenFileDialog.FileName, FileMode.Open))) { try { //read file Program.computers.ProductID = int.Parse(inputStream.ReadLine()); Program.computers.Cost = double.Parse(inputStream.ReadLine()); Program.computers.Condition = inputStream.ReadLine(); Program.computers.Platform = inputStream.ReadLine(); Program.computers.OS = inputStream.ReadLine(); Program.computers.Manufacturer = inputStream.ReadLine(); Program.computers.Model = inputStream.ReadLine(); Program.computers.RAMSize = inputStream.ReadLine(); Program.computers.ScreenSize = inputStream.ReadLine(); Program.computers.HDDSize = inputStream.ReadLine(); Program.computers.CPUBrand = inputStream.ReadLine(); Program.computers.CPUNumber = inputStream.ReadLine(); Program.computers.GPUType = inputStream.ReadLine(); Program.computers.CPUType = inputStream.ReadLine(); Program.computers.CPUSpeed = inputStream.ReadLine(); Program.computers.WebCam = inputStream.ReadLine(); inputStream.Close(); inputStream.Dispose(); ProductInfoForm_Activated(sender, e); } catch (IOException exception) { MessageBox.Show("Error: " + exception.Message, "File I/O Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
/// <summary> /// This is a methoad to load order from the file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void LoadProduct(object sender, EventArgs e) { ProductOpenFileDialog.FileName = "Product.txt"; ProductOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); ProductOpenFileDialog.Filter = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*"; var result = ProductOpenFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { using (StreamReader inputStream = new StreamReader( File.Open(ProductOpenFileDialog.FileName, FileMode.Open))) { Program.product.productID = short.Parse(inputStream.ReadLine()); Program.product.cost = decimal.Parse(inputStream.ReadLine()); Program.product.manufacturer = 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.CPU_number = 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.HDD_speed = 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.weight = inputStream.ReadLine(); inputStream.Close(); inputStream.Dispose(); } ProductInfoForm_Activated(sender, e); } }
/// <summary> /// Function to handle openSavedOrder button click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenSavedOrderButton_Click(object sender, EventArgs e) { _errflag = false; //this flag should be set to false when user starts to open from file //Configuration for openFileDialog ProductOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); ProductOpenFileDialog.FileName = "DefaultProduct.dat"; ProductOpenFileDialog.Filter = "Binary Files (*.dat)|*.dat|All Files (*.*)|*.*"; var result = ProductOpenFileDialog.ShowDialog(); //stores user action in result variable if (result != DialogResult.Cancel) { //open filestream using (BinaryReader inputStream = new BinaryReader(File.Open(ProductOpenFileDialog.FileName, FileMode.Open))) { //read from file into product object try { Program.product.productID = short.Parse(inputStream.ReadString()); Program.product.cost = decimal.Parse(inputStream.ReadString()); Program.product.manufacturer = inputStream.ReadString(); Program.product.model = inputStream.ReadString(); Program.product.RAM_type = inputStream.ReadString(); Program.product.RAM_size = inputStream.ReadString(); Program.product.displaytype = inputStream.ReadString(); Program.product.screensize = inputStream.ReadString(); Program.product.resolution = inputStream.ReadString(); Program.product.CPU_Class = inputStream.ReadString(); Program.product.CPU_brand = inputStream.ReadString(); Program.product.CPU_type = inputStream.ReadString(); Program.product.CPU_speed = inputStream.ReadString(); Program.product.CPU_number = inputStream.ReadString(); Program.product.condition = inputStream.ReadString(); Program.product.OS = inputStream.ReadString(); Program.product.platform = inputStream.ReadString(); Program.product.HDD_size = inputStream.ReadString(); Program.product.HDD_speed = inputStream.ReadString(); Program.product.GPU_Type = inputStream.ReadString(); Program.product.optical_drive = inputStream.ReadString(); Program.product.Audio_type = inputStream.ReadString(); Program.product.LAN = inputStream.ReadString(); Program.product.WIFI = inputStream.ReadString(); Program.product.width = inputStream.ReadString(); Program.product.height = inputStream.ReadString(); Program.product.depth = inputStream.ReadString(); Program.product.weight = inputStream.ReadString(); Program.product.moust_type = inputStream.ReadString(); Program.product.power = inputStream.ReadString(); Program.product.webcam = inputStream.ReadString(); } catch (Exception exception) { _errflag = true; //this flag is set to true when some error is caught MessageBox.Show("ERROR: " + exception.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } //cleanup inputStream.Close(); inputStream.Dispose(); } //when everything is good, product info form is displayed, else remains at start form if (_errflag == false) { Program.Forms[FormName.PRODUCT_INFO_FORM].Show(); Hide(); } } }
/// <summary> /// This is the event handler when the user clicks the open tool menu item /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void openToolStripMenuItem_Click(object sender, EventArgs e) { //configure the file dialog ProductOpenFileDialog.FileName = "Product.txt"; ProductOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); ProductOpenFileDialog.Filter = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*"; // open the file dialog var result = ProductOpenFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { try { // Open the stream for reading using (StreamReader inputStream = new StreamReader( File.Open(ProductOpenFileDialog.FileName, FileMode.Open))) { //read from the file Program.product.productID = short.Parse(inputStream.ReadLine()); Program.product.cost = decimal.Parse(inputStream.ReadLine()); Program.product.manufacturer = 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.CPU_number = 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.HDD_speed = 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(); //cleanup inputStream.Close(); inputStream.Dispose(); } NextButton_Click(sender, e); } 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); } } NextButton.Enabled = true; }
private void loadSavedOrderBtn_Click(object sender, EventArgs e) { // Configure ProductOpenFile Dialogue ProductOpenFileDialog.FileName = "Product.txt"; ProductOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); ProductOpenFileDialog.Filter = "Text File (*.txt)|*txt|All Files (*.*)|*.*"; // Open ProductOpenFile Dialogue var result = ProductOpenFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { try { using (StreamReader inputStream = new StreamReader( File.Open(ProductOpenFileDialog.FileName, FileMode.Open))) { // calling methods to the calss product members Program.product.productID = short.Parse(inputStream.ReadLine()); Program.product.cost = decimal.Parse(inputStream.ReadLine());; Program.product.manufacturer = 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.CPU_number = 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.HDD_speed = 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(); // closing the stream inputStream.Close(); inputStream.Dispose(); // showing the product info form Program.productInfoForm.Show(); //hiding the form this.Hide(); } } catch (IOException exception) { // Message box showing the error if the previouse code failed to retrieve the file MessageBox.Show("Error:" + exception.Message, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// This is event handler for OpenBinaryToolStripMenuItem Click event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenBinaryToolStripMenuItem_Click(object sender, EventArgs e) { // configure the file dialog ProductOpenFileDialog.FileName = "Product.dat"; ProductOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); ProductOpenFileDialog.Filter = "Binary Files (*.dat)|*.dat| All Files (*.*)|*.*"; // open the file dialog var result = ProductOpenFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { try { // open file stream to read using (BinaryReader inputStream = new BinaryReader( File.Open(ProductOpenFileDialog.FileName, FileMode.Open))) { // read stuff from the file into the Product object Program.product.productID = short.Parse(inputStream.ReadString()); Program.product.cost = decimal.Parse(inputStream.ReadString()); Program.product.manufacturer = inputStream.ReadString(); Program.product.model = inputStream.ReadString(); Program.product.RAM_type = inputStream.ReadString(); Program.product.RAM_size = inputStream.ReadString(); Program.product.displaytype = inputStream.ReadString(); Program.product.screensize = inputStream.ReadString(); Program.product.resolution = inputStream.ReadString(); Program.product.CPU_Class = inputStream.ReadString(); Program.product.CPU_brand = inputStream.ReadString(); Program.product.CPU_type = inputStream.ReadString(); Program.product.CPU_speed = inputStream.ReadString(); Program.product.CPU_number = inputStream.ReadString(); Program.product.condition = inputStream.ReadString(); Program.product.OS = inputStream.ReadString(); Program.product.platform = inputStream.ReadString(); Program.product.HDD_size = inputStream.ReadString(); Program.product.HDD_speed = inputStream.ReadString(); Program.product.GPU_Type = inputStream.ReadString(); Program.product.optical_drive = inputStream.ReadString(); Program.product.Audio_type = inputStream.ReadString(); Program.product.LAN = inputStream.ReadString(); Program.product.WIFI = inputStream.ReadString(); Program.product.width = inputStream.ReadString(); Program.product.height = inputStream.ReadString(); Program.product.depth = inputStream.ReadString(); Program.product.weight = inputStream.ReadString(); Program.product.moust_type = inputStream.ReadString(); Program.product.power = inputStream.ReadString(); Program.product.webcam = inputStream.ReadString(); //cleanup inputStream.Close(); inputStream.Dispose(); } // for inputting data to labels ProductInfoForm_Activated(sender, e); } 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 binary file type.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void SavedOrderButton_Click(object sender, EventArgs e) { //confgure the dile dialog ProductOpenFileDialog.FileName = "Product.txt"; ProductOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); ProductOpenFileDialog.Filter = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*"; //open the file diolog var result = ProductOpenFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { try { //open file stream to read using (StreamReader inputStream = new StreamReader(File.Open(ProductOpenFileDialog.FileName, FileMode.Open))) { // read stuff from the file Program.product.productID = short.Parse(inputStream.ReadLine()); Program.product.cost = decimal.Parse(inputStream.ReadLine()); Program.product.manufacturer = 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.CPU_number = 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.HDD_speed = 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(); //cleanup inputStream.Close(); inputStream.Dispose(); } Program.productInfoForm.Show(); this.Hide(); } catch (IOException exception) { Debug.WriteLine("ERROR " + exception.Message); MessageBox.Show("ERROR " + exception.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { //Configuration for openFileDialog ProductOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); ProductOpenFileDialog.FileName = "DefaultProduct.dat"; ProductOpenFileDialog.Filter = "Binary Files (*.dat)|*.dat|All Files (*.*)|*.*"; var result = ProductOpenFileDialog.ShowDialog(); //stores user action in result variable if (result != DialogResult.Cancel) { //open filestream try { using (BinaryReader inputStream = new BinaryReader(File.Open(ProductOpenFileDialog.FileName, FileMode.Open))) { //read from file into product object try { Program.product.productID = short.Parse(inputStream.ReadString()); Program.product.cost = decimal.Parse(inputStream.ReadString()); Program.product.manufacturer = inputStream.ReadString(); Program.product.model = inputStream.ReadString(); Program.product.RAM_type = inputStream.ReadString(); Program.product.RAM_size = inputStream.ReadString(); Program.product.displaytype = inputStream.ReadString(); Program.product.screensize = inputStream.ReadString(); Program.product.resolution = inputStream.ReadString(); Program.product.CPU_Class = inputStream.ReadString(); Program.product.CPU_brand = inputStream.ReadString(); Program.product.CPU_type = inputStream.ReadString(); Program.product.CPU_speed = inputStream.ReadString(); Program.product.CPU_number = inputStream.ReadString(); Program.product.condition = inputStream.ReadString(); Program.product.OS = inputStream.ReadString(); Program.product.platform = inputStream.ReadString(); Program.product.HDD_size = inputStream.ReadString(); Program.product.HDD_speed = inputStream.ReadString(); Program.product.GPU_Type = inputStream.ReadString(); Program.product.optical_drive = inputStream.ReadString(); Program.product.Audio_type = inputStream.ReadString(); Program.product.LAN = inputStream.ReadString(); Program.product.WIFI = inputStream.ReadString(); Program.product.width = inputStream.ReadString(); Program.product.height = inputStream.ReadString(); Program.product.depth = inputStream.ReadString(); Program.product.weight = inputStream.ReadString(); Program.product.moust_type = inputStream.ReadString(); Program.product.power = inputStream.ReadString(); Program.product.webcam = inputStream.ReadString(); } catch (Exception exp) { MessageBox.Show("ERROR: " + exp.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } //cleanup inputStream.Close(); inputStream.Dispose(); } } catch (IOException ioexception) { MessageBox.Show("ERROR: " + ioexception.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception exception) { MessageBox.Show("ERROR: " + exception.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } ProductInfoForm_Activated(sender, e); } }
private void openToolStripMenuItem1_Click(object sender, EventArgs e) { // Configure ProductOpenFile Dialogue ProductOpenFileDialog.FileName = "Product.txt"; ProductOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); ProductOpenFileDialog.Filter = "Text File (*.txt)|*txt|All Files (*.*)|*.*"; // Open ProductOpenFile Dialogue var result = ProductOpenFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { try { using (StreamReader inputStream = new StreamReader( File.Open("ProductInfo.txt", FileMode.Open))) { // getting content - From the file Program.product.productID = short.Parse(inputStream.ReadLine()); Program.product.cost = decimal.Parse(inputStream.ReadLine());; Program.product.manufacturer = 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.CPU_number = 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.HDD_speed = 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(); inputStream.Close(); inputStream.Dispose(); } } catch (IOException exception) { // Error Message if failed to get the file MessageBox.Show("Error:" + exception.Message, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// this is the event handler for the click event of the open tool strip menu item /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void openToolStripMenuItem_Click(object sender, EventArgs e) { // configure the file dialog ProductOpenFileDialog.FileName = "Product.txt"; ProductOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); ProductOpenFileDialog.Filter = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*"; // open the file dialog var result = ProductOpenFileDialog.ShowDialog(); if (result != DialogResult.Cancel) { try { // Open your stream to read using (StreamReader inputStream = new StreamReader( File.Open(ProductOpenFileDialog.FileName, FileMode.Open))) { // Read stuff into the Student class try { Program.product.productID = short.Parse(inputStream.ReadLine()); Program.product.cost = decimal.Parse(inputStream.ReadLine()); Program.product.manufacturer = 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.CPU_number = 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.HDD_speed = 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(); NextButton_Click(sender, e); } catch (FormatException exception) { MessageBox.Show("Error:" + exception.Message, "Format Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // cleanup inputStream.Close(); inputStream.Dispose(); //automatically click next to next form } } catch (IOException exception) { MessageBox.Show("Error: " + exception.Message, "File I/O Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { //this is to handle the exception when the user clicks the cancel button when loading //the file from the Start Form if (ProductIDButton.Text == "0") { MessageBox.Show("Please restart your order!", "Load Order Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Warning); Program.Forms[FormNames.START_FORM].Show(); this.Hide(); } } }