Example #1
0
        /// <summary>
        /// Affectation des valeurs par défaut
        /// </summary>
        protected void SetDefaullValues()
        {
            for (int i = 0; i < ListeComboBox.Count; i++)
            {
                ComboBox comboBox = ListeComboBox.Values.ElementAt(i);
                string   key      = ListeComboBox.Keys.ElementAt(i);
                // Valeur par défaut
                if (ListeValeursCritere.ContainsKey(key) && ListeValeursCritere[key].Id != 0)
                {
                    comboBox.CreateControl();
                    comboBox.SelectedValue = ListeValeursCritere[key].Id;


                    // Actualisation de ComboBoxs suivant
                    IGwinBaseBLO EntityPereService = this.Service
                                                     .CreateServiceBLOInstanceByTypeEntity(LsiteTypeObjetCritere[key]);
                    BaseEntity EntityPere = EntityPereService.GetBaseEntityByID(ListeValeursCritere[key].Id);


                    ComboBox comboBox_suivant = ListeComboBox.Values.ElementAt(i + 1);
                    string   key_suivant      = ListeComboBox.Keys.ElementAt(i + 1);


                    PropertyInfo PropertyFils = EntityPere.GetType()
                                                .GetProperties()
                                                .Where(p => p.Name == key_suivant + "s")
                                                .SingleOrDefault();
                    if (PropertyFils == null)
                    {
                        throw new PropertyDoesNotExistException("La classe " + EntityPere.GetType().Name + " ne contient pas la propriété " + key_suivant + "s");
                    }
                    comboBox_suivant.DataSource = PropertyFils.GetValue(EntityPere);
                }
            }
        }
        public override object ConvertValue(BaseFieldTraitementParam param)
        {
            List <BaseEntity> ls = null;

            ls = param.BaseField.Value as List <BaseEntity>;


            IGwinBaseBLO ServicesEntity = param.EntityBLO
                                          .CreateServiceBLOInstanceByTypeEntityAndContext(
                param.ConfigProperty.PropertyInfo.PropertyType.GetGenericArguments()[0],
                param.EntityBLO.Context
                );


            Type TypeListeObjetValeur = typeof(List <>).MakeGenericType(
                param.ConfigProperty.PropertyInfo.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);
            }

            return(ls_valeur);
        }
Example #3
0
        public override object ConvertValue(BaseFieldTraitementParam param)
        {
            IGwinBaseBLO ServicesEntity = param
                                          .EntityBLO
                                          .CreateServiceBLOInstanceByTypeEntity(param.ConfigProperty.PropertyInfo.PropertyType);

            BaseEntity ManyToOneEntity = ServicesEntity.GetBaseEntityByID(Convert.ToInt64(param.BaseField.Value));

            return(ManyToOneEntity);
        }
Example #4
0
        /// <summary>
        ///  Calcule des valeurs initiaux
        /// </summary>
        private void CalculeValeursInitiaux(Int64 Value)
        {
            if (Value == 0)
            {
                return;
            }


            /// Le ComboBox précédent prend les valeurs de l'Entite actuel de comboBox
            /// car l'entité actuel doit avoir une prorpiété de type type  de l'entityé précédent
            /// Le nom de cette propiété égale Nom d'entité
            /// si cette propiété n'existe pas la méthode lance une exception
            ///

            // Initialisation de la liste des valeurs par défaux
            if (ListeValeursInitiaux.Count() < this.LsiteTypeObjetCritere.Count())
            {
                for (int i = 0; i < this.LsiteTypeObjetCritere.Count(); i++)
                {
                    ListeValeursInitiaux.Add(ListeComboBox.Keys.ElementAt(i), 0);
                }
            }
            // Init la de la vlaeur de comboBox Actuel
            if (ListeValeursInitiaux.Count > 0)
            {
                ListeValeursInitiaux[ListeValeursInitiaux.Last().Key] = Value;
            }

            IGwinBaseBLO curentService = this.Service
                                         .CreateServiceBLOInstanceByTypeEntity(LsiteTypeObjetCritere[ListeValeursInitiaux.Last().Key]);
            BaseEntity curentEntity = curentService.GetBaseEntityByID(Value);

            BaseEntity previousEntity = null;

            for (int i = this.LsiteTypeObjetCritere.Count() - 1; i >= 1; i--)
            {
                string curentKey   = LsiteTypeObjetCritere.Keys.ElementAt(i);
                string Previouskey = ListeComboBox.Keys.ElementAt(i - 1);

                PropertyInfo PropertyPrevious = curentEntity.GetType()
                                                .GetProperties()
                                                .Where(p => p.Name == Previouskey)
                                                .SingleOrDefault();
                if (PropertyPrevious == null)
                {
                    throw new PropertyNotExistInEntityException();
                }

                // Affectation des valeurs au ComboBox précédent
                previousEntity = PropertyPrevious.GetValue(curentEntity) as BaseEntity;
                ListeValeursInitiaux[Previouskey] = previousEntity.Id;

                curentEntity = previousEntity;
            }
        }
        /// <summary>
        /// Chargement des comboBox suivants
        /// il s'exécute aprés le changement du valeur de chaque comboBox
        /// à chaque changement d'un comboBox on charge les données de comboBox suivant
        /// </summary>
        private void Value_SelectedIndexChanged(object sender, EventArgs e)
        {
            // if the selected comboBox is Blank
            bool isBlank = false;

            // n'exécuter pas cette événement, si nous somme à l'étape d'initialisation
            // des chmpas de critères
            if (this.StopEventSelectedIndexChange)
            {
                return;
            }


            // Initialisation de ComboBox, Service, Entite qui a ête changé
            ManyToOneField comboBoxChanged = (ManyToOneField)sender;

            // if Blank Value dont do anything
            if (Convert.ToInt64(comboBoxChanged.SelectedValue) == 0)
            {
                isBlank = true;
            }


            comboBoxChanged.CreateControl();
            int          indexComboBoxChanged  = ListeComboBox.Values.ToList <ManyToOneField>().IndexOf(comboBoxChanged);
            string       keyComboBoxCanged     = ListeComboBox.Keys.ElementAt(indexComboBoxChanged);
            IGwinBaseBLO serviceComboBoxActuel = this.Service
                                                 .CreateServiceBLOInstanceByTypeEntity(Criterias[keyComboBoxCanged]);
            BaseEntity EntiteActuel = serviceComboBoxActuel.GetBaseEntityByID(Convert.ToInt64(comboBoxChanged.SelectedValue));

            /// Actualisation de ComboBox suivant s'il existe
            /// Le ComboBox suivant prend les valeurs de l'Entite actuel de comboBox
            /// car l'entité actuel doit avoir une prorpiété de type type Collection de l'entityé suivant
            /// Le nom de cette propiété égale Nom d'entité suivant + "s"
            /// si cette propiété n'existe pas la méthode lance une exception
            if (comboBoxChanged.SelectedValue != null && (ListeComboBox.Values.Count() - 1) >= (indexComboBoxChanged + 1))
            {
                // [Update] chargement des données par des requête Linq au lieux d'utiliser
                // les membres Virtuel

                // ComboBox suivant
                ManyToOneField nextComboBox = ListeComboBox.Values.ElementAt(indexComboBoxChanged + 1);

                string keyNexComboBox = ListeComboBox.Keys.ElementAt(indexComboBoxChanged + 1);

                PropertyInfo PropertyContenantValeursComboSuivant = null;
                if (!isBlank)
                {
                    PropertyContenantValeursComboSuivant = EntiteActuel.GetType()
                                                           .GetProperties()
                                                           .Where(p => p.Name == keyNexComboBox + "s")
                                                           .SingleOrDefault();
                    if (PropertyContenantValeursComboSuivant == null)
                    {
                        throw new PropertyNotExistInEntityException(keyNexComboBox + "s");
                    }
                }
                else
                {
                    nextComboBox.DataSource = null;
                }
                // Affectation des valeurs au ComboBox suivant
                IList ls_source = null;
                if (PropertyContenantValeursComboSuivant != null)
                {
                    ls_source = PropertyContenantValeursComboSuivant.GetValue(EntiteActuel) as IList;


                    // Initalisation avec la valeur par défaux s'il existe
                    if (this.FilterPreviesValues != null && this.FilterPreviesValues.Keys.Contains(keyNexComboBox))
                    {
                        this.StopEventSelectedIndexChange = true;
                        nextComboBox.DataSource           = null;
                        nextComboBox.DataSource           = ls_source;
                        this.StopEventSelectedIndexChange = false;
                        nextComboBox.SelectedValue        = this.FilterPreviesValues[keyNexComboBox];
                    }
                    else
                    {
                        nextComboBox.DataSource = ls_source;
                    }
                }


                // Si ce Combo n'a pas d'information alors vider les combBobx suivant
                if (ls_source == null || ls_source.Count == 0)
                {
                    for (int i = (indexComboBoxChanged + 1); i < ListeComboBox.Values.Count(); i++)
                    {
                        ManyToOneField comboBox_suivant2 = ListeComboBox.Values.ElementAt(i);
                        comboBox_suivant2.DataSource   = null;
                        comboBox_suivant2.TextCombobox = "";
                    }
                }
            }
        }
