/// <summary> /// Loads the map with uesr and friend locations /// </summary> /// <param name="queryDate">location on that date </param> /// <param name="friendFid">friend id to load map</param> /// <param name="locationId">location id to load map</param> /// <returns>map script for page which can be called simply by loadmap()</returns> public string LoadMap(string queryDate, string friendFid, string locationId) { StringBuilder sb = new StringBuilder("<script language=javascript>function loadMap() {"); sb.Append(String.Format("userFID={0};", user.FacebookId)); try { DataRow location; if (locationId != null) { location = tLocations.Select("locationID=" + locationId)[0]; } else if (friendFid != null) { location = tLocations.Select("ID=" + friendFid)[0]; } else if (!string.IsNullOrEmpty(queryDate)) { // ReSharper disable UndocumentedThrownException throw new Exception("not implemeneted yet"); // ReSharper restore UndocumentedThrownException //queryDate = DateTime.Now.ToString("u").Replace("Z", string.Empty); //DataRow location = dtLocations.Select("ID=" + friendFid)[0]; //sb = SocialerMap.InitializeMap(sb, location[3].ToString(), location[4].ToString(), 15); } else { location = tLocations.Select("ID=" + this.user.FacebookId)[0]; } sb = SocialerMap.InitializeMap(sb, location[3].ToString(), location[4].ToString(), 15); } catch { sb = SocialerMap.InitializeMap(sb, "41.00527", "28.97696", 2); } // load user locations) foreach (DataRow item in tLocations.Rows) { SocialerMapDbObject socialerMap = new SocialerMapDbObject { UserId = item[1].ToString(), LocationId = item[0].ToString(), Date = item[2].ToString().Replace('.', '/'), Latitude = item[3].ToString().Replace(',', '.').Trim(' '), Longitude = item[4].ToString().Replace(',', '.').Trim(' '), PostToWall = (bool)item[5], Desc = item[6].ToString(), Common = (bool)item[7] }; sb = SocialerMap.AddMarker(sb, socialerMap.UserId == this.user.FacebookId ? true : false, socialerMap, GetfriendName(socialerMap.UserId)); } sb.Append("}</script>"); return(sb.ToString()); }
/* * /// <summary> * /// executes Stored Procedure * /// </summary> * /// <param name="sp">procedure to execute</param> * /// <param name="values">parameters of SP</param> * /// <returns>result of execution</returns> * public DataSet ExecSp(string sp, params object[] values) * { * DataSet ds = new DataSet(); * try * { * using (SqlCommand command = new SqlCommand(sp, this._conn)) * { * command.CommandType = CommandType.StoredProcedure; * this._conn.Open(); * SqlCommandBuilder.DeriveParameters(command); * for (int i = 1; i <= values.Length; i++) * { * command.Parameters[i].Value = values[i - 1]; * } * * SqlDataAdapter adap = new SqlDataAdapter(command); * adap.Fill(ds); * } * } * catch (Exception ex) * { * InsertLog(null, EventType.DbError, "ExecSp", ex.Message); * } * finally * { * this._conn.Close(); * } * * return ds; * } */ /// <summary> /// inserts socialerobject to database /// </summary> /// <param name="obj">SocialerMap db obj to save DB </param> /// <returns>locationID of last inserted item</returns> public string InsertSocialerObj(SocialerMapDbObject obj) { if (string.IsNullOrEmpty(obj.Date)) { obj.Date = DateTime.Now.ToString("u").Replace("Z", string.Empty); } InsertLog(obj.UserId, EventType.Inserted, "InsertSocialerObj", obj.ToString()); return(this.ExecuteScalar(String.Format("exec saveLocationProc {0},'{1}','{2}','{3}',{4},'{5}',{6}", obj.UserId, obj.Date, obj.Latitude, obj.Longitude, (obj.PostToWall ? 1 : 0), obj.Desc, (obj.Common ? 1 : 0))).ToString()); }
/// <summary> /// Delete SocialerMap object from the database using userID validation /// </summary> /// <param name="obj">SocialerMap object to delete</param> /// <param name="userId"> user validator ID</param> public void DeleteSocialerObj(SocialerMapDbObject obj, string userId) { if (obj.LocationId != null) { return; } DataTable userLocation = this.Get("select ID from tLocation where locationID= " + obj.LocationId); if (userLocation.Rows[0][0].ToString() == userId) { this.Exec("delete from tLocation where locationID=" + obj.LocationId); InsertLog(userId, EventType.Deleted, "DeleteSocialerObj", null); } else { InsertLog(userId, EventType.HackingAttempt, "DeleteSocialerObj", null); } }
/// <summary> /// Adds Map Marker to the Map /// </summary> /// <param name="sb">string which keeps javascript to load Map</param> /// <param name="removable">Is this map can be removed by user</param> /// <param name="socialerMapObj">User's information</param> /// <param name="displayString">User's display information</param> /// <returns>javascript after modification</returns> public static StringBuilder AddMarker(StringBuilder sb, bool removable, SocialerMapDbObject socialerMapObj,string displayString) { sb.Append(String.Format( @"marker_{0} = new google.maps.Marker({{map: map,title: '{1}@{6}:{2}',icon:'https://graph.facebook.com/{3}/picture' }}); marker_{0}.setPosition(new google.maps.LatLng('{4}', '{5}')); ", socialerMapObj.LocationId, displayString, socialerMapObj.Date, socialerMapObj.UserId, socialerMapObj.Latitude, socialerMapObj.Longitude, socialerMapObj.Desc)); if (!removable) { sb.Append(" google.maps.event.addListener(marker_" + socialerMapObj.LocationId + @", 'click', function (e) { infowindow_" + socialerMapObj.LocationId + " = new google.maps.InfoWindow({content: '" + displayString + "@" + socialerMapObj.Date + ":" + socialerMapObj.Desc + @"'}); infowindow_" + socialerMapObj.LocationId + ".open(map, marker_" + socialerMapObj.LocationId + @");} );"); } else { sb.Append(String.Format( @"var content_{0}='<div>{1}@{3}:</br>{2}</br><a class=\button\ href=\#\ onclick=\ this.blur();deleteLocation(marker_{0},{0});\> <center>Delete this location</center> </a></div>'; google.maps.event.addListener(marker_{0}, 'click', function(e) {{ var infowindow = new google.maps.InfoWindow({{content: content_{0}}}); infowindow.open(map, marker_{0});}});", socialerMapObj.LocationId, displayString, socialerMapObj.Desc, socialerMapObj.Date)); } return sb; }
/// <summary> /// Adds Map Marker to the Map /// </summary> /// <param name="sb">string which keeps javascript to load Map</param> /// <param name="removable">Is this map can be removed by user</param> /// <param name="socialerMapObj">User's information</param> /// <param name="displayString">User's display information</param> /// <returns>javascript after modification</returns> public static StringBuilder AddMarker(StringBuilder sb, bool removable, SocialerMapDbObject socialerMapObj, string displayString) { sb.Append(String.Format( @"marker_{0} = new google.maps.Marker({{map: map,title: '{1}@{6}:{2}',icon:'https://graph.facebook.com/{3}/picture' }}); marker_{0}.setPosition(new google.maps.LatLng('{4}', '{5}')); ", socialerMapObj.LocationId, displayString, socialerMapObj.Date, socialerMapObj.UserId, socialerMapObj.Latitude, socialerMapObj.Longitude, socialerMapObj.Desc)); if (!removable) { sb.Append(" google.maps.event.addListener(marker_" + socialerMapObj.LocationId + @", 'click', function (e) { infowindow_" + socialerMapObj.LocationId + " = new google.maps.InfoWindow({content: '" + displayString + "@" + socialerMapObj.Date + ":" + socialerMapObj.Desc + @"'}); infowindow_" + socialerMapObj.LocationId + ".open(map, marker_" + socialerMapObj.LocationId + @");} );"); } else { sb.Append(String.Format( @"var content_{0}='<div>{1}@{3}:</br>{2}</br><a class=\button\ href=\#\ onclick=\ this.blur();deleteLocation(marker_{0},{0});\> <center>Delete this location</center> </a></div>'; google.maps.event.addListener(marker_{0}, 'click', function(e) {{ var infowindow = new google.maps.InfoWindow({{content: content_{0}}}); infowindow.open(map, marker_{0});}});", socialerMapObj.LocationId, displayString, socialerMapObj.Desc, socialerMapObj.Date)); } return(sb); }
private void LocationActions(NameValueCollection QueryString, FacebookLayer fb) { Database db = new Database(); SocialerMapDbObject obj = new SocialerMapDbObject(); switch (QueryString["action"]) { case "delete": obj.LocationId = Request.QueryString["locationID"]; db.DeleteSocialerObj(obj, fb.User.FacebookId); break; case "add": obj.UserId = fb.User.FacebookId; obj.Date = Request.QueryString["Date"]; obj.Latitude = Request.QueryString["Latitude"]; obj.Longitude = Request.QueryString["Longitude"]; obj.PostToWall = Convert.ToBoolean(Request.QueryString["postwall"]); obj.Desc = Request.QueryString["description"]; obj.Common = Convert.ToBoolean(Request.QueryString["common"]); string locationID = db.InsertSocialerObj(obj); if (obj.PostToWall) { dynamic parameters = new ExpandoObject(); parameters.message = "Checked in via SocialerMap"; parameters.link = "http://apps.facebook.com/socialermapfbapp/Default.aspx?locationID=" + locationID; parameters.name = QueryString["description"]; parameters.picture = "http://www.socialermap.com/socialermapfbapp/Resources/icon.png"; parameters.caption = "Find where i am at " + obj.Date; parameters.privacy = new { value = "ALL_FRIENDS", }; fb.fbClient.Post("/me/feed", parameters); } break; } }
/* /// <summary> /// executes Stored Procedure /// </summary> /// <param name="sp">procedure to execute</param> /// <param name="values">parameters of SP</param> /// <returns>result of execution</returns> public DataSet ExecSp(string sp, params object[] values) { DataSet ds = new DataSet(); try { using (SqlCommand command = new SqlCommand(sp, this._conn)) { command.CommandType = CommandType.StoredProcedure; this._conn.Open(); SqlCommandBuilder.DeriveParameters(command); for (int i = 1; i <= values.Length; i++) { command.Parameters[i].Value = values[i - 1]; } SqlDataAdapter adap = new SqlDataAdapter(command); adap.Fill(ds); } } catch (Exception ex) { InsertLog(null, EventType.DbError, "ExecSp", ex.Message); } finally { this._conn.Close(); } return ds; } */ /// <summary> /// inserts socialerobject to database /// </summary> /// <param name="obj">SocialerMap db obj to save DB </param> /// <returns>locationID of last inserted item</returns> public string InsertSocialerObj(SocialerMapDbObject obj) { if (string.IsNullOrEmpty(obj.Date)) { obj.Date = DateTime.Now.ToString("u").Replace("Z", string.Empty); } InsertLog(obj.UserId, EventType.Inserted, "InsertSocialerObj", obj.ToString()); return this.ExecuteScalar(String.Format("exec saveLocationProc {0},'{1}','{2}','{3}',{4},'{5}',{6}", obj.UserId, obj.Date, obj.Latitude, obj.Longitude, (obj.PostToWall ? 1 : 0), obj.Desc, (obj.Common ? 1 : 0))).ToString(); }
/// <summary> /// Loads the map with uesr and friend locations /// </summary> /// <param name="queryDate">location on that date </param> /// <param name="friendFid">friend id to load map</param> /// <param name="locationId">location id to load map</param> /// <returns>map script for page which can be called simply by loadmap()</returns> public string LoadMap(string queryDate, string friendFid, string locationId) { StringBuilder sb = new StringBuilder("<script language=javascript>function loadMap() {"); sb.Append(String.Format("userFID={0};", user.FacebookId)); try { DataRow location; if (locationId != null) { location = tLocations.Select("locationID=" + locationId)[0]; } else if (friendFid != null) { location = tLocations.Select("ID=" + friendFid)[0]; } else if (!string.IsNullOrEmpty(queryDate)) { // ReSharper disable UndocumentedThrownException throw new Exception("not implemeneted yet"); // ReSharper restore UndocumentedThrownException //queryDate = DateTime.Now.ToString("u").Replace("Z", string.Empty); //DataRow location = dtLocations.Select("ID=" + friendFid)[0]; //sb = SocialerMap.InitializeMap(sb, location[3].ToString(), location[4].ToString(), 15); } else { location = tLocations.Select("ID=" + this.user.FacebookId)[0]; } sb = SocialerMap.InitializeMap(sb, location[3].ToString(), location[4].ToString(), 15); } catch { sb = SocialerMap.InitializeMap(sb, "41.00527", "28.97696", 2); } // load user locations) foreach (DataRow item in tLocations.Rows) { SocialerMapDbObject socialerMap = new SocialerMapDbObject { UserId = item[1].ToString(), LocationId = item[0].ToString(), Date = item[2].ToString().Replace('.', '/'), Latitude = item[3].ToString().Replace(',', '.').Trim(' '), Longitude = item[4].ToString().Replace(',', '.').Trim(' '), PostToWall = (bool)item[5], Desc = item[6].ToString(), Common = (bool)item[7] }; sb = SocialerMap.AddMarker(sb, socialerMap.UserId == this.user.FacebookId ? true : false, socialerMap, GetfriendName(socialerMap.UserId)); } sb.Append("}</script>"); return sb.ToString(); }