Exemplo n.º 1
0
 private void AddToList(WayBillDay wayBillDay, int day)
 {
     if ((wayBillDay != null) && (wayBillDay.Distance > 0))
     {
         _list.Add(day, wayBillDay);
     }
 }
Exemplo n.º 2
0
        private WayBillDay CreateWayBillDaily(Driver driver, DateTime date, int everyDayCount, Random random)
        {
            if (_list.ContainsKey(date.Day))
            {
                return(null);
            }

            WayBillDay wayBillDay = new WayBillDay(_car, driver, date, everyDayCount);

            wayBillDay.Save();
            wayBillDay.ReadRoute(random);

            return(wayBillDay);
        }
Exemplo n.º 3
0
        public void Load()
        {
            if (_list.Count > 0)
            {
                return;
            }

            Dictionary <int, Driver> driverWithDay = GetDriversDictionary();

            if (driverWithDay.Count == 0)
            {
                return;
            }

            int count = _mileageList.GetDistance(_car, _date);

            Random random = new Random();

            int workDays = driverWithDay.Count;

            bool isShortMonth = ((count / workDays) < MIN_DAILY_MILEAGE);

            if (isShortMonth)
            {
                workDays /= 2;
            }
            int div = random.Next(1);


            var fuelList = FuelList.getInstance().GetListFiltred(_car, _date);

            foreach (var item in fuelList)
            {
                DateTime date = new DateTime(_date.Year, _date.Month, item.Date.Day);

                int curCount = count - GetDistance();
                if ((workDays - _list.Count) == 0)
                {
                    break;
                }

                int everyDayCount = curCount / (workDays - _list.Count);

                if (driverWithDay.ContainsKey(item.Date.Day))
                {
                    WayBillDay wayBillDay = CreateWayBillDaily(driverWithDay[item.Date.Day], date, everyDayCount, random);
                    AddToList(wayBillDay, item.Date.Day);
                }
                if (curCount < 10)
                {
                    break;
                }
            }

            foreach (var item in driverWithDay)
            {
                DateTime date = new DateTime(_date.Year, _date.Month, item.Key);

                if ((isShortMonth) && (item.Key % 2 == div))
                {
                    continue;
                }

                int curCount = count - GetDistance();
                if ((workDays - _list.Count) == 0)
                {
                    break;
                }

                int everyDayCount = curCount / (workDays - _list.Count);

                WayBillDay wayBillDay = CreateWayBillDaily(item.Value, date, everyDayCount, random);
                AddToList(wayBillDay, item.Key);

                if (curCount < 10)
                {
                    break;
                }
            }
        }