Example #6
0
        /// <summary>
        /// SelectedIndexChanged qui Actualise de tous les comboBoxs déscendantes
        /// </summary>
        private void Value_SelectedIndexChanged(object sender, EventArgs e)
        {
            // à chaque changement d'un combo on charge les donnée de comboBox suivant
            ComboBox comboBox = (ComboBox)sender;

            comboBox.CreateControl();
            int index_comboBox = ListeComboBox.Values.ToList <ComboBox>().IndexOf(comboBox);

            // Le Service de l'objet de ComboBox
            string       key     = ListeComboBox.Keys.ElementAt(index_comboBox);
            IGwinBaseBLO service = this.Service
                                   .CreateServiceBLOInstanceByTypeEntity(LsiteTypeObjetCritere[key]);

            // Actualisation de ComboBox suivant s'il existe, et le comboBox actual a une valeur
            if (comboBox.SelectedValue != null && (ListeComboBox.Values.Count() - 1) >= (index_comboBox + 1))
            {
                //
                // Actualisation de combobBox suivant
                //
                ComboBox comboBox_suivant = ListeComboBox.Values.ElementAt(index_comboBox + 1);
                string   key_suivant      = ListeComboBox.Keys.ElementAt(index_comboBox + 1);

                BaseEntity   EntityPere    = service.GetBaseEntityByID(Convert.ToInt64(comboBox.SelectedValue));
                PropertyInfo PropertyChild = EntityPere.GetType()
                                             .GetProperties()
                                             .Where(p => p.Name == key_suivant + "s")

                                             .SingleOrDefault();
                IList ls_source = null;
                if (PropertyChild != null)
                {
                    ls_source = PropertyChild.GetValue(EntityPere) as IList;
                    comboBox_suivant.DataSource = ls_source;
                }
                // Si ce Combo n'a pas d'information
                // alors vider les combBobx suivant
                if (ls_source == null || ls_source.Count == 0)
                {
                    for (int i = (index_comboBox + 1); i < ListeComboBox.Values.Count(); i++)
                    {
                        ComboBox comboBox_suivant2 = ListeComboBox.Values.ElementAt(i);
                        comboBox_suivant2.DataSource = null;
                        comboBox_suivant2.Text       = "";
                    }
                }
            }

            // si le Dernier ComboBox on actualise la ListeBox
            if ((ListeComboBox.Values.Count() - 1) == index_comboBox)
            {
                if (comboBox.SelectedValue != null)
                {
                    BaseEntity   EntityPere    = service.GetBaseEntityByID(Convert.ToInt64(comboBox.SelectedValue));
                    PropertyInfo PropertyChild = EntityPere.GetType()
                                                 .GetProperties()
                                                 .Where(p => p.Name == PropertyInfoOfCollection.PropertyType.GetGenericArguments()[0].Name + "s")
                                                 .SingleOrDefault();

                    if (PropertyChild == null)
                    {
                        throw new PropertyDoesNotExistException("La classe " + EntityPere.GetType().Name + " ne contient pas la propriété " + PropertyInfoOfCollection.PropertyType.GetGenericArguments()[0].Name + "s");
                    }
                    {
                        listBoxChoices.DataSource = null;
                        listBoxChoices.DataSource = PropertyChild.GetValue(EntityPere);
                        listBoxChoices.SelectedItems.Clear();
                    }
                }
                else
                {
                    listBoxChoices.DataSource = null;
                }
            }
        }