示例#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 void InitializeTeacher()
        {
            SetContentView(Resource.Layout.MainTeacher);
            this.ActionBar.NavigationMode = ActionBarNavigationMode.Standard;
            this.Title = "APlus Teacher Panel";

            Button btnGrade        = FindViewById <Button> (Resource.Id.btnGrade);
            Button btnSubmitGrades = FindViewById <Button> (Resource.Id.btnSubmitGrades);

            UpdateCounter();

            Button btnDeleteSavedGrades = FindViewById <Button> (Resource.Id.btnDeleteSavedGrades);

            btnGrade.Click += delegate {
                StartActivityForResult(typeof(ScanCodeActivity), 1);
            };

            btnSubmitGrades.Click += delegate {
                ThreadPool.QueueUserWorkItem(o => {
                    RunOnUiThread(() => btnSubmitGrades.Enabled = false);

                    while (!_checkedStatus)
                    {
                        Thread.Sleep(100);
                    }

                    try
                    {
                        ScannedCodesCollection.Sync();
                    }
                    finally
                    {
                        RunOnUiThread(() => {
                            btnSubmitGrades.Enabled = true;
                            UpdateCounter();
                        });
                    }
                });
            };

            btnDeleteSavedGrades.Click += delegate {
                ScannedCodesCollection.DeleteAllCodes();
                UpdateCounter();
            };
        }
示例#3
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();
        }
示例#4
0
        private void ShowCodeAlreadyScannedDialog()
        {
            ScannedCode code = ScannedCodesCollection.GetFullCodeFromCode(_qrCode);

            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(string.Format("Code has already been graded at {0} with {1}!", code.Subject, code.Grade));
            stringBuilder.Append("Do you want to delete the old grade and save a new one?");

            var dialogFragment = new DialogFragment();

            dialogFragment.InitializeYesNo(stringBuilder.ToString(), "Question", delegate {
                ScannedCodesCollection.DeleteCode(code);
                _codeAlreadyUsed = false;
            }, delegate {
                Finish();
            });

            dialogFragment.Show();
        }
示例#5
0
        private void Next(object sender, EventArgs e)
        {
            if (!CheckDataOk())
            {
                return;
            }

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

            ScannedCodesCollection.AddCode(code);

            Intent intent = new Intent(this, typeof(ScanCodeActivity));
            Bundle bundle = new Bundle();

            bundle.PutString("subject", _editTextSubject.Text);
            intent.PutExtras(bundle);

            StartActivity(intent);
            Finish();
        }
示例#6
0
        private void UpdateCounter()
        {
            if (this.Title != "APlus Teacher Panel")
            {
                return;
            }

            string alreadyUpdatedRegex = @".*\([0-9]+\)";
            string counterRegex        = @"(?!.*\()[0-9]+(?=\))";

            Button btnSubmitGrades = FindViewById <Button> (Resource.Id.btnSubmitGrades);
            int    codesCount      = ScannedCodesCollection.CodesCount();

            if (Regex.IsMatch(btnSubmitGrades.Text, alreadyUpdatedRegex))
            {
                btnSubmitGrades.Text = Regex.Replace(btnSubmitGrades.Text, counterRegex, codesCount.ToString());
            }
            else
            {
                btnSubmitGrades.Text += string.Format(" ({0})", codesCount);
            }
        }