Form.aspx.vb:
Option Explicit On
Option Strict On
Imports System.Data
Imports System.Data.SqlClient
Partial Class PermitApplication_Form
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
CType(fvMain.FindControl("chkBurnDescriptionOther"),
CheckBox).InputAttributes.Add("disabled", "disabled")
End Sub
Protected Sub cblBurnDescription_SelectedIndexChanged()
If CType(fvMain.FindControl("cblBurnDescription"),
CheckBoxList).SelectedIndex > -1 Then
Dim i As Integer
Dim sBurnDescription As String = ""
For i = 0 To CType(fvMain.FindControl("cblBurnDescription"),
CheckBoxList).Items.Count - 1
If CType(fvMain.FindControl("cblBurnDescription"),
CheckBoxList).Items(i).Selected Then
sBurnDescription &=
CType(fvMain.FindControl("cblBurnDescription"),
CheckBoxList).Items(i).Value.ToString & vbNewLine
CType(fvMain.FindControl("cblBurnDescription"),
CheckBoxList).Items(i).Enabled = False
End If
Next
If (CType(fvMain.FindControl("chkBurnDescriptionOther"),
CheckBox).Checked = True) Then
sBurnDescription &=
CType(fvMain.FindControl("txtBurnDescriptionOther"), TextBox).Text
End If
CType(fvMain.FindControl("Burn_Description"), TextBox).Text =
sBurnDescription
CType(fvMain.FindControl("upBurnDescrptionTXT"),
UpdatePanel).Update()
End If
End Sub
Protected Sub BurnDescriptionClear_onclick()
CType(fvMain.FindControl("Burn_Description"), TextBox).Text = ""
Dim elem As Object = PermitApplicationForm.Controls
For i = 0 To CType(fvMain.FindControl("cblBurnDescription"),
CheckBoxList).Items.Count - 1
CType(fvMain.FindControl("cblBurnDescription"),
CheckBoxList).Items(i).Selected = False
CType(fvMain.FindControl("cblBurnDescription"),
CheckBoxList).Items(i).Enabled = True
Next
CType(fvMain.FindControl("chkBurnDescriptionOther"),
CheckBox).Checked = False
CType(fvMain.FindControl("chkBurnDescriptionOther"),
CheckBox).InputAttributes.Add("disabled", "disabled")
CType(fvMain.FindControl("txtBurnDescriptionOther"), TextBox).Text =
""
End Sub
Protected Sub CustomValidatorAgree_ServerValidate(ByVal src As Object,
ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
Dim cv As CustomValidator
cv = CType(fvMain.FindControl("cvRulesAndRegs"), CustomValidator)
Dim chk As CheckBox
chk = CType(fvMain.FindControl("chkRulesAndRegs"), CheckBox)
Dim boolIsChecked As Boolean
boolIsChecked = chk.Checked
cv.IsValid = boolIsChecked
End Sub
Protected Function DeterminBPID(ByVal oCon As SqlConnection, ByVal sYear
As String) As Integer
Dim sSQL As String
Dim iBPID As Integer
Try
Dim temp1, temp2 As Integer
temp1 = CInt(CStr(sYear) & "0001")
temp2 = CInt(CStr(sYear) & "9999")
sSQL = "SELECT MAX(BPID) AS [MaxBPID] FROM BurningPermitMain
WHERE BPID >= @BPID1 And BPID <= @BPID2"
Dim oCmd As New Data.SqlClient.SqlCommand
oCmd.Connection = oCon
oCmd.CommandText = sSQL
oCmd.Parameters.AddWithValue("@BPID1", temp1)
oCmd.Parameters.AddWithValue("@BPID2", temp2)
If Not IsDBNull(oCmd.ExecuteScalar()) Then
iBPID = CInt(oCmd.ExecuteScalar())
iBPID += 1
Else
iBPID = CInt(CStr(sYear) & "0001")
End If
oCmd = Nothing
Catch ex As Exception
Dim sMessage As String
sMessage = ex.Message
'TODO:Redirect to an error page
'"An error occured with this application
(PermitApplication:Selecting BPID)."
Exit Function
End Try
Return iBPID
End Function
Protected Sub sdsMain_Inserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles
sdsMain.Inserting
'Start a transaction so we can find the ID of the inserted value
Dim cmd As SqlCommand
Dim con As SqlConnection
Dim InsertTransaction As SqlTransaction
cmd = CType(e.Command, SqlCommand)
con = cmd.Connection
con.Open()
InsertTransaction = con.BeginTransaction
cmd.Transaction = InsertTransaction
End Sub
Protected Sub sdsMain_Inserted(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles
sdsMain.Inserted
Dim cmd As SqlCommand
Dim InsertTransaction As SqlTransaction
Dim iID As Integer
cmd = CType(e.Command, SqlCommand)
InsertTransaction = cmd.Transaction
cmd.CommandText = "SELECT @@IDENTITY AS [ID]"
iID = CInt(cmd.ExecuteScalar().ToString)
InsertTransaction.Commit()
sdsMain.SelectParameters.Add("ID", CStr(iID))
sdsMain.SelectParameters("ID").DefaultValue = CStr(iID)
'fvMain.ChangeMode(FormViewMode.Edit)
'fvMain.DefaultMode = FormViewMode.Edit
Dim iBPID As Integer
Try
Dim sConnectString, sSQL As String
Dim oCon As New SqlConnection
Dim oCmd As New SqlCommand
sConnectString =
System.Configuration.ConfigurationManager.ConnectionStrings("RDOS_AppConnectionString").ToString
oCon.ConnectionString = sConnectString
oCon.Open()
sSQL = "SELECT BPID FROM BurningPermitMain WHERE ID = @ID"
oCmd = New Data.SqlClient.SqlCommand(sSQL, oCon)
oCmd.Parameters.AddWithValue("@ID", iID)
iBPID = CInt(oCmd.ExecuteScalar)
oCon.Close()
Catch ex As Exception
Dim sMessage As String
sMessage = ex.Message
'TODO:Redirect to an error page.
'"An error occured with this application
(PermitApplication:Selecting new BPID)."
Exit Sub
End Try
'TODO:this doesn't work, must set BPID then submit form
Response.Redirect("TrackPermit.aspx?BPID=" & iBPID)
End Sub
Protected Sub InsertButton_OnClick()
Dim sConnectString, sSQL As String
Dim oCon As New SqlConnection
sConnectString =
System.Configuration.ConfigurationManager.ConnectionStrings("RDOS_AppConnectionString").ToString
Try
oCon.ConnectionString = sConnectString
oCon.Open()
Catch ex As Exception
Dim sMessage As String
sMessage = ex.Message
'TODO:Redirect to an error page.
'"An error occured with this application
(PermitApplication:Opening Database Connection)."
Exit Sub
End Try
Dim iBPID As Integer
Dim sYear, sFirstName, sLastName, sMailingAddress, sCity,
sPostalCode, sPhone, sAltPhone, sCellPhone, sFax As String
Dim sEmail, sFireProtectionArea, sBurnDescription, sApplicationDate,
sOwnerFirstName, sOwnerLastName, sPrimfolio, sBurnLocationAddress,
sApplicationSubmittedBy, sPropertyType As String
sYear = CType(fvMain.FindControl("Year"), DropDownList).SelectedValue
sFirstName = CType(fvMain.FindControl("First_Name"), TextBox).Text
sLastName = CType(fvMain.FindControl("Last_Name"), TextBox).Text
sMailingAddress = CType(fvMain.FindControl("Mailing_Address"),
TextBox).Text
sCity = CType(fvMain.FindControl("City"), TextBox).Text
sPostalCode = CType(fvMain.FindControl("Postal_Code"), TextBox).Text
sPhone = CType(fvMain.FindControl("Phone"), TextBox).Text
sAltPhone = CType(fvMain.FindControl("Alt_Phone"), TextBox).Text
sCellPhone = CType(fvMain.FindControl("Cell_Phone"), TextBox).Text
sFax = CType(fvMain.FindControl("Fax"), TextBox).Text
sEmail = CType(fvMain.FindControl("Email"), TextBox).Text
sFireProtectionArea =
CType(fvMain.FindControl("Fire_Protection_Area"), DropDownList).SelectedValue
sBurnDescription = CType(fvMain.FindControl("Burn_Description"),
TextBox).Text
sApplicationDate = Now().ToString
sOwnerFirstName = CType(fvMain.FindControl("Owner_First_Name"),
TextBox).Text
sOwnerLastName = CType(fvMain.FindControl("Owner_Last_Name"),
TextBox).Text
sPrimfolio = CType(fvMain.FindControl("Primfolio"), TextBox).Text
sBurnLocationAddress = CType(fvMain.FindControl("Burn_Address"),
TextBox).Text
sApplicationSubmittedBy =
CType(fvMain.FindControl("ApplicationSubmitedBy"), DropDownList).SelectedValue
sPropertyType = CType(fvMain.FindControl("rblPropertyType"),
RadioButtonList).SelectedValue
iBPID = DeterminBPID(oCon, sYear)
If iBPID > 0 Then
sdsMain.InsertParameters("BPID").DefaultValue = CStr(iBPID)
sdsMain.InsertParameters("FirstName").DefaultValue = sFirstName
sdsMain.InsertParameters("LastName").DefaultValue = sLastName
sdsMain.InsertParameters("MailingAddress").DefaultValue =
sMailingAddress
sdsMain.InsertParameters("City").DefaultValue = sCity
sdsMain.InsertParameters("PostalCode").DefaultValue = sPostalCode
sdsMain.InsertParameters("Phone").DefaultValue = sPhone
sdsMain.InsertParameters("AltPhone").DefaultValue = sAltPhone
sdsMain.InsertParameters("CellPhone").DefaultValue = sCellPhone
sdsMain.InsertParameters("Fax").DefaultValue = sFax
sdsMain.InsertParameters("Email").DefaultValue = sEmail
sdsMain.InsertParameters("FireProtectionArea").DefaultValue =
sFireProtectionArea
sdsMain.InsertParameters("BurnDescription").DefaultValue =
sBurnDescription
sdsMain.InsertParameters("ApplicationDate").DefaultValue =
sApplicationDate
sdsMain.InsertParameters("OwnerFirstName").DefaultValue =
sOwnerFirstName
sdsMain.InsertParameters("OwnerLastName").DefaultValue =
sOwnerLastName
sdsMain.InsertParameters("Primfolio").DefaultValue = sPrimfolio
sdsMain.InsertParameters("BurnLocationAddress").DefaultValue =
sBurnLocationAddress
sdsMain.InsertParameters("ApplicationSubmitedBy").DefaultValue =
sApplicationSubmittedBy
sdsMain.InsertParameters("PropertyType").DefaultValue =
sPropertyType
Else
'Abort
'TODO:Redirect to error page
Exit Sub
End If
Dim sToEmailAddress, sFrom, sSenderEmailAddress, sEmailSubject As
String
Try
''Email addresses
sEmailSubject = "Burning Permit Application"
sSenderEmailAddress = "(e-mail address removed)"
sFrom = "Burning Permit Internal Application"
sSQL = "SELECT Email FROM BurningInfo WHERE Fire_Prot_Area =
@FireProtectionArea"
Dim oCmd As New Data.SqlClient.SqlCommand
oCmd.Connection = oCon
oCmd.CommandText = sSQL
oCmd.Parameters.AddWithValue("@FireProtectionArea",
sFireProtectionArea)
sToEmailAddress = oCmd.ExecuteScalar.ToString
If sToEmailAddress = "" Then
sToEmailAddress = "(e-mail address removed)"
End If
''=================================================================
'' Uncomment if you want to test.
''=================================================================
sToEmailAddress = "(e-mail address removed)"
''=================================================================
oCmd = Nothing
Catch ex As Exception
Dim sMessage As String
sMessage = ex.Message
'TODO:Redirect to an error page
'"An error occured with this application
(PermitApplication:Selecting Fire Department Email)."
Exit Sub
End Try
Try
Dim emailText As String
emailText = "<html><table cellpadding=2>" & vbNewLine & _
"<tr><td colspan=2>An Online Burning Permit Application has been
submitted via the RDOS intranet website.</td></tr>" & _
"<tr><td colspan=2>Please follow the link below and
approve/disapprove the application.</td></tr>" & _
"<tr><td colspan=2>---- Contact Information ----</td></tr>" & _
"<tr><td>Burning Permit ID:</td><td>" & iBPID & "</td></tr>" & _
"<tr><td>First Name:</td><td>" & sFirstName & "</td></tr>" & _
"<tr><td>Last Name:</td><td>" & sLastName & "</td></tr>" & _
"<tr><td>Owner's First Name:</td><td>" & sOwnerFirstName &
"</td></tr>" & _
"<tr><td>Owner's Last Name:</td><td>" & sOwnerLastName &
"</td></tr>" & _
"<tr><td>Mailing Address:</td><td>" & sMailingAddress &
"</td></tr>" & _
"<tr><td>City/Town:</td><td>" & sCity & "</td></tr>" & _
"<tr><td>Postal Code:</td><td>" & sPostalCode & "</td></tr>" & _
"<tr><td>Phone:</td><td>" & sPhone & "</td></tr>" & _
"<tr><td>Alternative Phone:</td><td>" & sAltPhone & "</td></tr>"
& _
"<tr><td>Cell Phone:</td><td>" & sCellPhone & "</td></tr>" & _
"<tr><td>Fax:</td><td>" & sFax & "</td></tr>" & _
"<tr><td>Email:</td><td>" & sEmail & "</td></tr>" & _
"<tr><td colspan=2>---- Burn Information ----</td></tr>" & _
"<tr><td>Address of Burn Location:</td><td>" &
sBurnLocationAddress & "</td></tr>" & _
"<tr><td>Fire Protection Area:</td><td>" & sFireProtectionArea &
"</td></tr>" & _
"<tr><td>Burn Description:</td><td>" & sBurnDescription &
"</td></tr>" & _
"<tr><td>Property Type:</td><td>" & sPropertyType & "</td></tr>"
& _
"<tr><td colspan=2>---- Follow up ----</td></tr>" & _
"<tr><td>Application Submited By:</td><td>" &
sApplicationSubmittedBy & "</td></tr>" & _
"<tr><td><a
href=
http://www.rdosmaps.bc.ca/BurningPermitX/TrackPermit.aspx?BPID=" & iBPID
& ">Click Here</a></td></tr></table></html>"
Dim oFromMailAddress As New
Net.Mail.MailAddress(sSenderEmailAddress, sFrom)
Dim oToMailAddress As New Net.Mail.MailAddress(sToEmailAddress)
Dim oMessage As New Net.Mail.MailMessage(oFromMailAddress,
oToMailAddress)
oMessage.Subject = sEmailSubject
oMessage.IsBodyHtml = True
oMessage.Body = emailText
Dim client As New Net.Mail.SmtpClient("rdosmail", 25)
client.Send(oMessage)
oMessage.Dispose()
oMessage = Nothing
Catch ex As Exception
Dim sMessage As String
sMessage = ex.Message
'TODO:Redirect to an error page
'"An error occured with this application
(PermitApplication_submitSending Email)."
Exit Sub
End Try
oCon.Close()
End Sub
End Class