public Session ProcessRow(Session session, MySqlDataReader Reader, int offset) { session.Id = Reader.GetInt32(0 + offset); session.Daytime_id = Reader.GetInt32(1 + offset); session.Classroom_id = Reader.GetInt32(2 + offset); session.Pair_id = Reader.GetInt32(3 + offset); return session; }
public int Save(Session session) { Boolean insert = true; if (session.Id != 0) { insert = false; } MySqlCommand command = this._db.CreateCommand(); if (insert) { command.CommandText = "INSERT INTO session (daytime_id, classroom_id, pair_id) VALUES " + "(?daytime_id, ?classroom_id, ?pair_id)"; } else { command.CommandText = "UPDATE session SET daytime_id = ?daytime_id, classroom_id = ?classroom_id, pair_id = ?pair_id WHERE id = ?id"; } command.Parameters.Add(new MySqlParameter("?id", MySqlDbType.Int32)).Value = session.Id; command.Parameters.Add(new MySqlParameter("?daytime_id", MySqlDbType.Int32)).Value = session.Daytime.Id; command.Parameters.Add(new MySqlParameter("?classroom_id", MySqlDbType.Int32)).Value = session.Classroom.Id; command.Parameters.Add(new MySqlParameter("?pair_id", MySqlDbType.Int32)).Value = session.Pair.ID; this._db.OpenConnection(); this._db.ExecuteCommand(command); this._db.CloseConnection(); if (insert) { this._db.OpenConnection(); MySqlCommand command2 = this._db.CreateCommand(); command2.CommandText = "SELECT LAST_INSERT_ID()"; MySqlDataReader Reader = this._db.ExecuteCommand(command2); Reader.Read(); this._db.CloseConnection(); return Reader.GetInt32(0); } return 0; }
public SessionWindow(Session session) { InitializeComponent(); _controller = PAZController.GetInstance(); List<Pair> pairs = _controller.PairMapper.FindAll(); foreach (Pair pair in pairs) { cbPairs.Items.Add(pair.ID + ", " + pair.ToString()); } foreach (Teacher teacher in _controller.TeacherMapper.FindAll()) { cbTeacher1.Items.Add(teacher.Id + ", " + teacher.ToString()); cbTeacher2.Items.Add(teacher.Id + ", " + teacher.ToString()); } foreach (Expert expert in _controller.ExpertMapper.FindAll()) { cbExpert1.Items.Add(expert.Id + ", " + expert.ToString()); cbExpert2.Items.Add(expert.Id + ", " + expert.ToString()); } List<string> teachers = new List<string>(); List<string> experts = new List<string>(); foreach (User user in session.Pair.Attachments) { if (user.User_type == "teacher") { Teacher t = _controller.TeacherMapper.Find(user.Id); teachers.Add(t.Id + ", " + t.ToString()); } else if (user.User_type == "expert") { Expert t = _controller.ExpertMapper.Find(user.Id); experts.Add(t.Id + ", " + t.ToString()); } } ids[0] = session.Pair.ID; string[] temp; cbPairs.SelectedIndex = cbPairs.Items.IndexOf(session.Pair.ID + ", " + session.Pair.ToString()); if (teachers.Count > 0) { cbTeacher1.SelectedIndex = cbTeacher1.Items.IndexOf(teachers[0]); cbTeacher2.SelectedIndex = cbTeacher2.Items.IndexOf(teachers[1]); temp = teachers[0].Split(','); ids[1] = Convert.ToInt32(temp[0]); temp = teachers[1].Split(','); ids[2] = Convert.ToInt32(temp[0]); } if (experts.Count > 0) { cbExpert1.SelectedIndex = cbExpert1.Items.IndexOf(experts[0]); cbExpert2.SelectedIndex = cbExpert2.Items.IndexOf(experts[1]); temp = experts[0].Split(','); ids[3] = Convert.ToInt32(temp[0]); temp = experts[1].Split(','); ids[4] = Convert.ToInt32(temp[0]); } }
void Session_Drop(object sender, DragEventArgs e) { CustomLabel session = sender as CustomLabel; if (session != null && session.Background != Brushes.Red) { // If the DataObject contains string data, extract it. if (e.Data.GetDataPresent(DataFormats.StringFormat)) { string dataString = (string)e.Data.GetData(DataFormats.StringFormat); if (dataString != null) { string[] other = dataString.Split(';'); Session s = _controller.SessionMapper.Find(Convert.ToInt32(other[0])); Daytime d = _controller.DaytimeMapper.Find(GetSessionDate(session), Grid.GetRow(session)); if (d == null) { string[] date = GetSessionDate(session).Split('-'); d = new Daytime(0, new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[1]), Convert.ToInt32(date[0])), Grid.GetRow(session) + 1); d.Id = _controller.DaytimeMapper.Save(d); } s.Daytime = d; s.Classroom = _controller.ClassroomMapper.Find(Grid.GetColumn(session) + 1); addSession(s, false); removeSessionLabel(other[1], Convert.ToInt32(other[2]), Convert.ToInt32(other[3])); } } else { int id = (int)e.Data.GetData("System.Int32"); if (id != 0) { Session s = new Session(); Daytime d = _controller.DaytimeMapper.Find(GetSessionDate(session), Grid.GetRow(session)); if (d == null) { string[] date = GetSessionDate(session).Split('-'); d = new Daytime(0, new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[1]), Convert.ToInt32(date[0])), Grid.GetRow(session) + 1); d.Id = _controller.DaytimeMapper.Save(d); } s.Daytime = d; s.Classroom = _controller.ClassroomMapper.Find(Grid.GetColumn(session) + 1); s.Pair = _controller.PairMapper.Find(Convert.ToInt32(id)); addSession(s, true); } } revertCheckAvailability(); } }
public void addSessionLabel(Session session, int newId) { CustomLabel s = addSessionLabel(session); s.Id = newId; }
public CustomLabel addSessionLabel(Session session) { CustomLabel sessionLabel = dateGrids[session.Daytime.Date.ToShortDateString()].Children[(session.Classroom.Id - 1) + ((session.Daytime.Timeslot - 1) * 8)] as CustomLabel; sessionLabel.Id = session.Id; string[] students = new string[1]; string[] teachers = new string[1]; string[] experts = new string[1]; foreach (User user in session.Pair.Participants) { string name = user.Firstname + " " + user.Surname + ","; if (user.User_type == "teacher") teachers[0] += name; else if (user.User_type == "student") students[0] += name; else experts[0] += name; } students = students[0].Split(','); if (experts[0] != null) experts = experts[0].Split(','); else experts = new string[]{"GEEN EXPERTS",""}; if (teachers[0] != null) teachers = teachers[0].Split(','); else teachers = new string[] { "GEEN DOCENTEN", "" }; sessionLabel.Content = students[0] + "\n" + students[1] + "\n\n" + teachers[0] + "\n" + teachers[1] + "\n\n" + experts[0] + "\n" + experts[1]; sessionLabel.ToolTip = "Studenten\n\nDocenten\n\nExperts"; sessionLabel.BorderBrush = Brushes.LightGray; sessionLabel.BorderThickness = new Thickness(2); sessionLabel.MouseMove += new System.Windows.Input.MouseEventHandler(session_MouseMove); sessionLabel.AllowDrop = false; sessionLabel.Drop -= Session_Drop; sessionLabel.Background = Brushes.White; //Context Menu System.Windows.Controls.ContextMenu editMenu = new ContextMenu(); //edit menu MenuItem edit = new MenuItem(); edit.Header = "Wijzigen"; edit.Click += new RoutedEventHandler(edit_Click); editMenu.Items.Add(edit); //delete menu MenuItem delete = new MenuItem(); delete.Header = "Verwijderen"; delete.Click += new RoutedEventHandler(delete_Click); editMenu.Items.Add(delete); sessionLabel.ContextMenu = editMenu; return sessionLabel; }
public void addSession(Session session,bool newSession) { int id = _controller.SessionMapper.Save(session); if (newSession) { addSessionLabel(session, id); _controller.toPlanWindow.loadAllPairs(_controller.PairMapper); } else addSessionLabel(session); _controller.MainWindow.updateOverzicht(); }
public Session ProcessRow(Session session, MySqlDataReader Reader) { return this.ProcessRow(session, Reader, 0); }
public Planning Plan(List<Pair> pairs) { IniFile ini = PAZController.GetInstance().IniReader; int max_tries = Int32.Parse(ini["AUTOPLANNERSETTINGS"]["max_tries"]); Random r = new Random(); Planning result = new Planning(); List<Classroom> classrooms = PAZController.GetInstance().ClassroomMapper.FindAll(); List<Daytime> daytimes = PAZController.GetInstance().DaytimeMapper.FindAll(); Dictionary<Daytime, List<Classroom>> available = new Dictionary<Daytime,List<Classroom>>(); Dictionary<Daytime, List<Expert>> availableExperts = new Dictionary<Daytime, List<Expert>>(); List<Expert> allExperts = PAZController.GetInstance().ExpertMapper.FindAll(); foreach (Daytime daytime in daytimes) { available.Add(daytime, new List<Classroom>(classrooms));//Clone :) List<Expert> expertsToAdd = new List<Expert>(); foreach (Expert expert in allExperts) { bool add = true; foreach (Blocked_timeslot bs in expert.BlockedTimeslots) { if (bs.Hardblock && bs.Daytime_id == daytime.Id) { add = false; break; } } if (add) { expertsToAdd.Add(expert); } } availableExperts.Add(daytime, expertsToAdd); } foreach (Pair pair in pairs) { Session session = new Session(); session.Pair = pair; int daytimeI = r.Next(0, available.Count); int tries = 0; while (session.Pair.ScoreAt(available.ElementAt(daytimeI).Key) == -1 && available.ElementAt(daytimeI).Value.Count < 1 && tries < max_tries) { daytimeI = r.Next(0, available.Count); ++tries; } session.Daytime = available.ElementAt(daytimeI).Key; int classRoomI = r.Next(0, available.ElementAt(daytimeI).Value.Count); session.Classroom = available.ElementAt(daytimeI).Value.ElementAt(classRoomI); available[session.Daytime].RemoveAt(classRoomI); if (!session.Pair.HasExpert()) { List<Expert> availableThisSlot = availableExperts.ElementAt(daytimeI).Value; if (availableThisSlot.Count > 1) { session.Pair.Attachments.Add(availableThisSlot.ElementAt(0)); availableThisSlot.RemoveAt(0); session.Pair.Attachments.Add(availableThisSlot.ElementAt(0)); availableThisSlot.RemoveAt(0); PAZController.GetInstance().PairMapper.Save(session.Pair); } } result.Sessions.Add(session); } if (result.GetScore() == -1) { return this.Plan(pairs); } return result; }
public SessionRow(Session session) { if (session.Daytime != null) { this.Datum = session.Daytime.Date.Day.ToString() + "-" + session.Daytime.Date.Month.ToString() + "-" + session.Daytime.Date.Year.ToString(); this.Tijd = session.Daytime.StartEndTime; } else { this.Datum = "Onbekend"; this.Tijd = "Onbekend"; } if (session.Classroom != null) { this.Lokaal = session.Classroom.Room_number; } else { this.Lokaal = ""; } if (session.Pair.Student2 != null) { this.Studenten = session.Pair.Student1.Firstname + " " + session.Pair.Student1.Surname + "\r" + session.Pair.Student2.Firstname + " " + session.Pair.Student2.Surname; } else { this.Studenten = session.Pair.Student1.Firstname + " " + session.Pair.Student1.Surname; } string returnStringTeachers = String.Empty; string returnStringExperts = String.Empty; if (session.Pair.Attachments != null) { foreach (User user in session.Pair.Attachments) { if (user is Teacher) { Teacher teacher = (Teacher)user; returnStringTeachers += teacher.Firstname + " " + teacher.Surname + "\r"; } else if (user is Expert) { Expert expert = (Expert)user; returnStringExperts += expert.Firstname + " " + expert.Surname + "\r"; } } } this.Docenten = returnStringTeachers; this.Deskundigen = returnStringExperts; this.AantalGasten = session.Pair.Number_of_guests; _dataList = new List<Object>(); _dataList.Add(Datum); _dataList.Add(Tijd); _dataList.Add(Lokaal); _dataList.Add(Studenten); _dataList.Add(Docenten); _dataList.Add(Deskundigen); _dataList.Add(AantalGasten); this._session = session; }