5,928
社区成员




procedure TfrmKp.FillDBGridWare(id: integer; bLoad: Boolean);
var
qu: TADOQuery;
s: string;
begin
s := 'Select * from Ware where ID = ' + IntToStr(id);
qu := TADOQuery.Create(Self);
qu.Connection := DM.conn;
qu.SQL.Text := s;
qu.Active := True;
qu.First;
if not qu.Eof then
begin
s := qu.FieldByName('WareName').AsString;
if dbg.Columns[3].PickList.IndexOf(s) < 0 then // -1
begin //判断的目的是为了在DBGridEh第二行选择同样商品时不重复加入PickList中
dbg.Columns[3].PickList.Add(s);
dbg.Columns[3].KeyList.Add(IntToStr(id));
end;
//赋值后必须跳转焦点,否则不生效,造成只计算一行的金额
dbg.SelectedIndex := dbg.SelectedIndex + 2; //跳过两列
if bLoad then
begin
ds_invd.Edit;
ds_invd.FieldByName('Unit').AsString := qu.FieldByName('Unit').AsString;
ds_invd.FieldByName('Price').AsCurrency := qu.FieldByName('Price').AsCurrency;
end;
end;
qu.Close;
qu.Free;
end;