自动编号增加的源码 procedure Tfrm_xingzhen.Button4Click(Sender: TObject); var counter:integer; id,id1:string; begin IF application.MessageBox('你要新增村名?','操作提示',mb_okcancel+mb_iconinformation) =IDOK then begin with maxno2 do begin close; sql.Clear;
sql.Text:='select max(xzid) from xingzhen'; open; id1:=maxno2.fields[0].asstring; if id1<>'' then begin counter:=strtoint(id1); counter:=counter+1; id:='0'+inttostr(counter); id:=copy(id,length(id)-1,2); end else id:='01'; end; edit4.Text:=id; edit5.Text:=id1; with xingzhenado2 do begin Close; SQL.Clear ; SQL.text:='insert into xingzhen(xzid,mingzheng)' ; SQL.Add('values (:xzid,:mingzheng)'); //Parameters.ParamByName('xzid').Value :=Trim(Edit1.Text); Parameters.ParamByName('xzid').Value :=id; Parameters.ParamByName('mingzheng').Value :=Trim(edit2.text); ExecSQL; FormActivate(Sender);
end; procedure Tfrm_KdEdit.ZbNewRecord(DataSet: TDataSet); var Sql:string; begin Sql:='select max(DjID) as DJID1 from DeliveryMaster where kdDateTime between #' + FormatDateTime('yyyy-mm-dd',now()) + '# and #' + FormatDateTime('yyyy-mm-dd',now()+1) + '#'; dbedit4.Field.Value:=now(); dbedit1.Field.Value := GetZbBh(Sql); Zb.FieldByName('UserName').AsString:=userName; end;
function Tfrm_KdEdit.GetZbBh(const Sql:String):string; var rs:TAdoQuery; rCount,sLen:integer; BhLen,MaxBh,Bh:string; begin BhLen:='0000'; rCount :=1; rs:=TAdoQuery.Create(application); rs.Connection:=dm.AdoConn; rs.SQL.Clear; rs.SQL.Add(Sql); rs.Open; if rs['DjID1']<>null then begin MaxBh:=rs['DjID1']; MaxBh:=Copy(MaxBh,Pos('-',MaxBh)+1,Length(MaxBh)); rCount:=StrToint(MaxBh)+1; end; Bh := inttostr(rCount); sLen :=Length(Bh); Bh :=copy(BhLen,sLen+1,Length(BhLen)) + Bh; Bh :='KD' + Formatdatetime('yyyymmdd',now()) + '-' + Bh; rs.Close; rs.Free; Result:=Bh; end;