Imports System.Text
Imports System.String
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Partial Class career
    Inherits System.Web.UI.Page
    Shared str As String
    Dim strFileName, strFileExtn, path, fupload, MapfilePath As String
    Dim dr As SqlDataReader
    Dim PositionName As String
    Public Shared vacancyid As String
    Dim cmd As New SqlCommand
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack = False Then
         
            vacancyid = Request.QueryString("ID")
            fillgrid()
            jobapp.Visible = False
            ' txtPosition.Text = PositionName
            txtJobID.Text = NewPrimaryKey(Me.Page)
            txtJobID.Enabled = False
            Session("g_User") = "000008I"
            Session("g_Company") = "00006Z4"
            txtctc.Attributes.Add("onkeypress", "return CheckNumericValue(event);")
            txtcitycode.Attributes.Add("onkeypress", "return numbersonly(event);")
            txtPhoneNo.Attributes.Add("onkeypress", "return numbersonly(event);")
            txtMobileNo.Attributes.Add("onkeypress", "return numbersonly(event);")
            txttotal.Attributes.Add("onkeypress", "return CheckNumericValue(event);")
            txtRexperince.Attributes.Add("onkeypress", "return CheckNumericValue(event);")
            File1.Attributes.Add("onblur", "return  CheckNull('BrowseResume');")
        End If
    End Sub

    Private Function UploadResumes(ByVal FileCtr As System.Web.UI.HtmlControls.HtmlInputFile, ByVal path As String, ByVal ftype As String) As String
        Try

      
            If FileCtr.Value <> "" Then
                strFileName = Mid(FileCtr.PostedFile.FileName.ToString, FileCtr.PostedFile.FileName.ToString.LastIndexOf("\") + 2, Len(FileCtr.PostedFile.FileName.ToString))
                strFileExtn = strFileName.Substring(strFileName.LastIndexOf(".") + 1)
                If strFileExtn.Trim = "doc" Then
                    fupload = FileExists(strFileName, path)
                End If
                If strFileExtn.ToLower <> ".doc" Or strFileExtn.ToLower <> ".docx" Then
                    fupload = FileExists(strFileName, path)
                    If fupload.ToString <> "" Then
                        Dim filepath As String = path & fupload
                        FileCtr.PostedFile.SaveAs(path & fupload)
                    End If
                Else
                    fupload = ""
                    'Dim strmessage As String = "You have a permission to upload only" & ftype & " file"
                    'CreateMessageAlert(FileCtr.Page, strmessage, "strKeyMessage")
                    lblMessage.Text = "Pleas Upload Word document file"
                    lblMessage.Visible = True
                End If
            End If
            Return fupload
        Catch ex As Exception

        End Try
    End Function

    

    Public Function FileExists(ByVal FileName As String, ByVal path As String) As String
        Dim strName, strFullPath, fname, fextn As String
        strFullPath = path & FileName
        strName = FileName
Check:
        If chkExists(strFullPath) = True Then                                            'check whether filename exist or not
            fname = Mid(strName, 1, strName.LastIndexOf("."))                            'Get filename
            fextn = Mid(strName, strName.LastIndexOf(".") + 2, strName.Length.ToString)  'Get fileextn
            strName = fname & "_1." & fextn                                              'if exist get full file name 
            strFullPath = path & strName
            GoTo Check
        Else
            Return strName                                                                'if not exist return same filename
        End If
    End Function

    Private Function chkExists(ByVal filename As String) As Boolean                      'to check whether file exist or not 
        Dim fn As New FileInfo(filename)
        If fn.Exists = True Then
            Return True
        Else
            Return False
        End If
    End Function

    Protected Sub VisibleControl()
        'lblJobApplicationCode.Visible = False
        'lblPosition.Visible = False
        'lblCandidateName.Visible = False
        'lblPhoneNo.Visible = False
        'lblMobileNo.Visible = False
        'lblEmailId.Visible = False
        'lblUploadResume.Visible = False
        txtJobCode.Visible = False
        txtPosition.Visible = False
        txtCandidateName.Visible = False
        txtPhoneNo.Visible = False
        txtMobileNo.Visible = False
        txtEmailId.Visible = False
        BtnAdd.Visible = False
        lblMessage.Visible = True
        File1.Visible = False
        ' HypPrev.Visible = True
    End Sub

    Protected Sub ClearControls()
        txtCandidateName.Text = ""
        txtbirthdate.Text = ""
        txtcitycode.Text = ""
        txtctc.Text = ""
        txtqualification.Text = ""
        txtpcompany.Text = ""
        txtpdesignation.Text = ""
        txtplocation.Text = ""
        txtRexperince.Text = ""
        txtPhoneNo.Text = ""
        txtMobileNo.Text = ""
        txtEmailId.Text = ""
        txtJobCode.Text = ""
        txtPosition.Text = ""
        lblMessage.Text = ""
    End Sub

    Protected Sub BtnAdd_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles BtnAdd.Click
        Try

      
            If txtCandidateName.Text.Trim = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "Candidate Name cannot be Null !", "StrKeyVal")      'Display the Message 
                Exit Sub
            End If
            If txtPhoneNo.Text.Trim = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "Phone No cannot be Null !", "StrKeyVal")      'Display the Message 
                Exit Sub
            End If
            MapfilePath = Server.MapPath("~/Upload Image/Application/")
            Dim str As String = UploadResumes(File1, MapfilePath, "doc")
            Session("Resume") = str
            'lblUploadResume.Text = "Uploaded  : " & Session("Resume")

            If Session("Resume") = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "Upload Resume !", "StrKeyVal")      'Display the Message 
                Exit Sub
            End If
            Dim sqlcol As Data.SqlClient.SqlParameterCollection = cmd.Parameters
            'DetailsView1.Rows(0).Visible = True
            sqlcol.Add(New SqlParameter("@JobApplications_Kid", SqlDbType.NVarChar, 10)).Value = txtJobID.Text.Trim      'Add Parameter Product_Kid and assign the value  to it
            sqlcol.Add(New SqlParameter("@JobApplications_Code", SqlDbType.NVarChar, 25)).Value = txtJobCode.Text.Trim
            sqlcol.Add(New SqlParameter("@JobApplications_VacancyId", SqlDbType.NVarChar, 10)).Value = DetailsView1.Rows(0).Cells(1).Text
            sqlcol.Add(New SqlParameter("@JobApplications_CandName", SqlDbType.NVarChar, 150)).Value = txtCandidateName.Text.Trim
            sqlcol.Add(New SqlParameter("@JobApplications_Sex", SqlDbType.NVarChar, 10)).Value = rbosex.SelectedValue
            sqlcol.Add(New SqlParameter("@JobApplications_Qualification", SqlDbType.NVarChar, 150)).Value = txtqualification.Text
            sqlcol.Add(New SqlParameter("@JobApplications_PresentDesignation", SqlDbType.NVarChar, 150)).Value = txtpdesignation.Text
            sqlcol.Add(New SqlParameter("@JobApplications_CurrentCompany", SqlDbType.NVarChar, 150)).Value = txtpcompany.Text
            sqlcol.Add(New SqlParameter("@JobApplications_currentCTC", SqlDbType.Decimal)).Value = txtctc.Text
            sqlcol.Add(New SqlParameter("@jobApplications_PresentLocation", SqlDbType.NVarChar, 150)).Value = txtplocation.Text
            sqlcol.Add(New SqlParameter("@JobApplications_RadyforRelocate", SqlDbType.NVarChar, 10)).Value = rborfr.SelectedValue
            sqlcol.Add(New SqlParameter("@JobApplications_BirthDate", SqlDbType.DateTime, 50)).Value = txtbirthdate.Text
            sqlcol.Add(New SqlParameter("@JobApplications_TotalExp", SqlDbType.Decimal)).Value = txttotal.Text
            sqlcol.Add(New SqlParameter("@JobApplications_RelavantExp", SqlDbType.Decimal)).Value = txtRexperince.Text
            If txtcitycode.Text = "" Then
                sqlcol.Add(New SqlParameter("@JobApplications_PhoneNo", SqlDbType.NVarChar, 100)).Value = "+91" & "-" & txtPhoneNo.Text.Trim
            Else
                sqlcol.Add(New SqlParameter("@JobApplications_PhoneNo", SqlDbType.NVarChar, 100)).Value = "+91" & "-" & txtcitycode.Text & "-" & txtPhoneNo.Text.Trim
            End If
            sqlcol.Add(New SqlParameter("@JobApplications_MobileNo", SqlDbType.NVarChar, 25)).Value = "+91" & "-" & txtMobileNo.Text.Trim
            sqlcol.Add(New SqlParameter("@JobApplications_EmailId", SqlDbType.NVarChar, 150)).Value = txtEmailId.Text.Trim
            sqlcol.Add(New SqlParameter("@JobApplications_ResumePath", SqlDbType.NVarChar, 150)).Value = Session("Resume")
            sqlcol.Add(New SqlParameter("@JobApplications_Status", SqlDbType.NVarChar, 10)).Value = "Pending"
            sqlcol.Add(New SqlParameter("@JobApplications_CompanyId", SqlDbType.NVarChar, 30)).Value = Session("g_Company")
            sqlcol.Add(New SqlParameter("@JobApplications_UserId", SqlDbType.NVarChar, 10)).Value = Session("g_User")
            sqlcol.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 50)).Value = ""
            sqlcol.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 10)).Value = "Insert"
            ExecQuery("JobApplications_Proc", sqlcol).StartsWith("True")
            ClearControls()
            ' VisibleControl()
            lblMessage.Visible = True
            lblMessage.Text = "You have sucssessfully applied for this position"
            jobapp.Visible = False
        Catch ex As Exception

        End Try
    End Sub
    Function fillgrid()
        Try
            Dim Str As String = "SELECT  Vacancy_Kid, Vacancy_Code AS [Job Code], Vacancy_PositionName AS Position, Vacancy_NoOfOpenings AS [No Of Openings], Vacancy_ReqdExperience AS Experience, Vacancy_ReqdAge AS Age, Vacancy_ReqdQualification AS Qualification, Vacancy_Location AS Location,Vacancy_positionflag as Status,Vacancy_JobDescription FROM Vacancy_Master where Vacancy_Isdeleted='0' order by Vacancy_Code "
            Dim da As New SqlDataAdapter(Str, con)
            Dim ds As New DataSet
            da.Fill(ds)
            'GridView1.DataSource = ds.Tables(0)
            'GridView1.DataBind()
            DataList1.DataSource = ds.Tables(0)
            DataList1.DataBind()
        Catch ex As Exception

        End Try
    End Function

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            lblMessage.Visible = False
            Dim b1 As Button = CType(sender, Button)
            jobapp.Visible = True
            Dim Str As String = "SELECT  Vacancy_Kid, Vacancy_Code AS [Job Code], Vacancy_PositionName AS Position, Vacancy_NoOfOpenings AS [No Of Openings], Vacancy_ReqdExperience AS Experience, Vacancy_ReqdAge AS Age, Vacancy_ReqdQualification AS Qualification, Vacancy_Location AS Location,Vacancy_JobDescription as Description,Vacancy_positionflag as Status FROM Vacancy_Master where Vacancy_Kid='" & b1.CommandArgument & "' and  Vacancy_Isdeleted='0' order by Vacancy_Code"
            Dim da As New SqlDataAdapter(Str, con)
            Dim ds As New DataSet
            da.Fill(ds)
            DetailsView1.DataSource = ds.Tables(0)
            DetailsView1.DataBind()
            DetailsView1.Rows(0).Visible = False
            txtJobCode.Text = ds.Tables(0).Rows(0).Item(1).ToString
            txtPosition.Text = ds.Tables(0).Rows(0).Item(2).ToString
            rborfr.SelectedIndex = 0
            rbosex.SelectedIndex = 0
            txtCandidateName.Focus()
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rbosex.SelectedIndexChanged

    End Sub

    Protected Sub DataList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataList1.SelectedIndexChanged

    End Sub
End Class
