Frage

I have a question that I'm looking for some help with. I have a system that books events and I need to get the 'appointment' information based on data stored in a 'events' table. So here's my question.

I have a table that has a 'StartDateTime', 'EndDateTime' and 'Duration' (for appointment duration which is fixed per event) I wont to automatically generate the time intervals based on the 'Start' and 'End' times using the 'Duration' for the Time Interval. I then want the system to return all possible times in a table showing any that are already booked.

I am using DateTime for StartDateTime Variable and EndDateTime Variable, for the TimeInterval I am using TimeSpan. I have found a couple of examples of this online but currently can't get them to except the following DateTime Format (dd/MM/yyyy HH:mm:ss).

(Will post example code later today)

Does anyone have any questions?

War es hilfreich?

Lösung

After a bit more digging and reading though my own question I managed to come up with a solution to both parts of my own question, I have posted part of the code bellow:

For the StartTime and EndTime I am using variable types of DateTime and then I am converting it to a string with the format of HH:mm (16:10) for the interval I am using TimeSpan for this section. I have the 3 variables as inputs to a function and then call access these vars within the script below, I then call and external function to check if the booking Exists or not returning false if slot booked or true if slot free.

        Table AppointmentTable = new Table();
        DateTime time = startTime;
        while (time <= endTime)
        {
            TableRow tblr_row = new TableRow();
            TableCell tblc_cell = new TableCell();
            TableCell tblc_time = new TableCell();
            try
            {
                if(Appointments.checkIfBookingExsists(time) == true)
                {
                    tblc_time.Text = time.ToString("HH:mm");
                    tblc_cell.Text = "Booked";
                    tblc_cell.CssClass = "Booked";
                }
                else if(Appointments.checkIfBookingExsists(time) == false)
                {
                    tblc_time.Text = time.ToString("HH:mm");
                    tblc_cell.Text = "Book";
                    tblc_cell.CssClass = "Book";
                }

            }
            catch (Exception ex)
            {
                tblc_time.Text = time.ToString("HH:mm");
                tblc_cell.Text = ex.Message;
            }
            tblc_time.CssClass = "tableCell";
            tblr_row.Controls.Add(tblc_time);
            tblr_row.Controls.Add(tblc_cell);
            AppointmentTable.CssClass = "table1";
            AppointmentTable.Controls.Add(tblr_row);
            //Move interval 16:10 > 16:20 interval 10 minutes
            time = time.Add(interval);
        }
        Page.Controls.Add(AppointmentTable);

I am not one of these people that is just looking for 'FREE CODE' but a hard working Network Engineer that has an interest in application development. I will always attempt to solve my own issues, but sometimes will ask for assistance. I understand the description of the question was 'bare or sketchy' but in the end I have found a solution.

Hope someone else can put this code to better use than I have!! :)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top