Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display days split in half 1

Status
Not open for further replies.

Halliarse

IS-IT--Management
Jan 8, 2007
213
GB
Hi

I am writing an application that incorporates the standard ASP.Net calendar and I wanted to know if it is possible to display a day split in 2?

i.e. If a statff member is on holiday today but only on a half day this morning, I want to show this morning as the specified colour and this afternoon as my standard defined calendar calendar!

If this is possible can someone please point me in the right direction?

Many thanks

Steve
 
I never tried it but what you should do is look at the page "view source" once it is rendered. I would assume it is a table cell. However I don't think you would be able to "split" it.
What you might have to do is divide each calender cell in 2 by adding 2 table cells or divs to each one. Then you can color those objects instead of the calendar cell itself.
 
Thanks again for the advice Jbenson001

I have another issue with this calendar too that maybe you wouldn't mind assisting with?

I want to change colour and disable days where a person may not be working! I've validated the numbers within my code as being correct but for some reason, it colours all the days the same! The code is below....what am I doing wrong?

If (e.Day.Date.DayOfWeek + 1) <> CurrentDay Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If

Best reagrds

Steve
 
Did the isselectable = false work? is it just the color that is the issue?
if it is just the color, it could be that you just can't really see it on your monitor. Just try a very sever color like Aqua just for testing.
 
It is setting all days to the colour (no problem with display) and disabling all of them....it just doesn't make sense! FYI, the code is within the DayRender and I've displayed the whole subroutine in case it's something else!

Thanks for your help.

Private Sub Calendar1_DayRender(sender As Object, e As DayRenderEventArgs) Handles Calendar1.DayRender

Dim DayLoop As Integer = 0
Dim CurrentDay As Integer = 0

For DayLoop = 1 To 7
Select Case DayLoop
Case 1
If Session("StylistDay1") = 1 Then
CurrentDay = DayLoop
Else
CurrentDay = 99
End If
Case 2
If Session("StylistDay2") = 1 Then
CurrentDay = DayLoop
Else
CurrentDay = 99
End If
Case 3
If Session("StylistDay3") = 1 Then
CurrentDay = DayLoop
Else
CurrentDay = 99
End If
Case 4
If Session("StylistDay4") = 1 Then
CurrentDay = DayLoop
Else
CurrentDay = 99
End If
Case 5
If Session("StylistDay5") = 1 Then
CurrentDay = DayLoop
Else
CurrentDay = 99
End If
Case 6
If Session("StylistDay6") = 1 Then
CurrentDay = DayLoop
Else
CurrentDay = 99
End If
Case 7
If Session("StylistDay7") = 1 Then
CurrentDay = DayLoop
Else
CurrentDay = 99
End If
End Select

If (e.Day.Date.DayOfWeek + 1) <> CurrentDay Then
' 'MsgBox((e.Day.Date.DayOfWeek + 1) & " " & CurrentDay)
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If

Next DayLoop

If e.Day.Date.DayOfWeek + 1 = Session("ClosedDay") Then
e.Cell.BackColor = System.Drawing.Color.Firebrick
e.Day.IsSelectable = False
End If

Dim nextDate As DateTime

If Not CType(Session("PublicHolidays"), DataSet) Is Nothing Then
For Each dr As DataRow In CType(Session("PublicHolidays"), DataSet).Tables(0).Rows
nextDate = CType(dr("BankHoliday"), DateTime)
If nextDate = e.Day.Date Then
e.Cell.BackColor = System.Drawing.Color.CornflowerBlue
End If
Next
End If

If Not CType(Session("StylistHolidays"), DataSet) Is Nothing Then
For Each dr As DataRow In CType(Session("StylistHolidays"), DataSet).Tables(0).Rows
nextDate = CType(dr("HolidayDate"), DateTime)
If nextDate = e.Day.Date Then
e.Cell.BackColor = System.Drawing.Color.Red
'e.Cell.Text = "SH"
End If
Next
End If

If e.Day.Date = Today Then
e.Cell.BackColor = System.Drawing.Color.Green
End If

End Sub
 
you have e.day.date.dayofweek + 1 which technically is incorrect(but does not throw and error). dayofweek returns the day name like "Sunday", "Monday" ..etc so I think you have a flaw there
And you really need to step through each line and be sure you are getting values you expect from session etc.
 
I've just debugged the value of e.day.date.dayofweek and it returns a numeric between 0 and 6 not a day name as you suggest....this was the reasoning behind performing arithmetic on it to match my days.

I'll take a look at the links and see if that throws any further light.

Thanks again
 
they dayofweek is showing you a numeric value because you are adding 1 to it. the property itself returns a string value of"Sunday".. etc
 
Hi jbenson001

The debugging was actaully done specifically on the dayoftheweek, outside of the arithmetic, and it still shows as a numeric! I've attached a screen shot for you....it maskes no sense to me!

Cheers

