/// <summary>
        /// Ajouter une gestion ManyToOne à l'interface
        /// </summary>
        /// <param name="form"></param>
        private void AddManyToOneManager(EntityManagementControl form, PropertyInfo item, BaseEntity obj)
        {
            // Annotation de l'propriété
            AffichageProprieteAttribute affichageProperty = (AffichageProprieteAttribute)item
                                                            .GetCustomAttribute(typeof(AffichageProprieteAttribute), true);


            // Préparation de l'interface s'il n'est pas encors préparer
            if (this.tabControlManagers.Visible == false)
            {
                this.tabControlManagers.Visible  = true;
                this.tabControl_MainManager.Dock = DockStyle.Fill;
                this.tabControlManagers.TabPages["main"].Text = "Gestion des " + obj.GetAffichageClasseAttribute().Majuscule;
                this.tabControlManagers.TabPages["main"].Controls.Add(this.tabControl_MainManager);
                this.tabControlManagers.Dock = DockStyle.Fill;
                this.panelDataGrid.Controls.Add(this.tabControlManagers);
            }

            // Création d'une TabPage dans TabControlManagers
            TabPage TabPageManyToOne = new TabPage();

            TabPageManyToOne.Name = obj + item.Name;
            TabPageManyToOne.Text = affichageProperty.Titre + " : " + obj;

            this.tabControlManagers.TabPages.Add(TabPageManyToOne);

            // Insertion du formulaire
            form.Dock = DockStyle.Fill;
            TabPageManyToOne.Controls.Add(form);
            this.tabControlManagers.SelectedTab = TabPageManyToOne;
        }
        public StringFiled(PropertyInfo propertyInfo, Orientation OrientationFiled, Size SizeLabel, Size SizeControl) : base(propertyInfo, OrientationFiled, SizeLabel, SizeControl)
        {
            InitializeComponent();

            AffichageProprieteAttribute AffichagePropriete = (AffichageProprieteAttribute)propertyInfo.GetCustomAttribute(typeof(AffichageProprieteAttribute));

            this.AffichagePropriete = AffichagePropriete;

            InitSizeStringFiled();
        }
        /// <summary>
        /// Initialisation de l'entity par les critère de recherche selection dans le filtre
        /// </summary>
        protected void InitialisationEntityParCritereRechercheFiltre()
        {
            // ? this.Entity.GetType();
            Type typeEntity = this.Service.TypeEntity;


            foreach (PropertyInfo item in ListeChampsFormulaire())
            {
                // Configuration de la propriété
                AffichageProprieteAttribute AffichagePropriete = (AffichageProprieteAttribute)item.GetCustomAttribute(typeof(AffichageProprieteAttribute));


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

                // Continue si une valeur de cette propriété existe dans le filtre
                if (!this.CritereRechercheFiltre.ContainsKey(item.Name))
                {
                    continue;
                }


                if (item.PropertyType.Name == "String")
                {
                    typeEntity
                    .GetProperty(item.Name)
                    .SetValue(this.Entity, this.CritereRechercheFiltre[item.Name].ToString());
                }
                if (typePropriete.Name == "Int32")
                {
                    typeEntity
                    .GetProperty(item.Name)
                    .SetValue(this.Entity, Convert.ToInt32(this.CritereRechercheFiltre[item.Name]));
                }

                if (typePropriete.Name == "DateTime")
                {
                    typeEntity
                    .GetProperty(item.Name)
                    .SetValue(this.Entity, Convert.ToDateTime(this.CritereRechercheFiltre[item.Name]));
                }


                if (AffichagePropriete.Relation == "ManyToOne")
                {
                    BaseEntity valeur_filtre = this.Service
                                               .CreateInstance_Of_Service_From_TypeEntity(item.PropertyType)
                                               .GetBaseEntityByID(Convert.ToInt64(this.CritereRechercheFiltre[item.Name]));
                    typeEntity.GetProperty(NomPropriete).SetValue(this.Entity, valeur_filtre);
                }
            }
        }
        /// <summary>
        /// Affiher l'entité dans le formulaire avec
        /// les valeurs initiaux de l'objet
        /// et les initiaux de filtre avec la priéorité pour le filtre
        /// </summary>
        public virtual void WriteEntityToField(Dictionary <string, object> CritereRechercheFiltre)
        {
            // début de la phase d'initialisation, pour ne pas lancer les evénement
            // de changement des valeurs des contôle
            isStepInitializingValues = true;

            BaseEntity entity     = this.Entity;
            Type       typeEntity = this.Service.TypeEntity;

            foreach (PropertyInfo item in ListeChampsFormulaire())
            {
                AffichageProprieteAttribute AffichagePropriete = (AffichageProprieteAttribute)item.GetCustomAttribute(typeof(AffichageProprieteAttribute));
                Type   typePropriete = item.PropertyType;
                string NomPropriete  = item.Name;

                switch (typePropriete.Name)
                {
                case "String":
                {
                    string valeur = (string)typeEntity.GetProperty(NomPropriete).GetValue(entity);
                    if (CritereRechercheFiltre != null && CritereRechercheFiltre.ContainsKey(item.Name))
                    {
                        valeur = CritereRechercheFiltre[item.Name].ToString();
                    }
                    if (this.AutoGenerateField)
                    {
                        BaseField baseField = this.FindGenerateField(item.Name);
                        baseField.Value = valeur;
                    }
                    else
                    {
                        TextBox txtBox = (TextBox)this.FindPersonelField(item.Name, "TextBox");
                        txtBox.Text = valeur;
                    }
                }
                break;

                case "Int32":
                {
                    int valeur = (int)typeEntity.GetProperty(NomPropriete).GetValue(entity);
                    if (CritereRechercheFiltre != null && CritereRechercheFiltre.ContainsKey(item.Name))
                    {
                        valeur = Convert.ToInt32(CritereRechercheFiltre[item.Name]);
                    }

                    if (this.AutoGenerateField)
                    {
                        BaseField baseField = this.FindGenerateField(item.Name);
                        baseField.Value = valeur;
                    }
                    else
                    {
                        TextBox txtBox = (TextBox)this.FindPersonelField(item.Name, "TextBox");
                        txtBox.Text = valeur.ToString();
                    }
                }
                break;

                case "DateTime":
                {
                    DateTime valeur = (DateTime)typeEntity.GetProperty(NomPropriete).GetValue(entity);
                    if (CritereRechercheFiltre != null && CritereRechercheFiltre.ContainsKey(item.Name))
                    {
                        valeur = Convert.ToDateTime(CritereRechercheFiltre[item.Name]);
                    }



                    if (this.AutoGenerateField)
                    {
                        BaseField baseField = this.FindGenerateField(item.Name);
                        baseField.Value = valeur;
                    }
                    else
                    {
                        DateTimePicker dateTimePicker = (DateTimePicker)this.FindPersonelField(item.Name, "DateTimePicker");
                        dateTimePicker.Value = valeur;
                    }
                }
                break;

                default:
                    if (AffichagePropriete.Relation == "ManyToOne")
                    {
                        BaseEntity valeur = (BaseEntity)typeEntity.GetProperty(NomPropriete).GetValue(entity);
                        if (valeur == null)
                        {
                            continue;
                        }
                        Int64 valeur_id = valeur.Id;
                        // La valeur Iniale de filtre
                        if (CritereRechercheFiltre != null && CritereRechercheFiltre.ContainsKey(item.Name))
                        {
                            valeur_id = Convert.ToInt64(CritereRechercheFiltre[item.Name]);
                        }

                        if (this.AutoGenerateField)
                        {
                            BaseField baseField = this.FindGenerateField(item.Name);
                            baseField.Value = valeur_id;
                        }
                        else
                        {
                            ComboBox comboBox = (ComboBox)this.FindPersonelField(item.Name, "ComboBox");
                            comboBox.CreateControl();
                            if (valeur.Id != 0)
                            {
                                comboBox.SelectedValue = valeur.Id;
                            }
                        }
                    }
                    break;
                }
            }

            // Fin de la phase d'initialisaiton
            this.isStepInitializingValues = false;
        }
        /// <summary>
        /// Insertion des colonne selon les annotation : AffichageProprieteAttribute
        /// </summary>
        private void InitDataGridView()
        {
            InitPropertyListDataGrid();

            int index_colonne = 0;
            AffichageDansFormGestionAttribute AffichageDansFormGestion = this.Service.getAffichageDansFormGestionAttribute();

            foreach (PropertyInfo propertyInfo in this.ListePropriete)
            {
                if (propertyInfo.Name == "Ordre" && !AffichageDansFormGestion.siAffichageAvecOrdre)
                {
                    continue;
                }

                // Trouver l'objet AffichagePropriete depuis l'annotation
                Attribute getAffichagePropriete = propertyInfo.GetCustomAttribute(typeof(AffichageProprieteAttribute));
                if (getAffichagePropriete == null)
                {
                    continue;
                }
                AffichageProprieteAttribute AffichagePropriete = (AffichageProprieteAttribute)getAffichagePropriete;

                // Insertion des la colonne selon le tupe de la propriété
                DataGridViewColumn colonne = new DataGridViewTextBoxColumn();;
                index_colonne++;

                switch (propertyInfo.PropertyType.Name)
                {
                case "String":
                {
                    colonne.ValueType        = typeof(String);
                    colonne.DataPropertyName = propertyInfo.Name;
                }
                break;

                case "Integer":
                {
                    colonne.ValueType        = typeof(String);
                    colonne.DataPropertyName = propertyInfo.Name;
                }
                break;

                case "DateTime":
                {
                    colonne                  = new DataGridViewTextBoxColumn();
                    colonne.ValueType        = typeof(DateTime);
                    colonne.DataPropertyName = propertyInfo.Name;
                }
                break;

                case "List`1":
                {
                    DataGridViewButtonColumn c = new DataGridViewButtonColumn();
                    c.UseColumnTextForButtonValue = true;
                    c.Text           = propertyInfo.Name;
                    colonne          = c;
                    colonne.ReadOnly = true;
                }
                break;

                default:
                {
                    colonne.DataPropertyName = propertyInfo.Name;
                }
                break;
                }


                colonne.HeaderText = AffichagePropriete.Titre;

                colonne.Name     = propertyInfo.Name;
                colonne.ReadOnly = true;
                if (AffichagePropriete.WidthColonne != 0)
                {
                    colonne.Width = AffichagePropriete.WidthColonne;
                }
                this.dataGridView.Columns.Insert(index_colonne, colonne);
            }
        }
        /// <summary>
        /// Création et Initalisation des contrôles du formulaire
        /// </summary>
        private void GenerateForm()
        {
            #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;

            // Affichage des champs par leurs type
            foreach (PropertyInfo item in ListeChampsFormulaire())
            {
                #region Recalcule des valeurs pardéfaut selon l'annotation de chauqe champs
                // l'annotation
                AffichageProprieteAttribute AffichagePropriete = (AffichageProprieteAttribute)item.GetCustomAttribute(typeof(AffichageProprieteAttribute));

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

                // Orientation
                Orientation orientation_config = orientation;
                if (AffichagePropriete.UseOrientationField)
                {
                    orientation_config = AffichagePropriete.OrientationField;
                }
                #endregion

                Control field_control = null;
                switch (item.PropertyType.Name)
                {
                    #region Champs String
                case "String":


                    StringFiled stringFiled = new StringFiled(
                        item,
                        orientation_config,
                        new Size(width_label, height_label),
                        new Size(width_control_config, height_control));
                    stringFiled.Location      = new System.Drawing.Point(x_field, y_field);
                    stringFiled.Name          = item.Name;
                    stringFiled.TabIndex      = ++TabIndex;
                    stringFiled.Text_Label    = AffichagePropriete.Titre;
                    stringFiled.FieldChanged += ControlPropriete_ValueChanged;
                    if (AffichagePropriete.isOblegatoir)
                    {
                        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));
                    int32Filed.Location      = new System.Drawing.Point(x_field, y_field);
                    int32Filed.Name          = item.Name;
                    int32Filed.TabIndex      = ++TabIndex;
                    int32Filed.Text_Label    = AffichagePropriete.Titre;
                    int32Filed.FieldChanged += ControlPropriete_ValueChanged;
                    if (AffichagePropriete.isOblegatoir)
                    {
                        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));
                    dateTimeField.Location      = new System.Drawing.Point(x_field, y_field);
                    dateTimeField.Name          = item.Name;
                    dateTimeField.TabIndex      = ++TabIndex;
                    dateTimeField.Text_Label    = AffichagePropriete.Titre;
                    dateTimeField.FieldChanged += ControlPropriete_ValueChanged;
                    if (AffichagePropriete.isOblegatoir)
                    {
                        dateTimeField.ValidatingFiled += DateTimePicker_Validating;
                    }
                    // Insertion à l'interface
                    this.ConteneurFormulaire.Controls.Add(dateTimeField);
                    field_control = dateTimeField;
                    break;
                    #endregion

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

                        // Création de champs ManyToOneField
                        Int64 InitValue = 0;
                        //if (ValeursFiltre != null && ValeursFiltre.Keys.Contains(propertyInfo.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
                                                                           );
                        manyToOneField.Location      = new System.Drawing.Point(x_field, y_field);
                        manyToOneField.Name          = item.Name;
                        manyToOneField.TabIndex      = ++TabIndex;
                        manyToOneField.Text_Label    = AffichagePropriete.Titre;
                        manyToOneField.FieldChanged += ControlPropriete_ValueChanged;
                        if (AffichagePropriete.isOblegatoir)
                        {
                            manyToOneField.Validating += ComboBox_Validating;
                        }
                        this.ConteneurFormulaire.Controls.Add(manyToOneField);
                        field_control = manyToOneField;
                    }
                    #endregion

                    #region Champs ManyToMany
                    if (AffichagePropriete.Relation == "ManyToMany")
                    {
                        //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();
                            }
                        }

                        InputCollectionControle InputCollectionControle = new InputCollectionControle(this.Service, item, ls_default_value, this.Entity);
                        InputCollectionControle.Name          = item.Name;
                        InputCollectionControle.ValueChanged += ControlPropriete_ValueChanged;

                        if (AffichagePropriete.TabPage)
                        {
                            InputCollectionControle.Dock = DockStyle.Fill;
                            TabPage tabPage = new TabPage();
                            tabPage.Name = "tabPage" + item.Name;
                            tabPage.Text = AffichagePropriete.Titre;
                            tabPage.Controls.Add(InputCollectionControle);
                            tabControlForm.TabPages.Add(tabPage);
                        }
                        else
                        {
                            this.ConteneurFormulaire.Controls.Add(InputCollectionControle);
                            field_control = InputCollectionControle;
                        }
                    }
                    #endregion
                }
                break;
                } // Fin de suitch

                // Insertion du Champs dans sa GroupeBox si il existe
                // [Bug] il n'est pas supprimé de l'inrface, car il est déja ajouté
                if (field_control != null && AffichagePropriete.GroupeBox != null && AffichagePropriete.GroupeBox != string.Empty)
                {
                    GroupesBoxMainContainers[AffichagePropriete.GroupeBox].Controls.Add(field_control);
                }
            }// 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)));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Lire les informations du formulaire vers l'Entity
        /// </summary>
        protected virtual void ReadFormToEntity()
        {
            BaseEntity entity     = this.Entity;
            Type       typeEntity = this.Service.TypeEntity;

            foreach (PropertyInfo item in ListeChampsFormulaire())
            {
                AffichageProprieteAttribute AffichagePropriete = (AffichageProprieteAttribute)item.GetCustomAttribute(typeof(AffichageProprieteAttribute));
                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 (AffichagePropriete.Relation == "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 (AffichagePropriete.Relation == "ManyToMany")
                {
                    List <BaseEntity> ls = null;
                    if (this.AutoGenerateField)
                    {
                        InputCollectionControle inputCollectionControle = null;
                        if (AffichagePropriete.TabPage)
                        {
                            Control[] recherche = this.tabControlForm.Controls.Find(item.Name, true);
                            if (recherche.Count() > 0)
                            {
                                inputCollectionControle = (InputCollectionControle)recherche.First();
                            }
                            else
                            {
                                throw new FieldNotExistInFormException();
                            }
                        }
                        else
                        {
                            Control[] recherche = this.ConteneurFormulaire.Controls.Find(item.Name, true);
                            if (recherche.Count() > 0)
                            {
                                inputCollectionControle = (InputCollectionControle)recherche.First();
                            }
                            else
                            {
                                throw new FieldNotExistInFormException();
                            }
                        }

                        ls = inputCollectionControle.Value;
                    }
                    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
            }
        }
        /// <summary>
        /// Obtient les valeurs du filtre
        /// </summary>
        /// <returns></returns>
        public Dictionary <string, object> CritereRechercheFiltre()
        {
            // Application de filtre
            Dictionary <string, object> RechercheInfos = new Dictionary <string, object>();

            foreach (PropertyInfo propertyInfo in PropertyListFilter())
            {
                // Trouver l'objet AffichagePropriete depuis l'annotation avec Filtre = True
                Attribute getAffichagePropriete = propertyInfo.GetCustomAttribute(typeof(AffichageProprieteAttribute));
                if (getAffichagePropriete == null)
                {
                    continue;
                }
                AffichageProprieteAttribute AffichagePropriete = (AffichageProprieteAttribute)getAffichagePropriete;
                if (AffichagePropriete.Filtre == false)
                {
                    continue;
                }


                switch (propertyInfo.PropertyType.Name)
                {
                case "String":
                {
                    StringFiled stringFiled = (StringFiled)this.groupBoxFiltrage.Controls.Find(propertyInfo.Name, true).First();
                    if (stringFiled.Value != String.Empty)
                    {
                        RechercheInfos[propertyInfo.Name] = stringFiled.Value;
                    }
                }
                break;

                case "Int32":
                {
                    Int32Filed int32Filed = (Int32Filed)this.groupBoxFiltrage.Controls.Find(propertyInfo.Name, true).First();
                    if ((int)int32Filed.Value != 0)
                    {
                        RechercheInfos[propertyInfo.Name] = int32Filed.Value;
                    }
                }
                break;

                case "DateTime":
                {
                    DateTimeField dateTimeField = (DateTimeField)this.groupBoxFiltrage.Controls.Find(propertyInfo.Name, true).First();
                    if ((DateTime)dateTimeField.Value != DateTime.MinValue)
                    {
                        RechercheInfos[propertyInfo.Name] = dateTimeField.Value;
                    }
                }
                break;

                default:     // Dans le cas d'un objet de type BaseEntity
                {
                    // [bug] groupBoxFiltrage doit être MainContainner
                    ManyToOneField ComboBoxEntity = (ManyToOneField)this.groupBoxFiltrage.Controls.Find(propertyInfo.Name, true).First();
                    BaseEntity     obj            = (BaseEntity)ComboBoxEntity.SelectedItem;
                    if (obj != null && Convert.ToInt32(obj.Id) != 0)
                    {
                        RechercheInfos[propertyInfo.Name] = obj.Id;
                    }
                }
                break;
                }
            }

            return(RechercheInfos);
        }
        /// <summary>
        /// Initialisation de filtre
        /// </summary>
        protected void initFiltre()
        {
            // Postion et Taille par défaut
            int width_label    = 50;
            int height_label   = 20;
            int width_control  = 50;
            int height_control = 20;
            int TabIndex       = 0;

            // Insertion des critère de recherche par Type
            foreach (PropertyInfo propertyInfo in PropertyListFilter())
            {
                // Trouver l'objet AffichagePropriete depuis l'annotation
                Attribute getAffichagePropriete = propertyInfo.GetCustomAttribute(typeof(AffichageProprieteAttribute));
                if (getAffichagePropriete == null)
                {
                    continue;
                }
                AffichageProprieteAttribute AffichagePropriete = (AffichageProprieteAttribute)getAffichagePropriete;
                if (AffichagePropriete.Filtre == false)
                {
                    continue;
                }

                // Utiliser le Largeur de la configuration s'il existe
                int item_width_control = width_control;
                if (AffichagePropriete.WidthColonne != 0)
                {
                    item_width_control = AffichagePropriete.WidthColonne;
                }

                if (propertyInfo.PropertyType.Name == "String")
                {
                    StringFiled stringFiled = new StringFiled(propertyInfo,
                                                              Orientation.Horizontal,
                                                              new Size(width_label, height_label),
                                                              new Size(item_width_control, height_control));
                    stringFiled.Name          = propertyInfo.Name;
                    stringFiled.TabIndex      = TabIndex++;
                    stringFiled.Text_Label    = AffichagePropriete.Titre;
                    stringFiled.FieldChanged += Filtre_TextBox_SelectedValueChanged;
                    MainContainer.Controls.Add(stringFiled);
                }
                if (propertyInfo.PropertyType.Name == "Int32")
                {
                    Int32Filed int32Filed = new Int32Filed(propertyInfo,
                                                           Orientation.Vertical,
                                                           new Size(width_label, height_label),
                                                           new Size(item_width_control, height_control)
                                                           );
                    int32Filed.Name          = propertyInfo.Name;
                    int32Filed.TabIndex      = TabIndex++;
                    int32Filed.Text_Label    = AffichagePropriete.Titre;
                    int32Filed.FieldChanged += Filtre_TextBox_SelectedValueChanged;
                    MainContainer.Controls.Add(int32Filed);
                }
                if (propertyInfo.PropertyType.Name == "DateTime")
                {
                    DateTimeField dateTimeField = new DateTimeField(propertyInfo, Orientation.Vertical,
                                                                    new Size(width_label, height_label),
                                                                    new Size(item_width_control, height_control)
                                                                    );
                    dateTimeField.Name       = propertyInfo.Name;
                    dateTimeField.TabIndex   = TabIndex++;
                    dateTimeField.Text_Label = AffichagePropriete.Titre;


                    dateTimeField.FieldChanged += Filtre_TextBox_SelectedValueChanged;
                    MainContainer.Controls.Add(dateTimeField);
                }

                //
                // Relation ManyToOne
                //
                if (AffichagePropriete.Relation != String.Empty &&
                    AffichagePropriete.Relation == AffichageProprieteAttribute.RELATION_MANYTOONE)
                {
                    // La valeurs pardéfaut
                    Int64 default_value = 0;
                    if (ValeursFiltre != null && ValeursFiltre.Keys.Contains(propertyInfo.Name))
                    {
                        default_value = (Int64)ValeursFiltre[propertyInfo.Name];
                    }

                    ManyToOneField manyToOneField = new ManyToOneField(this.Service, propertyInfo,
                                                                       this.MainContainer,
                                                                       Orientation.Horizontal,
                                                                       new Size(width_label, height_label),
                                                                       new Size(item_width_control, height_control),
                                                                       default_value
                                                                       );
                    manyToOneField.Name          = propertyInfo.Name;
                    manyToOneField.TabIndex      = TabIndex++;
                    manyToOneField.Text_Label    = AffichagePropriete.Titre;
                    manyToOneField.FieldChanged += Filtre_ComboBox_SelectedValueChanged;
                    MainContainer.Controls.Add(manyToOneField);


                    //
                    // Remplissage de ComboBox
                    //
                    //Type ServicesEntityEnRelationType = typeof(BaseRepository<>).MakeGenericType(propertyInfo.PropertyType);
                    //IBaseRepository ServicesEntity = (IBaseRepository)Activator.CreateInstance(ServicesEntityEnRelationType);
                    //List<object> ls = ServicesEntity.GetAllDetached();
                    //manyToOneField.ValueMember = "Id";
                    //manyToOneField.DisplayMember = AffichagePropriete.DisplayMember;
                    //manyToOneField.DataSource = ls;
                    //if (AffichagePropriete.isValeurFiltreVide) manyToOneField.SelectedIndex = -1;

                    //// Affectation de valeur initial
                    //if (this.ValeursFiltre != null && this.ValeursFiltre.ContainsKey(propertyInfo.Name))
                    //{
                    //    manyToOneField.CreateControl();
                    //    manyToOneField.Value = Convert.ToInt64(this.ValeursFiltre[propertyInfo.Name]);
                    //}
                }



                //if (MainContainer.Controls.Count > 0)
                //{
                //    int max_h = this.MainContainer.Controls.Cast<Control>().Max(c => c.Size.Height);
                //    this.MainContainer.Size = new Size(this.MainContainer.Size.Width, max_h);
                //}
            } // End For
        }
Exemplo n.º 10
0
        /// <summary>
        /// Affichage du filtre dans l'interface
        /// Remplissage de ListeComboBox
        /// </summary>
        private void InitAndLoadData()
        {
            this.DisplayMember = "";
            this.ValueMember   = "Id";


            if (this.PropertyInfo != null)
            {
                // DisplayMember de combobox actuel
                // Annotation : Affichage de l'objet

                AffichageClasseAttribute MetaAffichageClasse = BaseEntity.GetAffichageClasseAttribute(PropertyInfo.PropertyType);

                this.DisplayMember = MetaAffichageClasse.DisplayMember;
                this.Text_Label    = MetaAffichageClasse.Minuscule;

                Attribute getAffichagePropriete = PropertyInfo.GetCustomAttribute(typeof(AffichageProprieteAttribute));
                AffichageProprieteAttribute AffichagePropriete = (AffichageProprieteAttribute)getAffichagePropriete;

                #region Annotatin
                // Annotation : Critère de filtre
                Attribute metaSelectionCriteriaAttribute = this.PropertyInfo.PropertyType
                                                           .GetCustomAttribute(typeof(SelectionCriteriaAttribute));


                if (metaSelectionCriteriaAttribute != null)
                {
                    SelectionCriteriaAttribute MetaSelectionCriteria =
                        (SelectionCriteriaAttribute)metaSelectionCriteriaAttribute;

                    #endregion


                    int index = 10;

                    // Si un objet du critère de selection exite dans la classe
                    // Nous cherchons sa valeur pour l'utiliser
                    foreach (Type item in MetaSelectionCriteria.Criteria)
                    {
                        // Meta information d'affichage du de Critère
                        AffichageClasseAttribute MetaAffichageClasseCritere = (AffichageClasseAttribute)item.GetCustomAttribute(typeof(AffichageClasseAttribute));


                        ManyToOneField manyToOneFilter = new ManyToOneField(this.Service, item, null, null,
                                                                            this.orientationFiled,
                                                                            this.SizeLabel,
                                                                            this.SizeControl, 0
                                                                            );
                        manyToOneFilter.Name = item.Name;
                        //manyToOneFilter.Size = new System.Drawing.Size(this.widthField, this.HeightField);

                        manyToOneFilter.TabIndex   = ++index;
                        manyToOneFilter.Text_Label = item.Name;

                        manyToOneFilter.ValueMember   = "Id";
                        manyToOneFilter.DisplayMember = MetaAffichageClasseCritere.DisplayMember;
                        // pour le chargement de comboBox Suivant
                        manyToOneFilter.FieldChanged += Value_SelectedIndexChanged;

                        manyToOneFilter.Visible = true;

                        // [bug] Le contôle ne s'affiche pas dans le formilaire ??
                        //Form f = new Form();
                        //f.Controls.Add(manyToOneFilter);
                        //f.Show();

                        this.MainContainner.Controls.Add(manyToOneFilter);

                        ListeComboBox.Add(item.Name, manyToOneFilter);
                        LsiteTypeObjetCritere.Add(item.Name, item);
                    }
                }

                // Insertion du ComBox Actuel pour qu'il sera remplit par les données
                ListeComboBox.Add(this.PropertyInfo.PropertyType.Name, this);
                LsiteTypeObjetCritere.Add(this.PropertyInfo.PropertyType.Name, this.PropertyInfo.PropertyType);
            }
            else
            {
                // Cas des sous ComBobox de filtre

                // Insertion du ComBox Actuel pour qu'il sera remplit par les données
                ListeComboBox.Add(this.TypeOfObject.Name, this);
                LsiteTypeObjetCritere.Add(this.TypeOfObject.Name, this.TypeOfObject);
            }
            this.FieldChanged += Value_SelectedIndexChanged;
        }