📄 xfxg.pas
字号:
unit xfxg;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, DBTables, Grids, StdCtrls, Mask,registry;
type
Txfxgform = class(TForm)
grid: TStringGrid;
Query1: TQuery;
Label1: TLabel;
hdno: TMaskEdit;
Label2: TLabel;
time: TMaskEdit;
Label3: TLabel;
czy: TMaskEdit;
Label4: TLabel;
djno: TMaskEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Label5: TLabel;
yj: TMaskEdit;
Label6: TLabel;
xf: TMaskEdit;
Label7: TLabel;
Edit1: TEdit;
s1: TStoredProc;
S2: TStoredProc;
procedure FormCreate(Sender: TObject);
procedure gridSetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: String);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Button3Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure gridKeyPress(Sender: TObject; var Key: Char);
procedure djnoExit(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure djnoEnter(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
xfxgform: Txfxgform;
implementation
uses dataproc;
{$R *.DFM}
var
acc,ls,lssex,xftime:string;
oldmoney:double;
pisxj:boolean;
code:array [0..100] of string[6] ;
zy:array [0..100] of boolean;
custype:array [0..100] of string[2];
procedure init;
var
i:integer;
begin
acc:='';
with xfxgform do
begin
hdno.text:='';
djno.text:='';
time.text:=datetimetostr(now);
czy.text:=curper.code+' '+curper.name;
yj.text:='';
xf.Text :='';
edit1.text:='0';
button1.Enabled :=false;
i:=1;
while i<=grid.RowCount do
begin
grid.Cells [2,i]:=' ';
grid.Cells [3,i]:=' ';
grid.Cells [4,i]:=' ';
i:=i+1;
end;
end
end;
procedure Txfxgform.FormCreate(Sender: TObject);
var
i:integer;
tt:Tregistry;
begin
tt:=Tregistry.Create;
tt.Rootkey:=HKEY_LOCAL_MACHINE;
if tt.openkey('system\currentcontrolset\control\computername\computername',false) then
ls:=tt.readstring('computername');
tt.free;
shortdateformat:='yyyy-mm-dd';
init;
query1.Active :=false;
query1.sql.clear;
query1.sql.add('select cusname,price,custype,cuscode,iszy from cusitem ');
query1.Prepare;
query1.Open;
query1.Active :=true;
grid.RowCount :=query1.RecordCount+1 ;
grid.Cells[0,0]:=' 消费项目 ';
grid.Cells[1,0]:=' 消费单价 ';
grid.cells[2,0]:=' 消费金额 ';
grid.cells[3,0]:=' 消费数量 ';
grid.cells[4,0]:=' 专业人员 ';
i:=1;
if query1.RecordCount >0 then
begin
query1.First ;
while not query1.EOF do
begin
grid.Cells [0,i]:=query1.fieldbyname('cusname').asstring;
grid.Cells [1,i]:=floattostr(query1.fieldbyname('price').asfloat);
code[i-1]:=query1.fieldbyname('cuscode').asstring;
custype[i-1]:=query1.fieldbyname('custype').asstring;
zy[i-1]:=query1.fieldbyname('iszy').asboolean;
i:=i+1;
query1.next;
end
end
end;
procedure Txfxgform.gridSetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: String);
var
curxf,syyj:double;
i:integer;
begin
try
//*****************************************//
if length(trim(grid.cells[3,arow]))>0 then
grid.Cells [2,arow]:=floattostr(strtofloat(grid.cells[1,arow])*strtofloat(grid.cells[3,arow]))
else
grid.Cells [2,arow]:='';
curxf:=0.00;
i:=1;
while i<=grid.rowcount do
begin
if length(trim(grid.cells[2,i]))>0 then
curxf:=curxf+strtofloat(grid.cells[2, i]);
i:=i+1;
end;
edit1.text:=floattostr(curxf);
syyj:=strtofloat(yj.text)-curxf-strtofloat(xf.text);
//syyj:=strtofloat(yj.text)-strtofloat(xf.text)-curxf;
if syyj<0 then
begin
showmessage('押金只剩'+floattostr(syyj+strtofloat(grid.cells[2,arow]))+'元');
edit1.text:=floattostr(curxf-strtofloat(grid.cells[2,arow]));
grid.cells[acol,arow]:='';
grid.cells[2,arow]:='';
end;
//*****************************************//
if ((zy[arow-1]=false) or (length(trim(grid.cells[3,arow]))=0)) then
grid.cells[4,arow]:='';
//*****************************************//
except
end;
end;
procedure Txfxgform.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=13 then
selectnext(activecontrol,true,true);
if key=27 then
close;
end;
procedure Txfxgform.Button3Click(Sender: TObject);
begin
xfxgform.close;
end;
procedure Txfxgform.Button1Click(Sender: TObject);
var
i:integer;
begin
if length(trim(djno.text))=0 then
begin
showmessage('单号不能为空');
djno.setfocus;
exit;
end;
//********************************************//
query1.Active :=false;
query1.sql.clear;
query1.sql.add('update account set custom=:pcustom where accno=:paccno');
query1.ParamByName ('pcustom').asfloat:=strtofloat(trim(xf.text))+strtofloat(trim(edit1.text));
query1.ParamByName ('paccno').asstring:=acc;
query1.Prepare;
query1.ExecSQL;
//********************************************//
query1.active:=false;
query1.sql.clear;
query1.sql.add('delete custom where djcode=:pdjcode');
query1.ParamByName ('pdjcode').asstring:=trim(djno.text);
query1.Prepare;
query1.ExecSQL;
//********************************************//
i:=1;
while i<=grid.RowCount do
begin
if length(trim(grid.cells[3,i]))>0 then
begin
query1.Active :=false;
query1.sql.clear;
query1.sql.add('insert into custom (handno,sex,accno,custype,cuscode,cusprice,cusnum,money,regtime,moditime,proid,regid,djcode)');
query1.sql.add(' values(:phandno,:psex,:paccno,:pcustype,:pcuscode,:pprice,:pnum,:pmoney,:pregtime,:pmoditime,:pproid,:pregid,:pdjcode)');
query1.ParamByName ('phandno').asstring:=trim(hdno.text);
query1.ParamByName ('psex').asstring:=lssex;
query1.ParamByName ('paccno').asstring:=acc;
query1.ParamByName ('pcustype').asstring:=custype[i-1];
query1.ParamByName ('pcuscode').asstring:=code[i-1];
query1.ParamByName ('pprice').asfloat:=strtofloat(trim(grid.cells[1,i]));
query1.ParamByName ('pnum').asfloat:=strtofloat(trim(grid.cells[3,i]));
query1.ParamByName ('pmoney').asfloat:=strtofloat(trim(grid.cells[2,i]));
query1.ParamByName ('pregtime').asdatetime:=strtodatetime(trim(xftime));
query1.ParamByName ('pmoditime').asdatetime:=strtodatetime(trim(time.text));
query1.ParamByName ('pproid').asstring:=trim(grid.cells[4,i]);
query1.ParamByName ('pregid').asstring:=copy(trim(czy.text),1,6);
query1.ParamByName ('pdjcode').asstring:=trim(djno.text);
query1.Prepare;
query1.ExecSQL;
end;
i:=i+1;
end;
showmessage('消费单修改成功');
s2.ParamByName ('@ihand').asstring:=ACC;
s2.ParamByName ('@iwdno').asstring:=ls;
s2.Prepare;
s2.ExecProc;
init;
djno.setfocus;
end;
procedure Txfxgform.Button2Click(Sender: TObject);
begin
if length(trim(hdno.text))>0 then
begin
s2.ParamByName ('@ihand').asstring:=acc;
s2.ParamByName ('@iwdno').asstring:=ls;
s2.Prepare;
s2.ExecProc;
end;
init;
djno.setfocus;
end;
procedure Txfxgform.gridKeyPress(Sender: TObject; var Key: Char);
begin
if ((key<'0') or (key>'9')) then
if key<>char(8) then
key:=char(0);
end;
procedure Txfxgform.djnoExit(Sender: TObject);
var
i:integer;
totmoney:double;
aa:array [0..1] of string;
oldczy:string;
begin
if length(trim(djno.text))>0 then
begin
query1.Active :=false;
query1.sql.clear;
query1.sql.add('select * from custom where djcode=:pdjcode');
query1.ParamByName ('pdjcode').asstring:=trim(djno.text);
query1.Prepare;
query1.open;
if query1.recordcount <=0 then
begin
showmessage('此单号不存在');
djno.setfocus;
exit;
end
else
begin
query1.first;
lssex:=query1.fieldbyname('sex').asstring;
totmoney:=0.00;
acc:=query1.fieldbyname('accno').asstring;
xftime:=query1.fieldbyname('regtime').asstring;
oldczy:=query1.fieldbyname('regid').asstring;
hdno.text:=trim(query1.fieldbyname('handno').asstring);
while not query1.eof do
begin
i:=1;
totmoney:=totmoney+query1.fieldbyname('money').asfloat;
while i<= grid.RowCount do
begin
if code[i-1]=query1.fieldbyname('cuscode').asstring then
begin
grid.Cells [2,i]:=query1.fieldbyname('money').asstring;
grid.Cells [3,i]:=query1.fieldbyname('cusnum').asstring;
grid.Cells [4,i]:=query1.fieldbyname('proid').asstring;
end;
i:=i+1
end;
query1.Next ;
end;
getvalue(aa,'select deposit,custom from account where accno="'+trim(acc)+'"');
yj.text:=aa[0];
xf.text:=floattostr(strtofloat(aa[1])-totmoney);
edit1.text:=floattostr(totmoney);
oldmoney:=totmoney;
if trim(oldczy)=copy(czy.text,1,6) then
begin
grid.Enabled :=true;
button1.Enabled :=true;
//****lock handno***********//
s1.ParamByName ('@ihand').asstring:=acc;
s1.ParamByName ('@iwdno').asstring:=ls;
s1.Prepare;
s1.ExecProc;
end
else
begin
showmessage('此消费单不能修改');
button1.Enabled :=false;
end
end;
end
else
begin
button1.Enabled :=false;
init;
end;
end;
procedure Txfxgform.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if length(trim(hdno.text))>0 then
begin
s2.ParamByName ('@ihand').asstring:=acc;
s2.ParamByName ('@iwdno').asstring:=ls;
s2.Prepare;
s2.ExecProc;
end;
query1.free;
s1.free;
s2.free;
end;
procedure Txfxgform.djnoEnter(Sender: TObject);
begin
if acc<>'' then
begin
s2.ParamByName ('@ihand').asstring:=ACC;
s2.ParamByName ('@iwdno').asstring:=ls;
s2.Prepare;
s2.ExecProc;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -