Beispiel #1
0
        public void UpdateActualSum(DateTime dateMonday, int sum_of_hours)
        {
            BufferHourAvailable entity = this[dateMonday];

            int prevBuffer = GetPrevAvailableBuffer(dateMonday);

            if (entity == null)
            {
                return;
            }

            if (!entity.IsExistsEstimate)
            {
                LoadEstimateSum(entity);
            }

            if (sum_of_hours != entity.SumFromRecording)
            {
                entity.SumFromRecording = sum_of_hours;
                if (entity.Update(prevBuffer, BufferHoursPerWeek))
                {
                    UpdateBufferHoursSumFrom(entity);
                }
                _DoUpdateEntity(entity);
            }
        }
Beispiel #2
0
        private void UpdateBufferHoursSumFrom(BufferHourAvailable prevEntity)
        {
            Debug.Assert(prevEntity != null);


            if (BufferHours == null || BufferHours.Value == 0)
            {
                return;
            }

            // if last week in year - return
            if (prevEntity.WeekNumber == NumberOfWeekInYear)
            {
                return;
            }



            DateTime            date   = prevEntity.WeekBegin.AddDays(7);
            BufferHourAvailable entity = this[date];

            if (entity == null)
            {
                return;
            }

            if (entity.Update(prevEntity.AvailableBufferHour, BufferHoursPerWeek))
            {
                _DoUpdateEntity(entity);
                UpdateBufferHoursSumFrom(entity);
            }
        }
Beispiel #3
0
        internal void CheckAndBuildAllYearEntity()
        {
            if (Count == NumberOfWeekInYear)
            {
                return;
            }

            DateTime date            = dateBeginYear;
            byte     week            = 1;
            int      availablebuffer = 0;

            while (date < dateEndYear)
            {
                if (!_diction.ContainsKey(date))
                {
                    availablebuffer += BufferHoursPerWeek;

                    BufferHourAvailable entity = new BufferHourAvailable();
                    entity.StoreWorldID        = StoreWorld.ID;
                    entity.WeekBegin           = date;
                    entity.WeekEnd             = DateTimeHelper.GetSunday(date);//entity.WeekBegin.AddDays(6);
                    entity.WeekNumber          = week;
                    entity.Year                = (short)_year;
                    entity.SumFromPlanning     = null;
                    entity.SumFromRecording    = null;
                    entity.AvailableBufferHour = availablebuffer;

                    _DoUpdateEntity(entity);
                    AddEntityToList(entity);
                }
                week += 1;
                date  = DateTimeHelper.GetNextMonday(date);//date.AddDays(7);
            }
        }
Beispiel #4
0
        private int GetPrevAvailableBuffer(DateTime date)
        {
            Debug.Assert(date.DayOfWeek == DayOfWeek.Monday);

            DateTime            prevWeekMonday = date.AddDays(-7);
            BufferHourAvailable entity         = this[prevWeekMonday];

            return((entity != null) ? (int)entity.AvailableBufferHour : 0);
        }
Beispiel #5
0
 public BufferHourAvailable this[DateTime date]
 {
     get
     {
         BufferHourAvailable entity = null;
         _diction.TryGetValue(date, out entity);
         return(entity);
     }
 }
Beispiel #6
0
 protected virtual void _DoUpdateEntity(BufferHourAvailable entity)
 {
     if (!IgnoreSave)
     {
         //if (entity.IsNew)
         //    Service.Save(entity);
         //else
         //    Service.Update(entity);
         Service.SaveOrUpdate2(entity);
     }
 }
Beispiel #7
0
        private int LoadEstimateSum(BufferHourAvailable entity)
        {
            EstimatedWorldHoursBuilder2 b = new EstimatedWorldHoursBuilder2();

            int value = b.Build(StoreWorld, entity.WeekBegin, entity.WeekEnd);

            if (entity.SumActualBVEstimated != value)
            {
                entity.SumActualBVEstimated = value;
                _DoUpdateEntity(entity);
            }

            return(value);
        }
Beispiel #8
0
        internal void AddEntityToList(BufferHourAvailable entity)
        {
            if (_diction.ContainsKey(entity.WeekBegin))
            {
                _DoDeleteEntity(entity);
                return;
            }

            if (_bufferhoursList == null)
            {
                _bufferhoursList = new List <BufferHourAvailable>();
            }
            _bufferhoursList.Add(entity);
            _diction[entity.WeekBegin] = entity;
        }
Beispiel #9
0
        public void RecalculateYear()
        {
            if (_bufferhoursList != null)
            {
                _bufferhoursList.Sort(new ComparerAvailableBufferHours());

                int[] planned_sums = (ServerEnvironment.StoreToWorldService as StoreToWorldService).GetWorldWorkingHoursForYearAsWeeksSum(StoreWorld.ID, Year, true);
                int[] actual_sums  = (ServerEnvironment.StoreToWorldService as StoreToWorldService).GetWorldWorkingHoursForYearAsWeeksSum(StoreWorld.ID, Year, false);
                YearlyEstimatedWorldHoursBuilder estimateLoader = new YearlyEstimatedWorldHoursBuilder();
                int[] estimate_sums = estimateLoader.BuildYear(StoreWorld, Year);

                if (planned_sums != null && actual_sums != null && estimate_sums != null &&
                    planned_sums.Length == actual_sums.Length &&
                    planned_sums.Length == estimate_sums.Length &&
                    planned_sums.Length == NumberOfWeekInYear &&
                    _bufferhoursList.Count == planned_sums.Length &&
                    _bufferhoursList.Count == NumberOfWeekInYear)
                {
                    BufferHourAvailable buffer = null;

                    for (int i = 0; i < NumberOfWeekInYear; i++)
                    {
                        buffer = _bufferhoursList[i];
                        if (buffer.IsExistsEstimate)
                        {
                            buffer.SumActualBVEstimated = estimate_sums[i];
                        }
                        if (buffer.IsExistsPlanning)
                        {
                            buffer.SumFromPlanning = planned_sums[i];
                        }
                        if (buffer.IsExistsRecording)
                        {
                            buffer.SumFromRecording = actual_sums[i];
                        }
                    }
                }

                Update();
            }
        }
Beispiel #10
0
        public void UpdateEstimation()
        {
            if (_bufferhoursList != null)
            {
                //EstimatedWorldHoursBuilder estimateBuilder = new EstimatedWorldHoursBuilder();

                _bufferhoursList.Sort(new ComparerAvailableBufferHours());
                //double prev_buffer = 0;
                //foreach (BufferHourAvailable entity in _bufferhoursList)
                //{
                //    if (entity.IsExistsEstimate)
                //    {
                //        entity.SumActualBVEstimated = estimateBuilder.Build(StoreWorld, entity.WeekBegin, entity.WeekEnd);
                //    }
                //}

                YearlyEstimatedWorldHoursBuilder estimateLoader = new YearlyEstimatedWorldHoursBuilder();
                int[] sums = estimateLoader.BuildYear(StoreWorld, Year);

                int iCount = Math.Min(_bufferhoursList.Count, sums.Length);
                if (sums.Length != _bufferhoursList.Count)
                {
                    Debug.Assert(false);
                }

                BufferHourAvailable buffer = null;
                for (int i = 0; i < iCount; i++)
                {
                    buffer = _bufferhoursList[i];
                    if (buffer.IsExistsEstimate)
                    {
                        buffer.SumActualBVEstimated = sums[i];// estimateBuilder.Build(StoreWorld, entity.WeekBegin, entity.WeekEnd);
                    }
                }
            }
        }
Beispiel #11
0
        public int GetPrevAvailableBufferForWeek(DateTime date)
        {
            Debug.Assert(date.DayOfWeek == DayOfWeek.Monday);

            int prevBuffer = 0;

            if (dateBeginYear < date)// can't look on previous year
            {
                DateTime prevWeekMonday = date.AddDays(-7);

                BufferHourAvailable entity = Service.GetBufferHoursAvailable(StoreWorld.ID, prevWeekMonday);
                if (entity != null)
                {
                    prevBuffer = (int)entity.AvailableBufferHour;
                }
                else
                {
                    CheckAndBuildAllYearEntity();
                    prevBuffer = GetPrevAvailableBuffer(date);
                }
            }

            return(prevBuffer);
        }
Beispiel #12
0
 protected virtual void _DoDeleteEntity(BufferHourAvailable entity)
 {
     Service.Delete(entity);
 }