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

📄 submitnotice.aspx.vb

📁 Build words list automatic
💻 VB
字号:
Imports System.Data.OleDb
Imports XMContentManager.DataAccessBase

Public Class submitnotice
    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 Label2 As System.Web.UI.WebControls.Label
    Protected WithEvents Label3 As System.Web.UI.WebControls.Label
    Protected WithEvents Label4 As System.Web.UI.WebControls.Label
    Protected WithEvents Label5 As System.Web.UI.WebControls.Label
    Protected WithEvents Label6 As System.Web.UI.WebControls.Label
    Protected WithEvents Label7 As System.Web.UI.WebControls.Label
    Protected WithEvents body As System.Web.UI.HtmlControls.HtmlTable
    Protected WithEvents formArea As System.Web.UI.HtmlControls.HtmlTableCell
    Protected WithEvents lblAuthor As System.Web.UI.WebControls.Label
    Protected WithEvents txtAuthor As System.Web.UI.WebControls.TextBox
    Protected WithEvents lstCategory As System.Web.UI.WebControls.DropDownList
    Protected WithEvents txtNotice As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtInformation As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtTargetDate As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtTargetRange As System.Web.UI.WebControls.TextBox
    Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button
    Protected WithEvents lblResult As System.Web.UI.WebControls.Label
    Protected WithEvents Label8 As System.Web.UI.WebControls.Label
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents lblMandatory As System.Web.UI.WebControls.Label
    Protected WithEvents btnReset As System.Web.UI.WebControls.Button
    Protected WithEvents Label9 As System.Web.UI.WebControls.Label
    Protected WithEvents Label10 As System.Web.UI.WebControls.Label
    Protected WithEvents Label11 As System.Web.UI.WebControls.Label
    Protected WithEvents Label12 As System.Web.UI.WebControls.Label
    Protected WithEvents divForm As System.Web.UI.HtmlControls.HtmlGenericControl
    Protected WithEvents lblFeedback As System.Web.UI.WebControls.Label
    Protected WithEvents txtStartDate As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtEndDate As System.Web.UI.WebControls.TextBox

    '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
        'Put user code to initialize the page here
        If Page.IsPostBack Then Exit Sub
        Dim dacc As New DataAccessBase
        'If Not User.IsInRole(ConfigurationSettings.AppSettings("privilegedGroup")) Then
        '    divForm.InnerHtml = ""
        '    lblResult.Text = "You are not authorized to Add/Edit/Delete notices."
        '    Exit Sub
        'End If

        txtStartDate.Text = Format(Now(), "Short Date")
        txtEndDate.Text = Format(Now().AddDays(7), "Short Date")

        If Request.QueryString("task") = "edit" Then editNotice()
        'If Request.QueryString("task") = "delete" Then deleteNotice()

        Try
            dacc.Open(Session("connDbNotices"))
            Dim ds As DataSet = dacc.GetData("Categories", "SELECT Category FROM [Categories]")
            lstCategory.DataSource = ds.Tables("Categories")
            lstCategory.DataTextField = "Category"
            lstCategory.DataBind()

        Catch ex As Exception
            lblResult.Text = ex.Message
        Finally
            dacc.Close()
        End Try

    End Sub
    Private Sub editNotice()
        Dim id As Integer = Request.QueryString("id")
        lblResult.Text = "Edit mode, id = " & id
        Dim dacc As New DataAccessBase
        dacc.Open(Session("connDbNotices"))
        Dim ds As DataSet = dacc.GetData("Notices", "SELECT * FROM Notices WHERE ID =" & id)
        With ds.Tables("Notices").Rows(0)
            txtAuthor.Text = .Item(2)
            lstCategory.SelectedValue = .Item(4)
            txtNotice.Text = .Item(5)
            txtInformation.Text = .Item(6)
            txtStartDate.Text = .Item(7)
            txtEndDate.Text = .Item(8)
        End With
        dacc.Close()
    End Sub

    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        '1.check required fields are not blank
        '2.open database
        '3.send to database
        '4.close database
        If Request.QueryString("task") = "edit" Then
            btnSubmit_Edit() 'Slightly different
            Exit Sub
        End If
        '
        Dim dacc As New DataAccessBase
        dacc.Open(Session("connDbNotices"))
        'Get dataset with empty datatable as starting point
        Dim ds As DataSet = dacc.GetData("Notices", "SELECT * FROM [Notices] WHERE 1 = 0;")

        If ValidateFields() Then
            Try
                Dim dr As DataRow = FillDR(ds.Tables("Notices").NewRow)
                ds.Tables("Notices").Rows.Add(dr)
                dacc.PutData(ds, "Notices")
                If CBool(ConfigurationSettings.AppSettings("noticesModeration")) Then
                    lblResult.Text = " Notice submitted to moderator for checking before publishing. "
                Else
                    lblResult.Text = " Notice submitted Successfully "
                End If
                ResetFields()
            Catch ex As Exception
                lblResult.Text = ex.Message
            Finally
                dacc.Close()
            End Try
        End If

    End Sub

    Private Sub btnSubmit_Edit()
        Dim id As Integer = Request.QueryString("id")
        Dim dacc As New DataAccessBase
        lblResult.Text = "Edit mode, id = " & id
        If ValidateFields() Then
            Try
                dacc.Open(Session("connDbNotices"))
                Dim ds As DataSet = dacc.GetData("Notices", "SELECT * FROM Notices WHERE ID =" & id)
                Dim dr As DataRow = FillDR(ds.Tables("Notices").Rows(0))

                dacc.PutData(ds, "Notices")
                If CBool(ConfigurationSettings.AppSettings("noticesModeration")) Then
                    lblResult.Text = " Notice submitted to moderator for checking before publishing. "
                Else
                    lblResult.Text = " Notice submitted Successfully "
                End If

            Catch ex As Exception
                lblResult.Text = ex.Message & ex.GetType.ToString
            Finally
                dacc.Close()
            End Try
        End If
    End Sub

    Private Function FillDR(ByRef dr As DataRow) As DataRow
        dr(2) = txtAuthor.Text
        'if this a new notice, we need to put todays date in dr(3) as submitted date.
        If dr.RowState = DataRowState.Detached Then dr(3) = Format(Now(), "Short Date")
        dr(4) = lstCategory.SelectedItem.Text
        dr(5) = txtNotice.Text
        dr(6) = txtInformation.Text
        dr(7) = txtStartDate.Text
        'following is obsolete, these date text fields have default values.
        'If txtEndDate.Text = "" Then txtEndDate.Text = txtStartDate.Text
        dr(8) = txtEndDate.Text
        '041001 JPC control over writing notices, mainly for public internet sites.
        If CBool(ConfigurationSettings.AppSettings("noticesModeration")) Then
            dr(9) = False
        Else
            dr(9) = True
        End If
        Return dr
    End Function

    Private Function ValidateFields() As Boolean
        ValidateFields = True
        lblFeedback.Text = ""

        If txtAuthor.Text = "" Then
            ValidateFields = False
            lblFeedback.Text &= "**Please enter your name in the Author Field.  " & vbCrLf
        End If

        If txtNotice.Text = "" Then
            ValidateFields = False
            lblFeedback.Text &= "**Please enter a notice message. " & vbCrLf
        End If

        Try
            Dim dt As Date = Format(txtStartDate.Text, "Short Date")
            dt = Format(txtEndDate.Text, "Short Date")
        Catch
            ValidateFields = False
            lblFeedback.Text &= "**Please enter target dates matching the format dd/mm/yyyy - e.g. 15/05/2004.  "
        End Try
    End Function

    Private Sub ResetFields()
        txtAuthor.Text = ""
        txtNotice.Text = ""
        txtInformation.Text = ""
        txtStartDate.Text = Format(Now(), "Short Date")
        txtEndDate.Text = Format(Now().AddDays(7), "Short Date")
    End Sub

    Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
        ResetFields()
    End Sub

End Class

⌨️ 快捷键说明

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