基于指纹考勤机的真实的PHP操作Access数据库成功案例(最终实现) 2011-11-2v
听了我的建议,我们单位的食堂准备使用一台指纹考勤机统计吃饭人次,这样院里好给食堂的承包人以相应饭补。以前买过一台彩屏指纹机,数据库是access的,今儿又买了一台准备放到食堂里,而且考虑到停电,还特地配备了电池盒。
    这台不是彩屏的,但更加灵敏,反应速度比原来买的那台快,而且快不少。看看参数把:
    但有一样,使用U盘下载考勤数据时,是加密的.txt文档,用他们公司的软件才能把数据导入为Access表中。当然也可以自己弄.txt到.mdb的过程,但极为痛苦,极度难受,还很耗时。对于本周就上线运行的食堂管理系统而言,这是显然不合适的。
    但是是可以实现的,这里是ocx,说下实现思路:
    首先只能使用IE浏览器,通过调用ocx实现相关功能,就和一卡通里的IC卡模块一样。接着实例化一个类,使用GetGeneralLogData()方法获取记录,麻烦的就在这了,得到的结果不是想当然的数组或是比较容易处理的类型。这块很耗时。
    可以看一下函数的原型:
- long GetGeneralLogData(long *apnEnrollNumber, long *apnVerifyMode,long *apnInOutMode, DATA *apnDateTime)
    执行成功返回1,失败返回对应的错误代码。要先用LoadGeneralLogData或USBLoadDataFromFile指令,不然该指令会执行失败。
    不多说了,附件里是ocx,呵呵,有兴趣的自己研究去吧。这个思路都是浮云,在规定的时间里完不成的。涉及到调试ocx插件等等潜在问题,而且不是一个OCX或DLL的FKAttend就能搞定。我的方案是,使用他们给的工具导成mdb文档,再导入到我这个一卡通的大数据库里,这样所有记录都能得到妥善保存。而且领导也能一个页面,足不出户,查看到食堂消费情况。
    所以要通过PHP,读取mdb并写入mysql。
    这次用的不是ThinkPHP,而是叫做DoitPHP的框架,也是头一次使用,还以为比TP好用,看官网说数据处理特别快,但是不太容易掌握,总体还是略显青涩。
    这是MDB文件上传模块:
- //数据库文件上传
- 
    public function uploadAction(){
- 
        //保存目录检测
- 
        $dirurl = MDBDIR;
- 
        $dir = $this->instance('file_list');
- 
        $dir->make_dir($dirurl);
- 
        $fileupload = $this->instance('file_upload');
- 
        $new_file = $dirurl.MDBFILE;
- 
        $result = $fileupload->upload($_FILES['upload'], $new_file);
- 
        if(!$result){
- 
            $this->assign('msg','文件上传失败!');
- 
            $this->saveAction();
- 
        }
- 
        if(!$this->inputDBAction()){
- 
            $this->assign('msg','文件导入数据库失败!');
- 
        }else{
- 
            $this->assign('msg',"文件已成功导入至数据库,请您在)."' >这里查询记录!");
- 
        }
- 
        
- 
        $this->set_layout('usual');
- 
        $this->assign('load_js_name','canteen');
- 
        
- 
        //display page
- 
        $this->display('save');
- }
- //access数据库信息导入
- 
    public function inputDBAction(){
- 
        if(file_exists(MDBDIR.MDBFILE)){
- 
            $access = $this->module('access');
- //注意mdb是有密码,但没有用户名
- 
            $access->connect(MDBDIR.MDBFILE, '','2002', '', 0);
- 
            $execarr = array();
- 
            $result = $access->query("select * from ".mb_convert_encoding("考勤流水表", "GBK", "UTF-8")." where Used = No");
- 
            while($arr = $access->fetch_array($result))
- 
            {
- 
                $execarr[] = $arr;
- 
            }
- 
            //现在写入数据库
- 
             $att = $this->model('att_attendance');
- 
             $flag = TRUE;
- 
             foreach($execarr as $value){
- 
                 $data = $att->createRow();
- 
                 $data->userid = trim($value['UserID']);
-                  $data->flowtime = strtr(trim($value['FlowTime']),'/','-');
-                  $result = $att->save($data);
-                  if($result < 0){$flag = FALSE;break;}
- 
             }
- 
            return $flag;
- 
        }
- }
- public function queryAction(){
- 
        //权限验证
- 
        $checkauth = $this->module('Checkauth');
- 
        $checkauth->checkAuth(CANTEEN);
- 
        //设定日期
- 
        if(!isset($_POST['start']) && !isset($_POST['end'])){
- 
            //默认返回最近1周的记录
- 
            $now = getdate();
- //********根据今天来确定本周的日期,开始************
- 
            if($now['wday']==0)$foo = -7;
- 
            else $foo = 1-$now['wday'];
- 
            $start = $now['year'].'-'.$now['mon'].'-'.($now['mday']+$foo);
- 
            if($now['wday']==0)$foo = 0;
- 
            else $foo = 7-$now['wday'];
- 
            $end = $now['year'].'-'.$now['mon'].'-'.($now['mday']+$foo);
- //********根据今天来确定本周的日期,结束************
- 
            $result = $this->model('att_attendance');
- 
            //求出分组统计
- 
            $att = $result->execute("select
 att_attendance.userid,att_member.name,count(att_attendance.userid) as 
total from att_attendance,att_member WHERE att_attendance.userid = 
att_member.userid  GROUP BY userid");
- 
            //求得总数,使用Mysql嵌套查询
- 
            $sum = $result->execute("select
 sum(total)  from (select 
att_attendance.userid,att_member.name,count(att_attendance.userid) as 
total from att_attendance,att_member WHERE att_attendance.userid = 
att_member.userid  GROUP BY userid) as sum");
- 
            //在这里继续,显示出分组结果和总数结果,只是还没有把时间增加进去
- 
        }else{
- 
            //对提交上来的start和end作出新的查询
- 
        }
- 
        $this->set_layout('usual');
- 
        $this->assign('load_js_name','canteen');
- 
        exit();
- 
        //display page
- 
        $this->display();
- }
    当然这里还用了一个access的PHP类,大家可以到我的这篇文章去看:
    五岳之巅原创,转载请注明出处。谢谢。
 
                     
                    
                 
                    
                 


 FKAttend.zip
 FKAttend.zip 




 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号