Imports System.Data.SqlClient
Imports System.Data
Imports System.IO
Imports System.String
Imports System.Drawing.Imaging
Imports System.Drawing
Imports System.Drawing.Drawing2D
Partial Class productinformation
    Inherits System.Web.UI.Page

    Dim str, str1 As String
    Dim slc1 = "Select Date"
    Dim slc3 = "Select Year"
    Dim slc4 = "Select Country"
    Dim strcon As String = ConfigurationSettings.AppSettings.Item("ConnectionString")
    Dim con As New SqlConnection(strcon)
    Dim cmd As New SqlCommand()
    Dim dr As SqlDataReader
    Shared Category(10) As String
    Shared i As Integer
    Shared Category_Kid As String
    Shared Category_Code As String
    Shared img As Integer



    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
        'Put user code to initialize the page here
        Try
            If Session("SupplierID") Is Nothing And Session("AdminID") = Nothing Then
                If Session("SupplierID") Is Nothing Then
                    Response.Redirect("listproduct.aspx?sess=expire")
                    Exit Sub
                ElseIf Session("AdminID") = Nothing Then
                    Response.Redirect("~/admin/AdminLogin.aspx?sesn=expire")
                    Exit Sub
                End If
            End If
            
            If Page.IsPostBack = False Then
                tdproductcode1.Visible = False
                tdproductcode2.Visible = False
                tdatcoprice.Visible = False

                If Request.QueryString("ID") <> Nothing Or Session("ProductID") <> Nothing Then
                    tbl1.Visible = False


                    DivProduct.Style.Add("top", "20px")
                    DivProduct.Style.Add("left", "0px")
                    ' Exit Sub
                ElseIf Session("NewProduct") = "NewProduct" Then

                ElseIf Request.QueryString("subcatid") <> Nothing Then

                ElseIf Session("ProductID") = Nothing Then
                    Response.Redirect("list_product.aspx")
                Else
                    tbl1.Visible = False
                    DivProduct.Style.Add("top", "20px")
                    DivProduct.Style.Add("left", "0px")
                End If
              


                txtMarketPrice.Attributes.Add("onkeypress", "return decimalonly(event,this)")
                txtAtcoPrice.Attributes.Add("onkeypress", "return decimalonly(event,this)")
                txtShippingQty.Attributes.Add("onkeypress", "return decimalonly(event,this)")
                txtShippingCharges.Attributes.Add("onkeypress", "return decimalonly(event,this)")
                txtWeight.Attributes.Add("onkeypress", "return decimalonly(event,this)")
                txtLDimension.Attributes.Add("onkeypress", "return decimalonly(event,this)")
                txtHDimension.Attributes.Add("onkeypress", "return decimalonly(event,this)")
                txtWDimention.Attributes.Add("onkeypress", "return decimalonly(event,this)")
                txtDispatchIn.Attributes.Add("onkeypress", "return decimalonly(event,this)")
                txtSellQty.Attributes.Add("onkeypress", "return decimalonly(event,this)")

                Dim parentid As String
                'If Not Me.Page.IsPostBack Then
                g_FinYear = Session("g_FinYear").ToString()
                g_Company = Session("g_Company").ToString()
                'g_User = Session("g_User").ToString()
                parentid = Request.QueryString("subcatid")
                If parentid = Nothing Or parentid = "Root" Then
                    parentid = "Root Category"
                Else
                    parentid = Request.QueryString("subcatid")
                End If
                i = 0
                LoadCategory(parentid)
                cbosubCategory1.Visible = False
                cbosubCategory2.Visible = False
                cboCategory.Focus()



                img = 0
                fillcombos()
                i = 0
                If Request.QueryString("ID") <> Nothing Then
                    Session("Bool") = "Bool"
                    Session("ProductID") = RemoveLiterals(Request.QueryString("ID").ToString)
                    T1.Visible = True
                    GetExisting()
                ElseIf Session("NewProduct") = "NewProduct" Then
                    txtProductName.Enabled = False
                    Session("NewProduct") = Nothing
                    'Session("Product_code") = Nothing
                    'Session("Product_code") = GenerateProductCode(RemoveLiterals(Session("SupplierID").ToString.Trim))
                    'lblProductCode.Text = Session("Product_code")


                    lblCatError.Visible = False
                ElseIf Request.QueryString("subcatid") <> Nothing Then
                    'Exit Sub
                    txtProductName.Enabled = False
                    GoTo EndSub
                ElseIf Session("ProductID") = Nothing Then
                    Response.Redirect("list_product.aspx")
                Else
                    T1.Visible = True
                    Session("Bool") = "Bool"
                    GetExisting()
                End If


                If Session("CategoryId") <> Nothing Then

                Else

                End If
            End If
