📄 ctjk.pas
字号:
unit ctjk;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, DBTables, Grids, StdCtrls,printers, DBGrids, Mask, ExtCtrls;
type
Tctjkform = class(TForm)
q1: TQuery;
Button1: TButton;
Button2: TButton;
Button3: TButton;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
pass1: TEdit;
Panel1: TPanel;
Label6: TLabel;
curbc: TEdit;
Label7: TLabel;
Label8: TLabel;
bgtime: TMaskEdit;
Label9: TLabel;
edtime: TMaskEdit;
curname: TEdit;
Label1: TLabel;
StringGrid1: TStringGrid;
Panel2: TPanel;
Regid: TEdit;
Label2: TLabel;
Label3: TLabel;
pass: TEdit;
Panel3: TPanel;
Regid1: TEdit;
Label4: TLabel;
s1: TStoredProc;
Table1: TTable;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button2Click(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
procedure StringGrid1Click(Sender: TObject);
procedure curnameDblClick(Sender: TObject);
procedure Label2DblClick(Sender: TObject);
procedure curnameKeyPress(Sender: TObject; var Key: Char);
procedure RegidKeyPress(Sender: TObject; var Key: Char);
procedure passKeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
ctjkform: Tctjkform;
implementation
uses dataproc, ctjkprint;
{$R *.DFM}
function hdq(dd:string;k:integer):string;
begin
hdq:=copy(copy(' ',1,k)+trim(dd),length(trim(dd))+1,k);
end;
procedure formini;
var
lsdate,lsdate1,lsdate2:real;
// lsdate,lscode:string;
i:integer;
// aa:array [0..1] of string;
begin
with ctjkform do
begin
// lsdate:=datetostr(date());
q1.Active :=false;
q1.sql.clear;
q1.sql.Add('select max(jkTime) from jkmx where GiveTime='''+trim(bgtime.Text)+''' and bc='''+curper.curbc+'''');
q1.Prepare;
q1.open;
if not q1.Fields[0].isnull then
Label4.Caption:='上次本班交款时间:'+q1.Fields[0].asstring
else
Label4.Caption:='本班还没有交款!';
q1.Active :=false;
q1.sql.clear;
q1.sql.Add('select avg(zsbyjxj),avg(zsbyjzp),avg(zsbyjcard),avg(zsbyjgz),avg(zsbyjmd),sum(bcjxj),sum(bcjzp),sum(bcjcard),sum(bcjgz),sum(bcjmd) from jkmx where GiveTime='''+trim(bgtime.Text)+''' and bc='''+curper.curbc+'''');
q1.Prepare;
q1.open;
lsdate1:=0;
lsdate2:=0;
for i:=2 to 6 do
begin
if not q1.fields[i-2].isnull then
lsdate:=q1.fields[i-2].asfloat
else
lsdate:=0;
if i<>6 then StringGrid1.Cells[i,0]:=hdq(floattostr(lsdate),9)
else StringGrid1.Cells[i,0]:=hdq(floattostr(lsdate),6);
lsdate1:=lsdate1+lsdate;
if not q1.fields[i+3].isnull then
lsdate:=q1.fields[i+3].asfloat
else
lsdate:=0;
if i<>6 then StringGrid1.Cells[i,1]:=hdq(floattostr(lsdate),9)
else StringGrid1.Cells[i,1]:=hdq(floattostr(lsdate),6);
lsdate2:=lsdate2+lsdate;
end;
StringGrid1.Cells[7,0]:=hdq(floattostr(lsdate1),9);
StringGrid1.Cells[7,1]:=hdq(floattostr(lsdate2),9);
{ q1.Active :=false;
q1.sql.clear;
q1.sql.Add('select * from ctjkmoney ');
q1.Prepare;
q1.open; }
table1.Open;
DBGrid1.fields[0].displaylabel:=' 名称 ';
DBGrid1.fields[1].displaylabel:=' 数量';
DBGrid1.fields[2].displaylabel:=' 现金';
DBGrid1.fields[3].displaylabel:=' 支票';
DBGrid1.fields[4].displaylabel:=' 信用卡';
DBGrid1.fields[5].displaylabel:=' 挂帐';
DBGrid1.fields[6].displaylabel:=' 免单';
// DBGrid1.fields[7].displaylabel:=' 其他';
DBGrid1.fields[7].displaylabel:=' 小计';
dbgrid1.Columns[1].width:=40;
dbgrid1.Columns[2].width:=60;
dbgrid1.Columns[3].width:=60;
dbgrid1.Columns[4].width:=60;
dbgrid1.Columns[5].width:=60;
dbgrid1.Columns[6].width:=60;
dbgrid1.Columns[7].width:=80;
dbgrid1.Columns[0].width:=80;
q1.Last;
lsdate1:=0;
for i:=2 to 6 do
begin
if not q1.fields[i].isnull then
lsdate:=q1.fields[i].asfloat+strtofloat(StringGrid1.Cells[i,0])
else
lsdate:=strtofloat(StringGrid1.Cells[i,0]);
if i<>6 then
begin
StringGrid1.Cells[i,2]:=hdq(floattostr(lsdate),9);
StringGrid1.Cells[i,3]:=hdq(floattostr(lsdate-strtofloat(StringGrid1.Cells[i,1])),9);
end
else
begin
StringGrid1.Cells[i,2]:=hdq(floattostr(lsdate),6);
StringGrid1.Cells[i,3]:=hdq(floattostr(lsdate-strtofloat(StringGrid1.Cells[i,1])),6);
end;
lsdate1:=lsdate1+lsdate;
end;
StringGrid1.Cells[7,2]:=hdq(floattostr(lsdate1),9);
StringGrid1.Cells[7,3]:=hdq(floattostr(lsdate1-strtofloat(StringGrid1.Cells[7,1])),9);
if trim(StringGrid1.Cells[7,3])='0' then
Button2.Enabled:=false
else
Button2.Enabled:=true;
end;
end;
procedure Tctjkform.FormCreate(Sender: TObject);
begin
shortdateformat:='yyyy-mm-dd';
curbc.Text:=curper.curbc;
curname.Text:=curper.name;
edtime.text:=datetimetostr(now);
if curper.curbc='早' then bgtime.text:=datetostr(now)+' 00:00';
if curper.curbc='午' then bgtime.text:=datetostr(now)+' 10:00';
if curper.curbc='晚' then bgtime.text:=datetostr(now)+' 16:00';
//****************************************************************
{ s1.Prepare;
s1.ParamByName ('@lsbegtime').asdatetime:=strtodatetime(bgtime.text);
s1.ParamByName ('@lsendtime').asdatetime:=strtodatetime(edtime.text);
s1.Prepare;
s1.ExecProc ; }
StringGrid1.Cells[0,0]:='转上班应交';
StringGrid1.Cells[0,1]:='本班已交合计';
StringGrid1.Cells[0,2]:='本次应交合计';
StringGrid1.Cells[0,3]:='本次实交合计';
// StringGrid1.SetFocus;
ctjkform.ActiveControl:=StringGrid1;
formini;
end;
procedure Tctjkform.Button1Click(Sender: TObject);
begin
// prn;
application.CreateForm(Tctjkbptform,ctjkbptform);
ctjkbptform.hide;
// ctjkbptform.qr1.print;
ctjkbptform.qr1.preview;
ctjkbptform.Close;
ctjkbptform.free;
button2.Enabled :=true;
end;
procedure Tctjkform.Button3Click(Sender: TObject);
begin
ctjkform.Close;
end;
procedure Tctjkform.FormClose(Sender: TObject; var Action: TCloseAction);
begin
q1.Close;
// q1.Free;
s1.free;
end;
procedure Tctjkform.Button2Click(Sender: TObject);
begin
Panel2.Visible:=true;
Panel3.Visible:=true;
pass.SetFocus;
pass.Text:='****';
end;
procedure Tctjkform.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=112 then
begin
if xt=0 then help(26);
end;
{ if key=13 then
selectnext(activecontrol,true,true);}
if key=27 then
if Panel2.Visible then Panel2.Visible:=false
else
ctjkform.close;
end;
procedure Tctjkform.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var lsdate:real;
i:integer;
begin
if key=13 then
begin
if trim(StringGrid1.Cells[StringGrid1.col,StringGrid1.row])='' then
StringGrid1.Cells[StringGrid1.col,StringGrid1.row]:='0';
StringGrid1.Cells[StringGrid1.col,StringGrid1.row]:=hdq(StringGrid1.Cells[StringGrid1.col,StringGrid1.row],9);
if StringGrid1.col<8 then
begin
StringGrid1.col:=StringGrid1.col+1;
StringGrid1.SetFocus;
end
else
Button1.SetFocus;
lsdate:=0;
for i:=2 to 7 do
lsdate:=lsdate+strtofloat(StringGrid1.Cells[i,StringGrid1.Row]);
if StringGrid1.Row<>7 then
StringGrid1.Cells[8,StringGrid1.Row]:=hdq(floattostr(lsdate),9)
else
StringGrid1.Cells[8,StringGrid1.Row]:=hdq(floattostr(lsdate),6);
if StringGrid1.col=8 then
begin
Button1.SetFocus;
StringGrid1.col:=2;
end;
if trim(StringGrid1.Cells[8,3])='0' then
Button2.Enabled:=false
else
Button2.Enabled:=true;
end;
end;
procedure Tctjkform.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if (key<'0') or (key>'9') then
if (key<>#13) and (key<>#8) then key:=#0;
end;
procedure Tctjkform.StringGrid1Click(Sender: TObject);
begin
if StringGrid1.col=7 then
StringGrid1.col:=2;
end;
procedure Tctjkform.curnameDblClick(Sender: TObject);
begin
Panel2.Visible:=true;
Regid.SetFocus;
Regid.Text:='';
end;
procedure Tctjkform.Label2DblClick(Sender: TObject);
begin
Panel2.Visible:=false;
StringGrid1.SetFocus;
end;
procedure Tctjkform.curnameKeyPress(Sender: TObject; var Key: Char);
begin
key:=#0;
end;
procedure Tctjkform.RegidKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then pass.SetFocus;
end;
procedure Tctjkform.passKeyPress(Sender: TObject; var Key: Char);
var
i:integer;
begin
if key=#13 then
if Panel3.Visible then
begin
fm.Query1.Active :=false;
fm.Query1.sql.clear;
fm.Query1.sql.add('select NAME from stuff where pass='''+trim(passzh(trim(pass.Text)))+''' and name='''+trim(curname.Text)+'''');
fm.Query1.Open;
if not fm.Query1.eof then
begin
Panel2.Visible:=false;
Panel3.Visible:=false;
fm.Query1.Active :=false;
fm.Query1.sql.clear;
fm.Query1.sql.add('insert into jkmx values(:pGiveTime,:pbc,:pjkregid,:p11,:p12,:p13,:p14,:p15,:p16,:p21,:p22,:p23,:p24,:p25,:p26,:pjkTime) ');
fm.Query1.ParamByName('pGiveTime').asdatetime:=strtodatetime(bgtime.text);
fm.Query1.ParamByName('pbc').asstring:=trim(copy(trim(curbc.text),12,4));
fm.Query1.ParamByName('pjkregid').asstring:=trim(Regid1.text);
for i:=1 to 6 do
begin
fm.Query1.ParamByName('p1'+inttostr(i)).asfloat:=strtofloat(StringGrid1.Cells[i+1,0]);
fm.Query1.ParamByName('p2'+inttostr(i)).asfloat:=strtofloat(StringGrid1.Cells[i+1,3]);
end;
fm.Query1.ParamByName('pjkTime').asdatetime:=strtodatetime(edtime.text);
fm.Query1.Prepare;
fm.Query1.ExecSQL ;
fm.Query1.Active :=false;
showmessage('交款成功');
ctjkform.close;
end
else
begin
fm.Query1.Active :=false;
fm.Query1.sql.clear;
showmessage('输入有误,请重新输入!');
pass.SetFocus;
pass.Text:='****';
end;
end
else
begin
fm.Query2.Active :=false;
fm.Query2.sql.clear;
fm.Query2.sql.Add('select Name from stuff where code='''+trim(Regid.Text)+''' and pass='''+passzh(trim(pass.text))+'''');
fm.Query2.Prepare;
fm.Query2.open;
if not fm.Query2.Eof then
begin
curname.text:=fm.Query2.Fields[0].asstring;
pass1.text:=passzh(trim(Pass.Text));
Regid1.text:=Regid.Text;
Panel2.Visible:=false;
StringGrid1.SetFocus;
end
else
begin
showmessage('输入有误,请重新输入!');
Regid.SetFocus;
Regid.Text:='';
end;
fm.Query2.Close;
fm.Query2.Active :=false;
fm.Query2.sql.clear;
fm.Query2.UnPrepare;
fm.query2.RequestLive:=false;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -