Example #1
0
        private void InitializeReport()
        {
            //打印主从表数据
            string file = Application.StartupPath + @"\Reports\rptSO.frx";

            rptSO.Load(file);//加载报表模板文件

            DataSet ds = new bllSO().GetReportData(txtNoFrom.Text, txtNoTo.Text, txtDateFrom.DateTime, txtDateTo.DateTime);

            ds.Tables[0].TableName = "M";          //换个短的别名
            ds.Tables[1].TableName = "D";          //换个短的别名

            rptSO.RegisterData(ds.Tables[0], "M"); //注册数据源,主表
            rptSO.RegisterData(ds.Tables[1], "D"); //注册数据源,从表

            //给DataBand(主表数据)绑定数据源
            DataBand masterBand = rptSO.FindObject("Data1") as DataBand;

            masterBand.DataSource = rptSO.GetDataSource("M"); //主表

            //给DataBand(明细数据)绑定数据源
            DataBand detailBand = rptSO.FindObject("Data2") as DataBand;

            detailBand.DataSource = rptSO.GetDataSource("D"); //明细表

            //重要!!给明细表设置主外键关系!
            detailBand.Relation = new Relation();
            detailBand.Relation.ParentColumns    = new string[] { "SONO" };
            detailBand.Relation.ParentDataSource = rptSO.GetDataSource("M"); //主表
            detailBand.Relation.ChildColumns     = new string[] { "SONO" };
            detailBand.Relation.ChildDataSource  = rptSO.GetDataSource("D"); //明细表

            (rptSO.FindObject("Text52") as RichObject).Text = Loginer.CurrentUser.AccountName;
        }
Example #2
0
            public Base CloneObject(string alias)
            {
                Base result = null;
                Type type   = originalComponent.GetType();

                // try frequently used objects first. The CreateInstance method is very slow.
                if (type == typeof(TextObject))
                {
                    result = new TextObject();
                }
                else if (type == typeof(TableCell))
                {
                    result = new TableCell();
                }
                else if (type == typeof(DataBand))
                {
                    result = new DataBand();
                }
                else
                {
                    result = Activator.CreateInstance(type) as Base;
                }

                result.Assign(originalComponent);
                result.OriginalComponent = originalComponent;
                result.Alias             = alias;
                result.SetName(originalComponent.Name);
                if (result is ReportComponentBase)
                {
                    (result as ReportComponentBase).AssignPreviewEvents(originalComponent);
                }
                return(result);
            }
Example #3
0
        private void RenderMultiColumnBand(DataBand dataBand, int rowCount)
        {
            if (dataBand.Columns.Layout == ColumnLayout.AcrossThenDown)
            {
                RenderBandAcrossThenDown(dataBand, rowCount);
            }
            else
            {
                DataSourceBase dataSource = dataBand.DataSource;
                int            saveRow    = dataSource.CurrentRowNo;

                // calc height of each data row. This list is shared across RenderBandDownThenAcross calls.
                Hashtable heights = new Hashtable();
                for (int i = 0; i < rowCount; i++)
                {
                    dataSource.CurrentRowNo = i + saveRow;
                    heights[i + saveRow]    = CalcHeight(dataBand);
                }

                dataSource.CurrentRowNo = saveRow;
                while (rowCount > 0)
                {
                    rowCount = RenderBandDownThenAcross(dataBand, rowCount, heights);
                }
            }
        }
Example #4
0
 private void button2_Click(object sender, EventArgs e)
 {
     using (Report report = new Report())
     {
         ReportPage page = new ReportPage();
         page.Name = "Page1";
         report.Pages.Add(page);
         DataBand dataBand = new DataBand();
         dataBand.Name = "DataBand";
         page.Bands.Add(dataBand);
         TableObject table = new TableObject();
         table.Name        = "Table1";
         table.RowCount    = 10;
         table.ColumnCount = 10;
         for (int i = 0; i < 10; i++)
         {
             for (int j = 0; j < 10; j++)
             {
                 table[j, i].Text         = (10 * i + j + 1).ToString();
                 table[j, i].Border.Lines = BorderLines.All;
             }
         }
         dataBand.Objects.Add(table);
         if (report.Prepare())
         {
             report.ShowPrepared();
         }
     }
 }
Example #5
0
        private void RunReportPage(ReportPage page)
        {
            FPage = page;
            InitReprint();

            FPage.OnStartPage(EventArgs.Empty);
            StartFirstPage();
            OnStateChanged(FPage, EngineState.ReportPageStarted);
            OnStateChanged(FPage, EngineState.PageStarted);

            DataBand keepSummaryBand = FindDeepmostDataBand(page);

            if (keepSummaryBand != null)
            {
                keepSummaryBand.KeepSummary = true;
            }

            if (FPage.IsManualBuild)
            {
                FPage.OnManualBuild(EventArgs.Empty);
            }
            else
            {
                RunBands(page.Bands);
            }

            OnStateChanged(FPage, EngineState.PageFinished);
            OnStateChanged(FPage, EngineState.ReportPageFinished);
            EndLastPage();
            FPage.OnFinishPage(EventArgs.Empty);
        }
        private void RunDataBand(DataBand dataBand)
        {
            dataBand.InitDataSource();
            dataBand.DataSource.First();

            int rowCount = dataBand.DataSource.RowCount;

            if (dataBand.IsDatasourceEmpty && dataBand.PrintIfDatasourceEmpty)
            {
                rowCount = 1;
            }
            if (dataBand.CollectChildRows && rowCount > 1)
            {
                rowCount = 1;
            }
            if (dataBand.MaxRows > 0 && rowCount > dataBand.MaxRows)
            {
                rowCount = dataBand.MaxRows;
            }

            bool keepFirstRow = NeedKeepFirstRow(dataBand);
            bool keepLastRow  = NeedKeepLastRow(dataBand);

            RunDataBand(dataBand, rowCount, keepFirstRow, keepLastRow);
        }
