void SaveForm()
        {
            formDinamico.UpdateValues();
            var gps = LocationHelper.UpdateLocation();

            if (gps == null)
            {
                var alertGps = UIAlertController.Create("GPS Desativado",
                                                        "Ligue o GPS ou tire do modo aviao para continuar utilizando o sistema", UIAlertControllerStyle.Alert);
                alertGps.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (defaults) => { }));
                alertGps.View.TintColor = UIColor.FromRGB(10, 88, 90);
                PresentViewController(alertGps, true, null);
            }
            else
            {
                var batery = ((int)(UIDevice.CurrentDevice.BatteryLevel * 100F));
                if (gps.Location != null)
                {
                    controllerPCL.SetFormToTable(gps.Location.Coordinate.Latitude,
                                                 gps.Location.Coordinate.Longitude, StatusAPI.INICIADO, batery);
                }
                else
                {
                    controllerPCL.SetFormToTable(LocationHelper.LastLocation.Coordinate.Latitude,
                                                 LocationHelper.LastLocation.Coordinate.Longitude,
                                                 StatusAPI.INICIADO, batery);
                }
#if !DEBUG
                HockeyApp.MetricsManager.TrackEvent("FormAtualizado");
#endif
                DismissViewController(true, null);
            }
        }
        void JustificarAction(string motivo, string nomePdv, string enderecoPdv, NSIndexPath path)
        {
            var gps = LocationHelper.UpdateLocation();

            if (gps == null)
            {
                var alertGps = UIAlertController.Create("GPS Desativado",
                                                        "Ligue o GPS ou tire do modo aviao para continuar utilizando o sistema", UIAlertControllerStyle.Alert);
                alertGps.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (defaults) => { }));
                alertGps.View.TintColor = UIColor.FromRGB(10, 88, 90);
                PresentViewController(alertGps, true, null);
            }
            else
            {
                var index = feedCollection.Pdvs.FindIndex((obj) => obj.NomePDV.Equals(nomePdv) &&
                                                          obj.Endereco.Equals(enderecoPdv));
                var listTypePdv = feedCollection.Pdvs[index].listTypePdv;

                feedCollection.Pdvs.RemoveAt(index);
                collecFeedPdv.PerformBatchUpdates(delegate
                {
                    collecFeedPdv.DeleteItems(new NSIndexPath[] { path });
                }, null);
                feedCollection.Pdvs.RemoveAll((obj) => obj.NomePDV.Equals(nomePdv) && obj.Endereco.Equals(enderecoPdv));

                if (gps.Location == null)
                {
                    var batery = ((int)(UIDevice.CurrentDevice.BatteryLevel * 100F));
                    controllerPCL.Justificativa(listTypePdv, motivo,
                                                LocationHelper.LastLocation.Coordinate.Latitude,
                                                LocationHelper.LastLocation.Coordinate.Longitude, batery);
                }
                else
                {
                    var batery      = ((int)(UIDevice.CurrentDevice.BatteryLevel * 100F));
                    var gpsLocation = gps.Location.Coordinate;
                    controllerPCL.Justificativa(listTypePdv, motivo,
                                                gpsLocation.Latitude, gpsLocation.Longitude, batery);
                }
                controllerPCL.RegistroDePontoEletronico();
                PopulateProgressBar(true);
#if !DEBUG
                HockeyApp.MetricsManager.TrackEvent("JustificativaLoja");
#endif
                if (controllerPCL.CheckOutVisita(feedCollection.Pdvs.Count))
                {
                    CheckOutMessage();
                    var app = new AppDelegate();
                    app.ExecAPIs();
                }
            }
        }
 public override void ViewDidAppear(bool animated)
 {
     base.ViewDidAppear(animated);
     if (genController.IsHrDeAlmoco())
     {
         PopUpAlmoco("Gostaria de finalizar o horario de almoco em seu ponto eletronico ?");
     }
     UIApplication.Notifications.ObserveDidBecomeActive((sender, e) =>
     {
         if (genController.IsHrDeAlmoco())
         {
             PopUpAlmoco("Gostaria de finalizar o horario de almoco em seu ponto eletronico ?");
         }
         LocationHelper.UpdateLocation();
     });
 }
 public override void ViewDidAppear(bool animated)
 {
     base.ViewDidAppear(animated);
     InitPresentation();
     UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
     if (genericController.IsHrDeAlmoco())
     {
         PopUpAlmoco("Gostaria de finalizar o horario de almoco em seu ponto eletronico ?");
     }
     UIApplication.Notifications.ObserveDidBecomeActive((sender, e) =>
     {
         if (genericController.IsHrDeAlmoco())
         {
             PopUpAlmoco("Gostaria de finalizar o horario de almoco em seu ponto eletronico ?");
         }
         else if (tarefas != null && tarefas.Count < 1)
         {
             PopUpCheckOutAutomatico();
         }
         LocationHelper.UpdateLocation();
     });
 }
        EventHandler Ruptura()
        {
            return((sender, e) =>
            {
                var alert = UIAlertController.Create("Ruptura", "Tem certeza que o item esta em ruptura ?", UIAlertControllerStyle.Alert);
                alert.AddAction(UIAlertAction.Create("Nao", UIAlertActionStyle.Cancel, (actionCancel) =>
                {
                    MetricsManager.TrackEvent("CancelRuptura");
                }));

                alert.AddAction(UIAlertAction.Create("Sim", UIAlertActionStyle.Default, (actionOK) =>
                {
                    InvokeOnMainThread(delegate
                    {
                        var gps = LocationHelper.UpdateLocation();
                        if (gps == null)
                        {
                            var alertGps = UIAlertController.Create("GPS Desativado",
                                                                    "Ligue o GPS ou tire do modo aviao para continuar utilizando o sistema", UIAlertControllerStyle.Alert);
                            alertGps.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (defaults) => { }));
                            alertGps.View.TintColor = UIColor.FromRGB(10, 88, 90);
                            PresentViewController(alertGps, true, null);
                        }
                        else
                        {
                            var tarefasCell = ((UIButton)sender).Superview.Superview as TarefasCell;
                            var path = TarefasTable.IndexPathForRowAtPoint(new CoreGraphics.CGPoint(tarefasCell.Frame.X, tarefasCell.Frame.Y));
                            using (var cell = TarefasTable.CellAt(path) as TarefasCell)
                            {
                                var task = cell.GetTarefaInfo();
                                foreach (var itemIDVisita in listIdsPDVs)
                                {
                                    var tbProduto = controller.GetProdutosList(task.DescricaoDaTarefa);
                                    foreach (var produto in tbProduto)
                                    {
                                        var idProduto = produto.ID;
                                        if (controller.IsCorrectIDTarefaLoja(itemIDVisita.IdVisita, produto.ID))
                                        {
                                            var batery = ((int)(UIDevice.CurrentDevice.BatteryLevel * 100F));
                                            if (gps.Location != null)
                                            {
                                                controller.SetRuptura(itemIDVisita.IdVisita,
                                                                      controller.GetProdutos(task.DescricaoDaTarefa).ID, gps.Location.Coordinate.Latitude,
                                                                      gps.Location.Coordinate.Longitude, batery);
                                            }
                                            else
                                            {
                                                controller.SetRuptura(itemIDVisita.IdVisita,
                                                                      controller.GetProdutos(task.DescricaoDaTarefa).ID,
                                                                      LocationHelper.LastLocation.Coordinate.Latitude,
                                                                      LocationHelper.LastLocation.Coordinate.Longitude, batery);
                                            }
                                        }
                                    }
                                }
                                var index = tarefasTable.Tarefas.FindIndex((obj) => obj.DescricaoDaTarefa.Equals(task.DescricaoDaTarefa) &&
                                                                           obj.Categoria.Equals(task.Categoria));
                                TarefasTable.BeginUpdates();
                                tarefasTable.Tarefas.RemoveAt(index);
                                TarefasTable.DeleteRows(new NSIndexPath[] { path }, UITableViewRowAnimation.Left);
                                TarefasTable.EndUpdates();
                                if (tarefas.Count < 1)
                                {
                                    PopUpCheckOutAutomatico();
                                }
                            }
                        }
                    });
#if !DEBUG
                    HockeyApp.MetricsManager.TrackEvent("Ruptura");
#endif
                }));
                alert.View.TintColor = UIColor.FromRGB(10, 88, 90);
                PresentViewController(alert, true, null);
            });
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            var modelForm = new FormDinamicoModel()
            {
                Db        = new FormDinamicoDA(Sqlite_IOS.DB.dataBase),
                IdVisita  = IdPdv,
                IdProduto = IdProduto
            };

            controllerPCL = new FormDinamicoCon(IdPdv, IdProduto, false, modelForm);
            formDinamico  = new UIFormDinamico(controllerPCL, this, scrollViewFormDinamico);
            formDinamico.IniForm();

            backButton.TouchDown += (sender, e) =>
            {
                SaveForm();
            };

            gestureSaveForm.AddTarget((obj) => SaveForm());

            tabBarFormDinamico.ItemSelected += delegate
            {
                if (tabBarFormDinamico.SelectedItem.Title == tabFoto.Title)
                {
                    var actionSheetAlert = UIAlertController.Create("Tipo de foto", "Selecione a categoria da foto desejada", UIAlertControllerStyle.ActionSheet);
                    var fotos            = controllerPCL.GetTagsFoto();

                    foreach (string itemType in fotos)
                    {
                        actionSheetAlert.AddAction(UIAlertAction.Create(itemType, UIAlertActionStyle.Default, (action) => { TakePhoto(itemType); }));
                    }
                    actionSheetAlert.AddAction(UIAlertAction.Create("Outros", UIAlertActionStyle.Default, (action) => { TakePhoto("Outros"); }));
                    actionSheetAlert.AddAction(UIAlertAction.Create("Cancelar", UIAlertActionStyle.Cancel, (action) => { }));
                    var presentationPopover = actionSheetAlert.PopoverPresentationController;
                    if (presentationPopover != null)
                    {
                        presentationPopover.SourceView = View;
                        presentationPopover.PermittedArrowDirections = UIPopoverArrowDirection.Up;
                    }
                    actionSheetAlert.View.TintColor = UIColor.Black;
                    PresentViewController(actionSheetAlert, true, null);
                }
                else if (tabBarFormDinamico.SelectedItem.Title == tabConcluir.Title)
                {
                    var alert = UIAlertController.Create("Concluir", "Gostaria de concluir a tarefa ?", UIAlertControllerStyle.Alert);
                    alert.AddAction(UIAlertAction.Create("Nao", UIAlertActionStyle.Cancel, (actionCancel) =>
                    {
                        MetricsManager.TrackEvent("CancelConcluirTarefa");
                    }));
                    alert.AddAction(UIAlertAction.Create("Sim", UIAlertActionStyle.Default, (actionOK) =>
                    {
                        if (formDinamico.HasInvalidateFields())
                        {
                            var alertError = UIAlertController.Create("Existem campos obrigatorios ainda nao informados.", null, UIAlertControllerStyle.Alert);
                            alertError.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Cancel, (actionCancel) => { }));
                            alertError.View.TintColor = UIColor.FromRGB(10, 88, 90);
                            PresentViewController(alertError, true, null);
                        }
                        else
                        {
                            var gps = LocationHelper.UpdateLocation();
                            if (gps == null)
                            {
                                var alertGps = UIAlertController.Create("GPS Desativado",
                                                                        "Ligue o GPS ou tire do modo aviao para continuar utilizando o sistema", UIAlertControllerStyle.Alert);
                                alertGps.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (defaults) => { }));
                                alertGps.View.TintColor = UIColor.FromRGB(10, 88, 90);
                                PresentViewController(alertGps, true, null);
                            }
                            else
                            {
                                var batery = ((int)(UIDevice.CurrentDevice.BatteryLevel * 100F));
                                if (gps.Location != null)
                                {
                                    controllerPCL.SetFormToTable(gps.Location.Coordinate.Latitude,
                                                                 gps.Location.Coordinate.Longitude,
                                                                 StatusAPI.CONCLUIDO, batery);
                                }
                                else
                                {
                                    controllerPCL.SetFormToTable(LocationHelper.LastLocation.Coordinate.Latitude,
                                                                 LocationHelper.LastLocation.Coordinate.Longitude,
                                                                 StatusAPI.CONCLUIDO, batery);
                                }
#if !DEBUG
                                HockeyApp.MetricsManager.TrackEvent("FormConcluido");
#endif
                                DismissViewController(true, null);
                            }
                        }
                    }));
                    alert.View.TintColor = UIColor.FromRGB(10, 88, 90);
                    PresentViewController(alert, true, null);
                }
            };


            var g = new UITapGestureRecognizer(() => View.EndEditing(true))
            {
                CancelsTouchesInView = false
            };
            scrollViewFormDinamico.AddGestureRecognizer(g);
        }
