示例#1
0
        private void comboBoxGroup_SelectedValueChanged(object sender, EventArgs e)
        {
            TrackableGroup tg = comboBoxGroup.SelectedItem as TrackableGroup;
            _activeTrackableGroup = tg;
            listView1.Items.Clear();
            if (tg == null)
            {
                buttonGroupDelete.Enabled = false;
                buttonGroupRename.Enabled = false;
                buttonAddYouOwn.Enabled = false;
                buttonAddTrackables.Enabled = false;
                textBoxTBCodes.Enabled = false;
                showAllOnMapToolStripMenuItem.Enabled = false;
                updateAllTrackablesInGroupToolStripMenuItem.Enabled = false;
                textBoxGroupName.Text = "";
            }
            else
            {
                buttonGroupDelete.Enabled = true;
                buttonGroupRename.Enabled = true;
                buttonAddYouOwn.Enabled = true;
                textBoxTBCodes.Enabled = true;
                updateAllTrackablesInGroupToolStripMenuItem.Enabled = true;
                showAllOnMapToolStripMenuItem.Enabled = true;
                textBoxGroupName.Text = tg.Name;
                textBoxTBCodes_TextChanged(sender, e);

                listView1.BeginUpdate();
                try
                {
                    DbDataReader dr = _dbcon.ExecuteReader(string.Format("select * from trackables where groupid={0}", tg.ID));
                    while (dr.Read())
                    {
                        TrackableItem trk = new TrackableItem();
                        trk.Code = (string)dr["Code"];
                        if (dr["AllowedToBeCollected"] != null && dr["AllowedToBeCollected"].GetType() != typeof(DBNull))
                        {
                            trk.AllowedToBeCollected = (int)dr["AllowedToBeCollected"]!=0;
                        }
                        else
                        {
                            trk.AllowedToBeCollected = null;
                        }
                        trk.Archived = (int)dr["Archived"] != 0;
                        trk.BugTypeID = (int)dr["BugTypeID"];
                        trk.CurrentGeocacheCode = (string)dr["CurrentGeocacheCode"];
                        trk.CurrentGoal = (string)dr["CurrentGoal"];
                        trk.DateCreated = DateTime.Parse((string)dr["DateCreated"]);
                        trk.Description = (string)dr["Description"];
                        trk.IconUrl = (string)dr["IconUrl"];
                        trk.Id = (int)dr["Id"];
                        trk.InCollection = (int)dr["InCollection"] != 0;
                        trk.Name = (string)dr["Name"];
                        trk.TBTypeName = (string)dr["TBTypeName"];
                        trk.Url = (string)dr["Url"];
                        trk.WptTypeID = (int)dr["WptTypeID"];
                        trk.Owner = (string)dr["Owner"];

                        if (dr["HopCount"] != null && dr["HopCount"].GetType() != typeof(DBNull))
                        {
                            trk.HopCount = (int)dr["HopCount"];
                        }
                        else
                        {
                            trk.HopCount = 0;
                        }
                        if (dr["DiscoverCount"] != null && dr["DiscoverCount"].GetType() != typeof(DBNull))
                        {
                            trk.DiscoverCount = (int)dr["DiscoverCount"];
                        }
                        else
                        {
                            trk.DiscoverCount = 0;
                        }
                        if (dr["InCacheCount"] != null && dr["InCacheCount"].GetType() != typeof(DBNull))
                        {
                            trk.InCacheCount = (int)dr["InCacheCount"];
                        }
                        else
                        {
                            trk.InCacheCount = 0;
                        }
                        if (dr["DistanceKm"] != null && dr["DistanceKm"].GetType() != typeof(DBNull))
                        {
                            trk.DistanceKm = (double)dr["DistanceKm"];
                        }
                        else
                        {
                            trk.DistanceKm = 0.0;
                        }
                        if (dr["Lat"] != null && dr["Lat"].GetType() != typeof(DBNull))
                        {
                            trk.Lat = (double)dr["Lat"];
                        }
                        else
                        {
                            trk.Lat = null;
                        }
                        if (dr["Lon"] != null && dr["Lon"].GetType() != typeof(DBNull))
                        {
                            trk.Lon = (double)dr["Lon"];
                        }
                        else
                        {
                            trk.Lon = null;
                        }

                        ListViewItem lv = new ListViewItem(new string[] { trk.IconUrl, trk.Code, trk.Name, trk.Owner, trk.CurrentGeocacheCode, trk.HopCount.ToString().PadLeft(5), trk.InCacheCount.ToString().PadLeft(5), trk.DiscoverCount.ToString().PadLeft(5), trk.DistanceKm.ToString("0.0").PadLeft(9) }, trk.IconUrl);
                        lv.Tag = trk;
                        listView1.Items.Add(lv);
                    }
                }
                catch
                {
                }
                listView1.EndUpdate();
            }
        }
示例#2
0
        private void buttonGroupCreate_Click(object sender, EventArgs e)
        {
            try
            {
                string s = textBoxGroupName.Text.Trim();
                if (!string.IsNullOrEmpty(s))
                {
                    if ((long)_dbcon.ExecuteScalar(string.Format("select count(1) from groups where name='{0}'", s.Replace("'", "''"))) == 0)
                    {
                        int maxId = 1;
                        if (_trackableGroups.Count > 0)
                        {
                            _trackableGroups.Max(x => x.ID);
                            maxId++;
                        }
                        TrackableGroup tg = new TrackableGroup();
                        tg.ID = maxId;
                        tg.Name = s;

                        _dbcon.ExecuteNonQuery(string.Format("insert into groups (id, name) values ({0}, '{1}')",tg.ID,tg.Name.Replace("'","''")));
                        _trackableGroups.Add(tg);
                        comboBoxGroup.Items.Add(tg);
                        comboBoxGroup.SelectedItem = tg;
                        textBoxGroupName_TextChanged(this, EventArgs.Empty);
                    }
                }
            }
            catch
            {
            }
        }
示例#3
0
        private void TrackableGroupsForm_Shown(object sender, EventArgs e)
        {
            PluginSettings.Instance.DatabaseFileName = System.IO.Path.Combine(Core.PluginDataPath, "TrkGroup.db3" );

            try
            {
                _dbcon = new Utils.DBConComSqlite(PluginSettings.Instance.DatabaseFileName);
                initDatabase(_dbcon);
                DbDataReader dr = _dbcon.ExecuteReader("select * from groups");
                while (dr.Read())
                {
                    TrackableGroup tg = new TrackableGroup();
                    tg.ID = (int)dr["id"];
                    tg.Name = (string)dr["name"];
                    _trackableGroups.Add(tg);
                }
                initImageList();
                comboBoxGroup.Items.AddRange(_trackableGroups.ToArray());
            }
            catch
            {
                _dbcon = null;
            }

            comboBoxGroup_SelectedValueChanged(this, EventArgs.Empty);
            SelectedLanguageChanged(this, EventArgs.Empty);
        }