private void GetAppConfig() { Table_Config table_Config = this.DBHelper.GetAppConfig(); if (table_Config != null) { this.UrlDomain = table_Config.UrlDomain; this.UrlPrefix = table_Config.UrlPrefix; } }
public bool CreateTablesAndInitialData() { try { int countTableCreationSuccess = 0; var resultTappuser = db.GetTableInfo("Table_User"); if (resultTappuser.Count == 0) { db.CreateTable <Table_User>(); Table_User table_User = new Table_User { Username = "", Password = "" }; var resultDB = db.Insert(table_User); if (resultDB == 1) { countTableCreationSuccess += 1; } } else { countTableCreationSuccess += 1; } var resultTconfig = db.GetTableInfo("Table_Config"); if (resultTconfig.Count == 0) { db.CreateTable <Table_Config>(); Table_Config table_Config = new Table_Config { UrlDomain = "", UrlPrefix = "", FingerPrintAllow = false }; var resultDB = db.Insert(table_Config); if (resultDB == 1) { countTableCreationSuccess += 1; } } else { countTableCreationSuccess += 1; } if (countTableCreationSuccess == 2) { return(true); } else { return(false); } } catch (Exception) { return(false); } }
private async void RefreshAppConfig() { Table_Config table_Config = await DBHelper.GetAsyncAppConfig(); if (table_Config != null) { this.UrlDomain = table_Config.UrlDomain; this.UrlPrefix = table_Config.UrlPrefix; this.IsFingerPrint = table_Config.FingerPrintAllow; } }
public async Task <bool> CreateAsyncTablesAndInitialData() { try { int countTableCreationSuccess = 0; var resultTappuser = await dbAsync.GetTableInfoAsync("Table_User"); if (resultTappuser.Count == 0) { await dbAsync.CreateTableAsync <Table_User>(); Table_User table_User = new Table_User { Username = "", Password = "" }; var resultDB = await dbAsync.InsertAsync(table_User); if (resultDB == 1) { countTableCreationSuccess += 1; } } var resultTconfig = await dbAsync.GetTableInfoAsync("Table_Config"); if (resultTconfig.Count == 0) { await dbAsync.CreateTableAsync <Table_Config>(); Table_Config table_Config = new Table_Config { UrlDomain = "", UrlPrefix = "", FingerPrintAllow = false }; var resultDB = await dbAsync.InsertAsync(table_Config); if (resultDB == 1) { countTableCreationSuccess += 1; } } if (countTableCreationSuccess == 2) { return(true); } else { return(false); } } catch (Exception) { return(false); } }
private async void Save() { if (string.IsNullOrWhiteSpace(this.UrlDomain) || string.IsNullOrWhiteSpace(this.UrlPrefix)) { Alert.Show("Debe ingresar un dominio y un prefijo"); return; } Table_Config table_Config = new Table_Config { Id = 1, UrlDomain = this.UrlDomain, UrlPrefix = this.UrlPrefix, FingerPrintAllow = this.IsFingerPrint }; if (!await DBHelper.PullAsyncAppConfig(table_Config)) { Alert.Show("No se pudo actualizar la configuración."); return; } Toast.ShowSuccess("Configuración guardada!"); await Application.Current.MainPage.Navigation.PopModalAsync(); }
public async Task <bool> PullAsyncAppConfig(Table_Config table_Config) { try { var result = await dbAsync.UpdateAsync(table_Config); if (result == 1) { return(true); } else { return(false); } } catch (Exception) { return(false); } }
public LoginViewModel(InitialLoad initialLoad, Table_Config table_Config) { DBHelper = new Services.DataHelper(); GetFingerPrintAvailable(); if (initialLoad.IsSuccess) { if (initialLoad.HasConfigData) { #region Set UI & Global Data this.UIIsVisible = true; this.UIErrorIsVisible = false; this.IsChecked = table_Config.FingerPrintAllow; this.UrlDomain = table_Config.UrlDomain; this.UrlPrefix = table_Config.UrlPrefix; this.IsEnabled = true; #endregion if (IsChecked) { this.IsVisibleFingerPrint = true; this.IsVisibleLogin = false; } else { this.IsVisibleFingerPrint = false; this.IsVisibleLogin = true; } } else { Alert.Show("Aplicación sin configuración!"); } } else { this.UIIsVisible = false; this.UIErrorIsVisible = true; } }
public MainViewModel() { instance = this; InitialLoad initialLoad = new InitialLoad(); DataHelper dbHelper = new DataHelper(); Table_Config table_Config = null; if (!dbHelper.CreateTablesAndInitialData()) { initialLoad.IsSuccess = false; } else { initialLoad.IsSuccess = true; table_Config = dbHelper.GetAppConfig(); if (table_Config != null) { initialLoad.HasConfigData = true; } else { initialLoad.HasConfigData = false; } } this.Login = new LoginViewModel(initialLoad, table_Config); this.Home = new HomeViewModel(); this.Settings = new SettingsViewModel(); this.StatisticalReportsMenu = new StatisticalReportsMenuViewModel(); this.About = new AboutViewModel(); this.LotAndCommand = new LotAndCommandViewModel(false); this.LogExecutionDelay = new LogExecutionDelayViewModel(false); this.LogExecution = new LogExecutionViewModel(false); this.LogExecutionReport = new LogExecutionReportViewModel(false, new ObservableCollection <LogExecutionReportItem>()); this.LogExecutionChart = new LogExecutionChartViewModel(false, new List <LogExecutionResult>()); this.PlannerMenu = new PlannerMenuViewModel(); this.MonitoringAndExecutionMenu = new MonitoringAndExecutionMenuViewModel(); this.OperationsLog = new OperationsLogViewModel(false); this.ProcessMonitor = new ProcessMonitorViewModel(false); this.RecurrenceMonitor = new RecurrenceMonitorViewModel(false); this.StatusInfoPlanner = new StatusInfoPlannerViewModel(); this.Notifications = new NotificationsViewModel(false, new Models.LogItem()); this.InstanceNotifications = new InstanceNotificationsViewModel(new Models.InstanceItem()); this.Monitoring = new MonitoringViewModel(); this.Execution = new ExecutionViewModel(false, false); this.ExecutionStageTwo = new ExecutionStageTwoViewModel(false, new Models.LogItem()); this.ExecutionStageThree = new ExecutionStageThreeViewModel(false, new Models.InstanceItem()); this.CommandNotifications = new CommandNotificationsViewModel(new Models.CommandItem()); this.LogObservations = new LogObservationsViewModel(false, new LotAndCommandObservation(), new Models.LogItem()); this.OperatorChange = new OperatorChangeViewModel(false, new Models.LogItem()); this.ControlSchedulesExecution = new ControlSchedulesExecutionViewModel(false, new Models.LogItem()); this.StatusInfoControlSchedulesExecution = new StatusInfoControlSchedulesExecutionViewModel(); this.LogInquiries = new LogInquiriesViewModel(false, new Models.LogItem()); this.LogInquirieDetail = new LogInquirieDetailViewModel(new Models.ResultLogInquirieItem()); this.ControlSchedulesExecutionDetail = new ControlSchedulesExecutionDetailViewModel(new Models.CommandsToControl()); this.BatchQuery = new BatchQueryViewModel(false, new Models.CommandItem()); this.EditParameters = new EditParametersViewModel(new Models.CommandItem()); this.StatusInfoExecutionStageTwo = new StatusInfoExecutionStageTwoViewModel(); this.StatusInfoExecutionStageThree = new StatusInfoExecutionStageThreeViewModel(); this.StatusInfoLogInquiries = new StatusInfoLogInquiriesViewModel(); this.Dependencies = new DependenciesViewModel(false, new Models.CommandItem()); this.StatusInfoDependencies = new StatusInfoDependenciesViewModel(); this.LotAndCommandReport = new LotAndCommandReportViewModel(false, new ObservableCollection <LotAndCommandReportItem>()); this.LotAndCommandChart = new LotAndCommandChartViewModel(false, new List <LotAndCommandResult>()); this.LogExecutionDelayReport = new LogExecutionDelayReportViewModel(false, new ObservableCollection <LogExecutionDelayReportItem>()); this.LogExecutionDelayChart = new LogExecutionDelayChartViewModel(false, new List <LogExecutionDelayResult>()); this.OperationsLogReport = new OperationsLogReportViewModel(false, new ObservableCollection <OperationsLogReportItem>()); this.CommandData = new CommandDataViewModel(false, new Models.CommandItem()); this.Result = new ResultViewModel(false, new Models.CommandItem()); }
private async void FingerPrint() { try { ApiSrv = new Services.ApiService(ApiConsult.ApiAuth); RefreshAppConfig(); var request = new AuthenticationRequestConfiguration("Autenticación Biométrica", "ProBatch Mobile 2.0"); var result = await CrossFingerprint.Current.AuthenticateAsync(request); if (!result.Authenticated) { return; } UserDialogs.Instance.ShowLoading("Iniciando sesión...", MaskType.Black); Table_User tableUserFingerPrint = await DBHelper.GetAsyncProbatchCredentials(); if (tableUserFingerPrint == null) { UserDialogs.Instance.HideLoading(); Toast.ShowError("No se pudo obtener las credenciales de ProBatch"); return; } try { Response resultApiIsAvailable = await ApiSrv.ApiIsAvailable(); if (!resultApiIsAvailable.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(resultApiIsAvailable.Message); return; } Response resultToken = await ApiSrv.GetToken(); if (!resultToken.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(resultToken.Message); return; } else { Token token = JsonConvert.DeserializeObject <Token>(Crypto.DecodeString(resultToken.Data)); LoginPb loginPb = new LoginPb { Username = Crypto.DecodeString(tableUserFingerPrint.Username), Password = Crypto.DecodeString(tableUserFingerPrint.Password) }; Response resultLoginProbatch = await ApiSrv.AuthenticateProbath(token.Key, loginPb); if (!resultLoginProbatch.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(resultLoginProbatch.Message); return; } else { PbUser = JsonConvert.DeserializeObject <PbUser>(Crypto.DecodeString(resultLoginProbatch.Data)); if (!PbUser.IsValid) { UserDialogs.Instance.HideLoading(); bool deleteFingerPrintRegister = await UserDialogs.Instance.ConfirmAsync("Credenciales inválidas, deseas eliminar el registro biométrico?", "AST●ProBatch®", "Si", "No"); if (deleteFingerPrintRegister) { IsChecked = false; Table_Config table_Config = new Table_Config { Id = 1, UrlDomain = this.UrlDomain, UrlPrefix = this.UrlPrefix, FingerPrintAllow = IsChecked }; if (!await DBHelper.PullAsyncAppConfig(table_Config)) { Toast.ShowError("No se pudo actualizar la configuración."); return; } else { Table_User table_User = new Table_User { Id = 1, Username = string.Empty, Password = string.Empty }; if (!await DBHelper.PullAsyncProbatchCredentials(table_User)) { Toast.ShowError("No se pudo actualizar la configuración."); return; } else { IsVisibleLogin = true; IsVisibleFingerPrint = false; } } return; } } else { if (!IsChecked) { Table_Config table_Config = new Table_Config { Id = 1, UrlDomain = this.UrlDomain, UrlPrefix = this.UrlPrefix, FingerPrintAllow = this.IsChecked }; if (!await DBHelper.PullAsyncAppConfig(table_Config)) { Toast.ShowError("No se pudo actualizar la configuración."); return; } else { Table_User table_User = new Table_User { Id = 1, Username = string.Empty, Password = string.Empty }; if (!await DBHelper.PullAsyncProbatchCredentials(table_User)) { Toast.ShowError("No se pudo actualizar la configuración."); return; } else { IsVisibleLogin = true; IsVisibleFingerPrint = false; } } } UserDialogs.Instance.HideLoading(); this.Username = string.Empty; this.Password = string.Empty; MainViewModel.GetInstance().Home = new HomeViewModel(); Application.Current.MainPage = new NavigationPage(new HomePage()); Alert.Show("Bienvenido: " + PbUser.FisrtName.Trim() + ", " + PbUser.LastName.Trim() + "!", "Continuar"); } } } } catch //(Exception ex) { UserDialogs.Instance.HideLoading(); Toast.ShowError("Ocurrió un error."); return; } } catch //(Exception ex) { Toast.ShowError("Ocurrió un error datos locales."); return; } }
private async void Login() { if (string.IsNullOrEmpty(this.Username)) { Alert.Show("Debe ingresar un usuario"); return; } if (string.IsNullOrEmpty(this.Password)) { Alert.Show("Debe ingresar una contraseña"); return; } if (IsChecked) { if (!IsFingerPrintAvailable) { Alert.Show("Sensor de huella no disponible o no configurado."); IsChecked = false; return; } else { var request = new AuthenticationRequestConfiguration("Autenticación Biométrica", "ProBatch Mobile 2.0"); var result = await CrossFingerprint.Current.AuthenticateAsync(request); if (!result.Authenticated) { this.Username = string.Empty; this.Password = string.Empty; IsChecked = false; return; } } } ApiSrv = new Services.ApiService(ApiConsult.ApiAuth); RefreshAppConfig(); try { UserDialogs.Instance.ShowLoading("Iniciando sesión...", MaskType.Black); Response resultApiIsAvailable = await ApiSrv.ApiIsAvailable(); if (!resultApiIsAvailable.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(resultApiIsAvailable.Message); return; } Response resultToken = await ApiSrv.GetToken(); if (!resultToken.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(resultToken.Message); return; } else { Token token = JsonConvert.DeserializeObject <Token>(Crypto.DecodeString(resultToken.Data)); LoginPb loginPb = new LoginPb { Username = this.Username, Password = this.Password }; Response resultLoginProbatch = await ApiSrv.AuthenticateProbath(token.Key, loginPb); if (!resultLoginProbatch.IsSuccess) { UserDialogs.Instance.HideLoading(); Toast.ShowError(resultLoginProbatch.Message); return; } else { PbUser = JsonConvert.DeserializeObject <PbUser>(Crypto.DecodeString(resultLoginProbatch.Data)); if (!PbUser.IsValid) { UserDialogs.Instance.HideLoading(); //Alert.Show("Usuario y/o Password incorrectos"); this.IsEnabled = false; this.IsEnabled = true; return; } else { if (IsChecked) { Table_Config table_Config = new Table_Config { Id = 1, UrlDomain = this.UrlDomain, UrlPrefix = this.UrlPrefix, FingerPrintAllow = this.IsChecked }; if (!await DBHelper.PullAsyncAppConfig(table_Config)) { UserDialogs.Instance.HideLoading(); Toast.ShowError("No se pudo actualizar la configuración."); return; } else { Table_User table_User = new Table_User { Id = 1, Username = Crypto.EncryptString(this.Username), Password = Crypto.EncryptString(this.Password) }; if (!await DBHelper.PullAsyncProbatchCredentials(table_User)) { UserDialogs.Instance.HideLoading(); Toast.ShowError("No se pudo actualizar la configuración."); return; } else { IsVisibleLogin = false; IsVisibleFingerPrint = true; } } } UserDialogs.Instance.HideLoading(); this.Username = string.Empty; this.Password = string.Empty; MainViewModel.GetInstance().Home = new HomeViewModel(); Application.Current.MainPage = new NavigationPage(new HomePage()); Alert.Show("Bienvenido: " + PbUser.FisrtName.Trim() + ", " + PbUser.LastName.Trim() + "!", "Continuar"); } } } } catch //(Exception ex) { UserDialogs.Instance.HideLoading(); Toast.ShowError("Ocurrió un error."); return; } }