//-------------------------------------------------------------
 private void UnReadonlyControl(Control ctrl)
 {
     if (ctrl != null)
     {
         ctrl.EnabledChanged -= m_OnEnabledChanged;
         IControlALockEdition lockable = ctrl as IControlALockEdition;
         if (lockable != null)
         {
             lockable.OnChangeLockEdition -= m_OnLockEditionChanged;
             bool bLock = false;
             m_dicControlToLockEditionParCode.TryGetValue(lockable, out bLock);
             m_bIsStoringLockEdition = true;
             lockable.LockEdition    = bLock;
             m_bIsStoringLockEdition = false;
         }
         else
         {
             bool bEnabled = true;
             m_dicControlToEnableParCode.TryGetValue(ctrl, out bEnabled);
             m_bIsStoringEnable = true;
             ctrl.Enabled       = bEnabled;
             m_bIsStoringEnable = false;
         }
     }
     if (ctrl != null)
     {
         m_setReadOnlyParRestrictions.Remove(ctrl);
     }
 }
 //-------------------------------------------------------------------
 private void ReadOnlyControl(Control ctrl)
 {
     if (ctrl != null && !ctrl.IsDisposed)
     {
         ctrl.EnabledChanged -= m_OnEnabledChanged;
         ctrl.EnabledChanged += m_OnEnabledChanged;
         m_listeAbonnesAuxEvenements.Add(ctrl);
         IControlALockEdition lockable = ctrl as IControlALockEdition;
         if (lockable != null)
         {
             lockable.OnChangeLockEdition -= m_OnLockEditionChanged;
             lockable.OnChangeLockEdition += m_OnLockEditionChanged;
             m_bIsStoringLockEdition       = true;
             lockable.LockEdition          = true;
             m_bIsStoringLockEdition       = false;
         }
         else
         {
             m_bIsStoringEnable = true;
             ctrl.Enabled       = false;
             m_bIsStoringEnable = false;
         }
     }
     m_setReadOnlyParRestrictions.Add(ctrl);
 }
 private static void AjouterControleLockEditionChangedNonAutorise(IControlALockEdition ctrl)
 {
     if (!m_controlesLockEditionChangedNonAutorise.Contains(ctrl))
     {
         ctrl.OnChangeLockEdition += m_handlerLockEditionChangedNonAutorise;
         m_controlesLockEditionChangedNonAutorise.Add(ctrl);
     }
 }
 private static void ctrl_LockEditionChangedNonAutorise(object sender, EventArgs e)
 {
     if (typeof(IControlALockEdition).IsAssignableFrom(sender.GetType()))
     {
         IControlALockEdition ctrlALock = (IControlALockEdition)sender;
         if (!ctrlALock.LockEdition)
         {
             ctrlALock.LockEdition = true;
         }
     }
 }
        //-------------------------------------------------------------------
        private void PrivateStockeEtatDemandé(Control ctrl)
        {
            m_dicControlToEnableParCode[ctrl] = ctrl.Enabled;
            IControlALockEdition lockable = ctrl as IControlALockEdition;

            if (lockable != null)
            {
                m_dicControlToLockEditionParCode[lockable] = lockable.LockEdition;
            }
            foreach (Control child in ctrl.Controls)
            {
                PrivateStockeEtatDemandé(child);
            }
        }
        private void OnLockEditionChanged(object sender, EventArgs args)
        {
            if (m_bIsStoringLockEdition)
            {
                return;
            }
            m_bIsStoringLockEdition = true;
            IControlALockEdition ctrl = sender as IControlALockEdition;

            if (ctrl != null)
            {
                m_dicControlToLockEditionParCode[ctrl] = ctrl.LockEdition;
                if (!ctrl.LockEdition && m_setReadOnlyParRestrictions.Contains((Control)ctrl))
                {
                    ctrl.LockEdition = true;
                }
            }
            m_bIsStoringLockEdition = false;
        }
 //-------------------------------------------------------------------
 public void Clean()
 {
     foreach (Control ctrl in m_listeAbonnesAuxEvenements)
     {
         try
         {
             ctrl.EnabledChanged -= m_OnEnabledChanged;
             IControlALockEdition lockable = ctrl as IControlALockEdition;
             if (lockable != null)
             {
                 lockable.OnChangeLockEdition -= m_OnLockEditionChanged;
             }
         }
         catch { }
     }
     m_listeAbonnesAuxEvenements.Clear();
     m_dicControlToEnableParCode.Clear();
     m_dicControlToLockEditionParCode.Clear();
     m_setReadOnlyParRestrictions.Clear();
 }
        private void UpdateVisuel()
        {
            if (m_bIsUpdatingVisuel || ItemLigne == null)
            {
                return;
            }
            try
            {
                m_bIsUpdatingVisuel = true;
                CEquipement    equipement        = ItemLigne.LigneLivraison == null ? null : ItemLigne.LigneLivraison.Equipement;
                List <Control> controlesActifs   = new List <Control>();
                List <Control> controlesInactifs = new List <Control>();
                //Checkbox. La checkbox est active si la ligne de livraison
                //est nouvelle;
                m_chkEstRecue.Checked = ItemLigne.IsChecked;
                if (ItemLigne.LigneLivraison == null || ItemLigne.LigneLivraison.IsNew())
                {
                    controlesActifs.Add(m_chkEstRecue);
                }
                else
                {
                    controlesInactifs.Add(m_chkEstRecue);
                }

                //Sélection du type d'équipement
                //On ne peut sélectionner le type d'équipement que si
                //La ligne n'est pas liée à une ligne de commande
                //et que l'équipement est nouveau
                if (ItemLigne.LigneCommande != null)
                {
                    m_selectTypeEquipement.ElementSelectionne = ItemLigne.LigneCommande.TypeEquipement;
                }
                if (ItemLigne.LigneCommande == null && (ItemLigne.LigneLivraison == null ||
                                                        ItemLigne.LigneLivraison.IsNew()))
                {
                    controlesActifs.Add(m_selectTypeEquipement);
                }
                else
                {
                    controlesInactifs.Add(m_selectTypeEquipement);
                }

                //Sélection de la référence d'équipement
                //La sélection est active uniquement pour les lignes toutes neuves
                if (ItemLigne.LigneLivraison == null || ItemLigne.LigneLivraison.IsNew())
                {
                    controlesActifs.Add(m_txtSelectReference);
                }
                else
                {
                    controlesInactifs.Add(m_txtSelectReference);
                }

                //Equipement contenant
                //Actif si l'équipement n'est pas null, qu'il est nouveau
                //et qu'il a un type
                if (equipement != null &&
                    equipement.IsNew() && equipement.TypeEquipement != null)
                {
                    controlesActifs.Add(m_cmbEquipementConteneur);
                }
                else
                {
                    controlesInactifs.Add(m_cmbEquipementConteneur);
                }
                UpdateControleContainer();

                //Coordonnée : active pour les nouveaux équipements
                //Contenus dans un conteneur qui gère des coordonnées
                if (equipement != null && equipement.IsNew() &&
                    equipement.Emplacement != null)
                {
                    controlesActifs.Add(m_editCoordonnee);
                }
                else
                {
                    controlesInactifs.Add(m_editCoordonnee);
                }
                UpdateControleCoordonnee();



                //Numéro de série : uniquement pour les nouveaux équipements
                if (ItemLigne.LigneLivraison == null || (equipement != null && equipement.IsNew()))
                {
                    controlesActifs.Add(m_txtSerial);
                }
                else
                {
                    controlesInactifs.Add(m_txtSerial);
                }

                foreach (Control ctrl in controlesActifs)
                {
                    m_extModeEdition.SetModeEdition(ctrl, TypeModeEdition.EnableSurEdition);
                    IControlALockEdition ctLock = ctrl as IControlALockEdition;
                    if (ctLock != null)
                    {
                        ctLock.LockEdition = !m_extModeEdition.ModeEdition;
                    }
                    else
                    {
                        ctrl.Enabled = m_extModeEdition.ModeEdition;
                    }
                }
                foreach (Control ctrl in controlesInactifs)
                {
                    m_extModeEdition.SetModeEdition(ctrl, TypeModeEdition.Autonome);
                    IControlALockEdition ctLock = ctrl as IControlALockEdition;
                    if (ctLock != null)
                    {
                        ctLock.LockEdition = true;
                    }
                    else
                    {
                        ctrl.Enabled = false;
                    }
                }
            }
            finally
            {
                m_bIsUpdatingVisuel = false;
            }
        }
        public void AppliquerConfiguration(CConfigModulesTimos configuration)
        {
            if (!DesignMode && configuration != null)
            {
                if (LancementApplication != null)
                {
                    EventArgConfigureControl arg = new EventArgConfigureControl();
                    LancementApplication(arg);
                    if (arg.Cancel)
                    {
                        if (FinApplication != null)
                        {
                            FinApplication(this, new EventArgs());
                        }
                        return;
                    }
                }

                ClearSurveillance();

                foreach (Control ctrl in m_associations.Keys)
                {
                    string association = m_associations[ctrl];
                    if (association == null || association == "")
                    {
                        continue;
                    }

                    #region Recuperation de la restriction a Appliquer
                    ERestriction restriction = ERestriction.Aucune;

                    //Combinaison des restrictions
                    List <string> strIdsModulesApp = CSerializerModulesLicence.GetIdsModulesApp(association);
                    bool          bFind            = strIdsModulesApp.Count == 0;
                    foreach (string strIdApp in strIdsModulesApp)
                    {
                        CLicenceModuleAppPrtct mApp = configuration.GetModuleApp(strIdApp);
                        if (mApp != null)
                        {
                            restriction = restriction | mApp.Restriction;
                            bFind       = true;
                            if (restriction == ERestriction.Hide)
                            {
                                break;
                            }
                        }
                    }

                    if (bFind && restriction != ERestriction.Hide)
                    {
                        List <string> strIdsModulesClient = CSerializerModulesLicence.GetIdsModulesClient(association);
                        bFind = strIdsModulesClient.Count == 0;
                        foreach (string strId in strIdsModulesClient)
                        {
                            CLicenceModuleClientPrtct mCli = configuration.GetModuleClient(strId);
                            if (mCli != null)
                            {
                                restriction = restriction | mCli.Restriction;
                                bFind       = true;
                                if (restriction == ERestriction.Hide)
                                {
                                    break;
                                }
                            }
                        }
                    }

                    if (!bFind)
                    {
                        restriction = ERestriction.Hide;
                    }
                    #endregion

                    if (ApplicationConfiguration != null)
                    {
                        EventArgConfigureControl arg = new EventArgConfigureControl();
                        ApplicationConfiguration(ctrl, restriction, arg);
                        if (arg.Cancel)
                        {
                            return;
                        }
                    }

                    #region Affectation du controle et mise sous surveillance
                    switch (restriction)
                    {
                    case ERestriction.Hide:
                        ctrl.Visible = false;

                        if (ctrl is Crownwood.Magic.Controls.TabPage)
                        {
                            DetacheC2iTabPage((Crownwood.Magic.Controls.TabPage)ctrl);
                            AjouterControleParentChangedNonAutorise(ctrl);
                        }
                        else if (ctrl is TabPage)
                        {
                            TabPage tbp = (TabPage)ctrl;
                            //if (tbp.Parent != null && tbp.Parent is TabControl)
                            //{
                            //    AjouterControleAddedNonAutorise(tbp.Parent);
                            //    tbp.Parent = null;
                            //}
                            tbp.Parent = null;
                            AjouterControleParentChangedNonAutorise(tbp);
                        }
                        AjouterControleVisibleChangedNonAutorise(ctrl);
                        break;

                    case ERestriction.ReadOnly:
                        if (typeof(IControlALockEdition).IsAssignableFrom(ctrl.GetType()))
                        {
                            IControlALockEdition ctrlALock = (IControlALockEdition)ctrl;
                            ctrlALock.LockEdition = true;
                            AjouterControleLockEditionChangedNonAutorise(ctrlALock);
                        }
                        else
                        {
                            ctrl.Enabled = false;
                            AjouterControleEnableChangedNonAutorise(ctrl);
                        }
                        break;

                    case ERestriction.NoCreate:
                        break;

                    case ERestriction.NoDelete:
                        break;

                    case ERestriction.NoCreate | ERestriction.NoDelete:
                    case ERestriction.Aucune:
                    default:
                        break;
                    }
                    #endregion
                }
                if (FinApplication != null)
                {
                    FinApplication(this, new EventArgs());
                }
            }
        }