comparison Source/Web/UI/Design/WebObjectBinderDesigner.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2 using System.Web.UI.Design;
3 using System.Security.Permissions;
4 using System.ComponentModel;
5
6 namespace BLToolkit.Web.UI.Design
7 {
8 [SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.UnmanagedCode)]
9 class WebObjectBinderDesigner : DataSourceDesigner
10 {
11 private DesignerDataSourceView _view;
12 private WebObjectBinder _component;
13
14 public override string[] GetViewNames()
15 {
16 return new string[] { "DefaultView" };
17 }
18
19 public override DesignerDataSourceView GetView(string viewName)
20 {
21 if (string.IsNullOrEmpty(viewName))
22 viewName = "DefaultView";
23
24 if (viewName != "DefaultView")
25 return null;
26
27 if (_view == null)
28 _view = new ObjectDesignerDataSourceView(this, viewName);
29
30 return _view;
31 }
32
33 public override void Initialize(IComponent component)
34 {
35 _component = (WebObjectBinder)component;
36
37 base.Initialize(component);
38 }
39
40 public override bool CanConfigure
41 {
42 get { return true; }
43 }
44
45 public override void Configure()
46 {
47 }
48
49 #region ObjectDesignerDataSourceView
50
51 class ObjectDesignerDataSourceView : DesignerDataSourceView
52 {
53 public ObjectDesignerDataSourceView(WebObjectBinderDesigner owner, string viewName)
54 : base(owner, viewName)
55 {
56 _owner = owner;
57 }
58
59 private readonly WebObjectBinderDesigner _owner;
60
61 public override IDataSourceViewSchema Schema
62 {
63 get { return new ObjectViewSchema(_owner); }
64 }
65
66 public override bool CanDelete { get { return _owner._component._objectBinder.AllowRemove; } }
67 public override bool CanInsert { get { return _owner._component._objectBinder.AllowNew; } }
68 public override bool CanUpdate { get { return _owner._component._objectBinder.AllowEdit; } }
69 public override bool CanPage { get { return true; } }
70 public override bool CanSort { get { return true; } }
71 public override bool CanRetrieveTotalRowCount { get { return true; } }
72
73 class ObjectViewSchema : IDataSourceViewSchema
74 {
75 public ObjectViewSchema(WebObjectBinderDesigner owner)
76 {
77 _owner = owner;
78 }
79
80 private readonly WebObjectBinderDesigner _owner;
81
82 public IDataSourceViewSchema[] GetChildren()
83 {
84 return null;
85 }
86
87 public IDataSourceFieldSchema[] GetFields()
88 {
89 PropertyDescriptorCollection fields =
90 ((ITypedList)_owner._component._objectBinder).GetItemProperties(null);
91
92 IDataSourceFieldSchema[] schema = new IDataSourceFieldSchema[fields.Count];
93
94 for (int i = 0; i < schema.Length; i++)
95 schema[i] = new ObjectFieldSchema(fields[i]);
96
97 return schema;
98 }
99
100 public string Name
101 {
102 get
103 {
104 Type type = _owner._component._objectBinder.ItemType;
105
106 return type != null? type.Name: string.Empty;
107 }
108 }
109
110 class ObjectFieldSchema : IDataSourceFieldSchema
111 {
112 public ObjectFieldSchema(PropertyDescriptor propertyDescriptor)
113 {
114 _propertyDescriptor = propertyDescriptor;
115
116 DataObjectFieldAttribute attr =
117 (DataObjectFieldAttribute)_propertyDescriptor.Attributes[typeof(DataObjectFieldAttribute)];
118
119 if (attr != null)
120 {
121 _length = attr.Length;
122 _primaryKey = attr.PrimaryKey;
123 _isIdentity = attr.IsIdentity;
124 _isNullable = attr.IsNullable;
125 }
126 }
127
128 private readonly PropertyDescriptor _propertyDescriptor;
129 private readonly int _length = -1;
130 private readonly bool _isIdentity;
131 private readonly bool _isNullable;
132 private readonly bool _primaryKey;
133
134 public Type DataType { get { return _propertyDescriptor.PropertyType; } }
135 public bool Identity { get { return _isIdentity; } }
136 public bool IsReadOnly { get { return _propertyDescriptor.IsReadOnly; } }
137 public bool IsUnique { get { return false; } }
138 public int Length { get { return _length; } }
139 public string Name { get { return _propertyDescriptor.Name; } }
140 public int Precision { get { return -1; } }
141 public bool PrimaryKey { get { return _primaryKey; } }
142 public int Scale { get { return -1; } }
143
144 public bool Nullable
145 {
146 get
147 {
148 Type type = _propertyDescriptor.PropertyType;
149 Type underlyingType = System.Nullable.GetUnderlyingType(type);
150
151 return underlyingType != null? true: _isNullable;
152 }
153 }
154 }
155 }
156 }
157
158 #endregion
159 }
160 }