void OnTagRead(NfcTag tag) { try { string msg; _tag = tag; if (_tag == null) { msg = "Internal error, The Tag is Invalid!"; WarnNotify("Warning|" + msg); return; } if ((tag.Content == null) || (tag.Content.Count == 0)) { if (!tag.IsLocked()) { msg = "The Device has no valid content yet. You may proceed with Tag Writting."; WarnNotify("Warning|" + msg); } else { msg = "The Tag has no valid content, but is not writable"; WarnNotify("Warning|" + msg); } } else { var ndef = tag.Content.FirstOrDefault(); switch (ndef) { case null: msg = "This Tag is Empty."; WarnNotify("Warning|" + msg); return; case RtdSmartPoster smart: txtStudentMatric.Text = smart.Title.FirstOrDefault()?.Value ?? ""; btnStudentRequest_Click(this, EventArgs.Empty); msg = "Valid EdBoxPremium Student."; SuccessNotify("Awesome|" + msg); break; default: msg = "Data found but its not a EdBoxPremium Data."; WarnNotify("Warning|" + msg); break; } } } catch (Exception ex) { ErrorHandler.TreatError(ex); } }
void OnTagRead(NfcTag tag) { try { string msg; _tag = tag; _studentData = null; if (_tag == null) { msg = "Internal error, The Tag is Invalid!"; WarnNotify("Warning|" + msg); return; } if ((tag.Content == null) || (tag.Content.Count == 0)) { if (!tag.IsLocked()) { msg = "The Device has no valid content yet. You may proceed with Tag Writting."; WarnNotify("Warning|" + msg); } else { msg = "The Tag has no valid content, but is not writable"; WarnNotify("Warning|" + msg); } } else { var ndef = tag.Content.FirstOrDefault(); switch (ndef) { case null: msg = "This Tag is Empty."; WarnNotify("Warning|" + msg); return; case RtdSmartPoster smart: using (var localEntities = new LocalEntities()) { var matricNumber = smart.Title.FirstOrDefault()?.Value ?? ""; _studentData = localEntities.Student_ProfileData.FirstOrDefault(x => x.MatricNumber == matricNumber && x.TagId == _tagUID); msg = _studentData == null ? "No Student Record, Access Denied." : $"{_studentData.FirstName} {_studentData.LastName}, Access Granted"; var speak = new SpeechSynthesizer(); speak.SpeakAsync(msg); } SuccessNotify("Awesome|" + msg); break; default: msg = "Data found but its not an EdBoxPremium Data."; WarnNotify("Warning|" + msg); break; } } } catch (Exception ex) { ErrorHandler.TreatError(ex); } }
void OnTagRead(NfcTag _tag) { tag = _tag; Trace.WriteLine("Read terminated"); if (tag == null) { MessageBox.Show("Internal error, tag is null!"); return; } if ((tag.Content == null) || (tag.Content.Count == 0)) { if (!tag.IsLocked()) { MessageBox.Show("The Tag has no valid content yet. You may create your own content and write it onto the tag", "This NFC Tag is empty"); setEditable(true); } else { MessageBox.Show("The Tag has no valid content, but is not writable", "This NFC Tag is empty"); } } else { Unselect(); for (int i = 0; i < tag.Content.Count; i++) { /* Display the first record we support in the tag's content */ Ndef ndef = tag.Content[i]; if (ndef is RtdSmartPoster) { SelectSmartPoster(); } else if (ndef is RtdUri) { SelectUri(); } else if (ndef is RtdText) { SelectText(); } else if (ndef is RtdVCard) { SelectVCard(); } else if (ndef is RtdMedia) { SelectMedia(); } else if (ndef is RtdHandoverSelector) { SelectWifiHandover(); } if (control != null) { control.SetContent(ndef); break; } } if (!tag.IsLocked()) { /* It will be possible to rewrite the tag */ setEditable(true); } if (control == null) { /* No supported record has been found */ Unselect(); MessageBox.Show("This Tag contains a valid content, but this application doesn't know how to display it", "This NFC Tag is not supported"); } } }