internal ReportColumn Clone() { ReportColumn column = new ReportColumn(columnName); column.ColumnWidth = columnWidth; column.Attibutes = attibutes.Clone(); return(column); }
private void xtraTabControl1_SelectedPageChanged(object sender, TabPageChangedEventArgs e) { ReportColumn column = report.Columns.Find(xtraTabControl1.SelectedTabPage.Tag.ToString()); AddColControlToSelectPage(xtraTabControl1.SelectedTabPage); ClearColControlDataBinding(xtraTabControl1.SelectedTabPage); BindColProperty(column); }
private void BindColProperty(ReportColumn col) { columnName.DataBindings.Add(new Binding("Text", col.Attibutes, "NameZh_cn")); colFontName.DataBindings.Add(new FontNameBinding("SelectedIndex", col.Attibutes, "Font")); colFontSize.DataBindings.Add(new FontSizeBinding("SelectedIndex", col.Attibutes, "Font")); autoWidth.DataBindings.Add(new Binding("Checked", col.Attibutes, "IsAdjustWeith")); autoWrap.DataBindings.Add(new Binding("Checked", col.Attibutes, "AutoWrap")); noPrint.DataBindings.Add(new Binding("Checked", col.Attibutes.PrintStyle, "NoPrint")); noDataPrint.DataBindings.Add(new Binding("Checked", col.Attibutes.PrintStyle, "NoDataNoPrint")); colDynamicCol.DataBindings.Add(new Binding("Checked", col.Attibutes, "DynamicColumn")); colForecolor.DataBindings.Add(new ColorBinding("SelectedColor", col.Attibutes, "ForeBrush")); colBackgroundColor.DataBindings.Add(new ColorBinding("SelectedColor", col.Attibutes, "BackgroupBrush")); //基于图片点击 colFontBold.DataBindings.Add(new FontStyleBinding("Checked", col.Attibutes, "Font", "Bold", FontStyle.Bold)); colFontStike.DataBindings.Add(new FontStyleBinding("Checked", col.Attibutes, "Font", "Italic", FontStyle.Italic)); colFontUnderLine.DataBindings.Add(new FontStyleBinding("Checked", col.Attibutes, "Font", "Underline", FontStyle.Underline)); colVUp.DataBindings.Add(new VAlignBinding("Checked", col.Attibutes.Valign, "Alignment", StringAlignment.Near)); colVCenter.DataBindings.Add(new VAlignBinding("Checked", col.Attibutes.Valign, "Alignment", StringAlignment.Center)); colVBottom.DataBindings.Add(new VAlignBinding("Checked", col.Attibutes.Valign, "Alignment", StringAlignment.Far)); colHLeft.DataBindings.Add(new VAlignBinding("Checked", col.Attibutes.Valign, "LineAlignment", StringAlignment.Near)); colHCenter.DataBindings.Add(new VAlignBinding("Checked", col.Attibutes.Valign, "LineAlignment", StringAlignment.Center)); colHRight.DataBindings.Add(new VAlignBinding("Checked", col.Attibutes.Valign, "LineAlignment", StringAlignment.Far)); colUpBorder.DataBindings.Add(new Binding("Checked", col.Attibutes.BoundaryLine, "UpperBoundaryLine")); colDownBorder.DataBindings.Add(new Binding("Checked", col.Attibutes.BoundaryLine, "LowerBoundaryLine")); colLeftBorder.DataBindings.Add(new Binding("Checked", col.Attibutes.BoundaryLine, "LeftBoundaryLine")); colRightBorder.DataBindings.Add(new Binding("Checked", col.Attibutes.BoundaryLine, "RightBooundaryLine")); strike.DataBindings.Add(new InLineBinding("Checked", col.Attibutes, "Diagonal", 4)); stroke.DataBindings.Add(new InLineBinding("Checked", col.Attibutes, "Diagonal", 1)); backlash.DataBindings.Add(new InLineBinding("Checked", col.Attibutes, "Diagonal", 2)); crossLine.DataBindings.Add(new InLineBinding("Checked", col.Attibutes, "Diagonal", 3)); }
//插入列 private void InsertCol(object sender, EventArgs e) { using (ColumnNameInputDlg dlg = new ColumnNameInputDlg("", "", report.OriginalData.Columns)) { if (dlg.ShowDialog() == DialogResult.OK) { if (DesignHelper.ContainColumnName(report, dlg.IColumnText, "")) { Function.Alert("已经存在当前内部名称,插入列失败", "提示"); return; } ReportColumn newColumn = new ReportColumn(dlg.IColumnText); newColumn.Attibutes.NameZh_cn = dlg.EColumnText; int columnIndex = sheet.ActiveColumnIndex; sheet.Columns.Add(columnIndex, 1); sheet.ColumnHeader.Cells[0, columnIndex].Text = newColumn.Attibutes.NameZh_cn; sheet.ColumnHeader.Cells[1, columnIndex].Text = newColumn.ColumnName; newColumn.ColumnWidth = Convert.ToInt32(sheet.Columns[columnIndex].Width); report.Columns.Insert(columnIndex, newColumn); btn_save.Enabled = true; } } }
private void FillNewData(DataTable dt, Report currReport) { int pageNum = 1; int titleBandCount = 0; //将datatable根据-1,-2进行拆分 List <DataTable> listDt = SplitTable(dt); foreach (DataTable dataTable in listDt) { //整张表无数据,并且不是第一张表,忽略掉此表 if (dataTable.Select("rowGroup>=0").Length == 0 && pageNum > 1) { continue; } foreach (DataRow row in dataTable.Rows) { DataRow newRow = bodyData.NewRow(); //-1分页符 -2分隔符 -3宏变量 (-20,-5)共享列中的表头 int rowGroup = Convert.ToInt32(row["rowGroup"]); if (rowGroup == -1) { pageNum++; newRow[ConstantKey.XXXFLAG] = -1; bodyData.Rows.Add(newRow); } else if (rowGroup == -2) { } else if (rowGroup == -3) { macorsVerbCollection.Add(pageNum, row["macroName"].ToString(), row["macroValue"].ToString()); } else if (rowGroup >= -20 && rowGroup <= -5) { int count = 0; int dynmicColumnCount = 0; for (int i = 0; i < bodyData.Columns.Count - 1; i++) { string colName = bodyData.Columns[i].ColumnName; ReportColumn column = currReport.Columns.Find(colName); bool isDynmicColumn = column.Attibutes.DynamicColumn; string[] strs = colName.Split('_'); if (bodyTexts.HasText(Convert.ToInt32(row["rowGroup"]), colName) || isDynmicColumn) { Text text = bodyTexts[Convert.ToInt32(row["rowGroup"]), isDynmicColumn ? strs[0] : colName]; if (text == null) { if (isDynmicColumn) { count++; } continue; } Text newText = new Text(); newText.Attribute = text.Attribute; Location location = new Location(); location.Y1 = text.Location.Y1; location.Y2 = text.Location.Y2; /* * 单元格位置信息 * 数据中共享列的位置 = rpt中的位置 + 共享列个数 * 共享列之钱普通数据位置 = rpt中的位置 * 共享列之后的普通数据 = rpt中的位置 + 共享列个数 - 1(去掉原始的占列位置) */ if (isDynmicColumn) { int notVisibleColCount = dynmicColumnInfo.GetNotVistbleCount(dynmicColumnInfo.DynmicColumns, strs[0], text.ColumnSpan); int beforeNotVisibleColCount = dynmicColumnInfo.GetBeforeNotVisibleCount(dynmicColumnInfo.DynmicColumns, strs[0]); int xs = count / dynmicColumnInfo.DynmicColumns.VisibleColumnCount; location.X1 = text.Location.X1 + xs * dynmicColumnInfo.DynmicColumns.VisibleColumnCount - beforeNotVisibleColCount; location.X2 = text.Location.X2 + xs * dynmicColumnInfo.DynmicColumns.VisibleColumnCount - notVisibleColCount - beforeNotVisibleColCount; count += text.ColumnSpan - notVisibleColCount; dynmicColumnCount += text.ColumnSpan - notVisibleColCount; } else { ////共享列的个数,有共享列的情况下,需要去掉原始共享列暂用位置 //int tempDynmicColCount = dynmicColumnCount; //if (dynmicColumnCount > 0) // tempDynmicColCount = dynmicColumnCount - dynmicColumnInfo.DynmicColumns.Count; location.X1 = text.Location.X1 + dynmicColumnCount; location.X2 = text.Location.X2 + dynmicColumnCount; } if (text.ColumnSpan > dynmicColumnInfo.DynmicColumns.Count) { int colSpan = 0; List <string> list = new List <string>(); //判断合并列中是否包含了共享列,包含的话从新计算columnSpan int index = currReport.Columns.IndexOf(colName); int spanCount = GetSpanCount(report, index, text.ColumnSpan); for (int k = index; k < index + spanCount; k++) { if (currReport.Columns[k].Attibutes.DynamicColumn) { string dynmicName = currReport.Columns[k].ColumnName.Split('_')[0]; if (!list.Contains(dynmicName)) { list.Add(dynmicName); foreach (ReportColumn col in currReport.Columns) { if (dynmicName == col.ColumnName.Split('_')[0]) { colSpan += 1; } } } } else { colSpan += 1; } } int oldX2 = location.X2; location.X2 = location.X1 + colSpan - 1; int noPrintColumnCount = GetNotDisplayColumnCount(report, colName, text.ColumnSpan, listNoPrintColumn); dynmicColumnCount = location.X2 - oldX2 + noPrintColumnCount; } newText.Location = location; string context = string.Empty; if (dataTable.Columns.Contains(colName)) { context = row[colName].ToString(); } newText.Context = context; newText.BandIndex = 2; currReport.Texts.Add(newText); i += newText.ColumnSpan - 1; currReport.Bands.SetBindRowNum(2, 1); } } titleBandCount++; currReport.Bands.SetBindRowNum(2, titleBandCount); } else { int xxx_flag = 0; bool validRowGroup = false; for (int i = 0; i < bodyData.Columns.Count - 1; i++) { xxx_flag++; string colName = bodyData.Columns[i].ColumnName; bool isDynmicColumn = false; if (dynamicReport != null) { ReportColumn column = dynamicReport.Columns.Find(colName); if (column != null) { isDynmicColumn = column.Attibutes.DynamicColumn; } } string[] strs = colName.Split('_'); Text text = null; if (isDynmicColumn) { text = bodyTexts[rowGroup, strs[0]]; } else { if (bodyTexts.HasText(rowGroup, colName)) { text = bodyTexts[rowGroup, colName]; } else { text = GetPreText(rowGroup, colName); } } if (text == null) { continue; } validRowGroup = true; BodyDataStruct dataStruct = new BodyDataStruct(); //设置是否进入本页小计 setInPageRow(dataTable, row, dataStruct); if (dataTable.Columns.Contains(colName)) { dataStruct.Context = string.IsNullOrEmpty(text.CellText) ? row[colName].ToString() : text.CellText; } else { dataStruct.Context = text.CellText; } //有列合并的,查看是否存在固定不打印的列 int noPrintCount = 0; int noDataPrintCount = 0; if (text.ColumnSpan > 1) { int columnSpan = text.ColumnSpan; noPrintCount = GetNotDisplayColumnCount(currReport, colName, columnSpan, listNoPrintColumn); noDataPrintCount = GetNotDisplayColumnCount(currReport, colName, columnSpan, listNoDataPrintColumn); } //合并信息 dataStruct.ColMergeInfo.MergeCount = text.ColumnSpan - noPrintCount - noDataPrintCount; if (text.RowSpan > 1) { List <string> listRowGroup = new List <string>(); //有行合并的,查看数据中包含多少个合并行 for (int j = text.Location.Y1; j < text.Location.Y1 + text.RowSpan; j++) { foreach (Text bodyText in bodyTexts.BodyTexts) { if ( bodyText.Location.Y1 == j && bodyText.Location.Y2 == j && bodyText.Location.X1 == report.Columns.Count + 1 && bodyText.Location.X2 == report.Columns.Count + 1 ) { listRowGroup.Add(bodyText.Context); } } } DataRow[] rows = dataTable.Select(String.Format("RowGroup in ({0})", string.Join(",", listRowGroup.ToArray()))); dataStruct.RowMergeInfo.RowMergeCount = rows.Length; } else { dataStruct.RowMergeInfo.RowMergeCount = text.RowSpan; } //对齐方式 dataStruct.ColMergeInfo.LineAlignment = text.Attribute.Valign.LineAlignment; dataStruct.ColMergeInfo.Alignment = text.Attribute.Valign.Alignment; //边框信息 dataStruct.RowMergeInfo.BoundaryLine = text.Attribute.BoundaryLine.Clone(); //特殊线 switch (text.Attribute.Diagonal) { case 1: dataStruct.RowMergeInfo.BoundaryLine.IsSlash = true; break; case 2: dataStruct.RowMergeInfo.BoundaryLine.IsBackSlash = true; break; case 3: dataStruct.RowMergeInfo.BoundaryLine.IsCrossLine = true; break; default: dataStruct.RowMergeInfo.BoundaryLine.IsSlash = false; dataStruct.RowMergeInfo.BoundaryLine.IsBackSlash = false; dataStruct.RowMergeInfo.BoundaryLine.IsCrossLine = false; break; } //字体 dataStruct.ColMergeInfo.Font = text.Attribute.Font; newRow[colName] = dataStruct; i += text.ColumnSpan - 1 - noPrintCount - noDataPrintCount; } if (validRowGroup) { newRow[ConstantKey.XXXFLAG] = rowGroup > 1000 ? rowGroup : xxx_flag; bodyData.Rows.Add(newRow); } } } } }
//刷新当前报表节点 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; } }
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; }