public ActionResult Edit(BusTrip b) { if (ModelState.IsValid) { try { var bus = db.Bus.Single(a => a.ID == b.bus.ID); bus.Driver_name = b.bus.Driver_name; bus.color = b.bus.color; bus.Num_Chairs = b.bus.Num_Chairs; bus.tripid = b.bus.tripid; db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception) { var lines = db.trips.ToList(); b.trip = lines; return(View("Edit", b)); } } else { var lines = db.trips.ToList(); b.trip = lines; return(View("Edit", b)); } }
public void CheckIndex(List <BusTrip> trips, BusTrip trip) { trips = trips.Where(x => x.SlotName.Equals(trip.SlotName)).ToList(); trips.Sort(new StartTimeComparer()); if (trips.First().Equals(trip) && trips.Last().Equals(trip)) { IsFirst = true; IsLast = true; } else if (trips.First().Equals(trip)) { IsFirst = true; IsLast = false; NextTripInSlot = trips.ElementAt(trips.IndexOf(trip) + 1).Location; } else if (trips.Last().Equals(trip)) { IsFirst = false; PreviousTripInSlot = trips.ElementAt(trips.IndexOf(trip) - 1).Location; IsLast = true; } else { IsFirst = false; PreviousTripInSlot = trips.ElementAt(trips.IndexOf(trip) - 1).Location; IsLast = false; NextTripInSlot = trips.ElementAt(trips.IndexOf(trip) + 1).Location; } }
public ActionResult Add_New(BusTrip bt) { if (ModelState.IsValid) { try { var buses = db.trips.Where(c => c.id == bt.bus.tripid).SingleOrDefault(); buses.num_buses += 1; db.Bus.Add(bt.bus); db.SaveChanges(); return(Json(new { result = 1 })); } catch (Exception) { var lines = db.trips.ToList(); bt.trip = lines; return(View("Add_New", bt)); } } else { var lines = db.trips.ToList(); bt.trip = lines; return(Json(new { result = 0 })); } }
public int SaveBusTrip(BusTrip trip) { trip.owner = Ultis.Settings.SessionUserId; if (trip.tableID != 0) { return(database.Update(trip)); } else { return(database.Insert(trip)); } }
public ActionResult Add_New() { if (Session["Role"].ToString() != "Admin") { return(RedirectToAction("login", "User")); } else { var lines = db.trips.ToList(); BusTrip bt = new BusTrip() { trip = lines }; return(View(bt)); } }
async void SaveOfflineTrip(string startEnd) { try { BusTrip busTrip; var trip = App.Database.GetBusTrip(); if (trip == null || trip.EndTime != null) { busTrip = new BusTrip(); Guid randomID = Guid.NewGuid(); busTrip.Id = randomID.ToString(); busTrip.DriverId = Ultis.Settings.SessionUserItem.DriverId; busTrip.TruckId = Ultis.Settings.SessionUserItem.TruckId; busTrip.Uploaded = false; Ultis.Settings.TripRecordID = randomID.ToString(); } else { busTrip = trip; } var location = await Geolocation.GetLastKnownLocationAsync(); switch (startEnd) { case "Start": busTrip.StartTime = DateTime.Now; busTrip.StartGeoLoc = location.Latitude.ToString() + "," + location.Longitude.ToString(); break; case "End": busTrip.EndTime = DateTime.Now; busTrip.EndGeoLoc = location.Latitude.ToString() + "," + location.Longitude.ToString(); break; } App.Database.SaveBusTrip(busTrip); } catch (Exception ex) { await DisplayAlert("Error", ex.Message, "OK"); } }
public ActionResult Edit(int?id) { if (Session["Role"].ToString() != "Admin") { return(RedirectToAction("login", "User")); } else { var bus = db.Bus.Single(a => a.ID == id); var lines = db.trips.ToList(); BusTrip bt = new BusTrip { trip = lines, bus = bus }; return(View(bt)); } }
static void Main() { Program program = new Program(); int g = typeof(Hotels).GetProperties() .Select(field => field.Name) .ToList().Count; var hotelsList = new ExcelMapper("bustrips.xlsx").Fetch <Hotels>(); var puls = new ExcelMapper("PUL.xlsx").Fetch <PUL>(); var trips = new ExcelMapper("bustrips.xlsx").Fetch <BusTrip>(); var slots = new ExcelMapper("Assignments.xlsx").Fetch <Slot>(); var volunteers = new ExcelMapper("TLBC.xlsx").Fetch <Volunteer>(); var busIds = new ExcelMapper("BUSID.xlsx").Fetch <BusID>(); trips = trips.Where(x => !x.SlotName.ToUpper().Contains("CONV".ToUpper())); List <string> locationsDone = new List <string>(); program.StartWordApp(); string currentLocation; string currentDay; foreach (BusTrip busTrip in trips) { int water = 0; int startBuses = 0; int midBuses = 0; currentLocation = busTrip.Location; // Slot may have been done before if (locationsDone.Contains(currentLocation)) { continue; } List <BusTrip> locationTrips = trips.Where(x => x.Location.Equals(currentLocation)).ToList(); locationTrips.Sort(new StartTimeComparer()); currentDay = locationTrips.First().StartTimeDate; Console.WriteLine($"Location: {currentLocation}"); Console.WriteLine($"Day: {currentDay}"); program.OpenDocument("input.docx"); program.ActivateDocument(); program.CopyTable(); int busIndex = 1; for (int i = 0; i < locationTrips.Count; i++) { if (!currentDay.Equals(locationTrips[i].StartTimeDate)) { program.HeaderFindAndReplace("{TOTALWATER}", water.ToString()); program.HeaderFindAndReplace("{BUSCOUNT}", busIndex - 1); program.HeaderFindAndReplace("{FIRSTBUSCOUNT}", startBuses); program.HeaderFindAndReplace("{MIDBUSCOUNT}", midBuses); var filename1 = $"{currentLocation}_{currentDay.Replace("/", "")}"; program.SaveAs(filename1); program.SaveAsPDF(filename1); program.CloseDocument(); var emailThese1 = slots.Where(y => y.Location.Contains(currentLocation) && y.StartDate.Equals(currentDay) && y.Usage.Equals("AT_Pick")).ToList(); if (!emailThese1.Any()) { program.SendEmail("*****@*****.**", "At@Jw2019", "*****@*****.**", "Fail to send Assignment", $"Não foi possível encontrar assignments para a localização e dia: {currentLocation} / {currentDay}", $"{filename1}.pdf"); } emailThese1.ForEach(y => { program.SendEmail("*****@*****.**", "At@Jw2019", y.Email, $"Relatório Diário de Pickup {currentDay}", program.GetEmailBody(currentDay), $"{filename1}.pdf"); }); program.DeleteFile(filename1 + ".pdf"); program.DeleteFile(filename1 + ".docx"); currentDay = locationTrips[i].StartTimeDate; Console.WriteLine($"Day: {currentDay}"); busIndex = 1; water = 0; startBuses = 0; midBuses = 0; program.OpenDocument("input.docx"); program.ActivateDocument(); program.CopyTable(); } if (busIndex > 1) { program.PasteTable(); } if (((busIndex % 3) == 0) && !busIndex.Equals(program.CountTotalBus(locationTrips[i].StartTime, locationTrips))) { program.Document.Words.Last.InsertBreak(Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak); } BusTrip x = locationTrips.ElementAt(i); if (busIndex == 1) { program.HeaderFindAndReplace("{LOCATION}", program.GetNameByCode(puls.ToList(), x.Location)); program.HeaderFindAndReplace("{DATE}", x.StartTimeDate); program.FooterFindAndReplace("{LOCATION}", program.GetNameByCode(puls.ToList(), x.Location)); program.FooterFindAndReplace("{DATE}", x.StartTimeDate); } program.FindAndReplace("{LOCATION}", program.GetAddressByCode(puls.ToList(), x.Location)); program.FindAndReplace("{SLOTNAME}", x.SlotName); var busid = busIds.FirstOrDefault(y => y.SlotName.Equals(x.SlotName)); program.FindAndReplace("{BUSID}", busid == null ? "N/A" : busid.BUSID); program.FindAndReplace("{ACTIVITYNAME}", x.ActivityName); program.FindAndReplace("{LEAVETIME}", x.StartTime.ToString("dd/MM/yyyy HH:mm")); program.FindAndReplace("{DELEGATES}", x.Delegates); program.FindAndReplace("{ACTIVITYNAME}", x.ActivityName); program.FindAndReplace("{BUSINDEX}", busIndex); program.FindAndReplace("{OBS}", x.Obs); program.FindAndReplace("{TOURLEADER}", program.GetTLBySlot(slots.ToList(), volunteers.ToList(), x.SlotName)); program.FindAndReplace("{BUSCAPTAIN}", program.GetBCBySlot(slots.ToList(), volunteers.ToList(), x.SlotName)); Hotels hotel = hotelsList.ElementAt(trips.ToList().IndexOf(x)); string hotelsCell = String.Empty; Type fieldsType = typeof(Hotels); PropertyInfo[] fields = fieldsType.GetProperties(); for (int j = 0; j < fields.Length; j++) { if (((int)fields[j].GetValue(hotel)) > 0) { hotelsCell += String.IsNullOrEmpty(hotelsCell) ? String.Empty : ",\n"; hotelsCell += $"{program.GetNameByCode(puls.ToList(), fields[j].Name)} ({fields[j].GetValue(hotel)})"; } } program.FindAndReplace("{HOTEL}", hotelsCell); program.CheckIndex(trips.ToList(), locationTrips[i]); if (program.IsFirst && program.IsLast) { startBuses++; water += 6; program.FindAndReplace("{HASWATER}", "Sim"); program.FindAndReplace("{PREVIOUSLOCATION}", "Início de Trajeto"); program.FindAndReplace("{NEXTLOCATION}", "Última Paragem"); } else if (program.IsFirst) { startBuses++; water += 6; program.FindAndReplace("{HASWATER}", "Sim"); program.FindAndReplace("{PREVIOUSLOCATION}", "Início de Trajeto"); program.FindAndReplace("{NEXTLOCATION}", program.GetNameByCode(puls.ToList(), program.NextTripInSlot)); } else if (program.IsLast) { midBuses++; program.FindAndReplace("{HASWATER}", "Não"); program.FindAndReplace("{NEXTLOCATION}", "Última Paragem"); program.FindAndReplace("{PREVIOUSLOCATION}", program.GetNameByCode(puls.ToList(), program.PreviousTripInSlot)); } else { midBuses++; program.FindAndReplace("{HASWATER}", "Não"); program.FindAndReplace("{PREVIOUSLOCATION}", program.GetNameByCode(puls.ToList(), program.PreviousTripInSlot)); program.FindAndReplace("{NEXTLOCATION}", program.GetNameByCode(puls.ToList(), program.NextTripInSlot)); } busIndex++; } locationsDone.Add(currentLocation); program.HeaderFindAndReplace("{TOTALWATER}", water.ToString()); program.HeaderFindAndReplace("{BUSCOUNT}", busIndex - 1); program.HeaderFindAndReplace("{FIRSTBUSCOUNT}", startBuses); program.HeaderFindAndReplace("{MIDBUSCOUNT}", midBuses); var filename2 = $"{currentLocation}_{currentDay.Replace("/", "")}"; program.SaveAs(filename2); program.SaveAsPDF(filename2); program.CloseDocument(); var emailThese = slots.Where(x => x.Location.Contains(currentLocation) && x.StartDate.Equals(currentDay) && x.Usage.Equals("AT_Pick")).ToList(); if (!emailThese.Any()) { program.SendEmail("*****@*****.**", "At@Jw2019", "*****@*****.**", "Fail to send Assignment", $"Não foi possível encontrar assignments para a localização e dia: {currentLocation} / {currentDay}", $"{filename2}.pdf"); } emailThese.ForEach(x => { program.SendEmail("*****@*****.**", "At@Jw2019", x.Email, $"Relatório Diário de Pickup {currentDay}", program.GetEmailBody(currentDay), $"{filename2}.pdf"); }); program.DeleteFile(filename2 + ".pdf"); program.DeleteFile(filename2 + ".docx"); } //for (int i = 0; i < nomes.Count; i++) //{ // program.OpenDocument("input.docx"); // program.ActivateDocument(); // program.FindAndReplace("{NAME}", nomes.ElementAt(i)); // program.FindAndReplace("{DESIGNACAO}", "Same for everyone"); // program.SaveAs($"Test{i}"); // program.SaveAsPDF($"Test{i}"); // program.CloseDocument(); // program.SendEmail("*****@*****.**", "basquet7GMru", emails.ElementAt(i), "Test", program.GetEmailBody(), $"Test{i}.pdf"); // program.DeleteFile($"Test{i}.pdf"); // program.DeleteFile($"Test{i}.docx"); //} program.QuitWordApp(); }