📄 ag_main.pas
字号:
unit AG_Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, Menus, ImgList, StdCtrls, ToolWin, ExtCtrls, jpeg,
Grids, DBGrids, Inifiles, ADODB, DB, PublicUnit;
type
TReportFieldMessage = class
FieldName: string; //字段名称
FieldType: string; //维码,维属性,指标
DataType: string; //数据类型
Visible: Boolean; //是否投影
Constraints: string; //查询条件
OrderType: string; //排序类型
Grouping: Boolean; //是否小计
RpVisible: Boolean; //该项是否在工具中显示
//以下内容不在提交请求时赋值
Selected_Item_Table: array[0..5] of string;
Selected_Item_Con_In: array[0..5] of string;
Selected_Item_Con_Out: array[0..5] of string;
Aliase: string;
end;
TReportFieldConstraint = class
ACheckBox: TCheckBox;
ALable: TLabel;
AEdit: TEdit;
AComboBox: TComboBox;
GroupingCheckBox: TCheckBox;
destructor Destroy; override;
end;
TFrmAG_Main = class(TForm)
StatusBar1: TStatusBar;
CoolBar1: TCoolBar;
ToolBar2: TToolBar;
TB_cx: TToolButton;
SaveResult: TToolButton;
ToolButton6: TToolButton;
PageSetUp: TToolButton;
PrintAndPre: TToolButton;
PrintBtn: TToolButton;
ToolButton3: TToolButton;
ToolButton2: TToolButton;
ToolButton10: TToolButton;
ExitBtn: TToolButton;
ImageList1: TImageList;
Panel1: TPanel;
Panel2: TPanel;
Splitter1: TSplitter;
Panel3: TPanel;
Image1: TImage;
Label_xsxx: TLabel;
Label19: TLabel;
Panel4: TPanel;
Image2: TImage;
Label7: TLabel;
Label8: TLabel;
Label1: TLabel;
DBGrid1: TDBGrid;
Label2: TLabel;
ADOQuery1: TADOQuery;
DataSource1: TDataSource;
Label3: TLabel;
ToolButton4: TToolButton;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
Label4: TLabel;
ToolButton1: TToolButton;
ToolBar3: TToolBar;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure TB_cxClick(Sender: TObject);
procedure ExitBtnClick(Sender: TObject);
procedure PageSetUpClick(Sender: TObject);
procedure PrintAndPreClick(Sender: TObject);
procedure PrintBtnClick(Sender: TObject);
procedure SaveResultClick(Sender: TObject);
procedure ToolButton2Click(Sender: TObject);
procedure ToolButton4Click(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure DBGrid1DblClick(Sender: TObject);
procedure ToolButton1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
ReportType: string;
ReportCName: string;
ReportEName: string;
ReportHistroyCName, ReportHistroyEName: string;
ToolButtonList: TStrings;
ReportFields: TStrings;
Dementions, Measures: TStrings;
MultiFact: Boolean;
HistroyDone: Boolean;
SqlStrings: TStrings;
MyPageDesign: TPageDesign;
ConstraintComponentsList: TStrings;
function ReadReportList(ReportType: string): Boolean;
function GetReportFieldsMessage: Boolean;
function SetReportRequest: Boolean;
procedure CreateConstraintComponents;
procedure ChangeDateConstriant(Sender: TObject);
procedure ChangeCharConstriant(Sender: TObject);
procedure ChangeTimeConstriant(Sender: TObject);
procedure ChangeNumConstriant(Sender: TObject);
procedure GroupingCheckBoxClick(Sender: TObject);
procedure CreateToolButton(ButtonName: string);
procedure ToolButtonClick(Sender: TObject);
constructor ACreate(AReportType: string);
end;
procedure SetWork(AggType: string);
implementation
uses main, RP_PageSetup, AG_SelDate, AG_SelChar, AG_SelNum, AG_SelTime, TC_Main,
AG_Report, AG_HistroyList, GQ_UQueryMain;
{$R *.dfm}
procedure SetWork(AggType: string);
var
FrmAG_Main: TFrmAG_Main;
begin
FrmAG_Main := TFrmAG_Main.ACreate(AggType);
FrmAG_Main.Show;
end;
{-------------------------------------------------------------------------------}
destructor TReportFieldConstraint.Destroy;
begin
ACheckBox.Free;
ALable.Free;
AEdit.Free;
AComboBox.Free;
GroupingCheckBox.Free;
inherited;
end;
{-------------------------------------------------------------------------------}
constructor TFrmAG_Main.ACreate(AReportType: string);
begin
inherited Create(Application);
ReportType := AReportType;
end;
procedure TFrmAG_Main.FormShow(Sender: TObject);
var
s: string;
begin
Label1.Visible := False;
DbGrid1.Visible := False;
HistroyDone := False;
MultiFact := False;
ReportFields := TStringList.Create;
SQLStrings := TStringList.Create;
Dementions := TStringList.Create;
Measures := TStringList.Create;
ToolButtonList := TStringList.Create;
MyPageDesign := TPageDesign.Create;
ConstraintComponentsList := TStringList.Create;
if Pos('历史结果/', ReportType) = 0 then
begin
ReadReportList(ReportType);
Exit;
end;
ToolBar3.Visible := False;
TB_cx.Enabled := False;
SaveResult.Enabled := False;
s := ReportType;
Delete(s, 1, Length('历史结果/'));
ReportHistroyCName := Copy(s, 1, Pos('/', s) - 1);
ReportHistroyEName := Copy(s, Pos('/', s) + 1, 10000000000);
;
ReportType := '历史结果';
try
SqlStrings.LoadFromFile(ReportHistroyEName)
except
ShowMessage('无法读取报表源文件,无法工作!');
Exit;
end;
TB_cxClick(Sender);
DbGrid1.OnDblClick(Sender);
HistroyDone := True;
end;
procedure TFrmAG_Main.FormClose(Sender: TObject; var Action: TCloseAction);
var
i: integer;
begin
if ReportFields.Count <> 0 then
for i := ReportFields.Count - 1 downto 0 do
ReportFields.Objects[i].Free;
ReportFields.Free;
Dementions.Free;
Measures.Free;
SQLStrings.Free;
MyPageDesign.Free;
if ConstraintComponentsList.Count <> 0 then
for i := ConstraintComponentsList.Count - 1 downto 0 do
ConstraintComponentsList.Objects[i].Free;
ConstraintComponentsList.Clear;
ConstraintComponentsList.Free;
for i := ToolButtonList.Count - 1 downto 0 do
ToolButtonList.Objects[i].Free;
ToolButtonList.Free;
Action := caFree;
end;
{-------------------------------------------------------------------------------}
procedure TFrmAG_Main.TB_cxClick(Sender: TObject);
{var
ts:TStrings;
CReportFieldMessage:TReportFieldMessage;
i:integer;}
begin
if ReportType <> '历史结果' then
begin
Screen.Cursor := crHourGlass;
if not SetReportRequest then
begin
Screen.Cursor := crDefault;
MessageDlg('因为您没有至少选择一个查询条件和一个统计项或是其他原因,系统无法生成查询语句!',
mtConfirmation, [mbYes], 0);
Exit;
end;
{ts:=TStringList.Create;
for i:=0 to Dementions.Count-1 do
begin
CReportFieldMessage:=TReportFieldMessage(Dementions.Objects[i]);
ts.Add('名称='+CReportFieldMessage.FieldName+',字段类型='+CReportFieldMessage.FieldType+',数据类型='
+CReportFieldMessage.DataType+',约束='+CReportFieldMessage.Constraints+',排序='
+CReportFieldMessage.OrderType+',投影='+BoolToStr(CReportFieldMessage.Visible)+',小计='
+BoolToStr(CReportFieldMessage.Grouping));
end;
for i:=0 to Measures.Count-1 do
begin
CReportFieldMessage:=TReportFieldMessage(Dementions.Objects[i]);
ts.Add('名称='+CReportFieldMessage.FieldName+',字段类型='+CReportFieldMessage.FieldType+',数据类型='
+CReportFieldMessage.DataType+',约束='+CReportFieldMessage.Constraints+',排序='
+CReportFieldMessage.OrderType+',投影='+BoolToStr(CReportFieldMessage.Visible)+',小计='
+BoolToStr(CReportFieldMessage.Grouping));
end;
MessageDlg(ts.Text,mtConfirmation, [mbYes], 0);
ts.Free;}
if not AG_Report.GetSQLStrings(Dementions, Measures, MultiFact, SQLStrings)
then
begin
Screen.Cursor := crDefault;
ShowMessage('无法生成查询语句,该统计分析无法完成!');
Exit;
end;
end;
Screen.Cursor := crHourGlass;
with ADOQuery1 do
begin
Close;
ConnectionString := 'Provider=SQLOLEDB.1;Persist Security Info=False;User ID='
+ FrmMain.DbUser + ';Password=' + FrmMain.DbPass + ';Initial Catalog=' +
FrmMain.DbName + ';Data Source=' + PublicUnit.ServerName;
Sql.Assign(SQLStrings);
if not ExecuteSQLStatement(ADOQuery1) then
begin
Screen.Cursor := crDefault;
ShowMessage('数据库无法打开或表《MeasureResource》无法打开,请与系统管理员联系!');
Exit;
end;
end;
Label1.Visible := True;
if not DbGrid1.Visible then
DbGrid1.Visible := True;
SetDBGridFieldsDisplay(DbGrid1);
Screen.Cursor := crDefault;
end;
procedure TFrmAG_Main.SaveResultClick(Sender: TObject);
var
ADOQuery: TADOQuery;
Year, Month, Day: Word;
Hour, Min, Sec, MSec: Word;
begin
if SqlStrings.Count = 0 then
Exit;
DecodeDate(Now, Year, Month, Day);
DecodeTime(Time, Hour, Min, Sec, MSec);
ReportEName := 'Report_' + IntToStr(Month) + '_' + IntToStr(Day) + '_' +
IntToStr(Year) + '_' + IntToStr(Hour) + '_' + IntToStr(Min) + '_' +
IntToStr(Sec) + '.sql';
if not InputQuery('统计分析保存', '输入保存名称:(<25)', ReportCName) then
Exit;
if ReportCName = '' then
Exit;
Screen.Cursor := crHourGlass;
ADOQuery := TADOQuery.Create(Application);
with ADOQuery do
begin
ConnectionString := 'Provider=SQLOLEDB.1;Persist Security Info=False;User ID='
+ FrmMain.DbUser + ';Password=' + FrmMain.DbPass + ';Initial Catalog=' +
FrmMain.DbName + ';Data Source=' + PublicUnit.ServerName;
Sql.Add('Insert Into Report_HistroyList');
Sql.Add('(英文名称,中文名称,职员姓名)');
Sql.Add('Values');
Sql.Add('(''' + ReportEName + ''',''' + ReportCName + ''',''' +
FrmMain.UserName + ''')');
try
ExecSql
except
Screen.Cursor := crDefault;
ShowMessage('数据库读写失败,无法完成保存工作!');
Exit;
end;
end;
try
SqlStrings.SaveToFile(GetSaveReportDir + ReportEName);
Screen.Cursor := crDefault;
MessageDlg('统计分析保存成功!', mtInformation, [mbOk], 0);
except
Screen.Cursor := crDefault;
MessageDlg('无法保存报表,请检查报表文件保存路径的畅通!', mtInformation,
[mbOk], 0);
end;
Screen.Cursor := crDefault;
end;
procedure TFrmAG_Main.ToolButton2Click(Sender: TObject);
begin
if not ADOQuery1.Active then
Exit;
OutPuttoExcel(ADOQuery1);
end;
procedure TFrmAG_Main.PageSetUpClick(Sender: TObject);
var
RP_fPageSetup: TRP_fPageSetup;
begin
if SqlStrings.Count = 0 then
Exit;
Screen.Cursor := crHourGlass;
MyPageDesign.CServerName := FrmMain.ServerName;
MyPageDesign.CDataBaseName := FrmMain.DbName;
MyPageDesign.CDataBaseUser := FrmMain.DbUser;
MyPageDesign.CDBPassWord := FrmMain.DbPass;
MyPageDesign.CSqlString := Sqlstrings;
if MyPageDesign.ReportName = '' then
MyPageDesign.ReportName := Label1.Caption;
Application.CreateForm(TRP_fPageSetup, RP_fPageSetup);
RP_fPageSetup.APageDesign := MyPageDesign;
Screen.Cursor := crDefault;
RP_fPageSetup.ShowModal;
RP_fPageSetup.Free;
Screen.Cursor := crDefault;
end;
procedure TFrmAG_Main.PrintAndPreClick(Sender: TObject);
var
i: integer;
begin
if SqlStrings.Count = 0 then
Exit;
if not ExecuteSQLStatement(ADOQuery1) then
Exit;
Screen.Cursor := crHourGlass;
MyPageDesign.CServerName := FrmMain.ServerName;
MyPageDesign.CDataBaseName := FrmMain.DbName;
MyPageDesign.CDataBaseUser := FrmMain.DbUser;
MyPageDesign.CDBPassWord := FrmMain.DbPass;
MyPageDesign.CSqlString := Sqlstrings;
if MyPageDesign.ReportName = '' then
MyPageDesign.ReportName := Label1.Caption;
if MyPageDesign.ReportBodyColsWidth.Count = 0 then
begin
MyPageDesign.ReportBodyColsWidth.Clear;
SetLength(MyPageDesign.ReportBodyAlignment, ADOQuery1.FieldCount);
for i := 0 to ADOQuery1.FieldCount - 1 do
begin
MyPageDesign.ReportBodyColsWidth.Add(IntToStr(DBGrid1.Columns[i].Width));
MyPageDesign.ReportBodyAlignment[i] := DBGrid1.Columns[i].Alignment;
if DBGrid1.Columns[i].Width > (DBGrid1.Width div 5) * 2 then
DBGrid1.Columns[i].Width := (DBGrid1.Width div 5) * 2;
end;
end;
if not PreViewReportFile(MyPageDesign) then
begin
Screen.Cursor := crDefault;
MessageDlg('未能实现打印预览,请于系统管理员联系!', mtInformation, [mbOk],
0);
end;
end;
procedure TFrmAG_Main.PrintBtnClick(Sender: TObject);
var
i: integer;
begin
if sqlstrings.Count = 0 then
Exit;
Screen.Cursor := crHourGlass;
MyPageDesign.CServerName := FrmMain.ServerName;
MyPageDesign.CDataBaseName := FrmMain.DbName;
MyPageDesign.CDataBaseUser := FrmMain.DbUser;
MyPageDesign.CDBPassWord := FrmMain.DbPass;
MyPageDesign.CSqlString := Sqlstrings;
if MyPageDesign.ReportName = '' then
MyPageDesign.ReportName := Label1.Caption;
if MyPageDesign.ReportBodyColsWidth.Count = 0 then
begin
MyPageDesign.ReportBodyColsWidth.Clear;
SetLength(MyPageDesign.ReportBodyAlignment, ADOQuery1.FieldCount);
for i := 0 to ADOQuery1.FieldCount - 1 do
begin
MyPageDesign.ReportBodyColsWidth.Add(IntToStr(DBGrid1.Columns[i].Width));
MyPageDesign.ReportBodyAlignment[i] := DBGrid1.Columns[i].Alignment;
if DBGrid1.Columns[i].Width > (DBGrid1.Width div 5) * 2 then
DBGrid1.Columns[i].Width := (DBGrid1.Width div 5) * 2;
end;
end;
if not PrintReportFile(myPageDesign) then
begin
Screen.Cursor := crDefault;
MessageDlg('未能实现打印,请于系统管理员联系!', mtInformation, [mbOk], 0);
end;
Screen.Cursor := crDefault;
end;
procedure TFrmAG_Main.ExitBtnClick(Sender: TObject);
begin
Close;
end;
procedure TFrmAG_Main.ToolButton4Click(Sender: TObject);
begin
if not ADOQuery1.Active then
Exit;
TC_Main.SetWork(SqlStrings);
end;
procedure TFrmAG_Main.ToolButton1Click(Sender: TObject);
begin
Function_DB_ReadRight.UserOrUserGroupName := UserName;
Function_DB_ReadRight.UserOrUserGroupIdentify := '用户';
Function_DB_ReadRight.FunctionResourceName := '综合查询';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -