Exemplo n.º 1
0
        /// <summary>
        /// 写入位置信息
        /// </summary>
        /// <param name="positions"></param>
        /// <returns></returns>
        public bool AddPositions(List <Position> positions)
        {
            bool r = true;

            try
            {
                if (positions == null || positions.Count == 0)
                {
                    return(false);
                }

                AddPositionsBySql(positions);
                if (PartitionThread == null)
                {
                    int count2 = DbHistory.U3DPositions.Count();
                    PartitionThread = new Thread(InsertPartitionInfo);
                    PartitionThread.Start();
                    while (bPartitionInitFlag)
                    {
                    }
                }

                //1.批量插入历史数据数据
                DbHistory.BulkInsert(positions);//插件Z.EntityFramework.Extensions功能

                //修改实时数据
                EditTagPositionListOP(positions);
            }
            catch (Exception ex)
            {
                r = false;
            }
            return(r);
        }
        public bool AddPositions(List <Position> positions)
        {
            bool r = true;

            try
            {
                if (positions == null || positions.Count == 0)
                {
                    return(false);
                }

                //string sql = GetInsertSql(positions);
                //if (!string.IsNullOrEmpty(sql))
                //    DbHistory.Database.ExecuteSqlCommand(sql);

                //List<TagPosition> tagPosList = EditTagPositionList(positions);
                //string sql2 = GetUpdateSql(tagPosList);
                //if (!string.IsNullOrEmpty(sql2))
                //    Db.Database.ExecuteSqlCommand(sql2);

                //todo:获取位置信息参与计算的基站
                foreach (Position position in positions)
                {
                    if (position.Archors != null)
                    {
                        List <Archor> archorList = Archors.FindByCodes(position.Archors);
                        foreach (Archor archor in archorList)
                        {
                            //基站位置和Position位置相等(0.1是为了应对Double类型比较,可能出现的误差)
                            if (Math.Abs(archor.Y - position.Y) < 0.1f)
                            {
                                //找到对应ID,不往后找
                                position.TopoNodeId = archor.Dev.ParentId;
                                break;
                            }
                            //if (!position.TopoNodes.Contains(archor.Dev.ParentId))
                            //    position.TopoNodes.Add(archor.Dev.ParentId);
                        }
                    }
                    else
                    {
                        position.TopoNodeId = null;
                    }
                    //Todo:找不到合适的ID,需要处理一下


                    //foreach (string code in position.Archors)
                    //{
                    //    Archor archor=Archors.FindByCode(code);
                    //    if(!position.TopoNodes.Contains(archor.Dev.ParentId))
                    //        position.TopoNodes.Add(archor.Dev.ParentId);
                    //}
                }
                //1.批量插入历史数据数据
                DbHistory.BulkInsert(positions);//插件Z.EntityFramework.Extensions功能
                //2.获取并修改列表
                List <TagPosition> tagPosList = EditTagPositionList(positions);
                //3.更新列表
                TagPositions.Db.BulkUpdate(tagPosList);//插件Z.EntityFramework.Extensions功能
            }
            catch (Exception ex)
            {
                r = false;
            }
            return(r);
        }