Ejemplo n.º 1
0
        public static void UpdateDTs(tagByte tag)
        {
            string id = "'" + tag.tagID + "'";

            DataRow[] resultT = dtTracker.Select("tagID = " + id);

            if (resultT.Count() < 1)                                                                                     // if tag is not in Tracker,
            {
                dtTracker.Rows.Add(tag.tagID, tag.location, tag.RSSI, 1, tag.evnt, tag.dateTime, tag.dateTime, "false"); //Console.WriteLine("added to DGV:" + tag.tagID);
                //add it to Tracker
            }
            else if (resultT.Count() > 0) // if it is, check if it's in Master,
            {
                DataRow[] resultM = dtMaster.Select("alias = " + id);

                if (resultM.Count() > 0) // if it's in Master, Update RSSI, current location, and last read time
                {
                    foreach (DataRow row in resultM)
                    {
                        dtMaster.Rows[dtMaster.Rows.IndexOf(row)]["RSSI"]             = tag.RSSI;
                        dtMaster.Rows[dtMaster.Rows.IndexOf(row)]["last read time"]   = tag.dateTime;
                        dtMaster.Rows[dtMaster.Rows.IndexOf(row)]["current location"] = tag.location;

                        TagTimer.UpdateSubject(tag.tagID, tag.dateTime);
                    }
                }
                else//if it's not, check its readcount. if readcount hits threshhold, add it to master.
                {
                    foreach (DataRow row in resultT)
                    {
                        if (Convert.ToInt32(dtTracker.Rows[dtTracker.Rows.IndexOf(row)]["read count"]) >= readFloor) // && dtTracker.Rows[dtTracker.Rows.IndexOf(row)]["in master"] == "false")
                        {
                            dtMaster.Rows.Add(tag.tagID,
                                              dtTracker.Rows[dtTracker.Rows.IndexOf(row)]["discovered at antenna"],
                                              dtTracker.Rows[dtTracker.Rows.IndexOf(row)]["discovered at antenna"],
                                              DateTime.Now,
                                              DateTime.Now,
                                              tag.RSSI
                                              );

                            TagTimer.AddSubject(tag.tagID, tag.dateTime);

                            tag.evnt = "ADDED";
                            InsertSignal.IncomingSignal(tag);

                            dtTracker.Rows[dtTracker.Rows.IndexOf(row)]["in master"]  = "true";
                            dtTracker.Rows[dtTracker.Rows.IndexOf(row)]["RSSI"]       = "# # # # #";
                            dtTracker.Rows[dtTracker.Rows.IndexOf(row)]["last read"]  = "# # # # #";
                            dtTracker.Rows[dtTracker.Rows.IndexOf(row)]["read count"] = "0";
                        }
                        else//if it hasn't hit its readcount yet, keep updating it on tracker
                        {
                            if (dtTracker.Rows[dtTracker.Rows.IndexOf(row)]["in master"] != "false")
                            {
                                dtTracker.Rows[dtTracker.Rows.IndexOf(row)]["in master"] = "false";
                            }
                            dtTracker.Rows[dtTracker.Rows.IndexOf(row)]["RSSI"]       = tag.RSSI;
                            dtTracker.Rows[dtTracker.Rows.IndexOf(row)]["last read"]  = tag.dateTime;
                            dtTracker.Rows[dtTracker.Rows.IndexOf(row)]["read count"] = Convert.ToInt32(dtTracker.Rows[dtTracker.Rows.IndexOf(row)]["read count"]) + 1;
                        }
                    }
                }
            }
            RefreshSignal.IncomingSignal(bsTracker);
            RefreshSignal.IncomingSignal(bsMaster);

            //Refresh(bsTracker, dgvTracker);
            //Refresh(bsMaster, dgvMaster);
            ////SetCount(lblTagCount, (dgvTracker.Rows.Count - 1).ToString());
            //SetCount(lblTagCount, dgvTracker.Rows.Count.ToString());
        }
Ejemplo n.º 2
0
 public frmRFIDMain()
 {
     InitializeComponent();
     DataTables.InitDTs();
     TagTimer.InitTimer();
 }