var i:integer; curdate:string; begin adodataset1.open; for i:=0 to adodataset1.recordcount do begin curdate:=FormatDatetime('yy',now); //adodataset1.Append; edit1.Text:='kh'+curdate+'-00'+inttostr(i+1); next;
看不明白,KH090002是固定长度吗?如果是固定长度,KH099999的下一个如何表示?
'Select Max(ID) from 表......
不正真删除,加个删除字段就行啦.到时用一个view就行了
CREATE proc sp_GenerateDocCode @form_id int, @doc_code nvarchar(20) output as declare @flow_num nvarchar(6), @flow_num_length int--更新流水号 update sys_eform set flow_num = flow_num + 1 where form_id = @form_id and convert(nvarchar(6), flow_date, 112) = convert(nvarchar(6),getdate(), 112)--初始流水号 update sys_eform set flow_date = getdate(), flow_num = 1 where form_id = @form_id and convert(nvarchar(6), flow_date, 112) <> convert(nvarchar(6),getdate(), 112)select @flow_num = convert(nvarchar(6), flow_num), @flow_num_length = flow_num_length from sys_eform where form_id = @form_id while (len(@flow_num) < @flow_num_length) begin set @flow_num = '0' + @flow_num end--组合流水号 select @doc_code = form_code_prefix + form_code_separator + convert(nvarchar(6), flow_date, 112) + form_code_separator + @flow_num from sys_eform where form_id = @form_idGO
function GetNextID: String; var strSql, strValue, strYY: String; Temp: Integer; begin with adoquery do begin try Close; SQL.Clear; strYY := FormatDateTime('yy', Now); strSql := 'Select Max(ID) from 表名'; strSql := strSql + ' Where ID like ''%' + strYY+ '%'''; SQL.Add(strSql); Open; if adoquery.RecordCount = 0 then Result := 'KH'+ strYY + '0001' else begin strValue := Trim(adoquery.FieldByName('ID').AsString); if strValue = '' then Result := 'KH'+ strYY + '0001' else begin strValue := Trim(Copy(strValue, 5, 4)); Temp := StrToInt(strValue) + 1; Result := 'KH'+ strYY + Format('%.4d', [Temp]); end; end; except Result := 'KH'+ strYY + '0001'; end; end; end;
i:integer;
curdate:string;
begin
adodataset1.open;
for i:=0 to adodataset1.recordcount do
begin
curdate:=FormatDatetime('yy',now);
//adodataset1.Append;
edit1.Text:='kh'+curdate+'-00'+inttostr(i+1);
next;
CREATE proc sp_GenerateDocCode @form_id int, @doc_code nvarchar(20) output
as
declare
@flow_num nvarchar(6),
@flow_num_length int--更新流水号
update sys_eform
set flow_num = flow_num + 1
where form_id = @form_id and convert(nvarchar(6), flow_date, 112) = convert(nvarchar(6),getdate(), 112)--初始流水号
update sys_eform
set flow_date = getdate(), flow_num = 1
where form_id = @form_id and convert(nvarchar(6), flow_date, 112) <> convert(nvarchar(6),getdate(), 112)select @flow_num = convert(nvarchar(6), flow_num), @flow_num_length = flow_num_length
from sys_eform where form_id = @form_id
while (len(@flow_num) < @flow_num_length) begin
set @flow_num = '0' + @flow_num
end--组合流水号
select @doc_code = form_code_prefix + form_code_separator + convert(nvarchar(6), flow_date, 112) + form_code_separator + @flow_num from sys_eform where form_id = @form_idGO
var
strSql, strValue, strYY: String;
Temp: Integer;
begin
with adoquery do
begin
try
Close;
SQL.Clear;
strYY := FormatDateTime('yy', Now);
strSql := 'Select Max(ID) from 表名';
strSql := strSql + ' Where ID like ''%' + strYY+ '%''';
SQL.Add(strSql);
Open;
if adoquery.RecordCount = 0 then
Result := 'KH'+ strYY + '0001'
else
begin
strValue := Trim(adoquery.FieldByName('ID').AsString);
if strValue = '' then
Result := 'KH'+ strYY + '0001'
else
begin
strValue := Trim(Copy(strValue, 5, 4));
Temp := StrToInt(strValue) + 1;
Result := 'KH'+ strYY + Format('%.4d', [Temp]);
end;
end;
except
Result := 'KH'+ strYY + '0001';
end;
end;
end;