Exemple #1
0
        public void TravelRouteSetTest()
        {
            using (DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                db.ClearTable(TravelRouteSet.TableName);
                db.ClearTable(TravelRouteSetEntry.TableName);

                TravelRouteSet set = new TravelRouteSet("set1", null, db.ConnectionString, "desc", System.Guid.NewGuid().ToStrGuid());
                set.SaveToDB();
                Site a = new Site("a", null, db.ConnectionString, "desc", System.Guid.NewGuid().ToStrGuid());
                a.SaveToDB();
                Site b = new Site("b", null, db.ConnectionString, "desc", System.Guid.NewGuid().ToStrGuid());
                b.SaveToDB();
                TravelRoute route = new TravelRoute(null, db.ConnectionString, "routename", "routedesc", a, b, System.Guid.NewGuid().ToStrGuid(), null);
                route.SaveToDB();
                set.AddRoute(route);
                //loading
                ObservableCollection <TravelRoute> routes = new ObservableCollection <TravelRoute>
                {
                    route
                };
                ObservableCollection <TravelRouteSet> sets = new ObservableCollection <TravelRouteSet>();
                TravelRouteSet.LoadFromDatabase(sets, db.ConnectionString, false, routes);
                db.Cleanup();
                (sets.Count).Should().Be(1);
            }
        }
        private static void MakeNewAdjustedRoute([NotNull] Simulator sim,
                                                 [NotNull] TravelRouteSetEntry oldTravelRouteSetEntry,
                                                 int adjustingDistances,
                                                 [CanBeNull] string modRouteKey,
                                                 [NotNull] TransportationDistanceModifier modifier,
                                                 [NotNull] TravelRouteSet adjustedTravelrouteset)
        {
            var         oldRoute = oldTravelRouteSetEntry.TravelRoute;
            TravelRoute newRoute = new TravelRoute(null,
                                                   sim.ConnectionString,
                                                   oldRoute.Name + " adjustment " + adjustingDistances,
                                                   oldRoute.Description,
                                                   oldRoute.SiteA,
                                                   oldRoute.SiteB,
                                                   Guid.NewGuid().ToStrGuid(),
                                                   oldRoute.RouteKey);

            newRoute.SaveToDB();
            sim.TravelRoutes.It.Add(newRoute);
            foreach (var step in oldRoute.Steps)
            {
                double distance = step.Distance;
                if (step.StepKey?.ToLower(CultureInfo.InvariantCulture) == modRouteKey)
                {
                    distance = modifier.NewDistanceInMeters;
                }
                newRoute.AddStep(step.Name, step.TransportationDeviceCategory, distance, step.StepNumber, step.StepKey, false);
            }


            newRoute.SaveToDB();
            //Logger.Info("Adjusted route " + newRoute.Name);
            adjustedTravelrouteset.AddRoute(newRoute);
        }
        public ShowTravelRouteWindow(TravelRoute travelRoute)
        {
            InitializeComponent();

            this.travelRoute = travelRoute;

            LoadTravelRouteValues(travelRoute);
        }
 public RoutesOfPointOfInterest(TravelRoute route)
 {
     TravelRouteID                = route.TravelRouteID;
     TravelListItemID             = route.TravelListItemID;
     Driving                      = route.Driving;
     StartTravelPointOfInterestID = route.StartTravelPointOfInterestID;
     EndTravelPointOfInterestID   = route.EndTravelPointOfInterestID;
 }
 public async Task UpdateTravelRoute(int id, TravelRoute tl)
 {
     if (tl == null)
     {
         throw new ArgumentNullException(nameof(tl));
     }
     _context.Routes.Update(tl);
     await _context.SaveChangesAsync();
 }
 public async Task DeleteTravelRoute(TravelRoute tl)
 {
     if (tl == null)
     {
         throw new ArgumentNullException(nameof(tl));
     }
     _context.Routes.Remove(tl);
     await _context.SaveChangesAsync();
 }
