﻿Imports System
Imports System.Data.SqlClient
Imports System.Data
Imports System.IO
Imports System.String
Imports Ajax
Imports System.Drawing.Imaging
Imports System.Drawing
Imports System.Drawing.Drawing2D

Partial Class Admin_AddProduct
    Inherits System.Web.UI.Page

#Region "Declaration"

    Protected Shared i As Integer = 0
    Protected Shared img As Integer
    'Protected Shared Product_Image As String
    'Protected Shared Product_SpecialNotes As String
    'Protected Shared Product_MSDS As String
    'Protected Shared Product_GuarantyWarranty As String
    'Protected Shared Product_Catalog As String
    'Protected Shared Product_Certificate As String
    'Protected Shared Product_UserManual As String
    'Protected Shared Product_Packaging As String
    'Protected Shared Product_Installation As String
    Dim str, str1 As String
    Dim strcon As String = ConfigurationSettings.AppSettings.Item("ConnectionString")
    Dim con As New SqlConnection(strcon)
    Protected Shared clientIP As String
#End Region

#Region "Events"

    Protected Sub Admin_AddProduct_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("AdminID") Is Nothing Then
            Response.Redirect("AdminLogin.aspx?sesn=expire")
            Exit Sub
        End If
        Ajax.Utility.RegisterTypeForAjax(GetType(Admin_AddProduct))
        clientIP = Request.UserHostAddress().ToString() '------updated by Prachi - 28/08/2009 - to save product partially------

        If Not IsPostBack Then
            Try
                fillSupplier()
                ClearSharedVariable()
                Session("ProductID") = Nothing '------updated by Prachi - 28/08/2009 - to save product partially------
                Session("ProductName") = Nothing '------updated by Prachi - 03/09/2009 - to display product name in label------
                btnFinalSubmitProduct.Attributes.Add("onclick", "return CheckValidation('txt-" & txtProductName.ClientID.ToString & "-r-n-Please Enter Product Name..!');")
            Catch ex As Exception

            End Try
        End If

        '------updated by Prachi - 03/09/2009 - to display product name in label------
        If Not Session("ProductName") Is Nothing Then
            lblProductName.Text = Session("ProductName").ToString
            lblProductName.Visible = True
            txtProductName.Visible = False
        End If
        '------end update------
    End Sub

    Protected Sub ddlSupplierName_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlSupplierName.SelectedIndexChanged
        Try
            If ddlSupplierName.SelectedIndex > 0 Then
                LoadCategory("Root Category")
                cbosubCategory1.ClearSelection()
                cbosubCategory2.ClearSelection()
                cbosubCategory1.Visible = False
                cbosubCategory2.Visible = False
                tblProductInfo.Visible = False
                tblCategory.Visible = True
                hfSupplierId.Value = ddlSupplierName.SelectedValue.ToString
            Else
                tblCategory.Visible = False
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub cboCategory_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboCategory.SelectedIndexChanged
        If cboCategory.SelectedItem.Value = "0" Then
            Label2.Visible = True
            Label2.Text = "Please Select the Category"
            cbosubCategory1.Visible = False
            cbosubCategory2.Visible = False
            Label15.Visible = False
        Else
            Session("lastsubcategory") = ""
            Session("lastsubcategory") = cboCategory.SelectedItem.Value
            getparents(cboCategory.SelectedItem.Value)
            LoadSubCategory1(cboCategory.SelectedItem.Value)
        End If
    End Sub

    Protected Sub cbosubCategory1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbosubCategory1.SelectedIndexChanged
        Session("lastsubcategory") = cbosubCategory1.SelectedItem.Value
        getparents(cbosubCategory1.SelectedItem.Value)
        LoadSubCategory2(cbosubCategory1.SelectedItem.Value)
        cbosubCategory1.Visible = True
    End Sub

    Protected Sub cbosubCategory2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbosubCategory2.SelectedIndexChanged
        Try
            Session("lastsubcategory") = cbosubCategory2.SelectedItem.Value
            getparents(cbosubCategory2.SelectedItem.Value)
            LoadSubCategory3(cbosubCategory2.SelectedItem.Value)
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub chkCategory_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkCategory.DataBound
        Dim chk As CheckBoxList = sender
        'Dim strCategoryID As String
        Dim i As Integer
        For i = 0 To chk.Items.Count - 1
            'strCategoryID = chk.Items(i).Value
            chk.Items(i).Text = fillcategory(chk.Items(i).Value.ToString)
        Next
    End Sub

    Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        If Session("ProductID") Is Nothing Then
            CreateMessageAlert(Me, "Please Enter Product Name first", "strkeyval")
            ScriptManager.GetCurrent(Me).SetFocus(txtProductName)
        Else
            If (fuProductImage.HasFile) Then
                Dim fileType As String = Path.GetExtension(fuProductImage.FileName)
                If fileType.ToLower = ".gif" Or fileType.ToLower = ".jpg" Or fileType.ToLower = ".bmp" Or fileType.ToLower = ".jpeg" Or fileType.ToLower = ".png" Then
                    Dim folderpath As String = Server.MapPath("~/Upload Image/Product Image/UploadImages/")
                    ViewState("Product_Image") = Image_upload(fuProductImage, img, folderpath, ViewState("Product_Image"))
                    JJKeepAspectRatioNew(imgProductImage, folderpath & ViewState("Product_Image"), 160, 150)
                    imgProductImage.ImageUrl = "~/Upload Image/Product Image/UploadImages/" & ViewState("Product_Image")

                    '------updated by Prachi - 03/09/2009 - to insert product image------
                    ExecuteQuery("update Product_Master set Product_Image = '" & ViewState("Product_Image").ToString & "' where Product_Kid = '" & RemoveLiterals(Session("ProductID").ToString.Trim) & "'")
                    '------end update------
                Else
                    CreateMessageAlert(Me, "Please Select Valid Image File..", "strkeyval")
                    ScriptManager.GetCurrent(Me).SetFocus(fuProductImage)
                End If
            End If
        End If
    End Sub

    Protected Sub btnApplicationArrow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnApplicationArrow.Click
        Try
            If txtProdApplication.Text <> "" Then
                If lstApplication.Items.Count > 0 Then
                    'For i As Integer = 0 To lstApplication.Items.Count - 1
                    If lstApplication.Items.FindByText(txtProdApplication.Text.Trim) Is Nothing Then
                        lstApplication.Items.Add(txtProdApplication.Text.Trim)
                    End If
                    'If lstApplication.Items(i).Text.Trim <> txtProdApplication.Text.Trim Then
                    '    lstApplication.Items.Add(txtProdApplication.Text.Trim)
                    'End If

                    'Next
                Else
                    lstApplication.Items.Add(txtProdApplication.Text.Trim)
                End If
                txtProdApplication.Text = ""
                ScriptManager.GetCurrent(Me).SetFocus(txtProdApplication)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub btnAppBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAppBack.Click
        Try
            If lstApplication.Items.Count > 0 Then
                lstApplication.Items.Remove(lstApplication.SelectedItem)
                ScriptManager.GetCurrent(Me).SetFocus(lstApplication)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub btnProdFeatureArrow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProdFeatureArrow.Click
        Try
            If txtProductFeature.Text <> "" Then
                If lstProductFeature.Items.Count > 0 Then
                    'For i As Integer = 0 To lstApplication.Items.Count - 1
                    If lstProductFeature.Items.FindByText(txtProductFeature.Text.Trim) Is Nothing Then
                        lstProductFeature.Items.Add(txtProductFeature.Text.Trim)
                    End If
                    'If lstApplication.Items(i).Text.Trim <> txtProdApplication.Text.Trim Then
                    '    lstApplication.Items.Add(txtProdApplication.Text.Trim)
                    'End If

                    'Next
                Else
                    lstProductFeature.Items.Add(txtProductFeature.Text.Trim)
                End If
                txtProductFeature.Text = ""
                ScriptManager.GetCurrent(Me).SetFocus(txtProductFeature)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub btnProdFeatureBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProdFeatureBack.Click
        Try
            If lstProductFeature.Items.Count > 0 Then
                lstProductFeature.Items.Remove(lstProductFeature.SelectedItem)
                ScriptManager.GetCurrent(Me).SetFocus(lstProductFeature)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub btnProdTechArrow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProdTechArrow.Click
        Try
            If ddlParameter.SelectedIndex > 0 And txtParameterValue.Text <> "" Then
                If lstProductTechSpec.Items.Count > 0 Then
                    'For i As Integer = 0 To lstApplication.Items.Count - 1
                    If lstProductTechSpec.Items.FindByText(ddlParameter.SelectedItem.Text.Trim + " = " + txtParameterValue.Text.Trim) Is Nothing Then
                        lstProductTechSpec.Items.Add(New ListItem(ddlParameter.SelectedItem.Text.Trim + " = " + txtParameterValue.Text.Trim, ddlParameter.SelectedItem.Value.Trim + " = " + txtParameterValue.Text.Trim))
                    End If
                Else
                    lstProductTechSpec.Items.Add(New ListItem(ddlParameter.SelectedItem.Text.Trim + " = " + txtParameterValue.Text.Trim, ddlParameter.SelectedItem.Value.Trim + " = " + txtParameterValue.Text.Trim))
                End If
                txtParameterValue.Text = ""
                ScriptManager.GetCurrent(Me).SetFocus(txtParameterValue)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub btnProdTechBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProdTechBack.Click
        Try
            If lstProductTechSpec.Items.Count > 0 Then
                lstProductTechSpec.Items.Remove(lstProductTechSpec.SelectedItem)
                ScriptManager.GetCurrent(Me).SetFocus(txtParameterValue)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub lnkSaveParameter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkSaveParameter.Click
        Try
            Dim strTech As String
            strTech = InsertParameterMaster(txtNewParameter.Text, RemoveLiterals(Session("CategoryId").ToString), Session("g_Company").ToString, Session("g_User").ToString, Session("g_FinYear").ToString)

            If strTech = "false" Then
                CreateMessageAlert(Me, "Parameter Name is Already Present.!", "strkeyval")
                trAddNewParameter.Visible = False
                trProductTechSpec.Visible = True
                ScriptManager.GetCurrent(Me).SetFocus(txtParameterValue)
            Else
                FillTechnicalParameter()
                trAddNewParameter.Visible = False
                trProductTechSpec.Visible = True
                SetSelectedComboByText(ddlParameter, txtNewParameter.Text)
                ScriptManager.GetCurrent(Me).SetFocus(txtParameterValue)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub lnkCancelParameter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkCancelParameter.Click
        Try
            trAddNewParameter.Visible = False
            trProductTechSpec.Visible = True
            ScriptManager.GetCurrent(Me).SetFocus(txtParameterValue)
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub ddlParameter_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlParameter.SelectedIndexChanged
        Try
            If ddlParameter.SelectedValue = "OtherParameter" Then
                trAddNewParameter.Visible = True
                trProductTechSpec.Visible = False
                ScriptManager.GetCurrent(Me).SetFocus(txtNewParameter)
            Else
                ScriptManager.GetCurrent(Me).SetFocus(txtParameterValue)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub BtnSpecialNotes_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSpecialNotes.Click
        Try
            If (fuSpecialInstruAndNotes.HasFile) Then
                Dim fileType As String = Path.GetExtension(fuSpecialInstruAndNotes.FileName).ToLower
                If fileType.ToLower = ".pdf" Then
                    ViewState("Product_SpecialNotes") = Final_FileUpload(fuSpecialInstruAndNotes, img, Server.MapPath("~\Upload Image\Product Image\UploadImages\"))
                    hlSpecialInstruction.Text = ViewState("Product_SpecialNotes").ToString
                    hlSpecialInstruction.NavigateUrl = "~\Upload Image\Product Image\UploadImages\" & ViewState("Product_SpecialNotes").ToString
                    ScriptManager.GetCurrent(Me).SetFocus(BtnSpecialNotes)
                Else
                    'lblResult.Visible = True
                    'lblResult.Text = "Please select .pdf only!"
                    CreateMessageAlert(Me, "Please Select (.pdf) File Only..!", "strkeyval")
                    ScriptManager.GetCurrent(Me).SetFocus(fuSpecialInstruAndNotes)
                    Exit Sub
                End If
            Else
                CreateMessageAlert(Me, "Please Select (.pdf) File Only..!", "strkeyval")
                ScriptManager.GetCurrent(Me).SetFocus(btnProductMSDS)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub btnProductMSDS_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProductMSDS.Click
        Try
            If (fuProductMSDS.HasFile) Then
                Dim fileType As String = Path.GetExtension(fuProductMSDS.FileName)
                If fileType.ToLower = ".pdf" Then
                    ViewState("Product_MSDS") = Final_FileUpload(fuProductMSDS, img, Server.MapPath("~\Upload Image\Product Image\UploadImages\"))
                    hlProductMSDS.Text = ViewState("Product_MSDS").ToString
                    hlProductMSDS.NavigateUrl = "~\Upload Image\Product Image\UploadImages\" & ViewState("Product_MSDS").ToString
                    ScriptManager.GetCurrent(Me).SetFocus(btnProductMSDS)
                Else
                    CreateMessageAlert(Me, "Please Select (.pdf) File Only..!", "strkeyval")
                    ScriptManager.GetCurrent(Me).SetFocus(fuProductMSDS)
                    Exit Sub
                End If
            Else
                CreateMessageAlert(Me, "Please Select (.pdf) File Only..!", "strkeyval")
                ScriptManager.GetCurrent(Me).SetFocus(btnProductMSDS)

            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub btnGW_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGW.Click
        Try
            If (fuGuaWar.HasFile) Then
                Dim fileType As String = Path.GetExtension(fuGuaWar.FileName).ToLower
                'If fileType = ".pdf" Then
                ViewState("Product_GuarantyWarranty") = Final_FileUpload(fuGuaWar, img, Server.MapPath("~\Upload Image\Product Image\UploadImages\"))
                hlProdGuaWar.Text = ViewState("Product_GuarantyWarranty").ToString
                hlProdGuaWar.NavigateUrl = "~\Upload Image\Product Image\UploadImages\" & ViewState("Product_GuarantyWarranty").ToString
                ScriptManager.GetCurrent(Me).SetFocus(btnGW)
            Else
                CreateMessageAlert(Me, "Please Select File!", "strkeyval")
                ScriptManager.GetCurrent(Me).SetFocus(btnGW)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub btnProdCatalog_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProdCatalog.Click
        Try
            If (fucatalog.HasFile) Then
                Dim fileType As String = Path.GetExtension(fucatalog.FileName)
                If fileType.ToLower = ".pdf" Then
                    ViewState("Product_Catalog") = Final_FileUpload(fucatalog, img, Server.MapPath("~\Upload Image\Product Image\UploadImages\"))
                    hlCatalog.Text = ViewState("Product_Catalog").ToString
                    hlCatalog.NavigateUrl = "~\Upload Image\Product Image\UploadImages\" & ViewState("Product_Catalog").ToString
                    ScriptManager.GetCurrent(Me).SetFocus(btnProdCatalog)
                Else
                    CreateMessageAlert(Me, "Please Select (.pdf) File Only..!", "strkeyval")
                    ScriptManager.GetCurrent(Me).SetFocus(fucatalog)
                    Exit Sub
                End If
            Else
                CreateMessageAlert(Me, "Please Select (.pdf) File Only..!", "strkeyval")
                ScriptManager.GetCurrent(Me).SetFocus(btnProdCatalog)

            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub btnProdCertificate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProdCertificate.Click
        Try
            If (fuProdCertificate.HasFile) Then
                ViewState("Product_Certificate") = Final_FileUpload(fuProdCertificate, img, Server.MapPath("~\Upload Image\Product Image\UploadImages\"))
                hlCertificate.Text = ViewState("Product_Certificate").ToString
                hlCertificate.NavigateUrl = "~\Upload Image\Product Image\UploadImages\" & ViewState("Product_Certificate").ToString
                ScriptManager.GetCurrent(Me).SetFocus(btnProdCertificate)
            Else
                CreateMessageAlert(Me, "Please Select File!", "strkeyval")
                ScriptManager.GetCurrent(Me).SetFocus(btnProdCertificate)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub btnProdUserManual_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProdUserManual.Click
        Try
            If (fuUserManual.HasFile) Then
                ViewState("Product_UserManual") = Final_FileUpload(fuUserManual, img, Server.MapPath("~\Upload Image\Product Image\UploadImages\"))
                hlUserManual.Text = ViewState("Product_UserManual").ToString
                hlUserManual.NavigateUrl = "~\Upload Image\Product Image\UploadImages\" & ViewState("Product_UserManual").ToString
                ScriptManager.GetCurrent(Me).SetFocus(btnProdUserManual)
            Else
                CreateMessageAlert(Me, "Please Select File!", "strkeyval")
                ScriptManager.GetCurrent(Me).SetFocus(btnProdUserManual)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub btnProdPacakgingDetails_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProdPacakgingDetails.Click
        Try
            If (fuProdPackaging.HasFile) Then
                ViewState("Product_Packaging") = Final_FileUpload(fuProdPackaging, img, Server.MapPath("~\Upload Image\Product Image\UploadImages\"))
                hlPackaging.Text = ViewState("Product_Packaging").ToString
                hlPackaging.NavigateUrl = "~\Upload Image\Product Image\UploadImages\" & ViewState("Product_Packaging").ToString
                ScriptManager.GetCurrent(Me).SetFocus(btnProdPacakgingDetails)
            Else
                CreateMessageAlert(Me, "Please Select File!", "strkeyval")
                ScriptManager.GetCurrent(Me).SetFocus(btnProdPacakgingDetails)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub btnProdConsumableArrow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProdConsumableArrow.Click
        Try
            If txtConsumableName.Text <> "" And txtConsumableQty.Text <> "" Then
                If lstConsumableList.Items.Count > 0 Then
                    'For i As Integer = 0 To lstApplication.Items.Count - 1
                    If lstConsumableList.Items.FindByText(txtConsumableName.Text.Trim + " = " + txtConsumableQty.Text.Trim) Is Nothing Then
                        lstConsumableList.Items.Add(txtConsumableName.Text.Trim + " = " + txtConsumableQty.Text.Trim)
                    End If
                    'If lstApplication.Items(i).Text.Trim <> txtProdApplication.Text.Trim Then
                    '    lstApplication.Items.Add(txtProdApplication.Text.Trim)
                    'End If

                    'Next
                Else
                    lstConsumableList.Items.Add(txtConsumableName.Text.Trim + " = " + txtConsumableQty.Text.Trim)
                End If
                txtConsumableName.Text = ""
                txtConsumableQty.Text = ""
                ScriptManager.GetCurrent(Me).SetFocus(txtConsumableName)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub btnProdConsumableBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProdConsumableBack.Click
        Try
            If lstConsumableList.Items.Count > 0 Then
                lstConsumableList.Items.Remove(lstConsumableList.SelectedItem)
                ScriptManager.GetCurrent(Me).SetFocus(lstConsumableList)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub btnProdInstallation_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnProdInstallation.Click
        Try
            If (fuInstallation.HasFile) Then
                ViewState("Product_Installation") = Final_FileUpload(fuInstallation, img, Server.MapPath("~\Upload Image\Product Image\UploadImages\"))
                hlInstallation.Text = ViewState("Product_Installation").ToString
                hlInstallation.NavigateUrl = "~\Upload Image\Product Image\UploadImages\" & ViewState("Product_Installation").ToString
                ScriptManager.GetCurrent(Me).SetFocus(btnProdInstallation)
            Else
                CreateMessageAlert(Me, "Please Select File!", "strkeyval")
                ScriptManager.GetCurrent(Me).SetFocus(btnProdInstallation)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub btnFinalSubmitProduct_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFinalSubmitProduct.Click
        Try
            'Dim ProductKId As String
            'ProductKId = NewPrimaryKey(Me)
            'Session("ProductID") = ProductKId
            'Dim cmd As New SqlCommand
            'cmd.CommandType = CommandType.StoredProcedure
            'cmd.CommandText = "proc_InsertProduct"
            'cmd.Connection = con
            'cmd.Parameters.Add(New SqlParameter("@Product_Kid", SqlDbType.NVarChar, 20)).Value = ProductKId.ToString
            'cmd.Parameters.Add(New SqlParameter("@Product_Name", SqlDbType.NVarChar, 150)).Value = txtProductName.Text.ToString.Trim
            'cmd.Parameters.Add(New SqlParameter("@Product_RegDate", SqlDbType.DateTime)).Value = Date.Now
            'cmd.Parameters.Add(New SqlParameter("@Product_Description", SqlDbType.NVarChar, 2000)).Value = IIf(txtDescription.Text.ToString.Trim = "", Nothing, txtDescription.Text.ToString.Trim)
            'cmd.Parameters.Add(New SqlParameter("@Product_BrandId", SqlDbType.NVarChar, 10)).Value = ddlBrand.SelectedValue.Trim
            'cmd.Parameters.Add(New SqlParameter("@Product_CategoryId", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Session("CategoryId").ToString.Trim)
            'cmd.Parameters.Add(New SqlParameter("@Product_SupplierID", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(ddlSupplierName.SelectedValue.Trim)
            'cmd.Parameters.Add(New SqlParameter("@Product_ModelNo", SqlDbType.NVarChar, 100)).Value = IIf(txtModelNo.Text.Trim = "", Nothing, txtModelNo.Text.Trim)
            'cmd.Parameters.Add(New SqlParameter("@Product_Image", SqlDbType.NVarChar, 150)).Value = ViewState("Product_Image").ToString
            'cmd.Parameters.Add(New SqlParameter("@Product_MarketPrice", SqlDbType.Decimal)).Value = IIf(txtPrice.Text.Trim = "", Nothing, txtPrice.Text.Trim)
            'cmd.Parameters.Add(New SqlParameter("@Product_MarketPriceType", SqlDbType.NVarChar, 50)).Value = ddlPriceType.SelectedValue.Trim
            'cmd.Parameters.Add(New SqlParameter("@Product_DeliveryPeriod", SqlDbType.Decimal)).Value = IIf(txtDispatchIn.Text.Trim = "", Nothing, txtDispatchIn.Text.Trim)
            'cmd.Parameters.Add(New SqlParameter("@Product_DeliveryPeriodType", SqlDbType.NVarChar, 10)).Value = ddlDispatchIn.SelectedValue.Trim
            'cmd.Parameters.Add(New SqlParameter("@Product_Weight", SqlDbType.Decimal)).Value = IIf(txtShipWeight.Text.Trim = "", Nothing, txtShipWeight.Text.Trim)
            'cmd.Parameters.Add(New SqlParameter("@Product_WeightUnitId", SqlDbType.NVarChar, 50)).Value = ddlShipWeightType.SelectedValue.Trim
            'cmd.Parameters.Add(New SqlParameter("@Product_Dimension", SqlDbType.NVarChar, 25)).Value = IIf(IIf(txtDimenL.Text.Trim = "", "0", txtDimenL.Text.Trim) + "x" + IIf(txtDimenW.Text.Trim = "", "0", txtDimenW.Text.Trim) + "x" + IIf(txtDimenH.Text.Trim = "", "0", txtDimenH.Text.Trim) = "0x0x0", Nothing, IIf(txtDimenL.Text.Trim = "", "0", txtDimenL.Text.Trim) + "x" + IIf(txtDimenW.Text.Trim = "", "0", txtDimenW.Text.Trim) + "x" + IIf(txtDimenH.Text.Trim = "", "0", txtDimenH.Text.Trim))
            'cmd.Parameters.Add(New SqlParameter("@Product_DimensionUnitId", SqlDbType.NVarChar, 10)).Value = "00001:<"  ' For Dimension Static Value is mm.
            'cmd.Parameters.Add(New SqlParameter("@Product_MinOrderQty", SqlDbType.Decimal)).Value = IIf(txtMinSellQty.Text.Trim = "", Nothing, txtMinSellQty.Text.Trim)
            'cmd.Parameters.Add(New SqlParameter("@Product_MinOrderQtyType", SqlDbType.NVarChar, 50)).Value = ddlMinSellType.SelectedValue.Trim
            'cmd.Parameters.Add(New SqlParameter("@Product_ShippingQty", SqlDbType.Decimal)).Value = IIf(txtMinShipQty.Text.Trim = "", Nothing, txtMinShipQty.Text.Trim)
            'cmd.Parameters.Add(New SqlParameter("@Product_ShippingQtyType ", SqlDbType.NVarChar, 10)).Value = ddlMinShipType.SelectedValue.Trim
            'cmd.Parameters.Add(New SqlParameter("@Product_PcsPerKg", SqlDbType.NVarChar, 50)).Value = IIf(txtPcsPckg.Text.Trim = "", Nothing, txtPcsPckg.Text.Trim)
            'cmd.Parameters.Add(New SqlParameter("@Product_Approved", SqlDbType.NVarChar, 20)).Value = "C"
            'cmd.Parameters.Add(New SqlParameter("@Product_UserId", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Convert.ToString(Session("g_User")))
            'cmd.Parameters.Add(New SqlParameter("@Product_FinancialYearId", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Convert.ToString(Session("g_FinYear")))
            'cmd.Parameters.Add(New SqlParameter("@Product_CompanyId", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Convert.ToString(Session("g_Company")))
            'cmd.Parameters.Add(New SqlParameter("@Product_ClientIP", SqlDbType.NVarChar, 50)).Value = Request.UserHostAddress().ToString
            'cmd.Parameters.Add(New SqlParameter("@Product_IsDeleted", SqlDbType.NVarChar, 1)).Value = "0"
            'cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 50)).Value = "Insert"
            'cmd.Parameters.Add(New SqlParameter("@CmdType", SqlDbType.VarChar, 50)).Value = "Insert_Product"
            'If (con.State = ConnectionState.Closed) Then
            '    con.Open()
            'End If
            'cmd.ExecuteNonQuery()
            InsertProductCategoryMaster()       ''''' Insert Category Relation
            ''''''''''''''''''''' 16 Tab Start.....
            AddProductApplication()
            AddProductFeature()
            AddTechSpec()
            AddProdSpecInstr()
            AddProductMSDS()
            AddProductGuarantyWarranty()
            AddProductCatalog()
            AddProductCertificate()
            AddProductUserManual()
            AddProductPackaging()
            AddProductConsumable()
            AddProductCommission()

            CreateMessageAlert(Me, "Product Saved Successfully...", "strkeyval")
            Response.Redirect("AddProduct.aspx")
        Catch ex As Exception
            Throw ex
        End Try
    End Sub


#End Region

#Region "Methods"

    Protected Sub fillSupplier()
        Dim dt As New DataTable
        Try
            dt = ReturnDataTable("select distinct Supplier_Kid, Supplier_Code, Supplier_Name, Supplier_Address,Supplier_CategoryId FROM Supplier_Master WHERE Supplier_CompanyId = '" & Session("G_Company") & "'and supplier_Approved = 'Y' AND Supplier_IsDeleted = '0' and Supplier_CategoryId <> '' order by Supplier_Name asc")
            ddlSupplierName.DataSource = dt
            ddlSupplierName.DataTextField = "Supplier_Name"
            ddlSupplierName.DataValueField = "Supplier_Kid"
            ddlSupplierName.DataBind()
            ddlSupplierName.Items.Insert(0, "Select Supplier")
        Catch ex As Exception

        End Try
    End Sub

    Private Sub LoadCategory(ByVal parentid As String)
        FillCategoryName(parentid, lblCat)
        lblCat.Visible = False
        Dim strsql As String
        strsql = "SELECT Category_Kid as id, Category_Name as Name FROM Category_Master WHERE Category_ParentId = '" & parentid & "'and Category_IsDeleted='0' ORDER BY Category_Name"
        cboCategory.Items.Clear()
        cboCategory.Items.Add(New ListItem("Select Category", "-1"))
        Fill_Combo(strsql, cboCategory)
        If cboCategory.Items.Count > 1 Then
            Label14.Visible = True
            Label15.Visible = False
            Label16.Visible = False

            cboCategory.ForeColor = Drawing.Color.Red
            cbosubCategory1.ForeColor = Drawing.Color.Black
            cbosubCategory2.ForeColor = Drawing.Color.Black
            Label1.Visible = True
            Label14.Text = "Select the category"
        Else
            Label14.Visible = False
            Label15.Visible = False
            Label16.Visible = False
            ' Label2.Visible = True
            ' Label2.Text = "Add the product"

            Label1.Visible = False
            'txtProductName.Enabled = True
            'ScriptManager1.SetFocus(txtProductName)
            Session("CategoryId") = parentid
            Dim dtCategory As DataTable
            dtCategory = ReturnDataTable("SELECT CategoryRelation_CategoryID FROM CategoryRelation_Master WHERE (CategoryRelation_Flag IN (SELECT CategoryRelation_Flag FROM CategoryRelation_Master AS CategoryRelation_Master_1 WHERE  (CategoryRelation_CategoryID = N'" & parentid & "'))) AND (CategoryRelation_CategoryID <> N'" & parentid & "')")
            If dtCategory.Rows.Count > 0 Then
                tdJJCategorySuggest.Visible = True
                chkCategory.DataSource = dtCategory
                chkCategory.DataTextField = "CategoryRelation_CategoryID"
                chkCategory.DataValueField = "CategoryRelation_CategoryID"
                chkCategory.DataBind()
            Else
                tdJJCategorySuggest.Visible = False
            End If
            If Label2.Visible = True Then
                Label1.Visible = False
            End If
        End If
    End Sub

    Public Sub FillCategoryName(ByVal Catid As String, ByVal lbl As Label)
        If (i = -1) Then
            i = 0
        End If
        If (Catid = "Root Category") Then
            Exit Sub
        End If
        lbl.Text = "<b> Product Category >  </b>"
        Dim dt As DataTable
        dt = ReturnDataTable("Select * From Category_Master Where Category_Kid ='" & Catid & "' and Category_Isdeleted = '0' ")
        Dim ParentId As String
        ParentId = dt.Rows(0).Item(3).ToString()
        If ParentId = "Root Category" Then
            'Label1.Text += dt.Rows(0).Item(2).ToString()
            'Dim CategoryName(10) As String
            Dim j As Integer
            Category(i) = dt.Rows(0).Item(2).ToString() & "  >  "
            'Array.Reverse(Category)
            For j = 0 To i
                lbl.Text += Category(i)
                i = i - 1
            Next
            Exit Sub
        Else
            Category(i) = dt.Rows(0).Item(2).ToString() & "  >  "
            i = i + 1
            'Label1.Text += dt.Rows(0).Item(2).ToString() & "  >>  "
            FillCategoryName(dt.Rows(0).Item(3).ToString(), lbl)
        End If
        dt.Clear()
        'GridView1.DataSource = dt
        'GridView1.DataBind()
    End Sub

    Private Function getparents(ByVal i As String) As String
        Dim strsql As String
        strsql = "SELECT Category_ParentId, Category_Name FROM Category_Master WHERE Category_Kid = '" & i & "'"
        If con.State = ConnectionState.Closed Then
            con.Open()
        End If

        Dim da As New SqlDataAdapter(strsql, con)
        Dim ds As New DataSet
        da.Fill(ds)
        Dim j As String

        Dim flag As Boolean = False
        If ds.Tables(0).Rows.Count > 0 Then
            j = ds.Tables(0).Rows(0).Item(0).ToString
            flag = True
        Else
            Return 0
            Exit Function
        End If

        If flag = True Then
            str1 = ds.Tables(0).Rows(0).Item(1).ToString & " > " & str1
            str = "<a href=./AddProduct.aspx?subcatid=" & ds.Tables(0).Rows(0).Item(0).ToString & ">" & ds.Tables(0).Rows(0).Item(1).ToString & "</a>" & " > " & str
            getparents(j)
        End If
        'dr.Close()
        con.Close()
        Label13.Text = str
        Session("categorylevel") = Nothing
        Session("categorylevel") = str1
        Session("Category") = str1
    End Function

    Private Sub LoadSubCategory1(ByVal intId As String)
        FillCategoryName(intId, lblCat)
        lblCat.Visible = False
        Dim strsql As String
        strsql = "SELECT Category_Kid as id, Category_Name as Name FROM Category_Master WHERE Category_ParentId = '" & intId & "' and Category_IsDeleted='0' ORDER BY Category_Name"

        cbosubCategory1.Items.Clear()
        cbosubCategory1.Items.Add(New ListItem("Select Subcategory", "-1"))
        Fill_Combo(strsql, cbosubCategory1)
        If cbosubCategory1.Items.Count > 1 Then
            Label14.Visible = False
            Label15.Visible = True
            Label16.Visible = False
            cboCategory.ForeColor = Drawing.Color.Black
            cbosubCategory1.ForeColor = Drawing.Color.Red
            cbosubCategory2.ForeColor = Drawing.Color.Black
            cbosubCategory1.Visible = True
            cbosubCategory2.Visible = False
            Label15.Text = "Select the next level"

            Label1.Visible = True

        Else
            cbosubCategory1.Visible = False
            cbosubCategory2.Visible = False
            Label14.Visible = False
            Label15.Visible = False
            Label16.Visible = False
            Label1.Visible = False
            Session("CategoryId") = intId

            Dim dtCategory As DataTable
            dtCategory = ReturnDataTable("SELECT CategoryRelation_CategoryID FROM CategoryRelation_Master WHERE (CategoryRelation_Flag IN (SELECT CategoryRelation_Flag FROM CategoryRelation_Master AS CategoryRelation_Master_1 WHERE  (CategoryRelation_CategoryID = N'" & intId & "'))) AND (CategoryRelation_CategoryID <> N'" & intId & "')")
            If dtCategory.Rows.Count > 0 Then
                tdJJCategorySuggest.Visible = True
                chkCategory.DataSource = dtCategory
                chkCategory.DataTextField = "CategoryRelation_CategoryID"
                chkCategory.DataValueField = "CategoryRelation_CategoryID"
                chkCategory.DataBind()
            Else
                tdJJCategorySuggest.Visible = False
            End If
            If Label2.Visible = True Then
                Label1.Visible = False
            End If
            fillCombos()
            txtKeyPress()
            FillTechnicalParameter()
            ControlVisible()
            ScriptManager.GetCurrent(Me).SetFocus(txtProductName)
        End If

    End Sub

    Private Sub LoadSubCategory2(ByVal intId As String)
        FillCategoryName(intId, lblCat)
        lblCat.Visible = False
        Dim strsql As String
        strsql = "SELECT Category_Kid as id, Category_Name as Name FROM Category_Master WHERE Category_ParentId = '" & intId & "' and Category_IsDeleted='0' ORDER BY Category_Name"
        cbosubCategory2.Items.Clear()
        cbosubCategory2.Items.Add(New ListItem("Select Subcategory", "-1"))
        Fill_Combo(strsql, cbosubCategory2)
        If cbosubCategory2.Items.Count > 1 Then

            Label14.Visible = False
            Label15.Visible = False
            Label16.Visible = True
            cboCategory.ForeColor = Drawing.Color.Black
            cbosubCategory1.ForeColor = Drawing.Color.Black
            cbosubCategory2.ForeColor = Drawing.Color.Red
            Label16.Text = "Select the next level"
            cbosubCategory2.Visible = True
            Label1.Visible = True
        Else
            cbosubCategory2.Visible = False
            Label14.Visible = False
            Label15.Visible = False
            Label16.Visible = False
            Label1.Visible = False
            Session("CategoryId") = intId
            Dim dtCategory As DataTable
            dtCategory = ReturnDataTable("SELECT CategoryRelation_CategoryID FROM CategoryRelation_Master WHERE (CategoryRelation_Flag IN (SELECT CategoryRelation_Flag FROM CategoryRelation_Master AS CategoryRelation_Master_1 WHERE  (CategoryRelation_CategoryID = N'" & intId & "'))) AND (CategoryRelation_CategoryID <> N'" & intId & "')")
            If dtCategory.Rows.Count > 0 Then
                tdJJCategorySuggest.Visible = True
                chkCategory.DataSource = dtCategory
                chkCategory.DataTextField = "CategoryRelation_CategoryID"
                chkCategory.DataValueField = "CategoryRelation_CategoryID"
                chkCategory.DataBind()
            Else
                tdJJCategorySuggest.Visible = False
            End If
            If Label2.Visible = True Then
                Label1.Visible = False
            End If
            fillCombos()
            txtKeyPress()
            FillTechnicalParameter()
            ControlVisible()
            ScriptManager.GetCurrent(Me).SetFocus(txtProductName)
        End If
    End Sub

    Private Sub LoadSubCategory3(ByVal intId As String)
        FillCategoryName(intId, lblCat)
        lblCat.Visible = False
        Dim dt As DataTable = ReturnDataTable("SELECT Category_Kid as id, Category_Name as Name FROM Category_Master WHERE Category_ParentId = '" & intId & "' and Category_IsDeleted='0' ORDER BY Category_Name")

        If dt.Rows.Count > 0 Then

            Dim strsql As String
            strsql = "SELECT Category_Kid as id, Category_Name as Name FROM Category_Master WHERE Category_ParentId = '" & intId & "' and Category_IsDeleted='0' ORDER BY Category_Name"
            cboCategory.Items.Clear()
            cboCategory.Items.Add(New ListItem("Select Subcategory", "-1"))
            Fill_Combo(strsql, cboCategory)

            Label14.Visible = True
            Label15.Visible = False
            Label16.Visible = False
            cbosubCategory1.Visible = False
            cbosubCategory2.Visible = False
            cboCategory.ForeColor = Drawing.Color.Red
            cbosubCategory1.ForeColor = Drawing.Color.Black
            cbosubCategory2.ForeColor = Drawing.Color.Black
            Label14.Text = "Select the next level"
            Label1.Visible = True
        Else
            Label14.Visible = False
            Label15.Visible = False
            Label16.Visible = False
            Label1.Visible = False
            Session("CategoryId") = intId
            Dim dtCategory As DataTable
            dtCategory = ReturnDataTable("SELECT CategoryRelation_CategoryID FROM CategoryRelation_Master WHERE (CategoryRelation_Flag IN (SELECT CategoryRelation_Flag FROM CategoryRelation_Master AS CategoryRelation_Master_1 WHERE  (CategoryRelation_CategoryID = N'" & intId & "'))) AND (CategoryRelation_CategoryID <> N'" & intId & "')")
            If dtCategory.Rows.Count > 0 Then
                tdJJCategorySuggest.Visible = True
                chkCategory.DataSource = dtCategory
                chkCategory.DataTextField = "CategoryRelation_CategoryID"
                chkCategory.DataValueField = "CategoryRelation_CategoryID"
                chkCategory.DataBind()
            Else
                tdJJCategorySuggest.Visible = False
            End If
            If Label2.Visible = True Then
                Label1.Visible = False
            End If

            fillCombos()
            txtKeyPress()
            FillTechnicalParameter()
            ControlVisible()
            ScriptManager.GetCurrent(Me).SetFocus(txtProductName)
        End If

    End Sub

    Public Function fillcategory(ByVal strCatID As String) As String

        Dim dtCat As New DataTable
        Dim strValue As String = ""
        dtCat = ReturnDataTable("WITH CategoryList(Category_Kid,Category_Name,Category_ParentId) AS (SELECT Category_Master1.Category_Kid, Category_Master1.Category_Name, Category_Master1.Category_ParentId FROM Category_Master AS Category_Master1 WHERE Category_Master1.Category_Kid = '" & RemoveLiterals(strCatID.ToString) & "' UNION ALL SELECT Category_Master2.Category_Kid, Category_Master2.Category_Name, Category_Master2.Category_ParentId FROM Category_Master AS Category_Master2,CategoryList AS CategoryList WHERE Category_Master2.Category_Kid = CategoryList.Category_ParentId ) Select * From CategoryList")
        ' Dim str As String
        If dtCat.Rows.Count > 0 Then
            i = dtCat.Rows.Count
            While i > 0
                strValue = strValue + dtCat.Rows(i - 1).Item("Category_Name").ToString + " > "
                i = i - 1
            End While
        End If
        Return strValue

    End Function

    Public Sub fillCombos()
        Try
            Fill_Combo("SELECT distinct Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = N'Amount' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString() & "' order by unit_name", ddlPriceType)
            ddlPriceType.Items.FindByText("Rs.").Selected = True
            Fill_Combo("SELECT distinct Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = N'Qty' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString() & "' order by unit_name", ddlMinSellType)
            ddlMinSellType.Items.FindByText("Pcs").Selected = True
            Fill_Combo("SELECT distinct Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = N'Qty' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString() & "' order by unit_name", ddlMinShipType)
            ddlMinShipType.Items.FindByText("Pcs").Selected = True
            Fill_Combo("SELECT distinct Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = N'Days' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString() & "' order by unit_name", ddlDispatchIn)
            ddlDispatchIn.Items.FindByText("Days").Selected = True
            Fill_Combo("SELECT distinct Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = N'Weight' and unit_IsDeleted='0' and unit_CompanyId = '" & Session("g_Company").ToString() & "' order by unit_name", ddlShipWeightType)
            ddlShipWeightType.Items.FindByText("Kg").Selected = True

            Dim strSupID As String
            strSupID = RemoveLiterals(ddlSupplierName.SelectedValue)
            If strSupID.Contains("[") Then
                strSupID = strSupID.Replace("[", "[[]")
                'ElseIf strSupID.Contains("]") Then
                '    strSupID = strSupID.Replace("]", "[]]")
            End If

            Fill_Combo("Select Brand_Kid, Brand_Name From Brand_Master where Brand_IsDeleted = '0' and Brand_CompanyId like '%" & strSupID & "%'  order by Brand_Name", ddlBrand)
            ddlBrand.Items.Insert(ddlBrand.Items.Count, "Add Your Brand")

            FillCombo(ddlGuarantyType, "Unit_Kid", "Unit_Name", "SELECT Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = N'Days' AND Unit_CompanyId = '" & Session("g_Company") & "' AND Unit_IsDeleted = N'0'")
            FillCombo(ddlWarrantyType, "Unit_Kid", "Unit_Name", "SELECT Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = N'Days' AND Unit_CompanyId = '" & Session("g_Company") & "' AND Unit_IsDeleted = N'0'")

        Catch ex As Exception
            '  Response.Output.Write("Server error: " & ex.Message.ToString.ToUpperInvariant())
        End Try
    End Sub

    Public Sub txtKeyPress()
        txtPrice.Attributes.Add("onkeypress", "return decimalonly(event,this)")
        txtMinSellQty.Attributes.Add("onkeypress", "return decimalonly(event,this)")
        txtMinShipQty.Attributes.Add("onkeypress", "return decimalonly(event,this)")
        txtShipWeight.Attributes.Add("onkeypress", "return decimalonly(event,this)")
        txtDimenH.Attributes.Add("onkeypress", "return decimalonly(event,this)")
        txtDimenL.Attributes.Add("onkeypress", "return decimalonly(event,this)")
        txtDimenW.Attributes.Add("onkeypress", "return decimalonly(event,this)")
        txtDispatchIn.Attributes.Add("onkeypress", "return decimalonly(event,this)")
        txtPcsPckg.Attributes.Add("onkeypress", "return decimalonly(event,this)")
        txtGuaranty.Attributes.Add("onkeypress", "return blockNonNumbers(this,event,true,false);")
        txtWarranty.Attributes.Add("onkeypress", "return blockNonNumbers(this,event,true,false);")
    End Sub

    '<Ajax.AjaxMethod()> _
    'Public Sub ShowApplicationList()
    '    Try
    '        If txtProdApplication.Text <> "" Then
    '            If lstApplication.Items.Count > 0 Then
    '                For i As Integer = 0 To lstApplication.Items.Count - 1
    '                    If lstApplication.Items(i).Text.Trim <> txtProdApplication.Text.Trim Then
    '                        lstApplication.Items.Add(txtProdApplication.Text.Trim)
    '                    End If
    '                Next
    '            Else
    '                lstApplication.Items.Add(txtProdApplication.Text.Trim)
    '            End If
    '        End If
    '    Catch ex As Exception

    '    End Try
    'End Sub

    Private Sub JJKeepAspectRatioNew(ByRef Image1 As System.Web.UI.WebControls.Image, ByVal FilePath As String, ByVal newWidth As Long, ByVal newHeight As Long)
        Dim x As Long
        Dim y As Long
        Dim nx As Long
        Dim ny As Long
        Dim img As Image = Nothing
        If FilePath = "" Or IsDBNull(FilePath) Then
            Image1.Visible = False
            Exit Sub
        End If
        If System.IO.File.Exists(FilePath) = False Then
            Image1.Visible = False
            Exit Sub
        End If
        img = System.Drawing.Image.FromFile(FilePath)
        Dim nPercent As Single = 0
        x = img.Height
        y = img.Width
        nx = newHeight
        ny = newWidth

        If (y = ny Or y > ny) Then
            '========13.01.09
            'ny = (y * nx) / x
            'If (ny = newWidth Or ny < newWidth) Then
            '    Image1.Height = nx
            '    Image1.Width = ny
            'Else
            '    x = nx
            '    y = ny
            '    ny = newWidth
            '    nx = (x * ny) / y
            '    Image1.Height = nx
            '    Image1.Width = ny
            'End If
            nPercent = (CSng(ny) / CSng(y))
            Image1.Width = CInt((y * nPercent))
            Image1.Height = CInt((x * nPercent))

            x = Image1.Height.Value
            y = Image1.Width.Value
            If (x = nx Or x > nx) Then
                nPercent = (CSng(nx) / CSng(x))
                Image1.Width = CInt((y * nPercent))
                Image1.Height = CInt((x * nPercent))
            End If

        ElseIf (x = nx Or x > nx) Then
            nPercent = (CSng(nx) / CSng(x))
            Image1.Width = CInt((y * nPercent))
            Image1.Height = CInt((x * nPercent))

            '========13.01.09
            'nx = (x * ny) / y
            'If (nx = newHeight Or nx < newHeight) Then
            '    Image1.Height = nx
            '    Image1.Width = ny
            'Else
            '    x = nx
            '    y = ny
            '    nx = newHeight
            '    ny = (y * nx) / x
            '    Image1.Height = nx
            '    Image1.Width = ny
            'End If
        Else                 '========13.01.09
            Image1.Width = y
            Image1.Height = x
        End If
    End Sub

    Public Function Image_upload(ByRef fileup As FileUpload, ByVal i As Integer, ByVal folderpath As String, ByVal existfile As String) As String
        Try
            Dim filetype As String = Path.GetExtension(fileup.FileName)
            Dim j As Integer = Len(filetype)
            Dim filename As String = fileup.FileName
            '------updated by Prachi - 02/09/2009 - to generate unique guid for image uploaded by client------
            Dim file As String = Convert.ToString(System.Guid.NewGuid())
            filename = file & filetype
            'Dim file As String = Mid(fileup.FileName, 1, Len(filename) - j)
            'If existfile = "" Then
            '    While System.IO.File.Exists(folderpath & filename) ' function for checking file already exist
            '        i = i + 1
            '        filename = file & i & filetype
            '    End While
            'Else
            '    filename = existfile
            '    If FileIsLocked(folderpath & filename) = False Then
            '        System.IO.File.SetAttributes(folderpath & filename, FileAttributes.Normal)
            '    End If
            'End If
            '------end update------

            Dim filepath As String = folderpath & filename
            fileup.SaveAs(filepath)
            fileup.Dispose()
            'set a working directory
            Dim WorkingDirectory As String = folderpath

            'create a image object containing a verticel photograph
            Dim imgPhotoVert As Image = Image.FromFile(WorkingDirectory & filename)
            Dim imgPhotoHoriz As Image = Image.FromFile(WorkingDirectory & filename)
            Dim imgPhoto As Image = Nothing
            If imgPhotoVert.Height >= 650 Then
                imgPhoto = ConstrainProportions(imgPhotoVert, 650, Dimensions.Width, 650)
            ElseIf imgPhotoVert.Width >= 650 Then
                imgPhoto = ConstrainProportions(imgPhotoVert, 650, Dimensions.Height, 650)
            ElseIf imgPhotoVert.Height <= 200 Then
                imgPhoto = ConstrainProportions(imgPhotoVert, 250, 0, 250)
            ElseIf imgPhotoVert.Width <= 250 Then
                imgPhoto = ConstrainProportions(imgPhotoVert, 200, 1, 250)
            Else
                imgPhoto = ConstrainProportions(imgPhotoVert, imgPhotoVert.Width, Dimensions.Width, imgPhotoVert.Width)
            End If
            imgPhotoVert.Dispose()
            imgPhotoHoriz.Dispose()
            imgPhoto.Save(WorkingDirectory & filename)
            imgPhoto.Dispose()
            Return filename
        Catch ex As Exception

        End Try
    End Function

    Private Sub FillTechnicalParameter()
        Try
            Dim dt As New DataTable
            dt = ReturnDataTable("Select TechSpec_KID, TechSpec_Parameter from ProductTechnicalSpecification_Master where TechSpec_CategoryId='" & RemoveLiterals(Session("CategoryId").ToString) & "' order by TechSpec_Parameter")
            ddlParameter.Items.Clear()
            ddlParameter.DataSource = dt
            ddlParameter.DataTextField = "TechSpec_Parameter"
            ddlParameter.DataValueField = "TechSpec_KID"
            ddlParameter.DataBind()
            ddlParameter.Items.Insert(0, New ListItem("Select Parameter", 0))
            ddlParameter.Items.Insert(ddlParameter.Items.Count, New ListItem("Add New", "OtherParameter"))
        Catch ex As Exception

        End Try
    End Sub

    Public Function InsertParameterMaster(ByVal strParameter As String, ByVal strCategoryID As String, ByVal strCompanyID As String, ByVal strUserID As String, ByVal strFinancialYearID As String) As String
        Dim KID As String
        KID = NewPrimaryKey(Me)

        'Dim strMatch As String
        'strMatch = ReturnValue("SELECT     TechSpec_Kid FROM ProductTechnicalSpecification_Master WHERE     TechSpec_CategoryId = '" & strCategoryID.Trim & "' AND TechSpec_IsDeleted = '0' AND (soundex(TechSpec_parameter) = soundex('" & strParameter.Trim & "'))")
        'If strMatch <> "" Then
        '    Return "false"
        'End If
        If IsAlreadyPresent("Select count(*) from ProductTechnicalSpecification_Master where (TechSpec_Parameter='" & StrConv(strParameter.Trim, VbStrConv.ProperCase) & "' or TechSpec_Parameter like'" & StrConv(strParameter.Trim, VbStrConv.ProperCase) & "%') and TechSpec_CategoryId ='" & strCategoryID.ToString & "'") Then
            Return "false"
        End If
        If KID <> "" Then
            Dim con As New SqlConnection()
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")        'Read the connection string from web.config
            Dim cmd As New SqlCommand()
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "ProductTechnicalSpecificationMaster_Proc"
            cmd.Connection = con
            cmd.Parameters.Add(New SqlParameter("@TechSpec_Kid", SqlDbType.NVarChar, 10)).Value = KID
            cmd.Parameters.Add(New SqlParameter("@TechSpec_Code", SqlDbType.NVarChar, 25)).Value = Generate_Code("Select count(*) from ProductTechnicalSpecification_Master where TechSpec_Code='", "TSM").ToString()
            cmd.Parameters.Add(New SqlParameter("@TechSpec_Parameter", SqlDbType.NVarChar, 200)).Value = StrConv(strParameter.Trim, VbStrConv.ProperCase)
            cmd.Parameters.Add(New SqlParameter("@TechSpec_CategoryId", SqlDbType.NVarChar, 10)).Value = strCategoryID
            cmd.Parameters.Add(New SqlParameter("@TechSpec_CompanyId", SqlDbType.NVarChar, 10)).Value = strCompanyID.ToString
            cmd.Parameters.Add(New SqlParameter("@TechSpec_UserId", SqlDbType.NVarChar, 10)).Value = strUserID.ToString
            cmd.Parameters.Add(New SqlParameter("@TechSpec_FinancialYearId", SqlDbType.NVarChar, 10)).Value = strFinancialYearID.Trim
            cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 50)).Value = "Product Technical Specification Master"
            cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 10)).Value = "Insert"
            Try
                con.Open()
                cmd.ExecuteNonQuery()
                'System.Threading.Thread.Sleep(1000)
                con.Close()
                Return KID
            Catch ex As Exception
                con.Close()
                Return "false"
            End Try
            Return True
        Else
            Return "false"
        End If

    End Function

    Private Sub SetSelectedComboByText(ByVal cmb As DropDownList, ByVal val As String)
        Try
            If cmb.Items.Count > 0 Then
                For i As Integer = 0 To cmb.Items.Count - 1
                    If cmb.Items(i).Text.ToLower = val.ToLower Then
                        cmb.SelectedIndex = i
                        Exit Sub
                    End If
                Next
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub ControlVisible()
        Try

            tblProductInfo.Visible = True
            'tdJJCategorySuggest.Visible = True

            '' For TR Visible for Technical Spec...
            trAddNewParameter.Visible = False
            trProductTechSpec.Visible = True
            '''''''''''''''''''''''''''''''''''''''''
            '' For Guaranty/Warranty ''''''''''''''''
            trGuaranty.Style.Add("display", "none")
            TrWarranty.Style.Add("display", "none")
            rblGW.Attributes.Add("onclick", "return JJrblGW(this);")
            '''''''''''''''''''''''''''''''''''''''''
            '' For Product Installation and Commissioning ''''''
            rblICIsApplicable.Attributes.Add("onclick", "checkrblICIsApplicable(this);")
            rblICIsChargeable.Attributes.Add("onclick", "checkrblICIsChargeable(this);")
            txtICAmount.Attributes.Add("onkeypress", "return blockNonNumbers(this,event,false,false);")
            '''''''''''''''''''''''''''''''''''''''''

        Catch ex As Exception

        End Try
    End Sub

    Private Sub ClearSharedVariable()
        Try
            ViewState("Product_Image") = Nothing
            ViewState("Product_SpecialNotes") = Nothing
            ViewState("Product_MSDS") = Nothing
            ViewState("Product_GuarantyWarranty") = Nothing
            ViewState("Product_Catalog") = Nothing
            ViewState("Product_Certificate") = Nothing
            ViewState("Product_UserManual") = Nothing
            ViewState("Product_Packaging") = Nothing
            ViewState("Product_Installation") = Nothing
        Catch ex As Exception

        End Try
    End Sub

    Private Sub FillCombo(ByVal cmb As DropDownList, ByVal datafield As String, ByVal textfield As String, ByVal sqlQuery As String)
        Try
            Dim dtCmb As DataTable
            dtCmb = ReturnDataTable(sqlQuery)
            cmb.DataSource = dtCmb
            cmb.DataValueField = datafield
            cmb.DataTextField = textfield
            cmb.DataBind()
            cmb.Items.Insert(0, New ListItem("Select", "0"))
        Catch ex As Exception

        End Try
    End Sub

    Private Sub AddProductApplication()
        Try
            If lstApplication.Items.Count > 0 Then
                Dim con As New SqlConnection
                con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")

                For i As Integer = 0 To lstApplication.Items.Count - 1
                    Dim cmd As New SqlCommand
                    cmd.CommandType = CommandType.StoredProcedure
                    cmd.CommandText = "ProductApplication_Proc"                                        'Assign the Name of Stored Procedure, to Execute
                    cmd.Connection = con
                    cmd.Parameters.Add(New SqlParameter("@ProdApp_Kid", SqlDbType.NVarChar, 10)).Value = NewPrimaryKey(Me)
                    Dim Code_App As String = ReturnValue("Declare @Code as nvarchar(50) Select @Code = MAX(ProdApp_Code) from  ProductApplication WHERE ProdApp_Code LIKE" + "'PA" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/%'" + " Select Substring(@Code,len(@Code)-2,4)")
                    cmd.Parameters.Add(New SqlParameter("@ProdApp_Code", SqlDbType.NVarChar, 25)).Value = "PA" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today).ToString & "/" + IIf(Code_App = "", "0000", (Convert.ToInt32(IIf(Code_App = "", "0000", Code_App)) + 1).ToString.PadLeft(4, "0"))
                    'cmd.Parameters.Add(New SqlParameter("@ProdApp_Code", SqlDbType.NVarChar, 25)).Value = Generate_Code("Select count(*) from ProductApplication where ProdApp_Code='", "PA").ToString()
                    cmd.Parameters.Add(New SqlParameter("@ProdApp_Application", SqlDbType.NVarChar, 1000)).Value = lstApplication.Items(i).Text.Trim
                    cmd.Parameters.Add(New SqlParameter("@ProdApp_ProductId", SqlDbType.NVarChar, 10)).Value = RemoveLiterals(Convert.ToString(Session("ProductID")))
                    cmd.Parameters.Add(New SqlParameter("@ProdApp_FinancialYearId", SqlDbType.NVarChar, 10)).Value = Session("g_FinYear")
                    cmd.Parameters.Add(New SqlParameter("@ProdApp_CompanyId", SqlDbType.NVarChar, 10)).Value = Session("g_Company")
                    cmd.Parameters.Add(New SqlParameter("@ProdApp_UserId", SqlDbType.NVarChar, 10)).Value = Session("g_User")
                    cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 50)).Value = "Product Application"
                    cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 50)).Value = "Insert"

                    con.Open()
                    cmd.ExecuteNonQuery()
                    con.Close()
                Next
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub AddProductFeature()
        Try
            If lstProductFeature.Items.Count > 0 Then
                Dim con As New SqlConnection
                con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
               
                For i As Integer = 0 To lstProductFeature.Items.Count - 1
                    Dim cmd As New SqlCommand
                    cmd.CommandType = CommandType.StoredProcedure
                    cmd.CommandText = "ProductFeatures_Proc"
                    cmd.Connection = con
                    cmd.Parameters.Add(New SqlParameter("@ProdFeatures_Kid", SqlDbType.NVarChar, 10)).Value = NewPrimaryKey(Me)
                    Dim Code_App As String = ReturnValue("Declare @Code as nvarchar(50) Select @Code = MAX(ProdFeatures_Code) from  ProductFeatures WHERE ProdFeatures_Code LIKE" + "'PF" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/%'" + " Select Substring(@Code,len(@Code)-2,4)")
                    cmd.Parameters.Add(New SqlParameter("@ProdFeatures_Code", SqlDbType.NVarChar, 25)).Value = "PF" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/" + IIf(Code_App = "", "0000", (Convert.ToInt32(IIf(Code_App = "", "0000", Code_App)) + 1).ToString.PadLeft(4, "0"))
                    'cmd.Parameters.Add(New SqlParameter("@ProdFeatures_Code", SqlDbType.NVarChar, 25)).Value = Generate_Code("Select count(*) from ProductFeatures where ProdFeatures_Code='", "PF").ToString()
                    cmd.Parameters.Add(New SqlParameter("@ProdFeatures_Features", SqlDbType.NVarChar, 1000)).Value = lstProductFeature.Items(i).Text.Trim
                    cmd.Parameters.Add(New SqlParameter("@ProdFeatures_ProductId", SqlDbType.NVarChar, 10)).Value = RemoveLiterals(Convert.ToString(Session("ProductID")))
                    cmd.Parameters.Add(New SqlParameter("@ProdFeatures_FinancialYearId", SqlDbType.NVarChar, 10)).Value = Session("g_FinYear")
                    cmd.Parameters.Add(New SqlParameter("@ProdFeatures_CompanyId", SqlDbType.NVarChar, 10)).Value = Session("g_Company") 'Trim(g_Company)
                    cmd.Parameters.Add(New SqlParameter("@ProdFeatures_UserId", SqlDbType.NVarChar, 10)).Value = Session("g_User")
                    cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 100)).Value = "Product Feature"
                    cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 50)).Value = "Insert"

                    con.Open()
                    cmd.ExecuteNonQuery()
                    con.Close()
                Next
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub AddTechSpec()
        Try
            If lstProductTechSpec.Items.Count > 0 Then
                Dim con As New SqlConnection()
                con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")        'Read the connection string from web.config
               
                For i As Integer = 0 To lstProductTechSpec.Items.Count - 1
                    Dim cmd As New SqlCommand()
                    cmd.CommandType = CommandType.StoredProcedure
                    cmd.CommandText = "ProductTechnicalSpecification_Proc"
                    cmd.Connection = con
                    cmd.Parameters.Add(New SqlParameter("@TechSpec_Kid", SqlDbType.NVarChar, 10)).Value = NewPrimaryKey(Me)
                    Dim Code_App As String = ReturnValue("Declare @Code as nvarchar(50) Select @Code = MAX(TechSpec_Code) from  ProductTechnicalSpecification WHERE TechSpec_Code LIKE" + "'TS" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/%'" + " Select Substring(@Code,len(@Code)-2,4)")
                    cmd.Parameters.Add(New SqlParameter("@TechSpec_Code", SqlDbType.NVarChar, 25)).Value = "TS" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today).ToString & "/" + IIf(Code_App = "", "0000", (Convert.ToInt32(IIf(Code_App = "", "0000", Code_App)) + 1).ToString.PadLeft(4, "0"))

                    Dim Tech() As String
                    Tech = lstProductTechSpec.Items(i).Value.Split("=")
                    cmd.Parameters.Add(New SqlParameter("@TechSpec_value", SqlDbType.NVarChar, 200)).Value = Tech(1).ToString
                    cmd.Parameters.Add(New SqlParameter("@TechSpec_ParameterId", SqlDbType.NVarChar, 10)).Value = Tech(0).ToString
                    cmd.Parameters.Add(New SqlParameter("@TechSpec_ProductId", SqlDbType.NVarChar, 10)).Value = RemoveLiterals(Convert.ToString(Session("ProductID")))
                    cmd.Parameters.Add(New SqlParameter("@TechSpec_FinancialYearId", SqlDbType.NVarChar, 10)).Value = Session("g_FinYear").Trim
                    cmd.Parameters.Add(New SqlParameter("@TechSpec_CompanyId", SqlDbType.NVarChar, 10)).Value = Session("g_Company")
                    cmd.Parameters.Add(New SqlParameter("@TechSpec_UserId", SqlDbType.NVarChar, 10)).Value = Session("g_User")
                    cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 50)).Value = "Product Technical Specification"
                    cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 10)).Value = "Insert"

                    con.Open()
                    cmd.ExecuteNonQuery()
                    con.Close()
                Next

            End If
        Catch
        End Try
    End Sub

    Private Function AddProdSpecInstr() As Boolean
        Try
            If ViewState("Product_SpecialNotes") <> Nothing Then
                Dim con As New SqlConnection()
                con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")        'Read the connection string from web.config
                Dim cmd As New SqlCommand()
                cmd.CommandType = CommandType.StoredProcedure
                cmd.CommandText = "ProductSpecialNotesInstruction_Proc"
                cmd.Connection = con
                cmd.Parameters.Add(New SqlParameter("@ProdSpecInstr_Kid", SqlDbType.NVarChar, 10)).Value = NewPrimaryKey(Me)

                Dim Code_App As String = ReturnValue("Declare @Code as nvarchar(50) Select @Code = MAX(ProdSpecInstr_Code) from  ProductSpecialNotesInstruction WHERE ProdSpecInstr_Code LIKE" + "'TS" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/%'" + " Select Substring(@Code,len(@Code)-2,4)")
                cmd.Parameters.Add(New SqlParameter("@ProdSpecInstr_Code", SqlDbType.NVarChar, 25)).Value = "TS" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today).ToString & "/" + IIf(Code_App = "", "0000", (Convert.ToInt32(IIf(Code_App = "", "0000", Code_App)) + 1).ToString.PadLeft(4, "0"))

                'cmd.Parameters.Add(New SqlParameter("@ProdSpecInstr_Code", SqlDbType.NVarChar, 25)).Value = Generate_Code("Select count(*) from ProductSpecialNotesInstruction where ProdSpecInstr_Code='", "TS").ToString()
                cmd.Parameters.Add(New SqlParameter("@ProdSpecInstr_Instruction", SqlDbType.NVarChar, 1000)).Value = ViewState("Product_SpecialNotes").ToString
                cmd.Parameters.Add(New SqlParameter("@ProdSpecInstr_ProductId", SqlDbType.NVarChar, 10)).Value = RemoveLiterals(Convert.ToString(Session("ProductID")))
                cmd.Parameters.Add(New SqlParameter("@ProdSpecInstr_FileName", SqlDbType.NVarChar, 50)).Value = ViewState("Product_SpecialNotes").ToString
                cmd.Parameters.Add(New SqlParameter("@ProdSpecInstr_FinancialYearId", SqlDbType.NVarChar, 10)).Value = Session("g_FinYear")
                cmd.Parameters.Add(New SqlParameter("@ProdSpecInstr_CompanyId", SqlDbType.NVarChar, 10)).Value = Session("g_Company")
                cmd.Parameters.Add(New SqlParameter("@ProdSpecInstr_UserId", SqlDbType.NVarChar, 10)).Value = Session("g_User")
                cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 50)).Value = "Product Special Notes Instruction"
                cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 50)).Value = "Insert"

                con.Open()
                cmd.ExecuteNonQuery()
                con.Close()

            End If
        Catch
        End Try
    End Function

    Private Sub AddProductMSDS()
        Try
            If ViewState("Product_MSDS") <> Nothing Then
                Dim con As New SqlConnection
                con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
                Dim cmd As New SqlCommand
                cmd.CommandType = CommandType.StoredProcedure
                cmd.CommandText = "MaterialSafetyDataSheet_Proc"
                cmd.Connection = con

                cmd.Parameters.Add(New SqlParameter("@MSDS_Kid", SqlDbType.NVarChar, 20)).Value = NewPrimaryKey(Me)
                cmd.Parameters.Add(New SqlParameter("@MSDS_Code", SqlDbType.NVarChar, 25)).Value = GenerateMSDSCode().ToString
                cmd.Parameters.Add(New SqlParameter("@MSDS_IsDataSheetUpload", SqlDbType.NVarChar, 1)).Value = "Y"
                cmd.Parameters.Add(New SqlParameter("@MSDS_UploadedDataSheetName", SqlDbType.NVarChar, 50)).Value = ViewState("Product_MSDS").ToString

                cmd.Parameters.Add(New SqlParameter("@MSDS_ProductId", SqlDbType.NVarChar, 25)).Value = RemoveLiterals(Convert.ToString(Session("ProductID")))
                cmd.Parameters.Add(New SqlParameter("@MSDS_FinancialYearId", SqlDbType.NVarChar, 20)).Value = Session("g_FinYear")
                cmd.Parameters.Add(New SqlParameter("@MSDS_CompanyId", SqlDbType.NVarChar, 20)).Value = Session("g_Company")
                cmd.Parameters.Add(New SqlParameter("@MSDS_UserId", SqlDbType.NVarChar, 20)).Value = Session("g_User")
                cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 100)).Value = "Material Safety Data Sheet"
                cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 50)).Value = "Insert"
                con.Open()
                cmd.ExecuteNonQuery()
                con.Close()
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Function GenerateMSDSCode() As String
        Try
            Dim code As String
            Dim Code_App As String = ReturnValue("Declare @Code as nvarchar(50) Select @Code = MAX(MSDS_Code) from  MaterialSafetyDataSheet WHERE MSDS_Code LIKE" + "'MSS" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/%'" + " Select Substring(@Code,len(@Code)-2,4)")
            code = "MSS" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today).ToString & "/" + IIf(Code_App = "", "0000", (Convert.ToInt32(IIf(Code_App = "", "0000", Code_App)) + 1).ToString.PadLeft(4, "0"))
            Return code
        Catch ex As Exception

        End Try
    End Function

    Private Sub AddProductGuarantyWarranty()
        Try
            If ViewState("Product_GuarantyWarranty") <> Nothing Then
                Dim con As New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionString"))
                Dim strproc As String = "Product_GuarantyWarrantyDetails_Proc"
                Dim cmd As New SqlCommand(strproc, con)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add(New SqlParameter("@gwd_Kid", SqlDbType.NVarChar, 10)).Value = NewPrimaryKey(Me).Trim
                cmd.Parameters.Add(New SqlParameter("@gwd_Code", SqlDbType.NVarChar, 25)).Value = GenerateCodeGW("GWC").ToString()
                cmd.Parameters.Add(New SqlParameter("@gwd_Type", SqlDbType.NVarChar, 20)).Value = rblGW.SelectedItem.Value.ToString
                cmd.Parameters.Add(New SqlParameter("@gwd_ProductId", SqlDbType.NVarChar, 18)).Value = RemoveLiterals(Convert.ToString(Session("ProductID")))
                cmd.Parameters.Add(New SqlParameter("@gwd_FileName", SqlDbType.NVarChar, 50)).Value = ViewState("Product_GuarantyWarranty").ToString

                If rblGW.SelectedItem.Value = "Guaranty" Then
                    cmd.Parameters.Add(New SqlParameter("@gwd_pguarentee1", SqlDbType.NVarChar, 18)).Value = txtGuaranty.Text.Trim
                    cmd.Parameters.Add(New SqlParameter("@gwd_pguarentee2", SqlDbType.NVarChar, 18)).Value = ddlGuarantyType.SelectedValue.Trim
                Else
                    cmd.Parameters.Add(New SqlParameter("@gwd_pwarranty1", SqlDbType.NVarChar, 18)).Value = txtWarranty.Text.ToString
                    cmd.Parameters.Add(New SqlParameter("@gwd_pwarranty2", SqlDbType.NVarChar, 10)).Value = ddlWarrantyType.SelectedItem.Value.ToString
                End If
                cmd.Parameters.Add(New SqlParameter("@gwd_OMT", SqlDbType.NVarChar, 25)).Value = rblGWIsTraining.SelectedValue.ToString
                cmd.Parameters.Add(New SqlParameter("@gwd_AMC", SqlDbType.NVarChar, 25)).Value = rblGWIsContract.SelectedValue.ToString
                cmd.Parameters.Add(New SqlParameter("@gwd_FinancialYearId", SqlDbType.NVarChar, 25)).Value = Session("g_FinYear").ToString.Trim
                cmd.Parameters.Add(New SqlParameter("@gwd_CompanyId", SqlDbType.NVarChar, 10)).Value = Session("g_Company").Trim
                cmd.Parameters.Add(New SqlParameter("@gwd_UserId", SqlDbType.NVarChar, 10)).Value = Session("g_User").Trim
                cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 10)).Value = Me.Title.ToString.Trim
                cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.NVarChar, 10)).Value = "Insert"

                con.Open()
                cmd.ExecuteNonQuery()
                con.Close()
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Function GenerateCodeGW(ByRef code As String) As String
        Try
            Dim code1 As String
            Dim Code_App As String = ReturnValue("Declare @Code as nvarchar(50) Select @Code = MAX(gwd_Code) from  Product_GuarantyWarrantyDetails WHERE gwd_Code LIKE" + "'GWC" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/%'" + " Select Substring(@Code,len(@Code)-2,4)")
            code1 = "GWC" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today).ToString & "/" + IIf(Code_App = "", "0000", (Convert.ToInt32(IIf(Code_App = "", "0000", Code_App)) + 1).ToString.PadLeft(4, "0"))
            Return code1
        Catch ex As Exception

        End Try
    End Function

    Private Sub AddProductCatalog()
        Try
            If ViewState("Product_Catalog") <> Nothing Then
                Dim con As New SqlConnection
                con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")

                Dim cmd As New SqlCommand
                cmd.CommandType = CommandType.StoredProcedure
                cmd.CommandText = "Catalog_Proc"
                cmd.Connection = con

                cmd.Parameters.Add(New SqlParameter("@Catalog_kid", SqlDbType.NVarChar, 20)).Value = NewPrimaryKey(Me)
                cmd.Parameters.Add(New SqlParameter("@Catalog_code", SqlDbType.NVarChar, 25)).Value = GenerateCatalogCode().ToString

                cmd.Parameters.Add(New SqlParameter("@Catalog_pcatalog", SqlDbType.NVarChar, 1)).Value = "Y"
                cmd.Parameters.Add(New SqlParameter("@Catalog_upload", SqlDbType.NVarChar, 100)).Value = ViewState("Product_Catalog").ToString
                cmd.Parameters.Add(New SqlParameter("@Catalog_Adminupload", SqlDbType.NVarChar, 100)).Value = ""
                cmd.Parameters.Add(New SqlParameter("@Catalog_productid", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Convert.ToString(Session("ProductID")))
                cmd.Parameters.Add(New SqlParameter("@Catalog_companyid", SqlDbType.NVarChar, 20)).Value = Session("g_Company")
                cmd.Parameters.Add(New SqlParameter("@Catalog_userid", SqlDbType.NVarChar, 20)).Value = Session("g_User")
                cmd.Parameters.Add(New SqlParameter("@Catalog_financialyearid", SqlDbType.NVarChar, 20)).Value = Session("g_FinYear")
                cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 100)).Value = "Catalog"
                cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 10)).Value = "Insert"
                con.Open()
                cmd.ExecuteNonQuery()
                con.Close()
            End If

        Catch ex As Exception

        End Try
    End Sub

    Protected Function GenerateCatalogCode() As String
        Try
            Dim code As String
            Dim Code_App As String = ReturnValue("Declare @Code as nvarchar(50) Select @Code = MAX(Catalog_code) from  Catalog WHERE Catalog_code LIKE" + "'CAT" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/%'" + " Select Substring(@Code,len(@Code)-2,4)")
            code = "CAT" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today).ToString & "/" + IIf(Code_App = "", "0000", (Convert.ToInt32(IIf(Code_App = "", "0000", Code_App)) + 1).ToString.PadLeft(4, "0"))
            Return code
        Catch ex As Exception

        End Try
    End Function

    Private Sub AddProductCertificate()
        Try
            If ViewState("Product_Certificate") <> Nothing Then
                Dim con As New SqlConnection
                con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")

                Dim cmd As New SqlCommand
                cmd.CommandType = CommandType.StoredProcedure
                cmd.CommandText = "ProductStandardApproval_Proc"
                cmd.Connection = con

                cmd.Parameters.Add(New SqlParameter("@ProdStdApproval_Kid", SqlDbType.NVarChar, 10)).Value = NewPrimaryKey(Me)
                cmd.Parameters.Add(New SqlParameter("@ProdStdApproval_Code", SqlDbType.NVarChar, 25)).Value = GenerateProdStdAppCode().ToString
                cmd.Parameters.Add(New SqlParameter("@ProdStdApproval_StandardName", SqlDbType.NVarChar, 200)).Value = ""
                cmd.Parameters.Add(New SqlParameter("@ProdStdApproval_AgencyApproved", SqlDbType.NVarChar, 200)).Value = ""
                cmd.Parameters.Add(New SqlParameter("@ProdStdApproval_ProductId", SqlDbType.NVarChar, 10)).Value = RemoveLiterals(Convert.ToString(Session("ProductID")))
                cmd.Parameters.Add(New SqlParameter("@ProdStdApproval_FileName", SqlDbType.NVarChar, 100)).Value = ViewState("Product_Certificate").ToString
                cmd.Parameters.Add(New SqlParameter("@ProdStdApproval_AdminFileName", SqlDbType.NVarChar, 20)).Value = ""
                cmd.Parameters.Add(New SqlParameter("@ProdStdApproval_StandardId", SqlDbType.NVarChar, 10)).Value = "Select"
                cmd.Parameters.Add(New SqlParameter("@ProdStdApproval_FinancialYearId", SqlDbType.NVarChar, 10)).Value = Session("g_FinYear")
                cmd.Parameters.Add(New SqlParameter("@ProdStdApproval_CompanyId", SqlDbType.NVarChar, 10)).Value = Session("g_Company")
                cmd.Parameters.Add(New SqlParameter("@ProdStdApproval_UserId", SqlDbType.NVarChar, 10)).Value = Session("g_User")
                cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 50)).Value = "Product Standard Approval"
                cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.NVarChar, 10)).Value = "Insert"
                con.Open()
                cmd.ExecuteNonQuery()
                con.Close()
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Function GenerateProdStdAppCode() As String
        Try
            Dim code As String
            Dim Code_App As String = ReturnValue("Declare @Code as nvarchar(50) Select @Code = MAX(ProdStdApproval_Code) from  ProductStandardApproval WHERE ProdStdApproval_Code LIKE" + "'PSA" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/%'" + " Select Substring(@Code,len(@Code)-2,4)")
            code = "PSA" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today).ToString & "/" + IIf(Code_App = "", "0000", (Convert.ToInt32(IIf(Code_App = "", "0000", Code_App)) + 1).ToString.PadLeft(4, "0"))
            Return code
        Catch ex As Exception

        End Try

    End Function

    Private Sub AddProductUserManual()
        Try
            If ViewState("Product_UserManual") <> Nothing Then
                Dim con As New SqlConnection
                con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
                Dim cmd As New SqlCommand
                cmd.CommandType = CommandType.StoredProcedure
                cmd.CommandText = "InstallationManual_Proc"
                cmd.Connection = con

                cmd.Parameters.Add(New SqlParameter("@InstCommManual_Kid", SqlDbType.NVarChar, 20)).Value = NewPrimaryKey(Me)
                cmd.Parameters.Add(New SqlParameter("@InstCommManual_Code", SqlDbType.NVarChar, 25)).Value = GenerateUMCode().ToString()

                cmd.Parameters.Add(New SqlParameter("@InstCommManual_IsManualUpload", SqlDbType.NVarChar, 1)).Value = "Y"
                cmd.Parameters.Add(New SqlParameter("@InstCommManual_UploadedManualFileName", SqlDbType.NVarChar, 50)).Value = ViewState("Product_UserManual").ToString
                cmd.Parameters.Add(New SqlParameter("@InstCommManual_AdminUploadedManualFileName", SqlDbType.NVarChar, 50)).Value = ""
                cmd.Parameters.Add(New SqlParameter("@InstCommManual_ProductId", SqlDbType.NVarChar, 25)).Value = RemoveLiterals(Convert.ToString(Session("ProductID")))
                cmd.Parameters.Add(New SqlParameter("@InstCommManual_FinancialYearId", SqlDbType.NVarChar, 20)).Value = Session("g_FinYear")
                cmd.Parameters.Add(New SqlParameter("@InstCommManual_CompanyId", SqlDbType.NVarChar, 20)).Value = Session("g_Company")
                cmd.Parameters.Add(New SqlParameter("@InstCommManual_UserId", SqlDbType.NVarChar, 20)).Value = Session("g_User")
                cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 100)).Value = "Installation Manual"
                cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 50)).Value = "Insert"
                con.Open()
                cmd.ExecuteNonQuery()
                con.Close()
            End If
            
        Catch ex As Exception

        End Try
    End Sub

    Protected Function GenerateUMCode() As String
        Try
          
            Dim code As String
            Dim Code_App As String = ReturnValue("Declare @Code as nvarchar(50) Select @Code = MAX(InstCommManual_Code) from  InstallationManual WHERE InstCommManual_Code LIKE" + "'ICM" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/%'" + " Select Substring(@Code,len(@Code)-2,4)")
            code = "ICM" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today).ToString & "/" + IIf(Code_App = "", "0000", (Convert.ToInt32(IIf(Code_App = "", "0000", Code_App)) + 1).ToString.PadLeft(4, "0"))
            Return code
        Catch ex As Exception

        End Try
    End Function

    Private Sub AddProductPackaging()
        Try
            If ViewState("Product_Packaging") <> Nothing Then
                Dim con As New SqlConnection
                con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
                Dim cmd As New SqlCommand
                cmd.CommandType = CommandType.StoredProcedure
                cmd.CommandText = "ProductPackaging_Proc"
                cmd.Connection = con
                cmd.Parameters.Add(New SqlParameter("@ProdPackaging_Kid", SqlDbType.NVarChar, 20)).Value = NewPrimaryKey(Me)
                cmd.Parameters.Add(New SqlParameter("@ProdPackaging_Code", SqlDbType.NVarChar, 20)).Value = GeneratePckDetailsCode().ToString

                If rblIsFragile.SelectedValue = "Yes" Then
                    cmd.Parameters.Add(New SqlParameter("@ProdPackaging_IsFragile", SqlDbType.NVarChar, 25)).Value = "Y"
                Else
                    cmd.Parameters.Add(New SqlParameter("@ProdPackaging_IsFragile", SqlDbType.NVarChar, 25)).Value = "N"
                End If
                If rblIsWood.SelectedValue = "Yes" Then
                    cmd.Parameters.Add(New SqlParameter("@ProdPackaging_IsWoodContain", SqlDbType.NVarChar, 25)).Value = "Y"
                Else
                    cmd.Parameters.Add(New SqlParameter("@ProdPackaging_IsWoodContain", SqlDbType.NVarChar, 25)).Value = "N"
                End If
                If rblIsEnvironmental.SelectedValue = "Yes" Then
                    cmd.Parameters.Add(New SqlParameter("@ProdPackaging_IsEnvirnomentalFriendly", SqlDbType.NVarChar, 25)).Value = "Y"
                Else
                    cmd.Parameters.Add(New SqlParameter("@ProdPackaging_IsEnvirnomentalFriendly", SqlDbType.NVarChar, 25)).Value = "N"
                End If
                cmd.Parameters.Add(New SqlParameter("@ProdPackaging_ProdDetails", SqlDbType.NVarChar, 200)).Value = IIf(txtPackgingDetails.Text.ToString.Trim = "", Nothing, txtPackgingDetails.Text.ToString.Trim)
                cmd.Parameters.Add(New SqlParameter("@ProdPackaging_ProductId", SqlDbType.NVarChar, 25)).Value = RemoveLiterals(Convert.ToString(Session("ProductID")))
                cmd.Parameters.Add(New SqlParameter("@ProdPackaging_FileName", SqlDbType.NVarChar, 100)).Value = ViewState("Product_Packaging").ToString
                cmd.Parameters.Add(New SqlParameter("@ProdPackaging_FinancialYearId", SqlDbType.NVarChar, 20)).Value = Session("g_FinYear")
                cmd.Parameters.Add(New SqlParameter("@ProdPackaging_CompanyId", SqlDbType.NVarChar, 20)).Value = Session("g_Company")
                cmd.Parameters.Add(New SqlParameter("@ProdPackaging_UserId", SqlDbType.NVarChar, 20)).Value = Session("g_User")
                cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 100)).Value = "Product Packaging"
                cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 50)).Value = "Insert"

                con.Open()
                cmd.ExecuteNonQuery()
                con.Close()
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Function GeneratePckDetailsCode() As String
        Try
            Dim code As String
            Dim Code_App As String = ReturnValue("Declare @Code as nvarchar(50) Select @Code = MAX(ProdPackaging_Code) from  ProductPackaging WHERE ProdPackaging_Code LIKE" + "'PKG" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/%'" + " Select Substring(@Code,len(@Code)-2,4)")
            code = "PKG" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today).ToString & "/" + IIf(Code_App = "", "0000", (Convert.ToInt32(IIf(Code_App = "", "0000", Code_App)) + 1).ToString.PadLeft(4, "0"))
            Return code
        Catch
        End Try
    End Function

    Private Sub AddProductConsumable()
        Try
            If lstConsumableList.Items.Count > 0 Then
                Dim con As New SqlConnection
                con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
                For i As Integer = 0 To lstConsumableList.Items.Count - 1
                    Dim cmd As New SqlCommand
                    cmd.CommandType = CommandType.StoredProcedure
                    cmd.CommandText = "Consumables_Proc"
                    cmd.Connection = con
                    cmd.Parameters.Add(New SqlParameter("@c_kid", SqlDbType.NVarChar, 20)).Value = NewPrimaryKey(Me)
                    cmd.Parameters.Add(New SqlParameter("@c_code", SqlDbType.NVarChar, 25)).Value = GenerateConsumableCode().ToString
                    cmd.Parameters.Add(New SqlParameter("@c_productid", SqlDbType.NVarChar, 20)).Value = RemoveLiterals(Convert.ToString(Session("ProductID")))
                    Dim Consum() As String
                    Consum = lstConsumableList.Items(i).Text.Split("=")
                    cmd.Parameters.Add(New SqlParameter("@c_cname", SqlDbType.NVarChar, 150)).Value = Consum(0).ToString.Trim
                    cmd.Parameters.Add(New SqlParameter("@c_cquantity", SqlDbType.NVarChar, 100)).Value = Consum(1).ToString.Trim
                    cmd.Parameters.Add(New SqlParameter("@c_companyid", SqlDbType.NVarChar, 20)).Value = Session("g_Company")
                    cmd.Parameters.Add(New SqlParameter("@c_userid", SqlDbType.NVarChar, 20)).Value = Session("g_User")
                    cmd.Parameters.Add(New SqlParameter("@c_financialyearid", SqlDbType.NVarChar, 20)).Value = Session("g_FinYear")
                    cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 50)).Value = "Consumables"
                    cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 10)).Value = "Insert"
                    con.Open()
                    cmd.ExecuteNonQuery()
                    con.Close()
                Next
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Function GenerateConsumableCode() As String
        Try
          
            Dim code As String
            Dim Code_App As String = ReturnValue("Declare @Code as nvarchar(50) Select @Code = MAX(c_code) from  Consumables WHERE c_code LIKE" + "'CON" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/%'" + " Select Substring(@Code,len(@Code)-2,4)")
            code = "CON" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today).ToString & "/" + IIf(Code_App = "", "0000", (Convert.ToInt32(IIf(Code_App = "", "0000", Code_App)) + 1).ToString.PadLeft(4, "0"))
            Return code
        Catch ex As Exception

        End Try
    End Function

    Private Sub AddProductCommission()
        Try
            If ViewState("Product_Installation") <> Nothing Then
                Dim con As New SqlConnection
                con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")

                Dim cmd As New SqlCommand
                cmd.CommandText = "ProductInstallationCommissioning_Proc"
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Connection = con

                cmd.Parameters.Add(New SqlParameter("@InstallationComm_Kid", SqlDbType.NVarChar, 10)).Value = NewPrimaryKey(Me)
                cmd.Parameters.Add(New SqlParameter("@InstallationComm_Code", SqlDbType.NVarChar, 25)).Value = GenerateCodeIC().ToString()
                cmd.Parameters.Add(New SqlParameter("@InstallationComm_IsRequired", SqlDbType.NVarChar, 1)).Value = rblICIsApplicable.SelectedValue.ToString

                If rblICIsApplicable.SelectedValue = "Y" Then
                    cmd.Parameters.Add(New SqlParameter("@InstallationComm_IsChargeable", SqlDbType.NVarChar, 1)).Value = rblICIsChargeable.SelectedValue.ToString
                    If rblICIsChargeable.SelectedValue = "Y" Then
                        cmd.Parameters.Add(New SqlParameter("@InstallationComm_Amount", SqlDbType.NVarChar, 18)).Value = txtICAmount.Text
                    End If

                Else

                End If
                cmd.Parameters.Add(New SqlParameter("@InstallationComm_ProductId", SqlDbType.NVarChar, 10)).Value = RemoveLiterals(Convert.ToString(Session("ProductID")))
                cmd.Parameters.Add(New SqlParameter("@InstallationComm_FileName", SqlDbType.NVarChar, 100)).Value = ViewState("Product_Installation").ToString
                cmd.Parameters.Add(New SqlParameter("@InstallationComm_FinancialYearId", SqlDbType.NVarChar, 50)).Value = Session("g_FinYear")
                cmd.Parameters.Add(New SqlParameter("@InstallationComm_CompanyId", SqlDbType.NVarChar, 10)).Value = Session("g_Company")
                cmd.Parameters.Add(New SqlParameter("@InstallationComm_UserId", SqlDbType.NVarChar, 10)).Value = Session("g_User")
                cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 100)).Value = Me.Title.ToString
                cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.NVarChar, 20)).Value = "Insert"
                con.Open()
                cmd.ExecuteNonQuery()
                con.Close()
            End If
            
        Catch ex As Exception

        End Try
    End Sub

    Protected Function GenerateCodeIC() As String
        Try
            Dim code As String
            Dim Code_App As String = ReturnValue("Declare @Code as nvarchar(50) Select @Code = MAX(ProductDrawing_Code) from  ProductDrawing WHERE ProductDrawing_Code LIKE" + "'PRD" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/%'" + " Select Substring(@Code,len(@Code)-2,4)")
            code = "PRD" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today).ToString & "/" + IIf(Code_App = "", "0000", (Convert.ToInt32(IIf(Code_App = "", "0000", Code_App)) + 1).ToString.PadLeft(4, "0"))
            Return code
        Catch ex As Exception

        End Try
    End Function

    Public Sub InsertProductCategoryMaster()
        ExecuteQuery("insert into ProductCategory_Master values('" & NewPrimaryKey(Me) & "','" & RemoveLiterals(Session("ProductID").ToString) & "','" & RemoveLiterals(Session("CategoryId").ToString) & "') ")
        Dim i As Integer
        For i = 0 To chkCategory.Items.Count - 1
            If chkCategory.Items(i).Selected = True Then
                ExecuteQuery("insert into ProductCategory_Master values('" & NewPrimaryKey(Me) & "','" & RemoveLiterals(Session("ProductID").ToString) & "','" & RemoveLiterals(chkCategory.Items(i).Value.ToString) & "') ")
            End If
        Next
        chkCategory.Visible = False
    End Sub

    '------updated by Prachi - 28/08/2009 - to save product partially------
    <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)> _
    Public Function InsertProductName(ByVal prodName As String, ByVal suppId As String) As String
        Try
            Session("ProductName") = Nothing
            If prodName <> "" Then
                Dim prodID As String
                prodID = NewPrimaryKey(Me)
                Session("ProductID") = prodID
                Session("ProductName") = prodName
                ExecuteQuery("insert into Product_Master(Product_Kid, Product_Name, Product_RegDate, Product_SupplierId, Product_CategoryId, Product_Approved, Product_FinancialYearId, Product_CompanyId, Product_UserId, Product_IsDeleted, Product_ClientIP) values('" & prodID & "','" & prodName & "','" & Date.Now & "','" & suppId & "','" & RemoveLiterals(Session("CategoryId").ToString.Trim) & "','C','" & RemoveLiterals(Session("g_FinYear").ToString.Trim) & "','" & RemoveLiterals(Session("g_Company").ToString.Trim) & "','" & RemoveLiterals(Session("g_User").ToString.Trim) & "','0','" & clientIP & "')")
            End If
        Catch ex As Exception

        End Try
    End Function

    <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _
    Public Sub InsertProductDescription(ByVal prodDescription As String)
        Try
            If Session("ProductID") Is Nothing Then
                CreateMessageAlert(Me, "Please Enter Product Name first", "strkeyval")
            Else
                If prodDescription <> "" Then
                    ExecuteQuery("update Product_Master set Product_Description = '" & prodDescription & "' where Product_Kid = '" & RemoveLiterals(Session("ProductID").ToString.Trim) & "'")
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _
    Public Sub InsertPrice(ByVal price As String)
        Try
            If Session("ProductID") Is Nothing Then
                CreateMessageAlert(Me, "Please Enter Product Name first", "strkeyval")
            Else
                If price <> "" Then
                    ExecuteQuery("update Product_Master set Product_MarketPrice = '" & price & "' where Product_Kid = '" & RemoveLiterals(Session("ProductID").ToString.Trim) & "'")
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _
    Public Sub InsertPriceType(ByVal priceType As String)
        Try
            If Session("ProductID") Is Nothing Then
                CreateMessageAlert(Me, "Please Enter Product Name first", "strkeyval")
            Else
                If priceType <> "" Then
                    ExecuteQuery("update Product_Master set Product_MarketPriceType = '" & priceType & "' where Product_Kid = '" & RemoveLiterals(Session("ProductID").ToString.Trim) & "'")
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _
    Public Sub InsertBrand(ByVal brandId As String)
        Try
            If Session("ProductID") Is Nothing Then
                CreateMessageAlert(Me, "Please Enter Product Name first", "strkeyval")
            Else
                If brandId <> "" Then
                    ExecuteQuery("update Product_Master set Product_BrandId = '" & brandId & "' where Product_Kid = '" & RemoveLiterals(Session("ProductID").ToString.Trim) & "'")
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _
    Public Function CheckModelNoExist(ByVal suppId As String, ByVal model As String) As String
        Try
            If Session("ProductID") Is Nothing Then
                CreateMessageAlert(Me, "Please Enter Product Name first", "strkeyval")
            Else
                If model <> "" Then
                    Dim ModelNo As String
                    ModelNo = ReturnValue("SELECT Product_Name FROM Product_Master Where Product_ModelNo='" & model.Trim & "' And Product_SupplierId='" & RemoveLiterals(suppId.Trim) & "'")

                    If ModelNo = "" Then
                        ExecuteQuery("update Product_Master set Product_ModelNo = '" & model & "' where Product_Kid = '" & RemoveLiterals(Session("ProductID").ToString.Trim) & "'")
                    End If
                    Return ModelNo
                End If
            End If
        Catch ex As Exception

        End Try
    End Function

    <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _
    Public Sub InsertSellQty(ByVal sellQty As String)
        Try
            If Session("ProductID") Is Nothing Then
                CreateMessageAlert(Me, "Please Enter Product Name first", "strkeyval")
            Else
                If sellQty <> "" Then
                    ExecuteQuery("update Product_Master set Product_MinOrderQty = '" & sellQty & "' where Product_Kid = '" & RemoveLiterals(Session("ProductID").ToString.Trim) & "'")
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _
    Public Sub InsertSellQtyType(ByVal sellQtyType As String)
        Try
            If Session("ProductID") Is Nothing Then
                CreateMessageAlert(Me, "Please Enter Product Name first", "strkeyval")
            Else
                If sellQtyType <> "" Then
                    ExecuteQuery("update Product_Master set Product_MinOrderQtyType = '" & sellQtyType & "' where Product_Kid = '" & RemoveLiterals(Session("ProductID").ToString.Trim) & "'")
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _
    Public Sub InsertShipQty(ByVal shipQty As String)
        Try
            If Session("ProductID") Is Nothing Then
                CreateMessageAlert(Me, "Please Enter Product Name first", "strkeyval")
            Else
                If shipQty <> "" Then
                    ExecuteQuery("update Product_Master set Product_ShippingQty = '" & shipQty & "' where Product_Kid = '" & RemoveLiterals(Session("ProductID").ToString.Trim) & "'")
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _
    Public Sub InsertShipQtyType(ByVal shipQtyType As String)
        Try
            If Session("ProductID") Is Nothing Then
                CreateMessageAlert(Me, "Please Enter Product Name first", "strkeyval")
            Else
                If shipQtyType <> "" Then
                    ExecuteQuery("update Product_Master set Product_ShippingQtyType = '" & shipQtyType & "' where Product_Kid = '" & RemoveLiterals(Session("ProductID").ToString.Trim) & "'")
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)> _
    Public Sub InsertDimension(ByVal dimenH As String, ByVal dimenW As String, ByVal dimenL As String)
        Try
            If Session("ProductID") Is Nothing Then
                CreateMessageAlert(Me, "Please Enter Product Name first", "strkeyval")
            Else
                If dimenH <> "" And dimenW <> "" And dimenL <> "" Then
                    Dim dimension As String
                    dimension = dimenH + "x" + dimenW + "x" + dimenL
                    ExecuteQuery("update Product_Master set Product_Dimension = '" & dimension & "', Product_DimensionUnitId = '00001:<' where Product_Kid = '" & RemoveLiterals(Session("ProductID").ToString.Trim) & "'")
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _
    Public Sub InsertShipWeight(ByVal shipWeight As String)
        Try
            If Session("ProductID") Is Nothing Then
                CreateMessageAlert(Me, "Please Enter Product Name first", "strkeyval")
            Else
                If shipWeight <> "" Then
                    ExecuteQuery("update Product_Master set Product_Weight = '" & shipWeight & "' where Product_Kid = '" & RemoveLiterals(Session("ProductID").ToString.Trim) & "'")
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _
    Public Sub InsertShipWeightType(ByVal shipWeightType As String)
        Try
            If Session("ProductID") Is Nothing Then
                CreateMessageAlert(Me, "Please Enter Product Name first", "strkeyval")
            Else
                If shipWeightType <> "" Then
                    ExecuteQuery("update Product_Master set Product_WeightUnitId = '" & shipWeightType & "' where Product_Kid = '" & RemoveLiterals(Session("ProductID").ToString.Trim) & "'")
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _
    Public Sub InsertDispatchIn(ByVal dispatchIn As String)
        Try
            If Session("ProductID") Is Nothing Then
                CreateMessageAlert(Me, "Please Enter Product Name first", "strkeyval")
            Else
                If dispatchIn <> "" Then
                    ExecuteQuery("update Product_Master set Product_DeliveryPeriod = '" & dispatchIn & "' where Product_Kid = '" & RemoveLiterals(Session("ProductID").ToString.Trim) & "'")
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _
    Public Sub InsertDispatchInType(ByVal dispatchInType As String)
        Try
            If Session("ProductID") Is Nothing Then
                CreateMessageAlert(Me, "Please Enter Product Name first", "strkeyval")
            Else
                If dispatchInType <> "" Then
                    ExecuteQuery("update Product_Master set Product_DeliveryPeriodType = '" & dispatchInType & "' where Product_Kid = '" & RemoveLiterals(Session("ProductID").ToString.Trim) & "'")
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _
    Public Sub InsertPcsPckg(ByVal pcsPckg As String)
        Try
            If Session("ProductID") Is Nothing Then
                CreateMessageAlert(Me, "Please Enter Product Name first", "strkeyval")
            Else
                If pcsPckg <> "" Then
                    ExecuteQuery("update Product_Master set Product_PcsPerKg = '" & pcsPckg & "' where Product_Kid = '" & RemoveLiterals(Session("ProductID").ToString.Trim) & "'")
                End If
            End If
        Catch ex As Exception

        End Try
    End Sub '------end update------
#End Region

End Class
