Imports SystemImports System.WebImports System.Web.MailImports System.Web.UIImports System.Web.UI.WebcontrolsImports System.Data.SqlClientImports Microsoft.VisualBasic'Imports aspNetMXImports System.IOImports System.CollectionsNamespace PrezconPublic Class GMRegistration : Inherits PagePublic lblTop as LabelPublic ddGames as ListBox        Public ddGift As DropDownList        Public rbGameType As RadioButtonListPublic txtFirstName as textboxPublic txtLastName as TextboxPublic txtStreetAddress as TextboxPublic txtCity as TextboxPublic txtState as TextboxPublic txtZip as TextboxPublic txtEmail as TextboxPublic txtPhone as TextboxPublic bSubmit as ButtonPublic lblStatus as LabelPublic rbGmShirtSize as RadioButtonListPublic txtAsstGM as textboxPublic rbWillPlay as RadioButtonListPublic txtAvoid as textboxPublic rbDemo as RadioButtonListPublic txtDemo as textboxPublic rbJrEvent as RadiobuttonlistPublic txtJrEvent as textboxPublic txtarrival as textboxPublic txtdeparture as textboxPublic cbDayAndTimes as CheckboxListPublic rbRounds as RadioButtonListPublic txtRoundLen as textboxPublic txtContLen as textboxPublic rbFormat as RadioButtonListPublic rbStyle as RadioButtonListPublic txtGuidelines as textbox        Public GMCost As DecimalPublic sBod as stringPublic lContinue as HyperlinkPublic sAddress as stringPublic iGiftCost as Integer        Public giftHash As New Hashtable        Sub GetGiftData()            Dim sDefaultGift As String = "GM Shirt - XL $0.00"            Dim dbConnection As System.Data.IDbConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("DBReader").ToString)            Dim queryString As String = "SELECT * FROM GiftMaster WHERE Type = 'GM' ORDER BY MenuOrder"            Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand            dbCommand.CommandText = queryString            dbCommand.Connection = dbConnection            dbConnection.Open()            Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)            Dim wsTemp, wsGift, wsCost As String            While dataReader.Read()                wsGift = dataReader("gift")                wsCost = Format(dataReader("cost"), "Currency")                wsTemp = wsGift & " " & wsCost                ddGift.Items.Add(New ListItem(wsTemp))                'giftHash(wsTemp) = CDec(dataReader("cost"))                'Response.Write("gifthash(" & wsTemp & ")=" & giftHash(wsTemp) & "<br>")            End While            ddGift.SelectedIndex = ddGift.Items.IndexOf(ddGift.Items.FindByText(sDefaultGift))            dbConnection.Close()        End Sub        Sub LoadGiftHash()            Dim dbConnection As System.Data.IDbConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("DBReader").ToString)            Dim queryString As String = "SELECT * FROM GiftMaster WHERE Type = 'GM' ORDER BY MenuOrder"            Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand            dbCommand.CommandText = queryString            dbCommand.Connection = dbConnection            dbConnection.Open()            Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)            Dim wsTemp, wsGift, wsCost As String            While dataReader.Read()                wsGift = dataReader("gift")                wsCost = Format(dataReader("cost"), "Currency")                wsTemp = wsGift & " " & wsCost                giftHash(wsTemp) = CDec(dataReader("cost"))            End While            dbConnection.Close()        End Subsub Page_Load(Sender as Object, E as EventArgs)            If Page.IsPostBack Then                LoadGiftHash()                Validate_Data()            Else                GetGiftData()                ddGames.DataSource = GetGameData()                ddGames.DataBind()                ddGames.Items.Insert(0, "-- Please select a game here --")                bSubmit.Visible = True                lContinue.Visible = False                If Not Request.Cookies("PrezConGMInfo") Is Nothing Then                    txtFirstName.Text = Request.Cookies("PrezConGMInfo")("FirstName")                    txtLastName.Text = Request.Cookies("PrezConGMInfo")("LastName")                    txtStreetAddress.Text = Request.Cookies("PrezConGMInfo")("Address")                    txtCity.Text = Request.Cookies("PrezConGMInfo")("City")                    txtState.Text = Request.Cookies("PrezConGMInfo")("State").ToUpper                    txtZip.Text = Request.Cookies("PrezConGMInfo")("Zip")                    txtEmail.Text = Request.Cookies("PrezConGMInfo")("Email")                    txtPhone.Text = Request.Cookies("PrezConGMInfo")("Phone")                End If            End Ifend subsub Throw_an_error(sSummary as string, sErrText as string, sContact as string)    dim sBod as string    sBod = "<h1><font color=red>Error occured in validation</font></h1>"    sBod += "<h2>" & sSummary & "</h2>"    sBod += sErrText & "<br>" & sContact    response.write(sBod)    dim objMail as new MailMessage    objMail.From = "registrar@prezcon.com"            objMail.To = "registrar@prezcon.com"            'objMail.CC = " "    objMail.Subject = "Error report from PrezCon.com"    objMail.BodyFormat = MailFormat.HTML    objMail.Body = sBod    objMail.Priority = MailPriority.High    SmtpMail.SmtpServer = "localhost"    SmtpMail.Send(objMail)    response.write("<p>This information has been emailed to the PrezCon Webmaster.</p>")    response.endend subFunction GetGameData()            Dim dbConnection As System.Data.IDbConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("DBReader").ToString)    Dim queryString As String = "SELECT Game FROM GameMaster WHERE Active = 'Y' ORDER BY Game"    Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand    dbCommand.CommandText = queryString    dbCommand.Connection = dbConnection    dbConnection.Open    dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)    return dataReaderend functionsub Validate_Data()    ' validate email address provided'    Dim mx As MXValidate = New MXValidate()'    mx.LogInMemory = True'    Dim EmailAddress As String = txtEmail.Text'    Dim level As MXValidateLevel = mx.Validate(EmailAddress,MXValidateLevel.Mailbox)'    If not level = MXValidateLevel.Mailbox Then'        lblStatus.Font.Size = FontUnit.Point(8)'        lblStatus.ForeColor = Drawing.Color.Red'        lblStatus.text = "<h3>ERROR - " & EmailAddress & " is not a Valid Email Address</h3>"'        lblStatus.text += "Here is the session log<br>"'        lblStatus.text +="-----------------------"'        lblStatus.text += "<pre>" & mx.GetLog() & "</pre>"'        lblTop.ForeColor = Drawing.Color.Red'        lblTop.text = "Please see error information below"'        exit sub'    End If    ' create the SQL insert command    Dim InsertString As String    Insertstring = "INSERT INTO RegisteredGM(Game, FirstName, LastName, Status, Address, City, State, Zip, Email, Phone, LastUpdated) VALUES("    Insertstring += "'" + ddGames.SelectedItem.Value + "', "    Insertstring += "'" + txtFirstName.Text + "', "    Insertstring += "'" + txtLastName.Text + "', "    Insertstring += "'Request',"    sAddress = txtStreetAddress.Text.Replace(VbCrLf, ", ")    Insertstring += "'" + sAddress + "', "    Insertstring += "'" + txtCity.Text + "', "    Insertstring += "'" + txtState.Text.ToUpper + "', "    Insertstring += "'" + txtZip.Text + "', "    Insertstring += "'" + txtEmail.Text + "', "    Insertstring += "'" + txtPhone.Text + "', "    Insertstring += "'" + Now() + "')"    ' open the database and execute the insert command from above    try                Dim dbConnection As System.Data.IDbConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("DBWriter").ToString)        dbConnection.Open        Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand        dbCommand.CommandText = InsertString        dbCommand.Connection = dbConnection        dbCommand.ExecuteNonQuery()        dbConnection.Close	 catch myerr as exception        Throw_an_error("ERROR inserting record [" & Insertstring & "] - registration not recorded!", myerr.tostring, txtEmail.Text)    end try    ' create the confirmation email from the template and send    try        Dim objStreamReader as StreamReader        objStreamReader = File.OpenText(Server.MapPath("gm_confirm.txt"))        sBod = objStreamReader.ReadToEnd()	       objStreamReader.Close()        sBod = sBod.Replace("<firstname>", txtFirstName.Text)        sBod = sBod.Replace("<game>", ddGames.SelectedItem.Value)        sBod = sBod.Replace("<type>", rbGameType.SelectedItem.Text)        sBod = sBod.Replace("<fullname>", txtFirstName.Text + " " + txtLastName.Text)        sBod = sBod.Replace("<address>", sAddress)        sBod = sBod.Replace("<city>", txtCity.Text)        sBod = sBod.Replace("<state>", txtState.Text.ToUpper)        sBod = sBod.Replace("<zip>", txtZip.Text)        sBod = sBod.Replace("<email>", txtEmail.Text)        sBod = sBod.Replace("<phone>", txtPhone.Text)        dim sTemp as string = txtAsstGM.Text        sTemp = sTemp.Replace(VbCrLf, ", ")        sBod = sBod.Replace("<asst>", sTemp)        sBod = sBod.Replace("<play>", rbWillPlay.SelectedItem.Text)        sBod = sBod.Replace("<avoid>", txtAvoid.text)        sBod = sBod.Replace("<demo>", rbDemo.SelectedItem.Text)        sBod = sBod.Replace("<demotime>", txtDemo.text)        sBod = sBod.Replace("<jr>", rbJrEvent.SelectedItem.Text)        sBod = sBod.Replace("<jrtime>", txtJrEvent.text)        sBod = sBod.Replace("<arrival>", txtarrival.text)        sBod = sBod.Replace("<departure>", txtdeparture.text)        dim idx as integer        Dim sDatesandTime as string        Dim bDateTimeSelected as boolean = false        for idx = 0 to cbDayAndTimes.Items.Count -1            If cbDayAndTimes.Items(idx).Selected Then                sDatesandTime += cbDayAndTimes.Items(idx).Value & ", "                bDateTimeSelected = true            End If        Next        if bDateTimeSelected then            sBod = sBod.Replace("<datestimes>", left(sDatesandTime,len(sDatesandTime) -2))            Session("datestimes") = left(sDatesandTime,len(sDatesandTime) -2)        else            sBod = sBod.Replace("<datestimes>", "No event times selected")            Session("datestimes") = "No event times selected"        end if        sBod = sBod.Replace("<heatrnd>", rbRounds.SelectedItem.Text)        sBod = sBod.Replace("<heatlen>", txtRoundLen.text)        sBod = sBod.Replace("<contlen>", txtContLen.text)        sBod = sBod.Replace("<format>", rbFormat.SelectedItem.Text)        sBod = sBod.Replace("<style>", rbStyle.SelectedItem.Text)                Session("gift") = ddGift.SelectedItem.Text                iGiftCost = giftHash(ddGift.SelectedItem.Text)                sBod = sBod.Replace("<shirt>", ddGift.SelectedItem.Text)                If Now() < Session("GMDiscountDate") Then                    GMCost = 35 + iGiftCost                Else                    GMCost = 70 + iGiftCost                End If                Session("cost") = GMCost        sBod = sBod.Replace("<cost>", FormatCurrency(GMCost,2))        sBod = sBod.Replace("<agree>", txtGuidelines.Text)    catch myerr as exception        Throw_an_error("Unable to build email body.",  myerr.tostring, txtEmail.Text)    end try    try        ' send mail        dim objMail as new MailMessage        objMail.From = "registrar@prezcon.com"        objMail.To = txtEmail.Text        objMail.Subject = "PrezCon GM Registration Form - " & ddGames.SelectedItem.Value        objMail.CC = "registrar@prezcon.com"        objMail.BodyFormat = MailFormat.Text        objMail.Body = sBod        SmtpMail.SmtpServer = "localhost"        SmtpMail.Send(objMail)    catch myerr as exception        Throw_an_error("Unable to send email.", myerr.tostring, txtEmail.Text)    end try    ' build the URL for the link to player registration    dim strURL as string    try        strURL = "player_registration.aspx?"        strURL += "FName=" & Server.UrlEncode(txtFirstName.Text)        strURL += "&LName=" & Server.UrlEncode(txtLastName.Text)        strURL += "&Address=" & Server.UrlEncode(sAddress)        strURL += "&City=" & Server.UrlEncode(txtCity.Text)        strURL += "&State=" & Server.UrlEncode(txtState.Text.ToUpper)        strURL += "&Zip=" & Server.UrlEncode(txtZip.Text)        strURL += "&Email=" & Server.UrlEncode(txtEmail.Text)        strURL += "&Phone=" & Server.UrlEncode(txtPhone.Text)                strURL += "&Shirt=" & Server.UrlEncode(ddGift.SelectedItem.Text)        strURL += "&GMFee=" & Server.URLEncode(GMCost.toString)        Session("url") = strURL    catch myerr as exception        Throw_an_error("Unable to construct URL.", myerr.tostring, txtEmail.Text)    end try    ' lets try to store the info in a cookie    Response.Cookies("PrezConGMInfo").Expires = now.AddDays(-1)    Dim Cookie as HttpCookie = New HttpCookie("PrezConGMInfo")    Response.Cookies("PrezConGMInfo").Domain = "prezcon.com"    Cookie.Values.Add("FirstName",txtFirstName.Text)    Cookie.Values.Add("LastName",txtLastName.Text)    Cookie.Values.Add("Address",sAddress)    Cookie.Values.Add("City",txtCity.Text)    Cookie.Values.Add("State",txtState.Text.ToUpper)    Cookie.Values.Add("Zip",txtZip.Text)    Cookie.Values.Add("Email",txtEmail.Text)    Cookie.Values.Add("Phone",txtPhone.Text)    Cookie.Expires = now.AddMonths(24)    Response.Cookies.Add(Cookie)end subEnd ClassEnd Namespace