模拟代码如下:
public
cinvcode,cinvname,cinvstd,inputcode,sqlstring:string;
procedure TForm1.FormCreate(Sender: TObject);
var s1,s2:string;
begin
with adoconnection1 do
begin
if connected then connected:=false;
connectionstring:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=UFData_999_2001';
loginprompt:=false;
connected:=true;
end;
with adotable2 do
begin
if active then active:=false;
connection:=adoconnection1;
tablename:='xf_cinvcode';
active:=true;
end;
with wwdblookupcombodlg1 do
begin
selected.Clear;
selected.add('cinvcode'+#9+'20'+#9+'零件编号'+#9+'T');
selected.add('cinvname'+#9+'30'+#9+'零件名称'+#9+'T');
selected.add('cinvstd'+#9+'20'+#9+'规格型号'+#9+'T');
lookuptable:=adotable2;
lookupfield:='cinvcode';
end;
sqlstring:='select table_name from information_schema.tables where table_name='+'''xf_fhbatch''';
adodataset1.Recordset:=adoconnection1.Execute(sqlstring);
if adodataset1.RecordCount>0 then adoconnection1.Execute('drop table xf_fhbatch');
adodataset1.Recordset:=adoconnection1.Execute('select ccode,cname from xf_gx');
sqlstring:='create table xf_fhbatch (cinvcode char(20) not null,cinvname char(30) null,cinvstd char(20) null ';
adodataset1.First;
while not adodataset1.Eof do
begin
s1:= trim(adodataset1.fieldbyname('ccode').asstring);
s2:=trim(adodataset1.fieldbyname('cname').asstring);
sqlstring:=sqlstring+',['+s1+s2+'] money null default(0.00)';
s1:='';
s2:='';
adodataset1.next;
end;
sqlstring:=sqlstring+' ) on [primary]';
adoconnection1.Execute(sqlstring);
with adotable1 do
begin
connection:=adoconnection1;
tablename:='xf_fhbatch';
active:=true;
end;
wwdbgrid1.readonly:=true;
wwdbgrid1.datasource:=datasource1;
datasource1.DataSet:=adotable1;
wwdbgrid1.setcontroltype('cinvcode',fctcustom,'wwdblookupcombodlg1');
end;
procedure TForm1.wwDBGrid1ColExit(Sender: TObject);
begin
with wwdbgrid1 do
begin
if getactivefield.fieldname='cinvcode' then
begin
if (adotable1.State=dsedit) or (adotable1.state=dsinsert) then
adotable1.post;
if cinvcode='' then
begin //手工输入
inputcode:=trimleft(trimright(adotable1.fieldbyname('cinvcode').asstring));
if inputcode<>'' then
begin
sqlstring:='select * from inventory where cinvcode='+''''+inputcode+'''';
adodataset1.Recordset:=ADOConnection1.Execute(sqlstring);
if adodataset1.RecordCount>0 then
begin
adodataset1.First;
cinvcode:=adodataset1.fieldbyname('cinvcode').value;
cinvname:=adodataset1.fieldbyname('cinvname').value;
end //input is not null
else
begin //输入无效编码
messagedlg('无效的编号!',mtwarning,[mbcancel],0);
abort;
end; // batch is null
end
else //无输入
begin
messagedlg('编号不能为空',mtinformation,[mbok],0);
abort;
end;
end;
with adotable1 do
begin
edit;
fieldbyname('cinvcode').asstring:=cinvcode;
fieldbyname('cinvname').asstring:=cinvname;
post;
cinvcode:='';
cinvname:='';
cinvstd:='';
edit;
end;
end
else
adotable1.Edit;
end;
end;
注: sqlserver 7.0 database delphi5 + ip2000
另:xf_gx 表 记录 如下:
cdep ccode cname
01 0101 车
01 0102 铣
01 0103 磨
为某车间之工序表,现通过 xf_fhbatch 输入某一零件某一工序的定额工资。
请高手指教。