public static void GetAlert(ref AlertData alert, string comID, string deviceID, string recDateTime) { string strSQL = "SELECT unitID FROM tblUnits WHERE deviceID = " + deviceID + " and comID = " + comID; ProcessAlerts processAlerts = new ProcessAlerts(); ExecuteSQL exec = new ExecuteSQL(); DataSet ds; int unitID; try { ds = exec.getDataSet(strSQL); unitID = int.Parse(ds.Tables[0].Rows[0]["unitID"].ToString()); processAlerts.UnitID = unitID; processAlerts.ComID = int.Parse(comID); processAlerts.AlertTime = recDateTime; processAlerts.GetAlert(); alert = processAlerts.Alert; } catch (Exception ex) { Console.WriteLine("GetAlert(): " + ex.Message); } finally { processAlerts = null; exec = null; } }
protected void _gridRecords_DataBound(object sender, DataGridItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { AlertData _alert = new AlertData(); MapDataCommon.GetAlert(ref _alert, Session["trkCompany"].ToString(), deviceID, XtremeK.TimeZone.ToServerTime(e.Item.Cells[4].Text).ToString()); Color item_color = new Color(); if (_alert.AlertType == "Event") { item_color = ColorTranslator.FromHtml("#FFF26A"); } else if (_alert.AlertType == "Geofence" || _alert.AlertType == "Red Alert" || _alert.AlertType == "Speeding") { item_color = ColorTranslator.FromHtml("#FF766A"); } else { item_color = ColorTranslator.FromHtml("#61C04E"); } e.Item.BackColor = item_color; string html_color = ColorTranslator.ToHtml(item_color); e.Item.Attributes.Add("id", e.Item.ItemIndex.ToString()); e.Item.Attributes.Add("onclick", "highlightRow(this)"); e.Item.Attributes.Add("onmouseover", "this.style.cursor='pointer';this.style.backgroundColor = '#DCDCDC';"); e.Item.Attributes.Add("onmouseout", "this.style.cursor='pointer';this.style.backgroundColor = '" + html_color + "';"); } }
public void GetAlert() { AlertData data = new AlertData(); AlertSelect alertSelect = new AlertSelect(); alertSelect.UnitID = _unitID; alertSelect.ComID = _comID; alertSelect.AlertTime = _alertTime; alertSelect.Alert = data; alertSelect.GetAlert(); _alert = alertSelect.Alert; }
public static string GetAlertColor(AlertData alert) { string color = "green"; string alertType = alert.AlertType; if (alertType == "Speeding" || alertType == "Geofence" || alertType == "Red Alert") { color = "red"; } else if (alertType == "Event" || alertType == "Time") { color = "yellow"; } return color; }
public string GetMarkerScript() { DataSet ds = null; string _bfMarkerScript = ""; string _script = ""; string _bfPolyLine = ""; int end = 0; int start = 0; int _labelID = 0; try { ds = (DataSet)Session["historicalData"]; if (ds.Tables[0].Rows.Count> 0) { string _markerText = ""; decimal _lat = 0, _lng = 0; decimal latest_lat = 0, latest_lon = 0; start = int.Parse(Session["historicalPageID"].ToString()) * 25; end = start + 25; if (ds.Tables[0].Rows.Count < 25 || end > ds.Tables[0].Rows.Count) { end = ds.Tables[0].Rows.Count; } latest_lat = decimal.Parse(ds.Tables[0].Rows[start]["lat"].ToString()); latest_lon = decimal.Parse(ds.Tables[0].Rows[start]["long"].ToString()); _bfPolyLine += " var polyline=new GPolyline([ "; for (int i = start; i < end; i++) { int offset = i - start; AlertData _alert = new AlertData(); MapDataCommon.GetAlert(ref _alert, Session["trkCompany"].ToString(), ds.Tables[0].Rows[i]["deviceID"].ToString(), ds.Tables[0].Rows[i]["recDateTime"].ToString()); _markerText = MapDataCommon.GetDataSetMarkerText(ds, i, _alert.AlertMessage); _bfMarkerScript += " point=new GPoint(" + decimal.Parse(ds.Tables[0].Rows[i]["long"].ToString()) + "," +decimal.Parse(ds.Tables[0].Rows[i]["Lat"].ToString()) + ");"; _bfPolyLine += " new GLatLng(" + decimal.Parse(ds.Tables[0].Rows[i]["lat"].ToString()) + "," + decimal.Parse(ds.Tables[0].Rows[i]["Long"].ToString()) + "), "; if(i==0) { _bfMarkerScript += " icon0 = new GIcon();"; _bfMarkerScript += " icon0.image = '../Icon/" + ds.Tables[0].Rows[i]["iconName"].ToString() + ".png';"; _bfMarkerScript += " icon0.iconSize = new GSize(" + iconHeight + "," + iconWidth + ");"; _bfMarkerScript += " icon0.iconAnchor = new GPoint(" + iconHeight / 2 + "," + iconWidth / 2 + ");"; _bfMarkerScript += " icon0.infoWindowAnchor = new GPoint(15, 15);"; _bfMarkerScript += " marker[" + offset + "]=new GMarker(point,icon0);"; } else { string color = MapDataCommon.GetAlertColor(_alert); _bfMarkerScript += " icon0 = new GIcon();"; _bfMarkerScript += " icon0.image = '../Images/crumb_" + color + ".png';"; _bfMarkerScript += " icon0.iconSize = new GSize(" + 20 + "," + 34 + ");"; _bfMarkerScript += " icon0.iconAnchor = new GPoint(9,34);"; _bfMarkerScript += " icon0.infoWindowAnchor = new GPoint(9,9);"; _bfMarkerScript += " marker[" + offset + "]=new GMarker(point,icon0);"; } _bfMarkerScript += "label[" + offset + "] = new ELabel(new GLatLng(" + decimal.Parse(ds.Tables[0].Rows[i]["Lat"].ToString()) + "," + decimal.Parse(ds.Tables[0].Rows[i]["long"].ToString()) + "), '" + (ds.Tables[0].Rows.Count - i).ToString() + "', 'style1');"; _bfMarkerScript += "label[" + offset + "].pixelOffset=new GSize(5,10);"; _bfMarkerScript += "map.addOverlay(label[" + offset + "]);"; _bfMarkerScript += " myEvent[" + offset + "] = GEvent.addListener(marker[" + offset + "],'click',function(){"; _bfMarkerScript += " "; _bfMarkerScript += " marker[" + offset + "].openInfoWindowHtml('" + _markerText + "'); });"; _bfMarkerScript += "map.addOverlay(marker[" + offset + "]);"; _bfMarkerScript += " gmarkers[" + offset + "] = marker[" + offset + "];"; _bfMarkerScript += "htmls[" + offset + "] = '" + _markerText + "';"; } _lat = decimal.Parse(ds.Tables[0].Rows[end - 1]["lat"].ToString()); _lng = decimal.Parse(ds.Tables[0].Rows[end - 1]["long"].ToString()); _bfPolyLine += " new GLatLng(" + _lat + "," + _lng + ")], "; _bfPolyLine += " '#008000', 10);"; _bfPolyLine += "map.addOverlay(polyline);"; _bfMarkerScript += _bfPolyLine; _script += " map.clearOverlays();"; _script += " map.setCenter(new GLatLng(" + latest_lat + "," + latest_lon + "),11,G_HYBRID_MAP);"; _script += " GEvent.addListener(map,'zoomend',afterZoomEnd);"; _script += _bfMarkerScript.ToString(); } } catch (Exception ex) { Console.WriteLine(ex.Message.ToString()); } return _script; }
public AlertData getLastAlert() { string strSQL = "SELECT * FROM tblAlert WHERE unitID = " + "(SELECT DISTINCT unitID FROM tblUnits WHERE deviceID = " + Session["deviceID"].ToString() + " AND comID = " + Session["trkCompany"].ToString() + ") ORDER BY id DESC LIMIT 1;"; ExecuteSQL exec = new ExecuteSQL(); DataSet ds = new DataSet(); AlertData alert = new AlertData(); try { ds = exec.getDataSet(strSQL); if (ds.Tables[0].Rows.Count > 0) { alert.AlertTime = ds.Tables[0].Rows[0]["alertTime"].ToString(); alert.AlertMessage = ds.Tables[0].Rows[0]["alertMessage"].ToString(); alert.AlertType = ds.Tables[0].Rows[0]["alertType"].ToString(); } } catch (Exception ex) { throw new Exception ("getLastAlert(): " + ex.Message + "\n" + strSQL); } return alert; }
private DataSet createDataSet(DataSet ds) { if (ds.Tables[0].Rows.Count == 0) { return null; } DataTable dt = new DataTable(); dt.Columns.Add("location", typeof(string)); dt.Columns.Add("velocity", typeof(int)); dt.Columns.Add("distance", typeof(decimal)); dt.Columns.Add("recDateTime", typeof(string)); dt.Columns.Add("alert", typeof(string)); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { DataRow row = dt.NewRow(); AlertData _alert = new AlertData(); MapDataCommon.GetAlert(ref _alert, Session["trkCompany"].ToString(), ds.Tables[0].Rows[i]["deviceID"].ToString(), ds.Tables[0].Rows[i]["recDateTime"].ToString()); if (i > 0) { double lat1, lon1; double lat2, lon2; lat1 = double.Parse(ds.Tables[0].Rows[i - 1]["lat"].ToString()); lon1 = double.Parse(ds.Tables[0].Rows[i - 1]["long"].ToString()); lat2 = double.Parse(ds.Tables[0].Rows[i]["lat"].ToString()); lon2 = double.Parse(ds.Tables[0].Rows[i]["long"].ToString()); dt.Rows[i - 1]["distance"] = DistanceCalculator.CalcDistance(lat1, lon1, lat2, lon2); } row["location"] = MapDataCommon.GetReverseGeocodingString(ds.Tables[0].Rows[i]["lat"].ToString(), ds.Tables[0].Rows[i]["long"].ToString()); row["velocity"] = ds.Tables[0].Rows[i]["velocity"]; row["recDateTime"] = XtremeK.TimeZone.ToLocalTime(ds.Tables[0].Rows[i]["recDateTime"].ToString()).ToString(); if (_alert.AlertMessage.Length > 0) { row["alert"] = _alert.AlertMessage; } else { row["alert"] = "Position"; } dt.Rows.Add(row); } dt.Rows[dt.Rows.Count - 1]["distance"] = 0; DataSet data = new DataSet(); data.Tables.Add(dt); return data; }
private string GetMarkerScript(bool init) { StringBuilder _bfScript = new StringBuilder(); StringBuilder _bfMarkerScript = new StringBuilder(); StringBuilder _bfPolyLine = new StringBuilder(); StringBuilder _script = new StringBuilder(); IList<MapData> _mapData; ProcessBreadCrumbsData _breadCrumbs = new ProcessBreadCrumbsData(); try { if (Session["recTime"] != null) { _breadCrumbs.ComID = int.Parse(Session["trkCompany"].ToString()); _breadCrumbs.DeviceID = int.Parse(Request.QueryString["deviceID"].ToString()); _breadCrumbs.RecTime = long.Parse(Session["recTime"].ToString()); _breadCrumbs.GetData1(); _mapData = _breadCrumbs.MapData; _bfScript.Append(" map.clearOverlays();"); _bfScript.Append(" DisPoseNodes(); "); } else { if (!init) return null; _breadCrumbs.ComID = int.Parse(Session["trkCompany"].ToString()); _breadCrumbs.DeviceID = int.Parse(Request.QueryString["deviceID"].ToString()); _breadCrumbs.GetData2(); _mapData = _breadCrumbs.MapData; } if (_mapData.Count > 0) { string _markerText = ""; decimal _lat = 0, _lng = 0; _bfPolyLine.Append(" polyline=new GPolyline([ "); for (int i = 0; i < _mapData.Count; i++) { AlertData _alert = new AlertData(); MapDataCommon.GetAlert(ref _alert, Session["trkCompany"].ToString(), _mapData[i].DeviceID, _mapData[i].RecTimeRevised); // Get the marker text for the map data object _markerText = MapDataCommon.GetMapMarkerText(_mapData[i], _alert.AlertMessage.Replace("\"", @"\\""")); if (init) { if (Session["recTime"] == null) { Session["recTime"] = long.Parse(_mapData[i].RecTime.ToString()); } } _bfPolyLine.Append(" new GLatLng(" + _mapData[i].Latitude + "," + _mapData[i].Longitude + "), "); _bfMarkerScript.Append(" point=new GPoint(" + _mapData[i].Longitude + "," + _mapData[i].Latitude + ");"); if (i == 0) { _bfMarkerScript.Append(" icon0 = new GIcon();"); _bfMarkerScript.Append(" icon0.image = \\'../Icon/" + _mapData[i].IconName + ".png\\';"); _bfMarkerScript.Append(" icon0.iconSize = new GSize(" + iconHeight + "," + iconWidth + ");"); _bfMarkerScript.Append(" icon0.iconAnchor = new GPoint(" + iconHeight/2 + "," + iconWidth/2 + ");"); _bfMarkerScript.Append(" icon0.infoWindowAnchor = new GPoint(15, 15);"); _bfMarkerScript.Append(" icon0.infoShadowAnchor = new GPoint(18, 25);"); _bfMarkerScript.Append(" label = new ELabel(new GLatLng(" + _mapData[i].Latitude + "," + _mapData[i].Longitude + "), \\'" + _mapData[i].UnitName + "\\',\\'tag_red\\');"); _bfMarkerScript.Append(" label.pixelOffset=new GSize(15,0);"); _bfMarkerScript.Append(" map.addOverlay(label);"); _bfMarkerScript.Append(" if (hide) label.hide();"); _bfMarkerScript.Append(" marker[" + i + "]=new GMarker(point,icon0);"); } else { string color = MapDataCommon.GetAlertColor(_alert); _bfMarkerScript.Append(" icon0 = new GIcon();"); _bfMarkerScript.Append(" icon0.image = \\'../Images/crumb_" + color + ".png\\';"); _bfMarkerScript.Append(" icon0.iconSize = new GSize(" + 20 + "," + 34 + ");"); _bfMarkerScript.Append(" icon0.iconAnchor = new GPoint(9,34);"); _bfMarkerScript.Append(" icon0.infoWindowAnchor = new GPoint(9,9);"); _bfMarkerScript.Append(" marker[" + i + "]=new GMarker(point,icon0);"); } _bfMarkerScript.Append(" myEvent[" + i + "]= GEvent.addListener(marker[" + i + "],\\'click\\',function(){"); _bfMarkerScript.Append(" "); _bfMarkerScript.Append(" marker[" + i + "].openInfoWindowHtml(\\'" + _markerText + "\\'); });"); _bfMarkerScript.Append("map.addOverlay(marker[" + i + "]);"); _lat = _mapData[i].Latitude; _lng = _mapData[i].Longitude; if (_mapData[i].Velocity == "0") { i = _mapData.Count; } } _bfPolyLine.Append(" new GLatLng(" + _lat + "," + _lng + ")], "); _bfPolyLine.Append(" \\'#008000\\', 10);"); _bfPolyLine.Append("map.addOverlay(polyline)"); _bfMarkerScript.Append(_bfPolyLine.ToString()); if (init) _script.Append("map.setCenter(new GLatLng(" + _lat + "," + _lng + "),13,G_HYBRID_MAP);"); else _script.Append("map.setCenter(new GLatLng(" + _mapData[0].Latitude + "," + _mapData[0].Longitude + "));"); _script.Append(_bfMarkerScript.ToString()); _bfScript.Append(" setTimeout('evalMarker(\"" + _script.ToString() + "\")',5); "); return _bfScript.ToString(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { _mapData = null; _bfMarkerScript = null; _bfPolyLine = null; _bfScript = null; _breadCrumbs = null; } return ""; }