📄 pos.pas
字号:
unit POS;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, DBTables, Grids, DBGrids, StdCtrls, Shellapi;
type
TForm1 = class (TForm)
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Query1: TQuery;
btndbftosql: TButton;
btntotal: TButton;
btntrans: TButton;
Query1OP: TStringField;
Query1ECR: TStringField;
Query1RESERVED: TStringField;
Query1CLERK: TStringField;
Query1SALER: TStringField;
Query1SALEDATE: TDateField;
Query1SALETIME: TStringField;
Query1SNO: TFloatField;
Query1ORGTOTAL: TFloatField;
Query1TOTAL: TFloatField;
Query1TOTALDIS: TSmallintField;
Query1OPENNUM: TFloatField;
Query1CANCELNUM: TFloatField;
Query1DISNUM: TFloatField;
Query1PAY1: TFloatField;
Query1PAY2: TFloatField;
Query1PAY3: TFloatField;
Query1PAY4: TFloatField;
Query1PAY5: TFloatField;
Query1PAY6: TFloatField;
Query1DEPT: TStringField;
Query1CODE: TStringField;
Query1NAME: TStringField;
Query1UNIT: TStringField;
Query1NUM: TFloatField;
Query1DISCOUNT: TSmallintField;
Query1PRICE: TFloatField;
Query1AMOUNT: TFloatField;
Query1SUB: TFloatField;
Query2: TQuery;
Database1: TDatabase;
Edit9: TEdit;
btncopyfile: TButton;
btnexptrade: TButton;
Query3: TQuery;
Query3op: TStringField;
Query3ecr: TStringField;
Query3reserved: TStringField;
Query3clerk: TStringField;
Query3saler: TStringField;
Query3saledate: TStringField;
Query3saletime: TStringField;
Query3sno: TStringField;
Query3orgtotal: TStringField;
Query3total: TStringField;
Query3pay1: TStringField;
Query3pay2: TStringField;
Query3pay3: TStringField;
Query3pay4: TStringField;
Query3dept: TStringField;
procedure btndbftosqlClick(Sender: TObject);
procedure btntransClick(Sender: TObject);
procedure btntotalClick(Sender: TObject);
procedure btncopyfileClick(Sender: TObject);
procedure btnexptradeClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.btndbftosqlClick(Sender: TObject);
var
tempsql: string ;
begin
//winexec('\\SERVER\posfile\POSFILE\Exptrade.exe',1);
//winexec('E:\guohua\new\Exptrade.exe',1);
query1.first;
while not query1.eof do
begin
tempsql:='insert into postab(op,ecr,clerk,saler,saledate,saletime,sno,';
tempsql:=tempsql+'orgtotal,total,pay1,pay2,pay3,pay4,dept)';
tempsql:=tempsql+' values ('''+Trim(query1['op'])+''',';
tempsql:=tempsql+''''+Trim(query1['ecr'])+''',';
tempsql:=tempsql+''''+Trim(query1['clerk'])+''',';
tempsql:=tempsql+''''+Trim(query1['saler'])+''',';
tempsql:=tempsql+''''+Trim(query1['saledate'])+''',';
tempsql:=tempsql+''''+Trim(query1['saletime'])+''',';
tempsql:=tempsql+''''+Trim(query1['sno'])+''',';
tempsql:=tempsql+''''+Trim(query1['orgtotal'])+''',';
tempsql:=tempsql+''''+Trim(query1['total'])+''',';
tempsql:=tempsql+''''+Trim(query1['pay1'])+''',';
tempsql:=tempsql+''''+Trim(query1['pay2'])+''',';
tempsql:=tempsql+''''+Trim(query1['pay3'])+''',';
tempsql:=tempsql+''''+Trim(query1['pay4'])+''',';
if query1['dept']=NULL then tempsql:=tempsql+'NULL)'
else tempsql:=tempsql+''''+Trim(query1['dept'])+''')';
Query2.Close;
Query2.Sql.Clear ;
Query2.Sql.Add(tempsql);
query2.prepare;
Query2.ExecSQL ;
query1.next;
end;
end;
procedure TForm1.btntransClick(Sender: TObject);
var
tmpsql:string;
Present: TDateTime;
Year, Month, Day: Word;
begin
present:=now;
DecodeDate(Present, Year, Month, Day);
edit9.text :='Xs000'+IntToStr(Month)+IntToStr(Day)+'.dbf';
if fileexists('Xs000'+inttostr(month)+inttostr(day)+'.dbf') then
begin
tmpsql:='select * from '+''+extractfilename(edit9.text)+''+' where op='''+trim('T')+'''';
Query1.Close;
Query1.Sql.Clear ;
Query1.Sql.Add(tmpsql);
query1.prepare;
Query1.open ;
end
else
showmessage('no file found!');
end;
procedure TForm1.btntotalClick(Sender: TObject);
var
Present: TDateTime;
Year, Month, Day: Word;
totalsum : real;
totalcash : real;
totalbill : real;
totalcard : real;
totaloth : real;
tempstr,tempsql,tmpsql,tmpstr,sdate : string ;
Queryecr,Queryclerk,Query9:TQuery;
begin
Queryecr:=TQuery.Create(self);
Queryclerk:=TQuery.Create(Self);
Query9:=TQuery.Create(Self);
Queryecr.DatabaseName:='E:\guohua\new\';
Queryclerk.DatabaseName:='E:\guohua\new\';
Query9.DatabaseName:='E:\guohua\new\';
totalsum:=0;
totalcash:=0;
totalbill:=0;
totalcard:=0;
totaloth:=0;
tempsql:='select distinct ecr from '+''+extractfilename(edit9.text)+''+' where op='''+trim('T')+'''';
//showmessage(tempsql);
queryecr.Close;
queryecr.SQL.Clear;
queryecr.SQL.Add(tempsql);
queryecr.Prepare;
queryecr.Open;
while not queryecr.Eof do
begin
tempstr:='select distinct clerk from '+''+extractfilename(edit9.text)+''+' where op='''+trim('T')+''' and ecr='''+trim(queryecr['ecr'])+'''';
//showmessage(tempstr);
queryclerk.Close;
queryclerk.SQL.Clear;
queryclerk.SQL.Add(tempstr);
queryclerk.Prepare;
queryclerk.Open;
while not queryclerk.Eof do
begin
tmpsql:='select * from '+''+extractfilename(edit9.text)+''+' where op='''+Trim('T')+'''';
tmpsql:=tmpsql+' and clerk='''+trim(queryclerk['clerk'])+'''';
tmpsql:=tmpsql+' and ecr='''+trim(queryecr['ecr'])+'''';
//showmessage(tmpsql);
query9.Close;
query9.SQL.Clear;
query9.SQL.Add(tmpsql);
query9.Prepare;
query9.Open;
while not query9.Eof do
begin
totalcash:=totalcash+query9['pay1'];
totalbill:=totalbill+query9['pay2'];
totalcard:=totalcard+query9['pay3'];
totaloth:=totaloth+query9['pay4'];
totalsum:=totalsum+query9['total'];
//showmessage(floattostr(totalsum));
query9.Next;
end;
{插入库}
begin
with query3 do
begin
close;
sql.Clear ;
tmpstr:='insert into jkdtab(msum,mcashsum,mbillsum,mcardsum,mothsum,ipart,cpname,dptime)';
tmpstr:=tmpstr+' values (:tsum,:cash,:bill,:card,:oth,:ppart,:pname,:ptime)';
//showmessage(tmpstr);
SQL.Add(tmpstr);
parambyname('tsum').asfloat:=totalsum;
parambyname('cash').asfloat:=totalcash;
parambyname('bill').asfloat:=totalbill;
parambyname('card').asfloat:=totalcard;
parambyname('oth').asfloat:=totaloth;
parambyname('ppart').asstring:=query1.fieldbyname('ECR').asstring;
present:=query1.fieldbyname('saledate').asdatetime;
DecodeDate(Present, Year, Month, Day);
sdate :=IntToStr(year+100)+'-'+IntToStr(Month)+'-'+IntToStr(Day);
parambyname('ptime').asdatetime:=strtodatetime(sdate);
parambyname('pname').asstring:=queryclerk.fieldbyname('clerk').asstring;
execsql;
totalsum:=0;
totalcash:=0;
totalbill:=0;
totalcard:=0;
totaloth:=0;
end;
end;
queryclerk.Next;
end;
queryecr.Next ;
end;
query9.Free;
queryclerk.Free;
queryecr.Free;
end;
procedure TForm1.btncopyfileClick(Sender: TObject);
var
OpStruc:TSHFileOpStruct;
FromBuf,ToBuf:Array[0..128] of char;
present:tdatetime;
year,month,day:word;
begin
present:=now;
DecodeDate(Present, Year, Month, Day);
if FileExists('Xs000'+inttostr(month)+inttostr(day)+'.dbf') then
showmessage('delete old files!');
DeleteFile('Trd00'+inttostr(month)+inttostr(day)+'.1');
DeleteFile('Trd00'+inttostr(month)+inttostr(day)+'.2');
FillChar(FromBuf,Sizeof(FromBuf),0);
FillChar(ToBuf,Sizeof(ToBuf),0);
StrPCopy(FromBuf,Pchar('\\server\posfile\posfile\*.*'));
StrPCopy(ToBuf,Pchar('e:\guohua\new\'));
with OpStruc do
begin
Wnd:=handle;
wFunc:=FO_COPY;
pFrom:=@FromBuf;
pTo:=@Tobuf;
fFlags:=FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION;
fAnyOperationsAborted:=False;
hNameMappings:=nil;
lpszProgressTitle:=nil;
end;
if SHFileOperation(OpStruc)=0 then
messageBox(Handle,'复制完毕。','信息',MB_OK+MB_ICONINFORMATION);
end;
procedure TForm1.btnexptradeClick(Sender: TObject);
begin
winexec('E:\pos\Exptrade.exe',1);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -