function GetNo(AdoConnection:TAdoConnection;PreStr:String;TypeName:string):string;
var
adoqry_getno:TAdoQuery;
TmpPmParamCode,tmpstr,tmpwhcode,prestr2:String;
begin
adoqry_getno:=TAdoQuery.create(nil);
adoqry_getno.EnableBCD:=False;
With AdoQry_GetNo do
begin
Connection:=AdoConnection;
close;
sql.clear;
//采购合同
if (UpperCase(TypeName)='PC') then //OR (UpperCase(TypeName)='PO') then
begin
If UpperCase(TypeName)='PC' then TmpPmParamCode:=PreStr+'maxpcno';
// If UpperCase(TypeName)='PO' then TmpPmParamCode:=PreStr+'maxpono';
Sql.Add('select PmParamValueN from pmparam where PmParamCode=
mParamCode');
Parameters.ParamByName('PmParamCode').Value:=TmpPmParamCode;
Open;
If (Eof) then //如果该年度还没有记录,则添加
begin
Close;
Sql.Clear;
Sql.Add('Insert Into PmParam(pmparamcode,PmParamValueN) '+
'Values('''+TmpPmParamCode+''','+'0)');
ExecSql;
result:='0001';
end
else
begin
Result:=Copy(IntToStr(10000+FieldByName('PmParamValueN').AsInteger+1),2,4)
end;
Close;
Sql.Clear; //更新数据库记录,将最大的记录号保存进去。
Sql.Add('Update PmParam Set PmParamValueN='+result+
'where PmParamCode='''+TmpPmParamCode+'''');
ExecSql;
close;
result:=PreStr+Result;
end
//采购订单
else if (UpperCase(TypeName)='PO') then //OR (UpperCase(TypeName)='PO') then
begin
Sql.Add('select max(substring(pono,'+inttostr(length(prestr)+1)+',4)) as maxpono from po with(index(pk_po)) '
+' where substring(pono,1,'+inttostr(length(prestr))+')='+quotedstr(prestr));
Open;
If fieldbyname('maxpono').asstring='' then //如果该年度还没有记录,则添加
result:='0001'
else
Result:=Copy(IntToStr(10000+FieldByName('maxpono').Asinteger+1),2,4);
result:=PreStr+Result;
end
//生产订单
else if (UpperCase(TypeName)='MO') then //OR (UpperCase(TypeName)='MO') then
begin
Sql.Add('select max(substring(mono,'+inttostr(length(prestr)+1)+',4)) as maxmono from mo with(index(pk_mo)) '
+' where substring(mono,1,'+inttostr(length(prestr))+')='+quotedstr(prestr));
Open;
If fieldbyname('maxmono').asstring='' then //如果该年度还没有记录,则添加
result:='0001'
else
Result:=Copy(IntToStr(10000+FieldByName('maxmono').Asinteger+1),2,4);
result:=PreStr+Result;
end
end;
adoqry_getno.Free;
end;