/// <summary> /// Called when a cache is selected in the cache list /// </summary> /// <param name="cache"> /// The selected geocache <see cref="Geocache"/> /// </param> public void SetCache(Geocache cache) { m_cache = cache; m_model = new ListStore(typeof(Pixbuf), typeof(string), typeof(string)); if (cache == null) { this.Sensitive = false; return; } this.Sensitive = true; string imagesFolder = GetImagesFolder(); fileLabel.Text = String.Format(Catalog.GetString("Images Folder: {0}"), imagesFolder); if (Directory.Exists(imagesFolder)) { string[] files = Directory.GetFiles(imagesFolder); foreach (string file in files) { try { Pixbuf buf = new Pixbuf(file, 256, 256); string[] filePath = file.Split('/'); m_model.AppendValues(buf, filePath[filePath.Length - 1], file); } catch (GLib.GException) { // Ignore invalid image files } } } imagesView.Model = m_model; imagesView.PixbufColumn = 0; imagesView.TextColumn = 1; imagesView.SelectionMode = SelectionMode.Single; }
public IActionResult FindCoords(double Lat, double Lng) { //Geocache thisGeocache = new Geocache(); var foundAddress = Geocache.FindLocation(Lat, Lng); return(RedirectToAction("Show", foundAddress)); }
/// <summary> /// Check if a cache shall be displayed based on filter definition /// </summary> /// <param name="cache">Cache to be checked</param> /// <returns>true if cache shall be displayed (passes the filter definition)</returns> public override bool ToBeDisplayed(Geocache cache) { if ((cache._Ocd != null) && (cache._Ocd._dAltiMeters != Double.MaxValue)) { if ((_comparison == 0) && (cache._Ocd._dAltiMeters >= _altitude)) { return(true); } else if ((_comparison == 1) && (cache._Ocd._dAltiMeters == _altitude)) { return(true); } else if ((_comparison == 2) && (cache._Ocd._dAltiMeters <= _altitude)) { return(true); } else { return(false); } } else { return(false); } }
public void EditChildWaypoint(Waypoint pt) { Geocache parent = m_Window.CacheList.SelectedCache; WaypointDialog dlg = new WaypointDialog(); string origname = pt.Name; dlg.App = this; dlg.IgnorePrefix = m_Config.IgnoreWaypointPrefixes; dlg.SetPoint(pt); if ((int)ResponseType.Ok == dlg.Run()) { pt = dlg.GetPoint(); if (pt.Symbol == "Final Location") { parent.HasFinal = true; } if (!parent.Children) { parent.Children = true; } m_Store.AddWaypointOrCache(pt, false, false); if (pt.Name != origname) { m_Store.DeleteWaypoint(origname); } m_Window.Refresh(); m_Window.CacheInfo.SelectChildByName(pt.Name); } dlg.Hide(); }
public static bool AddGeocache(Database db, GeocacheData gd) { bool result = true; if (!Core.Settings.Default.GeocacheIgnored(gd)) { Geocache gc = db.GeocacheCollection.GetGeocache(gd.Code); if (gc == null) { gc = new Geocache(db, gd); gc.Selected = Core.Settings.Default.AutoSelectNewGeocaches; } else { if (gc.DataFromDate < gd.DataFromDate) { gc.BeginUpdate(); GeocacheData.Copy(gd, gc); gc.EndUpdate(); } } Utils.Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, ApplicationData.Instance.CenterLocation); } else { result = false; } return(result); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["id"] == null) { Response.Redirect("all.aspx"); } geocacheId = Request.QueryString["id"]; geocache = GeocacheDb.retrieveGeocache(geocacheId); username = GeocacheDb.retrieveUsername(geocache.iduser); geocacheNameLabel.DataBind(); usernameLabel.DataBind(); geocacheDateCreatedLabel.DataBind(); geocacheImage.DataBind(); geocacheDescriptionTextBox.DataBind(); bool geocacheReportStatus = GeocacheDb.retrieveGeocacheReportStatus(geocacheId); if (geocacheReportStatus == true) { reportButton.Enabled = false; reportButton.Text = "Reported"; } else { } SqlDataSource_Find.SelectCommand = "SELECT find.findId, find.findName, find.findDescription, find.findImage, find.findDateCreated, `user`.username, find.findStatus, COUNT(findReport.findId) AS noOfReport, (SELECT COUNT(*) FROM findReport WHERE findReport.findId = find.findId AND findReport.iduser = @iduser) AS reportStatus FROM find INNER JOIN `user` ON find.idUser = `user`.iduser LEFT JOIN findReport ON find.findId = findReport.findId WHERE find.geocacheId = @geocacheId GROUP BY find.findId;"; SqlDataSource_Find.SelectParameters.Add("@geocacheId", geocacheId); SqlDataSource_Find.SelectParameters.Add("@iduser", iduser.ToString()); }
/// <summary> /// Updates Cache Status /// </summary> /// <param name="cache"> /// A <see cref="Geocache"/> /// </param> /// <param name="log"> /// A <see cref="CacheLog"/> /// </param> public void UpdateCache(Geocache cache, CacheLog log) { if (cache == null) { return; } m_Win.App.CacheStore.AddLog(log.CacheCode, log); if (log.LogStatus == "Found it") { cache.DNF = false; cache.FTF = false; cache.Symbol = "Geocache Found"; m_Win.App.CacheStore.AddWaypointOrCache(cache, false, false); } else if (log.LogStatus == "Didn't find it") { cache.DNF = true; cache.FTF = false; cache.Symbol = "Geocache"; m_Win.App.CacheStore.AddWaypointOrCache(cache, false, false); } else if (log.LogStatus == "Needs Maintenance") { cache.CheckNotes = true; } }
/// <summary> /// Check if a cache shall be displayed based on filter definition /// </summary> /// <param name="cache">Cache to be checked</param> /// <returns>true if cache shall be displayed (passes the filter definition)</returns> public override bool ToBeDisplayed(Geocache cache) { // for logs & descriptions String keyBing = "<br><b><font color=#FF0000>[TRANSLATION - START]</font></b>"; // for hint String keyBing2 = "[TRANSLATION - START]"; // display only caches NOT translated if (IsTranslated(cache._LongDescription, keyBing)) { return(false); } if (IsTranslated(cache._ShortDescription, keyBing)) { return(false); } if (IsTranslated(cache._Hint, keyBing2)) { return(false); } foreach (CacheLog log in cache._Logs) { if (IsTranslated(log._Text, keyBing2)) { return(false); } } return(true); }
private void SetUserDataFields(Geocache cache) { if (!String.IsNullOrEmpty(cache.User1)) { uData1.Text = cache.User1; } else { uData1.Text = Catalog.GetString("None"); } if (!String.IsNullOrEmpty(cache.User2)) { uData2.Text = cache.User2; } else { uData2.Text = Catalog.GetString("None"); } if (!String.IsNullOrEmpty(cache.User3)) { uData3.Text = cache.User3; } else { uData3.Text = Catalog.GetString("None"); } if (!String.IsNullOrEmpty(cache.User4)) { uData4.Text = cache.User4; } else { uData4.Text = Catalog.GetString("None"); } }
public static List <Geocache> GetGeocaches(SiteInfo si, List <string> gcCodes) { List <Geocache> result = new List <Geocache>(); StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0}services/caches/geocaches?format=json&lpc=5&user_uuid={1}&fields=code|name|location|type|status|url|owner|is_found|size2|difficulty|terrain|description|hint2|images|attr_acodes|latest_logs|country|state|date_hidden|alt_wpts&cache_codes=", si.OKAPIBaseUrl, HttpUtility.UrlEncode(si.UserID)); for (int i = 0; i < gcCodes.Count; i++) { if (i > 0) { sb.Append('|'); } sb.Append(gcCodes[i]); } sb.AppendFormat("&consumer_key={0}", HttpUtility.UrlEncode(si.ConsumerKey)); string doc = GetResultOfUrl(sb.ToString()); var json = new JavaScriptSerializer() { MaxJsonLength = int.MaxValue }; var dict = (IDictionary <string, object>)json.DeserializeObject(doc); foreach (KeyValuePair <string, object> kp in dict) { if (kp.Value as Dictionary <string, object> != null) { Geocache gc = new Geocache(kp.Value as Dictionary <string, object>); result.Add(gc); } } return(result); }
public void SetCache(Geocache cache) { descriptionPane.SetCache(cache); cacheNotes.SetCache(cache); imageWidget.SetCache(cache); if (cache == null) { logViewer.SetCacheLogs(null); } else { logViewer.SetCacheLogs(m_App.CacheStore.GetCacheLogs(cache.Name)); } if (cache == null) { waypointWidget.SetCacheAndPoints(null, null); } else { waypointWidget.SetCacheAndPoints(cache, m_App.CacheStore.GetChildWaypoints(new string[] { cache.Name })); } quickInfoPane.SetCache(cache); if (imageWidget.HasImages) { imageLabel.Markup = "<b>" + Catalog.GetString("Images") + "</b>"; } else { imageLabel.Text = Catalog.GetString("Images"); } }
public IHttpActionResult Delete(int id) { Geocache geocache = db.Geocaches.Find(id); //Check if the geocache is null from the request body if (geocache == null) { return(NotFound()); } //Remove the geocache from the database var status = db.Geocaches.Remove(geocache); try { //Save changes to the database db.SaveChanges(); } catch (DbUpdateConcurrencyException) { //If there was an error with the save and the cache //does not exist if (!GeocacheExists(id)) { return(Conflict()); } else { //Return 500 if there was an updating error not handled by the if statement return(InternalServerError()); } } return(Ok(geocache)); }
/// <summary> /// Check if a cache shall be displayed based on filter definition /// </summary> /// <param name="cache">Cache to be checked</param> /// <returns>true if cache shall be displayed (passes the filter definition)</returns> public override bool ToBeDisplayed(Geocache cache) { if (_od != null) { if (_od._OfflineData.ContainsKey(cache._Code)) { OfflineCacheData ocd = _od._OfflineData[cache._Code]; if (ocd._NotDownloaded) { return(true); } else { return(false); } } else { return(true); } } else { return(true); } }
public void Refresh() { try { if (null != this.RefreshStart) { RefreshStart(this, new EventArgs()); } Geocache selected = SelectedCache; m_disabledOrArchivedCount = 0; m_visibleCount = 0; m_mineCount = 0; m_foundCount = 0; if (m_app.AppConfig.ImperialUnits) { m_distanceColumn.Title = Catalog.GetString("Mi"); distanceLabel.Text = Catalog.GetString("Mi"); } else { m_distanceColumn.Title = Catalog.GetString("km"); distanceLabel.Text = Catalog.GetString("km"); } UpdateStatus(); CacheStore.GlobalFilters.AddFilterCriteria(FilterList.KEY_STATUS, new bool[] { foundCheck.Active, notFoundCheck.Active, mineCheck.Active, availCheck.Active, notAvailCheck.Active, archiveCheck.Active }); cacheListTree.Model = null; if (m_list == null) { m_list = new CacheStoreModel(); } else { m_list.Clear(); } if (m_sort == null) { m_sort = new TreeModelSort(new TreeModelAdapter(m_list)); m_sort.SetSortFunc(3, TitleCompare); m_sort.SetSortFunc(2, DistanceCompare); m_sort.SetSortFunc(0, SymbolCompare); m_sort.DefaultSortFunc = DistanceCompare; } CacheStore.ReadCache += HandleCacheStoreReadCache; CacheStore.Complete += HandleCacheStoreComplete; CacheStore.GetUnfilteredCaches(m_app.CentreLat, m_app.CentreLon, m_app.OwnerIDs.ToArray()); CacheStore.ReadCache -= HandleCacheStoreReadCache; CacheStore.Complete -= HandleCacheStoreComplete; } catch (Exception e) { OCMApp.ShowException(e); } }
void HandleRmvCacheActivated(object sender, EventArgs e) { Geocache cache = m_Win.CacheList.SelectedCache; m_app.CacheStore.RemoveBookmarkEntry(m_app.CacheStore.ActiveBookmarkList, cache.Name); Refresh(); }
public void SetDescription(Geocache cache) { String baseURL = cache.URL.Scheme + "://" + cache.URL.Host; descWidget.SetHTML("<div style='font-family:sans-serif;font-size:10pt; background-color:#FFFFFF'>" + cache.ShortDesc + "\n\n" + cache.LongDesc + "</div>", baseURL); }
public override void Arrange() { base.Arrange(); cache = new Geocache { Name = "Geocache 500", Coordinate = new Coordinate(-89.0, 112.0) }; }
public override void Arrange() { base.Arrange(); cache = new Geocache { Name = string.Empty, Coordinate = new Coordinate(1000.0, -999) }; }
public void AutoGenerateChildren(MatchCollection matches) { int count = 0; m_App.CacheStore.StartUpdate(); foreach (Match match in matches) { DegreeMinutes[] coord = Utilities.ParseCoordString(match.Captures[0].Value); System.Console.WriteLine(Utilities.getCoordString(coord[0], coord[1])); Waypoint newPoint = new Waypoint(); Geocache parent = m_Cache; newPoint.Symbol = "Reference Point"; newPoint.Parent = parent.Name; newPoint.Lat = coord[0].GetDecimalDegrees(); newPoint.Lon = coord[1].GetDecimalDegrees(); newPoint.Desc = Catalog.GetString("Grabbed Waypoint"); String name = "RP" + parent.Name.Substring(2); if (m_App.AppConfig.IgnoreWaypointPrefixes) { name = parent.Name; } name = m_App.CacheStore.GetUniqueName(name); newPoint.Name = name; m_App.CacheStore.AddWaypointOrCache(newPoint, false, false); count++; } m_App.CacheStore.CompleteUpdate(); m_App.RefreshAll(); }
private void ParseXmlResponse(string response, List <Geocache> caches) { var formatProvider = new CultureInfo("en-US"); XmlDocument doc = new XmlDocument(); doc.LoadXml(response); var list = doc.SelectNodes("/markers/marker[@available='1']"); foreach (IXmlNode xmlNode in list) { try { Geocache cache = new Geocache(); var attributes = XmlUtils.GetAttributeMap(xmlNode); cache.Name = attributes["cachename"]; cache.Username = attributes["username"]; cache.Id = attributes["waypoint"]; cache.Type = attributes["cache_type_name"]; cache.Difficulty = Convert.ToDouble(attributes["difficulty"], formatProvider); cache.Terrain = Convert.ToDouble(attributes["terrain"], formatProvider); cache.Size = attributes["container_name"]; cache.Available = attributes["available"] == "1"; cache.Position = new BasicGeoposition() { Latitude = Convert.ToDouble(attributes["lat"], formatProvider), Longitude = Convert.ToDouble(attributes["lng"], formatProvider) }; caches.Add(cache); } catch (Exception ex) { Debug.WriteLine("[ERROR] " + ex.Message); } } }
public static string GetStatusIcon(Geocache cache, OCMApp app, bool ignoreFound) { if (cache.Found && !ignoreFound) { if (cache.FTF) { return(FTF_MI); } return(FOUND_MI); } if ((app.OwnerIDs.Contains(cache.OwnerID)) || (app.OwnerIDs.Contains(cache.CacheOwner))) { return(OWNED_MI); } if ((cache.HasCorrected || cache.HasFinal)) { if (app.AppConfig.SolvedModeState == SolvedMode.ALL) { return(CORRECTED_MI); } else if (app.AppConfig.SolvedModeState == SolvedMode.PUZZLES && cache.TypeOfCache == Geocache.CacheType.MYSTERY) { return(CORRECTED_MI); } } else if (cache.DNF && app.AppConfig.ShowDNFIcon) { return(DNF_MI); } return(null); }
public void setCoordinate(Geocache cache) { coordinateLabel.Markup = "<span font='bold 10'>" + Utilities.getCoordString(cache.Lat, cache.Lon) + "</span>"; if (cache.HasCorrected) { origCoord.Markup = Catalog.GetString("<i>Original: ") + Utilities.getCoordString(cache.OrigLat, cache.OrigLon) + "</i>"; } else { origCoord.Markup = String.Empty; } ; double distance = Utilities.calculateDistance(m_app.CentreLat, cache.Lat, m_app.CentreLon, cache.Lon); double bearing = Utilities.calculateBearing(m_app.CentreLat, cache.Lat, m_app.CentreLon, cache.Lon); string bmarker = Catalog.GetString("N"); if (bearing > 22.5 && bearing <= 67.5) { bmarker = Catalog.GetString("NE"); } else if (bearing > 67.5 && bearing <= 112.5) { bmarker = Catalog.GetString("E"); } else if (bearing > 112.5 && bearing <= 157.5) { bmarker = Catalog.GetString("SE"); } else if (bearing > 157.5 && bearing <= 202.5) { bmarker = Catalog.GetString("S"); } else if (bearing > 202.5 && bearing <= 247.5) { bmarker = Catalog.GetString("SW"); } else if (bearing > 247.5 && bearing <= 292.5) { bmarker = Catalog.GetString("W"); } else if (bearing > 292.5 && bearing <= 337.5) { bmarker = Catalog.GetString("NW"); } if (AppConfig.ImperialUnits) { distance = Utilities.KmToMiles(distance); distance_label.Markup = Catalog.GetString(String.Format(Catalog.GetString("<span font='bold italic 10'>({0} miles {1} from {2})</span>"), distance.ToString("0.00"), bmarker, m_app.CenterName)); } else { distance_label.Markup = Catalog.GetString(String.Format(Catalog.GetString("<span font='bold italic 10'>({0} km {1} from {2})</span>"), distance.ToString("0.00"), bmarker, m_app.CenterName)); } }
void HandleCacheListTreeSelectionChanged(object sender, EventArgs e) { m_Selected = GetSelectedCache(sender as TreeSelection); if (this.SelectionChanged != null) { this.SelectionChanged(this, new CacheEventArgs(m_Selected)); } }
public IGeocache AddGeocache(IGeocache geocache) { Geocache newGeocache = new Geocache(geocache); db.Geocaches.Add(newGeocache); db.SaveChanges(); geocache.ID = newGeocache.ID; return geocache; }
public async Task AddGeocacheAsync(Geocache geocache, int personID) { using (var db = new AppDbContext()) { var person = await db.Person.FirstAsync(p => p.ID == personID); person.Geocaches.Add(geocache); await db.SaveChangesAsync(); } }
public Geocache GetGeocacheByCode(string code) { if (sc != null && sc.isValid()) { Geocache g = new Geocache(code); if (!g.empty) return new Geocache(code); else return null; } else { return null; } }
public Geocache GetGeocache(Guid id) { if (sc != null && sc.isValid()) { Geocache g = new Geocache(id); if (!g.empty) return new Geocache(id); else return null; } else { return null; } }
/// <summary> /// Check if a cache shall be displayed based on filter definition /// </summary> /// <param name="cache">Cache to be checked</param> /// <returns>true if cache shall be displayed (passes the filter definition)</returns> public override bool ToBeDisplayed(Geocache cache) { foreach (String dt in _dates) { if (cache._DateCreation.Contains(dt)) { return(true); } } return(false); }
protected virtual void OnFTFCheck(object sender, System.EventArgs e) { if (m_caches.ContainsKey(m_currLog.CacheCode)) { Geocache cache = m_caches[m_currLog.CacheCode]; cache.FTF = firstToFindCheck.Active; hasUnsaved = true; saveButton.Sensitive = true; needsRefresh = true; } }
public override bool ToBeDisplayed(Geocache cache) { if (_dates.Contains(cache._dtDateCreation.ToString("ddMM"))) { return(true); } else { return(false); } }
/// <summary> /// Check if a cache shall be displayed based on filter definition /// </summary> /// <param name="cache">Cache to be checked</param> /// <returns>true if cache shall be displayed (passes the filter definition)</returns> public override bool ToBeDisplayed(Geocache cache) { if (_hs.Contains(cache._Code)) { return(false); } else { return(true); } }
private int SymbolCompare(TreeModel model, TreeIter tia, TreeIter tib) { Geocache cacheA = (Geocache)model.GetValue(tia, 0); Geocache cacheB = (Geocache)model.GetValue(tib, 0); if (cacheA == null || cacheB == null) { return(0); } return(String.Compare(cacheA.TypeOfCache.ToString(), cacheB.TypeOfCache.ToString())); }
private int CodeCompare(TreeModel model, TreeIter tia, TreeIter tib) { Geocache cacheA = (Geocache)model.GetValue(tia, 0); Geocache cacheB = (Geocache)model.GetValue(tib, 0); if (cacheA == null || cacheB == null) { return(0); } return(String.Compare(cacheA.Name, cacheB.Name)); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["id"] == null) { Response.Redirect("all.aspx"); } geocacheId = Request.QueryString["id"]; geocache = GeocacheDb.retrieveGeocache(geocacheId); if (!Page.IsPostBack) { nameTextBox.Text = geocache.geocacheName; descriptionTextBox.Text = geocache.geocacheDescription; latitudeTextBox.Text = geocache.geocacheLatitude; longitudeTextBox.Text = geocache.geocacheLongitude; verificationCodeLabel.Text = geocache.geocacheVerificationId; difficultyDropDownList.SelectedValue = geocache.geocacheDifficulty.ToString(); } }
/// <summary> /// inserts a geocache with location and logbook /// using insertGeocacheWithLocationAndLogbook /// stored procedure /// </summary> /// <param name="g"></param> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <returns></returns> public static bool? Insert(Geocache g, double latitude, double longitude) { try { using (System.Data.SqlClient.SqlConnection c = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager. ConnectionStrings["blueharvest-rds"].ConnectionString)) { using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand( "blueharvest.dbo.insertGeocacheWithLocationAndLogbook", c)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; // input parameter(s) // id = newid() // anniversary = sysutcdatetime() cmd.Parameters.Add("@code", System.Data.SqlDbType.NVarChar, 13); cmd.Parameters["@code"].Direction = System.Data.ParameterDirection.Input; cmd.Parameters["@code"].Value = g.name; cmd.Parameters.Add("@name", System.Data.SqlDbType.NVarChar, 50); cmd.Parameters["@name"].Direction = System.Data.ParameterDirection.Input; cmd.Parameters["@name"].Value = g.name; cmd.Parameters.Add("@description", System.Data.SqlDbType.NVarChar, -1); cmd.Parameters["@description"].Direction = System.Data.ParameterDirection.Input; cmd.Parameters["@description"].Value = g.description; cmd.Parameters.Add("@difficulty", System.Data.SqlDbType.Int); cmd.Parameters["@difficulty"].Direction = System.Data.ParameterDirection.Input; cmd.Parameters["@difficulty"].Value = g.difficulty; cmd.Parameters.Add("@terrain", System.Data.SqlDbType.Int); cmd.Parameters["@terrain"].Direction = System.Data.ParameterDirection.Input; cmd.Parameters["@terrain"].Value = g.terrain; cmd.Parameters.Add("@size", System.Data.SqlDbType.Int); cmd.Parameters["@size"].Direction = System.Data.ParameterDirection.Input; cmd.Parameters["@size"].Value = g.size; cmd.Parameters.Add("@status", System.Data.SqlDbType.Int); cmd.Parameters["@status"].Direction = System.Data.ParameterDirection.Input; cmd.Parameters["@status"].Value = g.status; cmd.Parameters.Add("@type", System.Data.SqlDbType.Int); cmd.Parameters["@type"].Direction = System.Data.ParameterDirection.Input; cmd.Parameters["@type"].Value = g.type; cmd.Parameters.Add("@userid", System.Data.SqlDbType.UniqueIdentifier); cmd.Parameters["@userid"].Direction = System.Data.ParameterDirection.Input; cmd.Parameters["@userid"].Value = g.userid; cmd.Parameters.Add("@latitude", System.Data.SqlDbType.Decimal, 10); cmd.Parameters["@latitude"].Precision = 10; cmd.Parameters["@latitude"].Scale = 7; cmd.Parameters["@latitude"].Direction = System.Data.ParameterDirection.Input; cmd.Parameters["@latitude"].Value = latitude; cmd.Parameters.Add("@longitude", System.Data.SqlDbType.Decimal, 10); cmd.Parameters["@longitude"].Precision = 10; cmd.Parameters["@longitude"].Scale = 7; cmd.Parameters["@longitude"].Direction = System.Data.ParameterDirection.Input; cmd.Parameters["@longitude"].Value = longitude; c.Open(); cmd.ExecuteNonQuery(); // open and execute } } return true; } catch { // the insert failed somehow (duplicate parameters, sql error, etc.) return false; } }
public static bool? Update(Geocache g) { // todo: update in db table return false; }
/// <summary>getGeocachesWithinDistance stored procedure</summary> /// <param name="minlatrad">minimum latitude in radians</param> /// <param name="maxlatrad">maximum latitude in radians</param> /// <param name="minlngrad">minimum longitude in radians</param> /// <param name="maxlngrad">maximum longitude in radians</param> /// <param name="latrad">center latitude coordinate in radians</param> /// <param name="lngrad">center longitude coordinate in radians</param> /// <param name="distance">distance (radius)</param> public Geocaches(double minlatrad, double maxlatrad, double minlngrad, double maxlngrad, double latrad, double lngrad, double distance) { using (System.Data.SqlClient.SqlConnection c = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager. ConnectionStrings["blueharvest-rds"].ConnectionString)) { using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand( "blueharvest.dbo.getGeocachesWithinDistance", c)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; // input parameter(s) cmd.Parameters.Add("@minlatrad", System.Data.SqlDbType.Decimal, 20); cmd.Parameters["@minlatrad"].Precision = 20; cmd.Parameters["@minlatrad"].Scale = 18; cmd.Parameters["@minlatrad"].Direction = System.Data.ParameterDirection.Input; cmd.Parameters["@minlatrad"].Value = minlatrad; cmd.Parameters.Add("@maxlatrad", System.Data.SqlDbType.Decimal, 20); cmd.Parameters["@maxlatrad"].Precision = 20; cmd.Parameters["@maxlatrad"].Scale = 18; cmd.Parameters["@maxlatrad"].Direction = System.Data.ParameterDirection.Input; cmd.Parameters["@maxlatrad"].Value = maxlatrad; cmd.Parameters.Add("@minlngrad", System.Data.SqlDbType.Decimal, 20); cmd.Parameters["@minlngrad"].Precision = 20; cmd.Parameters["@minlngrad"].Scale = 18; cmd.Parameters["@minlngrad"].Direction = System.Data.ParameterDirection.Input; cmd.Parameters["@minlngrad"].Value = minlngrad; cmd.Parameters.Add("@maxlngrad", System.Data.SqlDbType.Decimal, 20); cmd.Parameters["@maxlngrad"].Precision = 20; cmd.Parameters["@maxlngrad"].Scale = 18; cmd.Parameters["@maxlngrad"].Direction = System.Data.ParameterDirection.Input; cmd.Parameters["@maxlngrad"].Value = maxlngrad; cmd.Parameters.Add("@latrad", System.Data.SqlDbType.Decimal, 20); cmd.Parameters["@latrad"].Precision = 20; cmd.Parameters["@latrad"].Scale = 18; cmd.Parameters["@latrad"].Direction = System.Data.ParameterDirection.Input; cmd.Parameters["@latrad"].Value = latrad; cmd.Parameters.Add("@lngrad", System.Data.SqlDbType.Decimal, 20); cmd.Parameters["@lngrad"].Precision = 20; cmd.Parameters["@lngrad"].Scale = 18; cmd.Parameters["@lngrad"].Direction = System.Data.ParameterDirection.Input; cmd.Parameters["@lngrad"].Value = lngrad; cmd.Parameters.Add("@distance", System.Data.SqlDbType.Decimal, 10); cmd.Parameters["@distance"].Precision = 10; cmd.Parameters["@distance"].Scale = 5; cmd.Parameters["@distance"].Direction = System.Data.ParameterDirection.Input; cmd.Parameters["@distance"].Value = distance; c.Open(); // open connection using (System.Data.SqlClient.SqlDataReader r = cmd.ExecuteReader()) { if (r.HasRows) { while (r.Read()) { Geocache g = new Geocache(); g.id = Guid.Parse(r["geocacheid"].ToString()); g.anniversary = Convert.ToDateTime(r["anniversary"]); g.code = r["code"].ToString(); g.name = r["name"].ToString(); g.description = r["description"].ToString(); g.difficulty = Convert.IsDBNull(r["difficulty"]) ? 0 : (int)r["difficulty"]; g.terrain = Convert.IsDBNull(r["terrain"]) ? 0 : (int)r["terrain"]; g.size = Convert.IsDBNull(r["size"]) ? 0 : (int)r["size"]; g.status = Convert.IsDBNull(r["status"]) ? 0 : (int)r["status"]; g.type = Convert.IsDBNull(r["type"]) ? 0 : (int)r["type"]; // location g.location = new Location(); g.location.id = Guid.Parse(r["locationid"].ToString()); g.location.latitude = Convert.ToDouble(r["latitude"]); g.location.longitude = Convert.ToDouble(r["longitude"]); g.location.altitude = Convert.IsDBNull(r["altitude"]) ? 0 : (int)r["altitude"]; // user g.user = new User(); g.user.id = Guid.Parse(r["userid"].ToString()); g.user.username = r["username"].ToString(); g.user.email = r["email"].ToString(); // user role g.user.role = new Role(); g.user.role.id = Guid.Parse(r["roleid"].ToString()); g.user.role.name = r["rolename"].ToString(); // logbook g.logbook = new Logbook(); g.logbook.id = Guid.Parse(r["logbookid"].ToString()); Add(g); // add to the array } } } } } }
private Geocache BuildCache(IDataReader reader, double lat, double lon, List<string> hasChildren, List<string> hasFinal) { Trace("Building Cache.."); Geocache cache = new Geocache(); // DBVER 0 Fields cache.Name = reader.GetString(0); Trace(cache.Name); cache.Lat = double.Parse(reader.GetString(1), CultureInfo.InvariantCulture); cache.Lon = double.Parse(reader.GetString(2), CultureInfo.InvariantCulture); String url = reader.GetString(3); if (!String.IsNullOrEmpty(url)) cache.URL = new Uri(url); cache.URLName = reader.GetString(4); cache.Desc = reader.GetString(5); cache.Symbol = reader.GetString(6); cache.Type = reader.GetString(7); String time = reader.GetString(8); cache.Time = DateTime.Parse(time); cache.CacheName = reader.GetString(9); cache.CacheID = reader.GetString(10); cache.CacheOwner = reader.GetString(11); cache.OwnerID = reader.GetString(12); cache.PlacedBy = reader.GetString(13); cache.Difficulty = float.Parse(reader.GetString(14), CultureInfo.InvariantCulture); cache.Terrain = float.Parse(reader.GetString(15), CultureInfo.InvariantCulture); cache.Country = reader.GetString(16); cache.State = reader.GetString(17); cache.TypeOfCache = (Geocache.CacheType) Enum.Parse(typeof (Geocache.CacheType), reader.GetString(18)); cache.ShortDesc = reader.GetString(19); cache.LongDesc = reader.GetString(20); cache.Hint = reader.GetString(21); cache.Container = reader.GetString(22); String archived = reader.GetString(23); cache.Archived = Boolean.Parse(archived); String available = reader.GetString(24); cache.Available = Boolean.Parse(available); cache.Updated = DateTime.Parse(reader.GetString(25)); // From this point, the fields have been added in later DB Schema versions // Must check to see if they aren't DBNULL before getting the value Object val = reader.GetValue(26); if (val is string) cache.Notes = reader.GetString(26); val = reader.GetValue(27); if (val is string) cache.CheckNotes = Boolean.Parse(val as string); else cache.CheckNotes = false; val = reader.GetValue(28); if (val is string) cache.CorrectedLat = Double.Parse(val as string, CultureInfo.InvariantCulture); val = reader.GetValue(29); if (val is string) cache.CorrectedLon = Double.Parse(val as string, CultureInfo.InvariantCulture); val = reader.GetValue(30); if (val is string) cache.DNF = Boolean.Parse(val as string); val = reader.GetValue(31); if (val is string) cache.FTF = Boolean.Parse(val as string); val = reader.GetValue(32); if (val is string) cache.User1 = val as string; val = reader.GetValue(33); if (val is string) cache.User2 = val as string; val = reader.GetValue(34); if (val is string) cache.User3 = val as string; val = reader.GetValue(35); if (val is string) cache.User4 = val as string; // Preprocessed fields from other DB tables... These queries were run first for performance reason cache.Children = hasChildren.Contains(cache.Name); cache.HasFinal = hasFinal.Contains(cache.Name); // Calculated properties cache.Distance = Utilities.calculateDistance(lat, cache.Lat, lon, cache.Lon); return cache; }
private void AddGeocache(Geocache cache, bool partialUpdate) { Trace("Adding as geocache"); Trace("Partial update:" + partialUpdate.ToString()); string insert = String.Format(INSERT_GC, cache.Name, Escape(cache.CacheName), cache.CacheID, Escape(cache.CacheOwner), cache.OwnerID, Escape(cache.PlacedBy), cache.Difficulty.ToString(CultureInfo.InvariantCulture), cache.Terrain.ToString(CultureInfo.InvariantCulture), Escape(cache.Country), Escape(cache.State),cache.TypeOfCache.ToString(), Escape(cache.ShortDesc), Escape(cache.LongDesc), Escape(cache.Hint), cache.Container, cache.Archived.ToString(), cache.Available.ToString(), Escape(cache.Notes), cache.CheckNotes.ToString(), cache.CorrectedLat.ToString(CultureInfo.InvariantCulture), cache.CorrectedLon.ToString(CultureInfo.InvariantCulture), cache.DNF, cache.FTF, cache.User1, cache.User2, cache.User3, cache.User4); cache.ClearCorrectedFlag = false; string update; if (partialUpdate) { update = String.Format(ADD_EXISTING_GC, cache.Name, Escape(cache.CacheName), cache.CacheID, Escape(cache.CacheOwner), cache.OwnerID, Escape(cache.PlacedBy), cache.Difficulty.ToString(CultureInfo.InvariantCulture), cache.Terrain.ToString(CultureInfo.InvariantCulture), Escape(cache.Country), Escape(cache.State),cache.TypeOfCache.ToString(), Escape(cache.ShortDesc), Escape(cache.LongDesc), Escape(cache.Hint), cache.Container, cache.Archived.ToString(), cache.Available.ToString(), cache.CheckNotes.ToString(), cache.CorrectedLat.ToString(CultureInfo.InvariantCulture), cache.CorrectedLon.ToString(CultureInfo.InvariantCulture)); } else { update = String.Format(UPDATE_GC, cache.Name, Escape(cache.CacheName), cache.CacheID, Escape(cache.CacheOwner), cache.OwnerID, Escape(cache.PlacedBy), cache.Difficulty.ToString(CultureInfo.InvariantCulture), cache.Terrain.ToString(CultureInfo.InvariantCulture), Escape(cache.Country), Escape(cache.State),cache.TypeOfCache.ToString(), Escape(cache.ShortDesc), Escape(cache.LongDesc), Escape(cache.Hint), cache.Container, cache.Archived.ToString(), cache.Available.ToString(), Escape(cache.Notes), cache.CheckNotes.ToString(), cache.CorrectedLat.ToString(CultureInfo.InvariantCulture), cache.CorrectedLon.ToString(CultureInfo.InvariantCulture), cache.DNF, cache.FTF, cache.User1, cache.User2, cache.User3, cache.User4); } InsertOrUpdate (update, insert); }
private bool PostFilter(Geocache cache, double lat, double lon) { if (m_Advanced != null) { if (m_Advanced.Contains(FilterList.KEY_PLACEBEFORE)) if (cache.Time >= ((DateTime) m_Advanced.GetCriteria(FilterList.KEY_PLACEBEFORE))) return false; if (m_Advanced.Contains(FilterList.KEY_PLACEAFTER)) if (cache.Time <= ((DateTime) m_Advanced.GetCriteria(FilterList.KEY_PLACEAFTER))) return false; if (m_Advanced.Contains(FilterList.KEY_INFOBEFORE)) if (cache.Updated >= ((DateTime) m_Advanced.GetCriteria(FilterList.KEY_INFOBEFORE))) return false; if (m_Advanced.Contains(FilterList.KEY_INFOAFTER)) if (cache.Updated <= ((DateTime) m_Advanced.GetCriteria(FilterList.KEY_INFOAFTER))) return false; if (m_Advanced.Contains(FilterList.KEY_INFO_DAYS)) { int days = (int) m_Advanced.GetCriteria(FilterList.KEY_INFO_DAYS); DateTime dt = DateTime.Now.Subtract(new TimeSpan(days, 0,0,0)); if (cache.Updated <= dt) return false; } if (m_Advanced.Contains(FilterList.KEY_INFO_NDAYS)) { int days = (int) m_Advanced.GetCriteria(FilterList.KEY_INFO_NDAYS); DateTime dt = DateTime.Now.Subtract(new TimeSpan(days, 0,0,0)); if (cache.Updated >= dt) return false; } if (m_Advanced.Contains(FilterList.KEY_DIST)) { double filterlat = lat; double filterlon = lon; if (m_Advanced.Contains(FilterList.KEY_DIST_LAT)) lat = (double) m_Advanced.GetCriteria(FilterList.KEY_DIST_LAT); if (m_Advanced.Contains(FilterList.KEY_DIST_LON)) lon = (double) m_Advanced.GetCriteria(FilterList.KEY_DIST_LON); double limit = (double) m_Advanced.GetCriteria(FilterList.KEY_DIST); double dist = Utilities.calculateDistance(cache.Lat, filterlat, cache.Lon, filterlon); string op = m_Advanced.GetCriteria(FilterList.KEY_DIST_OP) as String; if (op == "<=") if (dist > limit) return false; if (op == ">=") if (dist < limit) return false; if (op == "==") if (dist != limit) return false; } } if (m_Global.Contains(FilterList.KEY_DIST)) { double limit = (double) m_Global.GetCriteria(FilterList.KEY_DIST); double dist = Utilities.calculateDistance(cache.Lat, lat, cache.Lon, lon); if (dist > limit) return false; } return true; }
public Geocaches(Guid userid, type type) { String sp; switch (type) { case type.favorite: sp = "blueharvest.dbo.getFavoriteGeocaches"; break; case type.found: sp = "blueharvest.dbo.getFoundGeocaches"; break; default: return; // nothing to see here! } using (System.Data.SqlClient.SqlConnection c = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager. ConnectionStrings["blueharvest-rds"].ConnectionString)) { using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sp, c)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; // input parameter(s) cmd.Parameters.Add("@userid", System.Data.SqlDbType.UniqueIdentifier); cmd.Parameters["@userid"].Direction = System.Data.ParameterDirection.Input; cmd.Parameters["@userid"].Value = userid; c.Open(); // open connection using (System.Data.SqlClient.SqlDataReader r = cmd.ExecuteReader()) { if (r.HasRows) { while (r.Read()) { Geocache g = new Geocache(); g.id = Guid.Parse(r["geocacheid"].ToString()); g.anniversary = Convert.ToDateTime(r["anniversary"]); g.code = r["code"].ToString(); g.name = r["name"].ToString(); g.description = r["description"].ToString(); g.difficulty = Convert.IsDBNull(r["difficulty"]) ? 0 : (int)r["difficulty"]; g.terrain = Convert.IsDBNull(r["terrain"]) ? 0 : (int)r["terrain"]; g.size = Convert.IsDBNull(r["size"]) ? 0 : (int)r["size"]; g.status = Convert.IsDBNull(r["status"]) ? 0 : (int)r["status"]; g.type = Convert.IsDBNull(r["type"]) ? 0 : (int)r["type"]; // location g.location = new Location(); g.location.id = Guid.Parse(r["locationid"].ToString()); g.location.latitude = Convert.ToDouble(r["latitude"]); g.location.longitude = Convert.ToDouble(r["longitude"]); g.location.altitude = Convert.IsDBNull(r["altitude"]) ? 0 : (int)r["altitude"]; // user g.user = new User(); g.user.id = Guid.Parse(r["userid"].ToString()); g.user.username = r["username"].ToString(); g.user.email = r["email"].ToString(); // user role g.user.role = new Role(); g.user.role.id = Guid.Parse(r["roleid"].ToString()); g.user.role.name = r["rolename"].ToString(); // logbook g.logbook = new Logbook(); g.logbook.id = Guid.Parse(r["logbookid"].ToString()); Add(g); // add to the array } } } } } }
public void SetSelectedCache(Geocache cache) { if (cache != null) { this.ZoomToSelectedCacheAction.Sensitive = true; this.SetSelectedCacheAsCentreAction.Sensitive = true; this.addCacheTo.Sensitive = true; if (Engine.getInstance().Store.BookmarkList != null) this.removeSelected.Sensitive = true; ViewOnlineAction.Sensitive = true; LogFindAction.Sensitive = true; printAction.Sensitive = true; if (cache.Symbol.Contains("Found")) { if (cache.FTF) { MarkFoundAction.Sensitive = true; MarkFirstToFindAction.Sensitive = false; } else { MarkFoundAction.Sensitive = false; MarkFirstToFindAction.Sensitive = true; } MarkUnfoundAction1.Sensitive = true; } else { MarkFoundAction.Sensitive = true; MarkFirstToFindAction.Sensitive = true; if (cache.DNF) { MarkUnfoundAction1.Sensitive = true; MarkDidNotFindAction.Sensitive = false; } else { MarkDidNotFindAction.Sensitive = true; MarkUnfoundAction1.Sensitive = false; } } CorrectedCoordinatesAction.Sensitive = true; MarkArchivedAction1.Sensitive = false; MarkDisabledAction1.Sensitive = false; MarkAvailableAction1.Sensitive = false; if (cache.Archived == false) MarkArchivedAction1.Sensitive = true; if (!cache.Available) MarkAvailableAction1.Sensitive = true; else MarkDisabledAction1.Sensitive = true; ModifyCacheAction.Sensitive = true; DeleteAction1.Sensitive = true; ViewSelectedCacheInQLandkarteGTAction.Sensitive = true; AddChildWaypointAction.Sensitive = true; } else { this.ZoomToSelectedCacheAction.Sensitive = false; this.SetSelectedCacheAsCentreAction.Sensitive = false; this.addCacheTo.Sensitive = false; this.removeSelected.Sensitive = false; ViewOnlineAction.Sensitive = false; LogFindAction.Sensitive = false; MarkFoundAction.Sensitive = false; MarkArchivedAction1.Sensitive = false; MarkAvailableAction1.Sensitive = false; MarkDisabledAction1.Sensitive = false; MarkUnfoundAction1.Sensitive = false; ModifyCacheAction.Sensitive = false; MarkDidNotFindAction.Sensitive = false; MarkFirstToFindAction.Sensitive = false; DeleteAction1.Sensitive = false; CorrectedCoordinatesAction.Sensitive = false; ViewSelectedCacheInQLandkarteGTAction.Sensitive = false; printAction.Sensitive = false; AddChildWaypointAction.Sensitive = false; } }
public static List<Geocache> retrieveGeocache() { //if (Membership.GetUser() != null) //{ // m = Membership.GetUser(); // // (retrieve memberId here) memberId = new int(m.ProviderUserKey.ToString()); //} List<Geocache> geocacheList = new List<Geocache>(); MySqlDataReader reader; MySqlConnection con = new MySqlConnection(connectionString); con.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = con; //if keyword if not null, search user table for match, return iduser[] int[] iduser = { 1, 2, 3 }; cmd.CommandText = "SELECT geocacheId, geocacheName, geocacheDateCreated FROM geocache"; cmd.Prepare(); reader = cmd.ExecuteReader(); while (reader.Read()) { Geocache g = new Geocache(); g.geocacheId = Guid.Parse(reader.GetString(0)); g.geocacheName = reader.GetString(1); g.geocacheDateCreated = reader.GetDateTime(2); geocacheList.Add(g); } return geocacheList; }
public static Geocache retrieveGeocache(string geocacheId) { //if (Membership.GetUser() != null) //{ // m = Membership.GetUser(); // // (retrieve memberId here) memberId = new int(m.ProviderUserKey.ToString()); //} Geocache g = new Geocache(); g.geocacheId = Guid.Parse(geocacheId); MySqlDataReader reader; MySqlConnection con = new MySqlConnection(connectionString); con.Open(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = con; cmd.CommandText = "SELECT geocache.geocacheName, geocache.geocacheDescription, geocache.geocacheDifficulty, geocache.geocacheLatitude, geocache.geocacheLongitude, geocache.geocacheImage, geocache.geocacheDateCreated, geocache.geocacheVerificationID, geocache.iduser FROM geocache WHERE geocacheId=@geocacheId"; cmd.Prepare(); cmd.Parameters.AddWithValue("@geocacheId", geocacheId); reader = cmd.ExecuteReader(); while (reader.Read()) { g.geocacheName = reader.GetString(0); g.geocacheDescription = reader.GetString(1); g.geocacheDifficulty = reader.GetInt32(2); g.geocacheLatitude = reader.GetString(3); g.geocacheLongitude = reader.GetString(4); g.geocacheImage = reader.GetString(5); g.geocacheDateCreated = reader.GetDateTime(6); g.geocacheVerificationId = reader.GetString(7); g.iduser = reader.GetInt32(8); } return g; }
public bool? InsertGeocache(Geocache g) { if (sc != null && sc.isValid()) { return Geocache.Insert(g); } else { return null; } }