/// <summary> /// Gets the appointment with the specified user / employee /// </summary> /// <param name="appointment"></param> /// <returns></returns> public USERS GetAppointmentUser(APTDETAILS appointment) { var users = GetUsers(); var matchingUser = users.Find(u => u.US_STAMP == appointment.APD_USER); return(matchingUser); }
private void calendar_MouseMove(object sender, MouseEventArgs e) { CalendarItem i = calendar.ItemAt(calendar.PointToClient(Cursor.Position)); if (i == null) { toolTip.Active = false; toolTip.Hide(this); } else if (toolTip.Active == false) { toolTip.Active = true; Point tooltipPosition = PointToClient(Cursor.Position); APTDETAILS a = (APTDETAILS)i.Tag; if (a == null) { return; } if (a.APD_DESCRIPTION == null) { a.APD_DESCRIPTION = Encoding.Default.GetBytes("**Ingen beskrivelse**"); } string textToShow = $"{a.APD_TIMEFROM} - {a.APD_TIMETO}\n" + "Linseoptimering\n" + $"Room number {a.APD_ROOM}\n" + "\n" + $"'{Encoding.Default.GetString(a.APD_DESCRIPTION)}'"; toolTip.Show(textToShow, this, tooltipPosition); } }
/// <summary> /// edits the specified appoint in the db /// </summary> /// <param name="appointment"></param> public void PutAppointment(APTDETAILS appointment) { using (db = new OptikItDbContext()) { var appointmentToEditQuery = from a in db.APTDETAILS where a.APD_STAMP == appointment.APD_STAMP select a; foreach (var a in appointmentToEditQuery) { a.APD_DATE = appointment.APD_DATE; a.APD_TIMEFROM = appointment.APD_TIMEFROM; a.APD_TIMETO = appointment.APD_TIMETO; a.APD_USER = appointment.APD_USER; a.APD_DESCRIPTION = appointment.APD_DESCRIPTION; a.APD_TYPE = appointment.APD_TYPE; a.APD_ROOM = appointment.APD_ROOM; a.APD_MOBILE = appointment.APD_MOBILE; a.APD_EMAIL = appointment.APD_EMAIL; } try { db.SaveChanges(); } catch (Exception) { } } }
/// <summary> /// Apply colors to all appointments (specified by employee) /// </summary> private void ApplyColorLogicToCalendarItems() { //Color logic here var items = calendar.Items; var systemColors = new ColorConverter().GetStandardValues(); List <Color> colors = systemColors.Cast <Color>().ToList(); int colorJump = 50; foreach (var i in items) { APTDETAILS appointment = (APTDETAILS)i.Tag; int colorIndex = appointment.APD_USER + colorJump; if (appointment.APD_USER == 11) { colorIndex = 2 + colorJump; } Color color = colors[colorIndex]; i.ApplyColor(color); } }
/// <summary> /// gets the appointment with specificed room /// </summary> /// <param name="appointment"></param> /// <returns></returns> public EYEEXAMROOMS GetAppointmentRoom(APTDETAILS appointment) { var rooms = GetRooms(); var matchingRoom = rooms.Find(r => r.ERO_NBR.Equals(appointment.APD_ROOM)); return(matchingRoom); }
/// <summary> /// gets specific appointments with specific users. /// </summary> /// <param name="appointment"></param> /// <returns></returns> public List <string> GetExtraAppointmentDetails(APTDETAILS appointment) { List <string> extraAppointmentDetails = new List <string>(); var users = GetUsers(); var matchingUser = users.Find(u => u.US_STAMP.Equals(appointment.APD_USER)); if (matchingUser != null) { extraAppointmentDetails.Add(matchingUser.US_USERNAME); } return(extraAppointmentDetails); }
/// <summary> /// gets all the appointment with the specified appointment type /// </summary> /// <param name="appointment"></param> /// <returns></returns> public static string GetAppointmentType(APTDETAILS appointment) { switch (appointment.APD_TYPE) { case 0: return("Steljustering"); case 1: return("Linseopsætning"); case 2: return("Synsprøve"); } return(null); }
/// <summary> /// cancels / deletes the specified appointment from db /// </summary> /// <param name="appointment"></param> public void DeleteAppointment(APTDETAILS appointment) { using (_db = new OptikItDbContext()) { var removeQuery = from a in _db.APTDETAILS where a.APD_STAMP == appointment.APD_STAMP select a; foreach (var a in removeQuery) { _db.APTDETAILS.Remove(a); } try { _db.SaveChanges(); } catch (Exception) { } } }
/// <summary> /// post new appointment to the db /// </summary> /// <param name="appointment"></param> public void PostAppointment(APTDETAILS appointment) { using (db = new OptikItDbContext()) { try { db.APTDETAILS.Add(appointment); db.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } } }
/// <summary> /// mouseover tooltip view to show brief description /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void calendar_MouseMove(object sender, MouseEventArgs e) { CalendarItem i = calendar.ItemAt(calendar.PointToClient(Cursor.Position)); if (i == null) { toolTip.Active = false; toolTip.Hide(this); } else if (toolTip.Active == false) { toolTip.Active = true; //Point tooltipPosition = PointToClient(Cursor.Position); Point tooltipPosition = PointToClient(new Point(Cursor.Position.X, Cursor.Position.Y + 40)); APTDETAILS a = (APTDETAILS)i.Tag; var type = CalendarViewController.GetAppointmentType(a); var room = _calendarViewController.GetAppointmentRoom(a); var user = _calendarViewController.GetAppointmentUser(a); if (a == null || user == null) { return; } if (a.APD_DESCRIPTION == null || Encoding.Default.GetString(a.APD_DESCRIPTION).Equals("")) { a.APD_DESCRIPTION = Encoding.Default.GetBytes("**Ingen beskrivelse**"); } string textToShow = $"{a.APD_TIMEFROM} - {a.APD_TIMETO}\n" + "\n" + $"{type}\n" + $"Lokale nr. {a.APD_ROOM}\n" + $"{user.US_USERNAME}" + "\n" + "\n" + $"'{Encoding.Default.GetString(a.APD_DESCRIPTION)}'"; toolTip.Show(textToShow, this, tooltipPosition); } }
private void calendar_LoadItems(object sender, CalendarLoadEventArgs e) { AddAppointmentsToCalendar(); //Color logic here var items = e.Calendar.Items; var systemColors = new ColorConverter().GetStandardValues(); List <Color> colors = systemColors.Cast <Color>().ToList(); int colorJump = 50; foreach (var i in items) { APTDETAILS appointment = (APTDETAILS)i.Tag; int colorIndex = appointment.APD_USER + colorJump; Color color = colors[colorIndex]; i.ApplyColor(color); } }
/// <summary> /// Returns the appointment type of the specified appointment /// </summary> /// <param name="appointment"></param> /// <returns></returns> public static string GetAppointmentType(APTDETAILS appointment) { string type = ""; switch (appointment.APD_TYPE) { case 1: type = "Synsprøve"; break; case 2: type = "Ny tilpasning"; break; case 3: type = "Linsekontrol"; break; case 4: type = "Udlevering"; break; case 5: type = "Efterkontrol"; break; case 6: type = "Svagsynsoptik"; break; case 7: type = "Møde"; break; case 8: type = "Genudmåling"; break; case 9: type = "FRI"; break; case 10: type = "Leverandør"; break; case 12: type = "PBS"; break; case 13: type = "Brevkæde"; break; case 14: type = "Lukkedag"; break; case 15: type = "Udlevering af briller"; break; case 16: type = "Sygehus apotek"; break; case 17: type = "Værksted arbejde"; break; default: type = "Synsprøve"; break; } return(type); }
private void okButton_Click(object sender, EventArgs e) { int id = _controller.GetNextAppointmentId(); DateTime date = new DateTime(dateTimePicker1.Value.Year, dateTimePicker1.Value.Month, dateTimePicker1.Value.Day, timeFromPicker.Value.Hour, timeFromPicker.Value.Minute, 0); if (date < DateTime.Today) { if (ClickedAppointment == null) { MessageBox.Show("Du skal vælge et tidspunkt i fremtiden", "Fejl", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { MessageBox.Show("Du kan ikke redigere en aftale der er overstået.", "Fejl", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } string timeFrom = timeFromPicker.Value.ToString("HH:mm"); string timeTo = timeToPicker.Value.ToString("HH:mm"); USERS user = (USERS)userCombo.SelectedItem; EYEEXAMROOMS room = (EYEEXAMROOMS)lokaleCombo.SelectedItem; CUSTOMERS customer = _customers.Find(c => c.CS_CPRNO.Equals(cprBox.Text)); AppointmentType type; switch (aftaleCombo.Text) { case "Synsprøve": type = AppointmentType.Synsprøve; break; case "Ny tilpasning": type = AppointmentType.NyTilpasning; break; case "Linsekontrol": type = AppointmentType.LinseKontrol; break; case "Udlevering": type = AppointmentType.Udlevering; break; case "Efterkontrol": type = AppointmentType.Efterkontrol; break; case "Svagsynsoptik": type = AppointmentType.Svagsynsoptik; break; case "Møde": type = AppointmentType.Møde; break; case "Genudmåling": type = AppointmentType.Genudmåling; break; case "FRI": type = AppointmentType.FRI; break; case "Leverandør": type = AppointmentType.Leverandør; break; case "PBS": type = AppointmentType.PBS; break; case "Brevkæde": type = AppointmentType.Brevkæde; break; case "Lukkedag": type = AppointmentType.Lukkedag; break; case "Udlevering af briller": type = AppointmentType.UdleveringAfBriller; break; case "Sygehus apotek": type = AppointmentType.SygehusApotek; break; case "Værksted arbejde": type = AppointmentType.Værkstedarbejde; break; default: type = AppointmentType.Synsprøve; break; } var description = beskrivelseBox.Text; APTDETAILS appointment = new APTDETAILS(); //That means to create a new appointment. if (ClickedAppointment == null) { dateTimeFrom = timeFromPicker.Value; dateTimeTo = timeToPicker.Value; int result = DateTime.Compare(dateTimeFrom, dateTimeTo); try { if (result > 0) //(date <= DateTime.Now.AddMinutes(-1)) { MessageBox.Show("Du skal vælge et tidspunkt i fremtiden", "Fejl", MessageBoxButtons.OK, MessageBoxIcon.Error); //ny aftale Trace.WriteLine( $"\n Ansatte: {userSelectionCombo.SelectedIndex} har Oprettet en ny aftale d. {DateTime.Now}"); return; } appointment = new APTDETAILS(id, user, room, date, timeFrom, timeTo, customer, type, description); appointment.APD_MOBILE = telefonBox.Text; appointment.APD_EMAIL = emailBox.Text; _controller.PostAppointment(appointment); MessageBox.Show("Success! Aftalen er oprettet.", "Succes!", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } catch (Exception) { MessageBox.Show("Der er fejl i den indtastede data. Prøv igen.", "Fejl i oprettelse", MessageBoxButtons.OK, MessageBoxIcon.Error); CalendarView.AddedNewAppointment = true; } } //To put an appointment else { appointment = new APTDETAILS(ClickedAppointment.APD_STAMP, user, room, date, timeFrom, timeTo, customer, type, description); appointment.APD_MOBILE = telefonBox.Text; appointment.APD_EMAIL = emailBox.Text; _controller.PutAppointment(appointment); MessageBox.Show("Success! Aftalen er redigeret.", "Succes!", MessageBoxButtons.OK, MessageBoxIcon.Information); Trace.WriteLine( $"\n{DateTime.Now}: Aftale på dato {appointment.APD_DATE} med kunde {appointment.APD_FIRST} {appointment.APD_LAST} er blevet rettet."); this.Close(); CalendarView.AddedNewAppointment = true; } }