| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 572 人关注过本帖
标题:[转载]编写个人Internet上网计费软件
只看楼主 加入收藏
云中雾
Rank: 1
等 级:新手上路
威 望:1
帖 子:168
专家分:3
注 册:2005-12-30
收藏
 问题点数:0 回复次数:0 
[转载]编写个人Internet上网计费软件
---- 随着Internet的日益普及,到Internet网上冲浪的人是越来越
多了,对于手头并不是很宽裕的网民特别是在家里上网的网民来
说,如果能及时知道自己上网已经花了多少钱,那么,每次到ISP那
缴纳费用时,至少可以做到心中有数。下面介绍一种非常方便的方
法,根据这个方法的原理,用VB、Delphi之类的软件很容易很快编
写出一个不错的个人Internet上网计费软件。

---- 工作原理

---- 现在一般个人上网,都是运行Windows 95/98平台,采用Modem
拨号上网方式,在Windows 95/98中,配置“拨号服务器”时,拨号
服务器有一个属性,就是是否记录日志文件,其默认值是“否”。
对于它,平常我们可能都没太注意。我们把它改成“是”,这样,
在每次上网后,Windows 95就会在其安装目录下(通常就是C盘的
Windows目录),把上网连通的时间以及上网过程中发生的事件记录
在ppplog.txt日志文件中。

---- ppplog.txt是一个标准的文本文件,在此文件中,上网发生的每
个事件记录占有一行,格式为:

日期 时间 发生的事件
|---------|-----------|-|---------------------|
12-19-1998 21:54:31.25
- Microsoft 拨号网络适配器日志已打开。
12-19-1998 21:54:31.25
- 服务器类型是 PPP (点到点协议)。
.
.
.
12-19-1998 22:44:49.08
- Microsoft 拨号网络适配器日志已关闭。
---- 上述内容是简体中文Windows 98的ppplog.txt文件格式,对于
Windows 95,基本格式是一样的,只是事件部分是英文的。

日期 时间 发生的事件
|---------|-----------|-|---------------------|
12-15-1998 16:34:27.71
- Remote access driver log opened.
12-15-1998 16:34:27.71
- Installable CP VxD SPAP is loaded
12-15-1998 16:34:27.71
- Server type is PPP (Point to Point Protocol).
.
.
.
12-15-1998 16:58:30.05
- Remote access driver log closed.
---- 对应于一次正常的上网过程,Windows 95/98必定会在ppplog.
txt文件中记录下包括什么时候日志文件已打开以及什么时候日志文
件已关闭的完整过程,这样,我们每次上网后读取ppplog.txt文
件,把含有“日志已打开”字符串的事件记录的时间作为我们计时
的起点,读取日期、时间,把含有“日志已关闭”字符串的事件记录
的时间作为我们计时的结束(对于Windows 95,字符串分别取”log
opened”和”log closed”),读取日期、时间,算出其时间差,
以该时间差作为时长,按照市话费每三分钟算一次,每次0.24元,
Internet费,每一分钟算一次,每次0.10元(我们这的收费标准),便
可以算出每次的花费费用了。我们可以把每次计算的结果保存在一
个数据库中,那么就可以随时查询自己的花费情况了。

---- 具体实现

---- 下面是我的具体实现过程,程序用Delphi编程实现。

---- 1、配置拨号服务器以便记录日志文件

---- 1.1、从任务栏上选取“开始”-〉“设置”-〉“控制面
板”。

---- 1.2、点击“网络”图标,出现网络配置对话框。

---- 1.3、在网络组件中选择“拨号服务器”,按“属性”按钮,
出现“拨号服务器”属性对话框。

---- 1. 4、选择其“高级”选项,然后选择“记录日志文件”项,
在其右边的设置值中选择 “是”。按“确定”按钮,接着系统提示
需要重新启动机器,重新启动后,设置就起作用了,以后每次上
网,都会把上网时间记录在日志文件ppplog.txt文件中。

---- 2、 建立一数据库internet.db

---- 数据库用来保存每次的计费数据,方便查询。

---- 利用Delphi软件包中的DataBase DeskTop程序建立

---- 数据库中包含有下列字段:

