Click here to Skip to main content
12,355,050 members (39,496 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads

Stats

101.7K views
2.6K downloads
121 bookmarked
Posted

Implementing Model-View-Presenter in ASP.NET

, 17 Nov 2007 CPOL
Three implementations of Model-View-Presenter in ASP.NET 2.0.
MVP.SampleApp
Lib
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll
MySql.Data.dll
nunit.framework.dll
Rhino.Mocks.dll
Model
Data
Interfaces
Properties
Presentation
Presentation.Tests
Properties
Interfaces
Properties
SubSonic
ActiveRecord
Builder
CodeGeneration
Templates
CodeLanguage
Configuration
Controls
Calendar
lang
skin
active-bg.gif
calendar.gif
dark-bg.gif
hover-bg.gif
menuarrow.gif
normal-bg.gif
rowhover-bg.gif
status-bg.gif
title-bg.gif
today-bg.gif
Resources
DataProviders
Properties
Sql Tools
SubSonic.snk
Sugar
WebApp
App_Data
Views
SQL2000SampleDb.msi
using System;
using System.CodeDom.Compiler;
using System.Data;
using Microsoft.VisualBasic;
using SubSonic.Utilities;

namespace SubSonic
{
	public class VBCodeLanguage : ICodeLanguage
	{
		#region Constants & enumerations

		private readonly string[] keywords = {
			// keywords
			"alias", "addHandler", "ansi", "as", "assembly", "auto", "binary", "byref", "byval", "case", "catch", "class",
			"custom", "date", "datetime", "default", "directcast", "each", "else", "elseif", "end", "error", "false",
			"finally", "for", "friend", "global", "handles", "implements", "in", "is", "lib", "loop", "me", "module",
			"mustinherit", "mustoverride", "mybase", "myclass", "narrowing", "new", "next", "nothing", "notinheritable",
			"notoverridable", "of", "off", "on", "option", "optional", "overloads", "overridable", "overrides", "paramarray",
			"partial", "preserve", "private", "property", "protected", "public", "raiseevent", "readonly", "resume", "shadows",
			"shared", "static", "step", "structure", "text", "then", "to", "true", "trycast", "unicode", "until", "when",
			"while", "widening", "withevents", "writeonly",
			// unreserved keywords
			"compare", "explicit", "isfalse", "istrue", "mid", "strict"
		};

		#endregion

		#region Properties

		public string CodeProvider
		{
			get { return "VBCodeProvider"; }
		}

		public string FileExtension
		{
			get { return SubSonic.FileExtension.DOT_VB; }
		}

		public string Identifier
		{
			get { return "VB"; }
		}

		public string ShortName
		{
			get { return "vb"; }
		}

		public string TemplatePrefix
		{
			get { return "VB_"; }
		}

		#endregion

		#region Methods

		public CodeDomProvider CreateCodeProvider()
		{
			return new VBCodeProvider();
		}

		public string GetDefaultValue(string colName, DbType dbType, bool isNullableColumn)
		{
			string variableType = GetDefaultValue(colName, dbType);
			if (isNullableColumn && Utility.IsNullableDbType(dbType))
				variableType = String.Format(CodeFragment.NULLABLE_VARIABLE_VB, variableType);
			return variableType;
		}

		public string GetUsingStatements(string[] namespaces)
		{
			string usingStatements = "";
			foreach (string space in namespaces)
				usingStatements += "Imports " + space + Environment.NewLine;
			return usingStatements;
		}

		public string GetVariableType(DbType dbType, bool isNullableColumn)
		{
			string variableType = GetVariableType(dbType);
			if (isNullableColumn && Utility.IsNullableDbType(dbType))
				variableType = String.Format(CodeFragment.NULLABLE_VARIABLE_VB, variableType);
			return variableType;
		}

		public bool IsKeyword(string word)
		{
			return Array.IndexOf(keywords, word.ToLower()) != -1;
		}

		#endregion

		#region Private methods

		private static string GetDefaultValue(string colName, DbType dbType)
		{
			if (Utility.IsLogicalDeleteColumn(colName))
				return "False";

			switch (dbType) {
				case DbType.Guid:
					return "Guid.Empty";
				case DbType.AnsiString:
				case DbType.AnsiStringFixedLength:
				case DbType.String:
				case DbType.StringFixedLength:
					return "Nothing";
				case DbType.Boolean:
					return "False";
				case DbType.Binary:
					return "Nothing";
				case DbType.Xml:
					return "";
				case DbType.Date:
				case DbType.DateTime:
					return "New Date(1900,01,01)";
				default:
					return "0";
			}
		}

		private static string GetVariableType(DbType dbType)
		{
			switch (dbType) {
				case DbType.AnsiString:
				case DbType.AnsiStringFixedLength:
				case DbType.String:
				case DbType.StringFixedLength: return "String";

				case DbType.Binary:		return "Byte()";
				case DbType.Boolean:	return "Boolean";
				case DbType.Byte:		return "Byte";

				case DbType.Currency:
				case DbType.Decimal:
				case DbType.VarNumeric:	return "Decimal";

				case DbType.Date:
				case DbType.DateTime:	return "DateTime";

				
				case DbType.Double:		return "Double";
				case DbType.Guid:		return "Guid";
				case DbType.Int16:		return "Short";
				case DbType.Int32:		return "Integer";
				case DbType.Int64:		return "Long";
				case DbType.Object:		return "Object";
				case DbType.SByte:		return "SByte";
				case DbType.Single:		return "Single";

				case DbType.Time:		return "TimeSpan";
				case DbType.UInt16:		return "UShort";
				case DbType.UInt32:		return "UInteger";
				case DbType.UInt64:		return "ULong";
				
				default:				return "String";
			}
		}

		#endregion
	}
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Alex Mueller
Web Developer
United States United States
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 17 Nov 2007
Article Copyright 2007 by Alex Mueller
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid