RTFormwork/项目代码/RTBasicsV1/D02针织坯布检验/DbPanel/L_DBDateTime.pas

144 lines
3.4 KiB
ObjectPascal
Raw Normal View History

2024-07-07 09:35:27 +08:00
unit L_DBDateTime;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,db,dbtables,dbctrls,Dialogs,
ComCtrls;
type
TDBDateTime = class(TDateTimePicker)
private
FDataLink:TFieldDataLink;
//TFieldDataLink<6E><6B>TDataLink<6E><6B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>DataSource<63>Ľ<EFBFBD><C4BD><EFBFBD>
procedure DataChange(sender:Tobject);
//<2F><>DataSet<65>ļ<EFBFBD>¼<EFBFBD>ı<C4B1><E4A3A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>
// ʱ<><CAB1><EFBFBD><EFBFBD>OnDataChange
// <20>¼<EFBFBD><C2BC><EFBFBD>DataChange<67><65><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
procedure UpdateData(sender:Tobject);
//<2F><><EFBFBD><EFBFBD>DataSetǰ<74><C7B0><EFBFBD><EFBFBD>OnUpdateData<74>¼<EFBFBD><C2BC><EFBFBD>
// UpdateData<74><61><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
function GetDataSource:TDataSource;
procedure SetdataSource(value:TDataSource);
Function GetDataField:String;
procedure SetdataField(Value:String);
procedure CMexit(var Message:TCMExit);
message CM_EXIT;//<2F><><EFBFBD>ؼ<EFBFBD>ʧȥ<CAA7><C8A5><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>CM_EXIT<49><54>Ϣ
protected
procedure Change;override;//<2F>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڡ<EFBFBD>
// ʱ<><CAB1><EFBFBD>ı<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>OnChange<67>¼<EFBFBD>
procedure Notification(AComponent:TComponent;
Operation:Toperation);override;
//<2F><>ijһ<C4B3>ؼ<EFBFBD><D8BC><EFBFBD>FORM<52><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱDELPHI<48><49>
// IDE<44><45><EFBFBD>ø÷<C3B8><C3B7><EFBFBD>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD>
public
constructor Create(AOwner:Tcomponent);override;
destructor Destroy;override;
published
property DataSource:TDataSource read GetDataSource
write SetDataSource;//Ϊ<>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD>DataSource<63><65><EFBFBD>ԣ<EFBFBD>
// ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DataSource<63><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
property DataField:String read GetDataField
write SetDataField;
end;//Ϊ<>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD>DataField<6C><64><EFBFBD>ԣ<EFBFBD>
// ʹ<><CAB9>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ijһ<C4B3>ֶε<D6B6>TField<6C><64><EFBFBD><EFBFBD>
procedure Register;//ע<><EFBFBD><E1B9B9>
implementation
procedure TDBDateTime.CMExit;
begin
try
FDataLink.UpdateRecord;
//<2F>ؼ<EFBFBD>ʧȥ<CAA7><C8A5><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>DataSet<65><74>
// <20><EFBFBD><E2BDAB><EFBFBD><EFBFBD>OnUpdateData<74>¼<EFBFBD>
except
Setfocus;
raise;
end;
DoExit;
end;
constructor TDBDateTime.Create(Aowner:Tcomponent);
begin
inherited Create(Aowner);
//<2F><><EFBFBD><EFBFBD>DataLink<6E><6B><EFBFBD>󣬹ҽ<F3A3ACB9>OnDataChange<67><65>
//OnUpdateData<74>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FDataLink:=TFieldDataLInk.Create;
FDataLink.OnDataChange:=DataChange;
FDataLink.OnUpdateData:=Updatedata;
end;
Destructor TDBDateTime.Destroy;
begin
FDataLink.OnDataChange:=nil;
FDataLink.OnUpdateData:=nil;
FDataLink.Free;
inherited Destroy;
end;
function TDBDateTime.GetdataSource:TdataSource;
begin
result:=FDataLink.DataSource;
end;
Procedure TDBDateTime.SetDataSource
(Value:TDataSource);
begin
FDataLink.DataSource:=Value;
end;
function TDBDateTime.GetDatafield:String;
begin
result:=FDataLink.FieldName;
end;
procedure TDBDateTime.SetDataField(value:String);
begin
FdataLink.FieldName:=value;
end;
procedure TDBDateTime.DataChange(Sender:Tobject);
begin
DateTime:=now;
//<2F><><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD>˻<CBBB><EEB6AF>DataSet<65><74><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC>䶯ʱ
//<2F>ؼ<EFBFBD><D8BC><EFBFBD>ʾ<EFBFBD><CABE>ǰ<EFBFBD><C7B0>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>Ӧ<EFBFBD>ֶ<EFBFBD>ֵ
if FDataLink.Field<>nil then
if FDataLink.Field.Text<>'' then
DateTime:=FDatalink.Field.AsDateTime;
end;
Procedure TDBDateTime.UpdateData(sender:Tobject);
begin
FDatalink.Field.AsDateTime:=DateTime;
//<2F>ÿؼ<C3BF><D8BC>е<EFBFBD><D0B5><EFBFBD><EFBFBD>ڡ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ֶ<EFBFBD>
end;
procedure TDBDateTime.Change;
begin
//<2F><><EFBFBD>û<EFBFBD><C3BB>ı<EFBFBD><C4B1>˿ؼ<CBBF><D8BC>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>DataSet<65><74>Ϊ<EFBFBD>༭״̬
FDataLink.Modified;
if not FDataLink.Editing then
FdataLink.Edit;
inherited Change;
end;
procedure TDBDateTime.Notification
(AComponent:TComponent;Operation:TOperation);
begin
inherited Notification(Acomponent,Operation);
//<2F><><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TdataSource
// <20><>ɾ<EFBFBD><C9BE>ʱ<EFBFBD><CAB1><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD>DataSource<63><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
if (Operation=opRemove) and (FDataLink<>nil)
and (AComponent=Datasource) then
DataSource:=nil;
end;
procedure Register;
begin
RegisterComponents('Data Controls',[TDBDateTime]);
end;
end.