Ejemplo n.º 1
0
        ///<summary>Surrond with Try/Catch. Error messages will be thrown to caller.</summary>
        public static bool IsGlobalDateLock(Permissions perm, DateTime date, bool isSilent = false, long codeNum = 0, double procFee = -1, long sheetDefNum = 0)
        {
            if (!(new[] {
                Permissions.AdjustmentCreate
                , Permissions.AdjustmentEdit
                , Permissions.PaymentCreate
                , Permissions.PaymentEdit
                , Permissions.ProcComplCreate
                , Permissions.ProcComplEdit
                , Permissions.ProcExistingEdit
                //,Permissions.ProcComplEditLimited
                //,Permissions.ImageDelete
                , Permissions.InsPayCreate
                , Permissions.InsPayEdit
                //,Permissions.InsWriteOffEdit//per Nathan 7/5/2016 this should not be affected by the global date lock
                , Permissions.SheetEdit
                , Permissions.SheetDelete
                , Permissions.CommlogEdit
                //,Permissions.ClaimDelete //per Nathan 01/18/2018 this should not be affected by the global date lock
                , Permissions.PayPlanEdit
                //,Permissions.ClaimHistoryEdit //per Nathan & Mark 03/01/2018 this should not be affected by the global lock date, not financial data.
            }).Contains(perm))
            {
                return(false);               //permission being checked is not affected by global lock date.
            }
            if (date.Year == 1)
            {
                return(false);               //Invalid or MinDate passed in.
            }
            if (!PrefC.GetBool(PrefName.SecurityLockIncludesAdmin) && GroupPermissions.HasPermission(Security.CurUser, Permissions.SecurityAdmin, 0))
            {
                return(false);               //admins are never affected by global date limitation when preference is false.
            }
            if (perm.In(Permissions.ProcComplCreate, Permissions.ProcComplEdit, Permissions.ProcExistingEdit) &&
                ProcedureCodes.CanBypassLockDate(codeNum, procFee))
            {
                return(false);
            }
            if (perm.In(Permissions.SheetEdit, Permissions.SheetDelete) && sheetDefNum > 0 && SheetDefs.CanBypassLockDate(sheetDefNum))
            {
                return(false);
            }
            //If global lock is Date based.
            if (date <= PrefC.GetDate(PrefName.SecurityLockDate))
            {
                if (!isSilent)
                {
                    MessageBox.Show(Lans.g("Security", "Locked by Administrator before ") + PrefC.GetDate(PrefName.SecurityLockDate).ToShortDateString());
                }
                return(true);
            }
            //If global lock is days based.
            int lockDays = PrefC.GetInt(PrefName.SecurityLockDays);

            if (lockDays > 0 && date <= DateTime.Today.AddDays(-lockDays))
            {
                if (!isSilent)
                {
                    MessageBox.Show(Lans.g("Security", "Locked by Administrator before ") + lockDays.ToString() + " days.");
                }
                return(true);
            }
            return(false);
        }