Esempio n. 1
0
        /// <summary>
        /// This is the event handler for the openToolStrip menu item click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //configure the file dialog
            ComputerOpenFileDialog.FileName         = "Product.txt";
            ComputerOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            ComputerOpenFileDialog.Filter           = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*";

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

            if (result != DialogResult.Cancel)
            {
                try
                {
                    //open file stream and read it
                    using (StreamReader inputStream = new StreamReader(
                               File.Open(ComputerOpenFileDialog.FileName, FileMode.Open)))
                    {
                        //read things from the file
                        Program.computer.ProductID    = int.Parse(inputStream.ReadLine());
                        Program.computer.Cost         = decimal.Parse(inputStream.ReadLine());
                        Program.computer.Manufacturer = inputStream.ReadLine();
                        Program.computer.Model        = inputStream.ReadLine();
                        Program.computer.Memory       = inputStream.ReadLine();
                        Program.computer.LCDType      = inputStream.ReadLine();
                        Program.computer.CPUBrand     = inputStream.ReadLine();
                        Program.computer.CPUType      = inputStream.ReadLine();
                        Program.computer.CPUSpeed     = inputStream.ReadLine();
                        Program.computer.CPUNumber    = inputStream.ReadLine();
                        Program.computer.Condition    = inputStream.ReadLine();
                        Program.computer.OS           = inputStream.ReadLine();
                        Program.computer.Platform     = inputStream.ReadLine();
                        Program.computer.HDDSize      = inputStream.ReadLine();
                        Program.computer.GPUType      = inputStream.ReadLine();
                        Program.computer.AudioType    = 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.Information);
                }
            }
        }
        private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // configure the file dialog
            ComputerOpenFileDialog.FileName         = "computer.txt";
            ComputerOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            ComputerOpenFileDialog.Filter           = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*";

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

            if (result != DialogResult.Cancel)
            {
                // Open your stream to read
                using (StreamReader inputStream = new StreamReader(
                           File.Open(ComputerOpenFileDialog.FileName, FileMode.Open)))
                {
                    // Read stuff into the Student class
                    Program.product.productID    = short.Parse(inputStream.ReadLine());
                    Program.product.condition    = inputStream.ReadLine();
                    Program.product.cost         = decimal.Parse(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();

                    // cleanup
                    inputStream.Close();
                    inputStream.Dispose();

                    ProductInfoForm_Activated(sender, e);
                }
            }
        }