public FormWayBillDaily(MainDGV dgv)
        {
            InitializeComponent();

            list     = new List <Car>();
            fuelList = FuelList.getInstance();

            foreach (DataGridViewCell cell in dgv.SelectedCells)
            {
                string     fio = dgv.GetFIO(cell.RowIndex);
                DriverList dl  = DriverList.getInstance();
                driverCurrent = dl.getItemByFullFIO(fio);

                int     idCar   = dgv.GetCarID(cell.RowIndex);
                CarList carList = CarList.getInstance();
                Car     car     = carList.getItem(idCar);
                list.Add(car);

                lbCars.Items.Add(car);
            }

            btnNext.Enabled = list.Count > 1;

            index = 0;

            lbCar.Text = "Выбранный автомобиль: " + list[index].ToString();
        }
Beispiel #2
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;
                }
            }
        }