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

            lblCurrentStudentName.Text    = studentProfileData.StudentProfileData.LastName + @", " + studentProfileData.StudentProfileData.FirstName;
            lblCurrentStudentStatus.Text  = $"Sex: {studentProfileData.StudentProfileData.Sex} | Phone: {studentProfileData.StudentProfileData.Phone}\n";
            lblCurrentStudentStatus.Text += $@"Email: {studentProfileData.StudentProfileData.Email}";

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

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

            // Convert byte[] to Image
            using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
            {
                picBxStudentImage.Image = Image.FromStream(ms, true);
            }
        }
        private void btnStudentRequest_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtStudentMatric.Text.Trim()))
            {
                WarnNotify("Warning|Please enter a Matric Number");
                return;
            }

            new Thread(() =>
            {
                try
                {
                    _workingState = true;

                    InfoNotify("Please Wait!|Searching for the Student.");

                    var settings =
                        RemoteRequest.Get(
                            $"{DatabaseManager.UpdateSpec.RemoteUrl}ApiStudentManagement/PullStudentDataByMatricNumber?matricNumber={txtStudentMatric.Text.Trim()}");
                    if (settings.Result.Status)
                    {
                        _studentData =
                            JsonConvert.DeserializeObject <StudentCompleteData>(
                                JsonConvert.SerializeObject(settings.Result.Data));

                        if (string.IsNullOrEmpty(_studentData.StudentProfileData.TagId))
                        {
                            WarnNotify("Awesome!|This is a valid student but it does not have a Tag Yet.");
                        }
                        else
                        {
                            SuccessNotify($"Awesome!|The Tag is Valid. Tag Id is {_tagUID} and Matriculation Number is {_studentData.StudentProfileData.MatricNumber}");
                        }
                    }
                    else
                    {
                        WarnNotify("Oops!|" + settings.Result.Message);
                    }

                    _workingState = false;
                }
                catch (Exception exception)
                {
                    ErrorHandler.TreatError(exception);
                }
            }).Start();
        }
        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");
                    txtStudentMatric.Clear();

                    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);
            }
        }