-
Notifications
You must be signed in to change notification settings - Fork 15
HowToProgressiveField
Carlo Barazzetta edited this page Jan 20, 2017
·
1 revision
If you want to autogenerate an incremental value for a field, you have to:
- declare and write a rule for the model in Delphi
rule.pas
unit - define the node
Rules:
for the model
Example from a real project:
type
TCalcProgressivoIntervento = class(TKRuleImpl)
public
procedure BeforeAdd(const ARecord: TKRecord); override;
end;
procedure TCalcProgressivoIntervento.BeforeAdd(const ARecord: TKRecord);
var
LDBConnection: TEFDBConnection;
LQuery: TEFDBQuery;
LAnnoIntervento: string;
begin
LDBConnection := TKConfig.Instance.DBConnections[TKConfig.Instance.DatabaseName];
LQuery := LDBConnection.CreateDBQuery;
try
LQuery.CommandText := 'SELECT MAX(CAST(RIGHT(INTERVENTO.ID,5) AS INTEGER)) MAXID FROM INTERVENTO';
LQuery.Open;
LAnnoIntervento := FormatDateTime('yy', ARecord.FieldByName('DataIntervento').AsDate);
ARecord.FieldByName('Id').AsString := LAnnoIntervento +
PadLeft(IntToStr(LQuery.DataSet.FieldByName('MAXID').AsInteger + 1),5);
finally
FreeAndNil(LQuery);
end;
end;
ModelName: Intervento
...
Rules:
CalcProgressivoIntervento:
InterventoCheck:
- Kitto at a glance
- Getting started
- Setup
-
Basic concepts
- Basic Materials
- Controllers
- Features
- Examples
- Developer's guide
- Library reference
- Frequently Asked Questions
- Kitto tips & tricks and how-tos
- Other information
- Kitto Enterprise