/// <summary> /// Create report with showing SaveFileDialog /// </summary> /// <param name="format">type of creating report</param> public void CreateReport(DefaultDialogs.TargetFileType format) { try { DefaultDialogs dialogs = new DefaultDialogs(); if (dialogs.SaveFileDialog(format) == true) { IReportCreator creator = GetIReportCreatorFromReportFormat(format); creator.CreateReport(dialogs.FilePath, properties.ToList()); } } catch (NullReferenceException e) { DefaultDialogs.ShowMessage("Не удалось создать отчет, возможно не достаточно свободной памяти\n" + "Системное описание ошибки" + e.Message, "Ошибка"); } catch (IOException e) { DefaultDialogs.ShowMessage(e.Message, "Ошибка"); } catch (Exception e) { DefaultDialogs.ShowMessage("Не опознанная ошибка!\n" + "Системное описание ошибки" + e.Message, "Ошибка"); } }
/// <summary> /// From enum format get appropriate object for creating report /// </summary> /// <param name="format"></param> /// <returns></returns> private IReportCreator GetIReportCreatorFromReportFormat(DefaultDialogs.TargetFileType format) { try { switch (format) { case DefaultDialogs.TargetFileType.DOC_DOCX: return(new DocReportCreator()); case DefaultDialogs.TargetFileType.PDF: return(new PdfReportCreator()); } return(null); } catch (Exception e) { throw new Exception("Не удалось создать объект для создания отчета\n Системное описание ошибки:" + e.Message); } }