private void pictureBox1_Click(object sender, EventArgs e) { try { string date = monthCalendar1.SelectionStart.ToShortDateString(); if (MessageBox.Show("Are you sure you want to add this message?", "Insert to DataBase", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { db.InsertContstraints(GlobalVariables.User_ID, Days.Text, StartHours.Text, EndHours.Text, Notes.Text, date, Semester.Text, Course.Text); this.Hide(); main m = new B_8.main(); m.Show(); } } catch (Exception exp) { MessageBox.Show("Colud not connect to sql"); } finally { if (db.isconnected == true) { db.CloseConnection(); } } }
private double NumberOfCourse() { try { reader = db.Select("*", "NewSchedule", "LecturerName", GlobalVariables.Full_Name); while (reader.Read()) { if (reader["Semester"].ToString().Trim().Equals(GlobalVariables.Semester)) { if (!(Courses.Contains(reader["Name"].ToString().Trim()))) { Courses.Add(reader["Name"].ToString().Trim()); } } } reader.Close(); return(check_credits()); } catch (Exception exp) { MessageBox.Show("Could not connect to sql"); return(0); } finally { if (db.isconnected == true) { db.CloseConnection(); } } }
private void Exam_Deatails_Load(object sender, EventArgs e) { try { reader = db.Select("*", "NewSchedule"); while (reader.Read()) { if (reader["LecturerName"].ToString().Trim().Equals(btn.Name) && reader["Name"].ToString().Trim().Equals(btn.Text.Substring(0, btn.Text.Length - 4))) { if (reader["NumOfExam"].ToString().Trim() == (btn.Text[btn.Text.Length - 1].ToString())) { label1.Text += btn.Text.Substring(0, btn.Text.Length - 4); label2.Text += reader["LecturerName"].ToString().Trim(); label3.Text += reader["StartHour"].ToString().Trim() + ":00" + "-" + reader["EndHour"].ToString().Trim() + ":00"; label4.Text += reader["Day"].ToString().Trim() + " , " + reader["Date"].ToString().Trim(); } } } reader.Close(); } catch (Exception exp) { MessageBox.Show("Colud not connect to sql"); } finally { if (db.isconnected == true) { db.CloseConnection(); } } }
private void CANCEL_Click(object sender, EventArgs e) { try { db.Update("true", "Constraints", "Seen", (constrains_details[0])); this.Close(); } catch (Exception exp) { MessageBox.Show("Colud not connect to sql"); } finally { if (db.isconnected == true) { db.CloseConnection(); } } }
private void button1_Click(object sender, EventArgs e) { string Email = textBox1.Text; if (Email != null) { SqlDataReader read = db.Select("*", "NewUsers"); try { while (read.Read()) {/*"*****@*****.**" */ if (Email == read["Email"].ToString().Trim()) { SmtpClient client = new SmtpClient("Smtp.gmail.com", 587); client.EnableSsl = true; client.Timeout = 10000; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "aA123456"); MailMessage mm = new MailMessage("*****@*****.**", Email, "Your password", read["Password"].ToString().Trim()); mm.BodyEncoding = UTF8Encoding.UTF8; mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure; client.Send(mm); MessageBox.Show("We Found Your Email: " + Email + "\ncheck your Email.."); this.Hide(); login ss = new login(); ss.Show(); IsFound = true; break; } } if (!IsFound) { MessageBox.Show("Email: " + Email + " NOT Found!"); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } finally { if (db.isconnected == true) { db.CloseConnection(); } } } }
private void confirm_Click(object sender, EventArgs e) { try { if (comboBox1.Text != "Course" && (string)comboBox2.SelectedItem != "ID") { if (MessageBox.Show("Are you sure?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { db.Connect(); SqlCommand cmd = new SqlCommand("DELETE FROM NewCourses WHERE Name = @id", db.cnn); cmd.Parameters.AddWithValue("@id", comboBox1.Text); if (db.cnn.State.ToString().Equals("Closed")) { db.cnn.Open(); } cmd.ExecuteNonQuery(); DataBase.numofcourses--; MessageBox.Show("The course " + comboBox1.Text + " has been deleted"); new DeleteCourse().Show(); } } } catch (Exception exp) { MessageBox.Show(exp.Message.ToString()); MessageBox.Show("Colud not connect to sql"); } finally { if (db.isconnected == true) { db.CloseConnection(); } } }
private void button1_Click(object sender, EventArgs e) { bool check = false; string name = textBox1.Text; string credits = textBox3.Text; string lectureH = textBox4.Text; string practiceH = textBox5.Text; string receiptH = textBox6.Text; string semester = comboBox2.Text; string Year = comboBox4.Text; string department = Department_combo.Text; string unit = Unit_combo.Text; string PrereqiD = PreReqID.Text; try { if (name != null && credits != null && lectureH != null && practiceH != null && receiptH != null && Year != null && semester != null && department != null && unit != null) { if (Int32.Parse(lectureH) > 0 & Int32.Parse(practiceH) > 0 & Int32.Parse(receiptH) > 0) // & Int32.Parse(Year) > 0) { check = db.InsertCourse(name, credits, lectureH, practiceH, receiptH, semester, Year, department, unit, PrereqiD); } } if (check) { MessageBox.Show("The course" + " " + name + " has been added successfully"); ClearAll(); } else { MessageBox.Show("Error occured!"); } } catch (Exception exp) { MessageBox.Show("Could not insert"); } finally { if (db.isconnected == true) { db.CloseConnection(); } } }
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { try { listView1.Items.Clear(); string sem = comboBox2.Text; if (sem != null) { SqlDataReader read = db.Select("*", "NewCourses"); while (read.Read()) { if (read["Semester"].ToString().Trim() == sem) { if (read["Department"].ToString().Trim() == GlobalVariables.User_Department) { ListViewItem row = new ListViewItem(read["Name"].ToString().Trim()); row.SubItems.Add(read["ID"].ToString().Trim()); row.SubItems.Add(read["Credits"].ToString().Trim()); row.SubItems.Add(read["LectureHour"].ToString().Trim()); row.SubItems.Add(read["PracticeHour"].ToString().Trim()); row.SubItems.Add(read["ReceptionHour"].ToString().Trim()); row.SubItems.Add(read["Semester"].ToString().Trim()); row.SubItems.Add(read["Year"].ToString().Trim()); row.SubItems.Add(read["Department"].ToString().Trim()); listView1.Items.Add(row); } } } read.Close(); } } catch (Exception) { MessageBox.Show("Could not connect to sl"); } finally { if (db.isconnected == true) { db.CloseConnection(); } } }
private void Course_Filtering_Suitability_Load(object sender, EventArgs e) { try { db = new DataBase(); if (GlobalVariables.User_Permission == "Secretary") { textBox1.Visible = false; list_of_dep = new List <string>(); comboBox2.Text = "Depratment"; comboBox2.Enabled = false; combobox3 = new ComboBox(); combobox3.Location = textBox1.Location; combobox3.Size = textBox1.Size; tableLayoutPanel2.Controls.Add(combobox3); reader = db.Select("Department", "Courses"); while (reader.Read()) { if (!list_of_dep.Contains(reader[0].ToString().Trim())) { list_of_dep.Add(reader[0].ToString().Trim()); } } reader.Close(); foreach (string item in list_of_dep) { combobox3.Items.Add(item); } } } catch (Exception exp) { MessageBox.Show("Colud not connect to sql"); } finally { if (db.isconnected == true) { db.CloseConnection(); } } }
private void Year_C_SelectedIndexChanged(object sender, EventArgs e) { try { if (Year_Department.Text != null) { combo_box.Enabled = true; } if (combo_box.Text != null) { read = db.Select("*", "NewCourses", Year_Department.Text, combo_box.Text); listView1.Items.Clear(); while (read.Read()) { ListViewItem item = new ListViewItem(read["Name"].ToString().Trim()); item.SubItems.Add(read["ID"].ToString().Trim()); item.SubItems.Add(read["Credits"].ToString().Trim()); item.SubItems.Add(read["LectureHour"].ToString().Trim()); item.SubItems.Add(read["PracticeHour"].ToString().Trim()); item.SubItems.Add(read["ReceptionHour"].ToString().Trim()); item.SubItems.Add(read["Semester"].ToString().Trim()); item.SubItems.Add(read["Year"].ToString().Trim()); item.SubItems.Add(read["Department"].ToString().Trim()); listView1.Items.Add(item); } read.Close(); } } catch (Exception exp) { MessageBox.Show("Could not connect to sql"); } finally { if (db.isconnected == true) { db.CloseConnection(); } } }
private void ShowClassInSchedule_Load(object sender, EventArgs e) { try { this.CenterToScreen(); reader = db.Select("*", "NewSchedule", "LectureID", btn.Name); while (reader.Read()) { if (reader["Type"].ToString().Trim().Equals(btn.Text)) { label1.Visible = false; label3.Text += reader["Date"].ToString().Trim(); label2.Text += reader["Classroom"].ToString().Trim(); label4.Text += reader["StartHour"].ToString().Trim() + ":00" + "-" + reader["EndHour"].ToString().Trim() + ":00"; label5.Text += " " + btn.Text; } else { label1.Text += reader["Name"].ToString().Trim(); label3.Text += reader["Date"].ToString().Trim(); label2.Text += reader["Classroom"].ToString().Trim(); label4.Text += reader["StartHour"].ToString().Trim() + ":00" + "-" + reader["EndHour"].ToString().Trim() + ":00"; label5.Text += " " + reader["Type"].ToString().Trim(); } } reader.Close(); } catch (Exception) { MessageBox.Show("Could not connect to sl"); } finally { if (db.isconnected == true) { db.CloseConnection(); } } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { try { db.cnn.Open(); SqlCommand counter = new SqlCommand("select count(ID) From NewUsers", db.cnn); reader = counter.ExecuteReader(); reader.Read(); count = Int32.Parse(reader[0].ToString().Trim()); reader.Close(); db.cnn.Close(); lecturer = new Lecturer[count]; reader = db.Select("*", "NewUsers"); for (int i = 0; i < count; i++) { reader.Read(); lecturer[i] = new Lecturer(); lecturer[i].FirstName = reader["FirstName"].ToString().Trim(); lecturer[i].LastName = reader["LastName"].ToString().Trim(); lecturer[i].Password = reader["Password"].ToString().Trim(); lecturer[i].Email = reader["Email"].ToString().Trim(); lecturer[i].Role = reader["Role"].ToString().Trim(); lecturer[i].Department = reader["Department"].ToString().Trim(); lecturer[i].Unit = reader["Unit"].ToString().Trim(); } reader.Close(); } catch (Exception exp) { MessageBox.Show("Could not connect to sql"); } finally { db.CloseConnection(); } }
private void ClassDepartment_Load(object sender, EventArgs e) { try { CenterToScreen(); int i = 0, j = 0; read = db.Select("*", "Classrooms"); while (read.Read()) { Button btn = new Button(); btn.Dock = DockStyle.Fill; btn.FlatStyle = FlatStyle.Flat; btn.Text = read["Name"].ToString().Trim(); btn.Click += new EventHandler(button_click); buttons.Add(btn); tableLayoutPanel2.Controls.Add(btn, j, i); j++; if (j % 11 == 0) { i++; } } read.Close(); } catch (Exception exp) { MessageBox.Show("Could not connect to sql"); } finally { if (db.isconnected == true) { db.CloseConnection(); } } }
private void permission() { try { bool flag = false; bool flag1 = true; if (GlobalVariables.User_Permission == "Secretary") { tableLayoutPanel4.Visible = true; Load_Buttons(); Init(0, "", a); SqlDataReader reader = db.Select("*", "NewSchedule"); while (reader.Read()) { if (reader["Semester"].ToString().Trim().Equals(GlobalVariables.Semester)) { if (reader["Type"].ToString().Trim().Equals("Exam") || reader["Type"].ToString().Trim().Equals("Meeting")) { string Sun_date = buttons[1].Text.Substring(6 + 1); DateTime tempDate = new DateTime(Int32.Parse(Sun_date.Substring(6)), Int32.Parse(Sun_date.Substring(3, 2)), Int32.Parse(Sun_date.Substring(0, 2))); string Exam_date = reader["Date"].ToString().Trim(); DateTime Week_from_now = tempDate.AddDays(6); DateTime ExamDate = new DateTime(Int32.Parse(Exam_date.Substring(6)), Int32.Parse(Exam_date.Substring(3, 2)), Int32.Parse(Exam_date.Substring(0, 2))); int diff = ExamDate.DayOfYear - tempDate.DayOfYear; int diff2 = ExamDate.DayOfYear - Week_from_now.DayOfYear; if (diff >= 0) { if (diff2 < 0) { flag = true; } } } if (flag == true || (reader["Type"].ToString().Trim() != "Exam" && reader["Type"].ToString().Trim() != "Meeting")) { 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]].BackgroundImage = Resources.blue_surface_with_creases_1160_191; buttons[button_indexes[i]].BackgroundImageLayout = ImageLayout.Stretch; buttons[button_indexes[i]].FlatStyle = FlatStyle.Flat; buttons[button_indexes[i]].FlatAppearance.BorderSize = 1; buttons[button_indexes[i]].Text = "..."; buttons[button_indexes[i]].ForeColor = Color.Green; buttons[button_indexes[i]].Image = Resources.User_Group_icon; buttons[button_indexes[i]].ImageAlign = ContentAlignment.MiddleLeft; flag = false; } } } } reader.Close(); } if (GlobalVariables.User_Permission == "Lecturer" || GlobalVariables.User_Permission == "Head Of Department") { Build(0);//id == 0 for lec or head of dep } if (GlobalVariables.User_Permission == "Practitioner") { Build(1); } if (Spec_date != new DateTime(1111, 11, 11)) { double d = (this.Spec_date - today).TotalDays; Init(Convert.ToInt32(d), this.Spec_date.DayOfWeek.ToString(), this.Spec_date); } } catch (Exception e) { MessageBox.Show(e.Message); MessageBox.Show("Could not connect to sql"); } finally { if (db.isconnected == true) { db.CloseConnection(); } } }
public Quat_date(Button btn) { try { string data, day, houer; b = new Button(); b = btn; this.Show(); CenterToScreen(); InitializeComponent(); comboBox2.Visible = false; label3.Text = "" + btn.Text + " is a: "; label6.Text = "Time of use in " + btn.Text; button1.Visible = false; // read = db.Select("Name", "Classrooms"); read = db.Select("*", "Classrooms"); while (read.Read()) { if (read["Name"].ToString().Trim().Equals(btn.Text)) { label5.Text = read["Type"].ToString().Trim(); } } read.Close(); read2 = db.Select("*", "NewSchedule", "Classroom", btn.Text); while (read2.Read()) { startH = Int32.Parse(read2["StartHour"].ToString().Trim()); endH = Int32.Parse(read2["EndHour"].ToString().Trim()); Shour = read2["StartHour"].ToString().Trim() + ":" + "00"; Ehour = read2["EndHour"].ToString().Trim() + ":" + "00"; if (read2["StartHour"].ToString().Length == 1) { Shour = "0" + Shour; } if (read2["EndHour"].ToString().Length == 1) { Ehour = "0" + Ehour; } if (read2["Classroom"].ToString().Trim().Equals(btn.Text)) { ListViewItem lv = new ListViewItem(read2["Date"].ToString()); lv.SubItems.Add(read2["Day"].ToString().Trim()); lv.SubItems.Add(Shour + "-" + Ehour); listView1.Items.Add(lv); counter++; } } read2.Close(); } catch (Exception) { MessageBox.Show("Could not connect to sql"); } finally { if (db.isconnected == true) { db.CloseConnection(); } } }
private void pictureBox1_Click(object sender, EventArgs e) { try { string filter1 = comboBox2.Text; string search = textBox1.Text; listView1.Items.Clear(); if (GlobalVariables.User_Permission != "Secretary") { reader = db.Select("*", "Courses"); while (reader.Read()) { if (reader[filter1].ToString().Trim().Contains(search.Trim())) { ListViewItem row = new ListViewItem(reader["Name"].ToString().Trim()); row.SubItems.Add(reader["ID"].ToString().Trim()); row.SubItems.Add(reader["Credits"].ToString().Trim()); row.SubItems.Add(reader["LectureHour"].ToString().Trim()); row.SubItems.Add(reader["PracticeHour"].ToString().Trim()); row.SubItems.Add(reader["ReceptionHour"].ToString().Trim()); row.SubItems.Add(reader["Semester"].ToString().Trim()); row.SubItems.Add(reader["Year"].ToString().Trim()); row.SubItems.Add(reader["Department"].ToString().Trim()); listView1.Items.Add(row); } } reader.Close(); if (listView1.Items.Count == 0) { MessageBox.Show("Could Not Found " + search + " in " + filter1, "Failed!", MessageBoxButtons.OK); } } else { string comboboxValue = combobox3.Text; reader = db.Select("*", "Courses", "Department", comboboxValue); while (reader.Read()) { ListViewItem row = new ListViewItem(reader["Name"].ToString().Trim()); row.SubItems.Add(reader["ID"].ToString().Trim()); row.SubItems.Add(reader["Credits"].ToString().Trim()); row.SubItems.Add(reader["LectureHour"].ToString().Trim()); row.SubItems.Add(reader["PracticeHour"].ToString().Trim()); row.SubItems.Add(reader["ReceptionHour"].ToString().Trim()); row.SubItems.Add(reader["Semester"].ToString().Trim()); row.SubItems.Add(reader["Year"].ToString().Trim()); row.SubItems.Add(reader["Department"].ToString().Trim()); listView1.Items.Add(row); } reader.Close(); } } catch (Exception exp) { MessageBox.Show("Colud not connect to sql"); } finally { if (db.isconnected == true) { db.CloseConnection(); } } }
private void button1_Click(object sender, EventArgs e) { try { first = textBox1.Text; last = textBox2.Text; ////username = first + last[0] + last[1]; reader = db.Select("*", "NewUsers", "Email", textBox6.Text); int count = 0, count_id = 0; while (reader.Read()) { if (reader["Email"].ToString().Trim().Equals(textBox6.Text)) { count++; } } reader.Close(); reader = db.Select("*", "NewUsers", "ID", textBox3.Text); while (reader.Read()) { if (reader["ID"].ToString().Trim().Equals(textBox3.Text)) { count_id++; } } reader.Close(); if (count == 0 && count_id == 0) { reader.Close(); id = textBox3.Text; password = textBox4.Text; password_again = textBox5.Text; email = textBox6.Text; Role = role.Text; department = Department_comboBox.Text; unit = comboBox1.Text; if (password == password_again) { db.InsertUser(first, last, id, email, password, Role, department, unit); this.Hide(); main ss = new main(); ss.Show(); } else { MessageBox.Show("Wrong input!\n The passwords are Different"); } } else if (count != 0) { MessageBox.Show("Wrong input!\n Email already exist in the system"); } else if (count_id != 0) { MessageBox.Show("Wrong input!\n ID already exist in the system"); } } catch (Exception) { MessageBox.Show("Could not connect to sql"); } finally { if (db.isconnected == true) { db.CloseConnection(); } } }
private void button1_Click(object sender, EventArgs e) { DateTime end_of_exams_semester_a = new DateTime(DateTime.Today.Year, 3, 5); DateTime end_of_semester_b = new DateTime(DateTime.Today.Year, 6, 15); DateTime end_of_exams_semester_b = new DateTime(DateTime.Today.Year, 7, 15); SqlDataReader read = db.Select("*", "NewUsers"); try { if (textBox1.Text == "") { MessageBox.Show("Logon Failure: unknown ID or invalid password"); return; } if (SQLFunctions.checkExistsEmail(textBox1.Text)) { if (SQLFunctions.checkLogIn(Convert.ToInt32(SQLFunctions.getIDbyEmail(textBox1.Text)), textBox2.Text)) { this.Hide(); if (SQLFunctions.checkRole(Convert.ToInt32(SQLFunctions.getIDbyEmail(textBox1.Text.ToString()))) == "Student") { FormMenuStudent mainForm = new FormMenuStudent(Convert.ToInt32(SQLFunctions.getIDbyEmail(textBox1.Text.ToString())), textBox2.Text); mainForm.Show(); } else if (SQLFunctions.checkRole(Convert.ToInt32(SQLFunctions.getIDbyEmail(textBox1.Text.ToString()))) == "SecretaryA") { FormMenuSecretary mainForm = new FormMenuSecretary(Convert.ToInt32(SQLFunctions.getIDbyEmail(textBox1.Text.ToString())), textBox2.Text); mainForm.Show(); } else if (SQLFunctions.checkRole(Convert.ToInt32(SQLFunctions.getIDbyEmail(textBox1.Text.ToString()))) == "Exam Department") { FormMenuExamDepartment mainForm = new FormMenuExamDepartment(); mainForm.Show(); } else if (SQLFunctions.checkRole(Convert.ToInt32(SQLFunctions.getIDbyEmail(textBox1.Text.ToString()))) == "Admin") { FormMenuAdmin mainForm = new FormMenuAdmin(); mainForm.Show(); } else { while (read.Read()) { if (textBox1.Text == read["Email"].ToString().Trim() && textBox2.Text == read["Password"].ToString().Trim()) { ID = read["ID"].ToString(); // GlobalVariables h;.ID = read["ID"].ToString().Trim(); GlobalVariables.User_ID = read["ID"].ToString().Trim(); GlobalVariables.Full_Name = read["FirstName"].ToString().Trim() + " " + read["LastName"].ToString().Trim(); GlobalVariables.User_Permission = read["Role"].ToString().Trim(); GlobalVariables.User_Department = read["Department"].ToString().Trim(); GlobalVariables.User_Email = read["Email"].ToString().Trim(); if (monthCalendar1.MaxDate >= DateTime.Today && monthCalendar1.MinDate <= DateTime.Today) { GlobalVariables.Semester = "A"; } else if (monthCalendar1.MaxDate < DateTime.Today && DateTime.Today <= end_of_exams_semester_a) { GlobalVariables.Semester = "Exam Period semester A"; } else if (end_of_exams_semester_a < DateTime.Today && DateTime.Today <= end_of_semester_b) { GlobalVariables.Semester = "B"; } else if (end_of_exams_semester_b >= DateTime.Today && DateTime.Today > end_of_semester_b) { GlobalVariables.Semester = "Exam Period semester B"; } else { GlobalVariables.Semester = "Summer Semester"; } IsFound = true; GlobalVariables.maxDate = monthCalendar1.MaxDate; GlobalVariables.minDate = monthCalendar1.MinDate; break; } GlobalVariables.maxDate = monthCalendar1.MaxDate; GlobalVariables.minDate = monthCalendar1.MinDate; } read.Close(); if (!IsFound) { MessageBox.Show("You have to sign up before"); textBox1.Text = ""; textBox2.Text = ""; return; } this.Hide(); main m = new main(); m.Show(); } } else { MessageBox.Show("Logon Failure: unknown ID or invalid password"); } } else { MessageBox.Show("Logon Failure: unknown ID or invalid password"); } } catch (SqlException exception) { MessageBox.Show(exception.ToString()); } finally { if (db.isconnected == true) { db.CloseConnection(); } } }
private void Show_Exams_Load(object sender, EventArgs e) { try { string name; if (GlobalVariables.User_Permission != "Secretary") { toolStripComboBox1.Visible = false; label1.Text = Calc_Dates(); this.CenterToScreen(); reader = db.Select("*", "NewSchedule"); while (reader.Read()) { if (reader["LecturerName"].ToString().Trim().Equals(GlobalVariables.Full_Name)) { if (reader["Type"].ToString().Trim().Equals("Exam")) { Button button1 = new Button(); button1.Size = new Size(panel1.Width, 70); button1.Font = new Font("Georgia", 14, FontStyle.Bold); button1.TextAlign = ContentAlignment.MiddleLeft; button1.Text = reader["Name"].ToString().Trim() + " - " + reader["NumOfExam"].ToString().Trim(); button1.Image = Resources.Actions_go_next_icon; button1.ForeColor = Color.White; button1.ImageAlign = ContentAlignment.MiddleRight; //button1.BackColor = Color.White; button1.BackgroundImage = Resources.blue_surface_with_creases_1160_191; button1.BackgroundImageLayout = ImageLayout.Stretch; button1.Click += new EventHandler(button1_Click); button1.Location = new Point(0, button_height); button_height += 70; button1.Name = reader["LecturerName"].ToString().Trim(); button1.Cursor = Cursors.Hand; panel1.Controls.Add(button1); } } } reader.Close(); } else { this.CenterToScreen(); toolStripComboBox1.Visible = true; label1.Text = Calc_Dates(); reader = db.Select("*", "NewUsers"); while (reader.Read()) { if (reader["Role"].ToString().Trim() != "Secretary") { name = reader["FirstName"].ToString().Trim() + " " + reader["LastName"].ToString().Trim(); toolStripComboBox1.Items.Add(name); } } reader.Close(); } } catch (Exception) { MessageBox.Show("Could not connect to sql"); } finally { if (db.isconnected == true) { db.CloseConnection(); } } }