private void DeleteSublistEntryInternal(ISublistEntry entry, SQLiteTransaction transaction)
        {
            const string deleteMainSql     = @"DELETE FROM Entry WHERE Id = @id";
            const string deleteRelationSql = @"DELETE FROM EntryRelation WHERE ChildId = @id OR ParentId = @id";

            using (var statement = transaction.Prepare(deleteRelationSql))
            {
                statement.Binding("@id", entry.Id);
                transaction.Execute(statement);
            }
            using (var statement = transaction.Prepare(deleteMainSql))
            {
                statement.Binding("@id", entry.Id);
                transaction.Execute(statement);
            }

            foreach (var sublistEntry in entry.SubEntries)
            {
                using (var statement = transaction.Prepare(deleteRelationSql))
                {
                    statement.Binding("@id", sublistEntry.Id);
                    transaction.Execute(statement);
                }
                using (var statement = transaction.Prepare(deleteMainSql))
                {
                    statement.Binding("@id", sublistEntry.Id);
                    transaction.Execute(statement);
                }

                DeleteSublistEntryInternal(sublistEntry, transaction);
            }
        }
Example #2
0
        public void UnindentItem(ISublistEntry entry)
        {
            var currentParent = _entryProvider.GetParent(entry, AllEntries);

            if (currentParent != null)
            {
                var parentOfParent = _entryProvider.GetParent(currentParent, AllEntries);
                if (parentOfParent != null)
                {
                    entry.ParentId = parentOfParent.Id;
                    parentOfParent.AddSubEntrySafely(entry);
                    currentParent.SubEntries.Remove(entry);
                    _entryProvider.ChangeEntry(entry);
                }
                else
                {
                    entry.ParentId = 0;
                    _entryProvider.ChangeEntry(entry);
                    currentParent.SubEntries.Remove(entry);
                    AllEntries.Add(entry);
                }

                RefreshAllEntries();
            }
        }
 public void DeleteSublistEntry(ISublistEntry entry)
 {
     using (var transaction = new SQLiteTransaction(SharedConnection))
     {
         DeleteSublistEntryInternal(entry, transaction);
         transaction.Commit();
     }
 }
 public void DeleteSublistEntry(ISublistEntry entry)
 {
     using (var transaction = new SQLiteTransaction(SharedConnection))
     {
         DeleteSublistEntryInternal(entry, transaction);
         transaction.Commit();
     }
 }
Example #5
0
 public void AddSubEntrySafely(ISublistEntry entry)
 {
     if (this == entry)
     {
         return;
     }
     foreach (var subEntryInNewEntry in entry.SubEntries)
     {
         AddSubEntrySafely(subEntryInNewEntry);
     }
     entry.ParentId = this.Id;
     SubEntries.Add(entry);
 }
Example #6
0
        public void CreateEntry(ISublistEntry parent)
        {
            var newEntry = new SublistEntry();

            if (parent != null)
            {
                parent.AddSubEntrySafely(newEntry);
            }
            else
            {
                AllEntries.Add(newEntry);
            }

            _entryProvider.StoreNewEntry(newEntry);

            RefreshAllEntries();
        }
Example #7
0
        public void CreateEntry(ISublistEntry parent)
        {
            var newEntry = new SublistEntry();

            if (parent != null)
            {
                parent.AddSubEntrySafely(newEntry);
            }
            else
            {
                AllEntries.Add(newEntry);
            }

            _entryProvider.StoreNewEntry(newEntry);

            RefreshAllEntries();
        }
        public void UpdateSublistEntry(ISublistEntry entry)
        {
            const string updateMainSql = @"UPDATE Entry " +
                                         "SET Title = @title, Completed = @completed " +
                                         "WHERE Id = @id";

            const string updateRelationsSql = @"INSERT OR REPLACE INTO EntryRelation " +
                                              "(ParentId, ChildId) " +
                                              "VALUES (@parentId, @id)";

            const string deleteRelationsSql = @"DELETE FROM EntryRelation " +
                                              "WHERE ChildId = @id";

            using (var transaction = new SQLiteTransaction(SharedConnection))
            {
                using (var statement = transaction.Prepare(updateMainSql))
                {
                    statement.Binding("@title", entry.Title);
                    statement.Binding("@completed", entry.Completed);
                    statement.Binding("@id", entry.Id);
                    transaction.Execute(statement);
                }

                if (entry.ParentId.HasValue && entry.ParentId.Value == 0)
                {
                    using (var statement = transaction.Prepare(deleteRelationsSql))
                    {
                        statement.Binding("@id", entry.Id);
                        transaction.Execute(statement);
                    }
                }
                else if (entry.ParentId.HasValue && entry.ParentId.Value != 0)
                {
                    using (var statement = transaction.Prepare(updateRelationsSql))
                    {
                        statement.Binding("@parentId", entry.ParentId);
                        statement.Binding("@id", entry.Id);
                        transaction.Execute(statement);
                    }
                }

                transaction.Commit();
            }
        }
