コード例 #1
0
        /// <summary>
        /// Gets the specified room availability in hours in the timeslot parametres (month & year)
        /// </summary>
        /// <param name="room"></param>
        /// <param name="monthNr"></param>
        /// <param name="year"></param>
        /// <returns></returns>
        public double GetRoomUsageInHours(EYEEXAMROOMS room, int monthNr, int year)
        {
            var allAppointments = GetAppointments();
            List <APTDETAILS> appointmentsByRoom = new List <APTDETAILS>();

            foreach (var a in allAppointments)
            {
                if (a.APD_ROOM == room.ERO_NBR.Value && a.APD_DATE.Value.Month == monthNr && a.APD_DATE.Value.Year == year)
                {
                    appointmentsByRoom.Add(a);
                }
            }

            List <TimeSpan> timeSpans = new List <TimeSpan>();

            foreach (var a in appointmentsByRoom)
            {
                TimeSpan timeFrom    = TimeSpan.Parse(a.APD_TIMEFROM);
                TimeSpan timeTo      = TimeSpan.Parse(a.APD_TIMETO);
                TimeSpan timeElapsed = timeTo - timeFrom;

                timeSpans.Add(timeElapsed);
            }

            double totalUsageInHours = 0;

            foreach (var t in timeSpans)
            {
                totalUsageInHours += t.TotalHours;
            }

            return(totalUsageInHours);
        }
コード例 #2
0
        /// <summary>
        /// Gets the specified room usage per month in specified month and year
        /// </summary>
        /// <param name="room"></param>
        /// <param name="totalRoomHoursPerMonth"></param>
        /// <param name="monthNr"></param>
        /// <param name="year"></param>
        /// <returns></returns>
        public double GetRoomAvailabilityInHours(EYEEXAMROOMS room, int totalRoomHoursPerMonth, int monthNr, int year)
        {
            double usageInHours = GetRoomUsageInHours(room, monthNr, year);

            return(totalRoomHoursPerMonth - usageInHours);
        }
コード例 #3
0
        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;
            }
        }