字段名 类型 说明
Begindate Date 起始日期
Begintime Time 起始时间
Enddate Date 结束日期
Endtime Time 结束时间
Timelen Number 时长
TelCost Currency 电话费用
Ispcost Currency Internet费用
---- 3、从日志文件ppplog.txt文件中读取数据

---- 为了避免重复读取数据,可以每次从ppplog.txt文件中读完数
据后,把ppplog.txt中的内容复制到ppplog.bak文件中,以便想查
看日志文件时可以查看,然后,把ppplog.txt文件置空。读取的数
据存放到数据库中。具体程序如下:

procedure TForm1.readlogExecute(Sender: TObject);
var
logfile: TextFile;
logbak: TextFile;
Str1: string;
datestr,timestr:string;
begin
AssignFile(logbak,'c:\windows\ppplog.bak');
if not FileExists('c:\windows\ppplog.bak') then
Rewrite(logbak)
else
Append(logbak);
if not FileExists('c:\windows\ppplog.txt') then
MessageDlg('日志文件不存在',
mtInformation,[mbOk],0)
else
begin
AssignFile(logfile, 'c:\windows\ppplog.txt');
Reset(logfile);
if Eof(logfile) then
begin
ShowMessage('日志文件已为空');
Exit;
end;
Table1.Open;
while not Eof(logfile) do
begin
Readln(logfile, Str1);
{‘log opened’作为计时的起点}
if Pos('log opened',Str1)< >0 then
begin
datestr:=copy(str1,1,10);
timestr:=copy(str1,12,8);
Table1.Append;
Table1.FieldValues['begindate']
:= StrToDate(datestr);
Table1.FieldValues['begintime']
:= StrToTime(timestr);
Table1.Post;
end;
{‘log closed’作为计时的结束}
if Pos('log closed',str1)< >0 then
begin
datestr:=copy(str1,1,10);
timestr:=copy(str1,12,8);
table1.Last;
table1.Edit;
Table1.FieldValues['enddate']
:= StrToDate(datestr);
Table1.FieldValues['endtime']
:= StrToTime(timestr);
Table1.Post;
end;
Writeln(logbak,str1);
end;
Table1.close;
Rewrite(logfile);
CloseFile(logfile);
CloseFile(logbak);
end;
end;
---- 4、计算费用的过程

---- 在该过程中,对于Internet计费的半价问题(市话没有半
价),只考虑到了晚上九点以后早上七点以前,对于节假日、星期
六、星期天没有考虑,有兴趣的朋友可自我完善此程序。

procedure TForm1.calcostExecute(Sender: TObject);
var
Year, Month, Day, Hour,
Min, Sec, MSec: Word;
Year1, Month1, Day1, Hour1,
Min1, Sec1, MSec1: Word;
tlen : integer;
tcost : Real;
begin
Table1.open;
while not Table1.Eof do
begin
{计算时长,以分钟为单位}
if Table1Enddate.IsNull then
tlen:=1
else
begin
DecodeDate(Table1.FieldValues
['begindate'],year,month,day);
DecodeDate(Table1.FieldValues
['enddate'],year1,month1,day1);
DecodeTime(Table1.FieldValues
['begintime'],hour,min,sec,msec);
DecodeTime(Table1.FieldValues
['endtime'],hour1,min1,sec1,msec1);
tlen:=((((((day1-day)*24+hour1)
-hour)*60+min1)-min)*60+sec1)-sec;
end;
if (tlen mod 60) > 0 then
tlen:=tlen div 60 +1
else
tlen := tlen div 60;
Table1.edit;
Table1.FieldValues['timelen'] := tlen;
{市话三分钟算一次}
if (tlen mod 3) > 0 then
tcost := (tlen div 3 + 1)*0.24
else
tcost := (tlen div 3)*0.24;
Table1.FieldValues['telcost'] := tcost;
if (hour >=21) or (hour< =7) then
Table1.FieldValues['ispcost'] := tlen*0.05
else
Table1.FieldValues['ispcost'] := tlen*0.1;
Table1.Next ;
end;
DbGrid1.Visible := True;
end;
搜索更多相关主题的帖子: 软件 Internet 计费 编写 上网 
2006-05-28 14:58
快速回复:[转载]编写个人Internet上网计费软件
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018673 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved