コード例 #1
0
        public void ManyToOneField_CreateInstanceTest()
        {
            // Model Data : Trainee, Groupe, Speciality
            using (ModelContext db = new ModelContext())
            {
                Panel Container   = new Panel();
                Size  SizeLabel   = new Size(100, 20);
                Size  SizeControl = new Size(100, 20);

                IGwinBaseBLO GroupeBLO = new GwinBaseBLO <Group>(db);
                PropertyInfo TaskProjectsPropertyInfo = typeof(Group).GetProperty(nameof(Group.TaskProjects));
                ConfigEntity configEntity             = ConfigEntity.CreateConfigEntity(typeof(Group));
                Trainee      trainee = new Trainee();



                ManyToManyField ManyToManyField = new ManyToManyField(
                    TaskProjectsPropertyInfo,
                    Orientation.Vertical,
                    SizeLabel,
                    SizeControl,
                    configEntity,
                    Container,
                    GroupeBLO);

                // Selected the first speciality
                // selectedindex = 1 , index 0 for EmptyData
                ManyToManyField
                .SelectionFilterManager
                .ListeComboBox[typeof(Project).Name]
                .SelectedIndex = 1;
            }
        }
        /// <summary>
        /// CreateField in EntryForm
        ///
        /// </summary>
        /// <param name="param">
        /// param.PropertyInfo
        /// param.Location
        /// param.OrientationField
        /// param.SizeLabel
        /// param.SizeControl
        /// param.ConfigProperty
        /// param.TabIndex
        /// param.Service
        /// param.ConfigEntity
        /// param.TabControlForm
        /// param.Entity
        /// param.ConteneurFormulaire
        /// </param>
        /// <returns>the created field</returns>
        public BaseField CreateField_In_EntryForm(CreateFieldParams param)
        {
            if (param.ConfigProperty.EntryForm?.TabPage == true)
            {
                TabPage tabPage = new TabPage();
                tabPage.Name = "tabPage" + param.PropertyInfo.Name;
                tabPage.Text = param.ConfigProperty.DisplayProperty.Title;
                param.TabControlForm.TabPages.Add(tabPage);
                param.ConteneurFormulaire = tabPage;
            }


            //Default Value
            List <BaseEntity> ls_default_value = null;

            if (param.Entity != null)
            {
                IList ls_obj = param.PropertyInfo.GetValue(param.Entity) as IList;

                if (ls_obj != null)
                {
                    ls_default_value = ls_obj.Cast <BaseEntity>().ToList();
                }
            }

            if (param.SizeControl.Height < 80)
            {
                param.SizeControl = new System.Drawing.Size(param.SizeControl.Width, 100);
            }

            ManyToManyField manyToManyField = new ManyToManyField(param.PropertyInfo,
                                                                  param.OrientationField,
                                                                  param.SizeLabel,
                                                                  param.SizeControl,
                                                                  param.ConfigProperty.ConfigEntity,
                                                                  param.ConteneurFormulaire,
                                                                  param.EntityBLO);

            manyToManyField.Name = param.PropertyInfo.Name;



            if (param.ConfigProperty.EntryForm?.TabPage == true)
            {
                manyToManyField.Dock = DockStyle.Fill;
            }

            // Inert in to Interface
            param.ConteneurFormulaire.Controls.Add(manyToManyField);
            return(manyToManyField);
        }
