Пример #1
0
        private void AfficheElement(IObjetHierarchiqueACodeHierarchique objet)
        {
            //Type typeForm = CFormFinder.GetTypeFormToEdit(objet.GetType());
            //if (typeForm == null || !typeForm.IsSubclassOf(typeof(CFormEditionStandard)))
            //    return;
            //CFormEditionStandard form = (CFormEditionStandard)Activator.CreateInstance(typeForm, new object[] { objet });
            //CTimosApp.Navigateur.AffichePage(form);
            CReferenceTypeForm refTypeForm = CFormFinder.GetRefFormToEdit(objet.GetType());

            if (refTypeForm != null)
            {
                CFormEditionStandard form = refTypeForm.GetForm((CObjetDonneeAIdNumeriqueAuto)objet) as CFormEditionStandard;
                if (form != null)
                {
                    CSc2iWin32DataNavigation.Navigateur.AffichePage(form);
                }
            }
        }
        //-------------------------------------------------------------------
        private static void AlloueCode(IObjetHierarchiqueACodeHierarchique objet, ref int nLastCodeAlloue)
        {
            if (nLastCodeAlloue == 0 && m_dicLastCodeForType.ContainsKey(objet.GetType()))
            {
                nLastCodeAlloue = m_dicLastCodeForType[objet.GetType()];
            }
            string strCle = "";

            if (nLastCodeAlloue > 0 && objet.ObjetParent == null)
            {
                //Teste la valeur suivante
                int nTmp = nLastCodeAlloue + 1;
                strCle = GetCle(nTmp, objet.NbCarsParNiveau);
                CListeObjetsDonnees lstExt = new CListeObjetsDonnees(objet.ContexteDonnee,
                                                                     objet.GetType(),
                                                                     new CFiltreData(objet.ChampIdParent + " is null and " +
                                                                                     objet.ChampCodeSystemePartiel + "=@1", strCle));
                if (lstExt.CountNoLoad == 0)
                {
                    nLastCodeAlloue = nTmp;
                    objet.ChangeCodePartiel(strCle);
                    m_dicLastCodeForType[objet.GetType()] = nLastCodeAlloue;
                    return;
                }
            }
            CFiltreData filtre = null;

            if (objet.ObjetParent != null)
            {
                filtre = new CFiltreData(objet.ChampIdParent + "=@1",
                                         objet.ObjetParent.Id);
            }
            else
            {
                filtre = new CFiltreData(objet.ChampIdParent + " is null and " +
                                         objet.ChampCodeSystemePartiel + ">@1", GetCle(nLastCodeAlloue, objet.NbCarsParNiveau));
            }

            CListeObjetsDonnees listeSoeurs = new CListeObjetsDonnees(objet.ContexteDonnee, objet.GetType(), filtre);

            listeSoeurs.PreserveChanges = true;
            listeSoeurs.AssureLectureFaite();

            listeSoeurs.InterditLectureInDB = true;

            Hashtable tableCodesUtilises = new Hashtable();

            foreach (IObjetHierarchiqueACodeHierarchique obj in listeSoeurs)
            {
                tableCodesUtilises[obj.CodeSystemePartiel] = true;
            }

            //Cherche le prochain numéro libre
            int nCpt = nLastCodeAlloue;

            strCle = "";
            do
            {
                nCpt++;
                strCle = GetCle(nCpt, objet.NbCarsParNiveau);

                /*listeSoeurs.Filtre = new CFiltreData(objet.ChampCodeSystemePartiel + "=@1",
                 *      strCle);*/
            }while (tableCodesUtilises.ContainsKey(strCle));
            nLastCodeAlloue = nCpt;
            objet.ChangeCodePartiel(strCle);
            m_dicLastCodeForType[objet.GetType()] = nLastCodeAlloue;
        }