예제 #1
0
        public override bool save(string fileName, PressureLossReportData reportData)
        {
            HtmlStreamWriter writer = new HtmlStreamWriter();

            try
            {
                // Check if the xslt file exists

                if (!File.Exists(writer.XsltFileName))
                {
                    string subMsg = ReportResource.xsltFileSubMsg
                                    .Replace("%FULLPATH%", writer.XsltFileName);

                    UIHelperFunctions.postWarning(
                        ReportResource.htmlGenerateTitle,
                        ReportResource.xsltFileMsg, subMsg);

                    return(false);
                }

                PressureLossReportHelper helper = PressureLossReportHelper.instance;
                if (helper == null)
                {
                    return(false);
                }

                //xml head
                writer.WriteStartDocument(false);

                //root node
                string transXML = "UserPressureLossReport";
                writer.WriteStartElement(transXML);

                //title
                writer.WriteElementString("Title", ReportResource.reportName);

                //domain
                if (helper.Domain == ReportResource.pipeDomain)
                {
                    writer.WriteElementString("DomainName", ReportResource.pipeReportName);
                }
                else
                {
                    writer.WriteElementString("DomainName", ReportResource.ductReportName);
                }

                //write project info
                ReportProjectInfo proInfo = new ReportProjectInfo();
                proInfo.writeToHTML(writer);

                //each system
                List <MEPSystem> systems = helper.getSortedSystems();
                if (systems == null || systems.Count < 1)
                {
                    return(false);
                }

                foreach (MEPSystem sysElem in systems)
                {
                    if (sysElem == null)
                    {
                        continue;
                    }

                    //system node
                    string xmlString = "System";
                    writer.WriteStartElement(xmlString);

                    //system info: name and info
                    MEPSystemInfo systemInfo = new MEPSystemInfo(sysElem);
                    systemInfo.writeToHTML(writer);

                    //critical path
                    if (helper.ReportData.DisplayCriticalPath)
                    {
                        string criticalInfo = ReportResource.criticalPath + " : " + MEPSystemInfo.getCriticalPath(sysElem);
                        criticalInfo += " ; " + ReportResource.totalPressureLoss + " : " + MEPSystemInfo.getCriticalPathPressureLoss(sysElem);
                        writer.WriteElementString("CriticalPath", criticalInfo);
                    }

                    List <MEPSection> sections = new List <MEPSection>();
                    MEPSystemInfo.getSectionsFromSystem(sysElem, sections);

                    //sections: title and info
                    SectionsInfo sectionInfo = new SectionsInfo(sections);
                    sectionInfo.writeToHTML(writer);

                    //segments: title and info
                    SegmentsInfo segmentsInfo = new SegmentsInfo(sections);
                    segmentsInfo.writeToHTML(writer);

                    //fittings: title and info
                    FittingsInfo fittingsInfo = new FittingsInfo(sections);
                    fittingsInfo.writeToHTML(writer);

                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
                writer.WriteEndDocument();

                writer.Save(fileName);
                return(true);
            }
            catch
            {
                writer.Close();
                //delete xml
                File.Delete(writer.XmlFileName);
                UIHelperFunctions.postWarning(ReportResource.htmlGenerateTitle, ReportResource.htmlMsg);
                return(false);
            }
        }
예제 #2
0
        // TODO
        public override bool save(string fileName, PressureLossReportData reportData)
        {
            try
            {
                PressureLossReportHelper helper = PressureLossReportHelper.instance;
                CsvStreamWriter          writer = new CsvStreamWriter();

                //title
                string strTitle = ReportResource.reportName;
                if (helper.Domain == ReportResource.pipeDomain)
                {
                    strTitle = ReportResource.pipeReportName;
                }
                else
                {
                    strTitle = ReportResource.ductReportName;
                }

                DataTable titleTB = new DataTable();
                titleTB.Columns.Add();
                titleTB.Rows.Add(strTitle);
                writer.AddData(titleTB, 1);
                writer.addOneEmptyRow();

                DataTable tbTitle = new DataTable();
                DataTable tb      = new DataTable();

                //Project info
                ReportProjectInfo proInfo = new ReportProjectInfo();
                proInfo.writeToCsv(writer);

                writer.addOneEmptyRow();

                //each system
                List <MEPSystem> systems = helper.getSortedSystems();
                if (systems == null || systems.Count < 1)
                {
                    return(false);
                }
                foreach (MEPSystem sysElem in systems)
                {
                    if (sysElem == null)
                    {
                        continue;
                    }

                    //system name and info
                    MEPSystemInfo systemInfo = new MEPSystemInfo(sysElem);
                    systemInfo.writeToCsv(writer);

                    if (systemInfo.needToWrite())
                    {
                        writer.addOneEmptyRow();
                    }

                    List <MEPSection> sections = new List <MEPSection>();
                    MEPSystemInfo.getSectionsFromSystem(sysElem, sections);

                    //sections: title and info
                    SectionsInfo sectionInfo = new SectionsInfo(sections);
                    sectionInfo.writeToCsv(writer);

                    if (reportData.DisplayCriticalPath)
                    {
                        string criticalInfo = ReportResource.criticalPath + " : " + MEPSystemInfo.getCriticalPath(sysElem);
                        criticalInfo += " ; " + ReportResource.totalPressureLoss + " : " + MEPSystemInfo.getCriticalPathPressureLoss(sysElem);

                        writer.addTitleRow(criticalInfo);
                    }

                    writer.addOneEmptyRow();

                    //segments: title and info
                    SegmentsInfo segmentsInfo = new SegmentsInfo(sections);
                    segmentsInfo.writeToCsv(writer);
                    if (segmentsInfo.needToWrite())
                    {
                        writer.addOneEmptyRow();
                    }

                    //fittings: title and info
                    FittingsInfo fittingsInfo = new FittingsInfo(sections);
                    fittingsInfo.writeToCsv(writer);
                    if (fittingsInfo.needToWrite())
                    {
                        writer.addOneEmptyRow();
                    }
                }

                writer.Save(fileName);
                return(true);
            }
            catch (Exception e)
            {
                if (e.Message == ReportConstants.failed_to_delete)
                {
                    string subMsg = ReportResource.csvSubMsg.Replace("%FULLPATH%", fileName);
                    UIHelperFunctions.postWarning(ReportResource.csvGenerateTitle, ReportResource.csvMsg, subMsg);
                }
                else
                {
                    UIHelperFunctions.postWarning(ReportResource.csvGenerateTitle, ReportResource.csvMsg);
                }
                return(false);
            }
        }