示例#1
0
        private async void OnSyncCompleted()
        {
            IsBusy = false;

            try
            {
                AppSettings.ReloadSetting();
                SyncHelper.Instance.StartAutoSync(15);
            }
            catch (Exception ex)
            {
                await CoreMethods.DisplayAlert(TranslateExtension.GetValue("error"), ex.Message, TranslateExtension.GetValue("error"));

                Debug.WriteLine("ERROR:" + ex.Message);
            }
            //TODO find out reason
            if (Device.RuntimePlatform == Device.iOS && Device.Idiom == TargetIdiom.Tablet)
            {
                if (CrossDeviceInfo.Current.VersionNumber.Major >= 13)
                {
                    Application.Current.MainPage = new NavigationContainer(ViewModelResolver.ResolveViewModel <ViewModels.Login.LoginViewModel>())
                    {
                        BarBackgroundColor = Color.FromHex("#2196F3"),
                        BarTextColor       = Color.White
                    };
                    return;
                }
            }

            Application.Current.MainPage = new MainPage();
        }
示例#2
0
        public static async Task <Stream> TakeVideoStreamAsync(string videoName = null)
        {
            try
            {
                Stream stream = null;

                if (await CameraHelper.CanTakePhoto())
                {
                    var name = videoName ?? ("VID_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".mp4");

                    var file = await CrossMedia.Current.TakeVideoAsync(new StoreVideoOptions
                    {
                        Directory = "Videos",
                        Name      = name
                    });

                    if (file == null)
                    {
                        return(null);
                    }

                    stream = file.GetStream();

                    file.Dispose();
                }

                return(stream);
            }
            catch (Exception e)
            {
                await Application.Current.MainPage.DisplayAlert(TranslateExtension.GetValue("error"), e.GetBaseException().Message, TranslateExtension.GetValue("ok"));

                return(null);
            }
        }
示例#3
0
        public static async Task <Stream> PickPhotoStreamAsync()
        {
            try
            {
                Stream result = null;

                if (await CameraHelper.CanTakePhoto())
                {
                    var file = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions
                    {
                        PhotoSize          = PhotoSize.MaxWidthHeight,
                        MaxWidthHeight     = 1600,
                        CompressionQuality = 85
                    });

                    if (file == null)
                    {
                        return(null);
                    }

                    result = file.GetStream();

                    file.Dispose();
                }

                return(result);
            }
            catch (Exception e)
            {
                await Application.Current.MainPage.DisplayAlert(TranslateExtension.GetValue("error"), e.GetBaseException().Message, TranslateExtension.GetValue("ok"));

                return(null);
            }
        }
示例#4
0
        public static async Task <Stream> PickVideoStreamAsync()
        {
            try
            {
                Stream stream = null;

                if (await CameraHelper.CanTakePhoto())
                {
                    var file = await CrossMedia.Current.PickVideoAsync();

                    if (file == null)
                    {
                        return(null);
                    }

                    stream = file.GetStream();

                    file.Dispose();
                }

                return(stream);
            }
            catch (Exception e)
            {
                await Application.Current.MainPage.DisplayAlert(TranslateExtension.GetValue("error"), e.GetBaseException().Message, TranslateExtension.GetValue("ok"));

                return(null);
            }
        }
示例#5
0
        public async Task <string> ScanQrCode()
        {
            try
            {
                var result = await new MobileBarcodeScanner()
                {
                    TopText = "Scan Code"
                }.Scan(new MobileBarcodeScanningOptions
                {
                    PossibleFormats = new List <BarcodeFormat>
                    {
                        BarcodeFormat.QR_CODE
                    },
                    AutoRotate = false,
                    UseFrontCameraIfAvailable = false,
                    TryHarder = true
                });

                if (result != null)
                {
                    CrossSimpleAudioPlayer.Current.Load("beep.wav");
                    CrossSimpleAudioPlayer.Current.Play();

                    return(result.Text);
                }

                return(null);
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert(TranslateExtension.GetValue("alert_title_error"), ex.Message, TranslateExtension.GetValue("alert_message_ok"));

                return(null);
            }
        }
示例#6
0
        public static async Task <string> PickPhotoPathAsync()
        {
            try
            {
                var path = string.Empty;

                if (await CameraHelper.CanTakePhoto())
                {
                    var file = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions
                    {
                        PhotoSize          = PhotoSize.MaxWidthHeight,
                        MaxWidthHeight     = 1600,
                        CompressionQuality = 85
                    });

                    if (file == null)
                    {
                        return(null);
                    }

                    path = file.Path;

                    file.Dispose();
                }

                return(path);
            }
            catch (Exception e)
            {
                await Application.Current.MainPage.DisplayAlert(TranslateExtension.GetValue("alert_title_error"), e.GetBaseException().Message, TranslateExtension.GetValue("alert_message_ok"));

                return(null);
            }
        }
