private IEnumerator<object> RefreshList(PriorityEntry newSelection)
        {
            PriorityEntry[] oldSelectedEntries;
            if (newSelection != null)
                oldSelectedEntries = new PriorityEntry[] { newSelection };
            else
                oldSelectedEntries = SelectedEntries.ToArray();

            using (new ControlWaitCursor(this)) {
                List.BeginUpdate();

                List.Items.Clear();
                List.Groups.Clear();

                int[] priorities = null;
                yield return Program.Database.ExecutePrimitiveArray<int>(
                    "SELECT DISTINCT priority FROM enemyPriorities ORDER BY priority DESC"
                ).Bind(() => priorities);

                var priorityGroups = new Dictionary<int, ListViewGroup>();

                foreach (int priority in priorities) {
                    if (priorityGroups.ContainsKey(priority))
                        continue;
                    else if (priority <= 0)
                        continue;

                    List.Groups.Add(priorityGroups[priority] = new ListViewGroup(
                        String.Format("priority:{0}", priority),
                        String.Format("Priority +{0}", priority)
                    ));
                }

                List.Groups.Add(priorityGroups[0] = new ListViewGroup(
                    "priority:0", "Default Priority"
                ));
                List.Groups.Add(priorityGroups[-1] = new ListViewGroup(
                    "priority:-1", "Never Attack"
                ));

                PriorityEntry[] entries = null;
                yield return Program.Database.ExecuteArray<PriorityEntry>(
                    "SELECT ep.groupID, ep.typeID, ep.priority, g.name AS groupName, t.name AS typeName " +
                    "FROM enemyPriorities ep " +
                    "LEFT OUTER JOIN evedata.groups g ON ep.groupID = g.groupID " +
                    "LEFT OUTER JOIN evedata.types t ON ep.typeID = t.typeID"
                ).Bind(() => entries);

                foreach (var entry in entries) {
                    var item = new ListViewItem(
                        entry.TypeName ?? entry.GroupName,
                        (entry.TypeName != null) ? "type" : "group",
                        priorityGroups[Math.Max(entry.Priority, -1)]
                    );
                    item.Tag = entry;

                    List.Items.Add(item);

                    foreach (var oldEntry in oldSelectedEntries) {
                        if ((oldEntry.TypeID == entry.TypeID) && (oldEntry.GroupID == entry.GroupID)) {
                            item.Selected = true;
                            break;
                        }
                    }
                }

                foreach (var group in priorityGroups.Values) {
                    if (group.Items.Count != 0)
                        continue;

                    var nullItem = new ListViewItem(
                        "", group
                    );
                    nullItem.Tag = null;
                    List.Items.Add(nullItem);
                }

                List.EndUpdate();

                if (List.SelectedIndices.Count > 0) {
                    List.EnsureVisible(List.SelectedIndices[List.SelectedIndices.Count - 1]);
                    List.EnsureVisible(List.SelectedIndices[0]);
                }
            }
        }
        private IEnumerator<object> RemoveItemsTask(PriorityEntry[] items)
        {
            using (new ControlWaitCursor(this))
            using (var xact = Program.Database.CreateTransaction()) {
                yield return xact;

                object[] args;

                foreach (var item in items) {
                    string sql = "DELETE FROM enemyPriorities WHERE ";
                    if (item.TypeID.HasValue) {
                        sql += "typeID = ? AND groupID = ?";
                        args = new object[] { item.TypeID.Value, item.GroupID.Value };
                    } else {
                        sql += "groupID = ? AND typeID IS NULL";
                        args = new object[] { item.GroupID.Value };
                    }

                    yield return Program.Database.ExecuteSQL(sql, args);
                }

                yield return xact.Commit();
            }

            Script.Preferences.Flush();

            yield return LoadConfiguration();
        }
示例#3
0
        private IEnumerator <object> RefreshList(PriorityEntry newSelection)
        {
            PriorityEntry[] oldSelectedEntries;
            if (newSelection != null)
            {
                oldSelectedEntries = new PriorityEntry[] { newSelection }
            }
            ;
            else
            {
                oldSelectedEntries = SelectedEntries.ToArray();
            }

            using (new ControlWaitCursor(this)) {
                List.BeginUpdate();

                List.Items.Clear();
                List.Groups.Clear();

                int[] priorities = null;
                yield return(Program.Database.ExecutePrimitiveArray <int>(
                                 "SELECT DISTINCT priority FROM enemyPriorities ORDER BY priority DESC"
                                 ).Bind(() => priorities));

                var priorityGroups = new Dictionary <int, ListViewGroup>();

                foreach (int priority in priorities)
                {
                    if (priorityGroups.ContainsKey(priority))
                    {
                        continue;
                    }
                    else if (priority <= 0)
                    {
                        continue;
                    }

                    List.Groups.Add(priorityGroups[priority] = new ListViewGroup(
                                        String.Format("priority:{0}", priority),
                                        String.Format("Priority +{0}", priority)
                                        ));
                }

                List.Groups.Add(priorityGroups[0] = new ListViewGroup(
                                    "priority:0", "Default Priority"
                                    ));
                List.Groups.Add(priorityGroups[-1] = new ListViewGroup(
                                    "priority:-1", "Never Attack"
                                    ));

                PriorityEntry[] entries = null;
                yield return(Program.Database.ExecuteArray <PriorityEntry>(
                                 "SELECT ep.groupID, ep.typeID, ep.priority, g.name AS groupName, t.name AS typeName " +
                                 "FROM enemyPriorities ep " +
                                 "LEFT OUTER JOIN evedata.groups g ON ep.groupID = g.groupID " +
                                 "LEFT OUTER JOIN evedata.types t ON ep.typeID = t.typeID"
                                 ).Bind(() => entries));

                foreach (var entry in entries)
                {
                    var item = new ListViewItem(
                        entry.TypeName ?? entry.GroupName,
                        (entry.TypeName != null) ? "type" : "group",
                        priorityGroups[Math.Max(entry.Priority, -1)]
                        );
                    item.Tag = entry;

                    List.Items.Add(item);

                    foreach (var oldEntry in oldSelectedEntries)
                    {
                        if ((oldEntry.TypeID == entry.TypeID) && (oldEntry.GroupID == entry.GroupID))
                        {
                            item.Selected = true;
                            break;
                        }
                    }
                }

                foreach (var group in priorityGroups.Values)
                {
                    if (group.Items.Count != 0)
                    {
                        continue;
                    }

                    var nullItem = new ListViewItem(
                        "", group
                        );
                    nullItem.Tag = null;
                    List.Items.Add(nullItem);
                }

                List.EndUpdate();

                if (List.SelectedIndices.Count > 0)
                {
                    List.EnsureVisible(List.SelectedIndices[List.SelectedIndices.Count - 1]);
                    List.EnsureVisible(List.SelectedIndices[0]);
                }
            }
        }