?? itear.pas
字號:
unit ITear;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Unitmb, StdCtrls, Grids, DBGridEh, Buttons, ComCtrls, ExtCtrls,
ToolWin, ImgList, Menus,adodb, FR_Ctrls,db, Mask, DBCtrls, dbcgrids,
DBCtrlsEh;
type
TITearForm = class(TmbForm)
Label1: TLabel;
edtQty: TEdit;
edtOutStore: TfrComboEdit;
procedure edtOutStoreButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure cmdEditClick(Sender: TObject);
procedure cmdSaveClick(Sender: TObject);
procedure edtNameButtonClick(Sender: TObject);
private
{ Private declarations }
nMQty,nMOldQty:real;
nMGoodsId,nMOldGoodsId:integer;
procedure InitInfo;override;
procedure InsertDetail;override;
procedure InsertMaster(sInvono:string);override;
procedure UpdateMaster;override;
procedure ShowMasterSpecial(bAdd:boolean);override;
public
{ Public declarations }
end;
var
ITearForm: TITearForm;
implementation
uses datamodule1, selPaytype;
{$R *.dfm}
procedure TITearForm.InitInfo;
begin
inherited;
nStoreId:=-1;
nCusId:=100;
nMGoodsId:=-1;
nOutStoreId:=-1;
end;
procedure TITearForm.InsertDetail;
var
sSql:string;
begin
with dataE2 do
begin
sSql:='( :billid, :itemno, :goodsid, :units, :qty, :price, :disc, :memo1)';
adoCmd.commandtext:='insert into '+myTable+'D values '+sSql;
adoCmd.parameters[0].value:=nBillId;
adoCmd.parameters[1].value:=queryDetail.fieldbyname('itemno').asinteger;
adoCmd.parameters[2].value:=nGoodsId;
adoCmd.parameters[3].value:=queryDetail.fieldbyname('units').asstring;
adoCmd.parameters[4].value:=nQty;
adoCmd.parameters[5].value:=queryDetail.fieldbyname('price').ascurrency;
adoCmd.parameters[6].value:=queryDetail.fieldbyname('disc').AsBoolean;;
adoCmd.parameters[7].value:=queryDetail.fieldbyname('memo1').asstring;
adoCmd.execute;
end;
end;
procedure TITearForm.InsertMaster(sInvoNo:string);
begin
with dataE2 do
InsertIBuildTear(bNew,nBillid,nStoreid,nOutStoreId,nEmployid,nMGoodsId,edtBillDate.date,edtInvoNo.text,edtmemo.text,myTable,strToFloat(edtQty.text),0);
end;
procedure TITearForm.UpdateMaster;
var
sSql:string;
i:integer;
begin
sMasterMemo:=trim(edtMemo.text);
nMQty:=StrToFloat(edtQty.text);
//dynamic sql sentence
i:=0;
with dataE2 do
begin
adoCmd.CommandText:='update '+mytable+' set ';
if nEmployId <> nOldEmployId then
begin
adoCmd.CommandText :=adoCmd.CommandText +' Employid= :employid ';
adoCmd.Parameters[i].value:=nEmployId;
inc(i);
end;
if nMGoodsId <> nMOldGoodsId then
begin
if i >0 then adoCmd.CommandText :=adoCmd.CommandText +',';
adoCmd.CommandText :=adoCmd.CommandText +' GoodsId= :goodsid ';
adoCmd.Parameters[i].value:=nMGoodsId;
inc(i);
end;
if nMQty <> nMOldQty then
begin
if i >0 then adoCmd.CommandText :=adoCmd.CommandText +',';
adoCmd.CommandText :=adoCmd.CommandText +' qty= :qty ';
adoCmd.Parameters[i].value:=nMQty;
inc(i);
end;
if nOldStoreId <> nStoreid then
begin
if i >0 then adoCmd.CommandText :=adoCmd.CommandText +',';
adoCmd.CommandText :=adoCmd.CommandText +' inStoreid= :instroeId ';
adoCmd.Parameters[i].value:=nStoreId;
inc(i);
end;
if nOldOutStoreId <> nOutStoreid then
begin
if i >0 then adoCmd.CommandText :=adoCmd.CommandText +',';
adoCmd.CommandText :=adoCmd.CommandText +' OutStoreid= :outstroeId ';
adoCmd.Parameters[i].value:=nOutStoreId;
inc(i);
end;
if sMasterMemo <> sOldMasterMemo then
begin
if i >0 then adoCmd.CommandText :=adoCmd.CommandText +',';
adoCmd.CommandText :=adoCmd.CommandText +' Memo= :Memo ';
adoCmd.Parameters[i].value:=sMastermemo;
inc(i);
end;
if i>0 then
begin
adoCmd.CommandText :=adoCmd.CommandText +' where BillId= :Billid ';
adoCmd.parameters[i].value:=nBillid;
adoCmd.Execute ;
end;
end; //dataE2
end;
procedure TITearForm.edtOutStoreButtonClick(Sender: TObject);
begin
inherited;
dlgselPayType.Newsql:='select storeid as id,name from store ';
dlgSelpaytype.Top :=self.top+(sender as TComboBox).Top +81;//toolbar1.height+edtInstore.Height+20 ;
dlgSelpaytype.Left :=self.Left+(sender as TComboBox).left+4 ;
if dlgselPayType.showmodal=mrok then
with dataE2 do
begin
(sender as TComboBox).Text :=dlgselPayType.xName;
nOutStoreId:=dlgSelPaytype.xid;
end;
end;
procedure TITearForm.FormCreate(Sender: TObject);
begin
inherited;
if nTableid=24 then
begin
LblFormName.Caption :='貨品組裝';
caption:=lblFormName.caption;
lblName.caption:='組裝貨品';
lblOther.caption:='組裝數量';
end;
end;
procedure TITearForm.ShowMasterSpecial(bAdd:boolean);
var
s,sSql:string;
begin
with DataE2 do
if not bAdd then
begin
nStoreId:=adoquery1.fieldbyname('instoreId').asinteger;
nOutStoreId:=adoquery1.fieldbyname('OutstoreId').asinteger;
nEmployId:=adoquery1.fieldbyname('EmployId').asinteger;
nMGoodsId:=adoquery1.fieldbyname('goodsId').asinteger;
nMQty:=adoquery1.fieldbyname('qty').asfloat;
sMasterMemo:=trim(adoquery1.fieldbyname('Memo').asstring);
edtqty.Text :=FloatTostr(nMqty);
s:='';
if tblStore.Locate('storeid',nstoreId,[loPartialKey])
then s:=tblStore.fieldbyname('name').asstring;
edtStore.text:=s;
s:='';
if tblStore.Locate('storeid',nOutstoreId,[loPartialKey])
then s:=tblStore.fieldbyname('name').asstring;
edtOutStore.text:=s;
s:='';
if OpenTable('select * from employ where EmployId= :employid',nEmployid) then
s:=adoquery1.fieldbyname('name').asstring;
edtEmp.text:=s;
adoQuery1.close;
s:='';
if OpenTable('select * from goods where goodsId= :Goodsid',nMGoodsId) then
s:=adoquery1.fieldbyname('name').asstring;
edtName.text:=s;
adoQuery1.close;
end
else begin //add emptye record,so clear last infomation
edtStore.Text:='';
edtOutStore.Text:='';
//edtEmp.Text:='';
edtQty.Text :='1';
s:='';
nEmployId:=1;
if OpenTable('select * from employ where EmployId= :employid',nEmployid) then
s:=adoquery1.fieldbyname('name').asstring;
edtEmp.text:=s;
adoQuery1.Close;
end;
end;
procedure TITearForm.cmdEditClick(Sender: TObject);
begin
inherited;
nMOldQty:=nMQty;
end;
procedure TITearForm.cmdSaveClick(Sender: TObject);
begin
if (nMGoodsId< 0 ) then
begin
application.MessageBox('請選擇拆卸貨品 ','錯誤',MB_OK+MB_ICONERROR);
exit;
end;
if (nOutStoreId< 0 ) then
begin
application.MessageBox('請選擇領料倉庫 ','錯誤',MB_OK+MB_ICONERROR);
exit;
end;
inherited;
end;
procedure TITearForm.edtNameButtonClick(Sender: TObject);
var
sTmp:string;
begin
inherited;
nMGoodsId:=nCusId;
//配料單有此分拆物品,取出該配料單;且未錄入物品
try
nMQty:=StrToFloat(edtQty.text);
except
nMQty:=1;
end;
with dataE2 do
if queryDetail.eof then
begin
sTmp:= 'select o.*,g.name,g.code,g.inprice from d_Material m,d_MaterialD o,goods g';
sTmp:=sTmp+' where m.GoodsId= :goodsId and m.BillId =o.Billid and o.goodsid=g.goodsid ';
adoQuery1.close;
adoQuery1.sql.clear;
adoQuery1.sql.add(sTmp);
adoQuery1.parameters[0].value:=nMGoodsId;
adoQuery1.open;
while not adoquery1.eof do
begin
queryDetail.append;
queryDetail.fieldbyname('GoodsId').asinteger:=adoQuery1.fieldbyname('GoodsId').asinteger;
queryDetail.fieldbyname('code').asstring:=adoQuery1.fieldbyname('code').asstring;
queryDetail.fieldbyname('name').asstring:=adoQuery1.fieldbyname('Name').asstring;
queryDetail.fieldbyname('qty').asfloat:=adoQuery1.fieldbyname('qty').asfloat*nMQty;
queryDetail.fieldbyname('Price').ascurrency:=adoQuery1.fieldbyname('inPrice').ascurrency;
queryDetail.fieldbyname('units').asstring:=adoQuery1.fieldbyname('units').asstring;
queryDetail.fieldbyname('disc').AsBoolean:=adoQuery1.fieldbyname('disc').AsBoolean;
adoQuery1.next;
end;
adoQuery1.close;
//無此語句時,刪除最后一行無反映,標志是文件尾
queryDetail.First ;
end;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -