private void openBinaryFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // configuration for openFileDialog
            StudentOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            StudentOpenFileDialog.FileName         = "Student.dat";
            StudentOpenFileDialog.Filter           = "Text Files (*.dat)|*.dat|All Files (*.*)|*.*";

            var result = StudentOpenFileDialog.ShowDialog();

            if (result != DialogResult.Cancel)
            {
                // open file stream to read
                using (BinaryReader inputStream = new BinaryReader(
                           File.Open(StudentOpenFileDialog.FileName, FileMode.Open)))
                {
                    // read stuff from the file into the Student object
                    Program.student.id        = int.Parse(inputStream.ReadString());
                    Program.student.StudentID = inputStream.ReadString();
                    Program.student.FirstName = inputStream.ReadString();
                    Program.student.LastName  = inputStream.ReadString();

                    // cleanup
                    inputStream.Close();
                    inputStream.Dispose();
                }
                NextButton_Click(sender, e);
            }
        }
Beispiel #2
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // configure the file dialog
            StudentOpenFileDialog.FileName         = "Student.txt";                   //Default filename when a user doesnt change the name
            StudentOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); // default direcotory
            StudentOpenFileDialog.Filter           = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*";

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

            if (result != DialogResult.Cancel)
            {
                try
                {
                    // open the stream for reading
                    using (StreamReader inputStream = new StreamReader(
                               File.Open(StudentOpenFileDialog.FileName, FileMode.Open)))
                    {
                        // reading everything from your Student.txt file
                        Program.student.Id        = int.Parse(inputStream.ReadLine());
                        Program.student.StudentID = inputStream.ReadLine();
                        Program.student.FirstName = inputStream.ReadLine();
                        Program.student.LastName  = inputStream.ReadLine();

                        //cleanup
                        inputStream.Close();
                        inputStream.Dispose();
                    }
                    // explicitly open the file one the user chose open the file
                    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);
                }
            }
        }
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // configure the file dialog
            StudentOpenFileDialog.FileName         = "Student.txt";
            StudentOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            StudentOpenFileDialog.Filter           = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*";

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

            if (result != DialogResult.Cancel)
            {
                try
                {
                    // Open your stream to read
                    using (StreamReader inputStream = new StreamReader(
                               File.Open(StudentOpenFileDialog.FileName, FileMode.Open)))
                    {
                        // Read stuff into the Student class
                        Program.student.id        = int.Parse(inputStream.ReadLine());
                        Program.student.StudentID = inputStream.ReadLine();
                        Program.student.FirstName = inputStream.ReadLine();
                        Program.student.LastName  = 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 + "\nPlease select the appropriate file type", "File I/O Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void openBinaryFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // configure the file dialog
            StudentOpenFileDialog.FileName         = "Student.dat";
            StudentOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            StudentOpenFileDialog.Filter           = "Binary Files (*.dat)|*.dat| All Files (*.*)|*.*";

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

            if (result != DialogResult.Cancel)
            {
                try
                {
                    // Open the  streawm for reading
                    using (BinaryReader inputStream = new BinaryReader(
                               File.Open(StudentOpenFileDialog.FileName, FileMode.Open)))
                    {
                        // read from the file
                        Program.student.id        = int.Parse(inputStream.ReadString());
                        Program.student.StudentID = inputStream.ReadString();
                        Program.student.FirstName = inputStream.ReadString();
                        Program.student.LastName  = inputStream.ReadString();

                        // 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);
                }
            }
        }
Beispiel #5
0
        private void OpenToolStripButton_Click(object sender, EventArgs e)
        {
            //configure the file dialog
            StudentOpenFileDialog.FileName         = "Student.txt";
            StudentOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            StudentOpenFileDialog.Filter           = "Text files (*.txt)|*.txt| All files (*.*)|*.*";

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

            if (result != DialogResult.Cancel)
            {
                try
                {
                    //open stream for reading
                    using (StreamReader inputStream = new StreamReader(
                               File.Open(StudentOpenFileDialog.FileName, FileMode.Open)))
                    {
                        //Read stuff from the file into the Student object
                        Program.student.id        = int.Parse(inputStream.ReadLine());
                        Program.student.StudentID = inputStream.ReadLine();
                        Program.student.FirstName = inputStream.ReadLine();
                        Program.student.LastName  = inputStream.ReadLine();

                        //Cleanup
                        inputStream.Close();
                        inputStream.Dispose();
                    }
                    NextButton_Click(sender, e);
                }
                catch (Exception exception)
                {
                    Debug.WriteLine(exception.Message);

                    MessageBox.Show("Error " + exception.Message, "ERROR",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Beispiel #6
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StudentOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            StudentOpenFileDialog.FileName         = "Student.txt";
            StudentOpenFileDialog.Filter           = "Text Files (*.txt)|*.txt|All Files(*.*)| *.*";
            var result = StudentOpenFileDialog.ShowDialog();

            if (result != DialogResult.Cancel)
            {
                using (StreamReader inputStream = new StreamReader(
                           File.Open(StudentOpenFileDialog.FileName, FileMode.Open)))
                {
                    Program.student.ID        = int.Parse(inputStream.ReadLine());
                    Program.student.StudentID = inputStream.ReadLine();
                    Program.student.FirstName = inputStream.ReadLine();
                    Program.student.LastName  = inputStream.ReadLine();
                    inputStream.Close();
                    inputStream.Dispose();
                }
                NextButton_Click(sender, e);
            }
        }
        private void OpenBinaryFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //configure file dialog
            StudentOpenFileDialog.FileName         = "Student.dat";
            StudentOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            StudentOpenFileDialog.Filter           = "Binary Files (*.dat)|*.dat| All Files (*.*)|*.*";

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

            if (result != DialogResult.Cancel)
            {
                try
                {
                    using (BinaryReader InputStream = new BinaryReader(
                               File.Open(StudentOpenFileDialog.FileName, FileMode.Open)))
                    {
                        //Read stuff into the class
                        Program.student.id        = int.Parse(InputStream.ReadString());;
                        Program.student.StudentID = InputStream.ReadString();
                        Program.student.FirstName = InputStream.ReadString();
                        Program.student.LastName  = InputStream.ReadString();

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

                        NextButton_Click(sender, e);
                    }
                }
                catch (IOException exception)
                {
                    MessageBox.Show("Error: " + exception.Message, "File I/O Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw;
                }
            }
        }
        private void OpenToolStripButton_Click(object sender, EventArgs e)
        {
            //configure open file dialog
            StudentOpenFileDialog.FileName         = "Student.txt";
            StudentOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
            StudentOpenFileDialog.Filter           = "Text Files (*.txt)|*.txt| All Files (*.*)|*.*";

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

            if (result != DialogResult.Cancel)
            {
                using (StreamReader inputStream = new StreamReader(
                           File.Open("Student.txt", FileMode.Open)))
                {
                    try
                    {
                        //read file
                        Program.student.id        = int.Parse(inputStream.ReadLine());
                        Program.student.StudentID = inputStream.ReadLine();
                        Program.student.FirstName = inputStream.ReadLine();
                        Program.student.LastName  = inputStream.ReadLine();

                        inputStream.Close();
                        inputStream.Dispose();

                        GetDataButton_Click(sender, e);
                    }
                    catch (IOException exception)
                    {
                        MessageBox.Show("Error: " + exception.Message, "File I/O Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }