void btn_Login_Click () { if (!(user.Text == "")) { //INSTANCE DBREPOSITORY DBRepository dbr = new DBRepository (); var usercheck = dbr.user_Check (user.Text.ToUpper(), password.Text); if (usercheck) { //UPDATE DE LA BDD AVEC CE USER AndHUD.Shared.ShowSuccess(this, "Bienvenue", MaskType.Black, TimeSpan.FromSeconds(2)); dbr.setUserdata (user.Text.ToUpper ()); StartActivity(typeof(HomeActivity)); } else { AndHUD.Shared.ShowError(this, "Mauvais mot de passe", MaskType.Black, TimeSpan.FromSeconds(2)); } } else { AndHUD.Shared.ShowError(this, "Champ user obligatoire", MaskType.Black, TimeSpan.FromSeconds(2)); } }
protected override void OnResume () { base.OnResume (); Task startupWork = new Task (() => { //INSTANCE DBREPOSITORY DBRepository dbr = new DBRepository (); //CREATION DE LA BDD dbr.CreateDB (); //CREATION DES TABLES dbr.CreateTable (); //TEST DE CONNEXION var connectivityManager = (ConnectivityManager)GetSystemService (ConnectivityService); var t = DateTime.Now.ToString ("dd_MM_yy"); string dir_log = (Android.OS.Environment.GetExternalStoragePublicDirectory (Android.OS.Environment.DirectoryDownloads)).ToString (); //Shared Preference ISharedPreferences pref = Application.Context.GetSharedPreferences ("AppInfo", FileCreationMode.Private); string log = pref.GetString ("Log", String.Empty); //GetTelId TelephonyManager tel = (TelephonyManager)this.GetSystemService (Context.TelephonyService); var telId = tel.DeviceId; //Si il n'y a pas de shared pref if (log == String.Empty) { Data.log_file = Path.Combine (dir_log, t + "_" + telId + "_log.txt"); ISharedPreferencesEditor edit = pref.Edit (); edit.PutString ("Log", Data.log_file); edit.Apply (); } else { //il y a des shared pref Data.log_file = pref.GetString ("Log", String.Empty); if (((File.GetCreationTime (Data.log_file)).CompareTo (DateTime.Now)) > 3) { File.Delete (Data.log_file); Data.log_file = Path.Combine (dir_log, t + "_" + telId + "_log.txt"); ISharedPreferencesEditor edit = pref.Edit (); edit.PutString ("Log", Data.log_file); edit.Apply (); Data.log_file = pref.GetString ("Log", String.Empty); } } File.AppendAllText (Data.log_file, "[LAUNCH] DMS lancée le " + DateTime.Now.ToString ("F") + "\n"); bool App_Connec = false; while (!App_Connec) { var activeConnection = connectivityManager.ActiveNetworkInfo; if ((activeConnection != null) && activeConnection.IsConnected) { try { string _url = "http://dms.jeantettransport.com/api/authen?chaufmdp="; var webClient = new WebClient (); webClient.Headers [HttpRequestHeader.ContentType] = "application/json"; string userData = ""; userData = webClient.DownloadString (_url); System.Console.WriteLine ("\n Webclient User Terminé ..."); //GESTION DU XML JsonArray jsonVal = JsonArray.Parse (userData) as JsonArray; var jsonArr = jsonVal; foreach (var row in jsonArr) { var checkUser = dbr.user_AlreadyExist (row ["userandsoft"], row ["usertransics"], row ["mdpandsoft"], "true"); Console.WriteLine ("\n" + checkUser + " " + row ["userandsoft"]); if (!checkUser) { var IntegUser = dbr.InsertDataUser (row ["userandsoft"], row ["usertransics"], row ["mdpandsoft"], "true"); Console.WriteLine ("\n" + IntegUser); } } App_Connec = true; } catch (System.Exception ex) { System.Console.WriteLine (ex); Insights.Report (ex); App_Connec = false; AndHUD.Shared.ShowError (this, "Une erreur c'est produite lors du lancement, réessaie dans 5 secondes", MaskType.Black, TimeSpan.FromSeconds (5)); } } else { App_Connec = false; //AndHUD.Shared.ShowError(this, "Pas de connexion, réessaie dans 5 secondes", MaskType.Black, TimeSpan.FromSeconds(5)); Toast.MakeText (this, "Pas de connexion", ToastLength.Long).Show (); Thread.Sleep (5000); } } }); startupWork.ContinueWith (t => { //Is a user login ? DBRepository dbr = new DBRepository (); var user_Login = dbr.is_user_Log_In (); if (!(user_Login == string.Empty)) { //Data.userAndsoft = user_Login; dbr.setUserdata (user_Login); File.AppendAllText (Data.log_file, "Connexion de " + Data.userAndsoft + " à " + DateTime.Now.ToString ("t") + "\n"); StartActivity (new Intent (Application.Context, typeof(HomeActivity))); } else { StartActivity (new Intent (Application.Context, typeof(MainActivity))); } }, TaskScheduler.FromCurrentSynchronizationContext ()); startupWork.Start (); }
protected override void OnResume() { base.OnResume(); DBRepository dbr = new DBRepository (); dbr.SETBadges(Data.userAndsoft); if (dbr.is_user_Log_In() == "false") { Intent intent = new Intent (this, typeof(MainActivity)); this.StartActivity (intent); this.OverridePendingTransition (Resource.Animation.abc_slide_in_top,Resource.Animation.abc_slide_out_bottom); } var t = DateTime.Now.ToString ("dd_MM_yy"); string dir_log = (Android.OS.Environment.GetExternalStoragePublicDirectory (Android.OS.Environment.DirectoryDownloads)).ToString (); //Shared Preference ISharedPreferences pref = Application.Context.GetSharedPreferences ("AppInfo", FileCreationMode.Private); string log = pref.GetString ("Log", String.Empty); //GetTelId TelephonyManager tel = (TelephonyManager)this.GetSystemService (Context.TelephonyService); var telId = tel.DeviceId; //Si il n'y a pas de shared pref if (log == String.Empty) { Data.log_file = Path.Combine (dir_log, t + "_" + telId + "_log.txt"); ISharedPreferencesEditor edit = pref.Edit (); edit.PutString ("Log", Data.log_file); edit.Apply (); } else { //il y a des shared pref Data.log_file = pref.GetString ("Log", String.Empty); if (((File.GetCreationTime (Data.log_file)).CompareTo (DateTime.Now)) > 3) { File.Delete (Data.log_file); Data.log_file = Path.Combine (dir_log, t + "_" + telId + "_log.txt"); ISharedPreferencesEditor edit = pref.Edit (); edit.PutString ("Log", Data.log_file); edit.Apply (); Data.log_file = pref.GetString ("Log", String.Empty); } } var user = dbr.getUserAndsoft (); dbr.setUserdata (user); var version = this.PackageManager.GetPackageInfo(this.PackageName, 0).VersionName; lblTitle.Text = Data.userAndsoft + " " + version; indicatorTimer = new System.Timers.Timer(); indicatorTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnIndicatorTimerHandler); indicatorTimer.Interval = 1000; indicatorTimer.Enabled = true; indicatorTimer.Start(); }