Solved

asp.net scheduler c#

Posted on 2014-02-06
6
376 Views
Last Modified: 2014-02-07
Hi Experts,

I have been asked to provide a room-booking app, about 10 rooms, and booking is for meetings so I would imagine 30min time intervals are sufficient.

In the first instance I am wondering how I might modify an existing calendar app to include times. The code for the calendar is below:
           <!------------------Calendar WeekDay & Date START ------------------------------->
                <table class="table" style="vertical-align: top; padding: 0; width: 100%; margin-top: 0px;">
                    <tr>
                        <td style="width: 30px; vertical-align: top; margin-top: 20px;">

                            <br />

                            <asp:ImageButton ID="btnPrev" runat="server" OnClick="btnPrev_Click" ImageUrl="~/Images/buttons/prev.png" /></td>
                        <td>
                            <asp:DataList ID="DataList1" RepeatColumns="7" ItemStyle-HorizontalAlign="Center"
                                ItemStyle-Wrap="true" CssClass="calendar" ItemStyle-Width="14%" ItemStyle-VerticalAlign="Top" ItemStyle-BorderWidth="0"
                                CellPadding="5" ItemStyle-BorderWidth-Bottom="0" RepeatDirection="Horizontal" Width="100%"
                                DataSourceID="ThisWeek" DataKeyField="date" runat="server">
                                <ItemTemplate>
                                    <h3 id="DkRedH3">
                                        <%#Eval("days")%></h3>
                                    <h3>
                                        <%#Eval("date", "{0:d MMM }")%>
                                    </h3>
                                    <br />
                                    <!------------------Calendar WeekDay & Date END ------------------------------->


                                    <!------------------Calendar Events Summary for Current Week START ------------------------------------->
                                    <asp:Label ID="lbldate" runat="server" Visible="False" Text='<%# Eval("date") %>' />
                                    

                                    <asp:Repeater ID="secondlevel" OnItemDataBound="List1_ItemDataBound" OnItemCommand="List1_ItemCommand" runat="server" DataSourceID="EventsThisWeek">
                                        <ItemTemplate>

                                            <asp:Table CellPadding="3" CellSpacing="0" ID="eventtable" CssClass="tablecell" Width="100%" runat="server">
                                                <asp:TableRow>
                                                    <asp:TableCell Style="width: 90%;">
                                                        <asp:HiddenField ID="ChildID" runat="server" Value='<%# Eval("CPDID") %>' />
                                                        <b>
                                                            <%#Eval("CPDdesc")%></b>
                                                    </asp:TableCell>
                                                    <asp:TableCell ID="eventcell" RowSpan="4">
                                                        <asp:Image ID="Image1" CssClass="counter" border="0" runat="server" />
                                                        <asp:ImageButton ID="btnMore" CssClass="btnMore" ImageUrl="~/Images/buttons/open.png" runat="server" />

                                                    </asp:TableCell>
                                                </asp:TableRow>

                                                <asp:TableRow>
                                                    <asp:TableCell>
                                            <span id="greyfontspan">
                                                <%#Eval("Location")%></span><br />
                                                    </asp:TableCell>
                                                </asp:TableRow>
                                                <asp:TableRow>
                                                    <asp:TableCell>
                                            <%# Eval("StartTime","{0:t}")%>
                                            -
                                            <%#Eval("EndTime", "{0:t}") %>
                                                    </asp:TableCell>
                                                </asp:TableRow>

                                            </asp:Table>
                                            <br />

                                        </ItemTemplate>
                                    </asp:Repeater>
                                    <br />
                                    <br />
                                    <br />
                                    <!------------------------------------SQL EMBEDDED - DO NOT RELOCATE-------------------->
                                    <asp:SqlDataSource runat="server" ID="EventsThisWeek" ConnectionString="<%$ connectionStrings:Training %>"
                                        SelectCommand="GetItemsTest" SelectCommandType="StoredProcedure">
                                        <SelectParameters>
                                            <asp:SessionParameter Name="JumpWeeks" SessionField="clickcount" Type="Int32" />
                                            <asp:SessionParameter Name="TheDate" Type="DateTime" SessionField="thedate" />
                                            <asp:ControlParameter Name="date" ControlID="lbldate" PropertyName="text" Type="DateTime" />
                                        </SelectParameters>
                                    </asp:SqlDataSource>
                                    <!------------------------------------SQL END------------------------------------------->
                                </ItemTemplate>
                            </asp:DataList>
                        </td>
                        <td style="width: 30px; vertical-align: top; margin-top: 20px;">

                            <br />

                            <asp:ImageButton ID="btnNext" runat="server" OnClick="btnNext_Click" ImageUrl="~/Images/buttons/next.png" /></td>
                    </tr>
                </table>
            </ContentTemplate>
        </asp:UpdatePanel>
        <!------------------Calendar Events Summary for Current Week END ------------------------------------->