Exemple #7
0
        public void TravelRouteTest()
        {
            using (DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                db.ClearTable(TravelRoute.TableName);
                db.ClearTable(TravelRouteStep.TableName);
                Location loc = new Location("loc1", null, db.ConnectionString, Guid.NewGuid().ToStrGuid());
                loc.SaveToDB();
                Site siteA = new Site("site1", null, db.ConnectionString, "desc", Guid.NewGuid().ToStrGuid());
                siteA.SaveToDB();

                Site siteB = new Site("site2", null, db.ConnectionString, "desc", Guid.NewGuid().ToStrGuid());
                siteB.SaveToDB();

                TransportationDeviceCategory td = new
                                                  TransportationDeviceCategory("transportationdevicecategory", null, db.ConnectionString, "desc", true, Guid.NewGuid().ToStrGuid());
                td.SaveToDB();
                TravelRoute tr = new TravelRoute(null, db.ConnectionString, "route", "desc", siteA, siteB,
                                                 Guid.NewGuid().ToStrGuid(), null);
                tr.SaveToDB();
                tr.AddStep("name1", td, 100, 1, "key1");
                tr.AddStep("name3", td, 100, 10, "key3");
                tr.AddStep("name2", td, 100, 2, "key2");
                //test the  sorting of steps while adding based on step number
                ("name1").Should().Be(tr.Steps[0].Name);
                ("name2").Should().Be(tr.Steps[1].Name);
                ("name3").Should().Be(tr.Steps[2].Name);
                ("key1").Should().Be(tr.Steps[0].StepKey);
                ("key2").Should().Be(tr.Steps[1].StepKey);
                ("key3").Should().Be(tr.Steps[2].StepKey);
                foreach (TravelRouteStep step in tr.Steps)
                {
                    Logger.Info(step.Name);
                }
                //loading
                ObservableCollection <Site> sites = new ObservableCollection <Site>
                {
                    siteA,
                    siteB
                };
                ObservableCollection <TransportationDeviceCategory> transportationDeviceCategories = new ObservableCollection <TransportationDeviceCategory>
                {
                    td
                };
                ObservableCollection <TravelRoute> routes = new ObservableCollection <TravelRoute>();
                TravelRoute.LoadFromDatabase(routes, db.ConnectionString, false, transportationDeviceCategories, sites);
                (routes.Count).Should().Be(1);
                tr = routes[0];
                ("name1").Should().Be(tr.Steps[0].Name);
                ("name2").Should().Be(tr.Steps[1].Name);
                ("name3").Should().Be(tr.Steps[2].Name);
                ("key1").Should().Be(tr.Steps[0].StepKey);
                ("key2").Should().Be(tr.Steps[1].StepKey);
                ("key3").Should().Be(tr.Steps[2].StepKey);
                db.Cleanup();
            }
        }
 public void AddTravelRoute(TravelRoute travelRoute)
 {
     if (travelRoute == null)
     {
         throw new ArgumentNullException(nameof(travelRoute));
     }
     _context.TravelRoutes.Add(travelRoute);
     // _context.SaveChanges();
 }
Exemple #9
0
        public IActionResult GetInterestPoints(TravelRoute route)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(Json(new { result = "missing or invalid parameters" })));
            }

            return(Ok(Json(_interestPointsService.GetInterestPoints(route))));
        }
Exemple #10
0
        public TravelRoutePanel(TravelRoute travelRoute)
        {
            InitializeComponent();

            travelRoutesSqlRepository = new TravelRoutesSqlRepository();

            this.travelRoute = travelRoute;

            SetTravelRouteValues();
        }
 private void LoadTravelRouteValues(TravelRoute travelRoute)
 {
     LblId.Text                 = travelRoute.Id.ToString();
     LblDateIssued.Text         = travelRoute.DateIssued.ToShortDateString();
     LblTimeIssued.Text         = travelRoute.TimeIssued.ToString();
     LblOrigin.Text             = travelRoute.Origin;
     LblDestination.Text        = travelRoute.Destination;
     LblKilometersTraveled.Text = travelRoute.KilometersTraveled.ToString();
     LblAverageSpeed.Text       = travelRoute.AverageSpeed.ToString();
     LblSpentFuel.Text          = travelRoute.SpentFuel.ToString();
 }
Exemple #12
0
        private void LoadDataToWindow(TravelWarrant travelWarrant)
        {
            // Travel Warrant

            LblIdTravelWarrant.Text   = travelWarrant.Id.ToString();
            LblStatus.Text            = travelWarrant.WarrantStatus;
            LblDateTravelWarrant.Text = travelWarrant.DateIssued.ToShortDateString();
            LblTimeTravelWarrant.Text = travelWarrant.TimeIssued.ToString();

            // Driver

            Driver driver = driversSqlRepository.ReadById(travelWarrant.DriverId);

            LblIdDriver.Text             = driver.Id.ToString();
            LblFirstName.Text            = driver.FirstName;
            LblLastName.Text             = driver.LastName;
            LblPhoneNumber.Text          = driver.PhoneNumber;
            LblDriversLicenceNumber.Text = driver.DriversLicenceNumber;

            // Vehicle

            Vehicle vehicle = vehiclesSqlRepository.ReadById(travelWarrant.VehicleId);

            LblIdVehicle.Text         = vehicle.Id.ToString();
            LblMake.Text              = vehicle.Make;
            LblModel.Text             = vehicle.Model;
            LblYearOfManufacture.Text = vehicle.YearOfManufacture.ToString();
            LblInitialMileage.Text    = vehicle.InitialMileage.ToString();
            LblAvailability.Text      = vehicle.Available == true ? "Available" : "Not available";

            // Fuel Cost

            FuelCost fuelCost = fuelCostsSqlRepository.ReadById(travelWarrant.FuelCostId);

            LblIdFuelCost.Text   = fuelCost.Id.ToString();
            LblDateIssuedFc.Text = fuelCost.DateIssued.ToShortDateString();
            LblTimeIssuedFc.Text = fuelCost.TimeIssued.ToString();
            LblPosition.Text     = fuelCost.Position;
            LblAmount.Text       = fuelCost.Amount.ToString();
            LblPrice.Text        = fuelCost.Price.ToString();

            // Travel Route

            TravelRoute travelRoute = travelRoutesSqlRepository.ReadById(travelWarrant.TravelRouteId);

            LblIdTravelRoute.Text      = travelRoute.Id.ToString();
            LblDateIssuedTr.Text       = travelRoute.DateIssued.ToShortDateString();
            LblTimeIssuedTr.Text       = travelRoute.TimeIssued.ToString();
            LblOrigin.Text             = travelRoute.Origin;
            LblDestination.Text        = travelRoute.Destination;
            LblKilometersTraveled.Text = travelRoute.KilometersTraveled.ToString();
            LblAverageSpeed.Text       = travelRoute.AverageSpeed.ToString();
            LblSpentFuel.Text          = travelRoute.SpentFuel.ToString();
        }
Exemple #13
0
        public async void OnNewRouteClicked(string newName, string newDescription)
        {
            if (!ShowNewRouteFields)
            {
                ShowNewRouteFields = true;
            }
            else
            {
                if (string.IsNullOrEmpty(newName))
                {
                    Message = "A name is required, try again.";
                    return;
                }

                IsLoading = true;
                Message   = "Processing, please wait.";
                string      newDescriptionRef = string.IsNullOrEmpty(newDescription) ? "No Description" : newDescription;
                TravelRoute newRoute          = new TravelRoute(newName, newDescriptionRef);

                //REST
                try
                {
                    HttpClient httpClient = new HttpClient();
                    Uri        uri        = new Uri(BASE_URL + "User/addTravelRoute/" + UserName + "/" + TravelPlan.Name);

                    HttpStringContent content = new HttpStringContent(
                        JsonConvert.SerializeObject(newRoute),
                        UnicodeEncoding.Utf8,
                        "application/json");

                    HttpResponseMessage httpResponseMessage = await httpClient.PostAsync(
                        uri,
                        content);

                    httpResponseMessage.EnsureSuccessStatusCode();
                    var httpResponseBody = await httpResponseMessage.Content.ReadAsStringAsync();

                    Message = httpResponseBody;

                    if (httpResponseBody.Split(" ")[0] != "Error:")
                    {
                        TravelPlan.AddTravelRoute(newRoute);
                        RaisePropertyChanged("RouteList");
                    }
                }
                catch (Exception ex)
                {
                    Message = ex.Message;
                }

                ShowNewRouteFields = false;
                IsLoading          = false;
            }
        }
 public void SetLocation(SolarSystem system)
 {
     if (systemLocation != system)
     {
         this.systemLocation = system;
         transform.position  = systemLocation.transform.position;
         if (currentRoute && blocking)
         {
             currentRoute.finishUsingRoute(currentEmpire);
         }
         currentRoute      = null;
         destinationSystem = null;
     }
 }
