?? thwhunt.pas
字號:
unit thwhunt;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ComCtrls, Grids, DBGridEh, StdCtrls, Buttons, ExtCtrls,
BaseGrid, AdvGrid;
type
Tthwhfrm = class(TForm)
BitBtn1: TBitBtn;
BitBtn3: TBitBtn;
GroupBox1: TGroupBox;
GroupBox4: TGroupBox;
Label1: TLabel;
Edit3: TEdit;
BitBtn2: TBitBtn;
AdvStringGrid1: TAdvStringGrid;
AdvStringGrid2: TAdvStringGrid;
Timer1: TTimer;
procedure BitBtn5Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormActivate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
thwhfrm: Tthwhfrm;
implementation
uses data;
{$R *.dfm}
procedure Tthwhfrm.BitBtn5Click(Sender: TObject);
var
m:integer;
begin
if edit3.Text='' then exit;
with dataman.dbxQuery do
begin
close;
sql.Clear;
sql.Add('select 貨物條形碼,單價,數量,金額,退貨原因 from withdraw where 退貨單據號='''+edit3.text+'''');
sql.Add('order by 貨物條形碼 DESC');
prepared;
open;
end;
if dataman.dbxQuery.IsEmpty then
showmessage('沒有單據號為'+trim(edit3.Text)+'的單據')
else
begin
m:=1;
dataman.dbxquery.first;
while not dataman.dbxquery.eof do
begin
advstringgrid1.cells[1,m]:=dataman.dbxquery.fields[0].value;
advstringgrid1.cells[2,m]:=dataman.dbxquery.fields[1].asstring;
advstringgrid1.cells[3,m]:=dataman.dbxquery.fields[2].asstring;
advstringgrid1.cells[4,m]:=dataman.dbxquery.fields[3].asstring;
if dataman.dbxQuery.Fields[4].Value=null then
advstringgrid1.cells[5,m]:=''
else
advstringgrid1.cells[5,m]:=dataman.dbxquery.fields[4].value;
advstringgrid2.cells[0,m]:=dataman.dbxquery.fields[2].asstring;
dataman.dbxquery.next;
inc(m);
end;
end;
end;
procedure Tthwhfrm.BitBtn3Click(Sender: TObject);
begin
close;
end;
procedure Tthwhfrm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
inherited;
thwhfrm:=nil;
thwhfrm.Free;
end;
procedure Tthwhfrm.FormActivate(Sender: TObject);
var
n:integer;
begin
for n:=1 to 8 do
advstringgrid1.Cells[0,n]:=inttostr(n);
advstringgrid1.Cells[1,0]:='貨物條形碼';
advstringgrid1.Cells[2,0]:='單價';
advstringgrid1.Cells[3,0]:='數量';
advstringgrid1.Cells[4,0]:='金額';
advstringgrid1.Cells[5,0]:='退貨原因';
edit3.Text:='';
end;
procedure Tthwhfrm.BitBtn1Click(Sender: TObject);
var
l,qualityt:integer;
totalt:real;
begin
timer1.Enabled:=false;
qualityt:=0;
totalt:=0;
try
if messagedlg('確定要修改此條記錄?',mtwarning,[mbyes,mbno],0)=mryes then
begin
dataman.ADOCon.BeginTrans;
//更新退貨單據表
for l:=1 to 5 do
begin
if trim(advstringgrid1.Cells[1,l])='' then break;
qualityt:=strtoint(advstringgrid1.cells[3,l])+qualityt;
totalt:=strtoint(advstringgrid1.Cells[4,l])+totalt;
end;
with dataman.thQuery do
begin
close;
sql.Clear;
sql.Add('update withdrawm');
sql.Add('set 退貨數量=:wgno,退貨金額=:tje');
sql.Add('where 退貨單據號='''+edit3.Text+'''');
parameters.ParamByName('wgno').Value:=qualityt;
parameters.ParamByName('tje').Value:=totalt;
prepared;
execsql;
//修改退貨明細表
close;
sql.Clear;
for l:=1 to 5 do
begin
if trim(advstringgrid1.Cells[1,l])='' then break;
sql.Add('update withdraw');
sql.add('set 單價=:dj,數量=:qu,金額=:total');
sql.Add('where 退貨單據號='''+trim(edit3.Text)+''' and 貨物條形碼='''+trim(advstringgrid1.Cells[1,l])+'''');
parameters.ParamByName('dj').Value:=strtofloat(trim(advstringgrid1.cells[2,l]));
parameters.ParamByName('qu').Value:=strtoint(trim(advstringgrid1.Cells[3,l]));
parameters.ParamByName('total').Value:=strtofloat(trim(advstringgrid1.Cells[4,l]));
execsql;
end;
//修改庫存
close;
sql.Clear;
for l:=1 to 5 do
begin
if trim(advstringgrid1.Cells[1,l])='' then break;
sql.Add('update kc set 庫存數量=庫存數量+:thno where 貨物條形碼='''+trim(advstringgrid1.Cells[1,l])+'''');
parameters.ParamByName('thno').Value:=strtoint(advstringgrid1.Cells[3,l])-strtoint(advstringgrid2.Cells[0,l]);
execsql;
end;
end;
dataman.ADOCon.CommitTrans;
showmessage('存盤成功!');
end;
except
dataman.ADOCon.RollbackTrans;
messagedlg('對不起!失敗了!',mtconfirmation,[mbok],0);
end;
end;
procedure Tthwhfrm.Timer1Timer(Sender: TObject);
var
m:integer;
begin
for m:=1 to 8 do
begin
if advstringgrid1.Cells[1,m]='' then break;
advstringgrid1.Cells[4,m]:=floattostr(strtoint(advstringgrid1.Cells[2,m])*strtofloatdef(advstringgrid1.Cells[3,m],0));
end;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -