Ejemplo n.º 1
0
        private void BtnSauvCat_Click(object sender, EventArgs e)
        {
            Categorie c = new Categorie
            {
                Libelle = txtLibelleAdd.Text.Trim()
            };

            if (kCkbCategorieParentAjout.Checked)
            {
                c.CategorieParent = Categorie.Charge((int)cbCategorieParent.SelectedValue);
            }
            else
            {
                c.CategorieParent = new Categorie();
            }

            Categorie.Sauve(c);
            ChargeCombo();
            txtLibelleAdd.Text = string.Empty;
        }
Ejemplo n.º 2
0
        public static Categorie GetCategorie(string catL, string scatL)
        {
            if (string.IsNullOrEmpty(catL))
            {
                catL = "Aucune";
            }
            Categorie retour = Categorie.ChargeParNom(catL);

            if (retour.Id == 0)
            {
                // Création de la categorie elle n'existe pas
                retour.Libelle         = catL;
                retour.CategorieParent = new Categorie();

                Categorie.Sauve(retour);
                retour = Categorie.ChargeParNom(catL);
            }

            // Exist-il une sous catégorie dans le fichier BP
            if (!string.IsNullOrEmpty(scatL))
            {
                bool             found = false;
                List <Categorie> lscat = Categorie.ChargeCategorieDeParent(retour);
                foreach (Categorie tempscat in lscat)
                {
                    // Est-ce qu'une sous catgorie OB est égale à une sous catégorie BP
                    if (tempscat.Libelle == scatL)
                    {
                        found = true;
                        // on effecte la sous categorie trouvée à l'operation
                        retour = tempscat;
                        break;
                    }
                }

                if (!found)
                {
                    // On n'a pas trouvé la sous catégorie, on doit la créer
                    Categorie scat = new Categorie
                    {
                        Libelle         = scatL,
                        CategorieParent = Categorie.Charge(retour.Id)
                    };
                    Categorie.Sauve(scat);

                    lscat = Categorie.ChargeCategorieDeParent(retour);
                    foreach (Categorie tempscat in lscat)
                    {
                        // Est-ce qu'une sous catgorie OB est égale à une sous catégorie BP
                        if (tempscat.Libelle == scatL)
                        {
                            // on effecte la sous categorie trouvée à l'operation
                            retour = tempscat;
                            break;
                        }
                    }
                }
            }
            else // La sous catégorie BP est vide, on prend donc la catégorie BP comme catégorie OB
            {
                retour = Categorie.ChargeParNom(catL);
            }
            return(retour);
        }