Archivi categoria: Uncategorized

Calendario

Elegantissimo codice .net per visualizzare un calendario html: più piccolo di così non saprei come fare…

[code lang=”vb”]
”’

”’ FUNZIONE GENERALE PER DISEGNARE UN CALENDARIO
”’

Function getCalendar(mese As Integer, anno As Integer) As String
Dim giorni = Enumerable.Range(1, Date.DaysInMonth(anno, mese)).Select(Function(n) New DateTime(anno, mese, n)).ToList
Dim lunedi As List(Of DateTime) = (From l In giorni Where l.DayOfWeek = DayOfWeek.Monday Select l).ToList
If giorni(0).DayOfWeek <> DayOfWeek.Monday Then lunedi.Insert(0, lunedi(0).AddDays(-7))
Dim s As String = “
” & Join(“LMMGVSD”.ToCharArray().Select(Function(i) “ ” & i & “

“).ToArray) & “


s &= Join(lunedi.Select(Function(k) “
” & Join(Enumerable.Range(0, 7).Select(Function(i) IIf(k.AddDays(i).Month = mese, “ ” & k.AddDays(i).Day & “

“, “

“)).ToArray) & “

“).ToArray)
Return “

” & s & “


End Function

[/code]