PageRenderTime 48ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/Integrator/CLRI/Cerebrum.Data.Manager/DataView.cs

#
C# | 411 lines | 307 code | 62 blank | 42 comment | 20 complexity | 7fbf0d298662f8d059bcc379fe7808fb MD5 | raw file
Possible License(s): AGPL-3.0
  1. namespace Cerebrum.Data
  2. {
  3. public class DataItemUnion : System.ComponentModel.Component, System.ComponentModel.IBindingList, System.ComponentModel.ISupportInitialize, System.ComponentModel.ITypedList
  4. {
  5. //private System.Collections.ArrayList Tables;
  6. private System.Collections.ArrayList Rows;
  7. public DataItemUnion()
  8. {
  9. //Tables = new System.Collections.ArrayList();
  10. Rows = new System.Collections.ArrayList();
  11. }
  12. public void Add(System.ComponentModel.IBindingList v)
  13. {
  14. int i;
  15. for (i=0; i <= v.Count- 1; i++)
  16. {
  17. this.Add(new Cerebrum.Data.DataItemView((System.ComponentModel.ICustomTypeDescriptor)v[i]));
  18. }
  19. }
  20. /*public void Add(System.Data.DataTable t)
  21. {
  22. this.Add(t.DefaultView);
  23. }
  24. public void Add(System.Data.DataTable[] t)
  25. {
  26. foreach (System.Data.DataTable tbl in t)
  27. {
  28. this.Add(tbl.DefaultView);
  29. }
  30. }*/
  31. public int Add(System.ComponentModel.ICustomTypeDescriptor r)
  32. {
  33. return this.Add(new Cerebrum.Data.DataItemView(r));
  34. }
  35. public void Add(System.ComponentModel.ICustomTypeDescriptor[] r)
  36. {
  37. foreach (System.ComponentModel.ICustomTypeDescriptor row in r)
  38. {
  39. this.Add(new Cerebrum.Data.DataItemView(row));
  40. }
  41. }
  42. public int Add(object value)
  43. {
  44. return this.Add((Cerebrum.Data.DataItemView)value);
  45. }
  46. int System.Collections.IList.Add(object value)
  47. {
  48. return this.Add((Cerebrum.Data.DataItemView)value);
  49. }
  50. protected int Add(Cerebrum.Data.DataItemView rv)
  51. {
  52. int i = Rows.Add(rv);
  53. if(_suspendCount == 0 && this.ListChanged!=null)
  54. {
  55. this.ListChanged(this, new System.ComponentModel.ListChangedEventArgs(System.ComponentModel.ListChangedType.ItemAdded, i));
  56. }
  57. return i;
  58. }
  59. int _suspendCount = 0;
  60. public void SuspendEvents()
  61. {
  62. _suspendCount ++;
  63. }
  64. public void ResumeEvents()
  65. {
  66. _suspendCount --;
  67. if(_suspendCount == 0)
  68. {
  69. Reset();
  70. }
  71. }
  72. public void Clear()
  73. {
  74. /*for(int i=Rows.Count-1;i>=0;i--)
  75. {
  76. RemoveAt(i);
  77. }*/
  78. Rows.Clear();
  79. Reset();
  80. }
  81. public void Reset()
  82. {
  83. if(_suspendCount == 0 && this.ListChanged!=null)
  84. {
  85. this.ListChanged(this, new System.ComponentModel.ListChangedEventArgs(System.ComponentModel.ListChangedType.Reset, -1));
  86. }
  87. }
  88. public bool Contains(object value)
  89. {
  90. return Rows.Contains(value);
  91. }
  92. public void CopyTo(System.Array array, int index)
  93. {
  94. Rows.CopyTo(array, index);
  95. }
  96. public int Count
  97. {
  98. get
  99. {
  100. return Rows.Count;
  101. }
  102. }
  103. public System.Collections.IEnumerator GetEnumerator()
  104. {
  105. return Rows.GetEnumerator();
  106. }
  107. public int IndexOf(object value)
  108. {
  109. return Rows.IndexOf(value);
  110. }
  111. public void Insert(int index, object value)
  112. {
  113. throw new System.NotSupportedException();
  114. }
  115. public bool IsSynchronized
  116. {
  117. get
  118. {
  119. return Rows.IsSynchronized;
  120. }
  121. }
  122. public object this[int index]
  123. {
  124. get
  125. {
  126. return Rows[index];
  127. }
  128. set
  129. {
  130. Rows[index] = value;
  131. if(_suspendCount == 0 && this.ListChanged!=null)
  132. {
  133. this.ListChanged(this, new System.ComponentModel.ListChangedEventArgs(System.ComponentModel.ListChangedType.ItemChanged, index));
  134. }
  135. }
  136. }
  137. public void Remove(object value)
  138. {
  139. int i = Rows.IndexOf(value);
  140. if(i>=0)
  141. {
  142. this.RemoveAt(i);
  143. }
  144. }
  145. public void RemoveAt(int index)
  146. {
  147. Rows.RemoveAt(index);
  148. if(_suspendCount == 0 && this.ListChanged!=null)
  149. {
  150. this.ListChanged(this, new System.ComponentModel.ListChangedEventArgs(System.ComponentModel.ListChangedType.ItemDeleted, index));
  151. }
  152. }
  153. public int Find(System.ComponentModel.PropertyDescriptor property, object key)
  154. {
  155. int i;
  156. System.Collections.IList s = Rows;
  157. for (i=0; i < s.Count; i++)
  158. {
  159. if (key.Equals(property.GetValue(s[i])))
  160. {
  161. return i;
  162. }
  163. }
  164. return -1;
  165. }
  166. #region IBindingList Members
  167. public void AddIndex(System.ComponentModel.PropertyDescriptor property)
  168. {
  169. // TODO: Add DataView.AddIndex implementation
  170. }
  171. public bool AllowNew
  172. {
  173. get
  174. {
  175. // TODO: Add DataView.AllowNew getter implementation
  176. return false;
  177. }
  178. }
  179. public void ApplySort(System.ComponentModel.PropertyDescriptor property, System.ComponentModel.ListSortDirection direction)
  180. {
  181. // TODO: Add DataView.ApplySort implementation
  182. }
  183. public System.ComponentModel.PropertyDescriptor SortProperty
  184. {
  185. get
  186. {
  187. // TODO: Add DataView.SortProperty getter implementation
  188. return null;
  189. }
  190. }
  191. public bool SupportsSorting
  192. {
  193. get
  194. {
  195. // TODO: Add DataView.SupportsSorting getter implementation
  196. return false;
  197. }
  198. }
  199. public bool IsSorted
  200. {
  201. get
  202. {
  203. // TODO: Add DataView.IsSorted getter implementation
  204. return false;
  205. }
  206. }
  207. public bool AllowRemove
  208. {
  209. get
  210. {
  211. // TODO: Add DataView.AllowRemove getter implementation
  212. return true;
  213. }
  214. }
  215. public bool SupportsSearching
  216. {
  217. get
  218. {
  219. // TODO: Add DataView.SupportsSearching getter implementation
  220. return true;
  221. }
  222. }
  223. public System.ComponentModel.ListSortDirection SortDirection
  224. {
  225. get
  226. {
  227. // TODO: Add DataView.SortDirection getter implementation
  228. return System.ComponentModel.ListSortDirection.Ascending;
  229. }
  230. }
  231. public event System.ComponentModel.ListChangedEventHandler ListChanged;
  232. public bool SupportsChangeNotification
  233. {
  234. get
  235. {
  236. // TODO: Add DataView.SupportsChangeNotification getter implementation
  237. return true;
  238. }
  239. }
  240. public void RemoveSort()
  241. {
  242. // TODO: Add DataView.RemoveSort implementation
  243. }
  244. public object AddNew()
  245. {
  246. // TODO: Add DataView.AddNew implementation
  247. return null;
  248. }
  249. public bool AllowEdit
  250. {
  251. get
  252. {
  253. // TODO: Add DataView.AllowEdit getter implementation
  254. return false;
  255. }
  256. }
  257. public void RemoveIndex(System.ComponentModel.PropertyDescriptor property)
  258. {
  259. // TODO: Add DataView.RemoveIndex implementation
  260. }
  261. #endregion
  262. #region IList Members
  263. public bool IsReadOnly
  264. {
  265. get
  266. {
  267. // TODO: Add DataView.IsReadOnly getter implementation
  268. return false;
  269. }
  270. }
  271. public bool IsFixedSize
  272. {
  273. get
  274. {
  275. // TODO: Add DataView.IsFixedSize getter implementation
  276. return false;
  277. }
  278. }
  279. #endregion
  280. #region ICollection Members
  281. public object SyncRoot
  282. {
  283. get
  284. {
  285. // TODO: Add DataView.SyncRoot getter implementation
  286. return Rows.SyncRoot;
  287. }
  288. }
  289. #endregion
  290. #region ISupportInitialize Members
  291. public void BeginInit()
  292. {
  293. // TODO: Add DataView.BeginInit implementation
  294. }
  295. public void EndInit()
  296. {
  297. // TODO: Add DataView.EndInit implementation
  298. }
  299. #endregion
  300. protected System.ComponentModel.PropertyDescriptorCollection m_SelectedColumns = new System.ComponentModel.PropertyDescriptorCollection(new System.ComponentModel.PropertyDescriptor[0]);
  301. public string[] FieldNames
  302. {
  303. get
  304. {
  305. string [] names = new string[m_SelectedColumns.Count];
  306. for(int i=0;i<m_SelectedColumns.Count;i++)
  307. {
  308. names[i] = m_SelectedColumns[i].Name;
  309. }
  310. return names;
  311. }
  312. set
  313. {
  314. m_SelectedColumns.Clear();
  315. for(int i=0;i<value.Length;i++)
  316. {
  317. m_SelectedColumns.Add(new Cerebrum.Data.DataItemPropertyDescriptor(value[i]));
  318. }
  319. }
  320. }
  321. public string SelectedColumns
  322. {
  323. get
  324. {
  325. return System.String.Join(",", FieldNames);
  326. }
  327. set
  328. {
  329. FieldNames = value.Split(new char[]{','});
  330. }
  331. }
  332. #region ITypedList Members
  333. public System.ComponentModel.PropertyDescriptorCollection GetItemProperties(System.ComponentModel.PropertyDescriptor[] listAccessors)
  334. {
  335. /*if(Rows.Count>0)
  336. {
  337. DataItemView rv = Rows[0] as DataItemView;
  338. return rv.GetProperties(null);
  339. }*/
  340. return m_SelectedColumns;
  341. }
  342. public string GetListName(System.ComponentModel.PropertyDescriptor[] listAccessors)
  343. {
  344. return System.String.Empty;
  345. }
  346. #endregion
  347. }
  348. }