Imports System.Data.SqlClient
Imports System.Data
Imports System.IO
Imports System.String
Imports ModCommon
Partial Class Admin_categorywisesupplier
    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

        Try
            'Put user code to initialize the page here

            lblMSG.Visible = False
            If Not Page.IsPostBack Then

                '------getting the value of subcatid from the getparents function that declared in this form--------
                g_FinYear = Session("g_FinYear").ToString()
                g_Company = Session("g_Company").ToString()
                g_User = Session("g_User").ToString()

                gvSupplierDetail.Visible = False
                fillRegisteredCategory()
                

            End If


        Catch
        End Try
    End Sub
    Protected Sub fillRegisteredCategory()

        Dim dt As DataTable = ReturnDataTable("Select Category_Kid,Category_Name from Category_Master WHERE Category_ParentID='Root Category' AND Category_IsDeleted='0' AND Category_FinancialYearId='" & g_FinYear & "' AND Category_CompanyId='" & g_Company & "' Order by Category_Name")
        If dt.Rows.Count > 0 Then
            cboCategory.DataTextField = "Category_Name"
            cboCategory.DataValueField = "Category_Kid"
            cboCategory.DataSource = dt
            cboCategory.DataBind()
        End If
        cboCategory.Items.Insert(0, "Select Category")
        cboCategory.Items.FindByText("Select Category").Selected = True
    End Sub
    Private Sub cboCategory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCategory.SelectedIndexChanged
        Try
            If cboCategory.SelectedItem.Text = "Select Category" Then
                 Label2.Visible = True
                Label2.Text = "Please Select the Category"
                Label3.Visible = False
                gvSupplierDetail.Visible = False
            Else
                BindGrid()
            End If
        Catch
        End Try

    End Sub


    Protected Sub gvSupplierDetail_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)
        Try
            gvSupplierDetail.PageIndex = e.NewPageIndex
            BindGrid()
        Catch
        End Try
    End Sub

    Protected Sub BindGrid()
        Try
            gvSupplierDetail.Visible = True

            If cboCategory.SelectedItem.Text = "Select Category" Then
                showmessage("Please Select Category.", lblMSG)

                gvSupplierDetail.Visible = False
                Exit Sub
            Else
                Label2.Visible = False
            End If


            Dim st As String = "SELECT DISTINCT Supplier_Master.Supplier_Name, Supplier_Master.Supplier_Address + ' - ' + City_Master.City_Name + ' - ' + Supplier_Master.Supplier_PinCode + ' - ' + State_Master.State_Name + ' - ' + Country_Master.Country_Name AS Address, Supplier_Master.Supplier_TelCountryCode + '-' + Supplier_Master.Supplier_TelCityCode + '-' + Supplier_Master.Supplier_TelNumber AS Telephone FROM         Supplier_Master INNER JOIN City_Master ON Supplier_Master.Supplier_CityId = City_Master.City_Kid 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  AND Supplier_Master.Supplier_CategoryId LIKE '%" & RemoveLiterals(cboCategory.SelectedItem.Value) & "%' AND Supplier_Master.Supplier_IsDeleted = '0' Order by Supplier_Master.Supplier_Name "
            Dim dt As DataTable = ReturnDataTable(st)

            If dt.Rows.Count > 0 Then
                gvSupplierDetail.Visible = True
                gvSupplierDetail.DataSource = dt
                gvSupplierDetail.DataBind()
            End If

            Dim j As Integer = dt.Rows.Count
            If j > 0 Then
                Label3.Visible = True
                Label3.Text = j & " Supplier(s) Founds."
            Else
                Label3.Text = ""
                Label3.Visible = False
                gvSupplierDetail.DataSource = Nothing
                gvSupplierDetail.DataBind()
            End If

        Catch
        End Try

    End Sub
End Class
