Imports System.Data
Imports System.Data.OleDb
Imports System.Web.UI.Control
Public Class dayview
    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
    Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
    Protected WithEvents lblerr As System.Web.UI.WebControls.Label
    Protected WithEvents lblDate As System.Web.UI.WebControls.Label
    Protected WithEvents lstClosing As System.Web.UI.WebControls.ListBox

    '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
        If Request.QueryString("clDate") = "" Then
            getrecord(Calendar1.TodaysDate.ToString())
            Dim mydate1 As String
            mydate1 = DatePart(DateInterval.Month, Calendar1.TodaysDate()).ToString()
            mydate1 = mydate1 & "/" & DatePart(DateInterval.Day, Calendar1.TodaysDate()).ToString()
            mydate1 = mydate1 & "/" & DatePart(DateInterval.Year, Calendar1.TodaysDate()).ToString()
            lblDate.Text = mydate1
        Else
            getrecord(Request.QueryString("clDate"))
            Dim mydate As String
            mydate = Request.QueryString("clDate")
            mydate = Replace(mydate, "'", "")
            lblDate.Text = mydate
        End If
    End Sub
    Public Sub getrecord(ByVal strdate As String)
        Dim objDBClass As New Acgg.dbClass

        Dim strFileNo As String
        Dim strSql As String
        Dim clTime As String
        Dim intCount As Integer

        '*****************************************************************************************
        Dim arrTime As New ArrayList

        arrTime.Add("12:00 AM")
        arrTime.Add("01:00 AM")
        arrTime.Add("02:00 AM")
        arrTime.Add("03:00 AM")
        arrTime.Add("04:00 AM")
        arrTime.Add("05:00 AM")
        arrTime.Add("06:00 AM")
        arrTime.Add("07:00 AM")
        arrTime.Add("08:00 AM")
        arrTime.Add("09:00 AM")
        arrTime.Add("10:00 AM")
        arrTime.Add("11:00 AM")
        arrTime.Add("12:00 PM")
        arrTime.Add("01:00 PM")
        arrTime.Add("02:00 PM")
        arrTime.Add("03:00 PM")
        arrTime.Add("04:00 PM")
        arrTime.Add("05:00 PM")
        arrTime.Add("06:00 PM")
        arrTime.Add("07:00 PM")
        arrTime.Add("08:00 PM")
        arrTime.Add("09:00 PM")
        arrTime.Add("10:00 PM")
        arrTime.Add("11:00 PM")
        '*****************************************************************************************
        If Session("DevId") = 0 Then
            strSql = "SELECT o.FileNo,o.CLDate,o.CLTime,p.DevID,p.propid,d.devid FROM NewOrders o, Property p,Developments d WHERE Day(o.ClDate)=" & Day(CDate(strdate)) & " AND Month(o.ClDate)=" & Month(CDate(strdate)) & " AND Year(o.ClDate)=" & Year(strdate) & " and o.PropId=p.PropId AND p.DevId=d.DevId"
        Else
            strSql = "SELECT o.FileNo,o.CLDate,o.CLTime,p.DevID,p.propid,d.devid FROM NewOrders o, Property p,Developments d WHERE Day(o.ClDate)=" & Day(CDate(strdate)) & " AND Month(o.ClDate)=" & Month(CDate(strdate)) & " AND Year(o.ClDate)=" & Year(strdate) & " and o.PropId=p.PropId AND p.DevId=d.DevId AND d.DevId=" & Session("DevId")
        End If

        objDBClass.OpenDB()
        '*******************************************************************************************
        Dim mytable As DataTable = New DataTable("mytable")
        Dim myrow As DataRow
        Dim blHas As Boolean

        Dim colHrs As New DataColumn
        colHrs.DataType = System.Type.GetType("System.String")
        colHrs.Caption = "Hours"
        colHrs.ColumnName = "Hours"
        mytable.Columns.Add(colHrs)

        Dim colFile As New DataColumn
        colFile.DataType = System.Type.GetType("System.String")
        colFile.Caption = "File #"
        colFile.ColumnName = "FileNo"
        mytable.Columns.Add(colFile)

        Dim objRead As OleDbDataReader
        Dim arrFile(100) As String
        Dim blHourAdded As Boolean

        For intCount = 0 To arrTime.Count - 1
            blHas = False
            clTime = arrTime.Item(intCount)
            blHourAdded = False
            objRead = objDBClass.retReader(strSql)
            If objRead.HasRows Then
                While objRead.Read()
                    If clTime = objRead("CLTime") Then
                        myrow = mytable.NewRow()
                        If Not blHourAdded Then
                            myrow("Hours") = clTime.ToString()
                        Else
                            myrow("Hours") = ""
                        End If
                        myrow("FileNo") = objRead("FileNo")
                        mytable.Rows.Add(myrow)
                        blHas = True
                        blHourAdded = True
                    End If
                End While

                If Not blHas Then
                    myrow = mytable.NewRow()
                    myrow("Hours") = clTime
                    myrow("FileNo") = ""
                    mytable.Rows.Add(myrow)
                End If
            End If
            objRead.Close()
            objRead = Nothing
        Next

        DataGrid1.Visible = True
        DataGrid1.DataSource = mytable
        DataGrid1.DataBind()
        mytable.Reset()
        '*******************************************************************************************

        Dim objRead1 As OleDbDataReader
        objRead1 = objDBClass.retReader(strSql)
        If objRead1.HasRows() Then
            lblerr.Visible = False
            DataGrid1.Visible = True
        Else
            lblerr.Visible = True
            DataGrid1.Visible = False
        End If

        objRead1 = Nothing
        objDBClass = Nothing
    End Sub
    Private Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
        Dim myDate As String
        Session("state") = "dayview"
        getrecord(Calendar1.SelectedDate.ToString())

        myDate = DatePart(DateInterval.Month, Calendar1.SelectedDate.Date()).ToString()
        myDate = myDate & "/" & DatePart(DateInterval.Day, Calendar1.SelectedDate.Date()).ToString()
        myDate = myDate & "/" & DatePart(DateInterval.Year, Calendar1.SelectedDate.Date()).ToString()

        lblDate.Text = myDate

    End Sub
End Class
