Exemplo n.º 1
0
        public static void DeleteCode(ScannedCode code)
        {
            Load();

            int index = 1;

            while (true)
            {
                string serializedClass = Functions.GetSetting("savedCodes", "code" + index);

                if (string.IsNullOrEmpty(serializedClass))
                {
                    break;
                }

                ScannedCode deserializedCode = DeserializeCode(serializedClass);

                if (code.Code == deserializedCode.Code)
                {
                    Functions.DeleteSetting("savedCodes", "code" + index);
                    _scannedCodes.Remove(code);
                    FixCodeIndexes(index + 1);
                    break;
                }

                index++;
            }
        }
Exemplo n.º 2
0
        public static string SerializeCode(ScannedCode code)
        {
            IFormatter formatter = new BinaryFormatter();

            using (MemoryStream memoryStream = new MemoryStream())
            {
                formatter.Serialize(memoryStream, code);
                return(Convert.ToBase64String(memoryStream.ToArray()));
            }
        }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 6
0
        public static void Load()
        {
            if (_scannedCodes.Count > 0)
            {
                return;
            }

            int index = 1;

            while (true)
            {
                string serializedClass = Functions.GetSetting("savedCodes", "code" + index);

                if (string.IsNullOrEmpty(serializedClass))
                {
                    break;
                }

                ScannedCode code = DeserializeCode(serializedClass);
                _scannedCodes.Add(code);

                index++;
            }
        }
Exemplo n.º 7
0
 public static void Save(ScannedCode code)
 {
     Load();
     Functions.SaveSetting("savedCodes", "code" + (_scannedCodes.Count), SerializeCode(code));
 }
Exemplo n.º 8
0
 public static void AddCode(ScannedCode code)
 {
     _scannedCodes.Add(code);
     Save(code);
 }