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); }
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); } }
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]); } }
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; } } }
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); }
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"; } }
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); } }
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); }