protected void repeater_ItemCreated(object sender, RepeaterItemEventArgs e)
        {
            InterrogationLog log = e.Item.DataItem as InterrogationLog;

            SmartLabel    policeName  = e.Item.FindControl("policeName") as SmartLabel;
            SmartLabel    culpritName = e.Item.FindControl("culpritName") as SmartLabel;
            SmartLabel    status      = e.Item.FindControl("status") as SmartLabel;
            DateTimeLabel StartTime   = e.Item.FindControl("StartTime") as DateTimeLabel;
            DateTimeLabel EndTime     = e.Item.FindControl("EndTime") as DateTimeLabel;
            User          user        = Data.User.Select(log.PoliceId);

            if (user != null)
            {
                policeName.Text = Data.User.Select(log.PoliceId).UserName;
            }
            culpritName.Text       = HostTag.GetById(log.CulpritId).HostName;
            StartTime.DisplayValue = log.StartTime;
            if (log.EndTime != null)
            {
                EndTime.DisplayValue = log.EndTime.Value;
                status.Text          = "提审完成";
            }
            else
            {
                status.Text = "提审中";
            }
        }
Exemplo n.º 2
0
        protected void saveNewRule_Click(object sender, EventArgs e)
        {
            AreaWarningRule rule = new AreaWarningRule();

            rule.EnableToAllTags = forAllTags.SelectedValue == "1";
            rule.AreaEventType   = byte.Parse(areaEventType.SelectedValue);
            rule.AreaId          = _id;
            rule.IsDisabled      = false;

            int[]     tagidarray = new int[tagSelector.SelectedUserIds.Count()];
            ArrayList alHostId   = new ArrayList();

            int[] hostIdArray = null;
            sTagID = "";
            for (int i = 0; i < tagSelector.SelectedUserIds.Count(); i++)
            {
                //根据hostid取得tagid
                HostTag ht = new HostTag();
                ht = HostTag.GetById(tagSelector.SelectedUserIds[i]);
                if (ht != null)
                {
                    alHostId.Add(ht.HostId);
                    sTagID       += ht.TagId + ",";
                    tagidarray[i] = ht.TagId;
                }
            }
            hostIdArray            = (int[])alHostId.ToArray(typeof(int));
            AreaWarningRule.sTagID = sTagID;

            if (!LocatingServiceUtil.IsAvailable())
            {
                AreaWarningRule.InsertAndReturnId(rule);
                if (rule.EnableToAllTags == false)
                {
                    //AreaWarningRuleCoverage.SetCoverage(rule.Id, hostIdArray);
                    AreaWarningRuleCoverage.SetCoverage(rule.Id, tagidarray);
                    //AreaWarningRuleCoverage.SetCoverage(rule.Id, tagSelector.SelectedTagIdArray);
                }
            }
            else
            {
                IServiceApi serviceApi = LocatingServiceUtil.Instance <IServiceApi>();
                EditResult  result     = serviceApi.InsertWarningRule(rule);
                rule.Id = result.Id;
                if (rule.EnableToAllTags == false)
                {
                    serviceApi.SetWarningRuleCoverage(rule.Id, tagidarray);
                    //serviceApi.SetWarningRuleCoverage(rule.Id, tagSelector.SelectedTagIdArray);
                }
            }

            Terminator.Redirect(Fetch.CurrentUrl);
        }
        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), "");
                            }
                        }

                        //删除标签历史记录和相关信息
                        GenericEventLog.DeleteByTagId(tagId);
                        TagEventStatus.DeleteMany(tagId);
                        TagPositionStatus.DeleteMany(tagId);
                        TagAlert.DeleteTagAlerts(tagId);
                    }

                    TagStatusView.SelectTagStatus(tagId).HostTag = null;
                }

                TagAlert.DeleteTagAlerts(_id);
                //删除host信息
                HostTag.DeleteHostTag(_id);
                //记录日志

                if (tagId > 0 && serviceAvailable)
                {
                    LocatingServiceUtil.Instance <IServiceApi>().ReloadTagHost(tagId);
                }
                Diary.Insert(ContextUser.Current.Id, tagId, _id, "删除定点报警标签" + host.HostName + "的信息" + (host.TagId == 0 ? "" : "并解除标签绑定。") + "。");
            }
            new SuccessTerminator().End("删除成功。", -1, Link.CloseWindow);
        }
Exemplo n.º 4
0
        protected void uploadButton_Click(object sender, EventArgs e)
        {
            string photoPath = "";

            if (uploadPhoto.HasFile)
            {
                photoPath = CreatePhotoUploadPath() + "/" + Misc.CreateUniqueFileName() + Path.GetExtension(uploadPhoto.FileName);

                try
                {
                    using (System.Drawing.Image image = System.Drawing.Image.FromStream(uploadPhoto.FileContent))
                    {
                        if (image != null)
                        {
                            using (Bitmap bitmap = new Bitmap(image, 100, 120))
                            {
                                bitmap.Save(Fetch.MapPath(PathUtil.ResolveUrl(photoPath)), ImageFormat.Jpeg);
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    Terminator.End("上传照片出错,可能是图片体积过大,或者不是图片格式文件。");
                    return;
                }
            }

            HostTag hostTag = HostTag.GetById(_id);

            //删除旧文件
            try
            {
                string oldPath = hostTag.ImagePath;
                if (oldPath != null)
                {
                    File.Delete(Fetch.MapPath(PathUtil.ResolveUrl(hostTag.ImagePath)));
                }
            }
            catch (Exception)
            {
            }
            hostTag.ImagePath = photoPath;
            //更新数据库
            HostTag.UpdateHostTag(hostTag);
            //TagUser.UpdatePhotoUrl(_id, photoPath);

            Terminator.Redirect(Fetch.CurrentUrl);
        }
        protected void LoadTagAlert()
        {
            using (AppDataContext db = new AppDataContext())
            {
                _tagAlert = db.TagAlerts.SingleOrDefault(t => t.AlertId == _id);

                if (_tagAlert == null)
                {
                    ShowMessagePage("报警事件不存在。");
                }
                else
                {
                    HostTag thisHostTag = HostTag.GetById(_tagAlert.HostId);
                    Tag     thisTag     = Tag.Select(thisHostTag.TagId);
                    if (thisTag != null)
                    {
                        tagName.Text = thisHostTag.HostName;
                        int coorid = _tagAlert.CoordinatesId;
                        if (CommonExtension.IsIlltreatTag(_tagAlert.HostId) && Config.Settings.ProjectType != ProjectTypeEnum.NMPrison)
                        {
                            coorid = CommonExtension.GetCoordinatesId(thisHostTag.Description.Substring(0, thisHostTag.Description.Length - 2));
                        }

                        if (Config.Settings.ProjectType == ProjectTypeEnum.NMPrison)
                        {
                            coordinatesName.Text = thisHostTag.HostName;
                        }
                        else
                        {
                            coordinatesName.Text = Coordinates.GetName(coorid);
                        }

                        if (LocatingServiceUtil.IsAvailable())
                        {
                            IServiceApi serviceApi = LocatingServiceUtil.Instance <IServiceApi>();
                            bool        boolean    = serviceApi.ClearTagStatus(thisTag.TagMac, (SupportEvent)_tagAlert.AlertType);
                        }

                        description.Text  = CommonExtension.GetEventDescription((SupportEvent)_tagAlert.AlertType, _tagAlert.HostId);
                        time.DisplayValue = _tagAlert.WriteTime;
                        if (_tagAlert.MasterUserId > 0)
                        {
                            alertMaster.Text = Data.User.Select(_tagAlert.MasterUserId) == null ? "未知" : Data.User.Select(_tagAlert.MasterUserId).UserName;
                        }

                        alertStatus.Text = NetRadio.Common.LocatingMonitor.Misc.GetAlertStatus((AlertStatusType)_tagAlert.AlertStatus);

                        list.DataSource   = db.AlertProcessLogs.Where(t => t.AlertId == _id).OrderBy(t => t.UpdateTime).ToList();
                        list.ItemCreated += new RepeaterItemEventHandler(list_ItemCreated);
                        list.DataBind();

                        if (!IsPostBack)
                        {
                            Dictionary <string, int> alertResults = new Dictionary <string, int>();
                            alertResults.Add(CommonExtension.GetEventDescription((SupportEvent)_tagAlert.AlertType, _tagAlert.HostId), 1);
                            alertResults.Add("误报", 2);
                            alertResults.Add("其它", 3);

                            foreach (var item in alertResults)
                            {
                                ListItem listitem = new ListItem(item.Key, item.Value.ToString());

                                if (item.Value == 1)
                                {
                                    listitem.Selected = true;
                                }

                                alertResultList.Items.Add(listitem);
                            }
                        }

                        if (_tagAlert.AlertStatus == (byte)AlertStatusType.New || _tagAlert.AlertStatus == (byte)AlertStatusType.Processing)
                        {
                            alertResultList.Visible = true;
                            alertResult.Visible     = false;
                            handover.Visible        = true;
                            alertProcess.Visible    = true;
                            otherReason.Visible     = true;
                        }
                        else
                        {
                            alertResultList.Visible = false;
                            alertResult.Visible     = true;
                            handover.Visible        = false;
                            alertProcess.Visible    = false;
                            otherReason.Visible     = false;

                            AlertProcessLog alertProcessLog = db.AlertProcessLogs.SingleOrDefault(t => t.AlertId == _id && t.AlertStatus == (byte)AlertStatusType.Resolved);

                            if (alertProcessLog != null)
                            {
                                alertResult.Text = alertProcessLog.ChangeReason;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        public static object GetData(int alertID)
        {
            string id_name     = "";
            string id_position = "";
            string id_type     = "";
            string id_time     = "";
            string id_table    = "";

            NameID[] id_selectResult = null;

            using (AppDataContext db = new AppDataContext())
            {
                TagAlert _tagAlert = db.TagAlerts.SingleOrDefault(t => t.AlertId == alertID);

                if (_tagAlert == null)
                {
                    throw new Exception("报警事件不存在!");
                }
                else
                {
                    HostTag thisHostTag = HostTag.GetById(_tagAlert.HostId);
                    Tag     thisTag     = Tag.Select(thisHostTag.TagId);
                    if (thisTag != null)
                    {
                        if (CommonExtension.IsIlltreatTag(_tagAlert.HostId))
                        {
                            if (Config.Settings.ProjectType == ProjectTypeEnum.NMPrison)
                            {
                                id_position = thisHostTag.HostName;
                            }
                            else
                            {
                                int coorid = CommonExtension.GetCoordinatesId(thisHostTag.Description.Substring(0, thisHostTag.Description.Length - 2));
                                id_position = Coordinates.GetName(coorid);
                            }
                        }
                        else
                        {
                            id_position = Coordinates.GetName(_tagAlert.CoordinatesId);
                        }


                        //if (Config.Settings.ProjectType == ProjectTypeEnum.NMPrison)
                        //{
                        //    id_position = thisHostTag.HostName;
                        //}
                        //else
                        //{

                        //    int coorid = CommonExtension.GetCoordinatesId(thisHostTag.Description.Substring(0, thisHostTag.Description.Length - 2));
                        //    id_position = Coordinates.GetName(coorid);

                        //}

                        if (LocatingServiceUtil.IsAvailable())
                        {
                            IServiceApi serviceApi = LocatingServiceUtil.Instance <IServiceApi>();
                            bool        boolean    = serviceApi.ClearTagStatus(thisTag.TagMac, (SupportEvent)_tagAlert.AlertType);
                        }

                        id_name = thisHostTag.HostName;
                        //id_position = Coordinates.GetName(coorid);
                        id_type = CommonExtension.GetEventDescription((SupportEvent)_tagAlert.AlertType, _tagAlert.HostId);
                        id_time = _tagAlert.WriteTime.ToString("yyyy/MM/dd HH:mm:ss");

                        id_selectResult = db.ProcessResults.Select(_d => new NameID {
                            ID = _d.ID, Name = _d.Text
                        }).ToArray();

                        id_table = GetProcessTable(alertID);


                        return(new
                        {
                            id_name,
                            id_position,
                            id_type,
                            id_time,
                            id_table,
                            id_selectResult
                        });
                    }
                }
            }



            return("");
        }
        private void AddHostTagGroup(int[] TagIdArray, int groupId)
        {
            int        MapId    = 0;
            List <int> lHostIds = new List <int>();

            for (int i = 0; i < TagIdArray.Length; i++)
            {
                HostTag host = HostTag.GetById(TagIdArray[i]);

                if (host != null && host.HostId > 0)
                {
                    HostTag.SetHostGroup(host.HostId, groupId);
                }
                else
                {
                    host = new HostTag();
                    Tag tag = Tag.Select(TagIdArray[i]);
                    if (tag != null)
                    {
                        host.HostExternalId = tag.SerialNo;
                        //TagHost tagHost = Tag.SelectTagHost(TagIdArray[i]);
                        host.HostName    = groupName.Text.Trim() + "_" + ((tag.TagMac.Length > 9) ? tag.TagMac.Substring(9) : tag.TagMac);
                        host.Description = tag.TagName;
                        host.ImagePath   = "";
                        host.HostType    = 0;
                        host.TagId       = TagIdArray[i];
                        host.HostId      = HostTag.AddOrUpdateHostTag(0, host.TagId, host.HostExternalId, host.HostName, host.HostType, host.Description, host.ImagePath);
                        HostTag.SetHostGroup(host.HostId, groupId);
                        if (i == 0)
                        {
                            TagStatusView tagView1 = TagStatusView.SelectTagStatusByHostId(host.HostId);
                            MapId = tagView1.MapId;
                        }
                    }
                }
                lHostIds.Add(host.HostId);
            }
            int[] hostIds = lHostIds.ToArray();
            if (LocatingServiceUtil.IsAvailable())
            {
                //内蒙不需要这样删除
                try
                {
                    int[] delhostIds;
                    GetDelIDs(out delhostIds, groupId, MapId, hostIds);
                    if (delhostIds.Count() > 1)
                    {
                        //合并两个数组,传值,以-1为分界值
                        int[] myhostIds = new int[delhostIds.Length + hostIds.Length];
                        delhostIds.CopyTo(myhostIds, 0);
                        hostIds.CopyTo(myhostIds, delhostIds.Length);
                        LocatingServiceUtil.Instance <IServiceApi>().UpdateHostGroup(myhostIds, groupId);
                    }
                    else
                    {
                        LocatingServiceUtil.Instance <IServiceApi>().UpdateHostGroup(hostIds, groupId);
                    }
                }
                catch (Exception err)
                {
                }
            }
        }
        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) + "]";
        }
        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);
        }
Exemplo n.º 10
0
        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("删除成功。");
        }
Exemplo n.º 11
0
        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("删除成功。");
        }