예제 #1
0
        void Fill()
        {
            Type objType = Reflector.GetPropertyTypeByPath(Source.GetType(), PropertyPath);



            if (typeof(IList).IsAssignableFrom(objType) && objType != typeof(string))
            {
                object source = Reflector.GetPropertyValueByPath(Source, PropertyPath);


                Type genericType = objType.IsArray ? objType.GetElementType() : objType.GetGenericArguments().First();

                table.ColumnStyles[1].Width = 0;


                Type   genericBindingList = (typeof(BindingList <>).MakeGenericType(genericType));
                object bindingList        = Activator.CreateInstance(genericBindingList, source);

                var dataEntryGridView = new DataEntryGridView()
                {
                    BorderStyle         = BorderStyle.None,
                    BackgroundColor     = SystemColors.Control,
                    AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                    Dock = DockStyle.Fill
                };

                if (genericType.IsPrimitive)
                {
                    Type   genericListDataSource = (typeof(BindingListSourceAdapter <>).MakeGenericType(genericType));
                    object listDataSource        = Activator.CreateInstance(genericListDataSource, bindingList);

                    dataEntryGridView.DataSource = listDataSource;
                }
                else
                {
                    dataEntryGridView.DataSource = bindingList;
                }
                table.Controls.Add(dataEntryGridView);



                return;
            }



            foreach (var prop in Reflector.GetAllPublicProperties(objType))
            {
                var propertyType    = prop.PropertyType;
                var propName        = prop.Name;
                var currentPropPath = string.IsNullOrEmpty(PropertyPath) ? propName : $"{PropertyPath}.{propName}";

                Add(propName);


                Control control;


                if (propertyType.IsPrimitive)
                {
                    if (propertyType == typeof(bool))
                    {
                        control = new CheckBox();
                        control.DataBindings.Add(new(nameof(CheckBox.Checked), Source, currentPropPath));
                    }
                    else
                    {
                        control = new ValidatingTextBox(propertyType);
                        control.DataBindings.Add(new(nameof(ValidatingTextBox.Value), Source, currentPropPath));
                    }
                }

                else if (propertyType.IsEnum)
                {
                    control = new ValidatingEnumComboBox(propertyType);
                    control.DataBindings.Add(new(nameof(ValidatingEnumComboBox.Value), Source, currentPropPath));
                }
                else if (propertyType == typeof(DateTime))
                {
                    control = new DateTimePicker();
                    control.DataBindings.Add(new(nameof(DateTimePicker.Value), Source, currentPropPath));
                }
                else if (propertyType == typeof(string))
                {
                    control = new TextBox();
                    control.DataBindings.Add(new Binding(nameof(TextBox.Text), Source, currentPropPath));
                }

                else
                {
                    control = new Button()
                    {
                        Text = "...", Size = new(40, 20)
                    };
                    control.Click += (_, _) => new DataEntryForm(Source, currentPropPath).Show();
                }
                Add(control);
            }
        }
        void Fill()
        {
            foreach (var param in method.GetParameters())
            {
                IDictionary <string, object> proxyDictionary = Proxy;

                var paramType = param.ParameterType;
                var paramName = param.Name;



                proxyDictionary[paramName] = paramType == typeof(string) ? string.Empty : Activator.CreateInstance(paramType);


                Add(paramName);


                Control control;


                if (paramType.IsPrimitive)
                {
                    if (paramType == typeof(bool))
                    {
                        control = new CheckBox();
                        BindExpandoField(control, nameof(CheckBox.Checked), Proxy, paramName);
                    }
                    else
                    {
                        control = new ValidatingTextBox(paramType);
                        BindExpandoField(control, nameof(ValidatingTextBox.Value), Proxy, paramName);
                    }
                }

                else if (paramType.IsEnum)
                {
                    control = new ValidatingEnumComboBox(paramType);
                    BindExpandoField(control, nameof(ValidatingEnumComboBox.Value), Proxy, paramName);
                }
                else if (paramType == typeof(DateTime))
                {
                    control = new DateTimePicker();
                    BindExpandoField(control, nameof(DateTimePicker.Value), Proxy, paramName);
                }
                else if (paramType == typeof(string))
                {
                    control = new TextBox();
                    BindExpandoField(control, nameof(TextBox.Text), Proxy, paramName);
                }

                else
                {
                    control = new Button()
                    {
                        Text = "...", Size = new(40, 20)
                    };
                    control.Click += (_, _) => new DataEntryForm(proxyDictionary[paramName]).Show();
                }

                Add(control);
            }
        }