添加二维码复用
This commit is contained in:
parent
f4818e3a29
commit
0743f82756
|
|
@ -24,19 +24,20 @@ procedure SetQrCodePath(Cds: TclientDataSet; FQrCodeField: string);
|
|||
|
||||
implementation
|
||||
|
||||
procedure SetQrCodePath(Cds: TclientDataSet; FQrCodeField: string);
|
||||
procedure SetQrCodePath(Cds: TClientDataSet; FQrCodeField: string);
|
||||
var
|
||||
QrCodeIdField: TField;
|
||||
CurrentQrCodeId, LastQrCodeId, LastQrCodePath: string;
|
||||
begin
|
||||
// 检查是否存在二维码ID字段
|
||||
if Trim(FQrCodeField) = '' then
|
||||
Exit;
|
||||
|
||||
// 检查二维码ID字段是否存在
|
||||
QrCodeIdField := Cds.FindField(FQrCodeField);
|
||||
if QrCodeIdField = nil then
|
||||
Exit;
|
||||
|
||||
// 生成二维码并绑定到ClientDataSet
|
||||
// 初始化变量
|
||||
LastQrCodeId := '';
|
||||
LastQrCodePath := '';
|
||||
|
||||
with Cds do
|
||||
begin
|
||||
DisableControls;
|
||||
|
|
@ -44,9 +45,25 @@ begin
|
|||
First;
|
||||
while not Eof do
|
||||
begin
|
||||
Edit;
|
||||
FieldByName('QRBARCODE').AsString := GetQrCode(QrCodeIdField.AsString);
|
||||
Post;
|
||||
CurrentQrCodeId := QrCodeIdField.AsString;
|
||||
|
||||
// 如果当前内容与上一条相同,则复用二维码路径
|
||||
if (CurrentQrCodeId = LastQrCodeId) and (LastQrCodePath <> '') then
|
||||
begin
|
||||
Edit;
|
||||
FieldByName('QRBARCODE').AsString := LastQrCodePath;
|
||||
Post;
|
||||
end
|
||||
else
|
||||
begin
|
||||
// 生成新的二维码并记录路径
|
||||
Edit;
|
||||
LastQrCodePath := GetQrCode(CurrentQrCodeId);
|
||||
FieldByName('QRBARCODE').AsString := LastQrCodePath;
|
||||
Post;
|
||||
LastQrCodeId := CurrentQrCodeId;
|
||||
end;
|
||||
|
||||
Next;
|
||||
end;
|
||||
finally
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user