public bool EditMonitorRange(PhysicalTopology pt) { try { Area area = db.Areas.Find((i) => i.Id == pt.Id); if (area != null && pt.InitBound != null) { RemoveDynamicAreaInfo(area, pt); area.Name = pt.Name;//2019_07_18_cww:添加名称,区域名称可以修改的 area.IsDynamicArea = pt.IsDynamicArea; area.ModelName = pt.ModelName; var transform = pt.Transfrom; //var parent = db.Areas.Find(area.ParentId);//父区域 //var parentBound = db.Bounds.Find(parent.InitBoundId);//父区域的范围 //if (parent.Type == AreaTypes.楼层 && pt.IsRelative)//加上偏移量 //{ // transform.X += parentBound.MinX; // transform.Z += parentBound.MinY; //} pt.InitBound.SetInitBound(pt.Transfrom); area.SetTransform(pt.Transfrom.ToDbModel()); db.Areas.Edit(area); var InitBoundT = pt.InitBound.ToDbModel(); var InitBound = db.Bounds.Find(p => p.Id == InitBoundT.Id); InitBound.SetInitBound(InitBoundT); db.Bounds.Edit(InitBound);//修改 List <DbModel.Location.AreaAndDev.Point> lst = db.Points.FindAll(p => p.BoundId == InitBound.Id); foreach (var item in InitBoundT.Points) { DbModel.Location.AreaAndDev.Point pi = lst.Find(p => p.Index == item.Index); pi.SetPoint(item.X, item.Y, item.Z); } db.Points.EditRange(lst); TagRelationBuffer.Instance().PuUpdateData(); BLL.Buffers.AuthorizationBuffer.Instance(db).PubUpdateData(); } else { return(false); } } catch (Exception ex) { Log.Error(tag, "EditMonitorRange", ex.ToString()); return(false); } return(true); }
private void Worker2_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker1 = sender as BackgroundWorker; string basePath = AppDomain.CurrentDomain.BaseDirectory; string filePath = basePath + "Data\\CADAreaInfo.xml"; CADAreaList list = XmlSerializeHelper.LoadFromFile <CADAreaList>(filePath); list.LineToBlock(); Bll bll = new Bll(); var areas = bll.Areas.ToList(false); List <Point> newPoints = new List <Point>(); List <Area> newBounds = new List <Area>(); List <Area> newAreas = new List <Area>(); int count = 0; for (int i1 = 0; i1 < list.Count; i1++) { CADArea item = list[i1]; var area = areas.Find(i => i.Name == item.Name); if (area != null) { count += item.Shapes.Count; } } int index = 0; for (int i1 = 0; i1 < list.Count; i1++) { CADArea item = list[i1]; var area = areas.Find(i => i.Name == item.Name); if (area != null) { for (int i = 0; i < item.Shapes.Count; i++) { index++; CADShape sp = item.Shapes[i]; Bound bound = new Bound(); bool r1 = bll.Bounds.Add(bound); if (r1) { Area newArea = new Area(); newArea.Name = sp.Name; newArea.Type = AreaTypes.CAD; newArea.ParentId = area.Id; newArea.InitBound = bound; var r2 = bll.Areas.Add(newArea); if (r2) { var pointList = new List <Point>(); foreach (var pt in sp.Points) { var point = new Point(); point.X = (float)pt.X / 1000 - 0.1f; point.Y = (float)pt.Y / 1000 - 0.1f; point.BoundId = bound.Id; var r3 = bll.Points.Add(point); pointList.Add(point); } bound.Shape = 0; bound.IsRelative = true; bound.SetInitBound(pointList.ToArray(), area.InitBound.MinZ, (float)area.InitBound.GetHeight()); bool r4 = bll.Bounds.Edit(bound); newArea.SetBound(bound); bll.Areas.Edit(newArea); } } int percent = (int)((index + 0.0) / count * 100); worker1.ReportProgress(percent); } } } //bll.Areas.AddRange(newAreas); }