Click here to Skip to main content
15,892,298 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 426K   22.2K   251  
Generates three tier code for ASP.NET.
'**==========================================================================================
'**
'** FILE  : UpdateUsers.aspx.vb
'** Author: Stevan Rodrigues
'**
'**==========================================================================================
'**
'** (c) The contents of this file , and of any file or document derived from it , are copyright 
'** to Webchamps . Unlicensed alteration, change or copying in any form, 
'** whether written, by photocopy, by print or by any other methods of reproduction is 
'** strictly prohibited.
'**
'**==========================================================================================
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports WebChamps.Components.Web
Imports  Company.ThreeTierDemoVB.Components.Business

'*********************************************************************
'
' Company.ThreeTierDemoVB.User Namespace
'
'*********************************************************************
Namespace Company.ThreeTierDemoVB.User
	Public Class UpdateUsers
	Inherits WebChamps.Components.Web.SitePage
		Protected PageMessage As System.Web.UI.WebControls.Label
		Protected ErrorMessage As System.Web.UI.WebControls.Label

		Protected FirstNameField As System.Web.UI.WebControls.TextBox
		Protected LastNameField As System.Web.UI.WebControls.TextBox
		Protected EmailField As System.Web.UI.WebControls.TextBox
		Protected CommentsField As System.Web.UI.WebControls.TextBox
		Protected UpdateRecord As System.Web.UI.WebControls.Button

		#Region " Web Form Designer Generated Code "

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

				AddHandler Me.Load, New System.EventHandler(AddressOf Me.Page_Load)
				AddHandler Me.UpdateRecord.Click, New System.EventHandler(AddressOf Me.UpdateRecord_Click)
			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 UserId As Int32

		'*********************************************************************
		'
		' Page_Load event
		'
 		'Company.ThreeTierDemoVB.Components.Data.UserDB.SelectUser(UserId) is called to populate the fields.
 		'
		'
		'*********************************************************************
		Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
			UserId = Int32.Parse(Request.Params("UserId"))
			' Insert code to process code when the page is loaded for first time or without a post back.
			If  Not IsPostBack Then
			'Define objects 
				Dim ParamUser As Company.ThreeTierDemoVB.Components.Business.User

				'Create the User instance.
				ParamUser = New Company.ThreeTierDemoVB.Components.Business.User(UserId)
				FirstNameField.Text = Convert.ToString(ParamUser.FirstName)
				LastNameField.Text = Convert.ToString(ParamUser.LastName)
				EmailField.Text = Convert.ToString(ParamUser.Email)
				CommentsField.Text = Convert.ToString(ParamUser.Comments)
			End If 
		End Sub

		'*********************************************************************
		'
		' UpdateRecord_Click event
		'
 		'The Company.ThreeTierDemoVB.Components.Data.UserDB.UpdateUsers_Tb is used to update record in the table.
		'
		'*********************************************************************
		Private Sub UpdateRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
			'Define objects 
			Dim ParamUser As Company.ThreeTierDemoVB.Components.Business.User
			Dim ReturnValue As Int32

			'Create the User instance.
			ParamUser = New Company.ThreeTierDemoVB.Components.Business.User()
			ParamUser.UserId = UserId
			ParamUser.FirstName = FirstNameField.Text
			ParamUser.LastName = LastNameField.Text
			ParamUser.Email = EmailField.Text
			ParamUser.Comments = CommentsField.Text
			'Assign the return value.
			ReturnValue = ParamUser.Update(User.Identity.Name)
			If ReturnValue = 0 Then
				Response.Redirect("Default.aspx")
			ElseIf ReturnValue = -1 Then
				ErrorMessage.Text = "Custom error!"
			ElseIf ReturnValue = 1 Then
				ErrorMessage.Text = "Database error!"
			Else 
				PageMessage.Text = "Record already exists!"
			End If 
		End Sub

	End Class
End Namespace

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