/// <summary> /// Save all notes to database (direct) /// </summary> /// <param name="companyId">companyId</param> public void Save(int companyId) { ServiceInformationTDS serviceInformationChanges = (ServiceInformationTDS)Data.GetChanges(); if (serviceInformationChanges != null) { if (serviceInformationChanges.NoteInformation.Rows.Count > 0) { ServiceInformationServiceNoteGateway serviceInformationServiceNoteGateway = new ServiceInformationServiceNoteGateway(serviceInformationChanges); foreach (ServiceInformationTDS.NoteInformationRow row in (ServiceInformationTDS.NoteInformationDataTable)serviceInformationChanges.NoteInformation) { // Insert new notes if ((!row.Deleted) && (!row.InServiceNoteDatabase)) { int? libraryFilesId = null; if (!row.IsLIBRARY_FILES_IDNull()) libraryFilesId = row.LIBRARY_FILES_ID; ServicesNote servicesNote = new ServicesNote(null); servicesNote.InsertDirect(row.ServiceID, row.RefID, row.Subject, row.UserID, row.DateTime_, row.Note, libraryFilesId, row.Deleted, row.COMPANY_ID); } // Update notes if ((!row.Deleted) && (row.InServiceNoteDatabase)) { int serviceId = row.ServiceID; int refId = row.RefID; bool originalDeleted = false; int originalCompanyId = companyId; // original values string originalSubject = serviceInformationServiceNoteGateway.GetSubjectOriginal(serviceId, refId); int originalUserId = serviceInformationServiceNoteGateway.GetUserIdOriginal(serviceId, refId); DateTime originalDateTime_ = serviceInformationServiceNoteGateway.GetDateTime_Original(serviceId, refId); string originalNote = serviceInformationServiceNoteGateway.GetNoteOriginal(serviceId, refId); int? originalLibraryFilesId = null; if (serviceInformationServiceNoteGateway.GetLibraryFilesIdOriginal(serviceId, refId).HasValue) originalLibraryFilesId = serviceInformationServiceNoteGateway.GetLibraryFilesIdOriginal(serviceId, refId); // new values string newSubject = serviceInformationServiceNoteGateway.GetSubject(serviceId, refId); string newNote = serviceInformationServiceNoteGateway.GetNote(serviceId, refId); int? newLibraryFilesId = null; if (serviceInformationServiceNoteGateway.GetLibraryFilesId(serviceId, refId).HasValue) newLibraryFilesId = serviceInformationServiceNoteGateway.GetLibraryFilesId(serviceId, refId); ServicesNote servicesNote = new ServicesNote(null); servicesNote.UpdateDirect(serviceId, refId, originalSubject, originalUserId, originalDateTime_, originalNote, originalLibraryFilesId, originalDeleted, originalCompanyId, serviceId, refId, newSubject, originalUserId, originalDateTime_, newNote, newLibraryFilesId, originalDeleted, originalCompanyId); } // Deleted notes if ((row.Deleted) && (row.InServiceNoteDatabase)) { ServicesNote servicesNote = new ServicesNote(null); servicesNote.DeleteDirect(row.ServiceID, row.RefID, row.COMPANY_ID); } } } } }
private void UpdateDatabase() { int companyId = Int32.Parse(hdfCompanyId.Value); LibraryFilesGateway libraryFilesGateway = new LibraryFilesGateway(libraryTDSForServices); libraryFilesGateway.Update(); DB.Open(); DB.BeginTransaction(); try { ServiceInformationServiceNoteGateway serviceInformationServiceNoteGateway = new ServiceInformationServiceNoteGateway(serviceInformationTDS); ServiceInformationServiceNote serviceInformationServiceNote = new ServiceInformationServiceNote(serviceInformationTDS); foreach (ServiceInformationTDS.NoteInformationRow rowNotes in (ServiceInformationTDS.NoteInformationDataTable)serviceInformationServiceNoteGateway.Table) { if (!rowNotes.IsLIBRARY_FILES_IDNull()) { if (rowNotes.LIBRARY_FILES_ID == 0 && rowNotes.FILENAME != "") { libraryFilesGateway.LoadByFileName(rowNotes.FILENAME, companyId); int newLibraryFilesId = libraryFilesGateway.GetlibraryFilesId(rowNotes.FILENAME); rowNotes.LIBRARY_FILES_ID = newLibraryFilesId; } } } // Save costs information ServiceInformationServiceCost serviceInformationServiceCost = new ServiceInformationServiceCost(serviceInformationTDS); serviceInformationServiceCost.Save(companyId); // Save notes information serviceInformationServiceNote.Save(companyId); // Save service information ServiceInformationBasicInformation serviceInformationBasicInformation = new ServiceInformationBasicInformation(serviceInformationTDS); serviceInformationBasicInformation.Save(companyId); DB.CommitTransaction(); // Store datasets libraryTDSForServices.AcceptChanges(); serviceInformationTDS.AcceptChanges(); Session["serviceInformationTDS"] = serviceInformationTDS; Session["libraryTDSForServices"] = libraryTDSForServices; } catch (Exception ex) { DB.RollbackTransaction(); string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' ')); Response.Redirect(url); } }
// //////////////////////////////////////////////////////////////////////// // PUBLIC METHODS // /// <summary> /// LoadByServiceId /// </summary> /// <param name="serviceId">serviceId</param> /// <param name="companyId">companyId</param> public void LoadByServiceId(int serviceId, int companyId) { ServiceInformationServiceNoteGateway serviceInformationServiceNoteGateway = new ServiceInformationServiceNoteGateway(Data); serviceInformationServiceNoteGateway.LoadAllByServiceId(serviceId, companyId); }