コード例 #1
0
 /// <summary>
 /// This method opens file when users click the open menu or load a saved file
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void ClickOpenToolStripMenuItem(object sender, EventArgs e)
 {
     try
     {
         string       filename;
         DialogResult result;
         OpenProductFileDialog.Filter           = "Text Files (*.txt)|*.txt|All files (*.*)|*.*";
         OpenProductFileDialog.FileName         = "";
         OpenProductFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
         result = OpenProductFileDialog.ShowDialog();
         if (result == DialogResult.OK)
         {
             filename = OpenProductFileDialog.FileName;
             Stream objStreamDeSerialize = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
             _selectedRowData = (Product)_objBinaryFormatter.Deserialize(objStreamDeSerialize);
             SettingTextFromData();
             //    MessageBox.Show("File Empty - No data to Read", "Error Reading File", MessageBoxButtons.OK, MessageBoxIcon.Error);
             NextButtonEnable();
             //this._reader.Close();   //flushes the buffer and read the files
         }
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception.Message);
         MessageBox.Show("Error Reading File", "File Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #2
0
        /// <summary>
        /// Event handler to handle click on the tool strip menu items
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string            filename;
            ToolStripMenuItem item = sender as ToolStripMenuItem;

            switch (item.Name)
            {
            case "selectAnotherProductToolStripMenuItem":
                this.Hide();
                this.previousForm.Show();
                break;

            case "openToolStripMenuItem":
                OpenProductFileDialog.Filter           = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
                OpenProductFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
                OpenProductFileDialog.FileName         = "Product.txt";
                if (OpenProductFileDialog.ShowDialog() == DialogResult.OK)
                {
                    filename = OpenProductFileDialog.FileName;
                    try
                    {
                        this._reader = new StreamReader(filename);

                        if (this._reader.Peek() != -1)
                        {
                            ProductIdTextBox.Text     = this._reader.ReadLine();
                            ConditionTextBox.Text     = this._reader.ReadLine();
                            CostTextBox.Text          = this._reader.ReadLine();
                            PlatformTextBox.Text      = this._reader.ReadLine();
                            OSTextBox.Text            = this._reader.ReadLine();
                            ManufacturerTextBox.Text  = this._reader.ReadLine();
                            ModelTextBox.Text         = this._reader.ReadLine();
                            MemoryTextBox.Text        = this._reader.ReadLine();
                            LCDSizeTextBox.Text       = this._reader.ReadLine();
                            HDDTextBox.Text           = this._reader.ReadLine();
                            CPUBrandTextBox.Text      = this._reader.ReadLine();
                            CPUNumberTextBox.Text     = this._reader.ReadLine();
                            GPUTypeTextBox.Text       = this._reader.ReadLine();
                            CPUTypeTextBox.Text       = this._reader.ReadLine();
                            CPUSpeedTextBox.Text      = this._reader.ReadLine();
                            WebCamTextBox.Text        = this._reader.ReadLine();
                            ServiceClass.selectedId   = Convert.ToInt32(ProductIdTextBox.Text);
                            ServiceClass.condition    = ConditionTextBox.Text;
                            ServiceClass.cost         = Convert.ToDecimal(CostTextBox.Text);
                            ServiceClass.platform     = PlatformTextBox.Text;
                            ServiceClass.os           = OSTextBox.Text;
                            ServiceClass.manufacturer = ManufacturerTextBox.Text;
                            ServiceClass.model        = ModelTextBox.Text;
                            ServiceClass.ram          = MemoryTextBox.Text;
                            ServiceClass.lcdSize      = LCDSizeTextBox.Text;
                            ServiceClass.hdd          = HDDTextBox.Text;
                            ServiceClass.cpuBrand     = CPUBrandTextBox.Text;
                            ServiceClass.cpuNumber    = CPUNumberTextBox.Text;
                            ServiceClass.gpuType      = GPUTypeTextBox.Text;
                            ServiceClass.cpuType      = CPUTypeTextBox.Text;
                            ServiceClass.cpuSpeed     = CPUSpeedTextBox.Text;
                            ServiceClass.webCam       = WebCamTextBox.Text;
                        }
                        else
                        {
                            MessageBox.Show("File Empty - No data to Read", "Error Reading File", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        this._reader.Close();
                    }
                    catch (Exception exception)
                    {
                        Debug.WriteLine(exception.Message);
                        MessageBox.Show("Error Reading File", "File Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                if (ProductIdTextBox.Text == "0")
                {
                    MessageBox.Show("No Data Found!!Please select product from previous form!!", "No Product Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.previousForm.Show();
                    this.Hide();
                }
                break;

            case "saveToolStripMenuItem":
                SaveProductFileDialog.Filter           = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
                SaveProductFileDialog.FileName         = "Product.txt";
                SaveProductFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
                if (SaveProductFileDialog.ShowDialog() == DialogResult.OK)
                {
                    filename = SaveProductFileDialog.FileName;
                    try
                    {
                        this._writer = new StreamWriter(filename);
                        this._writer.WriteLine(ProductIdTextBox.Text);
                        this._writer.WriteLine(ConditionTextBox.Text);
                        this._writer.WriteLine(CostTextBox.Text);
                        this._writer.WriteLine(PlatformTextBox.Text);
                        this._writer.WriteLine(OSTextBox.Text);
                        this._writer.WriteLine(ManufacturerTextBox.Text);
                        this._writer.WriteLine(ModelTextBox.Text);
                        this._writer.WriteLine(MemoryTextBox.Text);
                        this._writer.WriteLine(LCDSizeTextBox.Text);
                        this._writer.WriteLine(HDDTextBox.Text);
                        this._writer.WriteLine(CPUBrandTextBox.Text);
                        this._writer.WriteLine(CPUNumberTextBox.Text);
                        this._writer.WriteLine(GPUTypeTextBox.Text);
                        this._writer.WriteLine(CPUTypeTextBox.Text);
                        this._writer.WriteLine(CPUSpeedTextBox.Text);
                        this._writer.WriteLine(WebCamTextBox.Text);
                        this._writer.Close();
                        MessageBox.Show("File Written Successfully", "File Status",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception exception)
                    {
                        Debug.WriteLine(exception.Message);
                        MessageBox.Show("Error  Writing File", "File Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                break;

            case "exitToolStripMenuItem":
                this.Close();
                break;
            }
        }
コード例 #3
0
        public void loadData()
        {
            string filename;

            OpenProductFileDialog.Filter           = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            OpenProductFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            OpenProductFileDialog.FileName         = "Product.txt";
            if (OpenProductFileDialog.ShowDialog() == DialogResult.OK)
            {
                filename = OpenProductFileDialog.FileName;
                try
                {
                    this._reader = new StreamReader(filename);

                    if (this._reader.Peek() != -1)
                    {
                        ProductIdTextBox.Text    = this._reader.ReadLine();
                        ConditionTextBox.Text    = this._reader.ReadLine();
                        CostTextBox.Text         = this._reader.ReadLine();
                        PlatformTextBox.Text     = this._reader.ReadLine();
                        OSTextBox.Text           = this._reader.ReadLine();
                        ManufacturerTextBox.Text = this._reader.ReadLine();
                        ModelTextBox.Text        = this._reader.ReadLine();
                        MemoryTextBox.Text       = this._reader.ReadLine();
                        LCDSizeTextBox.Text      = this._reader.ReadLine();
                        HDDTextBox.Text          = this._reader.ReadLine();
                        CPUBrandTextBox.Text     = this._reader.ReadLine();
                        CPUNumberTextBox.Text    = this._reader.ReadLine();
                        GPUTypeTextBox.Text      = this._reader.ReadLine();
                        CPUTypeTextBox.Text      = this._reader.ReadLine();
                        CPUSpeedTextBox.Text     = this._reader.ReadLine();
                        WebCamTextBox.Text       = this._reader.ReadLine();
                        UserProduct.productID    = short.Parse(ProductIdTextBox.Text);
                        UserProduct.condition    = ConditionTextBox.Text;
                        UserProduct.cost         = Convert.ToDecimal(CostTextBox.Text);
                        UserProduct.platform     = PlatformTextBox.Text;
                        UserProduct.OS           = OSTextBox.Text;
                        UserProduct.manufacturer = ManufacturerTextBox.Text;
                        UserProduct.model        = ModelTextBox.Text;
                        UserProduct.RAM_size     = MemoryTextBox.Text;
                        UserProduct.screensize   = LCDSizeTextBox.Text;
                        UserProduct.HDD_size     = HDDTextBox.Text;
                        UserProduct.CPU_brand    = CPUBrandTextBox.Text;
                        UserProduct.CPU_number   = CPUNumberTextBox.Text;
                        UserProduct.GPU_Type     = GPUTypeTextBox.Text;
                        UserProduct.CPU_type     = CPUTypeTextBox.Text;
                        UserProduct.CPU_speed    = CPUSpeedTextBox.Text;
                        UserProduct.webcam       = WebCamTextBox.Text;
                    }
                    else
                    {
                        MessageBox.Show("File Empty - No data to Read", "Error Reading File", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    this._reader.Close();
                }
                catch (Exception exception)
                {
                    Debug.WriteLine(exception.ToString());
                    Debug.WriteLine(exception.Message);
                    MessageBox.Show("Error Reading File", "File Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// This is handler for Open MenuStrip click event for Open Existing File
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Create Variables
            DialogResult result;
            string       fileName;

            //Assign Properties to OpenDialog
            OpenProductFileDialog.Filter           = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            OpenProductFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            OpenProductFileDialog.Title            = "Open File";
            result = OpenProductFileDialog.ShowDialog();

            //If result is Ok then Open Saved File
            if (result == DialogResult.OK)
            {
                //pass value to the FileName
                fileName = OpenProductFileDialog.FileName;
                try
                {
                    this._reader = new StreamReader(fileName);

                    //If there is something to read
                    if (_reader.Peek() != -1)
                    {
                        //Read all saved data from buffer using ReadLine
                        //Read data of Product Basic Information
                        ProductIDTextBox.Text = this._reader.ReadLine();
                        ConditionTextBox.Text = this._reader.ReadLine();
                        CostTextBox.Text      = this._reader.ReadLine();

                        //Read data of Product Basic Information from Product Info GroupBox
                        PlatformTextBox.Text     = this._reader.ReadLine();
                        ManufacturerTextBox.Text = this._reader.ReadLine();
                        OSTextBox.Text           = this._reader.ReadLine();
                        ModelTextBox.Text        = this._reader.ReadLine();

                        //Read data of Tech Specs Information from Tech Specs GroupBox
                        MemoryTextBox.Text    = this._reader.ReadLine();
                        CPUBrandTextBox.Text  = this._reader.ReadLine();
                        CPUTypeTextBox.Text   = this._reader.ReadLine();
                        LCDSizeTextBox.Text   = this._reader.ReadLine();
                        CPUNumberTextBox.Text = this._reader.ReadLine();
                        CPUSpeedTextBox.Text  = this._reader.ReadLine();
                        HDDTextBox.Text       = this._reader.ReadLine();
                        GPUTypeTextBox.Text   = this._reader.ReadLine();
                        WebCamTextBox.Text    = this._reader.ReadLine();

                        _productID = Convert.ToInt32(ProductIDTextBox.Text);
                    }
                    else
                    {
                        MessageBox.Show("File Empty -No data to read", "Error Reading File",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    this._reader.Close();   //Flushes the Buffer
                }
                catch (Exception exception)
                {
                    Debug.WriteLine(exception.Message);
                    MessageBox.Show("Error Reading File", "File Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                //Fetch Product Id from database and store into _productID variable
                Program.product = (from product in dbProduct.products
                                   where product.productID == _productID
                                   select product).FirstOrDefault();
            }
        }