CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
CslaDesignerDataSourceView.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="CslaDesignerDataSourceView.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Object responsible for providing details about</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections;
10using System.Web.UI.Design;
11using System.ComponentModel.Design;
12using System.Data;
13using System.ComponentModel;
14
15namespace Csla.Web.Design
16{
21 public class CslaDesignerDataSourceView : DesignerDataSourceView
22 {
23
24 private CslaDataSourceDesigner _owner = null;
25
30 : base(owner, viewName)
31 {
32 _owner = owner;
33 }
34
43 public override IEnumerable GetDesignTimeData(int minimumRows, out bool isSampleData)
44 {
45 IDataSourceViewSchema schema = this.Schema;
46 DataTable result = new DataTable();
47
48 // create the columns
49 foreach (IDataSourceFieldSchema item in schema.GetFields())
50 {
51 result.Columns.Add(item.Name, item.DataType);
52 }
53
54 // create sample data
55 for (int index = 1; index <= minimumRows; index++)
56 {
57 object[] values = new object[result.Columns.Count];
58 int colIndex = 0;
59 foreach (DataColumn col in result.Columns)
60 {
61 if (col.DataType.Equals(typeof(string)))
62 values[colIndex] = "abc";
63 else if (col.DataType.Equals(typeof(System.DateTime)))
64 values[colIndex] = System.DateTime.Today.ToShortDateString();
65 else if (col.DataType.Equals(typeof(System.DateTimeOffset)))
66 values[colIndex] = System.DateTime.Today.ToShortDateString();
67 else if (col.DataType.Equals(typeof(bool)))
68 values[colIndex] = false;
69 else if (col.DataType.IsPrimitive)
70 values[colIndex] = index;
71 else if (col.DataType.Equals(typeof(Guid)))
72 values[colIndex] = Guid.Empty;
73 else if (col.DataType.IsValueType)
74 values[colIndex] = Activator.CreateInstance(col.DataType);
75 else
76 values[colIndex] = null;
77 colIndex += 1;
78 }
79 result.LoadDataRow(values, LoadOption.OverwriteChanges);
80 }
81
82 isSampleData = true;
83 return (IEnumerable)result.DefaultView;
84 }
85
95 public override IDataSourceViewSchema Schema
96 {
97 get
98 {
99 return new ObjectSchema(
100 _owner,
101 _owner.DataSourceControl.TypeName).GetViews()[0];
102 }
103 }
104
109 public override bool CanRetrieveTotalRowCount
110 {
111 get
112 {
113 return true;
114 }
115 }
116
117 private Type GetObjectType()
118 {
119 Type result;
120 try
121 {
122 ITypeResolutionService typeService = null;
123 typeService = (ITypeResolutionService)(_owner.Site.GetService(typeof(ITypeResolutionService)));
124 result = typeService.GetType(this._owner.DataSourceControl.TypeName, true, false);
125 }
126 catch
127 {
128 result = typeof(object);
129 }
130 return result;
131 }
132
142 public override bool CanDelete
143 {
144 get
145 {
146 Type objectType = GetObjectType();
147 if (typeof(Csla.Core.IUndoableObject).IsAssignableFrom(objectType))
148 {
149 return true;
150 }
151 else if (objectType.GetMethod("Remove") != null)
152 {
153 return true;
154 }
155 else
156 {
157 return false;
158 }
159 }
160 }
161
171 public override bool CanInsert
172 {
173 get
174 {
175 Type objectType = GetObjectType();
176 if (typeof(Csla.Core.IUndoableObject).IsAssignableFrom(objectType))
177 {
178 return true;
179 }
180 else
181 {
182 return false;
183 }
184 }
185 }
186
196 public override bool CanUpdate
197 {
198 get
199 {
200 Type objectType = GetObjectType();
201 if (typeof(Csla.Core.IUndoableObject).IsAssignableFrom(objectType))
202 {
203 return true;
204 }
205 else
206 {
207 return false;
208 }
209 }
210 }
211
216 public override bool CanPage
217 {
218 get
219 {
220 return _owner.DataSourceControl.TypeSupportsPaging;
221 }
222 }
223
228 public override bool CanSort
229 {
230 get
231 {
232 return _owner.DataSourceControl.TypeSupportsSorting;
233 }
234 }
235 }
236}
string TypeName
Get or set the full type name of the business object class to be used as a data source.
bool TypeSupportsSorting
Get or set a value indicating whether the business object data source supports sorting.
bool TypeSupportsPaging
Get or set a value indicating whether the business object data source supports paging.
Implements designer support for CslaDataSource.
Object responsible for providing details about data binding to a specific CSLA .NET object.
override bool CanInsert
Get a value indicating whether data binding can directly insert an instance of the object.
CslaDesignerDataSourceView(CslaDataSourceDesigner owner, string viewName)
Creates an instance of the object.
override bool CanDelete
Get a value indicating whether data binding can directly delete the object.
override bool CanRetrieveTotalRowCount
Get a value indicating whether data binding can retrieve the total number of rows of data.
override bool CanSort
Gets a value indicating whether the data source supports sorting.
override bool CanPage
Gets a value indicating whether the data source supports paging.
override IEnumerable GetDesignTimeData(int minimumRows, out bool isSampleData)
Returns a set of sample data used to populate controls at design time.
override IDataSourceViewSchema Schema
Returns schema information corresponding to the properties of the CSLA .NET business object.
override bool CanUpdate
Get a value indicating whether data binding can directly update or edit the object.
Object providing access to schema information for a business object.
Definition: ObjectSchema.cs:22
System.Web.UI.Design.IDataSourceViewSchema[] GetViews()
Returns a single element array containing the schema for the CSLA .NET business object.
Definition: ObjectSchema.cs:43
Defines the methods required to participate in n-level undo within the CSLA .NET framework.