Open in new window


SQL SP
@TheDate AS DATETIME,
@JumpWeeks AS INT = 0
AS
BEGIN



;WITH days AS (SELECT        - 7 AS d
                                 UNION ALL
                                 SELECT        d + 1 AS Expr1
                                 FROM            days AS days_2
                                 WHERE        (d < 7))
    SELECT        TOP (7) DATEADD(day, d, @TheDate) AS date, DATENAME(weekday, DATEADD(day, d, @TheDate)) AS Days, DATENAME(month, DATEADD(day, d, @TheDate)) 
                              AS Month, DATEPART(Year, DATEADD(day, d, @TheDate)) AS Year

     FROM            days AS days_1
     WHERE        (DATEPART(week, @TheDate) = DATEPART(week, DATEADD(day, d, @TheDate)))
END

Open in new window


So I'm using the calendar above to show events by week, they're called back by their date matching the @date of the weekday and multiple events on any given day are ordered by StartTme. So thinking of the current request I'm wondering whether I can somehow introduce times to the days so that each day is broken down by time into which I can them make bookings.
0
Comment
Question by:forsters
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 5

Assisted Solution

by:Jeroen Timmermans
Jeroen Timmermans earned 500 total points
ID: 39841331
If I understand correctly, you'll need to create a complex type which contains the date, a block-index and a reservationId. The index runs from 0 to 48.

You'll need to create these objects for every day you are showing on the calendar. After creating them, retrieve all the reservations from the database, and fill the reservationIds for the appropriate dates and blocks. In the UI you can handle what to do with booked timeblocks based on a filled out reservationId.

In the database, save a reservation with the date, the timeblock index and whatever info you need from the booker.
0
 

Author Comment

by:forsters
ID: 39841352
Hmm sounds...complex...I have some serious reading to do if that's the case, when you say "You'll need to create these objects for every day you are showing on the calendar" by some form of loop...?

I had wondered if I could retrieve time array from sql in the same way as I have done days and then just retrieve booking where date and time match...
0
 
LVL 5

Expert Comment

by:Jeroen Timmermans
ID: 39841362
How would you propose to match up the timeblocks to the times?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:forsters
ID: 39841512
Well, that was where I was stuck, but in fact I think if I have understood what you're saying I would only want to break my day into hours when I view a single day at a time.

I was studying Outlook calendars last night - when a week or month are viewed events are just listed in day blocks - I can do that much already -  the times are only specified for the view of a single day...soooo I had begun to think that I could/should do likewise which feels simpler.

So in my head I am thinking of viewing one room on one day showing hours between say 8am and 8pm - all I don't know how to do is call those time intervals (as datetimes) from sql - I should then be able for each...hmmm I see what you're saying how do I display a block of time booked as such.

Hmm this is why people pay for this stuff huh...ok idiots guide to complex types and block indexing...?
0
 
LVL 5

Accepted Solution

by:
Jeroen Timmermans earned 500 total points
ID: 39841593
I propose the following (mock code)

class TimeBlock{
DateTime date;
Int BlockIndex; //runs from 0 to 48, index 0 is 0:00 to 0:30, 1 is 0:30h to 1:00h, etc
Int? ReservationId;
}

First, retrieve all reservations from the database for the selected daterange.

Next, run a for-loop from the start- to the end-date and inside that a for-loop running from 0 to 48. Inside the second loop, create a new TimeBlock-instance, setting date, blockindex and if a reservation for this date and timeblock exists, the reservationId. Add the item to a collection.
After the outer loop finishes, use the collection to fill the calendar.
0
 

Author Closing Comment

by:forsters
ID: 39841872
Thank you I will have a go
0

Featured Post

A new era in Cloud training has arrived.

A day that will go down in Cloud history.. But are you ready for it? Will you accept this Cloud challenge?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question