private void saveGeneralInfo_MouseUp(object sender, EventArgs e) { int id = 1; if (comboBoxNrDays.SelectedIndex < 0) { MessageBox.Show("Number of working days is required!", "Information", MessageBoxButton.OK, MessageBoxImage.Warning); } if (cmbPeriodsperDay.SelectedIndex < 0) { MessageBox.Show("Number of periods/hours per day is required!", "Information", MessageBoxButton.OK, MessageBoxImage.Warning); } if (cmbMinNrLecturesperDay.SelectedIndex < 0) { MessageBox.Show("Number of minimum periods/hours per day is required!", "Information", MessageBoxButton.OK, MessageBoxImage.Warning); } if (cmbMaxNrLecturesperDay.SelectedIndex < 0) { MessageBox.Show("Number of maximum periods/hours per day is required!", "Information", MessageBoxButton.OK, MessageBoxImage.Warning); } string values = " number_of_days='" + comboBoxNrDays.SelectedValue + "', periods_per_day='" + cmbPeriodsperDay.SelectedValue + "', min_daily_lectures='" + cmbMinNrLecturesperDay.SelectedValue + "', max_daily_lectures='" + cmbMaxNrLecturesperDay.SelectedValue + "', editor='" + txtEditor.Text + "'"; int result = DBConnection.Update("general_info", values, id); if (result > 0) { MessageBox.Show("Successfully updated Info!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } }
private void saveTeacher_MouseUp(object sender, EventArgs e) { if (txtName.Text.Length == 0) { MessageBox.Show("Teacher name is required!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (txtSurname.Text.Length == 0) { MessageBox.Show("Teacher surname is required!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } if(txtEmail.Text.Length > 0 && !Regex.IsMatch(txtEmail.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$")) { MessageBox.Show("Please enter a valid email!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (txtId.Text.Length == 0) { string code = null; for (int i = 1; i < 1000; i++) { code = "t" + i.ToString("000"); DataView data = DBConnection.Select("teachers", "'*'", " code = '" + code + "'").DefaultView; if (data.Count == 0) break; } string values = "'" + txtName.Text + "', '" + txtSurname.Text + "', '" + txtTitle.Text + "', '" + txtEmail.Text + "', '" + txtPhone.Text + "', '" + code.ToString() + "', '" + txtNote.Text + "'"; int result = DBConnection.Create("teachers", "name, surname, title, email, phone, code, note", values); if (result > 0) { MessageBox.Show("Successfully created new Teacher!", "Information", MessageBoxButton.OK); txtId.Text = result.ToString(); } } else if (Convert.ToInt32(txtId.Text) > 0) { string values = "name='" + txtName.Text + "', surname='" + txtSurname.Text + "', title='" + txtTitle.Text + "', email='" + txtEmail.Text + "', phone='" + txtPhone.Text + "', code='" + txtCode.Text + "', note='" + txtNote.Text + "'"; int result = DBConnection.Update("teachers", values, Convert.ToInt32(txtId.Text)); if (result > 0) MessageBox.Show("Successfully updated Teacher!", "Information", MessageBoxButton.OK); } }
private void saveDepartment_MouseUp(object sender, EventArgs e) { try { if (txtName.Text == null || txtName.Text == "") { MessageBox.Show("Study program name is required!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (int.Parse(comboBox.SelectedIndex.ToString()) < 0) { MessageBox.Show("Please select study program's faculty!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (txtId.Text == "") { string values = "'" + txtName.Text + "', '" + comboBox.SelectedValue + "'"; int result = DBConnection.Create("departments", "name, faculty_id", values); if (result > 0) { MessageBox.Show("Successfully created new study program!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } } else if (Convert.ToInt32(txtId.Text) > 0) { string values = " name='" + txtName.Text + "', faculty_id='" + comboBox.SelectedValue + "'"; int result = DBConnection.Update("departments", values, Convert.ToInt32(txtId.Text)); if (result > 0) { MessageBox.Show("Successfully updated study program!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } } Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void updateCourseNames() { DataTable data = DBConnection.RAW_Select("Select c.name, p.groups, c.lecture_group, c.numeric_group, c.laboratory_group, c.id from courses c" + " JOIN courses p on c.base_parent_code = p.code Where c.base_parent_code IS not null"); if (data.Rows.Count != 0) { foreach (DataRow row in data.Rows) { string name = row.ItemArray[0].ToString().Split(new string[] { "_Gr" }, StringSplitOptions.None)[0]; string grField = ""; if (Convert.ToInt32(row.ItemArray[1].ToString()) > 1) { grField += " Gr. "; } else { grField += " "; } string lab = row.ItemArray[4].ToString(); string num = row.ItemArray[3].ToString(); string lect = row.ItemArray[2].ToString(); if (lab != null && lab != "") { name += grField + row.ItemArray[4].ToString(); } else if (num != null && num != "") { name += grField + row.ItemArray[3].ToString(); } else if (lect != null && lect != "" && grField != " ") { string group = grField + row.ItemArray[2].ToString().Split('r')[1]; name += group; } DBConnection.Update(" courses ", " name='" + name + "' ", Convert.ToInt32(row.ItemArray[5].ToString())); } } }
private void OnDoubleClick(object sender, MouseButtonEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed && e.ClickCount == 2) { foreach (UControl child in childs) { if (child.Clicked == "true") { if (comboBoxRooms.SelectedIndex != -1) { if (child.ControlAssigned == "false" && child.BlockedAssigned != "true") { //check if clicked period is a red position string cCode = txtCode.Text; int day = int.Parse(child.Column) - 1; int startPeriod = int.Parse(child.Row) - 1; string rCode = ""; string query = " SELECT code FROM rooms WHERE id=" + comboBoxRooms.SelectedValue; DataTable res = DBConnection.RAW_Select(query); ArrayList result = new ArrayList(); foreach (DataRow r in res.Rows) { rCode = r.ItemArray[0].ToString(); } string values = "'" + cCode + "', '" + rCode + "', '" + day + "', '" + startPeriod + "'"; string table = "timetable_" + getCurrentSemester(); DataView data = DBConnection.Select(table, "'*'", " course_code = '" + cCode + "'").DefaultView; if (data.Count == 0) { int createdId = DBConnection.Create(table, "course_code, room_code, day, start_period", values); } else { string vals = "room_code='" + rCode + "', day='" + day + "', start_period='" + startPeriod + "'"; int createdId = DBConnection.Update(table, vals, 0, " course_code='" + cCode + "'"); } MessageBox.Show("Class was placed successfully!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); Close(); break; } else { MessageBox.Show("Class can not be placed at this position!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); child.Clicked = "false"; break; } } else { MessageBox.Show("Please select a room first!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); child.Clicked = "false"; break; } } } } }
private void saveRoom_MouseUp(object sender, EventArgs e) { try { if (txtName.Text == null || txtName.Text == "") { MessageBox.Show("Room name is required!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (txtSize.Text == null || txtSize.Text == "") { MessageBox.Show("Room size is required!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (int.Parse(comboBox.SelectedIndex.ToString()) < 0) { MessageBox.Show("Please select building!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (txtId.Text == "") { string code = null; for (int i = 1; i < 1000; i++) { code = "r" + i.ToString("000"); DataView data = DBConnection.Select("rooms", "'*'", " code = '" + code + "'").DefaultView; if (data.Count == 0) { break; } } string values = "'" + txtName.Text + "', '" + Convert.ToInt32(txtSize.Text) + "', '" + code.ToString() + "', '" + comboBox.SelectedValue + "', '" + txtNote.Text + "'"; int result = DBConnection.Create("rooms", "name, size, code, building_id, note", values); if (result > 0) { MessageBox.Show("New room has been successfully created!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } } else if (Convert.ToInt32(txtId.Text) > 0) { string values = " name='" + txtName.Text + "', size='" + Convert.ToInt32(txtSize.Text) + "', code='" + txtCode.Text + "', building_id='" + comboBox.SelectedValue + "', note='" + txtNote.Text + "'"; int result = DBConnection.Update("rooms", values, Convert.ToInt32(txtId.Text)); if (result > 0) { MessageBox.Show("Room has been successfully updated!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } } Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }