public static Collection <Kurz> SelectByStudentAndOngoing(string idStudent) { using (Database db = new Database()) { db.Connect(); using (SqlCommand command = db.CreateCommand(SQL_COURSES_BY_STUDENT_ONGOING)) { command.Parameters.AddWithValue("@IdStudent", idStudent); SqlDataReader reader = db.Select(command); Collection <Kurz> kurzy = new Collection <Kurz>(); while (reader.Read()) { Kurz k = new Kurz(); int i = -1; k.Nazev = reader.GetString(++i); kurzy.Add(k); } return(kurzy); } } }
private void InitCourse(Kurz course) { COURSE_NAME.Text = course.Nazev; COURSE_DESC.Text = "Description: " + course.Popis; COURSE_CAPACITY.Text = "Capacity: " + course.Kapacita.ToString(); COURSE_SPECIALIZATION.Text = "Specialization: " + OborTable.SelectOne(course.IdObor).Nazev; AVG_MARK.Text = "Average mark: " + PisemkaTable.GetAvgMark(course.IdKurz).ToString(); ENDED.Text = "Ended: " + course.Ukoncen.ToString(); Collection <Pisemka> upcomingTests = PisemkaTable.SelectUpcomingTestsByCourse(course.IdKurz); Collection <Pisemka> pastTests = PisemkaTable.SelectPastTestsByCourse(course.IdKurz); UPCOMING_TESTS_LISTVIEW.Items.Clear(); PAST_TESTS_LISTVIEW.Items.Clear(); foreach (var t in pastTests) { ListViewItem i = new ListViewItem(t.IdPisemka.ToString()); i.SubItems.Add(t.DatumPisemky.ToShortDateString()); i.SubItems.Add(t.Znamka.ToString()); PAST_TESTS_LISTVIEW.Items.Add(i); } foreach (var t in upcomingTests) { ListViewItem i = new ListViewItem(t.IdPisemka.ToString()); i.SubItems.Add(t.DatumPisemky.ToShortDateString()); UPCOMING_TESTS_LISTVIEW.Items.Add(i); } }
private void UPDATE_BUTTON_Click(object sender, EventArgs e) { Kurz course = new Kurz(); course.IdKurz = this.idSelectedCourse; course.Nazev = NAME_VALUE.Text; course.Kapacita = Convert.ToInt32(CAPACITY_VALUE.Text); course.Popis = DETAIL_VALUE.Text; course.Vytvoren = START_DATE_DP.Value; course.IdVyucujici = this.idTeacher; if (SPECIALIZATION_CB.Text != null && SPECIALIZATION_CB.Text != "") { course.IdObor = OborTable.SelectOneByName(SPECIALIZATION_CB.Text).IdObor; } else { MessageBox.Show("Vyber obor!"); return; } if (course.Nazev != "" && course.Kapacita > 0 && course.Popis != "") { KurzTable.Update(course); } InitView(); InitCourse(course); }
private void CREATE_BUTTON_Click(object sender, EventArgs e) { Kurz k = new Kurz(); k.IdVyucujici = this.idTeacher; if (int.TryParse(CAPACITY_VALUE.Text, out int n) && NAME_VALUE.Text.Length > 1 && DETAIL_VALUE.Text.Length > 0 && SPECIALIZATION_CB.Text != "") { k.Kapacita = Convert.ToInt32(CAPACITY_VALUE.Text); k.IdObor = OborTable.SelectOneByName(SPECIALIZATION_CB.Text).IdObor; k.Nazev = NAME_VALUE.Text; k.Popis = DETAIL_VALUE.Text; k.Vytvoren = DateTime.Parse(START_DATE_DP.Text); KurzTable.Insert(k); SPECIALIZATION_CB.Text = ""; NAME_VALUE.Text = ""; CAPACITY_VALUE.Text = ""; DETAIL_VALUE.Text = ""; InitCourses(); } else { MessageBox.Show("Vypln vsechny udaje spravne!"); } }
public static int Insert(Kurz kurz, Database pDb = null) { Database db; if (pDb == null) { db = new Database(); db.Connect(); } else { db = pDb; } SqlCommand command = db.CreateCommand("spVytvorKurz"); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@p_nazev", kurz.Nazev); command.Parameters.AddWithValue("@p_popis", kurz.Popis); command.Parameters.AddWithValue("@p_vyucujici_id", kurz.IdVyucujici); command.Parameters.AddWithValue("@p_obor_id", kurz.IdObor); command.Parameters.AddWithValue("@p_kapacita", kurz.Kapacita); int ret = db.ExecuteNonQuery(command); if (pDb == null) { db.Close(); } return(ret); }
private void PrefillUpdateData(Kurz course) { InitSpecialization(); NAME_VALUE.Text = course.Nazev; CAPACITY_VALUE.Text = course.Kapacita.ToString(); DETAIL_VALUE.Text = course.Popis; START_DATE_DP.Value = course.Vytvoren; }
private void MY_COURSES_LISTVIEW_SelectedIndexChanged(object sender, EventArgs e) { if (MY_COURSES_LISTVIEW.SelectedItems.Count == 1) { this.idSelectedCourse = Convert.ToInt32(MY_COURSES_LISTVIEW.SelectedItems[0].Text); Kurz course = KurzTable.SelectOne(idSelectedCourse); InitCourse(course); PrefillUpdateData(course); } }
private void END_COURSE_BUTTON_Click(object sender, EventArgs e) { if (MY_COURSES_LISTVIEW.SelectedItems.Count == 1) { this.idSelectedCourse = Convert.ToInt32(MY_COURSES_LISTVIEW.SelectedItems[0].Text); Kurz course = KurzTable.SelectOne(idSelectedCourse); course.Ukoncen = DateTime.Now; KurzTable.Update(course); InitCourse(course); } }
private static void PrepareCommand(SqlCommand command, Kurz kurz) { command.Parameters.AddWithValue("@IdKurz", kurz.IdKurz); command.Parameters.AddWithValue("@Nazev", kurz.Nazev); command.Parameters.AddWithValue("@Popis", kurz.Popis); command.Parameters.AddWithValue("@Vytvoren", kurz.Vytvoren); command.Parameters.AddWithValue("@Ukoncen", kurz.Ukoncen == null ? DBNull.Value : (object)kurz.Ukoncen); command.Parameters.AddWithValue("@Kapacita", kurz.Kapacita); command.Parameters.AddWithValue("@IdObor", kurz.IdObor); command.Parameters.AddWithValue("@IdVyucujici", kurz.IdVyucujici); }
public override int GetHashCode() { unchecked { var hashCode = (Kod?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ Kurz.GetHashCode(); hashCode = (hashCode * 397) ^ (Mena?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ Mnozstvi; hashCode = (hashCode * 397) ^ (Zeme?.GetHashCode() ?? 0); return(hashCode); } }
public static int Update(Kurz kurz) { var db = new Database(); db.Connect(); SqlCommand command = db.CreateCommand(SQL_UPDATE); PrepareCommand(command, kurz); int ret = db.ExecuteNonQuery(command); db.Close(); return(ret); }
private void InitView() { MY_COURSES_LISTVIEW.Items.Clear(); Collection <Kurz> myCourses = KurzTable.SelectByTeacherId(idTeacher); if (myCourses.Count > 0) { Kurz firstCourse = myCourses[0]; foreach (var c in myCourses) { ListViewItem i = new ListViewItem(c.IdKurz.ToString()); i.SubItems.Add(c.Nazev); MY_COURSES_LISTVIEW.Items.Add(i); } InitCourse(firstCourse); } }
private static Collection <Kurz> Read(SqlDataReader reader, bool complete) { Collection <Kurz> kurzy = new Collection <Kurz>(); while (reader.Read()) { Kurz kurz = new Kurz(); int i = -1; kurz.IdKurz = reader.GetInt32(++i); kurz.Nazev = reader.GetString(++i); kurz.Popis = reader.GetString(++i); if (complete) { kurz.Vytvoren = reader.GetDateTime(++i); if (!reader.IsDBNull(++i)) { kurz.Ukoncen = reader.GetDateTime(i); } } kurz.Kapacita = reader.GetByte(++i); kurz.IdVyucujici = reader.GetInt32(++i); kurz.IdObor = reader.GetInt32(++i); if (complete) { kurz.Vyucujici = new Vyucujici(); kurz.Vyucujici.IdVyucujici = kurz.IdVyucujici; if (!reader.IsDBNull(++i)) { kurz.Vyucujici.Titul = reader.GetString(i); } kurz.Vyucujici.Jmeno = reader.GetString(++i); kurz.Vyucujici.Prijmeni = reader.GetString(++i); kurz.Obor = new Obor(); kurz.Obor.IdObor = kurz.IdObor; kurz.Obor.Nazev = reader.GetString(++i); } kurzy.Add(kurz); } return(kurzy); }
private static Collection <Kurz> Read2(SqlDataReader reader, bool complete) { Collection <Kurz> kurzy = new Collection <Kurz>(); while (reader.Read()) { Kurz kurz = new Kurz(); int i = -1; kurz.IdKurz = reader.GetInt32(++i); kurz.Nazev = reader.GetString(++i); if (complete) { kurz.Kapacita = reader.GetByte(++i); } kurz.IdObor = reader.GetInt32(++i); kurz.Obor = new Obor(); kurz.Obor.Nazev = reader.GetString(++i); kurzy.Add(kurz); } return(kurzy); }
private void SIGN_COURSE_BUTTON_Click(object sender, EventArgs e) { string courseName = AVAIL_COURSES_CB.Text; int studentsCount = 0, capacity = 0; if (courseName != null && courseName != "") { ZapsanyKurz zk = new ZapsanyKurz(); Kurz k = KurzTable.SelectByCourseName(courseName); if (k == null) { k = KurzTable.SelectLastCourseByName(courseName); } zk.IdKurz = k.IdKurz; studentsCount = KurzTable.GetStudentsCount(k.IdKurz); capacity = k.Kapacita; zk.IdStudent = idStudent; ZapsanyKurzTable.Insert(zk); if (studentsCount < capacity) { InitView(); } else { MessageBox.Show("J*z neni misto. Budete zapsan do fronty na tento kurz. " + "Jakmile se otevre kurz, budete zapsan do kurzu."); } } else { MessageBox.Show("Vyberte kurz z combo boxu!"); } }