private void Save_btn_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (Male_radioButton.Checked == true)
                {
                    Sex = Male_radioButton.Text.Trim();
                }
                else if (Female_radioButton.Checked == true)
                {
                    Sex = Female_radioButton.Text.Trim();
                }



                if (Single_radioButton.Checked == true)
                {
                    Marital_Status = Single_radioButton.Text.Trim();
                }
                else if (Married_radioButton.Checked == true)
                {
                    Marital_Status = Married_radioButton.Text.Trim();
                }

                connection.Open();
                SqlCommand Studentscommand = connection.CreateCommand();
                Studentscommand.CommandType = CommandType.Text;
                Studentscommand.CommandText = "INSERT INTO [Staff Members] ([ID Number], [Staff Title]) VALUES (@IDNumber, @StaffTitle)";
                Studentscommand.Parameters.Add("@IDNumber", SqlDbType.VarChar, 8).Value = ID_Number.Text.Trim();
                Studentscommand.Parameters.Add("@StaffTitle", SqlDbType.VarChar).Value  = Stuff_Title.Text.Trim();
                Studentscommand.ExecuteNonQuery();



                var SecretKey = "b14ca5898a4e4133bbce2ea2315a1916";

                SqlCommand Userscommand = connection.CreateCommand();
                Userscommand.CommandType = CommandType.Text;
                Userscommand.CommandText = "INSERT INTO [System Users] ([ID_Number], [Full_Name], [Surname], [Sex], [Marital_Status], [School_Role], [Email_Address], [Password]) VALUES (@IDNumber, @FullName, @Surname, @Sex, @MaritalStatus, @SchoolRole, @EmailAddress, @Password)";
                Userscommand.Parameters.Add("@IDNumber", SqlDbType.VarChar, 8).Value   = ID_Number.Text.Trim();
                Userscommand.Parameters.Add("@FullName", SqlDbType.VarChar).Value      = Full_Name.Text.Trim();
                Userscommand.Parameters.Add("@Surname", SqlDbType.VarChar).Value       = Surname.Text.Trim();
                Userscommand.Parameters.Add("@Sex", SqlDbType.VarChar, 1).Value        = Sex;
                Userscommand.Parameters.Add("@MaritalStatus", SqlDbType.VarChar).Value = Marital_Status;
                Userscommand.Parameters.Add("@SchoolRole", SqlDbType.VarChar).Value    = "Staff Members";
                Userscommand.Parameters.Add("@EmailAddress", SqlDbType.VarChar).Value  = Email_Address.Text.Trim();
                Userscommand.Parameters.Add("@Password", SqlDbType.VarChar).Value      = EncryptString(SecretKey, Password.Text.Trim());
                Userscommand.ExecuteNonQuery();


                DialogResult dialogResult = MessageBox.Show("Do you wish to add another Stuff Member?", "Success", MessageBoxButtons.YesNo, MessageBoxIcon.Information);


                if (dialogResult == DialogResult.Yes)
                {
                    ID_Number.Text              = "";
                    Full_Name.Text              = "";
                    Surname.Text                = "";
                    Male_radioButton.Checked    = false;
                    Female_radioButton.Checked  = false;
                    Single_radioButton.Checked  = false;
                    Married_radioButton.Checked = false;
                    Sex                = "";
                    Marital_Status     = "";
                    Email_Address.Text = "";
                    Password.Text      = "";
                    Stuff_Title.Text   = "";
                    connection.Close();
                    ID_Number.Focus();
                }
                else
                {
                    connection.Close();
                    Staff_Interface.Administration_Portal AdministrationPortal = new Staff_Interface.Administration_Portal(AdminFirstName, AdminSurname, AdminRegNumber);
                    AdministrationPortal.Show();
                    Close();
                }
            }
            catch (Exception ex)
            {
                connection.Close();
                DialogResult dialogResult = MessageBox.Show("Data NOT saved....." + ex.Message, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation);

                if (dialogResult == DialogResult.Cancel)
                {
                    connection.Close();
                    Staff_Interface.Administration_Portal AdministrationPortal = new Staff_Interface.Administration_Portal(AdminFirstName, AdminSurname, AdminRegNumber);
                    AdministrationPortal.Show();
                    Close();
                }
            }
        }
        private void Save_btn_Click(object sender, EventArgs e)
        {
            try
            {
                if (Male_radioButton.Checked == true)
                {
                    Sex = Male_radioButton.Text.Trim();
                }
                else if (Female_radioButton.Checked == true)
                {
                    Sex = Female_radioButton.Text.Trim();
                }



                if (Single_radioButton.Checked == true)
                {
                    Marital_Status = Single_radioButton.Text.Trim();
                }
                else if (Married_radioButton.Checked == true)
                {
                    Marital_Status = Married_radioButton.Text.Trim();
                }

                //bool IsValidEmail(string email)
                //{
                //    try
                //    {
                //        var addr = new System.Net.Mail.MailAddress(email);
                //        return addr.Address == email;
                //    }
                //    catch
                //    {
                //        return false;
                //    }
                //}

                MemoryStream ms = new MemoryStream();
                Student_pictureBox.Image.Save(ms, Student_pictureBox.Image.RawFormat);
                byte[] imgByte = ms.ToArray();



                connection.Open();
                SqlCommand Studentscommand = connection.CreateCommand();
                Studentscommand.CommandType = CommandType.Text;
                Studentscommand.CommandText = "INSERT INTO [Students] ([ID_Number], [School], [Department], [Level]) VALUES (@IDNumber, @School, @Department, @Level)";
                Studentscommand.Parameters.Add("@IDNumber", SqlDbType.VarChar, 8).Value   = ID_Number.Text.Trim();
                Studentscommand.Parameters.Add("@School", SqlDbType.VarChar).Value        = School_comboBox.Text.Trim();
                Studentscommand.Parameters.Add("@Department", SqlDbType.VarChar, 3).Value = Department_comboBox.Text.Trim();
                Studentscommand.Parameters.Add("@Level", SqlDbType.VarChar, 3).Value      = Level_ComboBox.Text.Trim();
                Studentscommand.ExecuteNonQuery();



                var SecretKey = "b14ca5898a4e4133bbce2ea2315a1916";

                SqlCommand Userscommand = connection.CreateCommand();
                Userscommand.CommandType = CommandType.Text;
                Userscommand.CommandText = "INSERT INTO [System Users] ([ID_Number], [Full_Name], [Surname], [Sex], [Marital_Status], [Picture], [School_Role], [Email_Address], [Password]) VALUES (@IDNumber, @FullName, @Surname, @Sex, @MaritalStatus, @Picture, @SchoolRole, @EmailAddress, @Password)";
                Userscommand.Parameters.Add("@IDNumber", SqlDbType.VarChar, 8).Value   = ID_Number.Text.Trim();
                Userscommand.Parameters.Add("@FullName", SqlDbType.VarChar).Value      = Full_Name.Text.Trim();
                Userscommand.Parameters.Add("@Surname", SqlDbType.VarChar).Value       = Surname.Text.Trim();
                Userscommand.Parameters.Add("@Sex", SqlDbType.VarChar, 1).Value        = Sex;
                Userscommand.Parameters.Add("@MaritalStatus", SqlDbType.VarChar).Value = Marital_Status;
                Userscommand.Parameters.Add("@Picture", SqlDbType.VarBinary).Value     = imgByte;
                Userscommand.Parameters.Add("@SchoolRole", SqlDbType.VarChar).Value    = "Student";
                Userscommand.Parameters.Add("@EmailAddress", SqlDbType.VarChar).Value  = Email_Address.Text.Trim();
                Userscommand.Parameters.Add("@Password", SqlDbType.VarChar).Value      = EncryptString(SecretKey, Password.Text.Trim());
                Userscommand.ExecuteNonQuery();

                #region Generate QR Code
                QRCoder.QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator();
                var qrData = qrGenerator.CreateQrCode(ID_Number.Text.Trim(), QRCoder.QRCodeGenerator.ECCLevel.H);
                var qrCode = new QRCoder.QRCode(qrData);
                var image  = qrCode.GetGraphic(150);
                pictureBoxQrImage.Image = image;

                #region Saving QR Code
                SaveFileDialog sf = new SaveFileDialog
                {
                    Filter = "JPG(*.JPG)|*.jpg"
                };

                if (sf.ShowDialog() == DialogResult.OK)
                {
                    pictureBoxQrImage.Image.Save(sf.FileName);
                }
                #endregion

                #endregion

                DialogResult dialogResult = MessageBox.Show("Do you wish to add another Student?", "Success", MessageBoxButtons.YesNo, MessageBoxIcon.Information);


                if (dialogResult == DialogResult.Yes)
                {
                    ID_Number.Text              = "";
                    School_comboBox.Text        = "";
                    Department_comboBox.Text    = "";
                    Level_ComboBox.Text         = "";
                    Full_Name.Text              = "";
                    Surname.Text                = "";
                    Male_radioButton.Checked    = false;
                    Female_radioButton.Checked  = false;
                    Single_radioButton.Checked  = false;
                    Married_radioButton.Checked = false;
                    Sex                      = "";
                    Marital_Status           = "";
                    imgByte                  = null;
                    Email_Address.Text       = "";
                    Password.Text            = "";
                    Student_pictureBox.Image = null;
                    connection.Close();
                    ID_Number.Focus();
                }
                else
                {
                    connection.Close();
                    Staff_Interface.Administration_Portal AdministrationPortal = new Staff_Interface.Administration_Portal(AdminFirstName, AdminSurname, AdminRegNumber);
                    AdministrationPortal.Show();
                    Close();
                }
            }
            catch (Exception ex)
            {
                connection.Close();
                DialogResult dialogResult = MessageBox.Show("Data NOT saved..." + ex.Message, "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation);

                if (dialogResult == DialogResult.Cancel)
                {
                    connection.Close();
                    Staff_Interface.Administration_Portal AdministrationPortal = new Staff_Interface.Administration_Portal(AdminFirstName, AdminSurname, AdminRegNumber);
                    AdministrationPortal.Show();
                    Close();
                }
            }
        }