Пример #1
0
        public static void RootCopy(Report sourceReport, Report destReport)
        {
            //生成块模型
            RptTextModule rootModule = new RptTextModule(sourceReport, new List <int>(new int[] { Bands.RootBandID }));

            //清除已以前的表脚
            destReport.Texts.ClearTexts(Bands.RootBandID);
            //同步表脚行显示及行数
            sourceReport.Bands.CopyRootTo(destReport.Bands);
            //依据新的columnsWidth生成RootTexts
            Texts texts = rootModule.MapNewText(destReport.Columns.GetColumnsWidth(null));

            foreach (Text text in texts)
            {
                destReport.Texts.Add(text);
            }
            destReport.WriteRpt();
        }
Пример #2
0
 private void btn_OK_Click(object sender, EventArgs e)
 {
     report.WriteRpt();
     this.Close();
 }
        private void SetReportProperty(TreeListNodes nodes)
        {
            foreach (TreeListNode node in nodes)
            {
                if (node.Checked && node["src"].ToString() != "")
                {
                    string rptPath = string.Empty;
                    if (!Function.DebugMode)
                    {
                        rptPath = Function.UserReportFolder + node["src"];
                        if (!System.IO.File.Exists(rptPath))
                        {
                            string sysRptPath = Function.ReportFolder + node["src"];
                            if (System.IO.File.Exists(sysRptPath))
                            {
                                System.IO.File.Copy(sysRptPath, rptPath);
                            }
                        }
                    }
                    else
                    {
                        rptPath = Function.ReportFolder + node["src"];
                    }
                    if (!System.IO.File.Exists(rptPath))
                    {
                        continue;
                    }
                    Report report = new Report();
                    report.RptFilePath = rptPath;
                    report.ReadRPT();

                    string fontName = ddlFontName.Text == "默认" ? report.Attributes.Font.Name : ddlFontName.Text;
                    float  fontSize = ddlFontSize.Text == "默认" ? report.Attributes.Font.Size : Math.Abs(float.Parse(ddlFontSize.Text));
                    report.Attributes.Font = new Font(fontName, fontSize);
                    foreach (ReportColumn column in report.Columns)
                    {
                        column.Attibutes.Font = new Font(fontName, fontSize, report.Attributes.Font.Style);
                    }
                    if (ddlMutliRowHeight.Text != "默认")
                    {
                        report.Attributes.RowHeiht = float.Parse(ddlMutliRowHeight.Text.Replace("倍行高", ""));
                    }
                    if (checkBrifeReport.CheckState != CheckState.Indeterminate)
                    {
                        report.Attributes.PrintStyle.IsBrifeStyle = checkBrifeReport.Checked;
                    }

                    Texts titleTexts = report.Texts.GetTextsBy(1);
                    foreach (Text text in report.Texts)
                    {
                        string    textFontName = string.Empty;
                        string    textFontSize = string.Empty;
                        FontStyle style        = new FontStyle();
                        bool      bold         = false;
                        switch (text.BandIndex)
                        {
                        case 1:
                            textFontName = ddlTitleFontName.Text;
                            textFontSize = ddlTitleFontSize.Text;
                            if (checkTitleBold.CheckState == CheckState.Indeterminate)
                            {
                                bold = text.Attribute.Font.Bold;
                            }
                            else
                            {
                                bold = checkTitleBold.Checked;
                            }
                            //在bandIndex = 1的区域中,字体最大的归为标题区,较小字体的归为表头区
                            foreach (Text titleText in titleTexts)
                            {
                                if (text.Attribute.Font.Size < titleText.Attribute.Font.Size)
                                {
                                    textFontName = ddlHeadFontName.Text;
                                    textFontSize = ddlHeadFontSize.Text;
                                    if (checkHeadBold.CheckState == CheckState.Indeterminate)
                                    {
                                        bold = text.Attribute.Font.Bold;
                                    }
                                    else
                                    {
                                        bold = checkHeadBold.Checked;
                                    }
                                }
                            }
                            break;

                        case 2:
                            textFontName = ddlHeadFontName.Text;
                            textFontSize = ddlHeadFontSize.Text;
                            if (checkHeadBold.CheckState == CheckState.Indeterminate)
                            {
                                bold = text.Attribute.Font.Bold;
                            }
                            else
                            {
                                bold = checkHeadBold.Checked;
                            }
                            break;

                        case 3:
                            textFontName = ddlBodyFontName.Text;
                            textFontSize = ddlBodyFontSize.Text;
                            if (checkBodyBold.CheckState == CheckState.Indeterminate)
                            {
                                bold = text.Attribute.Font.Bold;
                            }
                            else
                            {
                                bold = checkBodyBold.Checked;
                            }
                            break;

                        case 4:
                            textFontName = ddlSummaryFontName.Text;
                            textFontSize = ddlSummaryFontSize.Text;
                            if (checkSummaryBold.CheckState == CheckState.Indeterminate)
                            {
                                bold = text.Attribute.Font.Bold;
                            }
                            else
                            {
                                bold = checkSummaryBold.Checked;
                            }
                            break;

                        case 5:
                            textFontName = ddlFootFontName.Text;
                            textFontSize = ddlFootFontSize.Text;
                            if (checkFootBold.CheckState == CheckState.Indeterminate)
                            {
                                bold = text.Attribute.Font.Bold;
                            }
                            else
                            {
                                bold = checkFootBold.Checked;
                            }
                            break;
                        }
                        if (bold)
                        {
                            style |= FontStyle.Bold;
                        }
                        if (text.Attribute.Font.Italic)
                        {
                            style |= FontStyle.Italic;
                        }
                        if (text.Attribute.Font.Underline)
                        {
                            style |= FontStyle.Underline;
                        }


                        textFontName = textFontName == "默认" ? text.Attribute.Font.Name : textFontName;
                        textFontSize = textFontSize == "默认" ? text.Attribute.Font.Size.ToString() : textFontSize;
                        try
                        {
                            text.Attribute.Font = new Font(textFontName, Math.Abs(float.Parse(textFontSize)), style);
                        }
                        catch (Exception e)
                        {
                            Function.Alert(String.Format("批量修改字体设置错误,信息:{0}", e), "错误");
                        }
                    }
                    if (!string.IsNullOrEmpty(txtTopMargin.Text))
                    {
                        report.Attributes.Margin.Top = ConvertUtil.GetBoundary(txtTopMargin.Text);
                    }
                    if (!string.IsNullOrEmpty(txtBottomMargin.Text))
                    {
                        report.Attributes.Margin.Bottom = ConvertUtil.GetBoundary(txtBottomMargin.Text);
                    }
                    if (!string.IsNullOrEmpty(txtLeftMargin.Text))
                    {
                        report.Attributes.Margin.Left = ConvertUtil.GetBoundary(txtLeftMargin.Text);
                    }
                    if (!string.IsNullOrEmpty(txtRightMargin.Text))
                    {
                        report.Attributes.Margin.Right = ConvertUtil.GetBoundary(txtRightMargin.Text);
                    }
                    report.WriteRpt(false);
                }
                SetReportProperty(node.Nodes);
            }
        }
        //刷新当前报表节点
        public void ReferenceFocusedNode()
        {
            if (ReportList.FocusedNode == null)
            {
                return;
            }
            //InitMutliProjectStruct();
            string fileName = ReportList.FocusedNode.GetValue("src").ToString();

            if (!string.IsNullOrEmpty(fileName))
            {
                string descrName  = ReportList.FocusedNode.GetValue("name").ToString();
                int    descrLevel = 0;
                if (!int.TryParse(ReportList.FocusedNode.GetValue("level").ToString(), out descrLevel))
                {
                    Function.Alert("报表相关XML的LEVEL数据无效!", "提示");
                }
                curReport = new Report(descrName, descrLevel);

                curReport.ReadRPT(fileName);

                //用户报表
                string userFilePath = curReport.RptFilePath;
                if (userFilePath.StartsWith(Function.UserReportFolder))
                {
                    string sysFilePath = Function.ReportFolder + fileName;
                    if (File.GetLastWriteTime(sysFilePath) > File.GetLastWriteTime(userFilePath))
                    {
                        //系统报表新于用户报表,更新用户报表,保留原有列显示信息和参数设置
                        Report newReport = new Report(descrName, descrLevel);
                        newReport.RptFilePath = sysFilePath;
                        newReport.ReadRPT();
                        foreach (ReportColumn column in newReport.Columns)
                        {
                            ReportColumn col = curReport.Columns.Find(column.ColumnName);
                            if (col != null)
                            {
                                column.Attibutes.PrintStyle.NoPrint = col.Attibutes.PrintStyle.NoPrint;
                            }
                        }
                        curReport             = newReport;
                        curReport.RptFilePath = userFilePath;
                        curReport.WriteRpt(false);
                    }
                }

                arguments.Enabled = (Function.ProfileInt(curReport.RptFilePath, "报表参数", "enabled", 0) == 1 &&
                                     Function.ProfileInt(curReport.RptFilePath, "报表参数", "count", 0) != 0);
                //初始化预览方式数据
                //curReport.InitReportData(projectDataManager, 0);
                Dictionary <string, object> dict = new Dictionary <string, object>();
                dict["生成方式"] = "预览";
                curReport.InitReportData(projectDataManager.ProjectData as DataSet, dict);
                Repaint();
            }
            else
            {
                curReport        = null;
                ReportMode.Image = null;
            }
        }
Пример #5
0
        private void Save()
        {
            List <ReportColumn> listReportColumn = new List <ReportColumn>();

            foreach (Column col in sheet.Columns)
            {
                if (col.Label.ToLower() == "rowgroup")
                {
                    continue;
                }
                ReportColumn reportColumn = report.Columns[col.Label];
                listReportColumn.Add(reportColumn);
            }
            report.Columns.Clear();
            foreach (ReportColumn reportColumn in listReportColumn)
            {
                report.Columns.Add(reportColumn);
            }

            report.Texts.Clear();
            report.Bands.ClearEchoDic();
            int index     = 0;
            int bandIndex = 0;
            int count     = 0;

            for (int i = 0; i < sheet.RowCount; i++)
            {
                if (sheet.Rows[i].Tag != null)
                {
                    count = 0;
                    switch (sheet.Rows[i].Tag.ToString())
                    {
                    case "标题":
                        bandIndex = 1;
                        index     = startHeadIndex;
                        break;

                    case "表头":
                        bandIndex = 2;
                        index     = startTitileIndex;
                        break;

                    case "表体":
                        bandIndex = 3;
                        index     = startBodyIndex;
                        break;

                    case "页汇":
                        bandIndex = 4;
                        index     = startPageIndex;
                        break;

                    case "表脚":
                        bandIndex = 5;
                        index     = startFootIndex;
                        break;
                    }
                    //初始化
                    report.Bands.SetBindRowNum(bandIndex, 0);
                    continue;
                }
                count++;
                if (sheet.Cells[i, sheet.ColumnCount - 1].Text != "True")
                {
                    report.Bands.SetBindRowEcho(bandIndex, i - index + 1, false);
                }
                report.Bands.SetBindRowNum(bandIndex, count);

                for (int j = 0; j < sheet.ColumnCount; j++)
                {
                    if (sheet.Cells[i, j].CellType is FarPoint.Win.Spread.CellType.CheckBoxCellType)
                    {
                        continue;
                    }
                    DataRow[] rows = dtSpan.Select(string.Format("{0} >= minY and {0} <= maxY and {1} >= minX and {1} <= maxX", i, j));
                    if (rows.Length == 0)
                    {
                        //不在合并单元格中
                        Text text = new Text();
                        text.BandIndex   = bandIndex;
                        text.Context     = sheet.Cells[i, j].Text;
                        text.Location.X1 = j + 1;
                        text.Location.Y1 = i + 1 - index;
                        text.Location.X2 = j + sheet.Cells[i, j].ColumnSpan;
                        text.Location.Y2 = i + sheet.Cells[i, j].RowSpan - index;

                        SpecialLine line = specialLineInfo.GetSpecialLine(sheet.Cells[i, j]);
                        if (line != null)
                        {
                            text.Attribute.Diagonal = line.LineType;
                        }

                        DesignHelper.SetTextPropertys(sheet.Cells[i, j], text);

                        report.Texts.Add(text);
                        DataRow row = dtSpan.NewRow();
                        row["minX"] = j;
                        row["minY"] = i;
                        row["maxX"] = j + sheet.Cells[i, j].ColumnSpan - 1;
                        row["maxY"] = i + sheet.Cells[i, j].RowSpan - 1;
                        dtSpan.Rows.Add(row);
                    }
                }
            }
            report.WriteRpt();
            dtSpan.Clear();
            btn_save.Enabled = false;
        }