Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

asp.net scheduler c#

Posted on 2014-02-06
6
Medium Priority
?
380 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 2000 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
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 

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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

722 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