Imports System.Data.SqlClient
Imports ModCommon
Imports System.Data.Sql

Partial Class Admin_Default
    Inherits System.Web.UI.Page

    Protected Sub btnReport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReport.Click
        Try
            If Session("AdminID") Is Nothing Then
                Response.Redirect("AdminLogin.aspx?sesn=expire")
                Exit Sub
            End If
            If RadioButtonList1.SelectedIndex = -1 Then
                Label1.Visible = True
                Label1.Text = "First Select Product Approval."
                Exit Sub
            End If


            GetGridData()
        Catch
        End Try
    End Sub

    Public Sub GetDataTable(ByVal strCommand As String)
        Try
            Dim dt As Data.DataTable = ReturnDataTable(strCommand)
            Dim i As Integer

            For i = 0 To dt.Rows.Count - 1

                Dim str As String = ReturnValue("SELECT Unit_Name FROM Unit_Master WHERE Unit_Kid = '" & dt.Rows(i).Item("Market Type").ToString & "'")
                Dim lblMarket As Label = CType(GridView1.Rows(i).FindControl("lblMarket"), Label)
                lblMarket.Text = str & " " & dt.Rows(i).Item("Market Price")

                str = ReturnValue("SELECT Unit_Name FROM Unit_Master WHERE Unit_Kid = '" & dt.Rows(i).Item("Atco Type").ToString & "'")
                Dim lblAtcomaart As Label = CType(GridView1.Rows(i).FindControl("lblAtcomaart"), Label)
                lblAtcomaart.Text = str & " " & dt.Rows(i).Item("Atco Price")

                'Dim myTime As DateTime = Convert.ToDateTime(dt.Rows(i).Item("Reg Date")).ToString("dd-MMM-yyyy")
                Dim lblRegDate As Label = CType(GridView1.Rows(i).FindControl("lblRegDate"), Label)
                lblRegDate.Text = Convert.ToDateTime(dt.Rows(i).Item("Reg Date")).ToString("dd-MMM-yyyy")

            Next

        Catch
        End Try

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            
            Label1.Visible = False
        Catch
        End Try
    End Sub

    
    Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
        Try
            GridView1.PageIndex = e.NewPageIndex
            GetGridData()
        Catch
        End Try
    End Sub

    Public Sub GetGridData()
        Try
            Dim con As New SqlConnection
            Dim strCommandString As String


            Dim str1 As String = TextBox1.Text
            Dim str2 As String = TextBox2.Text

            Dim fromDate As Date = Convert.ToDateTime(TextBox1.Text).ToString("MM/dd/yyyy")
            Dim toDate As Date = Convert.ToDateTime(TextBox2.Text).ToString("MM/dd/yyyy")
            con.ConnectionString = ConfigurationManager.AppSettings("ConnectionString")
            con.Open()

            If RadioButtonList1.SelectedIndex = 0 Then
                strCommandString = "SELECT Product_Master.Product_Code as [Code], Product_Master.Product_Name as [Name], Product_Master.Product_ModelNo as [Model No], Product_Master.Product_MarketPriceType as [Market Type], Product_Master.Product_MarketPrice as [Market Price], Product_Master.Product_AtcoPriceType as [Atco Type], Product_Master.Product_AtcoPrice as [Atco Price], Supplier_Master.Supplier_Name as [Supp Name], Product_Master.Product_RegDate as [Reg Date] FROM Product_Master INNER JOIN Supplier_Master ON Product_Master.Product_SupplierId = Supplier_Master.Supplier_Kid WHERE Product_Master.Product_Approved = 'Y' AND Product_Master.Product_RegDate >= '" & fromDate & "' AND Product_Master.Product_RegDate <= '" & toDate & "'"
            ElseIf RadioButtonList1.SelectedIndex = 1 Then
                strCommandString = "SELECT Product_Master.Product_Code as [Code], Product_Master.Product_Name as [Name], Product_Master.Product_ModelNo as [Model No], Product_Master.Product_MarketPriceType as [Market Type], Product_Master.Product_MarketPrice as [Market Price], Product_Master.Product_AtcoPriceType as [Atco Type], Product_Master.Product_AtcoPrice as [Atco Price], Supplier_Master.Supplier_Name as [Supp Name], Product_Master.Product_RegDate as [Reg Date] FROM Product_Master INNER JOIN Supplier_Master ON Product_Master.Product_SupplierId = Supplier_Master.Supplier_Kid WHERE Product_Master.Product_Approved = 'N' AND Product_Master.Product_RegDate >= '" & fromDate & "' AND Product_Master.Product_RegDate <= '" & toDate & "'"
            ElseIf RadioButtonList1.SelectedIndex = 2 Then
                strCommandString = "SELECT Product_Master.Product_Code as [Code], Product_Master.Product_Name as [Name], Product_Master.Product_ModelNo as [Model No], Product_Master.Product_MarketPriceType as [Market Type], Product_Master.Product_MarketPrice as [Market Price], Product_Master.Product_AtcoPriceType as [Atco Type], Product_Master.Product_AtcoPrice as [Atco Price], Supplier_Master.Supplier_Name as [Supp Name], Product_Master.Product_RegDate as [Reg Date] FROM Product_Master INNER JOIN Supplier_Master ON Product_Master.Product_SupplierId = Supplier_Master.Supplier_Kid WHERE Product_Master.Product_RegDate >= '" & fromDate & "' AND Product_Master.Product_RegDate <= '" & toDate & "'"
            End If

            Dim myCommand As SqlCommand = New SqlCommand(strCommandString, con)

            Dim myAdapter As New SqlDataAdapter
            myAdapter.SelectCommand = myCommand

            Dim SqlDataSet As New Data.DataSet

            myAdapter.Fill(SqlDataSet, "Table1")

            Dim myDataTable1 As Data.DataTable = SqlDataSet.Tables("Table1")

            GridView1.DataSource = SqlDataSet
            GridView1.DataBind()

            GetDataTable(strCommandString)

            con.Close()
        Catch
        End Try
    End Sub
End Class