EndSub:

            If Session("NewProduct") = "NewProduct" Or Request.QueryString("subcatid") <> Nothing Then
                lblProductCode.Text = Session("Product_code")
            End If
            rwShippingCharges.Visible = False
            'AddBrandName.Visible = False
            lblError.Visible = False
            lblCatError.Visible = False
            lblError.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;First Save Your Product Name."

            cboCategory.Visible = True
            If lblMarketPrice.Text = "" OrElse lblMarketPrice.Text.Contains(" 0.00") Then
                lnktax.Visible = False
                lnktax.CausesValidation = True
            Else
                lnktax.Visible = True
                lnktax.Attributes.Add("onclick", "return OpenTAX();")

            End If
        Catch ex As Exception

        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 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 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)

        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)


            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
        Else
            Label14.Visible = False
            Label15.Visible = False
            Label16.Visible = False
            Label2.Visible = True
            Label2.Text = "Add the product"
            T1.Visible = True
            txtProductName.Enabled = True
            ScriptManager1.SetFocus(txtProductName)
            Session("CategoryId") = intId
            If Label2.Visible = True Then
                Label1.Visible = False
            End If
        End If

    End Sub
    Private Sub LoadCategory(ByVal parentid As String)
      
        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
            Label14.Text = "Select the category"
        Else
            Label14.Visible = False
            Label15.Visible = False
            Label16.Visible = False
            Label2.Visible = True
            Label2.Text = "Add the product"
            T1.Visible = True
            txtProductName.Enabled = True
            ScriptManager1.SetFocus(txtProductName)
            Session("CategoryId") = parentid
            If Label2.Visible = True Then
                Label1.Visible = False
            End If
        End If


    End Sub
    Private Sub LoadSubCategory1(ByVal intId As String)
      
        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
        Else
            cbosubCategory1.Visible = False
            cbosubCategory2.Visible = False
            Label14.Visible = False
            Label15.Visible = False
            Label16.Visible = False
            Label2.Visible = True
            Label2.Text = "Add the product"
            T1.Visible = True
            txtProductName.Enabled = True
            ScriptManager1.SetFocus(txtProductName)
            Session("CategoryId") = intId
            If Label2.Visible = True Then
                Label1.Visible = False
            End If
        End If

    End Sub
    Private Sub LoadSubCategory2(ByVal intId As String)
      
        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

            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
        Else
            cbosubCategory2.Visible = False
            Label14.Visible = False
            Label15.Visible = False
            Label16.Visible = False
            Label2.Visible = True
            Label2.Text = "Add the product"
            T1.Visible = True
            txtProductName.Enabled = True
            ScriptManager1.SetFocus(txtProductName)
            Session("CategoryId") = intId
            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-information.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
    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_CompanyId ='" & g_Company & "'")
        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() & "  >  "

            For j = 0 To i

                i = i - 1
            Next
            Exit Sub
        Else
            Category(i) = dt.Rows(0).Item(2).ToString() & "  >  "
            i = i + 1

            FillCategoryName(dt.Rows(0).Item(3).ToString())
        End If

    End Sub
    Public Sub GetExisting()
        Try
            If Session("ProductID").ToString() <> Nothing Then

                Dim dt As DataTable
                dt = ReturnDataTable("Select * From Product_Master Where Product_SupplierID = '" & Session("SupplierID").ToString & "'and Product_Kid = '" & Session("ProductID").ToString() & "'and Product_IsDeleted = '0'")
                If dt.Rows(0).Item("Product_UserId").ToString <> Session("g_User") Then
                    ' ExecuteQuery("update Product_Master set Product_UserId='" & RemoveLiterals(Session("g_User").ToString) & "' where Product_SupplierID = '" & Session("SupplierID").ToString & "' and Product_Kid = '" & Session("ProductID").ToString() & "'and Product_IsDeleted = '0' ")
                End If
                If dt.Rows.Count > 0 Then
                    lblCat.Text = ""
                    FillCategoryNameProduct(RemoveLiterals(dt.Rows(0).Item("Product_CategoryId").ToString.Trim))
                    'lblCatError.Visible = True
                    If IsDBNull(dt.Rows(0).Item("Product_Code")) Or dt.Rows(0).Item("Product_Code").ToString = "" Or dt.Rows(0).Item("Product_Code").ToString = "&nbsp;" Then
                        lblProductCode.Text = """Will be Generate After Approval."""
                        lblProductCode.Style.Add("font-size", "8pt")
                    Else
                        lblProductCode.Text = dt.Rows(0).Item("Product_Code").ToString()
                    End If
                    '   Product_code = lblProductCode.Text.ToString

                    If IsDBNull(dt.Rows(0).Item("Product_Name")) Or dt.Rows(0).Item("Product_Name").ToString = "" Then
                    Else
                        tdproductcode1.Visible = True
                        tdproductcode2.Visible = True
                        lblProductName.Visible = True
                        txtProductName.Visible = False
                        lblProductName.Text = dt.Rows(0).Item("Product_Name").ToString()
                        txtProductName.Text = dt.Rows(0).Item("Product_Name").ToString()
                        lnkProductName.Visible = False
                        If Session("AdminID") <> Nothing Then
                            lnkProductName.Visible = True
                            lnkProductName.Text = "Edit"
                            lnkProductName.CausesValidation = False
                        End If
                        'End If
                    End If

                    If IsDBNull(dt.Rows(0).Item("Product_Image")) Or dt.Rows(0).Item("Product_Image").ToString = "" Then
                    Else

                        fuProductImage.Visible = False
                        lblProductImage.Text = dt.Rows(0).Item("Product_Image").ToString()
                        lnkProductImage.Visible = False
                        imgProduct.ImageUrl = "~\Upload Image\Product Image\UploadImages\" & dt.Rows(0).Item("Product_Image").ToString()
                        Dim imgpath As String
                        imgpath = Server.MapPath(imgProduct.ImageUrl)
                        KeepAspectRatioNew(imgProduct, imgpath, 180, 150)
                        lblfileup.Visible = False
                        Label3.Visible = False
                        lblProductImage.Visible = False

                        If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                            lnkProductImage.Visible = True
                            lnkProductImage.Text = "Edit"
                            lblfileup.Visible = False
                            Label3.Visible = False
                            lblProductImage.Visible = False
                        End If
                        ' End If
                    End If

                    If IsDBNull(dt.Rows(0).Item("Product_MarketPriceType")) Or dt.Rows(0).Item("Product_MarketPriceType").ToString = "" Then
                        ddlMarketPriceUnit.Enabled = True
                    Else
                        Try

                            ddlMarketPriceUnit.ClearSelection()
                            txtMarketPrice.Visible = False
                            lblMarketPrice.Text = ReturnValue("Select Unit_Name from Unit_Master where Unit_Kid ='" & dt.Rows(0).Item("Product_MarketPriceType").ToString() & "'and Unit_IsDeleted ='0'")
                            lnkMarketPrice.Visible = False
                            ddlMarketPriceUnit.Visible = False
                            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                                lnkMarketPrice.Visible = True
                                lnkMarketPrice.Text = "Edit"
                                lnkMarketPrice.CausesValidation = False
                                'lnktax.CausesValidation = False
                            End If

                            'End If
                        Catch ex As Exception
                            ddlMarketPriceUnit.ClearSelection()
                        End Try

                    End If

                    If IsDBNull(dt.Rows(0).Item("Product_MarketPrice")) Or dt.Rows(0).Item("Product_MarketPrice").ToString = "" Then
                    Else
                        txtMarketPrice.Visible = False
                        lblMarketPrice.Text += "  " & dt.Rows(0).Item("Product_MarketPrice").ToString()
                        txtMarketPrice.Text = dt.Rows(0).Item("Product_MarketPrice").ToString()
                        lnkMarketPrice.Visible = False
                        ddlMarketPriceUnit.Visible = False
                        If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                            lnkMarketPrice.Visible = True
                            lnkMarketPrice.Text = "Edit"
                            lnkMarketPrice.CausesValidation = False
                            'lnktax.CausesValidation = False
                        End If
                        ' End If
                    End If

                    If IsDBNull(dt.Rows(0).Item("Product_AtcoPriceType")) Or dt.Rows(0).Item("Product_AtcoPriceType").ToString = "" Then
                    Else
                        Try

                            ddlAtcoPriceUnit.ClearSelection()
                            txtAtcoPrice.Visible = False
                            lblAtcoPrice.Text = ReturnValue("Select Unit_Name from Unit_Master where Unit_Kid ='" & dt.Rows(0).Item("Product_AtcoPriceType").ToString() & "'and Unit_IsDeleted ='0'")
                            lnkAtcoPrice.Visible = False
                            ddlAtcoPriceUnit.Visible = False
                            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                                lnkAtcoPrice.Visible = True
                                lnkAtcoPrice.Text = "Edit"
                                lnkAtcoPrice.CausesValidation = False
                            End If
                            'End If
                        Catch ex As Exception
                            ddlAtcoPriceUnit.ClearSelection()
                        End Try
                    End If


                    If IsDBNull(dt.Rows(0).Item("Product_AtcoPrice")) Or dt.Rows(0).Item("Product_AtcoPrice").ToString = "" Then
                    Else

                        txtAtcoPrice.Visible = False
                        lblAtcoPrice.Text += "  " & dt.Rows(0).Item("Product_AtcoPrice").ToString()
                        txtAtcoPrice.Text = dt.Rows(0).Item("Product_AtcoPrice").ToString()
                        lnkAtcoPrice.Visible = False
                        ddlAtcoPriceUnit.Visible = False
                        If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                            lnkAtcoPrice.Visible = True
                            lnkAtcoPrice.Text = "Edit"
                            lnkAtcoPrice.CausesValidation = False
                        End If
                        'End If
                    End If

                    If IsDBNull(dt.Rows(0).Item("Product_BrandId")) Or dt.Rows(0).Item("Product_BrandId").ToString = "" Then
                    Else
                        Try

                            ddlBrandName.ClearSelection()
                            lblBrandName.Text = ReturnValue("Select Brand_Name from Brand_Master where Brand_Kid ='" & dt.Rows(0).Item("Product_BrandId").ToString() & "'and Brand_IsDeleted ='0'")
                            lnkBrandName.Visible = False
                            ddlBrandName.Visible = False
                            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                                lnkBrandName.Visible = True
                                lnkBrandName.Text = "Edit"
                                lnkBrandName.CausesValidation = False
                            End If

                        Catch ex As Exception
                            ddlBrandName.ClearSelection()
                        End Try
                    End If

                    If IsDBNull(dt.Rows(0).Item("Product_ModelNo")) Or dt.Rows(0).Item("Product_ModelNo").ToString = "" Then

                    Else

                        txtModelNo.Visible = False
                        lblModelNo.Text = dt.Rows(0).Item("Product_ModelNo").ToString()
                        txtModelNo.Text = dt.Rows(0).Item("Product_ModelNo").ToString()
                        lnkModelNo.Visible = False
                        If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                            lnkModelNo.Visible = False
                            lnkModelNo.Text = "Edit"
                            lnkProductName.CausesValidation = False
                        End If

                    End If


                    If IsDBNull(dt.Rows(0).Item("Product_MinOrderQty")) Or dt.Rows(0).Item("Product_MinOrderQty").ToString = "" Then
                    Else

                        txtSellQty.Visible = False
                        lblSellQty.Text = dt.Rows(0).Item("Product_MinOrderQty").ToString()
                        txtSellQty.Text = dt.Rows(0).Item("Product_MinOrderQty").ToString()
                        lnkSellQty.Visible = False
                        ddlSellQtyUnit.Visible = False
                        If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                            lnkSellQty.Visible = True
                            lnkSellQty.Text = "Edit"
                            lnkSellQty.CausesValidation = False
                        End If
                        'End If
                    End If
                    If IsDBNull(dt.Rows(0).Item("Product_MinOrderQtyType")) Or dt.Rows(0).Item("Product_MinOrderQtyType").ToString = "" Then
                    Else
                        Try

                            ddlSellQtyUnit.ClearSelection()
                            txtSellQty.Visible = False
                            lblSellQty.Text += "  " & ReturnValue("Select Unit_Name from Unit_Master where Unit_Kid ='" & dt.Rows(0).Item("Product_MinOrderQtyType").ToString() & "'and Unit_IsDeleted ='0'")
                            lnkSellQty.Visible = False
                            ddlSellQtyUnit.Visible = False
                            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                                lnkSellQty.Visible = True
                                lnkSellQty.Text = "Edit"
                                lnkSellQty.CausesValidation = False
                            End If
                            'End If
                        Catch ex As Exception
                            ddlSellQtyUnit.ClearSelection()
                        End Try
                    End If

                    If IsDBNull(dt.Rows(0).Item("Product_ShippingQty")) Or dt.Rows(0).Item("Product_ShippingQty").ToString = "" Then
                    Else

                        txtShippingQty.Visible = False
                        lblShippingQty.Text = dt.Rows(0).Item("Product_ShippingQty").ToString()
                        txtShippingQty.Text = dt.Rows(0).Item("Product_ShippingQty").ToString()
                        lnkShippingQty.Visible = False
                        ddlShippingQtyUnit.Visible = False
                        If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                            lnkShippingQty.Visible = True
                            lnkShippingQty.Text = "Edit"
                        End If
                        'End If
                    End If
                    If IsDBNull(dt.Rows(0).Item("Product_ShippingQtyType")) Or dt.Rows(0).Item("Product_ShippingQtyType").ToString = "" Then
                    Else
                        Try

                            ddlShippingQtyUnit.ClearSelection()
                            txtShippingQty.Visible = False
                            lblShippingQty.Text += "  " & ReturnValue("Select Unit_Name from Unit_Master where Unit_Kid ='" & dt.Rows(0).Item("Product_ShippingQtyType").ToString() & "'and Unit_IsDeleted ='0'")
                            lnkShippingQty.Visible = False
                            ddlShippingQtyUnit.Visible = False
                            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                                lnkShippingQty.Visible = True
                                lnkShippingQty.Text = "Edit"
                            End If
                            'End If
                        Catch ex As Exception
                            ddlShippingQtyUnit.ClearSelection()
                        End Try
                    End If

                    If IsDBNull(dt.Rows(0).Item("Product_ShippingCharges")) Or dt.Rows(0).Item("Product_ShippingCharges").ToString = "" Then
                    Else

                        txtShippingCharges.Visible = False
                        lblShippingCharges.Text = dt.Rows(0).Item("Product_ShippingCharges").ToString()
                        txtShippingCharges.Text = dt.Rows(0).Item("Product_ShippingCharges").ToString()
                        lnkShippingCharge.Visible = False
                        ddlShippingChargesUnit.Visible = False
                        If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                            lnkShippingCharge.Visible = True
                            lnkShippingCharge.Text = "Edit"
                        End If

                    End If
                    If IsDBNull(dt.Rows(0).Item("Product_ShippingChargesType")) Or dt.Rows(0).Item("Product_ShippingChargesType").ToString = "" Then
                    Else
                        Try

                            ddlShippingChargesUnit.ClearSelection()
                            txtShippingCharges.Visible = False
                            lblShippingCharges.Text += "  " & ReturnValue("Select Unit_Name from Unit_Master where Unit_Kid ='" & dt.Rows(0).Item("Product_ShippingChargesType").ToString() & "'and Unit_IsDeleted ='0'")
                            lnkShippingCharge.Visible = False
                            ddlShippingChargesUnit.Visible = False
                            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                                lnkShippingCharge.Visible = True
                                lnkShippingCharge.Text = "Edit"
                            End If

                        Catch ex As Exception
                            ddlShippingChargesUnit.ClearSelection()
                        End Try

                    End If


                    If IsDBNull(dt.Rows(0).Item("Product_DeliveryPeriod")) Or dt.Rows(0).Item("Product_DeliveryPeriod").ToString = "" Then
                    Else

                        txtDispatchIn.Visible = False
                        lblDispatchIN.Text = dt.Rows(0).Item("Product_DeliveryPeriod").ToString()
                        txtDispatchIn.Text = dt.Rows(0).Item("Product_DeliveryPeriod").ToString()
                        lnkDispatchIN.Visible = False
                        ddlDispatchIn.Visible = False
                        If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                            lnkDispatchIN.Visible = True
                            lnkDispatchIN.Text = "Edit"
                        End If
                        ' End If
                    End If
                    If IsDBNull(dt.Rows(0).Item("Product_DeliveryPeriodType")) Or dt.Rows(0).Item("Product_DeliveryPeriodType").ToString = "" Then
                    Else
                        Try

                            ddlDispatchIn.ClearSelection()
                            txtDispatchIn.Visible = False
                            lblDispatchIN.Text += "  " & ReturnValue("Select Unit_Name from Unit_Master where Unit_Kid ='" & dt.Rows(0).Item("Product_DeliveryPeriodType").ToString() & "'and Unit_IsDeleted ='0'")
                            lnkDispatchIN.Visible = False
                            ddlDispatchIn.Visible = False
                            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                                lnkDispatchIN.Visible = True
                                lnkDispatchIN.Text = "Edit"
                            End If
                            'End If
                        Catch ex As Exception
                            ddlDispatchIn.ClearSelection()
                        End Try
                    End If

                    If IsDBNull(dt.Rows(0).Item("Product_Weight")) Or dt.Rows(0).Item("Product_Weight").ToString = "" Then
                    Else

                        txtWeight.Visible = False
                        lblWeight.Text = dt.Rows(0).Item("Product_Weight").ToString()
                        txtWeight.Text = dt.Rows(0).Item("Product_Weight").ToString()
                        lnkWeight.Visible = False
                        ddlWeightUnit.Visible = False
                        If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                            lnkWeight.Visible = True
                            lnkWeight.Text = "Edit"
                        End If
                        'End If
                    End If
                    If IsDBNull(dt.Rows(0).Item("Product_WeightUnitId")) Or dt.Rows(0).Item("Product_WeightUnitId").ToString = "" Then
                    Else
                        Try

                            ddlWeightUnit.ClearSelection()
                            txtWeight.Visible = False
                            lblWeight.Text += "  " & ReturnValue("Select Unit_Name from Unit_Master where Unit_Kid ='" & dt.Rows(0).Item("Product_WeightUnitId").ToString() & "'and Unit_IsDeleted ='0' AND Unit_Flag = 'Weight'")
                            lnkWeight.Visible = False
                            ddlWeightUnit.Visible = False
                            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                                lnkWeight.Visible = True
                                lnkWeight.Text = "Edit"
                            End If

                        Catch ex As Exception
                            ddlWeightUnit.ClearSelection()
                        End Try

                    End If

                    If IsDBNull(dt.Rows(0).Item("Product_Dimension")) Or dt.Rows(0).Item("Product_Dimension").ToString = "" Then
                    Else
                        Try
                            Dim str, str1, str2 As String
                            str = dt.Rows(0).Item("Product_Dimension")
                            Dim i As Integer = InStr(str, "x", CompareMethod.Text)
                            str1 = Mid(str, 1, i - 1)
                            str = Mid(str, i + 1, Len(str))
                            i = InStr(str, "x", CompareMethod.Text)
                            str2 = Mid(str, 1, i - 1)
                            str = Mid(str, i + 1, Len(str))
                            txtLDimension.Text = Val(str1)
                            txtHDimension.Text = Val(str2)
                            txtWDimention.Text = Val(str)
                            txtLDimension.Visible = False
                            txtWDimention.Visible = False
                            txtHDimension.Visible = False
                            ' X.Visible = False
                            'XX.Visible = False
                            lblDimension.Text = dt.Rows(0).Item("Product_Dimension").ToString()
                            lnkDimension.Visible = False
                            ddlDimension.Visible = False
                            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                                lnkDimension.Visible = True
                                lnkDimension.Text = "Edit"
                            End If

                        Catch ex As Exception
                            txtLDimension.Text = ""
                            txtHDimension.Text = ""
                            txtWDimention.Text = ""
                        End Try

                    End If
                    If IsDBNull(dt.Rows(0).Item("Product_DimensionUnitId")) Or dt.Rows(0).Item("Product_DimensionUnitId").ToString = "" Then
                    Else
                        Try

                            ddlDimension.ClearSelection()
                            txtLDimension.Visible = False
                            txtWDimention.Visible = False
                            txtHDimension.Visible = False
                            '  X.Visible = False
                            '   XX.Visible = False
                            lblDimension.Text += "  " & ReturnValue("Select Unit_Name from Unit_Master where Unit_Kid ='" & dt.Rows(0).Item("Product_DimensionUnitId").ToString() & "'and Unit_IsDeleted ='0'")
                            lnkDimension.Visible = False
                            ddlDimension.Visible = False
                            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                                lnkDimension.Visible = True
                                lnkDimension.Text = "Edit"
                            End If

                        Catch ex As Exception
                            ddlDimension.ClearSelection()
                        End Try

                    End If


                    If IsDBNull(dt.Rows(0).Item("Product_Description")) Or dt.Rows(0).Item("Product_Description").ToString = "" Then
                        lblmax.Visible = True
                    Else

                        txtProductDescription.Visible = False
                        Label16.Visible = False
                        tddesc.InnerText = dt.Rows(0).Item("Product_Description").ToString()
                        tddesc.NoWrap = False
                        txtProductDescription.Text = dt.Rows(0).Item("Product_Description").ToString()
                        lnkProductDescription.Visible = False
                        ProductDescLbl.Visible = True
                        ProductDescTxt.Visible = False
                        lblmax.Visible = False
                        If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                            lnkProductDescription.Visible = True
                            lnkProductDescription.Text = "Edit"
                            lblmax.Visible = False
                        End If

                    End If

                End If
                dt.Clear()
            Else
                Response.Redirect("list_product.aspx")
            End If
        Catch ex As Exception
            '  Response.Output.Write("Server error: " & ex.Message.ToString.ToUpperInvariant())
        End Try
    End Sub
    Protected Sub GenerateCode()
        Try
            Dim i As String
            Dim qry As String
            Dim code As String

            i = "1"
            i = Format(Val(i), "000")
            While True
                code = "PRD" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/" & i
                qry = "select count(*) from Product_Master where Product_Code='" & code & "'"
                If IsAlreadyPresent(qry) Then
                    i = Val(i) + 1
                    i = Format(Val(i), "000")
                Else

                    Exit Sub
                End If
            End While
        Catch ex As Exception

        End Try
    End Sub
    Protected Sub GenerateCategoryCode()
        Try
            Dim i As String
            Dim qry As String
            Dim code As String

            i = "1"
            i = Format(Val(i), "000")
            While True
                code = "PCM" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/" & i
                qry = "select count(*) from ProductCategory_Master where ProductCategoryMaster_Code='" & code & "'"
                If IsAlreadyPresent(qry) Then
                    i = Val(i) + 1
                    i = Format(Val(i), "000")
                Else
                    Category_Code = code
                    Exit Sub
                End If
            End While
        Catch ex As Exception
            ' Response.Output.Write("Server error: " & ex.Message.ToString.ToUpperInvariant())
        End Try
    End Sub
    Public Sub FillCategoryNameProduct(ByVal Catid As String)
        Try


            lblCatError.Text = ""
            Dim dt As DataTable
            dt = ReturnDataTable("Select * From Category_Master Where Category_Kid ='" & Catid & "' and Category_Isdeleted = '0'")
            If dt.Rows.Count > 0 Then
                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() & "  >  "

                    For j = 0 To i
                        lblCat.Visible = True
                        lblCat.Text += Category(i)
                        i = i - 1
                    Next
                    Exit Sub
                Else
                    Category(i) = dt.Rows(0).Item(2).ToString() & "  >  "
                    i = i + 1

                    FillCategoryNameProduct(dt.Rows(0).Item(3).ToString())
                End If
            Else
                lblCat.Text = ""
                lblCat.Visible = False
            End If
            dt.Clear()
        Catch ex As Exception
            ' Response.Output.Write("Server error: " & ex.Message.ToString.ToUpperInvariant())
        End Try
    End Sub
    Protected Sub lnkProductName_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkProductName.Click
        Try
            'If (txtProductName.Text = "" And txtModelNo.Text = "") Or (lblProductName.Text = "" And lblModelNo.Text = "") Then
            '    lblCatError.Visible = True
            '    lblCatError.Text = "Please Enter Product Name and Model No."
            '    Exit Sub
            'End If
            Dim prodname As String
            prodname = txtProductName.Text.Trim.ToString    'StrConv(txtProductName.Text.Trim.ToString, VbStrConv.ProperCase)
            If lnkProductName.Text = "Edit" Then
                txtProductName.Visible = True
                lblProductName.Visible = False
                txtProductName.Text = lblProductName.Text
                txtModelNo.Visible = True 'By Pankaj mishra for Model no
                txtModelNo.Text = lblModelNo.Text 'By Pankaj mishra for Model no
                lblModelNo.Visible = False 'By Pankaj mishra for Model no
                lnkProductName.Text = "Update"
                lnkProductName.CausesValidation = True
            ElseIf lnkProductName.Text = "Update" Then
                If txtProductName.Text = "" Or txtModelNo.Text = "" Then
                    lblCatError.Visible = True
                    lblCatError.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Please Enter Product Name and Model No."
                    Exit Sub
                End If
                Dim dt As New DataTable
                dt = ReturnDataTable("Select Product_Name,Product_ModelNo from Product_Master Where Product_Name ='" & prodname & "'and Product_ModelNo = '" & txtModelNo.Text & "'") 'By Pankaj mishra for Model no
                If dt.Rows.Count > 0 Then
                    lblCatError.Visible = True
                    lblCatError.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Product Name and Model No. Already Exist."
                    Exit Sub
                End If
                '' ExecuteQuery("Update Product_Master Set Product_Name = '" & prodname.Trim & "' , Product_ModelNo = '" & txtModelNo.Text & "',Product_ClientIP='" & Request.UserHostAddress & "', Product_UserId='" & RemoveLiterals(Session("g_User")) & "'  where product_Kid = '" & RemoveLiterals(Session("ProductID").ToString()) & "'")
                ExecuteQuery("update Product_Master set Product_UserId='" & RemoveLiterals(Session("g_User").ToString) & "' where Product_SupplierID = '" & Session("SupplierID").ToString & "' and Product_Kid = '" & Session("ProductID").ToString() & "'and Product_IsDeleted = '0' ")
                Dim cmd As New SqlCommand                                                       'Define command variable to execute the query
                cmd.CommandType = CommandType.StoredProcedure                                   'Set the Command Type to Stored procedure
                cmd.CommandText = "JJProduct_Master_Proc"                                        'Assign the Name of Stored Procedure, to Execute
                cmd.Connection = con                                                            'Assign the connection
                cmd.Parameters.Add(New SqlParameter("@Product_Kid", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Session("ProductID").ToString())
                cmd.Parameters.Add(New SqlParameter("@Product_ClientIP", SqlDbType.NVarChar, 50)).Value = Request.UserHostAddress
                cmd.Parameters.Add(New SqlParameter("@Product_Field1", SqlDbType.NVarChar, 100)).Value = "Product_Name"
                cmd.Parameters.Add(New SqlParameter("@Product_Value1", SqlDbType.NVarChar, 250)).Value = prodname.ToString.Trim
                cmd.Parameters.Add(New SqlParameter("@Product_Field2", SqlDbType.NVarChar, 100)).Value = "Product_ModelNo"
                cmd.Parameters.Add(New SqlParameter("@Product_Value2", SqlDbType.NVarChar, 150)).Value = txtModelNo.Text
                cmd.Parameters.Add(New SqlParameter("@mode", SqlDbType.VarChar, 50)).Value = "update"                                   'Add Parameter Mode and assign the DML Operation to Execute
                If (con.State = ConnectionState.Closed) Then
                    con.Open()
                End If
                cmd.ExecuteNonQuery()


                System.Threading.Thread.Sleep(500)
                lblModelNo.Visible = True
                lblModelNo.Text = ReturnValue("Select Product_ModelNo from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'") 'By Pankaj mishra for Model no
                txtModelNo.Visible = False 'By Pankaj mishra for Model no
                lblProductName.Visible = True
                lblProductName.Text = ReturnValue("Select Product_Name from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
                txtProductName.Visible = False
                lnkProductName.Text = "Edit"
            Else
                If txtProductName.Text = "" Or txtModelNo.Text = "" Then
                    lblCatError.Visible = True
                    lblCatError.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Please Enter Product Name and Model No."
                    Exit Sub
                End If
                If Session("CategoryId") = Nothing Then
                    lblCatError.Visible = True
                    lblCatError.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;First Select Category in Which you want to Save Your Product."
                    Exit Sub
                Else
                    lblCatError.Visible = False
                End If
                Session("ProductID") = NewPrimaryKey(Me)
                Session("Product_code") = Nothing
                'Session("Product_code") = GenerateProductCode(RemoveLiterals(Session("SupplierID").ToString.Trim))
                Dim dt As New DataTable
                dt = ReturnDataTable("Select Product_Name,Product_ModelNo from Product_Master Where Product_Name ='" & prodname & "'and Product_ModelNo = '" & txtModelNo.Text & "'") 'By Pankaj mishra for Model no
                If dt.Rows.Count > 0 Then
                    CreateMessageAlert(Me, "Product Name and Model No. Already Exist.", "StrKeyVal")
                    lblCatError.Visible = True
                    lblCatError.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Product Name and Model No. Already Exist."
                    Exit Sub
                End If

                ''   ExecuteQuery("insert into Product_Master(Product_Kid,Product_Code, Product_Name, Product_ModelNo, Product_RegDate, Product_CategoryId, Product_SupplierID, Product_UserId, Product_Approved, Product_FinancialYearId, Product_CompanyId,Product_ClientIP, Product_IsDeleted) Values ( '" & Session("ProductID").ToString() & "', '" & Session("Product_code") & "', '" & prodname & "','" & txtModelNo.Text & "','" & Date.Now & "' , '" & Session("CategoryID").ToString.Trim & "' , '" & Session("SupplierID") & "', '" & Session("g_User") & "','N', '" & Session("g_FinYear").ToString() & "','" & Session("g_Company").ToString() & "', '" & Request.UserHostAddress & "', '0')")


                Dim cmd As New SqlCommand                                                       'Define command variable to execute the query
                cmd.CommandType = CommandType.StoredProcedure                                   'Set the Command Type to Stored procedure
                cmd.CommandText = "JJProduct_Master_Proc"                                        'Assign the Name of Stored Procedure, to Execute
                cmd.Connection = con                                                            'Assign the connection
                cmd.Parameters.Add(New SqlParameter("@Product_Kid", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Session("ProductID").ToString()) 'Trim(txtCategoryId.Text)       'Add Parameter Category_Kid and assign the value of txtCategoryId TextField  to it
                cmd.Parameters.Add(New SqlParameter("@Product_Code", SqlDbType.NVarChar, 25)).Value = Session("Product_code") 'Trim(txtCategoryId.Text)       'Add Parameter Category_Kid and assign the value of txtCategoryId TextField  to it
                cmd.Parameters.Add(New SqlParameter("@Product_Name", SqlDbType.NVarChar, 200)).Value = prodname.ToString.Trim 'ProductKId.ToString 'Trim(txtCategoryId.Text)       'Add Parameter Category_Kid and assign the value of txtCategoryId TextField  to it
                cmd.Parameters.Add(New SqlParameter("@Product_ModelNo", SqlDbType.NVarChar, 150)).Value = txtModelNo.Text
                cmd.Parameters.Add(New SqlParameter("@Product_RegDate", SqlDbType.DateTime)).Value = Date.Now 'ProductKId.ToString 'Trim(txtCategoryId.Text)       'Add Parameter Category_Kid and assign the value of txtCategoryId TextField  to it
                cmd.Parameters.Add(New SqlParameter("@Product_CategoryId", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Session("CategoryID").ToString.Trim) 'ProductKId.ToString 'Trim(txtCategoryId.Text)       'Add Parameter Category_Kid and assign the value of txtCategoryId TextField  to it
                cmd.Parameters.Add(New SqlParameter("@Product_SupplierID", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Session("SupplierID")) 'ProductKId.ToString 'Trim(txtCategoryId.Text)       'Add Parameter Category_Kid and assign the value of txtCategoryId TextField  to it
                cmd.Parameters.Add(New SqlParameter("@Product_UserId", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Session("g_User")) 'ProductKId.ToString 'Trim(txtCategoryId.Text)       'Add Parameter Category_Kid and assign the value of txtCategoryId TextField  to it
                cmd.Parameters.Add(New SqlParameter("@Product_Approved", SqlDbType.NVarChar, 20)).Value = "N" 'ProductKId.ToString 'Trim(txtCategoryId.Text)       'Add Parameter Category_Kid and assign the value of txtCategoryId TextField  to it
                cmd.Parameters.Add(New SqlParameter("@Product_FinancialYearId", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Convert.ToString(Session("g_FinYear"))) '"Product_Name" 'Trim(txtCategoryCode.Text)       'Add Parameter Category_Code and assign the value of txtCategoryCode TextField to it
                cmd.Parameters.Add(New SqlParameter("@Product_CompanyId", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Convert.ToString(Session("g_Company"))) 'txtJJProductName.Text.ToString.Trim   'Trim(txtCategoryName.Text)       'Add Parameter Category_Name and assign the value of txtCategoryName TextField to it
                cmd.Parameters.Add(New SqlParameter("@Product_ClientIP", SqlDbType.NVarChar, 50)).Value = Request.UserHostAddress  'RemoveLiterals(Convert.ToString(Session("g_Company")))
                cmd.Parameters.Add(New SqlParameter("@Product_IsDeleted", SqlDbType.NVarChar, 1)).Value = "0"
                cmd.Parameters.Add(New SqlParameter("@mode", SqlDbType.VarChar, 50)).Value = "insert"                                   'Add Parameter Mode and assign the DML Operation to Execute (Insert)
                If (con.State = ConnectionState.Closed) Then
                    con.Open()
                End If
                cmd.ExecuteNonQuery()


                System.Threading.Thread.Sleep(1000)
                tbl1.Visible = False
                tdproductcode1.Visible = True
                tdproductcode2.Visible = True
                lblProductCode.Text = """Will be Generate After Approval."""
                lblProductName.Text = ReturnValue("Select Product_Name from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
                lblModelNo.Text = ReturnValue("Select Product_ModelNo from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'") 'By Pankaj mishra for Model no
                System.Threading.Thread.Sleep(1000)
                txtProductName.Visible = False
                txtModelNo.Visible = False 'By Pankaj mishra for Model no
                lblProductName.ForeColor = Drawing.Color.Black
                lnkProductName.Visible = False
                lblCatError.Text = ""
                FillCategoryNameProduct(Session("CategoryID").ToString)

                Session("CategoryID") = Nothing

                If Session("AdminID") <> Nothing Then
                    lnkProductName.Text = "Edit"
                    lnkProductName.Visible = True
                End If


            End If
        Catch ex As Exception
            'Response.Output.Write("Server error: " & ex.Message.ToString.ToUpperInvariant())
        End Try

    End Sub
    Protected Sub lnkProductImage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkProductImage.Click
        Try
            If lnkProductImage.Text = "Edit" Then
                fuProductImage.Visible = True
                lblfileup.Visible = True
                Label3.Visible = True
                lnkProductImage.Text = "Update"
                lblProductImage.Visible = False
            Else
                If lblProductName.Text <> "" Then
                    If (fuProductImage.HasFile And fuProductImage.FileBytes.Length < 512000) Then
                        lblProductImage.Text = ""
                        Dim file_name As String
                        Dim fileType As String = Path.GetExtension(fuProductImage.FileName)
                        If fileType.ToLower = ".gif" Or fileType = ".png" Or fileType = ".jpg" Or fileType = ".jpeg" Or fileType = ".bmp" Then
                            Dim folderpath As String = Server.MapPath("~/Upload Image/Product Image/UploadImages/")
                            ' file_name = ReturnValue("Select Product_Image from Product_Master Where Product_Kid ='" & RemoveLiterals(Session("ProductID").ToString) & "'and Product_IsDeleted = '0'")
                            file_name = Image_upload(fuProductImage, img, folderpath, file_name)

                            ''  ExecuteQuery("Update Product_Master Set Product_Image = '" & file_name & "',Product_ClientIP='" & Request.UserHostAddress & "', Product_UserId='" & RemoveLiterals(Session("g_User")) & "'  where product_Kid = '" & RemoveLiterals(Session("ProductID").ToString()) & "'")
                            ExecuteQuery("update Product_Master set Product_UserId='" & RemoveLiterals(Session("g_User").ToString) & "' where Product_SupplierID = '" & Session("SupplierID").ToString & "' and Product_Kid = '" & Session("ProductID").ToString() & "'and Product_IsDeleted = '0' ")
                            Dim cmd As New SqlCommand                                                       'Define command variable to execute the query
                            cmd.CommandType = CommandType.StoredProcedure                                   'Set the Command Type to Stored procedure
                            cmd.CommandText = "JJProduct_Master_Proc"                                        'Assign the Name of Stored Procedure, to Execute
                            cmd.Connection = con                                                            'Assign the connection
                            cmd.Parameters.Add(New SqlParameter("@Product_Kid", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Session("ProductID").ToString())
                            cmd.Parameters.Add(New SqlParameter("@Product_ClientIP", SqlDbType.NVarChar, 50)).Value = Request.UserHostAddress
                            cmd.Parameters.Add(New SqlParameter("@Product_Field1", SqlDbType.NVarChar, 100)).Value = "Product_Image"
                            cmd.Parameters.Add(New SqlParameter("@Product_Value1", SqlDbType.NVarChar, 150)).Value = file_name
                            cmd.Parameters.Add(New SqlParameter("@mode", SqlDbType.VarChar, 50)).Value = "update"                                   'Add Parameter Mode and assign the DML Operation to Execute
                            If (con.State = ConnectionState.Closed) Then
                                con.Open()
                            End If
                            cmd.ExecuteNonQuery()

                            System.Threading.Thread.Sleep(500)
                            fuProductImage.Visible = False
                            lblProductImage.Visible = True
                            lblProductImage.Text = file_name
                            lblProductImage.ForeColor = Drawing.Color.Black
                            imgProduct.Visible = True
                            imgProduct.ImageUrl = "~/Upload Image/Product Image/UploadImages/" & ReturnValue("Select Product_Image from Product_Master Where Product_Kid ='" & RemoveLiterals(Session("ProductID").ToString) & "'and Product_IsDeleted = '0'")
                            Dim imgepath As String
                            imgepath = Server.MapPath(imgProduct.ImageUrl)
                            KeepAspectRatioNew(imgProduct, imgepath, 150, 150)
                            lnkProductImage.Visible = False
                            lblfileup.Visible = False
                            Label3.Visible = False
                            lblProductImage.Visible = False

                        Else
                            CreateMessageAlert(Me, "Please Select Valid file type (.gif, .png, .jpg, .jpeg, .bmp, .JPG)", "StrKeyVal")
                            'lblProductImage.Text = "Valid file type (.gif, .png, .jpg, .jpeg, .bmp, .JPG)"
                            'lblProductImage.ForeColor = Drawing.Color.Red
                            Exit Sub
                        End If

                    Else
                        lblfileup.Visible = True
                        Label3.Visible = True
                        CreateMessageAlert(Me, "File size should not be more than 512 KB.", "StrKeyVal")
                        'CreateMessageAlert(Me, "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;File size should not be more than 512 KB.", "strkeyval")
                        ' lblProductImage.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;File size should not be more than 512 KB."
                        'lblProductImage.ForeColor = Drawing.Color.Red
                        fuProductImage.Focus()
                        Exit Sub
                    End If
                    If lnkProductImage.Text = "Update" Then
                        lnkProductImage.Visible = True
                        lnkProductImage.Text = "Edit"
                        fuProductImage.Visible = False
                        lblfileup.Visible = False
                        Label3.Visible = False
                        lblProductImage.Visible = False
                    End If
                    If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                        lnkProductImage.Text = "Edit"
                        lnkProductImage.Visible = True
                        lblProductImage.Visible = True
                        Label3.Visible = True
                        lblfileup.Visible = True

                    End If
                Else
                    lblError.Visible = True
            End If
            End If
        Catch ex As Exception
            'Response.Output.Write("Server error: " & ex.Message.ToString.ToUpperInvariant())
        End Try
    End Sub
    '=======================For  Upload All Image in Jpeg format and user define size BY Pankaj Mishra
    Public Function Image_upload(ByRef fileup As FileUpload, ByVal i As Integer, ByVal folderpath As String, ByVal existfile As String) As String
        Try


            Dim filetype As String = Path.GetExtension(fileup.FileName)
            Dim j As Integer = Len(filetype)
            Dim filename As String = fileup.FileName
            Dim file As String = Mid(fileup.FileName, 1, Len(filename) - j)
            If existfile = "" Then
                While System.IO.File.Exists(folderpath & filename) ' function for checking file already exist
                    i = i + 1
                    filename = file & i & filetype
                End While
            Else
                filename = existfile
                If FileIsLocked(folderpath & filename) = False Then
                    System.IO.File.SetAttributes(folderpath & filename, FileAttributes.Normal)
                End If
            End If


            Dim filepath As String = folderpath & filename
            fileup.SaveAs(filepath)
            fileup.Dispose()
            'set a working directory
            Dim WorkingDirectory As String = folderpath

            'create a image object containing a verticel photograph
            Dim imgPhotoVert As Image = Image.FromFile(WorkingDirectory & filename)
            Dim imgPhotoHoriz As Image = Image.FromFile(WorkingDirectory & filename)
            Dim imgPhoto As Image = Nothing
            If imgPhotoVert.Height >= 650 Then
                imgPhoto = ConstrainProportions(imgPhotoVert, 650, Dimensions.Width, 650)
            ElseIf imgPhotoVert.Width >= 650 Then
                imgPhoto = ConstrainProportions(imgPhotoVert, 650, Dimensions.Height, 650)
            ElseIf imgPhotoVert.Height <= 200 Then
                imgPhoto = ConstrainProportions(imgPhotoVert, 250, 0, 250)
            ElseIf imgPhotoVert.Width <= 250 Then
                imgPhoto = ConstrainProportions(imgPhotoVert, 200, 1, 250)
            Else
                imgPhoto = ConstrainProportions(imgPhotoVert, imgPhotoVert.Width, Dimensions.Width, imgPhotoVert.Width)
            End If
            imgPhotoVert.Dispose()
            imgPhotoHoriz.Dispose()
            imgPhoto.Save(WorkingDirectory & filename)
            imgPhoto.Dispose()
            Return filename
        Catch ex As Exception

        End Try
    End Function
    Protected Sub lnkMarketPrice_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkMarketPrice.Click
        Try

            If lnkMarketPrice.Text = "Edit" Then
                txtMarketPrice.Visible = True
                lblMarketPrice.Visible = False
                txtMarketPrice.Text = ReturnValue("Select Product_MarketPrice from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
                ddlMarketPriceUnit.Visible = True
                ddlMarketPriceUnit.Enabled = True
                lnkMarketPrice.CausesValidation = True
                Try
                    ddlMarketPriceUnit.ClearSelection()
                    ddlMarketPriceUnit.Items.FindByValue(ReturnValue("Select Product_MarketPriceType from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")).Selected = True
                Catch ex As Exception
                    ddlMarketPriceUnit.ClearSelection()
                End Try
                lnkMarketPrice.Text = "Update"
            Else
                If Val(txtMarketPrice.Text.ToString) > 0.0 Then
                    lblCatError.Visible = False
                Else
                    lblCatError.Visible = True
                    lblCatError.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Market price must be greater than zero."
                    Exit Sub
                End If
                If lblProductName.Text <> "" Then
                    lblMarketPrice.Text = ""
                    ' ExecuteQuery("Update Product_Master Set Product_MarketPrice = '" & txtMarketPrice.Text.ToString.Trim & "', Product_MarketPriceType = '" & ddlMarketPriceUnit.SelectedItem.Value & "',Product_ClientIP='" & Request.UserHostAddress & "', Product_UserId='" & RemoveLiterals(Session("g_User")) & "'  where product_Kid = '" & RemoveLiterals(Session("ProductID").ToString()) & "'")
                    ExecuteQuery("update Product_Master set Product_UserId='" & RemoveLiterals(Session("g_User").ToString) & "' where Product_SupplierID = '" & Session("SupplierID").ToString & "' and Product_Kid = '" & Session("ProductID").ToString() & "'and Product_IsDeleted = '0' ")
                    Dim cmd As New SqlCommand                                                       'Define command variable to execute the query
                    cmd.CommandType = CommandType.StoredProcedure                                   'Set the Command Type to Stored procedure
                    cmd.CommandText = "JJProduct_Master_Proc"                                        'Assign the Name of Stored Procedure, to Execute
                    cmd.Connection = con                                                            'Assign the connection
                    cmd.Parameters.Add(New SqlParameter("@Product_Kid", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Session("ProductID").ToString())
                    cmd.Parameters.Add(New SqlParameter("@Product_ClientIp", SqlDbType.NVarChar, 50)).Value = Request.UserHostAddress
                    cmd.Parameters.Add(New SqlParameter("@Product_Field1", SqlDbType.NVarChar, 100)).Value = "Product_MarketPrice"
                    cmd.Parameters.Add(New SqlParameter("@Product_Value1", SqlDbType.NVarChar, 200)).Value = txtMarketPrice.Text.ToString.Trim
                    cmd.Parameters.Add(New SqlParameter("@Product_Field2", SqlDbType.NVarChar, 50)).Value = "Product_MarketPriceType"
                    cmd.Parameters.Add(New SqlParameter("@Product_Value2", SqlDbType.NVarChar, 10)).Value = RemoveLiterals(ddlMarketPriceUnit.SelectedItem.Value)
                    cmd.Parameters.Add(New SqlParameter("@mode", SqlDbType.VarChar, 50)).Value = "update"                                   'Add Parameter Mode and assign the DML Operation to Execute
                    If (con.State = ConnectionState.Closed) Then
                        con.Open()
                    End If
                    cmd.ExecuteNonQuery()


                    System.Threading.Thread.Sleep(500)
                    lblMarketPrice.Text = ddlMarketPriceUnit.SelectedItem.Text & "  " & ReturnValue("Select Product_MarketPrice from Product_Master Where Product_Kid ='" & RemoveLiterals(Session("ProductID").ToString()) & "'and Product_IsDeleted = '0'")
                    txtMarketPrice.Visible = False
                    ddlMarketPriceUnit.Visible = False
                    lnkMarketPrice.Visible = False
                    lnktax.Visible = True
                    lnktax.Attributes.Add("onclick", "return OpenTAX();")
                    If lnkMarketPrice.Text = "Update" Then
                        lnkMarketPrice.Visible = True
                        lnkMarketPrice.Text = "Edit"
                        lblMarketPrice.Visible = True
                    End If
                    If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                        lnkMarketPrice.Visible = True
                        lnkMarketPrice.Text = "Edit"
                    End If
                Else
                    lblError.Visible = True
                End If

            End If
        Catch ex As Exception
            'Response.Output.Write("Server error: " & ex.Message.ToString.ToUpperInvariant())
        End Try
    End Sub
    Protected Sub lnkAtcoPrice_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkAtcoPrice.Click
        Try
            If lblMarketPrice.Text = "" Then
                lblCatError.Visible = True
                lblCatError.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;First enter market price."
                Exit Sub

            End If

            If Val(txtAtcoPrice.Text) > 0 Then
                lblCatError.Visible = False
            Else
                lblCatError.Visible = True
                lblCatError.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Atcomaart price must be greater than zero."
                Exit Sub
            End If



            Dim atcoPriceType As String
            atcoPriceType = ReturnValue("select Product_MarketPriceType from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")


            If ddlAtcoPriceUnit.Visible = True Then
                If atcoPriceType = ddlAtcoPriceUnit.SelectedValue.ToString Then
                    lblCatError.Visible = False
                Else
                    lblCatError.Visible = True
                    lblCatError.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Atcomaart price type same as market price type."
                    ddlAtcoPriceUnit.Focus()
                    Exit Sub
                End If
            End If

            If lnkAtcoPrice.Text = "Edit" Then
                txtAtcoPrice.Visible = True
                lblAtcoPrice.Visible = False
                txtAtcoPrice.Text = ReturnValue("Select Product_AtcoPrice from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
                ddlAtcoPriceUnit.Visible = True
                Try
                    ddlAtcoPriceUnit.ClearSelection()
                    ddlAtcoPriceUnit.Items.FindByValue(ReturnValue("Select Product_AtcoPriceType from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")).Selected = True
                Catch ex As Exception
                    ddlAtcoPriceUnit.ClearSelection()
                End Try
                lnkAtcoPrice.Text = "Update"
            Else
                If lblProductName.Text <> "" Then
                    Dim mrp As Double
                    mrp = CType(txtMarketPrice.Text, Double)
                    Dim atco As Double
                    atco = CType(txtAtcoPrice.Text, Double)
                    If mrp <= atco Then
                        lblCatError.Visible = True
                        lblCatError.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Atco Price Must Be Less Then Market Price."
                        txtAtcoPrice.Focus()
                        Exit Sub
                    End If
                    lblAtcoPrice.Text = ""
                    ExecuteQuery("Update Product_Master Set Product_AtcoPrice = '" & txtAtcoPrice.Text.ToString.Trim & "', Product_AtcoPriceType = '" & ddlAtcoPriceUnit.SelectedItem.Value & "',Product_ClientIP='" & Request.UserHostAddress & "', Product_UserId='" & RemoveLiterals(Session("g_User")) & "' , Product_UserId='" & RemoveLiterals(Session("g_User")) & "'  where product_Kid = '" & RemoveLiterals(Session("ProductID").ToString()) & "'")
                    System.Threading.Thread.Sleep(500)
                    lblAtcoPrice.Text = ddlAtcoPriceUnit.SelectedItem.Text & "  " & ReturnValue("Select Product_AtcoPrice from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
                    txtAtcoPrice.Visible = False
                    ddlAtcoPriceUnit.Visible = False
                    lnkAtcoPrice.Visible = False

                    If lnkAtcoPrice.Text = "Update" Then
                        lnkAtcoPrice.Visible = True
                        lnkAtcoPrice.Text = "Edit"
                        lblAtcoPrice.Visible = True
                    End If
                    If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                        lnkAtcoPrice.Visible = True
                        lnkAtcoPrice.Text = "Edit"
                    End If
                Else
                    lblError.Visible = True
                End If

            End If
        Catch ex As Exception
            'Response.Output.Write("Server error: " & ex.Message.ToString.ToUpperInvariant())
        End Try
    End Sub
    Protected Sub lnkBrandName_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkBrandName.Click
        Try
            If lnkBrandName.Text = "Edit" Then
                ddlBrandName.Visible = True
                lblBrandName.Visible = False
                Try
                    ddlBrandName.ClearSelection()
                    ddlBrandName.Items.FindByValue(ReturnValue("Select Product_BrandId from Product_Master where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")).Selected = True
                Catch ex As Exception
                    ddlBrandName.ClearSelection()
                End Try
                lnkBrandName.Text = "Update"
                lnkBrandName.CausesValidation = True
            Else
                If lblProductName.Text <> "" Then
                    lblBrandName.Text = ""
                    ' ExecuteQuery("Update Product_Master Set Product_BrandID = '" & ddlBrandName.SelectedItem.Value.ToString.Trim & "',Product_ClientIP='" & Request.UserHostAddress & "', Product_UserId='" & RemoveLiterals(Session("g_User")) & "' where product_Kid = '" & RemoveLiterals(Session("ProductID").ToString()) & "'")
                    ExecuteQuery("update Product_Master set Product_UserId='" & RemoveLiterals(Session("g_User").ToString) & "' where Product_SupplierID = '" & Session("SupplierID").ToString & "' and Product_Kid = '" & Session("ProductID").ToString() & "'and Product_IsDeleted = '0' ")
                    Dim cmd As New SqlCommand                                                       'Define command variable to execute the query
                    cmd.CommandType = CommandType.StoredProcedure                                   'Set the Command Type to Stored procedure
                    cmd.CommandText = "JJProduct_Master_Proc"                                        'Assign the Name of Stored Procedure, to Execute
                    cmd.Connection = con                                                            'Assign the connection
                    cmd.Parameters.Add(New SqlParameter("@Product_Kid", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Session("ProductID").ToString())
                    cmd.Parameters.Add(New SqlParameter("@Product_ClientIp", SqlDbType.NVarChar, 50)).Value = Request.UserHostAddress
                    cmd.Parameters.Add(New SqlParameter("@Product_Field1", SqlDbType.NVarChar, 100)).Value = "Product_BrandId"
                    cmd.Parameters.Add(New SqlParameter("@Product_Value1", SqlDbType.NVarChar, 10)).Value = RemoveLiterals(ddlBrandName.SelectedItem.Value.ToString.Trim)
                    cmd.Parameters.Add(New SqlParameter("@mode", SqlDbType.VarChar, 50)).Value = "update"                                   'Add Parameter Mode and assign the DML Operation to Execute 
                    If (con.State = ConnectionState.Closed) Then
                        con.Open()
                    End If
                    cmd.ExecuteNonQuery()

                    System.Threading.Thread.Sleep(500)
                    lblBrandName.Text = ddlBrandName.SelectedItem.Text
                    ' txtBrandName.Visible = False
                    lnkBrandName.Visible = False
                    ddlBrandName.Visible = False
                    If lnkBrandName.Text = "Update" Then
                        lnkBrandName.Visible = True
                        lblBrandName.Visible = True
                        lnkBrandName.Text = "Edit"
                    End If
                    If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                        lnkBrandName.Visible = True
                        lnkBrandName.Text = "Edit"
                    End If
                Else
                    lblError.Visible = True
                End If
            End If
        Catch ex As Exception
            'Response.Output.Write("Server error: " & ex.Message.ToString.ToUpperInvariant())
        End Try
    End Sub
    Protected Sub lnkSellQty_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkSellQty.Click
        Try
            If Val(txtSellQty.Text) >= 0 Then
                lblCatError.Visible = False
            Else

                lblCatError.Visible = True
                CreateMessageAlert(Me, "Min. order qty must be greater than zero.", "StrKeyVal")
                lblCatError.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Min. order qty must be greater than zero."
                Exit Sub
            End If
            If lnkSellQty.Text = "Edit" Then
                txtSellQty.Visible = True
                lblSellQty.Visible = False
                txtSellQty.Text = ReturnValue("Select Product_MinOrderQty from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
                ddlSellQtyUnit.Visible = True
                Try
                    ddlSellQtyUnit.ClearSelection()
                    ddlSellQtyUnit.Items.FindByValue(ReturnValue("Select Product_MinOrderQtyType from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")).Selected = True
                Catch ex As Exception
                    ddlSellQtyUnit.ClearSelection()
                End Try
                lnkSellQty.Text = "Update"
            Else
                If lblProductName.Text <> "" Then
                    lblSellQty.Text = ""
                    '' ExecuteQuery("Update Product_Master Set Product_MinOrderQty = '" & txtSellQty.Text & "', Product_MinOrderQtyType = '" & ddlSellQtyUnit.SelectedItem.Value & "',Product_ClientIP='" & Request.UserHostAddress & "', Product_UserId='" & RemoveLiterals(Session("g_User")) & "' where product_Kid = '" & RemoveLiterals(Session("ProductID").ToString()) & "'")
                    ExecuteQuery("update Product_Master set Product_UserId='" & RemoveLiterals(Session("g_User").ToString) & "' where Product_SupplierID = '" & Session("SupplierID").ToString & "' and Product_Kid = '" & Session("ProductID").ToString() & "'and Product_IsDeleted = '0' ")
                    Dim cmd As New SqlCommand                                                       'Define command variable to execute the query
                    cmd.CommandType = CommandType.StoredProcedure                                   'Set the Command Type to Stored procedure
                    cmd.CommandText = "JJProduct_Master_Proc"                                        'Assign the Name of Stored Procedure, to Execute
                    cmd.Connection = con                                                            'Assign the connection
                    cmd.Parameters.Add(New SqlParameter("@Product_Kid", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Session("ProductID").ToString())
                    cmd.Parameters.Add(New SqlParameter("@Product_ClientIp", SqlDbType.NVarChar, 50)).Value = Request.UserHostAddress
                    cmd.Parameters.Add(New SqlParameter("@Product_Field1", SqlDbType.NVarChar, 100)).Value = "Product_MinOrderQty"
                    cmd.Parameters.Add(New SqlParameter("@Product_Value1", SqlDbType.NVarChar, 200)).Value = txtSellQty.Text
                    cmd.Parameters.Add(New SqlParameter("@Product_Field2", SqlDbType.NVarChar, 100)).Value = "Product_MinOrderQtyType"
                    cmd.Parameters.Add(New SqlParameter("@Product_Value2", SqlDbType.NVarChar, 10)).Value = RemoveLiterals(ddlSellQtyUnit.SelectedItem.Value)
                    cmd.Parameters.Add(New SqlParameter("@mode", SqlDbType.VarChar, 50)).Value = "update"                                   'Add Parameter Mode and assign the DML Operation to Execute 
                    If (con.State = ConnectionState.Closed) Then
                        con.Open()
                    End If
                    cmd.ExecuteNonQuery()


                    System.Threading.Thread.Sleep(500)
                    lblSellQty.Text = ReturnValue("Select Product_MinOrderQty from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'") & "  " & ddlSellQtyUnit.SelectedItem.Text
                    txtSellQty.Visible = False
                    lnkSellQty.Visible = False
                    ddlSellQtyUnit.Visible = False
                    If lnkSellQty.Text = "Update" Then
                        lnkSellQty.Visible = True
                        lnkSellQty.Text = "Edit"
                        lblSellQty.Visible = True
                        txtSellQty.Visible = False
                        ddlSellQtyUnit.Visible = False
                    End If
                    If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                        lnkSellQty.Visible = True
                        lnkSellQty.Text = "Edit"
                    End If
                Else
                    lblError.Visible = True
                End If
            End If
        Catch ex As Exception
            ' Response.Output.Write("Server error: " & ex.Message.ToString.ToUpperInvariant())
        End Try
    End Sub
    Protected Sub lnkShippingQty_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkShippingQty.Click
        Try
            If Val(txtShippingQty.Text) >= 0 Then
                lblCatError.Visible = False
            Else
                CreateMessageAlert(Me, "Min. shipping qty must be greater than zero.", "StrKeyVal")
                lblCatError.Visible = True
                lblCatError.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Min. shipping qty must be greater than zero."
                Exit Sub
            End If
            If lnkShippingQty.Text = "Edit" Then
                txtShippingQty.Visible = True
                lblShippingQty.Visible = False
                txtShippingQty.Text = ReturnValue("Select Product_ShippingQty from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
                ddlShippingQtyUnit.Visible = True
                Try
                    ddlShippingQtyUnit.ClearSelection()
                    ddlShippingQtyUnit.Items.FindByValue(ReturnValue("Select Product_ShippingQtyType from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")).Selected = True
                Catch ex As Exception
                    ddlShippingQtyUnit.ClearSelection()
                End Try
                lnkShippingQty.Text = "Update"
            Else
                If lblProductName.Text <> "" Then
                    lblShippingQty.Text = ""
                    '' ExecuteQuery("Update Product_Master Set Product_ShippingQty = '" & txtShippingQty.Text & "', Product_ShippingQtyType = '" & ddlShippingQtyUnit.SelectedItem.Value & "',Product_ClientIP='" & Request.UserHostAddress & "', Product_UserId='" & RemoveLiterals(Session("g_User")) & "' where product_Kid = '" & RemoveLiterals(Session("ProductID").ToString()) & "'")
                    ExecuteQuery("update Product_Master set Product_UserId='" & RemoveLiterals(Session("g_User").ToString) & "' where Product_SupplierID = '" & Session("SupplierID").ToString & "' and Product_Kid = '" & Session("ProductID").ToString() & "'and Product_IsDeleted = '0' ")
                    Dim cmd As New SqlCommand                                                       'Define command variable to execute the query
                    cmd.CommandType = CommandType.StoredProcedure                                   'Set the Command Type to Stored procedure
                    cmd.CommandText = "JJProduct_Master_Proc"                                        'Assign the Name of Stored Procedure, to Execute
                    cmd.Connection = con                                                            'Assign the connection
                    cmd.Parameters.Add(New SqlParameter("@Product_Kid", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Session("ProductID").ToString())
                    cmd.Parameters.Add(New SqlParameter("@Product_ClientIp", SqlDbType.NVarChar, 50)).Value = Request.UserHostAddress
                    cmd.Parameters.Add(New SqlParameter("@Product_Field1", SqlDbType.NVarChar, 100)).Value = "Product_ShippingQty"
                    cmd.Parameters.Add(New SqlParameter("@Product_Value1", SqlDbType.NVarChar, 200)).Value = txtShippingQty.Text
                    cmd.Parameters.Add(New SqlParameter("@Product_Field2", SqlDbType.NVarChar, 100)).Value = "Product_ShippingQtyType"
                    cmd.Parameters.Add(New SqlParameter("@Product_Value2", SqlDbType.NVarChar, 10)).Value = RemoveLiterals(ddlShippingQtyUnit.SelectedItem.Value)
                    cmd.Parameters.Add(New SqlParameter("@mode", SqlDbType.VarChar, 50)).Value = "update"                                   'Add Parameter Mode and assign the DML Operation to Execute
                    If (con.State = ConnectionState.Closed) Then
                        con.Open()
                    End If
                    cmd.ExecuteNonQuery()


                    System.Threading.Thread.Sleep(500)
                    lblShippingQty.Text = ReturnValue("Select Product_ShippingQty from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'") & "  " & ddlShippingQtyUnit.SelectedItem.Text
                    txtShippingQty.Visible = False
                    lnkShippingQty.Visible = False
                    ddlShippingQtyUnit.Visible = False
                    If lnkShippingQty.Text = "Update" Then
                        lnkShippingQty.Text = "Edit"
                        txtShippingQty.Visible = False
                        lblShippingQty.Visible = True
                        lnkShippingQty.Visible = True
                        txtShippingQty.Visible = False
                    End If
                    If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                        lnkShippingQty.Text = "Edit"
                        lnkShippingQty.Visible = True
                    End If
                Else
                    lblError.Visible = True
                End If
            End If
        Catch ex As Exception
            ' Response.Output.Write("Server error: " & ex.Message.ToString.ToUpperInvariant())
        End Try
    End Sub
    Protected Sub lnkShippingCharge_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkShippingCharge.Click
        Try
            If Val(txtShippingCharges.Text) >= 0 Then
                lblCatError.Visible = False
            Else
                lblCatError.Visible = True
                lblCatError.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Shipping Charges must be greater than zero."
                Exit Sub
            End If

            If lnkShippingCharge.Text = "Edit" Then
                txtShippingCharges.Visible = True
                lblShippingCharges.Visible = False
                txtShippingCharges.Text = ReturnValue("Select Product_ShippingCharges from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
                ddlShippingChargesUnit.Visible = True
                Try
                    ddlShippingChargesUnit.ClearSelection()
                    ddlShippingChargesUnit.Items.FindByValue(ReturnValue("Select Product_ShippingChargesType from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")).Selected = True
                Catch ex As Exception
                    ddlShippingChargesUnit.ClearSelection()
                End Try
                lnkShippingCharge.Text = "Update"
            Else
                If lblProductName.Text <> "" Then
                    lblShippingCharges.Text = ""
                    '' ExecuteQuery("Update Product_Master Set Product_ShippingCharges = '" & txtShippingCharges.Text & "', Product_ShippingChargesType = '" & ddlShippingChargesUnit.SelectedItem.Value & "',Product_ClientIP='" & Request.UserHostAddress & "', Product_UserId='" & RemoveLiterals(Session("g_User")) & "' where product_Kid = '" & RemoveLiterals(Session("ProductID").ToString()) & "'")
                    ExecuteQuery("update Product_Master set Product_UserId='" & RemoveLiterals(Session("g_User").ToString) & "' where Product_SupplierID = '" & Session("SupplierID").ToString & "' and Product_Kid = '" & Session("ProductID").ToString() & "'and Product_IsDeleted = '0' ")
                    Dim cmd As New SqlCommand                                                       'Define command variable to execute the query
                    cmd.CommandType = CommandType.StoredProcedure                                   'Set the Command Type to Stored procedure
                    cmd.CommandText = "JJProduct_Master_Proc"                                        'Assign the Name of Stored Procedure, to Execute
                    cmd.Connection = con                                                            'Assign the connection
                    cmd.Parameters.Add(New SqlParameter("@Product_Kid", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Session("ProductID").ToString())
                    cmd.Parameters.Add(New SqlParameter("@Product_ClientIp", SqlDbType.NVarChar, 50)).Value = Request.UserHostAddress
                    cmd.Parameters.Add(New SqlParameter("@Product_Field1", SqlDbType.NVarChar, 100)).Value = "Product_ShippingCharges"
                    cmd.Parameters.Add(New SqlParameter("@Product_Value1", SqlDbType.NVarChar, 200)).Value = txtShippingCharges.Text
                    cmd.Parameters.Add(New SqlParameter("@Product_Field2", SqlDbType.NVarChar, 100)).Value = "Product_ShippingChargesType"
                    cmd.Parameters.Add(New SqlParameter("@Product_Value2", SqlDbType.NVarChar, 10)).Value = RemoveLiterals(ddlShippingChargesUnit.SelectedItem.Value)
                    cmd.Parameters.Add(New SqlParameter("@mode", SqlDbType.VarChar, 50)).Value = "update"                                   'Add Parameter Mode and assign the DML Operation to Execute 
                    If (con.State = ConnectionState.Closed) Then
                        con.Open()
                    End If
                    cmd.ExecuteNonQuery()

                    System.Threading.Thread.Sleep(500)
                    lblShippingCharges.Text = ddlShippingChargesUnit.SelectedItem.Text & "  " & ReturnValue("Select Product_ShippingCharges from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
                    txtShippingCharges.Visible = False
                    lnkShippingCharge.Visible = False
                    ddlShippingChargesUnit.Visible = False
                    If lnkShippingCharge.Text = "Update" Then
                        txtShippingCharges.Visible = False
                        lblShippingCharges.Visible = True
                        ddlShippingChargesUnit.Visible = False
                        lnkShippingCharge.Visible = True
                        lnkShippingCharge.Text = "Edit"
                    End If
                    If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                        lnkShippingCharge.Text = "Edit"
                        lnkShippingCharge.Visible = True
                    End If
                Else
                    lblError.Visible = True
                End If
            End If
        Catch ex As Exception
            '  Response.Output.Write("Server error: " & ex.Message.ToString.ToUpperInvariant())
        End Try
    End Sub
    Protected Sub lnkDispatchIN_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkDispatchIN.Click
        Try
            If Val(txtDispatchIn.Text) >= 0 Then
                lblCatError.Visible = False
            Else
                CreateMessageAlert(Me, "Dispatch Time must be greater than zero.", "StrKeyVal")
                lblCatError.Visible = True
                lblCatError.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Dispatch time must be greater than zero."
                Exit Sub
            End If



            If lnkDispatchIN.Text = "Edit" Then
                txtDispatchIn.Visible = True
                lblDispatchIN.Visible = False
                txtDispatchIn.Text = ReturnValue("Select Product_DeliveryPeriod from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
                ddlDispatchIn.Visible = True
                Try
                    ddlDispatchIn.ClearSelection()
                    ddlDispatchIn.Items.FindByValue(ReturnValue("Select Product_DeliveryPeriodType from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")).Selected = True
                Catch ex As Exception
                    ddlDispatchIn.ClearSelection()
                End Try
                lnkDispatchIN.Text = "Update"
            Else
                If lblProductName.Text <> "" Then
                    lblDispatchIN.Text = ""
                    '' ExecuteQuery("Update Product_Master Set Product_DeliveryPeriod = '" & txtDispatchIn.Text & "', Product_DeliveryPeriodType = '" & ddlDispatchIn.SelectedItem.Value & "',Product_ClientIP='" & Request.UserHostAddress & "', Product_UserId='" & RemoveLiterals(Session("g_User")) & "' where product_Kid = '" & RemoveLiterals(Session("ProductID").ToString()) & "'")
                    ExecuteQuery("update Product_Master set Product_UserId='" & RemoveLiterals(Session("g_User").ToString) & "' where Product_SupplierID = '" & Session("SupplierID").ToString & "' and Product_Kid = '" & Session("ProductID").ToString() & "'and Product_IsDeleted = '0' ")
                    Dim cmd As New SqlCommand                                                       'Define command variable to execute the query
                    cmd.CommandType = CommandType.StoredProcedure                                   'Set the Command Type to Stored procedure
                    cmd.CommandText = "JJProduct_Master_Proc"                                        'Assign the Name of Stored Procedure, to Execute
                    cmd.Connection = con                                                            'Assign the connection
                    cmd.Parameters.Add(New SqlParameter("@Product_Kid", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Session("ProductID").ToString())
                    cmd.Parameters.Add(New SqlParameter("@Product_ClientIp", SqlDbType.NVarChar, 50)).Value = Request.UserHostAddress
                    cmd.Parameters.Add(New SqlParameter("@Product_Field1", SqlDbType.NVarChar, 100)).Value = "Product_DeliveryPeriod"
                    cmd.Parameters.Add(New SqlParameter("@Product_Value1", SqlDbType.NVarChar, 200)).Value = txtDispatchIn.Text
                    cmd.Parameters.Add(New SqlParameter("@Product_Field2", SqlDbType.NVarChar, 100)).Value = "Product_DeliveryPeriodType"
                    cmd.Parameters.Add(New SqlParameter("@Product_Value2", SqlDbType.NVarChar, 10)).Value = RemoveLiterals(ddlDispatchIn.SelectedItem.Value)
                    cmd.Parameters.Add(New SqlParameter("@mode", SqlDbType.VarChar, 50)).Value = "update"                                   'Add Parameter Mode and assign the DML Operation to Execute 
                    If (con.State = ConnectionState.Closed) Then
                        con.Open()
                    End If
                    cmd.ExecuteNonQuery()


                    System.Threading.Thread.Sleep(500)
                    lblDispatchIN.Text = ReturnValue("Select Product_DeliveryPeriod from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'") & "  " & ddlDispatchIn.SelectedItem.Text
                    txtDispatchIn.Visible = False
                    lnkDispatchIN.Visible = False
                    ddlDispatchIn.Visible = False
                    If lnkDispatchIN.Text = "Update" Then
                        lnkDispatchIN.Visible = True
                        lblDispatchIN.Visible = True
                        txtDispatchIn.Visible = False
                        ddlDispatchIn.Visible = False
                        lnkDispatchIN.Text = "Edit"
                    End If
                    If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                        lnkDispatchIN.Text = "Edit"
                        lnkDispatchIN.Visible = True
                    End If
                Else
                    lblError.Visible = True
                End If
            End If
        Catch ex As Exception
            '  Response.Output.Write("Server error: " & ex.Message.ToString.ToUpperInvariant())
        End Try
    End Sub
    Protected Sub lnkWeight_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkWeight.Click
        Try
            If Val(txtWeight.Text) >= 0 Then
                lblCatError.Visible = False
            Else
                CreateMessageAlert(Me, "Shipping weight must be greater than zero.", "StrKeyVal")
                lblCatError.Visible = True
                lblCatError.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Shipping weight must be greater than zero."
                Exit Sub
            End If

            If lnkWeight.Text = "Edit" Then
                txtWeight.Visible = True
                lblWeight.Visible = False
                txtWeight.Text = ReturnValue("Select Product_Weight from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
                ddlWeightUnit.Visible = True
                Try
                    ddlWeightUnit.ClearSelection()
                    ddlWeightUnit.Items.FindByValue(ReturnValue("Select Product_WeightUnitId from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")).Selected = True
                Catch ex As Exception
                    ddlWeightUnit.ClearSelection()
                End Try
                lnkWeight.Text = "Update"
            Else
                If lblProductName.Text <> "" Then
                    lblWeight.Text = ""
                    '' ExecuteQuery("Update Product_Master Set Product_Weight = '" & txtWeight.Text & "', Product_WeightUnitId = '" & ddlWeightUnit.SelectedItem.Value & "',Product_ClientIP='" & Request.UserHostAddress & "', Product_UserId='" & RemoveLiterals(Session("g_User")) & "'  where product_Kid = '" & RemoveLiterals(Session("ProductID").ToString()) & "'")
                    ExecuteQuery("update Product_Master set Product_UserId='" & RemoveLiterals(Session("g_User").ToString) & "' where Product_SupplierID = '" & Session("SupplierID").ToString & "' and Product_Kid = '" & Session("ProductID").ToString() & "'and Product_IsDeleted = '0' ")
                    Dim cmd As New SqlCommand                                                       'Define command variable to execute the query
                    cmd.CommandType = CommandType.StoredProcedure                                   'Set the Command Type to Stored procedure
                    cmd.CommandText = "JJProduct_Master_Proc"                                        'Assign the Name of Stored Procedure, to Execute
                    cmd.Connection = con                                                            'Assign the connection
                    cmd.Parameters.Add(New SqlParameter("@Product_Kid", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Session("ProductID").ToString())
                    cmd.Parameters.Add(New SqlParameter("@Product_ClientIp", SqlDbType.NVarChar, 50)).Value = Request.UserHostAddress
                    cmd.Parameters.Add(New SqlParameter("@Product_Field1", SqlDbType.NVarChar, 100)).Value = "Product_Weight"
                    cmd.Parameters.Add(New SqlParameter("@Product_Value1", SqlDbType.NVarChar, 200)).Value = txtWeight.Text
                    cmd.Parameters.Add(New SqlParameter("@Product_Field2", SqlDbType.NVarChar, 100)).Value = "Product_WeightUnitId"
                    cmd.Parameters.Add(New SqlParameter("@Product_Value2", SqlDbType.NVarChar, 10)).Value = RemoveLiterals(ddlWeightUnit.SelectedItem.Value)
                    cmd.Parameters.Add(New SqlParameter("@mode", SqlDbType.VarChar, 50)).Value = "update"                                   'Add Parameter Mode and assign the DML Operation to Execute 
                    If (con.State = ConnectionState.Closed) Then
                        con.Open()
                    End If
                    cmd.ExecuteNonQuery()


                    System.Threading.Thread.Sleep(500)
                    lblWeight.Text = ReturnValue("Select Product_Weight from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'") & "  " & ddlWeightUnit.SelectedItem.Text
                    txtWeight.Visible = False
                    lnkWeight.Visible = False
                    ddlWeightUnit.Visible = False
                    If lnkWeight.Text = "Update" Then
                        lnkWeight.Visible = True
                        txtWeight.Visible = False
                        lblWeight.Visible = True
                        ddlWeightUnit.Visible = False
                        lnkWeight.Text = "Edit"
                    End If
                    If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                        lnkWeight.Text = "Edit"
                        lnkWeight.Visible = True
                    End If
                Else
                    lblError.Visible = True
                End If
            End If
        Catch ex As Exception
            '  Response.Output.Write("Server error: " & ex.Message.ToString.ToUpperInvariant())
        End Try
    End Sub
    Protected Sub lnkDimension_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkDimension.Click
        Try

            If Val(txtLDimension.Text) >= 0 And Val(txtHDimension.Text) >= 0 And Val(txtWDimention.Text) >= 0 Then
                lblCatError.Visible = False
            Else
                CreateMessageAlert(Me, "Shipping dimension must be greater than zero.", "StrKeyVal")
                lblCatError.Visible = True
                lblCatError.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Shipping dimension must be greater than zero."
                Exit Sub
            End If

            If lnkDimension.Text = "Edit" Then
                Dim str, str1, str2 As String
                str = ReturnValue("Select Product_Dimension from Product_Master Where Product_kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
                Dim i As Integer = InStr(str, "x", CompareMethod.Text)
                str1 = Mid(str, 1, i - 1)
                str = Mid(str, i + 1, Len(str))
                i = InStr(str, "x", CompareMethod.Text)
                str2 = Mid(str, 1, i - 1)
                str = Mid(str, i + 1, Len(str))
                txtLDimension.Text = Val(str1)
                txtHDimension.Text = Val(str2)
                txtWDimention.Text = Val(str)
                txtLDimension.Visible = True
                txtHDimension.Visible = True
                txtWDimention.Visible = True
                ddlDimension.Visible = True
                '  X.Visible = True
                '  XX.Visible = True
                lblDimension.Visible = False
                Try
                    ddlDimension.ClearSelection()
                    'ddlDimension.Items.FindByValue(ReturnValue("Select Product_DimensionUnitId from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")).Selected = True
                    ddlDimension.Items.FindByText("mm").Selected = True
                Catch ex As Exception
                    ddlDimension.ClearSelection()
                End Try
                lnkDimension.Text = "Update"
            Else
                If lblProductName.Text <> "" Then
                    ddlDimension.Items.FindByText("mm").Selected = True
                    lblDimension.Text = ""
                    '    X.Text = ""
                    '    XX.Text = ""

                    '' ExecuteQuery("Update Product_Master Set Product_Dimension = '" & txtLDimension.Text & "X" & txtHDimension.Text & "X" & txtWDimention.Text & "', Product_DimensionUnitId = '" & ddlDimension.SelectedItem.Value & "',Product_ClientIP='" & Request.UserHostAddress & "', Product_UserId='" & RemoveLiterals(Session("g_User")) & "'  where product_Kid = '" & RemoveLiterals(Session("ProductID").ToString()) & "'")
                    ExecuteQuery("update Product_Master set Product_UserId='" & RemoveLiterals(Session("g_User").ToString) & "' where Product_SupplierID = '" & Session("SupplierID").ToString & "' and Product_Kid = '" & Session("ProductID").ToString() & "'and Product_IsDeleted = '0' ")
                    Dim cmd As New SqlCommand                                                       'Define command variable to execute the query
                    cmd.CommandType = CommandType.StoredProcedure                                   'Set the Command Type to Stored procedure
                    cmd.CommandText = "JJProduct_Master_Proc"                                        'Assign the Name of Stored Procedure, to Execute
                    cmd.Connection = con                                                            'Assign the connection
                    cmd.Parameters.Add(New SqlParameter("@Product_Kid", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Session("ProductID").ToString())
                    cmd.Parameters.Add(New SqlParameter("@Product_ClientIp", SqlDbType.NVarChar, 50)).Value = Request.UserHostAddress
                    cmd.Parameters.Add(New SqlParameter("@Product_Field1", SqlDbType.NVarChar, 100)).Value = "Product_Dimension"
                    cmd.Parameters.Add(New SqlParameter("@Product_Value1", SqlDbType.NVarChar, 200)).Value = txtLDimension.Text & "X" & txtHDimension.Text & "X" & txtWDimention.Text
                    cmd.Parameters.Add(New SqlParameter("@Product_Field2", SqlDbType.NVarChar, 100)).Value = "Product_DimensionUnitId"
                    cmd.Parameters.Add(New SqlParameter("@Product_Value2", SqlDbType.NVarChar, 10)).Value = "00001:<"
                    cmd.Parameters.Add(New SqlParameter("@mode", SqlDbType.VarChar, 50)).Value = "update"                                   'Add Parameter Mode and assign the DML Operation to Execute
                    If (con.State = ConnectionState.Closed) Then
                        con.Open()
                    End If
                    cmd.ExecuteNonQuery()


                    System.Threading.Thread.Sleep(500)
                    lblDimension.Text = ReturnValue("Select Product_Dimension from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'") & " " & ddlDimension.SelectedItem.Text

                    txtLDimension.Visible = False
                    txtWDimention.Visible = False
                    txtHDimension.Visible = False
                    lnkDimension.Visible = False
                    ddlDimension.Visible = False
                    If lnkDimension.Text = "Update" Then
                        lnkDimension.Visible = True
                        lblDimension.Visible = True
                        lnkDimension.Text = "Edit"
                    End If

                    If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                        lnkDimension.Text = "Edit"
                        lnkDimension.Visible = True
                    End If

                Else
                    lblError.Visible = True
                End If
            End If
        Catch ex As Exception
            ' Response.Output.Write("Server error: " & ex.Message.ToString.ToUpperInvariant())
        End Try
    End Sub
    Protected Sub lnkProductDescription_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkProductDescription.Click
        Try
            Dim desclower As String
            desclower = StrConv(txtProductDescription.Text.Trim.Replace("'", "''"), VbStrConv.ProperCase)
            If lnkProductDescription.Text = "Edit" Then
                txtProductDescription.Visible = True
                txtProductDescription.Text = tddesc.InnerText
                ' lblProductDescription.Visible = False
                lnkProductDescription.Text = "Update"
                ProductDescTxt.Visible = True
                lblmax.Visible = True
                ProductDescLbl.Visible = False
                Label16.Visible = True
            Else
                If lblProductName.Text <> "" Then
                    tddesc.InnerText = ""
                    'lblProductDescription.Text = ""
                    ' ExecuteQuery("Update Product_Master Set Product_Description = '" & desclower & "',Product_ClientIP='" & Request.UserHostAddress & "', Product_UserId='" & RemoveLiterals(Session("g_User")) & "'  where product_Kid = '" & RemoveLiterals(Session("ProductID").ToString()) & "'")
                    ExecuteQuery("update Product_Master set Product_UserId='" & RemoveLiterals(Session("g_User").ToString) & "' where Product_SupplierID = '" & Session("SupplierID").ToString & "' and Product_Kid = '" & Session("ProductID").ToString() & "'and Product_IsDeleted = '0' ")
                    Dim cmd As New SqlCommand                                                       'Define command variable to execute the query
                    cmd.CommandType = CommandType.StoredProcedure                                   'Set the Command Type to Stored procedure
                    cmd.CommandText = "JJProduct_Master_Proc"                                        'Assign the Name of Stored Procedure, to Execute
                    cmd.Connection = con                                                            'Assign the connection
                    cmd.Parameters.Add(New SqlParameter("@Product_Kid", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Session("ProductID").ToString())
                    cmd.Parameters.Add(New SqlParameter("@Product_ClientIp", SqlDbType.NVarChar, 50)).Value = Request.UserHostAddress
                    cmd.Parameters.Add(New SqlParameter("@Product_Field1", SqlDbType.NVarChar, 100)).Value = "Product_Description"
                    cmd.Parameters.Add(New SqlParameter("@Product_Value1", SqlDbType.NVarChar, 2000)).Value = desclower
                    cmd.Parameters.Add(New SqlParameter("@mode", SqlDbType.VarChar, 50)).Value = "update"                                   'Add Parameter Mode and assign the DML Operation to Execute (Insert)
                    If (con.State = ConnectionState.Closed) Then
                        con.Open()
                    End If
                    cmd.ExecuteNonQuery()

                    System.Threading.Thread.Sleep(1000)
                    tddesc.InnerText = ReturnValue("Select Product_Description from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
                    tddesc.NoWrap = False
                    txtProductDescription.Visible = False
                    lnkProductDescription.Visible = False
                    ProductDescLbl.Visible = True
                    ProductDescTxt.Visible = False
                    lblmax.Visible = False
                    If lnkProductDescription.Text = "Update" Then
                        lnkProductDescription.Visible = True
                        lnkProductDescription.Text = "Edit"
                        ' lblProductDescription.Visible = True
                        Label16.Visible = False
                    End If
                    If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                        lnkProductDescription.Text = "Edit"
                        lnkProductDescription.Visible = True
                        Label16.Visible = False
                    End If
                Else
                    lblError.Visible = True
                End If
            End If
        Catch ex As Exception
            '  Response.Output.Write("Web Server error: " & ex.Message.ToString.ToUpperInvariant())
        End Try
    End Sub
    Public Sub fillcombos()
        Try
            Fill_Combo("SELECT distinct Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = N'Amount' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString() & "' order by unit_name", ddlMarketPriceUnit)
            ddlMarketPriceUnit.Items.FindByText("Rs.").Selected = True
            Fill_Combo("SELECT distinct Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = N'Amount' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString() & "' order by unit_name", ddlAtcoPriceUnit)
            ddlAtcoPriceUnit.Items.FindByText("Rs.").Selected = True
            Fill_Combo("SELECT distinct Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = N'Amount' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString() & "' order by unit_name", ddlShippingChargesUnit)
            ddlShippingChargesUnit.Items.FindByText("Rs.").Selected = True
            Fill_Combo("SELECT distinct Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = N'Qty' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString() & "' order by unit_name", ddlSellQtyUnit)
            ddlSellQtyUnit.Items.FindByText("Pcs").Selected = True
            Fill_Combo("SELECT distinct Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = N'Qty' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString() & "' order by unit_name", ddlShippingQtyUnit)
            ddlShippingQtyUnit.Items.FindByText("Pcs").Selected = True
            Fill_Combo("SELECT distinct Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = N'Days' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString() & "' order by unit_name", ddlDispatchIn)
            ddlDispatchIn.Items.FindByText("Days").Selected = True
            Fill_Combo("SELECT distinct Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = N'Weight' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString() & "' order by unit_name", ddlWeightUnit)
            ddlWeightUnit.Items.FindByText("Kg").Selected = True
            Fill_Combo("SELECT distinct Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = N'Dimension' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString() & "' order by unit_name", ddlDimension)
            ddlDimension.Items.FindByText("mm").Selected = True

            Dim strSupID As String
            strSupID = RemoveLiterals(Session("SupplierID").ToString)
            If strSupID.Contains("[") Then
                strSupID = strSupID.Replace("[", "[[]")
                'ElseIf strSupID.Contains("]") Then
                '    strSupID = strSupID.Replace("]", "[]]")
            End If

            Fill_Combo("Select Brand_Kid, Brand_Name From Brand_Master where Brand_IsDeleted = '0' and Brand_CompanyId like '%" & strSupID & "%'  order by Brand_Name", ddlBrandName)
        Catch ex As Exception
            '  Response.Output.Write("Server error: " & ex.Message.ToString.ToUpperInvariant())
        End Try
    End Sub
    Protected Sub CheckBox2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub
    Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click

        If lblProductName.Text = "" Then
            lblError.Visible = True
            txtProductName.Focus()
            Exit Sub
        ElseIf lblMarketPrice.Text = "" Then
            CreateMessageAlert(Me, "Please enter product price.", "StrKeyVal")
            lblError.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Please enter product price."
            lblError.Visible = True
            txtMarketPrice.Focus()
            Exit Sub

        ElseIf tddesc.InnerText.ToString.Trim = "" Then
            CreateMessageAlert(Me, "Please enter Product Description.", "StrKeyVal")
            lblError.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Please enter Product Description."
            lblError.Visible = True
            txtProductDescription.Focus()
            Exit Sub
            'ElseIf lblAtcoPrice.Text = "" Then
            '    lblError.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Enter Atcomaart Price."
            '    lblError.Visible = True
            '    txtAtcoPrice.Focus()
            '    Exit Sub
        ElseIf Session("ProductID") = Nothing Then
            lblError.Visible = True
            Exit Sub
        Else

            Response.Redirect("product-price.aspx")

        End If
    End Sub
    Protected Sub btnback_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Response.Redirect("List_Product.aspx")
    End Sub


End Class
