Imports System
Imports System.Data
Imports System.Data.SqlClient

Partial Class List_Product
    Inherits System.Web.UI.Page
    

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Dim logName As String = Request.QueryString.Get("logName")
        'Dim logTime As String = Request.QueryString.Get("logTime")
        'If logTime <> "" Then
        '    tdlog.InnerHtml = "You previously logged on " & logTime
        '    InsertAdminUserLog(Session("LogKid"), logName, 0, "AdminLogin", "Update")
        'End If
        Try

      
            txtcode.Attributes.Add("OnKeyPress", "javascript:if (event.keyCode == 13){document.getElementById('" & btnsearch.ClientID.ToString & "').click;} ")

            If Page.IsPostBack = False Then
                btnAddProd.Attributes.Add("onclick", "return AddNewProduct();")
                Session("ProductId") = Nothing
                If Request.QueryString("kid") = Nothing Then
                    Session("Code") = Nothing
                Else
                    Session("SupplierID") = Nothing
                    Session("ProductId") = Nothing
                    Session("SupplierID") = Request.QueryString("Kid")
                    Session("g_User") = ReturnValue("select Supplier_AdminUserID from supplier_master where Supplier_kid='" & RemoveLiterals(Session("SupplierID").ToString) & "' and Supplier_IsDeleted='0'")
                End If
                If Session.Item("SupplierID") Is Nothing Then
                    Response.Redirect("listproduct.aspx")
                Else

                    Session("g_User") = ReturnValue("select Supplier_AdminUserID from supplier_master where Supplier_kid='" & RemoveLiterals(Session("SupplierID").ToString) & "'  and Supplier_IsDeleted='0'")
                    ' Label1.Text = " Welcome  " & ReturnValue("select  Supplier_Name from Supplier_Master where supplier_kid='" & RemoveLiterals(Session.Item("SupplierID").ToString.Trim) & "' ")

                    'FillGrid()
                    FillGridNonApproved()
                    FillGridPartiallyFilled()
                    lblFilledProd.Text = "Total Records - " + "<b style='color:blue'>" + gvNonApproved.Rows.Count.ToString() + "</b>"
                    If gvNonApproved.Rows.Count = 0 Then
                        divFilledProduct.Style.Add("height", "50px")
                    ElseIf gvNonApproved.Rows.Count = 1 Then
                        divFilledProduct.Style.Add("height", "70px")
                    ElseIf gvNonApproved.Rows.Count = 2 Then
                        divFilledProduct.Style.Add("height", "140px")
                    ElseIf gvNonApproved.Rows.Count = 3 Then
                        divFilledProduct.Style.Add("height", "210px")
                    ElseIf gvNonApproved.Rows.Count = 4 Then
                        divFilledProduct.Style.Add("height", "280px")
                    ElseIf gvNonApproved.Rows.Count >= 5 Then
                        divFilledProduct.Style.Add("height", "350px")
                    End If
                    lblPartFilledProd.Text = "Total Records - " + "<b style='color:blue'>" + gvPartiallyFilled.Rows.Count.ToString() + "</b>"
                    If gvPartiallyFilled.Rows.Count = 0 Then
                        divPartFilledProduct.Style.Add("height", "50px")
                    ElseIf gvPartiallyFilled.Rows.Count = 1 Then
                        divPartFilledProduct.Style.Add("height", "70px")
                    ElseIf gvPartiallyFilled.Rows.Count = 2 Then
                        divPartFilledProduct.Style.Add("height", "140px")
                    ElseIf gvPartiallyFilled.Rows.Count = 3 Then
                        divPartFilledProduct.Style.Add("height", "210px")
                    ElseIf gvPartiallyFilled.Rows.Count = 4 Then
                        divPartFilledProduct.Style.Add("height", "280px")
                    ElseIf gvPartiallyFilled.Rows.Count >= 5 Then
                        divPartFilledProduct.Style.Add("height", "350px")
                    End If
                    'If Session("AdminID") = Nothing Then
                    '    Label1.Text = "WelCome To Mr. " & ReturnValue("Select Supplier_Name from Supplier_Master where Supplier_Kid = '" & Session("SupplierID").ToString() & "'and Supplier)IsDeleted = '0'")
                    'Else
                    '    Label1.Text = "WelCome To Mr. " & ReturnValue("Select Supplier_Name from Supplier_Master where Supplier_Kid = '" & Session("SupplierID").ToString() & "'and Supplier)IsDeleted = '0'")
                    'End If
                End If
                If Session("AdminID") <> Nothing Then
                    'btnAddProd.Visible = False
                    Session("g_User") = Session("AdminID")
                    '    ' Label1.Text = " Supplier:- " & ReturnValue("select  Supplier_Name from Supplier_Master where supplier_kid='" & RemoveLiterals(Session.Item("SupplierID").ToString.Trim) & "' ")
                End If
                ' Response.Cache.SetCacheability(HttpCacheability.NoCache)
            Else

            End If
        Catch ex As Exception
            Response.Write(ex.Message.ToString)
        End Try
    End Sub

    Protected Sub FillGridPartiallyFilled()
        Try
            If con.State = ConnectionState.Open Then
                con.Close()
            End If
            Dim ds As New DataSet
            Dim da As SqlDataAdapter
            da = New SqlDataAdapter("Product_NonApproved_Proc", con)
            da.SelectCommand.CommandType = CommandType.StoredProcedure
            da.SelectCommand.Parameters.Add(New SqlParameter("@SupplierId", SqlDbType.NVarChar))
            da.SelectCommand.Parameters("@SupplierId").Value = RemoveLiterals(Session("SupplierID"))
            da.SelectCommand.Parameters.Add(New SqlParameter("@Mode", SqlDbType.NVarChar))
            da.SelectCommand.Parameters("@Mode").Value = "Partially"
            da.Fill(ds)

            gvPartiallyFilled.Visible = True
            gvPartiallyFilled.Columns(0).Visible = True
            gvPartiallyFilled.Columns(1).Visible = True
            gvPartiallyFilled.DataSource = ds
            gvPartiallyFilled.DataBind()
            'System.Threading.Thread.Sleep(500)
            gvPartiallyFilled.Columns(0).Visible = False
            gvPartiallyFilled.Columns(1).Visible = False
            
        Catch ex As Exception
            Response.Write(ex.Message.ToString)
        End Try
    End Sub

    Protected Sub FillGridNonApproved()
        Try
            If con.State = ConnectionState.Open Then
                con.Close()
            End If
            Dim ds As New DataSet
            Dim da As SqlDataAdapter
            da = New SqlDataAdapter("Product_NonApproved_Proc", con)
            da.SelectCommand.CommandType = CommandType.StoredProcedure
            da.SelectCommand.Parameters.Add(New SqlParameter("@SupplierId", SqlDbType.NVarChar))
            da.SelectCommand.Parameters("@SupplierId").Value = RemoveLiterals(Session("SupplierID"))
            da.SelectCommand.Parameters.Add(New SqlParameter("@Mode", SqlDbType.NVarChar))
            da.SelectCommand.Parameters("@Mode").Value = "Filled"
            da.Fill(ds)

            gvNonApproved.Visible = True
            gvNonApproved.Columns(0).Visible = True
            gvNonApproved.Columns(1).Visible = True
            gvNonApproved.Columns(4).Visible = True
            gvNonApproved.DataSource = ds
            gvNonApproved.DataBind()
            'System.Threading.Thread.Sleep(500)
            gvNonApproved.Columns(0).Visible = False
            gvNonApproved.Columns(1).Visible = False
            gvNonApproved.Columns(4).Visible = False
            
        Catch ex As Exception
            Response.Write(ex.Message.ToString)
        End Try
    End Sub

    'Private Sub FillGrid()
    '    Try

    '        Dim index As Integer
    '        Dim pindex As Decimal
    '        Dim page As Integer
    '        Dim dt As DataTable
    '        Dim dr() As DataRow
    '        ' If Session("ProductList") Is Nothing Then
    '        dt = ReturnDataTable("Select    Product_Kid, Product_Code, Product_Name, Product_ModelNo, Product_Image  from Product_Master where Product_SupplierID='" & Session("SupplierID").ToString.Trim & "' and Product_IsDeleted='0' AND Product_Approved='Y'  ORDER BY Product_Code asc")
    '        'Session("ProductList") = dt
    '        ' Else
    '        ' dt = CType(Session("ProductList"), DataTable)
    '        'dt.DefaultView.RowFilter = ""
    '        ' End If


    '        If Session("Code") <> Nothing Then
    '            dr = dt.Select("Product_Code='" & Session("Code") & "'")
    '            If (dr.Length = 0) Then
    '                tdmsg.InnerHtml = "No Search Results Found!"
    '                Exit Sub
    '            End If
    '            tdmsg.InnerHtml = ""
    '            index = dt.Rows.IndexOf(dr(0)) + 1
    '            pindex = index / 5
    '            Dim str As String
    '            str = pindex.ToString
    '            If str.Contains(".") Then
    '                page = Integer.Parse(pindex.ToString.Substring(0, pindex.ToString.IndexOf(".")))
    '                gvProdDetails.PageIndex = page
    '            Else
    '                gvProdDetails.PageIndex = pindex - 1
    '            End If
    '            'pindex = index / 5
    '            'If index Mod 5 > 0 Then
    '            '    If index > 5 Then
    '            '        pindex = pindex + 1
    '            '    End If
    '            'End If
    '            ' ''If pindex = 0 Then
    '            ' ''    gvProdDetails.PageIndex = pindex
    '            ' ''Else
    '            ' ''    gvProdDetails.PageIndex = pindex + 1
    '            ' ''End If
    '        End If

    '        gvProdDetails.Visible = True
    '        gvProdDetails.Columns(0).Visible = True
    '        gvProdDetails.Columns(1).Visible = True
    '        gvProdDetails.DataSource = dt '.DefaultView.ToTable 'ReturnDataTable(qstr)
    '        gvProdDetails.DataBind()
    '        System.Threading.Thread.Sleep(500)
    '        gvProdDetails.Columns(0).Visible = False
    '        gvProdDetails.Columns(1).Visible = False
    '        If gvProdDetails.Rows.Count > 0 Then
    '            Label1.Visible = True
    '            txtcode.Visible = True
    '            btnsearch.Visible = True
    '        Else
    '            Label1.Visible = False
    '            txtcode.Visible = False
    '            btnsearch.Visible = False
    '        End If


    '        Session("Code") = Nothing
    '    Catch ex As Exception

    '    End Try
    'End Sub

    Private Shared Sub CheckAndFixPageIndex(ByRef gvGrid As System.Web.UI.WebControls.GridView, ByVal NewPageIndex As Integer)
        Dim intRows As Integer = -1

        If gvGrid.AllowPaging = True Then
            If Not gvGrid.DataSource Is Nothing Then
                If TypeOf gvGrid.DataSource Is System.Data.DataView Then
                    intRows = DirectCast(gvGrid.DataSource, System.Data.DataView).Count
                ElseIf TypeOf gvGrid.DataSource Is System.Data.DataTable Then
                    intRows = DirectCast(gvGrid.DataSource, System.Data.DataTable).Rows.Count
                ElseIf TypeOf gvGrid.DataSource Is ICollection Then
                    intRows = DirectCast(gvGrid.DataSource, ICollection).Count
                Else
                    intRows = -1
                End If

                If ((intRows - 1) \ gvGrid.PageSize) >= NewPageIndex Then
                    gvGrid.PageIndex = NewPageIndex
                Else
                    gvGrid.PageIndex = 0
                End If
            Else
                If (gvGrid.PageCount - 1) < NewPageIndex Then
                    gvGrid.PageIndex = 0
                Else
                    gvGrid.PageIndex = NewPageIndex
                End If
            End If
        End If
    End Sub

    Protected Sub lnkbtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        'Response.Redirect("Product_Information.aspx?ID=" & sender.CommandArgument())
        Response.Redirect("product-information.aspx?ID=" & RemoveLiterals(sender.CommandArgument()) & "&index=" & gvProdDetails.PageIndex)
    End Sub

    'Protected Sub gvProdDetails_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvProdDetails.PageIndexChanging
    '    Try

    '        gvProdDetails.PageIndex = e.NewPageIndex

    '        FillGrid()
    '    Catch ex As Exception

    '    End Try
    'End Sub

    Protected Sub BtnSkip_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddProd.Click
        Session("ProductId") = Nothing
        Session("NewProduct") = "NewProduct"
        'Response.Redirect("Product_Information.aspx")
        Response.Redirect("product-information.aspx")
    End Sub

    Protected Sub btnsearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsearch.Click
        Try
            Dim index As Integer
            Dim pindex As Decimal
            Session("Code") = txtcode.Text
            Session("ProductList") = Nothing
            Dim page As Integer
            Dim dr() As DataRow
            Dim dt As New DataTable

            'dt = ReturnDataTable("Select    Product_Kid, Product_Code, Product_Name, Product_ModelNo, Product_Image  from Product_Master where Product_SupplierID='" & Session("SupplierID").ToString.Trim & "' and Product_IsDeleted='0' and Product_Approved='Y' ")

            'Dim ds As New DataSet
            Dim da As SqlDataAdapter
            da = New SqlDataAdapter("Product_NonApproved_Proc", con)
            da.SelectCommand.CommandType = CommandType.StoredProcedure
            da.SelectCommand.Parameters.Add(New SqlParameter("@SupplierId", SqlDbType.NVarChar))
            da.SelectCommand.Parameters("@SupplierId").Value = RemoveLiterals(Session("SupplierID"))
            da.SelectCommand.Parameters.Add(New SqlParameter("@Mode", SqlDbType.NVarChar))
            da.SelectCommand.Parameters("@Mode").Value = "Filled"
            da.Fill(dt)

            If Session("Code") <> Nothing Then
                dr = dt.Select("Product_Code='" & Session("Code") & "'")
                If (dr.Length = 0) Then
                    tdmsg.InnerHtml = "No Search Results Found!"
                    Session("Code") = Nothing
                    FillGridNonApproved()
                    Exit Sub
                Else
                    tdmsg.InnerHtml = ""
                    index = dt.Rows.IndexOf(dr(0)) + 1
                    pindex = index / 5
                    Dim str As String
                    str = pindex.ToString
                    If str.Contains(".") Then
                        page = Integer.Parse(pindex.ToString.Substring(0, pindex.ToString.IndexOf(".")))
                        gvNonApproved.PageIndex = page
                    Else
                        gvNonApproved.PageIndex = pindex - 1
                    End If
                    pindex = index / 5
                    If index Mod 5 > 0 Then
                        If index > 5 Then
                            pindex = pindex + 1
                        End If
                    End If
                   
                End If

            End If
            FillGridNonApproved()
            Session("Code") = Nothing
            ''FillGrid("Select   Product_Kid, Product_Code, Product_Name, Product_ModelNo, Product_Image from Product_Master where Product_SupplierID='" & Session("SupplierID").ToString.Trim & "'and Product_code='" & txtcode.Text & "' and Product_IsDeleted='0' order by Product_Code")
        Catch ex As Exception

        End Try
    End Sub

    'Protected Sub gvProdDetails_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
    '    Try

    '        If e.Row.RowType = DataControlRowType.DataRow Then
    '            Dim img As Image
    '            Dim imgpath As String

    '            Dim str As String = CType(e.Row.Cells(0).FindControl("lblcode"), Label).Text
    '            If str = "" Or str = "&nbsp;" Or str = Nothing Then
    '                CType(e.Row.Cells(0).FindControl("lblcode"), Label).Text = """Will generate After Approval."""
    '                CType(e.Row.Cells(0).FindControl("lblcode"), Label).Style.Add("font-size", "8pt")
    '            End If

    '            img = CType(e.Row.Cells(0).FindControl("Image1"), Image)
    '            img.ImageUrl = Page.ResolveUrl("~\Upload Image\Product Image\UploadImages\" & e.Row.Cells(1).Text)
    '            If System.IO.File.Exists(Server.MapPath(img.ImageUrl)) Then
    '                imgpath = Server.MapPath(img.ImageUrl)
    '                KeepAspectRatioNew(img, imgpath, 50, 50)
    '            Else
    '                img.ImageUrl = Page.ResolveUrl("~/Images/no-product-image.JPG")
    '            End If

    '            CType(e.Row.Cells(0).FindControl("lnkDelete"), LinkButton).Attributes.Add("onclick", "return confirm('Are you Sure! Want to Delete ? ');")
    '            Dim kid As String = CType(e.Row.Cells(0).FindControl("lnkView"), LinkButton).CommandArgument.ToString
    '            kid = kid.Replace("\", "\\")
    '            CType(e.Row.Cells(0).FindControl("lnkView"), LinkButton).Attributes.Add("onclick", "return OpenForm('" & RemoveLiterals(kid.ToString) & "');")
    '            If Session("Code") <> Nothing Then
    '                If CType(e.Row.Cells(3).FindControl("lblCode"), Label).Text = Session("Code").ToString Then
    '                    e.Row.BackColor = Drawing.Color.WhiteSmoke
    '                End If
    '            End If
    '        End If
    '        If e.Row.RowType = DataControlRowType.Footer Then
    '            e.Row.Cells(3).Text = "Page   " & (gvProdDetails.PageIndex + 1) & " of    " & gvProdDetails.PageCount

    '        End If
    '    Catch ex As Exception

    '    End Try
    'End Sub

    'Protected Sub lnkDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    '    '    Dim kid As String = sender.CommandArgument()
    '    '    Dim ret_val As String
    '    '    ret_val = ReturnValue("Select Product_Approved from Product_Master WHERE Product_Kid='" & kid & "' AND Product_IsDeleted='0'")
    '    '    If (ret_val = "N") Then
    '    '        ExecuteQuery("Update Product_Master SET Product_IsDeleted='1' WHERE Product_Kid='" & kid & "' AND Product_Approved='N'")
    '    '        CreateMessageAlert(Me, "Product Deleted Successfully...", "StrKeyVal")
    '    '        Session("ProductList") = Nothing
    '    '        FillGrid()
    '    '    Else
    '    '        CreateMessageAlert(Me, "You Can Not Delete Approved Product. Contact Atcomaart Administrator.", "StrKeyVal")
    '    '    End If

    'End Sub

    'Protected Sub gvNonApproved_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvNonApproved.PageIndexChanging
    '    gvNonApproved.PageIndex = e.NewPageIndex
    '    FillGridNonApproved()
    '    gvNonApproved.SelectedIndex = -1
    'End Sub

    Protected Sub gvNonApproved_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvNonApproved.RowDataBound
        Try

            If e.Row.RowType = DataControlRowType.DataRow Then
                Dim img As Image
                Dim imgpath As String

                img = CType(e.Row.Cells(0).FindControl("ImageNonApproved"), Image)
                img.ImageUrl = Page.ResolveUrl("~\Upload Image\Product Image\UploadImages\" & e.Row.Cells(1).Text)
                If System.IO.File.Exists(Server.MapPath(img.ImageUrl)) Then
                    imgpath = Server.MapPath(img.ImageUrl)
                    KeepAspectRatioNew(img, imgpath, 50, 50)
                Else
                    img.ImageUrl = Page.ResolveUrl("~/Images/no-product-image.JPG")
                End If

                CType(e.Row.Cells(0).FindControl("lnkDeleteNonApproved"), LinkButton).Attributes.Add("onclick", "return confirm('Are you Sure! Want to Delete ? ');")
                Dim kid As String = CType(e.Row.Cells(0).FindControl("lnkViewFilled"), LinkButton).CommandArgument.ToString
                kid = kid.Replace("\", "\\")
                CType(e.Row.Cells(0).FindControl("lnkViewFilled"), LinkButton).Attributes.Add("onclick", "return OpenForm('" & RemoveLiterals(kid.ToString) & "');")

                If e.Row.Cells(4).Text = "Y" Then
                    CType(e.Row.Cells(0).FindControl("ImgApproved"), Image).Visible = True
                    CType(e.Row.Cells(0).FindControl("ImgApproved"), Image).ImageUrl = Page.ResolveUrl("~/Images/approved.gif")
                Else
                    CType(e.Row.Cells(0).FindControl("ImgApproved"), Image).Visible = False
                End If


                Dim str As String = CType(e.Row.Cells(0).FindControl("lblAppcode"), Label).Text
                If str = "" Or str = "&nbsp;" Or str = Nothing Then
                    CType(e.Row.Cells(0).FindControl("lblAppcode"), Label).Text = """Will generate After Approval."""
                    CType(e.Row.Cells(0).FindControl("lblAppcode"), Label).Style.Add("font-size", "8pt")
                End If


                If Session("Code") <> Nothing Then
                    If CType(e.Row.Cells(0).FindControl("lblAppcode"), Label).Text = Session("Code").ToString Then
                        e.Row.BackColor = Drawing.Color.Yellow
                    End If
                End If



            End If
            If e.Row.RowType = DataControlRowType.Footer Then

                'e.Row.Cells(3).Text = "Page   " & (gvNonApproved.PageIndex + 1) & " of    " & gvNonApproved.PageCount

            End If
        Catch ex As Exception
            Response.Write(ex.Message.ToString)
        End Try
    End Sub

    'Protected Sub gvPartiallyFilled_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvPartiallyFilled.PageIndexChanging
    '    gvPartiallyFilled.PageIndex = e.NewPageIndex
    '    FillGridPartiallyFilled()
    '    gvPartiallyFilled.SelectedIndex = -1
    'End Sub

    Protected Sub gvPartiallyFilled_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvPartiallyFilled.RowDataBound
        Try

            If e.Row.RowType = DataControlRowType.DataRow Then
                Dim img As Image
                Dim imgpath As String

                img = CType(e.Row.Cells(0).FindControl("ImagePartially"), Image)
                img.ImageUrl = Page.ResolveUrl("~\Upload Image\Product Image\UploadImages\" & e.Row.Cells(1).Text)
                If System.IO.File.Exists(Server.MapPath(img.ImageUrl)) Then
                    imgpath = Server.MapPath(img.ImageUrl)
                    KeepAspectRatioNew(img, imgpath, 50, 50)
                Else
                    img.ImageUrl = Page.ResolveUrl("~/Images/no-product-image.JPG")
                End If

                CType(e.Row.Cells(0).FindControl("lnkDeletePartially"), LinkButton).Attributes.Add("onclick", "return confirm('Are you Sure! Want to Delete ? ');")
                Dim kid As String = CType(e.Row.Cells(0).FindControl("lnkViewPartially"), LinkButton).CommandArgument.ToString
                kid = kid.Replace("\", "\\")
                CType(e.Row.Cells(0).FindControl("lnkViewPartially"), LinkButton).Attributes.Add("onclick", "return OpenForm('" & RemoveLiterals(kid.ToString) & "');")


                Dim str As String = CType(e.Row.Cells(0).FindControl("lblAppcode1"), Label).Text
                If str = "" Or str = "&nbsp;" Or str = Nothing Then
                    CType(e.Row.Cells(0).FindControl("lblAppcode1"), Label).Text = """Will generate After Approval."""
                    CType(e.Row.Cells(0).FindControl("lblAppcode1"), Label).Style.Add("font-size", "8pt")
                End If
            End If
            If e.Row.RowType = DataControlRowType.Footer Then
                'e.Row.Cells(3).Text = "Page   " & (gvPartiallyFilled.PageIndex + 1) & " of    " & gvPartiallyFilled.PageCount

            End If
        Catch ex As Exception
            Response.Write(ex.Message.ToString)
        End Try
    End Sub

    Protected Sub lnkDeleteNonApproved_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try

            Dim kid As String = sender.CommandArgument()
            Dim ret_val As String
            ret_val = ReturnValue("Select Product_Approved from Product_Master WHERE Product_Kid='" & RemoveLiterals(kid) & "' AND Product_IsDeleted='0'")
            If (ret_val = "N") Or (ret_val = "C") Then
                ExecuteQuery("Update Product_Master SET Product_IsDeleted='1' WHERE Product_Kid='" & RemoveLiterals(kid) & "'")
                ExecuteQuery("delete from ProductCategory_Master where ProductCategory_ProductID='" & RemoveLiterals(kid) & "'")
                CreateMessageAlert(Me, "Product Deleted Successfully...", "StrKeyVal")
                Session("ProductList") = Nothing
                FillGridNonApproved()
            Else
                CreateMessageAlert(Me, "You Can Not Delete Approved Product. Contact Atcomaart Administrator.", "StrKeyVal")

            End If
        Catch ex As Exception
            Response.Write(ex.Message.ToString)
        End Try

    End Sub

    Protected Sub lnkEditNonApproved_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Response.Redirect("product-information.aspx?ID=" & RemoveLiterals(sender.CommandArgument()) & "&index=" & gvProdDetails.PageIndex)
    End Sub

    Protected Sub lnkEditPartially_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Response.Redirect("product-information.aspx?ID=" & RemoveLiterals(sender.CommandArgument()) & "&index=" & gvProdDetails.PageIndex)
    End Sub

    Protected Sub lnkDeletePartially_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try

            Dim kid As String = sender.CommandArgument()
            Dim ret_val As String
            ret_val = ReturnValue("Select Product_Approved from Product_Master WHERE Product_Kid='" & RemoveLiterals(kid) & "' AND Product_IsDeleted='0'")
            If (ret_val = "N") Or (ret_val = "C") Then
                ExecuteQuery("Update Product_Master SET Product_IsDeleted='1' WHERE Product_Kid='" & RemoveLiterals(kid) & "'")
                ExecuteQuery("delete from ProductCategory_Master where ProductCategory_ProductID='" & RemoveLiterals(kid) & "'")
                CreateMessageAlert(Me, "Product Deleted Successfully...", "StrKeyVal")
                Session("ProductList") = Nothing
                FillGridPartiallyFilled()
            Else
                CreateMessageAlert(Me, "You Can Not Delete Approved Product. Contact Atcomaart Administrator.", "StrKeyVal")

            End If

        Catch ex As Exception
            Response.Write(ex.Message.ToString)
        End Try
    End Sub

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub

End Class
