private void LoadJailRoomList() { newJailRoom.Items.Clear(); newJailRoom.DataSource = MapArea.All; newJailRoom.DataTextField = "AreaName"; newJailRoom.DataValueField = "Id"; newJailRoom.DataBind(); int roomId = CulpritRoomReference.GetRoomIdByCulpritId(_id); ListItem listItem = newJailRoom.Items.FindByValue(roomId.ToString()); if (listItem == null) { newJailRoom.Items.Insert(0, new ListItem("请选择 ..", "-1")); } else { newJailRoom.SelectedIndex = -1; listItem.Selected = true; } }
public static string ChangeJailRoom(int culpritId, int newJailRoomId) { //get Host HostTag hostTag = HostTag.GetById(culpritId); if (hostTag == null || hostTag.HostName == "") { return(""); } //记录旧ID var oldJailRoomId = CulpritRoomReference.GetRoomIdByCulpritId(culpritId); //取得新监舍名称 string newName = MapArea.All.Where(x => x.Id == newJailRoomId).Select(x => x.AreaName).SingleOrDefault(); //判断是否相同 if (oldJailRoomId == newJailRoomId) { return(newName); } //执行更换 CulpritRoomReference.ChangeRoom(culpritId, newJailRoomId); //警告条件绑定 var isServiceAvailable = LocatingServiceUtil.IsAvailable(); int ruleId = 0; int[] culpritIdArray = null; int[] tagIdArray = null; //旧监舍 ------------------------------------- if (oldJailRoomId != 0) { //查询警告条件 ruleId = AreaWarningRule.SelectRuleByAreaId(oldJailRoomId).Select(x => x.Id).FirstOrDefault(); //如果警告条件不存在,则自动建立一条 if (ruleId == 0) { var rule = new AreaWarningRule { AreaEventType = (byte)AreaEventType.StayOutside, AreaId = oldJailRoomId, EnableToAllTags = false, IsDisabled = false }; if (isServiceAvailable) { ruleId = LocatingServiceUtil.Instance <IServiceApi>().InsertWarningRule(rule).Id; } else { ruleId = AreaWarningRule.InsertAndReturnId(rule); } } //为警告条件设置关联标签 culpritIdArray = CulpritRoomReference.All.Where(x => x.JailRoomId == oldJailRoomId).Select(x => x.CulpritId).ToArray(); tagIdArray = HostTag.All.Where(x => culpritIdArray.Contains(x.HostId) && x.TagId > 0).Select(x => x.TagId).ToArray(); if (isServiceAvailable) { LocatingServiceUtil.Instance <IServiceApi>().SetWarningRuleCoverage(ruleId, tagIdArray); } else { AreaWarningRuleCoverage.SetCoverage(ruleId, tagIdArray); } } //新监舍 ------------------------------------- //查询警告条件 ruleId = AreaWarningRule.SelectRuleByAreaId(newJailRoomId).Select(x => x.Id).FirstOrDefault(); //如果警告条件不存在,则自动建立一条 if (ruleId == 0) { var rule = new AreaWarningRule { AreaEventType = (byte)AreaEventType.StayOutside, AreaId = newJailRoomId, EnableToAllTags = false, IsDisabled = false }; if (isServiceAvailable) { ruleId = LocatingServiceUtil.Instance <IServiceApi>().InsertWarningRule(rule).Id; } else { ruleId = AreaWarningRule.InsertAndReturnId(rule); } } //为警告条件设置关联标签 culpritIdArray = CulpritRoomReference.All.Where(x => x.JailRoomId == newJailRoomId).Select(x => x.CulpritId).ToArray(); tagIdArray = HostTag.All.Where(x => culpritIdArray.Contains(x.HostId) && x.TagId > 0).Select(x => x.TagId).ToArray(); if (isServiceAvailable) { LocatingServiceUtil.Instance <IServiceApi>().SetWarningRuleCoverage(ruleId, tagIdArray); } else { AreaWarningRuleCoverage.SetCoverage(ruleId, tagIdArray); } //记录日志,返回 Diary.Insert(ContextUser.Current.Id, 0, culpritId, "将犯人" + hostTag.HostName + "更换监舍到" + newName); return(newName); }
protected void deleteButton_Click(object sender, EventArgs e) { HostTag host = HostTag.GetById(_id); if (host != null) { bool serviceAvailable = LocatingServiceUtil.IsAvailable(); var tagId = host.TagId; if (tagId > 0) { using (AppDataContext db = new AppDataContext()) { //更新标签名称 Tag tag = Tag.Select(tagId); if (tag != null) { string mac = tag.TagMac; if (serviceAvailable) { LocatingServiceUtil.Instance <IServiceApi>().UpdateTagNameAndSerialNo(tagId, "NewTag_" + mac.Substring(12), ""); } else { Tag.UpdateTagNameAndSerialNo(tagId, "NewTag_" + mac.Substring(12), ""); } } //删除标签历史记录和相关信息 AreaEventLog.DeleteByTagId(tagId); GenericEventLog.DeleteByTagId(tagId); TagPositionLog.DeleteByTagId(tagId); //LocationChangeLog.DeleteMany(tagId); //LatestEvent.DeleteByTagId(tagId); TagEventStatus.DeleteMany(tagId); TagPositionStatus.DeleteMany(tagId); AreaWarningRuleCoverage.DeleteMany(tagId); InterrogationLog.DeleteMany(host.HostId); TagAlert.DeleteTagAlerts(tagId); //删除低电记录: 不执行删除 //db.ExecuteCommand("delete from history_BatteryResetLog where TagId=", tagId); } TagLocateSetting.StopLocating(tagId); if (serviceAvailable) { var s = LocatingServiceUtil.Instance <IServiceApi>(); s.StartStopLocating(); } int areaId = CulpritRoomReference.GetRoomIdByCulpritId(host.HostId); if (areaId != 0) { //查询警告条件 var ruleId = AreaWarningRule.SelectRuleByAreaId(areaId).Select(x => x.Id).FirstOrDefault(); //如果警告条件不存在,则自动建立一条 if (ruleId != 0) { //为警告条件设置关联标签 var culpritIdArray = CulpritRoomReference.All.Where(x => x.JailRoomId == areaId).Select(x => x.CulpritId).ToArray(); var tagIdArray = HostTag.All.Where(x => culpritIdArray.Contains(x.HostId) && x.TagId > 0 && x.TagId != tagId).Select(x => x.TagId).ToArray(); if (serviceAvailable) { LocatingServiceUtil.Instance <IServiceApi>().SetWarningRuleCoverage(ruleId, tagIdArray); } else { AreaWarningRuleCoverage.SetCoverage(ruleId, tagIdArray); } } } } //删除使用者信息 CulpritRoomReference.DeleteByCulpritId(_id); //TagUser.DeleteById(_id); HostTag.DeleteHostTag(_id); TagStatusView.SelectTagStatus(tagId).HostTag = null; if (tagId > 0 && serviceAvailable) { LocatingServiceUtil.Instance <IServiceApi>().ReloadTagHost(tagId); } //记录日志 Diary.Insert(ContextUser.Current.Id, tagId, _id, "删除犯人" + host.HostName + "的信息" + (host.TagId == 0 ? "" : "并解除标签绑定。") + "。"); } ShowMessagePage("删除成功。"); }