protected void list_ItemCreated(object sender, RepeaterItemEventArgs e)
        {
            //---add by tan  2009-10-56---//
            DataRowView log = (DataRowView)e.Item.DataItem;

            if (log != null)
            {
                Img           icon            = e.Item.FindControl("icon") as Img;
                Anchor        tagName         = e.Item.FindControl("tagName") as Anchor;
                SmartLabel    facilityName    = e.Item.FindControl("facilityName") as SmartLabel;
                SmartLabel    coordinatesName = e.Item.FindControl("coordinatesName") as SmartLabel;
                SmartLabel    isDisappeared   = e.Item.FindControl("isDisappeared") as SmartLabel;
                DateTimeLabel writeTime       = e.Item.FindControl("writeTime") as DateTimeLabel;
                Anchor        replayRoute     = e.Item.FindControl("replayRoute") as Anchor;

                icon.Src             = CommonExtension.IdentityIcon(Convert.ToInt32(log["TagId"]));
                tagName.Text         = Convert.ToString(log["HostName"]);
                tagName.Href         = PathUtil.ResolveUrl("TagUsers/TagUser.aspx?id=" + Convert.ToString(log["hostid"]) + "&type=" + (int)_userType);
                facilityName.Text    = Convert.ToString(log["FacilityName"]);
                coordinatesName.Text = Convert.ToString(log["CoordinatesName"]);

                if (coordinatesName.Text.Length == 0)
                {
                    coordinatesName.Text = "离开监控区域";
                }

                if (Convert.ToInt32(log["IsDisappeared"]) >= 0)
                {
                    isDisappeared.Text = "";
                }
                else
                {
                    isDisappeared.Text = "消失";
                }
                writeTime.DisplayValue = Convert.ToDateTime(log["WriteTime"]);
                //replayRoute.Href = "javascript:viewTagPositionTrack(" + Convert.ToString(log["MapId"]) + ", '" + Convert.ToString(log["hostid"]) + "', '" + Convert.ToDateTime(log["WriteTime"]).AddMinutes(-10) + "', 10);";
                replayRoute.Href = "javascript:viewTagPositionTrack(0, '" + Convert.ToString(log["hostid"]) + "', '" + Convert.ToDateTime(log["WriteTime"]).AddMinutes(-10) + "', 10);";
            }

            //----------------------------------//

            //TagPositionLogView log = e.Item.DataItem as TagPositionLogView;

            /*
             *          if (log != null) {
             *                  Img icon = e.Item.FindControl("icon") as Img;
             *                  Anchor tagName = e.Item.FindControl("tagName") as Anchor;
             *                  SmartLabel facilityName = e.Item.FindControl("facilityName") as SmartLabel;
             *                  SmartLabel coordinatesName = e.Item.FindControl("coordinatesName") as SmartLabel;
             *                  DateTimeLabel writeTime = e.Item.FindControl("writeTime") as DateTimeLabel;
             *                  Anchor replayRoute = e.Item.FindControl("replayRoute") as Anchor;
             *
             *  icon.Src = CommonExtension.IdentityIcon(log.TagId);
             *                  tagName.Text = log.TagName;
             *                  tagName.Href = PathUtil.ResolveUrl("Objects/Tag.aspx?id=" + log.TagId);
             *                  facilityName.Text = log.FacilityName;
             *                  coordinatesName.Text = log.CoordinatesName;
             *                  writeTime.DisplayValue = log.WriteTime;
             *                  replayRoute.Href = "javascript:viewTagPositionTrack(" + log.MapId + ", '" + log.TagId + "', '" + log.WriteTime.AddMinutes(-10) + "', 10);";
             *          }
             */
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.Buffer          = true;
            context.Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
            context.Response.Expires         = 0;
            context.Response.CacheControl    = "no-cache";
            int mapId = Fetch.QueryUrlAsIntegerOrDefault("mapId", 0);

            int[] hostIdArray    = Strings.ParseToArray <int>(Fetch.QueryUrl("tagId"));
            int   requestSeconds = Fetch.QueryUrlAsInteger("minutes");

            int      seconds = requestSeconds * 60;
            DateTime startTime;

            if (requestSeconds < 0)
            {
                seconds   = Math.Abs(requestSeconds);
                startTime = DateTime.Now.AddSeconds(-seconds);
            }
            else
            {
                startTime = DateTime.Parse(Fetch.QueryUrl("startTime"));
            }


            Facility    facility;
            FacilityMap facilityMap;

            HostTag[] tags;

            using (AppDataContext db = new AppDataContext())
            {
                tags = db.HostTags.Where(h => hostIdArray.Contains(h.HostId)).ToArray();
                if (tags.Length == 0)
                {
                    return;
                }
            }


            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
            sb.AppendLine("<routeDisplay>");
            sb.AppendLine("	<title>" + (requestSeconds < 0 ? "标签实时定位" : "标签历史轨迹") + "</title>");
            sb.AppendLine("	<loop>" + (requestSeconds < 0 ? "True" : "False") + "</loop>");
            sb.AppendLine("	<timeInfo>");
            sb.AppendLine("		<fromTime>"+ startTime.ToString("yyyy/M/d H:mm:ss").Replace("-", "/") + "</fromTime>");
            sb.AppendLine("		<toTime>"+ startTime.AddSeconds(seconds + 1).ToString("yyyy/M/d H:mm:ss").Replace("-", "/") + "</toTime>");
            sb.AppendLine("		<timeZone>GMT"+ (Fetch.ServerUtcOffset > 0 ? "+" : "-") + Math.Abs(Fetch.ServerUtcOffset) + "</timeZone>");
            sb.AppendLine("	</timeInfo>");
            DateTime endTime;

            if (mapId > 0 && hostIdArray.Length >= 1)
            {
                facility = Facility.All.SingleOrDefault(f => f.MapId == mapId);
                if (facility == null)
                {
                    return;
                }
                facilityMap = FacilityMap.SelectFacilityMapById(mapId);
                if (facilityMap == null)
                {
                    return;
                }

                endTime = startTime.AddSeconds(seconds + 1);
                sb.Append(this.GetFacilityInnerXml(facility, facilityMap, endTime));

                foreach (var tag in tags)
                {
                    IList <TagPositionLog> tracks = this.GetPositionList(tag.HostId, startTime, seconds).Where(t => t.MapId == mapId).ToList();
                    if (tracks.Count == 0)
                    {
                        continue;
                    }
                    sb.AppendLine("	<tag id=\"" + tag.HostId + "\" name=\"" + tag.HostName + "\" moveSpeed=\"0.5\" icon=\"" + CommonExtension.IdentityIcon(tag.TagId) + "\">");
                    sb.Append(this.GetRouteInnerXml(tracks));
                    sb.AppendLine("	</tag>");
                }

                sb.AppendLine("	</routeDisplaymap>");
            }
            else
            {
                IList <TagPositionLog> tracksall = this.GetPositionList(tags[0].HostId, startTime, seconds);
                IList <TagPositionLog> tracks    = new List <TagPositionLog>();
                string iconFile = CommonExtension.IdentityIcon(tags[0].TagId);

                for (int i = 0; i < tracksall.Count; i++)
                {
                    if (tracksall[i].MapId == 0)
                    {
                        continue;
                    }

                    if (mapId != tracksall[i].MapId)
                    {
                        if (tracks.Count > 0)
                        {
                            if (i + 1 == tracksall.Count)
                            {
                                endTime = startTime.AddSeconds(seconds);
                            }
                            else
                            {
                                endTime = tracksall[i].WriteTime;
                            }
                            sb.AppendLine(SetRouteDisplayMap(mapId, startTime, endTime,
                                                             tags[0].HostId, tags[0].HostName, 0.5, iconFile, tracks));
                        }
                        mapId = tracksall[i].MapId;

                        tracks = new List <TagPositionLog>();
                        tracks.Add(tracksall[i]);
                    }
                    else
                    {
                        tracks.Add(tracksall[i]);

                        if (i + 1 == tracksall.Count)
                        {
                            endTime = startTime.AddSeconds(seconds + 1);
                            sb.AppendLine(SetRouteDisplayMap(mapId, startTime, endTime,
                                                             tags[0].HostId, tags[0].HostName, 0.5, iconFile, tracks));
                        }
                    }
                }

                if (tracks.Count == 1)
                {
                    endTime = startTime.AddSeconds(seconds + 1);
                    sb.AppendLine(SetRouteDisplayMap(mapId, startTime, endTime,
                                                     tags[0].HostId, tags[0].HostName, 0.5, iconFile, tracks));
                }
            }

            sb.AppendLine("</routeDisplay>");

            context.Response.ContentType = "text/xml";
            context.Response.Write(sb.ToString());
        }
