📄 styledtable.cs
字号:
if ( theSource[i] == ' ')
lastBlank = i;
tmpBuffer += theSource[i];
SizeF sf = g.MeasureString(tmpBuffer,theFont);
if ( sf.Width > theWidth)
{
int breakPoint = lastBlank != -1? lastBlank+1 : (i==0?1:i);
theResult = theSource.Substring(0,breakPoint);
theSource = theSource.Substring(breakPoint);
hasMore = true;
return hasMore;
}
}
theResult = theSource;
theSource = "";
return hasMore;
}
private StyledTableColumn[] resolveColumns(XmlNode theNode)
{
XmlNodeList columnNodes = theNode.ChildNodes;
StyledTableColumn[] result = new StyledTableColumn[columnNodes.Count];
for (int i=0;i<columnNodes.Count;i++)
{
result[i] = new StyledTableColumn();
try
{
result[i].Name = Helpers.SafeXMLToText(columnNodes[i].Attributes["name"].Value);
}
catch (Exception){}
try
{
result[i].Label = Helpers.SafeXMLToText(columnNodes[i].Attributes["label"].Value);
}
catch (Exception){}
try
{
result[i].FormatMask = columnNodes[i].Attributes["formatMask"].Value;
}
catch (Exception){}
try
{
result[i].Visible = Convert.ToBoolean(columnNodes[i].Attributes["visible"].Value);
}
catch (Exception){}
try
{
result[i].CalculateTotal = Convert.ToBoolean(columnNodes[i].Attributes["calculateTotal"].Value);
}
catch (Exception){}
try
{
result[i].Width = Convert.ToInt32(columnNodes[i].Attributes["width"].Value) ;
}
catch (Exception){}
try
{
string align = columnNodes[i].Attributes["align"].Value ;
switch (align)
{
case "Center":
result[i].Alignment = StyledTableColumn.AlignmentType.Center;
break;
case "Right":
result[i].Alignment = StyledTableColumn.AlignmentType.Right;
break;
default:
result[i].Alignment = StyledTableColumn.AlignmentType.Left;
break;
}
}
catch (Exception)
{
result[i].Alignment = StyledTableColumn.AlignmentType.Left;
}
}
return result;
}
private DataTable resolveStaticTableData(XmlNode theNode)
{
DataTable dataTable = new DataTable();
XmlNodeList recordNodes = theNode.ChildNodes;
int recordCount = recordNodes.Count;
if (recordCount > 0)
{
int columnCount = recordNodes[0].ChildNodes.Count;
for (int i=0;i<columnCount;i++)
dataTable.Columns.Add(new DataColumn());
for (int i=0;i<recordNodes.Count;i++)
{
XmlNodeList fieldNodes = recordNodes[i].ChildNodes;
string[] theRow = new string[columnCount];
for (int j=0;j<columnCount;j++)
{
try
{
theRow[j] = document.ResolveParameterValues(fieldNodes[j].InnerText);
}
catch (Exception)
{
theRow[j] = "";
}
}
dataTable.Rows.Add(theRow);
}
}
return dataTable;
}
#endregion
#region Private Functions
private void drawEmptyRows(Graphics g,int drawnSoFar)
{
int topBorder;
topBorder = mRegion.Top + mCellHeight * Math.Min(drawnSoFar,GetPossibleRowNumber() );
for (int j=0;j< GetPossibleRowNumber()- Math.Min(drawnSoFar,GetPossibleRowNumber());j++)
{
g.DrawLine(new Pen(Color.Black,1), mRegion.X, topBorder, mRegion.Right,topBorder);
int leftBorder = mRegion.X;
for (int i=0;i<mData.Columns.Count;i++)
{
SizeF sf = g.MeasureString("", mDataFont);
float yPos = leftBorder+1;
g.DrawString("", mDataFont,new SolidBrush(Color.Black),yPos,topBorder+mCellHeight/2-sf.Height/2);
leftBorder += mColumns[i].Width;
}
topBorder += mCellHeight;
}
}
private void drawBorders(Graphics g,int drawnSoFar)
{
int rectHeight;
if (mData != null)
{
if (mDrawEmptyRows)
rectHeight = mCellHeight * GetPossibleRowNumber() ;
else
rectHeight = mCellHeight * ( Math.Min(drawnSoFar,GetPossibleRowNumber()) );
}
else
rectHeight = drawnSoFar*mCellHeight;
if (this.mTableBorders.DisplayTopBorder)
g.DrawLine(new Pen(this.mBorderColor,1),mRegion.X,mRegion.Y,mRegion.X, mRegion.Y);
if (this.mTableBorders.DisplayBottomBorder)
g.DrawLine(new Pen(this.mBorderColor,1),mRegion.X,mRegion.Y+rectHeight,mRegion.X+mRegion.Width, mRegion.Y+rectHeight);
if (this.mTableBorders.DisplayLeftBorder)
g.DrawLine(new Pen(this.mBorderColor,1),mRegion.X,mRegion.Y,mRegion.X, mRegion.Y+rectHeight);
if (this.mTableBorders.DisplayRightBorder)
g.DrawLine(new Pen(this.mBorderColor,1),mRegion.X+mRegion.Width, mRegion.Y, mRegion.X+mRegion.Width, mRegion.Y+rectHeight);
//Skipping first column LeftBorder as this is written aboce in the DisplayLeftBorder check
int leftBorder = mRegion.X+Columns[0].Width;
if (this.mDisplayGridLines)
{
for (int i=1;i<mColumns.Length;i++)
{
if (mColumns[i].Visible)
{
g.DrawLine(new Pen(this.mBorderColor,1),leftBorder,mRegion.Y,leftBorder, mRegion.Y+rectHeight);
leftBorder += mColumns[i].Width;
}
}
}
}
#endregion
#region ICustomPaint Members
/// <summary>
/// Paints the StyledTable
/// </summary>
/// <param name="g">The Graphics object to draw</param>
/// <remarks>Causes the PictureBox to be painted to the screen.</remarks>
public override void Paint(System.Drawing.Graphics g)
{
// TODO: Add StyledTable.Paint implementation
int RowsDrawnSoFar = 0;
int GroupByFieldIndex = -1;
string PreviousGroupByFieldValue = "";
if (this.mGroupByField != "")
{
if (mData != null)
{
if (mData.Rows.Count > 0)
{
GroupByFieldIndex = mData.Columns.IndexOf(this.mGroupByField);
PreviousGroupByFieldValue = mData.Rows[0][GroupByFieldIndex].ToString();
}
}
}
if (mDrawHeader)
RowsDrawnSoFar = drawHeader(g, mRegion, RowsDrawnSoFar, PreviousGroupByFieldValue);
if (mData != null)
{
for (int i=0;i<mData.Rows.Count;i++)
{
DataRow nextRow = mData.Rows[i];
if (this.mGroupByField != "")
{
if (PreviousGroupByFieldValue != nextRow[GroupByFieldIndex].ToString())
{
if (this.mBlankLineBeforeNewGroup)
RowsDrawnSoFar += 1;
Rectangle temp = new Rectangle(this.X, this.Y+(this.mCellHeight*RowsDrawnSoFar), this.Width, this.mCellHeight);
PreviousGroupByFieldValue = nextRow[GroupByFieldIndex].ToString();
RowsDrawnSoFar = drawHeader(g, temp, RowsDrawnSoFar, PreviousGroupByFieldValue);
}
}
RowsDrawnSoFar = drawDataRow(g,i,RowsDrawnSoFar);
}
if (mDrawEmptyRows)
drawEmptyRows(g,RowsDrawnSoFar);
if (this.mColumnTotals.Count > 0)
RowsDrawnSoFar = DrawTotals(g, RowsDrawnSoFar);
}
drawBorders(g,RowsDrawnSoFar);
}
/// <summary>
/// Gets the region of the current StyledTable
/// </summary>
/// <returns>System.Drawing.Rectangle</returns>
public override Rectangle GetRegion()
{
return mRegion;
}
/// <summary>
/// Clones the structure of the StyledTable, including all properties
/// </summary>
/// <returns><see cref="daReport.ChartBox">daReport.ChartBox</see></returns>
public override object Clone()
{
StyledTable tmp = new StyledTable();
tmp.document = this.document;
tmp.X = this.X;
tmp.Y = this.Y;
tmp.Width = this.Width;
tmp.Height = this.Height;
tmp.DataFont = this.DataFont;
StyledTableColumn[] cols = new StyledTableColumn[this.Columns.Length];
for (int i=0;i<this.Columns.Length;i++)
cols[i] = this.Columns[i].Clone() as StyledTableColumn;
tmp.Columns = cols;
tmp.Data = this.Data;
tmp.DataSource = this.DataSource;
tmp.CellHeight = this.CellHeight;
tmp.DrawEmptyRows = this.DrawEmptyRows;
tmp.DrawHeader = this.DrawHeader;
tmp.HeaderBackgroundColor = this.HeaderBackgroundColor;
tmp.HeaderFont = this.HeaderFont;
return tmp;
}
#endregion
#region Creator
/// <summary>
/// Initializes a new instance of the StyledTable class.
/// </summary>
public StyledTable()
{
}
/// <summary>
/// Initializes a new instance of the StyledTable class.
/// </summary>
/// <param name="originX">x-position of the new StyledTable</param>
/// <param name="originY">y-position of the new StyledTable</param>
/// <param name="width">Width of the new StyledTable</param>
/// <param name="height">Height of the new StyledTable</param>
/// <param name="parent">Parent of the new StyledTable</param>
public StyledTable(int originX,int originY,int width,int height, DaPrintDocument parent):this()
{
document = parent;
mRegion = new Rectangle(originX,originY,width,height);
}
#endregion
}
#region Public Class TableBorders and Converter
/// <summary>Converter class for the TableBorders class</summary>
public class TableBordersConverter : ExpandableObjectConverter
{
/// <summary>
/// Converts the given value object to the specified type, using the specified context
/// and culture information
/// </summary>
/// <param name="context">An ITypeDescriptorContext that provides a format context</param>
/// <param name="culture">A CultureInfo object</param>
/// <param name="value">The Object to convert</param>
/// <param name="destinationType">The Type to convert the value parameter to</param>
/// <returns>An Object that represents the converted value</returns>
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if (typeof(System.String).Equals(destinationType) && value.GetType() == typeof(TableBorders))
{
return "Border Settings";
}
else
{
return this.ConvertTo(context, culture, value, destinationType);
}
}
}
/// <summary>TableBorders class</summary>
[TypeConverter(typeof(TableBordersConverter))]
public class TableBorders
{
#region Declarations
private bool mDisplayTopBorder = true;
private bool mDisplayBottomBorder = true;
private bool mDisplayLeftBorder = true;
private bool mDisplayRightBorder = true;
#endregion
#region Public Properties
/// <summary></summary>
[DescriptionAttribute("Display top border")]
public bool DisplayTopBorder
{
get { return this.mDisplayTopBorder; }
set { this.mDisplayTopBorder=value; }
}
/// <summary></summary>
[DescriptionAttribute("Display bottom border")]
public bool DisplayBottomBorder
{
get { return this.mDisplayBottomBorder; }
set { this.mDisplayBottomBorder=value; }
}
/// <summary></summary>
[DescriptionAttribute("Display left border")]
public bool DisplayLeftBorder
{
get { return this.mDisplayLeftBorder; }
set { this.mDisplayLeftBorder=value; }
}
/// <summary></summary>
[DescriptionAttribute("Display right border")]
public bool DisplayRightBorder
{
get { return this.mDisplayRightBorder; }
set { this.mDisplayRightBorder=value; }
}
#endregion
}
#endregion
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -