⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 styledtable.cs

📁 是用c#实现的一个有关于报表设计的程序代码
💻 CS
📖 第 1 页 / 共 4 页
字号:
#region License
/*
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option)
any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
*/
#endregion

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Design;
using System.Xml;


namespace daReport
{
	/// <summary>
	/// Summary description for StyledTable.
	/// </summary>
	public class StyledTable : ICustomPaint
	{
		#region Declarations
		private int mCellHeight = 18;
		private DataTable mData;
		private string mDataSource;
		private bool mSelectable = true;
		private Color mBorderColor = Color.Black;
		private string mGroupByField = "";
		private bool mBlankLineBeforeNewGroup = false;
		private bool mLineUnderNewGroup = false;
		private bool mDisplayGroupTitle = false;
		private StyledTableColumn[] mColumns = new StyledTableColumn[0];
		private Hashtable mColumnTotals = new Hashtable();

		private Rectangle mRegion = new Rectangle(0,0,0,0);
		private Font mDataFont = new Font("Tahoma",8,FontStyle.Regular);
		private Color mDataFontColor = Color.Black;
		private bool mDrawEmptyRows = false;

		private bool mDrawHeader = true;
		private Font mHeaderFont = new Font("Tahoma",8,FontStyle.Bold);
		private Color mHeaderFontColor = Color.Black;
		private Color mHeaderBackgroundColor = Color.White;

		private TableBorders mTableBorders = new TableBorders();
		private bool mDisplayGridLines = true;
		#endregion

		#region Public Properties

		/// <summary>
		/// Gets/Sets whether a blank line is inserted before a new group header
		/// </summary>
		/// <remarks>If set to true, a blank line is inserted before new group header are written out.
		/// </remarks>
		[Category("Appearance"), Description("Sets whether the a blank line is written out  before new group headers.")]
		public bool BlankLineBeforeNewGroup
		{
			get { return mBlankLineBeforeNewGroup; }
			set { mBlankLineBeforeNewGroup=value; }
		}


		/// <summary>
		/// Gets/Sets the border color for the StyledTable
		/// </summary>
		/// <remarks>This property sets the border color of the StyledTable object. This can be any color
		/// from the System.Drawing.Color structure
		/// </remarks>
		[Category("Appearance")]
		public Color BorderColor
		{
			get { return this.mBorderColor; }
			set { this.mBorderColor=value; }
		}


		/// <summary>
		/// Returns relative data row height after checking if row will be multi-line
		/// </summary>
		/// <param name="CurrentRow">Current Data Row to calculate height</param>
		/// <param name="g">Current Graphics object</param>
		/// <returns>integer value of relative row height</returns>
		public int CalculateRelativeDataRowHeight(DataRow CurrentRow, Graphics g)
		{
			int relativeDataRowHeight = 0;

			for (int i=0;i<Columns.Length;i++)
			{
				StyledTableColumn CurrentColumn = Columns[i];

				if (CurrentColumn.Visible)
				{
					object theObject = CurrentRow[CurrentColumn.Name];
					string tmpValue = FormatValue(theObject,CurrentRow.Table.Columns[CurrentColumn.Name].DataType, CurrentColumn.FormatMask);
					string theLine = "";
					int drawnRowsCounter = 0;

					bool hasMore = false;
					do
					{
						hasMore = splitString(ref tmpValue,ref theLine,mColumns[i].Width,g,mDataFont);					
						drawnRowsCounter++;
					}
					while ( hasMore );

					if (drawnRowsCounter>relativeDataRowHeight)
						relativeDataRowHeight = drawnRowsCounter;
				}
			}

			return relativeDataRowHeight;
		}


		// calculates relative header height with respect to cell height
		/// <summary>
		/// Returns relative header row height after checking if headers will be multi-line
		/// </summary>
		/// <param name="g">Graphics Object</param>
		/// <returns>integer value of relative Header row height</returns>
		public int CalculateRelativeHeaderHeight(Graphics g)
		{
			if (!mDrawHeader) return 0;

			int headerRelativeHeight = 0;

			ArrayList[] headerLabels = new ArrayList[mColumns.Length];
			for (int i=0;i<mColumns.Length;i++)
			{
				if (mColumns[i].Visible)
				{
					string tmpValue = mColumns[i].Label;
					string theLine = "";
					headerLabels[i] = new ArrayList();
					bool WillTextWrap = false;
					do
					{
						WillTextWrap = splitString(ref tmpValue,ref theLine,mColumns[i].Width,g,mHeaderFont);
						headerLabels[i].Add(theLine);
					}
					while(WillTextWrap);

					if (headerLabels[i].Count > headerRelativeHeight)
						headerRelativeHeight = headerLabels[i].Count;
				}
			}
			if (this.mDisplayGroupTitle)
				headerRelativeHeight += 1;

			if (this.mBlankLineBeforeNewGroup)
				headerRelativeHeight += 1;

			return headerRelativeHeight;
		}
		
		
		/// <summary>
		/// Gets/Sets the height of every cell in the table
		/// </summary>
		public int CellHeight
		{
			get {return mCellHeight;}
			set {mCellHeight = value;}
		}

		
		/// <summary>
		/// A collection of <see cref="daReport.StyledTableColumn">daReport.StyledTableColumn</see> columns.
		/// </summary>
		[Category("Data"), Description("Table columns.")]
		public StyledTableColumn[] Columns
		{
			get {return mColumns;}
			set 
			{
				mColumns = value;
				if (mColumns.Length>0)
				{
					int sumOfWidths = 0;
					for (int i=0;i<mColumns.Length;i++)
					{
						sumOfWidths += mColumns[i].Width;
					}
					mRegion.Width = sumOfWidths;
				}
			}
		}

		
		/// <summary>
		/// Gets/Sets the current System.Data.DataTable which contains the data for the StyledTable object.
		/// </summary>
		[Browsable(false)]
		public DataTable Data
		{
			get {return mData;}
			set {mData = value;}
		}


		/// <summary>
		/// Gets/Sets the data font for the StyledTable
		/// </summary>
		/// <remarks>This property sets the font of the StyledTable data rows. This can be any font
		/// from the System.Drawing.Font structure
		/// </remarks>
		[Category("DataRow Settings")]
		public Font DataFont
		{
			get {return mDataFont;}
			set {mDataFont = value;}
		}


		/// <summary>
		/// Gets/Sets the data font color for the StyledTable
		/// </summary>
		/// <remarks>This property sets the data row font color of the StyledTable object. This can be any color
		/// from the System.Drawing.Color structure
		/// </remarks>
		[Category("DataRow Settings")]
		public Color DataFontColor
		{
			get { return this.mDataFontColor; }
			set { this.mDataFontColor=value; }
		}

		
		/// <summary>
		/// The name for DataTable which exports data to this styled table
		/// </summary>
		/// <remarks>
		/// Relevant for dynamic contents table. The binding itself is done programmaticly with
		/// <see cref="daReport.DaPrintDocument.AddData">daReport.DaPrintDocument.AddData(DataTable)</see>
		/// method of the DaPrintDocument class.
		/// </remarks>
		[Category("Data"), Description("The name for DataTable which exports data to this styled table. Relevant for dynamic contents table. The binding itself is done programmaticly with AddData(DataTable) method of the DaPrintDocument class.")]
		public string DataSource
		{
			get {return mDataSource;}
			set {mDataSource = value;}
		}


		/// <summary>
		/// Gets/Sets whether the grid lines for the table are displayed
		/// </summary>
		/// <remarks>If set to true, the table grid lines are displayed, otherwise not.
		/// </remarks>
		[Category("Appearance"), Description("Sets whether the table's grid lines are displayed.")]
		public bool DisplayGridLines
		{
			get { return this.mDisplayGridLines; }
			set { this.mDisplayGridLines=value; }
		}


		/// <summary>
		/// Gets/Sets whether an underline is placed under the new group header
		/// </summary>
		/// <remarks>If set to true, a line is placed under the new group header.
		/// </remarks>
		[Category("Appearance"), Description("Sets whether the group title is displayed for new groups.")]
		public bool DisplayGroupTitle
		{
			get { return this.mDisplayGroupTitle; }
			set { this.mDisplayGroupTitle=value; }
		}


		/// <summary>
		/// Gets/Sets whether an the top border of the table is displayed
		/// </summary>
		/// <remarks>If set to true, the tables top border is not displayed.
		/// </remarks>
		[Category("Appearance"), Description("Settings for the table borders.")]
		public TableBorders DisplayTableBorders
		{
			get { return this.mTableBorders; }
			set { this.mTableBorders=value; }
		}


		/// <summary>
		/// Gets/Sets whether empty rows be drawn if any space in table area remains unused.
		/// </summary>
		[Category("DataRow Settings"), Description("Should empty rows be drawn if any space in table area remains unused.")]
		public bool DrawEmptyRows
		{
			get {return mDrawEmptyRows;}
			set {mDrawEmptyRows = value;}
		}


		/// <summary>
		/// Gets/Sets whether to draw the table header row in the generated report.
		/// </summary>
		/// <remarks>This will affect how many possible rows can be drawn on the table.
		/// See <see cref="daReport.StyledTable.GetPossibleRowNumber">daReport.StyledTable.GetPossibleRowNumber</see></remarks>
		[Category("Header Settings")]
		public bool DrawHeader
		{
			get {return mDrawHeader;}
			set {mDrawHeader = value;}
		}


		/// <summary>
		/// Returns possible number of rows for the current table region
		/// </summary>
		/// <returns>integer value of possible number of rows for current table</returns>
		public int GetPossibleRowNumber()
		{
			return mRegion.Height/mCellHeight;
		}


		/// <summary>
		/// Gets/Sets the GroupByField for the data
		/// </summary>
		/// <remarks>This property is only used for dynamic tables. Grouping occurs on the field specified.</remarks>
		[Category("Data")]
		public string GroupByField
		{
			get { return this.mGroupByField; }
			set { this.mGroupByField=value; }
		}


		/// <summary>
		/// Gets/Sets the header background color for the StyledTable
		/// </summary>
		/// <remarks>This property sets the header background color of the StyledTable object. This can be any color
		/// from the System.Drawing.Color structure
		/// </remarks>
		[Category("Header Settings")]
		public Color HeaderBackgroundColor
		{
			get {return mHeaderBackgroundColor;}
			set {mHeaderBackgroundColor = value;}
		}


		/// <summary>
		/// Gets/Sets the header font for the StyledTable
		/// </summary>
		/// <remarks>This property sets the header font of the StyledTable object. This can be any font
		/// from the System.Drawing.Font structure
		/// </remarks>
		[Category("Header Settings")]
		public Font HeaderFont
		{
			get {return mHeaderFont;}
			set {mHeaderFont = value;}
		}


		/// <summary>
		/// Gets/Sets the header font color for the StyledTable
		/// </summary>
		/// <remarks>This property sets the header font color of the StyledTable object. This can be any color
		/// from the System.Drawing.Color structure
		/// </remarks>
		[Category("Header Settings")]
		public Color HeaderFontColor
		{
			get { return this.mHeaderFontColor; }
			set { this.mHeaderFontColor=value; }
		}


		/// <summary>
		/// Gets/Sets whether an underline is placed under the new group header
		/// </summary>
		/// <remarks>If set to true, a line is placed under the new group header.
		/// </remarks>
		[Category("Appearance"), Description("Sets whether a line is written under the new group header.")]
		public bool LineUnderNewGroup
		{
			get { return this.mLineUnderNewGroup; }
			set { this.mLineUnderNewGroup=value; }
		}

		
		/// <summary>
		/// Gets/Sets the static data for the StyledTable object.
		/// </summary>
		[Category("Data")]
		[Editor(typeof(Editors.StaticTableEditor), typeof(UITypeEditor)), Description("Static table data.")]
		public string[][] StaticData
		{
			get
			{
				if (Data != null) 
				{

					int colNumber = Columns.Length;
					int rowNumber = Data.Rows.Count;

					string[][] tmpData = new string[rowNumber+1][];
					for (int i=0;i<rowNumber+1;i++)
					{
						tmpData[i] = new string[colNumber];
					}
				
					for (int j=0;j<colNumber;j++)
					{
						tmpData[0][j] = Columns[j].Name;
					}

					for (int i=0;i<rowNumber;i++)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -