public FormSecretary_AddOrRemoveLecture(int _id, string _password) { InitializeComponent(); string department; List <string> coursesProperties = new List <string>(); List <int> coursesID = new List <int>(); List <int> lecturesID = new List <int>(); id = _id; password = _password; department = SQLFunctions.getUsersDepartment(id); coursesProperties = SQLFunctions.findCoursePropertiesByDepartment(department); for (int i = 1; i < coursesProperties.Count; i += 9) { coursesID.Add(Convert.ToInt32(coursesProperties[i])); } for (int i = 0; i < coursesID.Count; i++) { lecturesID = SQLFunctions.findLecturesIDsForCourse(coursesID[i]); for (int j = 0; j < lecturesID.Count; j++) { lectureIDS.Add(lecturesID[j]); comboBox_Lectures.Items.Add(SQLFunctions.covertLectureIDtoLectureName(lecturesID[j]) + " " + lecturesID[j]); } } comboBox_Lectures.Items.Add("All"); this.AcceptButton = button_accept; textBox_StartTime.MaxLength = 2; textBox_EndTime.MaxLength = 2; textBox_day.MaxLength = 2; textBox_month.MaxLength = 2; textBox_year.MaxLength = 2; comboBox_AddRemove.DropDownStyle = ComboBoxStyle.DropDownList; comboBox_Lectures.DropDownStyle = ComboBoxStyle.DropDownList; }
private void button_accept_Click(object sender, EventArgs e) { int lectureID; List <int> studentIDs = new List <int>(); string dayForConstraints; string month; if (comboBox_AddRemove.SelectedIndex == 0) { if (verify_details() == true) { SQLFunctions.addChange(textBox_title.Text, textBox_description.Text, Convert.ToInt32(textBox_StartTime.Text), Convert.ToInt32(textBox_EndTime.Text), Convert.ToInt32(textBox_day.Text), Convert.ToInt32(textBox_month.Text), Convert.ToInt32(comboBox_year.Text), lectureIDS[comboBox_Lectures.SelectedIndex]); MessageBox.Show("Lesson was successfuly added"); } } else if (comboBox_AddRemove.SelectedIndex == 1) { lectureID = lectureIDS[comboBox_Lectures.SelectedIndex]; SQLFunctions.addChange(textBox_title.Text, textBox_description.Text, Convert.ToInt32(label_startTime.Text), Convert.ToInt32(label_endTime.Text), Convert.ToInt32(comboBox_day.Text), Convert.ToInt32(comboBox_month.Text), Convert.ToInt32(comboBox_year.Text), lectureID); DateTime day = new DateTime(Convert.ToInt32(comboBox_year.Items[comboBox_year.SelectedIndex]), Convert.ToInt32(comboBox_month.Items[comboBox_month.SelectedIndex]), Convert.ToInt32(comboBox_day.Items[comboBox_day.SelectedIndex])); month = comboBox_month.Items[comboBox_month.SelectedIndex].ToString(); if ((Convert.ToInt32(comboBox_day.Items[comboBox_day.SelectedIndex])) < 10) { dayForConstraints = "0" + comboBox_day.Items[comboBox_day.SelectedIndex].ToString(); } else { dayForConstraints = comboBox_day.Items[comboBox_day.SelectedIndex].ToString(); } if ((Convert.ToInt32(comboBox_month.Items[comboBox_day.SelectedIndex])) < 10) { month = "0" + month; } if (day > (new DateTime(Convert.ToInt32(day.Year), 03, 05)) && day < (new DateTime(Convert.ToInt32(day.Year), 6, 15))) { SQLFunctions.addConstraint(SQLFunctions.getLecturerIDByLecturerName(SQLFunctions.findLecturerNameByLectureID(lectureID)), day.DayOfWeek.ToString(), (label_startTime.Text + ":00").ToString(), (label_endTime.Text + ":00").ToString(), textBox_description.Text.ToString(), SQLFunctions.findLecturerNameByLectureID(lectureID), (dayForConstraints + "/" + month + "/" + comboBox_year.Items[comboBox_year.SelectedIndex].ToString()), "B", (SQLFunctions.covertLectureIDtoLectureName(lectureIDS[comboBox_Lectures.SelectedIndex])).ToString()); } else if (day > new DateTime(Convert.ToInt32(day.Year), 10, 30) && day < new DateTime(Convert.ToInt32(day.Year), 2, 4)) { SQLFunctions.addConstraint(SQLFunctions.getLecturerIDByLecturerName(SQLFunctions.findLecturerNameByLectureID(lectureID)), day.DayOfWeek.ToString(), (label_startTime.Text + ":00").ToString(), (label_endTime.Text + ":00").ToString(), textBox_description.Text.ToString(), SQLFunctions.findLecturerNameByLectureID(lectureID), (dayForConstraints + "/" + month + "/" + comboBox_year.Items[comboBox_year.SelectedIndex].ToString()), "A", (SQLFunctions.covertLectureIDtoLectureName(lectureIDS[comboBox_Lectures.SelectedIndex])).ToString()); } MessageBox.Show("Lesson was successfuly removed"); } else if (comboBox_AddRemove.SelectedIndex == 2) { if (verify_details() == true) { DateTime day = new DateTime(Convert.ToInt32(comboBox_year.Items[comboBox_year.SelectedIndex]), Convert.ToInt32(textBox_month.Text), Convert.ToInt32(textBox_day.Text)); month = textBox_month.Text.ToString(); dayForConstraints = textBox_day.Text.ToString(); if (Convert.ToInt32(textBox_day.Text) < 10) { if (!textBox_day.Text.Contains('0')) { dayForConstraints = "0" + textBox_day.Text; } } if (Convert.ToInt32(textBox_month.Text) < 10) { if (!textBox_month.Text.Contains('0')) { month = "0" + textBox_month.Text; } } SQLFunctions.addChange(textBox_title.Text, textBox_description.Text, Convert.ToInt32(textBox_StartTime.Text), Convert.ToInt32(textBox_EndTime.Text), Convert.ToInt32(textBox_day.Text), Convert.ToInt32(textBox_month.Text), Convert.ToInt32(comboBox_year.Text), 0); if (day > new DateTime(Convert.ToInt32(day.Year), 3, 5) && day < new DateTime(Convert.ToInt32(day.Year), 6, 15)) { SQLFunctions.addConstraint("0", day.DayOfWeek.ToString(), (textBox_StartTime.Text + ":00").ToString(), (textBox_EndTime.Text + ":00").ToString(), textBox_description.Text.ToString(), "", (dayForConstraints + "/" + month + "/" + comboBox_year.Items[comboBox_year.SelectedIndex].ToString()), "B", "General"); } else if (day > new DateTime(Convert.ToInt32(day.Year), 10, 30) && day < new DateTime(Convert.ToInt32(day.Year), 2, 4)) { SQLFunctions.addConstraint("0", day.DayOfWeek.ToString(), (textBox_StartTime.Text + ":00").ToString(), (textBox_EndTime.Text + ":00").ToString(), textBox_description.Text.ToString(), "", (dayForConstraints + "/" + month + "/" + comboBox_year.Items[comboBox_year.SelectedIndex].ToString()), "A", "General"); } MessageBox.Show("Event was successfuly Added"); } } foreach (Control c in this.Controls) { if ((c.GetType() == typeof(TextBox)) || (c.GetType() == typeof(ComboBox))) { c.Text = ""; } } }