public frmStudentView(string User)
        {
            InitializeComponent();

            //Filling the textboxes in order for the student to view his/her marks.
            Con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source = Students.accdb;
            Persist Security Info=False;";
            Con.Open();
            UserName = User;
            byte[]       ImageBytes;
            OleDbCommand Command = new OleDbCommand();

            Command.Connection  = Con;
            Command.CommandText = "select  FirstName,LastName,Passwords,tblStudents.StudentID,DOB,Mark1,Mark2,Mark3,Mark4,Mark5,Image,Address,Telephone,Gender from (tblStudents left join tblOtherInformation on tblStudents.StudentID=tblOtherInformation.StudentID) left join tblMarks on tblMarks.StudentID= tblStudents.StudentID where UserName='******'";
            OleDbDataReader Reader = Command.ExecuteReader();

            while (Reader.Read())
            {
                txtFirstName.Text  = Reader["FirstName"].ToString();
                txtLastName.Text   = Reader["LastName"].ToString();
                txtStudentID.Text  = Reader["StudentID"].ToString();
                txtDate.Text       = Convert.ToDateTime(Reader["DOB"].ToString()).ToString("yyyy/MM/dd");
                Mark[0]            = Reader["Mark1"].ToString();
                richtxtMarks.Text += Reader["Mark1"].ToString() + "\n";
                Mark[1]            = Reader["Mark2"].ToString();
                richtxtMarks.Text += Reader["Mark2"].ToString() + "\n";
                Mark[2]            = Reader["Mark3"].ToString();
                richtxtMarks.Text += Reader["Mark3"].ToString() + "\n";
                Mark[3]            = Reader["Mark4"].ToString();
                richtxtMarks.Text += Reader["Mark4"].ToString() + "\n";
                Mark[4]            = Reader["Mark5"].ToString();
                richtxtMarks.Text += Reader["Mark5"].ToString();
                txtPassword.Text   = Reader["Passwords"].ToString();
                txtAddress.Text    = Reader["Address"].ToString();
                txtTelephone.Text  = Reader["Telephone"].ToString();
                txtGender.Text     = Reader["Gender"].ToString();
                try
                {
                    ImageBytes = (byte[])Reader["Image"];
                    MemoryStream MS = new MemoryStream(ImageBytes, 0, ImageBytes.Length);
                    imgStudent.Image = Image.FromStream(MS, true);
                }
                catch { }
            }

            for (int i = 0; i < Mark.Length; i++)
            {
                Mark[i] = Mark[i].Replace(" ", "");
                if (Mark[i] == "")
                {
                    Array.Resize(ref Mark, i);
                    break;
                }
            }
            Marking Grading = new Marking();

            Grading.Calculation(Mark);
            txtAverage.Text = Grading._Average.ToString();
            txtLevel.Text   = Grading._Level.ToString();
            Con.Close();
        }
        public frmAdmin(bool Button, string User)
        {
            InitializeComponent();
            //Connecting to the database.
            Con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source = Students.accdb;
            Persist Security Info=False;";
            comboGender.Items.Add("Male");
            comboGender.Items.Add("Female");
            comboGender.Items.Add("Other");
            Buttons = Button;
            byte[] ImageBytes;
            UserName = User;
            if (Button == false)
            {
                //False means that the admin picked that he wanted to edit a user account.
                int NumberOfMarks = Mark.Length;
                btnSave.Text = "Save changes";
                Con.Open();
                OleDbCommand Command = new OleDbCommand();
                Command.Connection  = Con;
                Command.CommandText = "select  FirstName,LastName,Passwords,tblStudents.StudentID,DOB,Mark1,Mark2,Mark3,Mark4,Mark5,Image,Address,Telephone,Gender from (tblStudents left join tblOtherInformation on tblStudents.StudentID=tblOtherInformation.StudentID) left join tblMarks on tblMarks.StudentID= tblStudents.StudentID where UserName='******'";

                OleDbDataReader Reader = Command.ExecuteReader();
                while (Reader.Read())
                {
                    txtFirstName.Text  = Reader["FirstName"].ToString();
                    txtLastName.Text   = Reader["LastName"].ToString();
                    txtStudentID.Text  = Reader["StudentID"].ToString();
                    txtDate.Text       = Convert.ToDateTime(Reader["DOB"].ToString()).ToString("yyyy-MM-dd");
                    Mark[0]            = Reader["Mark1"].ToString();
                    richtxtMarks.Text += Reader["Mark1"].ToString() + "\n";
                    Mark[1]            = Reader["Mark2"].ToString();
                    richtxtMarks.Text += Reader["Mark2"].ToString() + "\n";
                    Mark[2]            = Reader["Mark3"].ToString();
                    richtxtMarks.Text += Reader["Mark3"].ToString() + "\n";
                    Mark[3]            = Reader["Mark4"].ToString();
                    richtxtMarks.Text += Reader["Mark4"].ToString() + "\n";
                    Mark[4]            = Reader["Mark5"].ToString();
                    richtxtMarks.Text += Reader["Mark5"].ToString();
                    txtPassword.Text   = Reader["Passwords"].ToString();
                    txtAddress.Text    = Reader["Address"].ToString();
                    txtTelephone.Text  = Reader["Telephone"].ToString();
                    comboGender.Text   = Reader["Gender"].ToString();
                    // http://stackoverflow.com/questions/9173904/byte-array-to-image-conversion and http://stackoverflow.com/questions/18998763/how-to-retrieve-binary-image-from-database-using-c-sharp-in-asp-net
                    // Changing the image into binary code is obtained from stackoverflow.
                    try
                    {
                        //Changing the stored binary into an image.
                        ImageBytes = (byte[])Reader["Image"];
                        MemoryStream MS = new MemoryStream(ImageBytes, 0, ImageBytes.Length);
                        imgStudent.Image = Image.FromStream(MS, true);
                    }
                    catch { }
                }
                //Detecting how many marks are available.
                for (int i = 0; i < Mark.Length; i++)
                {
                    Mark[i] = Mark[i].Replace(" ", "");
                    if (Mark[i] == "")
                    {
                        Array.Resize(ref Mark, i);
                        break;
                    }
                }
                Reader.Close();
                Marking Grading = new Marking();
                try
                {
                    //Calculating the average and level.
                    Grading.Calculation(Mark);
                    txtAverage.Text = Grading._Average.ToString();
                    txtLevel.Text   = Grading._Level.ToString();
                }
                catch { }
                Con.Close();
                Reader.Close();
            }
            if (Button == true)
            {
                //If the user decided to create a user, then it will a true.
                btnSave.Text         = "Create account";
                txtStudentID.Visible = false;
                lblStudentID.Visible = false;
                txtAverage.Visible   = false;
                txtLevel.Visible     = false;
                lblLevel.Visible     = false;
                lblAverage.Visible   = false;
            }
        }