Imports System
Imports System.Data
Imports System.Data.SqlClient
Partial Class BusinessAssociates_Proposal
    Inherits System.Web.UI.Page
    Shared g_User As String
    Shared g_Company As String
    Shared g_FinYear As String
    Shared valuee As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            txtEmailId.Focus()
            g_User = "U1"
            g_Company = "COM1"
            g_FinYear = "2007"
            valuee = Request.QueryString("val")

            If valuee = "MSSA - Proposal" Then
                Label1.Text = "MSSA Proposal Details"
                Label5.Text = "You have chosen to Download the Atcomaart <b> MSSA Proposal details. </b> Please complete the form given below & we will send you the link to your mailbox from where you can download the complete proposal details."
            Else
                Label1.Text = "AMF Proposal Details"
                Label5.Text = "You have chosen to Download the Atcomaart Franchisee Proposal details for <b>" & valuee & " .</b> Please complete the form given below & we will send you the link to your mailbox from where you can download the complete proposal details. "

            End If

        End If
    End Sub
    Public Sub ClearFields()
        txtCode.Text = ""
        txtEmailId.Text = ""
        txtKid.Text = ""
        txtMobileNo.Text = ""
        txtName.Text = ""
        ddlMr.SelectedValue = "Mr."
    End Sub


    Private Sub UpdateData(ByVal strMode As String)
        Try

        Dim cmd As New Data.SqlClient.SqlCommand()
            Dim sqlcoll As Data.SqlClient.SqlParameterCollection = cmd.Parameters
            sqlcoll.Add("@BusinessAssociates_Kid", Data.SqlDbType.NVarChar, 10).Value = txtKid.Text.Trim
            sqlcoll.Add("@BusinessAssociates_Code", Data.SqlDbType.NVarChar, 25).Value = txtCode.Text.Trim
            sqlcoll.Add("@BusinessAssociates_Email", Data.SqlDbType.NVarChar, 50).Value = txtEmailId.Text.Trim
            sqlcoll.Add("@BusinessAssociates_Name", Data.SqlDbType.NVarChar, 50).Value = txtName.Text.Trim
            sqlcoll.Add("@BusinessAssociates_MobileNo", Data.SqlDbType.Decimal).Value = txtMobileNo.Text.Trim
            sqlcoll.Add("@BusinessAssociates_RequestType", Data.SqlDbType.NVarChar, 50).Value = valuee
            sqlcoll.Add("@BusinessAssociates_UserId", Data.SqlDbType.NVarChar, 10).Value = g_User
            sqlcoll.Add("@BusinessAssociates_FinancialYearId", Data.SqlDbType.NVarChar, 10).Value = g_FinYear
            sqlcoll.Add("@BusinessAssociates_CompanyId", Data.SqlDbType.NVarChar, 10).Value = g_Company
            sqlcoll.Add("@FormName", Data.SqlDbType.NVarChar, 50).Value = Me.Title.ToString
            sqlcoll.Add("@Mode", Data.SqlDbType.Char, 15).Value = strMode.Trim
            If ExecQuery("BusinessAssociates_Proc", sqlcoll).StartsWith("True") Then
                cmd = Nothing
                sqlcoll = Nothing
            End If
        Catch ex As Exception

        End Try

    End Sub

    Private Sub GenerateCode()
        Try
            Dim i As String
            Dim qry As String
            Dim code As String
            txtKid.Text = Trim(NewPrimaryKey(Me))
            i = "1"
            i = Format(Val(i), "000")
            While True
                code = "BA" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/" & i
                qry = "Select count(*) from BusinessAssociates where BusinessAssociates_Code='" & code & "'"
                If IsAlreadyPresent(qry) Then
                    i = (Val(i) + 1).ToString
                    i = Format(Val(i), "000")
                Else
                    txtCode.Text = code
                    Exit Sub
                End If
            End While
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")     'Display the Error Message
        End Try
    End Sub

    Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
        Try
            'If CBool(Session("Add_Flag").ToString) = False Then
            '    CreateMessageAlert(Me, "You Do Not Have Access Right To Add New Record !", "StrKeyVal")  'Display the Message 
            '    Exit Sub
            'End If
            GenerateCode()
            If valuee = "" Then
                CreateMessageAlert(Me, "Sory For Inconvenience...!!!", "StrKeyVal")
                Exit Sub
            End If
            If Trim(txtCode.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                Exit Sub
            End If
            If Trim(txtEmailId.Text) = "" Then                                         'If txtPartTypeName TextField is Null then
                CreateMessageAlert(Me, "Email Address Cannot be Null !", "StrKeyVal")      'Display the Message
                Exit Sub
            End If
            If Trim(txtName.Text) = "" Then                                         'If txtPartTypeName TextField is Null then
                CreateMessageAlert(Me, "Email Address Cannot be Null !", "StrKeyVal")      'Display the Message
                Exit Sub
            End If
            If IsNumeric(txtMobileNo.Text) Then
            Else
                CreateMessageAlert(Me, "Please Enter Numeric Value..!!!!", "StrKeyVal")
                Exit Sub
            End If

            UpdateData("Insert")   'Inserts the Record
            CreateMessageAlert(Me, "Record Saved Successfully...", "StrKeyVal")             'Display the Message
            ClearFields()                                                                   'Clear the TextFields
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")                                 'Display the Error Message
        End Try
    End Sub
End Class
