1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
//------------------------------------------------------------------------------
// <copyright file="DataViewSettingCollection.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">Microsoft</owner>
// <owner current="true" primary="false">Microsoft</owner>
// <owner current="false" primary="false">Microsoft</owner>
//------------------------------------------------------------------------------
namespace System.Data {
using System;
using System.Diagnostics;
using System.ComponentModel;
using System.Collections;
[
Editor("Microsoft.VSDesigner.Data.Design.DataViewSettingsCollectionEditor, " + AssemblyRef.MicrosoftVSDesigner, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing),
]
public class DataViewSettingCollection : ICollection {
private readonly DataViewManager dataViewManager;
private readonly Hashtable list = new Hashtable();
internal DataViewSettingCollection(DataViewManager dataViewManager) {
if (dataViewManager == null) {
throw ExceptionBuilder.ArgumentNull("dataViewManager");
}
this.dataViewManager = dataViewManager;
}
public virtual DataViewSetting this[DataTable table] {
get {
if (table == null) {
throw ExceptionBuilder.ArgumentNull("table");
}
DataViewSetting dataViewSetting = (DataViewSetting) list[table];
if(dataViewSetting == null) {
dataViewSetting = new DataViewSetting();
this[table] = dataViewSetting;
}
return dataViewSetting;
}
set {
if (table == null) {
throw ExceptionBuilder.ArgumentNull("table");
}
value.SetDataViewManager(dataViewManager);
value.SetDataTable(table);
list[table] = value;
}
}
private DataTable GetTable(string tableName) {
DataTable dt = null;
DataSet ds = dataViewManager.DataSet;
if(ds != null) {
dt = ds.Tables[tableName];
}
return dt;
}
private DataTable GetTable(int index) {
DataTable dt = null;
DataSet ds = dataViewManager.DataSet;
if(ds != null) {
dt = ds.Tables[index];
}
return dt;
}
public virtual DataViewSetting this[string tableName] {
get {
DataTable dt = GetTable(tableName);
if(dt != null) {
return this[dt];
}
return null;
}
}
public virtual DataViewSetting this[int index] {
get {
DataTable dt = GetTable(index);
if(dt != null) {
return this[dt];
}
return null;
}
set {
DataTable dt = GetTable(index);
if(dt != null) {
this[dt] = value;
}else {
// throw excaption here.
}
}
}
// ----------- ICollection -------------------------
public void CopyTo(Array ar, int index) {
System.Collections.IEnumerator Enumerator = GetEnumerator();
while (Enumerator.MoveNext()) {
ar.SetValue(Enumerator.Current, index++);
}
}
public void CopyTo(DataViewSetting[] ar, int index) {
System.Collections.IEnumerator Enumerator = GetEnumerator();
while (Enumerator.MoveNext()) {
ar.SetValue(Enumerator.Current, index++);
}
}
[Browsable(false)]
public virtual int Count {
get {
DataSet ds = dataViewManager.DataSet;
return (ds == null) ? 0 : ds.Tables.Count;
}
}
public IEnumerator GetEnumerator() {
// I have to do something here.
return new DataViewSettingsEnumerator(dataViewManager);
}
[
Browsable(false)
]
public bool IsReadOnly {
get {
return true;
}
}
[Browsable(false)]
public bool IsSynchronized {
get {
// so the user will know that it has to lock this object
return false;
}
}
[Browsable(false)]
public object SyncRoot {
get {
return this;
}
}
internal void Remove(DataTable table) {
list.Remove(table);
}
private sealed class DataViewSettingsEnumerator : IEnumerator {
DataViewSettingCollection dataViewSettings;
IEnumerator tableEnumerator;
public DataViewSettingsEnumerator(DataViewManager dvm) {
DataSet ds = dvm.DataSet;
if(ds != null) {
dataViewSettings = dvm.DataViewSettings;
tableEnumerator = dvm.DataSet.Tables.GetEnumerator();
}else {
dataViewSettings = null;
tableEnumerator = DataSet.zeroTables.GetEnumerator();
}
}
public bool MoveNext() {
return tableEnumerator.MoveNext();
}
public void Reset() {
tableEnumerator.Reset();
}
public object Current {
get {
return dataViewSettings[(DataTable) tableEnumerator.Current];
}
}
}
}
}
|