{$Define Tfeiyong} unit UntDataBaseTrposV2;interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,adoDb,Variants; Type TrposV2 = class(TObject) Public AdoQuery :TAdoQuery; constructor Create(Adoconnection:TAdoconnection); destructor Destroy; override ; end;
{$IFDEF Tfeiyong} Tfeiyong = class(TrposV2) Private public Pecode : string; Pyearmonth : string; Pshui : real; Pdian : real; Pwuye : real; Pqunuan : real; Pweixiu : real; Pqita : real; Pbeizhu : string; Pstatus : integer; Pcashfirst : real; Pcashchg : real; Psubfirst : real; Psubchg : real; Pdisc : real; Puserid : string; Poperdate : TDatetime; Function FindRecorder(GiveValueToVariant:boolean):boolean; //查找某一条记录,用主键值做条件 Function InsertIntoTable:boolean; //向表中插入一条记录 Function UpdateTable:boolean; //更新一条记录,用主键值做条件 Function DeleteTable(PromptDlg:boolean):boolean; //删除一条记录,用主键值做条件 End; {$ENDIF} implementation { TrposV2 } constructor TrposV2.create(ADOConnection:TADOConnection) ; begin adoquery:=Tadoquery.Create(nil); adoquery.Connection:= ADOConnection; end; destructor TrposV2.Destroy; begin adoquery.Free; adoquery:=nil; inherited; end; {$IFDEF Tfeiyong} Function Tfeiyong.InsertIntoTable:boolean; Begin result:=false; if (Pecode=NULL) Or (Pecode='') then begin Application.MessageBox('有不允许为空的字段不能为空!','系统提示',MB_ICONWARNING); Exit ; End ; if (Pyearmonth=NULL) Or (Pyearmonth='') then begin Application.MessageBox('有不允许为空的字段不能为空!','系统提示',MB_ICONWARNING); Exit ; End ; With ADOQuery do Begin Close; Sql.text:= 'Insert into feiyong ('+ 'ecode,yearmonth,shui,dian,wuye,qunuan,weixiu,qita,beizhu,status,'+ ' cashfirst,cashchg,subfirst,subchg,disc,userid,'+ 'operdate) values ('+ ':P_ecode,:P_yearmonth,:P_shui,:P_dian,:P_wuye,:P_qunuan,:P_weixiu,:P_qita,:P_beizhu,:P_status,'+ ' :P_cashfirst,:P_cashchg,:P_subfirst,:P_subchg,:P_disc,:P_userid,'+ ':P_operdate) '; Parameters.ParamByName('P_ecode').Value:=Copy(Pecode,1,10) ; Parameters.ParamByName('P_yearmonth').Value:=Copy(Pyearmonth,1,6) ; Parameters.ParamByName('P_shui').Value:=Pshui ; Parameters.ParamByName('P_dian').Value:=Pdian ; Parameters.ParamByName('P_wuye').Value:=Pwuye ; Parameters.ParamByName('P_qunuan').Value:=Pqunuan ; Parameters.ParamByName('P_weixiu').Value:=Pweixiu ; Parameters.ParamByName('P_qita').Value:=Pqita ; Parameters.ParamByName('P_beizhu').Value:=Copy(Pbeizhu,1,50) ; Parameters.ParamByName('P_status').Value:=Pstatus ; Parameters.ParamByName('P_cashfirst').Value:=Pcashfirst ; Parameters.ParamByName('P_cashchg').Value:=Pcashchg ; Parameters.ParamByName('P_subfirst').Value:=Psubfirst ; Parameters.ParamByName('P_subchg').Value:=Psubchg ; Parameters.ParamByName('P_disc').Value:=Pdisc ; Parameters.ParamByName('P_userid').Value:=Copy(Puserid,1,32) ; Parameters.ParamByName('P_operdate').Value:=Poperdate ; Try EXECSql ; result:=True ; except Application.MessageBox('存储失败!','系统提示',MB_ICONWARNING); End; End; end; Function Tfeiyong.UpdateTable:boolean; Begin result:=false; if (Pecode=NULL) Or (Pecode='') then begin Application.MessageBox('有不允许为空的字段不能为空!','系统提示',MB_ICONWARNING); Exit ; End ; if (Pyearmonth=NULL) Or (Pyearmonth='') then begin Application.MessageBox('有不允许为空的字段不能为空!','系统提示',MB_ICONWARNING); Exit ; End ; With ADOQuery do Begin Close; Sql.text:=' Update feiyong set '+ ' shui=:P_shui,dian=:P_dian,wuye=:P_wuye,qunuan=:P_qunuan,weixiu=:P_weixiu,qita=:P_qita,beizhu=:P_beizhu,status=:P_status,'+ ' cashfirst=:P_cashfirst,cashchg=:P_cashchg,subfirst=:P_subfirst,subchg=:P_subchg,disc=:P_disc,userid=:P_userid,'+ 'operdate=:P_operdate' + ' Where (ecode=:P_ecode) and (yearmonth=:P_yearmonth)' ; Parameters.ParamByName('P_ecode').Value:=Copy(Pecode,1,10) ; Parameters.ParamByName('P_yearmonth').Value:=Copy(Pyearmonth,1,6) ; Parameters.ParamByName('P_shui').Value:=Pshui ; Parameters.ParamByName('P_dian').Value:=Pdian ; Parameters.ParamByName('P_wuye').Value:=Pwuye ; Parameters.ParamByName('P_qunuan').Value:=Pqunuan ; Parameters.ParamByName('P_weixiu').Value:=Pweixiu ; Parameters.ParamByName('P_qita').Value:=Pqita ; Parameters.ParamByName('P_beizhu').Value:=Copy(Pbeizhu,1,50) ; Parameters.ParamByName('P_status').Value:=Pstatus ; Parameters.ParamByName('P_cashfirst').Value:=Pcashfirst ; Parameters.ParamByName('P_cashchg').Value:=Pcashchg ; Parameters.ParamByName('P_subfirst').Value:=Psubfirst ; Parameters.ParamByName('P_subchg').Value:=Psubchg ; Parameters.ParamByName('P_disc').Value:=Pdisc ; Parameters.ParamByName('P_userid').Value:=Copy(Puserid,1,32) ; Parameters.ParamByName('P_operdate').Value:=Poperdate ; Try EXECSql ; result:=true; except Application.MessageBox('存储失败!','系统提示',MB_ICONWARNING); End; End; end; Function Tfeiyong.DeleteTable(PromptDlg:boolean ):boolean; Begin result:=false; With ADOQuery do Begin Close; Sql.text:=' Delete From feiyong Where ecode=:P_ecode and yearmonth=:P_yearmonth'; Parameters.ParamByName('P_ecode').Value:=Pecode ; Parameters.ParamByName('P_yearmonth').Value:=Pyearmonth ; if PromptDlg then begin if application.MessageBox('你将删除选定的记录,继续吗?','系统提示', MB_OKCANCEL+MB_ICONWARNING)=1 then Begin ExecSql; result:=true; end; end else begin ExecSql; result:=true; end; End; end; Function Tfeiyong.FindRecorder(GiveValueToVariant:boolean):boolean; Begin result:=false; With ADOQuery do Begin Close; Sql.text:=' Select * From feiyong Where ecode=:P_ecode and yearmonth=:P_yearmonth'; Parameters.ParamByName('P_ecode').Value:=Pecode ; Parameters.ParamByName('P_yearmonth').Value:=Pyearmonth ; Open; if recordcount>0 then begin result:=true; if GiveValueToVariant then begin //Pecode:=Fieldbyname('ecode').asstring; // //Pyearmonth:=Fieldbyname('yearmonth').asstring; // Pshui:=Fieldbyname('shui').asfloat; // Pdian:=Fieldbyname('dian').asfloat; // Pwuye:=Fieldbyname('wuye').asfloat; // Pqunuan:=Fieldbyname('qunuan').asfloat; // Pweixiu:=Fieldbyname('weixiu').asfloat; // Pqita:=Fieldbyname('qita').asfloat; // Pbeizhu:=Fieldbyname('beizhu').asstring; // Pstatus:=Fieldbyname('status').asinteger; // Pcashfirst:=Fieldbyname('cashfirst').asfloat; // Pcashchg:=Fieldbyname('cashchg').asfloat; // Psubfirst:=Fieldbyname('subfirst').asfloat; // Psubchg:=Fieldbyname('subchg').asfloat; // Pdisc:=Fieldbyname('disc').asfloat; // Puserid:=Fieldbyname('userid').asstring; // Poperdate:=Fieldbyname('operdate').asdatetime; // End; End; End; end; {$ENDIF} end.
把ADO的所有组件全部封装..只要放一个就全放了.爽
unit OperationClass;interface uses Windows,Forms, SysUtils,DB, ADODB,DBTables; type //申请接口 Toperate=Class private FSQL_Text:string; protected procedure ExecuteAppend;virtual;abstract; procedure ExecuteDelete;virtual;abstract; procedure ExecuteModified;virtual;abstract; public procedure Append; procedure Delete; procedure Modified; end; //对数据集的操作 ToperateDataset=Class(Toperate) private //判断对数据集操作是否符合条件 function JudgeIF:Boolean; protected Function JudgeDelete:Boolean;virtual;abstract; Function JudgeModified:Boolean;virtual;abstract; procedure ExecuteAppend;override; procedure ExecuteDelete;override; procedure ExecuteModified;override; public Property SQL_Text:String read FSQL_Text write FSQL_Text; constructor Create(ADOQuy:TADOQuery;BDEQuy:TQuery;SQLText:String); end; //对数据集的操作 TEnteroperateDataset=Class(ToperateDataset) private protected Function JudgeDelete:Boolean;override; Function JudgeModified:Boolean;override; public end;implementation var FADOQuy:TADOQuery; FBDEQuy:TQuery; FSQLText:String;Type Box_Flag=(mtInformation,mtError,mtWarning); Type Flag=(btOK,btOKCancel);//*================================================================ //* 函数 名:ShowMessageBox //* 参 数:Content:string;Box_Type:Box_Flag;Flag:Flag //* Box_Type 1:mtWarning 2:mtError 3:mtInformation //* Flag 1:mb_Yes,mb_cancle //* 功能描述: 各种提示信息(信息提示,错误提示,警告提示) //* //* 返 回 值: //* //* 抛出异常: //* //* 作 者:tgc 2003/5/23 //*================================================================ Function Func_ShowMessagebox(Content:string;Box_Type:Box_Flag;Flag:Flag):Integer; Begin Case Box_Type Of mtInformation: Begin IF Flag=btOK Then Result:=Application.MessageBox(Pchar(Content),'提示信息', MB_OK+MB_ICONINFORMATION) Else Result:=Application.MessageBox(PChar(Content),'提示信息', MB_OKCANCEL+MB_ICONINFORMATION); End; mtError: Begin IF Flag=btOK Then Result:=Application.MessageBox(PChar(Content),'错误提示', MB_OK+MB_ICONERROR); End; mtWarning: Begin IF Flag=btOK Then Result:=Application.MessageBox(PChar(Content),'请您注意', MB_OK+MB_ICONWARNING) Else Result:=Application.MessageBox(PChar(Content),'请您注意', MB_OKCANCEL+MB_ICONWARNING); End; End; End;{ Toperate} procedure Toperate.Append; begin ExecuteAppend; end;procedure Toperate.Delete; begin ExecuteDelete; end;procedure Toperate.Modified; begin ExecuteModified; end; { ToperateDataset }constructor ToperateDataset.Create(ADOQuy: TADOQuery; BDEQuy: TQuery; SQLText: String); begin inherited Create(); FADOQuy:=ADOQuy; FBDEQuy:=BDEQuy; FSQLText:=SQLText; end;
procedure ToperateDataset.ExecuteAppend; begin inherited; if JudgeIF then begin try if (FADOQuy<>nil) and (FSQLText<>'') then begin if FADOQuy.State<>dsInsert then begin with FADOQuy do begin Close; SQL.Clear; SQL.Add(FSQLText); Open; Append; end; end else FADOQuy.Append end else if (FBDEQuy<>nil ) and (FSQLText<>'') then begin if FBDEQuy.State<>dsInsert then begin with FBDEQuy do begin Close; SQL.Clear; SQL.Add(FSQLText); Open; Append; end; end else FBDEQuy.Append; end; except on E:Exception do Func_ShowMessagebox('执行增加操作出错! 错误原因如下:'+Chr(10)+E.message,mtError,btOK); end; end;end;procedure ToperateDataset.ExecuteDelete; begin inherited; if JudgeIF then begin try if (FADOQuy<>nil) and (FSQLText<>'') then begin with FADOQuy do begin Close; SQL.Clear; SQL.Add(FSQLText); Open; if JudgeDelete then begin IF Not IsEmpty Then begin if Func_ShowMessagebox('你确定要删除当前记录吗?',mtInformation,btOKCancel)=1 then Delete ; end else Func_ShowMessagebox('没有你要删除的记录!',mtInformation,btOK); end; end; end else if (FBDEQuy<>nil ) and (FSQLText<>'') then begin with FBDEQuy do begin Close; SQL.Clear; SQL.Add(FSQLText); Open; if JudgeDelete then begin IF Not IsEmpty Then begin if Func_ShowMessagebox('你确定要删除当前记录吗?',mtInformation,btOKCancel)=1 then Delete ; end else Func_ShowMessagebox('没有你要删除的记录!',mtInformation,btOK); end; end; end; except on E:Exception do Func_ShowMessagebox('执行删除操作出错! 错误原因如下:'+Chr(10)+E.message,mtError,btOK); end; end; end;procedure ToperateDataset.ExecuteModified; begin inherited; if JudgeIF then begin try if (FADOQuy<>nil) and (FSQLText<>'') then begin if FADOQuy.State<>dsEdit then begin with FADOQuy do begin Close; SQL.Clear; SQL.Add(FSQLText); Open; if JudgeModified then begin IF Not IsEmpty Then Edit else Func_ShowMessagebox('没有你要修改的记录!',mtInformation,btOK); end; end; end else Func_ShowMessagebox('数据集已经是修改状态!',mtInformation,btOK); end else if (FBDEQuy<>nil ) and (FSQLText<>'') then begin if FBDEQuy.State<>dsEdit then begin with FBDEQuy do begin Close; SQL.Clear; SQL.Add(FSQLText); Open; if JudgeModified then begin IF Not IsEmpty Then Edit else Func_ShowMessagebox('没有你要修改的记录!',mtInformation,btOK); end; end; end else Func_ShowMessagebox('数据集已经是修改状态!',mtInformation,btOK); end; except on E:Exception do Func_ShowMessagebox('执行修改操作出错! 错误原因如下:'+Chr(10)+E.message,mtError,btOK); end; end; end;function ToperateDataset.JudgeIF: Boolean; begin if (FADOQuy=nil) and (FBDEQuy=nil) then begin Func_ShowMessagebox('数据集为空,此操作无效!',mtError,btOK); Result:=False; Exit; end else if (FADOQuy<>nil) and (FBDEQuy<>nil) then begin Func_ShowMessagebox('数据集太多,此操作无效!',mtError,btOK); Result:=False; Exit; end; if FSQLText='' then FSQLText:=SQL_Text; if FSQLText='' then begin Func_ShowMessagebox('没有SQL语句,此操作无效!',mtError,btOK); Result:=False; Exit; end; Result:=True; end;{ TEnteroperateDataset }function TEnteroperateDataset.JudgeDelete: Boolean; begin Result:=True; end;function TEnteroperateDataset.JudgeModified: Boolean; begin Result:=True; end;end.
bluemeteor(挂月||╭∩╮(︶_︶)╭∩╮)的说法!
每张表建立相应的过程,这个应该好写
就是SQL语句的问题
表的字段比较多,每张表也不相同,我采用的方法是记录(表的所有字段定义成记录,表的主键也定义成记录,这样做的好处是传参数少点)
=>
//增:新增会计科目表(tbsubject)资料表操作函数
procedure AddSubject(recInsert: TrecSubject);
====这一步,只要表的结构定下来,就好写
====我这边是采用自动生成的方法2)业务流程再封装在一层(类)==关键在这一层
注意是对业务流程进行处理,不是单张表,涉及到多张表之间的关联
如:会计科目维护,有新增,修改,删除,打印...
=>
TClassSubject = class(TObject)
//新增会计科目
procedure TClassSubject.Add;
begin
AddSubject(FRecSubject); //调用上边那层的过程
.....//再处理关联部分
end;3)用户介面直接调用业务流程(类)的东西就可以
就是把用户录入的介面资料采取在相应的记录或List里
procedure TFrmSubject.AddSubject;
begin
clsSubject.Add;//调用业务类里面的东西
btnAddClick(nil);
end;>>现在一直在采用这种写法,主要是程序的维护起来很方便
同志啊,如果写成一个类那可是不那么容易...
unit UntDataBaseTrposV2;interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,adoDb,Variants;
Type
TrposV2 = class(TObject)
Public
AdoQuery :TAdoQuery;
constructor Create(Adoconnection:TAdoconnection);
destructor Destroy; override ;
end;
{$IFDEF Tfeiyong}
Tfeiyong = class(TrposV2)
Private
public
Pecode : string;
Pyearmonth : string;
Pshui : real;
Pdian : real;
Pwuye : real;
Pqunuan : real;
Pweixiu : real;
Pqita : real;
Pbeizhu : string;
Pstatus : integer;
Pcashfirst : real;
Pcashchg : real;
Psubfirst : real;
Psubchg : real;
Pdisc : real;
Puserid : string;
Poperdate : TDatetime;
Function FindRecorder(GiveValueToVariant:boolean):boolean; //查找某一条记录,用主键值做条件
Function InsertIntoTable:boolean; //向表中插入一条记录
Function UpdateTable:boolean; //更新一条记录,用主键值做条件
Function DeleteTable(PromptDlg:boolean):boolean; //删除一条记录,用主键值做条件
End;
{$ENDIF}
implementation
{ TrposV2 }
constructor TrposV2.create(ADOConnection:TADOConnection) ;
begin
adoquery:=Tadoquery.Create(nil);
adoquery.Connection:= ADOConnection;
end;
destructor TrposV2.Destroy;
begin
adoquery.Free;
adoquery:=nil;
inherited;
end;
{$IFDEF Tfeiyong}
Function Tfeiyong.InsertIntoTable:boolean;
Begin
result:=false;
if (Pecode=NULL) Or (Pecode='') then
begin
Application.MessageBox('有不允许为空的字段不能为空!','系统提示',MB_ICONWARNING);
Exit ;
End ;
if (Pyearmonth=NULL) Or (Pyearmonth='') then
begin
Application.MessageBox('有不允许为空的字段不能为空!','系统提示',MB_ICONWARNING);
Exit ;
End ;
With ADOQuery do
Begin
Close;
Sql.text:=
'Insert into feiyong ('+
'ecode,yearmonth,shui,dian,wuye,qunuan,weixiu,qita,beizhu,status,'+
' cashfirst,cashchg,subfirst,subchg,disc,userid,'+
'operdate) values ('+
':P_ecode,:P_yearmonth,:P_shui,:P_dian,:P_wuye,:P_qunuan,:P_weixiu,:P_qita,:P_beizhu,:P_status,'+
' :P_cashfirst,:P_cashchg,:P_subfirst,:P_subchg,:P_disc,:P_userid,'+
':P_operdate) ';
Parameters.ParamByName('P_ecode').Value:=Copy(Pecode,1,10) ;
Parameters.ParamByName('P_yearmonth').Value:=Copy(Pyearmonth,1,6) ;
Parameters.ParamByName('P_shui').Value:=Pshui ;
Parameters.ParamByName('P_dian').Value:=Pdian ;
Parameters.ParamByName('P_wuye').Value:=Pwuye ;
Parameters.ParamByName('P_qunuan').Value:=Pqunuan ;
Parameters.ParamByName('P_weixiu').Value:=Pweixiu ;
Parameters.ParamByName('P_qita').Value:=Pqita ;
Parameters.ParamByName('P_beizhu').Value:=Copy(Pbeizhu,1,50) ;
Parameters.ParamByName('P_status').Value:=Pstatus ;
Parameters.ParamByName('P_cashfirst').Value:=Pcashfirst ;
Parameters.ParamByName('P_cashchg').Value:=Pcashchg ;
Parameters.ParamByName('P_subfirst').Value:=Psubfirst ;
Parameters.ParamByName('P_subchg').Value:=Psubchg ;
Parameters.ParamByName('P_disc').Value:=Pdisc ;
Parameters.ParamByName('P_userid').Value:=Copy(Puserid,1,32) ;
Parameters.ParamByName('P_operdate').Value:=Poperdate ;
Try
EXECSql ;
result:=True ;
except
Application.MessageBox('存储失败!','系统提示',MB_ICONWARNING);
End;
End;
end;
Function Tfeiyong.UpdateTable:boolean;
Begin
result:=false;
if (Pecode=NULL) Or (Pecode='') then
begin
Application.MessageBox('有不允许为空的字段不能为空!','系统提示',MB_ICONWARNING);
Exit ;
End ;
if (Pyearmonth=NULL) Or (Pyearmonth='') then
begin
Application.MessageBox('有不允许为空的字段不能为空!','系统提示',MB_ICONWARNING);
Exit ;
End ;
With ADOQuery do
Begin
Close;
Sql.text:=' Update feiyong set '+
' shui=:P_shui,dian=:P_dian,wuye=:P_wuye,qunuan=:P_qunuan,weixiu=:P_weixiu,qita=:P_qita,beizhu=:P_beizhu,status=:P_status,'+
' cashfirst=:P_cashfirst,cashchg=:P_cashchg,subfirst=:P_subfirst,subchg=:P_subchg,disc=:P_disc,userid=:P_userid,'+
'operdate=:P_operdate' +
' Where (ecode=:P_ecode) and (yearmonth=:P_yearmonth)' ;
Parameters.ParamByName('P_ecode').Value:=Copy(Pecode,1,10) ;
Parameters.ParamByName('P_yearmonth').Value:=Copy(Pyearmonth,1,6) ;
Parameters.ParamByName('P_shui').Value:=Pshui ;
Parameters.ParamByName('P_dian').Value:=Pdian ;
Parameters.ParamByName('P_wuye').Value:=Pwuye ;
Parameters.ParamByName('P_qunuan').Value:=Pqunuan ;
Parameters.ParamByName('P_weixiu').Value:=Pweixiu ;
Parameters.ParamByName('P_qita').Value:=Pqita ;
Parameters.ParamByName('P_beizhu').Value:=Copy(Pbeizhu,1,50) ;
Parameters.ParamByName('P_status').Value:=Pstatus ;
Parameters.ParamByName('P_cashfirst').Value:=Pcashfirst ;
Parameters.ParamByName('P_cashchg').Value:=Pcashchg ;
Parameters.ParamByName('P_subfirst').Value:=Psubfirst ;
Parameters.ParamByName('P_subchg').Value:=Psubchg ;
Parameters.ParamByName('P_disc').Value:=Pdisc ;
Parameters.ParamByName('P_userid').Value:=Copy(Puserid,1,32) ;
Parameters.ParamByName('P_operdate').Value:=Poperdate ;
Try
EXECSql ;
result:=true;
except
Application.MessageBox('存储失败!','系统提示',MB_ICONWARNING);
End;
End;
end;
Function Tfeiyong.DeleteTable(PromptDlg:boolean ):boolean;
Begin
result:=false;
With ADOQuery do
Begin
Close;
Sql.text:=' Delete From feiyong Where ecode=:P_ecode and yearmonth=:P_yearmonth';
Parameters.ParamByName('P_ecode').Value:=Pecode ;
Parameters.ParamByName('P_yearmonth').Value:=Pyearmonth ;
if PromptDlg then begin
if application.MessageBox('你将删除选定的记录,继续吗?','系统提示', MB_OKCANCEL+MB_ICONWARNING)=1 then
Begin
ExecSql;
result:=true;
end;
end else begin
ExecSql;
result:=true;
end;
End;
end;
Function Tfeiyong.FindRecorder(GiveValueToVariant:boolean):boolean;
Begin
result:=false;
With ADOQuery do
Begin
Close;
Sql.text:=' Select * From feiyong Where ecode=:P_ecode and yearmonth=:P_yearmonth';
Parameters.ParamByName('P_ecode').Value:=Pecode ;
Parameters.ParamByName('P_yearmonth').Value:=Pyearmonth ;
Open;
if recordcount>0 then begin
result:=true;
if GiveValueToVariant then begin
//Pecode:=Fieldbyname('ecode').asstring; //
//Pyearmonth:=Fieldbyname('yearmonth').asstring; //
Pshui:=Fieldbyname('shui').asfloat; //
Pdian:=Fieldbyname('dian').asfloat; //
Pwuye:=Fieldbyname('wuye').asfloat; //
Pqunuan:=Fieldbyname('qunuan').asfloat; //
Pweixiu:=Fieldbyname('weixiu').asfloat; //
Pqita:=Fieldbyname('qita').asfloat; //
Pbeizhu:=Fieldbyname('beizhu').asstring; //
Pstatus:=Fieldbyname('status').asinteger; //
Pcashfirst:=Fieldbyname('cashfirst').asfloat; //
Pcashchg:=Fieldbyname('cashchg').asfloat; //
Psubfirst:=Fieldbyname('subfirst').asfloat; //
Psubchg:=Fieldbyname('subchg').asfloat; //
Pdisc:=Fieldbyname('disc').asfloat; //
Puserid:=Fieldbyname('userid').asstring; //
Poperdate:=Fieldbyname('operdate').asdatetime; //
End;
End;
End;
end;
{$ENDIF}
end.
uses
Windows,Forms, SysUtils,DB, ADODB,DBTables;
type
//申请接口
Toperate=Class
private
FSQL_Text:string;
protected
procedure ExecuteAppend;virtual;abstract;
procedure ExecuteDelete;virtual;abstract;
procedure ExecuteModified;virtual;abstract;
public
procedure Append;
procedure Delete;
procedure Modified;
end; //对数据集的操作
ToperateDataset=Class(Toperate)
private
//判断对数据集操作是否符合条件
function JudgeIF:Boolean;
protected
Function JudgeDelete:Boolean;virtual;abstract;
Function JudgeModified:Boolean;virtual;abstract; procedure ExecuteAppend;override;
procedure ExecuteDelete;override;
procedure ExecuteModified;override;
public
Property SQL_Text:String read FSQL_Text write FSQL_Text;
constructor Create(ADOQuy:TADOQuery;BDEQuy:TQuery;SQLText:String);
end; //对数据集的操作
TEnteroperateDataset=Class(ToperateDataset)
private
protected
Function JudgeDelete:Boolean;override;
Function JudgeModified:Boolean;override;
public
end;implementation
var
FADOQuy:TADOQuery;
FBDEQuy:TQuery;
FSQLText:String;Type
Box_Flag=(mtInformation,mtError,mtWarning);
Type
Flag=(btOK,btOKCancel);//*================================================================
//* 函数 名:ShowMessageBox
//* 参 数:Content:string;Box_Type:Box_Flag;Flag:Flag
//* Box_Type 1:mtWarning 2:mtError 3:mtInformation
//* Flag 1:mb_Yes,mb_cancle
//* 功能描述: 各种提示信息(信息提示,错误提示,警告提示)
//*
//* 返 回 值:
//*
//* 抛出异常:
//*
//* 作 者:tgc 2003/5/23
//*================================================================
Function Func_ShowMessagebox(Content:string;Box_Type:Box_Flag;Flag:Flag):Integer;
Begin
Case Box_Type Of
mtInformation:
Begin
IF Flag=btOK Then
Result:=Application.MessageBox(Pchar(Content),'提示信息',
MB_OK+MB_ICONINFORMATION)
Else
Result:=Application.MessageBox(PChar(Content),'提示信息',
MB_OKCANCEL+MB_ICONINFORMATION);
End;
mtError:
Begin
IF Flag=btOK Then
Result:=Application.MessageBox(PChar(Content),'错误提示',
MB_OK+MB_ICONERROR);
End;
mtWarning:
Begin
IF Flag=btOK Then
Result:=Application.MessageBox(PChar(Content),'请您注意',
MB_OK+MB_ICONWARNING)
Else
Result:=Application.MessageBox(PChar(Content),'请您注意',
MB_OKCANCEL+MB_ICONWARNING);
End;
End;
End;{ Toperate}
procedure Toperate.Append;
begin
ExecuteAppend;
end;procedure Toperate.Delete;
begin
ExecuteDelete;
end;procedure Toperate.Modified;
begin
ExecuteModified;
end;
{ ToperateDataset }constructor ToperateDataset.Create(ADOQuy: TADOQuery; BDEQuy: TQuery;
SQLText: String);
begin
inherited Create();
FADOQuy:=ADOQuy;
FBDEQuy:=BDEQuy;
FSQLText:=SQLText;
end;
begin
inherited;
if JudgeIF then
begin
try
if (FADOQuy<>nil) and (FSQLText<>'') then
begin
if FADOQuy.State<>dsInsert then
begin
with FADOQuy do
begin
Close;
SQL.Clear;
SQL.Add(FSQLText);
Open;
Append;
end;
end
else
FADOQuy.Append
end
else if (FBDEQuy<>nil ) and (FSQLText<>'') then
begin
if FBDEQuy.State<>dsInsert then
begin
with FBDEQuy do
begin
Close;
SQL.Clear;
SQL.Add(FSQLText);
Open;
Append;
end;
end
else
FBDEQuy.Append;
end;
except
on E:Exception do
Func_ShowMessagebox('执行增加操作出错! 错误原因如下:'+Chr(10)+E.message,mtError,btOK);
end;
end;end;procedure ToperateDataset.ExecuteDelete;
begin
inherited;
if JudgeIF then
begin
try
if (FADOQuy<>nil) and (FSQLText<>'') then
begin
with FADOQuy do
begin
Close;
SQL.Clear;
SQL.Add(FSQLText);
Open;
if JudgeDelete then
begin
IF Not IsEmpty Then
begin
if Func_ShowMessagebox('你确定要删除当前记录吗?',mtInformation,btOKCancel)=1 then
Delete ;
end
else
Func_ShowMessagebox('没有你要删除的记录!',mtInformation,btOK);
end;
end;
end
else if (FBDEQuy<>nil ) and (FSQLText<>'') then
begin
with FBDEQuy do
begin
Close;
SQL.Clear;
SQL.Add(FSQLText);
Open;
if JudgeDelete then
begin
IF Not IsEmpty Then
begin
if Func_ShowMessagebox('你确定要删除当前记录吗?',mtInformation,btOKCancel)=1 then
Delete ;
end
else
Func_ShowMessagebox('没有你要删除的记录!',mtInformation,btOK);
end;
end;
end;
except
on E:Exception do
Func_ShowMessagebox('执行删除操作出错! 错误原因如下:'+Chr(10)+E.message,mtError,btOK);
end;
end;
end;procedure ToperateDataset.ExecuteModified;
begin
inherited;
if JudgeIF then
begin
try
if (FADOQuy<>nil) and (FSQLText<>'') then
begin
if FADOQuy.State<>dsEdit then
begin
with FADOQuy do
begin
Close;
SQL.Clear;
SQL.Add(FSQLText);
Open;
if JudgeModified then
begin
IF Not IsEmpty Then
Edit
else
Func_ShowMessagebox('没有你要修改的记录!',mtInformation,btOK);
end;
end;
end
else
Func_ShowMessagebox('数据集已经是修改状态!',mtInformation,btOK);
end
else if (FBDEQuy<>nil ) and (FSQLText<>'') then
begin
if FBDEQuy.State<>dsEdit then
begin
with FBDEQuy do
begin
Close;
SQL.Clear;
SQL.Add(FSQLText);
Open;
if JudgeModified then
begin
IF Not IsEmpty Then
Edit
else
Func_ShowMessagebox('没有你要修改的记录!',mtInformation,btOK);
end;
end;
end
else
Func_ShowMessagebox('数据集已经是修改状态!',mtInformation,btOK);
end;
except
on E:Exception do
Func_ShowMessagebox('执行修改操作出错! 错误原因如下:'+Chr(10)+E.message,mtError,btOK);
end;
end;
end;function ToperateDataset.JudgeIF: Boolean;
begin
if (FADOQuy=nil) and (FBDEQuy=nil) then
begin
Func_ShowMessagebox('数据集为空,此操作无效!',mtError,btOK);
Result:=False;
Exit;
end
else if (FADOQuy<>nil) and (FBDEQuy<>nil) then
begin
Func_ShowMessagebox('数据集太多,此操作无效!',mtError,btOK);
Result:=False;
Exit;
end; if FSQLText='' then
FSQLText:=SQL_Text; if FSQLText='' then
begin
Func_ShowMessagebox('没有SQL语句,此操作无效!',mtError,btOK);
Result:=False;
Exit;
end;
Result:=True;
end;{ TEnteroperateDataset }function TEnteroperateDataset.JudgeDelete: Boolean;
begin
Result:=True;
end;function TEnteroperateDataset.JudgeModified: Boolean;
begin
Result:=True;
end;end.