Exemplo n.º 1
0
 public FormMain()
 {
     InitializeComponent();
     this.Control = new Control();
     this.comboBoxAvailableTypes.Items.AddRange(Control.FootballFactories);
     this.FormObjectFields = new FormObjectFields(Control, this);
     Control.CreateStartObjects();
     foreach (var obj in Control.ApplicationObjects)
     {
         listBox.Items.Add(obj);
     }
 }
Exemplo n.º 2
0
        public void CreateFormFields(FormObjectFields form, Control control)
        {
            const int LabelWidth                   = 100;
            const int LabelMarginLeft              = 0;
            const int TextBoxAndComboBoxWidth      = 140;
            const int TextBoxAndComboBoxMarginLeft = 100;
            const int MarginStep                   = 30;
            const int FormMarginTop                = 70;
            int       marginTop  = 0;
            IFootball currObject = control.CurrObject;

            foreach (var property in currObject.GetType().GetProperties())
            {
                string propertyName = GetFieldName(property);
                Type   propertyType = property.PropertyType;

                form.Controls.Add(CreateLabel(propertyName, LabelWidth, LabelMarginLeft, marginTop));

                if ((propertyType == typeof(string)) || (propertyType == typeof(int)))
                {
                    TextBox textBox = CreateTextBox(propertyName, TextBoxAndComboBoxWidth,
                                                    TextBoxAndComboBoxMarginLeft, marginTop);
                    if (propertyType == typeof(string))
                    {
                        textBox.Text = (string)property.GetValue(currObject) ?? "";
                    }
                    else
                    {
                        textBox.Text = (int)property.GetValue(currObject) != 0 ?
                                       property.GetValue(currObject).ToString() : "";
                    }
                    form.Controls.Add(textBox);
                }
                else if (propertyType.IsEnum)
                {
                    ComboBox comboBox = CreateComboBox(propertyName, TextBoxAndComboBoxWidth,
                                                       TextBoxAndComboBoxMarginLeft, marginTop);
                    comboBox.Items.Add("");
                    foreach (var enumName in GetEnumNames(property.PropertyType))
                    {
                        comboBox.Items.Add(enumName);
                    }
                    comboBox.SelectedIndex = (int)property.GetValue(currObject);
                    form.Controls.Add(comboBox);
                }
                else if (propertyType.IsClass)
                {
                    if (propertyType.IsGenericType)
                    {
                        ComboBox comboBox = CreateComboBox(propertyName, TextBoxAndComboBoxWidth,
                                                           TextBoxAndComboBoxMarginLeft, marginTop);
                        var listObjects = property.GetValue(currObject) as IList;
                        foreach (var football in listObjects)
                        {
                            comboBox.Items.Add(football);
                        }
                        form.Controls.Add(comboBox);
                    }
                    else
                    {
                        bool genericParameter = IsGenericParameter(property.PropertyType, currObject.GetType());
                        if (genericParameter)
                        {
                            ComboBox comboBox = CreateComboBox(propertyName, TextBoxAndComboBoxWidth,
                                                               TextBoxAndComboBoxMarginLeft, marginTop);
                            foreach (var applicationObject in control.ApplicationObjects)
                            {
                                if (applicationObject.GetType() == property.PropertyType)
                                {
                                    comboBox.Items.Add(applicationObject);
                                }
                            }
                            comboBox.SelectedItem = property.GetValue(currObject);
                            form.Controls.Add(comboBox);
                        }
                        else
                        {
                            Button buttonComposition = form.Controls["buttonComposition"] as Button;
                            buttonComposition.Location = new Point(buttonComposition.Location.X, marginTop);
                            buttonComposition.Visible  = true;
                            control.CompositionObject  = property.GetValue(currObject);
                        }
                    }
                }
                marginTop += MarginStep;
            }
            Button buttonOk     = form.Controls["ButtonOk"] as Button;
            Button buttonCansel = form.Controls["ButtonCancel"] as Button;

            buttonOk.Location     = new Point(buttonOk.Location.X, marginTop);
            buttonCansel.Location = new Point(buttonCansel.Location.X, marginTop);
            form.Height           = marginTop + FormMarginTop;
        }