Example #7
0
        public bool AddData(string materDataName, DataTable dataTable, string dataSourceName)
        {
            AddData(dataTable, dataSourceName);
            DataBand db = this.Report.FindObject(materDataName) as DataBand;

            if (db == null)
            {
                MessageBox.Show("未找到控件 [" + materDataName + "]", "提示");
                return(false);
            }
            else
            {
                FastReport.Data.DataSourceBase source = this.Report.GetDataSource(dataSourceName);
                if (source == null)
                {
                    MessageBox.Show("没有找到名为[" + dataSourceName + "] 的数据源", "提示");
                    return(false);
                }
                else
                {
                    db.DataSource = source;
                    return(true);
                }
            }
        }
Example #8
0
 public DataBandEditorForm(DataBand band)
 {
     FBand = band;
     InitializeComponent();
     Localize();
     Init();
 }
        private GroupHeaderBand LoadDetailReportGroupHeaderBand(DataBand data, string bandName)
        {
            if (bandName == null)
            {
                return(null);
            }

            GroupHeaderBand groupHeader = new GroupHeaderBand();

            if (data.Parent is GroupHeaderBand)
            {
                GroupHeaderBand parent = data.Parent as GroupHeaderBand;
                groupHeader.Data   = data;
                parent.NestedGroup = groupHeader;
            }
            else
            {
                groupHeader.Data = data;
                page.Bands.Add(groupHeader);
            }


            string detailDescription = GetObjectDescription(bandName);

            LoadBand(groupHeader, detailDescription);
            LoadObjects(detailDescription, groupHeader);
            return(groupHeader);
        }
Example #10
0
        private void btnPrintSingle_Click(object sender, EventArgs e)
        {
            string frxPath = Application.StartupPath + @"\Resource\InstorageLable.frx";

            if (!File.Exists(frxPath))
            {
                MessageBox.Show("找不到入仓打印模板:" + frxPath);
                return;
            }

            Report report = new Report();

            report.Load(frxPath);
            List <InstorageInfoViewModel> model = BrandModel(instorageinfoID);
            int totalPieces = model.Sum(m => m.Pieces);//该次入仓总件数

            model.ForEach(m => { m.TotalPieces  = totalPieces;
                                 m.TotalWayBill = model.Count; });

            report.RegisterData(model, "waybillList");
            var      datasource = report.GetDataSource("waybillList");
            DataBand data1      = report.FindObject("data1") as DataBand;

            if (data1 != null)
            {
                data1.DataSource = datasource;
            }
            report.Prepare();
            //report.Show();
            report.Print();
            report.Dispose();
        }
        private void ShowGroupFooter(GroupHeaderBand header)
        {
            // finish group event
            OnStateChanged(header, EngineState.GroupFinished);

            // rollback to previous data row to print the header condition in the footer.
            DataBand       dataBand   = header.GroupDataBand;
            DataSourceBase dataSource = dataBand.DataSource;

            dataSource.Prior();

            GroupFooterBand footer = header.GroupFooter;

            if (footer != null)
            {
                footer.AbsRowNo++;
                footer.RowNo++;
            }
            RemoveReprint(footer);
            ShowBand(footer);
            RemoveReprint(header);

            // restore current row
            dataSource.Next();

            OutlineUp(header);
            if (header.KeepTogether)
            {
                EndKeep();
            }
            if (footer != null && footer.KeepWithData)
            {
                EndKeep();
            }
        }
Example #12
0
        private void LoadDetailReportGroupBands(XmlNode detailReportBands, DataBand data)
        {
            List <XmlNode> headers = GetListOfBandsByName(detailReportBands, "GroupHeaderBand");
            List <XmlNode> footers = GetListOfBandsByName(detailReportBands, "GroupFooterBand");
            int            level   = -1;

            for (int i = 0; i < headers.Count; i++)
            {
                level++;
                XmlNode header;

                if (i == 0)
                {
                    header = headers.Where(x => GetAttribute(x, "Level") == string.Empty).FirstOrDefault();
                }
                else
                {
                    header = headers.Where(x => GetAttribute(x, "Level") == level.ToString()).FirstOrDefault();
                }

                GroupHeaderBand headerBand = LoadDetailReportGroupHeader(header, data);

                if (header == null)
                {
                    continue;
                }

                string headerLevel = GetAttribute(header, "Level");

                XmlNode footer = footers.Where(x => GetAttribute(x, "Level").Equals(headerLevel)).FirstOrDefault();
                LoadDetailReportGroupFooter(footer, headerBand);
            }
        }
Example #13
0
        static Report GetTableReport()
        {
            Report     report = new Report();
            ReportPage page   = new ReportPage();

            page.Name = "Page1";
            report.Pages.Add(page);
            DataBand dataBand = new DataBand();

            dataBand.Name = "DataBand";
            page.Bands.Add(dataBand);
            TableObject table = new TableObject();

            table.Name        = "Table1";
            table.RowCount    = 10;
            table.ColumnCount = 10;
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    table[j, i].Text         = (10 * i + j + 1).ToString();
                    table[j, i].Border.Lines = BorderLines.All;
                }
            }
            dataBand.Objects.Add(table);
            table.CreateUniqueNames();
            return(report);
        }
Example #14
0
        private void RunDataBand(DataBand dataBand)
        {
            if (page.Columns.Count > 1 && Report.Engine.UnlimitedHeight)
            {
                dataBand.Columns.Count = page.Columns.Count;
            }

            dataBand.InitDataSource();
            dataBand.DataSource.First();

            int rowCount = dataBand.DataSource.RowCount;

            if (dataBand.IsDatasourceEmpty && dataBand.PrintIfDatasourceEmpty)
            {
                rowCount = 1;
            }
            if (dataBand.CollectChildRows && rowCount > 1)
            {
                rowCount = 1;
            }
            if (dataBand.MaxRows > 0 && rowCount > dataBand.MaxRows)
            {
                rowCount = dataBand.MaxRows;
            }

            bool keepFirstRow = NeedKeepFirstRow(dataBand);
            bool keepLastRow  = NeedKeepLastRow(dataBand);

            RunDataBand(dataBand, rowCount, keepFirstRow, keepLastRow);

            // do not leave the datasource in EOF state to allow print something in the footer
            dataBand.DataSource.Prior();
        }
        private void RenderBandAcrossThenDown(DataBand dataBand, int rowCount)
        {
            DataSourceBase dataSource  = dataBand.DataSource;
            int            saveRow     = dataSource.CurrentRowNo;
            bool           keepLastRow = NeedKeepLastRow(dataBand);

            // create output band
            using (DataBand outputBand = new DataBand())
            {
                outputBand.SetReport(Report);

                int columnNo = 0;
                for (int i = 0; i < rowCount; i++)
                {
                    bool isLastRow = i == rowCount - 1;
                    dataSource.CurrentRowNo = i + saveRow;
                    if (columnNo == 0)
                    {
                        outputBand.Clear();
                        outputBand.Assign(dataBand);
                        outputBand.OutlineExpression = "";
                        outputBand.Border            = new Border();
                        outputBand.Fill = new SolidFill();
                    }

                    // write to the output band
                    ShowBand(dataBand, outputBand, dataBand.Columns.Positions[columnNo], 0);
                    // add outline
                    AddBandOutline(dataBand);
                    // outline up
                    OutlineUp(dataBand);

                    dataBand.RowNo++;
                    dataBand.AbsRowNo++;
                    columnNo++;
                    if (columnNo == dataBand.Columns.Count || isLastRow)
                    {
                        columnNo = 0;

                        // keep footer
                        if (isLastRow && keepLastRow && dataBand.IsDeepmostDataBand)
                        {
                            StartKeep(outputBand);
                        }

                        // show output band itself
                        ShowBand(outputBand, false);

                        // end keep footer
                        if (isLastRow && keepLastRow && dataBand.IsDeepmostDataBand)
                        {
                            CheckKeepFooter(dataBand);
                        }
                    }
                }
            }

            dataSource.CurrentRowNo = saveRow + rowCount;
        }
Example #16
0
        /// <summary>
        /// Creates a DataBand instance in the specified ReportPage.
        /// </summary>
        /// <param name="page">The ReportPage instance.</param>
        /// <returns>The DataBand instance.</returns>
        public static DataBand CreateDataBand(ReportPage page)
        {
            DataBand band = new DataBand();

            page.Bands.Add(band);
            band.CreateUniqueName();
            return(band);
        }
Example #17
0
        /// <summary>
        /// Creates a DataFooterBand instance in the specified DataBand.
        /// </summary>
        /// <param name="data">The DataBand instance.</param>
        /// <returns>The DataFooterBand instance.</returns>
        public static DataFooterBand CreateDataFooterBand(DataBand data)
        {
            DataFooterBand dataFooter = new DataFooterBand();

            data.Footer = dataFooter;
            dataFooter.CreateUniqueName();
            return(dataFooter);
        }
