⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 registration.aspx.vb

📁 Build words list automatic
💻 VB
字号:
Public Class Registration
    Inherits System.Web.UI.Page


#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm
    Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button
    Protected WithEvents txtCountry As System.Web.UI.WebControls.TextBox
    Protected WithEvents lblCountry As System.Web.UI.WebControls.Label
    Protected WithEvents txtCity As System.Web.UI.WebControls.TextBox
    Protected WithEvents lblCity As System.Web.UI.WebControls.Label
    Protected WithEvents reqEmail As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents regEmail As System.Web.UI.WebControls.RegularExpressionValidator
    Protected WithEvents txtEmail As System.Web.UI.WebControls.TextBox
    Protected WithEvents lblEmail As System.Web.UI.WebControls.Label
    Protected WithEvents txtPhone As System.Web.UI.WebControls.TextBox
    Protected WithEvents lblPhone As System.Web.UI.WebControls.Label
    Protected WithEvents txtOrganisationType As System.Web.UI.WebControls.TextBox
    Protected WithEvents lblOrganisationType As System.Web.UI.WebControls.Label
    Protected WithEvents txtOrganisation As System.Web.UI.WebControls.TextBox
    Protected WithEvents lblOrganisation As System.Web.UI.WebControls.Label
    Protected WithEvents reqLastname As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents txtLastName As System.Web.UI.WebControls.TextBox
    Protected WithEvents lblLastName As System.Web.UI.WebControls.Label
    Protected WithEvents reqFirstname As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents txtFirstNames As System.Web.UI.WebControls.TextBox
    Protected WithEvents lblFirstNames As System.Web.UI.WebControls.Label
    Protected WithEvents lblUsername As System.Web.UI.WebControls.Label
    Protected WithEvents lblID As System.Web.UI.WebControls.Label
    Protected WithEvents lblFeedback As System.Web.UI.WebControls.Label
    Protected WithEvents btnClose As System.Web.UI.WebControls.LinkButton

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dacc As New DataAccessBase
        Dim ds As DataSet, sSQL As String

        lblFeedback.EnableViewState = False

        If Page.IsPostBack Then Exit Sub

        Try
            dacc.Open(Session("connDbControl"))
            dacc.IsFillSchema = True

            sSQL = "SELECT * FROM Persons WHERE PersonID = '" & Session("Username") & "';"
            ds = dacc.GetData("Persons", sSQL)
            Session("dsPersons") = ds
            dacc.Close()

            If Session("Username") <> "" Then
                Dim dr As DataRow
                dr = ds.Tables("Persons").Rows(0)
                lblUsername.Text = dr.Item("PersonID").ToString
                txtFirstNames.Text = dr.Item("FirstNames").ToString
                txtLastName.Text = dr.Item("LastName").ToString
                txtOrganisation.Text = dr.Item("Organisation").ToString
                txtOrganisationType.Text = dr.Item("Organisationtype").ToString
                txtPhone.Text = dr.Item("Phone").ToString
                txtEmail.Text = dr.Item("Email").ToString
                txtCity.Text = dr.Item("City").ToString
                txtCountry.Text = dr.Item("Country").ToString
            End If
        Catch ex As Exception
            dacc.Close()
            lblFeedback.ForeColor = Color.Red
            lblFeedback.Text = "ERROR: " & ex.Message
        End Try
    End Sub

    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim ds As DataSet
        Dim dacc As New DataAccessBase
        Dim sSQL As String
        Dim sNewPersonID As String, sNewPersonIdStart As String, sNewPassword As String
        Dim dr As DataRow
        Dim bNewUser As Boolean, bAutoEmail As Boolean
        Dim s As String

        Try
            dacc.IsWrapBrackets = True
            'Bring the dataset back out of storage
            ds = Session("dsPersons")
            dacc.Open(Session("connDbControl"))
            If ds.Tables("Persons").Rows.Count = 0 Then
                'This is a new registration .. generate Username from FirstNames
                sNewPersonIdStart = Replace(txtFirstNames.Text, "'", "")
                sNewPersonIdStart = Left(Replace(sNewPersonIdStart, " ", ""), 6)
                'does it already exist?
                sNewPersonID = sNewPersonIdStart

                Dim i As Integer

                For i = 0 To 99
                    If i > 0 Then sNewPersonID = sNewPersonIdStart & Format(i, "00")
                    sSQL = "SELECT PersonId FROM Persons WHERE PersonID = '" & sNewPersonID & "';"
                    'Function GetData for the first table, FillTable for any extra tables
                    Call dacc.FillTable(ds, "TestUser", sSQL)
                    If ds.Tables("TestUser").Rows.Count = 0 Then Exit For
                    ds.Tables.Remove(ds.Tables("TestUser"))
                Next i
                If i = 100 Then
                    lblFeedback.ForeColor = Color.Red
                    lblFeedback.Text = "ERROR: There are too many people here with names like '" & sNewPersonIdStart & "'.  Please alter your FirstNames, eg use a nickname, and try again."
                    Exit Sub
                End If
                sNewPassword = Format(Timer, "00000")
                '
                dr = ds.Tables("Persons").NewRow
                dr.Item("PersonID") = sNewPersonID
                dr.Item("Password") = sNewPassword
            Else
                'Existing user, dr is the existing first row
                dr = ds.Tables("Persons").Rows(0)
            End If

            dr.Item("FirstNames") = txtFirstNames.Text
            dr.Item("LastName") = txtLastName.Text
            dr.Item("Organisation") = txtOrganisation.Text
            dr.Item("Organisationtype") = txtOrganisationType.Text
            dr.Item("Phone") = txtPhone.Text
            dr.Item("Email") = txtEmail.Text
            dr.Item("City") = txtCity.Text
            dr.Item("Country") = txtCountry.Text
            '
            If ds.Tables("Persons").Rows.Count = 0 Then
                'This is a new row, so after building it, we need to Add it
                ds.Tables("Persons").Rows.Add(dr)
                lblUsername.Text = sNewPersonID
                bNewUser = True
            End If

            dacc.PutData(ds, "Persons")
            dacc.Close()

            '050626 JPC String value from configurationsettings needs checking for various
            '   user interpretations of boolean true like "1", "-1", "true", "True", "yes", "Y"
            s = Trim(LCase(ConfigurationSettings.AppSettings("IsAutoEmail")))
            If IsNumeric(s) Then
                If CDbl(s) <> 0 Then bAutoEmail = True
            Else
                If Left(s, 1) = "t" Or Left(s, 1) = "y" Then bAutoEmail = True
            End If
            If bAutoEmail And bNewUser Then
                'Send an email
                Try
                    Dim Email As New System.Web.Mail.MailMessage
                    Email.To = txtEmail.Text
                    Email.From = ConfigurationSettings.AppSettings("AutoEmailFrom")
                    Email.Subject = "Registration Confirmed"
                    Email.Body = "Welcome to our group.  Your Username is '" & sNewPersonID & "'  Your password is '" & sNewPassword & "'."
                    If ConfigurationSettings.AppSettings("AutoEmailSmtpServer") > "" Then
                        System.Web.Mail.SmtpMail.SmtpServer = ConfigurationSettings.AppSettings("AutoEmailSmtpServer")
                    End If
                    System.Web.Mail.SmtpMail.Send(Email)
                    lblFeedback.ForeColor = Color.Green
                    lblFeedback.Text = "Registration successful.  Your username and password is now being emailed to the address you have supplied."
                Catch ex As Exception
                    'SILENT error messaging, write a 'LogEvent'
                    dacc.Open(Session("connDbControl"))
                    sSQL = "INSERT INTO LogEvents(DateOfEvent, Description) " _
                    & "VALUES('" & Format(Now, "yyyy-MM-dd HH:mm") & "'" _
                    & ",'EMAIL SEND ERROR: " _
                    & Replace(Left(ex.message, 230), "'", "''") & "');"
                    dacc.ExecuteNonQuery(sSQL)
                    dacc.Close()
                    lblFeedback.ForeColor = Color.Green
                    lblFeedback.Text = "Registration process started.  The administrator will check your registration and contact you."
                End Try
            ElseIf bNewUser Then
                lblFeedback.ForeColor = Color.Green
                lblFeedback.Text = "Registration Process Started.  The administrator will check your registration and contact you."
            Else
                'Existing rather than new user
                lblFeedback.ForeColor = Color.Green
                lblFeedback.Text = "Changes Saved OK"
            End If
        Catch ex As Exception
            dacc.Close()
            lblFeedback.ForeColor = Color.Red
            lblFeedback.Text = "ERROR: " & ex.Message
        End Try
    End Sub

End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -