Ejemplo n.º 1
0
        public static void GenerateForcesReport(string filename, IEADiagram diagram)
        {
            IReportDocument report = null;

            try
            {
                string filenameExtension = filename.Substring(filename.IndexOf('.'));
                var    saveFileDialog1   = new SaveFileDialog();
                saveFileDialog1.Title       = "SaveDescription report as..";
                saveFileDialog1.Filter      = "Microsoft Excel (*" + filenameExtension + ")|*" + filenameExtension;
                saveFileDialog1.FilterIndex = 0;

                if (saveFileDialog1.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                saveFileDialog1.CheckFileExists = true;
                saveFileDialog1.CheckPathExists = true;
                string reportFilename = saveFileDialog1.FileName;
                report = ReportFactory.Create(ReportType.Excel, reportFilename);
                report.Open();
                if (diagram.IsForcesView())
                {
                    report.InsertForcesTable(new ForcesModel(diagram));
                }
                var customMessage = new ExportReportsCustomMessageBox("Excel", reportFilename);
                customMessage.Show();
            }
            finally
            {
                if (report != null)
                {
                    report.Close();
                }
            }
        }
Ejemplo n.º 2
0
        public static void GenerateReport(IEAPackage decisionViewPackage, string filename, ReportType reportType)
        {
            IEARepository    repository = EAMain.Repository;
            List <IDecision> decisions  =
                decisionViewPackage.GetAllDecisions().Select(element => Decision.Load(element)).ToList();
            List <IEADiagram> diagrams = decisionViewPackage.GetAllDiagrams().ToList();

            IReportDocument report = null;

            try
            {
                string filenameExtension = filename.Substring(filename.IndexOf('.'));
                var    saveFileDialog1   = new SaveFileDialog();
                saveFileDialog1.Title  = Messages.SaveReportAs;
                saveFileDialog1.Filter = "Microsoft " + reportType.ToString() + " (*" + filenameExtension + ")|*" +
                                         filenameExtension;
                saveFileDialog1.FilterIndex = 0;

                if (saveFileDialog1.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                saveFileDialog1.CheckFileExists = true;
                saveFileDialog1.CheckPathExists = true;
                string reportFilename = saveFileDialog1.FileName;
                report = ReportFactory.Create(reportType, reportFilename);
                //if the report cannot be created because is already used by another program a message will appear
                if (report == null)
                {
                    MessageBox.Show("Check if another program is using this file.",
                                    "Fail to create report",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
                report.Open();


                //Insert Decision Relationship Viewpoint
                foreach (IEADiagram diagram in diagrams.Where(diagram => diagram.IsRelationshipView()))
                {
                    report.InsertDiagramImage(diagram);
                }

                //Retrieve Topics
                List <ITopic> topics = (from IEAElement element in repository.GetAllElements()
                                        where EAMain.IsTopic(element)
                                        select Topic.Load(element)).ToList();

                report.InsertDecisionDetailViewMessage();

                // Insert Decisions that have a Topic
                foreach (ITopic topic in topics)
                {
                    report.InsertTopicTable(topic);
                    //Insert Decisions with parent element the current Topic
                    foreach (IDecision decision in decisions)
                    {
                        IEAElement parent = EAMain.Repository.GetElementByGUID(decision.Topic.GUID);
                        if (parent != null && EAMain.IsTopic(parent))
                        {
                            if (parent.GUID.Equals(topic.GUID))
                            {
                                report.InsertDecisionTable(decision);
                            }
                        }
                    }
                }

                // Insert an appropriate message before the decisions that are not included in a topic
                report.InsertDecisionWithoutTopicMessage();

                // Insert decisions without a Topic
                foreach (IDecision decision in decisions)
                {
                    IEAElement parent = EAMain.Repository.GetElementByID(decision.ID).ParentElement;
                    if (parent == null || !EAMain.IsTopic(parent))
                    {
                        report.InsertDecisionTable(decision);
                    }
                }

                foreach (
                    IEADiagram diagram in
                    diagrams.Where(diagram => !diagram.IsForcesView() && !diagram.IsRelationshipView()))
                {
                    report.InsertDiagramImage(diagram);
                }
                foreach (IEADiagram diagram in diagrams.Where(diagram => diagram.IsForcesView()))
                {
                    report.InsertForcesTable(new ForcesModel(diagram));
                }
                var customMessage = new ExportReportsCustomMessageBox(reportType.ToString(), reportFilename);
                customMessage.Show();
            }
            finally
            {
                if (report != null)
                {
                    report.Close();
                }
            }
        }