示例#1
0
        /// <summary>
        /// Возвращает список неотправленных на сервер сессий чтения
        /// </summary>
        public List<RfidSession> GetUnshippedTags()
        {
            var sessions = new List<RfidSession>();
            var sessionCmd = new SQLiteCommand(@"SELECT * from reading_sessions where delivery_status <> " + (int)RfidSession.DeliveryStatus.Shipped, connection);

            using (var sessionReader = sessionCmd.ExecuteReader())
            {
                while (sessionReader.Read())
                {
                    var session = new RfidSession
                        {
                            id = sessionReader.GetInt32(0),
                            time = sessionReader.GetString(1),
                            location = sessionReader.GetString(2),
                            deliveryStatus = (RfidSession.DeliveryStatus)sessionReader.GetInt32(3),
                            readingStatus = (RfidSession.ReadingStatus)sessionReader.GetInt32(4),
                            sessionMode = (RfidSession.SessionMode)sessionReader.GetInt32(5)
                        };

                    var tagCmd = new SQLiteCommand(@"SELECT * from tubes where session_id = " + session.id, connection);
                    using (var tagReader = tagCmd.ExecuteReader())
                    {
                        while (tagReader.Read())
                        {
                            session.tags.Add(tagReader.GetString(1));
                        }
                    }
                    sessions.Add(session);
                }
            }
            return sessions;
        }
示例#2
0
文件: Program.cs 项目: onami/exp
        public void Read()
        {
            var session = new RfidSession { sessionMode = RfidSession.SessionMode.Reading };

            reader.GetTags(0, 20, ref session.tags, out session.time);

            Console.WriteLine("Count: {0}", session.tags.Count);

            lock (collector)
            {
                collector.Write(session);
            }

            return;
        }
示例#3
0
        public void Write(RfidSession session)
        {
            if (session.tags.Count == 0)
                return;

            var transaction = connection.BeginTransaction();

            //Register a new session
            var cmd = new SQLiteCommand(@"
            INSERT INTO reading_sessions (time_marker,  location_id,  delivery_status,  reading_status,  reading_mode)
                                  VALUES(@time_marker, @location_id, @delivery_status, @reading_status, @reading_mode)", connection);
            cmd.Parameters.AddWithValue("@time_marker", session.time);
            cmd.Parameters.AddWithValue("@location_id", session.location);
            cmd.Parameters.AddWithValue("@delivery_status", session.deliveryStatus);
            cmd.Parameters.AddWithValue("@reading_status", session.readingStatus);
            cmd.Parameters.AddWithValue("@reading_mode", session.sessionMode);
            cmd.ExecuteNonQuery();

            //Look up the last session id
            cmd.CommandText = "SELECT last_insert_rowid()";
            var sessionId = Convert.ToInt32(cmd.ExecuteScalar());

            //Prepare for INSERT
            cmd = new SQLiteCommand("INSERT INTO tubes (session_id, tag) VALUES(@session_id, @tag)", connection);
            cmd.Parameters.AddWithValue("@session_id", sessionId);
            var tag_ = new SQLiteParameter("@tag");
            cmd.Parameters.Add(tag_);

            //Add new tags
            foreach (var tag in session.tags)
            {
                tag_.Value = tag;
                cmd.ExecuteNonQuery();
            }

            transaction.Commit();
        }