public VehicleSchedule IsScheduleBooked(VehicleInformation vehicle, DateTime selectedDate, string shift) { try { SqlConnectionObj.Open(); string query = string.Format("SELECT * FROM ScheduleVehicle WHERE VehicleRegNo='{0}' AND Date='{1}' AND Shift='{2}'", vehicle.RegNo, selectedDate, shift); SqlCommandObj.CommandText = query; SqlDataReader reader = SqlCommandObj.ExecuteReader(); while (reader.Read()) { VehicleSchedule vehicleSchedule = new VehicleSchedule(); vehicleSchedule.Vehicle.RegNo = reader[0].ToString(); vehicleSchedule.SelectedDate = (DateTime)reader[1]; vehicleSchedule.SelectShift = reader[2].ToString(); vehicleSchedule.BookedBy = reader[3].ToString(); vehicleSchedule.Address = reader[4].ToString(); return(vehicleSchedule); } } catch (Exception exceptionObj) { throw new Exception("Exception occured! In Schedule Booking.", exceptionObj); } finally { if (SqlConnectionObj != null && SqlConnectionObj.State == ConnectionState.Open) { SqlConnectionObj.Close(); } } return(null); }
internal new static TaskTravelDurationDataSet Read(StateBinaryReader reader, VehicleSchedule schedule) { TaskTravelDurationDataSet result = new TaskTravelDurationDataSet(); result.DoRead(reader, schedule); return(result); }
/// <summary> /// Updates the vehicle schedule. /// </summary> /// <param name="from">From.</param> /// <param name="to">To.</param> public static void UpdateVehicleSchedule(VehicleSchedule from, ref VehicleSchedule to) { to.RouteScheduleId = from.RouteScheduleId; to.VehicleId = from.VehicleId; to.Date = from.Date; to.Active = from.Active; }
public VehicleScheduleCapacity(VehicleSchedule vehicleSchedule) { VehicleSchedule = vehicleSchedule ?? throw new ArgumentNullException(nameof(vehicleSchedule)); _hasValidData = null; _dirty = true; SubscribeUnitStorageChange(); }
internal static Measurement Read(StateBinaryReader reader, VehicleSchedule schedule, VehicleScheduleData data) { RootTask task = schedule.GetTasks()[reader.ReadInt()]; Measurement result = MeasurementSurrogate.Read(reader, data, task); result.DoRead(reader, schedule, data); return(result); }
static private void VehicleSchedule_AddTask_pof(VehicleSchedule __instance, RootTask task) { Vehicle vehicle = __instance.Vehicle; if (vehicle) { Current.OnScheduleChanged(vehicle, task); } }
static private void VehicleSchedule_MoveTask_pof(VehicleSchedule __instance, int newIndex, List <RootTask> ____tasks) { Vehicle vehicle = __instance.Vehicle; if (vehicle) { Current.OnScheduleChanged(vehicle, ____tasks[newIndex]); } }
public Snapshot(VehicleSchedule schedule) { ImmutableList <RootTask> tasks = schedule.GetTasks(); int count = tasks.Count; for (int i = 0; i < count; i++) { RootTask task = tasks[i]; _taskSnapshots.Add(new TaskSnapshot(task, i)); } }
protected virtual void DoRead(StateBinaryReader reader, VehicleSchedule schedule) { int count = reader.ReadInt(); for (int i = 0; i < count; i++) { int taskIndex = reader.ReadInt(); RootTask task = schedule.GetTasks()[taskIndex]; _data.Add(task, DurationDataSet.Read(reader)); } }
// GET: VehicleSchedules public ActionResult Index() { VehicleSchedule myModel = new VehicleSchedule(); if (TempData["model"] != null) { myModel = (VehicleSchedule)TempData["model"]; TempData.Remove("model"); } return(View(myModel)); }
// GET: AddVehicleSchedule public ActionResult Index(string vehicleID) { if (vehicleID != null) { VehicleSchedule mySchedule = new VehicleSchedule(); mySchedule.VehicleID = int.Parse(vehicleID); return(View(mySchedule)); } return(View()); }
protected override void DoRead(StateBinaryReader reader, VehicleSchedule schedule, VehicleScheduleData data) { base.DoRead(reader, schedule, data); _startDistance = null; if (ScheduleStopwatch.GetSchemaVersion(typeof(VehicleScheduleData)) >= 2) { if (reader.ReadBool()) { _startDistance = reader.ReadFloat(); } } }
public bool IsScheduleBooked(VehicleInformation vehicle, DateTime selectedDate, string shift) { VehicleSchedule vehicleSchedule = new VehicleSchedule(); vehicleSchedule = _vehicleScheduleGateway.IsScheduleBooked(vehicle, selectedDate, shift); if (vehicleSchedule != null) { message = string.Format("This schedule is already booked by : {0}", vehicleSchedule.BookedBy); return(true); } message = string.Format("New Schedule is saved!"); return(false); }
/// <summary> /// Updates the vehicle schedule. /// </summary> /// <param name="vehicleSchedule">The vehicle schedule.</param> /// <returns>The updated vehicle schedule.</returns> public VehicleSchedule UpdateVehicleSchedule(VehicleSchedule vehicleSchedule) { var existingRoadSchedule = this.GetVehicleSchedule(vehicleSchedule.Id); if (existingRoadSchedule != null) { DataModelUpdater.UpdateVehicleSchedule(vehicleSchedule, ref existingRoadSchedule); this.context.Update(existingRoadSchedule); this.context.SaveChanges(); } return(existingRoadSchedule); }
public ActionResult PageData(IDataTablesRequest request) { CodeFirst.CodeFirst db = new CodeFirst.CodeFirst(); // Nothing important here. Just creates some mock data. var data = VehicleSchedule.GetData(); //This code is for joining if we want to show information of the Vehicle instead of the ID var vehicles = db.Vehicles.ToList(); var newData = (from s in data join v in vehicles on s.VehicleID equals v.VehicleID select new { ScheduleID = s.Veh_Schedule_ID, Date = s.Date, StartTime = s.StartTime, EndTime = s.EndTime, Status = s.Status, Brand = v.Brand, Model = v.Model, NumberPlate = v.NumberPlate }).ToList(); // Global filtering. // Filter is being manually applied due to in-memmory (IEnumerable) data. // If you want something rather easier, check IEnumerableExtensions Sample. var filteredData = newData.Where(_item => _item.ScheduleID.ToString().Contains(request.Search.Value) || _item.Date.ToUpper().Contains(request.Search.Value.ToUpper()) || _item.StartTime.ToString().ToUpper().Contains(request.Search.Value.ToUpper()) || _item.EndTime.ToString().ToUpper().Contains(request.Search.Value.ToUpper()) || _item.Status.ToUpper().Contains(request.Search.Value.ToUpper()) || _item.Brand.ToUpper().Contains(request.Search.Value.ToUpper()) || _item.Model.ToUpper().Contains(request.Search.Value.ToUpper()) || _item.NumberPlate.ToUpper().Contains(request.Search.Value.ToUpper()) ); // Paging filtered data. // Paging is rather manual due to in-memmory (IEnumerable) data. var dataPage = filteredData.Skip(request.Start).Take(request.Length); // Response creation. To create your response you need to reference your request, to avoid // request/response tampering and to ensure response will be correctly created. var response = DataTablesResponse.Create(request, data.Count(), filteredData.Count(), dataPage); // Easier way is to return a new 'DataTablesJsonResult', which will automatically convert your // response to a json-compatible content, so DataTables can read it when received. return(new DataTablesJsonResult(response, JsonRequestBehavior.AllowGet)); }
protected override void DoRead(StateBinaryReader reader, VehicleSchedule schedule) { base.DoRead(reader, schedule); if (ScheduleStopwatch.GetSchemaVersion(typeof(TaskDurationDataSet)) >= 2) { int count = reader.ReadInt(); for (int i = 0; i < count; i++) { int taskIndex = reader.ReadInt(); float value = reader.ReadFloat(); if (taskIndex > -1) { _distanceData.Add(schedule.GetTasks()[taskIndex], value); } else { ScheduleStopwatch.logger.Log(UnityEngine.LogType.Warning, "RootTask index = -1"); } } } }
public void TestVehicleSchedules() { var databaseService = this.container.Resolve <IDatabaseService>(); var fleetOperator = new Operator { Name = "Greyhound", AddressLine1 = "58 Portree Cres", AddressCity = "Heathwood", AddressPostCode = "4110", AddressState = "QLD", AddressCountry = "Australia", PrimaryContact = "0411342791", PrimaryEmail = "*****@*****.**", Active = true }; fleetOperator = databaseService.CreateOperator(fleetOperator); var destination1 = new Destination { City = "Test Location 1", State = "Test Location 1", PostCode = 1000, Active = true }; destination1 = databaseService.CreateDestination(destination1); var destination2 = new Destination { City = "Test Location 2", State = "Test Location 2", PostCode = 6000, Active = true }; destination2 = databaseService.CreateDestination(destination2); var route = new Route { DepartureId = destination1.Id, ArrivalId = destination2.Id, Active = true }; route = databaseService.CreateRoute(route); var routeSchedule = new RouteSchedule { OperatorId = fleetOperator.Id, RouteId = route.Id, Day = DayOfWeek.Monday, Time = new TimeSpan(9, 0, 0), Active = true }; routeSchedule = databaseService.CreateRouteSchedule(routeSchedule); var layout = new SeatLayout { Rows = 10, Columns = 4, Layout = "A1:B1;A2:B2;A3,B3:C3,D3", Active = true }; layout = databaseService.CreateSeatLayout(layout); var vehicle = new Vehicle { SeatLayoutId = layout.Id, VehicleType = "Premium Volvo", Manufacturer = "Volvo", DriveType = "Automatic", Model = "V2110", RegistrationNumber = "BA 2233", RegistrationState = "Dhaka Metro", RegistrationExpiry = new DateTime(2021, 9, 12), VIN = "V5263YY83784", Year = 2017, BaseStation = "Dhaka", TotalSeats = 24, Active = true }; vehicle = databaseService.CreateVehicle(vehicle); var vehicleSchedule = new VehicleSchedule { OperatorId = fleetOperator.Id, RouteScheduleId = routeSchedule.Id, VehicleId = vehicle.Id, Date = DateTime.Today, Active = true }; vehicleSchedule = databaseService.CreateVehicleSchedule(vehicleSchedule); var newVehicleSchedule = databaseService.GetVehicleSchedule(vehicleSchedule.Id); Assert.IsTrue(newVehicleSchedule != null); Assert.AreEqual(newVehicleSchedule.OperatorId, vehicleSchedule.OperatorId); Assert.AreEqual(newVehicleSchedule.RouteScheduleId, vehicleSchedule.RouteScheduleId); Assert.AreEqual(newVehicleSchedule.Date, vehicleSchedule.Date); Assert.AreEqual(newVehicleSchedule.Operator?.Name, vehicleSchedule.Operator?.Name); newVehicleSchedule.Date = new DateTime(2019, 07, 19); newVehicleSchedule = databaseService.UpdateVehicleSchedule(newVehicleSchedule); var updatedVehicleSchedule = databaseService.GetVehicleSchedule(newVehicleSchedule.Id); Assert.IsTrue(updatedVehicleSchedule != null); Assert.AreEqual(updatedVehicleSchedule.Date, newVehicleSchedule.Date); databaseService.DeleteVehicleSchedule(vehicleSchedule.Id); Assert.AreEqual(databaseService.GetVehicleSchedule(vehicleSchedule.Id), null); Assert.AreEqual(databaseService.GetVehicleSchedule(newVehicleSchedule.Id), null); Assert.AreEqual(databaseService.GetVehicleSchedule(updatedVehicleSchedule.Id), null); databaseService.DeleteVehicle(vehicle.Id); databaseService.DeleteSeatLayout(layout.Id); databaseService.DeleteRouteSchedule(routeSchedule.Id); databaseService.DeleteRoute(route.Id); databaseService.DeleteDestination(destination1.Id); databaseService.DeleteDestination(destination2.Id); databaseService.DeleteOperator(fleetOperator.Id); }
private bool ProcessSchedule(Dictionary <VehicleUnit, StorageState> storages, bool onlyRefit, Dictionary <RootTask, TaskTransfers> transfers = null, Dictionary <int, Dictionary <RootTask, TaskTransfers> > transfersPerUnit = null) { ImmutableList <RootTask> tasks = VehicleSchedule.GetTasks(); int tasksCount = tasks.Count; for (int i = 0; i < tasksCount; i++) { RootTask task = tasks[i]; ImmutableList <SubTask> subTasks = task.GetSubTasks(); int subTaskCount = subTasks.Count; TaskTransfers transfer = null; TaskTransfers[] transferPerUnit = null; for (int j = 0; j < subTaskCount; j++) { SubTask subTask = subTasks[j]; if (subTask is RefitTask refitTask) { if (!Refit(refitTask, storages)) { return(false); } } else if (!onlyRefit && subTask is TransferTask transferTask) { if (!Transfer(transferTask, storages, ref transfer, ref transferPerUnit, transfers != null, transfersPerUnit != null)) { return(false); } } } if (transfer != null) { transfers.Add(task, transfer); } if (transferPerUnit != null && transferPerUnit.Length > 0) { for (int j = 0; j < transferPerUnit.Length; j++) { TaskTransfers unitTransfer = transferPerUnit[j]; if (unitTransfer != null) { if (!transfersPerUnit.TryGetValue(j, out Dictionary <RootTask, TaskTransfers> unitTransfers)) { unitTransfers = new Dictionary <RootTask, TaskTransfers>(); transfersPerUnit.Add(j, unitTransfers); } if (unitTransfers.TryGetValue(task, out TaskTransfers addedUnitTransfers)) { addedUnitTransfers.Add(unitTransfer); } else { unitTransfers.Add(task, unitTransfer); } } } } } return(true); }
/// <summary> /// Creates the vehicle schedule. /// </summary> /// <param name="vehicleSchedule">The vehicle schedule.</param> /// <returns>The new vehicle schedule.</returns> public VehicleSchedule CreateVehicleSchedule(VehicleSchedule vehicleSchedule) { this.context.VehicleSchedules.Add(vehicleSchedule); this.context.SaveChanges(); return(vehicleSchedule); }
public void TestInitialize() { Target = VehicleSchedule.Loco("W1"); }
protected virtual void DoRead(StateBinaryReader reader, VehicleSchedule schedule, VehicleScheduleData data) { startTime = new DateTime(reader.ReadLong()); }
private static IEnumerable <Message> GetSchedules(Schedule schedule, Excel.Workbook book) { var messages = new List <Message>(); Excel.Worksheet sheet = book.Worksheets["Trains"] as Excel.Worksheet; var r = 2; Train currentTrain = null; string trainId = null; VehicleSchedule currentLoco = null; Dictionary <string, VehicleSchedule> locoSchedules = new Dictionary <string, VehicleSchedule>(); Dictionary <string, DriverDuty> driverDuties = new Dictionary <string, DriverDuty>(); while (true) { var row = (Array)sheet.get_Range(Cell("A", r), Cell("K", r)).Cells.Value; if (row.GetValue(1, 1) == null) { break; } else { var type = row.Value(9).ToUpperInvariant(); switch (type) { case "TRAINDEF": trainId = row.Value(8); var train = schedule.Timetable.Train(trainId); if (train.IsNone) { messages.Add(Message.Error(CultureInfo.CurrentCulture, $"Train {trainId} cannot be found.")); break; } currentTrain = train.Value; break; case "LOCOMOTIVE": var locoId = row.Value(8); if (locoId != null) { if (!locoSchedules.ContainsKey(locoId)) { locoSchedules.Add(locoId, VehicleSchedule.Loco(locoId)); } currentLoco = locoSchedules[locoId]; if (currentTrain != null) { var locoMessages = new List <Message>(); var fromStationSignature = row.Value(3); var toStationSignature = row.Value(4); var fromTime = Time.Parse(row.Value(5)); var toTime = Time.Parse(row.Value(6)); //if (lt2 < lt1) lt2 = lt2.AddDays(1); // TODO: Handle over midnight times, if necessary var(fromCall, fromIndex) = currentTrain.FindBetweenArrivlAndBeparture(fromStationSignature, fromTime); var(toCall, toIndex) = currentTrain.FindBetweenArrivlAndBeparture(toStationSignature, toTime); if (fromCall.IsNone) { locoMessages.Add(Message.Error(CultureInfo.CurrentCulture, Resources.Strings.LocoAtStationWithDepartureDoNotRefersToAnExistingTimeInTrain, locoId, fromStationSignature, fromTime, currentTrain)); } if (toCall.IsNone) { locoMessages.Add(Message.Error(CultureInfo.CurrentCulture, Resources.Strings.LocoAtStationWithArrivalDoNotRefersToAnExistingTimeInTrain, locoId, fromStationSignature, toTime, currentTrain)); } if (fromIndex >= toIndex) { locoMessages.Add(Message.Error(CultureInfo.CurrentCulture, Resources.Strings.LocoInTrainHasWrongTimingEndStartionIsBeforeStartStation, locoId, currentTrain, fromTime, toTime)); } messages.AddRange(locoMessages); if (locoMessages.CanContinue()) { TrainPart trainPart = new TrainPart(currentTrain, fromIndex, toIndex); currentLoco.Add(trainPart); } } } break; case "TRAINSET": var trainsetId = row.Value(8); break; case "JOB": var jobId = row.Value(8); if (jobId != null) { var jobMessages = new List <Message>(); if (currentTrain is null) { messages.Add(Message.Error(CultureInfo.CurrentCulture, $"There is not a current train for job {jobId}.")); break; } if (currentLoco is null) { messages.Add(Message.Error(CultureInfo.CurrentCulture, $"There is not a current loco for job {jobId}.")); break; } if (!driverDuties.ContainsKey(jobId)) { driverDuties.Add(jobId, new DriverDuty(jobId)); } var currentLocoSchedule = locoSchedules.Values.SingleOrDefault(l => l.Identity == currentLoco.Identity); if (currentLocoSchedule is null) { messages.Add(Message.Error(CultureInfo.CurrentCulture, $"Job {jobId} referse no a nonexisting loco schedule {currentLoco}.")); break; } var dt1 = Time.Parse(row.Value(5)); var dt2 = Time.Parse(row.Value(6)); if (dt2 < dt1) { dt2 = dt2.AddDays(1); } var part = currentLocoSchedule.Parts.Select((value, index) => (value, index)).SingleOrDefault(p => p.value.Train.Number == currentTrain.Number && (p.value.From.Arrival == dt1 || p.value.From.Departure == dt1 || dt1 < currentLocoSchedule.Parts.First().From.Arrival) && (p.value.To.Arrival == dt2 || p.value.To.Departure == dt2 || dt2 > currentLocoSchedule.Parts.Last().To.Departure)); if (part.value == null) { jobMessages.Add(Message.Error($"Error in train {currentTrain} for job {jobId}.")); } if (jobMessages.CanContinue()) { driverDuties[jobId].Add(new VehicleSchedulePart(currentLocoSchedule, part.index, part.index)); messages.AddRange(jobMessages); } } break; case "GROUP": if (currentTrain != null) { currentTrain.Category = row.Value(8); } break; default: break; } } r++; } foreach (var loco in locoSchedules.Values) { schedule.AddLocoSchedule(loco); } foreach (var duty in driverDuties.Values) { schedule.AddDriverDuty(duty); } return(messages); }