Esempio n. 1
0
        public static List <TravelsGrid> GetTravelsList(DateTime DepartureDate, DateTime ArrivalDate, int DayTolerance, string Lat, string Lng)
        {
            List <TravelsGrid> TravelsGridList = new List <TravelsGrid>();

            using (PodrozeEntities context = new PodrozeEntities())
            {
                DateTime departureDateFrom = DepartureDate.AddDays(DayTolerance * (-1));
                DateTime departureDateTo   = DepartureDate.AddDays(DayTolerance);
                DateTime arrivalDateFrom   = ArrivalDate.AddDays(DayTolerance * (-1));
                DateTime arrivalDateTo     = ArrivalDate.AddDays(DayTolerance);

                var travelListQuery = (from BusinessTrip in context.BusinessTrips
                                       where BusinessTrip.DepartureDate >= departureDateFrom &&
                                       BusinessTrip.DepartureDate <= departureDateTo &&
                                       BusinessTrip.ArrivalDate >= arrivalDateFrom &&
                                       BusinessTrip.ArrivalDate <= arrivalDateTo &&
                                       BusinessTrip.Active == true
                                       select BusinessTrip)
                                      .Include(x => x.Users)
                                      .Include(x => x.Destinations)
                                      .Include(x => x.Cars);

                List <BusinessTrips> BusinessTripsList = travelListQuery.ToList();

                foreach (BusinessTrips businessTrip in BusinessTripsList)
                {
                    TravelsGrid travel = new TravelsGrid();
                    travel.TripId             = businessTrip.Id;
                    travel.UserName           = businessTrip.Users.SurName + " " + businessTrip.Users.FirstName;
                    travel.Address            = businessTrip.Destinations.Address;
                    travel.RegistrationNumber = businessTrip.Cars.RegistrationNumber;
                    travel.DepartureDate      = businessTrip.DepartureDate;
                    travel.ArrivalDate        = businessTrip.ArrivalDate;
                    travel.Lat = businessTrip.Destinations.Latitude;
                    travel.Lng = businessTrip.Destinations.Longitude;
                    string startGeolocation = travel.Lat.ToString().Replace(',', '.') + ',' + travel.Lng.ToString().Replace(',', '.');
                    string endGeolocation   = Lat.Replace(',', '.') + ',' + Lng.Replace(',', '.');
                    if (startGeolocation == endGeolocation)
                    {
                        travel.Distance = "0";
                        travel.Duration = "0";
                    }
                    else
                    {
                        Dictionary <string, string> result = GoogleApi.GenerateRoute.GetDistance(startGeolocation, endGeolocation, "");
                        travel.Distance = result["distance"];
                        travel.Duration = result["duration"];
                    }
                    TravelsGridList.Add(travel);
                }
            }
            return(TravelsGridList);
        }
Esempio n. 2
0
        private void btnJoinToTravel_Click(object sender, EventArgs e)
        {
            BusinessClasses.TravelsGrid tg = (BusinessClasses.TravelsGrid)dataGridView1.SelectedRows[0].DataBoundItem;
            int notResrvedPlaces           = BusinessClasses.MenageContext.GetNotReservedPlaces(tg);

            if (notResrvedPlaces > 0)
            {
                AddJoinTrip(BusinessClasses.MenageContext.GetCarIdByRegistration(tg.RegistrationNumber), tg.DepartureDate, tg.ArrivalDate);
            }
            else
            {
                MessageBox.Show("Brak wolnych miejsc");
            }
        }
Esempio n. 3
0
        private void LoadCarsToCombox()
        {
            List <string> registrations = new List <string>();

            foreach (DataGridViewRow dgrv in dataGridView1.Rows)
            {
                BusinessClasses.TravelsGrid tg = (BusinessClasses.TravelsGrid)dgrv.DataBoundItem;
                registrations.Add(tg.RegistrationNumber);
            }

            cmbCars.DataSource    = BusinessClasses.MenageContext.GetCars(registrations);
            cmbCars.DisplayMember = "CmbCars";
            cmbCars.ValueMember   = "Id";
        }
Esempio n. 4
0
 private void dataGridView1_SelectionChanged(object sender, EventArgs e)
 {
     if (dataGridView1.SelectedRows.Count > 0)
     {
         BusinessClasses.TravelsGrid travel = (BusinessClasses.TravelsGrid)dataGridView1.SelectedRows[0].DataBoundItem;
         {
             string latlng1 = lat + "," + lng;
             string latlng2 = travel.Lat + "," + travel.Lng;
             if (latlng1 != latlng2)
             {
                 Dictionary <string, string> result1 = GoogleApi.GenerateRoute.GetDistance(Properties.Settings.Default.CompanyLatLng, latlng1, "", "&waipoints=" + latlng2);
                 double distance1 = 0;
                 double.TryParse(result1["distance2"], out distance1);
                 Dictionary <string, string> result2 = GoogleApi.GenerateRoute.GetDistance(Properties.Settings.Default.CompanyLatLng, latlng2, "", "&waipoints=" + latlng1);
                 double distance2 = 0;
                 double.TryParse(result2["distance2"], out distance2);
                 if (distance1 == 0 || distance2 == 0)
                 {
                     MessageBox.Show("Nie udało się znaleźć trasy");
                 }
                 else if (distance1 < distance2)
                 {
                     chromeWebBrowser.Load(string.Format("http://maps.google.com/maps?saddr={0}&daddr={1}+to:{2}&dirflg=d&hl=pl", Properties.Settings.Default.CompanyLatLng, latlng1, latlng2));
                 }
                 else
                 {
                     chromeWebBrowser.Load(string.Format("http://maps.google.com/maps?saddr={0}&daddr={1}+to:{2}&dirflg=d&hl=pl", Properties.Settings.Default.CompanyLatLng, latlng2, latlng1));
                 }
             }
             else
             {
                 chromeWebBrowser.Load(string.Format("http://maps.google.com/maps?saddr={0}&daddr={1}&dirflg=d&hl=pl", Properties.Settings.Default.CompanyLatLng, latlng1));
             }
         }
     }
 }
Esempio n. 5
0
 private void btnRemoveTrip_Click(object sender, EventArgs e)
 {
     BusinessClasses.TravelsGrid travelsGrid = (BusinessClasses.TravelsGrid)dataGridView1.SelectedRows[0].DataBoundItem;
     BusinessClasses.MenageContext.RemoveTrip(travelsGrid.TripId);
     LoadTravels();
 }