コード例 #1
0
        protected bool ValidateExit(bool ItemExit)
        {
            ControllerAskExitResult enabledResults = ControllerAskExitResult.None;

            if (ItemExit)
            {
                if (DataAvail.Utils.EnumFlags.IsContain(State, ControllerStates.CanAcceptChanges))
                    enabledResults |= ControllerAskExitResult.Save;

                if (DataAvail.Utils.EnumFlags.IsContain(State, ControllerStates.CanRejectChanges))
                    enabledResults |= ControllerAskExitResult.Reject;

                if (DataAvail.Utils.EnumFlags.IsContain(State, ControllerStates.CanEndEdit))
                {
                    enabledResults |= ControllerAskExitResult.EndEdit;
                }
                else if (DataAvail.Utils.EnumFlags.IsContain(State, ControllerStates.CanAcceptChanges) && TableContext.IsCanSaveInCache)
                {
                    enabledResults |= ControllerAskExitResult.JustExit;
                }

                if (DataAvail.Utils.EnumFlags.IsContain(State, ControllerStates.CanCancelEdit))
                    enabledResults |= ControllerAskExitResult.CancelEdit;

            }
            else
            {
                if (DataAvail.Utils.EnumFlags.IsContain(State, ControllerStates.CanBatchAcceptChanges))
                    enabledResults |= ControllerAskExitResult.Save;

                if (DataAvail.Utils.EnumFlags.IsContain(State, ControllerStates.CanBatchRejectChanges))
                    enabledResults |= ControllerAskExitResult.Reject;
            }

            if (enabledResults == ControllerAskExitResult.None)
            {
                return true;
            }
            else
            {
                enabledResults |= ControllerAskExitResult.CancelExit;
            }

            ControllerAskExitEventArgs args = new ControllerAskExitEventArgs(enabledResults);

            OnAskExit(args);

            if (ItemExit)
            {
                switch (args.result)
                {
                    case ControllerAskExitResult.Save:
                        return Commands.Execute(ControllerCommandTypes.AcceptChanges);
                    case ControllerAskExitResult.Reject:
                        return Commands.Execute(ControllerCommandTypes.RejectChanges);
                    case ControllerAskExitResult.EndEdit:
                        return Commands.Execute(ControllerCommandTypes.EndEdit);
                    case ControllerAskExitResult.CancelEdit:
                        return Commands.Execute(ControllerCommandTypes.CancelEdit);
                    case ControllerAskExitResult.JustExit:
                        return true;
                    case ControllerAskExitResult.CancelExit:
                        return false;
                }
            }
            else
            {
                switch (args.result)
                {
                    case ControllerAskExitResult.Save:
                        return Commands.Execute(ControllerCommandTypes.BatchAcceptChanges);
                    case ControllerAskExitResult.Reject:
                        return Commands.Execute(ControllerCommandTypes.BatchRejectChanges);
                    case ControllerAskExitResult.JustExit:
                        return true;
                    case ControllerAskExitResult.CancelExit:
                        return false;
                }
            }

            return true;
        }
コード例 #2
0
 private void OnAskExit(ControllerAskExitEventArgs args)
 {
     if (AskExit != null)
         AskExit(this, args);
 }