Exemple #15
0
        private void ImportTravelRouteFromXml()
        {
            try
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();

                if (openFileDialog.ShowDialog() == true)
                {
                    string filePath = openFileDialog.FileName;

                    XmlDocument doc = new XmlDocument();

                    doc.Load(filePath);

                    List <string> travelRouteData = new List <string>();

                    foreach (XmlNode node in doc.DocumentElement.ChildNodes)
                    {
                        travelRouteData.Add(node.InnerText);
                    }

                    DateTime dateIssued         = DateTime.Parse(travelRouteData[0]);
                    TimeSpan timeIssued         = TimeSpan.Parse(travelRouteData[1]);
                    string   origin             = travelRouteData[2];
                    string   destination        = travelRouteData[3];
                    float    kilometersTraveled = float.Parse(travelRouteData[4]);
                    float    averageSpeed       = float.Parse(travelRouteData[5]);
                    float    spentFuel          = float.Parse(travelRouteData[6]);

                    TravelRoute travelRoute = new TravelRoute(dateIssued, timeIssued, origin, destination, kilometersTraveled, averageSpeed, spentFuel);

                    bool success = travelRoutesSqlRepository.Create(travelRoute);

                    if (success)
                    {
                        MessageBox.Show("Success");
                    }
                    else
                    {
                        MessageBox.Show("Fail");
                    }

                    LoadTravelRoutesToStackPanel();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #16
0
        private void ReadTravelRoutes(string filePath)
        {
            XmlReader xmlReader = XmlReader.Create(filePath);

            xmlReader.ReadToFollowing("TravelRoute");

            do
            {
                xmlReader.MoveToFirstAttribute();
                int id = int.Parse(xmlReader.Value);

                xmlReader.ReadToFollowing("DateIssued");
                DateTime dateIssued = DateTime.Parse(xmlReader.ReadElementContentAsString());

                xmlReader.ReadToFollowing("TimeIssued");
                TimeSpan timeIssued = TimeSpan.Parse(xmlReader.ReadElementContentAsString());

                xmlReader.ReadToFollowing("Origin");
                string origin = xmlReader.ReadElementContentAsString();

                xmlReader.ReadToFollowing("Destination");
                string destination = xmlReader.ReadElementContentAsString();

                xmlReader.ReadToFollowing("KilometersTraveled");
                float kilometersTraveled = xmlReader.ReadElementContentAsFloat();

                xmlReader.ReadToFollowing("AverageSpeed");
                float averageSpeed = xmlReader.ReadElementContentAsFloat();

                xmlReader.ReadToFollowing("SpentFuel");
                float spentFuel = xmlReader.ReadElementContentAsFloat();

                TravelRoute travelRoute = new TravelRoute()
                {
                    Id                 = id,
                    DateIssued         = dateIssued,
                    TimeIssued         = timeIssued,
                    Origin             = origin,
                    Destination        = destination,
                    KilometersTraveled = kilometersTraveled,
                    AverageSpeed       = averageSpeed,
                    SpentFuel          = spentFuel
                };

                travelRoutesSqlRepository.Restore(travelRoute);
            } while (xmlReader.ReadToFollowing("TravelRoute"));

            xmlReader.Close();
        }
        public void TestRoutNotFound()
        {
            var ctr = new TravelRoute();

            ctr.LoadRoutes(new List <(string from, string to)>()
            {
                ("Мельбурн", "Кельн"),
                ("Москва", "Париж"),
                ("Тверь", "Москва")
            });

            var res = ctr.FindRoute("Мельбурн", "Париж");

            Assert.Empty(res);
        }
        public void TestNotFullRout()
        {
            var ctr = new TravelRoute();

            ctr.LoadRoutes(new List <(string from, string to)>()
            {
                ("Мельбурн", "Кельн"),
                ("Москва", "Париж"),
                ("Тверь", "Москва")
            });

            var res = ctr.GetRoute();

            Assert.Null(res);
        }
    private bool CheckNextSystemStillViable(SolarSystem system)
    {
        if (path.Count == 1 || !currentEmpire || !system.GetEmpire() || currentEmpire == system.GetEmpire())
        {
            currentRoute = systemLocation.GetTravelRoutes().Find(c => c.GetDestination(systemLocation) == path.Peek());
            if (currentRoute.IsBlocked(currentEmpire))
            {
                currentRoute = null;
                return(false);
            }


            return(true);
        }
        return(false);
    }
        private void CreateTravelRoute()
        {
            if (TbDate.Text != string.Empty && TbTime.Text != string.Empty && TbOrigin.Text != string.Empty && TbDestination.Text != string.Empty && TbKilometersTraveled.Text != string.Empty && TbAverageSpeed.Text != string.Empty && TbSpentFuel.Text != string.Empty)
            {
                if (DateTime.TryParse(TbDate.Text, out DateTime date) && TimeSpan.TryParse(TbTime.Text, out TimeSpan time) && float.TryParse(TbKilometersTraveled.Text, out float kilometersTraveled) && float.TryParse(TbAverageSpeed.Text, out float averageSpeed) && float.TryParse(TbSpentFuel.Text, out float spentFuel))
                {
                    if ((Regex.IsMatch(TbDate.Text, @"\d\d/\d\d/\d\d\d\d") || Regex.IsMatch(TbDate.Text, @"\d/\d\d/\d\d\d\d")) && Regex.IsMatch(TbTime.Text, @"\d\d:\d\d:\d\d"))
                    {
                        TravelRoute createdTravelRoute = new TravelRoute()
                        {
                            DateIssued         = date,
                            TimeIssued         = time,
                            Origin             = TbOrigin.Text,
                            Destination        = TbDestination.Text,
                            KilometersTraveled = kilometersTraveled,
                            AverageSpeed       = averageSpeed,
                            SpentFuel          = spentFuel
                        };

                        bool success = travelRoutesSqlRepository.Create(createdTravelRoute);

                        if (success)
                        {
                            MessageBox.Show("Success");
                            Close();
                        }
                        else
                        {
                            MessageBox.Show("Fail");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Date format must be: \"MM/dd/yyyy\"\nTime format must be: \"HH:MM:ss\"");
                    }
                }
                else
                {
                    MessageBox.Show("Kilometers traveled, average speed and spent fuel must be numbers\nDate format must be: \"MM/dd/yyyy\"\nTime format must be: \"HH:MM:ss\"");
                }
            }
            else
            {
                MessageBox.Show("All input fields are required");
            }
        }
    private void CreateLineRenderer(SolarSystem destination, float distance)
    {
        TravelRoute route = destination.travelRoutes.Find(c => c.ContainsSystem(this) == true);

        if (!route)
        {
            var          travelRoute  = Instantiate(travelRoutePrefab, transform.position, transform.rotation);
            LineRenderer lineRenderer = travelRoute.GetComponent <LineRenderer>();
            lineRenderer.SetPosition(0, transform.position);
            lineRenderer.SetPosition(1, destination.transform.position);
            lineRenderer.transform.SetParent(transform.Find("TravelRoutes"));
            route           = travelRoute.GetComponent <TravelRoute>();
            route.systemOne = this;
            route.systemTwo = destination;
            route.SetDistance(distance);
        }
        travelRoutes.Add(route);
    }
        public void TestGetRoutBetween3Cities()
        {
            var ctr = new TravelRoute();

            ctr.LoadRoutes(new List <(string from, string to)>()
            {
                ("Мельбурн", "Кельн"),
                ("Москва", "Париж"),
                ("Кельн", "Москва")
            });

            var res = ctr.GetRoute();

            Assert.NotNull(res);
            Assert.Equal(3, res.Count);
            Assert.Equal(("Мельбурн", "Кельн"), res[0]);
            Assert.Equal(("Кельн", "Москва"), res[1]);
            Assert.Equal(("Москва", "Париж"), res[2]);
        }
        public void TestLoadIncorrectRoutes()
        {
            var ctr = new TravelRoute();

            Assert.Throws <ArgumentNullException>(() => ctr.LoadRoutes(null));
            Assert.Throws <ArgumentNullException>(() =>
                                                  ctr.LoadRoutes(new List <(string from, string to)>()
            {
                ("Мельбурн", "Кельн"),
                ("Москва", null),
                ("Кельн", "Москва")
            }));
            Assert.Throws <ArgumentNullException>(() =>
                                                  ctr.LoadRoutes(new List <(string from, string to)>()
            {
                ("Мельбурн", "Кельн"),
                ("Москва", ""),
                ("Кельн", "Москва")
            }));
        }
Exemple #24
0
 public List <InterestPoint> GetInterestPoints(TravelRoute route)
 {
     if (route.start_latitude > route.end_latitude && route.start_longitude < route.end_longitude)
     {
         return(_interestPointRepository.GetInterestPoints(route, ORIENTATION_TYPE.SOUTH_EAST));
     }
     else if (route.start_latitude < route.end_latitude && route.start_longitude < route.end_longitude)
     {
         return(_interestPointRepository.GetInterestPoints(route, ORIENTATION_TYPE.NORTH_EAST));
     }
     else if (route.start_latitude > route.end_latitude && route.start_longitude > route.end_longitude)
     {
         return(_interestPointRepository.GetInterestPoints(route, ORIENTATION_TYPE.SOUTH_WEST));
     }
     else if (route.start_latitude < route.end_latitude && route.start_longitude > route.end_longitude)
     {
         return(_interestPointRepository.GetInterestPoints(route, ORIENTATION_TYPE.NORTH_WEST));
     }
     return(new List <InterestPoint>());
 }
Exemple #25
0
        private List <InterestPoint> GetInterestPointsWithDirection(TravelRoute route, string routeDirection)
        {
            if (ORIENTATION_TYPE.SOUTH_EAST.Equals(routeDirection))
            {
                return(_collection.Find(point =>
                                        point.latitude < route.start_latitude &&
                                        point.latitude > route.end_latitude &&
                                        point.longitude > route.start_longitude &&
                                        point.longitude < route.end_longitude
                                        ).ToList());
            }
            else if (ORIENTATION_TYPE.NORTH_EAST.Equals(routeDirection))
            {
                return(_collection.Find(point =>
                                        point.latitude > route.start_latitude &&
                                        point.latitude < route.end_latitude &&
                                        point.longitude > route.start_longitude &&
                                        point.longitude < route.end_longitude
                                        ).ToList());
            }
            else if (ORIENTATION_TYPE.SOUTH_WEST.Equals(routeDirection))
            {
                return(_collection.Find(point =>
                                        point.latitude < route.start_latitude &&
                                        point.latitude > route.end_latitude &&
                                        point.longitude < route.start_longitude &&
                                        point.longitude > route.end_longitude
                                        ).ToList());
            }
            else if (ORIENTATION_TYPE.NORTH_WEST.Equals(routeDirection))
            {
                return(_collection.Find(point =>
                                        point.latitude > route.start_latitude &&
                                        point.latitude < route.end_latitude &&
                                        point.longitude < route.start_longitude &&
                                        point.longitude > route.end_longitude
                                        ).ToList());
            }

            return(new List <InterestPoint>());
        }
Exemple #26
0
 public string PostNewTravelRoute(string username, string travelplan, [FromBody] JsonElement value)
 {
     if (_userRepository.GetAllUsersShort().Where(u => u.UserName == username).Count() < 1)
     {
         return("Error: Unknown user");
     }
     else
     {
         User user = _userRepository.GetByName(username);
         if (user.Travelplans.Where(t => t.Name == travelplan).Count() < 1)
         {
             return("Error: Unknown travelplan");
         }
         TravelRoute response = JsonConvert.DeserializeObject <TravelRoute>(value.GetRawText());
         if (user.Travelplans.Where(t => t.Name == travelplan).First().RouteList.Where(i => i.Name == response.Name).Count() > 0)
         {
             return("Error: TravelRoute already exists");
         }
         user.Travelplans.Where(t => t.Name == travelplan).First().AddTravelRoute(response);
         _userRepository.Update(user);
         _userRepository.SaveChanges();
         return(response.Name + " succesfully added to " + username + "'s TravelPlan \"" + travelplan + "\"");
     }
 }
Exemple #27
0
 public List <InterestPoint> GetInterestPoints(TravelRoute route, string routeDirection)
 {
     return(GetInterestPointsWithDirection(route, routeDirection));
 }
        private void GenerateVehicleReport()
        {
            Vehicle v     = vehiclesSqlRepository.ReadById(vehicle.Id);
            string  make  = v.Make;
            string  model = v.Model;

            float currentlyTraveledKilometers = v.InitialMileage;

            float averageSpeed = 0;
            int   counter      = 0;

            List <TravelWarrant> travelWarrants = travelWarrantsSqlRepository.ReadAll();
            List <TravelRoute>   travelRoutes   = travelRoutesSqlRepository.ReadAll();

            foreach (TravelWarrant travelWarrant in travelWarrants)
            {
                if (travelWarrant.VehicleId == v.Id)
                {
                    TravelRoute travelRoute = travelRoutesSqlRepository.ReadById(travelWarrant.TravelRouteId);

                    currentlyTraveledKilometers += travelRoute.KilometersTraveled;
                    averageSpeed += travelRoute.AverageSpeed;
                    counter++;
                }
            }

            averageSpeed /= counter;

            var resourceName = Assembly.GetExecutingAssembly().GetManifestResourceNames().Where(q => q.Contains("Template.html")).FirstOrDefault();

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    StringBuilder  sb       = new StringBuilder();
                    List <Service> services = servicesSqlRepository.ReadAll();

                    foreach (Service service in services)
                    {
                        if (service.Vehicle.Id == v.Id)
                        {
                            sb.Append("<table>\n");
                            sb.Append("<tr>\n");

                            foreach (ServiceItem serviceItem in service.ServiceItems)
                            {
                                sb.Append("<td></br>");
                                sb.Append("Service item\n");
                                sb.Append("</br>");
                                sb.Append(serviceItem.Name + "\n");
                                sb.Append("</br>");
                                sb.Append(serviceItem.Price + "\n");
                                sb.Append("</br>");
                                sb.Append("</td>\n");
                            }

                            sb.Append("</tr>\n");
                            sb.Append("</table>\n");
                        }
                    }

                    string html = reader.ReadToEnd().Replace("$$MAKE$$", make).Replace("$$MODEL$$", model).Replace("$$CTK$$", currentlyTraveledKilometers.ToString()).Replace("$$AVERAGESPEED$$", averageSpeed.ToString()).Replace("$$SERVICEITEMS$$", sb.ToString());

                    File.WriteAllText(@"../../../DataForExport/HtmlVehicleReport.html", html);
                }
            }
            MessageBox.Show("Success");

            System.Diagnostics.Process.Start(@"C:\Development\project-adpc-vehiclemanager\DataForExport/HtmlVehicleReport.html");
        }
 public async Task UpdateTravelRoute(int id, TravelRoute tl) =>
 await _http.PutAsync <TravelRoute, TravelRoute>($"TravelRoutes/{id}", tl);
 public async Task DeleteTravelRoute(TravelRoute tl) =>
 await _http.DeleteAsync("TravelRoutes", tl.TravelRouteID);