|
EventCalendarControl.cs
If available , could someone post this code in vb ?
Also, it appears the transparent gif leaves a shadow imprint inside the gantt task bar, which is visible to the user. Appears in both IE 6and FF1.5 browsers. Anyway to resolve this ?
|
|
|
|
|
If your still interested.
---------oOo---------
Imports System
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Xml
<defaultproperty("xmldata"), toolboxdata("<{0}:eventkalendercontrol="" runat="server">")> _
Public Class EventKalenderControl
Inherits System.Web.UI.WebControls.WebControl
Dim _text As String
Private m_xmlData As String, m_blockColor As String, m_toggleColor As String, m_cellWidth As String, m_cellHeight As String, m_blankGifPath As String
Private m_year As Integer, m_quarter As Integer
Dim m_names() As String
Public Function EventCalendarControl()
m_names = New String(3) {}
End Function
#Region "Properties"
'
' Gets or sets a value that contains XML data containing the events.
'
<bindable(true), category("appearance"),="" defaultvalue("")=""> _
Public Property XMLData() As String
Get
Return m_xmlData
End Get
Set(ByVal Value As String)
m_xmlData = Value
End Set
End Property
'
' Gets or sets a value that indicates the quarter (1,2,3,4)
'
<bindable(true), category("appearance"),="" defaultvalue(1)=""> _
Public Property Quarter() As Integer
Get
Return m_quarter
End Get
Set(ByVal Value As Integer)
m_quarter = Value
End Set
End Property
'
' Gets or sets a value that indicates the Year e.g. 2005
'
<bindable(true), category("appearance"),="" defaultvalue("")=""> _
Public Property Year() As Integer
Get
Return m_year
End Get
Set(ByVal Value As Integer)
m_year = Value
End Set
End Property
'
' Gets or sets a value that indicates the default BlockColor
'
<bindable(true), category("appearance"),="" defaultvalue("red")=""> _
Public Property BlockColor() As String
Get
Return m_blockColor
End Get
Set(ByVal Value As String)
m_blockColor = Value
End Set
End Property
'
' Gets or sets a value that indicates the cell width of the event calendar 'grid'
'
<bindable(true), category("appearance"),="" defaultvalue("15")=""> _
Public Property CellWidth() As Integer
Get
Return Integer.Parse(m_cellWidth)
End Get
Set(ByVal Value As Integer)
m_cellWidth = Value.ToString()
End Set
End Property
'
' Gets or sets a value that indicates the cell height of the event calendar 'grid'
'
<bindable(true), category("appearance"),="" defaultvalue("15")=""> _
Public Property CellHeight() As Integer
Get
Return Integer.Parse(m_cellHeight)
End Get
Set(ByVal Value As Integer)
m_cellHeight = Value.ToString()
End Set
End Property
'
' Gets or sets a value that indicates a color the event calendar will use to delimit the day names and event names.
'
<bindable(true), category("appearance"),="" defaultvalue("#dcdcdc")=""> _
Public Property ToggleColor() As String
Get
Return m_toggleColor
End Get
Set(ByVal Value As String)
m_toggleColor = Value
End Set
End Property
'
' Gets or sets a value that indicates a color the event calendar will use to delimit the day names and event names.
'
<bindable(true), category("appearance"),="" defaultvalue("#dcdcdc")=""> _
Public Property BlankGifPath() As String
Get
Return m_blankGifPath
End Get
Set(ByVal Value As String)
m_blankGifPath = Value
End Set
End Property
#End Region
#Region "Event Handling"
'
' writes out some javascript so the calendar grid can resize itself
'
' <param name="e" />
Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
MyBase.OnPreRender(e)
If Not MyBase.Page.IsStartupScriptRegistered("EventCalendar") Then
MyBase.Page.RegisterStartupScript("EventCalendar", _
"" + _
"function ResizeTables()" + _
"{" + _
"document.getElementById('divcal').style.width = '1px';" + _
"document.getElementById('divcal').style.width = document.getElementById('tblcal').clientWidth + 'px';" + _
"};" + _
"")
MyBase.Page.RegisterStartupScript("EventCalendarOnLoad", _
"" + _
"ResizeTables();" + _
"")
MyBase.Page.RegisterStartupScript("EventCalendarOnResize", _
"" + _
"ResizeTables();" + _
"")
End If
End Sub
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
' create a 2 column, 1 row table, the first column will contain the text for the tasks that
' is non scrollable.
writer.AddAttribute("border", "0")
writer.AddAttribute("cellSpacing", "0")
writer.AddAttribute("cellPadding", "0")
writer.AddAttribute("width", "100%")
writer.RenderBeginTag("table")
writer.RenderBeginTag("tr")
writer.AddAttribute("valign", "top")
writer.AddAttribute("align", "right")
writer.RenderBeginTag("td nowrap")
RenderLeftHandPane(writer)
writer.RenderEndTag()
writer.AddAttribute("id", "tblcal")
writer.AddAttribute("valign", "top")
writer.AddAttribute("align", "left")
writer.AddAttribute("width", "100%")
writer.RenderBeginTag("td nowrap")
RenderRightHandPane(writer)
writer.RenderEndTag()
writer.RenderEndTag()
writer.RenderEndTag()
End Sub
#End Region
#Region "Helper Functions"
Private Sub RenderLeftHandPane(ByVal writer As HtmlTextWriter)
Dim blocktext, grouptext As String
writer.AddAttribute("border", "1")
writer.AddAttribute("style", "FONT-SIZE: " + Font.Size.ToString + ";FONT-FAMILY: " + Font.Name + ";BORDER-COLLAPSE: collapse")
writer.AddAttribute("borderColor", "#000000")
writer.AddAttribute("cellSpacing", "0")
writer.AddAttribute("cellPadding", "0")
writer.RenderBeginTag("table")
'empty row to match month headers on right hand pane
writer.RenderBeginTag("tr")
writer.RenderBeginTag("td")
writer.Write(" ")
writer.RenderEndTag()
writer.RenderEndTag()
'empty row to match day headers on right hand pane
writer.RenderBeginTag("tr")
writer.RenderBeginTag("td")
writer.Write(" ")
writer.RenderEndTag()
writer.RenderEndTag()
' now need to write the rows
' Load the XML
Dim xmlDoc As New XmlDocument
xmlDoc.LoadXml(m_xmlData)
Dim xmlRows As XmlNodeList = xmlDoc.SelectNodes("//group")
Dim xmlRow As XmlNode
For Each xmlRow In xmlRows
grouptext = xmlRow.SelectSingleNode("name").InnerText
writer.RenderBeginTag("tr")
writer.AddAttribute("bgcolor", m_toggleColor)
writer.AddAttribute("height", m_cellHeight)
writer.RenderBeginTag("td nowrap")
writer.Write((" " + grouptext + " "))
writer.RenderEndTag()
writer.RenderEndTag()
Dim xmlBlocks As XmlNodeList = xmlRow.SelectNodes("block")
Dim xmlBlock As XmlNode
For Each xmlBlock In xmlBlocks
writer.RenderBeginTag("tr")
blocktext = xmlBlock.SelectSingleNode("name").InnerText
'write the activity
writer.AddAttribute("height", m_cellHeight)
writer.RenderBeginTag("td nowrap")
writer.Write((" " + blocktext + " "))
writer.RenderEndTag()
writer.RenderEndTag()
Next xmlBlock
Next xmlRow
writer.RenderEndTag()
End Sub 'RenderLeftHandPane
Private Sub RenderRightHandPane(ByVal writer As HtmlTextWriter)
Dim startdate, enddate, dayname, href, blocktext, blockcolor As String
Dim startindex, endindex, imagewidth, month As Integer
Dim i As Integer
Dim week As Boolean = False
Dim quarter As New QuarterHelper(m_year, m_quarter)
writer.AddAttribute("style", "width:1px; overflow-x:scroll;")
writer.AddAttribute("id", "divcal")
writer.RenderBeginTag("div")
writer.AddAttribute("border", "1")
writer.AddAttribute("style", "FONT-SIZE: " + Font.Size.ToString + ";FONT-FAMILY: " + Font.Name + ";BORDER-COLLAPSE: collapse")
writer.AddAttribute("borderColor", "#000000")
writer.AddAttribute("cellSpacing", "0")
writer.AddAttribute("cellPadding", "0")
writer.RenderBeginTag("table")
'write month headers
writer.RenderBeginTag("tr")
For i = 1 To 3
month = i + 3 * (quarter.QuarterIndex - 1)
writer.AddAttribute("align", "center")
writer.AddAttribute("colspan", quarter.TotalDaysInMonth(month).ToString())
writer.RenderBeginTag("td")
writer.Write(quarter.GetMonthName(i))
writer.RenderEndTag()
Next i
writer.RenderEndTag()
'write day headers
writer.RenderBeginTag("tr")
For i = 3 * quarter.QuarterIndex - 2 To 3 * quarter.QuarterIndex
Dim j As Integer
For j = 1 To quarter.TotalDaysInMonth(i)
dayname = quarter.GetDayName(i, j)
If dayname = "M" Then
week = Not week
End If
writer.AddAttribute("align", "center")
writer.AddAttribute("width", m_cellWidth)
writer.AddAttribute("height", m_cellHeight)
If week Then
writer.AddAttribute("bgcolor", m_toggleColor)
End If
writer.RenderBeginTag("td")
writer.Write(dayname)
writer.RenderEndTag()
Next j
Next i
writer.RenderEndTag()
' now need to write the rows
' Load the XML
Dim xmlDoc As New XmlDocument
xmlDoc.LoadXml(m_xmlData)
Dim xmlRows As XmlNodeList = xmlDoc.SelectNodes("//group")
Dim xmlRow As XmlNode
For Each xmlRow In xmlRows
' empty row to match group name
writer.RenderBeginTag("tr")
writer.AddAttribute("colspan", quarter.Days.ToString())
writer.AddAttribute("width", (quarter.Days * Integer.Parse(m_cellWidth)).ToString())
writer.RenderBeginTag("td")
writer.Write((" "))
writer.RenderEndTag()
writer.RenderEndTag()
Dim node As XmlNode = xmlRow.SelectSingleNode("blockcolor")
If Not (node Is Nothing) Then
blockcolor = node.InnerText
Else
blockcolor = m_blockColor
End If
' write out the events
Dim strHTML As String
Dim xmlBlocks As XmlNodeList = xmlRow.SelectNodes("block")
Dim xmlBlock As XmlNode
For Each xmlBlock In xmlBlocks
writer.RenderBeginTag("tr")
startdate = xmlBlock.SelectSingleNode("StartDate").InnerText
enddate = xmlBlock.SelectSingleNode("EndDate").InnerText
href = xmlBlock.SelectSingleNode("href").InnerText
blocktext = xmlBlock.SelectSingleNode("name").InnerText
startindex = quarter.getColumnIndex(startdate)
endindex = quarter.getColumnIndex(enddate)
'write out the padding cells
For i = 0 To startindex - 1
writer.AddAttribute("width", m_cellWidth)
writer.AddAttribute("height", m_cellHeight)
writer.RenderBeginTag("td")
writer.Write(" ")
writer.RenderEndTag()
Next i
'create the filled in block
writer.AddAttribute("colspan", (endindex - startindex + 1).ToString())
writer.AddAttribute("bgColor", blockcolor)
writer.AddAttribute("width", m_cellWidth)
writer.AddAttribute("height", m_cellHeight)
writer.RenderBeginTag("td nowrap")
If href <> String.Empty Then
imagewidth = (endindex - startindex + 1) * Integer.Parse(m_cellWidth)
strHTML = ""
writer.Write(strHTML)
Else
writer.Write(" ")
End If
writer.RenderEndTag()
'
'write out the padding cells
For i = endindex To (quarter.Days - 1) - 1
writer.AddAttribute("width", m_cellWidth)
writer.AddAttribute("height", m_cellHeight)
writer.RenderBeginTag("td")
writer.Write(" ")
writer.RenderEndTag()
Next i
writer.RenderEndTag()
Next xmlBlock
Next xmlRow
writer.RenderEndTag() ' close table tag
writer.RenderEndTag() ' close div tag
End Sub 'RenderRightHandPane
#End Region
#Region "Helper Classes"
Private Class QuarterHelper
Private m_year As Integer
Private m_quarter As Integer
Private m_names(3) As String
Private m_NoOfDays As Integer
Public Sub New()
End Sub 'New
Public Sub New(ByVal year As Integer, ByVal quarter As Integer)
m_quarter = quarter
m_year = year
m_names = getQuarterNames()
m_NoOfDays = getDaysInQuarter(m_year, m_quarter)
End Sub 'New
Public ReadOnly Property Year() As Integer
Get
Return m_year
End Get
End Property
Public ReadOnly Property QuarterIndex() As Integer
Get
Return m_quarter
End Get
End Property
Public ReadOnly Property Names() As String()
Get
Return m_names
End Get
End Property
Public ReadOnly Property Days() As Integer
Get
Return m_NoOfDays
End Get
End Property
Public Function GetMonthName(ByVal i As Integer) As String
Return m_names((i - 1))
End Function 'GetMonthName
Public Function TotalDays() As Integer
Dim retval As Integer = 0
Select Case m_quarter
Case 1
retval = DateTime.DaysInMonth(m_year, 1)
retval += DateTime.DaysInMonth(m_year, 2)
retval += DateTime.DaysInMonth(m_year, 3)
Case 2
retval = DateTime.DaysInMonth(m_year, 4)
retval += DateTime.DaysInMonth(m_year, 5)
retval += DateTime.DaysInMonth(m_year, 6)
Case 3
retval = DateTime.DaysInMonth(m_year, 7)
retval += DateTime.DaysInMonth(m_year, 8)
retval += DateTime.DaysInMonth(m_year, 9)
Case 4
retval = DateTime.DaysInMonth(m_year, 10)
retval += DateTime.DaysInMonth(m_year, 11)
retval += DateTime.DaysInMonth(m_year, 12)
End Select
Return retval
End Function 'TotalDays
Public Function TotalDaysInMonth(ByVal i As Integer) As Integer
Return DateTime.DaysInMonth(m_year, i)
End Function 'TotalDaysInMonth
Public Function GetDayName(ByVal month As Integer, ByVal day As Integer) As String
Dim retval As String = String.Empty
Dim d As New DateTime(m_year, month, day)
Select Case d.DayOfWeek
Case DayOfWeek.Monday
retval = "M"
Case DayOfWeek.Tuesday
retval = "T"
Case DayOfWeek.Wednesday
retval = "O"
Case DayOfWeek.Thursday
retval = "T"
Case DayOfWeek.Friday
retval = "F"
Case DayOfWeek.Saturday
retval = "L"
Case DayOfWeek.Sunday
retval = "S"
'Case DayOfWeek.Monday
' retval = "M"
'Case DayOfWeek.Tuesday
' retval = "T"
'Case DayOfWeek.Wednesday
' retval = "W"
'Case DayOfWeek.Thursday
' retval = "T"
'Case DayOfWeek.Friday
' retval = "F"
'Case DayOfWeek.Saturday
' retval = "S"
'Case DayOfWeek.Sunday
' retval = "S"
End Select
Return retval
End Function 'GetDayName
Private Function getQuarterNames() As String()
Dim retval(3) As String
Select Case m_quarter
Case 1
retval(0) = "Januar"
retval(1) = "Febuar"
retval(2) = "Marts"
Case 2
retval(0) = "April"
retval(1) = "Maj"
retval(2) = "Juni"
Case 3
retval(0) = "Juli"
retval(1) = "August"
retval(2) = "September"
Case 4
retval(0) = "Oktober"
retval(1) = "November"
retval(2) = "December"
'Case 1
' retval(0) = "January"
' retval(1) = "Febuary"
' retval(2) = "March"
'Case 2
' retval(0) = "April"
' retval(1) = "May"
' retval(2) = "June"
'Case 3
' retval(0) = "July"
' retval(1) = "August"
' retval(2) = "September"
'Case 4
' retval(0) = "October"
' retval(1) = "November"
' retval(2) = "December"
End Select
Return retval
End Function 'getQuarterNames
Private Function getDaysInQuarter(ByVal year As Integer, ByVal quarter As Integer) As Integer
Dim dtS, dtE As DateTime
If quarter < 4 Then
dtS = New DateTime(year, 3 * quarter - 2, 1)
dtE = New DateTime(year, 3 * quarter - 2 + 3, 1)
Else
dtS = New DateTime(year, 3 * quarter - 2, 1)
dtE = New DateTime(year + 1, 1, 1)
End If
Dim ts As New TimeSpan(dtE.Subtract(dtS).Ticks)
Return ts.Days
End Function 'getDaysInQuarter
Public Function getColumnIndex(ByVal day As String) As Integer
Dim dt As DateTime = DateTime.Parse(day)
Dim offset As Integer = 0
Dim retval As Integer = 0
Dim i As Integer
For i = 1 To m_quarter - 1
offset += getDaysInQuarter(m_year, i)
Next i
retval = dt.DayOfYear - 1 - offset
If retval < 0 Then
retval = 0
End If
If retval > getDaysInQuarter(m_year, m_quarter) Then
retval = getDaysInQuarter(m_year, m_quarter)
End If
Return retval
End Function 'getColumnIndex
End Class 'QuarterHelper
#End Region
End Class
------o0o----------
Regards
Svend
|
|
|
|
|
Jean-marc,
I found a small bug in your control. Its handle in a wrong way events that the year is not the same of the control's year.
I did some modifications on the getColumnIndex() function to fix it.
I created a new propertie to set the Culture and I changed the code to get the Days and Month's names in the desired language.
If you, or somebody, wants the code please tell me.
Calixto
|
|
|
|
|
just post the suggested changes here
(in case you croak tomorrow)
|
|
|
|
|
Hi,
I would appreciate the code,
Thanks
|
|
|
|
|
Hi,
I also would appreciate the code,
Thanks
|
|
|
|
|
I would like to get your changes.
|
|
|
|
|
Hi Eduardo,
I would appreciate the code,
Thanks
Andoni
|
|
|
|
|
Hi Calixto, i'm interested on the "Fix".
Can u send me a copy of the code?
Thx
Luca
(sluca@hotmail.com)
|
|
|
|
|
This is a lovely control.
Are there any addition to it, such as events, databinding, etc?
Please email me, if so,
Thanks
|
|
|
|
|
I am unable to get an xml file (instead of a string) to load in the gannt chart. It gives the following error.
The data at the root level is invalid. Line 1, position 1.
Can anyone please tell me what i am doing wrong.
Thank you
|
|
|
|
|
cant you read the file into a string?
|
|
|
|
|
Thank you very much for the response. I finaly got that to work but I get the dreded Object reference not set to an instance of the object
My code is :
Dim myds As New DataSet
Dim myGroupAdapter As SqlDataAdapter
Dim myBlockAdapter As SqlDataAdapter
Dim myconn As New SqlConnection
myconn.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings("connectionString")
myGroupAdapter = New SqlDataAdapter("select name, blockcolor, carid from [group]", myconn)
myBlockAdapter = New SqlDataAdapter("Select href, startdate, enddate, name, carid from block", myconn)
myGroupAdapter.Fill(myds, "group")
myBlockAdapter.Fill(myds, "block")
Dim primaryKey As DataColumn = myds.Tables("group").Columns("CarID")
Dim ForeginKey As DataColumn = myds.Tables("block").Columns("CarID")
Dim relation As New DataRelation("group", primaryKey, ForeginKey)
relation.Nested = True
myds.Relations.Add(relation)
Dim xmldata As String
xmldata = myds.GetXml()
EventCalendarControl2.XMLData = xmldata
EventCalendarControl2.BlankGifPath = "trans.gif"
EventCalendarControl2.Year = 2005
EventCalendarControl2.Quarter = 2
EventCalendarControl2.BlockColor = "blue"
EventCalendarControl2.ToggleColor = "#dcdcdc"
EventCalendarControl2.CellHeight = 15
EventCalendarControl2.CellWidth = 15
End Sub
Can any one please tell me what i am doing wrong.
|
|
|
|
|
Hello,
Great control. I had a doubt. Is it possible to change the xml node to suit my table name. If so where can i make the chages. Otherwise can you please give me the structure of the tables you used to create the xml.
Thank you.
|
|
|
|
|
Will new version be avalible soon? It would really help me.
|
|
|
|
|
Hi Jean-Marc,
I like your control. I wrote a EventHandler for clicking on the date items. I used EventArgs however to get the Dateitem which has begun clicked on, probadly best that I use System.Web.UI.WebControls.DayRenderEventArgs.
If want the code let me know.
Gavin
i386 the technology source
http://www.i386.com
|
|
|
|
|
Hi,
I would appreciate the code,
Thanks
|
|
|
|
|
im going to completely refactor this code to make it more flexible and add more features. for example i want to be able to add repeating events on the same line, as mentioned in a previous message.
watch this space! if anyone wants to contribute please send me your code and ideas.
jean-marc.
|
|
|
|
|
Is there any multispot version?
I need to show record for specified item sold. For example, item A sold on 1 July and 12 July. So i need to highlight those 2 dates.Is it possible to set 2 different time span in one row?(2 set of startdate and enddate within 1 block)?
As I noticed, the text within the <name></name> will appear as tooltip, so is it possible to have 2 set of time span in one row? And each timespan has its own link (href) and tooltip (<name></name>)?
Thanks in advance.
|
|
|
|
|
no there isnt a multispot version. it would be quite easy to do it, you would just need to enhance the XML and get the code to read the xml and create the blocks.
|
|
|
|
|
I was looking for a simple control to display booking schedules for a real eastate agency. I must say i searched for lot of components (ILOG, NetAdvantage, DotNetCharting) but the problem with these is that they all generate images to display the planning instead of html which is much more customisable and flexible (ex : for scrolling)
Nice features to add would be to choose for which period (from, to) the planning would be displayed, to display more periods for one bloc, allow to switch to between hour and day views.
We still examinate some others controls for our project but if we take yours I can post my enhancements if you want.
Best regards
Gilles
|
|
|
|
|
yeah, i would probably now refactor the code, as its a bit messy.
it would be good to be able to choose the period as well.
i wrote a print friendly version (where it displays a month only), but the code got messy.
jm.
|
|
|
|
|
I am interested in you printer friendly version even if it is messy.
Just curious how you are dealing with the div's
JA
|
|
|
|
|
Hi,
I really wondered about the control, this really helps a lot...
is that possible to color in a different way when dates over laps for the same event, and in a month view for unique event?
I'm doin a resource calendar for project tracking sir, can u pls help me out
Regards
Shiva
|
|
|
|
|
It is a great yet simple and has the opportunity to grow, congratulation.
Gilles if you make the enhancements I would like to have a look if possible, as I am working on a similar project.
Thank you.
|
|
|
|
|