/// <summary>
        /// 新增一条记录
        /// </summary>
        /// <param name="entity"></param>
        public override void AddEntity(DBWatchHistoryChanneInfo entity)
        {
            var item = DataInfos.FirstOrDefault(watch => watch.VID == entity.VID);

            if (item != null)
            {
                DataInfos.Remove(item);
                _table.DeleteOnSubmit(item);
            }
            DataInfos.Insert(0, entity);
            _table.InsertOnSubmit(entity);
            SubmitDatabase();
        }
        /// <summary>
        /// 新增一条搜索历史记录,如果存在则更新
        /// </summary>
        /// <param name="entity"></param>
        public override void AddEntity(DBHistorySearchInfo entity)
        {
            var item = DataInfos.FirstOrDefault(o => o.Key == entity.Key);

            if (item != null)
            {
                DataInfos.Remove(item);
                _table.DeleteOnSubmit(item);
            }
            _table.InsertOnSubmit(entity);
            DataInfos.Insert(0, entity);
            SubmitDatabase();
        }
示例#3
0
        /// <summary>
        /// 插入一条本地数据,如果存在则更新
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        public void InsertLocalRecord(CloudDataInfo record)
        {
            record.Device     = Device;
            record.ModifyTime = DateTime.Now.Subtract(DateTime.Parse("1601,1,1")).Ticks + CloudFactoryBase.TimeInterval;

            var index = DataInfos.IndexOf(record);

            if (index != -1)
            {
                var local = DataInfos[index];
                record.UUID = local.UUID;
                UpdateDeviceHistory(local);
                record.DeviceHistory = local.DeviceHistory;
                local          = record;
                local.DataType = CloudInfoEnum.Update;
                DataInfos.RemoveAt(index);
                DataInfos.Insert(0, local);
            }
            else
            {
                record.UUID = Guid.NewGuid().ToString();
                if (DataInfos.Count >= MaxCount)
                {
                    var removeIndex = DataInfos.Count - 1;
                    var removeInfo  = DataInfos[removeIndex];
                    removeInfo.DataType = CloudInfoEnum.Delete;
                    _postFactory.AddDeleteInfo(removeInfo);
                    DataInfos.RemoveAt(removeIndex);
                }
                record.DataType = CloudInfoEnum.Add;
                UpdateDeviceHistory(record);
                DataInfos.Insert(0, record);
            }
            PostChange();
            SubmitChange();

            if (LocalChangeAction != null)
            {
                LocalChangeAction();
            }
        }