Imports System.Web.Configuration
Imports System.Data.SqlClient
Imports System.IO
Imports System.Data
Imports System
Imports System.Collections
Imports System.Xml.Serialization
Imports System.Windows.Forms
Imports System.Net.Mail
Partial Class applicant
Inherits System.Web.UI.Page
Function shortendate(ByVal sItem As String) As String
shortendate = FormatDateTime(sItem, DateFormat.ShortDate)
End Function
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If Page.IsValid Then
Dim insertSQL As String
insertSQL = "Insert into Application (Position, Title, PreviousName, Firstname, Surname, CurrentAddress, PhoneHome, PhoneMobile, "
insertSQL = insertSQL & " PreviousAddress1, PreviousAddress2, PreviousAddress3, PreviousAddress4, "
insertSQL = insertSQL & "DoB, PlaceofB, nationality, DL, CR, CRDetails, UCCJ, UCCJDetails,PH, "
insertSQL = insertSQL & "EmploymentGaps,SubmitOnlineDate) Values (@Position,@Title, @PreviousName,@FirstName,@SurName,@CurrentAddress,@PhoneHome,@PhoneMobile,"
insertSQL = insertSQL & "@PreviousAddress1,@PreviousAddress2,@PreviousAddress3,@PreviousAddress4,"
insertSQL = insertSQL & "@DoB,@PlaceofB,@nationality,@DL,@CR,@CRDetails,@UCCJ,@UCCJDetails,@PH,"
insertSQL = insertSQL & "@EmploymentGaps,GETDATE())"
Dim connectionString As String = WebConfigurationManager.ConnectionStrings("cstr").ConnectionString
Dim con As New SqlConnection(connectionString)
Dim cmd As New SqlCommand(insertSQL, con)
cmd.Parameters.AddWithValue("@Position", Position.Text)
cmd.Parameters.AddWithValue("@Title", Title.Text)
cmd.Parameters.AddWithValue("@Previousname", PreviousName.Text)
cmd.Parameters.AddWithValue("@FirstName", System.Globalization.CultureInfo.CurrentUICulture.TextInfo.ToTitleCase(FirstName.Text))
cmd.Parameters.AddWithValue("@SurName", System.Globalization.CultureInfo.CurrentUICulture.TextInfo.ToTitleCase(Surname.Text))
cmd.Parameters.AddWithValue("@CurrentAddress", CurrentAddress.Text)
cmd.Parameters.AddWithValue("@PhoneHome", PhoneHome.Text)
cmd.Parameters.AddWithValue("@PhoneMobile", PhoneMobile.Text)
cmd.Parameters.AddWithValue("@PreviousAddress1", PreviousAddress1.Text)
cmd.Parameters.AddWithValue("@PreviousAddress2", PreviousAddress2.Text)
cmd.Parameters.AddWithValue("@PreviousAddress3", PreviousAddress3.Text)
cmd.Parameters.AddWithValue("@PreviousAddress4", PreviousAddress4.Text)
cmd.Parameters.AddWithValue("@DoB", ApplicantsDOB.Text)
cmd.Parameters.AddWithValue("@PlaceofB", PlaceofB.Text)
cmd.Parameters.AddWithValue("@nationality", nationality.Text)
cmd.Parameters.AddWithValue("@DL", DL.Text)
cmd.Parameters.AddWithValue("@CR", CR.Text)
cmd.Parameters.AddWithValue("@CRDetails", CRdetails.Text)
cmd.Parameters.AddWithValue("@UCCJ", UCCJ.Text)
cmd.Parameters.AddWithValue("@UCCJDetails", UCCJdetails.Text)
cmd.Parameters.AddWithValue("@PH", PH.Text)
cmd.Parameters.AddWithValue("@EmploymentGaps", EmploymentGaps.Text)
cmd.CommandText = insertSQL
Try
con.Open()
cmd.ExecuteNonQuery()
Catch SQLExp As SqlException
'Uncomment the next line to debug the SQL insert command
Response.Write("An SQL Server Error Occurred - " & SQLExp.ToString())
Response.Write("An error has occurred. Please contact European Background on 0044 1730 829202 to correct data entry")
Exit Sub
'Response.Redirect("errorpage.aspx?errmessage=" & "A database error has occurred")
End Try
con.Close()
' MailHelper.SendMailMessage("bob@sowton.net", "bob@sowton.net", "", "", "New Applicant Details", "A new applicant from Sony")
Response.Redirect("applicantdone.aspx")
End If
End Sub
Public Class MailHelper
'''
''' Sends an mail message
'''
''' Sender address
''' recipient address
''' Bcc recipient
''' Cc recipient
''' Subject of mail message
''' Body of mail message
Public Shared Sub SendMailMessage(ByVal from As String, ByVal recipient As String, ByVal bcc As String, ByVal cc As String, ByVal subject As String, ByVal body As String)
' Instantiate a new instance of MailMessage
Dim mMailMessage As New MailMessage()
' Set the sender address of the mail message
mMailMessage.From = New MailAddress(from)
' Set the recipient address of the mail message
mMailMessage.To.Add(New MailAddress(recipient))
' Check if the bcc value is nothing or an empty string
If Not bcc Is Nothing And bcc <> String.Empty Then
' Set the Bcc address of the mail message
mMailMessage.Bcc.Add(New MailAddress(bcc))
End If
' Check if the cc value is nothing or an empty value
If Not cc Is Nothing And cc <> String.Empty Then
' Set the CC address of the mail message
mMailMessage.CC.Add(New MailAddress(cc))
End If
' Set the subject of the mail message
mMailMessage.Subject = subject
' Set the body of the mail message
mMailMessage.Body = body
' Set the format of the mail message body as HTML
mMailMessage.IsBodyHtml = True
' Set the priority of the mail message to normal
mMailMessage.Priority = MailPriority.Normal
' Instantiate a new instance of SmtpClient
Dim mSmtpClient As New SmtpClient()
' Send the mail message
mSmtpClient.Send(mMailMessage)
End Sub
End Class
End Class