コード例 #1
0
ファイル: Utils.cs プロジェクト: dioptre/nkd
 public void Fill(TableReport report)
 {
     IDataAdapter ad = report.DataAdapter as IDataAdapter;
     DataSet ds = report.DataSource as DataSet;
     if (ad != null && ds != null)
         ad.Fill(ds);
 }
コード例 #2
0
        /// <summary>
        /// 功能:响应导出Excel文件事件
        /// 作者:付强
        /// 日期:2013年7月9日
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void printPreviewBarCheckItem5_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.FileName = this.m_reportData.ToString();

            if (e.Item.Name.Equals(this.printPreviewBarCheckItem13.Name))
            {
                sfd.Filter = "Excel 2003文件(*.xls)|*.xls";
            }
            else
            {
                sfd.Filter = "Excel 2007文件(*.xlsx)|*.xlsx";
            }
            sfd.FilterIndex      = 1;
            sfd.RestoreDirectory = true;
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                string localFilePath = sfd.FileName.ToString();
                string fileNameExt   = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1);
                try
                {
                    TableReport tReport = this.m_reportData as TableReport;
                    if (tReport != null)
                    {
                        ExportExcel(localFilePath, tReport);
                    }
                    else
                    {
                        if (localFilePath.EndsWith(".xls"))
                        {
                            this.m_report.ExportToXls(localFilePath);
                        }
                        else
                        {
                            this.m_report.ExportToXlsx(localFilePath);
                        }
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("发生未知异常,请重试", "金建软件");
                }

                /*PageReport pReport = this.m_reportData as PageReport;
                 * if (pReport != null)
                 * {
                 *  ExportExcel(localFilePath, pReport);
                 * }
                 *
                 * ExplainReport eReport = this.m_reportData as ExplainReport;
                 * if (eReport != null)
                 * {
                 *  ExportExcel(localFilePath, eReport);
                 * }*/
            }
        }
コード例 #3
0
                public void Fill(TableReport report)
                {
                    IDataAdapter ad = report.DataAdapter as IDataAdapter;
                    DataSet      ds = report.DataSource as DataSet;

                    if (ad != null && ds != null)
                    {
                        ad.Fill(ds);
                    }
                }
コード例 #4
0
        public static string GenerateReport(TableReport report)
        {
            ClearReports();
            string timeStamp = DateTime.Now.ToString("yyyyMMddHH");
            string fileName  = SystemConstants.TempReportFolder + timeStamp + Guid.NewGuid() + ".rdlc";

            var content = report.Render();

            File.WriteAllText(fileName, report.Render());

            return(fileName);
        }
コード例 #5
0
        /// <summary>
        /// 创建表格
        /// </summary>
        /// <param name="rpf">报表个字段格式</param>
        /// <param name="rowHeight"></param>
        /// <param name="border"></param>
        /// <returns></returns>
        private DetailBand CreateTableDetail(TableReport p_info)
        {
            DetailBand new_Detail = new DetailBand();

            if (p_info.ReportFields != null)
            {
                XRTable tableDetail = new XRTable();
                tableDetail.Dpi    = 254F;
                tableDetail.Width  = this.PageWidth - (this.Margins.Left + this.Margins.Right) - 4;
                tableDetail.Height = 56;
                XRTableRow detailRow = new XRTableRow();
                detailRow.Dpi    = 254F;
                detailRow.Height = 56;

                foreach (FieldReport item in p_info.ReportFields)
                {
                    XRTableCell detailCell = new XRTableCell();
                    detailCell.Dpi   = 254F;
                    detailCell.Font  = item.FormFont;
                    detailCell.Width = item.RowWidth;
                    if (item.Field != null)
                    {
                        detailCell.DataBindings.Add("Text", null, item.Field);
                    }
                    detailCell.TextAlignment = this.Alignments(item.ContentAlignment);
                    detailCell.Padding       = new PaddingInfo(5, 254F);
                    detailCell.Multiline     = true;
                    detailCell.WordWrap      = true;
                    detailCell.CanGrow       = true;
                    detailCell.Borders       = (BorderSide)(BorderSide.Right | BorderSide.Left | BorderSide.Bottom);
                    detailCell.BorderWidth   = 1;
                    detailRow.Cells.Add(detailCell);
                }
                tableDetail.Rows.Add(detailRow);

                XRTableRow m_Row = (tableDetail.Controls[0] as XRTableRow);
                for (int i = 0; i < m_Row.Controls.Count; i++)
                {
                    XRTableCell m_Cell = (m_Row.Controls[i] as XRTableCell);
                    m_Cell.WidthF = m_Cell.Width;
                    p_info.ReportFields[i].RowWidth = m_Cell.Width;
                }
                tableDetail.WidthF = tableDetail.Width;
                new_Detail.Controls.Add(tableDetail);
            }
            new_Detail.HeightF = 0;
            return(new_Detail);
        }
コード例 #6
0
        /// <summary>
        /// 初始化报表
        /// </summary>
        /// <param name="p_info">报表格式对象</param>
        public GenerateReport(_ObjectReport p_info)
        {
            this.ReportUnit = ReportUnit.TenthsOfAMillimeter; //使用0.1毫米计量单位
            this.Dpi        = 254F;
            this.Bands.Clear();
            if (p_info != null)
            {
                switch (p_info.GetType().Name)
                {
                case "TableReport":
                    TableReport m_info = p_info as TableReport;
                    this.DataSource = m_info.DataSource;
                    this.Margins    = m_info.Margins;
                    this.PaperKind  = m_info.PaperKind;
                    this.Landscape  = this.IsDirection(m_info.Landscape);
                    DetailBand     new_Detail         = CreateTableDetail(m_info);
                    PageHeaderBand new_PageHeaderBand = CreateTableHeader(m_info);
                    this.Bands.AddRange(new DevExpress.XtraReports.UI.Band[] { new_PageHeaderBand, new_Detail });
                    break;

                case "PageReport":
                    PageReport m_pinfo = p_info as PageReport;
                    this.Margins   = m_pinfo.Margins;
                    this.PaperKind = m_pinfo.PaperKind;
                    this.Landscape = this.IsDirection(m_pinfo.Landscape);
                    DetailBand new_pDetail = this.CreateRowDetail(m_pinfo);
                    this.Bands.AddRange(new DevExpress.XtraReports.UI.Band[] { new_pDetail });
                    break;

                case "ExplainReport":
                    ExplainReport m_ExplainReport = p_info as ExplainReport;
                    this.Margins    = m_ExplainReport.Margins;
                    this.PaperKind  = m_ExplainReport.PaperKind;
                    this.DataSource = null;
                    this.Landscape  = this.IsDirection(m_ExplainReport.Landscape);
                    DetailBand     new_EDetail = this.CreateRowDetail(m_ExplainReport);
                    PageHeaderBand new_ExplainPageHeaderBand = CreateTitleHeader(m_ExplainReport);
                    this.Bands.AddRange(new DevExpress.XtraReports.UI.Band[] { new_ExplainPageHeaderBand, new_EDetail });
                    break;

                default:
                    break;
                }
            }
        }