Beispiel #3
0
        protected void settingList_ItemCreated(object sender, RepeaterItemEventArgs e)
        {
            DBViewTagSetting setting = e.Item.DataItem as DBViewTagSetting;

            if (setting != null)
            {
                Img icon = e.Item.FindControl("icon") as Img;
                icon.Src = CommonExtension.IdentityIcon((int)setting.Id);//TagId);


                Anchor     tagName  = (Anchor)e.Item.FindControl("tagName");
                SmartLabel userType = (SmartLabel)e.Item.FindControl("userType");
                SmartLabel userMemo = (SmartLabel)e.Item.FindControl("memo");
                tagName.Text = setting.HostName;

                HostTagGroupStatus tagUser = HostTagGroupStatus.SelectByTagId((int)setting.Id);//.TagId);
                int groupId = 0;
                if (tagUser != null)
                {
                    groupId       = tagUser.HostGroupId;
                    userType.Text = BusTagUserType.GetTagUserTypeName(tagUser.HostGroupId);
                    userMemo.Text = tagUser.Description;
                }
                tagName.Href = PathUtil.ResolveUrl(string.Format("/TagUsers/TagUser.aspx?id={0}&type={1}",
                                                                 setting.HostId, groupId));

                SmartLabel idSelection  = (SmartLabel)e.Item.FindControl("idSelection");
                string     disableOrNot = this.IsLocatingServiceAvailable ? "" : " disabled=\"disabled\"";
                idSelection.Text = "<input type=\"checkbox\" name=\"selection\"" + disableOrNot + " onclick=\"javascript:Locating.selectTag(this);\" value=\"" + setting.Id + "\" />";//setting.TagId + "\" />";


                if (setting.CommandState == null)
                {
                    return;     // <-----------------If never been configured ----------------------------------------------
                }

                SmartLabel    commandState = (SmartLabel)e.Item.FindControl("commandState");
                DateTimeLabel startTime    = (DateTimeLabel)e.Item.FindControl("startTime");
                Anchor        operate      = (Anchor)e.Item.FindControl("operate");

                switch ((LocatingCommandState)setting.CommandState)
                {
                case LocatingCommandState.WaitToStart:
                    operate.Text      = "N/A";
                    operate.CssClass  = "t3";
                    commandState.Text = "请求开始中";
                    commandState.Style.Add("color", "Green");
                    break;

                case LocatingCommandState.WaitToStop:
                    operate.Text      = "N/A";
                    operate.CssClass  = "t3";
                    commandState.Text = "请求停止中";
                    commandState.Style.Add("color", "Red");
                    break;

                default:
                case LocatingCommandState.Executed:
                    if (setting.WorkingStatus == (byte)TagWorkingStatus.Locating)
                    {
                        operate.Text           = "停止";
                        operate.Href           = "javascript:Locating.quickStop(" + setting.Id + ");"; //setting.TagId + ");";
                        startTime.DisplayValue = (DateTime)setting.UpdateTime;
                    }
                    else
                    {
                        operate.Text    = "快速启动";
                        operate.ToolTip = "按照已设定参数快速启动";
                        operate.Href    = "javascript:Locating.quickStart(" + setting.Id + ");"; //setting.TagId + ");";
                    }
                    operate.Attributes["id"] = "op_" + setting.Id;                               //setting.TagId;
                    break;
                }

                if (!this.IsLocatingServiceAvailable)
                {
                    operate.Text     = "N/A";
                    operate.Href     = null;
                    operate.CssClass = "t3";
                    operate.ToolTip  = "系统未检测到LocatingServer运行。";
                }
            }
        }