예제 #1
0
        public bool AddReserve(Reserve reserve, int officeIndex)
        {
            var        isFree     = true;
            DataOffice dataOffice = new DataOffice();

            for (int i = 0; i < Reserves.Count; i++)
            {
                var serviceReserve     = dataOffice.Offices[officeIndex].DataServices.Services.First(service => service.Name == Reserves[i].Service);
                var endDateTime        = Reserves[i].WriteTime.AddMinutes(Convert.ToDouble(serviceReserve.Time));
                var reserveEndDateTime = reserve.WriteTime.AddMinutes(Convert.ToDouble(serviceReserve.Time));
                if ((Reserves[i].WriteTime <= reserve.WriteTime && reserve.WriteTime < endDateTime || Reserves[i].WriteTime <= reserveEndDateTime && reserveEndDateTime < endDateTime) && Reserves[i].Address == reserve.Address)
                {
                    isFree = false;
                    continue;
                }
                else
                {
                    continue;
                }
            }
            if (isFree)
            {
                Reserves.Add(reserve);
                Reserves = Reserves.OrderBy(reserved => reserved.WriteTime).ToList <Reserve>();
            }
            ShowReserve();
            return(isFree);
        }
예제 #2
0
        private void GenerateQueue(Random random, int countHuman, DataOffice dataOffice, DataService dataService)
        {
            var dateTime = DateTime.Now;

            ReserveForm.ReservesData.Clear();
            for (int i = 0; i < 6; i++)
            {
                ReserveForm.ReservesData.Add(new ReserveData());
            }
            List <DateTime> writeTimes = new List <DateTime>();

            for (int i = 0; i < 6; i++)
            {
                writeTimes.Add(new DateTime(dateTime.Year, dateTime.Month, dateTime.Day + 1, 8, dateTime.Minute, 0));
            }
            for (uint i = 0; i < countHuman; i++)
            {
                var officeIndex  = random.Next(0, 6);
                var office       = dataOffice.Offices[officeIndex];
                var serviceIndex = random.Next(0, 3);
                var service      = dataService.Services[serviceIndex];
                office.DataServices.Services[serviceIndex].CountHuman++;
                writeTimes[officeIndex] = writeTimes[officeIndex].AddHours(1);
                if (writeTimes[officeIndex].Hour >= 21)
                {
                    writeTimes[officeIndex] = writeTimes[officeIndex].AddHours(21 - writeTimes[officeIndex].Hour + 11);
                }
                ReserveForm.ReservesData[officeIndex].Reserves.Add(new Reserve(office.Address, writeTimes[officeIndex], service.Name));
                var id = random.Next(5);
                Client = new Client(id);
            }
        }
예제 #3
0
        public ReserveForm()
        {
            InitializeComponent();
            DataOffice dataOffice = new DataOffice();

            for (int i = 0; i < dataOffice.Offices.Count; i++)
            {
                AddressComboBox.Items.Add(dataOffice.Offices[i].Address);
            }
            DataService dataService = new DataService();

            for (int i = 0; i < dataService.Services.Count; i++)
            {
                ServiceComboBox.Items.Add(dataService.Services[i].Name);
            }
            AddressComboBox.SelectedIndex = 0;
            HoursComboBox.SelectedIndex   = 0;
            MinutesComboBox.SelectedIndex = 0;
            ServiceComboBox.SelectedIndex = 0;
            var dateTime = DateTime.Now;

            dateTime             = dateTime.AddDays(1);
            DateTimePicker.Value = dateTime;
            dataGridViews        = new List <DataGridView>()
            {
                ReservedTimeGrid0, ReservedTimeGrid1, ReservedTimeGrid2, ReservedTimeGrid3, ReservedTimeGrid4, ReservedTimeGrid5
            };
            for (int i = 0; i < 6; i++)
            {
                GridPull(ReservesData[i].Reserves, dataGridViews[i]);
            }
        }
예제 #4
0
 private void ClearQueue(DataOffice dataOffice)
 {
     for (int i = 0; i < dataOffice.Offices.Count; i++)
     {
         for (int t = 0; t < dataOffice.Offices[i].DataServices.Services.Count; t++)
         {
             dataOffice.Offices[i].DataServices.Services[t].CountHuman = 0;
         }
     }
 }
예제 #5
0
        private void Button1_Click(object sender, EventArgs e)
        {
            Random      random      = new Random();
            var         countHuman  = random.Next(10, 101);
            DataOffice  dataOffice  = new DataOffice();
            DataService dataService = new DataService();

            ClearQueue(dataOffice);
            GenerateQueue(random, countHuman, dataOffice, dataService);
            Log(dataOffice);
        }
예제 #6
0
        private void Log(DataOffice dataOffice)
        {
            Data.Text = $"Current user address: {Client.CurrentUserAddress}\n";
            var ways = Client.SetWays();

            for (int i = 0; i < ways.Count; i++)
            {
                Data.Text += ways[i].ToString();
                dataOffice.Offices[i].CalculateDelay();
                Data.Text += dataOffice.Offices[i] + "\n";
            }
        }
예제 #7
0
        public void GridPull(List <Reserve> reserves, DataGridView reservedTimeGrid)
        {
            reserves = ReservesData[AddressComboBox.SelectedIndex].Reserves;
            DataOffice dataOffice = new DataOffice();

            reservedTimeGrid.Rows.Clear();
            for (int i = 0; i < reserves.Count; i++)
            {
                var serviceReserve = dataOffice.Offices[AddressComboBox.SelectedIndex].DataServices.Services.First(service => service.Name == reserves[i].Service);
                var endDateTime    = reserves[i].WriteTime.AddMinutes(Convert.ToDouble(serviceReserve.Time));
                reservedTimeGrid.Rows.Add(reserves[i].WriteTime, endDateTime);
            }
        }
예제 #8
0
        private void RefreshReserve()
        {
            DataOffice dataOffice = new DataOffice();

            for (int i = 0; i < dataOffice.Offices.Count; i++)
            {
                for (int t = 0; t < dataOffice.Offices[i].DataServices.Services.Count; t++)
                {
                    for (int j = 0; j < ReserveForm.ReservesData[i].Reserves.Count; j++)
                    {
                        if (dataOffice.Offices[i].DataServices.Services[t].Name == ReserveForm.ReservesData[i].Reserves[j].Service)
                        {
                            dataOffice.Offices[i].DataServices.Services[t].CountHuman++;
                        }
                    }
                }
            }
            Log(dataOffice);
        }