/// <summary> /// Save all notes to database (direct) /// </summary> /// <param name="companyId">companyId</param> public void Save(int companyId) { UnitInformationTDS unitInformationChanges = (UnitInformationTDS)Data.GetChanges(); if (unitInformationChanges.NoteInformation.Rows.Count > 0) { UnitInformationNoteDetailsGateway unitInformationNoteDetailsGateway = new UnitInformationNoteDetailsGateway(unitInformationChanges); foreach (UnitInformationTDS.NoteInformationRow row in (UnitInformationTDS.NoteInformationDataTable)unitInformationChanges.NoteInformation) { // Insert new Notes if ((!row.Deleted) && (!row.InDatabase)) { int? libraryFilesId = null; if (!row.IsLIBRARY_FILES_IDNull()) libraryFilesId = row.LIBRARY_FILES_ID; UnitsNote unitsNote = new UnitsNote(null); unitsNote.InsertDirect(row.UnitID, row.RefID, row.Subject, row.UserID, row.DateTime_, row.Note, row.Deleted, row.COMPANY_ID, libraryFilesId); } // Update Notes if ((!row.Deleted) && (row.InDatabase)) { int unitId = row.UnitID; int refId = row.RefID; bool originalDeleted = false; int originalCompanyId = companyId; // Original values string originalSubject = unitInformationNoteDetailsGateway.GetSubjectOriginal(unitId, refId); int originalUserId = unitInformationNoteDetailsGateway.GetUserIdOriginal(unitId, refId); DateTime originalDateTime_ = unitInformationNoteDetailsGateway.GetDateTime_Original(unitId, refId); string originalNote = unitInformationNoteDetailsGateway.GetNoteOriginal(unitId, refId); int? originalLibraryFilesId = unitInformationNoteDetailsGateway.GetLibraryFilesIdOriginal(unitId, refId); // New values string newSubject = unitInformationNoteDetailsGateway.GetSubject(unitId, refId); string newNote = unitInformationNoteDetailsGateway.GetNote(unitId, refId); int? newLibraryFilesId = unitInformationNoteDetailsGateway.GetLibraryFilesId(unitId, refId); UnitsNote unitsNote = new UnitsNote(null); unitsNote.UpdateDirect(unitId, refId, originalSubject, originalUserId, originalDateTime_, originalNote, originalDeleted, originalCompanyId, originalLibraryFilesId, unitId, refId, newSubject, originalUserId, originalDateTime_, newNote, originalDeleted, originalCompanyId, newLibraryFilesId); } // Delete note if ((row.Deleted) && (row.InDatabase)) { UnitsNote unitsNote = new UnitsNote(null); unitsNote.DeleteDirect(row.UnitID, row.RefID, row.COMPANY_ID); } } } }
private void UpdateDatabase() { int companyId = Int32.Parse(hdfCompanyId.Value); int unitId = Int32.Parse(hdfUnitId.Value); LibraryFilesGateway libraryFilesGateway = new LibraryFilesGateway(libraryTDSForUnits); libraryFilesGateway.Update(); DB.Open(); DB.BeginTransaction(); try { // ... if can edit everything if (Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_UNITS_EDIT"])) { // Save inspection details UnitInformationInspectionDetails unitInformationInspectionDetails = new UnitInformationInspectionDetails(unitInformationTDS); unitInformationInspectionDetails.Save(unitId, companyId); // Save notes information UnitInformationNoteDetailsGateway unitInformationNoteDetailsGateway = new UnitInformationNoteDetailsGateway(unitInformationTDS); UnitInformationNoteDetails unitInformationNoteDetails = new UnitInformationNoteDetails(unitInformationTDS); foreach (UnitInformationTDS.NoteInformationRow rowNotes in (UnitInformationTDS.NoteInformationDataTable)unitInformationNoteDetailsGateway.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; } } } unitInformationNoteDetails.Save(companyId); // Save costs information UnitInformationCostInformation unitInformationCostInformation = new UnitInformationCostInformation(unitInformationTDS); unitInformationCostInformation.Save(companyId); // Save costs exceptions information UnitInformationCostExceptionsInformation unitInformationCostExceptionsInformation = new UnitInformationCostExceptionsInformation(unitInformationTDS); unitInformationCostExceptionsInformation.Save(companyId, unitId); // Save unit details UnitInformationUnitDetails unitInformationUnitDetails = new UnitInformationUnitDetails(unitInformationTDS); unitInformationUnitDetails.Save(arrayCategoriesSelectedForEdit, companyId); } // ... if could only edit notes if (!Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_UNITS_EDIT"]) && Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_UNITS_COMMENTS"])) { // Save notes information UnitInformationNoteDetailsGateway unitInformationNoteDetailsGateway = new UnitInformationNoteDetailsGateway(unitInformationTDS); UnitInformationNoteDetails unitInformationNoteDetails = new UnitInformationNoteDetails(unitInformationTDS); foreach (UnitInformationTDS.NoteInformationRow rowNotes in (UnitInformationTDS.NoteInformationDataTable)unitInformationNoteDetailsGateway.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; } } } unitInformationNoteDetails.Save(companyId); } DB.CommitTransaction(); // Store datasets unitInformationTDS.AcceptChanges(); libraryTDSForUnits.AcceptChanges(); Session["unitInformationTDS"] = unitInformationTDS; Session["libraryTDSForUnits"] = libraryTDSForUnits; } catch (Exception ex) { DB.RollbackTransaction(); string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' ')); Response.Redirect(url); } }
// //////////////////////////////////////////////////////////////////////// // PUBLIC METHODS // /// <summary> /// LoadByUnitId /// </summary> /// <param name="unitId">unitId</param> /// <param name="companyId">companyId</param> public void LoadByUnitId(int unitId, int companyId) { UnitInformationNoteDetailsGateway unitInformationNoteDetailsGateway = new UnitInformationNoteDetailsGateway(Data); unitInformationNoteDetailsGateway.LoadAllByUnitId(unitId, companyId); }