Example #18
0
        private void SetReportPageLayout(XmlItem labelParameters, ReportPage page)
        {
            float paperWidth  = Converter.StringToFloat(labelParameters.GetProp("PaperWidth"), true) * 25.4f;
            float paperHeight = Converter.StringToFloat(labelParameters.GetProp("PaperHeight"), true) * 25.4f;
            float leftMargin  = Converter.StringToFloat(labelParameters.GetProp("LeftMargin"), true) * 25.4f;
            float topMargin   = Converter.StringToFloat(labelParameters.GetProp("TopMargin"), true) * 25.4f;

            float labelWidth  = Converter.StringToFloat(labelParameters.GetProp("Width"), true) * 25.4f;
            float labelHeight = Converter.StringToFloat(labelParameters.GetProp("Height"), true) * 25.4f;
            int   rows        = (int)Converter.StringToFloat(labelParameters.GetProp("Rows"), true);

            if (rows == 0)
            {
                rows = 1;
            }
            int columns = (int)Converter.StringToFloat(labelParameters.GetProp("Columns"), true);

            if (columns == 0)
            {
                columns = 1;
            }
            float rowGap    = Converter.StringToFloat(labelParameters.GetProp("RowGap"), true) * 25.4f;
            float columnGap = Converter.StringToFloat(labelParameters.GetProp("ColumnGap"), true) * 25.4f;

            // setup paper
            page.Clear();
            page.Landscape    = labelParameters.GetProp("Landscape") == "true";
            page.PaperWidth   = paperWidth;
            page.PaperHeight  = paperHeight;
            page.LeftMargin   = leftMargin;
            page.RightMargin  = 0;
            page.TopMargin    = topMargin;
            page.BottomMargin = 0;

            // setup columns
            page.Columns.Count = columns;
            page.Columns.Width = labelWidth;
            page.Columns.Positions.Clear();
            for (int i = 0; i < columns; i++)
            {
                page.Columns.Positions.Add(i * (labelWidth + columnGap));
            }

            // setup data band
            DataBand band = new DataBand();

            page.Bands.Add(band);
            band.CreateUniqueName();
            band.Width  = labelWidth * Units.Millimeters;
            band.Height = labelHeight * Units.Millimeters;
            // setup row gap (use child band)
            if (rowGap > 0)
            {
                band.Child = new ChildBand();
                band.Child.CreateUniqueName();
                band.Child.Height = rowGap * Units.Millimeters;
            }
        }
        private void BuildDataBandTree(TreeNodeCollection parent, DataBand dataBand)
        {
            if (dataBand != null)
            {
                var dataBandNode = AddBandNode(parent, dataBand, "Data: {0}", "Data");

                AddDataBandNode(dataBandNode.Nodes, dataBand.Bands);
            }
        }
Example #20
0
        private void LoadDetailReportHeaderFooter(XmlNode detailReportBands, DataBand data)
        {
            XmlNode header = FindBandNode(detailReportBands, "ReportHeaderBand");
            XmlNode footer = FindBandNode(detailReportBands, "ReportFooterBand");

            GroupHeaderBand headerBand = LoadDetailReportGroupHeader(header, data);

            LoadDetailReportGroupFooter(footer, headerBand);
        }
Example #21
0
        /// <summary>
        /// 添加主从关系
        /// </summary>
        /// <param name="ChildControlName">
        /// 子控件名称
        /// </param>
        /// <param name="ParentColumnName">
        /// 对应父控件列名
        /// </param>
        /// <param name="ChildColumnName">
        /// 对应子控件列名
        /// </param>
        public void AddRelation(string childControlName, string parentColumnName, string childColumnName)
        {
            DataBand db = this.Report.FindObject(childControlName) as DataBand;

            FastReport.Data.Relation relation = new FastReport.Data.Relation();
            relation.ParentDataSource = (db.Parent as DataBand).DataSource;
            relation.ParentColumns    = new string[] { parentColumnName };
            relation.ChildColumns     = new string[] { childColumnName };
            db.Relation = relation;
        }
        private void btnReport_Click(object sender, EventArgs e)
        {
            btnStore.Enabled = true;
            if (cbCourse.Text == "")
            {
                MessageBox.Show("blank fields !!!");
            }
            else
            {
                DataBand       d1             = null;
                DataBand       d2             = null;
                DataSourceBase parentDs       = null;
                DataSourceBase childDs        = null;
                DataSourceBase customersTable = null;
                DataSourceBase ordersTable    = null;
                Relation       rel            = null;
                report.Dictionary.Clear();

                DataTable dt = dataGridView1.DataSource as DataTable;

                DataView view = new DataView(dt);
                view.RowFilter = "Ch = 1";


                dt = view.ToTable();


                report.RegisterData(dt, "ShowQuestions");
                report.RegisterData(DbProcess.ShowAnswer(), "ShowAnswer");
                report.SetParameterValue("mypara", textBox1.Text);
                //report.SetParameterValue("depar", cbDepartmanlar.Text);
                report.SetParameterValue("course", cbCourse.Text);
                report.SetParameterValue("smester", cbAcedemicYear.Text);
                report.SetParameterValue("exam", comboBox4.Text);
                parentDs         = report.GetDataSource("ShowQuestions");
                childDs          = report.GetDataSource("ShowAnswer");
                parentDs.Enabled = true;
                childDs.Enabled  = true;
                customersTable   = report.Dictionary.DataSources.FindByAlias("ShowQuestions");
                ordersTable      = report.Dictionary.DataSources.FindByAlias("ShowAnswer");
                rel                  = new Relation();
                rel.Name             = "customersOrders";
                rel.ParentDataSource = customersTable;
                rel.ChildDataSource  = ordersTable;
                rel.ParentColumns    = new string[] { "Id" };
                rel.ChildColumns     = new string[] { "QuestionId" };
                report.Dictionary.Relations.Add(rel);
                report.Dictionary.UpdateRelations();
                d1            = report.FindObject("Data1") as DataBand;
                d1.DataSource = parentDs;
                d2            = report.FindObject("Data2") as DataBand;
                d2.DataSource = childDs;
                report.Show();
            }
        }
        public byte[] PrintResultPDF(string userNo)
        {
            try
            {
                Config.WebMode = true;
                Report rep = new Report();
                rep.Load(Server.MapPath("~/App_Data/rptResult.frx"));

                using (VShapeUpDataContext _context = new VShapeUpDataContext())
                {
                    var data = (from x in _context.V_ChallengeResult_Reports
                                where x.UserNo == userNo
                                select x).ToList().ToDataTable();

                    rep.RegisterData(data, "Report");
                    DataBand band = rep.FindObject("Data") as DataBand;
                    band.DataSource = rep.GetDataSource("Report");
                }

                if (rep.Report.Prepare())
                {
                    PDFExport pdfExport = new PDFExport();
                    pdfExport.ShowProgress   = false;
                    pdfExport.Compressed     = true;
                    pdfExport.AllowPrint     = true;
                    pdfExport.EmbeddingFonts = true;

                    MemoryStream strm = new MemoryStream();
                    rep.Report.Export(pdfExport, strm);
                    rep.Dispose();
                    pdfExport.Dispose();
                    strm.Position = 0;

                    return(strm.ToArray());


                    //ImageExport export = new ImageExport();
                    //MemoryStream strm = new MemoryStream();
                    //rep.Report.Export(export, strm);
                    //rep.Dispose();
                    //export.Dispose();
                    //strm.Position = 0;

                    //return strm.ToArray();
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
 private void CheckKeepFooter(DataBand dataBand)
 {
     if (FreeSpace < GetFootersHeight(dataBand))
     {
         EndColumn();
     }
     else
     {
         EndKeep();
     }
 }
Example #25
0
        private void ShowHierarchy(DataBand dataBand, int rowCount)
        {
            HierarchyItem rootItem = MakeHierarchy(dataBand, rowCount);

            if (rootItem == null)
            {
                return;
            }

            ShowHierarchy(dataBand, rootItem, 1, "");
        }
        public bool Process(object sender, EngineState state)
        {
            ProcessAt processAt  = textObject.ProcessAt;
            bool      canProcess = false;

            if ((processAt == ProcessAt.DataFinished && state == EngineState.BlockFinished) ||
                (processAt == ProcessAt.GroupFinished && state == EngineState.GroupFinished))
            {
                // check which data is finished
                BandBase topParentBand = textObject.Band;
                if (topParentBand is ChildBand)
                {
                    topParentBand = (topParentBand as ChildBand).GetTopParentBand;
                }

                if (processAt == ProcessAt.DataFinished && state == EngineState.BlockFinished)
                {
                    // total can be printed on the same data header, or on its parent data band
                    DataBand senderBand = sender as DataBand;
                    canProcess = true;
                    if (topParentBand is DataHeaderBand && (topParentBand.Parent != sender))
                    {
                        canProcess = false;
                    }
                    if (topParentBand is DataBand && senderBand.Parent != topParentBand)
                    {
                        canProcess = false;
                    }
                }
                else
                {
                    // total can be printed on the same group header
                    canProcess = sender == topParentBand;
                }
            }
            else
            {
                canProcess = (processAt == ProcessAt.ReportFinished && state == EngineState.ReportFinished) ||
                             (processAt == ProcessAt.ReportPageFinished && state == EngineState.ReportPageFinished) ||
                             (processAt == ProcessAt.PageFinished && state == EngineState.PageFinished) ||
                             (processAt == ProcessAt.ColumnFinished && state == EngineState.ColumnFinished);
            }

            if (canProcess)
            {
                Process();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #27
0
        private void ShowDataFooter(DataBand dataBand)
        {
            dataBand.DataSource.Prior();

            DataFooterBand footer = dataBand.Footer;

            RemoveReprint(footer);
            ShowBand(footer);
            RemoveReprint(dataBand.Header);

            dataBand.DataSource.Next();
        }
Example #28
0
        private void LoadSubreport(XmlNode subreportNode)
        {
            component = ComponentsFactory.CreateSubreportObject(subreportNode.Attributes["Name"].Value, parent);
            ReportPage subPage = ComponentsFactory.CreateReportPage(Report);
            DataBand   subBand = ComponentsFactory.CreateDataBand(subPage);

            subBand.Height = 2.0f * Utils.Units.Centimeters;
            (component as SubreportObject).ReportPage = subPage;
            XmlNodeList nodeList = subreportNode.ChildNodes;

            LoadReportItem(nodeList);
        }
        private void LoadDetailBand() // Data
        {
            string name = FindObjectName(DETAIL_BAND_MASK);

            if (!String.IsNullOrEmpty(name))
            {
                DataBand data        = ComponentsFactory.CreateDataBand(page);
                string   description = GetObjectDescription(name);
                LoadBand(data, description);
                LoadObjects(description, data);
                LoadGroupHeaderFooterBand(data);
            }
        }
Example #30
0
        private DataBand FindDeepmostDataBand(ReportPage page)
        {
            DataBand result = null;

            foreach (Base c in page.AllObjects)
            {
                if (c is DataBand)
                {
                    result = c as DataBand;
                }
            }
            return(result);
        }
Example #31
0
        /// <summary>
        /// 生成默认报表
        /// </summary>
        /// <returns></returns>
        public FastReport.Report DefaultReport()
        {

            FastReport.Report report = new FastReport.Report();
            //判断有报表数据,则注册数据
            if (dt != null && dt.Rows.Count > 0)
            {
                report.RegisterData(dt, styleObject);
            }
            else
            {
                return null;
            }
            //查询报表设置
            DataTable dtReportSet = DBHelper.GetTable("", "tb_report_set", "*", string.Format("set_object='{0}' and set_user='******'", styleObject, GlobalStaticObj.UserID), "", "order by set_num");
            if (dtReportSet == null || dtReportSet.Rows.Count == 0)
            {
                return null;
            }
            // enable the "Employees" table to use it in the report
            report.GetDataSource(styleObject).Enabled = true;

            // add report page
            ReportPage page = new ReportPage();
            if (paperSize != null)
            {
                page.PaperWidth = paperSize.Width;
                page.PaperHeight = paperSize.Height;
            }
            report.Pages.Add(page);
            // always give names to objects you create. You can use CreateUniqueName method to do this;
            // call it after the object is added to a report.
            page.CreateUniqueName();

            // create title band
            page.ReportTitle = new ReportTitleBand();
            // native FastReport unit is screen pixel, use conversion 
            page.ReportTitle.Height = Units.Centimeters * 1;
            page.ReportTitle.CreateUniqueName();

            // create title text
            TextObject titleText = new TextObject();
            titleText.Parent = page.ReportTitle;
            titleText.CreateUniqueName();
            //titleText.Bounds = new RectangleF(Units.Centimeters * 5, 0, Units.Centimeters * 10, Units.Centimeters * 1);
            titleText.Bounds = new RectangleF(0, 0, Units.Millimeters * page.PaperWidth, Units.Centimeters * 1);
            titleText.Font = new Font("Arial", 14, FontStyle.Bold);
            titleText.Text = styleTitle;
            titleText.HorzAlign = HorzAlign.Center;
            titleText.VertAlign = VertAlign.Center;
            //内容行高
            float rowHeight = Units.Centimeters * 1F;
            //标题行高,如果有合并列,怎行高价高
            float rowHeaderHeight = rowHeight;
            if (dicSpanRows != null && dicSpanRows.Count > 0)
            {
                rowHeaderHeight = Units.Centimeters * 1.5f;
            }
            page.PageHeader = new PageHeaderBand();
            page.PageHeader.Height = rowHeaderHeight;
            page.PageHeader.CreateUniqueName();
            #region 生成报表内容
            // create data band
            DataBand dataBand = new DataBand();
            page.Bands.Add(dataBand);
            dataBand.CreateUniqueName();
            dataBand.DataSource = report.GetDataSource(styleObject);
            dataBand.Height = rowHeight;
            float x = 0F;//x坐标

            foreach (DataRow dr in dtReportSet.Rows)
            {
                //判断是否要打印
                if (CommonCtrl.IsNullToString(dr["is_print"]) != "1")
                {
                    continue;
                }
                //列宽
                float columnWidth = Units.Centimeters * 2;
                //标题
                string headerName = string.Empty;
                //获取设置的列宽和标题
                float.TryParse(dr["set_width"].ToString(), out columnWidth);
                //columnWidth = columnWidth * 0.9f;
                headerName = dr["set_name"].ToString();
                //生成标题
                TextObject txtHeader = new TextObject();
                txtHeader.Parent = page.PageHeader;
                txtHeader.CreateUniqueName();
                txtHeader.Text = headerName;
                txtHeader.HorzAlign = HorzAlign.Center;
                txtHeader.VertAlign = VertAlign.Center;
                //生成标题竖线
                LineObject lineHeaderVer = new LineObject();
                lineHeaderVer.Parent = page.PageHeader;
                //生成标题横线
                LineObject lineHeaderHor = new LineObject();
                lineHeaderHor.Parent = page.PageHeader;
                lineHeaderHor.Bounds = new RectangleF(x, 0, columnWidth, 1f);

                //数据源列名称
                string dataName = dr["set_data_name"].ToString();
                string spanName = IsContainDataColumn(dataName);
                //判断列是否是合并列
                if (spanName.Length > 0)
                {
                    #region 合并列标题
                    txtHeader.Bounds = new RectangleF(x, rowHeaderHeight / 2, columnWidth, rowHeaderHeight / 2);
                    lineHeaderVer.Bounds = new RectangleF(x, rowHeaderHeight / 2, 1F, rowHeaderHeight / 2);
                    //生成合并列的短竖线
                    LineObject lineHeaderHorSpan = new LineObject();
                    lineHeaderHorSpan.Parent = page.PageHeader;
                    lineHeaderHorSpan.Bounds = new RectangleF(x, rowHeaderHeight / 2, columnWidth, 1F);
                    //判断是否包含合并列头
                    if (dicSpanWidth.ContainsKey(spanName))
                    {
                        //增加合并列头的列宽
                        RectangleF rf = dicSpanWidth[spanName];
                        rf.Width += columnWidth;
                        dicSpanWidth[spanName] = rf;
                    }
                    else
                    {
                        //记录合并列头
                        RectangleF rf = new RectangleF();
                        rf.X = x;
                        rf.Y = 0;
                        rf.Width = columnWidth;
                        rf.Height = rowHeaderHeight / 2;
                        dicSpanWidth.Add(spanName, rf);
                    }
                    #endregion
                }
                else
                {
                    lineHeaderVer.Bounds = new RectangleF(x, 0, 1F, rowHeaderHeight);
                    txtHeader.Bounds = new RectangleF(x, 0, columnWidth, rowHeaderHeight);
                }
                // create two text objects with employee's name and birth date
                //生成内容
                TextObject empNameText = new TextObject();
                empNameText.Parent = dataBand;
                empNameText.CreateUniqueName();
                empNameText.Bounds = new RectangleF(x, 0, columnWidth, rowHeight);
                DataColumn dc = dt.Columns[dataName];
                empNameText.Text = string.Format("[{0}.{1}]", styleObject, dataName);
                //empNameText.HideZeros = true;
                if (dc != null && dc.DataType != typeof(string))
                {
                    empNameText.HorzAlign = HorzAlign.Right;
                }
                else
                {
                    empNameText.HorzAlign = HorzAlign.Center;
                }
                empNameText.VertAlign = VertAlign.Center;
                //生成内容列的竖线
                LineObject lineVertical = new LineObject();
                lineVertical.Parent = dataBand;
                lineVertical.Bounds = new RectangleF(x, 0, 1F, rowHeight);
                //生成内容列顶部的横线
                LineObject lineHorizontal = new LineObject();
                lineHorizontal.Parent = dataBand;
                lineHorizontal.Bounds = new RectangleF(x, 0, columnWidth, 1f);
                //生成内荣列底部的横线
                LineObject lineHorizontalD = new LineObject();
                lineHorizontalD.Parent = dataBand;
                lineHorizontalD.Bounds = new RectangleF(x, rowHeight, columnWidth, 1f);

                //x坐标增加当前列
                x += columnWidth;
            }

            //生成标题右边的竖线
            LineObject lineHeaderRightVer = new LineObject();
            lineHeaderRightVer.Parent = page.PageHeader;
            lineHeaderRightVer.Bounds = new RectangleF(x, 0, 1f, rowHeight);
            //生成内容右边的竖线
            LineObject lineRightVer = new LineObject();
            lineRightVer.Parent = dataBand;
            lineRightVer.Bounds = new RectangleF(x, 0, 1f, rowHeight);
            //生成合并列头
            foreach (string span in dicSpanWidth.Keys)
            {
                //合并列头
                TextObject txtSpan = new TextObject();
                txtSpan.Parent = page.PageHeader;
                txtSpan.CreateUniqueName();
                txtSpan.Bounds = dicSpanWidth[span];
                txtSpan.Text = span;
                txtSpan.HorzAlign = HorzAlign.Center;
                txtSpan.VertAlign = VertAlign.Center;
                //合并列头的竖线
                LineObject lineHeaderVer = new LineObject();
                lineHeaderVer.Parent = page.PageHeader;
                lineHeaderVer.Bounds = new RectangleF(txtSpan.Bounds.X, txtSpan.Bounds.Y, 1f, txtSpan.Bounds.Height);
            }
            #endregion
            #region 生成页脚
            page.PageFooter = new PageFooterBand();
            page.PageFooter.Height = rowHeaderHeight;
            page.PageHeader.CreateUniqueName();
            TextObject txtPageN = new TextObject();
            txtPageN.Parent = page.PageFooter;
            txtPageN.CreateUniqueName();
            txtPageN.Text = "[PageNofM]";
            txtPageN.Bounds = new RectangleF(100, 0, 200, rowHeaderHeight);

            //TextObject txtTotalPages = new TextObject();
            //txtTotalPages.Parent = page.PageFooter;
            //txtTotalPages.CreateUniqueName();
            //txtTotalPages.Text = "[TotalPages]";
            //txtTotalPages.Bounds = new RectangleF(350, 0, 200, rowHeaderHeight);
            #endregion
            return report;

        }
Example #32
0
        private void reportShow()
        {
            this.Invoke(new setStatusDelegate1(setStatus));
            int i = 0, j = 0;
            dbHepler db = new dbHepler();

            string sql = this.Invoke(new getsql(generatesql)) as string;
            MessageBox.Show(sql);
            // string sql = "select * from [20028] where XH='128590'";
            DataSet Student = db.LoadData(sql);
            report.Pages.Clear();
            //report.Load("Untitled.frx");
            ;

            //DataBand data = (DataBand)report.FindObject("data1");

            for (i = 0; i < Student.Tables[0].Rows.Count / 10; i++)
            {
                ReportPage page1 = new ReportPage();

                report.Pages.Add(page1);

                DataBand data = new DataBand();
                page1.Bands.Add(data);
                for (j = 0; j < 10; j++)
                {

                    TextObject text1 = new TextObject();
                    if (j % 2 == 0)
                    {
                        text1.Bounds = new RectangleF(Units.Centimeters * 4, Units.Centimeters * 3 * j, Units.Centimeters * 5, Units.Centimeters * 0.6f);
                    }
                    else
                    {
                        text1.Bounds = new RectangleF(Units.Centimeters * 9 + Units.Centimeters * 4, Units.Centimeters * 3 * (j - 1), Units.Centimeters * 5, Units.Centimeters * 0.6f);

                    }

                    text1.Text = Student.Tables[0].Rows[10 * i + j]["name"].ToString();
                    data.Objects.Add(text1);

                    PictureObject pic = new PictureObject();
                    if (j % 2 == 0)
                    {
                        pic.Bounds = new RectangleF(0, Units.Centimeters * 3 * j, Units.Centimeters * 2, Units.Centimeters * 2);
                    }
                    else
                    {
                        pic.Bounds = new RectangleF(Units.Centimeters * 9 + Units.Centimeters * 0, Units.Centimeters * 3 * (j - 1), Units.Centimeters * 2, Units.Centimeters * 2);

                    }
                    if (File.Exists("./" + "20"+Student.Tables[0].Rows[10 * i + j]["XH"].ToString().Substring(0,2) + "/" + Student.Tables[0].Rows[10 * i + j]["XH"].ToString()+ ".jpg"))
                        pic.Image = Image.FromFile("./" +"20"+ Student.Tables[0].Rows[10 * i + j]["XH"].ToString().Substring(0,2) + "/" + Student.Tables[0].Rows[10 * i + j]["XH"].ToString() + ".jpg");
                    data.Objects.Add(pic);

                    BarcodeObject bar = new BarcodeObject();
                    if (j % 2 == 0)
                    {
                        bar.Bounds = new RectangleF(0, Units.Centimeters * 3 * j + Units.Centimeters * 2.5f, Units.Centimeters * 8, Units.Centimeters * 2);
                    }
                    else
                    {
                        bar.Bounds = new RectangleF(Units.Centimeters * 9 + Units.Centimeters * 0, Units.Centimeters * 3 * (j - 1) + Units.Centimeters * 2.5f, Units.Centimeters * 8, Units.Centimeters * 2);

                    }
                    //pic.Image = Image.FromFile("100001.jpg");
                    bar.Text = Student.Tables[0].Rows[10 * i + j]["ZKZH"].ToString();
                    data.Objects.Add(bar);

                }

            }

            if (Student.Tables[0].Rows.Count % 10 != 0)
            {
                Console.WriteLine((10 * i + j).ToString());
                ReportPage page2 = new ReportPage();

                report.Pages.Add(page2);

                DataBand data2 = new DataBand();
                page2.Bands.Add(data2);

                for (int k = 10 * (i - 1) + j; k < Student.Tables[0].Rows.Count; k++)
                {

                    TextObject text1 = new TextObject();
                    if (k % 2 == 0)
                    {
                        text1.Bounds = new RectangleF(Units.Centimeters * 4, Units.Centimeters * 3 * (k % 10), Units.Centimeters * 5, Units.Centimeters * 0.6f);
                    }
                    else
                    {
                        text1.Bounds = new RectangleF(Units.Centimeters * 9 + Units.Centimeters * 4, Units.Centimeters * 3 * (k % 10 - 1), Units.Centimeters * 5, Units.Centimeters * 0.6f);

                    }

                    text1.Text = Student.Tables[0].Rows[k]["name"].ToString();
                    data2.Objects.Add(text1);

                    PictureObject pic = new PictureObject();
                    if (k % 2 == 0)
                    {
                        pic.Bounds = new RectangleF(0, Units.Centimeters * 3 * k % 10, Units.Centimeters * 2, Units.Centimeters * 2);
                    }
                    else
                    {
                        pic.Bounds = new RectangleF(Units.Centimeters * 9 + Units.Centimeters * 0, Units.Centimeters * 3 * (k % 10 - 1), Units.Centimeters * 2, Units.Centimeters * 2);

                    }
                    if (File.Exists("./" + "20" + Student.Tables[0].Rows[k]["XH"].ToString().Substring(0,2) + "/" + Student.Tables[0].Rows[k]["XH"].ToString() + ".jpg"))
                        pic.Image = Image.FromFile("./" + "20"+Student.Tables[0].Rows[k]["XH"].ToString().Substring(0,2) + "/" + Student.Tables[0].Rows[k]["XH"].ToString()+ ".jpg");
                    data2.Objects.Add(pic);

                    BarcodeObject bar = new BarcodeObject();
                    if (k % 2 == 0)
                    {
                        bar.Bounds = new RectangleF(0, Units.Centimeters * 3 * (k % 10) + Units.Centimeters * 2.5f, Units.Centimeters * 8, Units.Centimeters * 2);
                    }
                    else
                    {
                        bar.Bounds = new RectangleF(Units.Centimeters * 9 + Units.Centimeters * 0, Units.Centimeters * 3 * (k % 10 - 1) + Units.Centimeters * 2.5f, Units.Centimeters * 8, Units.Centimeters * 2);

                    }
                    //pic.Image = Image.FromFile("100001.jpg");
                    bar.Text = Student.Tables[0].Rows[k]["ZKZH"].ToString();
                    data2.Objects.Add(bar);

                }
            }
            this.Invoke(new setStatusDelegate1(setStatus2));
            this.Invoke(new setStatusDelegate1(reportShow1));
        }