zoukankan      html  css  js  c++  java
  • 在做销售录入界面时,如何使用dbgrid?(50分)

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

    procedure Tfrmingoods.adddata ;
    var
    i:integer;
    begin
    for i:=0 to listgrid.RowCount -1 do
    begin
    if trim(listgrid.Cells[1,i])=trim(goodsid.Text) then
    begin
    messagedlg('该种商品已输入!',mtWarning,[mbok],0);
    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[1,listgrid.RowCount-1]:=dm.commquery.FieldValues['goodsid'];
    listgrid.Cells[2,listgrid.RowCount-1]:=dm.commquery.FieldValues['goodsname'];
    listgrid.Cells[3,listgrid.RowCount-1]:=dm.commquery.FieldValues['standard'];
    listgrid.Cells[4,listgrid.RowCount-1]:=dm.commquery.FieldValues['unit'];
    listgrid.Cells[6,listgrid.RowCount-1]:=trim(format('%8.2f',[dm.commquery.Fieldbyname('inprice').AsFloat]));
    listgrid.RowCount :=listgrid.RowCount +1;
    listgrid.Col:=5;
    listgrid.Row:=listgrid.RowCount-2;
    listgrid.SetFocus ;
    currentcursor(listgrid.RowCount-1);
    end
    else
    messagedlg('没有该种商品',mtWarning,[mbok],0);
    except
    messagedlg('输入了非法字符!',mtWarning,[mbok],0);
    end;
    end;
    end;
    下面是用query+dbgird做得:
    procedure Tfrmoutgoods.goodsidKeyPress(Sender: TObject; var Key: Char);
    begin
    if key=#13 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']:=0;
    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:=0;
    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='+#39+trim(storname.Text)+#39);
    dm.commquery.Open;
    if dm.commquery.Eof then
    begin
    messagedlg('该商品没有库存!',mtWarning,[mbok],0);
    flage:=2;
    end
    else
    begin
    if dm.commquery.FieldValues['storecount']<sender.Value then
    begin
    messagedlg('该商品库存不足!',mtWarning,[mbok],0);
    flage:=1;
    end;
    end;
    dm.commquery.Close ;
    case flage of
    0: tempquery.FieldValues['flage']:=0;
    1: tempquery.FieldValues['flage']:=1;
    2: tempquery.FieldValues['flage']:=2;
    end;
    end
    else
    begin
    application.MessageBox('请选择出货仓库。','提示',mb_ok);
    end;
    end;
    用query+dbgrid需要一个临时表来做。
  • 相关阅读:
    OpenGL 混合功能
    Android之Project、Module的区别
    Android之基于监听的事件处理机制
    Android之布局
    You may experience an access violation when you access an STL object through a pointer or reference in a different DLL or EXE
    导出类成员里含有stl对象
    从html代码里提取字符编码
    libcurl-7.54.1附加zlib1.2.11的编译
    libcurl同时下载多个文件
    在内存中运行可执行程序(转)
  • 原文地址:https://www.cnblogs.com/jijm123/p/10502232.html
Copyright © 2011-2022 走看看