public void BindCardToPerson(Personnel person, LocationCard tag) { if (tag != null && person != null) { LocationCardToPersonnel cardToPerson = new LocationCardToPersonnel(); cardToPerson.PersonnelId = person.Id; cardToPerson.LocationCardId = tag.Id; LocationCardToPersonnels.Add(cardToPerson); tag.IsActive = true;//绑定了人员就激活 LocationCards.Edit(tag); } }
private void EditTagPositionListOP(List <Position> positions) { //1.获取列表 List <LocationCardPosition> tagPosList = LocationCardPositions.ToList(); List <LocationCardPosition> changedTagPosList = new List <LocationCardPosition>(); List <LocationCardPosition> newTagPosList = new List <LocationCardPosition>(); //2.修改数据 for (int i = 0; i < positions.Count; i++) { Position position = positions[i]; if (position == null) { continue; //位置信息可能有null } LocationCard lc = LocationCards.Where(p => p.Code == position.Code).FirstOrDefault(); if (lc == null) { continue; } if (lc.Flag != position.Flag || lc.Power != position.Power) { lc.Flag = position.Flag; lc.Power = position.Power; if (lc.Power >= 400) { lc.PowerState = 0; } else { lc.PowerState = 1; } LocationCards.Edit(lc); } var tagPos = tagPosList.Find(item => item.Id == position.Code); if (tagPos != null) { tagPos.Edit(position);//修改实时位置数据 if (!changedTagPosList.Contains(tagPos)) { changedTagPosList.Add(tagPos); } } else { LocationCardPosition newTagPos = new LocationCardPosition(position); newTagPosList.Add(newTagPos); } } List <LocationCardPosition> noChangedTagPosList = new List <LocationCardPosition>();//没有移动的位置信息 foreach (var tag1 in tagPosList) { if (!changedTagPosList.Contains(tag1)) { noChangedTagPosList.Add(tag1); } } ////设置实时位置的移动状态 //foreach (var tag1 in noChangedTagPosList) //{ // TimeSpan time = DateTime.Now - tag1.DateTime; // if (time.TotalSeconds > 30) // { // if (tag1.Flag == "0:0:0:0:1") // { // tag1.MoveState = 1; // } // else // { // tag1.MoveState = 2; // } // } //} try { LocationCardPositions.Db.BulkUpdate(changedTagPosList);//插件Z.EntityFramework.Extensions功能 } catch (Exception ex) { Log.Error(string.Format("EditTagPositionListOP1,Type:{0},Count:{1},Error:{2}", typeof(LocationCardPosition), changedTagPosList.Count(), ex.Message)); } try { LocationCardPositions.Db.BulkInsert(newTagPosList);//插件Z.EntityFramework.Extensions功能 } catch (Exception ex) { Log.Error(string.Format("EditTagPositionListOP2,Type:{0},Count:{1},Error:{2}", typeof(LocationCardPosition), changedTagPosList.Count(), ex.Message)); } }