Steve
 
 http://files.engineering.com/getfile.aspx?folder=4f3f04e5-421f-4c9e-84ae-24614cbd2695&file=Capture.JPG
remove all code in your dayrender event and put this
Response.Write(e.Day.Date.DayOfWeek.ToString() + "<br />")

then do
Response.Write(e.Day.Date.DayOfWeek + 1)

You will see what I mean
 
Hi JBension001

I've totally changed the way I coded this, removing all of the arithmetic...my original routines that were writing the data were writing it incorrectly!

I have a table called StylistHours which holds data relating to days worked. I want my calendar to change the colour and not allow selection if the day does not match any of the day records within this table.

The data from the table is built into a dataset and the following code runs:

Dim NextDay As Integer

If Not CType(Session("StylistHours"), DataSet) Is Nothing Then
For Each dr As DataRow In CType(Session("StylistHours"), DataSet).Tables(0).Rows
NextDay = CType(dr("Day"), Integer)
If NextDay = e.Day.Date.DayOfWeek.ToString Then
Else
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Next
End If

This code changes every cell to LightSalmon! I have put a display into the 'If NextDay' and it is finding matches correctly so can you see why it would be setting all the days?

Thanks

Steve
 
Apolofies for the name mispell JBenson001.....just to advise that one of my coded lines is incorrect If NextDay = e.Day.Date.DayOfWeek.ToString, ignore the .tostring
 
So how do I actually compare it then? I've tried the following now and that doesn't work either!!

Dim NextDay As Integer

If Not CType(Session("StylistHours"), DataSet) Is Nothing Then
For Each dr As DataRow In CType(Session("StylistHours"), DataSet).Tables(0).Rows
NextDay = CType(dr("Day"), Integer)

If NextDay = Int(e.Day.Date.DayOfWeek) Then
Else
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Next
End If

Thanks again

Steve
 
I've also tried this too....this doesn't work either!

Dim NextDay As Integer
Dim NextDayName As String = String.Empty

If Not CType(Session("StylistHours"), DataSet) Is Nothing Then
For Each dr As DataRow In CType(Session("StylistHours"), DataSet).Tables(0).Rows
NextDay = CType(dr("Day"), Integer)
Select Case NextDay
Case 1
NextDayName = "Monday"
Case 2
NextDayName = "Tuesday"
Case 3
NextDayName = "Wednesday"
Case 4
NextDayName = "Thursday"
Case 5
NextDayName = "Friday"
Case 6
NextDayName = "Saturday"
Case 7
NextDayName = "Sunday"
End Select

If NextDayName = e.Day.Date.DayOfWeek.ToString Then
Else
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Next
End If
 
I don't know your data
what columns/values are in the dataset?
What do they represent? What datatype(s) are they?

The debugger is great. You can stop it on your case and inspect your data elements to be sure you have what you expect.
You can then also check the properties of the cell object and see what properties/methods are available to you.

I was playing with it yesterday and found lots of properties on the cell object I didn't know existed and could possible use.
 
Within the StylistHours table is a column called 'Day' which is an integer and stores values from 1 to 7. These represent the days that a stylist is available to work.

I'm trying to change the calendar colour for days where the stylist does not work and also to make those days non-selectable.
 
This is a quick example. My logic is probably way off from what you want but hopefully it will help.

Code:
dim dt as datatable = DirectCast(Session("StylistHours"), DataSet).Tables(0)
For Each dr As DataRow In dt.rows
  Select Case dr("Day")
     Case "1"
        if e.Day.dayNumberText = "1" then

        end if 
     Case "2"

     Case "3" 


        ...etc
  End Select

end for
 
Right, I think we are making progress! Your code actually relates to the day number within the actual date as opposed to the day number of the week.

I have changed the code to the following and the result is as attached, however, it's the wrong way round! The days that are salmon coloured shouldn't be and the days that aren't, should be!

Dim dt As DataTable = DirectCast(Session("StylistHours"), DataSet).Tables(0)
For Each dr As DataRow In dt.Rows
Select Case dr("Day")
Case "1"
If e.Day.Date.DayOfWeek.ToString = "Monday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Case "2"
If e.Day.Date.DayOfWeek.ToString = "Tuesday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Case "3"
If e.Day.Date.DayOfWeek.ToString = "Wednesday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Case "4"
If e.Day.Date.DayOfWeek.ToString = "Thursday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Case "5"
If e.Day.Date.DayOfWeek.ToString = "Friday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Case "6"
If e.Day.Date.DayOfWeek.ToString = "Saturday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
Case "7"
If e.Day.Date.DayOfWeek.ToString = "Sunday" Then
e.Cell.BackColor = System.Drawing.Color.LightSalmon
e.Day.IsSelectable = False
End If
End Select
Next
 
 http://files.engineering.com/getfile.aspx?folder=9c768394-ebdd-4659-8d0d-dd0c3e7c705d&file=Capture.JPG
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top