async void UpdateLogBook(clsTrip data) { try { var content = await CommonFunction.CallWebService(1, data, Ultis.Settings.SessionBaseURI, ControllerUtil.postNewLogRecordURL(), this); clsResponse response = JsonConvert.DeserializeObject <clsResponse>(content); if (response.IsGood) { if (endLogEntry.IsVisible == false) { endLogEntry.IsVisible = true; if (Ultis.Settings.Language.Equals("English")) { await DisplayAlert("Success", "New log record added", "OK"); } else { await DisplayAlert("Berjaya", "Record baru ditambah", "OK"); } endTime.Time = DateTime.Now.TimeOfDay; } else { if (Ultis.Settings.Language.Equals("English")) { await DisplayAlert("Success", "Log Book record updated.", "OK"); } else { await DisplayAlert("Berjaya", "Kemaskini data buku log.", "OK"); } } Ultis.Settings.RefreshListView = "Yes"; imageLinkID = response.Result["LinkId"]; camera_icon.IsEnabled = true; trip.Id = response.Result["Id"]; UploadImage(); } } catch { } }
async void Handle_Tapped(object sender, System.EventArgs e) { var image = sender as Image; switch (image.StyleId) { case "camera_icon": await CommonFunction.StoreImages(offlineLogID, this, "NormalImage"); DisplayImage(); if (!(String.IsNullOrEmpty(imageLinkID))) { UploadImage(); } break; case "confirm_icon": try { clsTrip newTrip = new clsTrip(); if (!(String.IsNullOrEmpty(startLocation.Text)) && !(String.IsNullOrEmpty(startOdometer.Text))) { string startDate_Time = startDate.Date.ToString("yyyy-MM-dd") + "T" + startTime.Time.ToString(); newTrip.StartTime = Convert.ToDateTime(startDate_Time); newTrip.StartOdometer = Convert.ToInt32(startOdometer.Text); newTrip.StartLocationName = startLocation.Text.ToUpper(); newTrip.DriverId = Ultis.Settings.SessionUserItem.DriverId; newTrip.TruckId = Ultis.Settings.SessionUserItem.TruckId; newTrip.StartGeoLoc = ControllerUtil.getPositionAsync(); if (endLogEntry.IsVisible == true) { if (!(String.IsNullOrEmpty(endLocation.Text)) && !(String.IsNullOrEmpty(endOdometer.Text))) { if (Convert.ToInt32(startOdometer.Text) <= Convert.ToInt32(endOdometer.Text)) { string endDate_Time = endDate.Date.Year + "-" + endDate.Date.Month + "-" + endDate.Date.Day + "T" + endTime.Time.ToString(); newTrip.EndTime = Convert.ToDateTime(endDate_Time); newTrip.EndOdometer = Convert.ToInt32(endOdometer.Text); newTrip.EndLocationName = endLocation.Text.ToUpper(); newTrip.Id = trip.Id; newTrip.EndGeoLoc = ControllerUtil.getPositionAsync(); newTrip.LinkId = ""; UpdateLogBook(newTrip); } else { if (Ultis.Settings.Language.Equals("English")) { await DisplayAlert("Error", "End Odometer must more than start odometer.", "OK"); } else { await DisplayAlert("Kesilapan", "Odometer untuk akhir perlu lebih daripada odometer untuk permulaan.", "OK"); } } } else { if (Ultis.Settings.Language.Equals("English")) { await DisplayAlert("Error", "Please fill in all mandatory field.", "OK"); } else { await DisplayAlert("Kesilapan", "Sila mengisikan semua data yang diperlukan oleh permulaan.", "OK"); } } } else { UpdateLogBook(newTrip); } } else { if (Ultis.Settings.Language.Equals("English")) { await DisplayAlert("Error", "Please fill in all mandatory field.", "OK"); } else { await DisplayAlert("Kesilapan", "Sila mengisikan semua data yang diperlukan oleh permulaan.", "OK"); } } } catch (Exception ex) { await DisplayAlert("Error", ex.Message, "OK"); } break; } }
public async void logDefaultValue() { if (existingRecordId != "") { endLogEntry.IsVisible = true; confirm_icon.IsEnabled = true; offlineLogID = existingRecordId; uri = ControllerUtil.getLogInfoURL(existingRecordId); } else { Guid log = Guid.NewGuid(); offlineLogID = log.ToString(); uri = ControllerUtil.getNewLogURL(); } try { var client = new HttpClient(); client.BaseAddress = new Uri(Ultis.Settings.SessionBaseURI); var response = await client.GetAsync(uri); var content = await response.Content.ReadAsStringAsync(); Debug.WriteLine(content); newLogResponse = JsonConvert.DeserializeObject <clsResponse>(content); trip = JObject.Parse(content)["Result"].ToObject <clsTrip>(); startDate.Date = trip.StartTime.Date; startTime.Time = trip.StartTime.TimeOfDay; imageLinkID = trip.LinkId; if (existingRecordId != "") { startOdometer.Text = trip.StartOdometer.ToString(); startLocation.Text = trip.StartLocationName; endOdometer.Text = trip.EndOdometer.ToString(); endLocation.Text = trip.EndLocationName; if (!(String.IsNullOrEmpty(trip.EndTime.ToString()))) { endDate.Date = trip.EndTime.Value.Date; endTime.Time = trip.EndTime.Value.TimeOfDay; } else { endDate.Date = DateTime.Now.Date; endTime.Time = DateTime.Now.TimeOfDay; } } foreach (clsKeyValue location in trip.LocationList) { AutoComplete existingLocation = App.Database.GetAutoCompleteValue(location.Value.ToUpper()); if (existingLocation == null) { existingLocation = new AutoComplete(); } existingLocation.Value = location.Value.ToUpper(); existingLocation.Type = "Location"; App.Database.SaveAutoCompleteAsync(existingLocation); } foreach (clsCaptionValue language in trip.Captions) { string lblCaption = language.Caption; if (lblStart.Text == lblCaption) { lblStart.Text = language.Value; } else if (lblStartDateTime.Text == lblCaption) { lblStartDateTime.Text = language.Value; lblEndDateTime.Text = language.Value; } else if (lblStartOdometer.Hint == lblCaption) { lblStartOdometer.Hint = language.Value; } else if (lblStartFrom.Hint == lblCaption) { lblStartFrom.Hint = language.Value; } else if (lblEnd.Text == lblCaption) { lblEnd.Text = language.Value; } else if (lblEndOdometer.Hint == lblCaption) { lblEndOdometer.Hint = language.Value; } else if (lblEndLocation.Hint == lblCaption) { lblEndLocation.Hint = language.Value; } } List <AutoComplete> locations = new List <AutoComplete>(App.Database.GetAutoCompleteValues("Location")); List <string> locationSuggestion = new List <string>(); for (int i = 0; i < locations.Count; i++) { locationSuggestion.Add(locations[i].Value); } startLocation.DataSource = locationSuggestion; endLocation.DataSource = locationSuggestion; if (!(String.IsNullOrEmpty(imageLinkID))) { camera_icon.IsEnabled = true; } } catch (HttpRequestException) { await DisplayAlert("Unable to connect", "Please try again later", "Ok"); } catch (Exception exception) { await DisplayAlert("Json Error", exception.Message, "Ok"); } }
//search database for pending bus trip and sync to server public static async Task UploadPendingRecord() { try { if (NetworkCheck.IsInternet()) { if (!(String.IsNullOrEmpty(Ultis.Settings.SessionSettingKey))) { //upload bus trip record var pendingBusTrip = App.Database.GetPendingTrip(); List <clsTrip> completeTrips = new List <clsTrip>(); foreach (BusTrip busTrip in pendingBusTrip) { if (busTrip.EndTime != null && busTrip.Uploaded == false) { clsTrip trip = new clsTrip { Id = busTrip.Id, TruckId = busTrip.TruckId, DriverId = busTrip.DriverId, StartTime = busTrip.StartTime, StartOdometer = 0, StartLocationName = "", StartGeoLoc = busTrip.StartGeoLoc, EndTime = busTrip.EndTime, EndOdometer = 0, EndLocationName = "", EndGeoLoc = busTrip.EndGeoLoc, TrxStatus = 5, LinkId = "", LocationList = {}, Captions = {} }; completeTrips.Add(trip); } } if (completeTrips.Count != 0) { var content = await CommonFunction.CallWebService(1, completeTrips, Ultis.Settings.SessionBaseURI, ControllerUtil.postTrips(), null); clsResponse response = JsonConvert.DeserializeObject <clsResponse>(content); if (response.IsGood) { /*foreach (clsTrip uploadedTrip in completeTrips) * { * var completedTrip = App.Database.GetUploadedTrip(uploadedTrip.Id); * * if (completedTrip != null) * { * completedTrip.Uploaded = true; * * App.Database.SaveBusTrip(completedTrip); * } * }*/ App.Database.DeleteBusTrip(); //upload bus ticket record var pendingTicket = App.Database.GetSoldTicket(); List <clsTicket> tickets = new List <clsTicket>(); foreach (SoldTicket soldTicket in pendingTicket) { if (!(String.IsNullOrEmpty(soldTicket.TripId))) { clsTicket ticket = new clsTicket { TrxTime = soldTicket.TrxTime, TruckId = soldTicket.TruckId, DriverId = soldTicket.DriverId, TripId = soldTicket.TripId, RouteId = soldTicket.RouteId, StopId = soldTicket.StopId, TicketType = soldTicket.TicketType, PaymentType = soldTicket.PaymentType, Amount = soldTicket.Amount }; tickets.Add(ticket); } } if (tickets.Count != 0) { var ticket_content = await CommonFunction.CallWebService(1, tickets, Ultis.Settings.SessionBaseURI, ControllerUtil.postTickets(), null); clsResponse ticket_response = JsonConvert.DeserializeObject <clsResponse>(ticket_content); if (ticket_response.IsGood) { /*foreach (clsTicket ticket in tickets) * { * var completeTicket = App.Database.GetUploadedTicket(ticket.); * * if (completeTicket != null) * { * completeTicket.Uploaded = true; * * App.Database.SaveTicketTransaction(completeTicket); * } * }*/ App.Database.DeleteTicket(); var test = App.Database.gettesting(); } } } } } } } catch { } }