Solved

asp.net scheduler c#

Posted on 2014-02-06
6
362 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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