📄 selectgoods.pas
字号:
SQL.Add('select storeid,name from store');
SQL.Add('where name = :name');
Parameters[0].Value:=cboStore.Text;
open;
result:=FieldValues['Storeid'];
end;
end;
procedure TSelectGoodsForm.btnAddClick(Sender: TObject);
var
iRow:Integer;
begin
if DataE2.QueryTmp.Active then
iRow:=DataE2.QueryTmp.RecordCount
else iRow:=0;
if iRow>0 then
begin
qrySelGoods.Open;
qrySelGoods.Append;
qrySelGoods.FieldByName('Id').AsInteger:=GetID('Id','Goods');
qrySelGoods.FieldByName('GoodsId').AsInteger:=DataE2.QueryTmp.FieldByName('GoodsId').AsInteger;
qrySelGoods.FieldByName('code').AsString:=DataE2.QueryTmp.FieldByName('code').AsString;
qrySelGoods.FieldByName('name').AsString:=DataE2.QueryTmp.FieldByName('name').AsString;
qrySelGoods.fieldbyname('perqty').value:=DataE2.QueryTmp.fieldbyname('perqty').ascurrency;
if FStatus='I' then
begin
qrySelGoods.FieldByName('Price').AsCurrency:=DataE2.QueryTmp.FieldByName('inPrice').AsCurrency;
qrySelGoods.FieldByName('units').AsString:=DataE2.QueryTmp.FieldByName('units').AsString; end
else if FStatus='O' then
begin
if datae2.bOutUnit2 then
begin
qrySelGoods.FieldByName('units').AsString:=DataE2.QueryTmp.FieldByName('unit2').AsString;
qrySelGoods.FieldByName('price').asfloat:=datae2.GetLastSalePrice(FCusId,DataE2.QueryTmp.FieldByName('GoodsId').AsInteger,true);
//记下成本
qrySelGoods.fieldbyname('InPrice').value:=DataE2.QueryTmp.fieldbyname('inprice2').ascurrency; end
else
begin
qrySelGoods.FieldByName('units').AsString:=DataE2.QueryTmp.FieldByName('units').AsString;
qrySelGoods.FieldByName('price').asfloat:=datae2.GetLastSalePrice(FCusId,DataE2.QueryTmp.FieldByName('GoodsId').AsInteger,false);
//记下成本
qrySelGoods.fieldbyname('InPrice').value:=DataE2.QueryTmp.fieldbyname('inprice').ascurrency;
end;
end;
btnDel.Enabled:=True;
end;
end;
procedure TSelectGoodsForm.btnDelClick(Sender: TObject);
var
iRow:Integer;
begin
qrySelGoods.Refresh;
iRow:=qrySelGoods.RecordCount;
if iRow>0 then
qrySelGoods.Delete
else
btnDel.Enabled:=False;
end;
procedure TSelectGoodsForm.FormCreate(Sender: TObject);
begin
try
connectTmp.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+
ExtractFilePath(Application.ExeName)+
'GoodsTmp.mdb;Persist Security Info=False';
connectTmp.Connected:=true;
except
Application.MessageBox('连接临时数据错误!','错误提示',64);
end;
end;
procedure TSelectGoodsForm.btnOkClick(Sender: TObject);
begin
if qrySelGoods.Active then
begin
with qrySelGoods do
begin
first;
if not Eof then
begin
while not Eof do
begin
DataE2.queryDetail.Append;
DataE2.queryDetail.FieldByName('GoodsId').AsString:=FieldByName('GoodsId').AsString;
DataE2.queryDetail.FieldByName('code').AsString:=FieldByName('code').AsString;
DataE2.queryDetail.FieldByName('name').AsString:=FieldByName('name').AsString;
DataE2.queryDetail.fieldbyname('perqty').value:=fieldbyname('perqty').ascurrency;
DataE2.queryDetail.FieldByName('units').AsString:=FieldByName('units').AsString;
DataE2.queryDetail.FieldByName('qty').AsInteger:=1;
DataE2.queryDetail.FieldByName('Price').AsCurrency:=FieldByName('Price').AsCurrency;
if FStatus='O' then
if ( dataE2.gTableId=11 ) or ( dataE2.gTableId= 12 ) then
DataE2.queryDetail.fieldbyname('cost').value:=fieldbyname('inprice').ascurrency;
if datae2.bOutUnit2 and (FStatus='O') then
DataE2.queryDetail.FieldByName('disc').AsBoolean:=true
else
DataE2.queryDetail.FieldByName('disc').AsBoolean:=false;
next;
end;
end;
end;
end;
close;
end;
procedure TSelectGoodsForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
with qryTmp do
begin
close;
SQL.Clear;
SQL.Add('delete from Goods');
ExecSQL;
end;
DataE2.QueryTmp.Close;
qrySelGoods.Close;
end;
function TSelectGoodsForm.GetID(Fieldname, TableName: string): integer;
var
sSQL:string;
begin
sSQL:='select max('+FieldName+') as New_ID from '+TableName;
with qryTmp do
begin
close;
sql.clear;
sql.text:=sSQL;
open;
if FieldByName('new_ID').AsInteger=null then
result:=1
else
result:=FieldByName('new_ID').AsInteger+1;
end;
end;
procedure TSelectGoodsForm.cboStoreSelect(Sender: TObject);
var
strsql:string;
begin
// if FStatus='I' then
strsql:='select * from vInGoods ';
strsql:=strsql + ' where (storeid = :storeid or storeid=0)';
strsql:=strsql + ' order by code';
if DataE2.QueryTmp.Active then DataE2.QueryTmp.Close;
DataE2.QueryTmp.SQL.Text:=strsql;
DataE2.QueryTmp.Prepared:=true;
DataE2.QueryTmp.Parameters[0].Value:=GetStoreId;
DataE2.QueryTmp.Open;
{ else if FStatus='O' then
begin
strsql:='select * from vOutGoods ';
strsql:=strsql + ' where (storeid = :storeid or storeid=0)';
strsql:=strsql + ' and (clientid = :clientid or clientid=-1)';
strsql:=strsql + ' order by code';
with DataE2.QueryTmp do
begin
if Active then Close;
SQL.Text:=strsql;
Prepared:=true;
Parameters[0].Value:=GetStoreId;
Parameters[1].Value:=FCusId;
Open;
end;
end; }
end;
procedure TSelectGoodsForm.cboPriceSelect(Sender: TObject);
var
strsql:string;
begin
dbgGoods.Columns[7].Title.caption:=cboPrice.text;
case cboPrice.ItemIndex of
0:dbgGoods.Columns[7].FieldName:='SpePrice';
1:dbgGoods.Columns[7].FieldName:='SalePrice';
2:dbgGoods.Columns[7].FieldName:='SpePrice2';
3:dbgGoods.Columns[7].FieldName:='SalePrice2';
4:begin
strsql:='select * from vOutGoods ';
strsql:=strsql + ' where (storeid = :storeid or storeid=0)';
strsql:=strsql + ' and (clientid = :clientid)';
strsql:=strsql + ' and typeCode like :typeCode';
strsql:=strsql + ' order by code';
with DataE2.QueryTmp do
begin
if Active then Close;
SQL.Text:=strsql;
Prepared:=true;
Parameters[0].Value:=GetStoreId;
Parameters[1].Value:=FCusId;
if TreeView1.Selected <> nil then
Parameters[2].Value:=copy(TreeView1.Selected.Text,1,pos(' ',TreeView1.Selected.Text)-1)+'%'
else
Parameters[2].Value:='%';
Open;
end;
dbgGoods.Columns[7].FieldName:='CusPrice';
end;
end;
end;
procedure TSelectGoodsForm.dbgGoodsKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = VK_RETURN then
btnAdd.Click;
end;
procedure TSelectGoodsForm.DBGridEh1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = VK_DELETE then
btnDel.Click;
end;
procedure TSelectGoodsForm.FormKeyPress(Sender: TObject; var Key: Char);
begin
if key = #27 then
close;
end;
procedure TSelectGoodsForm.qrySelGoodsNewRecord(DataSet: TDataSet);
begin
qrySelGoods.FieldByName('units').AsString:='';
qrySelGoods.FieldByName('Price').AsCurrency:=0;
end;
procedure TSelectGoodsForm.dbgGoodsDblClick(Sender: TObject);
begin
btnAdd.Click;
end;
procedure TSelectGoodsForm.edtcodeChange(Sender: TObject);
var
strsql:String;
begin
strsql:='select * from vInGoods ';
strsql:=strsql + ' where (code like :code';
strsql:=strsql + ' or name like :name or barcode like :barcode)';
strsql:=strsql + ' and (storeid = :storeid or storeid=0)';
strsql:=strsql + ' order by code';
with DataE2.QueryTmp do
begin
if Active then Close;
SQL.Text:=strsql;
Prepared:=true;
Parameters[0].Value:=edtcode.Text+'%';
Parameters[1].Value:='%'+edtcode.Text+'%';
Parameters[2].Value:=edtcode.Text+'%';
Parameters[3].Value:=GetStoreId;
Open;
end;
cboPrice.ItemIndex:=0;
dbgGoods.Columns[7].FieldName:='SpePrice';
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -