private void OnNodeChecked(object sender, TreeViewEventArgs e)
        {
            ReportNode rn = e.Node.Tag as ReportNode;

            if (null != rn)
            {
                rn.Activated = !rn.Activated;
            }
            UpdateReport();
        }
        public ReportNode GetChildByName(string name)
        {
            ReportNode child = _children.Find(
                delegate(ReportNode rn) { return(string.Equals(rn.Name, name, StringComparison.CurrentCultureIgnoreCase)); }
                );

            if (null == child)
            {
                _children.Add(child = new ReportNode(name));
            }
            return(child);
        }
Exemple #3
0
        private void AddNode(ReportNode rn, TreeNode tnParent)
        {
            TreeNode tn = new TreeNode(rn.Name);

            tn.Checked = rn.Activated;
            tn.Tag     = rn;
            tnParent.Nodes.Add(tn);

            foreach (ReportNode rnChild in rn.Children)
            {
                AddNode(rnChild, tn);
            }
            tn.Expand();
        }
Exemple #4
0
        public ReporterPDF(ReportData inputData, ref ReportNode rnRoot
                           , string templatePath, string outputFilePath)
        {
            // absolute output file path
            string absOutputFilePath = string.Empty;

            if (Path.IsPathRooted(outputFilePath))
            {
                absOutputFilePath = outputFilePath;
            }
            else
            {
                absOutputFilePath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), outputFilePath));
            }
            // absolute template path
            string absTemplatePath = string.Empty;

            if (Path.IsPathRooted(templatePath))
            {
                absTemplatePath = templatePath;
            }
            else
            {
                absTemplatePath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), templatePath));
            }

            // does output directory exists
            string outDir = Path.GetDirectoryName(absOutputFilePath);

            if (!Directory.Exists(outDir))
            {
                try { Directory.CreateDirectory(outDir); }
                catch (UnauthorizedAccessException /*ex*/)
                { throw new UnauthorizedAccessException(string.Format("User not allowed to write under {0}", Directory.GetParent(outDir).FullName)); }
                catch (Exception ex)
                { throw new Exception(string.Format("Directory {0} does not exist, and could not be created.", outDir), ex); }
            }
            // html file path
            string htmlFilePath = Path.ChangeExtension(absOutputFilePath, "html");

            BuildAnalysisReport(inputData, ref rnRoot, absTemplatePath, htmlFilePath);

            PdfConvert.ConvertHtmlToPdf(new PdfDocument()
            {
                Url = htmlFilePath
            }, new PdfOutput()
            {
                OutputFilePath = absOutputFilePath
            });
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            // caption
            Text = string.Format(Resources.ID_REPORT_CAPTION, Data.Title);
            // toolbar show dimension
            toolSBDimensions.Checked = Settings.Default.ShowDimensions;
            // tree initialize root
            _rnRoot = new ReportNode(Resources.ID_REPORT);
            try
            {
                // font size controls
                cbFontSizeDetail.InitializeContent();
                cbFontSizeDetail.FontSizeRatio = Settings.Default.FontSizeRatioDetail;
                cbFontSizeLarge.InitializeContent();
                cbFontSizeLarge.FontSizeRatio = Settings.Default.FontSizeRatioLarge;
                // image definition
                cbDefinitionDetail.InitializeContent();
                cbDefinitionDetail.SelectedIndex = Settings.Default.ImageDefinitionDetail;
                cbDefinitionLarge.InitializeContent();
                int iDefLarge = Settings.Default.ImageDefinitionLarge;
                cbDefinitionLarge.SelectedIndex = iDefLarge >= 4 ? iDefLarge : 4;
                // image layout
                cbHTMLSizeDetail.InitializeContent();
                cbHTMLSizeDetail.SelectedIndex = Settings.Default.ImageHTMLSizeDetail;
                cbHTMLSizeLarge.InitializeContent();
                int iHTMLSizeLarge = Settings.Default.ImageHTMLSizeLarge;
                cbHTMLSizeLarge.SelectedIndex = iHTMLSizeLarge >= 5 ? iHTMLSizeLarge : 5;
            }
            catch (Exception /*ex*/)
            {
            }
            // define event handling after initializing size/font combo boxes
            cbDefinitionDetail.SelectedIndexChanged += new EventHandler(OnUpdateReport);
            cbDefinitionLarge.SelectedIndexChanged  += new EventHandler(OnUpdateReport);
            cbFontSizeDetail.SelectedIndexChanged   += new EventHandler(OnUpdateReport);
            cbFontSizeLarge.SelectedIndexChanged    += new EventHandler(OnUpdateReport);
            cbHTMLSizeDetail.SelectedIndexChanged   += new EventHandler(OnUpdateReport);
            cbHTMLSizeLarge.SelectedIndexChanged    += new EventHandler(OnUpdateReport);

            UpdateReport();

            // log template path once
            _log.InfoFormat("Using report template = {0}", Reporter.TemplatePath);
        }
Exemple #6
0
        public ReporterPDF(ReportData inputData, ref ReportNode rnRoot
                           , string templatePath, string outputFilePath)
        {
            // absolute output file path
            string absOutputFilePath;

            if (Path.IsPathRooted(outputFilePath))
            {
                absOutputFilePath = outputFilePath;
            }
            else
            {
                absOutputFilePath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), outputFilePath));
            }
            // absolute template path
            string absTemplatePath;

            if (Path.IsPathRooted(templatePath))
            {
                absTemplatePath = templatePath;
            }
            else
            {
                absTemplatePath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), templatePath));
            }

            // does output directory exists
            string outDir = Path.GetDirectoryName(absOutputFilePath);

            if (!Directory.Exists(outDir))
            {
                try { Directory.CreateDirectory(outDir); }
                catch (UnauthorizedAccessException /*ex*/)
                { throw new UnauthorizedAccessException(string.Format("User not allowed to write under {0}", Directory.GetParent(outDir).FullName)); }
                catch (Exception ex)
                { throw new Exception(string.Format("Directory {0} does not exist, and could not be created.", outDir), ex); }
            }
            // html file path
            string htmlFilePath = Path.ChangeExtension(absOutputFilePath, "html");

            BuildAnalysisReport(inputData, ref rnRoot, absTemplatePath, htmlFilePath);

            try
            {
                var ignore = Environment.GetEnvironmentVariable("WKHTMLTOXSHARP_NOBUNDLES");

                if (ignore == null || ignore.ToLower() != "true")
                {
                    // Register all available bundles
                    WkHtmlToXLibrariesManager.Register(new Win32NativeBundle());
                    WkHtmlToXLibrariesManager.Register(new Win64NativeBundle());
                }

                using (IHtmlToPdfConverter converter = new MultiplexingConverter())
                {
                    converter.GlobalSettings.Margin.Top    = "0cm";
                    converter.GlobalSettings.Margin.Bottom = "0cm";
                    converter.GlobalSettings.Margin.Left   = "0cm";
                    converter.GlobalSettings.Margin.Right  = "0cm";
                    converter.GlobalSettings.Orientation   = PdfOrientation.Portrait;
                    converter.GlobalSettings.Size.PageSize = PdfPageSize.A4;

                    converter.ObjectSettings.Page = htmlFilePath;
                    converter.ObjectSettings.Web.EnablePlugins      = true;
                    converter.ObjectSettings.Web.EnableJavascript   = true;
                    converter.ObjectSettings.Web.Background         = true;
                    converter.ObjectSettings.Web.LoadImages         = true;
                    converter.ObjectSettings.Load.LoadErrorHandling = LoadErrorHandlingType.ignore;

                    byte[] bufferPDF = converter.Convert();
                    File.WriteAllBytes(absOutputFilePath, bufferPDF);
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }
Exemple #7
0
 /// <summary>
 /// ReportHtml : generate html report
 /// </summary>
 public ReporterHtml(ReportData inputData, ref ReportNode rnRoot, string templatePath, string outpuFilePath)
 {
     BuildAnalysisReport(inputData, ref rnRoot, templatePath, outpuFilePath);
 }
        public ReporterMSWord(ReportData inputData, ref ReportNode rnRoot
                              , string templatePath, string outputFilePath, Margins margins)
        {
            // absolute output file path
            string absOutputFilePath = string.Empty;

            if (Path.IsPathRooted(outputFilePath))
            {
                absOutputFilePath = outputFilePath;
            }
            else
            {
                absOutputFilePath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), outputFilePath));
            }
            // absolute template path
            string absTemplatePath = string.Empty;

            if (Path.IsPathRooted(templatePath))
            {
                absTemplatePath = templatePath;
            }
            else
            {
                absTemplatePath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), templatePath));
            }

            // does output directory exists
            string outDir = Path.GetDirectoryName(absOutputFilePath);

            if (!Directory.Exists(outDir))
            {
                try { Directory.CreateDirectory(outDir); }
                catch (System.UnauthorizedAccessException /*ex*/)
                { throw new UnauthorizedAccessException(string.Format("User not allowed to write under {0}", Directory.GetParent(outDir).FullName)); }
                catch (Exception ex)
                { throw new Exception(string.Format("Directory {0} does not exist, and could not be created.", outDir), ex); }
            }
            // html file path
            string htmlFilePath = Path.ChangeExtension(absOutputFilePath, "html");

            BuildAnalysisReport(inputData, ref rnRoot, absTemplatePath, htmlFilePath);
            // opens word
            Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
            wordApp.Visible = true;
            Microsoft.Office.Interop.Word.Document wordDoc = wordApp.Documents.Open(htmlFilePath, false, true, NoEncodingDialog: true);
            // embed pictures (unlinking images)
            for (int i = 1; i <= wordDoc.InlineShapes.Count; ++i)
            {
                if (null != wordDoc.InlineShapes[i].LinkFormat && !wordDoc.InlineShapes[i].LinkFormat.SavePictureWithDocument)
                {
                    wordDoc.InlineShapes[i].LinkFormat.SavePictureWithDocument = true;
                }
            }
            // set margins (unit?)
            wordDoc.PageSetup.TopMargin    = wordApp.CentimetersToPoints(margins.Top);
            wordDoc.PageSetup.BottomMargin = wordApp.CentimetersToPoints(margins.Bottom);
            wordDoc.PageSetup.RightMargin  = wordApp.CentimetersToPoints(margins.Right);
            wordDoc.PageSetup.LeftMargin   = wordApp.CentimetersToPoints(margins.Left);
            // set print view
            wordApp.ActiveWindow.ActivePane.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdPrintView;
            wordDoc.SaveAs(absOutputFilePath, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocumentDefault);
            _log.Info(string.Format("Saved doc report to {0}", outputFilePath));
            // wait before deleting image
            int timeBeforeDeletion = Properties.Settings.Default.SleepTimeBeforeImageDeletion;

            System.Threading.Thread.Sleep(timeBeforeDeletion * 1000);
            // delete image directory
            DeleteImageDirectory();
            // delete html report
            File.Delete(htmlFilePath);
        }