示例#7
0
        private void InitMenu()
        {
            menuItems = new List <HomeMenuItem>
            {
                new HomeMenuItem {
                    Id = MenuItemType.Interventions, Title = TranslateExtension.GetValue("home_menu_title_interventions"), Icon = "ic_menu_interventions_black.png"
                }
            };

            if (AppSettings.MenuShowNonAssignedIntervention)
            {
                menuItems.Add(new HomeMenuItem {
                    Id = MenuItemType.InterventionsNotAssigned, Title = TranslateExtension.GetValue("home_menu_title_interventions_not_assigned"), Icon = "ic_menu_interventions_not_assigned_black.png"
                });
            }

            if (AppSettings.IsAdmin || AppSettings.IsModerator)
            {
                menuItems.Add(new HomeMenuItem {
                    Id = MenuItemType.Quote, Title = TranslateExtension.GetValue("home_menu_title_quote"), Icon = "ic_local_atm_black.png"
                });
                menuItems.Add(new HomeMenuItem {
                    Id = MenuItemType.Invoice, Title = TranslateExtension.GetValue("home_menu_title_invoice"), Icon = "ic_local_atm_black.png"
                });
                //menuItems.Add(new HomeMenuItem { Id = MenuItemType.Invoice, Title = TranslateExtension.GetValue("home_menu_title_invoice"), Icon = "ic_assignment_black.png" });
            }

            if (AppSettings.IsAdmin || AppSettings.IsModerator || AppSettings.MenuShowClientAddress)
            {
                menuItems.Add(new HomeMenuItem {
                    Id = MenuItemType.Customers, Title = TranslateExtension.GetValue("home_menu_title_customers"), Icon = "ic_menu_customers_black.png"
                });
                menuItems.Add(new HomeMenuItem {
                    Id = MenuItemType.Addresses, Title = TranslateExtension.GetValue("home_menu_title_addresses"), Icon = "ic_menu_addresses_black.png"
                });
            }

            menuItems.AddRange(new List <HomeMenuItem>()
            {
                new HomeMenuItem {
                    Id = MenuItemType.Messages, Title = TranslateExtension.GetValue("home_menu_title_messages"), Icon = "ic_menu_messages_black.png"
                },
                new HomeMenuItem {
                    Id = MenuItemType.Tracking, Title = TranslateExtension.GetValue("home_menu_title_tracking"), Icon = "ic_menu_tracking_black.png"
                },
                new HomeMenuItem {
                    Id = MenuItemType.Settings, Title = TranslateExtension.GetValue("home_menu_title_settings"), Icon = "ic_menu_settings_black.png"
                },
                new HomeMenuItem {
                    Id = MenuItemType.About, Title = TranslateExtension.GetValue("home_menu_title_about"), Icon = "ic_menu_info_black.png"
                },
                new HomeMenuItem {
                    Id = MenuItemType.LogOut, Title = TranslateExtension.GetValue("home_menu_title_log_out"), Icon = "ic_menu_log_out_black.png"
                }
            });

            ListViewMenu.ItemsSource = null;
            ListViewMenu.ItemsSource = menuItems;
        }
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     try
     {
         return(TranslateExtension.GetValue((string)value));
     }
     catch
     {
         return(default);
示例#9
0
        private async Task LogOut()
        {
            if (await DisplayAlert(TranslateExtension.GetValue("alert_title_log_out"), TranslateExtension.GetValue("alert_message_log_out_confirm"), TranslateExtension.GetValue("alert_message_yes"), TranslateExtension.GetValue("alert_message_no")))
            {
                Settings.LoggedIn = false;

                Application.Current.MainPage = new NavigationContainer(ViewModelResolver.ResolveViewModel <LoginViewModel>())
                {
                    BarBackgroundColor = Color.DodgerBlue,
                    BarTextColor       = Color.White
                };
            }
        }
示例#10
0
 private async void NavigateToDetail(HomeMenuItem sender, TaskCompletionSource <bool> tcs)
 {
     try
     {
         if (sender.TargetType != null)
         {
             await CoreMethods.PushViewModel(sender.TargetType, false);
         }
     }
     catch (Exception ex)
     {
         await CoreMethods.DisplayAlert(TranslateExtension.GetValue("error"), ex.Message, TranslateExtension.GetValue("ok"));
     }
     finally
     {
         tcs.SetResult(true);
     }
 }
示例#11
0
        private async void OnSyncCompleted()
        {
            IsBusy = false;

            try
            {
                AppSettings.ReloadSetting();

                SyncHelper.Instance.StartAutoSync(15);
            }
            catch (Exception ex)
            {
                await CoreMethods.DisplayAlert(TranslateExtension.GetValue("error"), ex.Message, TranslateExtension.GetValue("error"));

                Debug.WriteLine("ERROR:" + ex.Message);
            }

            Application.Current.MainPage = new MainPage();
        }
示例#12
0
        public static async Task <Stream> TakePhotoStreamAsync(string imageName = null)
        {
            try
            {
                Stream result = null;

                if (await CameraHelper.CanTakePhoto())
                {
                    var name = imageName ?? ("IMG_" + DateTime.Now.ToString("yyyyMMddhhmmss"));

                    var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                    {
                        PhotoSize          = PhotoSize.Medium,
                        MaxWidthHeight     = 800,
                        DefaultCamera      = CameraDevice.Rear,
                        SaveToAlbum        = false,
                        CompressionQuality = 65,
                        Directory          = "Organilog",
                        Name = name
                    });

                    if (file == null)
                    {
                        return(null);
                    }

                    result = file.GetStreamWithImageRotatedForExternalStorage();

                    file.Dispose();

                    //System.GC.Collect();
                }

                return(result);
            }
            catch (Exception e)
            {
                await Application.Current.MainPage.DisplayAlert(TranslateExtension.GetValue("alert_title_error"), e.GetBaseException().Message, TranslateExtension.GetValue("alert_message_ok"));

                return(null);
            }
        }
示例#13
0
        private void GetHostDetail()
        {
            if (IsBusy || !ConnectivityHelper.IsNetworkAvailable())
            {
                return;
            }

            IsBusy = true;
            Task.Run(async() =>
            {
                return(await databaseService.GetHostDetails(scannedToken));
            }).ContinueWith(task => Device.BeginInvokeOnMainThread(() =>
            {
                IsBusy = false;
                if (task.Status == TaskStatus.RanToCompletion)
                {
                    if (task.Result != null)
                    {
                        if (task.Result.Success)
                        {
                            OnLogInSuccess(task.Result.Host);
                        }
                        else if (!string.IsNullOrWhiteSpace(task.Result.Message))
                        {
                            CoreMethods.DisplayAlert("", task.Result.Message, TranslateExtension.GetValue("ok"));
                        }
                        else
                        {
                            CoreMethods.DisplayAlert("Request Fail", "Property not found", TranslateExtension.GetValue("ok"));
                        }
                    }
                    else
                    {
                        CoreMethods.DisplayAlert("", TranslateExtension.GetValue("dialog_message_server_error"), TranslateExtension.GetValue("ok"));
                    }
                }
                else if (task.IsFaulted)
                {
                    CoreMethods.DisplayAlert(TranslateExtension.GetValue("error"), task.Exception?.GetBaseException().Message, TranslateExtension.GetValue("ok"));
                }
            }));
        }
示例#14
0
        private async Task LogOut()
        {
            if (await DisplayAlert(TranslateExtension.GetValue("alert_title_log_out"), TranslateExtension.GetValue("alert_message_log_out_confirm"), TranslateExtension.GetValue("alert_message_yes"), TranslateExtension.GetValue("alert_message_no")))
            {
                Settings.RemoveCurrentUserName();
                Settings.RemoveCurrentPassword();

                Settings.RemoveCurrentUser();

                Settings.RemoveLoggedIn();
                //Stupid changed. it should remove everything
                //Settings.ClearEverything();

                Application.Current.MainPage = new NavigationContainer(ViewModelResolver.ResolveViewModel <ViewModels.Login.LoginViewModel>())
                {
                    BarBackgroundColor = Color.DodgerBlue,
                    BarTextColor       = Color.White
                };
            }
        }
        public static bool IsNetworkAvailable(bool showAlert = true)
        {
            if (!CrossConnectivity.IsSupported)
            {
                return(true);
            }

            if (!CrossConnectivity.Current.IsConnected)
            {
                if (showAlert)
                {
                    //You are offline, notify the user
                    Application.Current.MainPage?.DisplayAlert("Network", TranslateExtension.GetValue("alert_no_internt_message"), "OK");
                }

                return(false);
            }

            return(true);
        }
示例#16
0
        public async Task StartScan(MobileBarcodeScanningOptions options = null)
        {
            try
            {
                var scanner = new MobileBarcodeScanner()
                {
                    TopText = "Scan Code"
                };
                scanner.ScanContinuously(options ?? new MobileBarcodeScanningOptions
                {
                    PossibleFormats = new List <BarcodeFormat>
                    {
                        BarcodeFormat.EAN_8,
                        BarcodeFormat.EAN_13,
                        BarcodeFormat.CODE_39,
                        BarcodeFormat.CODE_128,
                        BarcodeFormat.QR_CODE
                    },
                    AutoRotate = false,
                    UseFrontCameraIfAvailable = false,
                    TryHarder = true
                }, (result) =>
                {
                    CrossSimpleAudioPlayer.Current.Load("beep.wav");
                    CrossSimpleAudioPlayer.Current.Play();

                    OnScanned?.Invoke(this, result.Text);
                    MessagingCenter.Send(this, MessageKey.BARCODE_SCANNED, result.Text);
                });

                Device.StartTimer(TimeSpan.FromSeconds(3), () =>
                {
                    scanner.AutoFocus();
                    return(true);
                });
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert(TranslateExtension.GetValue("alert_title_error"), ex.Message, TranslateExtension.GetValue("alert_message_ok"));
            }
        }
示例#17
0
        private void RenderPicker()
        {
            if (string.IsNullOrWhiteSpace(Unite.TypeStr))
            {
                RenderEntry();
                return;
            }

            var stk = new StackLayout()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Spacing           = 0
            };

            var title = new Label()
            {
                FontSize  = 14,
                Text      = Unite.Name,
                TextColor = Color.Black
            };

            stk.Children.Add(title);

            var input = new Picker()
            {
                Title              = TranslateExtension.GetValue("select"),
                FontSize           = 14,
                TextColor          = Color.Black,
                ItemDisplayBinding = new Binding("Value")
            };

            input.SetBinding(Picker.ItemsSourceProperty, new Binding("UniteItems", BindingMode.TwoWay, source: Unite));
            input.SelectedIndexChanged += Input_SelectedIndexChanged;
            if (!string.IsNullOrWhiteSpace(Unite.Value) && Unite.UniteItems.Find(ui => ui.Value.Equals(Unite.Value)) is UniteItem uniteItem)
            {
                input.SelectedItem = uniteItem;
            }
            stk.Children.Add(input);

            Content = stk;
        }
示例#18
0
        public static async Task <string> TakePhotoPathAsync(string imageName = null)
        {
            try
            {
                var path = string.Empty;

                if (await CameraHelper.CanTakePhoto())
                {
                    var       name = imageName ?? ("IMG_" + DateTime.Now.ToString("yyyyMMddhhmmss"));
                    MediaFile file = null;

                    file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                    {
                        PhotoSize          = PhotoSize.MaxWidthHeight,
                        MaxWidthHeight     = 1600,
                        DefaultCamera      = CameraDevice.Rear,
                        SaveToAlbum        = false,
                        CompressionQuality = 85,
                        Directory          = "Kamooni",
                        Name = name
                    });

                    if (file == null)
                    {
                        return(null);
                    }

                    path = file.Path;

                    //file.Dispose();
                }

                return(path);
            }
            catch (Exception e)
            {
                await Application.Current.MainPage.DisplayAlert(TranslateExtension.GetValue("error"), e.GetBaseException().Message, TranslateExtension.GetValue("ok"));

                return(null);
            }
        }
示例#19
0
        public async static Task <string> ScanSerial(bool useFrontCamera = false, MobileBarcodeScanningOptions options = null)
        {
            try
            {
                var result = await new MobileBarcodeScanner()
                {
                    TopText = "Scan Code"
                }.Scan(options ?? new MobileBarcodeScanningOptions
                {
                    PossibleFormats = new List <BarcodeFormat>
                    {
                        BarcodeFormat.EAN_8,
                        BarcodeFormat.EAN_13,
                        BarcodeFormat.CODE_39,
                        BarcodeFormat.CODE_128
                    },
                    AutoRotate = false,
                    UseFrontCameraIfAvailable = useFrontCamera,
                    TryHarder        = true,
                    DisableAutofocus = false
                });

                if (result != null)
                {
                    CrossSimpleAudioPlayer.Current.Load("beep.wav");
                    CrossSimpleAudioPlayer.Current.Play();
                    return(result.Text);
                }

                return(null);
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert(TranslateExtension.GetValue("error"), ex.Message, TranslateExtension.GetValue("ok"));

                return(null);
            }
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            switch (value)
            {
            case 1:
                return(TranslateExtension.GetValue("LOW"));

            case 2:
                return(TranslateExtension.GetValue("NORMAL"));

            case 3:
                return(TranslateExtension.GetValue("HIGH"));

            case 4:
                return(TranslateExtension.GetValue("URGENT"));

            case 5:
                return(TranslateExtension.GetValue("IMMEDIATE"));

            default:
                return("");
            }
        }
示例#21
0
        private async void SaveMasterMenu(object sender, TaskCompletionSource <bool> tcs)
        {
            try
            {
                var current = LocalDb.Table <HomeMenuItem>().ToList();

                LocalDb.DeleteAll <HomeMenuItem>();

                foreach (var menu in MasterMenus)
                {
                    if (current.ToList().Find(m => m.Id == menu.Id) is HomeMenuItem menuItem)
                    {
                        menuItem.Title = menu.Title;
                        menuItem.Hide  = menu.Hide;
                    }
                }

                foreach (var menu in current)
                {
                    LocalDb.Insert(new HomeMenuItem {
                        Id = menu.Id, Title = menu.Title, Icon = menu.Icon, Hide = menu.Hide
                    });
                }

                MessagingCenter.Send(this, MessageKey.HOME_MENUS_CHANGED);

                await CoreMethods.PopViewModel();

                tcs.SetResult(true);
            }
            catch (Exception ex)
            {
                await CoreMethods.DisplayAlert(TranslateExtension.GetValue("error"), ex.GetBaseException().Message, TranslateExtension.GetValue("ok"));

                tcs.SetResult(true);
            }
        }
        private void NewTermsConditions(object sender)
        {
            if (IsBusy || !ConnectivityHelper.IsNetworkAvailable())
            {
                return;
            }

            Task.Run(async() =>
            {
                return(await termsConditionsService.NewTermsConditions(Host));
            }).ContinueWith(task => Device.BeginInvokeOnMainThread(() =>
            {
                if (task.Status == TaskStatus.RanToCompletion)
                {
                    if (task.Result != null)
                    {
                        if (task.Result.Success)
                        {
                            CoreMethods.DisplayAlert("Update Successfully", task.Result.Message, TranslateExtension.GetValue("ok"));
                            CoreMethods.PopViewModel();
                        }
                        else
                        {
                            CoreMethods.DisplayAlert("Update Unsuccessfully", task.Result.Message, TranslateExtension.GetValue("ok"));
                        }
                    }
                    else
                    {
                        CoreMethods.DisplayAlert("Update Unsuccessfully", TranslateExtension.GetValue("dialog_message_server_error"), TranslateExtension.GetValue("ok"));
                    }
                }
                else if (task.IsFaulted)
                {
                    CoreMethods.DisplayAlert(TranslateExtension.GetValue("error"), task.Exception?.GetBaseException().Message, TranslateExtension.GetValue("ok"));
                }
            }));
        }
示例#23
0
        public static async Task <bool> CanTakePhoto()
        {
            var cameraStatus = await PermissionsHelper.CheckPermissions(Permission.Camera);

            if (!cameraStatus)
            {
                await Application.Current.MainPage.DisplayAlert(Permission.Camera.ToString() + " Denied", "Unable to take photos.", TranslateExtension.GetValue("ok"));

                return(false);
            }

            var storageStatus = await PermissionsHelper.CheckPermissions(Permission.Storage);

            if (!storageStatus)
            {
                await Application.Current.MainPage.DisplayAlert(Permission.Storage.ToString() + " Denied", "Unable to take photos.", TranslateExtension.GetValue("ok"));

                return(false);
            }

            await CrossMedia.Current.Initialize();

            if (!CrossMedia.Current.IsCameraAvailable)
            {
                await Application.Current.MainPage.DisplayAlert("No Camera", "No camera available.", TranslateExtension.GetValue("ok"));

                return(false);
            }

            return(true);
        }
