private void GrdNotesAdd() { if (ValidateNotesFooter()) { Page.Validate("notesDataAdd"); if (Page.IsValid) { int unitId = Int32.Parse(hdfUnitId.Value); int companyId = Int32.Parse(hdfCompanyId.Value); string newSubject = ((TextBox)grdNotes.FooterRow.FindControl("tbxNoteSubjectNew")).Text.Trim(); int loginId = Convert.ToInt32(Session["loginID"]); DateTime dateTime_ = DateTime.Now; string newNote = ((TextBox)grdNotes.FooterRow.FindControl("tbxNoteNoteNew")).Text.Trim(); bool inDatabase = false; int? libraryFilesId = null; string fileName = ((Label)grdNotes.FooterRow.FindControl("lblFileNameNoteAttachmentNew")).Text.Trim(); if (fileName != "") { LibraryFilesGateway libraryFilesGateway = new LibraryFilesGateway(); libraryFilesId = libraryFilesGateway.GetlibraryFilesId(fileName); } UnitInformationNoteDetails model = new UnitInformationNoteDetails(unitInformationTDS); model.Insert(unitId, newSubject, loginId, dateTime_, newNote, false, companyId, inDatabase, libraryFilesId); Session.Remove("unitsNotesTempDummy"); Session["unitInformationTDS"] = unitInformationTDS; grdNotes.DataBind(); grdNotes.PageIndex = grdNotes.PageCount - 1; } } }
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); } }
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); } }