Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.IO
Imports ModCommon
Partial Class VacancyMaster
    Inherits System.Web.UI.Page
    Shared Search As Boolean
    Shared Search1 As Boolean
    Shared g_User As String
    Shared g_Company As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            If (Not IsPostBack) Then        'If IsPostBack is false then
                ClearFields()               'Clear the TextFields
                UnLockTextBox(False)        'Unlock (Enable) TextFields
                g_User = "U1"
                g_Company = "COM1"
                'g_User = Session("g_User").ToString
                'g_Company = Session("g_Company").ToString
                FillGrid("")                  'Fills the DatagGrid with All Records
                Call CancelClick(Me, BtnAdd, BtnSave, BtnEdit, BtnDelete, BtnCancel, BtnSearch)
                Search = False              'Default Value for Search Mode
                Call CheckRights(Me, g_User, "Bank Master")
            End If
            txtVacancyCode.MaxLength = 20 : txtVacancyPositonName.MaxLength = 50
            txtVacancyPositonName.Attributes.Add("onblur", "return CheckNull('txtVacancyPositonName');")
            txtVacancyPositonName.Attributes.Add("onkeypress", "return BlockNumericValue(event);")
            txtVacancyNoOfOpenings.Attributes.Add("onkeypress", "return CheckNumericValue(event);")
            txtVacancyReqAge.Attributes.Add("onkeypress", "return CheckNumericValue(event);")
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")
        End Try
    End Sub

    Protected Sub ClearFields()
        Try
            txtVacancyCode.Text = ""                           'Assign Null to the TextField
            txtVacancyPositonName.Text = ""                           'Assign Null to the TextField
            txtVacancyNoOfOpenings.Text = ""                           'Assign Null to the TextField
            txtVacancyJobDescription.Text = ""                           'Assign Null to the TextField
            txtVacancyLocation.Text = ""                           'Assign Null to the TextField
            txtVacancyReqAge.Text = ""                           'Assign Null to the TextField
            txtVacancyReqExp.Text = ""                           'Assign Null to the TextField
            txtVacancyReqQualification.Text = ""                           'Assign Null to the TextField
            txtClosingDate.Text = ""
            txtVacancyDate.Text = ""                           'Assign Null to the TextField
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")     'Display the Error Message
        End Try
    End Sub

    Protected Sub UnLockTextBox(ByVal Action As Boolean)
        Try
            'txtVacancyCode.Enabled = Action                    'Enable / Disable the TextField
            txtVacancyPositonName.Enabled = Action                    'Enable / Disable the TextField
            txtVacancyNoOfOpenings.Enabled = Action                    'Enable / Disable the TextField
            txtVacancyJobDescription.Enabled = Action                    'Enable / Disable the TextField
            txtVacancyLocation.Enabled = Action                    'Enable / Disable the TextField
            txtVacancyReqAge.Enabled = Action                    'Enable / Disable the TextField
            txtVacancyReqExp.Enabled = Action                    'Enable / Disable the TextField
            txtVacancyReqQualification.Enabled = Action                    'Enable / Disable the TextField
            txtVacancyDate.Enabled = Action                    'Enable / Disable the TextField
            txtClosingDate.Enabled = Action
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")     'Display the Error Message
        End Try
    End Sub

    Protected Sub FillGrid(ByVal PTN As String)
        Try

            Dim qry As String                                   'Define a String Variable for Query
            Dim con As New SqlConnection                        'Define connection variable for connecting to SQL-Server
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")    'Read the ConnectionString from web.config File
            con.Open()                                          'Open the Connection
            gvVacancy.Columns(1).Visible = True
            If Trim(PTN) = "" Then
                qry = "select distinct Vacancy_Kid,Vacancy_Code as [Code],Vacancy_PositionName as [Name],Vacancy_Date as [Date], Vacancy_ClosingDate as [ClosingDate] from Vacancy_Master where Vacancy_isdeleted='0' and Vacancy_companyId='" & g_Company & "'"
            Else
                qry = "select distinct Vacancy_Kid,Vacancy_Code as [Code],Vacancy_PositionName as [Name],Vacancy_Date as [Date] from Vacancy_Master where Vacancy_isdeleted='0' and Vacancy_companyId='" & g_Company & "' and Vacancy_PositionName like '" & Trim(PTN) & "%'"
            End If
            Dim cmd As New SqlCommand(qry, con)                 'Define command variable to execute the query
            Dim dr As SqlDataReader                             'Define DataReader variable for storing the output of the query
            dr = cmd.ExecuteReader                              'Assign the output of query to DataReader variable
            gvVacancy.DataSource = dr                          'Set the DataReader Variable as DataSource for the Grid
            gvVacancy.DataBind()                               'Bind the Data to the Grid
            gvVacancy.Columns(1).Visible = False
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")     'Display the Error Message
        End Try
    End Sub

    Protected Sub BtnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        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
            ClearFields()                                       'Clears the TextFields
            UnLockTextBox(True)                                 'Enable the TextFields
            Call AddClick(Me, BtnAdd, BtnSave, BtnEdit, BtnDelete, BtnCancel, BtnSearch)
            Call GenerateBankCode()
            txtVacancyPositonName.Focus()                                 'Put the Focus to BankCode TextField
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")     'Display the Error Message
        End Try
    End Sub

    Protected Sub gvVacancy_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            Dim qry As String
            Dim con As New SqlConnection                        'Define connection variable for connecting to SQL-Server
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")    'Read the ConnectionString from web.config File
            con.Open()
            txtVacancyId.Text = gvVacancy.SelectedRow.Cells(1).Text     'Assign the value of cell to the textField
            qry = "select Vacancy_Kid,Vacancy_Code,Vacancy_PositionName,Vacancy_NoOfOpenings,Vacancy_ReqdExperience,Vacancy_ReqdAge,Vacancy_ReqdQualification,Vacancy_JobDescription,Vacancy_Location,Vacancy_Date,Vacancy_ClosingDate from  Vacancy_Master where Vacancy_IsDeleted = '0' and Vacancy_kid='" & txtVacancyId.Text.Trim & "'"
            Dim cmd As New SqlCommand(qry, con)                 'Define command variable to execute the query
            Dim dt As DataTable
            Dim ds As New DataSet
            Dim adp As New SqlDataAdapter
            adp.SelectCommand = cmd
            adp.Fill(ds, "Vacancy")
            dt = ds.Tables("Vacancy")
            If dt.Rows.Count <> 0 Then
                If Search = False Then  'If Search mode is False Then Fill All DropDownLists                    
                    With gvVacancy
                        If IsDBNull(dt.Rows(0).Item("Vacancy_Code")) = True Then
                            txtVacancyCode.Text = ""
                        Else
                            txtVacancyCode.Text = dt.Rows(0).Item("Vacancy_Code").ToString
                        End If
                        If IsDBNull(dt.Rows(0).Item("Vacancy_PositionName")) = True Then
                            txtVacancyPositonName.Text = ""
                        Else
                            txtVacancyPositonName.Text = dt.Rows(0).Item("Vacancy_PositionName").ToString
                        End If
                        If IsDBNull(dt.Rows(0).Item("Vacancy_NoOfOpenings")) = True Then
                            txtVacancyNoOfOpenings.Text = ""
                        Else
                            txtVacancyNoOfOpenings.Text = dt.Rows(0).Item("Vacancy_NoOfOpenings").ToString
                        End If
                        If IsDBNull(dt.Rows(0).Item("Vacancy_ReqdExperience")) = True Then
                            txtVacancyReqExp.Text = ""
                        Else
                            txtVacancyReqExp.Text = dt.Rows(0).Item("Vacancy_ReqdExperience").ToString
                        End If
                        If IsDBNull(dt.Rows(0).Item("Vacancy_ReqdAge")) = True Then
                            txtVacancyReqAge.Text = ""
                        Else
                            txtVacancyReqAge.Text = dt.Rows(0).Item("Vacancy_ReqdAge").ToString
                        End If
                        If IsDBNull(dt.Rows(0).Item("Vacancy_ReqdQualification")) = True Then
                            txtVacancyReqQualification.Text = ""
                        Else
                            txtVacancyReqQualification.Text = dt.Rows(0).Item("Vacancy_ReqdQualification").ToString
                        End If
                        If IsDBNull(dt.Rows(0).Item("Vacancy_JobDescription")) = True Then
                            txtVacancyJobDescription.Text = ""
                        Else
                            txtVacancyJobDescription.Text = dt.Rows(0).Item("Vacancy_JobDescription").ToString
                        End If
                        If IsDBNull(dt.Rows(0).Item("Vacancy_Location")) = True Then
                            txtVacancyLocation.Text = ""
                        Else
                            txtVacancyLocation.Text = dt.Rows(0).Item("Vacancy_Location").ToString
                        End If
                        If IsDBNull(dt.Rows(0).Item("Vacancy_Date")) = True Then
                            txtVacancyDate.Text = ""
                        Else
                            Dim str As Date
                            str = dt.Rows(0).Item("Vacancy_Date").ToString
                            txtVacancyDate.Text = str
                        End If
                        If IsDBNull(dt.Rows(0).Item("Vacancy_ClosingDate")) = True Then
                            txtClosingDate.Text = ""
                        Else
                            Dim str As Date
                            str = dt.Rows(0).Item("Vacancy_ClosingDate").ToString
                            txtClosingDate.Text = str
                        End If
                    End With
                End If
            End If
            UnLockTextBox(True)                                             'Enable the TextFields
            Call GridClick(Me, BtnAdd, BtnSave, BtnEdit, BtnDelete, BtnCancel, BtnSearch)
            Search = False
            txtVacancyPositonName.Focus()
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")                 'Display the Error Message
        End Try
    End Sub

    Protected Sub BtnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        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
            If Trim(txtVacancyCode.Text) = "" Then                                         'If  TextField is Null then
                CreateMessageAlert(Me, "Vacancy Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyCode.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyPositonName.Text) = "" Then                                         'If TextField is Null then
                CreateMessageAlert(Me, "Position Name Cannot be Null !", "StrKeyVal")      'Display the Message
                txtVacancyPositonName.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyNoOfOpenings.Text) = "" Then                                         'If  TextField is Null then
                CreateMessageAlert(Me, "NoOfOpenings Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyNoOfOpenings.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyJobDescription.Text) = "" Then                                         'If  TextField is Null then
                CreateMessageAlert(Me, "JobDescription Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyJobDescription.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyLocation.Text) = "" Then                                         'If  TextField is Null then
                CreateMessageAlert(Me, "Location Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyLocation.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyReqAge.Text) = "" Then                                         'If TextField is Null then
                CreateMessageAlert(Me, "ReqAge Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyReqAge.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyReqExp.Text) = "" Then                                         'If TextField is Null then
                CreateMessageAlert(Me, "ReqExp Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyReqExp.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyReqQualification.Text) = "" Then                                         'If  TextField is Null then
                CreateMessageAlert(Me, "ReqQualification Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyReqQualification.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyDate.Text) = "" Then                                         'If TextField is Null then

                CreateMessageAlert(Me, "Post Date Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyDate.Focus()
                Exit Sub
            End If

            If Trim(txtClosingDate.Text) = "" Then                                         'If TextField is Null then

                CreateMessageAlert(Me, "Post Closing Date Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtClosingDate.Focus()
                Exit Sub
            End If

            If IsAlreadyPresent("select count(*) from Vacancy_Master where Vacancy_Code='" & txtVacancyCode.Text.Trim & "'and Vacancy_isdeleted='0' and Vacancy_companyId='" & g_Company & "'") Then  ' To Check Existance of Engineer Code
                CreateMessageAlert(Me, " Vacancy Code Already Present !", "StrKeyVal")      'Display the Message
                txtVacancyCode.Text = "" : txtVacancyCode.Focus()
                Exit Sub
            End If
            If IsAlreadyPresent("select count(*) from Vacancy_Master where Vacancy_PositionName='" & txtVacancyPositonName.Text.Trim & "'and Vacancy_isdeleted='0' and Vacancy_companyId='" & g_Company & "'") Then  ' To Check Existance of Engineer Code
                CreateMessageAlert(Me, " Postion Name Already Present !", "StrKeyVal")      'Display the Message
                txtVacancyPositonName.Text = "" : txtVacancyPositonName.Focus()
                Exit Sub
            End If

            If DateDiff(DateInterval.Day, Convert.ToDateTime(txtVacancyDate.Text.Trim), Convert.ToDateTime(txtClosingDate.Text.Trim)) >= 0 Then
            Else
                CreateMessageAlert(Me, "Please Select Proper Date..!!!", "StrKeyVal")
                Exit Sub

            End If
            Dim con As New SqlConnection                                                    'Define connection variable for connecting to SQL-Server
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")    'Read the ConnectionString from web.config File
            con.Open()                                                                 'Open the Connection
            Dim cmd As New SqlCommand                                                       'Define command variable to execute the query
            cmd.CommandType = CommandType.StoredProcedure                                   'Set the Command Type to Stored procedure
            cmd.CommandText = "Vacancy_Master_Proc"                                        'Assign the Name of Stored Procedure, to Execute
            cmd.Connection = con                                                            'Assign the connection
            cmd.Parameters.Add(New SqlParameter("@Vacancy_Kid", SqlDbType.NVarChar, 20)).Value = Trim(txtVacancyId.Text)       'Add Parameter Vacancy_Kid and assign the value  to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_Code", SqlDbType.NVarChar, 20)).Value = Trim(txtVacancyCode.Text)       'Add Parameter Vacancy_Code and assign the value of txtVacancyCode TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_PositionName", SqlDbType.NVarChar, 25)).Value = Trim(txtVacancyPositonName.Text)       'Add Parameter Vacancy_PositionName and assign the value of txtVacancyPositonName TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_NoOfOpenings", SqlDbType.Int)).Value = Convert.ToInt32(txtVacancyNoOfOpenings.Text)      'Add Parameter Vacancy_NoOfOpenings and assign the value of txtVacancyNoOfOpenings TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_ReqdExperience", SqlDbType.NVarChar, 25)).Value = Trim(txtVacancyReqExp.Text)       'Add Parameter Vacancy_Name and assign the value of txtVacancyReqExp TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_ReqdAge", SqlDbType.Int)).Value = Convert.ToInt32(txtVacancyReqAge.Text)  'Add Parameter Vacancy_ReqAge and assign the value of txtVacancyReqAge TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_ReqdQualification", SqlDbType.NVarChar, 25)).Value = Trim(txtVacancyReqQualification.Text)       'Add Parameter Vacancy_ReqQualification and assign the value of txtVacancyReqQualification TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_JobDescription", SqlDbType.NVarChar, 25)).Value = Trim(txtVacancyJobDescription.Text)       'Add Parameter Vacancy_JobDescription and assign the value of txtVacancyJobDescription TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_Location", SqlDbType.NVarChar, 25)).Value = Trim(txtVacancyLocation.Text)       'Add Parameter Vacancy_Location and assign the value of txtVacancyLocation TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_Date", SqlDbType.DateTime)).Value = txtVacancyDate.Text      'Add Parameter Vacancy_Date and assign the value of txtVacancyDate TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_ClosingDate", SqlDbType.DateTime)).Value = txtClosingDate.Text
            cmd.Parameters.Add(New SqlParameter("@Vacancy_CompanyId", SqlDbType.NVarChar, 20)).Value = Trim(g_Company)       'Add Parameter Company_Code and assign the value of Session("g_Company") to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_UserId", SqlDbType.NVarChar, 20)).Value = Trim(g_User)             'Add Parameter UserCode and assign the value of Session("g_User").toString to it
            cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 100)).Value = "Vacancy Master"                           'Add Parameter FormName and assign the name of form to it
            cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 50)).Value = "Insert"                                   'Add Parameter Mode and assign the DML Operation to Execute (Insert)
            cmd.ExecuteNonQuery()                                                           'Execute the Query
            FillGrid("")                                                                      'Fill the Grid
            CreateMessageAlert(Me, "Record Saved Successfully...", "StrKeyVal")             'Display the Message
            ClearFields()                                                                   'Clear the TextFields
            UnLockTextBox(False)                                                            'Disable the TextFields
            Call SaveClick(Me, BtnAdd, BtnSave, BtnEdit, BtnDelete, BtnCancel, BtnSearch)
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")                                 'Display the Error Message
        End Try
    End Sub

    Protected Sub BtnEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            'If CBool(Session("Modify_Flag").ToString) = False Then
            '    CreateMessageAlert(Me, "You Do Not Have Access Right To Modify An Existing Record !", "StrKeyVal")  'Display the Message 
            '    Exit Sub
            'End If
            If Trim(txtVacancyCode.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "Vacancy Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyCode.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyPositonName.Text) = "" Then                                         'If txtPartTypeName TextField is Null then
                CreateMessageAlert(Me, "Position Name Cannot be Null !", "StrKeyVal")      'Display the Message
                txtVacancyPositonName.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyNoOfOpenings.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "NoOfOpenings Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyNoOfOpenings.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyJobDescription.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "JobDescription Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyJobDescription.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyLocation.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "Location Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyLocation.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyReqAge.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "ReqAge Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyReqAge.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyReqExp.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "ReqExp Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyReqExp.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyReqQualification.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "ReqQualification Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyReqQualification.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyDate.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "Post Date Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyDate.Focus()
                Exit Sub
            End If

            If Trim(txtClosingDate.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "Post Closing Date Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtClosingDate.Focus()
                Exit Sub
            End If


            If IsAlreadyPresent("select count(*) from Vacancy_Master where Vacancy_code!='" & Trim(txtVacancyCode.Text) & "' and  Vacancy_PositionName='" & txtVacancyPositonName.Text.Trim & "'  and Vacancy_isdeleted='0' and Vacancy_companyId='" & g_Company & "'") Then  ' To Check Existance of Engineer Code
                CreateMessageAlert(Me, " Vacancy Name Already Present !", "StrKeyVal")      'Display the Message
                txtVacancyPositonName.Text = "" : txtVacancyPositonName.Focus()
                Exit Sub
            End If

            Dim con As New SqlConnection                                                    'Define connection variable for connecting to SQL-Server
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")    'Read the ConnectionString from web.config File
            con.Open()                                                                      'Open the Connection
            Dim cmd As New SqlCommand                                                       'Define command variable to execute the query
            cmd.CommandType = CommandType.StoredProcedure                                   'Set the Command Type to Stored procedure
            cmd.CommandText = "Vacancy_Master_Proc"                                        'Assign the Name of Stored Procedure, to Execute
            cmd.Connection = con                                                            'Assign the connection

            cmd.Parameters.Add(New SqlParameter("@Vacancy_Kid", SqlDbType.NVarChar, 20)).Value = Trim(txtVacancyId.Text)       'Add Parameter Vacancy_Kid and assign the value  to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_Code", SqlDbType.NVarChar, 20)).Value = Trim(txtVacancyCode.Text)       'Add Parameter Vacancy_Code and assign the value of txtVacancyCode TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_PositionName", SqlDbType.NVarChar, 25)).Value = Trim(txtVacancyPositonName.Text)       'Add Parameter Vacancy_PositionName and assign the value of txtVacancyPositonName TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_NoOfOpenings", SqlDbType.Int)).Value = Convert.ToInt32(txtVacancyNoOfOpenings.Text)      'Add Parameter Vacancy_NoOfOpenings and assign the value of txtVacancyNoOfOpenings TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_ReqdExperience", SqlDbType.NVarChar, 25)).Value = Trim(txtVacancyReqExp.Text)       'Add Parameter Vacancy_Name and assign the value of txtVacancyReqExp TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_ReqdAge", SqlDbType.Int)).Value = Convert.ToInt32(txtVacancyReqAge.Text)  'Add Parameter Vacancy_ReqAge and assign the value of txtVacancyReqAge TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_ReqdQualification", SqlDbType.NVarChar, 25)).Value = Trim(txtVacancyReqQualification.Text)       'Add Parameter Vacancy_ReqQualification and assign the value of txtVacancyReqQualification TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_JobDescription", SqlDbType.NVarChar, 25)).Value = Trim(txtVacancyJobDescription.Text)       'Add Parameter Vacancy_JobDescription and assign the value of txtVacancyJobDescription TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_Location", SqlDbType.NVarChar, 25)).Value = Trim(txtVacancyLocation.Text)       'Add Parameter Vacancy_Location and assign the value of txtVacancyLocation TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_Date", SqlDbType.DateTime)).Value = txtVacancyDate.Text      'Add Parameter Vacancy_Date and assign the value of txtVacancyDate TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_ClosingDate", SqlDbType.DateTime)).Value = txtClosingDate.Text
            cmd.Parameters.Add(New SqlParameter("@Vacancy_CompanyId", SqlDbType.NVarChar, 20)).Value = Trim(g_Company)       'Add Parameter Company_Code and assign the value of Session("g_Company") to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_UserId", SqlDbType.NVarChar, 20)).Value = Trim(g_User)             'Add Parameter UserCode and assign the value of Session("g_User").toString to it
            cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 100)).Value = "Vacancy Master"
            cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 50)).Value = "Update"                                   'Add Parameter Mode and assign the DML Operation to Execute (Update)
            cmd.ExecuteNonQuery()                                                           'Execute the Query
            FillGrid("")                                                                      'Fill the Grid
            CreateMessageAlert(Me, "Record Modified Successfully...", "StrKeyVal")             'Display the Message
            ClearFields()                                                                   'Clear the TextFields
            UnLockTextBox(False)                                                            'Disable the TextFields
            Call EditClick(Me, BtnAdd, BtnSave, BtnEdit, BtnDelete, BtnCancel, BtnSearch)
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")                                 'Display the Error Message
        End Try

    End Sub

    Protected Sub BtnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            'If CBool(Session("Delete_Flag").ToString) = False Then
            '    CreateMessageAlert(Me, "You Do Not Have Access Right To Delete An Existing Record !", "StrKeyVal")  'Display the Message 
            '    Exit Sub
            'End If
            If Trim(txtVacancyCode.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "Vacancy Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyCode.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyPositonName.Text) = "" Then                                         'If txtPartTypeName TextField is Null then
                CreateMessageAlert(Me, "Position Name Cannot be Null !", "StrKeyVal")      'Display the Message
                txtVacancyPositonName.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyNoOfOpenings.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "NoOfOpenings Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyNoOfOpenings.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyJobDescription.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "JobDescription Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyJobDescription.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyLocation.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "Location Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyLocation.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyReqAge.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "ReqAge Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyReqAge.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyReqExp.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "ReqExp Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyReqExp.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyReqQualification.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "ReqQualification Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyReqQualification.Focus()
                Exit Sub
            End If
            If Trim(txtVacancyDate.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "Post Date Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtVacancyDate.Focus()
                Exit Sub
            End If

            If Trim(txtClosingDate.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "Post Closing Date Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                txtClosingDate.Focus()
                Exit Sub
            End If

            'If IsAlreadyPresent("select count(*) from Vacancy_Master where Vacancy_Code='" & txtVacancyCode.Text.Trim & "'and Vacancy_isdeleted='0' and Vacancy_companyId='" & g_Company & "'") Then  ' To Check Existance of Engineer Code
            '    CreateMessageAlert(Me, " Unable to Delete, Referenced to Other Records... !", "StrKeyVal")      'Display the Message
            '    btnCancel_Click(sender, e)
            '    Exit Sub
            'End If
            Dim con As New SqlConnection                                                    'Define connection variable for connecting to SQL-Server
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")    'Read the ConnectionString from web.config File
            con.Open()                                                                      'Open the Connection
            Dim cmd As New SqlCommand                                                       'Define command variable to execute the query
            cmd.CommandType = CommandType.StoredProcedure                                   'Set the Command Type to Stored procedure
            cmd.CommandText = "Vacancy_Master_Proc"                                        'Assign the Name of Stored Procedure, to Execute
            cmd.Connection = con                                                            'Assign the connection

            cmd.Parameters.Add(New SqlParameter("@Vacancy_Kid", SqlDbType.NVarChar, 20)).Value = Trim(txtVacancyId.Text)       'Add Parameter Vacancy_Kid and assign the value  to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_Code", SqlDbType.NVarChar, 20)).Value = Trim(txtVacancyCode.Text)       'Add Parameter Vacancy_Code and assign the value of txtVacancyCode TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_PositionName", SqlDbType.NVarChar, 25)).Value = Trim(txtVacancyPositonName.Text)       'Add Parameter Vacancy_PositionName and assign the value of txtVacancyPositonName TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_NoOfOpenings", SqlDbType.Int)).Value = Convert.ToInt32(txtVacancyNoOfOpenings.Text)      'Add Parameter Vacancy_NoOfOpenings and assign the value of txtVacancyNoOfOpenings TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_ReqdExperience", SqlDbType.NVarChar, 25)).Value = Trim(txtVacancyReqExp.Text)       'Add Parameter Vacancy_Name and assign the value of txtVacancyReqExp TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_ReqdAge", SqlDbType.Int)).Value = Convert.ToInt32(txtVacancyReqAge.Text)  'Add Parameter Vacancy_ReqAge and assign the value of txtVacancyReqAge TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_ReqdQualification", SqlDbType.NVarChar, 25)).Value = Trim(txtVacancyReqQualification.Text)       'Add Parameter Vacancy_ReqQualification and assign the value of txtVacancyReqQualification TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_JobDescription", SqlDbType.NVarChar, 25)).Value = Trim(txtVacancyJobDescription.Text)       'Add Parameter Vacancy_JobDescription and assign the value of txtVacancyJobDescription TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_Location", SqlDbType.NVarChar, 25)).Value = Trim(txtVacancyLocation.Text)       'Add Parameter Vacancy_Location and assign the value of txtVacancyLocation TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_Date", SqlDbType.DateTime)).Value = txtVacancyDate.Text      'Add Parameter Vacancy_Date and assign the value of txtVacancyDate TextField to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_ClosingDate", SqlDbType.DateTime)).Value = txtClosingDate.Text
            cmd.Parameters.Add(New SqlParameter("@Vacancy_CompanyId", SqlDbType.NVarChar, 20)).Value = Trim(g_Company)       'Add Parameter Company_Code and assign the value of Session("g_Company") to it
            cmd.Parameters.Add(New SqlParameter("@Vacancy_UserId", SqlDbType.NVarChar, 20)).Value = Trim(g_User)             'Add Parameter UserCode and assign the value of Session("g_User").toString to it
            cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 100)).Value = "Vacancy Master"
            cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 50)).Value = "Delete"                                   'Add Parameter Mode and assign the DML Operation to Execute (Delete)
            cmd.ExecuteNonQuery()                                                           'Execute the Query
            FillGrid("")                                                                      'Fill the Grid
            CreateMessageAlert(Me, "Record Deleted Successfully...", "StrKeyVal")             'Display the Message
            ClearFields()                                                                   'Clear the TextFields
            UnLockTextBox(False)                                                            'Disable the TextFields
            Call DeleteClick(Me, BtnAdd, BtnSave, BtnEdit, BtnDelete, BtnCancel, BtnSearch)
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")                                 'Display the Error Message
        End Try
    End Sub

    Protected Sub BtnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            ClearFields()                                       'Clears the TextFields
            UnLockTextBox(False)                                'Disable the TextFields
            Search = False
            txtVacancyPositonName.AutoPostBack = False
            Call FillGrid("")
            Call CancelClick(Me, BtnAdd, BtnSave, BtnEdit, BtnDelete, BtnCancel, BtnSearch)
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")     'Display the Error Message
        End Try
    End Sub

    Protected Sub BtnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Search = True                                       'Set Search Mode True
        Call SearchClick(Me, BtnAdd, BtnSave, BtnEdit, BtnDelete, BtnCancel, BtnSearch)
        txtVacancyPositonName.Enabled = True
        txtVacancyPositonName.AutoPostBack = True
        'Enable txtPartTypeName TextField
        'Call txtBankName_TextChanged(sender, e)
        txtVacancyPositonName.Focus()
    End Sub

    Protected Sub txtVacancyPositonName_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        If Search = True Then                               'If Search Mode is true then
            Call FillGrid(Trim(txtVacancyPositonName.Text))  'Fill the Grid filtering on txtStockLocationName 
        End If
        If BtnSave.Enabled Then BtnSave.Focus()
    End Sub

    Protected Sub GenerateBankCode()
        Try
            Dim i As String
            Dim qry As String
            Dim code As String
            txtVacancyId.Text = NewPrimaryKey(Me)
            i = "1"
            i = Format(Val(i), "000")
            While True
                code = "VCY" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/" & i
                qry = "select count(*) from Vacancy_Master where Vacancy_Code='" & code & "'"
                If IsAlreadyPresent(qry) Then
                    i = Val(i) + 1
                    i = Format(Val(i), "000")
                Else
                    txtVacancyCode.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

    
End Class
