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); } }
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 ProcessUpload2(int projectId, int refId, int companyId) { LibraryFilesGateway libraryFilesGateway = new LibraryFilesGateway(); try { //... Set the default path to store uploaded files. AppSettingsReader appSettingReader = new AppSettingsReader(); string websitePath = appSettingReader.GetValue("WebsitePath", typeof(System.String)).ToString(); string filename = ""; //... Get the extension of file string[] shortFilename = nuifAttachment.FileName.Split(new char[] { '.' }); string ext = "." + shortFilename[shortFilename.Length - 1]; bool exit = false; while (!exit) { StringBuilder builder = new StringBuilder(); Random rand = new Random(); char ch; for (int i = 0; i < 8; i++) { ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * rand.NextDouble() + 65))); builder.Append(ch); } filename = builder.ToString(); filename = filename + ext; libraryFilesGateway.LoadByFileName(filename, companyId); if (libraryFilesGateway.Table.Rows.Count > 0) { exit = false; } else { exit = true; } } string pathFull = websitePath + "\\Files\\LF_DGHOUGDH\\Library\\"; //... Save the file nuifAttachment.MoveTo(Path.Combine(pathFull, filename), MoveToOptions.Overwrite); LibraryFiles libraryFiles = new LibraryFiles(libraryTDS); libraryFiles.Insert(filename, tbxDescription.Text, nuifAttachment.FileName, null, Convert.ToInt32(ViewState["libraryCategoriesId"]), Convert.ToInt32(hdfLoginId.Value), int.Parse(Session["companyID"].ToString()), nuifAttachment.FileContent.Length.ToString()); //Note: COMPANY_ID ProjectNavigatorProjectNotes model = new ProjectNavigatorProjectNotes(projectNavigatorTDS); model.UpdateLibraryFilesId(projectId, refId, 0, nuifAttachment.FileName, filename); Session["lfsProjectTDS"] = projectTDS; Session["lfsLibraryTDS"] = libraryTDS; Session["projectNavigatorTDS"] = projectNavigatorTDS; Session["fromAttachment"] = "yes"; } catch (Exception ex) { } }