示例#24
0
        public static async Task <bool> IsGeolocationAvailable()
        {
            if (!await PermissionsHelper.CheckPermissions(Permission.Location))
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    Application.Current?.MainPage?.DisplayAlert("Location", "Location permission is denied. Please go into Settings and turn on Location for the app.", TranslateExtension.GetValue("ok"));
                });
                return(false);
            }

            if (!CrossGeolocator.IsSupported)
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    Application.Current?.MainPage?.DisplayAlert("Location", "Location is not supported.", TranslateExtension.GetValue("ok"));
                });
                return(false);
            }

            if (!CrossGeolocator.Current.IsGeolocationAvailable)
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    Application.Current?.MainPage?.DisplayAlert("Location", "Location is not available.", TranslateExtension.GetValue("ok"));
                });
                return(false);
            }

            return(IsGeolocationEnabled());
        }
        public Task <Intervention> GetRelations(Intervention intervention)
        {
            if (intervention == null)
            {
                return(Task.FromResult(intervention));
            }

            intervention.User = App.LocalDb.Table <User>().ToList().FirstOrDefault(user => user.UserId == CurrentUser.Id && ((intervention.FkUserServerlId > 0 && intervention.FkUserServerlId == user.ServerId) || (!intervention.FkUserAppId.Equals(Guid.Empty) && !user.Id.Equals(Guid.Empty) && intervention.FkUserAppId.Equals(user.Id))) && user.IsActif == 1);

            intervention.ChildInterventions = App.LocalDb.Table <Intervention>().ToList().FindAll(inter => ((inter.FkParentServerlId > 0 && inter.FkParentServerlId == intervention.ServerId) || (!inter.FkParentAppId.Equals(Guid.Empty) && inter.FkParentAppId.Equals(intervention.Id))) && inter.IsActif == 1).ToObservableCollection();

            if (intervention.ChildInterventions != null)
            {
                foreach (var child in intervention.ChildInterventions)
                {
                    child.User = App.LocalDb.Table <User>().ToList().FirstOrDefault(user => user.UserId == CurrentUser.Id && ((child.FkUserServerlId > 0 && child.FkUserServerlId == user.ServerId) || (!child.FkUserAppId.Equals(Guid.Empty) && !user.Id.Equals(Guid.Empty) && child.FkUserAppId.Equals(user.Id))) && user.IsActif == 1);
                }
            }
            intervention.LinkInterventionTasks = App.LocalDb.Table <LinkInterventionTask>().ToList().FindAll(lit =>
                                                                                                             lit.UserId == CurrentUser.Id &&
                                                                                                             ((lit.FkInterventionServerId > 0 && lit.FkInterventionServerId == intervention.ServerId) ||
                                                                                                              (!lit.FkInterventionAppliId.Equals(Guid.Empty) && lit.FkInterventionAppliId.Equals(intervention.Id))) && lit.IsActif == 1);
            if (intervention.LinkInterventionTasks != null)
            {
                foreach (var lit in intervention.LinkInterventionTasks)
                {
                    lit.Task = App.LocalDb.Table <Tasks>().ToList().FirstOrDefault(ta => ta.UserId == CurrentUser.Id && ((lit.FkTaskServerId > 0 && lit.FkTaskServerId == ta.ServerId) || (!lit.FkTaskAppliId.Equals(Guid.Empty) && !ta.Id.Equals(Guid.Empty) && lit.FkTaskAppliId.Equals(ta.Id))) && ta.IsActif == 1);
                }
            }

            intervention.UniteLinks = App.LocalDb.Table <UniteLink>().ToList().FindAll(unl => unl.UserId == CurrentUser.Id && ((unl.FkColumnServerId > 0 && unl.FkColumnServerId == intervention.ServerId) || (!unl.FkColumnAppliId.Equals(Guid.Empty) && unl.FkColumnAppliId.Equals(intervention.Id))) && unl.IsActif == 1);

            if (intervention.UniteLinks != null)
            {
                foreach (var unl in intervention.UniteLinks)
                {
                    unl.Unite = App.LocalDb.Table <Unite>().ToList().FirstOrDefault(un => un.UserId == CurrentUser.Id && ((unl.FkUniteServerId > 0 && unl.FkUniteServerId == un.ServerId) || (!unl.FkUniteAppliId.Equals(Guid.Empty) && !un.Id.Equals(Guid.Empty) && unl.FkUniteAppliId.Equals(un.Id))) && un.IsActif == 1);

                    if (unl.Unite != null)
                    {
                        unl.UniteTitle   = unl.Unite.Nom;
                        unl.UniteDisplay = (unl.Unite.FieldType == 3 && !string.IsNullOrWhiteSpace(unl.UniteValue)) ? unl.UniteValue.Equals("1") ? TranslateExtension.GetValue("yes") : TranslateExtension.GetValue("no") : unl.UniteDisplay = unl.UniteValue;
                    }
                    if (unl.Unite != null && (unl.Unite.FieldType == 4 || unl.Unite.FieldType == 10) && unl.UniteDisplay != null)
                    {
                        var dataItem = unl.UniteDisplay.Split(',');
                        if (dataItem == null || dataItem.Length == 0 || dataItem[0].Contains(";"))
                        {
                            dataItem = unl.UniteDisplay.Split(';');
                        }
                        if (dataItem == null || dataItem.Length == 0)
                        {
                            continue;
                        }
                        int n;
                        if (dataItem != null && dataItem.Length > 0 && int.TryParse(dataItem[0], out n))
                        {
                            var temp = "";
                            for (int i = 0; i < dataItem.Length; i++)
                            {
                                var uniteItem = App.LocalDb.Table <UniteItem>().ToList().FirstOrDefault(uni => uni.ServerId == int.Parse(dataItem[i]));
                                temp += uniteItem.Value + ";";
                            }
                            if (temp.Length > 1)
                            {
                                unl.UniteDisplay = temp;
                            }
                        }
                    }
                    if (unl.UniteDisplay != null && unl.UniteDisplay.Contains("http"))
                    {
                        //var link = unl.UniteDisplay.Length > 50 ? unl.UniteDisplay.Substring(0, 50) : unl.UniteDisplay;

                        unl.IsWebLink = true;
                    }
                    else
                    {
                        unl.IsNotWebLink = true;
                    }
                }
            }

            intervention.LinkInterventionProducts = App.LocalDb.Table <LinkInterventionProduct>().ToList().FindAll(lip => lip.UserId == CurrentUser.Id && ((lip.FkInterventionServerId > 0 && lip.FkInterventionServerId == intervention.ServerId) || (!lip.FkInterventionAppliId.Equals(Guid.Empty) && lip.FkInterventionAppliId.Equals(intervention.Id))) && lip.IsActif == 1).ToObservableCollection();
            if (intervention.LinkInterventionProducts != null)
            {
                foreach (var lip in intervention.LinkInterventionProducts)
                {
                    lip.Product = App.LocalDb.Table <Product>().ToList().FirstOrDefault(pro => pro.UserId == CurrentUser.Id && ((lip.FkProductServerId > 0 && lip.FkProductServerId == pro.ServerId) || (!lip.FkProductId.Equals(Guid.Empty) && !pro.Id.Equals(Guid.Empty) && lip.FkProductId.Equals(pro.Id))) && pro.IsActif == 1);
                }
            }

            intervention.LinkInterventionEquipments = App.LocalDb.Table <LinkInterventionEquipment>().ToList().FindAll(lie => lie.UserId == CurrentUser.Id && ((lie.FkInterventionServerId > 0 && lie.FkInterventionServerId == intervention.ServerId) || (!lie.FkInterventionAppliId.Equals(Guid.Empty) && lie.FkInterventionAppliId.Equals(intervention.Id))) && lie.IsActif == 1).ToObservableCollection();
            if (intervention.LinkInterventionEquipments != null)
            {
                foreach (var lip in intervention.LinkInterventionEquipments)
                {
                    lip.Equipment = App.LocalDb.Table <Equipment>().ToList().FirstOrDefault(pro => pro.UserId == CurrentUser.Id && ((lip.FkEquipmentServerId > 0 && lip.FkEquipmentServerId == pro.ServerId) || (!lip.FkEquipmentAppliId.Equals(Guid.Empty) && !pro.Id.Equals(Guid.Empty) && lip.FkEquipmentAppliId.Equals(pro.Id))) && pro.IsActif == 1);
                }
            }

            intervention.MediaLinks = App.LocalDb.Table <MediaLink>().ToList().FindAll(medl => medl.UserId == CurrentUser.Id && ((medl.FkColumnServerId > 0 && medl.FkColumnServerId == intervention.ServerId) || (!medl.FkColumnAppliId.Equals(Guid.Empty) && medl.FkColumnAppliId.Equals(intervention.Id))) && !medl.IsDelete && medl.IsActif == 1).ToObservableCollection();

            if (intervention.MediaLinks != null)
            {
                foreach (var medl in intervention.MediaLinks)
                {
                    medl.Media = App.LocalDb.Table <Media>().ToList().FirstOrDefault(med => med.UserId == CurrentUser.Id && ((medl.FkMediaServerId > 0 && medl.FkMediaServerId == med.ServerId) || (!medl.FkMediaAppliId.Equals(Guid.Empty) && !med.Id.Equals(Guid.Empty) && medl.FkMediaAppliId.Equals(med.Id))) && med.IsActif == 1);
                }
            }

            return(Task.FromResult(intervention));
        }
