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++; } }
public static string SerializeCode(ScannedCode code) { IFormatter formatter = new BinaryFormatter(); using (MemoryStream memoryStream = new MemoryStream()) { formatter.Serialize(memoryStream, code); return(Convert.ToBase64String(memoryStream.ToArray())); } }
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(); }
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(); }
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(); }
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++; } }
public static void Save(ScannedCode code) { Load(); Functions.SaveSetting("savedCodes", "code" + (_scannedCodes.Count), SerializeCode(code)); }
public static void AddCode(ScannedCode code) { _scannedCodes.Add(code); Save(code); }