Click here to Skip to main content
12,444,360 members (55,721 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads

Stats

102.2K 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.Collections.Generic;
using SubSonic.Utilities;
using System.Data;

namespace SubSonic
{

    public class DBCollection : List<DB>
    {

        public DB this[string dbName]
        {
            get
            {
                foreach (DB db in this)
                {
                    if (Utility.IsMatch(db.ProviderName, dbName))
                    {
                        return db;
                    }
                }
                return null;
            }
            set
            {
                for(int index = 0; index < Count; index++)
                {
                    if(Utility.IsMatch(this[index].ProviderName, dbName))
                    {
                        this[index] = value;
                        break;
                    }
                }
            }
        }

    }

    public class DB
    {

        public DB(string providerName)
        {
            //load up the tables
            Tables = new TableSchema.TableCollection();
            Views = new TableSchema.TableCollection();

            _tables.AddRange(DataService.GetTables(providerName));
            _views.AddRange(DataService.GetViews(providerName));

            if (_sps == null)
            {
                LoadStoredProcedures(providerName);
            }
        }

        private void LoadStoredProcedures(string providerName)
        {
            //DataService.ResetDatabases();
            string[] sps = DataService.GetSPList(providerName);
            if (sps.Length > 0)
            {
                _sps = new List<StoredProcedure>();
                //System.Data.IDataReader rdr = null;
                DataProvider provider = DataService.Providers[providerName];
                foreach (string s in sps)
                {
                    if(String.IsNullOrEmpty(provider.SPStartsWith) || s.StartsWith(provider.SPStartsWith))
                    {
                        //declare the sp
                        StoredProcedure sp = new StoredProcedure(s, provider);

                        //get the params
                        IDataReader rdr = DataService.GetSPParams(s, providerName);
                        while(rdr.Read())
                        {
                            StoredProcedure.Parameter par = new StoredProcedure.Parameter();
                            par.DBType = DataService.GetDbType(rdr[SqlSchemaVariable.DATA_TYPE].ToString(), providerName);
                            string sMode = rdr[SqlSchemaVariable.MODE].ToString();
                            if(Utility.IsMatch(sMode, SqlSchemaVariable.MODE_INOUT))
                            {
                                par.Mode = ParameterDirection.InputOutput;
                            }
                            par.Name = rdr[SqlSchemaVariable.NAME].ToString();
                            par.QueryParameter = provider.MakeParam(par.Name);
                            par.DisplayName = Utility.GetParameterName(par.Name, provider);
                            sp.Parameters.Add(par);
                        }
                        rdr.Close();
                        _sps.Add(sp);
                    }
                }
            }
        }
        #region props

        private string _connectionString;

        public string ConnectionString
        {
            get { return _connectionString; }
            set { _connectionString = value; }
        }

        private string _providerName;

        public string ProviderName
        {
            get { return _providerName; }
            set { _providerName = value; }
        }

        private DataProvider _provider;

        public DataProvider Provider
        {
            get { return _provider; }
            set { _provider = value; }
        }

        private TableSchema.TableCollection _tables;

        public TableSchema.TableCollection Tables
        {
            get { return _tables; }
            set { _tables = value; }
        }

        private TableSchema.TableCollection _views;

        public TableSchema.TableCollection Views
        {
            get { return _views; }
            set { _views = value; }
        }

        private List<StoredProcedure> _sps;// =new List<StoredProcedure>();

        public List<StoredProcedure> StoredProcedures {
            get
            {
                if(_sps == null)
                {
                    LoadStoredProcedures(ProviderName);
                }
                return _sps;
            }
            set { _sps = value; }
        }
	

        #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...

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