Example #9
0
        public void IndentItem(ISublistEntry entry, ISublistEntry newParent)
        {
            if (newParent != null)
            {
                var oldParent = _entryProvider.GetParent(entry, AllEntries);
                if (oldParent != null && oldParent.SubEntries.First() == entry)
                {
                    return;
                }

                entry.ParentId = newParent.Id;
                newParent.AddSubEntrySafely(entry);
                oldParent?.SubEntries.Remove(entry);
                AllEntries.Remove(entry);
                _entryProvider.ChangeEntry(entry);

                RefreshAllEntries();
            }
        }
        public long AddSublistEntry(ISublistEntry entry)
        {
            const string mainSql = @"INSERT INTO Entry " +
                                   "(Title, Completed, CreatedAtUtc) " +
                                   "VALUES " +
                                   "(@title, @completed, @createdAtUtc)";

            const string relationSql = @"INSERT INTO EntryRelation " +
                                       "(ParentId, ChildId) " +
                                       "VALUES " +
                                       "(@parentId, @childId)";

            using (var transaction = new SQLiteTransaction(SharedConnection))
            {
                using (var statement = transaction.Prepare(mainSql))
                {
                    statement.Binding("@title", entry.Title);
                    statement.Binding("@completed", entry.Completed);
                    statement.Binding("@createdAtUtc", entry.CreatedAtUtc);
                    transaction.Execute(statement);
                }
                entry.Id = transaction.LastInsertRowId();

                if (entry.ParentId.HasValue)
                {
                    using (var statement = transaction.Prepare(relationSql))
                    {
                        statement.Binding("@parentId", entry.ParentId.Value);
                        statement.Binding("@childId", entry.Id);
                        transaction.Execute(statement);
                    }
                }

                transaction.Commit();
            }

            return entry.Id;
        }
        public long AddSublistEntry(ISublistEntry entry)
        {
            const string mainSql = @"INSERT INTO Entry " +
                                   "(Title, Completed, CreatedAtUtc) " +
                                   "VALUES " +
                                   "(@title, @completed, @createdAtUtc)";

            const string relationSql = @"INSERT INTO EntryRelation " +
                                       "(ParentId, ChildId) " +
                                       "VALUES " +
                                       "(@parentId, @childId)";

            using (var transaction = new SQLiteTransaction(SharedConnection))
            {
                using (var statement = transaction.Prepare(mainSql))
                {
                    statement.Binding("@title", entry.Title);
                    statement.Binding("@completed", entry.Completed);
                    statement.Binding("@createdAtUtc", entry.CreatedAtUtc);
                    transaction.Execute(statement);
                }
                entry.Id = transaction.LastInsertRowId();

                if (entry.ParentId.HasValue)
                {
                    using (var statement = transaction.Prepare(relationSql))
                    {
                        statement.Binding("@parentId", entry.ParentId.Value);
                        statement.Binding("@childId", entry.Id);
                        transaction.Execute(statement);
                    }
                }

                transaction.Commit();
            }

            return(entry.Id);
        }
Example #12
0
        public ISublistEntry GetParent(ISublistEntry entry, IList <ISublistEntry> tree)
        {
            if (!entry.ParentId.HasValue)
            {
                return(null);
            }

            foreach (var item in tree)
            {
                if (item.Id == entry.ParentId.Value)
                {
                    return(item);
                }

                var parent = GetParent(entry, item.SubEntries);
                if (parent != null)
                {
                    return(parent);
                }
            }

            return(null);
        }
Example #13
0
        public ISublistEntry GetParent(ISublistEntry entry, IList<ISublistEntry> tree)
        {
            if (!entry.ParentId.HasValue)
            {
                return null;
            }

            foreach (var item in tree)
            {
                if (item.Id == entry.ParentId.Value)
                {
                    return item;
                }

                var parent = GetParent(entry, item.SubEntries);
                if (parent != null)
                {
                    return parent;
                }
            }

            return null;
        }
Example #14
0
 public void DeleteEntry(ISublistEntry entry)
 {
     _dataProvider.DeleteSublistEntry(entry);
 }
Example #15
0
 public ISublistEntry StoreNewEntry(ISublistEntry entry)
 {
     entry.Id = _dataProvider.AddSublistEntry(entry);
     return entry;
 }
Example #16
0
 private void HierarchicListView_OnSublistEntryUpdated(object sender, ISublistEntry e)
 {
     _viewModel?.UpdateEntry(e);
 }
Example #17
0
 public void UpdateEntry(ISublistEntry entry)
 {
     entry.IsVisible = _showCompleted || !entry.Completed;
     _entryProvider.ChangeEntry(entry);
 }
Example #18
0
 private void SubItemsListView_OnSublistEntryUpdated(object sender, ISublistEntry e)
 {
     OnSublistEntryUpdated(e);
 }
