Imports System
Imports System.Web
Imports System.Data
Imports System.Web.Security
Imports System.Web.UI.WebControls
Partial Class Admin_Product_Approval
    Inherits System.Web.UI.Page
    Shared Category(10) As String
    Shared i As Integer
    Shared id As String
    Shared suppkid As String

    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 Page.IsPostBack = False Then
            If Session("AdminID") = Nothing Then
                Response.Redirect("AdminLogin.aspx")
            End If
            If Request.QueryString("ID") = Nothing Then
                suppkid = Session("suppkid")
            Else

                Session("suppkid") = Request.QueryString("ID").ToString()
                suppkid = Session("suppkid")
            End If
            g_User = Session("g_User").ToString
            g_Company = Session("g_Company").ToString
            g_FinYear = Session("g_FinYear").ToString
            FillGrid()
            Panel1.Visible = False
            FormView1.Visible = False
            'If gvapproval.Rows.Count <> 0 Then
            '    LinkButton1.Text = "You Have " & gvapproval.Rows.Count.ToString() & " Pending Product Approvals..!!"
            '    gvapproval.Visible = False
            '    'btnUpdate.Visible = False
            '    div1.Visible = False
            'Else
            '    LinkButton1.Text = "You Dont Have Any Pending Approvals..!!"
            '    gvapproval.Visible = False
            '    'btnUpdate.Visible = False
            '    div1.Visible = False
            'End If
        Else
            'linkButton1.Visible = False
        End If
    End Sub
    Private Sub FillGrid()
        gvapproval.Columns(0).Visible = True
        gvapproval.DataSource = getTable("SELECT Product_Master.Product_Name AS Name, Product_Master.Product_Description AS Description, Product_Master.Product_Kid AS Kid, Product_Master.Product_Image AS Image, Supplier_Master.Supplier_Name AS SupplierName FROM Product_Master INNER JOIN Supplier_Master ON Product_Master.Product_SupplierId = Supplier_Master.Supplier_Kid WHERE (Product_Master.Product_Approved = 'N')and Product_SupplierId = '" & RemoveLiterals(suppkid) & "'and Product_Isdeleted = '0' order by Product_Name", "ProductDetails")
        gvapproval.DataBind()
        gvapproval.Columns(0).Visible = False
    End Sub

    'Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
    '    If gvapproval.PageCount <> 0 Then
    '        gvapproval.Visible = True
    '        div1.Visible = True
    '    Else
    '        gvapproval.Visible = False
    '        div1.Visible = False
    '    End If
    'End Sub

    Protected Sub btnDetails_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim b As Button
        Panel1.Visible = False
        b = sender
        Dim Kid As String
        Kid = b.CommandArgument
        FormView1.Visible = True
        i = 0
        FormView1.DataSource = getTable("SELECT Product_Master.*, Product_Kid AS Expr1, Product_IsDeleted AS Expr2 FROM Product_Master WHERE Product_Kid = '" & RemoveLiterals(Kid) & "'AND Product_IsDeleted = '0'", "ViewDetails")
        FormView1.DataBind()
        Dim marketprice As String
        marketprice = ReturnValue("Select Unit_Name from Unit_Master Where Unit_Kid = '" & CType(FormView1.FindControl("lblMarketUnit"), Label).Text & "'and Unit_IsDeleted = '0'")
        CType(FormView1.FindControl("lblMarketUnit"), Label).Text = marketprice
        Dim Atcomaartprice As String
        Atcomaartprice = ReturnValue("Select Unit_Name from Unit_Master Where Unit_Kid = '" & CType(FormView1.FindControl("lblAtcomaartUnit"), Label).Text & "'and Unit_IsDeleted = '0'")
        CType(FormView1.FindControl("lblAtcomaartUnit"), Label).Text = Atcomaartprice
        Dim SellUnit As String
        SellUnit = ReturnValue("Select Unit_Name from Unit_Master Where Unit_Kid = '" & CType(FormView1.FindControl("lblSellUnit"), Label).Text & "'and Unit_IsDeleted = '0'")
        CType(FormView1.FindControl("lblSellUnit"), Label).Text = SellUnit
        Dim ShipUnit As String
        ShipUnit = ReturnValue("Select Unit_Name from Unit_Master Where Unit_Kid = '" & CType(FormView1.FindControl("lblShipUnit"), Label).Text & "'and Unit_IsDeleted = '0'")
        CType(FormView1.FindControl("lblShipUnit"), Label).Text = ShipUnit
        Dim WeightUnit As String
        WeightUnit = ReturnValue("Select Unit_Name from Unit_Master Where Unit_Kid = '" & CType(FormView1.FindControl("lblWeightUnit"), Label).Text & "'and Unit_IsDeleted = '0'")
        CType(FormView1.FindControl("lblWeightUnit"), Label).Text = WeightUnit
        Dim DimensionUnit As String
        DimensionUnit = ReturnValue("Select Unit_Name from Unit_Master Where Unit_Kid = '" & CType(FormView1.FindControl("lblDimensionUnit"), Label).Text & "'and Unit_IsDeleted = '0'")
        CType(FormView1.FindControl("lblDimensionUnit"), Label).Text = DimensionUnit
        Dim DispatchUnit As String
        DispatchUnit = ReturnValue("Select Unit_Name from Unit_Master Where Unit_Kid = '" & CType(FormView1.FindControl("lblDispatchUnit"), Label).Text & "'and Unit_IsDeleted = '0'")
        CType(FormView1.FindControl("lblDispatchUnit"), Label).Text = DispatchUnit
        Dim Brand As String
        Brand = ReturnValue("Select Brand_Name from Brand_Master Where Brand_Kid = '" & CType(FormView1.FindControl("lblBrand"), Label).Text & "'and Brand_IsDeleted = '0'")
        CType(FormView1.FindControl("lblBrand"), Label).Text = Brand
        Dim catid As String
        catid = ReturnValue("Select Product_CategoryID from Product_Master where Product_Kid= '" & Kid & "'and Product_IsDeleted='0' and Product_FinancialYearId ='" & g_FinYear & "' and Product_CompanyId ='" & g_Company & "'")
        FillCategoryName(catid)
    End Sub
    Public Sub FillCategoryName(ByVal Catid As String)
        Dim dt As DataTable
        dt = ReturnDataTable("Select * From Category_Master Where Category_Kid ='" & Catid & "' and Category_Isdeleted = '0' and Category_FinancialYearId ='" & g_FinYear & "' and Category_CompanyId ='" & g_Company & "'")
        Dim ParentId As String
        ParentId = dt.Rows(0).Item(3).ToString()
        If ParentId = "Root Category" Then
            'Label1.Text += dt.Rows(0).Item(2).ToString()
            'Dim CategoryName(10) As String
            Dim j As Integer
            Category(i) = dt.Rows(0).Item(2).ToString() & " > "
            'Array.Reverse(Category)
            For j = 0 To i
                CType(FormView1.FindControl("lblCategoryName"), Label).Text += Category(i)
                i = i - 1
            Next
            Exit Sub
        Else
            Category(i) = dt.Rows(0).Item(2).ToString() & " > "
            i = i + 1
            'Label1.Text += dt.Rows(0).Item(2).ToString() & "  >>  "
            FillCategoryName(dt.Rows(0).Item(3).ToString())
        End If
        'GridView1.DataSource = dt
        'GridView1.DataBind()
    End Sub

    Protected Sub btnApprove_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        FormView1.Visible = False
        Panel1.Visible = False
        Dim b As Button
        b = sender
        Dim Kid As String
        Kid = b.CommandArgument
        Dim sql As String = "UPDATE Product_Master SET Product_Approved = 'Y' WHERE (Product_Kid = '" & Kid & "') AND (Product_IsDeleted = N'0')"
        ExecuteQuery(sql)
        FillGrid()
        CreateMessageAlert(Me, "Prodcut approved.", "StrKeyVal")
    End Sub

    Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Panel1.Visible = True
        FormView1.Visible = False
        Dim b As Button
        b = sender
        id = b.CommandArgument
        lblProductName.Text = "Product : " & ReturnValue("Select Product_Name from Product_Master where Product_IsDeleted = '0' and Product_Kid = '" & id & "'")
    End Sub

    Protected Sub gvapproval_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvapproval.SelectedIndexChanged

    End Sub

   
    Protected Sub FormView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewPageEventArgs) Handles FormView1.PageIndexChanging

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        FormView1.Visible = False
    End Sub

    Protected Sub btnDetails_Click1(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub

    Protected Sub btnYes_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnYes.Click
        Dim sql As String = "UPDATE Product_Master SET Product_Isdeleted = '1' WHERE (Product_Kid = '" & id & "')"
        ExecuteQuery(sql)
        FillGrid()
        Panel1.Visible = False
    End Sub

    Protected Sub btnNo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNo.Click
        Panel1.Visible = False
    End Sub

    Protected Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        FormView1.Visible = False
    End Sub

    Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Response.Redirect("List_Supplier.aspx")
    End Sub
End Class
