Imports System
Imports System.Data
Partial Class Admin_List_Supplier
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ''If Session("AdminID") = Nothing Then
        '    Response.Redirect("AdminLogin.aspx")
        'End If
        If Session("AdminID") Is Nothing Then
            Response.Redirect("AdminLogin.aspx?sesn=expire")
            Exit Sub
        End If
        If Not IsPostBack Then
            'g_User = Session("g_User").ToString()
            'g_Company = Session("g_Company")
            'g_FinYear = Session("g_FinYear")
            If Session("AdminID") = Nothing Then
                Response.Redirect("AdminLogin.aspx")
            End If
            fillgrid()
        End If
    End Sub

    Protected Sub fillgrid()
        Dim dt As New DataTable
        Dim i As Integer
        Dim arr
        Dim mycat As String = ""
        Dim admincat As String = ""
        Dim finalstr As String
        Dim temp_str As String
        Dim dt_temp As New DataTable
        Dim j As Integer = 0
        Dim dt1 As New DataTable

        Try
            ' query for listing of Category wise supplier
            ''admincat = ReturnValue("select Replace(AdminUser_CategoryId,' - ',',') from AdminUser where AdminUser_Kid='" & Session("AdminID") & "'")

            ''finalstr = admincat.Substring(0, admincat.Length - 1)

            ''arr = Split(finalstr, ",")

            ''For i = 0 To arr.Length - 1
            ''    temp_str = "select distinct Supplier_Kid, Supplier_Code, Supplier_Name, Supplier_Address,Supplier_CategoryId FROM Supplier_Master WHERE Supplier_FinancialYearId = '" & Session("G_FinYear") & "'AND Supplier_CompanyId = '" & Session("G_Company") & "'and supplier_Approved = 'Y' AND Supplier_CategoryId <> '' and Supplier_CategoryId like '%" & arr(i).ToString & "%' AND Supplier_IsDeleted = '0' order by supplier_name asc"
            ''    dt_temp = ReturnDataTable(temp_str)
            ''    dt1.Merge(dt_temp, True)
            ''Next

            '==========query for listing of all supplier================
            temp_str = "SELECT distinct  Supplier_Kid, Supplier_Code, Supplier_Name, Supplier_Address,Supplier_CategoryId FROM Supplier_Master WHERE Supplier_FinancialYearId = '" & Session("G_FinYear") & "'AND Supplier_CompanyId = '" & Session("G_Company") & "'and supplier_Approved = 'Y' AND Supplier_categoryid <> '' AND Supplier_IsDeleted = '0' order by supplier_name asc"
            dt = ReturnDataTable(temp_str)

            'for finding unique record from the datatable

            gvSpplier.Columns(0).Visible = True
            gvSpplier.DataSource = FindUniqueRecord(dt, "Supplier_Kid")
            gvSpplier.DataBind()
            gvSpplier.Columns(0).Visible = False
            If dt.Rows.Count = 3 Then
                divProduct.Style.Add("height", "100px")
            ElseIf dt.Rows.Count = 5 Then
                divProduct.Style.Add("height", "150px")
            ElseIf dt.Rows.Count = 7 Then
                divProduct.Style.Add("height", "200px")
            ElseIf dt.Rows.Count = 9 Then
                divProduct.Style.Add("height", "250px")
            ElseIf dt.Rows.Count > 9 Then
                divProduct.Style.Add("height", "370px")
            End If
        Catch ex As Exception

        End Try
    End Sub
   
    Protected Sub btnDetails_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        'Dim b As Button
        'b = sender
        'Dim kid As String
        'kid = b.CommandArgument
        Response.Redirect("../suppliers/List_Product.aspx?Kid=" & sender.CommandArgument)
    End Sub

    Protected Sub btnPendingProducts_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        'Dim b As Button
        'b = sender
        'Dim kid As String
        'kid = b.CommandArgument
        Response.Redirect("Product_Approval.aspx?ID=" & sender.CommandArgument)
    End Sub

    'Protected Sub gvSpplier_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvSpplier.PageIndexChanging
    '    Try
    '        gvSpplier.PageIndex = e.NewPageIndex
    '        fillgrid()
    '    Catch ex As Exception

    '    End Try

    'End Sub

End Class
