Exemplo n.º 1
0
        private IEnumerator <object> AddGroupTask()
        {
            using (new ControlWaitCursor(this))
                using (var dialog = new AddGroupDialog()) {
                    long categoryID = 0;
                    yield return(Program.Database.ExecuteScalar <long>(
                                     "SELECT categoryID FROM evedata.categories WHERE name = ?",
                                     "Entity"
                                     ).Bind(() => categoryID));

                    int groupID = (from se in SelectedEntries
                                   where se.GroupID.HasValue
                                   select se.GroupID.Value).FirstOrDefault();

                    yield return(dialog.PopulateList(categoryID, groupID));

                    if (dialog.ShowDialog() != DialogResult.OK)
                    {
                        yield break;
                    }

                    var newGroup = dialog.Group.SelectedItem as GroupEntry;

                    int priority = 0;
                    if (SelectedEntries.Count() > 0)
                    {
                        priority = SelectedEntries.Max((pe) => pe.Priority);
                    }

                    using (var xact = Program.Database.CreateTransaction()) {
                        yield return(xact);

                        yield return(Program.Database.ExecuteSQL(
                                         "DELETE FROM enemyPriorities WHERE groupID = ? and typeID IS NULL",
                                         newGroup.ID
                                         ));

                        yield return(Program.Database.ExecuteSQL(
                                         "REPLACE INTO enemyPriorities (groupID, priority) VALUES (?, ?)",
                                         newGroup.ID, priority
                                         ));

                        yield return(xact.Commit());
                    }

                    Program.EventBus.Broadcast(Script, "PreferenceChanged", "*");

                    yield return(RefreshList(new PriorityEntry {
                        GroupID = newGroup.ID
                    }));
                }
        }
        private IEnumerator<object> AddGroupTask()
        {
            using (new ControlWaitCursor(this))
            using (var dialog = new AddGroupDialog()) {
                long categoryID = 0;
                yield return Program.Database.ExecuteScalar<long>(
                    "SELECT categoryID FROM evedata.categories WHERE name = ?",
                    "Entity"
                ).Bind(() => categoryID);

                int groupID = (from se in SelectedEntries
                               where se.GroupID.HasValue
                               select se.GroupID.Value).FirstOrDefault();

                yield return dialog.PopulateList(categoryID, groupID);

                if (dialog.ShowDialog() != DialogResult.OK)
                    yield break;

                var newGroup = dialog.Group.SelectedItem as GroupEntry;

                int priority = 0;
                if (SelectedEntries.Count() > 0)
                    priority = SelectedEntries.Max((pe) => pe.Priority);

                using (var xact = Program.Database.CreateTransaction()) {
                    yield return xact;

                    yield return Program.Database.ExecuteSQL(
                        "DELETE FROM enemyPriorities WHERE groupID = ? and typeID IS NULL",
                        newGroup.ID
                    );

                    yield return Program.Database.ExecuteSQL(
                        "REPLACE INTO enemyPriorities (groupID, priority) VALUES (?, ?)",
                        newGroup.ID, priority
                    );

                    yield return xact.Commit();
                }

                Program.EventBus.Broadcast(Script, "PreferenceChanged", "*");

                yield return RefreshList(new PriorityEntry { GroupID = newGroup.ID });
            }
        }