Imports System.Data
Imports System.Data.SqlClient
Partial Class Admin_suppwiseviewreport
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("AdminID") Is Nothing Then
            Response.Redirect("AdminLogin.aspx?sesn=expire")
            Exit Sub
        End If

        Dim str As String
        str = Request.QueryString.Get("Kid")
        str = DecodeURL(str)
        Session("SupplierID") = str
        If Not Page.IsPostBack Then
            fillgrid(str, DropDownList1.SelectedItem.Value)
        End If

        Dim cn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings("ConnectionString"))
        Dim objAdapter As SqlDataAdapter
        Dim ObjDS As DataSet
        cn.Open()
        Try
            'fillgrid(str)
            'objAdapter = New SqlDataAdapter("SELECT Supplier_Master.Supplier_Name, Supplier_Master.Supplier_Address, Supplier_Master.Supplier_PinCode, Supplier_Master.Supplier_TelNumber, City_Master.City_Name, Country_Master.Country_Name, State_Master.State_Name FROM City_Master INNER JOIN Supplier_Master ON City_Master.City_Kid = Supplier_Master.Supplier_CityId INNER JOIN State_Master ON City_Master.City_StateId = State_Master.State_Kid INNER JOIN Country_Master ON State_Master.State_CountryId = Country_Master.Country_Kid where Supplier_Master.Supplier_Kid='" & str & "'", cn)
            objAdapter = New SqlDataAdapter("SELECT Supplier_Master.Supplier_Name,Supplier_Master.Supplier_Address, Supplier_Master.Supplier_PinCode, Supplier_Master.Supplier_TelNumber,City_Master.City_Name, State_Master.State_Name, Country_Master.Country_Name FROM Supplier_Master LEFT OUTER JOIN City_Master ON Supplier_Master.Supplier_CityId = City_Master.City_Kid LEFT OUTER JOIN Country_Master INNER JOIN State_Master ON Country_Master.Country_Kid = State_Master.State_CountryId ON City_Master.City_StateId = State_Master.State_Kid WHERE Supplier_Master.Supplier_Kid = '" & str & "'", cn)
            objAdapter.SelectCommand.CommandType = CommandType.Text
            ObjDS = New DataSet
            objAdapter.Fill(ObjDS)
            If (ObjDS.Tables(0).Rows.Count = 0) Then
                tddetail.Visible = False
                tdmsg.InnerHtml = "No Supplier Details Found"
                Exit Sub
            End If
            tdmsg.InnerHtml = ""
            tddetail.Visible = True

            If (ObjDS.Tables(0).Rows(0).Item("Supplier_Address").ToString = "") Then
                Label1.Text = ""
            End If
            'If (ObjDS.Tables(0).Rows(0).Item("City_Name").ToString = "") Then
            '    Label5.Text = ""
            'End If
            'If (ObjDS.Tables(0).Rows(0).Item("Supplier_PinCode").ToString = "") Then
            '    Label6.Text = ""
            'End If
            If ObjDS.Tables(0).Rows(0).Item("Supplier_TelNumber").ToString = "&nbsp;" Then
                ObjDS.Tables(0).Rows(0).Item("Supplier_TelNumber") = "N/A"
            End If
            lblname.Text = ObjDS.Tables(0).Rows(0).Item("Supplier_Name").ToString
            'Label1.Text = ObjDS.Tables(0).Rows(0).Item("Supplier_Address").ToString & "  " & ObjDS.Tables(0).Rows(0).Item("City_Name").ToString & ", Ph.- " & ObjDS.Tables(0).Rows(0).Item("Supplier_TelNumber").ToString & ",  <br/> " & ObjDS.Tables(0).Rows(0).Item("State_Name").ToString & ", " & ObjDS.Tables(0).Rows(0).Item("Country_Name").ToString & " - " & ObjDS.Tables(0).Rows(0).Item("Supplier_PinCode").ToString
            Label1.Text = ObjDS.Tables(0).Rows(0).Item("Supplier_Address").ToString & ",  " & ObjDS.Tables(0).Rows(0).Item("City_Name").ToString & ",  <br/> " & ObjDS.Tables(0).Rows(0).Item("State_Name").ToString & ", " & ObjDS.Tables(0).Rows(0).Item("Country_Name").ToString & " - " & ObjDS.Tables(0).Rows(0).Item("Supplier_PinCode").ToString & "<br/> Ph.- " & ObjDS.Tables(0).Rows(0).Item("Supplier_TelNumber").ToString
        Catch ex As Exception
            ' Throw ex
        Finally
            cn.Close()
            cn.Dispose()
        End Try
    End Sub

    Public Sub fillgrid(ByVal suppId As String, ByVal ddlVal As Integer)
        Try
            ''''''''''''''''''''
            Dim objAdapter As SqlDataAdapter
            Dim ObjDt As DataTable
            Dim con As New System.Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings("ConnectionString"))
            If (con.State = ConnectionState.Closed) Then
                con.Open()
            End If

            Try
                objAdapter = New SqlDataAdapter("SupplierWiseProduct_Proc", con)
                objAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

                If ddlVal = 0 Then
                    objAdapter.SelectCommand.Parameters.AddWithValue("@Mode", "All")
                    'cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 20)).Value = "All"
                ElseIf ddlVal = 1 Then
                    objAdapter.SelectCommand.Parameters.AddWithValue("@Mode", "Partially Filled")
                    'cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 20)).Value = "Partially Filled"
                ElseIf ddlVal = 2 Then
                    objAdapter.SelectCommand.Parameters.AddWithValue("@Mode", "Filled")
                    'cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 20)).Value = "Filled"
                End If
                objAdapter.SelectCommand.Parameters.AddWithValue("@SupplierID", suppId)
                objAdapter.SelectCommand.CommandTimeout = 200

                ObjDt = New DataTable
                objAdapter.Fill(ObjDt)

                GridView1.DataSource = ObjDt
                GridView1.DataBind()

                lblCount.Text = "Total " + ObjDt.Rows.Count.ToString + " Records Available.."
                Dim product_kid As String
                product_kid = GridView1.Columns(0).ToString
                'Return ObjDt
            Catch ex As Exception
                'RegisterBug(HttpContext.Current.Request.Url.ToString, ex.Message, Err.Number, New System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, System.Net.Dns.GetHostAddresses(My.Computer.Name)(0).ToString, HttpContext.Current.Session("g_User"), Nothing)
            Finally
                con.Close()
                con.Dispose()
            End Try
            ''''''''''''''''
            'Dim da As SqlDataAdapter
            'Dim ds As New DataSet
            'Dim cmd As New SqlCommand

            'cmd.CommandType = CommandType.StoredProcedure
            'cmd.CommandText = "SupplierWiseProduct_Proc"
            'cmd.Connection = con

            'cmd.CommandTimeout = 200
            'da = New SqlDataAdapter(cmd)
            'da.Fill(ds)
           
        Catch ex As SqlException

        End Try
    End Sub

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        Dim str As String
        str = Request.QueryString.Get("Kid")
        str = DecodeURL(str)
        If DropDownList1.SelectedItem.Value = 0 Then
            fillgrid(str, 0)
        ElseIf DropDownList1.SelectedItem.Value = 1 Then
            fillgrid(str, 1)
        ElseIf DropDownList1.SelectedItem.Value = 2 Then
            fillgrid(str, 2)
        End If
    End Sub

    Protected Sub viewedit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            Dim kid As String = sender.CommandArgument()
            kid = kid.Replace("\", "\\")
            Dim script As String
            script = "window.open(""{0}"", ""{1}"", ""{2}"");"
            script = String.Format(script, "../suppliers/addnewproduct.aspx?Product=" & RemoveLiterals(kid), "_blank", "toolbar=0,location=0,scrollbars=1,status=0,menubar=0,resizable=0,width=' + parseInt(screen.width) + ',height=' + parseInt(screen.height) + ';'")
            ScriptManager.RegisterStartupScript(Page, GetType(Page), "Redirect", script, True)
        Catch ex As Exception

        End Try
    End Sub
End Class
