/// <summary> /// Initialize the message resoucre by the message xml file /// </summary> /// <param name="filename"></param> /// <remarks> /// Author: PhatLT. FPTSS. /// Created date: 14/02/2011 /// </remarks> public static void InitTitle(string filename) { DataSet ds = new DataSet("GENERAL"); ds.ReadXml(filename); try { DataTable dt = ds.Tables["Titles"]; if (!dt.Columns.Contains("Name") || !dt.Columns.Contains("Value")) { throw new Exception("XML file is not valid."); } DataView vw = dt.DefaultView; vw.Sort = "Name"; clsMessages[] msgs = new clsMessages[vw.Count]; int i = 0; string name = ""; string value = ""; foreach (DataRowView rview in vw) { name = (string)rview["Name"]; value = (string)rview["Value"]; msgs[i] = new clsMessages(name, value); i++; } titles = msgs; } catch (Exception ex) { throw new Exception("XML file is not valid.", ex); } }
public async void CheckLocation(string type) { try { lstmessage.Clear(); if (!HttpRequest.CheckConnection()) { var objUser = App.Database.GetCheckinCheckoutLocation(); using (await MaterialDialog.Instance.LoadingDialogAsync(message: Resx.AppResources.pleaseWait)) { //DependencyService.Get<IProgressBar>().Show(Resx.AppResources.pleaseWait); var request = new GeolocationRequest(GeolocationAccuracy.High); var fakelocation = await Geolocation.GetLocationAsync(request); if (fakelocation != null) { if (fakelocation.IsFromMockProvider) { await DependencyService.Get <IXSnack>().ShowMessageAsync("You are using Fake Location."); return; } } lstmessage = new List <clsMessages>(); if (objUser != null && objUser.Count > 0) { try { foreach (var item in objUser) { var msg = new clsMessages(); try { var locator = CrossGeolocator.Current; if (locator.IsGeolocationAvailable && locator.IsGeolocationEnabled) { var sourceLocation = await locator.GetPositionAsync(TimeSpan.FromSeconds(10)); if (sourceLocation != null) { Location sourceCoordinates = new Location(sourceLocation.Latitude, sourceLocation.Longitude); //LatLongLocation = sourceCoordinates; Location destinationCoordinates = new Location(item.lat, item.lng); LatLongLocation = destinationCoordinates; double distance = Location.CalculateDistance(sourceCoordinates, destinationCoordinates, DistanceUnits.Kilometers); double distanceMeter = distance * 1000; //Radius = distanceMeter; if (distanceMeter < item.radius) { msg.Status = true; //DependencyService.Get<IProgressBar>().Hide(); ////await App.Current.MainPage.DisplayAlert("AttendanceApp", Resx.AppResources.youAreInLocation, Resx.AppResources.ok); //IsUserExist = true; //IsAccordianOpen = !IsAccordianOpen; } else { //DependencyService.Get<IProgressBar>().Hide(); //await DependencyService.Get<IXSnack>().ShowMessageAsync(Resx.AppResources.youAreOutOfLocation); //IsUserExist = false; msg.Status = false; msg.Message = Resx.AppResources.youAreOutOfLocation; } } } else { msg.Status = false; msg.Message = Resx.AppResources.pleaseEnableYourLocationService; //DependencyService.Get<IProgressBar>().Hide(); //await DependencyService.Get<IXSnack>().ShowMessageAsync(Resx.AppResources.pleaseEnableYourLocationService); //return; } } catch (Exception ex) { msg.Status = false; msg.Message = ex.Message; } lstmessage.Add(msg); } } catch (Exception ex) { IsUserExist = false; //DependencyService.Get<IProgressBar>().Hide(); await DependencyService.Get <IXSnack>().ShowMessageAsync(ex.Message); } } else { //DependencyService.Get<IProgressBar>().Hide(); await DependencyService.Get <IXSnack>().ShowMessageAsync("Please checkIn/checkOut atleast first in net connectivity."); } } return; } using (await MaterialDialog.Instance.LoadingDialogAsync(message: Resx.AppResources.pleaseWait)) { //DependencyService.Get<IProgressBar>().Show(Resx.AppResources.pleaseWait); var request = new GeolocationRequest(GeolocationAccuracy.High); var fakelocation = await Geolocation.GetLocationAsync(request); if (fakelocation != null) { if (fakelocation.IsFromMockProvider) { await DependencyService.Get <IXSnack>().ShowMessageAsync("You are using Fake Location."); return; } } App.Database.ClearCheckinCheckoutDetails(); var menuItem = await CommonMethods.GetLocations(); if (menuItem.locationData != null) { foreach (var item in menuItem.locationData) { DBLocationData dbdata = new DBLocationData(); var msg = new clsMessages(); dbdata.lat = item.lat; dbdata.lng = item.lng; dbdata.radius = item.radius; App.Database.SaveCheckinCheckoutLocation(dbdata); try { var locator = CrossGeolocator.Current; if (locator.IsGeolocationAvailable && locator.IsGeolocationEnabled) { var sourceLocation = await locator.GetPositionAsync(TimeSpan.FromSeconds(10)); if (sourceLocation != null) { Location sourceCoordinates = new Location(sourceLocation.Latitude, sourceLocation.Longitude); //LatLongLocation = sourceCoordinates; Location destinationCoordinates = new Location(item.lat, item.lng); LatLongLocation = destinationCoordinates; double distance = Location.CalculateDistance(sourceCoordinates, destinationCoordinates, DistanceUnits.Kilometers); double distanceMeter = distance * 1000; //Radius = distanceMeter; if (distanceMeter < item.radius) { //DependencyService.Get<IProgressBar>().Hide(); //IsUserExist = true; //IsAccordianOpen = !IsAccordianOpen; msg.Status = true; } else { //DependencyService.Get<IProgressBar>().Hide(); //await DependencyService.Get<IXSnack>().ShowMessageAsync(Resx.AppResources.youAreOutOfLocation); //IsUserExist = false; msg.Status = false; msg.Message = Resx.AppResources.youAreOutOfLocation; } } } else { msg.Status = false; msg.Message = Resx.AppResources.pleaseEnableYourLocationService; //DependencyService.Get<IProgressBar>().Hide(); //await DependencyService.Get<IXSnack>().ShowMessageAsync(Resx.AppResources.pleaseEnableYourLocationService); //return; } } catch (Exception ex) { msg.Status = false; msg.Message = ex.Message; //DependencyService.Get<IProgressBar>().Hide(); //IsUserExist = false; //await DependencyService.Get<IXSnack>().ShowMessageAsync(ex.Message); } lstmessage.Add(msg); } } else { IsUserExist = false; //DependencyService.Get<IProgressBar>().Hide(); await DependencyService.Get <IXSnack>().ShowMessageAsync(Resx.AppResources.ErrorLoadingData); } } } catch (Exception ex) { IsUserExist = false; //DependencyService.Get<IProgressBar>().Hide(); await DependencyService.Get <IXSnack>().ShowMessageAsync(ex.Message); } finally { //DependencyService.Get<IProgressBar>().Hide(); if (lstmessage != null && lstmessage.Count > 0) { if (lstmessage.Any(x => x.Status)) { IsUserExist = true; MessagingCenter.Send <string>(type, "NotifyMsg"); } else { foreach (var item in lstmessage) { await DependencyService.Get <IXSnack>().ShowMessageAsync(item.Message); } } } } }
protected override async void OnResume() { lstMessage = new List <clsMessages>(); var snackbarConfiguration = new MaterialSnackbarConfiguration() { TintColor = Color.White, MessageTextColor = HttpRequest.CheckConnection() ? Color.White : Color.Red }; if (!HttpRequest.CheckConnection()) { await DependencyService.Get <IXSnack>().ShowMessageAsync("You are not connected to internet."); } else { await DependencyService.Get <IXSnack>().ShowMessageAsync("You are connected to internet."); DependencyService.Get <IProgressBar>().Show(Resx.AppResources.pleaseWait); var data = App.database.GetBooking(); if (data != null) { if (data.Count > 0) { try { await DependencyService.Get <IXSnack>().ShowMessageAsync("Syncing Data. Please wait.."); foreach (var item in data) { clsMessages messagedata = new clsMessages(); var locjsonStringOfflone = Newtonsoft.Json.JsonConvert.DeserializeObject <LocationData>(item.Location); var locationData = new LocationData() { lat = locjsonStringOfflone.lat, lng = locjsonStringOfflone.lng, radius = locjsonStringOfflone.radius }; var locjsonString = Newtonsoft.Json.JsonConvert.SerializeObject(locationData); var postData = new List <BookingModel>() { new BookingModel() { DateTime = item.DateTime, Direction = item.Direction, Location = locjsonString, HappinessOption = item.HappinessOption, ReasonCode = item.ReasonCode } }; var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(postData); var loginInfo = await CommonMethods.BookingAttendance(jsonString); if (loginInfo.Status) { messagedata.Status = loginInfo.Status; messagedata.Message = loginInfo.Message; App.database.ClearBookingBasedOnId(item); //await MaterialDialog.Instance.SnackbarAsync(message: "Data successfully synced to the server.", //msDuration: MaterialSnackbar.DurationLong); } else { messagedata.Status = loginInfo.Status; messagedata.Message = loginInfo.Message; DependencyService.Get <IProgressBar>().Hide(); //await MaterialDialog.Instance.SnackbarAsync(message: "Error syncing data to the server.", // msDuration: MaterialSnackbar.DurationLong); } lstMessage.Add(messagedata); } } catch (Exception ex) { DependencyService.Get <IProgressBar>().Hide(); await DependencyService.Get <IXSnack>().ShowMessageAsync(ex.Message); } finally { DependencyService.Get <IProgressBar>().Hide(); if (lstMessage.Any(x => x.Status == false)) { await DependencyService.Get <IXSnack>().ShowMessageAsync("Error syncing data to the server."); } else { await DependencyService.Get <IXSnack>().ShowMessageAsync("Data successfully synced to the server."); } } } else { DependencyService.Get <IProgressBar>().Hide(); Device.BeginInvokeOnMainThread(async() => { await DependencyService.Get <IXSnack>().ShowMessageAsync("There is no record stored locally."); }); } } else { DependencyService.Get <IProgressBar>().Hide(); Device.BeginInvokeOnMainThread(async() => { await DependencyService.Get <IXSnack>().ShowMessageAsync(Resx.AppResources.ErrorLoadingData); }); } } }
/// <summary> /// Initialize the message resoucre by the message xml file /// </summary> /// <param name="filename"></param> /// <remarks> /// Author: PhatLT. FPTSS. /// Created date: 14/02/2011 /// </remarks> public static void InitTitle(string filename) { DataSet ds = new DataSet("GENERAL"); ds.ReadXml(filename); try { DataTable dt = ds.Tables["Titles"]; if(!dt.Columns.Contains("Name") || !dt.Columns.Contains("Value")) throw new Exception("XML file is not valid."); DataView vw = dt.DefaultView; vw.Sort = "Name"; clsMessages[]msgs = new clsMessages[vw.Count]; int i = 0; string name = ""; string value = ""; foreach(DataRowView rview in vw) { name = (string)rview["Name"]; value = (string)rview["Value"]; msgs[i] = new clsMessages(name, value); i ++ ; } titles = msgs; } catch(Exception ex) { throw new Exception("XML file is not valid.", ex); } }