示例#26
0
        public Task <Intervention> GetRelations(Intervention intervention)
        {
            intervention.User = App.LocalDb.Table <User>().ToList().FirstOrDefault(user => user.UserId == CurrentUser.Id && ((intervention.FkUserServerlId > 0 && intervention.FkUserServerlId == user.ServerId) || (!intervention.FkUserAppId.Equals(Guid.Empty) && !user.Id.Equals(Guid.Empty) && intervention.FkUserAppId.Equals(user.Id))) && user.IsActif == 1);

            intervention.ChildInterventions = App.LocalDb.Table <Intervention>().ToList().FindAll(inter => inter.UserId == CurrentUser.Id && ((inter.FkParentServerlId > 0 && inter.FkParentServerlId == intervention.ServerId) || (!inter.FkParentAppId.Equals(Guid.Empty) && inter.FkParentAppId.Equals(intervention.Id))) && inter.IsActif == 1).ToObservableCollection();

            foreach (var child in intervention.ChildInterventions)
            {
                child.User = App.LocalDb.Table <User>().ToList().FirstOrDefault(user => user.UserId == CurrentUser.Id && ((child.FkUserServerlId > 0 && child.FkUserServerlId == user.ServerId) || (!child.FkUserAppId.Equals(Guid.Empty) && !user.Id.Equals(Guid.Empty) && child.FkUserAppId.Equals(user.Id))) && user.IsActif == 1);
            }

            intervention.LinkInterventionTasks = App.LocalDb.Table <LinkInterventionTask>().ToList().FindAll(lit => lit.UserId == CurrentUser.Id && ((lit.FkInterventionServerId > 0 && lit.FkInterventionServerId == intervention.ServerId) || (!lit.FkInterventionAppliId.Equals(Guid.Empty) && lit.FkInterventionAppliId.Equals(intervention.Id))) && lit.IsActif == 1);

            foreach (var lit in intervention.LinkInterventionTasks)
            {
                lit.Task = App.LocalDb.Table <Tasks>().ToList().FirstOrDefault(ta => ta.UserId == CurrentUser.Id && ((lit.FkTaskServerId > 0 && lit.FkTaskServerId == ta.ServerId) || (!lit.FkTaskAppliId.Equals(Guid.Empty) && !ta.Id.Equals(Guid.Empty) && lit.FkTaskAppliId.Equals(ta.Id))) && ta.IsActif == 1);
            }

            intervention.UniteLinks = App.LocalDb.Table <UniteLink>().ToList().FindAll(unl => unl.UserId == CurrentUser.Id && ((unl.FkColumnServerId > 0 && unl.FkColumnServerId == intervention.ServerId) || (!unl.FkColumnAppliId.Equals(Guid.Empty) && unl.FkColumnAppliId.Equals(intervention.Id))) && unl.IsActif == 1);
            foreach (var unl in intervention.UniteLinks)
            {
                unl.Unite = App.LocalDb.Table <Unite>().ToList().FirstOrDefault(un => un.UserId == CurrentUser.Id && ((unl.FkUniteServerId > 0 && unl.FkUniteServerId == un.ServerId) || (!unl.FkUniteAppliId.Equals(Guid.Empty) && !un.Id.Equals(Guid.Empty) && unl.FkUniteAppliId.Equals(un.Id))) && un.IsActif == 1);

                if (unl.Unite != null)
                {
                    unl.UniteTitle   = unl.Unite.Nom;
                    unl.UniteDisplay = (unl.Unite.FieldType == 3 && !string.IsNullOrWhiteSpace(unl.UniteValue)) ? unl.UniteValue.Equals("1") ? TranslateExtension.GetValue("yes") : TranslateExtension.GetValue("no") : unl.UniteDisplay = unl.UniteValue;
                }
            }

            intervention.LinkInterventionProducts = App.LocalDb.Table <LinkInterventionProduct>().ToList().FindAll(lip => lip.UserId == CurrentUser.Id && ((lip.FkInterventionServerId > 0 && lip.FkInterventionServerId == intervention.ServerId) || (!lip.FkInterventionAppliId.Equals(Guid.Empty) && lip.FkInterventionAppliId.Equals(intervention.Id))) && lip.IsActif == 1).ToObservableCollection();
            foreach (var lip in intervention.LinkInterventionProducts)
            {
                lip.Product = App.LocalDb.Table <Product>().ToList().FirstOrDefault(pro => pro.UserId == CurrentUser.Id && ((lip.FkProductServerId > 0 && lip.FkProductServerId == pro.ServerId) || (!lip.FkProductId.Equals(Guid.Empty) && !pro.Id.Equals(Guid.Empty) && lip.FkProductId.Equals(pro.Id))) && pro.IsActif == 1);
            }

            intervention.MediaLinks = App.LocalDb.Table <MediaLink>().ToList().FindAll(medl => medl.UserId == CurrentUser.Id && ((medl.FkColumnServerId > 0 && medl.FkColumnServerId == intervention.ServerId) || (!medl.FkColumnAppliId.Equals(Guid.Empty) && medl.FkColumnAppliId.Equals(intervention.Id))) && !medl.IsDelete && medl.IsActif == 1).ToObservableCollection();
            foreach (var medl in intervention.MediaLinks)
            {
                medl.Media = App.LocalDb.Table <Media>().ToList().FirstOrDefault(med => med.UserId == CurrentUser.Id && ((medl.FkMediaServerId > 0 && medl.FkMediaServerId == med.ServerId) || (!medl.FkMediaAppliId.Equals(Guid.Empty) && !med.Id.Equals(Guid.Empty) && medl.FkMediaAppliId.Equals(med.Id))) && med.IsActif == 1);
            }

            return(Task.FromResult(intervention));
        }