コード例 #7
0
ファイル: MReportnew.cs プロジェクト: baoho1703/Tai-Nguyen
        public List <TableReport> GetDataReport(AccountCookie accountCookie)
        {
            List <TableReport>       tableReports     = new List <TableReport>();
            tongcuclamnghiepEntities tongcuclamnghiep = new tongcuclamnghiepEntities();
            var _Unit     = tongcuclamnghiep.m_unit.Where(a => a.status == true && a.account_id == accountCookie.Id).FirstOrDefault();
            var _Precious = tongcuclamnghiep.m_precious.Where(a => a.status == false).FirstOrDefault();

            if (_Precious != null && _Unit != null)
            {
                bool CheckView     = true;
                var  _UnitPrecious = tongcuclamnghiep.m_unit_precious.Where(a => a.unit_id == _Unit.id && a.precious_id == _Precious.id).FirstOrDefault();
                if (_UnitPrecious != null)
                {
                    if (_UnitPrecious.completedate != null)
                    {
                        CheckView = false;
                    }
                }
                if (CheckView == true)
                {
                    int Precious_Id_Before = 0;
                    int UnitPrecious_Id    = 0;
                    if (tongcuclamnghiep.m_precious.Any(a => a.status == false && a.id != _Precious.id))
                    {
                        Precious_Id_Before = tongcuclamnghiep.m_precious.Where(a => a.status == true && a.id != _Precious.id).OrderByDescending(a => a.completedate).Select(a => a.id).FirstOrDefault();
                    }
                    if (_UnitPrecious != null)
                    {
                        UnitPrecious_Id = tongcuclamnghiep.m_unit_precious.Where(a => a.unit_id == _Unit.id && a.precious_id == Precious_Id_Before).Select(a => a.id).FirstOrDefault();
                    }
                    tongcuclamnghiep.m_reporttable.Where(a => a.status == true).OrderBy(a => a.order).ToList().ForEach(a =>
                    {
                        TableReport tableReport        = new TableReport();
                        tableReport.IdBaoCao           = a.id;
                        tableReport.Title              = a.title;
                        tableReport.Order              = a.order.Value;
                        tableReport.AutoRow            = a.autorow.Value;
                        List <HeaderComponent> headers = new List <HeaderComponent>();
                        tongcuclamnghiep.m_header.Where(b => a.status == true && b.reporttable_id == a.id).OrderBy(b => b.order).ToList().ForEach(b =>
                        {
                            HeaderComponent header = new HeaderComponent();
                            header.Id           = b.id;
                            header.Title        = b.headername;
                            header.RowSpan      = b.rowspan.Value;
                            header.ColSpan      = b.colspan.Value;
                            header.HeaderId     = b.header_id;
                            header.Level        = b.level;
                            header.Is_No        = b.is_no;
                            header.Is_Component = b.is_component;
                            header.OrderHeader  = b.order.Value;
                            headers.Add(header);
                        });
                        tableReport.headers = headers.OrderBy(b => b.Level).ThenBy(b => b.OrderHeader).ToList();
                        List <TableComponent> tableComponents = new List <TableComponent>();
                        a.m_component.Where(b => b.status == true).GroupBy(b => b.orderrow).ToList().ForEach(b =>
                        {
                            TableComponent tableComponent           = new TableComponent();
                            tableComponent.RowId                    = b.Key.Value;
                            List <HeaderComponent> headerComponents = new List <HeaderComponent>();
                            tableReport.headers.ForEach(c => {
                                var _CPM = tongcuclamnghiep.m_component.Where(d => d.header_id == c.Id && d.orderrow == b.Key).FirstOrDefault();
                                if (_CPM != null)
                                {
                                    HeaderComponent header = new HeaderComponent();
                                    header.Id          = _CPM.id;
                                    header.OrderHeader = c.OrderHeader;
                                    header.HeaderId    = _CPM.header_id;
                                    header.TextAlign   = _CPM.m_header.valuetextalign;
                                    header.TextBold    = _CPM.m_header.is_valuebold.Value;
                                    header.TextUpper   = _CPM.m_header.is_valueupper.Value;
                                    header.TextValue   = _CPM.componentname;
                                    header.Title       = _CPM.m_header.headername;
                                    header.TypeValue   = _CPM.typevalue.Value;
                                    header.Is_No       = _CPM.m_header.is_no;
                                    if (_UnitPrecious == null)
                                    {
                                        header.Save = false;
                                        if (Precious_Id_Before > 0 && UnitPrecious_Id > 0)
                                        {
                                            var _dataUnitReportBefore = tongcuclamnghiep.m_unit_datareport.Where(d => d.component_id == _CPM.id && d.unit_precious_id == UnitPrecious_Id).FirstOrDefault();
                                            if (_dataUnitReportBefore == null)
                                            {
                                                header.TextUnit = "";
                                            }
                                            else
                                            {
                                                header.TextUnit = _dataUnitReportBefore.data_text;
                                            }
                                        }
                                        else
                                        {
                                            header.TextUnit = "";
                                        }
                                    }
                                    else
                                    {
                                        var _dataUnitReport = _CPM.m_unit_datareport.Where(d => d.unit_precious_id == _UnitPrecious.id).FirstOrDefault();
                                        if (_dataUnitReport == null)
                                        {
                                            header.Save = false;
                                            if (Precious_Id_Before > 0 && UnitPrecious_Id > 0)
                                            {
                                                var _dataUnitReportBefore = tongcuclamnghiep.m_unit_datareport.Where(d => d.component_id == _CPM.id && d.unit_precious_id == UnitPrecious_Id).FirstOrDefault();
                                                if (_dataUnitReportBefore == null)
                                                {
                                                    header.TextUnit = "";
                                                }
                                                else
                                                {
                                                    header.TextUnit = _dataUnitReportBefore.data_text;
                                                }
                                            }
                                            else
                                            {
                                                header.TextUnit = "";
                                            }
                                        }
                                        else
                                        {
                                            header.Save     = true;
                                            header.TextUnit = _dataUnitReport.data_text;
                                        }
                                    }

                                    header.Is_Component = _CPM.m_header.is_component;
                                    headerComponents.Add(header);
                                }
                            });
                            tableComponent.headers = headerComponents;

                            tableComponents.Add(tableComponent);
                        });
                        tableReport.tableComponents = tableComponents;

                        tableReports.Add(tableReport);
                    });
                }
            }
            return(tableReports);
        }
