private void Build(int id) { try { tableLayoutPanel4.Visible = false; string temp1 = ""; if (id == 0) { temp1 = "Lecture"; } else { temp1 = "Practice"; } Load_Buttons(); Init(0, "", a); SqlDataReader reader = db.Select("*", "NewSchedule"); DataBase db2 = new DataBase(); string hour = " "; while (reader.Read()) { bool flag1 = true; if ((reader["LecturerName"].ToString().Trim().Equals(GlobalVariables.Full_Name) && (reader["Type"].ToString().Trim().Equals(temp1)) || (reader["Type"].ToString().Trim().Equals("ReceptionHours")) || reader["Type"].ToString().Trim().Equals("Meeting") || reader["Type"].ToString().Trim().Equals("Exam"))) { if (GlobalVariables.Semester.Equals(reader["Semester"].ToString().Trim()) || reader["Type"].ToString().Trim().Equals("Meeting")) { // reader2 = db2.Select("*", "Constraints"); while (reader2.Read()) { string Sche_hour = reader["StartHour"].ToString().Trim() + ":00" + "-" + reader["EndHour"].ToString().Trim() + ":00"; if ((reader["LecturerName"].ToString().Trim() == reader2["FullName"].ToString().Trim() && reader["Day"].ToString().Trim() == reader2["Days"].ToString().Trim() && (reader2["StartHours"].ToString().Trim() + "-" + reader2["EndHours"].ToString().Trim()) == Sche_hour && reader2["Approved"].ToString().Trim() == "true" && Spec_date.ToShortDateString() == reader2["Date"].ToString().Trim()) || check_spec_date(Spec_date, reader2["Date"].ToString().Trim())) { hour = reader2["StartHours"].ToString().Trim() + "-" + reader2["EndHours"].ToString().Trim(); flag1 = false; break; } } } reader2.Close(); if (flag1 == true) { reader2 = db2.Select("*", "Constraints"); while (reader2.Read()) { // if (reader["Type"].ToString().Trim().Equals("Exam") || reader["Type"].ToString().Trim().Equals("Meeting")) { if (ExamFilter(reader) != "Exam" && ExamFilter(reader) != "Meeting") { flag1 = false; } } if (flag1 == true) { button_indexes = get_button_index(reader["StartHour"].ToString().Trim() + ":00" + "-" + reader["EndHour"].ToString().Trim() + ":00", reader["Day"].ToString().Trim()); for (int i = 0; i < button_indexes.Length; i++) { buttons[button_indexes[i]].BackColor = Color.Green; if (reader["Type"].ToString().Trim() == "Meeting") { buttons[button_indexes[i]].Text = reader["Type"].ToString().Trim(); buttons[button_indexes[i]].Name = reader["LectureID"].ToString().Trim(); } else { buttons[button_indexes[i]].Text = reader["Name"].ToString().Trim(); } buttons[button_indexes[i]].Enabled = true; buttons[button_indexes[i]].FlatStyle = FlatStyle.Flat; buttons[button_indexes[i]].FlatAppearance.BorderSize = 1; buttons[button_indexes[i]].Click += new EventHandler(showClassDate); buttons[button_indexes[i]].Name = reader["LectureID"].ToString().Trim(); } } } reader2.Close(); } } } reader.Close(); } catch (Exception) { MessageBox.Show("Could not connect to sql"); } finally { if (db.isconnected == true) { db.CloseConnection(); } } }