求高手帮忙
delphi吧
全部回复
仅看楼主
level 1
songqics2006 楼主
给一个程序加上日志记录功能,上传到mysql数据库,记录每个操作,请问怎么实现,谁能举个例子,随便一个小程序加个这个功能,我那个是大程序,要一个模块一个的加,谢谢各位了
2013年10月08日 02点10分 1
level 10
我的实现方法:
1.定义一个全局类:
{ TGlobal 全局变量 }
TGlobal = class(TBaseItem) //TBaseItem 可以改为 TObject
private
FWriteLogSwitch: Boolean;
public
property WriteLogSwitch: Boolean read GetWriteLogSwitch; //日志开关: 0, 不写; 1, 写入
procedure WriteEventLog(OperatorId: Integer; Content: string); //写入事件日志,受 WriteLogSwitch 值影响
end;
implementation
procedure TGlobal.WriteEventLog(OperatorId: Integer; Content: string);
begin
if WriteLogSwitch = False then Exit;
with DataModule_Globe.CDS_Query_ExecSQL do
begin
Close;
CommandText := 'EXEC proc_insert_EventLog :@OperatorId,:@Content ';
Params.ParamByName('@OperatorId').AsInteger := OperatorId;
Params.ParamByName('@Content').AsString := Content;
Execute;
Close;
end;
end;
end.
2.调用方法:(GlobalValue 为全局类的实体对象 )
在需要的地方,写以下语句:
GlobalValue.WriteEventLog(Operator.ID, '工作流[WorkflowID: ' + IntToStr(mTmpWorkflow.ID) + '] 保存成功');
3.数据库中的事件日志表及存储过程:
if exists (select 1 from sysobjects where id = object_id('EventLog') and type = 'U') drop table EventLoggo
/*==============================================================*//* Table: EventLog *//*==============================================================*/create table EventLog ( ID integer identity, EventTime datetime null, OperatorId integer not null default -1, Content text null, constraint PK_EVENTLOG primary key nonclustered (ID))go
if exists (select 1 from sysobjects where id = object_id('proc_insert_EventLog') and type = 'P') drop procedure proc_insert_EventLoggo
create procedure proc_insert_EventLog( @OperatorId integer, @Content text) asbegin insert into EventLog(EventTime,OperatorId,Content) values(getdate(),@OperatorId,@Content)endgo
I
2013年10月08日 03点10分 2
先谢谢你,这能记录每个操作么,怎么实现到程序里面啊。
2013年10月09日 05点10分
level 8
我那个是大程序,要一个模块一个的加,谢谢各位了, 楼上的全局类很适合你的大程 序
2013年10月09日 01点10分 3
1