コード例 #3
0
        /// <summary>
        /// Création et Initalisation des contrôles du formulaire
        /// </summary>
        private void GenerateFormIfNotGenerated()
        {
            // Generate if not generated
            if (!this.AutoGenerateField || this.isGeneratedForm)
            {
                return;
            }

            this.isGeneratedForm = true;

            #region Taille par défaut
            // Positions et Tailles par défaut
            int y_field         = 0;
            int x_field         = 0;
            int width_label     = 100;
            int height_label    = 10;
            int width_control   = 200;
            int height_control  = 25;
            int width_groueBox  = 100;
            int height_groueBox = 200; // il ne sera pas utilisé

            // Orientation par défaut
            Orientation orientation = Orientation.Vertical;
            #endregion

            #region Préparation de l'interface par Panel et GroupeBox
            // Initalisation de l'interface avec TabControl
            this.InitTabPageInterface();

            // Création des groupBox s'il existe
            Dictionary <string, Control> GroupesBoxMainContainers = new Dictionary <string, Control>();
            this.CreateGroupesBoxes(GroupesBoxMainContainers, width_groueBox, height_groueBox);
            #endregion

            // L'index de la touche Entrer
            int TabIndex = 0;

            var listeProprite = from i in this.Service.TypeEntity.GetProperties()
                                where i.GetCustomAttribute(typeof(EntryFormAttribute)) != null
                                orderby((EntryFormAttribute)i.GetCustomAttribute(typeof(EntryFormAttribute))).Ordre
                                select i;



            // Affichage des champs par leurs type
            foreach (PropertyInfo item in listeProprite)
            {
                #region Recalcule des valeurs pardéfaut selon l'annotation de chauqe champs
                // l'annotation
                ConfigProperty configProperty = new ConfigProperty(item, this.ConfigEntity);

                // Taile du Field
                int width_control_config = width_control;
                if (configProperty.EntryForm?.WidthControl != 0)
                {
                    width_control_config = configProperty.EntryForm.WidthControl;
                }

                // Orientation
                Orientation orientation_config = orientation;
                if (configProperty.EntryForm?.UseOrientationField == true)
                {
                    orientation_config = configProperty.EntryForm.OrientationField;
                }
                #endregion

                Control field_control   = null;
                Control FiledContainner = this.ConteneurFormulaire;
                if (configProperty.EntryForm?.GroupeBox != null && configProperty.EntryForm?.GroupeBox != string.Empty)
                {
                    FiledContainner = GroupesBoxMainContainers[configProperty.EntryForm?.GroupeBox];
                }


                switch (item.PropertyType.Name)
                {
                    #region Champs String
                case "String":


                    StringField stringFiled = new StringField(
                        item,
                        orientation_config,
                        new Size(width_label, height_label),
                        new Size(width_control_config, height_control),
                        this.ConfigEntity);
                    stringFiled.Location      = new System.Drawing.Point(x_field, y_field);
                    stringFiled.Name          = item.Name;
                    stringFiled.TabIndex      = ++TabIndex;
                    stringFiled.Text_Label    = configProperty.DisplayProperty.Titre;
                    stringFiled.FieldChanged += ControlPropriete_ValueChanged;
                    if (configProperty.EntryForm?.isOblegatoir == true)
                    {
                        stringFiled.ValidatingFiled += textBoxString_Validating;
                    }
                    // Insertion à l'interface
                    this.ConteneurFormulaire.Controls.Add(stringFiled);
                    field_control = stringFiled;

                    break;
                    #endregion

                    #region Champs Int32
                case "Int32":

                    Int32Filed int32Filed = new Int32Filed(
                        item,
                        orientation_config,
                        new Size(width_label, height_label),
                        new Size(width_control_config, height_control),
                        this.ConfigEntity);
                    int32Filed.Location      = new System.Drawing.Point(x_field, y_field);
                    int32Filed.Name          = item.Name;
                    int32Filed.TabIndex      = ++TabIndex;
                    int32Filed.Text_Label    = configProperty.DisplayProperty.Titre;
                    int32Filed.FieldChanged += ControlPropriete_ValueChanged;
                    if (configProperty.EntryForm?.isOblegatoir == true)
                    {
                        int32Filed.ValidatingFiled += TextBoxInt32_Validating;
                    }
                    // Insertion à l'interface
                    this.ConteneurFormulaire.Controls.Add(int32Filed);
                    field_control = int32Filed;
                    break;
                    #endregion

                    #region Champs DateTime
                case "DateTime":

                    DateTimeField dateTimeField = new DateTimeField(
                        item,
                        orientation_config,
                        new Size(width_label, height_label),
                        new Size(width_control_config, height_control),
                        this.ConfigEntity);

                    dateTimeField.Location      = new System.Drawing.Point(x_field, y_field);
                    dateTimeField.Name          = item.Name;
                    dateTimeField.TabIndex      = ++TabIndex;
                    dateTimeField.Text_Label    = configProperty.DisplayProperty.Titre;
                    dateTimeField.FieldChanged += ControlPropriete_ValueChanged;
                    if (configProperty.EntryForm?.isOblegatoir == true)
                    {
                        dateTimeField.ValidatingFiled += DateTimePicker_Validating;
                    }
                    // Insertion à l'interface
                    this.ConteneurFormulaire.Controls.Add(dateTimeField);
                    field_control = dateTimeField;
                    break;
                    #endregion

                default:
                {
                    #region Champs : ManyToOne
                    if (configProperty.Relationship?.Relation == RelationshipAttribute.Relations.ManyToOne)
                    {
                        // Déterminer le contenue du Field ManyToOne : GroupeBox ou Panel
                        Control ConteneurManyToMany = this.ConteneurFormulaire;
                        if (configProperty.EntryForm?.GroupeBox != null && configProperty.EntryForm?.GroupeBox != string.Empty)
                        {
                            ConteneurManyToMany = GroupesBoxMainContainers[configProperty.EntryForm?.GroupeBox];
                        }

                        // Création de champs ManyToOneField
                        Int64 InitValue = 0;
                        //if (ValeursFiltre != null && ValeursFiltre.Keys.Contains(properperty.DisplayProperty.TitretyInfo.Name))
                        //    default_value = (Int64)ValeursFiltre[propertyInfo.Name];

                        ManyToOneField manyToOneField = new ManyToOneField(this.Service, item,
                                                                           ConteneurManyToMany, orientation_config,
                                                                           new Size(width_label, height_label),
                                                                           new Size(width_control_config, height_control), InitValue, this.ConfigEntity
                                                                           );
                        manyToOneField.Location      = new System.Drawing.Point(x_field, y_field);
                        manyToOneField.Name          = item.Name;
                        manyToOneField.TabIndex      = ++TabIndex;
                        manyToOneField.Text_Label    = configProperty.DisplayProperty.Titre;
                        manyToOneField.FieldChanged += ControlPropriete_ValueChanged;
                        if (configProperty.EntryForm?.isOblegatoir == true)
                        {
                            manyToOneField.Validating += ComboBox_Validating;
                        }
                        this.ConteneurFormulaire.Controls.Add(manyToOneField);
                        field_control = manyToOneField;
                    }
                    #endregion

                    #region Champs ManyToMany
                    if (configProperty.Relationship?.Relation == RelationshipAttribute.Relations.ManyToMany)
                    {
                        if (configProperty.EntryForm?.TabPage == true)
                        {
                            TabPage tabPage = new TabPage();
                            tabPage.Name = "tabPage" + item.Name;
                            tabPage.Text = configProperty.DisplayProperty.Titre;
                            tabControlForm.TabPages.Add(tabPage);
                            FiledContainner = tabPage;
                        }


                        //Trouver les Valeurs par défaut
                        List <BaseEntity> ls_default_value = null;
                        if (this.Entity != null)
                        {
                            IList ls_obj = item.GetValue(this.Entity) as IList;

                            if (ls_obj != null)
                            {
                                ls_default_value = ls_obj.Cast <BaseEntity>().ToList();
                            }
                        }



                        ManyToManyField manyToManyField = new ManyToManyField(item,
                                                                              orientation_config,
                                                                              new Size(width_label, height_label),
                                                                              new Size(width_control_config, height_control),
                                                                              this.ConfigEntity,
                                                                              FiledContainner,
                                                                              this.Service);
                        manyToManyField.Name          = item.Name;
                        manyToManyField.FieldChanged += ControlPropriete_ValueChanged;



                        if (configProperty.EntryForm?.TabPage == true)
                        {
                            manyToManyField.Dock = DockStyle.Fill;
                        }

                        field_control = manyToManyField;
                    }
                    #endregion
                }
                break;
                } // Fin de suitch
                FiledContainner.Controls.Add(field_control);
                // Insertion du Champs dans sa GroupeBox si il existe
                // [Bug] il n'est pas supprimé de l'inrface, car il est déja ajouté
            }// Fin de for

            // TabControl sur Enregistrer et Annuler
            this.btEnregistrer.TabIndex = ++TabIndex;
            this.btAnnuler.TabIndex     = ++TabIndex;


            foreach (GroupBox item in this.ConteneurFormulaire.Controls.Cast <Control>().Where(c => c.GetType() == typeof(GroupBox)))
            {
                // item.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold);
                item.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel, ((byte)(0)));
            }
            foreach (FlowLayoutPanel item in GroupesBoxMainContainers.Values)
            {
                item.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(0)));
            }
        }
コード例 #4
0
        /// <summary>
        /// Lire les informations du formulaire vers l'Entity
        /// </summary>
        public virtual void ReadFormToEntity()
        {
            BaseEntity entity     = this.Entity;
            Type       typeEntity = this.Service.TypeEntity;

            foreach (PropertyInfo item in ListeChampsFormulaire())
            {
                ConfigProperty attributesOfProperty = new ConfigProperty(item, this.ConfigEntity);

                Type   typePropriete = item.PropertyType;
                string NomPropriete  = item.Name;

                #region Read :String Field
                if (typePropriete.Name == "String")
                {
                    string value = "";
                    if (this.AutoGenerateField)
                    {
                        BaseField baseField = this.FindGenerateField(item.Name);
                        value = baseField.Value.ToString();
                    }
                    else
                    {
                        TextBox txtBox = (TextBox)this.FindPersonelField(item.Name, "TextBox");
                        value = txtBox.Text;
                    }
                    typeEntity.GetProperty(NomPropriete).SetValue(entity, value);
                }
                #endregion

                #region Read : Int32 Field
                if (item.PropertyType.Name == "Int32")
                {
                    int Nombre = 0;
                    if (this.AutoGenerateField)
                    {
                        BaseField baseField = this.FindGenerateField(item.Name);
                        Nombre = Convert.ToInt32(baseField.Value);
                    }
                    else
                    {
                        TextBox txtBox = (TextBox)this.FindPersonelField(item.Name, "TextBox");
                        if (!int.TryParse(txtBox.Text, out Nombre))
                        {
                            MessageBox.Show("Impossible de lire un nombre :" + txtBox.Text);
                        }
                    }
                    typeEntity.GetProperty(NomPropriete).SetValue(entity, Nombre);
                }
                #endregion

                #region Read : DateTime Field
                if (typePropriete.Name == "DateTime")
                {
                    DateTime date = DateTime.MinValue;
                    if (this.AutoGenerateField)
                    {
                        BaseField baseField = this.FindGenerateField(item.Name);
                        date = Convert.ToDateTime(baseField.Value);
                    }
                    else
                    {
                        DateTimePicker dateTimePicker = (DateTimePicker)this.FindPersonelField(item.Name, "TextBox");
                        date = dateTimePicker.Value;
                    }
                    typeEntity.GetProperty(NomPropriete).SetValue(entity, date);
                }
                #endregion

                #region Read : ManyToOne Field
                if (attributesOfProperty.Relationship?.Relation == RelationshipAttribute.Relations.ManyToOne)
                {
                    Int64 id;
                    if (this.AutoGenerateField)
                    {
                        BaseField baseField = this.FindGenerateField(item.Name);
                        id = Convert.ToInt64(baseField.Value);
                    }
                    else
                    {
                        ComboBox comboBox = (ComboBox)this.FindPersonelField(item.Name, "ComboBox");
                        id = Convert.ToInt64(comboBox.SelectedValue);
                    }
                    IBaseRepository ServicesEntity  = this.Service.CreateInstance_Of_Service_From_TypeEntity(item.PropertyType);
                    BaseEntity      ManyToOneEntity = ServicesEntity.GetBaseEntityByID(Convert.ToInt32(id));
                    typeEntity.GetProperty(NomPropriete).SetValue(entity, ManyToOneEntity);
                }
                #endregion

                #region  Read : ManyToMany
                if (attributesOfProperty.Relationship?.Relation == RelationshipAttribute.Relations.ManyToMany)
                {
                    List <BaseEntity> ls = null;
                    if (this.AutoGenerateField)
                    {
                        ManyToManyField manyToManyField = null;
                        if (attributesOfProperty.EntryForm?.TabPage == true)
                        {
                            Control[] recherche = this.tabControlForm.Controls.Find(item.Name, true);
                            if (recherche.Count() > 0)
                            {
                                manyToManyField = (ManyToManyField)recherche.First();
                            }
                            else
                            {
                                throw new FieldNotExistInFormException();
                            }
                        }
                        else
                        {
                            Control[] recherche = this.ConteneurFormulaire.Controls.Find(item.Name, true);
                            if (recherche.Count() > 0)
                            {
                                manyToManyField = (ManyToManyField)recherche.First();
                            }
                            else
                            {
                                throw new FieldNotExistInFormException();
                            }
                        }

                        ls = manyToManyField.Value as List <BaseEntity>;
                    }
                    else
                    {
                        ListBox comboBox = (ListBox)this.FindPersonelField(item.Name, "ListBox");
                        ls = comboBox.Items.Cast <BaseEntity>().ToList <BaseEntity>();
                    }


                    IBaseRepository ServicesEntity = this.Service.CreateInstance_Of_Service_From_TypeEntity(item.PropertyType.GetGenericArguments()[0], this.Service.Context());


                    Type  TypeListeObjetValeur = typeof(List <>).MakeGenericType(item.PropertyType.GetGenericArguments()[0]);
                    IList ls_valeur            = (IList)Activator.CreateInstance(TypeListeObjetValeur);



                    foreach (BaseEntity b in ls)
                    {
                        var entity_valeur = ServicesEntity.GetBaseEntityByID(b.Id);
                        ls_valeur.Add(entity_valeur);
                    }


                    typeEntity.GetProperty(NomPropriete).SetValue(entity, ls_valeur);
                }
                #endregion
            }
        }