| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | using System; |
| | using System.Collections; |
| | using System.Text; |
| | using System.Data; |
| | using System.Reflection; |
| | using System.ComponentModel; |
| | using System.Windows.Forms; |
| |
|
| | namespace OutlookStyleControls |
| | { |
| | #region DataSourceRowComparer - implementation of abstract comparer class |
| | |
| | |
| | |
| | |
| | internal class DataSourceRowComparer : IComparer |
| | { |
| | IComparer baseComparer; |
| | public DataSourceRowComparer(IComparer baseComparer) |
| | { |
| | this.baseComparer = baseComparer; |
| | } |
| |
|
| | #region IComparer Members |
| |
|
| | public int Compare(object x, object y) |
| | { |
| | DataSourceRow r1 = (DataSourceRow)x; |
| | DataSourceRow r2 = (DataSourceRow)y; |
| | return baseComparer.Compare(r1.BoundItem, r2.BoundItem); |
| | } |
| |
|
| | #endregion |
| | } |
| | #endregion DataSourceRowComparer - implementation of abstract comparer class |
| |
|
| | #region DataSourceRow - abstract representation of a data item. |
| | |
| | |
| | |
| | |
| | |
| | |
| | internal class DataSourceRow : CollectionBase |
| | { |
| | DataSourceManager manager; |
| | object boundItem; |
| | public DataSourceRow(DataSourceManager manager, object boundItem) |
| | { |
| | this.manager = manager; |
| | this.boundItem = boundItem; |
| | } |
| |
|
| | public object this[int index] |
| | { |
| | get |
| | { |
| | return List[index]; |
| | } |
| | } |
| |
|
| | public object BoundItem |
| | { |
| | get |
| | { |
| | return boundItem; |
| | } |
| | } |
| |
|
| | public int Add(object val) |
| | { |
| | return List.Add(val); |
| | } |
| |
|
| | } |
| | #endregion DataSourceRow - abstract representation of a data item. |
| |
|
| | #region DataSourceManager - manages a bound datasource. |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | internal class DataSourceManager |
| | { |
| | private object dataSource; |
| | private string dataMember; |
| |
|
| | public ArrayList Columns; |
| | public ArrayList Rows; |
| |
|
| | public DataSourceManager(object dataSource, string dataMember) |
| | { |
| | this.dataSource = dataSource; |
| | this.dataMember = dataMember; |
| | InitManager(); |
| | } |
| |
|
| | |
| | |
| | |
| | public string DataMember |
| | { |
| | get { return dataMember; } |
| | } |
| |
|
| | |
| | |
| | |
| | public object DataSource |
| | { |
| | get { return dataSource; } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | private void InitManager() |
| | { |
| | if (dataSource is IListSource) |
| | InitDataSet(); |
| | if (dataSource is IList) |
| | InitList(); |
| | if (dataSource is OutlookGrid) |
| | InitGrid(); |
| | } |
| |
|
| | private void InitDataSet() |
| | { |
| | Columns = new ArrayList(); |
| | Rows = new ArrayList(); |
| |
|
| | DataTable table = ((DataSet)dataSource).Tables[this.dataMember]; |
| | |
| | foreach (DataColumn c in table.Columns) |
| | Columns.Add(c.ColumnName); |
| |
|
| | foreach (DataRow r in table.Rows) |
| | { |
| | DataSourceRow row = new DataSourceRow(this, r); |
| | for (int i = 0; i < Columns.Count; i++) |
| | row.Add(r[i]); |
| | Rows.Add(row); |
| | } |
| | } |
| |
|
| | private void InitGrid() |
| | { |
| | Columns = new ArrayList(); |
| | Rows = new ArrayList(); |
| |
|
| | OutlookGrid grid = (OutlookGrid)dataSource; |
| | |
| | foreach (DataGridViewColumn c in grid.Columns) |
| | Columns.Add(c.Name); |
| |
|
| | foreach (OutlookGridRow r in grid.Rows) |
| | { |
| | if (!r.IsGroupRow && !r.IsNewRow) |
| | { |
| | DataSourceRow row = new DataSourceRow(this, r); |
| | for (int i = 0; i < Columns.Count; i++) |
| | row.Add(r.Cells[i].Value); |
| | Rows.Add(row); |
| | } |
| | } |
| | } |
| |
|
| | private void InitList() |
| | { |
| | Columns = new ArrayList(); |
| | Rows = new ArrayList(); |
| | IList list = (IList)dataSource; |
| |
|
| | |
| | BindingFlags bf = BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty; |
| | PropertyInfo[] props = list[0].GetType().GetProperties(); |
| | foreach (PropertyInfo pi in props) |
| | Columns.Add(pi.Name); |
| |
|
| | foreach (object obj in list) |
| | { |
| | DataSourceRow row = new DataSourceRow(this, obj); |
| | foreach (PropertyInfo pi in props) |
| | { |
| | object result = obj.GetType().InvokeMember(pi.Name, bf, null, obj, null); |
| | row.Add(result); |
| | } |
| | Rows.Add(row); |
| | } |
| | } |
| |
|
| | public void Sort(System.Collections.IComparer comparer) |
| | { |
| | Rows.Sort(new DataSourceRowComparer(comparer)); |
| | } |
| |
|
| | } |
| | #endregion DataSourceManager - manages a bound datasource. |
| | } |
| |
|