Example #19
0
 private void OnSublistEntryUpdated(ISublistEntry e)
 {
     SublistEntryUpdated?.Invoke(this, e);
 }
        private void DeleteSublistEntryInternal(ISublistEntry entry, SQLiteTransaction transaction)
        {
            const string deleteMainSql = @"DELETE FROM Entry WHERE Id = @id";
            const string deleteRelationSql = @"DELETE FROM EntryRelation WHERE ChildId = @id OR ParentId = @id";

            using (var statement = transaction.Prepare(deleteRelationSql))
            {
                statement.Binding("@id", entry.Id);
                transaction.Execute(statement);
            }
            using (var statement = transaction.Prepare(deleteMainSql))
            {
                statement.Binding("@id", entry.Id);
                transaction.Execute(statement);
            }

            foreach (var sublistEntry in entry.SubEntries)
            {
                using (var statement = transaction.Prepare(deleteRelationSql))
                {
                    statement.Binding("@id", sublistEntry.Id);
                    transaction.Execute(statement);
                }
                using (var statement = transaction.Prepare(deleteMainSql))
                {
                    statement.Binding("@id", sublistEntry.Id);
                    transaction.Execute(statement);
                }

                DeleteSublistEntryInternal(sublistEntry, transaction);
            }
        }
        public void UpdateSublistEntry(ISublistEntry entry)
        {
            const string updateMainSql = @"UPDATE Entry " +
                                          "SET Title = @title, Completed = @completed " +
                                          "WHERE Id = @id";

            const string updateRelationsSql = @"INSERT OR REPLACE INTO EntryRelation " +
                                               "(ParentId, ChildId) " +
                                               "VALUES (@parentId, @id)";

            const string deleteRelationsSql = @"DELETE FROM EntryRelation " +
                                               "WHERE ChildId = @id";

            using (var transaction = new SQLiteTransaction(SharedConnection))
            {
                using (var statement = transaction.Prepare(updateMainSql))
                {
                    statement.Binding("@title", entry.Title);
                    statement.Binding("@completed", entry.Completed);
                    statement.Binding("@id", entry.Id);
                    transaction.Execute(statement);
                }

                if (entry.ParentId.HasValue && entry.ParentId.Value == 0)
                {
                    using (var statement = transaction.Prepare(deleteRelationsSql))
                    {
                        statement.Binding("@id", entry.Id);
                        transaction.Execute(statement);
                    }
                }
                else if (entry.ParentId.HasValue && entry.ParentId.Value != 0)
                {
                    using (var statement = transaction.Prepare(updateRelationsSql))
                    {
                        statement.Binding("@parentId", entry.ParentId);
                        statement.Binding("@id", entry.Id);
                        transaction.Execute(statement);
                    }
                }

                transaction.Commit();
            }
        }
Example #22
0
        public void UnindentItem(ISublistEntry entry)
        {
            var currentParent = _entryProvider.GetParent(entry, AllEntries);
            if (currentParent != null)
            {
                var parentOfParent = _entryProvider.GetParent(currentParent, AllEntries);
                if (parentOfParent != null)
                {
                    entry.ParentId = parentOfParent.Id;
                    parentOfParent.AddSubEntrySafely(entry);
                    currentParent.SubEntries.Remove(entry);
                    _entryProvider.ChangeEntry(entry);
                }
                else
                {
                    entry.ParentId = 0;
                    _entryProvider.ChangeEntry(entry);
                    currentParent.SubEntries.Remove(entry);
                    AllEntries.Add(entry);
                }

                RefreshAllEntries();
            }
        }
Example #23
0
 public void UpdateEntry(ISublistEntry entry)
 {
     entry.IsVisible = _showCompleted || !entry.Completed;
     _entryProvider.ChangeEntry(entry);
 }
Example #24
0
        public void IndentItem(ISublistEntry entry, ISublistEntry newParent)
        {
            if (newParent != null)
            {
                var oldParent = _entryProvider.GetParent(entry, AllEntries);
                if (oldParent != null && oldParent.SubEntries.First() == entry)
                {
                    return;
                }

                entry.ParentId = newParent.Id;
                newParent.AddSubEntrySafely(entry);
                oldParent?.SubEntries.Remove(entry);
                AllEntries.Remove(entry);
                _entryProvider.ChangeEntry(entry);

                RefreshAllEntries();

            }
        }
Example #25
0
 public void AddSubEntrySafely(ISublistEntry entry)
 {
     if (this == entry)
     {
         return;
     }
     foreach (var subEntryInNewEntry in entry.SubEntries)
     {
         AddSubEntrySafely(subEntryInNewEntry);
     }
     entry.ParentId = this.Id;
     SubEntries.Add(entry);
 }
Example #26
0
 public void ChangeEntry(ISublistEntry entry)
 {
     _dataProvider.UpdateSublistEntry(entry);
 }
Example #27
0
 public void ChangeEntry(ISublistEntry entry)
 {
     _dataProvider.UpdateSublistEntry(entry);
 }
Example #28
0
 public void DeleteEntry(ISublistEntry entry)
 {
     _dataProvider.DeleteSublistEntry(entry);
 }
Example #29
0
 private void HierarchicListView_OnSublistEntryUpdated(object sender, ISublistEntry e)
 {
     _viewModel?.UpdateEntry(e);
 }
Example #30
0
 public ISublistEntry StoreNewEntry(ISublistEntry entry)
 {
     entry.Id = _dataProvider.AddSublistEntry(entry);
     return(entry);
 }