示例#27
0
        public async Task NavigateFromMenu(int id)
        {
            if (lastPage == id)
            {
                IsPresented = false;
                return;
            }

            try
            {
                Page newPage = null;

                switch (id)
                {
                case (int)MenuItemType.Interventions:
                    newPage = ViewModelResolver.ResolveViewModel <ViewModels.Interventions.InterventionsViewModel>();
                    break;

                case (int)MenuItemType.InterventionsNotAssigned:
                    newPage = ViewModelResolver.ResolveViewModel <ViewModels.InterventionsNotAssigned.InterventionsNotAssignedViewModel>();
                    break;

                case (int)MenuItemType.Quote:
                    newPage = ViewModelResolver.ResolveViewModel <ViewModels.Quotes.QuotesViewModel>();
                    break;

                case (int)MenuItemType.Invoice:
                    newPage = ViewModelResolver.ResolveViewModel <ViewModels.Invoices.InvoicesViewModel>();
                    break;

                case (int)MenuItemType.Issue:
                    newPage = ViewModelResolver.ResolveViewModel <ViewModels.Issues.IssuesViewModel>();
                    break;

                case (int)MenuItemType.Messages:
                    newPage = ViewModelResolver.ResolveViewModel <ViewModels.Messages.MessagesViewModel>();
                    break;

                case (int)MenuItemType.Customers:
                    newPage = ViewModelResolver.ResolveViewModel <ViewModels.Customers.CustomersViewModel>();
                    break;

                case (int)MenuItemType.Addresses:
                    newPage = ViewModelResolver.ResolveViewModel <ViewModels.Addresses.AddressesViewModel>();
                    break;

                case (int)MenuItemType.Equipment:
                    newPage = ViewModelResolver.ResolveViewModel <ViewModels.Equipments.EquipmentsViewModel>();
                    break;

                case (int)MenuItemType.Products:
                    newPage = ViewModelResolver.ResolveViewModel <ViewModels.Products.ProductsViewModel>();
                    break;

                case (int)MenuItemType.Tracking:
                    newPage = ViewModelResolver.ResolveViewModel <ViewModels.Tracking.TrackingViewModel>();
                    break;

                case (int)MenuItemType.Settings:
                    newPage = ViewModelResolver.ResolveViewModel <ViewModels.SystemSettings.SettingsViewModel>();
                    break;

                case (int)MenuItemType.About:
                    newPage = ViewModelResolver.ResolveViewModel <ViewModels.About.AboutViewModel>();
                    break;

                case (int)MenuItemType.LogOut:
                    await LogOut();

                    break;
                }

                if (newPage != null)
                {
                    if (Detail is NavigationPage)
                    {
                        ((NavigationPage)Detail).NotifyAllChildrenPopped();
                    }
                    if (Detail is INavigationService)
                    {
                        ((INavigationService)Detail).NotifyChildrenPageWasPopped();
                    }

                    Detail = new NavigationContainer(newPage)
                    {
                        BarBackgroundColor = Color.FromHex("#2196F3"),
                        BarTextColor       = Color.White
                    };
                    lastPage = id;

                    if (Device.RuntimePlatform == Device.Android)
                    {
                        await Task.Delay(100);
                    }

                    IsPresented = false;
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert(TranslateExtension.GetValue("alert_title_error"), ex.GetBaseException().Message, TranslateExtension.GetValue("alert_message_ok"));
            }
        }
示例#28
0
        private void RenderText()
        {
            var stk = new StackLayout()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Padding           = 10,
                Spacing           = 2
            };

            var name = new Label()
            {
                FontSize        = 14,
                Text            = TranslateExtension.GetValue(Setting.Name),
                TextColor       = Color.Black,
                VerticalOptions = LayoutOptions.Center
            };

            var value = new Label()
            {
                FontSize        = 13,
                TextColor       = Color.Gray,
                VerticalOptions = LayoutOptions.Center
            };

            if (Setting.Name.Equals("APP_LAST_SYNCHRO") || Setting.Name.Equals("APP_LAST_SYNCHRO_PRODUCT") || Setting.Name.Equals("APP_LAST_SYNCHRO_INVOICE") || Setting.Name.Equals("APP_LAST_SYNCHRO_ISSUE") || Setting.Name.Equals("APP_LAST_SYNCHRO_EQUIPMENT"))
            {
                value.SetBinding(Label.TextProperty, new Binding("Value", BindingMode.Default, converter: new UnixToDateTimeConverter(), stringFormat: TranslateExtension.GetValue("label_text_current_value_2") + " {0:dd/MM/yyyy HH:mm:ss}", source: Setting));
            }
            else
            {
                value.SetBinding(Label.TextProperty, new Binding("Value", BindingMode.Default, stringFormat: TranslateExtension.GetValue("label_text_current_value_2") + " {0}", source: Setting));
            }

            stk.Children.Add(name);
            stk.Children.Add(value);

            stk.GestureRecognizers.Add(new TapGestureRecognizer()
            {
                Command = new Command(async(sender) =>
                {
                    if (await Application.Current.MainPage.DisplayAlert(TranslateExtension.GetValue(Setting.Name), TranslateExtension.GetValue(Setting.Message), TranslateExtension.GetValue("yes"), TranslateExtension.GetValue("no")))
                    {
                        if (Setting.Name.Equals("APP_LAST_SYNCHRO"))
                        {
                            Settings.LastSync = "0";
                            if (App.LocalDb.Table <Setting>().ToList().Find(se => se.Name.Equals("APP_LAST_SYNCHRO")) is Setting lastSync)
                            {
                                lastSync.Value = "0";
                                App.LocalDb.Update(lastSync);
                            }
                            Setting.Value = "0";
                        }
                        else if (Setting.Name.Equals("APP_LAST_SYNCHRO_PRODUCT"))
                        {
                            Settings.LastSyncProduct = "0";
                            if (App.LocalDb.Table <Setting>().ToList().Find(se => se.Name.Equals("APP_LAST_SYNCHRO_PRODUCT")) is Setting lastSyncProduct)
                            {
                                lastSyncProduct.Value = "0";
                                App.LocalDb.Update(lastSyncProduct);
                            }
                            Setting.Value = "0";
                        }
                        else if (Setting.Name.Equals("APP_LAST_SYNCHRO_INVOICE"))
                        {
                            Settings.LastSyncInvoice = "0";
                            if (App.LocalDb.Table <Setting>().ToList().Find(se => se.Name.Equals("APP_LAST_SYNCHRO_INVOICE")) is Setting lastSyncInvoice)
                            {
                                lastSyncInvoice.Value = "0";
                                App.LocalDb.Update(lastSyncInvoice);
                            }
                            Setting.Value = "0";
                        }
                        else if (Setting.Name.Equals("APP_LAST_SYNCHRO_ISSUE"))
                        {
                            Settings.LastSyncInvoice = "0";
                            if (App.LocalDb.Table <Setting>().ToList().Find(se => se.Name.Equals("APP_LAST_SYNCHRO_ISSUE")) is Setting lastSyncIssue)
                            {
                                lastSyncIssue.Value = "0";
                                App.LocalDb.Update(lastSyncIssue);
                            }
                            Setting.Value = "0";
                        }
                        else if (Setting.Name.Equals("APP_LAST_SYNCHRO_EQUIPMENT"))
                        {
                            Settings.LastSyncEquipment = "0";
                            if (App.LocalDb.Table <Setting>().ToList().Find(se => se.Name.Equals("APP_LAST_SYNCHRO_EQUIPMENT")) is Setting lastSyncEquipment)
                            {
                                lastSyncEquipment.Value = "0";
                                App.LocalDb.Update(lastSyncEquipment);
                            }
                            Setting.Value = "0";
                        }
                    }
                })
            });
        public Task <bool> SyncFromServer(int method, Action onSuccess, Action <string> onError = null, bool showOverlay = false)
        {
            if (!ConnectivityHelper.IsNetworkAvailable(method == 2))
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    onError?.Invoke(TranslateExtension.GetValue("alert_no_internt_message"));
                });
                return(Task.FromResult(false));
            }

            if (showOverlay)
            {
                DependencyService.Get <IPopupService>().ShowContent(new LoadingScreen1()
                {
                    Message = TranslateExtension.GetValue("content_message_synchronizing")
                });
            }

            Task.Run(async() =>
            {
                return(await SyncFromServer(method));
            }).ContinueWith(task => Device.BeginInvokeOnMainThread(() =>
            {
                if (showOverlay)
                {
                    DependencyService.Get <IPopupService>().HideContent();
                }

                if (task.Status == TaskStatus.RanToCompletion)
                {
                    if (task.Result)
                    {
                        if (showOverlay)
                        {
                            UserDialogs.Instance.Toast(new ToastConfig(TranslateExtension.GetValue("alert_message_sync_completed"))
                            {
                            });
                        }
                        onSuccess?.Invoke();
                    }
                    else
                    {
                        if (showOverlay)
                        {
                            UserDialogs.Instance.Toast(new ToastConfig(TranslateExtension.GetValue("alert_message_sync_failed"))
                            {
                            });
                        }
                        onError?.Invoke(TranslateExtension.GetValue("alert_message_sync_failed"));
                    }
                }
                else if (task.IsFaulted && task.Exception?.GetBaseException().Message is string message)
                {
                    if (showOverlay)
                    {
                        UserDialogs.Instance.Toast(new ToastConfig(message)
                        {
                        });
                    }
                    onError?.Invoke(message);
                }
            }));

            return(Task.FromResult(true));
        }
示例#30
0
        public static bool IsGeolocationEnabled()
        {
            if (!CrossGeolocator.Current.IsGeolocationEnabled)
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    Application.Current?.MainPage?.DisplayAlert("Location", "Location is turn off. Please turn Location on to use the app.", TranslateExtension.GetValue("ok"));
                });
                return(false);
            }

            return(true);
        }