/// <summary> /// Retrieves the next available TodoID to assign to a new TodoItem record. /// </summary> /// <returns></returns> protected int GetNextTodoID() { try { if (m_blAccessDataSource) { return(TodoDataSync.GetCounterID("TodoID")); } else { if (m_lstItems.Count > 0) { return(m_lstItems.Max(t => t.TodoID) + 1); } else { return(1); } }//end if } catch (Exception err) { ErrorHandler.ShowErrorMessage(err, "Error in GetNextTodoID function of TodoList class."); return(-1); } }
/// <summary> /// Loads all the users into the UserList class from the underlying data source. /// </summary> public void Load() { try { Clear(); TodoDataSync.LoadUsers(m_dsSource.Users); foreach (TodoDB.UsersRow rowUser in m_dsSource.Users) { User user = new TodoModel.User(rowUser); user.SyncDataToClass(); user.ItemStatus = TodoModelItemStatus.Unmodified; m_lstItems.Add(user); }//next rowTodoItem } catch (Exception err) { ErrorHandler.ShowErrorMessage(err, "Error in Load function of UserList class."); } }
/// <summary> /// Loads all the Todo items for the specified user into the TodoList class from the underlying data source. /// </summary> /// <param name="user">The user whose Todo items to load into the TodoList class.</param> public void Load(User user) { try { Clear(); m_User = user; TodoDataSync.LoadTodoItems(user.UserID, m_dsSource.TodoItems); foreach (TodoDB.TodoItemsRow rowTodoItem in m_dsSource.TodoItems) { TodoItem todo = new TodoItem(rowTodoItem); todo.SyncDataToClass(); todo.ItemStatus = TodoModelItemStatus.Unmodified; //m_lstTodoItems.Add(todo); m_lstItems.Add(todo); }//next rowTodoItem } catch (Exception err) { ErrorHandler.ShowErrorMessage(err, "Error in Load function of TodoList class."); } }
/// <summary> /// Updates all changes to the Todo items made in the TodoList class to the class's underlying data source. /// </summary> /// <returns>Success: Returns number of records updated, Failure: -1</returns> public int Update() { try { IEnumerable <TodoItem> lstNewTodoItems = m_lstItems.Where(t => t.ItemStatus == TodoModelItemStatus.New); IEnumerable <TodoItem> lstModTodoItems = m_lstItems.Where(t => t.ItemStatus == TodoModelItemStatus.Modified); foreach (TodoItem item in lstNewTodoItems) { item.SyncDataToSource(); m_dsSource.TodoItems.AddTodoItemsRow((TodoDB.TodoItemsRow)item.GetRowSource()); }//next item foreach (TodoItem item in lstModTodoItems) { item.SyncDataToSource(); }//next item foreach (TodoItem item in m_lstDelTodoItems) { ((TodoDB.TodoItemsRow)item.GetRowSource()).Delete(); }//next item int iRowCount = TodoDataSync.UpdateTodoItems(m_dsSource.TodoItems); m_lstItems.ForEach(t => t.ItemStatus = TodoModelItemStatus.Unmodified); m_lstDelTodoItems.Clear(); return(iRowCount); } catch (Exception err) { ErrorHandler.ShowErrorMessage(err, "Error in Update Overload 1 function of TodoList class."); return(-1); } }