Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports ModCommon

Partial Class product_price
    Inherits System.Web.UI.Page
    Shared g_User As String
    Shared g_Company As String
    Shared g_FinYear As String
    Dim strcon As String = ConfigurationSettings.AppSettings.Item("ConnectionString")
    Dim con As New SqlConnection(strcon)
    Shared Product_Kid As String
    Shared FileName As String
    Dim str As String = ""
    Public strPath As String
    Shared CheckFlag As Boolean = False
    Shared Flag As Boolean = False
    Shared gwcode As String
    Shared img As Integer
    Shared Category1(50) As String
    Shared i As Integer
    Shared conn As New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionString"))

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            If Session("SupplierID") Is Nothing And Session("AdminID") = Nothing Then
                Response.Redirect("listproduct.aspx?sess=expire")
                Exit Sub
            End If
           
            If Page.IsPostBack = False Then
                bulkorder1.Visible = False
                Panel2.Visible = False
                i = 0
                ' g_User = Session("g_User").ToString
                ' g_Company = Session("g_Company").ToString
                '  g_FinYear = Session("g_FinYear").ToString

                ' Dim id As String = Session("SupplierID")


                '====Commented as per CRN(Change Request Note) by Atcomaart Team
                ''txtStandardPrice.Attributes.Add("onkeypress", "return CheckNumericValue(event)")
                ''txtMOPrice.Attributes.Add("onkeypress", "return CheckNumericValue(event)")
                ''txtTransferPrice.Attributes.Add("onkeypress", "return CheckNumericValue(event)")
                ''txtSpecialPrice.Attributes.Add("onkeypress", "return CheckNumericValue(event)")
                ''txtBMinOrderQty.Attributes.Add("onkeypress", "return CheckNumericValue(event)")
                ''txtBAtcoPurPrice.Attributes.Add("onkeypress", "return CheckNumericValue(event)")
                ''txtBAtcoMaartPrice.Attributes.Add("onkeypress", "return CheckNumericValue(event)")
                txtPackagingCharge.Attributes.Add("onkeypress", "return CheckNumericValue(event)")


                isAccess.Visible = False
                If Session("SupplierID") Is Nothing Then
                    Response.Redirect("listproduct.aspx")
                    Exit Sub
                Else

                    GetExisting()
                    GetExisting1()
                    PageLoadFillBOPGrid()
                    isAccess.Visible = True
                    trwear.Visible = False

                End If

                'g_User = "000008I"
                'g_Company = "00006Z4"
                'g_FinYear = "000010N"

                DDLFill()
                If Session("ProductId") Is Nothing Then
                    Response.Redirect("Product-Information.aspx")
                    Exit Sub
                Else
                    'Product_Kid = Session("ProductID").ToString.Trim
                End If

            End If
            bulkorder1.Visible = False
            Panel2.Visible = False
            Label17.Visible = False
            lblBulkError.Visible = False


        Catch
        End Try
    End Sub

    Public Sub GetExisting()
        Try
            If Not Session("ProductId") Is Nothing Then
                Try
                    Dim dt As Data.DataTable
                    Dim strMarket As String
                    If Session("ProductID") Is Nothing AndAlso Session("ProductId") Is Nothing Then
                        Response.Redirect("List_Product.aspx")
                        Exit Sub
                    End If
                    Try
                        If Session("ProductID") <> Nothing Then
                            '    dt = getTable("select * from product_master where product_kid='" & Session("ProductId") & "'", "PRD")
                            '    LabelV4.Text = createheaderlabel(Session("ProductId"))
                            '    Product_Kid = Session("ProductId")
                            'Else
                            dt = getTable("select Product_Kid, Product_Code, Product_Name, Product_Description, Product_BrandId, Product_SupplierId, Product_CategoryId, Product_ModelNo,Product_Image, Product_MarketPrice, Product_MarketPriceType, Product_AtcoPrice, Product_AtcoPriceType, Product_Dimension, Product_DimensionUnitId, Product_MinOrderQty, Product_MinOrderQtyType, Product_ShippingQty, Product_ShippingQtyType, Product_PcsPerKg,Product_Weight,Product_WeightUnitId ,Product_DeliveryPeriod, Product_DeliveryPeriodType from product_master where product_kid='" & Session("ProductID") & "' and Product_Isdeleted='0'", "PRD")
                            createheaderlabel(dt.Rows(0).Item("Product_CategoryId").ToString)

                            'Product_Kid = Session("ProductID")
                        End If
                    Catch
                    End Try

                    Try
                        Image5.ImageUrl = "~\Upload Image\Product Image\UploadImages\" & dt.Rows(0)("Product_Image").ToString
                        Dim imgpath As String
                        imgpath = Server.MapPath(Image5.ImageUrl)
                        KeepAspectRatioNew(Image5, imgpath, 241, 202)

                    Catch
                    End Try
                    ' KeepAspectRatio(Image3, 228, 150)
                    lblprodcode.Text = dt.Rows(0)("Product_Code").ToString
                    'txtProductName.Text = dt.Rows(0)("Product_Name").ToString
                    lblProductName.InnerText = dt.Rows(0)("Product_Name").ToString
                    If IsDBNull(dt.Rows(0)("Product_Description")) Or dt.Rows(0)("Product_Description").ToString = "" Then
                        ProdDesc1.Style.Add("height", "0px")
                        ProdDesc1.Visible = False
                    Else
                        ProdDesc1.Visible = True
                        ProdDesc1.InnerHtml = dt.Rows(0)("Product_Description").ToString()
                        ProdDesc1.NoWrap = False
                    End If
                    Dim brandid As String = dt.Rows(0)("Product_BrandId").ToString()
                    Dim brandname As String = ""
                    Try
                        If brandid <> "" Then
                            brandname = ReturnValue("select Brand_Name from Brand_Master where Brand_Kid='" & brandid & "'")
                        End If
                    Catch
                    End Try
                    LblProductBrand.Text = brandname
                    lblProductMfrNo.Text = dt.Rows(0)("Product_ModelNo").ToString

                    lblProductMarketPrice.Text = chkDBNull(dt.Rows(0)("Product_MarketPrice").ToString)

                    Try
                        strMarket = ReturnValue("select unit_name from unit_master where unit_kid='" & dt.Rows(0)("Product_MarketPriceType").ToString & "' and Unit_IsDeleted ='0'")
                        lblProductMarketPrice.Text = strMarket & " " & lblProductMarketPrice.Text
                    Catch
                    End Try

                    lblProductAtcoPrice.Text = chkDBNull(dt.Rows(0)("Product_AtcoPrice").ToString)
                    Try
                        Dim stratco As String = ReturnValue("select unit_name from unit_master where unit_kid='" & dt.Rows(0)("Product_AtcoPriceType").ToString & "'")
                        lblProductAtcoPrice.Text = stratco & " " & lblProductAtcoPrice.Text
                    Catch
                    End Try

                    'lblProductSpecialPrice.Text &= " " & dt.Rows(0)("Product_SpecialPriceType").ToString
                    lblProductShippingQty.Text = chkNull(dt.Rows(0)("Product_ShippingQty").ToString)
                    strMarket = ReturnValue("select unit_name from unit_master where unit_kid='" & dt.Rows(0)("Product_ShippingQtyType").ToString & "' and Unit_IsDeleted ='0'")
                    lblProductShippingQty.Text &= " " & strMarket
                    lblProductSellQty.Text = chkNull(dt.Rows(0)("Product_MinOrderQty").ToString)
                    strMarket = ReturnValue("select unit_name from unit_master where unit_kid='" & dt.Rows(0)("Product_MinOrderQtyType").ToString & "' and Unit_IsDeleted ='0'")
                    lblProductSellQty.Text &= " " & strMarket
                    lblProductShippingWeight.Text = chkNull(dt.Rows(0)("Product_Weight").ToString)
                    strMarket = ReturnValue("select unit_name from unit_master where unit_kid='" & dt.Rows(0)("Product_WeightUnitId").ToString & "' and Unit_IsDeleted ='0' AND Unit_Flag = 'Weight'")
                    lblProductShippingWeight.Text &= " " & strMarket
                    lblProductShippDimention.Text = chkNull(dt.Rows(0)("Product_Dimension").ToString)
                    strMarket = ReturnValue("select unit_name from unit_master where unit_kid='" & dt.Rows(0)("Product_DimensionUnitId").ToString & "'and Unit_IsDeleted ='0' ")
                    lblProductShippDimention.Text &= " " & strMarket
                    'lblProductPcsPerCarton.Text = ds.Tables(0).Rows(0)("Product_Name").ToString
                    lblProductDispatchIn.Text = chkNull(dt.Rows(0)("Product_DeliveryPeriod").ToString)
                    strMarket = ReturnValue("select unit_name from unit_master where unit_kid='" & dt.Rows(0)("Product_DeliveryPeriodType").ToString & "' and Unit_IsDeleted ='0'")
                    lblProductDispatchIn.Text &= " " & strMarket
                    dt.Clear()
                Catch
                End Try
                '        'If Session("ProductID") Is Nothing Then
                '        '    Response.Redirect("List_Product.aspx")
                '        '    Exit Sub
                '        'End If
                '        Dim dt As DataTable = ReturnDataTable("Select Product_Name,Product_Code,Product_Image,Product_CategoryId,Product_MarketPrice,Product_MarketPriceType,Product_AtcoPrice,Product_AtcoPriceType,Product_BrandId,Product_ModelNo From Product_Master Where Product_SupplierID = '" & Session("SupplierID").ToString & "'and Product_Kid = '" & Session("ProductId").ToString.Trim & "'and Product_IsDeleted = '0'")
                '        If dt.Rows.Count > 0 Then
                '            'lblCat.Text = ""
                '            FillCategoryName(RemoveLiterals(dt.Rows(0).Item("Product_CategoryId").ToString.Trim))

                '            Try
                '                If IsDBNull(dt.Rows(0).Item("Product_Image")) Or dt.Rows(0).Item("Product_Image").ToString = "" Then
                '                Else
                '                    Image5.ImageUrl = "~/Upload Image/Product Image/UploadImages/" & dt.Rows(0).Item("Product_Image").ToString()
                '                    Dim imgpath As String
                '                    imgpath = Server.MapPath(Image5.ImageUrl)
                '                    KeepAspectRatioNew(Image5, imgpath, 150, 150)
                '                End If
                '            Catch
                '            End Try

                '            Try
                '                If IsDBNull(dt.Rows(0).Item("Product_Code")) Or dt.Rows(0).Item("Product_Code").ToString = "" Then
                '                Else
                '                    Label9.Text = dt.Rows(0).Item("Product_Code").ToString()
                '                End If
                '            Catch
                '            End Try

                '            If IsDBNull(dt.Rows(0).Item("Product_Name")) Or dt.Rows(0).Item("Product_Name").ToString = "" Then
                '            Else
                '                Label12.Text = dt.Rows(0).Item("Product_Name").ToString()
                '            End If


                '            If IsDBNull(dt.Rows(0).Item("Product_MarketPriceType")) Or dt.Rows(0).Item("Product_MarketPriceType").ToString = "" Then
                '            Else
                '                Try
                '                    Label13.Text = ReturnValue("Select Unit_Name from Unit_Master where Unit_Kid ='" & dt.Rows(0).Item("Product_MarketPriceType").ToString() & "'and Unit_Flag='Amount' and Unit_IsDeleted ='0'")
                '                Catch
                '                End Try

                '            End If

                '            If IsDBNull(dt.Rows(0).Item("Product_MarketPrice")) Or dt.Rows(0).Item("Product_MarketPrice").ToString = "" Then
                '            Else
                '                Label13.Text += "  " & dt.Rows(0).Item("Product_MarketPrice").ToString()

                '            End If

                '            If IsDBNull(dt.Rows(0).Item("Product_AtcoPriceType")) Or dt.Rows(0).Item("Product_AtcoPriceType").ToString = "" Then
                '            Else
                '                Try

                '                    Label14.Text = ReturnValue("Select Unit_Name from Unit_Master where Unit_Kid ='" & dt.Rows(0).Item("Product_AtcoPriceType").ToString() & "'and Unit_Flag='Amount' and Unit_IsDeleted ='0'")

                '                Catch
                '                End Try
                '            End If


                '            If IsDBNull(dt.Rows(0).Item("Product_AtcoPrice")) Or dt.Rows(0).Item("Product_AtcoPrice").ToString = "" Then
                '            Else
                '                Label14.Text += "  " & dt.Rows(0).Item("Product_AtcoPrice").ToString()
                '            End If

                '            If IsDBNull(dt.Rows(0).Item("Product_BrandId")) Or dt.Rows(0).Item("Product_BrandId").ToString = "" Then
                '            Else
                '                Try
                '                    Label15.Text = ReturnValue("Select Brand_Name from Brand_Master where Brand_Kid ='" & dt.Rows(0).Item("Product_BrandId").ToString() & "'and Brand_IsDeleted ='0'")

                '                Catch ex As Exception
                '                End Try
                '            End If

                '            If IsDBNull(dt.Rows(0).Item("Product_ModelNo")) Or dt.Rows(0).Item("Product_ModelNo").ToString = "" Then

                '            Else
                '                Label16.Text = dt.Rows(0).Item("Product_ModelNo").ToString()

                '            End If

                '        End If
                '        dt.Clear()
                '    Else
                '        Response.Redirect("List_Product.aspx")
            End If
        Catch
        End Try

    End Sub
    Protected Sub createheaderlabel(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
                        LabelV4.Visible = True
                        LabelV4.Text += Category(i)
                        i = i - 1
                    Next
                    Exit Sub
                Else
                    Category(i) = dt.Rows(0).Item(2).ToString() & "  >  "
                    i = i + 1

                    createheaderlabel(dt.Rows(0).Item(3).ToString())
                End If
            Else
                LabelV4.Text = ""
                LabelV4.Visible = False
            End If
            dt.Clear()
        Catch ex As Exception
            ' Response.Output.Write("Server error: " & ex.Message.ToString.ToUpperInvariant())
        End Try
    End Sub
    Public Sub GetExisting1()

        Standard.Visible = False
        MarketOperating.Visible = False
        AtcoPurchase.Visible = False
        SpecialPrice.Visible = False

        Try

            Dim dt As DataTable = ReturnDataTable("Select Product_Image,Product_StandardPrice,Product_StandardPriceType,Product_PackagingCharge,Product_PackagingChargeType,Product_MOPrice,Product_MOPriceType,Product_TransferPrice,Product_TransferPriceType,Product_SpecialPrice,Product_SpecialPriceType,Product_PcsPerKg,Product_IsSpareParts,Product_IsWear_Tear,Product_IsAssc From Product_Master Where Product_SupplierID = '" & Session("SupplierID").ToString & "'and Product_Kid = '" & Session("ProductId").ToString.Trim & "'and Product_IsDeleted = '0'")

            If dt.Rows.Count > 0 Then

                ''Try
                ''    If IsDBNull(dt.Rows(0).Item("Product_Image")) Or dt.Rows(0).Item("Product_Image").ToString = "" Then
                ''    Else
                ''        Image5.ImageUrl = "~/Upload Image/Product Image/UploadImages/" & dt.Rows(0).Item("Product_Image").ToString()
                ''    End If
                ''Catch
                ''End Try
                ''====Commented as per CRN(Change Request Note) by Atcomaart Team
                ''Try
                ''    If IsDBNull(dt.Rows(0).Item("Product_StandardPriceType")) Or dt.Rows(0).Item("Product_StandardPriceType").ToString = "" Then
                ''        If Session("AdminID") = Nothing And lblStandardPrice.Text <> "" Then
                ''            ddlStandardPriceType.Visible = False
                ''        Else
                ''            If txtStandardPrice.Visible = True Then
                ''                btnStandardPrice.Enabled = True
                ''                btnStandardPrice.Visible = True
                ''                ddlStandardPriceType.Visible = True
                ''            Else
                ''                ddlStandardPriceType.Visible = True
                ''            End If
                ''        End If
                ''    Else
                ''        ddlStandardPriceType.ClearSelection()
                ''        txtStandardPrice.Visible = False
                ''        lblStandardPrice.Text = ""
                ''        lblStandardPrice.Text = ReturnValue("Select Unit_Name from Unit_Master where Unit_Kid ='" & dt.Rows(0).Item("Product_StandardPriceType").ToString() & "'and Unit_Flag='Amount' and Unit_IsDeleted ='0'")
                ''        btnStandardPrice.Visible = False
                ''        ddlStandardPriceType.Visible = False
                ''        If Session("AdminID") <> Nothing or Session("AdminID") = Nothing Then
                ''            btnStandardPrice.Visible = True
                ''            btnStandardPrice.Enabled = True
                ''            btnStandardPrice.Text = "Edit"
                ''        End If
                ''    End If
                ''Catch ex As Exception
                ''    ddlStandardPriceType.ClearSelection()
                ''End Try

                ''Try
                ''    If IsDBNull(dt.Rows(0).Item("Product_StandardPrice")) Or dt.Rows(0).Item("Product_StandardPrice").ToString = "" Then
                ''        If Session("AdminID") <> Nothing Then
                ''            btnStandardPrice.Enabled = True
                ''            btnStandardPrice.Visible = True
                ''            ''    txtProductDescription.Text = dt.Rows(0).Item("Product_Description").ToString()
                ''        Else
                ''            btnStandardPrice.Enabled = True
                ''            btnStandardPrice.Visible = True
                ''            txtStandardPrice.Visible = True
                ''        End If
                ''    Else

                ''        txtStandardPrice.Visible = False
                ''        lblStandardPrice.Text += "  " & dt.Rows(0).Item("Product_StandardPrice").ToString()
                ''        txtStandardPrice.Text = dt.Rows(0).Item("Product_StandardPrice").ToString()
                ''        btnStandardPrice.Visible = False
                ''        'ImageButton4.Visible = False
                ''        If Session("AdminID") <> Nothing Then
                ''            ImageButton4.Visible = True
                ''            btnStandardPrice.Visible = True
                ''            btnStandardPrice.Enabled = True
                ''            btnStandardPrice.Text = "Edit"
                ''        End If
                ''        'End If
                ''    End If
                ''Catch
                ''End Try
                ''Try
                ''    If IsDBNull(dt.Rows(0).Item("Product_MOPriceType")) Or dt.Rows(0).Item("Product_MOPriceType").ToString = "" Then
                ''        If Session("AdminID") = Nothing And lblMOPrice.Text <> "" Then
                ''            ddlMOPriceType.Visible = False
                ''        Else
                ''            If txtMOPrice.Visible = True Then
                ''                ddlMOPriceType.Visible = True
                ''            Else
                ''                ddlMOPriceType.Visible = False
                ''            End If
                ''        End If
                ''    Else
                ''        ddlMOPriceType.ClearSelection()
                ''        txtMOPrice.Visible = False
                ''        lblMOPrice.Text = ReturnValue("Select Unit_Name from Unit_Master where Unit_Kid ='" & dt.Rows(0).Item("Product_MOPriceType").ToString() & "'and Unit_Flag='Amount' and Unit_IsDeleted ='0'")
                ''        btnMOPrice.Visible = False
                ''        ddlMOPriceType.Visible = False
                ''        If Session("AdminID") <> Nothing Then
                ''            btnMOPrice.Visible = True
                ''            btnMOPrice.Text = "Edit"
                ''        End If
                ''    End If
                ''Catch ex As Exception
                ''    ddlMOPriceType.ClearSelection()
                ''End Try
                ''Try
                ''    If IsDBNull(dt.Rows(0).Item("Product_MOPrice")) Or dt.Rows(0).Item("Product_MOPrice").ToString = "" Then
                ''        If Session("AdminID") <> Nothing Then

                ''        Else
                ''            txtMOPrice.Visible = True
                ''        End If
                ''    Else

                ''        txtMOPrice.Visible = False
                ''        lblMOPrice.Text += " " & dt.Rows(0).Item("Product_MOPrice").ToString()
                ''        txtMOPrice.Text = dt.Rows(0).Item("Product_MOPrice").ToString()
                ''        btnMOPrice.Visible = False
                ''        ' ImageButton5.Visible = False
                ''        If Session("AdminID") <> Nothing Then
                ''            ImageButton5.Visible = True
                ''            btnMOPrice.Visible = True
                ''            btnMOPrice.Text = "Edit"
                ''        End If
                ''        'End If
                ''    End If
                ''Catch
                ''End Try

                ''Try
                ''    If IsDBNull(dt.Rows(0).Item("Product_TransferPriceType")) Or dt.Rows(0).Item("Product_TransferPriceType").ToString = "" Then
                ''        If Session("AdminID") = Nothing And lblTransferPrice.Text <> "" Then
                ''            ddlTransferPriceType.Visible = False
                ''        Else
                ''            If txtTransferPrice.Visible = True Then
                ''                ddlTransferPriceType.Visible = True
                ''            Else
                ''                ddlTransferPriceType.Visible = False
                ''            End If
                ''        End If
                ''    Else
                ''        ddlTransferPriceType.ClearSelection()
                ''        txtTransferPrice.Visible = False
                ''        lblTransferPrice.Text = ReturnValue("Select Unit_Name from Unit_Master where Unit_Kid ='" & dt.Rows(0).Item("Product_TransferPriceType").ToString() & "'and Unit_Flag='Amount' and Unit_IsDeleted ='0'")
                ''        btnTransferPrice.Visible = False
                ''        ddlTransferPriceType.Visible = False
                ''        If Session("AdminID") <> Nothing Then
                ''            btnTransferPrice.Visible = True
                ''            btnTransferPrice.Text = "Edit"
                ''        End If
                ''    End If
                ''Catch ex As Exception
                ''    ddlTransferPriceType.ClearSelection()
                ''End Try

                ''Try
                ''    If IsDBNull(dt.Rows(0).Item("Product_TransferPrice")) Or dt.Rows(0).Item("Product_TransferPrice").ToString = "" Then
                ''        If Session("AdminID") <> Nothing Then
                ''            ' btnTransferPrice.Visible = True
                ''            '  btnTransferPrice.Text = "Edit"
                ''        Else
                ''            txtTransferPrice.Visible = True
                ''        End If
                ''    Else
                ''        'If Session("AdminID") <> Nothing Then
                ''        '    txtProductDescription.Text = dt.Rows(0).Item("Product_Description").ToString()
                ''        'Else
                ''        txtTransferPrice.Visible = False
                ''        lblTransferPrice.Text += " " & dt.Rows(0).Item("Product_TransferPrice").ToString()
                ''        txtTransferPrice.Text = dt.Rows(0).Item("Product_TransferPrice").ToString()
                ''        btnTransferPrice.Visible = False
                ''        '  ImageButton7.Visible = False
                ''        'ProductDescLbl.Visible = True
                ''        'ProductDescTxt.Visible = False
                ''        If Session("AdminID") <> Nothing Then
                ''            ImageButton7.Visible = True
                ''            btnTransferPrice.Visible = True
                ''            btnTransferPrice.Text = "Edit"
                ''        End If
                ''        'End If
                ''    End If
                ''Catch
                ''End Try

                ''Try
                ''    If IsDBNull(dt.Rows(0).Item("Product_SpecialPriceType")) Or dt.Rows(0).Item("Product_SpecialPriceType").ToString = "" Then
                ''        If Session("AdminID") = Nothing And lblSpecialPrice.Text <> "" Then
                ''            ddlSpecialPriceType.Visible = False
                ''        Else
                ''            If txtSpecialPrice.Visible = True Then
                ''                ddlSpecialPriceType.Visible = True
                ''            Else
                ''                ddlSpecialPriceType.Visible = False
                ''            End If
                ''        End If
                ''    Else
                ''        ddlSpecialPriceType.ClearSelection()
                ''        txtSpecialPrice.Visible = False
                ''        lblSpecialPrice.Text = ReturnValue("Select Unit_Name from Unit_Master where Unit_Kid ='" & dt.Rows(0).Item("Product_SpecialPriceType").ToString() & "'and Unit_Flag='Amount' and Unit_IsDeleted ='0'")
                ''        btnSpecialPrice.Visible = False
                ''        ddlSpecialPriceType.Visible = False
                ''        If Session("AdminID") <> Nothing Then
                ''            btnSpecialPrice.Visible = True
                ''            btnSpecialPrice.Text = "Edit"
                ''        End If
                ''    End If
                ''Catch ex As Exception
                ''    ddlSpecialPriceType.ClearSelection()
                ''End Try


                ''Try
                ''    If IsDBNull(dt.Rows(0).Item("Product_SpecialPrice")) Or dt.Rows(0).Item("Product_SpecialPrice").ToString = "" Then
                ''        If Session("AdminID") <> Nothing Then
                ''        Else
                ''            txtSpecialPrice.Visible = True
                ''            ddlSpecialPriceType.Visible = True
                ''        End If
                ''    Else
                ''        txtSpecialPrice.Visible = False
                ''        lblSpecialPrice.Text += " " & dt.Rows(0).Item("Product_SpecialPrice").ToString()
                ''        txtSpecialPrice.Text = dt.Rows(0).Item("Product_SpecialPrice").ToString()
                ''        btnSpecialPrice.Visible = False
                ''        ' ImageButton8.Visible = False
                ''        ddlSpecialPriceType.Visible = False
                ''        If Session("AdminID") <> Nothing Then
                ''            ImageButton8.Visible = True
                ''            btnSpecialPrice.Visible = True
                ''            btnSpecialPrice.Text = "Edit"
                ''        End If
                ''        'End If
                ''    End If
                ''Catch
                ''End Try



                Try
                    If IsDBNull(dt.Rows(0).Item("Product_PackagingChargeType")) Or dt.Rows(0).Item("Product_PackagingChargeType").ToString = "" Then
                        
                        If Session("AdminID") = Nothing And lblPackagingCharge.Text <> "" Then
                            ddlPackagingCharge.Visible = False
                        Else
                            If txtPackagingCharge.Visible = True Then
                                ddlPackagingCharge.Visible = True
                            Else
                                ddlPackagingCharge.Visible = False
                            End If
                        End If
                    Else
                        ddlPackagingCharge.ClearSelection()
                        txtPackagingCharge.Visible = False
                        lblPackagingCharge.Text = ReturnValue("Select Unit_Name from Unit_Master where Unit_Kid ='" & dt.Rows(0).Item("Product_PackagingChargeType").ToString() & "'and Unit_Flag='Amount' and Unit_IsDeleted ='0'")
                        lnkPackagingCharge.Visible = False
                        ddlPackagingCharge.Visible = False
                        If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                            lnkPackagingCharge.Visible = True
                            lnkPackagingCharge.Text = "Edit"
                        End If
                    End If
                Catch ex As Exception
                    ddlPackagingCharge.ClearSelection()
                End Try


                Try
                    If IsDBNull(dt.Rows(0).Item("Product_PackagingCharge")) Or dt.Rows(0).Item("Product_PackagingCharge").ToString = "" Then
                        rdopackagingType.Enabled = True
                        rdopackagingType.SelectedValue = 1

                        'lblpercent.Visible = True
                        ddlPackagingCharge.Visible = False

                        If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                        Else
                            txtPackagingCharge.Visible = True
                            ddlPackagingCharge.Visible = True
                        End If
                    Else
                        Dim marketp As String = ReturnValue("select Product_MarketPrice from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
                        Dim marketprice As Double = CType(marketp, Double)

                        rdopackagingType.Enabled = False
                        If IsDBNull(dt.Rows(0).Item("Product_PackagingChargeType")) Or dt.Rows(0).Item("Product_PackagingChargeType").ToString = "" Then
                            rdopackagingType.SelectedValue = 1
                            lblCalculatePackCharge.Text = "( " & (100 * CType(dt.Rows(0).Item("Product_PackagingCharge").ToString(), Double)) / marketp & "% )"
                            lblPackagingCharge.Text = "Rs. " & dt.Rows(0).Item("Product_PackagingCharge").ToString()

                            'lblpercent.Visible = True
                        Else
                            rdopackagingType.SelectedValue = 2
                            lblpercent.Visible = False
                            lblPackagingCharge.Text += " " & dt.Rows(0).Item("Product_PackagingCharge").ToString()

                        End If

                        rdopackagingType.Enabled = False
                        txtPackagingCharge.Visible = False
                        txtPackagingCharge.Text = dt.Rows(0).Item("Product_PackagingCharge").ToString()
                        lnkPackagingCharge.Visible = False
                        lblpercent.Visible = False
                        ' ImageButton8.Visible = False
                        ddlPackagingCharge.Visible = False
                        If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                            Image4.Visible = True
                            lnkPackagingCharge.Visible = True
                            lnkPackagingCharge.Text = "Edit"
                        End If
                        'End If
                    End If
                Catch
                End Try

                Try
                    If IsDBNull(dt.Rows(0).Item("Product_PcsPerKg")) Or dt.Rows(0).Item("Product_PcsPerKg").ToString = "" Then
                        ImageButton14.Visible = True
                        btnPcs.Visible = True
                        btnPcs.Text = "Save"
                    Else

                        txtPcs.Visible = False
                        lblPcs.Text = dt.Rows(0).Item("Product_PcsPerKg").ToString()
                        txtPcs.Text = dt.Rows(0).Item("Product_PcsPerKg").ToString()
                        btnPcs.Visible = False
                        ' ImageButton14.Visible = False
                        If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                            ImageButton14.Visible = True
                            btnPcs.Visible = True
                            btnPcs.Text = "Edit"
                        End If
                        'End If
                    End If
                Catch
                End Try

                Try
                    If IsDBNull(dt.Rows(0).Item("Product_IsSpareParts")) Or dt.Rows(0).Item("Product_IsSpareParts").ToString = "" Then
                        rdoSparePart.Items.FindByValue("N").Selected = True
                        isAccess.Visible = False
                        rdoAccessories.Enabled = True
                        btnAccessories.Enabled = True
                        rdoAccessories.Items.FindByValue("N").Selected = True
                        Label26.Text = ""
                        Label26.Visible = False
                    Else
                        rdoSparePart.Visible = False
                        btnSparePart.Visible = False
                        If dt.Rows(0).Item("Product_IsSpareParts").ToString = "Y" Then
                            Label26.Visible = True
                            Label26.Text = "Yes"
                            isAccess.Visible = True
                            rdoAccessories.ClearSelection()
                            rdoAccessories.Enabled = False
                            btnAccessories.Enabled = False
                        ElseIf dt.Rows(0).Item("Product_IsSpareParts").ToString = "N" Then
                            Label26.Visible = True
                            Label26.Text = "No"
                            isAccess.Visible = False
                            rdoAccessories.Enabled = True
                            btnAccessories.Enabled = True
                        End If

                        If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                            btnSparePart.Visible = True
                            btnSparePart.Text = "Edit"
                        End If

                    End If


                Catch
                End Try


                Try
                    If IsDBNull(dt.Rows(0).Item("Product_IsWear_Tear")) Or dt.Rows(0).Item("Product_IsWear_Tear").ToString = "" Then
                        rdoWearTear.Visible = True
                        rdoWearTear.ClearSelection()
                        rdoWearTear.Items.FindByValue("N").Selected = True
                        Label27.Text = ""
                        Label27.Visible = False
                    Else
                        rdoWearTear.Visible = False
                        btnWearTear.Visible = False
                        If dt.Rows(0).Item("Product_IsWear_Tear").ToString = "Y" Then
                            Label27.Visible = True
                            Label27.Text = "Yes"
                        ElseIf dt.Rows(0).Item("Product_IsWear_Tear").ToString = "N" Then
                            Label27.Visible = True
                            Label27.Text = "No"

                        End If

                        If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                            btnWearTear.Visible = True
                            btnWearTear.Text = "Edit"
                        End If

                    End If
                Catch
                End Try

                Try
                    If IsDBNull(dt.Rows(0).Item("Product_IsAssc")) Or dt.Rows(0).Item("Product_IsAssc").ToString = "" Then
                        rdoAccessories.ClearSelection()
                        rdoAccessories.Items.FindByValue("N").Selected = True
                        Label28.Text = ""
                        Label28.Visible = False
                    Else
                        rdoAccessories.Visible = False
                        btnAccessories.Visible = False
                        If dt.Rows(0).Item("Product_IsAssc").ToString = "Y" Then
                            Label28.Visible = True
                            Label28.Text = "Yes"
                        ElseIf dt.Rows(0).Item("Product_IsAssc").ToString = "N" Then
                            Label28.Visible = True
                            Label28.Text = "No"
                        End If

                        If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                            btnAccessories.Visible = True
                            btnAccessories.Text = "Edit"
                        End If

                    End If
                Catch
                End Try





                Try
                    dt.Clear()
                    dt = getTable("select Keyword_Name from Product_Keyword where Keyword_ProductId='" & Session("ProductID").ToString.Trim & "'", "PK")
                    If dt.Rows.Count <> 0 Then
                        If IsDBNull(dt.Rows(0).Item("Keyword_Name")) Or dt.Rows(0).Item("Keyword_Name").ToString = "" Then
                        Else
                            txtKeyword.Visible = False
                            lblKeyword.Text = dt.Rows(0).Item("Keyword_Name").ToString()
                            txtKeyword.Text = dt.Rows(0).Item("Keyword_Name").ToString()
                            btnKeyword.Visible = False
                            ' ImageButton22.Visible = False
                            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                                ImageButton22.Visible = True
                                btnKeyword.Visible = True
                                btnKeyword.Text = "Edit"
                            End If
                        End If
                    End If
                Catch
                End Try

            End If
            dt.Clear()


        Catch ex As Exception
        End Try
    End Sub
    'Public Sub FillCategoryName(ByVal Catid As String)
    '    Dim dt As DataTable
    '    dt = ReturnDataTable("Select * From Category_Master Where Category_Kid ='" & Catid & "' and Category_Isdeleted = '0' and Category_CompanyId ='" & Session("g_Company").ToString & "'")
    '    If dt.Rows.Count > 0 Then
    '        Dim ParentId As String
    '        ParentId = dt.Rows(0).Item(3).ToString()
    '        If ParentId = "Root Category" Then
    '            'Label1.Text += dt.Rows(0).Item(2).ToString()
    '            'Dim CategoryName(10) As String
    '            Dim j As Integer
    '            Category1(i) = dt.Rows(0).Item(2).ToString() & "  >  "
    '            'Array.Reverse(Category)
    '            For j = 0 To i
    '                lblCat.Text += Category1(i)
    '                i = i - 1
    '            Next
    '            Exit Sub
    '        Else
    '            Category1(i) = dt.Rows(0).Item(2).ToString() & "  >  "
    '            i = i + 1
    '            'Label1.Text += dt.Rows(0).Item(2).ToString() & "  >  "
    '            FillCategoryName(dt.Rows(0).Item(3).ToString())
    '        End If

    '    Else
    '        lblCat.Text = ""
    '        lblCat.Visible = False
    '    End If
    '    dt.Clear()

    '    'GridView1.DataSource = dt
    '    'GridView1.DataBind()
    'End Sub
    Public Sub DDLFill()
        ''====Commented as per CRN(Change Request Note) by Atcomaart Team
        ''Try
        ''    Fill_Combo("SELECT Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = 'Amount' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString & "' order by unit_name", ddlStandardPriceType)
        ''    ddlStandardPriceType.ClearSelection()
        ''    ddlStandardPriceType.Items.FindByText("Rs.").Selected = True
        ''Catch
        ''End Try
        ''Try
        ''    Fill_Combo("SELECT Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = 'Amount' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString & "' order by unit_name", ddlMOPriceType)
        ''    ddlMOPriceType.ClearSelection()
        ''    ddlMOPriceType.Items.FindByText("Rs.").Selected = True
        ''Catch
        ''End Try
        ''Try
        ''    Fill_Combo("SELECT Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = 'Amount' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString & "' order by unit_name", ddlSpecialPriceType)
        ''    ddlSpecialPriceType.ClearSelection()
        ''    ddlSpecialPriceType.Items.FindByText("Rs.").Selected = True
        ''Catch
        ''End Try
        ''Try
        ''    Fill_Combo("SELECT Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = 'Amount' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString & "' order by unit_name", ddlTransferPriceType)
        ''    ddlTransferPriceType.ClearSelection()
        ''    ddlTransferPriceType.Items.FindByText("Rs.").Selected = True
        ''Catch
        ''End Try
        'Try
        '    Fill_Combo("SELECT Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = 'Qty' and unit_IsDeleted='0' and unit_CompanyId = '" & g_Company & "' order by unit_name", ddlMinOrderQtyType)
        '    ddlMinOrderQtyType.ClearSelection()
        '    ddlMinOrderQtyType.Items.FindByText("Pcs").Selected = True
        'Catch
        'End Try
        'Try
        '    Fill_Combo("SELECT Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = 'Qty' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString & "' order by unit_name", ddlBMinOrderQty)
        '    ddlBMinOrderQty.ClearSelection()
        '    ' ddlBMinOrderQty.Items.FindByText("Pcs").Selected = True
        'Catch
        'End Try
        'Try
        '    Fill_Combo("SELECT Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = 'Amount' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString & "' order by unit_name", ddlBAtcoPurPriceType)
        '    ddlBAtcoPurPriceType.ClearSelection()
        '    ddlBAtcoPurPriceType.Items.FindByText("Rs.").Selected = True
        'Catch
        'End Try
        Try
            Fill_Combo("SELECT Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = 'Amount' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString & "' order by unit_name", ddlPackagingCharge)
            ddlPackagingCharge.ClearSelection()
            ddlPackagingCharge.Items.FindByText("Rs.").Selected = True
        Catch
        End Try
        'Try
        '    Fill_Combo("SELECT Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = 'Amount' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString & "' order by unit_name", ddlBAtcoMaartPriceType)
        '    ddlBAtcoMaartPriceType.ClearSelection()
        '    ddlBAtcoMaartPriceType.Items.FindByText("Rs.").Selected = True
        'Catch
        'End Try
        'Try
        '    Fill_Combo("SELECT Unit_Kid, Unit_Name FROM Unit_Master WHERE Unit_Flag IN ('Qty', 'Dimension', 'Weight') AND Unit_IsDeleted = N'0' order by unit_name", ddlBAtcoPurPriceTypePerUnit)
        '    ddlBAtcoPurPriceTypePerUnit.ClearSelection()
        '    'ddlBAtcoMaartPriceType.Items.FindByText("Rs.").Selected = True
        'Catch
        'End Try
        'Try
        '    Fill_Combo("SELECT Unit_Kid, Unit_Name FROM Unit_Master WHERE Unit_Flag IN ('Qty', 'Dimension', 'Weight') AND Unit_IsDeleted = N'0' order by unit_name", ddlBAtcoMaartPriceTypePerUnit)
        '    ddlBAtcoMaartPriceTypePerUnit.ClearSelection()
        '    'ddlBAtcoMaartPriceType.Items.FindByText("Rs.").Selected = True
        'Catch
        'End Try


    End Sub


    Protected Sub btnStandardPrice_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            'Dim dt1 As DataTable = ReturnDataTable("SELECT Product_AtcoPrice FROM Product_Master WHERE Product_IsDeleted = N'0' And Product_Kid = '" & Session("ProductId").ToString() & "'")

            'Dim atcomaartPrice As Integer = Val(dt1.Rows(0).Item("Product_AtcoPrice").ToString)
            'If atcomaartPrice > Val(txtStandardPrice.Text) Then
            '    Label17.Visible = False
            'Else
            '    Label17.Visible = True
            '    Label17.Text = "Standard Price must be less than Atcomaart price."
            '    Exit Sub
            'End If

            If Val(txtStandardPrice.Text) < 0 Then
                showmessage("<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Standard Price must be greater than zero.", Label17)
                Exit Sub
            End If

            If txtStandardPrice.Visible = True Then
                If Not IsDBNull(txtStandardPrice.Text) Or txtStandardPrice.Text <> "" Then
                    Dim dt As DataTable = ReturnDataTable("Select Product_MarketPrice,Product_MOPrice,Product_AtcoPrice From Product_Master Where Product_SupplierID = '" & Session("SupplierID").ToString & "'and Product_Kid = '" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")
                    Dim MarketPrice As Double = CType(dt.Rows(0).Item("Product_MarketPrice").ToString, Double)
                    Dim AtcoPrice As Double = CType(dt.Rows(0).Item("Product_AtcoPrice").ToString, Double)
                    If Not IsDBNull(dt.Rows(0).Item("Product_MOPrice")) Or dt.Rows(0).Item("Product_MOPrice").ToString <> "" Then
                        Dim MOPrice As Double = CType(dt.Rows(0).Item("Product_MOPrice").ToString, Double)
                        Dim StandardPrice As Double = CType(txtStandardPrice.Text.ToString, Double)
                        If MarketPrice > StandardPrice And MOPrice < StandardPrice And AtcoPrice < StandardPrice Then
                            Label17.Text = ""
                            Label17.Visible = False
                        Else
                            Label17.Visible = True
                            Label17.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Standard price must be less than market price and greater than market operating price and Atcomaart Price."
                            Exit Sub
                        End If
                    Else
                        Dim StandardPrice As Double = CType(txtStandardPrice.Text.ToString, Double)
                        If MarketPrice > StandardPrice And AtcoPrice < StandardPrice Then
                            Label17.Text = ""
                            Label17.Visible = False
                        Else
                            Label17.Visible = True
                            Label17.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Standard price must be less than market price and greater than  Atcomaart Price ."
                            Exit Sub
                        End If
                    End If
                    dt.Clear()
                End If
            End If


            Dim atcoPriceType As String
            atcoPriceType = ReturnValue("select Product_MarketPriceType from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
            If ddlStandardPriceType.Visible = True Then
                If atcoPriceType = ddlStandardPriceType.SelectedValue.ToString Then
                    Label17.Visible = False
                Else
                    Label17.Visible = True
                    Label17.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Standard price type same as market price type."
                    ddlStandardPriceType.Focus()
                    Exit Sub
                End If
            End If

            If btnStandardPrice.Text = "Edit" Then
                txtStandardPrice.Visible = True
                lblStandardPrice.Visible = False
                txtStandardPrice.Text = ReturnValue("Select Product_StandardPrice from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")
                ddlStandardPriceType.Visible = True
                Try
                    ddlStandardPriceType.ClearSelection()
                    ddlStandardPriceType.Items.FindByValue(ReturnValue("Select Product_StandardPriceType from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")).Selected = True
                Catch ex As Exception
                    ddlStandardPriceType.ClearSelection()
                End Try
                btnStandardPrice.Text = "Update"
            Else
                If Session("ProductID") <> Nothing Then
                    lblStandardPrice.Text = ""
                    ExecuteQuery("UPDATE Product_Master SET Product_StandardPrice = '" & txtStandardPrice.Text.ToString.Trim & "', Product_StandardPriceType = '" & ddlStandardPriceType.SelectedItem.Value.ToString.Trim & "',Product_ClientIP='" & Request.UserHostAddress & "' WHERE Product_Kid = '" & Session("ProductID").ToString.Trim & "'")
                    lblStandardPrice.Text = ddlStandardPriceType.SelectedItem.Text & "  " & ReturnValue("Select Product_StandardPrice from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")
                    txtStandardPrice.Visible = False
                    ddlStandardPriceType.Visible = False
                    btnStandardPrice.Visible = False
                    'End If
                    If btnStandardPrice.Text = "Update" Then
                        btnStandardPrice.Visible = True
                        btnStandardPrice.Text = "Edit"
                        lblStandardPrice.Visible = True
                    End If
                    If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                        btnStandardPrice.Visible = True
                        btnStandardPrice.Text = "Edit"
                    End If
                Else
                    'lblError.Visible = True
                End If

            End If

        Catch
        End Try

    End Sub

    Protected Sub btnMOPrice_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        If Val(txtMOPrice.Text) < 0 Then
            showmessage("<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Market Operating Price must be greater than zero.", Label17)
            Exit Sub
        End If

        Try
            If txtMOPrice.Visible = True Then
                If Not IsDBNull(txtMOPrice.Text) Or txtMOPrice.Text <> "" Then
                    Dim dt As DataTable = ReturnDataTable("Select Product_MarketPrice,Product_StandardPrice,Product_AtcoPrice,Product_MOPrice From Product_Master Where Product_SupplierID = '" & Session("SupplierID").ToString & "'and Product_Kid = '" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")
                    If Not IsDBNull(dt.Rows(0).Item("Product_StandardPrice")) Or dt.Rows(0).Item("Product_StandardPrice").ToString <> "" Then
                        Dim StandardPrice As Double = CType(dt.Rows(0).Item("Product_StandardPrice").ToString, Double)
                        Dim AtcoPrice As Double = CType(dt.Rows(0).Item("Product_AtcoPrice").ToString, Double)
                        Dim MOPrice As Double = CType(txtMOPrice.Text.ToString, Double)
                        If StandardPrice > MOPrice And AtcoPrice < MOPrice Then
                            Label17.Text = ""
                            Label17.Visible = False
                        Else
                            Label17.Visible = True
                            Label17.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Market operating price must be less than Standard price and greater than atcomaart price."
                            Exit Sub
                        End If
                    Else
                        Dim MarketPrice As Double = CType(dt.Rows(0).Item("Product_MarketPrice").ToString, Double)
                        Dim AtcoPrice As Double = CType(dt.Rows(0).Item("Product_AtcoPrice").ToString, Double)
                        Dim MOPrice As Double = CType(txtMOPrice.Text.ToString, Double)
                        If MarketPrice > MOPrice And AtcoPrice < MOPrice Then
                            Label17.Text = ""
                            Label17.Visible = False
                        Else
                            Label17.Visible = True
                            Label17.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Market operating price must be less than market price and greater than atcomaart price."
                            Exit Sub
                        End If
                    End If
                    dt.Clear()
                End If
            End If

            Dim atcoPriceType As String
            atcoPriceType = ReturnValue("select Product_MarketPriceType from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
            If ddlMOPriceType.Visible = True Then
                If atcoPriceType = ddlMOPriceType.SelectedValue.ToString Then
                    Label17.Visible = False
                Else
                    Label17.Visible = True
                    Label17.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Market operating price type same as market price type."
                    ddlMOPriceType.Focus()
                    Exit Sub
                End If
            End If


            If btnMOPrice.Text = "Edit" Then
                txtMOPrice.Visible = True
                lblMOPrice.Visible = False
                txtMOPrice.Text = ReturnValue("Select Product_MOPrice from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")
                ddlMOPriceType.Visible = True
                Try
                    ddlMOPriceType.ClearSelection()
                    ddlMOPriceType.Items.FindByValue(ReturnValue("Select Product_MOPriceType from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")).Selected = True
                Catch ex As Exception
                    ddlMOPriceType.ClearSelection()
                End Try
                btnMOPrice.Text = "Update"
            Else
                If Session("ProductID") <> Nothing Then
                    lblMOPrice.Text = ""
                    ExecuteQuery("UPDATE Product_Master SET Product_MOPrice = '" & txtMOPrice.Text.ToString.Trim & "', Product_MOPriceType = '" & ddlMOPriceType.SelectedItem.Value.ToString.Trim & "',Product_ClientIP='" & Request.UserHostAddress & "' WHERE Product_Kid = '" & Session("ProductID").ToString.Trim & "'")
                    lblMOPrice.Text = ddlMOPriceType.SelectedItem.Text & "  " & ReturnValue("Select Product_MOPrice from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")
                    txtMOPrice.Visible = False
                    ddlMOPriceType.Visible = False
                    btnMOPrice.Visible = False
                    'End If
                    If btnMOPrice.Text = "Update" Then
                        btnMOPrice.Visible = True
                        btnMOPrice.Text = "Edit"
                        lblMOPrice.Visible = True
                    End If
                    If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                        btnMOPrice.Visible = True
                        btnMOPrice.Text = "Edit"
                    End If
                Else
                    'lblError.Visible = True
                End If

            End If

        Catch
        End Try
    End Sub

    Protected Sub btnTransferPrice_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        If Val(txtTransferPrice.Text) < 0 Then
            showmessage("<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Atco Purchase Price must be greater than zero.", Label17)
            Exit Sub
        End If

        Try
            If txtTransferPrice.Visible = True Then
                If Not IsDBNull(txtTransferPrice.Text) Or txtTransferPrice.Text <> "" Then
                    Dim dt As DataTable = ReturnDataTable("Select * From Product_Master Where Product_SupplierID = '" & Session("SupplierID").ToString & "'and Product_Kid = '" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")
                    Dim AtcoPrice As Double = CType(dt.Rows(0).Item("Product_AtcoPrice").ToString, Double)
                    If Not IsDBNull(dt.Rows(0).Item("Product_SpecialPrice")) Or dt.Rows(0).Item("Product_SpecialPrice").ToString <> "" Then
                        Dim SpecialPrice As Double = CType(dt.Rows(0).Item("Product_SpecialPrice").ToString, Double)
                        Dim TransferPrice As Double = CType(txtTransferPrice.Text.ToString, Double)
                        If AtcoPrice > TransferPrice And SpecialPrice < TransferPrice Then
                            Label17.Text = ""
                            Label17.Visible = False
                        Else
                            Label17.Visible = True
                            Label17.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Atcomaart Purchaes price must be less than atcomaart price and greater than special price."
                            Exit Sub
                        End If
                    Else
                        Dim TransferPrice As Double = CType(txtTransferPrice.Text.ToString, Double)
                        If AtcoPrice > TransferPrice Then
                            Label17.Text = ""
                            Label17.Visible = False
                        Else
                            Label17.Visible = True
                            Label17.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Atcomaart Purchase price must be less than atcomaart price ."
                            Exit Sub
                        End If
                    End If
                    dt.Clear()
                End If
            End If

            Dim atcoPriceType As String
            atcoPriceType = ReturnValue("select Product_MarketPriceType from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
            If ddlTransferPriceType.Visible = True Then
                If atcoPriceType = ddlTransferPriceType.SelectedValue.ToString Then
                    Label17.Visible = False
                Else
                    Label17.Visible = True
                    Label17.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Atcomaart Purchase price type same as market price type."
                    ddlTransferPriceType.Focus()
                    Exit Sub
                End If
            End If


            If btnTransferPrice.Text = "Edit" Then
                txtTransferPrice.Visible = True
                lblTransferPrice.Visible = False
                txtTransferPrice.Text = ReturnValue("Select Product_TransferPrice from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")
                ddlTransferPriceType.Visible = True
                Try
                    ddlTransferPriceType.ClearSelection()
                    ddlTransferPriceType.Items.FindByValue(ReturnValue("Select Product_TransferPriceType from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")).Selected = True
                Catch ex As Exception
                    ddlTransferPriceType.ClearSelection()
                End Try
                btnTransferPrice.Text = "Update"
            Else
                If Session("ProductID") <> Nothing Then
                    lblTransferPrice.Text = ""
                    ExecuteQuery("UPDATE Product_Master SET Product_TransferPrice = '" & txtTransferPrice.Text.ToString.Trim & "', Product_TransferPriceType = '" & ddlTransferPriceType.SelectedItem.Value.ToString.Trim & "',Product_ClientIP='" & Request.UserHostAddress & "' WHERE Product_Kid = '" & Session("ProductID").ToString.Trim & "'")
                    lblTransferPrice.Text = ddlTransferPriceType.SelectedItem.Text & "  " & txtTransferPrice.Text
                    txtTransferPrice.Visible = False
                    ddlTransferPriceType.Visible = False
                    btnTransferPrice.Visible = False
                    'End If
                    If btnTransferPrice.Text = "Update" Then
                        btnTransferPrice.Visible = True
                        btnTransferPrice.Text = "Edit"
                        lblTransferPrice.Visible = True
                    End If
                    If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                        btnTransferPrice.Visible = True
                        btnTransferPrice.Text = "Edit"
                    End If
                Else
                    'lblError.Visible = True
                End If

            End If

        Catch
        End Try
    End Sub

    Protected Sub btnSpecialPrice_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSpecialPrice.Click

        If Val(txtSpecialPrice.Text) < 0 Then
            showmessage("<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Special Price must be greater than zero.", Label17)
            Exit Sub
        End If


        Try
            If txtSpecialPrice.Visible = True Then
                If Not IsDBNull(txtSpecialPrice.Text) Or txtSpecialPrice.Text <> "" Then
                    Dim dt As DataTable = ReturnDataTable("Select * From Product_Master Where Product_SupplierID = '" & Session("SupplierID").ToString & "'and Product_Kid = '" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")
                    If Not IsDBNull(dt.Rows(0).Item("Product_TransferPrice")) Or dt.Rows(0).Item("Product_TransferPrice").ToString <> "" Then
                        Dim TransferPrice As Double = CType(dt.Rows(0).Item("Product_TransferPrice").ToString, Double)
                        Dim SpecialPrice As Double = CType(txtSpecialPrice.Text.ToString, Double)
                        If TransferPrice > SpecialPrice Then
                            Label17.Text = ""
                            Label17.Visible = False
                        Else
                            Label17.Visible = True
                            Label17.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Special price must be less than transfer price."
                            Exit Sub
                        End If
                    Else
                        Dim AtcoPrice As Double = CType(dt.Rows(0).Item("Product_AtcoPrice").ToString, Double)
                        Dim SpecialPrice As Double = CType(txtSpecialPrice.Text.ToString, Double)
                        If AtcoPrice > SpecialPrice Then
                            Label17.Text = ""
                            Label17.Visible = False
                        Else
                            Label17.Visible = True
                            Label17.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Special price must be less than atcomaart price."
                            Exit Sub
                        End If
                    End If
                    dt.Clear()
                End If
            End If

            Dim atcoPriceType As String
            atcoPriceType = ReturnValue("select Product_MarketPriceType from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
            If ddlSpecialPriceType.Visible = True Then
                If atcoPriceType = ddlSpecialPriceType.SelectedValue.ToString Then
                    Label17.Visible = False
                Else
                    Label17.Visible = True
                    Label17.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Special price type same as market price type."
                    ddlSpecialPriceType.Focus()
                    Exit Sub
                End If
            End If





            If btnSpecialPrice.Text = "Edit" Then
                txtSpecialPrice.Visible = True
                lblSpecialPrice.Visible = False
                txtSpecialPrice.Text = ReturnValue("Select Product_SpecialPrice from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")
                ddlSpecialPriceType.Visible = True
                Try
                    ddlSpecialPriceType.ClearSelection()
                    ddlSpecialPriceType.Items.FindByValue(ReturnValue("Select Product_SpecialPriceType from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")).Selected = True
                Catch ex As Exception
                    ddlSpecialPriceType.ClearSelection()
                End Try
                btnSpecialPrice.Text = "Update"
            Else
                If Session("ProductID") <> Nothing Then
                    lblSpecialPrice.Text = ""
                    ExecuteQuery("UPDATE Product_Master SET Product_SpecialPrice = '" & txtSpecialPrice.Text.ToString.Trim & "', Product_SpecialPriceType = '" & ddlSpecialPriceType.SelectedItem.Value.ToString.Trim & "',Product_ClientIP='" & Request.UserHostAddress & "' WHERE Product_Kid = '" & Session("ProductID").ToString.Trim & "'")
                    lblSpecialPrice.Text = ddlSpecialPriceType.SelectedItem.Text & "  " & txtSpecialPrice.Text
                    txtSpecialPrice.Visible = False
                    ddlSpecialPriceType.Visible = False
                    btnSpecialPrice.Visible = False
                    'End If
                    If btnSpecialPrice.Text = "Update" Then
                        btnSpecialPrice.Visible = True
                        btnSpecialPrice.Text = "Edit"
                        lblSpecialPrice.Visible = True
                    End If
                    If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                        btnSpecialPrice.Visible = True
                        btnSpecialPrice.Text = "Edit"
                    End If
                Else
                    'lblError.Visible = True
                End If

            End If

        Catch
        End Try
    End Sub

    Protected Sub btnMinOrderQty_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub

    Protected Sub btnPcs_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        If Val(txtPcs.Text) < 0 Then
            showmessage("<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Pcs(Per Carton/Pckg) must be greater than zero.", Label17)
            Exit Sub
        End If


        Try
            If txtPcs.Visible = True Then
                If Session("ProductID") <> Nothing Then
                    lblPcs.Text = ""
                    ExecuteQuery("UPDATE Product_Master SET Product_PcsPerKg = '" & txtPcs.Text.ToString.Trim & "',Product_ClientIP='" & Request.UserHostAddress & "' WHERE Product_Kid = '" & Session("ProductID").ToString.Trim & "'")
                    lblPcs.Text = ReturnValue("Select Product_PcsPerKg from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")
                    txtPcs.Visible = False
                    btnPcs.Visible = False
                    'End If
                    If btnPcs.Text = "Update" Then
                        btnPcs.Visible = True
                        btnPcs.Text = "Edit"
                        lblPcs.Visible = True
                    End If
                    If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                        btnPcs.Visible = True
                        btnPcs.Text = "Edit"
                    End If
                Else
                    'lblError.Visible = True
                End If


            Else
                If btnPcs.Text = "Edit" Then
                    txtPcs.Visible = True
                    lblPcs.Visible = False
                    txtPcs.Text = ReturnValue("Select Product_PcsPerKg from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")
                    btnPcs.Text = "Update"
                End If
            End If
        Catch
        End Try
    End Sub

    Protected Sub btnKeyword_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnKeyword.Click
        Try
            If btnKeyword.Text = "Edit" Then
                txtKeyword.Visible = True
                lblKeyword.Visible = False
                txtKeyword.Text = ReturnValue("select Keyword_Name from Product_Keyword where Keyword_ProductId='" & Session("ProductID").ToString.Trim & "'")
                btnKeyword.Text = "Update"
                RequiredFieldValidator4.EnableClientScript = True
            Else
                If Session("ProductID") <> Nothing Then
                    lblKeyword.Text = ""
                    KeywordAdd()
                    lblKeyword.Text = ReturnValue("select Keyword_Name from Product_Keyword where Keyword_ProductId='" & Session("ProductID").ToString.Trim & "'")
                    txtKeyword.Visible = False
                    btnKeyword.Visible = False
                    'End If
                    If btnKeyword.Text = "Update" Then
                        btnKeyword.Visible = True
                        btnKeyword.Text = "Edit"
                        lblKeyword.Visible = True
                    End If
                    If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                        btnKeyword.Visible = True
                        btnKeyword.Text = "Edit"
                        RequiredFieldValidator4.EnableClientScript = False
                    End If
                Else
                    'lblError.Visible = True
                End If

            End If

        Catch
        End Try
    End Sub

    Public Sub KeywordAdd()
        Try
            Dim Keyword_Kid As String
            Keyword_Kid = NewPrimaryKey(Me)
            Dim cmdd As New SqlCommand
            cmdd.CommandText = "Product_Keyword_Proc"    'give a storeprocedure
            cmdd.CommandType = CommandType.StoredProcedure
            cmdd.Connection = con

            'ASSIGN all the parameter that is define in Store Procedure
            cmdd.Parameters.Add(New SqlParameter("Keyword_Kid", SqlDbType.NVarChar, 10)).Value = Trim(Keyword_Kid)
            cmdd.Parameters.Add(New SqlParameter("Keyword_ProductId", SqlDbType.NVarChar, 10)).Value = Trim(Session("ProductID").ToString.Trim)
            cmdd.Parameters.Add(New SqlParameter("Keyword_Name", SqlDbType.NVarChar, 200)).Value = Trim(txtKeyword.Text)
            cmdd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 100)).Value = "Product_Information"                          'Add Parameter FormName and assign the name of form to it
            cmdd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.NVarChar, 20)).Value = "Insert"
            con.Open()
            cmdd.ExecuteNonQuery()
            con.Close()
            con.Dispose()
        Catch
        End Try
    End Sub

    'Public Function NewPrimaryKey1(ByVal aspxpage As System.Web.UI.UserControl) As String
    '    NewPrimaryKey1 = ""
    '    Try
    '        Dim mycon As New SqlConnection()
    '        mycon.ConnectionString = ConfigurationManager.AppSettings("ConnectionString")     'Read the ConnectionString from web.config File
    '        mycon.Open()
    '        Dim myCommand As New SqlCommand("New_Kid", mycon)
    '        myCommand.CommandType = CommandType.StoredProcedure
    '        Dim retValParam As New SqlParameter("@sKey", SqlDbType.Char, 7)
    '        retValParam.Direction = ParameterDirection.Output
    '        retValParam.IsNullable = True
    '        retValParam.Size = 7
    '        myCommand.Parameters.Add(retValParam)
    '        Dim reader As SqlDataReader = myCommand.ExecuteReader()
    '        NewPrimaryKey1 = retValParam.Value.ToString

    '        myCommand.Dispose()
    '        If Not reader.IsClosed Then reader.Close()
    '        If mycon.State = ConnectionState.Open Then mycon.Close()

    '    Catch Ex As Exception
    '        'CreateMessageAlert(Me, Ex.Message, "StrKeyVal")
    '        NewPrimaryKey1 = ""
    '    End Try
    'End Function


    Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
        Response.Redirect("Product_TechnicalInformation.aspx")
    End Sub

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try

            If Val(txtBMinOrderQty.Text) <= 0 Then
                showmessage("Minimum order quantity must be greater than zero.", lblBulkError)
                Exit Sub
            End If


            If Val(txtBAtcoPurPrice.Text) <= 0 Then
                showmessage("Atco purchase price must be greater than zero.", lblBulkError)
                Exit Sub
            End If

            If Val(txtBAtcoMaartPrice.Text) <= 0 Then
                showmessage("AtcoMaart price must be greater than zero.", lblBulkError)
                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 atcoPriceType = ddlBAtcoPurPriceType.SelectedValue.ToString Then
                lblBulkError.Visible = False
            Else
                lblBulkError.Visible = True
                lblBulkError.Text = "Atco purchase price same as market price type."
                ddlBAtcoPurPriceType.Focus()
                Exit Sub
            End If

            atcoPriceType = ReturnValue("select Product_MarketPriceType from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
            If atcoPriceType = ddlBAtcoMaartPriceType.SelectedValue.ToString Then
                lblBulkError.Visible = False
            Else
                lblBulkError.Visible = True
                lblBulkError.Text = "AtcoMaart price same as market price type."
                ddlBAtcoMaartPriceType.Focus()
                Exit Sub
            End If



            Dim con As New SqlConnection
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
            Dim cmd As New SqlCommand
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "BulkOrderPrices_Proc"                                        'Assign the Name of Stored Procedure, to Execute
            cmd.Connection = con
            cmd.Parameters.Add(New SqlParameter("@BOP_Kid", SqlDbType.NVarChar, 10)).Value = NewPrimaryKey(Me)
            cmd.Parameters.Add(New SqlParameter("@BOP_Code", SqlDbType.NVarChar, 25)).Value = Generate_Code("Select count(*) from BulkOrderPrices where ProdApp_Code='", "BOP")
            cmd.Parameters.Add(New SqlParameter("@BOP_ProductID", SqlDbType.NVarChar, 10)).Value = Session("ProductId")
            cmd.Parameters.Add(New SqlParameter("@BOP_MinOrderQty", SqlDbType.NVarChar, 10)).Value = txtBMinOrderQty.Text.ToString.Trim
            cmd.Parameters.Add(New SqlParameter("@BOP_MinOrderQtyType", SqlDbType.NVarChar, 10)).Value = ddlBMinOrderQty.SelectedItem.Value.ToString.Trim
            cmd.Parameters.Add(New SqlParameter("@BOP_AtcoPurchasePrice", SqlDbType.Decimal, 18)).Value = Convert.ToDecimal(txtBAtcoPurPrice.Text.ToString.Trim)
            cmd.Parameters.Add(New SqlParameter("@BOP_AtcoPurchasePriceType", SqlDbType.NVarChar, 10)).Value = ddlBAtcoPurPriceType.SelectedItem.Value.ToString.Trim
            cmd.Parameters.Add(New SqlParameter("@BOP_AtcoPurchasePriceTypePerUnit", SqlDbType.NVarChar, 10)).Value = ddlBAtcoPurPriceTypePerUnit.SelectedItem.Value.ToString.Trim
            cmd.Parameters.Add(New SqlParameter("@BOP_AtcoMaartPrice", SqlDbType.Decimal, 18)).Value = Convert.ToDecimal(txtBAtcoMaartPrice.Text.ToString.Trim)
            cmd.Parameters.Add(New SqlParameter("@BOP_AtcoMaartPriceType", SqlDbType.NVarChar, 10)).Value = ddlBAtcoMaartPriceType.SelectedItem.Value.ToString.Trim
            cmd.Parameters.Add(New SqlParameter("@BOP_AtcoMaartPriceTypePerUnit", SqlDbType.NVarChar, 10)).Value = ddlBAtcoMaartPriceTypePerUnit.SelectedItem.Value.ToString.Trim
            cmd.Parameters.Add(New SqlParameter("@BOP_FinancialYearId", SqlDbType.NVarChar, 10)).Value = Session("g_FinYear").ToString
            cmd.Parameters.Add(New SqlParameter("@BOP_CompanyId", SqlDbType.NVarChar, 10)).Value = Trim(Session("g_Company").ToString)
            cmd.Parameters.Add(New SqlParameter("@BOP_UserId", SqlDbType.NVarChar, 10)).Value = Trim(Session("g_User"))
            cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 50)).Value = "Bulk Order Prices"
            cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 50)).Value = "Insert"

            con.Open()
            cmd.ExecuteNonQuery()
            con.Close()
            ClearBulkOrderPricesFields()
            EnableBulkOrderText(False)
            'Tr1.Visible = False
            'Tr2.Visible = True
            FillBOPGrid()
        Catch ex As Exception
        End Try
    End Sub
    Public Sub EnableBulkOrderText(ByVal Action As Boolean)
        txtBAtcoMaartPrice.Enabled = Action
        txtBAtcoPurPrice.Enabled = Action
        txtBMinOrderQty.Enabled = Action
        ddlBAtcoMaartPriceType.Enabled = Action
        ddlBAtcoMaartPriceTypePerUnit.Enabled = Action
        ddlBAtcoPurPriceType.Enabled = Action
        ddlBAtcoPurPriceTypePerUnit.Enabled = Action
        ddlBMinOrderQty.Enabled = Action
    End Sub

    Protected Sub btnAddMore_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddMore.Click
        Try
            If AddBulkOrderPrices() = True Then
                ClearBulkOrderPricesFields()
                FillBOPGrid()
                ScriptManager2.SetFocus(txtBMinOrderQty)
                'Tr2.Visible = True
                'getPACode()
            End If
        Catch
        End Try
    End Sub

    Public Sub PageLoadFillBOPGrid()
        Try


            Dim myCon As New SqlConnection(ConfigurationManager.AppSettings("ConnectionString"))
            Dim myDataSet As DataSet = New DataSet
            Dim myCommandText As String = "SELECT * FROM BulkOrderPrices Where BulkOrderPrices.BOP_ProductID = '" & Session("ProductId").Trim & "' AND BulkOrderPrices.BOP_IsDeleted = '0'"
            Dim myCommand As SqlCommand = New SqlCommand(myCommandText, myCon)
            Dim myAdapter As SqlDataAdapter = New SqlDataAdapter()
            myAdapter.SelectCommand = myCommand
            myCon.Open()
            myAdapter.Fill(myDataSet, "BulkOrderPrices")
            Dim i As Integer = myDataSet.Tables(0).Rows.Count
            If i > 0 Then
                gvBOP.DataSource = myDataSet.Tables(0).DefaultView
                gvBOP.DataBind()
                getGridTable()
                'Tr1.Visible = False
            Else
                Label25.Visible = False
                'Tr1.Visible = True
                'Tr2.Visible = False
                EnableBulkOrderText(True)
                ClearBulkOrderPricesFields()
            End If
            myDataSet.Clear()
            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                gvBOP.Columns(0).Visible = True
                'Tr1.Visible = True
                'Tr2.Visible = True
                EnableBulkOrderText(True)
                ClearBulkOrderPricesFields()
                btnUpdate.Visible = True
            Else
                gvBOP.Columns(0).Visible = False
                btnUpdate.Visible = False
            End If

            If myCon.State = ConnectionState.Open Then myCon.Close()
            myCon = Nothing
            myCommand = Nothing

        Catch
        End Try
    End Sub

    Public Sub FillBOPGrid()
        Try


            Dim myCon As New SqlConnection(ConfigurationManager.AppSettings("ConnectionString"))
            Dim myDataSet As DataSet = New DataSet
            Dim myCommandText As String = "SELECT * FROM BulkOrderPrices Where BulkOrderPrices.BOP_ProductID = '" & Session("ProductId").Trim & "' AND BulkOrderPrices.BOP_IsDeleted = '0'"
            Dim myCommand As SqlCommand = New SqlCommand(myCommandText, myCon)
            Dim myAdapter As SqlDataAdapter = New SqlDataAdapter()
            myAdapter.SelectCommand = myCommand
            myCon.Open()
            myAdapter.Fill(myDataSet)
            gvBOP.DataSource = myDataSet
            gvBOP.DataBind()
            getGridTable()
            myDataSet.Clear()
            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                gvBOP.Columns(0).Visible = True
                'Tr1.Visible = True
                'Tr2.Visible = True
                EnableBulkOrderText(True)
                ClearBulkOrderPricesFields()
            Else
                gvBOP.Columns(0).Visible = False
            End If

            If myCon.State = ConnectionState.Open Then myCon.Close()
            myCon = Nothing
            myCommand = Nothing

        Catch
        End Try
    End Sub

    Public Sub getGridTable()
        Try
            Dim sql As String = "SELECT * FROM BulkOrderPrices Where BulkOrderPrices.BOP_ProductID = '" & Session("ProductId").Trim & "' AND BulkOrderPrices.BOP_IsDeleted = '0'"
            Dim dt As DataTable = getTable(sql, "BOP")
            If dt.Rows.Count > 0 Then
                Dim strVal As String
                Dim i As Integer
                For i = 0 To dt.Rows.Count - 1
                    Label25.Visible = True
                    Try
                        strVal = dt.Rows(i)("BOP_MinOrderQtyType").ToString
                        strVal = ReturnValue("SELECT DISTINCT Unit_Name FROM Unit_Master WHERE Unit_Kid = '" & strVal & "'")
                        CType(gvBOP.Rows(i).FindControl("Label22"), Label).Text = dt.Rows(i)("BOP_MinOrderQty").ToString & " " & strVal
                    Catch
                    End Try

                    Try
                        strVal = dt.Rows(i)("BOP_AtcoPurchasePriceType").ToString
                        strVal = ReturnValue("SELECT DISTINCT Unit_Name FROM Unit_Master WHERE Unit_Kid = '" & strVal & "'")
                        CType(gvBOP.Rows(i).FindControl("Label23"), Label).Text = dt.Rows(i)("BOP_AtcoPurchasePrice").ToString & " " & strVal
                        strVal = dt.Rows(i)("BOP_AtcoPurchasePriceTypePerUnit").ToString
                        strVal = ReturnValue("SELECT DISTINCT Unit_Name FROM Unit_Master WHERE Unit_Kid = '" & strVal & "'")
                        CType(gvBOP.Rows(i).FindControl("Label23"), Label).Text &= "/" & strVal
                    Catch
                    End Try

                    Try
                        strVal = dt.Rows(i)("BOP_AtcoMaartPriceType").ToString
                        strVal = ReturnValue("SELECT DISTINCT Unit_Name FROM Unit_Master WHERE Unit_Kid = '" & strVal & "'")
                        CType(gvBOP.Rows(i).FindControl("Label24"), Label).Text = dt.Rows(i)("BOP_AtcoMaartPrice").ToString & " " & strVal
                        strVal = dt.Rows(i)("BOP_AtcoMaartPriceTypePerUnit").ToString
                        strVal = ReturnValue("SELECT DISTINCT Unit_Name FROM Unit_Master WHERE Unit_Kid = '" & strVal & "'")
                        CType(gvBOP.Rows(i).FindControl("Label24"), Label).Text &= "/" & strVal
                    Catch
                    End Try

                Next
            Else
                Label25.Visible = False
            End If
            dt.Clear()
        Catch
        End Try

    End Sub



    Public Sub ClearBulkOrderPricesFields()
        txtBAtcoMaartPrice.Text = ""
        txtBAtcoPurPrice.Text = ""
        txtBMinOrderQty.Text = ""
        Try
            Fill_Combo("SELECT Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = 'Qty' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString & "' order by unit_name", ddlBMinOrderQty)
            ddlBMinOrderQty.ClearSelection()
            'ddlBMinOrderQty.Items.FindByText("Pcs").Selected = True
        Catch
        End Try
        Try
            Fill_Combo("SELECT Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = 'Amount' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString & "' order by unit_name", ddlBAtcoPurPriceType)
            ddlBAtcoPurPriceType.ClearSelection()
            ddlBAtcoPurPriceType.Items.FindByText("Rs.").Selected = True
        Catch
        End Try
        Try
            Fill_Combo("SELECT Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = 'Amount' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString & "' order by unit_name", ddlBAtcoMaartPriceType)
            ddlBAtcoMaartPriceType.ClearSelection()
            ddlBAtcoMaartPriceType.Items.FindByText("Rs.").Selected = True
        Catch
        End Try
        Try
            Fill_Combo("SELECT Unit_Kid, Unit_Name FROM Unit_Master WHERE Unit_Flag IN ('Qty', 'Dimension', 'Weight') AND Unit_IsDeleted = N'0' order by unit_name", ddlBAtcoPurPriceTypePerUnit)
            ddlBAtcoPurPriceTypePerUnit.ClearSelection()
            'ddlBAtcoMaartPriceType.Items.FindByText("Rs.").Selected = True
        Catch
        End Try
        Try
            Fill_Combo("SELECT Unit_Kid, Unit_Name FROM Unit_Master WHERE Unit_Flag IN ('Qty', 'Dimension', 'Weight') AND Unit_IsDeleted = N'0' order by unit_name", ddlBAtcoMaartPriceTypePerUnit)
            ddlBAtcoMaartPriceTypePerUnit.ClearSelection()
            'ddlBAtcoMaartPriceType.Items.FindByText("Rs.").Selected = True
        Catch
        End Try
    End Sub

    Private Function AddBulkOrderPrices() As Boolean
        Try
            If Val(txtBMinOrderQty.Text) < 0 Then
                showmessage("Minimum order quantity must be greater than zero.", lblBulkError)
                Exit Function
            End If


            If Val(txtBAtcoPurPrice.Text) < 0 Then
                showmessage("Atco purchase price must be greater than zero.", lblBulkError)
                Exit Function
            End If

            If Val(txtBAtcoMaartPrice.Text) < 0 Then
                showmessage("AtcoMaart price must be greater than zero.", lblBulkError)
                Exit Function
            End If


            Dim atcoPriceType As String
            atcoPriceType = ReturnValue("select Product_MarketPriceType from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
            If atcoPriceType = ddlBAtcoPurPriceType.SelectedValue.ToString Then
                lblBulkError.Visible = False
            Else
                lblBulkError.Visible = True
                lblBulkError.Text = "Atco purchase price type same as market price type."
                ddlBAtcoPurPriceType.Focus()
                Exit Function
            End If

            atcoPriceType = ReturnValue("select Product_MarketPriceType from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
            If atcoPriceType = ddlBAtcoMaartPriceType.SelectedValue.ToString Then
                lblBulkError.Visible = False
            Else
                lblBulkError.Visible = True
                lblBulkError.Text = "AtcoMaart price type same as market price type."
                ddlBAtcoMaartPriceType.Focus()
                Exit Function
            End If


            Dim con As New SqlConnection
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
            Dim cmd As New SqlCommand
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "BulkOrderPrices_Proc"                                        'Assign the Name of Stored Procedure, to Execute
            cmd.Connection = con
            cmd.Parameters.Add(New SqlParameter("@BOP_Kid", SqlDbType.NVarChar, 10)).Value = NewPrimaryKey(Me)
            cmd.Parameters.Add(New SqlParameter("@BOP_Code", SqlDbType.NVarChar, 25)).Value = Generate_Code("Select count(*) from BulkOrderPrices where ProdApp_Code='", "BOP")
            cmd.Parameters.Add(New SqlParameter("@BOP_ProductID", SqlDbType.NVarChar, 10)).Value = Session("ProductId")
            cmd.Parameters.Add(New SqlParameter("@BOP_MinOrderQty", SqlDbType.NVarChar, 10)).Value = txtBMinOrderQty.Text.ToString.Trim
            cmd.Parameters.Add(New SqlParameter("@BOP_MinOrderQtyType", SqlDbType.NVarChar, 10)).Value = ddlBMinOrderQty.SelectedItem.Value.ToString.Trim
            cmd.Parameters.Add(New SqlParameter("@BOP_AtcoPurchasePrice", SqlDbType.Decimal, 18)).Value = Convert.ToDecimal(txtBAtcoPurPrice.Text.ToString.Trim)
            cmd.Parameters.Add(New SqlParameter("@BOP_AtcoPurchasePriceType", SqlDbType.NVarChar, 10)).Value = ddlBAtcoPurPriceType.SelectedItem.Value.ToString.Trim
            cmd.Parameters.Add(New SqlParameter("@BOP_AtcoPurchasePriceTypePerUnit", SqlDbType.NVarChar, 10)).Value = ddlBAtcoPurPriceTypePerUnit.SelectedItem.Value.ToString.Trim
            cmd.Parameters.Add(New SqlParameter("@BOP_AtcoMaartPrice", SqlDbType.Decimal, 18)).Value = Convert.ToDecimal(txtBAtcoMaartPrice.Text.ToString.Trim)
            cmd.Parameters.Add(New SqlParameter("@BOP_AtcoMaartPriceType", SqlDbType.NVarChar, 10)).Value = ddlBAtcoMaartPriceType.SelectedItem.Value.ToString.Trim
            cmd.Parameters.Add(New SqlParameter("@BOP_AtcoMaartPriceTypePerUnit", SqlDbType.NVarChar, 10)).Value = ddlBAtcoMaartPriceTypePerUnit.SelectedItem.Value.ToString.Trim
            cmd.Parameters.Add(New SqlParameter("@BOP_FinancialYearId", SqlDbType.NVarChar, 10)).Value = Session("g_FinYear").ToString
            cmd.Parameters.Add(New SqlParameter("@BOP_CompanyId", SqlDbType.NVarChar, 10)).Value = Trim(Session("g_Company").ToString)
            cmd.Parameters.Add(New SqlParameter("@BOP_UserId", SqlDbType.NVarChar, 10)).Value = Trim(Session("g_User"))
            cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 50)).Value = "Bulk Order Prices"
            cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 50)).Value = "Insert"

            con.Open()
            cmd.ExecuteNonQuery()
            con.Close()
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function


    Protected Sub gvBOP_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvBOP.PageIndexChanging
        gvBOP.PageIndex = e.NewPageIndex
        FillBOPGrid()
    End Sub

    Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        Try


            If Val(txtBMinOrderQty.Text) <= 0 Then
                showmessage("Minimum order quantity must be greater than zero.", lblBulkError)
                Exit Sub
            End If


            If Val(txtBAtcoPurPrice.Text) <= 0 Then
                showmessage("Atco purchase price must be greater than zero.", lblBulkError)
                Exit Sub
            End If

            If Val(txtBAtcoMaartPrice.Text) <= 0 Then
                showmessage("AtcoMaart price must be greater than zero.", lblBulkError)
                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 ddlBAtcoPurPriceType.Visible = True Then
                If atcoPriceType = ddlBAtcoPurPriceType.SelectedValue.ToString Then
                    lblBulkError.Visible = False
                Else
                    lblBulkError.Visible = True
                    lblBulkError.Text = "Atco purchase price same as market price type."
                    ddlBAtcoPurPriceType.Focus()
                    Exit Sub
                End If
            End If

            atcoPriceType = ReturnValue("select Product_MarketPriceType from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
            If ddlBAtcoMaartPriceType.Visible = True Then
                If atcoPriceType = ddlBAtcoMaartPriceType.SelectedValue.ToString Then
                    lblBulkError.Visible = False
                Else
                    lblBulkError.Visible = True
                    lblBulkError.Text = "AtcoMaart price same as market price type."
                    ddlBAtcoMaartPriceType.Focus()
                    Exit Sub
                End If
            End If


            Dim BOPKid As String = gvBOP.SelectedDataKey.Value.ToString.Trim
            Dim sql As String = "SELECT * FROM BulkOrderPrices Where BOP_Kid = '" & BOPKid.ToString.Trim & "'"
            Dim dt As DataTable = getTable(sql, "BOP")

            Dim con As New SqlConnection
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
            Dim cmd As New SqlCommand
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "BulkOrderPrices_Proc"                                        'Assign the Name of Stored Procedure, to Execute
            cmd.Connection = con
            cmd.Parameters.Add(New SqlParameter("@BOP_Kid", SqlDbType.NVarChar, 10)).Value = BOPKid.ToString.Trim
            cmd.Parameters.Add(New SqlParameter("@BOP_Code", SqlDbType.NVarChar, 25)).Value = dt.Rows(0).Item("BOP_Code").ToString.Trim
            cmd.Parameters.Add(New SqlParameter("@BOP_ProductID", SqlDbType.NVarChar, 10)).Value = Session("ProductId")
            cmd.Parameters.Add(New SqlParameter("@BOP_MinOrderQty", SqlDbType.NVarChar, 10)).Value = txtBMinOrderQty.Text.ToString.Trim
            cmd.Parameters.Add(New SqlParameter("@BOP_MinOrderQtyType", SqlDbType.NVarChar, 10)).Value = ddlBMinOrderQty.SelectedItem.Value.ToString.Trim
            cmd.Parameters.Add(New SqlParameter("@BOP_AtcoPurchasePrice", SqlDbType.Decimal, 18)).Value = Convert.ToDecimal(txtBAtcoPurPrice.Text.ToString.Trim)
            cmd.Parameters.Add(New SqlParameter("@BOP_AtcoPurchasePriceType", SqlDbType.NVarChar, 10)).Value = ddlBAtcoPurPriceType.SelectedItem.Value.ToString.Trim
            cmd.Parameters.Add(New SqlParameter("@BOP_AtcoPurchasePriceTypePerUnit", SqlDbType.NVarChar, 10)).Value = ddlBAtcoPurPriceTypePerUnit.SelectedItem.Value.ToString.Trim
            cmd.Parameters.Add(New SqlParameter("@BOP_AtcoMaartPrice", SqlDbType.Decimal, 18)).Value = Convert.ToDecimal(txtBAtcoMaartPrice.Text.ToString.Trim)
            cmd.Parameters.Add(New SqlParameter("@BOP_AtcoMaartPriceType", SqlDbType.NVarChar, 10)).Value = ddlBAtcoMaartPriceType.SelectedItem.Value.ToString.Trim
            cmd.Parameters.Add(New SqlParameter("@BOP_AtcoMaartPriceTypePerUnit", SqlDbType.NVarChar, 10)).Value = ddlBAtcoMaartPriceTypePerUnit.SelectedItem.Value.ToString.Trim
            cmd.Parameters.Add(New SqlParameter("@BOP_FinancialYearId", SqlDbType.NVarChar, 10)).Value = Session("g_FinYear").ToString
            cmd.Parameters.Add(New SqlParameter("@BOP_CompanyId", SqlDbType.NVarChar, 10)).Value = Trim(Session("g_Company").ToString)
            cmd.Parameters.Add(New SqlParameter("@BOP_UserId", SqlDbType.NVarChar, 10)).Value = Trim(Session("g_User"))
            cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 50)).Value = "Bulk Order Prices"
            cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 50)).Value = "Update"

            con.Open()
            cmd.ExecuteNonQuery()
            con.Close()
            ClearBulkOrderPricesFields()
            ScriptManager2.SetFocus(txtBMinOrderQty)
            FillBOPGrid()
            'Tr2.Visible = True
            dt.Clear()
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub gvBOP_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvBOP.SelectedIndexChanged
        Try

            Dim BOPKid As String = gvBOP.SelectedDataKey.Value.ToString.Trim
            Dim sql As String = "SELECT * FROM BulkOrderPrices Where BOP_Kid = '" & BOPKid.ToString.Trim & "'"
            Dim dt As DataTable = getTable(sql, "BOP")

            txtBMinOrderQty.Text = dt.Rows(0).Item("BOP_MinOrderQty").ToString '
            ddlBMinOrderQty.ClearSelection()
            ddlBMinOrderQty.Items.FindByValue(dt.Rows(0).Item("BOP_MinOrderQtyType").ToString).Selected = True
            txtBAtcoPurPrice.Text = dt.Rows(0).Item("BOP_AtcoPurchasePrice").ToString
            ddlBAtcoPurPriceType.ClearSelection()
            ddlBAtcoPurPriceType.Items.FindByValue(dt.Rows(0).Item("BOP_AtcoPurchasePriceType").ToString).Selected = True
            ddlBAtcoPurPriceTypePerUnit.ClearSelection()
            ddlBAtcoPurPriceTypePerUnit.Items.FindByValue(dt.Rows(0).Item("BOP_AtcoPurchasePriceTypePerUnit").ToString).Selected = True
            txtBAtcoMaartPrice.Text = dt.Rows(0).Item("BOP_AtcoMaartPrice").ToString
            ddlBAtcoMaartPriceType.ClearSelection()
            ddlBAtcoMaartPriceType.Items.FindByValue(dt.Rows(0).Item("BOP_AtcoMaartPriceType").ToString).Selected = True
            ddlBAtcoMaartPriceTypePerUnit.ClearSelection()
            ddlBAtcoMaartPriceTypePerUnit.Items.FindByValue(dt.Rows(0).Item("BOP_AtcoMaartPriceTypePerUnit").ToString).Selected = True
            dt.Clear()
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub btnStandardPrice_Click1(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub

    Protected Sub rdoSparePart_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        If rdoSparePart.SelectedIndex = 0 Then
            isAccess.Visible = False
            rdoAccessories.Enabled = False
            rdoAccessories.ClearSelection()
            btnAccessories.Enabled = False
            trwear.Visible = True
        ElseIf rdoSparePart.SelectedIndex = 1 Then
            isAccess.Visible = True
            rdoAccessories.Enabled = True
            btnAccessories.Enabled = True
            trwear.Visible = False
        End If
    End Sub

    Protected Sub btnSparePart_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            Dim AsVal As String = ReturnValue("Select Product_IsAssc from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")
            Dim Spart As String = ReturnValue("SELECT ODTSP_ProductId  FROM OtherDetail_SpareParts Where ODTSP_SparePartId ='" & Session("ProductID").ToString.Trim & "'")
            If btnSparePart.Text = "Edit" Then

                rdoSparePart.Visible = True
                rdoSparePart.ClearSelection()
                rdoSparePart.Enabled = True
                Dim Val As String = ReturnValue("Select Product_IsSpareParts from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")
                Try
                    rdoSparePart.Items.FindByValue(Val).Selected = True
                Catch
                End Try
                Label26.Text = ""
                Label26.Visible = False
                btnSparePart.Text = "Update"
            Else
                If (AsVal <> "Y" And rdoSparePart.SelectedIndex = 0) Or btnSparePart.Text = "Update" Or btnSparePart.Text = "Save" Then
                    If Session("ProductID") <> Nothing And Spart = "" Then
                        ExecuteQuery("UPDATE Product_Master SET Product_IsSpareParts = '" & rdoSparePart.SelectedValue.ToString & "',Product_ClientIP='" & Request.UserHostAddress & "' WHERE Product_Kid = '" & Session("ProductID").ToString.Trim & "'")

                        If isAccess.Visible = False Then
                            '  ExecuteQuery("UPDATE Product_Master SET Product_IsWear_Tear = 'N' WHERE Product_Kid = '" & Session("ProductID").ToString.Trim & "'")
                        ElseIf isAccess.Visible = True Then
                            ' ExecuteQuery("UPDATE Product_Master SET Product_IsAssc = 'N' WHERE Product_Kid = '" & Session("ProductID").ToString.Trim & "'")
                            ExecuteQuery("UPDATE Product_Master SET Product_IsWear_Tear = 'N',Product_ClientIP='" & Request.UserHostAddress & "' WHERE Product_Kid = '" & Session("ProductID").ToString.Trim & "'")
                            Label27.Text = "No"
                        End If
                        System.Threading.Thread.Sleep(1000)
                        rdoSparePart.Visible = False
                        Label26.Visible = True
                        Label26.Text = rdoSparePart.SelectedItem.Text.ToString
                        btnSparePart.Visible = False

                        If btnSparePart.Text = "Update" Then
                            btnSparePart.Visible = True
                            btnSparePart.Text = "Edit"
                            rdoSparePart.Enabled = False
                        End If
                        If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                            btnSparePart.Visible = True
                            btnSparePart.Text = "Edit"
                        End If
                    Else
                        showmessage("<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;This product already saved as a SpareParts for a Product. So You can't change it.", Label26)
                        Exit Sub
                    End If
                Else
                    showmessage("<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;This product already saved as a Accessories.", Label26)
                    Exit Sub
                End If

            End If
        Catch
        End Try
    End Sub

    Protected Sub btnWearTear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnWearTear.Click
        Try
            Dim SpVal As String = ReturnValue("Select Product_IsSpareParts from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")
            If btnWearTear.Text = "Edit" Then

                rdoWearTear.Visible = True
                rdoWearTear.ClearSelection()
                rdoWearTear.Enabled = True
                Dim Val As String = ReturnValue("Select Product_IsWear_Tear from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")
                Try
                    rdoWearTear.Items.FindByValue(Val).Selected = True
                Catch
                End Try
                Label27.Text = ""
                Label27.Visible = False
                btnWearTear.Text = "Update"
            Else
                If SpVal = "Y" Then
                    If Session("ProductID") <> Nothing Then
                        ExecuteQuery("UPDATE Product_Master SET Product_IsWear_Tear = '" & rdoWearTear.SelectedValue.ToString & "',Product_ClientIP='" & Request.UserHostAddress & "' WHERE Product_Kid = '" & Session("ProductID").ToString.Trim & "'")
                        System.Threading.Thread.Sleep(1000)
                        rdoWearTear.Visible = False
                        Label27.Visible = True
                        Label27.Text = rdoWearTear.SelectedItem.Text.ToString
                        btnWearTear.Visible = False

                        If btnWearTear.Text = "Update" Then
                            btnWearTear.Visible = True
                            btnWearTear.Text = "Edit"
                            rdoWearTear.Enabled = False
                        End If
                        If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                            btnWearTear.Visible = True
                            btnWearTear.Text = "Edit"
                        End If

                    End If
                Else
                    showmessage("<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;First save this product is spare parts.", Label27)
                    Exit Sub
                End If


            End If

        Catch
        End Try
    End Sub

    Protected Sub btnAccessories_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            Dim SpVal As String = ReturnValue("Select Product_IsSpareParts from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")
            Try
                If btnAccessories.Text = "Edit" Then

                    rdoAccessories.Visible = True
                    rdoAccessories.ClearSelection()
                    rdoAccessories.Enabled = True
                    Dim Val As String = ReturnValue("Select Product_IsAssc from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")
                    Try
                        rdoAccessories.Items.FindByValue(Val).Selected = True
                    Catch
                    End Try
                    Label28.Text = ""
                    Label28.Visible = False
                    btnAccessories.Text = "Update"
                Else
                    If (SpVal <> "Y" And rdoAccessories.SelectedIndex = 0) Or (btnAccessories.Text = "Update" And SpVal = "N") Or (btnAccessories.Text = "Save" And SpVal = "N") Then
                        If Session("ProductID") <> Nothing Then
                            ExecuteQuery("UPDATE Product_Master SET Product_IsAssc = '" & rdoAccessories.SelectedValue.ToString & "',Product_ClientIP='" & Request.UserHostAddress & "' WHERE Product_Kid = '" & Session("ProductID").ToString.Trim & "'")
                            rdoAccessories.Visible = False
                            Label28.Visible = True
                            Label28.Text = rdoAccessories.SelectedItem.Text.ToString
                            btnAccessories.Visible = False

                            If btnAccessories.Text = "Update" Then
                                btnAccessories.Visible = True
                                btnAccessories.Text = "Edit"
                                rdoAccessories.Enabled = False
                            End If
                            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                                btnAccessories.Visible = True
                                btnAccessories.Text = "Edit"
                            End If

                        End If

                    Else
                        showmessage("<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;This product is spare parts, you can't save it as a Accessories.", Label28)
                        Exit Sub
                    End If
                   
                End If

            Catch
            End Try



            'If Session("ProductID") <> Nothing Then
            '    ExecuteQuery("UPDATE Product_Master SET Product_IsAssc = '" & rdoAccessories.SelectedValue.ToString & "' WHERE Product_Kid = '" & Session("ProductID").ToString.Trim & "'")
            '    rdoAccessories.Visible = False
            '    Label28.Text = rdoAccessories.SelectedItem.Text.ToString
            '    btnAccessories.Visible = False

            'End If
        Catch
        End Try
    End Sub

    Protected Sub rdoWearTear_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub

    Protected Sub btnProdSave_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub

    
    Protected Sub btnback_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnback.Click
        Response.Redirect("product-information.aspx")
    End Sub

    Protected Sub lnkPackagingCharge_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkPackagingCharge.Click
        Dim atcoPriceType As String
        atcoPriceType = ReturnValue("select Product_MarketPriceType from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
        Dim atcopricep As String
        atcopricep = ReturnValue("select Product_MarketPrice from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")

        If Val(txtPackagingCharge.Text) < 0 Then
            showmessage("<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Packaging Charge must be greater than zero.", Label17)
            Exit Sub
        End If
        If atcopricep = "" And atcoPriceType = "" Then
            showmessage("<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Please Enter Price First.", Label17)
            Exit Sub
        End If

        Try


            If ddlPackagingCharge.Visible = True Then
                If atcoPriceType = ddlPackagingCharge.SelectedValue.ToString Then
                    Label17.Visible = False
                Else
                    Label17.Visible = True
                    Label17.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Packaging Price type same as market price type."
                    ddlPackagingCharge.Focus()
                    Exit Sub
                End If
            End If

            If lnkPackagingCharge.Text = "Edit" Then
                txtPackagingCharge.Visible = True
                lblPackagingCharge.Visible = False
                rdopackagingType.Enabled = True
                Dim pack_price As String = ReturnValue("Select Product_PackagingCharge from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")
                Dim pack_pricetype As String = ReturnValue("Select Product_PackagingChargeType from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")

                If pack_pricetype <> "" Then
                    Try
                        ddlPackagingCharge.Visible = True
                        lblpercent.Visible = False
                        ddlPackagingCharge.ClearSelection()
                        ddlPackagingCharge.Items.FindByValue(ReturnValue("Select Product_PackagingChargeType from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")).Selected = True
                    Catch ex As Exception
                        ddlPackagingCharge.ClearSelection()
                    End Try
                Else
                    ddlPackagingCharge.Visible = False
                    lblpercent.Visible = True
                End If

                If rdopackagingType.SelectedValue = "1" Then
                    Dim marketp As String = ReturnValue("select Product_MarketPrice from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
                    Dim marketprice As Double = CType(marketp, Double)
                    txtPackagingCharge.Text = (100 * CType(pack_price, Double)) / marketp
                    lblCalculatePackCharge.Visible = True
                    lblCalculatePackCharge.Text = "Rs. " & pack_price
                Else
                    txtPackagingCharge.Text = pack_price
                    lblCalculatePackCharge.Visible = False
                End If

                'txtPackagingCharge.Text = pack_price    'ReturnValue("Select Product_PackagingCharge from Product_Master Where Product_Kid ='" & Session("ProductID").ToString.Trim & "'and Product_IsDeleted = '0'")
                'ddlPackagingCharge.Visible = True

                lnkPackagingCharge.Text = "Update"
            Else
                If Session("ProductID") <> Nothing Then
                    lblPackagingCharge.Text = ""
                    If rdopackagingType.SelectedValue = 1 Then

                        If txtPackagingCharge.Text > 100 Then
                            Label17.Visible = True
                            Label17.Text = "<img alt='' src='" & Page.ResolveUrl("../Images/javascripts.gif") & "'/>&nbsp;Packaging Charge in % should Not more than 100."
                            txtPackagingCharge.Focus()
                            txtPackagingCharge.Text = ""
                            Exit Sub
                        End If

                        Dim marketp As String = ReturnValue("select Product_MarketPrice from Product_Master Where Product_Kid ='" & Session("ProductID") & "'and Product_IsDeleted = '0'")
                        Dim marketprice As Double = CType(marketp, Double)

                        Dim pack_charge As Double = (marketprice * CType(txtPackagingCharge.Text, Double)) / 100
                        lblPackagingCharge.Text = pack_charge
                        ExecuteQuery("UPDATE Product_Master SET Product_PackagingCharge = '" & pack_charge & "', Product_PackagingChargeType =Null,Product_ClientIP='" & Request.UserHostAddress & "' WHERE Product_Kid = '" & Session("ProductID").ToString.Trim & "'")
                        lblCalculatePackCharge.Visible = True
                        lblCalculatePackCharge.Text = "( " & txtPackagingCharge.Text & " %)"
                        lblpercent.Visible = False
                        lblPackagingCharge.Text = "Rs. " & pack_charge

                    Else
                        ExecuteQuery("UPDATE Product_Master SET Product_PackagingCharge = '" & txtPackagingCharge.Text.ToString.Trim & "', Product_PackagingChargeType = '" & ddlPackagingCharge.SelectedItem.Value.ToString.Trim & "',Product_ClientIP='" & Request.UserHostAddress & "' WHERE Product_Kid = '" & Session("ProductID").ToString.Trim & "'")
                        lblPackagingCharge.Text = ddlPackagingCharge.SelectedItem.Text & "  " & txtPackagingCharge.Text
                        lblCalculatePackCharge.Visible = False
                    End If
                    rdopackagingType.Enabled = False
                    txtPackagingCharge.Visible = False
                    ddlPackagingCharge.Visible = False
                    lnkPackagingCharge.Visible = False
                    'End If
                    If lnkPackagingCharge.Text = "Update" Then
                        lnkPackagingCharge.Visible = True
                        lnkPackagingCharge.Text = "Edit"
                        lblPackagingCharge.Visible = True
                    End If
                    If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                        lnkPackagingCharge.Visible = True
                        lnkPackagingCharge.Text = "Edit"
                    End If
                Else
                    'lblError.Visible = True
                End If

            End If

        Catch
        End Try
    End Sub

    Protected Sub rdopackagingType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdopackagingType.SelectedIndexChanged
        If rdopackagingType.SelectedValue = "1" Then

            ddlPackagingCharge.Visible = False
            lblpercent.Visible = True
        Else
            ddlPackagingCharge.Visible = True
            lblpercent.Visible = False

        End If
        lnkPackagingCharge.Visible = True
    End Sub

End Class
