Click here to Skip to main content
15,886,199 members
Articles / Web Development / ASP.NET

Three Tier Code Generator For ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.78/5 (34 votes)
8 Jul 200512 min read 425.4K   22.2K   251  
Generates three tier code for ASP.NET.
Public MustInherit Class GeneralDateTime
    Inherits System.Web.UI.UserControl
    Protected WithEvents drpYear As System.Web.UI.WebControls.DropDownList
    Protected WithEvents drpMonth As System.Web.UI.WebControls.DropDownList
    Protected WithEvents drpDay As System.Web.UI.WebControls.DropDownList

#Region " Web Form Designer Generated Code "

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

    End Sub

    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 m_American As Boolean

    Public Property CssClass() As String
        Get
            Return drpDay.CssClass
        End Get
        Set(ByVal Value As String)
            drpDay.CssClass = Value
            drpMonth.CssClass = Value
            drpYear.CssClass = Value
        End Set
    End Property

    Public Property UDay() As Integer
        Get
            Return drpDay.SelectedItem.Value
        End Get
        Set(ByVal Value As Integer)
            drpDay.Items.FindByValue(Value).Selected = True
        End Set
    End Property

    Public Property UMonth() As Integer
        Get
            Return drpMonth.SelectedItem.Value
        End Get
        Set(ByVal Value As Integer)
            drpMonth.Items.FindByValue(Value).Selected = True
        End Set
    End Property

    Public Property UYear() As Integer
        Get
            Return drpYear.SelectedItem.Value
        End Get
        Set(ByVal Value As Integer)
            drpYear.Items.FindByValue(Value).Selected = True
        End Set
    End Property

    Public Property American() As Boolean
        Get
            Return m_American
        End Get
        Set(ByVal Value As Boolean)
            m_American = Value
        End Set
    End Property

    Public Property DDate() As String
        Get
            Return ReturnDate()
        End Get
        Set(ByVal Value As String)
            DisplayDate(Value)
        End Set
    End Property

    Private Function ReturnDate() As String
        If m_American = True Then
            Return String.Format("{1}/{0}/{2}", drpDay.SelectedItem.Value, drpMonth.SelectedItem.Value, drpYear.SelectedItem.Value)
        Else
            Return String.Format("{0}/{1}/{2}", drpDay.SelectedItem.Value, drpMonth.SelectedItem.Value, drpYear.SelectedItem.Value)
        End If
    End Function

    Private Sub DisplayDate(ByVal SDate As String)
        If m_American = True Then
            drpDay.Items.FindByValue(Microsoft.VisualBasic.Day(SDate)).Selected = True
            drpMonth.Items.FindByValue(Microsoft.VisualBasic.Month(SDate)).Selected = True
            drpYear.Items.FindByValue(Microsoft.VisualBasic.Year(SDate)).Selected = True
        Else
            Dim SDates As String()
            Dim SDateParts As String()
            SDates = SDate.Split(" ")
            SDateParts = SDates(0).Split("/")
            drpDay.Items.FindByValue(SDateParts(0)).Selected = True
            drpMonth.Items.FindByValue(SDateParts(1)).Selected = True
            drpYear.Items.FindByValue(SDateParts(2)).Selected = True
        End If
    End Sub

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
Australia Australia
Stevan is a Microsoft Certified Solutions Developer in .Net Architecture (MCSD.Net Early Achiever – one among the first 2500 worldwide), Microsoft Certified Application Developer in .Net – MCAD.Net (Charter Member - one among the first 5000 developers worldwide).

Comments and Discussions