private IList <TagPositionLog> GetPositionList(int hostId, DateTime startTime, int seconds) { using (AppDataContext db = new AppDataContext()) { var tracks = db.TagPositionLogs .Where(t => t.HostId == hostId && t.WriteTime >= startTime && t.WriteTime <= startTime.AddSeconds(seconds + 1) && t.X > 0 && t.Y > 0) .OrderBy(t => t.Id) .ToList(); var single = db.TagPositionLogs .OrderByDescending(t => t.Id) .FirstOrDefault(t => t.HostId == hostId && t.Id < (tracks.Count == 0 ? int.MaxValue : tracks[0].Id)); if (single != null) { tracks.Insert(0, single); } else { TagPositionLog aLog = new TagPositionLog(); aLog.HostId = hostId; aLog.X = -1; aLog.Y = -1; aLog.Z = -1; aLog.WriteTime = startTime; if (tracks != null && tracks.Count > 0) { aLog.MapId = tracks.First().MapId; aLog.TagId = tracks.First().TagId; } tracks.Insert(0, aLog); } return(tracks); } }
private void LoadRepeater(List <int> listAreaCoordinates, int[] TagIdArray, DateTime dtFrom, DateTime dtTo, string SearchType) { try { IList <AreaInOutTime> lTime = new List <AreaInOutTime>(); int totalCount = 0; using (AppDataContext db = new AppDataContext()) { for (int i = 0; i < TagIdArray.Length; i++) { long totalTicks = 0; int entryCount = 0; DateTime firstInTime = DateTime.MinValue; DateTime lastOutTime = DateTime.MinValue; DateTime endTime = DateTime.Now; if (dtTo < endTime) { endTime = dtTo; } int hostId = TagIdArray[i]; HostTag oHost = HostTag.GetById(hostId); if (oHost == null) { lblMessage.Text += String.Format("ID={0}不存在", hostId); continue; } int tagId = oHost.TagId; string hostName = oHost.HostName; IList <TagPositionLog> lLog = db.TagPositionLogs .Where(x => x.HostId == hostId && x.WriteTime >= dtFrom && x.WriteTime <= endTime) .OrderBy(x => x.WriteTime).ToList(); var firstQuery = db.TagPositionLogs.Where(x => x.WriteTime < dtFrom && x.HostId == hostId) .OrderByDescending(x => x.WriteTime).Take(1); TagPositionLog prevLog = null; try { if (firstQuery != null) { prevLog = firstQuery.First(); } } catch { } AreaInOutTime areaTime = new AreaInOutTime(); areaTime.hostName = hostName; areaTime.hostId = hostId; //previous log if (prevLog != null) { if (prevLog.X > 0) { if (listAreaCoordinates.Contains(prevLog.CoordinatesId)) { areaTime.inTime = dtFrom; firstInTime = areaTime.inTime; } } } bool bFirst = true; if (lLog != null && lLog.Count > 0) { foreach (TagPositionLog log in lLog) { DateTime dtWriteTime = new DateTime(log.WriteTime.Year, log.WriteTime.Month, log.WriteTime.Day, log.WriteTime.Hour, log.WriteTime.Minute, log.WriteTime.Second); if (bFirst) { bFirst = false; //first log if (log.X > 0 && listAreaCoordinates.Contains(log.CoordinatesId)) { if (areaTime.inTime == DateTime.MinValue) { areaTime.inTime = dtWriteTime; firstInTime = areaTime.inTime; } } else { areaTime.outTime = dtWriteTime; if (areaTime.inTime < dtWriteTime) { lastOutTime = areaTime.outTime; } } } else { if (log.X > 0 && listAreaCoordinates.Contains(log.CoordinatesId)) { if (areaTime.inTime == DateTime.MinValue) { areaTime.inTime = dtWriteTime; firstInTime = areaTime.inTime; if (areaTime.outTime != DateTime.MinValue) { areaTime.outTime = DateTime.MinValue; } } else { if (areaTime.outTime == DateTime.MinValue) { } else { double disappearedTime = (dtWriteTime - areaTime.outTime).Duration().TotalSeconds; if (disappearedTime > 60) { areaTime.stayTime = (areaTime.outTime - areaTime.inTime).Duration(); totalTicks += areaTime.stayTime.Ticks; if (SearchType == "2") { lTime.Add(areaTime); } entryCount++; areaTime = new AreaInOutTime(); areaTime.inTime = dtWriteTime; } else { areaTime.outTime = DateTime.MinValue; } } } } else { if (areaTime.outTime == DateTime.MinValue) { areaTime.outTime = dtWriteTime; lastOutTime = areaTime.outTime; } } } } } if (areaTime.inTime != DateTime.MinValue) { if (areaTime.outTime != DateTime.MinValue) { double disappearedTime = (endTime - areaTime.outTime).Duration().TotalSeconds; if (disappearedTime > 60) { areaTime.stayTime = (areaTime.outTime - areaTime.inTime).Duration(); totalTicks += areaTime.stayTime.Ticks; if (SearchType == "2") { lTime.Add(areaTime); } entryCount++; } else { areaTime.stayTime = (endTime - areaTime.inTime).Duration(); totalTicks += areaTime.stayTime.Ticks; if (SearchType == "2") { lTime.Add(areaTime); } entryCount++; } lastOutTime = areaTime.outTime; } else { areaTime.stayTime = (endTime - areaTime.inTime).Duration(); totalTicks += areaTime.stayTime.Ticks; if (SearchType == "2") { lTime.Add(areaTime); } entryCount++; } } if (totalTicks > 0) { lastOutTime = areaTime.outTime; //record the last out time areaTime = new AreaInOutTime(); areaTime.hostId = -1; if (SearchType == "1") { areaTime.hostName = hostName; areaTime.inTime = firstInTime; areaTime.outTime = lastOutTime; //assign last out time //if (areaTime.inTime < lastOutTime) // areaTime.outTime = lastOutTime; } else if (SearchType == "2") { areaTime.hostName = "--- ---"; areaTime.inTime = DateTime.MinValue; areaTime.outTime = DateTime.MinValue; } areaTime.stayTime = new TimeSpan(totalTicks); lTime.Add(areaTime); totalCount++; } else { areaTime = new AreaInOutTime(); areaTime.hostName = hostName; areaTime.inTime = DateTime.MinValue; areaTime.outTime = DateTime.MinValue; areaTime.stayTime = new TimeSpan(0); lTime.Add(areaTime); totalCount++; } } } DataTable dt = new DataTable(); dt.Columns.Add("hostName", typeof(string)); dt.Columns.Add("inTime", typeof(string)); dt.Columns.Add("outTime", typeof(string)); dt.Columns.Add("stayTime", typeof(string)); for (int i = 0; i < lTime.Count(); i++) { string inTimeValue = (lTime.ElementAt(i).inTime == DateTime.MinValue) ? "" : lTime.ElementAt(i).inTime.ToString(); string outTimeValue = (lTime.ElementAt(i).outTime == DateTime.MinValue) ? "" : lTime.ElementAt(i).outTime.ToString(); dt.Rows.Add( lTime.ElementAt(i).hostName, inTimeValue, outTimeValue, lTime.ElementAt(i).stayTime.ToString() ); } ViewState["dt"] = dt; list.DataSource = lTime; list.DataBind(); } catch (Exception err) { lblMessage.Text += err.ToString(); } lbltime.Text = " 从[" + dtFrom.ToString("yyyy年MM月dd日HH时mm分", DateTimeFormatInfo.InvariantInfo) + "] 到 [" + dtTo.ToString("yyyy年MM月dd日HH时mm分", DateTimeFormatInfo.InvariantInfo) + "]"; }
protected void deleteButton_Click(object sender, EventArgs e) { //TagUser user = TagUser.SelectById(_id); 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); TagAlert.DeleteTagAlerts(tagId); //保留低电记录 //db.ExecuteCommand("delete from history_BatteryResetLog where TagId=", tagId); } TagLocateSetting.StopLocating(tagId); if (serviceAvailable) { LocatingServiceUtil.Instance <IServiceApi>().StartStopLocating(); } //TagUser.DeleteById(_id); TagStatusView.SelectTagStatus(tagId).HostTag = null; } TagAlert.DeleteTagAlerts(_id); //删除人员信息 HostTag.DeleteHostTag(_id); //记录日志 if (tagId > 0 && serviceAvailable) { LocatingServiceUtil.Instance <IServiceApi>().ReloadTagHost(tagId); } Diary.Insert(ContextUser.Current.Id, tagId, _id, "删除使用者" + host.HostName + "的信息" + (host.TagId == 0 ? "" : "并解除标签绑定。") + "。"); } ShowMessagePage("删除成功。"); }
public string GetJobSize(string beginTime, string endTime) { #region 新算法 string _res = ""; try { DateTime _beginTime = DateTime.Parse(beginTime); DateTime _endTime = DateTime.Parse(endTime); IList <InterrogationLog> interrogationLogs = new List <InterrogationLog>(); IList <TagPositionLog> positionReconds = new List <TagPositionLog>(); Dictionary <int, int> policeJobAmount = new Dictionary <int, int>(); List <int> interrogationRooms = new List <int>(); Dictionary <InterrogationLog, int> interrogationItems = new Dictionary <InterrogationLog, int>(); using (AppExtensionDataContext dbExtension = new AppExtensionDataContext()) { interrogationLogs = dbExtension.InterrogationLogs.Where(t => t.StartTime > _beginTime && t.EndTime < _endTime).ToList(); } using (AppDataContext db = new AppDataContext()) { interrogationRooms = db.LocationGroups.Where(t => t.GroupId == (int)PrisonCoordinatesGroup.InterrogateRoom).Select(t => t.LocationId).ToList(); policeJobAmount = db.HostPositionStatusViews.ToList().Where(u => u.TagId > 0 && u.HostGroupId == (byte)TagUserType.Cop).ToDictionary(u => u.HostId, u => u.HostGroupId - 1); positionReconds = db.TagPositionLogs.Where(t => t.WriteTime > _beginTime && t.WriteTime < _endTime && interrogationRooms.Contains(t.CoordinatesId)).ToList(); } foreach (var item in interrogationLogs) { int interrogationRoomId = 0; TagPositionLog culpritOutItem = positionReconds.Where(t => t.WriteTime > item.StartTime && t.HostId == item.CulpritId).OrderBy(t => t.WriteTime).FirstOrDefault();//culpritOutItem表示犯人从监区带出,而非从提审室外出 interrogationRoomId = culpritOutItem.CoordinatesId; if (culpritOutItem != null && culpritOutItem.HostId > 0) { TagPositionLog outItem = positionReconds.Where(t => t.CoordinatesId == interrogationRoomId && t.WriteTime > item.StartTime).OrderBy(t => t.WriteTime).FirstOrDefault(); if (outItem != null && policeJobAmount.Keys.Contains(outItem.HostId.Value)) { policeJobAmount[outItem.HostId.Value]++; } TagPositionLog inItem = positionReconds.Where(t => t.CoordinatesId == interrogationRoomId && t.WriteTime > item.EndTime).OrderBy(t => t.WriteTime).FirstOrDefault(); if (inItem != null && policeJobAmount.Keys.Contains(inItem.HostId.Value)) { policeJobAmount[inItem.HostId.Value]++; } } else { continue; } } Dictionary <HostTag, int> JobAmountresult = new Dictionary <HostTag, int>(); using (AppDataContext db = new AppDataContext()) { var query = from a in policeJobAmount from b in db.HostTags where a.Key == b.HostId select new { b, a.Value }; JobAmountresult = query.OrderByDescending(t => t.Value).ToDictionary(t => t.b, t => t.Value); } StringBuilder sb = new StringBuilder(""); sb.AppendFormat(@" <table style='width: 100%;' cellpadding=0 cellspacing=0 border=0 class='grid alternate fixed'> <thead class=category> <th style='text-align: center;'> 警员名称 </th> <th style='text-align: center;'> 警员编号 </th> <th style='text-align: center;'> 警员工作量 </th> </thead> "); if (JobAmountresult.Count > 0) { foreach (var item in JobAmountresult) { sb.AppendFormat(@" <tr> <td style='text-align: center;'> {0} </td> <td style='border-left: solid 1px #e9e9e9;text-align: center;'> {1} </td> <td style='border-left: solid 1px #e9e9e9;text-align: center;'> {2} </td> </tr> ", item.Key.HostName, item.Key.HostExternalId, item.Value); } } else { sb.AppendFormat(@" <tr> <td colspan=3> 无数据!!! </td> </tr>" ); } sb.AppendFormat(@"</table>"); _res = sb.ToString(); } catch (Exception e1) { _res = e1.Message; } return(_res); #endregion #region 原算法 // string _res = ""; // try // { // DateTime _beginTime = DateTime.Parse(beginTime); // DateTime _endTime = DateTime.Parse(endTime); // SqlParameter p1 = new SqlParameter("@BeginTime", _beginTime); // SqlParameter p2 = new SqlParameter("@EndTime", _endTime); // DataSet ds = Summer.Query.RunProcedure("GetPoliceJobSize", new SqlParameter[2] { p1, p2 }, "LocatingMonitor"); // StringBuilder sb = new StringBuilder(""); // sb.AppendFormat(@" // <table style='width: 100%;' cellpadding=0 cellspacing=0 border=0 class='grid alternate fixed'> // <thead class=category> // <th style='text-align: center;'> // 警员名称 // </th> // <th style='text-align: center;'> // 警员编号 // </th> // <th style='text-align: center;'> // 警员工作量 // </th> // </thead> // "); // bool hasData = false; // if (ds != null && ds.Tables.Count == 1) // { // foreach (DataRow log in ds.Tables[0].Rows) // { // sb.AppendFormat(@" // <tr> // <td style='text-align: center;'> // {0} // </td> // <td style='border-left: solid 1px #e9e9e9;text-align: center;'> // {1} // </td> // <td style='border-left: solid 1px #e9e9e9;text-align: center;'> // {2} // </td> // </tr> // ", log["HostName"], log["HostExternalid"], log["JobSize"]); // hasData = true; // } // } // if (!hasData) // { // sb.AppendFormat(@" // <tr> // <td colspan=3> // 无数据!!! // </td> // </tr>" // ); // } // sb.AppendFormat(@"</table>"); // _res = sb.ToString(); // } // catch (Exception e1) // { // _res = e1.Message; // } // return _res; #endregion }
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("删除成功。"); }