private void DisplayStudentData(Student_ProfileData studentProfileData)
        {
            if (studentProfileData == null)
            {
                picBxStudentImage.Image      = Resources.logo_only_128;
                lblCurrentStudentName.Text   = @"Waiting for Student";
                lblCurrentStudentStatus.Text = @"Please Place a Tag";
                picBxStudentImageDup.Image   = Resources.logo_only_128;
                picBxStudentImageDup.Visible = false;
                return;
            }

            lblCurrentStudentName.Text    = studentProfileData.LastName + @", " + studentProfileData.FirstName;
            lblCurrentStudentStatus.Text  = $"Program: {studentProfileData.Program} | Department: {studentProfileData.Department}\n";
            lblCurrentStudentStatus.Text += $"Sex: {studentProfileData.Sex} | Blood Group: {studentProfileData.BloodGroup}\n";

            lblCurrentStudentStatus.Text += $"Phone: {studentProfileData.Phone} | Email: {studentProfileData.Email}";

            if (string.IsNullOrEmpty(studentProfileData.Picture))
            {
                return;
            }

            var imageBytes = Convert.FromBase64String(studentProfileData.Picture);

            using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
            {
                picBxStudentImage.Image = Image.FromStream(ms, true);
            }
        }
        private void btnAcceptAttendance_Click(object sender, EventArgs e)
        {
            if (_schoolAttendances.Any(x => x.StudentMatricNumber == _studentData.MatricNumber))
            {
                WarnNotify("Not Allowed|This Student has already been Noted");
                return;
            }

            _schoolAttendances.Add(new School_Attendance()
            {
                IsDeleted           = false,
                AttendanceSessionId = 0,
                DateRecorded        = DateTime.Now,
                StudentMatricNumber = _studentData.MatricNumber,
                StudentTagId        = _tagUID
            });

            lstTakenAttendance.Items.Add($"{_studentData.MatricNumber}: {_tagUID}");
            _studentData = null;
        }
        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 ReaderStatusChanged(uint readerState, CardBuffer cardAtr)
        {
            try
            {
                string msg;

                if (InvokeRequired)
                {
                    this.BeginInvoke(new ReaderStatusChangedInvoker(ReaderStatusChanged), readerState, cardAtr);
                    return;
                }

                SCARD.ReaderStatusToString(readerState);

                if (cardAtr != null)
                {
                    _tagATR = RemoveSpaces(cardAtr.AsString(" "));
                }
                else
                {
                }

                if (readerState == SCARD.STATE_UNAWARE)
                {
                    if (_cardchannel != null)
                    {
                        _cardchannel.Disconnect();
                        _cardchannel = null;
                    }

                    if (!_inLoop)
                    {
                        msg = "The reader we were working with has gone AWOL from the system.";
                        WarnNotify("Warning|" + msg);
                        _inLoop = true;
                    }

                    tmrTagMonitor.Enabled = true;
                    msg = "Reader not Found. Please check Connection.";
                    WarnNotify("Warning|" + msg);
                }
                else if ((readerState & SCARD.STATE_EMPTY) != 0)
                {
                    _tag    = null;
                    _inLoop = false;

                    _studentData = null;
                    InfoNotify("Ready|Please insert another card for Tagging");

                    if (_cardchannel == null)
                    {
                        return;
                    }

                    _cardchannel.Disconnect();
                    _cardchannel = null;
                }
                else if ((readerState & SCARD.STATE_UNAVAILABLE) != 0)
                {
                }
                else if ((readerState & SCARD.STATE_MUTE) != 0)
                {
                }
                else if ((readerState & SCARD.STATE_INUSE) != 0)
                {
                    _inLoop = false;
                }
                else if ((readerState & SCARD.STATE_PRESENT) != 0)
                {
                    _inLoop = false;
                    if (_cardchannel != null)
                    {
                        return;
                    }

                    _cardchannel = new SCardChannel(DeviceManager.DeviceSpec.Nfc);

                    if (_cardchannel.Connect())
                    {
                        var mifare = new MiFareCardProg();
                        _tagUID = RemoveSpaces(mifare.GetUID(DeviceManager.DeviceSpec.Nfc).Trim());

                        _cardthread = new Thread(card_read_proc);
                        _cardthread.Start();
                    }
                    else
                    {
                        msg =
                            "NearField failed to connect to the card in the reader. Check that you don't have another application running in background that tries to work with the smartcards in the same time as NearField";
                        WarnNotify("Warning|" + msg);
                        _cardchannel = null;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.TreatError(ex);
            }
        }