Ejemplo n.º 1
0
 /// <summary>
 /// 插入数据
 /// </summary>
 /// <param name="channelName">通道名称</param>
 /// <param name="message">待插入消息</param>
 /// <returns>是否成功</returns>
 public Boolean InsertMessageData(String channelName, ReceiveObject message)
 {
     lock (queueLock)
     {
         Boolean result = true;
         if (this.lastInsertTime.ContainsKey(message.ReceiveID.ToString()) == false)
         {
             this.lastInsertTime[message.ReceiveID.ToString()] = DateTime.MinValue;
         }
         if (DateTime.Now < lastInsertTime[message.ReceiveID.ToString()].AddMilliseconds(100))
         {
             result = false;
         }
         else
         {
             if (this.isDisposed == false)
             {
                 messageQueue.Enqueue(new MessageModel()
                 {
                     Message     = message,
                     ChannelName = channelName,
                 });
             }
             if ((messageQueue.Count > 100) || this.isDisposed)
             {
                 var tempBuffer = messageQueue;
                 messageQueue = new Queue <MessageModel>();
                 foreach (var item in tempBuffer)
                 {
                     var sql = ConstDefine.InsertData;
                     SQLiteParameter[] parameters = new SQLiteParameter[]
                     {
                         new SQLiteParameter("@FrameType", item.Message.FrameType),
                         new SQLiteParameter("@ReceiveID", item.Message.ReceiveID),
                         new SQLiteParameter("@TimeStamp", item.Message.TimeStamp),
                         new SQLiteParameter("@Length", item.Message.Length),
                         new SQLiteParameter("@data1", item.Message.ReceiveData[0]),
                         new SQLiteParameter("@data2", item.Message.ReceiveData[1]),
                         new SQLiteParameter("@data3", item.Message.ReceiveData[2]),
                         new SQLiteParameter("@data4", item.Message.ReceiveData[3]),
                         new SQLiteParameter("@data5", item.Message.ReceiveData[4]),
                         new SQLiteParameter("@data6", item.Message.ReceiveData[5]),
                         new SQLiteParameter("@data7", item.Message.ReceiveData[6]),
                         new SQLiteParameter("@data8", item.Message.ReceiveData[7]),
                         new SQLiteParameter("@IsSelfSend", item.Message.IsSelfSend),
                         new SQLiteParameter("@ChannelName", item.ChannelName)
                     };
                     var effectLines = SQLExecuteHandler.ExecuteNonQuery(ref this.connection, ref sql, parameters);
                     if (effectLines < 0)
                     {
                         result = false;
                     }
                 }
                 tempBuffer.Clear();
             }
         }
         return(result);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="page">要显示的页数</param>
        /// <param name="size">每页需要显示的数据量</param>
        /// <returns>查询结果列表</returns>
        public List <ChannelDataInfo> QueryDataList(Int32 page, Int32 size = 1000)
        {
            var result = new List <ChannelDataInfo>();
            var sql    = $"SELECT * FROM {ConstDefine.TableName} order by id limit {size} offset {page}*{size}";

            result = SQLExecuteHandler.QueryData(ref this.connection, ref sql);
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 删除全部记录
        /// </summary>
        /// <returns>返回受影响行数</returns>
        public Int32 DeleteAllRecord()
        {
            Int32 result = 0;
            var   sql    = ConstDefine.DeleteAllRecord;

            result = SQLExecuteHandler.ExecuteNonQuery(ref this.connection, ref sql);
            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 判断指定表是否存在
        /// </summary>
        /// <returns>判断结果</returns>
        private Boolean TableExist()
        {
            Boolean result         = false;
            var     sql            = ConstDefine.TableExistQuery;
            var     parameterArray = new SQLiteParameter[]
            {
                new SQLiteParameter("name", ConstDefine.TableName)
            };

            if (SQLExecuteHandler.QueryCount(ref this.connection, ref sql, parameterArray) > 0)
            {
                result = true;
            }
            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 创建表
        /// </summary>
        private void CreateTable()
        {
            var sql = ConstDefine.CreateTable;

            SQLExecuteHandler.ExecuteNonQuery(ref this.connection, ref sql);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 删除表
        /// </summary>
        public void DeleteTable()
        {
            var sql = ConstDefine.DeleteTable;

            SQLExecuteHandler.ExecuteNonQuery(ref this.connection, ref sql);
        }