Protected WithEvents dynamicDataGrid As System.Web.UI.WebControls.DataGrid
Protected WithEvents report As System.Web.UI.HtmlControls.HtmlGenericControl
'Input Parameters
Private dtFromDate As DateTime
Private dtToDate As DateTime
Private strMobileList As String
'url for page to link too
Private strURL As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
strMobileList = Request.Form("Mobiles:selectedMobileList")
If (strMobileList = "") Then strMobileList = Request.QueryString("Mobile")
Dim strTemp As String = Request.Form("DateTimeRange:fromDay") & " " & _
Request.Form("DateTimeRange:fromMonth") & " " & _
Request.Form("DateTimeRange:fromYear") & " " & _
Request.Form("DateTimeRange:fromTime")
If (strTemp = " ") Then strTemp = Request.QueryString("FromDateTime")
dtFromDate = Convert.ToDateTime(strTemp, myCulture)
strTemp = Request.Form("DateTimeRange:toYear") & " " & _
Request.Form("DateTimeRange:toMonth") & " " & _
Request.Form("DateTimeRange:toDay") & " " & _
Request.Form("DateTimeRange:toTime")
If (strTemp = " ") Then strTemp = Request.QueryString("ToDateTime")
dtToDate = Convert.ToDateTime(strTemp, myCulture)
strURL = Request.Form("CAN_Message_RES_detail")
'Fetch data
Dim connCAN_Msg As SqlClient.SqlConnection
connCAN_Msg = conDB.Connect
connCAN_Msg.Open()
'to check whether true or false for the km or miles
Dim strSQL As String
Dim a As Boolean
a = Session("user_miles")
'to change to miles
If a = True Then
strSQL = _
" SELECT Mobile.Label + ' ( ' + Mobile.Registration + ' / ' + CAST(CAN_Message.Locator_ID AS varchar(5)) + ' )' AS Vehicle," & _
" SUM(CAN_Message.Distance * .6214) as distance, " & _
" SUM(CAN_Message.Fuel_Consumption / CAN_Message.Distance * .6214) as Fuel_Used," & _
" AVG(CAN_Message.Fuel_Consumption) as Consumption_Rate" & _
" FROM CAN_Message INNER JOIN " & _
" Mobile ON CAN_Message.Locator_ID = Mobile.Mobile_ID " & _
" WHERE CAN_Message.Locator_Id IN (" & strMobileList & ") " & _
" AND CAN_Message.Creation_Date >=" & strSQLFromDateTime & " AND Creation_Date<=" & strSQLToDateTime & _
" GROUP BY Mobile.Label + ' ( ' + Mobile.Registration + ' / ' + CAST(CAN_Message.Locator_ID AS varchar(5)) + ' )' "
Else
'to change to km
strSQL = _
" SELECT Mobile.Label + ' ( ' + Mobile.Registration + ' / ' + CAST(CAN_Message.Locator_ID AS varchar(5)) + ' )' AS Vehicle," & _
" SUM(CAN_Message.Distance) as distance, " & _
" SUM(CAN_Message.Fuel_Consumption / CAN_Message.Distance) as Fuel_Used," & _
" AVG(CAN_Message.Fuel_Consumption) as Consumption_Rate" & _
" FROM CAN_Message INNER JOIN " & _
" Mobile ON CAN_Message.Locator_ID = Mobile.Mobile_ID " & _
" WHERE CAN_Message.Locator_Id IN (" & strMobileList & ") " & _
" AND CAN_Message.Creation_Date >=" & strSQLFromDateTime & " AND Creation_Date<=" & strSQLToDateTime & _
" GROUP BY Mobile.Label + ' ( ' + Mobile.Registration + ' / ' + CAST(CAN_Message.Locator_ID AS varchar(5)) + ' )' "
End If
Dim cmdSQL As SqlCommand = New SqlCommand(strSQL, connCAN_Msg)
Dim daCANMsg As SqlDataAdapter = New SqlDataAdapter(cmdSQL)
Dim dsCANMsg As DataSet = New DataSet()
daCANMsg.Fill(dsCANMsg, "CANMsg")
DisplayTable(dsCANMsg)
End Sub
Sub DisplayTable(ByVal myDataSet As DataSet)
dynamicDataGrid = New DataGrid()
dynamicDataGrid.CssClass = "reportText"
dynamicDataGrid.CellPadding = 0
dynamicDataGrid.CellSpacing = 0
dynamicDataGrid.BorderStyle = BorderStyle.None
dynamicDataGrid.GridLines = GridLines.None
dynamicDataGrid.HeaderStyle.CssClass = "reportTextHeader"
dynamicDataGrid.ItemStyle.CssClass = "reportTextRow"
dynamicDataGrid.AlternatingItemStyle.CssClass = "reportTextRowAlt"
dynamicDataGrid.FooterStyle.CssClass = "reportTextFooter"
dynamicDataGrid.ShowFooter = True
dynamicDataGrid.AutoGenerateColumns = False
Dim myDataGridCol As New BoundColumn()
'myDataGridCol.HeaderImageUrl = "css_reports/reportTextHeaderLeft.jpg"
myDataGridCol.HeaderStyle.Width = Unit.Percentage(0)
myDataGridCol.ItemStyle.CssClass = "reportTextBorderLeft"
dynamicDataGrid.Columns.Add(myDataGridCol)
myDataGridCol = New BoundColumn()
myDataGridCol.HeaderText = "Vehicle"
myDataGridCol.HeaderStyle.CssClass = "col1"
myDataGridCol.DataField = "Vehicle"
dynamicDataGrid.Columns.Add(myDataGridCol)
myDataGridCol = New BoundColumn()
myDataGridCol.HeaderText = "Distance"
myDataGridCol.HeaderStyle.CssClass = "col2"
myDataGridCol.DataField = "Distance"
dynamicDataGrid.Columns.Add(myDataGridCol)
myDataGridCol = New BoundColumn()
myDataGridCol.HeaderText = "Fuel Used"
myDataGridCol.HeaderStyle.CssClass = "col3"
myDataGridCol.DataField = "Fuel_Used"
dynamicDataGrid.Columns.Add(myDataGridCol)
myDataGridCol = New BoundColumn()
myDataGridCol.HeaderText = "Consumption Rate"
myDataGridCol.HeaderStyle.CssClass = "col4"
myDataGridCol.DataField = "Consumption_Rate"
dynamicDataGrid.Columns.Add(myDataGridCol)
myDataGridCol = New BoundColumn()
myDataGridCol.HeaderStyle.CssClass = "col5"
myDataGridCol.ItemStyle.CssClass = "reportTextBorderLeft"
dynamicDataGrid.Columns.Add(myDataGridCol)
report.Controls.Add(dynamicDataGrid)
dynamicDataGrid.DataSource = myDataSet
dynamicDataGrid.DataBind()
End Sub