#region License
/**
* Ingenious MVC : An MVC framework for .NET 2.0
* Copyright (C) 2006, JDP Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: - Kent Boogaart (kentcb@internode.on.net)
*/
#endregion
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing.Design;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ingenious.Mvc.Util;
using Ingenious.Mvc.Web.Forms.Views;
namespace Ingenious.Mvc.Web.Forms.UI.WebControls{
[ParseChildren(true)]
[DefaultEvent("Selecting")]
public class ControllerDataSource : DataSourceControl
{
private ObjectDataSource _objectDataSource;
[DefaultValue(0)]
[Category("Cache")]
[TypeConverter(typeof(DataSourceCacheDurationConverter))]
public virtual int CacheDuration
{
get
{
return _objectDataSource.CacheDuration;
}
set
{
_objectDataSource.CacheDuration = value;
}
}
[DefaultValue(0)]
[Category("Cache")]
public virtual DataSourceCacheExpiry CacheExpirationPolicy
{
get
{
return _objectDataSource.CacheExpirationPolicy;
}
set
{
_objectDataSource.CacheExpirationPolicy = value;
}
}
[DefaultValue("")]
[Category("Cache")]
public virtual string CacheKeyDependency
{
get
{
return _objectDataSource.CacheKeyDependency;
}
set
{
_objectDataSource.CacheKeyDependency = value;
}
}
[DefaultValue(0)]
[Category("Data")]
public ConflictOptions ConflictDetection
{
get
{
return _objectDataSource.ConflictDetection;
}
set
{
_objectDataSource.ConflictDetection = value;
}
}
[DefaultValue(false)]
[Category("Data")]
public bool ConvertNullToDBNull
{
get
{
return _objectDataSource.ConvertNullToDBNull;
}
set
{
_objectDataSource.ConvertNullToDBNull = value;
}
}
[DefaultValue("")]
[Category("Data")]
public string DataObjectTypeName
{
get
{
return _objectDataSource.DataObjectTypeName;
}
set
{
_objectDataSource.DataObjectTypeName = value;
}
}
[DefaultValue("")]
[Category("Data")]
public string DeleteMethod
{
get
{
return _objectDataSource.DeleteMethod;
}
set
{
_objectDataSource.DeleteMethod = value;
}
}
[DefaultValue((string) null)]
[Category("Data")]
[PersistenceMode(PersistenceMode.InnerProperty)]
[MergableProperty(false)]
[Editor("System.Web.UI.Design.WebControls.ParameterCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
public ParameterCollection DeleteParameters
{
get
{
return _objectDataSource.DeleteParameters;
}
}
[DefaultValue(false)]
[Category("Cache")]
public virtual bool EnableCaching
{
get
{
return _objectDataSource.EnableCaching;
}
set
{
_objectDataSource.EnableCaching = value;
}
}
[DefaultValue(false)]
[Category("Paging")]
public bool EnablePaging
{
get
{
return _objectDataSource.EnablePaging;
}
set
{
_objectDataSource.EnablePaging = value;
}
}
[DefaultValue("")]
[Category("Data")]
public string FilterExpression
{
get
{
return _objectDataSource.FilterExpression;
}
set
{
_objectDataSource.FilterExpression = value;
}
}
[DefaultValue((string) null)]
[Category("Data")]
[Editor("System.Web.UI.Design.WebControls.ParameterCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[PersistenceMode(PersistenceMode.InnerProperty)]
[MergableProperty(false)]
public ParameterCollection FilterParameters
{
get
{
return _objectDataSource.FilterParameters;
}
}
[DefaultValue("")]
[Category("Data")]
public string InsertMethod
{
get
{
return _objectDataSource.InsertMethod;
}
set
{
_objectDataSource.InsertMethod = value;
}
}
[DefaultValue((string) null)]
[Category("Data")]
[PersistenceMode(PersistenceMode.InnerProperty)]
[MergableProperty(false)]
[Editor("System.Web.UI.Design.WebControls.ParameterCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
public ParameterCollection InsertParameters
{
get
{
return _objectDataSource.InsertParameters;
}
}
[DefaultValue("maximumRows")]
[Category("Paging")]
public string MaximumRowsParameterName
{
get
{
return _objectDataSource.MaximumRowsParameterName;
}
set
{
_objectDataSource.MaximumRowsParameterName = value;
}
}
[DefaultValue("{0}")]
[Category("Data")]
public string OldValuesParameterFormatString
{
get
{
return _objectDataSource.OldValuesParameterFormatString;
}
set
{
_objectDataSource.OldValuesParameterFormatString = value;
}
}
[DefaultValue("")]
[Category("Paging")]
public string SelectCountMethod
{
get
{
return _objectDataSource.SelectCountMethod;
}
set
{
_objectDataSource.SelectCountMethod = value;
}
}
[DefaultValue("")]
[Category("Data")]
public string SelectMethod
{
get
{
return _objectDataSource.SelectMethod;
}
set
{
_objectDataSource.SelectMethod = value;
}
}
[DefaultValue((string) null)]
[Category("Data")]
[PersistenceMode(PersistenceMode.InnerProperty)]
[MergableProperty(false)]
[Editor("System.Web.UI.Design.WebControls.ParameterCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
public ParameterCollection SelectParameters
{
get
{
return _objectDataSource.SelectParameters;
}
}
[DefaultValue("")]
[Category("Data")]
public string SortParameterName
{
get
{
return _objectDataSource.SortParameterName;
}
set
{
_objectDataSource.SortParameterName = value;
}
}
[DefaultValue("")]
[Category("Cache")]
public virtual string SqlCacheDependency
{
get
{
return _objectDataSource.SqlCacheDependency;
}
set
{
_objectDataSource.SqlCacheDependency = value;
}
}
[DefaultValue("startRowIndex")]
[Category("Paging")]
public string StartRowIndexParameterName
{
get
{
return _objectDataSource.StartRowIndexParameterName;
}
set
{
_objectDataSource.StartRowIndexParameterName = value;
}
}
[DefaultValue("")]
[Category("Data")]
public string UpdateMethod
{
get
{
return _objectDataSource.UpdateMethod;
}
set
{
_objectDataSource.UpdateMethod = value;
}
}
[DefaultValue((string) null)]
[Category("Data")]
[PersistenceMode(PersistenceMode.InnerProperty)]
[MergableProperty(false)]
[Editor("System.Web.UI.Design.WebControls.ParameterCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
public ParameterCollection UpdateParameters
{
get
{
return _objectDataSource.UpdateParameters;
}
}
public event EventHandler<ObjectDataSourceStatusEventArgs> Deleted;
public event EventHandler<ObjectDataSourceMethodEventArgs> Deleting;
public event EventHandler<ObjectDataSourceFilteringEventArgs> Filtering;
public event EventHandler<ObjectDataSourceStatusEventArgs> Inserted;
public event EventHandler<ObjectDataSourceMethodEventArgs> Inserting;
public event EventHandler<ObjectDataSourceStatusEventArgs> Selected;
public event EventHandler<ObjectDataSourceSelectingEventArgs> Selecting;
public event EventHandler<ObjectDataSourceStatusEventArgs> Updated;
public event EventHandler<ObjectDataSourceMethodEventArgs> Updating;
public ControllerDataSource()
{
_objectDataSource = new ObjectDataSource();
//bubble up appropriate events
_objectDataSource.Deleted += delegate(object sender, ObjectDataSourceStatusEventArgs e)
{
EventHelper.Raise(Deleted, this, e);
};
_objectDataSource.Deleting += delegate(object sender, ObjectDataSourceMethodEventArgs e)
{
EventHelper.Raise(Deleting, this, e);
};
_objectDataSource.Filtering += delegate(object sender, ObjectDataSourceFilteringEventArgs e)
{
EventHelper.Raise(Filtering, this, e);
};
_objectDataSource.Inserted += delegate(object sender, ObjectDataSourceStatusEventArgs e)
{
EventHelper.Raise(Inserted, this, e);
};
_objectDataSource.Inserting += delegate(object sender, ObjectDataSourceMethodEventArgs e)
{
EventHelper.Raise(Inserting, this, e);
};
_objectDataSource.Selected += delegate(object sender, ObjectDataSourceStatusEventArgs e)
{
EventHelper.Raise(Selected, this, e);
};
_objectDataSource.Selecting += delegate(object sender, ObjectDataSourceSelectingEventArgs e)
{
EventHelper.Raise(Selecting, this, e);
};
_objectDataSource.Updated += delegate(object sender, ObjectDataSourceStatusEventArgs e)
{
EventHelper.Raise(Updated, this, e);
};
_objectDataSource.Updating += delegate(object sender, ObjectDataSourceMethodEventArgs e)
{
EventHelper.Raise(Updating, this, e);
};
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
//this event wouldn't be firing without the Page instance
Debug.Assert(Page != null);
PageBase pageBase = Page as PageBase;
//page must be of type PageBase
ExceptionHelper.ThrowIf(pageBase == null, "Page_Load.incorrectPageType", Page.GetType().FullName, typeof(PageBase).FullName);
//the page must have a controller in order to use this control
ExceptionHelper.ThrowIf(pageBase.Controller == null, "Page_Load.noController", pageBase.Id);
//pass the controller's full name onto the ObjectDataSource
_objectDataSource.TypeName = pageBase.Controller.GetType().AssemblyQualifiedName;
//handle the creation of the controller
_objectDataSource.ObjectCreating += new ObjectDataSourceObjectEventHandler(_objectDataSource_ObjectCreating);
}
protected override DataSourceView GetView(string viewName)
{
//just forward the request to the ObjectDataSource
return ((IDataSource) _objectDataSource).GetView(viewName);
}
void _objectDataSource_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
{
//here we assign the controller as the object instance
e.ObjectInstance = (Page as PageBase).Controller;
}
public int Delete()
{
return _objectDataSource.Delete();
}
public int Insert()
{
return _objectDataSource.Insert();
}
public IEnumerable Select()
{
return _objectDataSource.Select();
}
public int Update()
{
return _objectDataSource.Update();
}
}
}
|