Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Net.Mail
Imports System.Web.Mail

Partial Class product_inquiry
    Inherits System.Web.UI.Page
    Dim Inquiry As New clsCRMInquiry
    Dim CRM As New clsCRMProspects
    Shared Category(10) As String
    Shared i As Integer
    Dim value As String
    Dim objProduct As New clsProductInquiry '------Updated By Prachi - 21/08/2009------

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            '------Updated By Prachi - 21/08/2009 - to bind dropdown with table------
            FillContactPersonTitle()
            FillQtyRequiredUnit()
            '------end update------

            'Response.Write(Session("ProductCode"))
            txtCompanyName.Focus()
            i = 0
            If Request.QueryString("StID") <> Nothing Then
                Session("ProductCode") = Request.QueryString("StID").ToString
            End If

            If Request.QueryString("product-code") <> Nothing Then
                Session("ProductCode") = DecodeURL((Request.QueryString("product-code")))
            End If

            'If ViewState("catid") = Nothing Then
            Session("catid") = ReturnValue("Select Product_CategoryID from Product_Master where Product_Kid= '" & RemoveLiterals(Session("ProductCode").ToString()) & "'and Product_IsDeleted='0'")
            'End If

            ' get categoryid according productid
            FillCategoryName(Session("catid"))
            getlbl()
            btnCancel.Attributes.Add("onclick", "javascript:window.close();")
            'Fill_Combo("SELECT distinct Unit_Kid, Unit_Name, Unit_Flag FROM Unit_Master WHERE Unit_Flag = N'Qty' and unit_IsDeleted='0' order by unit_name", ddlQtyType)
            Image1.Attributes.Add("onmouseOver", "javascript:over(this)")
            btnClose.Attributes.Add("onclick", "javascript:window.close();")

            '------updated by Prachi - 26/08/2009 - to allow key like backspace, delete------
            'txtCountryCode.Attributes.Add("onkeypress", "return numericonly(event,this);")
            'txtCityCode.Attributes.Add("onkeypress", "return numericonly(event,this);")
            'txtPhoneNo.Attributes.Add("onkeypress", "return numericonly(event,this);")
            'txtCountryCodeM.Attributes.Add("onkeypress", "return numericonly(event,this);")
            'txtMobileNo.Attributes.Add("onkeypress", "return numericonly(event,this);")
            'txtQtyRequired.Attributes.Add("onkeypress", "return decimalonly(event,this);")
            txtCountryCode.Attributes.Add("blockNonNumbers", "return blockNonNumbers(this,event,false,false);")
            txtCityCode.Attributes.Add("onkeypress", "return blockNonNumbers(this,event,false,false);")
            txtPhoneNo.Attributes.Add("onkeypress", "return blockNonNumbers(this,event,false,false);")
            txtCountryCodeM.Attributes.Add("onkeypress", "return blockNonNumbers(this,event,false,false);")
            txtMobileNo.Attributes.Add("onkeypress", "return blockNonNumbers(this,event,false,false);")
            txtQtyRequired.Attributes.Add("onkeypress", "return blockNonNumbers(this,event,true,false);")
            '------end update------

            'txtCityCode.Attributes.Add("onkeydown", "return testmobile(document.getElementById('txtCountryCode'));")
            'txtMobileNo.Attributes.Add("onkeydown", "return testmobile(document.getElementById('txtCountryCodeM'));")
            'txtPhoneNo.Attributes.Add("onkeydown", "return testphone(document.getElementById('txtCountryCode'),document.getElementById('txtCityCode'));")

            txtCountryCode.Text = "91"
            txtCountryCodeM.Text = "91"
            tbl1.Visible = False
            value = Request.QueryString("flag")

            If Session("BuyId") <> Nothing And value = "Buyer" Then
                fillbuyerinfo()
            End If
            'Image1.Attributes.Add("onmouseOut", "javascript:out(this)")
        End If
        lblMsg.Visible = False
    End Sub

    Protected Sub fillbuyerinfo()
        Dim dt As DataTable
        Dim str As String
        str = "select BuyerRegister_Name,BuyerRegister_EmailId,BuyerRegister_CompanyName,BuyerRegister_TelephoneNo,BuyerRegister_MobileNo from BuyerRegister where BuyerRegister_Kid='" & Session("BuyId") & "'"
        dt = ReturnDataTable(str)
        txtCompanyName.Text = dt.Rows(0).Item("BuyerRegister_CompanyName")
        txtContactPersonName.Text = dt.Rows(0).Item("BuyerRegister_Name")
        txtEmailID.Text = dt.Rows(0).Item("BuyerRegister_EmailId")
        txtQtyRequired.Text = "1"
        Dim tele As String
        tele = dt.Rows(0).Item("BuyerRegister_TelephoneNo")
        Dim teleno = Split(tele, "-")
        txtCityCode.Text = teleno(1)
        txtPhoneNo.Text = teleno(2)
        Dim mob As String
        mob = dt.Rows(0).Item("BuyerRegister_MobileNo")
        Dim mobno = Split(mob, "-")
        txtMobileNo.Text = mobno(1)
    End Sub

    Public Sub getlbl()
        lblProductName.Text = ReturnValue("Select Product_Name From Product_Master where Product_Kid = '" & RemoveLiterals(Session("ProductCode").ToString.Trim) & "' and Product_IsDeleted ='0'")
        lblProductCode.Text = ReturnValue("Select Product_Code From Product_Master where Product_Kid = '" & RemoveLiterals(Session("ProductCode").ToString.Trim) & "' and Product_IsDeleted ='0'")
        lblModelNo.Text = ReturnValue("Select Product_ModelNo From Product_Master where Product_Kid = '" & RemoveLiterals(Session("ProductCode").ToString.Trim) & "' and Product_IsDeleted ='0'")
    End Sub

    Public Sub FillCategoryName(ByVal Catid As String)
        ' Fill category herarchy in label
        Try
            Dim dt As DataTable
            dt = ReturnDataTable("Select * From Category_Master Where Category_Kid ='" & Catid & "' and Category_Isdeleted = '0'")
            Dim ParentId As String
            ParentId = dt.Rows(0).Item(3).ToString()
            If ParentId = "Root Category" Then
                Dim j As Integer
                Category(i) = dt.Rows(0).Item(2).ToString() & "  >  "
                For j = 0 To i
                    lblCat.Text += Category(i)
                    i = i - 1
                Next
                Exit Sub
            Else
                Category(i) = dt.Rows(0).Item(2).ToString() & "  >  "
                i = i + 1
                FillCategoryName(dt.Rows(0).Item(3).ToString())
            End If
            dt.Clear()
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Try
            'If CheckValid() = True Then
            ' lblError.Visible = False

            If txtQtyRequired.Text <> "" Then
                If ddlQtyType.SelectedIndex = 0 Then
                    showmessage("Please Select Unit.", lblMsg)
                    ScriptManager1.SetFocus(ddlQtyType)
                    Exit Sub
                End If
            End If

            If txtRequiredDate.Text <> "" Then
                Try
                    Dim dt As DateTime
                    dt = Format$(Convert.ToDateTime(txtRequiredDate.Text.ToString), "")

                    If dt <= DateTime.Now Then
                        showmessage("Please Select Proper Future Date.", lblMsg)
                        ScriptManager1.SetFocus(txtRequiredDate.Text)
                        Exit Sub
                    End If
                Catch ex As Exception
                    showmessage("Please Enter Correct Date.", lblMsg)
                    ScriptManager1.SetFocus(txtRequiredDate.Text)
                    Exit Sub
                End Try
            End If

            If txtPhoneNo.Text = "" And txtMobileNo.Text = "" Then
                showmessage("Plese Give Atleast One Contact Details. Like Phone No Or Mobile No", lblMsg)
                Exit Sub
            End If

            If txtEmailID.Text = "" Then
                showmessage("Please Enter EmailID", lblMsg)
                Exit Sub
            End If

            If chkcall.Checked = True Then
                If txtPhoneNo.Text = "" And txtMobileNo.Text = "" Then
                    showmessage("Plese Give Atleast One Contact No. For Contact.", lblMsg)
                    Exit Sub
                End If
            End If

            Dim con As New SqlConnection
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
            Dim cmd As New SqlCommand
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "Product_Specific_Inquiry_Proc" ' storeprocedure
            cmd.Connection = con
            cmd.Parameters.Add(New SqlParameter("@PSE_Kid", SqlDbType.NVarChar, 10)).Value = NewPrimaryKey(Me)
            cmd.Parameters.Add(New SqlParameter("@PSE_Code", SqlDbType.NVarChar, 25)).Value = GenerateCode()
            cmd.Parameters.Add(New SqlParameter("@PSE_ProductID", SqlDbType.NVarChar, 10)).Value = Session("ProductCode")
            cmd.Parameters.Add(New SqlParameter("@PSE_CompanyName", SqlDbType.NVarChar, 200)).Value = txtCompanyName.Text
            cmd.Parameters.Add(New SqlParameter("@PSE_ContactPersonName", SqlDbType.NVarChar, 200)).Value = Trim(txtContactPersonName.Text)
            cmd.Parameters.Add(New SqlParameter("@PSE_PhoneCountryCode", SqlDbType.NVarChar, 10)).Value = Trim(txtCountryCode.Text)
            cmd.Parameters.Add(New SqlParameter("@PSE_PhoneCityCode", SqlDbType.NVarChar, 10)).Value = Trim(txtCityCode.Text)
            cmd.Parameters.Add(New SqlParameter("@PSE_PhoneNo", SqlDbType.NVarChar, 20)).Value = Trim(txtPhoneNo.Text)
            cmd.Parameters.Add(New SqlParameter("@PSE_MobileCountryCode", SqlDbType.NVarChar, 10)).Value = Trim(txtCountryCodeM.Text)
            cmd.Parameters.Add(New SqlParameter("@PSE_MobileNo", SqlDbType.NVarChar, 20)).Value = Trim(txtMobileNo.Text)
            cmd.Parameters.Add(New SqlParameter("@PSE_EmailId", SqlDbType.NVarChar, 50)).Value = Trim(txtEmailID.Text)
            cmd.Parameters.Add(New SqlParameter("@PSE_QtyRequired", SqlDbType.NVarChar, 10)).Value = Trim(txtQtyRequired.Text)
            cmd.Parameters.Add(New SqlParameter("@PSE_QtyRequiredUnit", SqlDbType.NVarChar, 10)).Value = Trim(ddlQtyType.SelectedItem.Value.ToString)
            cmd.Parameters.Add(New SqlParameter("@PSE_RequiredByDate", SqlDbType.NVarChar, 50)).Value = Trim(txtRequiredDate.Text)
            cmd.Parameters.Add(New SqlParameter("@PSE_RequiredPlace", SqlDbType.NVarChar, 200)).Value = Trim(txtRequiredPlace.Text)
            cmd.Parameters.Add(New SqlParameter("@PSE_SpecificRequirement", SqlDbType.NVarChar, 200)).Value = Trim(txtSpecificRequirement.Text)
            If chkcall.Checked = True Then
                cmd.Parameters.Add(New SqlParameter("@PSE_FlagCall", SqlDbType.NVarChar, 1)).Value = "Y"
            Else
                cmd.Parameters.Add(New SqlParameter("@PSE_FlagCall", SqlDbType.NVarChar, 1)).Value = "N"
            End If
            If chkSendOtherSupp.Checked = True Then
                cmd.Parameters.Add(New SqlParameter("@PSE_SendOtherSupplier", SqlDbType.Bit)).Value = 1
            ElseIf chkSendOtherSupp.Checked = False Then
                cmd.Parameters.Add(New SqlParameter("@PSE_SendOtherSupplier", SqlDbType.Bit)).Value = 0
            End If
            cmd.Parameters.Add(New SqlParameter("@PSE_Status", SqlDbType.NVarChar, 50)).Value = "Pending"
            cmd.Parameters.Add(New SqlParameter("@PSE_InquiryDate", SqlDbType.DateTime)).Value = Date.Now
            cmd.Parameters.Add(New SqlParameter("@PSE_FinancialYearId", SqlDbType.NVarChar, 10)).Value = ""
            cmd.Parameters.Add(New SqlParameter("@PSE_CompanyId", SqlDbType.NVarChar, 10)).Value = ""
            cmd.Parameters.Add(New SqlParameter("@PSE_UserId", SqlDbType.NVarChar, 10)).Value = ""
            cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 50)).Value = "Product Specidic Inquiry"
            cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.NVarChar, 10)).Value = "Insert" ' mode

            If con.State = ConnectionState.Open Then ' check connection state
                con.Close()
            End If
            con.Open()
            cmd.ExecuteNonQuery()
            System.Threading.Thread.Sleep(1000)
            con.Close() ' close connection
            con.Dispose()
            '==========================For Voffice CRM Prospect By Pankaj Mishra========================================
            'hdcustid.Value = System.Guid.NewGuid.ToString
            'CRMProspectData("Insert", DateTime.Now.Date, "10")
            'System.Threading.Thread.Sleep(1000)
            'CRMProspectInquiry()
            'System.Threading.Thread.Sleep(1000)
            '==========================End CRM Prospect===================================================
            customeremail()
            sendmail()
            'tbl.Visible = False
            'tbl1.Visible = True

            '------Updated By Prachi - 19/08/2009 - to insert in prospect bank------
            Dim strProspectCode As String
            strProspectCode = GenerateProspectCode()
            objProduct.Mode = "Insert_ProductInquiry"
            objProduct.CmdType = "Insert"
            objProduct.ProspectCode = strProspectCode
            objProduct.CompanyName = txtCompanyName.Text.Trim
            objProduct.Title = ddlTitle.SelectedValue.ToString
            objProduct.ContactPersonFirstName = txtContactPersonName.Text.Trim
            objProduct.ContactPersonMiddleName = txtMiddleName.Text.Trim
            objProduct.ContactPersonLastName = txtLastName.Text.Trim
            objProduct.TelephoneNo = txtCountryCode.Text.Trim + txtCityCode.Text.Trim + txtPhoneNo.Text.Trim
            objProduct.MobileNo = txtCountryCodeM.Text.Trim + txtMobileNo.Text.Trim
            objProduct.EmailAddress = txtEmailID.Text.Trim
            objProduct.ProductName = lblProductName.Text
            objProduct.QtyRequired = txtQtyRequired.Text.Trim.ToString
            objProduct.QtyRequiredUnit = ddlQtyType.SelectedValue
            If txtRequiredDate.Text = "" Then
                objProduct.RequiredByDate = System.Data.SqlTypes.SqlDateTime.Null
            Else
                objProduct.RequiredByDate = CType(txtRequiredDate.Text.Trim, System.Data.SqlTypes.SqlDateTime)
            End If
            objProduct.RequiredPlace = txtRequiredPlace.Text.Trim
            objProduct.SpecificRequirement = txtSpecificRequirement.Text.Trim
            Dim dtCat As New DataTable
            Dim Category_ID As String = ""
            Category_ID = ReturnValue("WITH ParentCategory(Category_Kid,Category_Name,Category_ParentId) AS (SELECT Category_Master1.Category_Kid, Category_Master1.Category_Name, Category_Master1.Category_ParentId FROM dbo.Category_Master AS Category_Master1 WHERE Category_Master1.Category_Kid = '" & RemoveLiterals(Session("catid")) & "' UNION ALL SELECT		Category_Master2.Category_Kid, Category_Master2.Category_Name, Category_Master2.Category_ParentId FROM Category_Master AS Category_Master2 , ParentCategory AS ParentCategory WHERE Category_Master2.Category_Kid = ParentCategory.Category_ParentId ) SELECT Category_Kid FROM ParentCategory WHERE Category_Parentid = 'Root Category'")
            objProduct.CategoryID = IIf(Category_ID = "", Nothing, Category_ID)
            objProduct.BrandID = IIf(Session("brandid") Is Nothing, Nothing, Convert.ToString(Session("brandid")))
            If chkSendOtherSupp.Checked = True Then
                objProduct.OtherSupplier = 1
                objProduct.ProductCode = Nothing
                objProduct.ProductModelNo = Nothing
                objProduct.MarketPrice = Nothing
            ElseIf chkSendOtherSupp.Checked = False Then
                objProduct.OtherSupplier = 0
                objProduct.ProductCode = lblProductCode.Text
                objProduct.ProductModelNo = lblModelNo.Text
                Dim product_marketprice As String
                product_marketprice = ReturnValue("SELECT Product_MarketPrice FROM dbo.Product_Master WHERE Product_Code='" & lblProductCode.Text & "'")
                If product_marketprice = "" Then
                    objProduct.MarketPrice = Nothing
                Else
                    objProduct.MarketPrice = CType(product_marketprice, Decimal)
                End If
            End If

            clsProductInquiry.Insert_ProductInquiry(objProduct)
            '------end update------
        Catch ex As Exception
            showmessage(ex.Message, lblMsg)                                'Display the Error Message
        End Try
    End Sub

    '------Updated By Prachi - 21/08/2009 - to fill ContactPersonTitle combo with enum variables------
    Private Sub FillContactPersonTitle()
        For Each i As clsProductInquiry.ContactPersonTitle In [Enum].GetValues(GetType(clsProductInquiry.ContactPersonTitle))
            ddlTitle.Items.Add(New ListItem(i.ToString(), Convert.ToInt32(i)))
        Next
    End Sub '------end update------

    '------Updated By Prachi - 21/08/2009 - to generate prospect code------
    Private Function GenerateProspectCode() As String
        Try
            Dim maxId As String
            objProduct.Mode = "Select_MaxProspectCode"
            objProduct.CmdType = "Select"
            maxId = clsProductInquiry.Select_MaxProspectCode(objProduct)

            Dim arrCode(5) As Integer
            Dim code As String
            Dim prefix As String
            Dim charc As Char
            prefix = maxId.Substring(0, 5)
            code = maxId.Substring(5)

            Dim i As Integer
            If code = "99999" Then
                If prefix.Contains("Z") Then
                    i = prefix.IndexOf("Z")
                    charc = prefix.Chars(i - 1)
                    charc = Convert.ToChar(Asc(charc) + 1)
                    prefix = prefix.Substring(0, i - 1) + charc + prefix.Substring(i)
                    code = "00001"
                Else
                    charc = prefix.Chars(prefix.Length - 1)
                    charc = Convert.ToChar(Asc(charc) + 1)
                    prefix = prefix.Substring(0, prefix.Length - 1) + charc
                    code = "00001"
                End If
            Else
                code = Format(code + 1, "00000")
            End If
            prefix = prefix + code
            Return prefix
        Catch ex As Exception

        End Try
    End Function '------end update------

    '------Updated By Prachi - 21/08/2009 - to fill QtyRequiredUnit combo------
    Private Sub FillQtyRequiredUnit()
        Try
            Dim dt As New DataTable
            objProduct.Mode = "Select_QtyRequiredUnit"
            objProduct.CmdType = "Select"
            dt = clsProductInquiry.Select_QtyRequiredUnit(objProduct)

            ddlQtyType.DataSource = dt
            ddlQtyType.DataTextField = "Unit"
            ddlQtyType.DataValueField = "Unit_Kid"
            ddlQtyType.DataBind()
            ddlQtyType.Items.Insert(0, New ListItem("Select", "0"))
        Catch ex As Exception

        End Try
    End Sub '------end update------

    Private Sub CRMProspectData(ByVal str As String, ByVal leaddate As Date, ByVal status As String)
        Try
            CRM.CustomerID = hdcustid.Value
            CRM.LeadDate = leaddate 'DateTime.Now.Date
            CRM.CompanyName = txtCompanyName.Text.Trim
            CRM.CompanyType = 1
            CRM.ContactPerson = Trim(txtContactPersonName.Text)
            CRM.MobileNo = txtCountryCodeM.Text + "-" + txtMobileNo.Text
            CRM.PhoneNo = txtCountryCode.Text + "-" + txtCityCode.Text + "-" + txtPhoneNo.Text
            CRM.CityId = 0
            CRM.Email = txtEmailID.Text.Trim
            CRM.CompanyAddress = Nothing
            CRM.CompanyRequirements = Nothing
            CRM.CompanyRemarks = Nothing
            CRM.CRMStatus = status
            CRM.Category = hdcatid.Value
            CRM.CompanyCustomerMode = 5
            CRM.AdminId = "00000000-0000-0000-0000-000000000000"
            CRM.CompanyID = "f6b59677-9946-489c-8628-465872369428"
            CRM.FormName = Me.Title.ToString
            CRM.Mode = str
            clsCRMProspects.AddCRMCustomer(CRM)
        Catch ex As Exception

        End Try
    End Sub

    Private Sub CRMProspectInquiry()
        Try
            Inquiry.CustomerId = hdcustid.Value
            Inquiry.InquiryId = System.Guid.NewGuid.ToString
            Inquiry.CategoryId = hdcatid.Value
            Inquiry.InquiryType = 2
            Inquiry.InqDate = System.DateTime.Now
            Inquiry.ReqDate = txtRequiredDate.Text
            Inquiry.Quentity = txtQtyRequired.Text
            Inquiry.RequiredPlace = txtRequiredPlace.Text
            Inquiry.ModelNo = lblModelNo.Text
            Inquiry.ProductCode = lblProductCode.Text.ToUpper
            Inquiry.ProductName = lblProductName.Text
            Inquiry.InquiryStatus = 5
            Inquiry.Details = txtSpecificRequirement.Text
            Inquiry.UnitName = ddlQtyType.SelectedItem.Text
            Inquiry.AdminId = "00000000-0000-0000-0000-000000000000"
            Inquiry.CompanyId = "f6b59677-9946-489c-8628-465872369428"
            Inquiry.FormName = "addnewinquiry.aspx"
            Inquiry.Mode = "insert"
            clsCRMInquiry.InsertInquiry(Inquiry)
        Catch ex As Exception

        End Try
    End Sub

    Public Sub sendmail()
        Try
            Dim lt As New Label
            lt.Text = "<h1> Inquiry From " & txtEmailID.Text & " </h1> </br>"
            lt.Text += lblCat.Text
            lt.Text += "<br/>Product Code :    "
            lt.Text += "<b>" & lblProductCode.Text & "</b>"
            lt.Text += "<br/>Product Name :    "
            lt.Text += "<b>" & lblProductName.Text & "</b>"
            lt.Text += "<br/>Product ModelNo. :    "
            lt.Text += "<b>" & lblModelNo.Text & "</b>"
            lt.Text += "<br/>Company Name :    "
            lt.Text += "<b>" & txtCompanyName.Text & "</b>"
            lt.Text += "<br/>Company Contact Person Name :    "
            lt.Text += "<b>" & txtContactPersonName.Text & "</b>"

            If txtCityCode.Text = "" And txtPhoneNo.Text = "" Then
            Else
                lt.Text += "<br/>Phone No :    "
                lt.Text += "<b>" & txtCountryCode.Text & "-" & txtCityCode.Text & "-" & txtPhoneNo.Text & "</b>"
            End If

            If txtMobileNo.Text <> "" Then
                lt.Text += "<br/>Mobile No :    "
                lt.Text += "<b>" & txtCountryCodeM.Text & "-" & txtMobileNo.Text & "</b>"
            End If

            If txtEmailID.Text = "" Then
                lt.Text += "<br/>Email ID :    "
                lt.Text += "<b>" & txtEmailID.Text & "</b>"
            End If

            If txtQtyRequired.Text <> "" Then
                lt.Text += "<br/>Quantity Required :    "
                lt.Text += "<b>" & txtQtyRequired.Text & "   " & ddlQtyType.SelectedItem.Text & "</b>"
            End If

            If txtRequiredDate.Text <> "" Then
                lt.Text += "<br/>Required By Date :    "
                lt.Text += "<b>" & txtRequiredDate.Text & "</b>"
            End If

            If txtRequiredPlace.Text <> "" Then
                lt.Text += "<br/>Place At Which Required :    "
                lt.Text += "<b>" & txtRequiredPlace.Text & "</b>"
            End If

            If txtSpecificRequirement.Text <> "" Then
                lt.Text += "<br/>Specific Requirement :    "
                lt.Text += "<b>" & txtSpecificRequirement.Text & "</b>"
            End If

            If chkcall.Checked = True Then
                lt.Text += "<br/>Call Me :    "
                lt.Text += "<b> Please Call Me. </b>"
            Else
                lt.Text += "<br/>Call Me :    "
                lt.Text += "<b> NO </b>"
            End If
            'Dim mail As New MailMessage("contact@atcomaart.com", "pankajmishra2006@gmail.com", "Product Specific Inquiry.", lt.Text)
            'mail.IsBodyHtml = True
            'mail.Priority = Net.Mail.MailPriority.High
            'Dim smtpclient As New System.Net.Mail.SmtpClient("smtp.gmail.com")
            'smtpclient.Credentials = New System.Net.NetworkCredential("contact@atcomaart.com", "contact@55017_atco")
            'smtpclient.Send(mail)
            '' '' ''Dim mailmsg As New MailMessage
            ' '' '' ''From requires an instance of the MailAddress type
            '' '' ''mailmsg.From = New MailAddress("contact@atcomaart.com", txtEmailID.Text)
            ' '' '' ''To is a collection of MailAddress types
            '' '' ''mailmsg.To.Add(New MailAddress("contact@atcomaart.com", "Atcomaart Ltd."))
            ' '' '' ''MyMailMessage.CC.Add(New MailAddress("pankajmishra2006@gmail.com", "CC Name"))
            ' '' '' ''    mailmsg.Bcc.Add(New MailAddress("pankaj.mishra@edeskservices.com", "eDesk Services Ltd."))
            '' '' ''mailmsg.Subject = "Product Specific Inquiry."
            '' '' ''mailmsg.Body = lt.Text
            '' '' ''mailmsg.IsBodyHtml = True
            '' '' ''mailmsg.Priority = MailPriority.High
            '' '' ''Dim smtpsrver As New SmtpClient("smtp.gmail.com")
            '' '' ''smtpsrver.Credentials = New Net.NetworkCredential("contact@atcomaart.com", "contact@55017_atco")
            '' '' ''smtpsrver.Send(mailmsg)
            MailSender.SendEmail("contact@atcomaart.com", "Product Specific Inquiry.", lt.Text, MailFormat.Html, "")
            tbl.Visible = False
            tbl1.Visible = True
        Catch ex As Exception
            showmessage(ex.Message, lblMsg)
        End Try
    End Sub

    Public Sub customeremail()
        Try
            Dim StrMail As String = ""
            'Dim objmessage As New MailMessage()
            StrMail = "<!DOCTYPE HTML PUBLIC ""-//IETF//DTD HTML//EN"">"
            StrMail = StrMail & "<html>" & "<head>" & "<meta http-equiv=""Content-Type"""
            StrMail = StrMail & "<content=""text/html""; charset=""iso-8859-1"">"
            StrMail = StrMail & "<title>Contact Us</title>" & "</head><body><P align=left>"
            StrMail = StrMail & "<table width='739' border='0' cellspacing='0' cellpadding='0' align='left' style='BORDER-RIGHT: #8c8e81 thin solid; BORDER-TOP: #8c8e81 thin solid; FONT-SIZE: 9pt;  BORDER-LEFT: #8c8e81 thin solid; BORDER-BOTTOM: #8c8e81 thin solid; FONT-FAMILY: Verdana' >"
            StrMail = StrMail & "<tr>" & "<td>" & "Dear Client!!"
            StrMail = StrMail & "<br>"
            StrMail = StrMail & "<br>"
            StrMail = StrMail & "<br> We highly appreciate your time and efforts to visit our website and inquire with us on your product and supplies needs. We understand that you are looking forward to finding out the products and brands under one roof."
            StrMail = StrMail & "<br><br><br> We will get back to you soon.<br/>Thanks for inquiry & visiting our website."
            ''StrMail = StrMail & "<br><br><br> Currently you can register with us BUYER and complete the details of your company and requirements on our website. We are coming soon with our industrial retail warehouse all over the country to give a wider range of choice of products and be much closer to you. "
            ''StrMail = StrMail & "<br><br><br> For any questions and concerns get back to us."
            ' 'StrMail = StrMail & "<br><br><br> Looking forward to long term relationship with you!. <br><br>"
            StrMail = StrMail & "<br> Thank's & Regards'S."
            ''StrMail = StrMail & "<br> We highly appreciate your time and efforts to visit our website and enquire with us on your product and supplies needs. We understand that you are looking forward to finding out the products, brands and services of best quality, price and service under one roof. "
            ''StrMail = StrMail & "<br><br><br> ATCOMAART! Brings you tremendous value and wealth addition to your business by being your representative as PURCHASE/MATERIALS Department by which your purchase cycle is shortened, lag time is reduced, inventories are controlled, products at your doorstep, and administrative costs are reduced significantly.  Our alternative channels of marketing gives you perfect range of products with complete details, comparisons, and choice."
            ''StrMail = StrMail & "<br><br><br> Currently you can register with us BUYER and complete the details of your company and requirements on our website. We are coming soon with our industrial retail warehouse all over the country to give a wider range of choice of products and be much closer to you. "
            ''StrMail = StrMail & "<br><br><br> For any questions and concerns get back to us."
            ''StrMail = StrMail & "<br><br><br> Looking forward to long term relationship with you!. <br><br>"
            'StrMail = StrMail & "<B>" & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & "New Supplier Registration on Atcomaart Web Site:-" & "</B>"
            ''StrMail = StrMail & "<B>" & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & "Details of the Your Inquiry are as follows:" & "</B>"
            ''StrMail = StrMail & "<br>" & "<br>"
            ''StrMail = StrMail & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & "Product Name " & "&nbsp;&nbsp;&nbsp;" & ":" & "&nbsp;&nbsp;&nbsp;&nbsp; " & lblProductName.Text & ""
            ''StrMail = StrMail & "<br>"
            ''StrMail = StrMail & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & "Product Code " & "&nbsp;&nbsp;&nbsp;" & ":" & "&nbsp;&nbsp;&nbsp;&nbsp; " & lblProductCode.Text & ""
            ''StrMail = StrMail & "<br>"
            ''StrMail = StrMail & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & "Product ModelNo. " & "&nbsp;&nbsp;&nbsp;" & ":" & "&nbsp;&nbsp;&nbsp;&nbsp; " & lblModelNo.Text & ""
            ''StrMail = StrMail & "<br>"
            ''StrMail = StrMail & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & "Company Name " & "&nbsp;&nbsp;&nbsp;" & ":" & "&nbsp;&nbsp;&nbsp;&nbsp; " & txtCompanyName.Text.Trim & ""
            ''StrMail = StrMail & "<br>"
            ''StrMail = StrMail & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & "Company Contact Person Name  " & "&nbsp;&nbsp;&nbsp;" & ":" & "&nbsp;&nbsp;&nbsp;&nbsp; " & txtContactPersonName.Text & ""
            ''StrMail = StrMail & "<br>"
            ''StrMail = StrMail & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & "Telephone No.-" & "&nbsp;&nbsp;&nbsp;" & ":" & "&nbsp;&nbsp;&nbsp;&nbsp; " & txtCountryCode.Text & "-" & txtCityCode.Text & "-" & txtPhoneNo.Text & "</B>"
            ''StrMail = StrMail & "<br>"
            ''StrMail = StrMail & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & "Mobile No.-" & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp" & ":" & "&nbsp;&nbsp;&nbsp;&nbsp; " & txtCountryCodeM.Text & "-" & txtMobileNo.Text & "</B>"
            ''StrMail = StrMail & "<br>"
            ''If chkcall.Checked = True Then
            ''    StrMail = StrMail & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Call Me :    "
            ''    StrMail = StrMail & "<b> Please Call Me. </b>"
            ''Else
            ''    StrMail = StrMail & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Call Me :    "
            ''    StrMail = StrMail & "<b> NO </b>"
            ''End If
            ''StrMail = StrMail & "<br>"
            ''StrMail = StrMail & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & "Quantity Required " & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & ":" & "&nbsp;&nbsp;&nbsp;&nbsp; " & txtQtyRequired.Text & "   " & ddlQtyType.SelectedItem.Text & "</B>"
            ''StrMail = StrMail & "<br>"
            ''StrMail = StrMail & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & "Required By Date " & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp" & ":" & "&nbsp;&nbsp;&nbsp;&nbsp; " & txtRequiredDate.Text & "</B>"
            ''StrMail = StrMail & "<br>"
            ''StrMail = StrMail & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & "Place At Which Required " & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp" & ":" & "&nbsp;&nbsp;&nbsp;&nbsp; " & txtRequiredPlace.Text & "</B>"
            ''StrMail = StrMail & "<br>"
            ''StrMail = StrMail & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & "EmailId-" & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp" & ":" & "&nbsp;&nbsp;&nbsp;&nbsp; " & txtEmailID.Text & "</B>"
            ''StrMail = StrMail & "<br>"
            ''StrMail = StrMail & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & "Specific Requirement " & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp" & ":" & "&nbsp;&nbsp;&nbsp;&nbsp; " & txtSpecificRequirement.Text & "</B>"
            StrMail = StrMail & "<br><br>"
            StrMail = StrMail & "<br> ATCOMAART Team"
            StrMail = StrMail & "<br> <a href='http://www.atcomaart.com/'>www.atcomaart.com</a>"
            StrMail = StrMail & "<br> <a href='mailto:contact@atcomaart.com'>contact@atcomaart.com</a> <br><br>"
            '  StrMail = StrMail & "<br> <a href='mailto:ceo@atcomaart.com'> ceo@atcomaart.com</a><br><br>"
            StrMail = StrMail & "</td></tr></table></p></body></html>"
            '' '' ''Dim MyMailMessage As New MailMessage()
            ' '' '' ''From requires an instance of the MailAddress type
            '' '' ''MyMailMessage.From = New MailAddress("contact@atcomaart.com", "Atcomaart Ltd.")
            ' '' '' ''To is a collection of MailAddress types
            '' '' ''MyMailMessage.To.Add(txtEmailID.Text)
            ' '' '' ''MyMailMessage.CC.Add(New MailAddress("pankajmishra2006@gmail.com", "CC Name"))
            ' '' '' ''  MyMailMessage.Bcc.Add(New MailAddress("pankaj.mishra@edeskservices.com", "eDesk Services Ltd."))
            '' '' ''MyMailMessage.Subject = "Inquiry for " & lblProductName.Text & " from www.atcomaart.com website ."
            '' '' ''MyMailMessage.Body = StrMail
            '' '' ''MyMailMessage.IsBodyHtml = True
            '' '' ''MyMailMessage.Priority = MailPriority.High
            '' '' ''Dim smtpclient As New SmtpClient("smtp.gmail.com")
            '' '' ''smtpclient.Credentials = New Net.NetworkCredential("contact@atcomaart.com", "contact@55017_atco")
            '' '' ''smtpclient.Send(MyMailMessage)
            MailSender.SendEmail(txtEmailID.Text, "Inquiry for " & lblProductName.Text & " from www.atcomaart.com website .", StrMail, MailFormat.Html, "")
        Catch ex As Exception

        End Try
    End Sub

    Private Function GenerateCode() As String
        ' generate kid and code
        Try
            Dim i As String
            Dim qry As String
            Dim code As String
            'txtBranchNetworkKid.Text = Trim(NewPrimaryKey(Me))
            i = "1"
            i = Format(Val(i), "000")
            While True
                code = "PSI" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/" & i
                qry = "Select count(*) from Product_Specific_Inquiry where PSE_Code='" & code & "'"
                If IsAlreadyPresent(qry) Then
                    i = (Val(i) + 1).ToString
                    i = Format(Val(i), "000")
                Else
                    Return code
                    Exit Function
                End If
            End While
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")     'Display the Error Message
        End Try
    End Function
End Class
