using System; using System.Data; using System.Drawing; using System.Windows.Forms; namespace GoldPrinter { public class GoldGrid : GridBase { private string _colsAlignList = ""; private object _DataSource = null; public string ColsAlignString { get { return this._colsAlignList; } set { if (value != null) { this._colsAlignList = value; } } } public object DataSource { get { return this._DataSource; } set { if (value != null) { this._DataSource = value; string text = value.GetType().ToString(); switch (text) { case "System.String[]": { string[] array = (string[])this._DataSource; string[,] array2 = new string[1, array.Length]; for (int i = 0; i < array.Length; i++) { array2[0, i] = array[i]; } this.DataSource = array2; break; } case "System.String[,]": base.GridText = (string[,])this._DataSource; break; case "System.Data.DataTable": base.GridText = this.ToArrFromDataTable((DataTable)this._DataSource); break; case "System.Windows.Forms.DataGrid": base.GridText = this.ToArrFromDataGrid((System.Windows.Forms.DataGrid)this._DataSource); break; } } } } public void SetText(int row, int col, string text) { this._arrStrGrid[row, col] = text; } public void SetText(string text) { this._arrStrGrid[base.RowSel, base.ColSel] = text; } public string GetText(int row, int col) { return this._arrStrGrid[row, col]; } public string GetText() { return this._arrStrGrid[base.RowSel, base.ColSel]; } public void SetTextOnRowSel(int rowSel, int startCol, int endCol, string text) { for (int i = startCol; i <= endCol; i++) { this.SetText(rowSel, i, text); } } public void SetTextOnColSel(int colSel, int startRow, int endRow, string text) { for (int i = startRow; i <= endRow; i++) { this.SetText(i, colSel, text); } } public CellRectangle GetMergeCell() { return this.GetMergeCell(base.Location, this._arrStrGrid, base.PreferredRowHeight, base.ColsWidth, base.RowSel, base.ColSel); } private void InitColsAlignString() { string text = ""; string str = ""; switch (base.AlignMent) { case AlignFlag.Left: str = "L"; break; case AlignFlag.Center: str = "C"; break; case AlignFlag.Right: str = "R"; break; } for (int i = this._colsAlignList.Length; i < base.Cols; i++) { text += str; } this._colsAlignList = text; if (this._colsAlignList.Length > base.Cols) { this._colsAlignList.Substring(0, base.Cols); } } public string[,] ToArrFromDataTable(DataTable source) { string[,] result; if (source == null) { result = new string[0, 0]; } else { int count = source.Rows.Count; int count2 = source.Columns.Count; string[,] array = new string[count, count2]; for (int i = 0; i < count; i++) { for (int j = 0; j < count2; j++) { array[i, j] = source.Rows[i][j].ToString(); } } result = array; } return result; } public string[,] ToArrFromDataGrid(System.Windows.Forms.DataGrid source) { string[,] result; if (source == null) { result = new string[0, 0]; } else { int num = 0; int num2 = 0; try { for (int i = 0; i < 2147483646; i++) { string text = source[0, i].ToString(); num2++; } } catch (Exception ) { } try { for (int i = 0; i < 2147483646; i++) { string text = source[i, 0].ToString(); num++; } } catch (Exception ) { } string[,] array = new string[num, num2]; try { for (int i = 0; i < num; i++) { for (int j = 0; j < num2; j++) { array[i, j] = source[i, j].ToString(); } } } catch (Exception ) { } result = array; } return result; } protected virtual AlignFlag[] GetColsAlign(string alignment) { AlignFlag[] result; if (alignment == null || alignment.Length == 0) { result = new AlignFlag[0]; } else { int length = alignment.Length; AlignFlag[] array = new AlignFlag[length]; int i = 0; while (i < length) { string text = alignment.Substring(i, 1).ToUpper(); string text2 = text; if (text2 == null) { goto IL_7C; } if (!(text2 == "C")) { if (!(text2 == "R")) { goto IL_7C; } array[i] = AlignFlag.Right; } else { array[i] = AlignFlag.Center; } IL_82: i++; continue; IL_7C: array[i] = AlignFlag.Left; goto IL_82; } result = array; } return result; } protected virtual CellRectangle GetMergeCell(Point GridLocation, string[,] arrStrGrid, int rowHeight, int[] ArrColWidth, int rowSel, int colSel) { CellRectangle result = new CellRectangle(0, 0, 0, 0); int length = arrStrGrid.GetLength(0); int length2 = arrStrGrid.GetLength(1); int num = 1; int num2 = 1; int num3 = rowSel; int num4 = rowSel; int num5 = colSel; int num6 = colSel; for (int i = rowSel - 1; i >= 0; i--) { if (!(arrStrGrid[rowSel, colSel] == arrStrGrid[i, colSel])) { break; } num++; num3--; } for (int i = rowSel + 1; i < length; i++) { if (!(arrStrGrid[rowSel, colSel] == arrStrGrid[i, colSel])) { break; } num++; num4++; } for (int j = colSel - 1; j >= 0; j--) { if (!(arrStrGrid[rowSel, colSel] == arrStrGrid[rowSel, j])) { break; } num2++; num5--; } for (int j = colSel + 1; j < length2; j++) { if (!(arrStrGrid[rowSel, colSel] == arrStrGrid[rowSel, j])) { break; } num2++; num6++; } int num7 = GridLocation.X; int cellTop = GridLocation.Y + num3 * rowHeight; int num8 = 0; for (int k = num5 - 1; k >= 0; k--) { num7 += ArrColWidth[k]; } for (int k = num5; k <= num6; k++) { num8 += ArrColWidth[k]; } int cellHeight = num * rowHeight; result = new CellRectangle(num7, cellTop, num8, cellHeight); return result; } } }