/// <summary>
        /// This Open File Event when Open from menu is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //configure the file dialog
            ProductInfoOpenFileDialog.FileName         = "Product.txt";
            ProductInfoOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            ProductInfoOpenFileDialog.Filter           = "Text Files (*.txt)|*.txt| All Files{*.*)|*.*";

            //open the file dialog
            var result = ProductInfoOpenFileDialog.ShowDialog();

            if (result != DialogResult.Cancel)
            {
                try
                {
                    //Open the stream for reading
                    using (StreamReader inputStream = new StreamReader(File.Open(ProductInfoOpenFileDialog.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();
                        LoadDatatoTextBox();
                    }
                }
                catch (IOException exception)
                {
                    MessageBox.Show("ERROR" + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Beispiel #2
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ProductInfoOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            ProductInfoOpenFileDialog.FileName         = "Product.txt";
            ProductInfoOpenFileDialog.Filter           = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";

            var result = ProductInfoOpenFileDialog.ShowDialog();

            if (result != DialogResult.Cancel)
            {
                using (StreamReader inputStream = new StreamReader(
                           File.Open(ProductInfoOpenFileDialog.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.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();

                    NextButton.Enabled = true;
                }
            }
        }
        /// <summary>
        /// Load saved product data from user selected file
        /// read selected file and generate new selectedProduct object
        /// with all required fileds.
        /// </summary>
        private void LoadProductFromFile()
        {
            try
            {
                var result = ProductInfoOpenFileDialog.ShowDialog();

                if (result != DialogResult.Cancel)
                {
                    StreamReader streamReader = new StreamReader(ProductInfoOpenFileDialog.FileName);

                    string line = streamReader.ReadLine();

                    if (!string.IsNullOrEmpty(line))
                    {
                        string[] data = line.Split(',');

                        if (data.Length == 16)
                        {
                            Program.selectedProduct           = new Product();
                            Program.selectedProduct.productID = Convert.ToInt16(data[0]);
                            Program.selectedProduct.condition = data[1];
                            Program.selectedProduct.cost      = Convert.ToDecimal(data[2]);

                            Program.selectedProduct.platform     = data[3];
                            Program.selectedProduct.OS           = data[4];
                            Program.selectedProduct.manufacturer = data[5];
                            Program.selectedProduct.model        = data[6];

                            Program.selectedProduct.RAM_size   = data[7];
                            Program.selectedProduct.screensize = data[8];
                            Program.selectedProduct.HDD_size   = data[9];
                            Program.selectedProduct.CPU_brand  = data[10];
                            Program.selectedProduct.CPU_number = data[11];
                            Program.selectedProduct.GPU_Type   = data[12];
                            Program.selectedProduct.CPU_type   = data[13];
                            Program.selectedProduct.CPU_speed  = data[14];
                            Program.selectedProduct.webcam     = data[15];
                        }
                    }

                    streamReader.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Failed to Load Data!",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }