Пример #1
0
        static void Main(string[] args)
        {
            ILog log = LogManager.GetLogger(typeof(Program));
            XmlConfigurator.Configure();

            try
            {
                // check arguments
                if (args.Length != 1)
                {
                    log.Info("No command argument. Exiting...");
                    return;
                }
                if (!File.Exists(args[0]))
                {
                    log.Info(string.Format("File {0} could not be found. Exiting...", args[0]));
                    return;
                }

                string filePath = args[0];
                // load document
                Document doc = new Document(filePath,  new DocumentListenerLog());
                // get first analysis
                List<CasePalletAnalysis> analyses = doc.Analyses;
                if (analyses.Count == 0)
                {
                    log.Info("Document has no analysis -> Exiting...");
                    return;
                }
                // build output file path
                string outputFilePath = Path.ChangeExtension(Path.GetTempFileName(), "doc");
                string templatePath = @"..\..\..\TreeDim.StackBuilder.Reporting\ReportTemplates\";
                ReporterMSWord reporter = new ReporterMSWord(
                    new ReportData(analyses[0], analyses[0].GetSelSolutionBySolutionIndex(0))
                    , templatePath, outputFilePath, new Margins());
                Console.WriteLine("Saved report to: {0}", outputFilePath);

                // Display resulting report in Word
                Process.Start(new ProcessStartInfo(outputFilePath));
            }
            catch (Exception ex)
            {
                log.Error(ex.ToString());
            }
        }
        private void toolStripButtonReport_Click(object sender, EventArgs e)
        {
            try
            {
                Document doc;
                CasePalletAnalysis analysis;
                CasePalletSolution casePalletSol;
                if (!GenerateProject(out doc, out analysis, out casePalletSol))
                    return;
                SelCasePalletSolution selSolution = new SelCasePalletSolution(doc, analysis, casePalletSol);

                // define report
                FormDefineReport formReport = new FormDefineReport();
                formReport.ProjectName = doc.Name;
                if (DialogResult.OK != formReport.ShowDialog())
                    return;

                Reporter.CompanyLogo = string.Empty;
                Reporter.ImageSizeSetting = Reporter.eImageSize.IMAGESIZE_DEFAULT;
                Reporter reporter;

                ReportData reportData = new ReportData(analysis, selSolution);

                if (formReport.FileExtension == "doc")
                {
                    // create "MS Word" report file
                    reporter = new ReporterMSWord(
                        reportData
                        , Settings.Default.ReportTemplatePath
                        , formReport.FilePath
                        , new Margins());
                }
                else if (formReport.FileExtension == "html")
                {
                    // create "html" report file
                    reporter = new ReporterHtml(
                        reportData
                        , Settings.Default.ReportTemplatePath
                        , formReport.FilePath);
                }
                else
                    return;

                // open file
                if (formReport.OpenGeneratedFile)
                    Process.Start(new ProcessStartInfo(formReport.FilePath));
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
            }
        }
        private void ToolsGenerateReport(object sender, EventArgs e)
        {
            try
            {
                FormDefineReport formReport = new FormDefineReport();
                formReport.ProjectName = _analysis.Name;
                if (DialogResult.OK != formReport.ShowDialog())
                    return;
                // selected solution
                SelCasePalletSolution selSolution = new SelCasePalletSolution(null, _analysis, CurrentSolution);
                ReportData reportData = new ReportData(_analysis, selSolution);

                Reporter.CompanyLogo = string.Empty;
                Reporter.ImageSizeSetting = Reporter.eImageSize.IMAGESIZE_DEFAULT;
                Reporter reporter;
                if (formReport.FileExtension == "doc")
                {
                    // create "MS Word" report file
                    reporter = new ReporterMSWord(
                        reportData
                        , Settings.Default.ReportTemplatePath
                        , formReport.FilePath
                        , new Margins());
                }
                else if (formReport.FileExtension == "html")
                {
                    // create "html" report file
                    reporter = new ReporterHtml(
                        reportData
                        , Settings.Default.ReportTemplatePath
                        , formReport.FilePath);
                }
                else
                    return;

                // open file
                if (formReport.OpenGeneratedFile)
                    Process.Start(new ProcessStartInfo(formReport.FilePath));
            }
            catch (Exception ex)
            { _log.Error(ex.ToString()); }
        }
Пример #4
0
 private void ProcessReportSolution(reportSolution rSol)
 {
     // create document
     Document doc = new Document(rSol.reportParameters.name, rSol.reportParameters.description, rSol.reportParameters.author, DateTime.Now, null);
     // load analysis
     CasePalletAnalysis analysis = LoadPalletAnalysis(doc, rSol.solutionRef.analysisId);
     if (null == analysis)
         return;
     // compute solutions
     TreeDim.StackBuilder.Engine.CasePalletSolver solver = new TreeDim.StackBuilder.Engine.CasePalletSolver();
     solver.ProcessAnalysis(analysis);
     // retrieve wanted solution
     List<Basics.CasePalletSolution> solutions = analysis.Solutions;
     if (rSol.solutionRef.index >= solutions.Count)
         throw new Exception(string.Format("Analysis {0} has no solution with index {1}", analysis.Name, rSol.solutionRef.index));
     Basics.CasePalletSolution sol = solutions[(int)rSol.solutionRef.index];
     // selected solution
     SelCasePalletSolution selSolution = new SelCasePalletSolution(doc, analysis, sol);
     // generate report
     ReporterMSWord reporter = new ReporterMSWord(new ReportData(analysis, selSolution)
         , rSol.reportParameters.templateFilePath, rSol.reportParameters.outputPath, new Margins());
 }
Пример #5
0
 private void DocumentTreeView_SolutionReportNodeClicked(object sender, AnalysisTreeViewEventArgs eventArg)
 {
     try
     {
         // build analysis name
         string analysisName = string.Empty;
         if (null != eventArg.Analysis) analysisName = eventArg.Analysis.Name;
         else if (null != eventArg.PackPalletAnalysis) analysisName = eventArg.PackPalletAnalysis.Name;
         else if (null != eventArg.BoxCaseAnalysis) analysisName = eventArg.BoxCaseAnalysis.Name;
         else if (null != eventArg.BoxCasePalletAnalysis) analysisName = eventArg.BoxCasePalletAnalysis.Name;
         else if (null != eventArg.CylinderAnalysis) analysisName = eventArg.CylinderAnalysis.Name;
         else if (null != eventArg.HCylinderAnalysis) analysisName = eventArg.HCylinderAnalysis.Name;
         else
         {
             _log.Error("Unsupported analysis type ?");
             return;
         }
         // save file dialog
         SaveFileDialog dlg = new SaveFileDialog();
         dlg.InitialDirectory = Properties.Settings.Default.ReportInitialDirectory;
         dlg.FileName = Path.ChangeExtension(CleanString(analysisName), "doc");
         dlg.Filter = Resources.ID_FILTER_MSWORD;
         dlg.DefaultExt = "doc";
         dlg.ValidateNames = true;
         if (DialogResult.OK == dlg.ShowDialog())
         {
             // build output file path
             string outputFilePath = dlg.FileName;
             string htmlFilePath = Path.ChangeExtension(outputFilePath, "html");
             // save directory
             Properties.Settings.Default.ReportInitialDirectory = Path.GetDirectoryName(dlg.FileName);
             // getting current culture
             string cultAbbrev = System.Globalization.CultureInfo.CurrentCulture.ThreeLetterWindowsLanguageName;
             // build report
             ReportData reportObject = new ReportData(
                     eventArg.Analysis, eventArg.SelSolution
                     , eventArg.CylinderAnalysis, eventArg.SelCylinderPalletSolution
                     , eventArg.HCylinderAnalysis, eventArg.SelHCylinderPalletSolution
                     , eventArg.BoxCaseAnalysis, eventArg.SelBoxCaseSolution
                     , eventArg.BoxCasePalletAnalysis, eventArg.SelBoxCasePalletSolution
                     , eventArg.PackPalletAnalysis, eventArg.SelPackPalletSolution
                     );
             Reporter.CompanyLogo = Properties.Settings.Default.CompanyLogoPath;
             Reporter.ImageSizeSetting = (Reporter.eImageSize)Properties.Settings.Default.ReporterImageSize;
             ReporterMSWord reporter = new ReporterMSWord(
                 reportObject
                 , Settings.Default.ReportTemplatePath
                 , dlg.FileName
                 , new Margins());
         }
     }
     catch (System.Runtime.InteropServices.COMException ex)
     {
         _log.Error("MS Word not installed? : "+ ex.Message);
     }
     catch (Exception ex)
     {
         _log.Error(ex.ToString());
     }
 }