コード例 #1
0
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if (requestCode != 1)
            {
                return;
            }

            if (data == null)
            {
                Finish();
                return;
            }

            string result = data.GetStringExtra("la.droid.qr.result");

            if (string.IsNullOrWhiteSpace(result))
            {
                ResponseManager.ShowMessage("Error", "Invalid QR code scanned!");
                return;
            }

            _qrCode = result;

            if (ScannedCodesCollection.CodeExists(result))
            {
                _codeAlreadyUsed = true;
                ShowCodeAlreadyScannedDialog();
                return;
            }

            _scannedCode = true;
        }
コード例 #2
0
        private static void DoLogout()
        {
            if (Functions.IsOffline())
            {
                Functions.CurrentContext.StartActivity(typeof(LoginActivity));
                Functions.CurrentContext.Finish();                  // Rest of log in data cleared in constructor
                return;
            }

            var data = new NameValueCollection();

            data.Add("logout", string.Empty);

            string response = WebFunctions.Request(data);

            if (response == "Logged out successfully" || response == "Not logged in!")
            {
                Functions.CurrentContext.StartActivity(typeof(LoginActivity));
                Functions.CurrentContext.Finish();                  // Rest of log in data cleared in constructor
            }
            else
            {
                ResponseManager.ShowMessage("Error", response);
                ResponseManager.DismissLoading();
            }
        }
コード例 #3
0
        public static void DeleteAllCodes()
        {
            Functions.DeleteSetting("savedCodes");
            _scannedCodes.Clear();

            ResponseManager.ShowMessage("Success", "All local grades deleted!");
        }
コード例 #4
0
        private bool CheckDataOk()
        {
            if (string.IsNullOrWhiteSpace(_editTextSubject.Text))
            {
                ResponseManager.ShowMessage("Error", "Subject cannot be empty!");
                return(false);
            }

            return(true);
        }
コード例 #5
0
        private void DoRegister(object sender, EventArgs e)
        {
            if (Functions.IsOffline())
            {
                ResponseManager.ShowMessage("Error", "No internet connection!");
                return;
            }

            if (_txtPassword.Text != _txtPassword2.Text)
            {
                ResponseManager.ShowMessage("Error", "Passwords do not match!");
                return;
            }

            ResponseManager.ShowLoading("Creating account...");

            var data = new NameValueCollection();

            data.Add("register", string.Empty);
            data.Add("email", _txtEmail.Text);
            data.Add("password", Functions.GetSha256(_txtPassword.Text));
            data.Add("firstname", _txtFirstName.Text);
            data.Add("lastname", _txtLastName.Text);
            data.Add("class", _txtClass.Text);

            string reply = WebFunctions.Request(data);

            ResponseManager.DismissLoading();

            if (reply != "Account created!")
            {
                ResponseManager.ShowMessage("Error", reply);
                WebFunctions.ClearCookies();
                return;
            }

            RunOnUiThread(delegate {
                var dialogFragment = new DialogFragment();

                dialogFragment.InitializeOk(reply, "Success", delegate {
                    Intent resultData = new Intent();
                    resultData.PutExtra("email", _txtEmail.Text);
                    resultData.PutExtra("password", _txtPassword.Text);
                    SetResult(Result.Ok, resultData);
                    Finish();
                });

                dialogFragment.Show();
            });
        }
コード例 #6
0
        private void Finish(object sender, EventArgs e)
        {
            if (!CheckDataOk())
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(_editTextSubject.Text))
            {
                ResponseManager.ShowMessage("Error", "Subject cannot be empty!");
                return;
            }

            ScannedCode code = new ScannedCode(_editTextSubject.Text, int.Parse(_txtViewGrade.Text), _qrCode);

            ScannedCodesCollection.AddCode(code);
            Finish();
        }
コード例 #7
0
        private void DoLogin(object sender, EventArgs e)
        {
            if (Functions.IsOffline())
            {
                ResponseManager.ShowMessage("Error", "No internet connection!");
                return;
            }

            ResponseManager.ShowLoading("Logging in...");

            var data = new NameValueCollection();

            data.Add("login", string.Empty);
            data.Add("email", _txtEmail.Text);
            data.Add("password", Functions.GetSha256(_txtPassword.Text));

            string reply = WebFunctions.Request(data);

            if (reply != "Login success!")
            {
                ResponseManager.DismissLoading();
                ResponseManager.ShowMessage("Error", reply);
                WebFunctions.ClearCookies();
                return;
            }

            data.Clear();
            data.Add("getaccounttype", string.Empty);

            reply = WebFunctions.Request(data);

            if (reply != "student" && reply != "teacher")
            {
                ResponseManager.DismissLoading();
                ResponseManager.ShowMessage("Error", "Unrecognized account type!");
                WebFunctions.ClearCookies();
                return;
            }

            Functions.SaveSetting("settings", "accountType", reply);
            Functions.SaveSetting("settings", "loggedIn", "true");
            StartActivity(typeof(MainActivity));
            Finish();
        }
