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 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(); } }
public void AddSubEntrySafely(ISublistEntry entry) { if (this == entry) { return; } foreach (var subEntryInNewEntry in entry.SubEntries) { AddSubEntrySafely(subEntryInNewEntry); } entry.ParentId = this.Id; SubEntries.Add(entry); }
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 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(); } }
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); }
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); }
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; }
public void DeleteEntry(ISublistEntry entry) { _dataProvider.DeleteSublistEntry(entry); }
public ISublistEntry StoreNewEntry(ISublistEntry entry) { entry.Id = _dataProvider.AddSublistEntry(entry); return entry; }
private void HierarchicListView_OnSublistEntryUpdated(object sender, ISublistEntry e) { _viewModel?.UpdateEntry(e); }
public void UpdateEntry(ISublistEntry entry) { entry.IsVisible = _showCompleted || !entry.Completed; _entryProvider.ChangeEntry(entry); }
private void SubItemsListView_OnSublistEntryUpdated(object sender, ISublistEntry e) { OnSublistEntryUpdated(e); }
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(); } }
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 UpdateEntry(ISublistEntry entry) { entry.IsVisible = _showCompleted || !entry.Completed; _entryProvider.ChangeEntry(entry); }
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 void AddSubEntrySafely(ISublistEntry entry) { if (this == entry) { return; } foreach (var subEntryInNewEntry in entry.SubEntries) { AddSubEntrySafely(subEntryInNewEntry); } entry.ParentId = this.Id; SubEntries.Add(entry); }
public void ChangeEntry(ISublistEntry entry) { _dataProvider.UpdateSublistEntry(entry); }
public void ChangeEntry(ISublistEntry entry) { _dataProvider.UpdateSublistEntry(entry); }
public void DeleteEntry(ISublistEntry entry) { _dataProvider.DeleteSublistEntry(entry); }
private void HierarchicListView_OnSublistEntryUpdated(object sender, ISublistEntry e) { _viewModel?.UpdateEntry(e); }
public ISublistEntry StoreNewEntry(ISublistEntry entry) { entry.Id = _dataProvider.AddSublistEntry(entry); return(entry); }