699 lines
11 KiB
C#
699 lines
11 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Drawing;
|
|
|
|
namespace GoldPrinter
|
|
{
|
|
public class GridBase : IGrid, IDisposable
|
|
{
|
|
protected ArrayList _arrRowsHeight;
|
|
|
|
protected ArrayList _arrColsWidth;
|
|
|
|
protected ArrayList _arrColsAlign;
|
|
|
|
protected string[,] _arrStrGrid = new string[0, 0];
|
|
|
|
private Point _location = new Point(0, 0);
|
|
|
|
private int _Width = 300;
|
|
|
|
private int _Height = 200;
|
|
|
|
private Font _font = new Font("宋体", 10f);
|
|
|
|
private AlignFlag _alignFlag = AlignFlag.Left;
|
|
|
|
private GridLineFlag _gridLineFlag = GridLineFlag.Both;
|
|
|
|
private GridMergeFlag _gridMergeFlag = GridMergeFlag.None;
|
|
|
|
private GridBorderFlag _gridBorderFlag = GridBorderFlag.Single;
|
|
|
|
private int _rows = 0;
|
|
|
|
private int _cols = 0;
|
|
|
|
private int _fixedRows = 0;
|
|
|
|
private int _fixedCols = 0;
|
|
|
|
private int _row = 0;
|
|
|
|
private int _col = 0;
|
|
|
|
private int _rowSel = 0;
|
|
|
|
private int _colSel = 0;
|
|
|
|
private int _rowheight = 20;
|
|
|
|
private int _colWidth = 75;
|
|
|
|
public Point Location
|
|
{
|
|
get
|
|
{
|
|
return this._location;
|
|
}
|
|
set
|
|
{
|
|
this._location = value;
|
|
}
|
|
}
|
|
|
|
public int Width
|
|
{
|
|
get
|
|
{
|
|
return this._Width;
|
|
}
|
|
set
|
|
{
|
|
this._Width = this.GetValidIntValue(value);
|
|
}
|
|
}
|
|
|
|
public int Height
|
|
{
|
|
get
|
|
{
|
|
return this._Height;
|
|
}
|
|
set
|
|
{
|
|
this._Height = this.GetValidIntValue(value);
|
|
}
|
|
}
|
|
|
|
public Font Font
|
|
{
|
|
get
|
|
{
|
|
return this._font;
|
|
}
|
|
set
|
|
{
|
|
this._font = value;
|
|
}
|
|
}
|
|
|
|
public AlignFlag AlignMent
|
|
{
|
|
get
|
|
{
|
|
return this._alignFlag;
|
|
}
|
|
set
|
|
{
|
|
this._alignFlag = value;
|
|
this.ChangeFieldAlignMent();
|
|
}
|
|
}
|
|
|
|
public GridLineFlag Line
|
|
{
|
|
get
|
|
{
|
|
return this._gridLineFlag;
|
|
}
|
|
set
|
|
{
|
|
this._gridLineFlag = value;
|
|
}
|
|
}
|
|
|
|
public GridMergeFlag Merge
|
|
{
|
|
get
|
|
{
|
|
return this._gridMergeFlag;
|
|
}
|
|
set
|
|
{
|
|
this._gridMergeFlag = value;
|
|
}
|
|
}
|
|
|
|
public GridBorderFlag Border
|
|
{
|
|
get
|
|
{
|
|
return this._gridBorderFlag;
|
|
}
|
|
set
|
|
{
|
|
this._gridBorderFlag = value;
|
|
}
|
|
}
|
|
|
|
public int Rows
|
|
{
|
|
get
|
|
{
|
|
return this._rows;
|
|
}
|
|
set
|
|
{
|
|
this._rows = this.GetValidIntValue(value);
|
|
this.ChangeFieldRows();
|
|
}
|
|
}
|
|
|
|
public int Cols
|
|
{
|
|
get
|
|
{
|
|
return this._cols;
|
|
}
|
|
set
|
|
{
|
|
this._cols = this.GetValidIntValue(value);
|
|
this.ChangeFieldCols();
|
|
}
|
|
}
|
|
|
|
public int FixedRows
|
|
{
|
|
get
|
|
{
|
|
return this._fixedRows;
|
|
}
|
|
set
|
|
{
|
|
this._fixedRows = this.GetValidIntValue(value);
|
|
if (this._fixedRows > this.Rows)
|
|
{
|
|
this._fixedRows = this.Rows;
|
|
}
|
|
}
|
|
}
|
|
|
|
public int FixedCols
|
|
{
|
|
get
|
|
{
|
|
return this._fixedCols;
|
|
}
|
|
set
|
|
{
|
|
this._fixedCols = this.GetValidIntValue(value);
|
|
if (this._fixedCols > this.Cols)
|
|
{
|
|
this._fixedCols = this.Cols;
|
|
}
|
|
}
|
|
}
|
|
|
|
public int Row
|
|
{
|
|
get
|
|
{
|
|
return this._row;
|
|
}
|
|
set
|
|
{
|
|
this._row = this.GetValidIntValue(value);
|
|
if (this._row >= this.Rows)
|
|
{
|
|
this._row = this.Rows - 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
public int Col
|
|
{
|
|
get
|
|
{
|
|
return this._col;
|
|
}
|
|
set
|
|
{
|
|
this._col = this.GetValidIntValue(value);
|
|
if (this._col >= this.Cols)
|
|
{
|
|
this._col = this.Cols - 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
public int RowSel
|
|
{
|
|
get
|
|
{
|
|
return this._rowSel;
|
|
}
|
|
set
|
|
{
|
|
int num = this.GetValidIntValue(value);
|
|
if (num >= this._rows)
|
|
{
|
|
num = this._rows - 1;
|
|
}
|
|
this._rowSel = num;
|
|
}
|
|
}
|
|
|
|
public int ColSel
|
|
{
|
|
get
|
|
{
|
|
return this._colSel;
|
|
}
|
|
set
|
|
{
|
|
int num = this.GetValidIntValue(value);
|
|
if (num >= this._cols)
|
|
{
|
|
num = this._cols - 1;
|
|
}
|
|
this._rowSel = num;
|
|
}
|
|
}
|
|
|
|
public int PreferredRowHeight
|
|
{
|
|
get
|
|
{
|
|
return this._rowheight;
|
|
}
|
|
set
|
|
{
|
|
this._rowheight = this.GetValidIntValue(value);
|
|
this.ChangeFieldPreferredRowHeight();
|
|
}
|
|
}
|
|
|
|
public int PreferredColWidth
|
|
{
|
|
get
|
|
{
|
|
return this._rowheight;
|
|
}
|
|
set
|
|
{
|
|
this._rowheight = this.GetValidIntValue(value);
|
|
this.ChangeFieldPreferredColWidth();
|
|
}
|
|
}
|
|
|
|
public int[] RowsHeight
|
|
{
|
|
get
|
|
{
|
|
int[] array = new int[this._rows];
|
|
for (int i = 0; i < this._rows; i++)
|
|
{
|
|
array[i] = (int)this._arrRowsHeight[i];
|
|
}
|
|
return array;
|
|
}
|
|
set
|
|
{
|
|
int num = 0;
|
|
while (num < this._rows && num < value.Length)
|
|
{
|
|
this._arrRowsHeight[num] = value[num];
|
|
num++;
|
|
}
|
|
}
|
|
}
|
|
|
|
public int[] ColsWidth
|
|
{
|
|
get
|
|
{
|
|
int[] array = new int[this._cols];
|
|
for (int i = 0; i < this._cols; i++)
|
|
{
|
|
array[i] = (int)this._arrColsWidth[i];
|
|
}
|
|
return array;
|
|
}
|
|
set
|
|
{
|
|
int num = 0;
|
|
while (num < this._cols && num < value.Length)
|
|
{
|
|
this._arrColsWidth[num] = value[num];
|
|
num++;
|
|
}
|
|
}
|
|
}
|
|
|
|
public AlignFlag[] ColsAlignment
|
|
{
|
|
get
|
|
{
|
|
AlignFlag[] array = new AlignFlag[this._cols];
|
|
for (int i = 0; i < this._cols; i++)
|
|
{
|
|
array[i] = (AlignFlag)this._arrColsAlign[i];
|
|
}
|
|
return array;
|
|
}
|
|
set
|
|
{
|
|
AlignFlag[] array = new AlignFlag[this._cols];
|
|
int num = 0;
|
|
while (num < this._cols && num < array.Length)
|
|
{
|
|
this._arrColsAlign[num] = array[num];
|
|
num++;
|
|
}
|
|
}
|
|
}
|
|
|
|
public string Text
|
|
{
|
|
get
|
|
{
|
|
return this._arrStrGrid[this._row, this._col];
|
|
}
|
|
set
|
|
{
|
|
this._arrStrGrid[this._row, this._col] = value;
|
|
}
|
|
}
|
|
|
|
public string[,] GridText
|
|
{
|
|
get
|
|
{
|
|
return this._arrStrGrid;
|
|
}
|
|
set
|
|
{
|
|
this._arrStrGrid = value;
|
|
this._rows = this._arrStrGrid.GetLength(0);
|
|
this._cols = this._arrStrGrid.GetLength(1);
|
|
this.InitRowHeight();
|
|
this.InitColWidth();
|
|
this.InitColAlignMent();
|
|
}
|
|
}
|
|
|
|
private int GetValidIntValue(int val)
|
|
{
|
|
int num = val;
|
|
if (num < 0)
|
|
{
|
|
num = 0;
|
|
}
|
|
if (num > 2147483647)
|
|
{
|
|
num = 2147483647;
|
|
}
|
|
return num;
|
|
}
|
|
|
|
public int get_RowHeight(int index)
|
|
{
|
|
return (int)this._arrRowsHeight[index];
|
|
}
|
|
|
|
public void set_RowHeight(int index, int rowHeight)
|
|
{
|
|
int validIntValue = this.GetValidIntValue(rowHeight);
|
|
this._arrRowsHeight[index] = validIntValue;
|
|
}
|
|
|
|
public int get_ColWidth(int index)
|
|
{
|
|
return (int)this._arrColsWidth[index];
|
|
}
|
|
|
|
public void set_ColWidth(int index, int colWidth)
|
|
{
|
|
int validIntValue = this.GetValidIntValue(colWidth);
|
|
this._arrColsWidth[index] = validIntValue;
|
|
}
|
|
|
|
public AlignFlag get_ColAlignment(int index)
|
|
{
|
|
return (AlignFlag)this._arrColsAlign[index];
|
|
}
|
|
|
|
public void set_ColAlignment(int index, AlignFlag colAlignment)
|
|
{
|
|
this._arrColsAlign[index] = colAlignment;
|
|
}
|
|
|
|
public string get_TextMatrix(int row, int col)
|
|
{
|
|
return this._arrStrGrid[row, col];
|
|
}
|
|
|
|
public void set_TextMatrix(int row, int col, string textMatrix)
|
|
{
|
|
this._arrStrGrid[row, col] = textMatrix;
|
|
}
|
|
|
|
protected virtual void ChangeFieldPreferredRowHeight()
|
|
{
|
|
this.InitRowHeight();
|
|
}
|
|
|
|
protected virtual void ChangeFieldPreferredColWidth()
|
|
{
|
|
this.InitColWidth();
|
|
}
|
|
|
|
protected virtual void ChangeFieldAlignMent()
|
|
{
|
|
this.InitColAlignMent();
|
|
}
|
|
|
|
protected virtual void ChangeFieldRows()
|
|
{
|
|
this.ReDimArrString(ref this._arrStrGrid, this._rows, this._cols);
|
|
this.ResetRowHeight();
|
|
}
|
|
|
|
protected virtual void ChangeFieldCols()
|
|
{
|
|
this.ReDimArrString(ref this._arrStrGrid, this._rows, this._cols);
|
|
this.ResetColWidth();
|
|
}
|
|
|
|
protected void InitRowHeight()
|
|
{
|
|
this._arrRowsHeight = new ArrayList();
|
|
for (int i = 0; i < this._rows; i++)
|
|
{
|
|
this._arrRowsHeight.Add(this._rowheight);
|
|
}
|
|
}
|
|
|
|
protected void InitColWidth()
|
|
{
|
|
this._arrColsWidth = new ArrayList();
|
|
for (int i = 0; i < this._cols; i++)
|
|
{
|
|
this._arrColsWidth.Add(this._colWidth);
|
|
}
|
|
}
|
|
|
|
protected void InitColAlignMent()
|
|
{
|
|
this._arrColsAlign = new ArrayList();
|
|
for (int i = 0; i < this._cols; i++)
|
|
{
|
|
this._arrColsAlign.Add(this._alignFlag);
|
|
}
|
|
}
|
|
|
|
protected void ResetRowHeight()
|
|
{
|
|
int num = this._arrRowsHeight.Count - this._cols;
|
|
if (num > 0)
|
|
{
|
|
num = Math.Abs(num);
|
|
for (int i = 0; i < num; i++)
|
|
{
|
|
this._arrRowsHeight.RemoveAt(this._arrRowsHeight.Count - 1);
|
|
}
|
|
}
|
|
else if (num < 0)
|
|
{
|
|
num = Math.Abs(num);
|
|
for (int i = 0; i < num; i++)
|
|
{
|
|
this._arrRowsHeight.Add(this._rowheight);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void ResetColWidth()
|
|
{
|
|
int num = this._arrColsWidth.Count - this._cols;
|
|
if (num > 0)
|
|
{
|
|
num = Math.Abs(num);
|
|
for (int i = 0; i < num; i++)
|
|
{
|
|
this._arrColsWidth.RemoveAt(this._arrColsWidth.Count - 1);
|
|
}
|
|
}
|
|
else if (num < 0)
|
|
{
|
|
num = Math.Abs(num);
|
|
for (int i = 0; i < num; i++)
|
|
{
|
|
this._arrColsWidth.Add(this._colWidth);
|
|
}
|
|
}
|
|
}
|
|
|
|
public virtual void Dispose()
|
|
{
|
|
this.Font.Dispose();
|
|
}
|
|
|
|
public GridBase() : this(3, 4)
|
|
{
|
|
}
|
|
|
|
public GridBase(int rows, int cols)
|
|
{
|
|
this._rows = rows;
|
|
this._cols = cols;
|
|
this.Initialize(rows, cols);
|
|
}
|
|
|
|
public IGrid Clone()
|
|
{
|
|
return (IGrid)base.MemberwiseClone();
|
|
}
|
|
|
|
public void Initialize(int rows, int cols)
|
|
{
|
|
this._rows = rows;
|
|
this._cols = cols;
|
|
this.ReDimArrString(ref this._arrStrGrid, rows, cols);
|
|
this.InitRowHeight();
|
|
this.InitColWidth();
|
|
this.InitColAlignMent();
|
|
}
|
|
|
|
public int GetAllColsWidthSum()
|
|
{
|
|
int num = 0;
|
|
for (int i = 0; i < this.Cols; i++)
|
|
{
|
|
num += (int)this._arrColsWidth[i];
|
|
}
|
|
return num;
|
|
}
|
|
|
|
public int GetAllRowsHeightSum()
|
|
{
|
|
int num = 0;
|
|
for (int i = 0; i < this.Rows; i++)
|
|
{
|
|
num += (int)this._arrRowsHeight[i];
|
|
}
|
|
return num;
|
|
}
|
|
|
|
public int[] GetAverageColsWidth()
|
|
{
|
|
int[] array = new int[this._cols];
|
|
int num = 0;
|
|
int num2 = this._Width / this._cols;
|
|
for (int i = 0; i < this._cols - 1; i++)
|
|
{
|
|
array[i] = num2;
|
|
num++;
|
|
}
|
|
array[array.Length - 1] = this._Width - num2 * num;
|
|
return array;
|
|
}
|
|
|
|
protected void ReDimArrString(ref string[,] arrStr, int rows, int cols)
|
|
{
|
|
if (arrStr == null || arrStr.Length == 0)
|
|
{
|
|
arrStr = new string[rows, cols];
|
|
for (int i = 0; i < rows; i++)
|
|
{
|
|
for (int j = 0; j < cols; j++)
|
|
{
|
|
arrStr[i, j] = "";
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string[,] array = new string[rows, cols];
|
|
int length = arrStr.GetLength(0);
|
|
int length2 = arrStr.GetLength(1);
|
|
int num = 0;
|
|
int num2 = 0;
|
|
if (rows >= length)
|
|
{
|
|
if (cols >= length2)
|
|
{
|
|
num = length;
|
|
num2 = length2;
|
|
for (int i = 0; i < length; i++)
|
|
{
|
|
for (int j = 0; j < cols; j++)
|
|
{
|
|
array[i, j] = "";
|
|
}
|
|
}
|
|
for (int i = length; i < rows; i++)
|
|
{
|
|
for (int j = 0; j < cols; j++)
|
|
{
|
|
array[i, j] = "";
|
|
}
|
|
}
|
|
}
|
|
if (cols <= length2)
|
|
{
|
|
num = length;
|
|
num2 = cols;
|
|
for (int i = length; i < rows; i++)
|
|
{
|
|
for (int j = 0; j < length2; j++)
|
|
{
|
|
array[i, j] = "";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (rows <= length)
|
|
{
|
|
if (cols >= length2)
|
|
{
|
|
num = rows;
|
|
num2 = length2;
|
|
for (int i = 0; i < length; i++)
|
|
{
|
|
for (int j = length2; j < cols; j++)
|
|
{
|
|
array[i, j] = "";
|
|
}
|
|
}
|
|
}
|
|
if (cols <= length2)
|
|
{
|
|
num = rows;
|
|
num2 = cols;
|
|
}
|
|
}
|
|
for (int i = 0; i < num; i++)
|
|
{
|
|
for (int j = 0; j < num2; j++)
|
|
{
|
|
array[i, j] = arrStr[i, j];
|
|
}
|
|
}
|
|
arrStr = array;
|
|
}
|
|
}
|
|
}
|
|
}
|