Esempio n. 1
0
        protected virtual void INReplenishmentSeason_RowInserting(PXCache sender, PXRowInsertingEventArgs e)
        {
            INReplenishmentSeason row = (INReplenishmentSeason)e.Row;

            if (row.StartDate != null && row.EndDate != null && !ValidateOverlap(sender, row))
            {
                sender.RaiseExceptionHandling <INReplenishmentSeason.endDate>(row, row.EndDate, new PXSetPropertyException(Messages.PeriodsOverlap));
                e.Cancel = true;
            }
        }
Esempio n. 2
0
 protected virtual bool ValidateOverlap(PXCache sender, INReplenishmentSeason row)
 {
     foreach (INReplenishmentSeason season in this.Seasons.Select())
     {
         if (season.SeasonID == row.SeasonID || row.StartDate > season.EndDate || row.EndDate < season.StartDate)
         {
             continue;
         }
         return(false);
     }
     return(true);
 }
Esempio n. 3
0
        protected virtual void INReplenishmentSeason_RowUpdating(PXCache sender, PXRowUpdatingEventArgs e)
        {
            INReplenishmentSeason row     = (INReplenishmentSeason)e.NewRow;
            INReplenishmentSeason old_row = (INReplenishmentSeason)e.Row;

            if (row.StartDate != null && row.EndDate != null &&
                (!sender.ObjectsEqual <INReplenishmentSeason.startDate>(row, old_row) ||
                 !sender.ObjectsEqual <INReplenishmentSeason.endDate>(row, old_row)) &&
                !ValidateOverlap(sender, row))
            {
                if (!sender.ObjectsEqual <INReplenishmentSeason.startDate>(row, old_row))
                {
                    sender.RaiseExceptionHandling <INReplenishmentSeason.startDate>(row, row.StartDate, new PXSetPropertyException(Messages.PeriodsOverlap));
                }

                if (!sender.ObjectsEqual <INReplenishmentSeason.endDate>(row, old_row))
                {
                    sender.RaiseExceptionHandling <INReplenishmentSeason.endDate>(row, row.EndDate, new PXSetPropertyException(Messages.PeriodsOverlap));
                }
                e.Cancel = true;
            }
        }
Esempio n. 4
0
        protected virtual bool CheckSeasonOverlaps(PXCache cache, INReplenishmentSeason season)
        {
            foreach (INReplenishmentSeason otherSeason in this.Seasons.Select())
            {
                bool overlaps = false;

                if (otherSeason.SeasonID == season.SeasonID)
                {
                    continue;
                }

                if (IsDateInSeason(season.StartDate, otherSeason))
                {
                    overlaps = true;
                    cache.RaiseExceptionHandling <INReplenishmentSeason.startDate>(season, season.StartDate, new PXSetPropertyException(Messages.PeriodsOverlap));
                }

                if (IsDateInSeason(season.EndDate, otherSeason))
                {
                    overlaps = true;
                    cache.RaiseExceptionHandling <INReplenishmentSeason.endDate>(season, season.EndDate, new PXSetPropertyException(Messages.PeriodsOverlap));
                }

                if (IsDateInSeason(otherSeason.StartDate, season))
                {
                    overlaps = true;
                    cache.RaiseExceptionHandling <INReplenishmentSeason.startDate>(season, season.StartDate, new PXSetPropertyException(Messages.PeriodsOverlap));
                    cache.RaiseExceptionHandling <INReplenishmentSeason.endDate>(season, season.EndDate, new PXSetPropertyException(Messages.PeriodsOverlap));
                }

                if (overlaps)
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 5
0
 public static bool IsDateInSeason(DateTime?date, INReplenishmentSeason season)
 {
     return(season.StartDate <= date && date <= season.EndDate);
 }
Esempio n. 6
0
        protected virtual void INReplenishmentSeason_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            INReplenishmentSeason row = (INReplenishmentSeason)e.Row;

            CheckSeasonOverlaps(sender, row);
        }