private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                bool isvalidated = validatefields();
                if (isvalidated)
                {
                    NotAvailableTime notAvailableTime = new NotAvailableTime();
                    notAvailableTime.Lecturer   = LectuercomboBox.SelectedItem.ToString();
                    notAvailableTime.GroupID    = GroupcomboBox.SelectedItem.ToString();
                    notAvailableTime.SubGroupID = SubGroupcomboBox.SelectedItem.ToString();
                    notAvailableTime.SessionID  = SessionIDtextBox.Text;
                    notAvailableTime.Time       = TimetextBox.Text;


                    string message = NotAvailableTimeController.AddNotAvailableTime(notAvailableTime);
                    MessageBox.Show(message);
                    clear();
                }
                else
                {
                    MessageBox.Show("please fill in all fields!");
                }
            }
            catch (NullReferenceException nre)
            {
                MessageBox.Show("please fill in all fields!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 private void dataGridView6_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
 {
     try
     {
         if (e.RowIndex >= 0)
         {
             DataGridViewRow  row = dataGridView6.Rows[e.RowIndex];
             int              NotAvailableTimeID = Convert.ToInt32(row.Cells[0].Value.ToString());
             NotAvailableTime notAvailableTime   = NotAvailableTimeController.SelectedNotAvailableTime(NotAvailableTimeID);
             if (notAvailableTime != null)
             {
                 Hidelabel55.Text = notAvailableTime.NotAvailableTimeID.ToString();
             }
             else
             {
                 Hidelabel55.Text = string.Empty;
             }
         }
     }
     catch (FormatException fe)
     {
         MessageBox.Show("no data selected");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        public static NotAvailableTime SelectedNotAvailableTime(int notAvailableTimeid)
        {
            string query = "SELECT NotAvailableTimeID, Lecturer, GroupID, SubGroupID, SessionID, Time " +
                           " FROM notavailabletime where NotAvailableTimeID  = " + notAvailableTimeid;
            MySqlConnection databaseConnection = new MySqlConnection(connectionString);
            MySqlCommand    commandDatabase    = new MySqlCommand(query, databaseConnection);

            commandDatabase.CommandTimeout = 60;
            MySqlDataReader reader;

            try
            {
                databaseConnection.Open();
                reader = commandDatabase.ExecuteReader();
                if (reader.HasRows)
                {
                    NotAvailableTime notAvailableTime = new NotAvailableTime();
                    if (reader.Read())
                    {
                        notAvailableTime.NotAvailableTimeID = reader.GetInt32(0);
                        notAvailableTime.Lecturer           = reader.GetString(1);
                        notAvailableTime.GroupID            = reader.GetString(2);
                        notAvailableTime.SubGroupID         = reader.GetString(3);
                        notAvailableTime.SessionID          = reader.GetString(4);
                        notAvailableTime.Time = reader.GetString(5);
                    }
                    return(notAvailableTime);
                }
                else
                {
                    Console.WriteLine("No rows found.");
                }
                databaseConnection.Close();
                return(null);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
        public static string AddNotAvailableTime(NotAvailableTime notavailabletime)
        {
            string query = "INSERT INTO notavailabletime(`Lecturer`,`GroupID`,`SubGroupID`," +
                           "`SessionID`,`Time`) " +
                           "VALUES " +
                           "('" + notavailabletime.Lecturer + "', '" + notavailabletime.GroupID + "', '" + notavailabletime.SubGroupID + "', '" + notavailabletime.SessionID + "', " +
                           "'" + notavailabletime.Time + "')";
            MySqlConnection databaseConnection = new MySqlConnection(connectionString);
            MySqlCommand    commandDatabase    = new MySqlCommand(query, databaseConnection);

            commandDatabase.CommandTimeout = 60;
            try
            {
                databaseConnection.Open();
                MySqlDataReader myReader = commandDatabase.ExecuteReader();
                databaseConnection.Close();
                return("User succesfully registered");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }