Esempio n. 1
0
 public void RefreshImageProp()
 {
     if (_bindingSource == null)
     {
         _bindingSource = new BindingSource(Items, "");
     }
     _imageProperty = _bindingSource
                      .GetItemProperties(null)
                      .Cast <PropertyDescriptor>().FirstOrDefault(descriptor => descriptor.Name.Equals(_imageMember));
 }
Esempio n. 2
0
    /// <summary>
    /// Rebuilds the internal sorted collection.
    /// </summary>
    private void SyncInternalItems()
    {
        // locate the property descriptor that corresponds to the value of GroupMember
        _groupProperty = null;
        foreach (PropertyDescriptor descriptor in _bindingSource.GetItemProperties(null))
        {
            if (descriptor.Name.Equals(_groupMember))
            {
                _groupProperty = descriptor;
                break;
            }
        }

        // rebuild the collection and sort using custom logic
        _internalItems.Clear();
        foreach (object item in _bindingSource)
        {
            _internalItems.Add(item);
        }
//		_internalItems.Sort(this);

        // bind the underlying ComboBox to the sorted collection
        if (_internalSource == null)
        {
            _internalSource = new BindingSource(_internalItems, String.Empty);
            base.DataSource = _internalSource;
        }
        else
        {
            _internalSource.ResetBindings(false);
        }
    }
Esempio n. 3
0
        private PropertyDescriptorCollection GetProperties(Column column)
        {
            using (BindingSource source = new BindingSource())
            {
                source.DataSource = column.Reference != null ? column.Reference : column.DataType;
                // to get properties list of ICustomTypeDescriptor type, we need an instance
                object instance = null;
                if (source.DataSource is Type &&
                    typeof(ICustomTypeDescriptor).IsAssignableFrom(source.DataSource as Type))
                {
                    try
                    {
                        GetTypeInstanceEventArgs args = new GetTypeInstanceEventArgs(source.DataSource as Type);
                        Config.ReportSettings.OnGetBusinessObjectTypeInstance(null, args);
                        instance          = args.Instance;
                        source.DataSource = instance;
                    }
                    catch
                    {
                    }
                }

                // generic list? get element type
                if (column.Reference == null && column.DataType.IsGenericType)
                {
                    source.DataSource = column.DataType.GetGenericArguments()[0];
                }

                PropertyDescriptorCollection properties         = source.GetItemProperties(null);
                PropertyDescriptorCollection filteredProperties = new PropertyDescriptorCollection(null);

                foreach (PropertyDescriptor prop in properties)
                {
                    FilterPropertiesEventArgs args = new FilterPropertiesEventArgs(prop);
                    Config.ReportSettings.OnFilterBusinessObjectProperties(source.DataSource, args);
                    if (!args.Skip)
                    {
                        filteredProperties.Add(args.Property);
                    }
                }

                if (instance is IDisposable)
                {
                    try
                    {
                        (instance as IDisposable).Dispose();
                    }
                    catch
                    {
                    }
                }

                return(filteredProperties);
            }
        }
Esempio n. 4
0
 public void UpdateData(BindingSource bindingSrc)
 {
     this.bindingSrc = bindingSrc;
     VirtualMode     = false;
     dataTable       = (DataTable)bindingSrc.DataSource;
     if (dataTable == null)
     {
         throw new ArgumentException("BindingSource DataSource must be DataTable!");
     }
     RowCount    = bindingSrc.Count + HeaderHeight + FooterHeight;
     ColumnCount = bindingSrc.GetItemProperties(null).Count;
     VirtualMode = true;
 }
Esempio n. 5
0
 /// <summary>
 /// Sorts the data source and sets it
 /// </summary>
 private void SetDataSourceAndSort()
 {
     if (m_BindingSource == null)
     {
         return;
     }
     // Only do the sorting if the base class does not do this
     if (!base.Sorted && !String.IsNullOrEmpty(DisplayMember))
     {
         IComparer comparer = null;
         foreach (PropertyDescriptor descriptor in m_BindingSource.GetItemProperties(null))
         {
             if (descriptor.Name.Equals(DisplayMember))
             {
                 comparer = new TwoLevelComparer(m_GroupPropertyDescriptor, descriptor);
                 break;
             }
         }
         if (comparer == null)
         {
             throw new ApplicationException("DisplayMember property not found");
         }
         // rebuild the collection and sort using custom logic
         ArrayList arrayList = new ArrayList();
         foreach (object item in m_BindingSource)
         {
             arrayList.Add(item);
         }
         arrayList.Sort(comparer);
         base.DataSource = new BindingSource(arrayList, String.Empty);
     }
     else
     {
         base.DataSource = m_BindingSource;
     }
 }
        private PropertyDescriptorCollection GetProperties(Column column)
        {
            using (BindingSource source = new BindingSource())
            {
                source.DataSource = column.Reference != null ? column.Reference : column.DataType;

                PropertyDescriptorCollection properties         = source.GetItemProperties(null);
                PropertyDescriptorCollection filteredProperties = new PropertyDescriptorCollection(null);

                foreach (PropertyDescriptor prop in properties)
                {
                    FilterPropertiesEventArgs args = new FilterPropertiesEventArgs(prop);
                    Config.ReportSettings.OnFilterBusinessObjectProperties(source.DataSource, args);
                    if (!args.Skip)
                    {
                        filteredProperties.Add(args.Property);
                    }
                }

                return(filteredProperties);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Rebuilds the internal sorted collection.
        /// </summary>
        private void SyncInternalItems()
        {
            // locate the property descriptor that corresponds to the value of GroupMember
            mGroupProperty = null;
            foreach (PropertyDescriptor descriptor in mBindingSource.GetItemProperties(null))
            {
                if (descriptor.Name.Equals(mGroupMember))
                {
                    mGroupProperty = descriptor;
                    break;
                }
            }

            // rebuild the collection and sort using custom logic
            mInternalItems.Clear();
            foreach (object item in mBindingSource)
            {
                mInternalItems.Add(item);
            }
            mInternalItems.Sort(this);

            // bind the underlying ComboBox to the sorted collection
            base.DataSource = mInternalItems;
        }
Esempio n. 8
0
        public void SetDataSource(BindingSource source)
        {
            tblMain.Controls.Clear();
            tblMain.RowStyles.Clear();
            tblMain.RowCount = 0;

            var dataTypeArray = Enum.GetValues(typeof(QueryParameter.DataType)).OfType <QueryParameter.DataType>().ToArray();
            var props         = source.GetItemProperties(null).OfType <PropertyDescriptor>()
                                .Where(p => Filter == null || Filter.Contains(p))
                                .OrderBy(p => p.DisplayName ?? p.Name)
                                .ToArray();

            foreach (var prop in props)
            {
                tblMain.RowStyles.Add(new RowStyle(SizeType.AutoSize));
                tblMain.RowCount += 1;
                var currRow = tblMain.RowCount - 1;

                var lbl = new Label();
                lbl.AutoSize = true;
                lbl.Text     = prop.DisplayName ?? prop.Name;
                lbl.Anchor   = AnchorStyles.Left;
                tblMain.Controls.Add(lbl, 0, currRow);

                var currProp = prop as QueryParamDescriptor;
                if (currProp != null)
                {
                    var box = new ComboBox();
                    box.Anchor        = AnchorStyles.Left;
                    box.DropDownStyle = ComboBoxStyle.DropDownList;
                    box.DataSource    = Enum.GetValues(typeof(QueryParameter.DataType));
                    tblMain.Controls.Add(box, 1, currRow);
                    _initialValues.Add(Array.IndexOf(dataTypeArray, currProp.Param.Type));
                    box.SelectedIndexChanged += (s, e) =>
                    {
                        if (!_isLoaded)
                        {
                            return;
                        }

                        tblMain.Controls.Remove(tblMain.GetControlFromPosition(2, currRow));
                        var newValue = (QueryParameter.DataType)((ComboBox)s).SelectedValue;
                        currProp.Param.Type = newValue;
                        switch (newValue)
                        {
                        case QueryParameter.DataType.Boolean:
                            currProp.SetValue(source.Current, default(bool));
                            AddControl(source, currProp, typeof(bool), currRow);
                            break;

                        case QueryParameter.DataType.DateTime:
                            currProp.SetValue(source.Current, default(DateTime));
                            AddControl(source, currProp, typeof(DateTime), currRow);
                            break;

                        case QueryParameter.DataType.Decimal:
                            currProp.SetValue(source.Current, default(decimal));
                            AddControl(source, currProp, typeof(decimal), currRow);
                            break;

                        case QueryParameter.DataType.Integer:
                            currProp.SetValue(source.Current, default(long));
                            AddControl(source, currProp, typeof(long), currRow);
                            break;

                        default:
                            currProp.SetValue(source.Current, default(string));
                            AddControl(source, currProp, typeof(string), currRow);
                            break;
                        }
                    };
                }

                AddControl(source, prop, null, currRow);
            }
        }
Esempio n. 9
0
        public static ArrayList GetDataSourceDataFields(object dataSource, string dataMember, string fieldToExclude)
        {
            ArrayList arrayList = new ArrayList();

            if (dataSource != null)
            {
                try
                {
                    if (dataSource.GetType().GetInterface("IDataSource") != null)
                    {
                        try
                        {
                            MethodInfo method = dataSource.GetType().GetMethod("Select");
                            if (method != null)
                            {
                                if (method.GetParameters().Length == 1)
                                {
                                    Type            type        = dataSource.GetType().Assembly.GetType("System.Web.UI.DataSourceSelectArguments", true);
                                    ConstructorInfo constructor = type.GetConstructor(new Type[0]);
                                    dataSource = method.Invoke(dataSource, new object[1]
                                    {
                                        constructor.Invoke(new object[0])
                                    });
                                }
                                else
                                {
                                    dataSource = method.Invoke(dataSource, new object[0]);
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                    DataTable dataTable = null;
                    if (dataSource is BindingSource)
                    {
                        BindingSource bindingSource = (BindingSource)dataSource;
                        string        dataMember2   = bindingSource.DataMember;
                        try
                        {
                            if (string.IsNullOrEmpty(dataMember))
                            {
                                dataMember = DataBindingHelper.GetDataSourceDefaultDataMember(bindingSource);
                            }
                            bindingSource.DataMember = dataMember;
                            foreach (PropertyDescriptor itemProperty in bindingSource.GetItemProperties(null))
                            {
                                if (itemProperty.Name != fieldToExclude)
                                {
                                    arrayList.Add(new DataFieldDescriptor(itemProperty.Name, itemProperty.PropertyType));
                                }
                            }
                        }
                        finally
                        {
                            bindingSource.DataMember = dataMember2;
                        }
                    }
                    else if (dataSource is DataTable)
                    {
                        dataTable = (DataTable)dataSource;
                    }
                    else if (dataSource is DataView)
                    {
                        dataTable = ((DataView)dataSource).Table;
                    }
                    else if (dataSource is DataSet && ((DataSet)dataSource).Tables.Count > 0)
                    {
                        dataTable = ((!string.IsNullOrEmpty(dataMember)) ? ((DataSet)dataSource).Tables[dataMember] : ((DataSet)dataSource).Tables[0]);
                    }
                    else if (dataSource is IDataAdapter)
                    {
                        DataSet dataSet = new DataSet();
                        dataSet.Locale = CultureInfo.CurrentCulture;
                        DataTable[] array = ((IDataAdapter)dataSource).FillSchema(dataSet, SchemaType.Mapped);
                        if (array.Length > 0)
                        {
                            dataTable = array[0];
                        }
                    }
                    else if (dataSource is IDataReader)
                    {
                        IDataReader dataReader = (IDataReader)dataSource;
                        if (!dataReader.IsClosed)
                        {
                            DataTable schemaTable = dataReader.GetSchemaTable();
                            if (schemaTable != null)
                            {
                                foreach (DataRow row in schemaTable.Rows)
                                {
                                    string text  = (string)row["ColumnName"];
                                    Type   type2 = (Type)row["DataType"];
                                    if (text != fieldToExclude)
                                    {
                                        arrayList.Add(new DataFieldDescriptor(text, type2));
                                    }
                                }
                            }
                        }
                    }
                    else if (dataSource is IDbCommand)
                    {
                        IDbCommand  dbCommand   = (IDbCommand)dataSource;
                        IDataReader dataReader2 = null;
                        if (dbCommand.Connection != null)
                        {
                            try
                            {
                                dbCommand.Connection.Open();
                                dataReader2 = dbCommand.ExecuteReader();
                                DataTable schemaTable2 = dataReader2.GetSchemaTable();
                                if (schemaTable2 != null)
                                {
                                    foreach (DataRow row2 in schemaTable2.Rows)
                                    {
                                        string text2 = (string)row2["ColumnName"];
                                        Type   type3 = (Type)row2["DataType"];
                                        if (text2 != fieldToExclude)
                                        {
                                            arrayList.Add(new DataFieldDescriptor(text2, type3));
                                        }
                                    }
                                }
                                dataReader2.Close();
                            }
                            finally
                            {
                                if (dbCommand.Connection != null && dbCommand.Connection.State != 0)
                                {
                                    dbCommand.Connection.Close();
                                }
                                if (dataReader2 != null && !dataReader2.IsClosed)
                                {
                                    dataReader2.Close();
                                }
                            }
                        }
                    }
                    if (dataTable != null)
                    {
                        {
                            foreach (DataColumn column in dataTable.Columns)
                            {
                                if (column.ColumnName != fieldToExclude)
                                {
                                    arrayList.Add(new DataFieldDescriptor(column.ColumnName, column.DataType));
                                }
                            }
                            return(arrayList);
                        }
                    }
                    if (arrayList.Count == 0 && dataSource is ITypedList)
                    {
                        {
                            foreach (PropertyDescriptor itemProperty2 in ((ITypedList)dataSource).GetItemProperties(null))
                            {
                                if (itemProperty2.PropertyType != typeof(string) && itemProperty2.Name != fieldToExclude)
                                {
                                    arrayList.Add(new DataFieldDescriptor(itemProperty2.Name, itemProperty2.PropertyType));
                                }
                            }
                            return(arrayList);
                        }
                    }
                    if (arrayList.Count == 0)
                    {
                        if (dataSource is IEnumerable)
                        {
                            IEnumerator enumerator6 = ((IEnumerable)dataSource).GetEnumerator();
                            enumerator6.Reset();
                            enumerator6.MoveNext();
                            {
                                foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(enumerator6.Current))
                                {
                                    if (property.PropertyType != typeof(string) && property.Name != fieldToExclude)
                                    {
                                        arrayList.Add(new DataFieldDescriptor(property.Name, property.PropertyType));
                                    }
                                }
                                return(arrayList);
                            }
                        }
                        return(arrayList);
                    }
                    return(arrayList);
                }
                catch
                {
                    return(arrayList);
                }
            }
            return(arrayList);
        }