コード例 #8
0
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            if (item.ItemId == Resource.Id.action_settings)
            {
                ResponseManager.ShowLoading("Logging out...");
                ThreadPool.QueueUserWorkItem(o => DoLogout());
            }
            else if (item.ItemId == Resource.Id.action_refresh)
            {
                if (Functions.IsOffline())
                {
                    ResponseManager.ShowMessage("Error", "Cannot complete action while offline.");
                    return(base.OnOptionsItemSelected(item));
                }

                ResponseManager.ShowLoading("Fetching user data...");
                ThreadPool.QueueUserWorkItem(o => FetchStudentData());
            }

            return(base.OnOptionsItemSelected(item));
        }
コード例 #9
0
        private void InitializeStudent()
        {
            SetContentView(Resource.Layout.MainStudent);
            this.ActionBar.NavigationMode = ActionBarNavigationMode.Standard;
            this.Title = "APlus Student Panel";

            if (Functions.IsOffline())
            {
                ResponseManager.ShowMessage("Error", "Cannot complete action while offline.");
                return;
            }

            ResponseManager.ShowLoading("Fetching user data...");

            ThreadPool.QueueUserWorkItem(o => {
                while (!_checkedStatus)
                {
                    Thread.Sleep(100);
                }

                FetchStudentData();
            });
        }
コード例 #10
0
        private void btnRegister_OnClick(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(_txtEmail.Text) || string.IsNullOrWhiteSpace(_txtPassword.Text) ||
                string.IsNullOrWhiteSpace(_txtPassword2.Text) || string.IsNullOrWhiteSpace(_txtFirstName.Text) ||
                string.IsNullOrWhiteSpace(_txtLastName.Text) || string.IsNullOrWhiteSpace(_txtClass.Text))
            {
                ResponseManager.ShowMessage("Error", "Information is missing!");
                return;
            }

            if (_txtPassword.Text.Length < 6)
            {
                ResponseManager.ShowMessage("Error", "Password must be at least 6 characters long!");
                return;
            }

            if (_txtPassword.Text != _txtPassword2.Text)
            {
                ResponseManager.ShowMessage("Error", "Passwords don't match!");
                return;
            }

            ThreadPool.QueueUserWorkItem(o => DoRegister(sender, e));
        }
コード例 #11
0
        public static void Sync()
        {
            Load();

            if (_scannedCodes.Count == 0)
            {
                ResponseManager.ShowMessage("Note", "No grades to sync!");
                return;
            }

            StringBuilder stringBuilder = new StringBuilder();

            foreach (var code in _scannedCodes)
            {
                stringBuilder.AppendFormat("{0}-|-{1}-|-{2}-||-", code.Subject, code.Grade, code.Code);
            }

            var data = new NameValueCollection();

            data.Add("newgrades", string.Empty);
            data.Add("data", stringBuilder.ToString());

            string reply = WebFunctions.Request(data);

            string[] formattedReply = Regex.Split(reply, Environment.NewLine);

            foreach (string line in formattedReply)
            {
                if (line.StartsWith("Grade saved"))
                {
                    DeleteFirstCode();
                }
                else if (line.StartsWith("Code already used"))
                {
                    DeleteFirstCode();
                }
            }

            reply          = reply.Replace("Grade saved!", string.Empty);
            reply          = reply.Replace("Code already used!", string.Empty);
            formattedReply = Regex.Split(reply, Environment.NewLine);
            formattedReply = formattedReply.TrimArray();

            List <string> gradedStudents = new List <string> ();
            StringBuilder resultMessage  = new StringBuilder();

            foreach (string line in formattedReply)
            {
                if (line.StartsWith("Graded student"))
                {
                    gradedStudents.Add(line.Replace("Graded student: ", string.Empty));
                }
                else
                {
                    foreach (string line2 in formattedReply)
                    {
                        resultMessage.AppendLine(line2);
                    }

                    Functions.CurrentContext.RunOnUiThread(() => ResponseManager.ShowMessage("Success", resultMessage.ToString()));
                    return;
                }
            }

            if (gradedStudents.Count == 0)
            {
                resultMessage.AppendLine("All sent codes were already graded!");
            }
            else
            {
                resultMessage.AppendLine("Grades successfully synced to server! Results:");
                resultMessage.AppendLine();

                foreach (string student in Functions.ShuffleArray(gradedStudents.ToArray()))
                {
                    resultMessage.AppendLine(student);
                }
            }

            Functions.CurrentContext.RunOnUiThread(() => ResponseManager.ShowMessage("Success", resultMessage.ToString()));
        }