Solved

asp.net scheduler c#

Posted on 2014-02-06
6
357 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
  • 3
  • 3
6 Comments
 
LVL 5

Assisted Solution

by:Jeroen Timmermans
Jeroen Timmermans earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
How would you propose to match up the timeblocks to the times?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:forsters
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you I will have a go
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now