コード例 #8
0
        private static void DisplayGeneratorExamples()
        {
            bool exitToProducts = false;

            while (!exitToProducts)
            {
                Console.WriteLine("Select a DynamicPDF Generator for .NET example to run:");
                Console.WriteLine(" A : Hello World");
                Console.WriteLine(" B : All Page Elements");
                Console.WriteLine(" C : Calender");
                Console.WriteLine(" D : Charting");
                Console.WriteLine(" E : Contact List");
                Console.WriteLine(" F : AES 256 Bit Encryption");
                Console.WriteLine(" G : RC4 128 Bit Encryption");
                Console.WriteLine(" H : Hello World Languages");
                Console.WriteLine(" I : Tagged Pdf");
                Console.WriteLine(" J : HTML Tags");
                Console.WriteLine(" K : HTML Tags With Styles");
                Console.WriteLine(" L : HTML Layout");
                Console.WriteLine(" M : Image With Alternate Text");
                Console.WriteLine(" N : Mailing Labels");
                Console.WriteLine(" O : Package PDF");
                Console.WriteLine(" P : Simple Report");
                Console.WriteLine(" Q : Simple XML Report");
                Console.WriteLine(" R : Table Report");
                Console.WriteLine(" S : Tagged PDF With Structure Elements");
                Console.WriteLine(" T : Tiff To PDF");
                Console.WriteLine(" U : Time Machine");
                Console.WriteLine(" V : Time Machine Tagged PDF");
                Console.WriteLine(" W : Watermark");
                Console.WriteLine(" X : Invoice");
                Console.WriteLine(" Y : USEnvelope");
                Console.WriteLine();
                Console.WriteLine("Press 'Backspace' for the main products menu");
                Console.WriteLine("Press 'Esc' to exit application");
                Console.WriteLine();
                ConsoleKeyInfo runKey = Console.ReadKey();
                Console.WriteLine();

                string exampleName = string.Empty;
                string fileName    = string.Empty;
                switch (runKey.Key)
                {
                case ConsoleKey.A:
                    exampleName = "Hello World";
                    fileName    = "HelloWorld.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    HelloWorld.Run(fileName);
                    break;

                case ConsoleKey.B:
                    exampleName = "All Page Elements";
                    fileName    = "AllPageElements.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    AllPageElements.Run(fileName);
                    break;

                case ConsoleKey.C:
                    exampleName = "Calender";
                    fileName    = "Calender.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    Calender.Run(fileName);
                    break;

                case ConsoleKey.D:
                    exampleName = "Charting";
                    fileName    = "Charting.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    Charting.Run(fileName);
                    break;

                case ConsoleKey.E:
                    exampleName = "Contact List";
                    fileName    = "ContactList.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    ContactList.Run(fileName);
                    break;

                case ConsoleKey.F:
                    Console.Clear();
                    exampleName = "AES 256 Bit Encryption";
                    fileName    = "Aes256BitEncryption.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    Aes256BitEncryption.Run(fileName);
                    break;

                case ConsoleKey.G:
                    exampleName = "RC4 128 Bit Encryption";
                    fileName    = "RC4128BitEncryption.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    RC4128BitEncryption.Run(fileName);
                    break;

                case ConsoleKey.H:
                    exampleName = "Hello World Languages";
                    fileName    = "HelloWorldLanguages.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    HelloWorldLanguages.Run(fileName);
                    break;

                case ConsoleKey.I:
                    exampleName = "Tagged PDF";
                    fileName    = "TaggedPdf.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    TaggedPdf.Run(fileName);
                    break;

                case ConsoleKey.J:
                    exampleName = "HTML Tags";
                    fileName    = "HtmlTags.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    HtmlAreaPDF.Run_WithHtmlTags(fileName);
                    break;

                case ConsoleKey.K:
                    exampleName = "HTML Tags With Styles";
                    fileName    = "HtmlTagsWithStyles.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    HtmlAreaPDF.Run_WithHtmlTagsAndStyles(fileName);
                    break;

                case ConsoleKey.L:
                    exampleName = "HTML Layout";
                    fileName    = "HtmlLayout.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    HtmlLayoutPDF.Run(fileName);
                    break;

                case ConsoleKey.M:
                    exampleName = "Image With Alternate Text";
                    fileName    = "ImageWithAltText.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    AltTextImage.Run(fileName);
                    break;

                case ConsoleKey.N:
                    exampleName = "Mailing Labels";
                    fileName    = "MailingLabels.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    MailingLabels.Run(fileName);
                    break;

                case ConsoleKey.O:
                    exampleName = "Package PDF";
                    fileName    = "PackagePdf.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    PackagePdf.Run(fileName);
                    break;

                case ConsoleKey.P:
                    exampleName = "Simple Report";
                    fileName    = "SimpleReport.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    SimpleReport.Run(fileName);
                    break;

                case ConsoleKey.Q:
                    exampleName = "Simple XML Report";
                    fileName    = "SimpleXmlReport.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    SimpleXMLReport.Run(fileName);
                    break;

                case ConsoleKey.R:
                    exampleName = "Table Report";
                    fileName    = "TableReport.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    TableReport.Run(fileName);
                    break;

                case ConsoleKey.S:
                    exampleName = "Tagged PDF With Structure Elements";
                    fileName    = "TaggedPdfWithStructureElements.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    TaggedPdfWithStructureElements.Run(fileName);
                    break;

                case ConsoleKey.T:
                    exampleName = "Tiff To PDF";
                    fileName    = "TiffToPdf.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    TiffToPdf.Run(fileName);
                    break;

                case ConsoleKey.U:
                    exampleName = "Time Machine";
                    fileName    = "TimeMachine.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    TimeMachine.Run(fileName);
                    break;

                case ConsoleKey.V:
                    exampleName = "Time Machine Tagged PDF";
                    fileName    = "TimeMachineTaggedPdf.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    TimeMachineTaggedPdf.Run(fileName);
                    break;

                case ConsoleKey.W:
                    exampleName = "Watermark";
                    fileName    = "Watermark.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    Watermark.Run(fileName);
                    break;

                case ConsoleKey.X:
                    exampleName = "Invoice";
                    fileName    = "Invoice.pdf";
                    Console.WriteLine("Please enter the invoice number(s) to include. Use a comma ',' to seperate multiple entries (Ex: 10248,10249,10250):");
                    Console.WriteLine();
                    Console.WriteLine("10248");
                    Console.WriteLine("10249");
                    Console.WriteLine("10250");
                    Console.WriteLine("10251");
                    Console.WriteLine("10252");
                    Console.WriteLine("10360");
                    Console.WriteLine("10979");
                    Console.WriteLine("11077");
                    Console.WriteLine();
                    string invoiceNumbers = Console.ReadLine();
                    Console.WriteLine(exampleName + " example is running...");
                    byte[] pdf = GeneratorInvoice.Run(invoiceNumbers.Split(','));
                    File.WriteAllBytes(fileName, pdf);
                    break;

                case ConsoleKey.Y:
                    exampleName = "USEnvelope";
                    fileName    = "USEnvelope.pdf";
                    Console.WriteLine(exampleName + " example is running...");
                    USEnvelope.Run(fileName);
                    break;

                case ConsoleKey.Escape:
                    System.Environment.Exit(0);
                    break;

                case ConsoleKey.Backspace:
                    exitToProducts = true;
                    break;

                default:
                    Console.WriteLine();
                    Console.WriteLine("Key not recognized.");
                    break;
                }
                if (fileName != string.Empty)
                {
                    DisplayOutputPathWithOptionToOpen(fileName);
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// 功能:导出Excel表格
        /// 作者:付强
        /// 日期:2013年7月9日
        /// </summary>
        /// <param name="fileName">要保存的文件路径及名称</param>
        /// <param name="reportSource">数据源</param>
        private void ExportExcel(string fileName, TableReport reportSource)
        {
            Microsoft.Office.Interop.Excel._Application xlsApp = new ApplicationClass();
            if (xlsApp == null)
            {
                return;
            }
            Workbook  xlsBook = xlsApp.Workbooks.Add(true);
            Worksheet xlSheet = (Worksheet)xlsBook.Worksheets[1];

            xlSheet.Cells[1, 1] = reportSource.ReportName;
            Range range = xlSheet.get_Range(xlsApp.Cells[1, 1], xlsApp.Cells[1, reportSource.ReportFields.Length]);

            range.MergeCells          = true;
            range.Font.Size           = 24;
            range.Font.Bold           = true;
            range.HorizontalAlignment = XlHAlign.xlHAlignCenter;

            if (!string.IsNullOrEmpty(reportSource.XMMC))
            {
                xlSheet.Cells[2, 1] = "项目名称:" + reportSource.XMMC;
                range                     = xlSheet.get_Range(xlsApp.Cells[2, 1], xlsApp.Cells[2, 2]);
                range.MergeCells          = true;
                range.HorizontalAlignment = XlHAlign.xlHAlignLeft;
            }
            if (!string.IsNullOrEmpty(reportSource.ZYMC))
            {
                xlSheet.Cells[2, 3] = "专业名称:" + reportSource.ZYMC;

                range                     = xlSheet.get_Range(xlsApp.Cells[2, 3], xlsApp.Cells[2, reportSource.ReportFields.Length]);
                range.MergeCells          = true;
                range.HorizontalAlignment = XlHAlign.xlHAlignRight;
            }


            System.Data.DataTable dt = reportSource.DataSource as System.Data.DataTable;

            int    rowSpan = 3, colSpan = 0, position = 0;
            string band = "";

            for (int i = 0; i < reportSource.ReportFields.Length; i++)
            {
                FieldReport item = reportSource.ReportFields[i];
                if (item.Bands.Equals(string.Empty))
                {
                    //xlSheet.Cells[rowSpan + 1, i + 1] = item.Caption;
                    range = xlSheet.get_Range(xlsApp.Cells[rowSpan, i + 1], xlsApp.Cells[rowSpan + 1, i + 1]);
                    range.Borders.LineStyle       = XlLineStyle.xlContinuous;
                    range.MergeCells              = true;
                    xlSheet.Cells[rowSpan, i + 1] = item.Caption;
                    range.Font.Bold           = true;
                    range.Borders.LineStyle   = XlLineStyle.xlContinuous;
                    range.HorizontalAlignment = XlHAlign.xlHAlignCenter;
                    range.ColumnWidth         = item.RowWidth / 15;

                    position += 1;
                    colSpan   = 0;
                }
                else
                {
                    if (!band.Equals(item.Bands))
                    {
                        position += colSpan;
                        colSpan   = 0;
                    }

                    //xlSheet.Cells[rowSpan, i + 1] = item.Bands;
                    range                                = (Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[rowSpan, i + 1];
                    range.Font.Bold                      = true;
                    range.HorizontalAlignment            = XlHAlign.xlHAlignCenter;
                    range                                = xlSheet.get_Range(xlsApp.Cells[rowSpan, position + 1], xlsApp.Cells[rowSpan, position + 1 + colSpan]);
                    range.MergeCells                     = true;
                    xlSheet.Cells[rowSpan, position + 1] = item.Bands;

                    range.Borders.LineStyle = XlLineStyle.xlContinuous;
                    range.EntireColumn.AutoFit();
                    xlSheet.Cells[rowSpan + 1, i + 1] = item.Caption;
                    range                     = (Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[rowSpan + 1, i + 1];
                    range.Font.Bold           = true;
                    range.HorizontalAlignment = XlHAlign.xlHAlignCenter;
                    range.Borders.LineStyle   = XlLineStyle.xlContinuous;
                    range.ColumnWidth         = item.RowWidth / 15;

                    colSpan++;
                    band = item.Bands;
                }
            }

            for (int r = 0; r < dt.Rows.Count; r++)
            {
                if (reportSource.ReportFields.Length >= dt.Columns.Count)
                {
                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        if (dt.Columns[i].ColumnName.Equals("XMBM"))
                        {
                            xlSheet.Cells[r + 5, i + 1] = "'" + dt.Rows[r][i].ToString();
                        }
                        else
                        {
                            xlSheet.Cells[r + 5, i + 1] = dt.Rows[r][i].ToString();
                        }
                        range = xlSheet.get_Range(xlsApp.Cells[r + 5, i + 1], xlsApp.Cells[r + 5, i + 1]);
                        range.Borders.LineStyle = XlLineStyle.xlContinuous;
                    }
                }
                else
                {
                    for (int i = 0; i < dt.Columns.Count - (dt.Columns.Count - reportSource.ReportFields.Length); i++)
                    {
                        xlSheet.Cells[r + 5, i + 1] = dt.Rows[r][i].ToString();
                        range = xlSheet.get_Range(xlsApp.Cells[r + 5, i + 1], xlsApp.Cells[r + 5, i + 1]);
                        range.Borders.LineStyle = XlLineStyle.xlContinuous;
                    }
                }
            }
            xlsBook.Saved = true;
            xlsBook.SaveCopyAs(fileName);
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: scalablecory/GitHubIssues
    static ErrorCode Main_Internal(string[] args)
    {
        try
        {
            if ((args.Length == 0) ||
                Parser.IsOption(args[0], _helpOptions) ||
                _helpActions.ContainsIgnoreCase(args[0]))
            {   // Print help
                PrintUsage();
                return((int)ErrorCode.Success);
            }

            if ((args.Length == 1) && args[0].StartsWith("@"))
            {
                args = System.IO.File.ReadLines(args[0].Substring(1)).ToArray();
            }

            // Parse first 'action' argument
            string        actionArg = args[0];
            ActionCommand action    = 0;
            {
                bool isValidActionArg = false;
                foreach (ActionCommand actionCommand in Enum.GetValues(typeof(ActionCommand)))
                {
                    if (actionArg.Equals(actionCommand.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        action           = actionCommand;
                        isValidActionArg = true;
                        break;
                    }
                }
                if (!isValidActionArg)
                {
                    ReportError($"Error: unrecognized action '{actionArg}' - command line argument #1");
                    return(ErrorCode.InvalidCommand);
                }
            }

            Parser optionsParser = new Parser(
                args.Skip(1).ToArray(),
                PrintUsage);

            switch (action)
            {
            case ActionCommand.cache:
            {
                if (!optionsParser.Parse(
                        new Option[] { _configOption, _prefixOption },
                        new Option[] { _authenticationTokenOption, _commentsPrefixOption }))
                {
                    return(ErrorCode.InvalidCommand);
                }
                IEnumerable <string> configFiles = _configOption.GetValues(optionsParser);
                string filePrefix = _prefixOption.GetValue(optionsParser);
                // Optional args
                string authenticationToken = _authenticationTokenOption.GetValue(optionsParser);
                string commentsFilePrefix  = _commentsPrefixOption.GetValue(optionsParser);

                return(CacheGitHubIssues(configFiles, filePrefix, commentsFilePrefix, authenticationToken));
            }

            case ActionCommand.cacheRange:
            {
                if (!optionsParser.Parse(
                        new Option[] { _configOption, _prefixOption, _startIndexOption, _endIndexOption },
                        new Option[] { _authenticationTokenOption, _commentsPrefixOption }))
                {
                    return(ErrorCode.InvalidCommand);
                }
                IEnumerable <string> configFiles = _configOption.GetValues(optionsParser);
                string filePrefix = _prefixOption.GetValue(optionsParser);
                int    startIndex = Int32.Parse(_startIndexOption.GetValue(optionsParser));
                int    endIndex   = Int32.Parse(_endIndexOption.GetValue(optionsParser));
                // Optional args
                string authenticationToken = _authenticationTokenOption.GetValue(optionsParser);

                if (startIndex <= 0)
                {
                    optionsParser.ReportError($"Option /startIndex has to be positive number.");
                    return(ErrorCode.InvalidCommand);
                }
                if (endIndex < startIndex)
                {
                    optionsParser.ReportError($"Option /endIndex has to larger than /startIndex.");
                    return(ErrorCode.InvalidCommand);
                }

                return(CacheGitHubIssuesRange(
                           configFiles,
                           filePrefix,
                           startIndex,
                           endIndex,
                           authenticationToken));
            }

            case ActionCommand.query:
            {
                if (!optionsParser.Parse(
                        new Option[] { _configOption, _endOption, _outputOption },
                        new Option[] { _beginOption, _outputJsonOption }))
                {
                    return(ErrorCode.InvalidCommand);
                }
                IEnumerable <string> configFiles = _configOption.GetValues(optionsParser);
                IEnumerable <string> beginFiles  = _beginOption.GetValues(optionsParser);
                IEnumerable <string> endFiles    = _endOption.GetValues(optionsParser);
                string outputJsonFile            = _outputJsonOption.GetValue(optionsParser);
                string outputFile = _outputOption.GetValue(optionsParser);

                Config      config = new Config(configFiles);
                QueryReport report = new QueryReport(config, beginFiles, endFiles);
                report.Write(outputFile, outputJsonFile);
                return(ErrorCode.Success);
            }

            case ActionCommand.report:
            {
                if (!optionsParser.Parse(
                        new Option[] { _configOption, _endOption },
                        new Option[] { _beginOption, _middleOption, _outputOption, _outputCsvOption, _nameOption }))
                {
                    return(ErrorCode.InvalidCommand);
                }
                IEnumerable <string> configFiles = _configOption.GetValues(optionsParser);
                IEnumerable <string> beginFiles  = _beginOption.GetValues(optionsParser);
                IEnumerable <string> middleFiles = _middleOption.GetValues(optionsParser);
                IEnumerable <string> endFiles    = _endOption.GetValues(optionsParser);

                string outputFile        = _outputOption.GetValue(optionsParser);
                string csvFileNamePrefix = _outputCsvOption.GetValue(optionsParser);
                string reportName        = _nameOption.GetValue(optionsParser);

                if ((outputFile == null) && (csvFileNamePrefix == null))
                {
                    optionsParser.ReportError("Required at least one option: '/out' or '/out_csv'.");
                    return(ErrorCode.InvalidCommand);
                }
                if ((csvFileNamePrefix != null) &&
                    csvFileNamePrefix.EndsWith(".csv", StringComparison.OrdinalIgnoreCase))
                {
                    optionsParser.ReportError($"Option '/out_csv' takes file name prefix, not file name {csvFileNamePrefix}.");
                    return(ErrorCode.InvalidCommand);
                }

                TableReport report = new TableReport(configFiles, beginFiles, middleFiles, endFiles);
                if (outputFile != null)
                {
                    HtmlTableReport.Write(report, outputFile, reportName);
                }
                // Note we can have both options
                if (csvFileNamePrefix != null)
                {
                    CsvTableReport.Write(report, csvFileNamePrefix, reportName);
                }
                return(ErrorCode.Success);
            }

            case ActionCommand.contributions:
            {
                if (!optionsParser.Parse(
                        new Option[] { _configOption, _inputOption },
                        new Option[] { _outputOption, _outputCsvOption }))
                {
                    return(ErrorCode.InvalidCommand);
                }
                IEnumerable <string> configFiles = _configOption.GetValues(optionsParser);
                IEnumerable <string> inputFiles  = _inputOption.GetValues(optionsParser);

                string outputFileHtml = _outputOption.GetValue(optionsParser);
                string outputFileCsv  = _outputCsvOption.GetValue(optionsParser);

                if ((outputFileHtml == null) && (outputFileCsv == null))
                {
                    optionsParser.ReportError("Required at least one option: '/out' or '/out_csv'.");
                    return(ErrorCode.InvalidCommand);
                }

                ContributionsReport report = new ContributionsReport(configFiles, inputFiles);
                if (outputFileHtml != null)
                {
                    HtmlContributionsReport.Write(report, outputFileHtml);
                }
                // Note we can have both options
                if (outputFileCsv != null)
                {
                    //CsvContributionsReport.Write(report, outputFileCsv);
                }
                return(ErrorCode.Success);
            }

            case ActionCommand.alerts:
            {
                if (!optionsParser.Parse(
                        new Option[] { _configOption, _beginOption, _endOption, _templateOption },
                        new Option[] { _filterOption, _skipEmailOption, _outputOption }))
                {
                    return(ErrorCode.InvalidCommand);
                }
                IEnumerable <string> configFiles = _configOption.GetValues(optionsParser);
                IEnumerable <string> beginFiles  = _beginOption.GetValues(optionsParser);
                IEnumerable <string> endFiles    = _endOption.GetValues(optionsParser);
                string templateFile = _templateOption.GetValue(optionsParser);
                // Optional args
                IEnumerable <string> alertFilters = _filterOption.GetValues(optionsParser);
                bool   skipEmail  = _skipEmailOption.IsDefined(optionsParser);
                string outputFile = _outputOption.GetValue(optionsParser);

                Config config = new Config(configFiles);
                IEnumerable <DataModelIssue> beginIssues = IssueCollection.LoadIssues(
                    beginFiles,
                    config,
                    IssueKindFlags.Issue | IssueKindFlags.PullRequest)
                                                           .DistinctFirst_ByIssueNumber()
                                                           .ToArray();
                IEnumerable <DataModelIssue> endIssues = IssueCollection.LoadIssues(
                    endFiles,
                    config,
                    IssueKindFlags.Issue | IssueKindFlags.PullRequest)
                                                         .DistinctLast_ByIssueNumber()
                                                         .ToArray();

                if (AlertReport_Diff.DetectLargeChanges(beginIssues, endIssues, config))
                {
                    return(ErrorCode.EmailSendFailure);
                }

                return(GetSendEmailErrorCode(AlertReport_Diff.SendEmails(
                                                 config,
                                                 templateFile,
                                                 skipEmail,
                                                 outputFile,
                                                 alertFilters,
                                                 beginIssues,
                                                 endIssues)));
            }

            case ActionCommand.history:
            {
                if (!optionsParser.Parse(
                        new Option[] { _inputOption, _outputOption },
                        Option.EmptyList))
                {
                    return(ErrorCode.InvalidCommand);
                }
                IEnumerable <string> inputFiles = _inputOption.GetValues(optionsParser);
                string outputFile = _outputOption.GetValue(optionsParser);

                HistoryReport.Create(inputFiles, outputFile);
                return(ErrorCode.Success);
            }

            case ActionCommand.untriaged:
            {
                if (!optionsParser.Parse(
                        new Option[] { _configOption, _inputOption, _templateOption },
                        new Option[] { _filterOption, _skipEmailOption, _outputOption }))
                {
                    return(ErrorCode.InvalidCommand);
                }
                IEnumerable <string> configFiles = _configOption.GetValues(optionsParser);
                IEnumerable <string> inputFiles  = _inputOption.GetValues(optionsParser);
                string templateFile = _templateOption.GetValue(optionsParser);
                // Optional args
                IEnumerable <string> alertFilters = _filterOption.GetValues(optionsParser);
                bool   skipEmail  = _skipEmailOption.IsDefined(optionsParser);
                string outputFile = _outputOption.GetValue(optionsParser);

                Config config = new Config(configFiles);

                return(GetSendEmailErrorCode(AlertReport_Untriaged.SendEmails(
                                                 config,
                                                 templateFile,
                                                 skipEmail,
                                                 outputFile,
                                                 alertFilters,
                                                 inputFiles)));
            }

            case ActionCommand.needsResponse:
            {
                if (!optionsParser.Parse(
                        new Option[] { _configOption, _inputOption, _commentsOption, _templateOption },
                        new Option[] { _filterOption, _skipEmailOption, _outputOption }))
                {
                    return(ErrorCode.InvalidCommand);
                }
                IEnumerable <string> configFiles   = _configOption.GetValues(optionsParser);
                IEnumerable <string> inputFiles    = _inputOption.GetValues(optionsParser);
                IEnumerable <string> commentsFiles = _commentsOption.GetValues(optionsParser);
                string templateFile = _templateOption.GetValue(optionsParser);
                // Optional args
                IEnumerable <string> alertFilters = _filterOption.GetValues(optionsParser);
                bool   skipEmail  = _skipEmailOption.IsDefined(optionsParser);
                string outputFile = _outputOption.GetValue(optionsParser);

                Config config = new Config(configFiles);
                IEnumerable <DataModelIssue> issues = IssueCollection.LoadIssues(
                    inputFiles,
                    config,
                    IssueKindFlags.Issue);
                IEnumerable <DataModelIssue> comments = IssueCollection.LoadIssues(
                    commentsFiles,
                    config,
                    IssueKindFlags.Comment);

                return(GetSendEmailErrorCode(AlertReport_NeedsResponse.SendEmails(
                                                 config,
                                                 templateFile,
                                                 skipEmail,
                                                 outputFile,
                                                 alertFilters,
                                                 issues,
                                                 comments)));
            }

            default:
                Debug.Assert(false);
                return(ErrorCode.CatastrophicFailure);
            }
        }
        catch (Exception ex)
        {
            Console.Error.WriteLine();
            Console.Error.WriteLine();
            Console.Error.WriteLine();
            Console.Error.WriteLine("Catastrophic failure:");
            Console.Error.WriteLine(ex);
            return(ErrorCode.CatastrophicFailure);
        }
    }
コード例 #11
0
        public static void ReadFromXML(TableReport report, string xmlFileName)
        {
            var       usCulture = new CultureInfo("en-US");
            XDocument doc       = XDocument.Load(xmlFileName);

            if (doc.Root.Attribute("Title") != null)
            {
                report.Title = doc.Root.Attribute("Title").Value;
            }

            var chart = doc.Descendants("Chart").FirstOrDefault();

            if (chart != null)
            {
                var reportChart = new ReportChart();

                if (chart.Attribute("XAxisField") != null)
                {
                    reportChart.XAxisFieldName = chart.Attribute("XAxisField").Value;
                }

                if (chart.Attribute("XAxisLabelField") != null)
                {
                    reportChart.XAxisLabelFieldName = chart.Attribute("XAxisLabelField").Value;
                }

                if (chart.Attribute("LegendLabelFieldName") != null)
                {
                    reportChart.LegendLabelFieldName = chart.Attribute("LegendLabelFieldName").Value;
                }

                if (chart.Attribute("YAxisField") != null)
                {
                    reportChart.YAxisFieldName = chart.Attribute("YAxisField").Value;
                }

                if (chart.Attribute("Width") != null)
                {
                    reportChart.Height = float.Parse(chart.Attribute("Width").Value, usCulture);
                }

                if (chart.Attribute("Height") != null)
                {
                    reportChart.Height = float.Parse(chart.Attribute("Height").Value, usCulture);
                }

                if (chart.Attribute("Title") != null)
                {
                    reportChart.Title = chart.Attribute("Title").Value;
                }

                if (chart.Attribute("Type") != null)
                {
                    reportChart.ChartType = chart.Attribute("Type").Value;
                }

                if (chart.Attribute("ShowLegend") != null)
                {
                    reportChart.ShowLegend = bool.Parse(chart.Attribute("ShowLegend").Value);
                }

                report.Chart = reportChart;
            }

            var columns = doc.Descendants("Column");

            foreach (var column in columns)
            {
                var tableColumn = new TableDataColumn();

                if (column.Attribute("Field") != null)
                {
                    tableColumn.FieldName = column.Attribute("Field").Value;
                }

                if (column.Attribute("HeaderText") != null)
                {
                    tableColumn.HeaderText = column.Attribute("HeaderText").Value;
                }

                if (column.Attribute("Width") != null)
                {
                    tableColumn.Width = float.Parse(column.Attribute("Width").Value, usCulture);
                }

                if (column.Attribute("TextAlign") != null)
                {
                    tableColumn.TextAlign = column.Attribute("TextAlign").Value;
                }

                if (column.Attribute("Format") != null)
                {
                    tableColumn.Format = column.Attribute("Format").Value;
                }

                report.Columns.Add(tableColumn);
            }

            var footers = doc.Descendants("Footer");

            foreach (var footer in footers)
            {
                var tableFooter = new TableDataFooterRow();
                var cell1       = new TableDataFooterCell();
                cell1.TextAlign = "Right";
                cell1.ColSpan   = columns.Count() - 1;

                if (footer.Attribute("LabelSpan") != null)
                {
                    int span = Convert.ToInt32(footer.Attribute("LabelSpan").Value);
                    cell1.ColSpan = span;
                }

                if (footer.Attribute("Label") != null)
                {
                    cell1.Value = footer.Attribute("Label").Value;
                }

                tableFooter.FooterCells.Add(cell1);

                for (int x = 0; x < 20; x++)
                {
                    var cell2 = new TableDataFooterCell();
                    cell2.TextAlign = "Right";
                    cell2.Format    = "N2";

                    string indexStr = "";

                    if (x > 0)
                    {
                        indexStr = Convert.ToString(x + 1);
                    }

                    if (footer.Attribute("Format" + indexStr) != null)
                    {
                        cell2.Format = footer.Attribute("Format" + indexStr).Value;
                    }

                    if (footer.Attribute("Content" + indexStr) != null)
                    {
                        cell2.Value = footer.Attribute("Content" + indexStr).Value;
                        tableFooter.FooterCells.Add(cell2);
                    }
                    else
                    {
                        break;
                    }
                }
                report.FooterRows.Add(tableFooter);
            }

            var group1 = doc.Descendants("Group1").FirstOrDefault();

            if (group1 != null)
            {
                if (group1.Attribute("Field") != null)
                {
                    report.GroupByField1 = group1.Attribute("Field").Value;
                }

                if (group1.Attribute("Header") != null)
                {
                    report.GroupByRowContent1 = group1.Attribute("Header").Value;
                }

                if (group1.Attribute("SortBy") != null)
                {
                    report.GroupBy1SortField = group1.Attribute("SortBy").Value;
                }

                if (group1.Attribute("SortDescending") != null)
                {
                    report.GroupBy1SortDescending = Convert.ToBoolean(group1.Attribute("SortDescending").Value);
                }

                if (group1.Attribute("FooterLabel") != null && group1.Attribute("FooterContent") != null)
                {
                    TableDataFooterRow groupFooterRow = new TableDataFooterRow();

                    TableDataFooterCell cell1 = new TableDataFooterCell();
                    cell1.ColSpan = columns.Count() - 1;

                    if (group1.Attribute("FooterLabelSpan") != null)
                    {
                        int span = Convert.ToInt32(group1.Attribute("FooterLabelSpan").Value);
                        cell1.ColSpan = span;
                    }

                    cell1.Value = group1.Attribute("FooterLabel").Value;
                    groupFooterRow.FooterCells.Add(cell1);

                    for (int x = 0; x < 20; x++)
                    {
                        string indexStr = "";

                        if (x > 0)
                        {
                            indexStr = Convert.ToString(x + 1);
                        }

                        if (group1.Attribute("FooterContent" + indexStr) != null)
                        {
                            TableDataFooterCell cell2 = new TableDataFooterCell();
                            cell2.Value  = group1.Attribute("FooterContent" + indexStr).Value;
                            cell2.Format = "N2";

                            if (group1.Attribute("Format" + indexStr) != null)
                            {
                                cell2.Format = group1.Attribute("Format" + indexStr).Value;
                            }

                            groupFooterRow.FooterCells.Add(cell2);
                        }
                        else
                        {
                            break;
                        }
                    }

                    report.GroupFooterRows1.Add(groupFooterRow);
                }
            }

            var group2 = doc.Descendants("Group2").FirstOrDefault();

            if (group2 != null)
            {
                if (group2.Attribute("Field") != null)
                {
                    report.GroupByField2 = group2.Attribute("Field").Value;
                }

                if (group2.Attribute("Header") != null)
                {
                    report.GroupByRowContent2 = group2.Attribute("Header").Value;
                }

                if (group2.Attribute("SortBy") != null)
                {
                    report.GroupBy2SortField = group2.Attribute("SortBy").Value;
                }

                if (group2.Attribute("SortDescending") != null)
                {
                    report.GroupBy2SortDescending = Convert.ToBoolean(group2.Attribute("SortDescending").Value);
                }

                if (group2.Attribute("FooterLabel") != null && group2.Attribute("FooterContent") != null)
                {
                    TableDataFooterRow groupFooterRow = new TableDataFooterRow();

                    TableDataFooterCell cell1 = new TableDataFooterCell();
                    cell1.ColSpan = columns.Count() - 1;

                    if (group2.Attribute("FooterLabelSpan") != null)
                    {
                        int span = Convert.ToInt32(group2.Attribute("FooterLabelSpan").Value);
                        cell1.ColSpan = span;
                    }

                    cell1.Value = group2.Attribute("FooterLabel").Value;
                    groupFooterRow.FooterCells.Add(cell1);

                    for (int x = 0; x < 20; x++)
                    {
                        string indexStr = "";

                        if (x > 0)
                        {
                            indexStr = Convert.ToString(x + 1);
                        }

                        if (group2.Attribute("FooterContent" + indexStr) != null)
                        {
                            TableDataFooterCell cell2 = new TableDataFooterCell();
                            cell2.Value  = group2.Attribute("FooterContent" + indexStr).Value;
                            cell2.Format = "N2";

                            if (group2.Attribute("Format" + indexStr) != null)
                            {
                                cell2.Format = group2.Attribute("Format" + indexStr).Value;
                            }

                            groupFooterRow.FooterCells.Add(cell2);
                        }
                        else
                        {
                            break;
                        }
                    }


                    report.GroupFooterRows2.Add(groupFooterRow);
                }
            }
        }
コード例 #12
0
        /// <summary>
        /// 创建页头
        /// </summary>
        /// <param name="p_info">表格报表对象</param>
        /// <returns>页头内容</returns>
        private XRTable CreateTitleHeader(TableReport p_info)
        {
            XRTable headerTable = new XRTable();

            headerTable.Dpi    = 254F;
            headerTable.Name   = "Page";
            headerTable.Width  = this.PageWidth - (this.Margins.Left + this.Margins.Right) - 4;
            headerTable.Height = 56;

            if (p_info.TitleCaption != string.Empty)
            {
                XRTableRow titleRow = new XRTableRow();
                titleRow.Dpi = 254F;
                //标题
                XRTableCell titleCell = new XRTableCell();
                titleCell.Dpi           = 254F;
                titleCell.Text          = p_info.TitleCaption;
                titleCell.TextAlignment = this.Alignments(p_info.TitleTextAlignment);
                titleCell.Width         = this.PageWidth - (this.Margins.Left + this.Margins.Right) - 4;
                titleCell.Font          = p_info.TitleFont;
                titleCell.BorderWidth   = 0;
                titleRow.Height         = (int)MeasureString(p_info.TitleCaption, p_info.TitleFont, titleCell.Width).Height + 1;
                titleRow.Cells.Add(titleCell);
                headerTable.Rows.Add(titleRow);
            }

            XRTableRow x_titleRow = new XRTableRow();

            x_titleRow.Dpi    = 254F;
            x_titleRow.Height = 56;
            //项目名称
            XRTableCell l_titleCell = new XRTableCell();

            l_titleCell.Dpi           = 254F;
            l_titleCell.TextAlignment = TextAlignment.MiddleLeft;
            l_titleCell.Width         = (headerTable.Width / 2);
            l_titleCell.Font          = new Font("宋体", 9F);
            l_titleCell.BorderWidth   = 0;
            x_titleRow.Cells.Add(l_titleCell);
            //专业名称
            XRTableCell r_titleCell = new XRTableCell();

            r_titleCell.Dpi         = 254F;
            r_titleCell.Width       = (headerTable.Width / 2);
            r_titleCell.BorderWidth = 0;
            XRPageInfo m_pageInfo = new XRPageInfo();

            m_pageInfo.Dpi           = 254F;
            m_pageInfo.Font          = new Font("宋体", 9F);
            m_pageInfo.TextAlignment = TextAlignment.MiddleRight;
            m_pageInfo.Width         = (headerTable.Width / 2);
            m_pageInfo.Height        = 56;

            switch (p_info.ReportType)
            {
            case "项目报表":
                l_titleCell.Text  = string.Format("项目名称:{0}", p_info.XMMC);
                m_pageInfo.Format = "\t第{0}页/共{1}页";
                break;

            case "单位报表":
                l_titleCell.Text  = string.Format("工程名称:{0}", p_info.XMMC);
                m_pageInfo.Format = string.Format("专业名称:{0}", p_info.ZYMC) + "\t第{0}页/共{1}页";
                break;

            default:
                break;
            }
            r_titleCell.Controls.Add(m_pageInfo);
            x_titleRow.Cells.Add(r_titleCell);
            headerTable.Rows.Add(x_titleRow);
            return(headerTable);
        }
コード例 #13
0
        /// <summary>
        /// 创建表格头
        /// </summary>
        /// <param name="rpf">报表个字段格式</param>
        /// <param name="border"></param>
        /// <returns></returns>
        private PageHeaderBand CreateTableHeader(TableReport p_info)
        {
            PageHeaderBand new_PageHeaderBand = new PageHeaderBand();

            new_PageHeaderBand.Controls.Add(CreateTitleHeader(p_info));
            if (p_info.ReportFields != null)
            {
                XRTable    headerTable  = null;
                XRTableRow headerOneRow = null;         //一级表头
                XRTableRow headerTwoRow = null;         //二级表头
                string     bands        = "**********"; //上一和并列的值
                for (int i = 0; i < p_info.ReportFields.Length; i++)
                {
                    FieldReport item = p_info.ReportFields[i];
                    if (item.Bands == string.Empty)
                    {
                        if (item.Bands != bands)
                        {
                            bands               = item.Bands;
                            headerTable         = new XRTable();
                            headerTable.Dpi     = 254F;
                            headerTable.Width   = 0;
                            headerTable.Height  = 112;
                            headerOneRow        = new XRTableRow();
                            headerOneRow.Dpi    = 254F;
                            headerOneRow.Height = 112;
                        }
                        XRTableCell headerCell = new XRTableCell();
                        headerCell.Dpi         = 254F;
                        headerCell.Font        = item.HeaderFont;
                        headerCell.Borders     = (BorderSide)(BorderSide.Top | BorderSide.Right | BorderSide.Left | BorderSide.Bottom);
                        headerCell.BorderWidth = 1;
                        int width = 0;
                        if (new_PageHeaderBand.Controls.Count > 1 && headerTable.Width == 5)
                        {
                            width = 3;
                        }
                        headerCell.Width         = item.RowWidth + width;
                        headerCell.WordWrap      = true;
                        headerCell.CanGrow       = true;
                        headerCell.TextAlignment = this.Alignments(item.TopAlignment);
                        headerCell.Text          = item.Caption;
                        headerCell.Tag           = item.Field;
                        headerTable.Width       += item.RowWidth - (headerTable.Width == 5 ? 5 : 0);
                        headerOneRow.Cells.Add(headerCell);
                        if (item.Bands != p_info.ReportFields[i + (i == p_info.ReportFields.Length - 1 ? 0 : 1)].Bands || i == p_info.ReportFields.Length - 1)
                        {
                            headerTable.Rows.Add(headerOneRow);
                            headerTable.Location = GetTable(new_PageHeaderBand);
                            if (new_PageHeaderBand.Controls.Count > 1)
                            {
                                headerTable.Width = headerTable.Width + 3;
                            }
                            new_PageHeaderBand.Controls.Add(headerTable);
                            new_PageHeaderBand.Height = 0;
                        }
                    }
                    else
                    {
                        if (item.Bands != bands)
                        {
                            bands               = item.Bands;
                            headerTable         = new XRTable();
                            headerTable.Dpi     = 254F;
                            headerTable.Width   = 0;
                            headerTable.Height  = 112;
                            headerOneRow        = new XRTableRow();
                            headerOneRow.Dpi    = 254F;
                            headerOneRow.Height = 56;

                            XRTableCell headerOneCell = new XRTableCell();
                            headerOneCell.Dpi           = 254F;
                            headerOneCell.Font          = item.HeaderFont;
                            headerOneCell.Borders       = (BorderSide)(BorderSide.Top | BorderSide.Right | BorderSide.Left);
                            headerOneCell.BorderWidth   = 1;
                            headerOneCell.Width         = item.RowWidth;
                            headerOneCell.WordWrap      = true;
                            headerOneCell.CanGrow       = true;
                            headerOneCell.TextAlignment = this.Alignments(item.TopAlignment);
                            headerOneCell.Text          = item.Bands;
                            headerOneCell.Tag           = item.Field;
                            headerOneRow.Cells.Add(headerOneCell);
                            headerTable.Rows.Add(headerOneRow);

                            headerTwoRow        = new XRTableRow();
                            headerTwoRow.Dpi    = 254F;
                            headerTwoRow.Height = 56;
                        }

                        XRTableCell headerTwoCell = new XRTableCell();
                        headerTwoCell.Dpi         = 254F;
                        headerTwoCell.Font        = item.HeaderFont;
                        headerTwoCell.Borders     = (BorderSide)(BorderSide.Top | BorderSide.Right | BorderSide.Left | BorderSide.Bottom);
                        headerTwoCell.BorderWidth = 1;
                        int width = 0;
                        if (new_PageHeaderBand.Controls.Count > 1 && headerTable.Width == 5)
                        {
                            width = 3;
                        }
                        headerTwoCell.Width         = item.RowWidth + width;
                        headerTwoCell.WordWrap      = true;
                        headerTwoCell.CanGrow       = true;
                        headerTwoCell.TextAlignment = this.Alignments(item.TopAlignment);
                        headerTwoCell.Text          = item.Caption;
                        headerTable.Width          += item.RowWidth - (headerTable.Width == 5 ? 5 : 0);
                        headerTwoRow.Cells.Add(headerTwoCell);
                        if (item.Bands != p_info.ReportFields[i + (i == p_info.ReportFields.Length - 1 ? 0 : 1)].Bands || i == p_info.ReportFields.Length - 1)
                        {
                            headerTable.Rows.Add(headerTwoRow);
                            headerTable.Location = GetTable(new_PageHeaderBand);
                            if (new_PageHeaderBand.Controls.Count > 1)
                            {
                                headerTable.Width = headerTable.Width + 3;
                            }
                            new_PageHeaderBand.Controls.Add(headerTable);
                            new_PageHeaderBand.Height = 0;
                        }
                    }
                }
            }
            return(new_PageHeaderBand);
        }