?? reportcontrol.pas
字號:
{************************************
* 表格式報表處理系統 of DELPHI *
* China Report system of DELPHI *
* 簡稱:CReport V3.0 *
* 原創:郭家駿、王寒松 *
* 修改:廖伯志 *
* 修改:趙慧誠,本人水平有限(大部 *
* 分看不懂),只能增加行號和子行號;*
* LineNum行號,SubLineNum子行號(每個*
* 子表行號) *
* 最后修改日期:1999.11.22 *
*************************************}
unit ReportControl;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, Math, Printers, Menus, Db, FileCtrl;
const
// Horz Align
TEXT_ALIGN_LEFT = 0;
TEXT_ALIGN_CENTER = 1;
TEXT_ALIGN_RIGHT = 2;
// Vert Align
TEXT_ALIGN_TOP = 0;
TEXT_ALIGN_VCENTER = 1;
TEXT_ALIGN_BOTTOM = 2;
// 斜線定義
LINE_LEFT1 = 1; // left top to right bottom
LINE_LEFT2 = 2; // left top to right
LINE_LEFT3 = 4; // left top to bottom
LINE_RIGHT1 = $100; // right top to left bottom
LINE_RIGHT2 = $200; // right top to left
LINE_RIGHT3 = $400; // right top to bottom
type
TReportCell = class;
TReportLine = class;
TReportControl = class;
TReportCell = class(TObject)
private
{ Private declarations }
FLeftMargin: Integer; // 左邊的空格
FOwnerLine: TReportLine; // 隸屬行
FOwnerCell: TReportCell; // 隸屬的單元格
FCellsList: TList; // 覆蓋的Cell
// Index
FCellIndex: Integer; // Cell在行中的索引
// size & position
FCellLeft: Integer;
FCellWidth: Integer;
FCellRect: TRect; // 計算得來
FTextRect: TRect;
FDragCellHeight: Integer;
FMinCellHeight: Integer;
FRequiredCellHeight: Integer;
// Cell的Top屬性從隸屬的行中取得
// int GetCellTop();
// Cell的Height屬性從隸屬行和跨越行中取得
// int GetCellHeight();
// border
FLeftLine: Boolean;
FLeftLineWidth: Integer;
FTopLine: Boolean;
FTopLineWidth: Integer;
FRightLine: Boolean;
FRightLineWidth: Integer;
FBottomLine: Boolean;
FBottomLineWidth: Integer;
// 斜線
FDiagonal: UINT;
// color
FTextColor: COLORREF;
FBackGroundColor: COLORREF;
// align
FHorzAlign: Integer;
FVertAlign: Integer;
// string
FCellText: string;
// font
FLogFont: TLOGFONT;
function GetCellHeight: Integer;
function GetCellTop: Integer;
function GetOwnerLineHeight: Integer;
protected
{ Protected declarations }
procedure SetLeftMargin(LeftMargin: Integer);
procedure SetOwnerLine(OwnerLine: TReportLine);
procedure SetOwnerCell(Cell: TReportCell);
function GetOwnedCellCount: Integer;
procedure SetCellLeft(CellLeft: Integer);
procedure SetCellWidth(CellWidth: Integer);
procedure SetLeftLine(LeftLine: Boolean);
procedure SetLeftLineWidth(LeftLineWidth: Integer);
procedure SetTopLine(TopLine: Boolean);
procedure SetTopLineWidth(TopLineWidth: Integer);
procedure SetRightLine(RightLine: Boolean);
procedure SetRightLineWidth(RightLineWidth: Integer);
procedure SetBottomLine(BottomLine: Boolean);
procedure SetBottomLineWidth(BottomLineWidth: Integer);
procedure SetCellText(CellText: string);
procedure SetLogFont(NewFont: TLOGFONT);
procedure SetBackGroundColor(BkColor: COLORREF);
procedure SetTextColor(TextColor: COLORREF);
public
{ Public declarations }
procedure AddOwnedCell(Cell: TReportCell);
procedure RemoveAllOwnedCell;
procedure RemoveOwnedCell(Cell: TReportCell);
function IsCellOwned(Cell: TReportCell): Boolean;
procedure CalcCellRect;
procedure CalcMinCellHeight;
procedure PaintCell(hPaintDC: HDC; bPrint: Boolean);
procedure CopyCell(Cell: TReportCell; bInsert: Boolean);
constructor Create;
destructor Destroy; override;
// Properties
property LeftMargin: Integer read FLeftMargin write SetLeftMargin;
property OwnerLine: TReportLine read FOwnerLine write SetOwnerLine;
property OwnerCell: TReportCell read FOwnerCell write SetOwnerCell;
property OwnedCellCount: Integer read GetOwnedCellCount;
property CellIndex: Integer read FCellIndex write FCellIndex;
// size & position
property CellLeft: Integer read FCellLeft write SetCellLeft;
property CellWidth: Integer read FCellWidth write SetCellWidth;
property CellTop: Integer read GetCellTop;
property CellHeight: Integer read GetCellHeight;
property CellRect: TRect read FCellRect;
property TextRect: TRect read FTextRect;
property DragCellHeight: Integer read FDragCellHeight;
// or protected property ?
property MinCellHeight: Integer read FMinCellHeight write FMinCellHeight;
property RequiredCellHeight: Integer read FRequiredCellHeight;
property OwnerLineHeight: Integer read GetOwnerLineHeight;
// border
property LeftLine: Boolean read FLeftLine write SetLeftLine default True;
property LeftLineWidth: Integer read FLeftLineWidth write SetLeftLineWidth default 1;
property TopLine: Boolean read FTopLine write SetTopLine default True;
property TopLineWidth: Integer read FTopLineWidth write SetTopLineWidth default 1;
property RightLine: Boolean read FRightLine write SetRightLine default True;
property RightLineWidth: Integer read FRightLineWidth write SetRightLineWidth default 1;
property BottomLine: Boolean read FBottomLine write SetBottomLine default True;
property BottomLineWidth: Integer read FBottomLineWidth write SetBottomLineWidth default 1;
// 斜線
property Diagonal: UINT read FDiagonal write FDiagonal;
// color
property TextColor: COLORREF read FTextColor write SetTextColor default clBlack;
property BkColor: COLORREF read FBackGroundColor write SetBackGroundColor default clWhite;
// align
property HorzAlign: Integer read FHorzAlign write FHorzAlign default 1;
property VertAlign: Integer read FVertAlign write FVertAlign default 1;
// string
property CellText: string read FCellText write SetCellText;
// font
property LogFont: TLOGFONT read FLogFont write SetLogFont;
end;
TReportLine = class(TObject)
private
{ Private declarations }
FReportControl: TReportControl; // Report Control的指針
FCells: TList; // 保存所有在該行中的CELL
FIndex: Integer; // 行的索引
FMinHeight: Integer;
FDragHeight: Integer;
FLineTop: Integer;
FLineRect: TRect;
function GetLineHeight: Integer;
function GetLineRect: TRect;
procedure SetDragHeight(const Value: Integer);
procedure SetLineTop(const Value: Integer);
protected
{ Protected declarations }
public
{ Public declarations }
property ReportControl: TReportControl read FReportControl write FReportControl;
property Index: Integer read FIndex write FIndex;
property LineHeight: Integer read GetLineHeight write SetDragHeight;
property LineTop: Integer read FLineTop write SetLineTop;
property LineRect: TRect read GetLineRect;
property PrevLineRect: TRect read FLineRect;
procedure CalcLineHeight;
procedure CreateLine(LineLeft, CellNumber, PageWidth: Integer);
procedure CopyLine(Line: TReportLine; bInsert: Boolean);
constructor Create;
destructor Destroy; override;
end;
TReportControl = class(TWinControl)
private
{ Private declarations }
FPreviewStatus: Boolean;
FLineList: TList;
FSelectCells: TList;
FEditCell: TReportCell;
FReportScale: Integer;
FPageWidth: Integer;
FPageHeight: Integer;
FLeftMargin: Integer;
FRightMargin: Integer;
FTopMargin: Integer;
FBottomMargin: Integer;
FcellFont: TlogFont;
FcellFont_d: TlogFont;
FLeftMargin1: Integer;
FRightMargin1: Integer;
FTopMargin1: Integer;
FBottomMargin1: Integer;
// 換頁加表頭(不加表頭)
FNewTable: Boolean;
// 定義打印多少行后從新加表頭
FDataLine: Integer;
FTablePerPage: Integer;
// 鼠標操作支持
FMousePoint: TPoint;
// 編輯、顏色及字體
FEditWnd: HWND;
FEditBrush: HBRUSH;
FEditFont: HFONT;
// FReportMenu : TPopupMenu;
protected
{ Protected declarations }
procedure CreateWnd; override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure SaveToFile(FileName: string);
procedure LoadFromFile(FileName: string);
procedure PrintIt;
procedure ResetContent;
procedure SetScale(const Value: Integer);
property cellFont: TlogFont read Fcellfont write Fcellfont; //default true;
property cellFont_d: TlogFont read Fcellfont_d write Fcellfont_d; //default true;
// Message Handler
procedure WMLButtonDown(var Message: TMessage); message WM_LBUTTONDOWN;
procedure WMLButtonDBLClk(var Message: TMessage); message WM_LBUTTONDBLCLK;
procedure WMMouseMove(var Message: TMessage); message WM_MOUSEMOVE;
procedure WMContextMenu(var Message: TMessage); message WM_CONTEXTMENU;
procedure WMPaint(var Message: TMessage); message WM_PAINT;
procedure WMCOMMAND(var Message: TMessage); message WM_COMMAND;
procedure WMCtlColor(var Message: TMessage); message WM_CTLCOLOREDIT;
// Window size
procedure CalcWndSize;
procedure NewTable(ColNumber, RowNumber: Integer);
procedure InsertLine;
function CanInsert: Boolean;
procedure AddLine;
function CanAdd: Boolean;
procedure DeleteLine;
procedure InsertCell;
procedure DeleteCell;
procedure AddCell;
procedure CombineCell;
procedure SplitCell;
procedure VSplitCell(Number: Integer);
function CanSplit: Boolean;
procedure SetCellLines(bLeftLine, bTopLine, bRightLine, bBottomLine: Boolean;
nLeftLineWidth, nTopLineWidth, nRightLineWidth, nBottomLineWidth: Integer);
procedure SetCellDiagonal(NewDiagonal: UINT);
procedure SetCellColor(NewTextColor, NewBackColor: COLORREF);
procedure SetCellFont(CellFont: TLOGFONT);
procedure SetCellAlign(NewHorzAlign, NewVertAlign: Integer);
procedure SetMargin(nLeftMargin, nTopMargin, nRightMargin, nBottomMargin: Integer);
function GetMargin: TRect;
function getcellfont:tfont; // add wang hang song
procedure UpdateLines;
procedure StartMouseDrag(point: TPoint);
procedure StartMouseSelect(point: TPoint; bSelectFlag: Boolean; shift_down: byte);
procedure MouseMoveHandler(message: TMSG);
// 選中區的操作
function AddSelectedCell(Cell: TReportCell): Boolean;
function RemoveSelectedCell(Cell: TReportCell): Boolean;
procedure RemoveAllSelectedCell;
function IsCellSelected(Cell: TReportCell): Boolean;
function CellFromPoint(point: TPoint): TReportCell;
property IsPreview: Boolean read FPreviewStatus write FPreviewStatus default False;
property ReportScale: Integer read FReportScale write SetScale default 100;
property IsNewTable: Boolean read FNewTable write FNewTable default True;
property DataLine: Integer read FDataLine write FDataLine default 2147483647;
property TablePerPage: Integer read FTablePerPage write FTablePerPage default 2147483647;
published
{ Published declarations }
property Left;
property Top;
property Cursor;
property Hint;
property Visible default True;
property Enabled default True;
property OnMouseMove;
property OnMouseDown;
property OnMouseUp;
property ShowHint;
end;
TDatasetItem = class(TObject)
pDataset: TDataset;
strName: string;
end;
TVarTableItem = class(TObject)
strVarName: string;
strVarValue: string;
end;
TMyRect = class(TObject)
public
Left: Integer;
Top: Integer;
Right: Integer;
Bottom: Integer;
end;
TReportRunTime = class(TComponent)
private
FFileName: TFileName;
FAutoGroup : Boolean;
FEnableEdit : Boolean;
FDList: TList; // 保存數據集的指針和名稱的對照
FVarList: TList; // 保存變量的名字和值的對照表
FLineList: TList; // 保存報表的設計信息(從文件中讀入)
FPrintLineList: TList; //保存要打印的某一頁的行信息
FOwnerCellList: TList; // 保存每一頁中合并后單元格前后的指針
Width: Integer;
Height: Integer;
// 定義換頁加表頭
FNewTable: Boolean;
//定義行號
FLineNum:Integer;
FSubLineNum:Integer;
//定義從表數據葉好
FSubPageNum:Integer;
// 定義打印多少行后從新加表頭
FDataLine: Integer;
FTablePerPage: Integer;
FReportScale: Integer;
FPageWidth: Integer;
FPageHeight: Integer;
FHeaderHeight: Integer;
Fallprint: Boolean; //是否打印全部記錄,默認為全部
FLeftMargin: Integer;
FRightMargin: Integer;
FTopMargin: Integer;
FBottomMargin: Integer;
FLeftMargin1: Integer;
FRightMargin1: Integer;
FTopMargin1: Integer;
FBottomMargin1: Integer;
FPageCount: Integer; // page count in print preview
procedure UpdateLines;
procedure UpdatePrintLines;
procedure PrintOnePage;
procedure LoadRptFile;
function GetDatasetName(strCellText: string): string;
function GetDataset(strCellText: string): TDataset;
function DatasetByName(strDatasetName: string): TDataset;
function GetVarValue(strVarName: string): string;
function GetFieldName(strCellText: string): string;
procedure SetRptFileName(const Value: TFileName);
procedure SaveTempFile(PageNumber: Integer);
procedure LoadTempFile(strFileName: string);
procedure DeleteAllTempFiles;
procedure SetAutoGroup(Value : Boolean);
procedure SetEnableEdit(Value : Boolean);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure SetDataset(strDatasetName: string; pDataSet: TDataSet);
procedure SetVarValue(strVarName, strVarValue: string);
property allprint: boolean read Fallprint write Fallprint default true;
procedure ResetContent;
procedure PrintPreview(bPreviewMode: Boolean);
procedure PreparePrint;
procedure loadfile(value: tfilename);
procedure Print;
procedure Resetself;
Function Cancelprint:boolean;
published
property ReportFile: TFileName read FFileName write SetRptFileName;
property AutoGroup:boolean Read Fautogroup Write setautogroup Default True;
property EnableEdit:boolean Read FEnableEdit Write setEnableEdit;
end;
TCellTable = class(TObject)
PrevCell: TReportCell;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -