Solved

asp.net scheduler c#

Posted on 2014-02-06
6
361 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
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Question! 4 36
SQL Insert parts by customer 12 34
i have to take the screenshot of command prompt? how to do this? 1 37
MailAddress in vb 4 15
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 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