/// <summary> /// Inserts a database record for a WorkItemStatus. /// CompletionAmount is automatically set to 0. /// </summary> /// <param name="wise"></param> /// <returns>Returns the WorkItemStatusEntry ID on insert, or -1</returns> public int InsertWorkItemStatusEntry(BaseWorkItemStatusEntry wise) { int workItemStatusID = -1; using (var connection = new SQLiteConnection(dbConnectionString)) { using (var cmd = new SQLiteCommand(connection)) { connection.Open(); cmd.CommandText = "INSERT INTO WorkItemStatusEntry (WorkItem_ID, WorkItemStatus_ID, CompletionAmount, CreationDateTime) " + "VALUES (@workItemID, @statusID, @completionAmount, @creation)"; cmd.Parameters.AddWithValue("@workItemID", wise.WorkItemID); cmd.Parameters.AddWithValue("@statusID", wise.WorkItemStatusID); cmd.Parameters.AddWithValue("@completionAmount", wise.CompletionAmount); cmd.Parameters.AddWithValue("@creation", wise.CreationDateTime); cmd.ExecuteNonQuery(); // Get the identity value cmd.CommandText = "SELECT last_insert_rowid()"; workItemStatusID = (int)(Int64)cmd.ExecuteScalar(); wise.WorkItemStatusEntryID = workItemStatusID; wise.PendingDBOperation = DBActionRequired.NONE; } connection.Close(); } return(workItemStatusID); }
/// <summary> /// Update a WorkItemStatusEntry. /// </summary> /// <param name="wise"></param> public void UpdateWorkItemStatusEntry(BaseWorkItemStatusEntry wise) { wise.ModificationDateTime = DateTime.Now; using (var connection = new SQLiteConnection(dbConnectionString)) { using (var cmd = new SQLiteCommand(connection)) { connection.Open(); cmd.CommandText = "UPDATE WorkItemStatusEntry " + "SET WorkItemStatus_ID = @workItemStatusID, " + "CompletionAmount = @completionAmount, " + "ModificationDateTime = @modTime " + "WHERE WorkItem_ID = @workItemID"; cmd.Parameters.AddWithValue("@workItemStatusID", wise.WorkItemStatusID); cmd.Parameters.AddWithValue("@completionAmount", wise.CompletionAmount); cmd.Parameters.AddWithValue("@modTime", wise.ModificationDateTime); cmd.Parameters.AddWithValue("@workItemID", wise.WorkItemID); cmd.ExecuteNonQuery(); wise.PendingDBOperation = DBActionRequired.NONE; } connection.Close(); } }