Demo entry 5905221

add page (new)

   

Submitted by anonymous on Aug 31, 2016 at 09:32
Language: VB.net. Code size: 6.3 kB.

#Region "Ctor"
    Public Enum pageActionType
        Add
        Edit
        AddSubpage
    End Enum
    Public Enum pageTypeName
        Link
        Page
    End Enum
#End Region
#Region "Insert or Update page"
    Protected Sub btnAddPage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddPage.Click

        ' variables
        Dim action_type As New pageActionType
        Dim _page_type As pageTypeName
        Dim ParentPage As Integer
        Dim hasError As Boolean = False
        Dim defaultPageId As Integer = clsPortaldb.Get_Page_is_Defualt(CInt(drpLanguages.SelectedValue))
        Dim pageId As Integer = 0
        ' #end variables

        ' set page type
        If Not String.IsNullOrEmpty(Request("id")) And String.IsNullOrEmpty(Request("edit")) Then
            action_type = pageActionType.AddSubpage ' ## add sub page
        ElseIf Not String.IsNullOrEmpty(Request("id")) And Not String.IsNullOrEmpty(Request("edit")) Then
            action_type = pageActionType.Edit ' ## edit page
        Else
            action_type = pageActionType.Add ' ## add new page
        End If ' qp
        ' #end set page type

        ' set parent page value
        If (action_type = pageActionType.AddSubpage) Then  ' add sub page
            ParentPage = Request("id")
        ElseIf (action_type = pageActionType.Edit) Then  ' edit page
            ParentPage = Val(cboParentPage.SelectedValue)
            pageId = Val(Request("id")) ' set current page id
        ElseIf (action_type = pageActionType.Add) Then  ' add new page
            ParentPage = 0
        End If
        ' #end set parent page value

        ' set page type
        If (cboLink.SelectedValue = "0") Then   ' page
            _page_type = pageTypeName.Page
        ElseIf (cboLink.SelectedValue = "1") Then  ' link
            _page_type = pageTypeName.Link
        End If
        ' #end set page type

        ' page fields
        Dim pageName As String = ""
        Dim pageTitle As String = ""
        Dim description As String = ""
        Dim keywords As String = ""
        Dim pageOrder As Integer = 0
        'Dim parentPage As Integer = 0
        Dim includeInMenu As Boolean = False
        Dim pageData As String = ""
        Dim isDefaultPage As Boolean = False
        Dim pageType As Integer = 0
        Dim isInHeaderMenu As Boolean = False
        Dim isLink As Integer = 0
        Dim link As String = ""
        Dim lang As Integer = 0
        Dim id As Integer = 0
        Dim urlTitle As String = ""
        Dim isActive As Boolean = False
        ' #end page fields

        ' fill value of page fields
        pageName = txtPagename.Text.Trim
        pageTitle = txttitle.Text.Trim
        description = txtDescription.Text.Trim
        keywords = ""
        pageOrder = Val(txtPageOrder.Text)
        includeInMenu = chkIncludeInMenu.Checked
        pageData = txtText.Text.Trim
        isDefaultPage = chkIsDefault.Checked
        pageType = If(Not String.IsNullOrEmpty(cboPageType.SelectedValue), Val(cboPageType.SelectedValue), 0)
        isInHeaderMenu = chkHeaderMenu.Checked
        isLink = Val(cboLink.SelectedValue)
        link = If(_page_type = pageTypeName.Link, txtlink.Text, "")
        lang = Val(drpLanguages.SelectedValue)
        id = pageId
        urlTitle = clsFunctions.NormalizeAddress(txtTitleUrl.Text.Trim)
        isActive = chkIsActive.Checked
        ' #end fill value of page fields

        If defaultPageId > 0 And defaultPageId <> pageId Then
            msgbox1.Show("شما مجاز به انتخاب بیشتر از یک صفحه اصلی برای هر زبان نیستید", "error")
            Exit Sub
        End If

        If (action_type = pageActionType.Add Or action_type = pageActionType.AddSubpage) Then
            Dim result As Integer = clsPortaldb.Pages_Insert(pageName, _
                                           pageTitle, _
                                           description, _
                                           keywords, _
                                           pageOrder, _
                                           ParentPage, _
                                           includeInMenu, _
                                           pageData, _
                                           isDefaultPage, _
                                           pageType, _
                                           isInHeaderMenu, _
                                           link, _
                                           lang, _
                                           isLink, _
                                           urlTitle, _
                                           isActive)
            If (result = -1) Then
                msgbox1.Show("خطا : اطلاعات مورد نظر ویرایش نگردید .", "error")
                Exit Sub
            Else
                pageId = result
            End If

        ElseIf (action_type = pageActionType.Edit) Then

            Dim result As String = clsPortaldb.Pages_Update_By_Id(pageName, _
                                           pageTitle, _
                                           description, _
                                           keywords, _
                                           pageOrder, _
                                           ParentPage, _
                                           includeInMenu, _
                                           pageData, _
                                           isDefaultPage, _
                                           pageType, _
                                           isInHeaderMenu, _
                                           link, _
                                           lang, _
                                           pageId, _
                                           isLink, _
                                           urlTitle, _
                                           isActive)
            If (result = "") Then
                msgbox1.Show("خطا : اطلاعات مورد نظر ویرایش نگردید .", "error")
                Exit Sub
            End If


        End If

        Response.Redirect(String.Concat("Add_Page.aspx?edit=true&id=", pageId.ToString))
    End Sub
#End Region

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).