Click here to Skip to main content
15,896,313 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 426.3K   22.2K   251  
Generates three tier code for ASP.NET.
<%

Function DeclareDynamicCntrl(Tab)
	Dim NumLoop
	For NumLoop = 0 to (FieldCount)
		If Instr(Lcase(InputFieldsNames(NumLoop)),"selectdynamic") Then
			DeclareDynamicCntrl = DeclareDynamicCntrl & GetStatement(Declaration("Private", AllFieldsNames(NumLoop) & "DataView", "System.Data.DataView", "0", CodingLanguage), CodingLanguage, Tab)
		End If
	Next		
End Function

Function LoopForListCntrlFunctions(Tab)
	Dim NumLoop
	FOR NumLoop = 0 to FieldCount
		If Instr(Lcase(InputFieldsNames(NumLoop)),"selectdynamic") Then
			LoopForListCntrlFunctions = LoopForListCntrlFunctions &  GetListCntrlDataSrc(AllFieldsNames(NumLoop), Tab) & vbCrLf &_
			GetListCntrlSelectedIndex(AllFieldsNames(NumLoop), Tab) & vbCrLf
		End If
	NEXT
End Function

Function GetListCntrlDataSrc(ListCntrl, Tab)
	
	GetListCntrlDataSrc = FunctionStart("Protected", ListCntrl & "_DataSource", "", "System.Data.DataView", CodingLanguage, Tab) & vbCrLf &_	
				OpenScope(CodingLanguage, Tab) &_
				GetStatement(GetReturn(ListCntrl & "DataView", CodingLanguage), CodingLanguage, Tab & vbTab & vbTab & vbTab) &_
				FunctionEnd("1", CodingLanguage, Tab)
End Function

Function GetListCntrlSelectedIndex(ListCntrl, Tab)
	GetListCntrlSelectedIndex = FunctionStart("Protected", ListCntrl & "_SelectedIndex", Declaration("", ListCntrl, "String", "1", CodingLanguage), "Int32", CodingLanguage, Tab) & vbCrLf &_
				OpenScope(CodingLanguage, Tab) &_
				ForStart("i", "Int32", "0", ListCntrl & "DataView.Count", CodingLanguage, Tab & vbTab) &_
				OpenScope(CodingLanguage, Tab & vbTab) &_
				IfStart("Convert.ToString(" & ListCntrl & "DataView[i][""" & ListCntrl & """]).Trim().Equals(" & ListCntrl & ".Trim())", CodingLanguage, Tab & vbTab & vbTab) &_
				OpenScope(CodingLanguage, Tab & vbTab & vbTab) &_
				GetStatement(GetReturn("i", CodingLanguage), CodingLanguage, Tab & vbTab & vbTab & vbTab) &_
				IfEnd(CodingLanguage, Tab & vbTab & vbTab) &_
				ForEnd(CodingLanguage, Tab & vbTab)&_
				GetStatement(GetReturn("0", CodingLanguage), CodingLanguage, Tab & vbTab) &_
				FunctionEnd("1", CodingLanguage, Tab)
End Function

Function BindDynamicListControl(Tab)
	Dim NumLoop
	If Instr(Lcase(InputFields),"selectdynamic") Then
		BindDynamicListControl = FunctionStart("Protected", "BindDynamicListControl", "", "void", CodingLanguage, Tab) & vbCrLf &_
					OpenScope(CodingLanguage, Tab) 
		
		For NumLoop = 0 to (FieldCount)
			If Instr(Lcase(InputFieldsNames(NumLoop)),"selectdynamic") Then
				BindDynamicListControl = BindDynamicListControl & GetListCntrlDataView(AllFieldsNames(NumLoop), Tab & vbTab) 
			End If
		Next
		BindDynamicListControl = BindDynamicListControl & FunctionEnd("0", CodingLanguage, Tab) 
	End If
End Function

Function GetListCntrlDataView(ListCntrl, Tab)
	GetListCntrlDataView =  GetStatement(ListCntrl & "DataView = DynamicListControl.ExecuteDataView(" & DataDynamicControl(ListCntrl) & ")", CodingLanguage, Tab) 				
End Function

Function DynamicListControlCreate(Mode, Tab)
	Dim NumLoop
	For NumLoop = 0 to FieldCount
		If Instr(lcase(InputFieldsNames(NumLoop)),"selectdynamic") Then
			DynamicListControlCreate = DynamicListControlCreate & GetStatement("DynamicListControl.Create(" & GetCast(AllFieldsNames(NumLoop) & "Field", "System.Web.UI.WebControls.ListControl", CodingLanguage) & ", " & DataDynamicControl(AllFieldsNames(NumLoop)) & ", " & DynamicListControlValue(AllFieldsNames(NumLoop), Mode ) & ", """")", CodingLanguage, Tab)		
		End If
	Next	
End Function

Function DynamicListControlValue(FieldName, Mode)
	Select Case Mode
	Case 0
		DynamicListControlValue = """0"""
	Case 1
		DynamicListControlValue = "Convert.ToString(" & FieldName & ")"
	End Select
End Function

Function DataDynamicControl(fieldName)
	Dim NewFieldName
	NewFieldName = Left(FieldName,len(FieldName)-2)
	DataDynamicControl = """" & NewFieldName & """, """ & NewFieldName & """, """ & FieldName & """, """ & NewFieldName & "s_tb"""
End Function
%>

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