// ////////////////////////////////////////////////////////////////////////
 // PUBLIC METHODS
 //
 /// <summary>
 /// LoadAllByMaterialId
 /// </summary>
 /// <param name="materialId">materialId</param>              
 /// <param name="companyId">companyId</param>
 public void LoadAllByMaterialId(int materialId, int companyId)
 {
     MaterialsInformationNoteInformationGateway materialsInformationNoteInformationGateway = new MaterialsInformationNoteInformationGateway(Data);
     materialsInformationNoteInformationGateway.LoadAllByMaterialId(materialId, companyId);
 }
        /// <summary>
        /// Save all materials to database (direct)
        /// </summary>
        /// <param name="companyId">companyId</param>
        public void Save(int companyId)
        {
            MaterialsInformationTDS materialInformationChanges = (MaterialsInformationTDS)Data.GetChanges();

            if (materialInformationChanges.NoteInformation.Rows.Count > 0)
            {
                MaterialsInformationNoteInformationGateway materialsInformationNoteInformationGateway = new MaterialsInformationNoteInformationGateway(materialInformationChanges);

                foreach (MaterialsInformationTDS.NoteInformationRow row in (MaterialsInformationTDS.NoteInformationDataTable)materialInformationChanges.NoteInformation)
                {
                    // Insert new Notes
                    if ((!row.Deleted) && (!row.InDatabase))
                    {
                        MaterialsNotes materialsNotes = new MaterialsNotes(null);
                        materialsNotes.InsertDirect(row.MaterialID, row.RefID, row.Subject, row.UserID, row.DateTime_, row.Note, row.Deleted, row.COMPANY_ID);
                    }

                    // Update Notes
                    if ((!row.Deleted) && (row.InDatabase))
                    {
                        int materialId = row.MaterialID;
                        int refId = row.RefID;
                        bool originalDeleted = row.Deleted;
                        int originalCompanyId = companyId;

                        // original values
                        string originalSubject = materialsInformationNoteInformationGateway.GetSubjectOriginal(materialId, refId);
                        int originalUserId = materialsInformationNoteInformationGateway.GetUserIdOriginal(materialId, refId);
                        DateTime originalDateTime_ = materialsInformationNoteInformationGateway.GetDateTime_Original(materialId, refId);
                        string originalNote = materialsInformationNoteInformationGateway.GetNoteOriginal(materialId, refId);

                        // new values
                        string newSubject = materialsInformationNoteInformationGateway.GetSubject(materialId, refId);
                        string newNote = materialsInformationNoteInformationGateway.GetNote(materialId, refId);

                        MaterialsNotes materialsNotes = new MaterialsNotes(null);
                        materialsNotes.UpdateDirect(materialId, refId, originalSubject, originalUserId, originalDateTime_, originalNote, originalDeleted, originalCompanyId, materialId, refId, newSubject, originalUserId, originalDateTime_, newNote, originalDeleted, originalCompanyId);
                    }

                    // Deleted notes
                    if ((row.Deleted) && (row.InDatabase))
                    {
                        MaterialsNotes materialsNotes = new MaterialsNotes(null);
                        materialsNotes.DeleteDirect(row.MaterialID, row.RefID, row.COMPANY_ID);
                    }
                }
            }
        }
        /// ////////////////////////////////////////////////////////////////////////
        /// PRIVATE METHODS
        ///
        /// <summary>
        /// UpdateFieldsForSections
        /// </summary>
        private void UpdateFieldsForSections()
        {
            foreach (MaterialsByProcessReportTDS.MaterialsByProcessReportRow row in (MaterialsByProcessReportTDS.MaterialsByProcessReportDataTable)Table)
            {
                MaterialsInformationNoteInformationGateway materialsInformationNoteInformationGateway = new MaterialsInformationNoteInformationGateway();
                materialsInformationNoteInformationGateway.LoadAllByMaterialId(row.MaterialID, row.COMPANY_ID);

                MaterialsInformationNoteInformation materialsInformationNoteInformation = new MaterialsInformationNoteInformation(materialsInformationNoteInformationGateway.Data);
                string comments = materialsInformationNoteInformation.GetAllNotes(row.MaterialID, row.COMPANY_ID, materialsInformationNoteInformationGateway.Table.Rows.Count, "\n");

                if (comments.Length > 0)
                {
                    row.Notes = comments;
                }
                else
                {
                    row.SetNotesNull();
                }
            }
        }