private async Task <bool> addGeocachesToDatabase(List <ListViewItem> lvis) { bool result = false; _geocacheCodes = new List <string>(); foreach (ListViewItem lvi in lvis) { if (!(lvi.Tag as GeocacheVisitsItem).InDatabase) { _geocacheCodes.Add((lvi.Tag as GeocacheVisitsItem).Code); } } if (_geocacheCodes.Count > 0) { this.ControlBox = false; this.groupBox1.Enabled = false; this.groupBox2.Enabled = false; this.panel1.Enabled = false; using (Utils.FrameworkDataUpdater upd = new Utils.FrameworkDataUpdater(_core)) { await Task.Run(() => { this.getGeocachesThreadMethod(); }); } if (!string.IsNullOrEmpty(_errormessage)) { System.Windows.Forms.MessageBox.Show(_errormessage, Utils.LanguageSupport.Instance.GetTranslation(Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } else { result = true; } foreach (ListViewItem lvi in lvis) { GeocacheVisitsItem vi = lvi.Tag as GeocacheVisitsItem; if (!vi.InDatabase) { vi.InDatabase = Utils.DataAccess.GetGeocache(_core.Geocaches, vi.Code) != null; if (vi.InDatabase) { lvi.SubItems[0].Text = Utils.LanguageSupport.Instance.GetTranslation(STR_YES); } } } listView1_SelectedIndexChanged(this, null); button3.Enabled = (from a in _geocacheVisitsItems where !a.InDatabase select a).Count() > 0; button5.Enabled = (from a in _geocacheVisitsItems where a.InDatabase select a).Count() > 0; this.ControlBox = true; this.groupBox1.Enabled = true; this.groupBox2.Enabled = true; this.panel1.Enabled = true; } else { result = true; } return(result); }
private void processGeocacheVisitsFile(string[] lines) { listView1.Items.Clear(); _geocacheVisitsItems.Clear(); button3.Enabled = false; button5.Enabled = false; try { foreach (string s in lines) { string[] parts = s.Replace("\0", "").Split(new char[] { ',' }, 4); if (parts.Length == 4) { GeocacheVisitsItem vi = new GeocacheVisitsItem(); vi.Code = parts[0]; vi.LogDate = DateTime.Parse(parts[1]).ToLocalTime(); vi.LogType = Utils.DataAccess.GetLogType(_core.LogTypes, parts[2]); vi.Comment = parts[3].Replace("\"", ""); vi.InDatabase = Utils.DataAccess.GetGeocache(_core.Geocaches, vi.Code) != null; if (vi.Code.IndexOf("GC") > 0) { vi.Code = vi.Code.Substring(vi.Code.IndexOf("GC")); } _geocacheVisitsItems.Add(vi); } } } catch { } if (_geocacheVisitsItems.Count > 0) { _geocacheVisitsItems.Sort(delegate(GeocacheVisitsItem t1, GeocacheVisitsItem t2) { return(t1.LogDate.CompareTo(t2.LogDate)); } ); foreach (GeocacheVisitsItem vi in _geocacheVisitsItems) { ListViewItem lvi = new ListViewItem(new string[] { vi.InDatabase?Utils.LanguageSupport.Instance.GetTranslation(STR_YES) : Utils.LanguageSupport.Instance.GetTranslation(STR_NO), vi.Code, vi.LogDate.ToString("d"), Utils.LanguageSupport.Instance.GetTranslation(vi.LogType.Name), vi.Comment }); lvi.Tag = vi; listView1.Items.Add(lvi); } } button3.Enabled = (from a in _geocacheVisitsItems where !a.InDatabase select a).Count() > 0; button5.Enabled = (from a in _geocacheVisitsItems where a.InDatabase select a).Count() > 0; }
private void processGeocacheVisitsFile(string[] lines) { listView1.Items.Clear(); _geocacheVisitsItems.Clear(); button3.Enabled = false; button5.Enabled = false; try { int i = 0; while (i < lines.Length) { string s = lines[i]; string[] parts = s.Replace("\0", "").Split(new char[] { ',' }, 4); if (parts.Length == 4) { DateTime dt; if (parts[0].StartsWith("GC") && DateTime.TryParse(parts[1], out dt)) { GeocacheVisitsItem vi = new GeocacheVisitsItem(); vi.Code = parts[0]; vi.LogDate = dt.ToLocalTime(); vi.LogType = Utils.DataAccess.GetLogType(_core.LogTypes, parts[2]); vi.InDatabase = Utils.DataAccess.GetGeocache(_core.Geocaches, vi.Code) != null; StringBuilder sb = new StringBuilder(); sb.AppendLine(parts[3].Replace("\"", "")); //read till next i++; while (i < lines.Length) { s = lines[i]; parts = s.Replace("\0", "").Split(new char[] { ',' }, 4); if (parts.Length == 4) { if (parts[0].StartsWith("GC") && DateTime.TryParse(parts[1], out dt)) { break; } else { sb.AppendLine(s.Trim().Replace("\"", "")); i++; } } else { sb.AppendLine(s.Trim().Replace("\"", "")); i++; } } vi.Comment = sb.ToString(); ListViewItem lvi = new ListViewItem(new string[] { vi.InDatabase?Utils.LanguageSupport.Instance.GetTranslation(STR_YES) : Utils.LanguageSupport.Instance.GetTranslation(STR_NO), vi.Code, vi.LogDate.ToString("d"), Utils.LanguageSupport.Instance.GetTranslation(vi.LogType.Name), vi.Comment }); lvi.Tag = vi; _geocacheVisitsItems.Add(vi); listView1.Items.Add(lvi); } else { i++; } } else { i++; } } } catch { } button3.Enabled = (from a in _geocacheVisitsItems where !a.InDatabase select a).Count() > 0; button5.Enabled = (from a in _geocacheVisitsItems where a.InDatabase select a).Count() > 0; }
private void processGeocacheVisitsFile(string[] lines) { listView1.Items.Clear(); _geocacheVisitsItems.Clear(); button3.Enabled = false; button5.Enabled = false; try { foreach (string s in lines) { string[] parts = s.Replace("\0","").Split(new char[] { ',' }, 4); if (parts.Length == 4) { GeocacheVisitsItem vi = new GeocacheVisitsItem(); vi.Code = parts[0]; vi.LogDate = DateTime.Parse(parts[1]).ToLocalTime(); vi.LogType = Utils.DataAccess.GetLogType(_core.LogTypes, parts[2]); vi.Comment = parts[3].Replace("\"", ""); vi.InDatabase = Utils.DataAccess.GetGeocache(_core.Geocaches, vi.Code)!=null; if (vi.Code.IndexOf("GC") > 0) { vi.Code = vi.Code.Substring(vi.Code.IndexOf("GC")); } _geocacheVisitsItems.Add(vi); } } } catch { } if (_geocacheVisitsItems.Count > 0) { _geocacheVisitsItems.Sort(delegate(GeocacheVisitsItem t1, GeocacheVisitsItem t2) { return (t1.LogDate.CompareTo(t2.LogDate)); } ); foreach (GeocacheVisitsItem vi in _geocacheVisitsItems) { ListViewItem lvi = new ListViewItem(new string[] { vi.InDatabase?Utils.LanguageSupport.Instance.GetTranslation(STR_YES):Utils.LanguageSupport.Instance.GetTranslation(STR_NO), vi.Code, vi.LogDate.ToString("d"), Utils.LanguageSupport.Instance.GetTranslation(vi.LogType.Name), vi.Comment }); lvi.Tag = vi; listView1.Items.Add(lvi); } } button3.Enabled = (from a in _geocacheVisitsItems where !a.InDatabase select a).Count() > 0; button5.Enabled = (from a in _geocacheVisitsItems where a.InDatabase select a).Count() > 0; }
private void processGeocacheVisitsFile(string[] lines) { listView1.Items.Clear(); _geocacheVisitsItems.Clear(); button3.Enabled = false; button5.Enabled = false; try { int i = 0; while (i<lines.Length) { string s = lines[i]; string[] parts = s.Replace("\0", "").Split(new char[] { ',' }, 4); if (parts.Length == 4) { DateTime dt; if (parts[0].StartsWith("GC") && DateTime.TryParse(parts[1], out dt)) { GeocacheVisitsItem vi = new GeocacheVisitsItem(); vi.Code = parts[0]; vi.LogDate = dt.ToLocalTime(); vi.LogType = Utils.DataAccess.GetLogType(_core.LogTypes, parts[2]); vi.InDatabase = Utils.DataAccess.GetGeocache(_core.Geocaches, vi.Code) != null; StringBuilder sb = new StringBuilder(); sb.AppendLine(parts[3].Replace("\"", "")); //read till next i++; while (i < lines.Length) { s = lines[i]; parts = s.Replace("\0", "").Split(new char[] { ',' }, 4); if (parts.Length == 4) { if (parts[0].StartsWith("GC") && DateTime.TryParse(parts[1], out dt)) { break; } else { sb.AppendLine(s.Trim().Replace("\"", "")); i++; } } else { sb.AppendLine(s.Trim().Replace("\"", "")); i++; } } vi.Comment = sb.ToString(); ListViewItem lvi = new ListViewItem(new string[] { vi.InDatabase?Utils.LanguageSupport.Instance.GetTranslation(STR_YES):Utils.LanguageSupport.Instance.GetTranslation(STR_NO), vi.Code, vi.LogDate.ToString("d"), Utils.LanguageSupport.Instance.GetTranslation(vi.LogType.Name), vi.Comment }); lvi.Tag = vi; _geocacheVisitsItems.Add(vi); listView1.Items.Add(lvi); } else { i++; } } else { i++; } } } catch { } button3.Enabled = (from a in _geocacheVisitsItems where !a.InDatabase select a).Count() > 0; button5.Enabled = (from a in _geocacheVisitsItems where a.InDatabase select a).Count() > 0; }