在做销售录入界面时,如何使用dbgrid?(50分)

给你段源码看一看
用stringgird做得:

procedure Tfrmingoods.adddata ;
var
i:integer;
begin
for i:= to listgrid.RowCount - do
begin
if trim(listgrid.Cells[,i])=trim(goodsid.Text) then
begin
messagedlg('该种商品已输入!',mtWarning,[mbok],);
exit;
end;
end;
if goodsid.Text<>'' then
begin
if dm.commquery.Active then
dm.commquery.Active :=false;
dm.commquery.SQL.Clear ;
dm.commquery.SQL.Add('select * from goods where goodsid='+goodsid.Text+' and isdel=0');
try
dm.commquery.Open ;
if not dm.commquery.Eof then
begin
// currentrow:=cursorposition;
listgrid.Cells[,listgrid.RowCount-]:=dm.commquery.FieldValues['goodsid'];
listgrid.Cells[,listgrid.RowCount-]:=dm.commquery.FieldValues['goodsname'];
listgrid.Cells[,listgrid.RowCount-]:=dm.commquery.FieldValues['standard'];
listgrid.Cells[,listgrid.RowCount-]:=dm.commquery.FieldValues['unit'];
listgrid.Cells[,listgrid.RowCount-]:=trim(format('%8.2f',[dm.commquery.Fieldbyname('inprice').AsFloat]));
listgrid.RowCount :=listgrid.RowCount +;
listgrid.Col:=;
listgrid.Row:=listgrid.RowCount-;
listgrid.SetFocus ;
currentcursor(listgrid.RowCount-);
end
else
messagedlg('没有该种商品',mtWarning,[mbok],);
except
messagedlg('输入了非法字符!',mtWarning,[mbok],);
end;
end;
end;
下面是用query+dbgird做得:
procedure Tfrmoutgoods.goodsidKeyPress(Sender: TObject; var Key: Char);
begin
if key=# then
begin
if dm.commquery.Active then
dm.commquery.Active :=false;
dm.commquery.SQL.Clear ;
dm.commquery.SQL.Add('select goodsid,goodsname,standard,unit,redailprice from goods where goodsid='+goodsid.Text+' and isdel=0');
dm.commquery.Open;
if not dm.commquery.Eof then
begin
if not tempquery.Active then
tempquery.Open ;
if tempquery.Locate('goodsid',goodsid.Text,[loCaseInsensitive]) then
begin
application.MessageBox('该商品已经输入。','提示',mb_ok);
end
else
begin
tempquery.Append ;
tempquery.FieldValues['goodsid']:=dm.commquery.FieldValues['goodsid'];
tempquery.FieldValues['goodsname']:=dm.commquery.FieldValues['goodsname'];
tempquery.FieldValues['standard']:=dm.commquery.FieldValues['standard'];
tempquery.FieldValues['goodsunit']:=dm.commquery.FieldValues['unit'];
tempquery.FieldValues['goodsprice']:=dm.commquery.FieldValues['redailprice'];
tempquery.FieldValues['flage']:=;
end;
end //结束关于goods表的查询。
else
application.MessageBox('没有该商品。','提示',mb_ok);
end;
end; procedure Tfrmoutgoods.tempqueryCalcFields(DataSet: TDataSet);
begin
tempquerytotalprice.Value :=tempquerygoodscount.Value *tempquerygoodsprice.Value ;
end; procedure Tfrmoutgoods.tempquerygoodscountValidate(Sender: TField);
var
flage:integer; //定义商品的库存状态类别:0:有库存且满足所需;1:库存中该商品数量不足;2:库存中没有该商品;
begin
if (goodsid.Text<>'') and (trim(storname.Text)<>'') then
begin
flage:=;
if dm.commquery.Active then
dm.commquery.Active :=false;
dm.commquery.SQL.Clear ;
dm.commquery.SQL.Add('select sum(a.incount) as storecount from storagelist a,storehouse b where a.storehouseid=b.storehouseid and a.goodsid='+tempquery.FieldValues['goodsid']+' and b.storehousename='+#+trim(storname.Text)+#);
dm.commquery.Open;
if dm.commquery.Eof then
begin
messagedlg('该商品没有库存!',mtWarning,[mbok],);
flage:=;
end
else
begin
if dm.commquery.FieldValues['storecount']<sender.Value then
begin
messagedlg('该商品库存不足!',mtWarning,[mbok],);
flage:=;
end;
end;
dm.commquery.Close ;
case flage of
: tempquery.FieldValues['flage']:=;
: tempquery.FieldValues['flage']:=;
: tempquery.FieldValues['flage']:=;
end;
end
else
begin
application.MessageBox('请选择出货仓库。','提示',mb_ok);
end;
end;
用query+dbgrid需要一个临时表来做。
上一篇:openstack私有云布署实践【11.1 计算nova - compute节点配置(科兴环境)】


下一篇:python记录_day019 类的约束 异常处理 日志