在添加记录insert前判断是否流水号重复,表中要建立macdizhi字段存储mac地址,参看健鹏软件
设计思路:
01 02 03(机器号)
25 25 25(流水号)
当几台机器获取流水号相同时,要判断数据库中是否有25的流水号
判断第一条记录是不是该机器添加的
有记录时---- 如果是 -> 流水号不变
如不是 -> 选记录数最大流水号,改变当前流水号并赋值
无记录 ---- 直接添加
//查看流水号,避免不同计算机流水号输入重复,只限单机只开一个客户端
with ADOQuery_temp do
begin
Close;
SQL.Clear;
SQL.Add('select liushuihao from Y_liushui where liushuihao=:liushuihao and caozuobiaoshi=''药品销售''');
Parameters.ParamByName('liushuihao').Value:=Trim(Edit_liushuihao.Text);
Open;
end;
if ADOQuery_temp.RecordCount>0 then
begin
//判断记录是不是该机器录的,如果是,流水号不变,如不是要再选出最大流水号并赋值
with ADOQuery_temp do
begin
Close;
SQL.Clear;
SQL.Add('select liushuihao from Y_liushui where liushuihao=:liushuihao and macdizhi=:macdizhi and caozuobiaoshi=''药品销售''');
Parameters.ParamByName('liushuihao').Value:=Trim(Edit_liushuihao.Text);
Parameters.ParamByName('macdizhi').Value:=Trim(Frm_Login.GetMacAddress);
Open;
end;
//如不是自己机器录的,选最大流水号赋值
if ADOQuery_temp.RecordCount=0 then
begin
with ADOQuery_liushuihaocx do
begin
Close;
SQL.Clear;
SQL.Add('select isnull(max(liushuihao),0) as liushuihao from Y_liushui where caozuobiaoshi=''药品销售''');
Open;
end;
if (ADOQuery_liushuihaocx.FieldValues['liushuihao']=null) or (ADOQuery_liushuihaocx.FieldValues['liushuihao']=0) then
begin
Edit_liushuihao.Text:='1';
end
else
begin
Edit_liushuihao.Text:=IntToStr(ADOQuery_liushuihaocx.FieldValues['liushuihao']+1);
end;
end;
end;
//获取计算机Mac地址函数
function TFrm_Login.GetMacAddress: string;
var
Lib: Cardinal;
Func: function(GUID: PGUID): Longint; stdcall;
GUID1, GUID2: TGUID;
begin
Result := '';
Lib := LoadLibrary('rpcrt4.dll');
if Lib <> 0 then
begin
if Win32Platform <>VER_PLATFORM_WIN32_NT then
@Func := GetProcAddress(Lib, 'UuidCreate')
else @Func := GetProcAddress(Lib, 'UuidCreateSequential');
if Assigned(Func) then
begin
if (Func(@GUID1) = 0) and
(Func(@GUID2) = 0) and
(GUID1.D4[2] = GUID2.D4[2]) and
(GUID1.D4[3] = GUID2.D4[3]) and
(GUID1.D4[4] = GUID2.D4[4]) and
(GUID1.D4[5] = GUID2.D4[5]) and
(GUID1.D4[6] = GUID2.D4[6]) and
(GUID1.D4[7] = GUID2.D4[7]) then
begin
Result :=
IntToHex(GUID1.D4[2], 2) +'-'+
IntToHex(GUID1.D4[3], 2) +'-'+
IntToHex(GUID1.D4[4], 2) +'-'+
IntToHex(GUID1.D4[5], 2) +'-'+
IntToHex(GUID1.D4[6], 2) +'-'+
IntToHex(GUID1.D4[7], 2);
end;
end;
FreeLibrary(Lib);
end;
end;