//---------------------------------------------------
        public void InsertBefore(int nIndex)
        {
            if (!CanAddNew())
            {
                return;
            }
            if (nIndex >= m_listeControlsUtiles.Count - 1)
            {
                return;
            }
            CControlePrevisionOperation ctrl = GetControle(nIndex);

            if (ctrl.TypeOperation == null)
            {
                return;
            }
            int nNiveau = ctrl.TypeOperation.Niveau;

            m_panelControles.SuspendDrawing();
            ctrl = GetNewControle(nIndex);
            ctrl.InitControle(null, nIndex, nNiveau, false);
            ReordonneeTout();
            m_panelControles.ResumeDrawing();
            m_panelControles.Visible = false;
            m_panelControles.Visible = true;
            ctrl.Focus();
        }
        public void Init(IElementAOperationPrevisionnelle element)
        {
            Visible = false;
            m_panelControles.SuspendDrawing();
            m_elementEdite = element;
            foreach (Control ctrl in m_listeControlsUtiles)
            {
                ctrl.Visible = false;
                ((CControlePrevisionOperation)ctrl).Operation = null;
            }

            m_listeControlesReserve.AddRange(m_listeControlsUtiles);
            m_listeControlsUtiles.Clear();
            CListeObjetsDonnees liste = m_elementEdite.Operations;

            liste.Filtre = new CFiltreData(COperation.c_champIdOpParente + " is null");
            int nIndex = 0;

            foreach (COperation donnee in liste)
            {
                AddOperation(donnee, ref nIndex, false);
            }
            if (m_listeControlsUtiles.Count == 0 && m_gestionnaireModeEdition.ModeEdition)
            {
                CControlePrevisionOperation ctrl = GetNewControle(0);
                ctrl.InitControle(null, 0, 0, true);
            }
            ReordonneeTout();

            RecalcSize();

            m_panelControles.ResumeDrawing();
            Visible = true;
        }
        //------------------------------------------------------------------------------------
        private void AddOperation(COperation operation, ref int nIndex, bool bRecalcSize)
        {
            bool bEntete = m_panelControles.Controls.Count == 0;
            CControlePrevisionOperation ctrl = GetNewControle(nIndex);

            ctrl.Visible = true;
            ctrl.InitControle(operation, nIndex, operation.TypeOperation.Niveau, bEntete);
            nIndex++;
            foreach (COperation operationFille in operation.OperationsFilles)
            {
                AddOperation(operationFille, ref nIndex, false);
            }
            if (bRecalcSize)
            {
                RecalcSize();
            }
        }
        //---------------------------------------------------
        public void InsertAfter(int nIndex)
        {
            if (!CanAddNew())
            {
                return;
            }
            CControlePrevisionOperation ctrl = GetControle(nIndex);

            if (ctrl.TypeOperation == null)
            {
                return;
            }
            int nNiveau = ctrl.TypeOperation.Niveau;

            m_panelControles.SuspendDrawing();
            ctrl = GetNewControle(nIndex + 1);
            ctrl.InitControle(null, nIndex + 1, nNiveau, false);
            ReordonneeTout();
            m_panelControles.ResumeDrawing();
            m_panelControles.Visible = false;
            m_panelControles.Visible = true;
            ctrl.Focus();
            RecalcSize();
        }
        //---------------------------------------------------
        public bool RemoveDonnee(CControlePrevisionOperation controle)
        {
            CResultAErreur result = CResultAErreur.True;

            if (controle.Operation != null)
            {
                result = controle.Operation.CanDelete();
                if (!result)
                {
                    CFormAlerte.Afficher(result.Erreur);
                    return(false);
                }
            }
            int nNiveau = controle.Niveau;
            int nIndex  = controle.Index;

            CControlePrevisionOperation ctrlSuivant = null;

            if (nIndex + 1 < m_listeControlsUtiles.Count)
            {
                ctrlSuivant = (CControlePrevisionOperation)m_listeControlsUtiles[nIndex + 1];
            }
            while (ctrlSuivant != null && ctrlSuivant.Niveau > nNiveau)
            {
                if (!RemoveDonnee(ctrlSuivant))
                {
                    return(false);
                }
                if (nIndex + 1 < m_listeControlsUtiles.Count)
                {
                    ctrlSuivant = (CControlePrevisionOperation)m_listeControlsUtiles[nIndex + 1];
                }
                else
                {
                    ctrlSuivant = null;
                }
            }
            if (controle.Operation != null)
            {
                result = controle.Operation.Delete();
                if (!result)
                {
                    return(false);
                }
            }

            m_listeControlsUtiles.Remove(controle);
            m_listeControlesReserve.Add(controle);
            nIndex = controle.Index;
            for (int nChange = nIndex; nChange < m_listeControlsUtiles.Count; nChange++)
            {
                ((CControlePrevisionOperation)m_listeControlsUtiles[nChange]).Index = nIndex;
                nIndex++;
            }

            controle.Operation = null;
            controle.Hide();

            //s'il n'y a plus de contrôle, il faut en ajouter 1 !!!
            if (m_listeControlsUtiles.Count == 0 && m_gestionnaireModeEdition.ModeEdition)
            {
                CControlePrevisionOperation ctrl = GetNewControle(0);
                ctrl.InitControle(null, 0, 0, true);
            }
            RecalcSize();

            return(true);
        }