예제 #7
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            UIApplication.SharedApplication.SetMinimumBackgroundFetchInterval(UIApplication.BackgroundFetchIntervalMinimum);
            try
            {
                var loginDA = new LoginDA(Sqlite_IOS.DB.dataBase);
                InvokeOnMainThread(delegate
                {
                    if (loginDA.GetInfoUsuario() == null)
                    {
                        autenticado = false;
                    }
                    else
                    {
                        autenticado = true;
                    }
                });
            }
            catch (Exception)
            {
                autenticado = false;
            }
            finally
            {
#if !DEBUG
                var manager = BITHockeyManager.SharedHockeyManager;
                manager.Configure("642401fb0ca946e5ab22ab2c69cb2cb2");
                manager.CrashManager.CrashManagerStatus = BITCrashManagerStatus.AutoSend;
                manager.StartManager();
#endif

                if (!autenticado)
                {
                    var loginViewController = GetViewController(MainStoryboard, "Login") as LoginController;
                    SetRootViewController(loginViewController, false);
                }
                else
                {
                    var modelPDV = new MenuPdvsModel
                    {
                        dbGenericActivity = new GenericActDA(Sqlite_IOS.DB.dataBase),
                        dbPdvs            = new MenuPdvsDA(Sqlite_IOS.DB.dataBase)
                    };
                    InvokeOnMainThread(
                        delegate
                    {
                        modelPDV.infoUsuario = modelPDV.dbGenericActivity.GetUsersIDsLogged();
                        var visita           = modelPDV.dbPdvs.GetVisitaAtual();
                        if (visita != null)
                        {
                            if (visita.Count > 0)
                            {
                                var TarefasViewController = GetViewController(MainStoryboard, "TarefasController") as TarefasController;
                                SetRootViewController(TarefasViewController, false);
                            }
                        }
                    });

#if !DEBUG
                    if (modelPDV != null && modelPDV.infoUsuario[0] != null)
                    {
                        manager.UserId    = modelPDV.infoUsuario[0].ID;
                        manager.UserEmail = modelPDV.infoUsuario[0].SERVIDOR;
                        manager.StartManager();
                    }
#endif
                }
            }
            UNUserNotificationCenter.Current.GetNotificationSettings((settings) =>
            {
                if (settings.AlertSetting != UNNotificationSetting.Enabled)
                {
                    UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert, (approved, err) => { });
                }

                if (settings.BadgeSetting != UNNotificationSetting.Enabled)
                {
                    UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Badge, (approved, err) => { });
                }

                if (settings.SoundSetting != UNNotificationSetting.Enabled)
                {
                    UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Sound, (approved, err) => { });
                }
            });

            var authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);

            if (authorizationStatus != AVAuthorizationStatus.Authorized)
            {
                AVCaptureDevice.RequestAccessForMediaTypeAsync(AVMediaType.Video);
            }

            UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
            LocationHelper.UpdateLocation();
            return(true);
        }
        EventHandler CheckIn()
        {
            return((sender, e) =>
            {
                var contaCell = ((UIButton)sender).Superview.Superview as FeedPDVCell;
                var path = collecFeedPdv.IndexPathForItemAtPoint(new CGPoint(contaCell.Frame.X, contaCell.Frame.Y));
                using (var cell = collecFeedPdv.CellForItem(path) as FeedPDVCell)
                {
                    var info = cell.GetPdvCardUiInfo();
                    var alert = UIAlertController.Create("CheckIn", "Gostaria de efetuar o Check-In em " + info.NomePDV +
                                                         "\n" + info.Endereco + " ? ", UIAlertControllerStyle.Alert);
                    alert.AddAction(UIAlertAction.Create("Nao", UIAlertActionStyle.Cancel, (actionCancel) =>
                    {
                        MetricsManager.TrackEvent("CancelCheckIn");
                    }));

                    alert.AddAction(UIAlertAction.Create("Sim", UIAlertActionStyle.Default, (actionOK) =>
                    {
                        var isToOpenTarefas = false;
                        var index = feedCollection.Pdvs.FindIndex((obj) => obj.NomePDV.Equals(info.NomePDV) &&
                                                                  obj.Endereco.Equals(info.Endereco));

                        var gps = LocationHelper.UpdateLocation();
                        if (gps == null)
                        {
                            var alertGps = UIAlertController.Create("GPS Desativado",
                                                                    "Ligue o GPS ou tire do modo aviao para continuar utilizando o sistema", UIAlertControllerStyle.Alert);
                            alertGps.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, (defaults) => { }));
                            alertGps.View.TintColor = UIColor.FromRGB(10, 88, 90);
                            PresentViewController(alertGps, true, null);
                        }
                        else
                        {
                            var cordenadaEsperada = controllerPCL.GetCoordinates(feedCollection.Pdvs[index].listTypePdv);
                            if (gps.Location == null)
                            {
                                var batery = ((int)(UIDevice.CurrentDevice.BatteryLevel * 100F));
                                controllerPCL.CheckIn(feedCollection.Pdvs[index].listTypePdv,
                                                      LocationHelper.LastLocation.Coordinate.Latitude,
                                                      LocationHelper.LastLocation.Coordinate.Longitude, batery);
                                isToOpenTarefas = true;
                            }
                            else
                            {
                                var gpsEsperado = new CLLocation(cordenadaEsperada[0], cordenadaEsperada[1]);
                                var distance = gpsEsperado.DistanceFrom(gps.Location);
                                if (distance > 500 &&
                                    (int)cordenadaEsperada[0] > 0 && (int)cordenadaEsperada[1] > 0)
                                {
                                    isToOpenTarefas = false;
                                    var alertRangePDV = UIAlertController.Create("PDV longe do esperado",
                                                                                 "Sua localizacao atual está diferente da esperada, tem certeza que gostaria de continuar ?"
                                                                                 , UIAlertControllerStyle.Alert);
                                    alertRangePDV.AddAction(UIAlertAction.Create("Nao", UIAlertActionStyle.Cancel, (actionCancelRangePDV) =>
                                    {
                                        MetricsManager.TrackEvent("CancelCheckIn");
                                    }));

                                    alertRangePDV.AddAction(UIAlertAction.Create("Sim", UIAlertActionStyle.Default, (actionOKRangePDV) =>
                                    {
                                        var batery = ((int)(UIDevice.CurrentDevice.BatteryLevel * 100F));
                                        var gpsLocation = gps.Location.Coordinate;
                                        controllerPCL.RegistroDePontoEletronico();
                                        controllerPCL.CheckIn(feedCollection.Pdvs[index].listTypePdv,
                                                              gpsLocation.Latitude, gpsLocation.Longitude, batery);

                                        if (Storyboard.InstantiateViewController("TarefasController") is TarefasController tarefas)
                                        {
#if !DEBUG
                                            MetricsManager.TrackEvent("CheckInLoja");
#endif
                                            ShowViewController(tarefas, null);
                                        }
                                    }));
                                    alertRangePDV.View.TintColor = UIColor.FromRGB(10, 88, 90);
                                    PresentViewController(alertRangePDV, true, null);
                                }
                                else
                                {
                                    var batery = ((int)(UIDevice.CurrentDevice.BatteryLevel * 100F));
                                    isToOpenTarefas = true;
                                    var gpsLocation = gps.Location.Coordinate;
                                    controllerPCL.CheckIn(feedCollection.Pdvs[index].listTypePdv,
                                                          gpsLocation.Latitude, gpsLocation.Longitude, batery);
                                }
                            }
                            if (isToOpenTarefas)
                            {
                                controllerPCL.RegistroDePontoEletronico();
                                if (Storyboard.InstantiateViewController("TarefasController") is TarefasController tarefas)
                                {
#if !DEBUG
                                    MetricsManager.TrackEvent("CheckInLoja");
#endif
                                    ShowViewController(tarefas, null);
                                }
                            }
                        }
                    }));
                    alert.View.TintColor = UIColor.FromRGB(10, 88, 90);
                    PresentViewController(alert, true, null);
                }
            });
        }