private void InsertProjectNote(int originalProjectId)
        {
            // ... Data for current project
            ProjectTDS projectTDSTemp = new ProjectTDS();
            ProjectNotesGateway projectNotesGatewayTemp = new ProjectNotesGateway(projectTDSTemp);
            projectNotesGatewayTemp.LoadAllByProjectId(originalProjectId);

            ProjectNotesGateway projectNotesGateway = new ProjectNotesGateway(projectTDS);
            projectNotesGateway.LoadAllByProjectId(originalProjectId);

            ProjectNotes projectNotes = new ProjectNotes(projectTDS);

            // ... Definition of general variables
            int refId;
            string subject;
            DateTime dateTime;
            int loginId;
            string note;
            bool deleted;
            int? libraryFilesId;

            foreach (ProjectTDS.LFS_PROJECT_NOTERow row in projectTDSTemp.Tables["LFS_PROJECT_NOTE"].Rows)
            {
                // ... Definition of general variables
                refId = row.RefID;
                subject = row.Subject;
                dateTime = row.DateTime;
                loginId = row.LoginID;
                try { note = row.Note; }
                catch { note = ""; }
                deleted = row.Deleted;
                try { libraryFilesId = row.LIBRARY_FILES_ID; }
                catch { libraryFilesId = null; }

                // ... Insert Notes
                projectNotes.Insert(0, subject, dateTime, loginId, note, deleted, libraryFilesId, Int32.Parse(hdfCompanyId.Value.Trim()));
            }
        }
        private void LoadNotes()
        {
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int projectId = Int32.Parse(hdfProjectId.Value);

            // Data for Notes
            ProjectNotes  projectNotes = new ProjectNotes(projectTDS);
            projectNotes.LoadAllByProjectId(projectId);

            tbxNotes.Text = projectNotes.GetAllProjectNotes(projectId, companyId, projectNotes.Table.Rows.Count, "\n");

            //   ProjectGateway projectGateway = new ProjectGateway(projectTDS);

            //   int? libraryCategoriesId = null; if (projectGateway.GetLibraryCategoriesId(int.Parse(hdfProjectId.Value)).HasValue) libraryCategoriesId = (int)projectGateway.GetLibraryCategoriesId(int.Parse(hdfProjectId.Value));

            //    if (libraryCategoriesId.HasValue)
            //    {
            //        ViewState["libraryCategoriesId"] = (int)libraryCategoriesId;
            //        tbxCategoryAssocited.Text = GetFullCategoryName((int)libraryCategoriesId);
            //        btnAssociate.Visible = false;
            //        btnUnassociate.Visible = true;
            //    }
            //    else
            //    {
            //        tbxCategoryAssocited.Text = "";
            //        btnAssociate.Visible = true;
            //        btnUnassociate.Visible = false;
            //    }
        }
        /// <summary>
        /// Save all notes to database (direct)
        /// </summary>
        /// <param name="companyId">companyId</param>
        public void Save(int companyId)
        {
            ProjectNavigatorTDS notesChanges = (ProjectNavigatorTDS)Data.GetChanges();

            if (notesChanges != null)
            {
                if (notesChanges.ProjectNotes.Rows.Count > 0)
                {
                    ProjectNavigatorProjectNotesGateway projectNavigatorProjectNotesGateway = new ProjectNavigatorProjectNotesGateway(notesChanges);

                    foreach (ProjectNavigatorTDS.ProjectNotesRow row in (ProjectNavigatorTDS.ProjectNotesDataTable)notesChanges.ProjectNotes)
                    {
                        // Insert new Notes
                        if ((!row.Deleted) && (!row.InNoteDatabase))
                        {
                            int? libraryFilesId = null; if (!row.IsLIBRARY_FILES_IDNull()) libraryFilesId = row.LIBRARY_FILES_ID;

                            ProjectNotes projectNotes = new ProjectNotes(null);
                            projectNotes.InsertDirect(row.ProjectID, row.RefID, row.Subject, row.LoginID, row.DateTime, row.Note, row.Deleted, row.COMPANY_ID, libraryFilesId);
                        }

                        // Update Notes
                        if ((!row.Deleted) && (row.InNoteDatabase))
                        {
                            int projectId = row.ProjectID;
                            int refId = row.RefID;
                            bool originalDeleted = false;
                            int originalCompanyId = companyId;

                            // original values
                            string originalSubject = projectNavigatorProjectNotesGateway.GetSubjectOriginal(projectId, refId);
                            int originalLoginId = projectNavigatorProjectNotesGateway.GetLoginIdOriginal(projectId, refId);
                            DateTime originalDateTime = projectNavigatorProjectNotesGateway.GetDateTimeOriginal(projectId, refId);
                            string originalNote = projectNavigatorProjectNotesGateway.GetNoteOriginal(projectId, refId);
                            int? originalLibraryFilesId = projectNavigatorProjectNotesGateway.GetLibraryFilesIdOriginal(projectId, refId);

                            // new values
                            string newSubject = projectNavigatorProjectNotesGateway.GetSubject(projectId, refId);
                            string newNote = projectNavigatorProjectNotesGateway.GetNote(projectId, refId);
                            int? newLibraryFilesId = projectNavigatorProjectNotesGateway.GetLibraryFilesId(projectId, refId);

                            ProjectNotes projectNotes = new ProjectNotes(null);
                            projectNotes.UpdateDirect(projectId, refId, originalSubject, originalLoginId, originalDateTime, originalNote, originalDeleted, originalCompanyId, originalLibraryFilesId, projectId, refId, newSubject, originalLoginId, originalDateTime, newNote, originalDeleted, originalCompanyId, newLibraryFilesId);
                        }

                        // Deleted notes
                        if ((row.Deleted) && (row.InNoteDatabase))
                        {
                            ProjectNotes projectNotes = new ProjectNotes(null);
                            projectNotes.DeleteDirect(row.ProjectID, row.RefID, row.COMPANY_ID);
                        }
                    }
                }
            }
        }