Imports System
Imports System.Data
Imports System.Data.SqlClient

Partial Class Admin_product_category_update
    Inherits System.Web.UI.Page
    Shared Category(10) As String
    Shared i As Integer
    Dim str, str1 As String

    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
        If Not IsPostBack Then
            Session("Bool") = "True"
            If Request.QueryString("subcatid") = Nothing Then
                Session("Update") = Nothing
            End If
            'Session("Admin") = "Admin"
            i = 0
            'Fill_Combo("SELECT DISTINCT Supplier_Master.Supplier_Kid, Supplier_Master.Supplier_Name FROM  SupplierLogin RIGHT OUTER JOIN  Supplier_Master ON SupplierLogin.AdminUser_Kid = Supplier_Master.Supplier_AdminUserId WHERE SupplierLogin.AdminUser_IsDeleted = '0' and SupplierLogin.UserType_Kid='00000E6' and Supplier_Master.Supplier_Isdeleted='0' and Supplier_Master.Supplier_Kid!='' order by Supplier_Name", ddlSupplierName)
            Fill_Combo("SELECT DISTINCT Supplier_Master.Supplier_Kid, Supplier_Master.Supplier_Name FROM  SupplierLogin RIGHT OUTER JOIN  Supplier_Master ON SupplierLogin.AdminUser_Kid = Supplier_Master.Supplier_AdminUserId WHERE SupplierLogin.AdminUser_IsDeleted = '0' and SupplierLogin.AdminUser_UserTypeId='00000E6' and Supplier_Master.Supplier_Isdeleted='0' and Supplier_Master.Supplier_Kid!='' order by Supplier_Name", ddlSupplierName)
            ddlProductName.Items.Insert(0, New ListItem("Select Product Name - Product Code - Model No. ", "Select"))
            'tdDDL.Visible = False

            If Request.QueryString("subcatid") = Nothing Then
                'Session("Update") = Nothing
                LoadCategory("Root Category")
            Else
                If Request.QueryString("subcatid") = "Root" Then
                    LoadCategory("Root Category")
                Else
                    LoadCategory(RemoveLiterals(Request.QueryString("subcatid").ToString))
                End If

            End If


            cbosubCategory1.Visible = False
            cbosubCategory2.Visible = False
            cboCategory.Focus()
            tdJJCategorySuggest.Visible = False
            btnUpdate.Attributes.Add("onclick", "return CheckProdCat();")

        End If
        lblMSG.Visible = False
    End Sub

    Private Sub LoadCategory(ByVal parentid As String)
        FillCategoryName(parentid, lblCat)
        lblCat.Visible = False
        Dim strsql As String
        strsql = "SELECT Category_Kid as id, Category_Name as Name FROM Category_Master WHERE Category_ParentId = '" & parentid & "'and Category_IsDeleted='0' ORDER BY Category_Name"
        cboCategory.Items.Clear()
        cboCategory.Items.Add(New ListItem("Select Category", "-1"))
        Fill_Combo(strsql, cboCategory)
        If cboCategory.Items.Count > 1 Then
            Label14.Visible = True
            Label15.Visible = False
            Label16.Visible = False

            cboCategory.ForeColor = Drawing.Color.Red
            cbosubCategory1.ForeColor = Drawing.Color.Black
            cbosubCategory2.ForeColor = Drawing.Color.Black
            'T1.Visible = False
            Label1.Visible = True
            Label14.Text = "Select the category"
            hfCategory.Value = ""
        Else
            Label14.Visible = False
            Label15.Visible = False
            Label16.Visible = False
            Label2.Visible = True
            Label2.Text = "Last Category Selected."
            'T1.Visible = True
            Label1.Visible = False
            'txtProductName.Enabled = True
            'ScriptManager1.SetFocus(txtProductName)
            Session("CategoryId") = parentid
            hfCategory.Value = RemoveLiterals(parentid.ToString)

            Dim dtCategory As DataTable
            dtCategory = ReturnDataTable("SELECT CategoryRelation_CategoryID FROM CategoryRelation_Master WHERE (CategoryRelation_Flag IN (SELECT CategoryRelation_Flag FROM CategoryRelation_Master AS CategoryRelation_Master_1 WHERE  (CategoryRelation_CategoryID = N'" & RemoveLiterals(hfCategory.Value.ToString) & "'))) AND (CategoryRelation_CategoryID <> N'" & RemoveLiterals(hfCategory.Value.ToString) & "')")
            If dtCategory.Rows.Count > 0 Then
                tdJJCategorySuggest.Visible = True
                chkCategory.DataSource = dtCategory
                chkCategory.DataTextField = "CategoryRelation_CategoryID"
                chkCategory.DataValueField = "CategoryRelation_CategoryID"
                chkCategory.DataBind()
            Else
                tdJJCategorySuggest.Visible = False
            End If

            If Label2.Visible = True Then
                Label1.Visible = False
            End If
        End If


    End Sub

    Public Sub FillCategoryName(ByVal Catid As String, ByVal lbl As Label)
        If (i = -1) Then
            i = 0
        End If
        If (Catid = "Root Category") Then
            Exit Sub
        End If
        lbl.Text = "<b> Product Category >  </b>"
        Dim dt As DataTable
        dt = ReturnDataTable("Select * From Category_Master Where Category_Kid ='" & Catid & "' and Category_Isdeleted = '0' ")
        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
                lbl.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(), lbl)
        End If
        dt.Clear()
        'GridView1.DataSource = dt
        'GridView1.DataBind()
    End Sub

    Public Sub FillProductCombo(ByVal strQuery As String, ByVal ddl As DropDownList)
        Try
            Dim SqlCon As New SqlConnection(ConfigurationManager.AppSettings("ConnectionString"))  ' Declare connection Object
            Dim SqlAdapter As New SqlDataAdapter      ' Declare Dataadapter Object
            Dim SqlDataSet As New Data.DataSet        ' Declare Dataset Object
            Dim DT As New Data.DataTable              ' Declare Datatable Oblect
            Dim sqlCmd As New SqlCommand(strQuery, SqlCon) ' Declare Command Object
            Dim i As Integer

            SqlCon.Open()                                 ' Open Connection
            SqlAdapter.SelectCommand = sqlCmd             ' Set command to Adapter
            SqlAdapter.Fill(SqlDataSet, "TableName")      ' Links Adapter with DataSet
            DT = SqlDataSet.Tables("TableName")           ' Get datatable from dataset
            sqlCmd.ExecuteNonQuery()                      ' Executes Command

            ddl.Items.Insert(0, New ListItem("Select Product Name -[Product Code]- Model No. ", "Select"))     ' Insert Blank Row at index 0  

            For i = 0 To DT.Rows.Count - 1
                ddl.Items.Insert(i + 1, New ListItem(DT.Rows(i).Item(1), DT.Rows(i).Item(0)))  '' Add Items(code,Exact Value) into DropDownList
            Next i
            ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue(""))     '' Assigning 0 th Index to DropDownList

            SqlCon.Close()                                '' Close Connection Object
            SqlCon.Dispose()                              '' Dispose Connection Oblect
            sqlCmd.Dispose()                              '' Dispose command object
            SqlAdapter.Dispose()                          '' Dispose adapter Object
            SqlDataSet.Dispose()                          '' Dispose dataset Object
            DT.Dispose()                                  '' Dispose datatable Object
        Catch ex As Exception
            CreateMessageAlert(ddl.Page, ex.Message, "StrKeyVal")     'Display the Error Message
            ddl = Nothing
        End Try
    End Sub

    Private Sub cboCategory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCategory.SelectedIndexChanged
        If cboCategory.SelectedItem.Value = "0" Then
            Label2.Visible = True
            Label2.Text = "Please Select the Category"
            cbosubCategory1.Visible = False
            cbosubCategory2.Visible = False
            Label15.Visible = False

        Else
            Session("lastsubcategory") = ""
            Session("lastsubcategory") = cboCategory.SelectedItem.Value
            getparents(cboCategory.SelectedItem.Value)
            LoadSubCategory1(cboCategory.SelectedItem.Value)

        End If

    End Sub
    Private Sub LoadSubCategory1(ByVal intId As String)
        FillCategoryName(intId, lblCat)
        lblCat.Visible = False
        Dim strsql As String
        strsql = "SELECT Category_Kid as id, Category_Name as Name FROM Category_Master WHERE Category_ParentId = '" & intId & "' and Category_IsDeleted='0' ORDER BY Category_Name"

        cbosubCategory1.Items.Clear()
        cbosubCategory1.Items.Add(New ListItem("Select Subcategory", "-1"))
        Fill_Combo(strsql, cbosubCategory1)
        If cbosubCategory1.Items.Count > 1 Then
            Label14.Visible = False
            Label15.Visible = True
            Label16.Visible = False
            cboCategory.ForeColor = Drawing.Color.Black
            cbosubCategory1.ForeColor = Drawing.Color.Red
            cbosubCategory2.ForeColor = Drawing.Color.Black
            cbosubCategory1.Visible = True
            cbosubCategory2.Visible = False
            Label15.Text = "Select the next level"
            'T1.Visible = False
            Label1.Visible = True
            tdJJCategorySuggest.Visible = False
            hfCategory.Value = ""
        Else
            cbosubCategory1.Visible = False
            cbosubCategory2.Visible = False
            Label14.Visible = False
            Label15.Visible = False
            Label16.Visible = False
            Label2.Visible = True
            Label2.Text = "Last Category Selected."
            'T1.Visible = True
            Label1.Visible = False
            'txtProductName.Enabled = True
            'ScriptManager1.SetFocus(txtProductName)
            Session("CategoryId") = intId
            hfCategory.Value = RemoveLiterals(intId.ToString)

            Dim dtCategory As DataTable
            dtCategory = ReturnDataTable("SELECT CategoryRelation_CategoryID FROM CategoryRelation_Master WHERE (CategoryRelation_Flag IN (SELECT CategoryRelation_Flag FROM CategoryRelation_Master AS CategoryRelation_Master_1 WHERE  (CategoryRelation_CategoryID = N'" & RemoveLiterals(hfCategory.Value.ToString) & "'))) AND (CategoryRelation_CategoryID <> N'" & RemoveLiterals(hfCategory.Value.ToString) & "')")
            If dtCategory.Rows.Count > 0 Then
                tdJJCategorySuggest.Visible = True
                chkCategory.DataSource = dtCategory
                chkCategory.DataTextField = "CategoryRelation_CategoryID"
                chkCategory.DataValueField = "CategoryRelation_CategoryID"
                chkCategory.DataBind()
            Else
                tdJJCategorySuggest.Visible = False
            End If


            If Label2.Visible = True Then
                Label1.Visible = False
            End If
        End If

    End Sub

    Private Function getparents(ByVal i As String) As String
        Dim strsql As String
        strsql = "SELECT Category_ParentId, Category_Name FROM Category_Master WHERE Category_Kid = '" & i & "'"
        If con.State = ConnectionState.Closed Then
            con.Open()
        End If

        Dim da As New SqlDataAdapter(strsql, con)
        Dim ds As New DataSet
        da.Fill(ds)
        Dim j As String

        Dim flag As Boolean = False
        If ds.Tables(0).Rows.Count > 0 Then
            j = ds.Tables(0).Rows(0).Item(0).ToString
            flag = True
        Else
            Return 0
            Exit Function
        End If

        If flag = True Then
            str1 = ds.Tables(0).Rows(0).Item(1).ToString & " > " & str1
            str = "<a href=./product-category-update.aspx?subcatid=" & ds.Tables(0).Rows(0).Item(0).ToString & ">" & ds.Tables(0).Rows(0).Item(1).ToString & "</a>" & " > " & str
            getparents(j)
        End If
        'dr.Close()
        con.Close()
        Label13.Text = str
        Session("categorylevel") = Nothing
        Session("categorylevel") = str1
        Session("Category") = str1
    End Function
    Private Sub cbosubCategory1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbosubCategory1.SelectedIndexChanged
        Session("lastsubcategory") = cbosubCategory1.SelectedItem.Value
        getparents(cbosubCategory1.SelectedItem.Value)
        LoadSubCategory2(cbosubCategory1.SelectedItem.Value)
        cbosubCategory1.Visible = True
    End Sub

    Private Sub LoadSubCategory2(ByVal intId As String)
        FillCategoryName(intId, lblCat)
        lblCat.Visible = False
        Dim strsql As String
        strsql = "SELECT Category_Kid as id, Category_Name as Name FROM Category_Master WHERE Category_ParentId = '" & intId & "' and Category_IsDeleted='0' ORDER BY Category_Name"
        cbosubCategory2.Items.Clear()
        cbosubCategory2.Items.Add(New ListItem("Select Subcategory", "-1"))
        Fill_Combo(strsql, cbosubCategory2)
        If cbosubCategory2.Items.Count > 1 Then
            tdJJCategorySuggest.Visible = False
            Label14.Visible = False
            Label15.Visible = False
            Label16.Visible = True
            cboCategory.ForeColor = Drawing.Color.Black
            cbosubCategory1.ForeColor = Drawing.Color.Black
            cbosubCategory2.ForeColor = Drawing.Color.Red
            Label16.Text = "Select the next level"
            cbosubCategory2.Visible = True
            'T1.Visible = False
            Label1.Visible = True
            hfCategory.Value = ""
        Else
            cbosubCategory2.Visible = False
            Label14.Visible = False
            Label15.Visible = False
            Label16.Visible = False
            Label2.Visible = True
            Label2.Text = "Last Category Selected."
            'T1.Visible = True
            Label1.Visible = False
            'txtProductName.Enabled = True
            'ScriptManager1.SetFocus(txtProductName)
            Session("CategoryId") = intId

            hfCategory.Value = RemoveLiterals(intId.ToString)

            Dim dtCategory As DataTable
            dtCategory = ReturnDataTable("SELECT CategoryRelation_CategoryID FROM CategoryRelation_Master WHERE (CategoryRelation_Flag IN (SELECT CategoryRelation_Flag FROM CategoryRelation_Master AS CategoryRelation_Master_1 WHERE  (CategoryRelation_CategoryID = N'" & RemoveLiterals(hfCategory.Value.ToString) & "'))) AND (CategoryRelation_CategoryID <> N'" & RemoveLiterals(hfCategory.Value.ToString) & "')")
            If dtCategory.Rows.Count > 0 Then
                tdJJCategorySuggest.Visible = True
                chkCategory.DataSource = dtCategory
                chkCategory.DataTextField = "CategoryRelation_CategoryID"
                chkCategory.DataValueField = "CategoryRelation_CategoryID"
                chkCategory.DataBind()
            Else
                tdJJCategorySuggest.Visible = False
            End If


            If Label2.Visible = True Then
                Label1.Visible = False
            End If
        End If



    End Sub
    Private Sub cbosubCategory2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbosubCategory2.SelectedIndexChanged

        Session("lastsubcategory") = cbosubCategory2.SelectedItem.Value
        getparents(cbosubCategory2.SelectedItem.Value)
        LoadSubCategory3(cbosubCategory2.SelectedItem.Value)
    End Sub
    Private Sub LoadSubCategory3(ByVal intId As String)
        FillCategoryName(intId, lblCat)
        lblCat.Visible = False
        Dim dt As DataTable = ReturnDataTable("SELECT Category_Kid as id, Category_Name as Name FROM Category_Master WHERE Category_ParentId = '" & intId & "' and Category_IsDeleted='0' ORDER BY Category_Name")

        If dt.Rows.Count > 0 Then

            Dim strsql As String
            strsql = "SELECT Category_Kid as id, Category_Name as Name FROM Category_Master WHERE Category_ParentId = '" & intId & "' and Category_IsDeleted='0' ORDER BY Category_Name"
            cboCategory.Items.Clear()
            cboCategory.Items.Add(New ListItem("Select Subcategory", "-1"))
            Fill_Combo(strsql, cboCategory)

            tdJJCategorySuggest.Visible = False
            Label14.Visible = True
            Label15.Visible = False
            Label16.Visible = False
            cbosubCategory1.Visible = False
            cbosubCategory2.Visible = False
            cboCategory.ForeColor = Drawing.Color.Red
            cbosubCategory1.ForeColor = Drawing.Color.Black
            cbosubCategory2.ForeColor = Drawing.Color.Black
            Label14.Text = "Select the next level"
            'T1.Visible = False
            Label1.Visible = True
            hfCategory.Value = ""
        Else
            Label14.Visible = False
            Label15.Visible = False
            Label16.Visible = False
            Label2.Visible = True
            Label2.Text = "Last Category Selected."

            'T1.Visible = True
            Label1.Visible = False
            'txtProductName.Enabled = True
            'ScriptManager1.SetFocus(txtProductName)
            Session("CategoryId") = intId
            hfCategory.Value = RemoveLiterals(intId.ToString)
            Dim dtCategory As DataTable
            dtCategory = ReturnDataTable("SELECT CategoryRelation_CategoryID FROM CategoryRelation_Master WHERE (CategoryRelation_Flag IN (SELECT CategoryRelation_Flag FROM CategoryRelation_Master AS CategoryRelation_Master_1 WHERE  (CategoryRelation_CategoryID = N'" & RemoveLiterals(hfCategory.Value.ToString) & "'))) AND (CategoryRelation_CategoryID <> N'" & RemoveLiterals(hfCategory.Value.ToString) & "')")
            If dtCategory.Rows.Count > 0 Then
                tdJJCategorySuggest.Visible = True
                chkCategory.DataSource = dtCategory
                chkCategory.DataTextField = "CategoryRelation_CategoryID"
                chkCategory.DataValueField = "CategoryRelation_CategoryID"
                chkCategory.DataBind()
            Else
                tdJJCategorySuggest.Visible = False
            End If



            If Label2.Visible = True Then
                Label1.Visible = False
            End If
        End If

    End Sub

    Protected Sub chkCategory_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkCategory.DataBound

        Dim chk As CheckBoxList = sender
        'Dim strCategoryID As String
        Dim i As Integer
        For i = 0 To chk.Items.Count - 1
            'strCategoryID = chk.Items(i).Value
            chk.Items(i).Text = fillcategory(chk.Items(i).Value.ToString)


        Next


    End Sub

    Public Function fillcategory(ByVal strCatID As String) As String

        Dim str As String
        Dim strValue As String = " "
        Dim strV(10) As String
        Dim count As Integer = 0
        str = strCatID
        While str <> "Root Category"
            strV(count) = ReturnValue("Select Category_Name from Category_Master where Category_KID='" & RemoveLiterals(str.ToString) & "' and Category_Isdeleted = '0'") 'CType(Session("dtCategory"), DataTable).Select("Category_KID='" & str & "'")(0).Item("Category_Name").ToString
            count = count + 1
            'strValue += "<b>" & str & "<b>  >  "
            str = ReturnValue("Select Category_ParentID from Category_Master where Category_KID='" & RemoveLiterals(str.ToString) & "' and Category_Isdeleted = '0'") 'CType(Session("dtCategory"), DataTable).Select("Category_KID='" & str & "'")(0).Item("Category_ParentID")
        End While

        Dim i As Integer
        Array.Reverse(strV)
        For i = 0 To strV.Length - 1
            If IsNothing(strV(i)) Then
            Else
                strValue += " " & strV(i).ToString & " >  "
            End If

        Next
        Return strValue


    End Function


    Protected Sub ddlProductName_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlProductName.SelectedIndexChanged
        i = 0
        If ddlProductName.SelectedIndex > 0 Then
            Session("Update") = ddlProductName.SelectedItem.Value
            'tdDDL.Visible = True
            tdCat.InnerText = ""
            tdCat.Style.Add("color", "black")
            'FillCategoryName1(ReturnValue("Select Product_CategoryId from Product_Master where Product_KId ='" & ddlProductName.SelectedItem.Value & "'"))
            Dim strCatID As String
            strCatID = ReturnValue("Select Product_CategoryId from Product_Master where Product_KId ='" & ddlProductName.SelectedItem.Value & "'")
            tdCat.InnerHtml = "<b>Product Category:</b> <br/>"
            'FillCategoryName(RemoveLiterals(dt.Rows(0).Item("Product_CategoryId")).ToString.Trim, lblCat)
            tdCat.InnerHtml += fillcategory(RemoveLiterals(strCatID).ToString.Trim)

            Dim dtCat As New DataTable
            dtCat = ReturnDataTable("Select ProductCategory_CategoryID from ProductCategory_Master where ProductCategory_ProductID='" & RemoveLiterals(ddlProductName.SelectedItem.Value.ToString) & "' and ProductCategory_CategoryID <>'" & RemoveLiterals(strCatID.ToString).ToString.Trim & "' ")
            If dtCat.Rows.Count > 0 Then
                Dim dtCatCount As Integer
                For dtCatCount = 0 To dtCat.Rows.Count - 1
                    tdCat.InnerHtml += "<br/>" & fillcategory(RemoveLiterals(dtCat.Rows(dtCatCount).Item("ProductCategory_CategoryId")).ToString.Trim)
                Next
            End If


            'lblCat.Visible = True
        Else
            Session("Update") = Nothing
            'tdDDL.Visible = False
            showmessage("Select Product Name.!", lblMSG)
        End If

    End Sub

    Public Sub FillCategoryName1(ByVal Catid As String)
        Try


            ' used to fill category hirarchy in label
            Dim dt As DataTable
            dt = ReturnDataTable("Select * From Category_Master Where Category_Kid ='" & Catid & "' and Category_Isdeleted = '0'")
            Dim ParentId As String
            ParentId = dt.Rows(0).Item(3).ToString()
            If ParentId = "Root Category" Then

                Dim j As Integer
                Category(i) = dt.Rows(0).Item(2).ToString() & "  >  "
                'Array.Reverse(Category)
                For j = 0 To i
                    tdCat.Style.Add("color", "blue")
                    tdCat.InnerText += 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() & "  >  "
                FillCategoryName1(dt.Rows(0).Item(3).ToString())
            End If
            dt.Clear()
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub ddlSupplierName_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlSupplierName.SelectedIndexChanged
        'tdDDL.Visible = False
        tdCat.InnerText = ""
        Session("Update") = Nothing
        If ddlSupplierName.SelectedIndex > 0 Then
            ddlProductName.Items.Clear()
            FillProductCombo("SELECT Product_Kid, Product_Name + ' -[' + isnull(Product_Code,'') + ']- ' + isnull(Product_ModelNo,'') AS Name FROM Product_Master where Product_SupplierId ='" + ddlSupplierName.SelectedItem.Value + "' and Product_Isdeleted ='0' and Product_Kid !='' order by Product_Code", ddlProductName)
        Else
            showmessage("Record Not Found.!", lblMSG)
            ddlProductName.Items.Insert(0, New ListItem("Select Product Name - Product Code - Model No. ", "Select"))
        End If
    End Sub

    Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        InsertProductCategoryMaster()


    End Sub

    Public Sub InsertProductCategoryMaster()
        Try

        
            ExecuteQuery("Delete from ProductCategory_Master where ProductCategory_ProductID='" & RemoveLiterals(ddlProductName.SelectedValue.ToString) & "'")
            ExecuteQuery("update Product_Master set Product_CategoryId = '" & RemoveLiterals(hfCategory.Value.ToString) & "' where Product_Kid = '" & RemoveLiterals(ddlProductName.SelectedValue.ToString) & "'")
            'insert into Product_Master (Product_CategoryID) values('" & RemoveLiterals(hfCategory.Value.ToString) & "') where (Product_Kid ='" & RemoveLiterals(ddlProductName.SelectedValue.ToString) & "')")
            ExecuteQuery("insert into ProductCategory_Master values('" & NewPrimaryKey(Me) & "','" & RemoveLiterals(ddlProductName.SelectedValue.ToString) & "','" & RemoveLiterals(hfCategory.Value.ToString) & "') ")
            Dim i As Integer
            For i = 0 To chkCategory.Items.Count - 1
                If chkCategory.Items(i).Selected = True Then
                    ExecuteQuery("insert into ProductCategory_Master values('" & NewPrimaryKey(Me) & "','" & RemoveLiterals(ddlProductName.SelectedValue.ToString) & "','" & RemoveLiterals(chkCategory.Items(i).Value.ToString) & "') ")
                End If
            Next
            'chkCategory.Visible = False
            CreateMessageAlert(Me, "Category Updated Successfully.!", "strkeyval")
            ddlProductName.ClearSelection()
            tdCat.InnerHtml = ""

        Catch ex As Exception

        End Try
    End Sub
End Class
