CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
CslaDataSourceView.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="CslaDataSourceView.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>The object responsible for managing data binding</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections;
10using System.Web.UI;
11
12namespace Csla.Web
13{
14
19 public class CslaDataSourceView : DataSourceView
20 {
21
22 private CslaDataSource _owner;
23 private string _typeAssemblyName;
24 private string _typeName;
25 private bool _typeSupportsPaging;
26 private bool _typeSupportsSorting;
27
34 public CslaDataSourceView(CslaDataSource owner, string viewName)
35 : base(owner, viewName)
36 {
37 _owner = owner;
38 }
39
44 public string TypeAssemblyName
45 {
46 get { return _typeAssemblyName; }
47 set { _typeAssemblyName = value; }
48 }
49
55 public string TypeName
56 {
57 get { return _typeName; }
58 set { _typeName = value; }
59 }
60
71 {
72 get { return _typeSupportsPaging; }
73 set { _typeSupportsPaging = value; }
74 }
75
81 {
82 get { return _typeSupportsSorting; }
83 set { _typeSupportsSorting = value; }
84 }
85
86 #region Select
87
95 protected override System.Collections.IEnumerable
96 ExecuteSelect(DataSourceSelectArguments arguments)
97 {
98 // get the object from the page
99 SelectObjectArgs args = new SelectObjectArgs(arguments);
100 _owner.OnSelectObject(args);
101 object result = args.BusinessObject;
102
103 if (arguments.RetrieveTotalRowCount)
104 {
105 int rowCount;
106 if (result == null)
107 rowCount = 0;
108 else if (result is Csla.Core.IReportTotalRowCount)
109 rowCount = ((Csla.Core.IReportTotalRowCount)result).TotalRowCount;
110 else if (result is IList)
111 rowCount = ((IList)result).Count;
112 else if (result is IEnumerable)
113 {
114 IEnumerable temp = (IEnumerable)result;
115 int count = 0;
116 foreach (object item in temp)
117 count++;
118 rowCount = count;
119 }
120 else
121 rowCount = 1;
122 arguments.TotalRowCount = rowCount;
123 }
124
125 // if the result isn't IEnumerable then
126 // wrap it in a collection
127 if (!(result is IEnumerable))
128 {
129 ArrayList list = new ArrayList();
130 if (result != null)
131 list.Add(result);
132 result = list;
133 }
134
135 // now return the object as a result
136 return (IEnumerable)result;
137 }
138
139 #endregion
140
141 #region Insert
142
147 public override bool CanInsert
148 {
149 get
150 {
151 if (typeof(Csla.Core.IUndoableObject).IsAssignableFrom(
152 CslaDataSource.GetType(_typeAssemblyName, _typeName)))
153 return true;
154 else
155 return false;
156 }
157 }
158
167 protected override int ExecuteInsert(
168 IDictionary values)
169 {
170 // tell the page to insert the object
171 InsertObjectArgs args =
172 new InsertObjectArgs(values);
173 _owner.OnInsertObject(args);
174 return args.RowsAffected;
175 }
176
177 #endregion
178
179 #region Delete
180
185 public override bool CanDelete
186 {
187 get
188 {
189 if (typeof(Csla.Core.IUndoableObject).IsAssignableFrom(
190 CslaDataSource.GetType(_typeAssemblyName, _typeName)))
191 return true;
192 else
193 return false;
194 }
195 }
196
207 protected override int ExecuteDelete(IDictionary keys, IDictionary oldValues)
208 {
209
210 // tell the page to delete the object
211 DeleteObjectArgs args = new DeleteObjectArgs(keys, oldValues);
212 _owner.OnDeleteObject(args);
213 return args.RowsAffected;
214 }
215
216 #endregion
217
218 #region Update
219
224 public override bool CanUpdate
225 {
226 get
227 {
228 if (typeof(Csla.Core.IUndoableObject).IsAssignableFrom(
229 CslaDataSource.GetType(_typeAssemblyName, _typeName)))
230 return true;
231 else
232 return false;
233 }
234 }
235
248 protected override int ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues)
249 {
250 // tell the page to update the object
251 UpdateObjectArgs args = new UpdateObjectArgs(keys, values, oldValues);
252 _owner.OnUpdateObject(args);
253 return args.RowsAffected;
254 }
255
256 #endregion
257
258 #region Other Operations
259
264 public override bool CanPage
265 {
266 get
267 {
268 return _typeSupportsPaging;
269 }
270 }
271
277 public override bool CanRetrieveTotalRowCount
278 {
279 get { return true; }
280 }
281
286 public override bool CanSort
287 {
288 get
289 {
290 return _typeSupportsSorting;
291 }
292 }
293
294 #endregion
295
296 }
297}
A Web Forms data binding control designed to support CSLA .NET business objects as data sources.
The object responsible for managing data binding to a specific CSLA .NET object.
override bool CanPage
Gets a value indicating whether the data source supports paging of the data.
override bool CanRetrieveTotalRowCount
Gets a value indicating whether the data source can retrieve the total number of rows of data.
override int ExecuteDelete(IDictionary keys, IDictionary oldValues)
Implements the delete behavior for the control by raising the CslaDataSource.DeleteObject event.
override int ExecuteInsert(IDictionary values)
Implements the insert behavior for the control by raising the CslaDataSource.InsertObject event.
string TypeAssemblyName
Get or set the name of the assembly (no longer used).
override System.Collections.IEnumerable ExecuteSelect(DataSourceSelectArguments arguments)
Implements the select behavior for the control by raising the CslaDataSource.SelectObject event.
override bool CanInsert
Gets a value indicating whether the data source can insert data.
bool TypeSupportsPaging
Get or set a value indicating whether the business object data source supports paging.
override bool CanSort
Gets a alue indicating whether the data source supports sorting of the data.
override bool CanUpdate
Gets a value indicating whether the data source can update data.
bool TypeSupportsSorting
Get or set a value indicating whether the business object data source supports sorting.
override bool CanDelete
Gets a value indicating whether the data source can delete data.
override int ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues)
Implements the update behavior for the control by raising the CslaDataSource.UpdateObject event.
CslaDataSourceView(CslaDataSource owner, string viewName)
Creates an instance of the object.
string TypeName
Get or set the full type name of the business object class to be used as a data source.
Argument object used in the DeleteObject event.
int RowsAffected
Gets or sets the number of rows affected while handling this event.
Argument object used in the InsertObject event.
int RowsAffected
Gets or sets the number of rows affected while handling this event.
Argument object used in the SelectObject event.
object BusinessObject
Get or set a reference to the business object that is created and populated by the SelectObject event...
Argument object used in the UpdateObject event.
int RowsAffected
Gets or sets the number of rows affected while handling this event.
Implement this interface in a collection to report a total row count to Csla.Web.CslaDataSource,...
Defines the methods required to participate in n-level undo within the CSLA .NET framework.