Imports System.Data
Imports System.Data.OleDb

Public Class mycalender
    Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents Calendar1 As System.Web.UI.WebControls.Calendar

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        
    End Sub

    Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
        Dim objDBClass As New Acgg.dbClass
        Dim objRead As OleDbDataReader
        Dim strFileNo As String
        Dim strSql As String

        Try
            'strSql = "SELECT FileNo,CLDate FROM NewOrders WHERE Month(ClDate)=" & Month(CDate(e.Day.Date)) & " AND Year(ClDate)=" & Year(CDate(e.Day.Date))
            If Session("DevId") = 0 Then
                strSql = "SELECT o.OrdId,o.FileNo,o.CLDate,p.DevID,p.propid,d.devid FROM NewOrders o,Property p,developments d WHERE Month(ClDate)=" & Month(CDate(e.Day.Date)) & " AND Year(ClDate)=" & Year(CDate(e.Day.Date)) & " and o.PropId=p.PropId AND p.DevId=d.DevId"
            Else
                strSql = "SELECT o.OrdId,o.FileNo,o.CLDate,p.DevID,p.propid,d.devid FROM NewOrders o,Property p,developments d WHERE Month(ClDate)=" & Month(CDate(e.Day.Date)) & " AND Year(ClDate)=" & Year(CDate(e.Day.Date)) & " and o.PropId=p.PropId AND p.DevId=d.DevId AND d.DevId=" & Session("DevId")
            End If
            objDBClass.OpenDB()
            objRead = objDBClass.retReader(strSql)

            Do While objRead.Read
                If e.Day.Date = objRead("ClDate") Then
                    Dim objHypLink As New System.Web.UI.WebControls.HyperLink
                    If e.Cell.Controls.Count = 2 Then
                        objHypLink.Text = " ..."
                        objHypLink.Font.Size = objHypLink.Font.Size.XXSmall
                        objHypLink.ForeColor = Color.Green
                        'objHypLink.NavigateUrl = "javascript:ClCalendarPopup('" & objRead("ClDate") & "');"
                        objHypLink.NavigateUrl = "ClCalendar.aspx?state=dayview&clDate='" & objRead("ClDate") & "'"
                        'Session("state") = "dayview"

                        'objHypLink.NavigateUrl = "ClCalendarPopup.aspx?ClDate=" & objRead("ClDate")
                        'objHypLink.Target = "_Blank"
                        e.Cell.Controls.Add(objHypLink)
                    ElseIf e.Cell.Controls.Count = 1 Then
                        objHypLink.Text = " [" & objRead("FileNo") & "]"
                        objHypLink.Font.Size = objHypLink.Font.Size.Point(7)
                        objHypLink.ForeColor = Color.Red
                        objHypLink.NavigateUrl = "Details.aspx?FromClose=True&FileNo=" & objRead("FileNo")
                        'objHypLink.NavigateUrl = "Details.aspx?FromClose=True&FileNo=" & objRead("OrdId")
                        e.Cell.Controls.Add(objHypLink)
                        e.Cell.BorderColor = Color.LightSkyBlue
                    Else
                        'nothing
                    End If
                End If
            Loop
            objRead.Close()
            objDBClass.CloseDB()
        Catch Exc As Exception
            'lblError.Text = "Error: " & Exc.Message
        Finally
            objRead = Nothing
            objDBClass = Nothing
        End Try

    End Sub

    Private Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
        Dim objDBClass As New Acgg.dbClass
        Dim objRead As OleDbDataReader
        Dim strFileNo As String
        Dim strSql As String
        Dim SDate As String
        Session("state") = "dayview"
        SDate = Calendar1.SelectedDate()
        Response.Redirect("ClCalendar.aspx?clDate='" & SDate & "'")
    End Sub

End Class
