Пример #1
0
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);



            
            // Set the main flag of the activity
            isRunning = true;

            // First initialize and then set the ServerIP
            DataAccessLayer.SQLiteUtilities.Initialize ();
            DataAccessLayer.Utilities.ServerIP = BusinessLayer.User.GetURL();
            DataAccessLayer.Utilities.MainColor = BusinessLayer.User.GetColor();

            //DataAccessLayer.Utilities.ServerIP = "92.79.164.242";

            // Set the layout
            SetContentView(Resource.Layout.ActivityAuthentication);


            networkStatus = GetNetworkStatus ();

            // The SQLite Utility will be initialized
            // -> Open Connection -> Create Database -> Create Security and Object tables
            //DataAccessLayer.SQLiteUtilities.Initialize ();

            EdName = FindViewById<EditText> (Resource.Id.EdName);
            EdPassword = FindViewById<EditText> (Resource.Id.EdPassword);
            EdMandant = FindViewById<EditText> (Resource.Id.EdMandant);
            EdUrl = FindViewById<EditText>(Resource.Id.EdLoginUrl);
            TxtResult = FindViewById<TextView> (Resource.Id.txtResult);
            LyDummy = FindViewById<LinearLayout> (Resource.Id.LayoutDummy);
            CbOffline = FindViewById<CheckBox>(Resource.Id.cbOffline);

            // RELEASE CHANGE: delete these three lines
            // Get the LoginSaveOption to determine which of the controls should be filled
            string loginSaveOption = BusinessLayer.User.GetLoginSaveOption();
            if (loginSaveOption == "0")
            {
                // Don't show anything
                EdName.Text = "";
                EdPassword.Text = "";
                EdMandant.Text = "";
            }
            else if(loginSaveOption == "1")
            {
                // Just show the Name and Mandant
                // Get the last logged-in User
                BusinessLayer.User user = BusinessLayer.User.GetLastOnlineLoggedUser();
                EdName.Text = user.Name;
                EdMandant.Text = user.Mandant;
            }
            else
            {
                // Show Name, Mandant and passord
                BusinessLayer.User user = BusinessLayer.User.GetLastOnlineLoggedUser();
                EdName.Text = user.Name;
                EdMandant.Text = user.Mandant;
                EdPassword.Text = user.Password;

            }


            //            EdName.Text = "MB7";
            //            EdPassword.Text = "100";
            //            EdMandant.Text = "100";
            EdUrl.Text = DataAccessLayer.Utilities.ServerIP;
            EdUrl.Visibility = ViewStates.Gone;

            // Show the CheckboxOffline if you have network connectability
            // And check it
            if (networkStatus == DataAccessLayer.NetworkState.Disconnected)
            {
                CbOffline.Visibility = ViewStates.Visible;
                CbOffline.Checked = true;
            }
            else
                CbOffline.Visibility = ViewStates.Gone;

            // Handle dismiss button click
            BtnCancel = FindViewById<Button>(Resource.Id.BtnCancel);
            BtnCancel.Click += BtnCancel_Click;

            BtnOk = FindViewById<Button> (Resource.Id.BtnOk);
            BtnOk.Click += BtnOk_Click;

            BtnSetting = FindViewById<Button>(Resource.Id.BtnSetting);
            BtnSetting.Click += BtnSetting_Click;
            //Process.KillProcess (Process.MyPid ());



        }
Пример #2
0
        async public void Authenticate(bool Offline)
        {
            Console.WriteLine("Authenticate");
            ProgressDialog progressDialog = null;

            try
            {
                progressDialog = ProgressDialog.Show(this, "Apollo", Resources.GetString(Resource.String.Authenticating), false);
                progressDialog.SetProgressStyle(ProgressDialogStyle.Spinner);

                InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
                imm.HideSoftInputFromWindow(EdMandant.WindowToken, 0);

                TxtResult.Text = "";
                if (Validate () == false)
                    return;
                networkStatus = GetNetworkStatus ();

                BusinessLayer.User tempUser =await BusinessLayer.User.CreateAsync (EdName.Text, EdPassword.Text, EdMandant.Text,networkStatus,Offline);
                Console.WriteLine("Disposed");
                if (tempUser == null)
                {
                    // There has been a connection failure
                    // The app has to go offline
                    new AlertDialog.Builder(this)
                        .SetPositiveButton("OK", (sender, args) =>
                            {
                                // User pressed yes
                            })
                        .SetMessage(Resource.String.ConnectionFailed)
                        .SetTitle(Resource.String.ConnectionFailedTitle)
                        .Show()
                        ;

                    // Show and check the CheckboxOffline
                    CbOffline.Visibility = ViewStates.Visible;
                    CbOffline.Checked = true;

                    return;
                }

                // Logged successfully
                if (String.IsNullOrEmpty (tempUser.Name) == false)
                {
                    // now check if this device has a license to use the app
                    if (await this.ValidateLicenseAsync(tempUser) == false)
                        return ;

                    // Set the global variable
                   MainActivity.User = tempUser;

                    // then get the permissions of this user
                    Toast.MakeText (this, Resource.String.LoggedSuccessfully,ToastLength.Short);
                    isRunning = false;
                    Finish ();
                    this.StartActivity (typeof(MainActivity));  
                    // Save the user in the offline database
                   MainActivity.User.SaveOnlineUserData();
                    return;
                }
                TxtResult.Visibility = ViewStates.Visible;
                TxtResult.Text = this.Resources.GetString(Resource.String.WrongNamePassword);

                // If the user entered wrong username or password
                // lock the screen for 10 seconds
                if (++counter  > 2)
                {
                    counter = 0;
                    TxtResult.Text = this.Resources.GetString(Resource.String.SystemLocked);
                    TxtResult.Visibility = ViewStates.Visible;
                    TxtResult.RefreshDrawableState();

                    ThreadPool.QueueUserWorkItem (o => LockTenSecond(TxtResult));

                    // Lock the form for 10 Second and show that to the user;
                    //Task.Run(() =>LockTenSecond(TxtResult));
                    //
                    //                  //Thread.Sleep (10000);
                    //TxtResult.Visibility = ViewStates.Gone;
                    return;
                }


            }
            catch(Exception ex)
            {
                AlertDialog a = new  AlertDialog.Builder (this)
                    .SetTitle ("Error")
                    .SetMessage (ex.Message)
                    .SetPositiveButton (Android.Resource.String.Ok, delegate (object o, DialogClickEventArgs e) {})
                    .Create();
                a.Show();
            }
            finally
            {
                if (progressDialog != null)
                    progressDialog.Dismiss ();
            }

            return ;

        }