Statistiques
| Révision:

xamarin / SicpaXamDevice / trunk / Sicpa.Xam.Device.Droid / Rfid / Agrident / AgridentReceiver.cs @ 4

Historique | Voir | Annoter | Télécharger (1,742 ko)

1 4 jfbompa
using Android.Content;
2
using Sicpa.Xam.Device.Forms.Models;
3
using System;
4
5
6
namespace Sicpa.Xam.Device.Droid.Rfid.Agrident
7
{
8
    public class AgridentReceiver : BroadcastReceiver
9
    {
10
        public EventHandler<InfosRfid> TagLuReceiver;
11
        public override void OnReceive(Context context, Intent intent)
12
        {
13
            if (intent.Action.Equals(AgridentConstantes.LECTURE_TAG_REUSSI))
14
            {
15
                //on récupère la string DONNEE_LU de l'intent
16
                string tmpDonnee = intent.GetStringExtra(AgridentConstantes.DONNEE_LUE);
17
                //ici on met en forme toutes les informations qui doivent êtres contenu dans la classe RfidInfos
18
                string tmpIsoRfid = tmpDonnee.Substring(1, 15);
19
                string tmpCodePays = tmpDonnee.Substring(1, 3);
20
                string tmpdNumAnimal = tmpDonnee.Substring(4, 12);
21
                string tmpTypeTag = "";
22
                string tmpIsoEtendu = tmpDonnee;
23
                string tmpCodeEtendu = tmpDonnee.Substring(0, 1);
24
                bool tmpTagLu = true;
25
                //on met toutes ces infos dans une variable qui sera passée à l'événement
26
                var infosEvent = new InfosRfid() { IsoRfid = tmpIsoRfid, CodePays = tmpCodePays, NumeroAnimal = tmpdNumAnimal, TypeTag = tmpTypeTag, IsoEtendu = tmpIsoEtendu, CodeEtendu = tmpCodeEtendu, TagLu = tmpTagLu };
27
28
                TagLuReceiver?.Invoke(this, infosEvent);
29
            }
30
            else
31
            {
32
                var infosEvent = new InfosRfid() { IsoRfid = "No Tag", CodePays = "", NumeroAnimal = "", TypeTag = "", IsoEtendu = "", CodeEtendu = "", TagLu = false };
33
                TagLuReceiver?.Invoke(this, infosEvent);
34
            }
35
36
        }
37
    }
38
}