📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls,inifiles, cxStyles, cxCustomData,
cxGraphics, cxFilter, cxData, cxEdit, DB, cxDBData,
cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGridLevel,
cxClasses, cxControls, cxGridCustomView, cxGrid, ADODB, DBTables;
type
TForm1 = class(TForm)
RICHEDIT1: TMemo;
Edit1: TEdit;
Timer1: TTimer;
Label1: TLabel;
pubqry: TADOQuery;
ADOConnection1: TADOConnection;
asd: TEdit;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
size:integer;
buf:pchar;
i,s_rec,d_rec:integer;//s_rec ini文件中的话单记录起始号
f:file;
filename,start_time,place,remark,time_long,time_num:string;//话单文件,开始时间,
tel_type:string;
test_money,total_money,jg:double;
cou:integer;
t:tinifile;//ini文件类
implementation
{$R *.dfm}
uses un_utl;
procedure TForm1.Timer1Timer(Sender: TObject);
var
po,j:integer;
s,inifilename:string;
pay_mode,regis,dep,server_no,expense_type,currency:string;
rate,discount,service:double;
work_date:string;
begin
filename:='c:\centrex\bill\'+formatdatetime('yyyymmdd',date)+'.bil';
inifilename:='c:\centrex\bill\bill.ini';
if FileExists(filename) then//存在当日话单
if fileexists(inifilename) then//存在INI文件取值S_REC
begin
TRY
T := TINIFILE.Create(INIFILENAME);
s_rec:= T.ReadINTEGER('rec',filename, -1);
FINALLY T.FREE; END;
if s_rec=-1 then s_rec:=0;
end
else//不存在创建新的INI 文件s_rec=0
TRY
T := TINIFILE.Create(INIFILENAME);
T.WriteINTEGER('rec',filename, -1);
s_rec:=0;
FINALLY T.FREE; END
else//当日话单不存在取昨日话单
begin
filename:='c:\centrex\bill\'+formatdatetime('yyyymmdd',date-1)+'.bil';
TRY
T := TINIFILE.Create(INIFILENAME);
s_rec:= T.ReadINTEGER('rec',filename, -1);
FINALLY T.FREE; END;
end;
//filename:='d:\20040416.bil';
assignfile(f,filename);//定义话单对象
reset(f,1);
try
size:=filesize(f);//话单文件长度
getmem(buf,size+1);//设置存储空间
blockread(f,buf^,size);//读取话单到缓存
buf[size]:=#0;
finally
closefile(f);
end;
d_rec:=size div 118;//d_rec为文件的记录总数
j:=s_rec;
if (s_rec<d_rec) then
begin
for i:=1 to d_rec-j do//可能有多条记录未进行处理
begin
//取出长途标志,判断是否计费
//取出应答起始时间,主叫号,被叫号,费用
//话费类型
tel_type:=INTTOhex(ord(buf[67+s_rec*118]),2);//取出通话类型
if tel_type='13' then//市话
begin
jg:=0.1;
end
else
if tel_type='23' then//网话
begin
jg:=0.05
end
else
if tel_type='33' then
begin
jg:=0.025
end
else
if tel_type='43' then
begin
jg:=0.4
end
else
begin
s_rec:=s_rec+1;
TRY
T := TINIFILE.Create(INIFILENAME);
T.WriteINTEGER('rec',filename, s_rec);
FINALLY T.FREE;
END;
continue;
end;
//起始时间
start_time:='20'+INTTOSTR_REP(ord(buf[8+s_rec*118]),2)+'-'+INTTOSTR_REP(ord(buf[9+s_rec*118]),2)+'-'+
INTTOSTR_REP(ord(buf[10+s_rec*118]),2)+' '+INTTOSTR_REP(ord(buf[11+s_rec*118]),2)+':'+
INTTOSTR_REP(ord(buf[12+s_rec*118]),2)+':'+INTTOSTR_REP(ord(buf[13+s_rec*118]),2);
// 主叫号
place:=INTTOhex(ord(buf[50+s_rec*118]),2)+INTTOhex(ord(buf[51+s_rec*118]),2)+
INTTOhex(ord(buf[52+s_rec*118]),2)+INTTOhex(ord(buf[53+s_rec*118]),2)+
INTTOhex(ord(buf[54+s_rec*118]),2);
// +INTTOhex(ord(buf[31+s_rec*118]),2)+
// INTTOhex(ord(buf[32+s_rec*118]),2)+INTTOhex(ord(buf[33+s_rec*118]),2)+
// INTTOhex(ord(buf[34+s_rec*118]),2)+INTTOhex(ord(buf[35+s_rec*118]),2);
po:=pos('F',place);
place:=copy(place,1,po-1);
if length(place)=3 then place:='0'+place;
//被叫号
remark:=inttohex(ord(buf[38+s_rec*118]),2)+inttohex(ord(buf[39+s_rec*118]),2)+
inttohex(ord(buf[40+s_rec*118]),2)+inttohex(ord(buf[41+s_rec*118]),2)+
inttohex(ord(buf[42+s_rec*118]),2)+inttohex(ord(buf[43+s_rec*118]),2)+
inttohex(ord(buf[44+s_rec*118]),2)+inttohex(ord(buf[45+s_rec*118]),2)+
inttohex(ord(buf[46+s_rec*118]),2)+inttohex(ord(buf[47+s_rec*118]),2);
po:=pos('F',remark);
remark:=copy(remark,1,po-1);
if (length(remark)=5) or (tel_type<>'13') then
begin
end
else
begin
s_rec:=s_rec+1;
TRY
T := TINIFILE.Create(INIFILENAME);
T.WriteINTEGER('rec',filename, s_rec);
FINALLY T.FREE;
END;
continue;
end;
//计费次数
s:='$'+inttohex(ord(buf[88+s_rec*118]),2)+
inttohex(ord(buf[87+s_rec*118]),2)+
inttohex(ord(buf[86+s_rec*118]),2)+
inttohex(ord(buf[85+s_rec*118]),2);
time_num:=inttostr(strtoint(s));
//时长
s:='$'+inttohex(ord(buf[23+s_rec*118]),2)+
inttohex(ord(buf[22+s_rec*118]),2)+
inttohex(ord(buf[21+s_rec*118]),2)+
inttohex(ord(buf[20+s_rec*118]),2);
time_long:=inttostr(strtoint(s));
//费用
total_money:=jg*strtoint(time_num);
test_money:=test_money+total_money;
richedit1.Lines.Add(start_time+' '+time_long+' '+place+' '+remark+' '+time_num+' '+floattostr(total_money));
richedit1.Invalidate ;
{//写入pub_total_account
pubqry.close;
pubqry.sql.clear;
pubqry.sql.add('select max(registerno) registerno from useroom where room='+''''+place+'''');
pubqry.open;
if not pubqry.eof then
begin
//取编号
regis:=pubqry.fieldbyname('registerno').asstring;
pubqry.close;
pubqry.sql.clear;
pubqry.sql.add('select cardno from register where registerno='+''''+regis+''''+' and '+'inno=0');
pubqry.open;
//取服务号
server_no:=pubqry.fieldbyname('cardno').asstring;
pubqry.close;
pubqry.sql.clear;
pubqry.sql.add('select dates from workinfo');
pubqry.open;
//取工作时间
work_date:=formatdatetime('yyyy-mm-dd hh:mm:ss',pubqry.fieldbyname('dates').asdatetime);
s:= 'insert into pub_total_account'+
' values('+''''+server_no+''''+','+''''+start_time+''''+',null,'+''''+'客房部'+''''+','+
''''+place+''''+','+''''+'电话费tel'+''''+','+''''+'RMB'+''''+','+
'1'+','+floattostr(total_money)+','+'1'+','+'0,'+''''+'记帐'+''''+','+
''''+remark+''''+','+'1,'+''''+work_date+''''+','+''''+'值'+''''+','+''''+'default'+''''+')';
pubqry.close;
pubqry.sql.clear;
pubqry.sql.add(s);
pubqry.execsql;
end;
//}
TRY
s_rec:=s_rec+1;
T := TINIFILE.Create(INIFILENAME);
T.WriteINTEGER('rec',filename, s_rec);
FINALLY T.FREE;
END;
edit1.text:=inttostr(strtoint(edit1.Text)+1);
asd.text:=floattostr(test_money);
end;//对应FOR
end;//对应IF
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
edit1.text:='0';//初始化
test_money:=0.0;//初始化
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -