private void UpdateDatabase()
        {
            // Get ids
            int toDoId = Int32.Parse(hdfToDoListId.Value);
            string toDolistType = hdfFmType.Value;
            int companyId = Int32.Parse(hdfCompanyId.Value);

            // Delete
            DB.Open();
            DB.BeginTransaction();
            try
            {
                ToDoListToDoListActivity toDoListToDoListActivity = new ToDoListToDoListActivity(toDolistInformationTDS);
                toDoListToDoListActivity.DeleteAllDirect(toDoId, companyId);

                ToDoListToDoList toDoList = new ToDoListToDoList(null);
                toDoList.DeleteDirect(toDoId, companyId);

                DB.CommitTransaction();
            }
            catch (Exception ex)
            {
                DB.RollbackTransaction();

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        /// <summary>
        /// Save all activities to database (direct)
        /// </summary>
        /// <param name="companyId">companyId</param>
        public void Save(int companyId)
        {
            ToDoListInformationTDS toDoListInformationChanges = (ToDoListInformationTDS)Data.GetChanges();

            if (toDoListInformationChanges != null)
            {
                if (toDoListInformationChanges.ActivityInformation.Rows.Count > 0)
                {
                    ToDoListInformationActivityInformationGateway toDoListInformationActivityInformationGateway = new ToDoListInformationActivityInformationGateway(toDoListInformationChanges);

                    foreach (ToDoListInformationTDS.ActivityInformationRow row in (ToDoListInformationTDS.ActivityInformationDataTable)toDoListInformationChanges.ActivityInformation)
                    {
                        // Insert new activity
                        if ((!row.Deleted) && (!row.InDataBase))
                        {
                            // new values
                            int toDoId = row.ToDoID;
                            int refId = row.RefID;

                            int employeeId = toDoListInformationActivityInformationGateway.GetEmployeeID(toDoId, refId);
                            string type_ = toDoListInformationActivityInformationGateway.GetType_(toDoId, refId);
                            DateTime dateTime_ = toDoListInformationActivityInformationGateway.GetDateTime_(toDoId, refId);
                            string comment = toDoListInformationActivityInformationGateway.GetComment(toDoId, refId);

                            ToDoListToDoListActivity toDoListToDoListActivity = new ToDoListToDoListActivity(null);
                            toDoListToDoListActivity.InsertDirect(toDoId, refId, employeeId, type_, dateTime_, row.Deleted, row.COMPANY_ID, comment);
                        }

                        // Update activities
                        if ((!row.Deleted) && (row.InDataBase))
                        {
                            int toDoId = row.ToDoID;
                            int refId = row.RefID;
                            bool originalDeleted = false;
                            int originalCompanyId = companyId;

                            // original values
                            int originalEmployeeId = toDoListInformationActivityInformationGateway.GetEmployeeID(toDoId, refId);
                            string originalType_ = toDoListInformationActivityInformationGateway.GetType_(toDoId, refId);
                            DateTime originalDateTime_ = toDoListInformationActivityInformationGateway.GetDateTime_(toDoId, refId);
                            string originalComment = toDoListInformationActivityInformationGateway.GetComment(toDoId, refId);

                            // new values
                            int newEmployeeId = toDoListInformationActivityInformationGateway.GetEmployeeIDOriginal(toDoId, refId);
                            string newComment = toDoListInformationActivityInformationGateway.GetCommentOriginal(toDoId, refId);

                            ToDoListToDoListActivity toDoListToDoListActivity = new ToDoListToDoListActivity(null);
                            toDoListToDoListActivity.UpdateDirect(toDoId, refId, originalEmployeeId, originalType_, originalDateTime_, originalDeleted, originalCompanyId, originalComment, toDoId, refId, newEmployeeId, originalType_, originalDateTime_, originalDeleted, originalCompanyId, newComment);
                        }

                        // Deleted activity
                        if ((row.Deleted) && (row.InDataBase))
                        {
                            ToDoListToDoListActivity toDoListToDoListActivity = new ToDoListToDoListActivity(null);
                            toDoListToDoListActivity.DeleteDirect(row.ToDoID, row.RefID, row.COMPANY_ID);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Save to do lists
        /// </summary>
        /// <param name="creationDate">creationDate</param>        
        /// <param name="companyId">companyId</param>
        public int? Save(DateTime creationDate, int companyId)
        {
            int newToDoListId = 0;

            ToDoListAddTDS ToDoListAddChanges = (ToDoListAddTDS)Data.GetChanges();
            if (ToDoListAddChanges.BasicInformation.Rows.Count > 0)
            {
                ToDoListToDoListGateway toDoListToDoListGateway = new ToDoListToDoListGateway(ToDoListAddChanges);

                foreach (ToDoListAddTDS.BasicInformationRow row in (ToDoListAddTDS.BasicInformationDataTable)ToDoListAddChanges.BasicInformation)
                {
                    string subject = ""; if (!row.IsSubjectNull()) subject = row.Subject;
                    string comment = ""; if (!row.IsCommentNull()) comment = row.Comment;
                    DateTime? dueDate = null; if (!row.IsDueDateNull()) dueDate = row.DueDate;
                    int? unitId = null; if (!row.IsUnitIdNull()) unitId = row.UnitId;
                    int employeeId = 0; if (!row.IsTeamMemberIDNull()) employeeId = row.TeamMemberID;
                    bool deleted = row.Deleted;
                    string state = row.State;
                    int createdById = row.CreatedByID;
                    int refId = 1;
                    string type_ = row.Type_;

                    // ... Insert the to do list
                    ToDoListToDoList toDoListToDoList = new ToDoListToDoList(null);
                    newToDoListId = toDoListToDoList.InsertDirect(subject, creationDate, createdById, state, dueDate, unitId, deleted, companyId);

                    // ... Insert first Activity (Default Assignation - first Activity)
                    ToDoListToDoListActivity toDoListToDoListActivity = new ToDoListToDoListActivity(null);
                    toDoListToDoListActivity.InsertDirect(newToDoListId, refId, employeeId, type_, creationDate, row.Deleted, companyId, comment);
                }
            }

            return newToDoListId;
        }