| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1939 人关注过本帖
标题:求助一个按钮控件的问题!
只看楼主 加入收藏
bcly0808
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2013-3-22
结帖率:50%
收藏
 问题点数:0 回复次数:8 
求助一个按钮控件的问题!
在网上找了一个身份证信息采集代码,放到了表单的COMMAND1的Click中,现在是每点击一次COMMAND1(开始)按钮可以采集一条身份证信息,现在的想法是只点击一次COMMAND1(开始)按钮可以连续采集身份证信息,就是采集完第一位同学的身份证信息,不用点击COMMAND1(开始)按钮,可以直接可以采集第二名,第三名,第四名……N名同学的身份证信息,再添加一个COMMAND2(停止)按钮,点击一下COMMAND2(停止)按钮,停止采集,不想用计时器,请位各位高手帮助指导一下,小学生在此拜过!
程序代码:
DECLARE Integer SDT_OpenPort IN sdtapi.dll Integer iPort
DECLARE Integer SDT_ClosePort IN sdtapi.dll Integer iPort
DECLARE Integer SDT_StartFindIDCard IN sdtapi.dll Integer iPort, String @pucManaInfo, Integer iIfOpen 
DECLARE Integer SDT_SelectIDCard IN sdtapi.dll Integer iPort, String @pucManaMsg, Integer iIfOpen 
DECLARE Integer SDT_ReadBaseMsg IN sdtapi.dll Integer iPort, String @pucCHMsg, Integer @puiCHMsgLen, String @pucPHMsg, Integer @puiPHMsgLen, Integer iIfOpen
DECLARE Integer GetBmp IN WltRS.dll string wlt_file, integer intf
DECLARE Long GdipLoadImageFromFile IN Gdiplus.dll String cFile, Long @ nativeImage
DECLARE Long GdipSaveImageToFile IN Gdiplus.dll Long nativeImage, String cFile, String EncoderClsID, String EncoderParameters
DECLARE Long GdipDisposeImage IN Gdiplus.dll Long nativeImage


LOCAL iRet As Integer && 返回码 
LOCAL iPort As Integer && 端口号 
LOCAL iIfOpen As Integer && 是否需要打开端口 
LOCAL find_sta
find_sta=.t.

LOCAL pucManaInfo As String
LOCAL pucManaMsg As String
LOCAL pucCHMsg As String && 文字信息 
LOCAL pucPHMsg As String && 照片信息 
LOCAL pucFPMsg As String && 指纹信息 
LOCAL uiCHMsgLen As Integer, uiPHMsgLen As Integer

iRet = 0
pucManaInfo = SPACE(4)
pucManaMsg = SPACE(8)
pucCHMsg = SPACE(512)
pucPHMsg = SPACE(1024)
pucFPMsg = SPACE(1024)
uiCHMsgLen = 0
uiPHMsgLen = 0


iPort = 1001 && 端口设置为 1001 代表是 USB 设备
iIfOpen = 0

IF iIfOpen = 0
    iRet = SDT_OpenPort(iPort)
    IF iRet != 144
        MESSAGEBOX("SDT_OpenPort 错误, 错误代码为 " + LTRIM(STR(iRet)), 16, '错误')
        SDT_ClosePort(iPort) 
        RETURN
    ENDIF 
ENDIF 


DO WHILE .T. && 找卡 
    iRet = SDT_StartFindIDCard(iPort, @pucManaInfo, iIfOpen) 
    IF iRet = 159
        iRet = SDT_SelectIDCard(iPort, @pucManaMsg, iIfOpen) 
        IF iRet == 144 
            EXIT 
        ENDIF 
    ENDIF 
    *IF MESSAGEBOX("没有找到身份证,请放身份证?", 32 + 4, '询问') <> 6
    *    find_sta=.f.
    *    EXIT
    *ENDIF 
ENDDO 


iRet = SDT_ReadBaseMsg(iPort, @pucCHMsg, @uiCHMsgLen, @pucPHMsg, @uiPHMsgLen, iIfOpen) 
IF iRet != 0x90 
    MESSAGEBOX("SDT_ReadBaseMsg 错误, 错误代码为 " + LTRIM(STR(iRet)), 16, '错误')
    IF iIfOpen = 0
        SDT_ClosePort(iPort) 
        find_sta=.f.
        RETURN 
    ENDIF 
ENDIF 

*WAIT WINDOW "身份证信息获取成功!" NOWAIT 
tmp_read=STRCONV(left(pucCHMsg,uiCHMsgLen),6)
xm_read=ALLTRIM(LEFTC(tmp_read,15))&&读出的字符串前15位是姓名
xbpd = SUBSTRC(tmp_read,16,1) &&读出的字符串前16位是性别,1代表男,2代表女
mzpd = SUBSTRC(tmp_read,17,2) &&读出的字符串前17-18位是民族,01是汉族
tmp_rq = SUBSTRC(tmp_read,19,8) &&读出的字符串前19-25位是出生日期
thisform.label2.Caption=ALLTRIM(xm_read)+'身份证获取成功'

IF xbpd="1"
    xb_read="男"
ELSE 
    xb_read="女"
ENDIF

DO CASE 
    CASE mzpd = "01"
        mz_read = "汉族"
    CASE mzpd = "02"
        mz_read = "蒙古族"
    CASE mzpd = "03"
        mz_read = "回族"
    CASE mzpd = "04"
        mz_read = "藏族"
    CASE mzpd = "05"
        mz_read = "维吾尔族"
    CASE mzpd = "06"
        mz_read = "苗族"
    CASE mzpd = "07"
        mz_read = "彝族"
    CASE mzpd = "08"
        mz_read = "壮族"
    CASE mzpd = "09"
        mz_read = "布依族"
    CASE mzpd = "10"
        mz_read = "朝鲜族"
    CASE mzpd = "11"
        mz_read = "满族"
    CASE mzpd = "12"
        mz_read = "侗族"
    CASE mzpd = "13"
        mz_read = "瑶族"
    CASE mzpd = "14"
        mz_read = "白族"
    CASE mzpd = "15"
        mz_read = "土家族"
    CASE mzpd = "16"
        mz_read = "哈尼族"
    CASE mzpd = "17"
        mz_read = "哈萨克族"
    CASE mzpd = "18"
        mz_read = "傣族"
    CASE mzpd = "19"
        mz_read = "黎族"
    CASE mzpd = "20"
        mz_read = "傈僳族"
    CASE mzpd = "21"
        mz_read = "佤族"
    CASE mzpd ="22"
        mz_read = "畲族"
    CASE mzpd = "23"
        mz_read = "高山族"
    CASE mzpd ="24"
        mz_read = "拉祜族"
    CASE mzpd = "25"
        mz_read = "水族"
    CASE mzpd = "26"
        mz_read = "东乡族"
    CASE mzpd = "27"
        mz_read = "纳西族"
    CASE mzpd = "28"
        mz_read = "景颇族"
    CASE mzpd = "29"
        mz_read = "柯尔克孜族"
    CASE mzpd = "30"
        mz_read = "土族"
    CASE mzpd = "31"
        mz_read = "达翰尔族"
    CASE mzpd = "32"
        mz_read = "仫佬族"
    CASE mzpd = "33"
        mz_read = "羌族"
    CASE mzpd = "34"
        mz_read = "布朗族"
    CASE mzpd = "35"
        mz_read = "撒拉族"
    CASE mzpd = "36"
        mz_read = "毛南族"
    CASE mzpd = "37"
        mz_read = "仡佬族"
    CASE mzpd = "38"
        mz_read = "锡伯族"
    CASE mzpd = "39"
        mz_read = "阿昌族"
    CASE mzpd = "40"
        mz_read = "普米族"
    CASE mzpd ="41"
        mz_read = "塔吉克族"
    CASE mzpd = "42"
        mz_read = "怒族"
    CASE mzpd = "43"
        mz_read = "乌孜别克族"
    CASE mzpd = "44"
        mz_read = "俄罗斯族"
    CASE mzpd = "45"
        mz_read = "鄂温克族"
    CASE mzpd = "46"
        mz_read = "德昂族"
    CASE mzpd = "47"
        mz_read = "保安族"
    CASE mzpd = "48"
        mz_read = "裕固族"
    CASE mzpd = "49"
        mz_read = "京族"
    CASE mzpd = "50"
        mz_read = "塔塔尔族"
    CASE mzpd = "51"
        mz_read = "独龙族"
    CASE mzpd = "52"
        mz_read = "鄂伦春族"
    CASE mzpd = "53"
        mz_read = "赫哲族"
    CASE mzpd = "54"
        mz_read = "门巴族"
    CASE mzpd = "55"
        mz_read = "珞巴族"
    CASE mzpd ="56"
        mz_read = "基诺族"
    CASE mzpd = "57"
        mz_read = "其它"
    CASE mzpd = "98"
        mz_read = "外国人入籍"
ENDCASE


SET SAFETY OFF
SET CENTURY ON
SET DATE TO ANSI
csrq_read = CTOD(SUBSTR(tmp_rq,1,4) + "/" + SUBSTR(tmp_rq,5,2) + "/" + SUBSTR(tmp_rq,7,2)) &&出生日期
dz_read = SUBSTRC(tmp_read,27,35) &&地址的数据
sfzhm_read = SUBSTRC(tmp_read,62,18) &&身份证号码的数据
qfjg_read = ALLTRIM(SUBSTRC(tmp_read,80,15)) &&签发机关的数据
tmp_rqq = SUBSTRC(tmp_read,95,8) &&签发日期
tmp_rqz = SUBSTRC(tmp_read,103,8) &&有限期限
yxqq_read = CTOD(SUBSTR(tmp_rqq,1,4) + "/" + SUBSTR(tmp_rqq,5,2) + "/" + SUBSTR(tmp_rqq,7,2) ) && 有效起始日
yxqz_read = CTOD(SUBSTR(tmp_rqz,1,4) + "/" + SUBSTR(tmp_rqz,5,2)+"/"+SUBSTR(tmp_rqz,7,2)) && 有效终止日
qtxx_read = RIGHTC(tmp_read,18)&&其他内容,暂时不知道是什么

photo_tmp = SYS(5) + SYS(2003) + "\" + ALLTRIM(sfzhm_read) + ".wlt" &&这里是获得照片的程序
=STRTOFILE(LEFT(pucPHMsg,uiPHMsgLen),photo_tmp,1)

*IF iIfOpen = 0 &&关闭端口
*    SDT_ClosePort(iPort) 
*    SDT_OpenPort(iPort) 
*ENDIF 

photo_bmp = SYS(5) + SYS(2003) + "\" + ALLTRIM(sfzhm_read) + ".bmp"
photo_jpg = SYS(5) + SYS(2003) + "\photos\" + ALLTRIM(sfzhm_read) + ".jpg"


*CLEAR
*? "姓名:" + xm_read
*? "性别:" + xb_read
*? "民族:" + mz_read
*? "出生日期:" + DTOC(csrq_read)
*? "地址:" + dz_read
*? "身份证号:" + sfzhm_read
*? "签发机关:" + qfjg_read
*? "有效期起:" + DTOC(yxqq_read)
*? "有效期止:" + DTOC(yxqz_read)
*? "其它信息:" + qtxx_read
*? "照片路径:" + photo_jpg
a=GetBmp(photo_tmp,2)
*?a
IF NOT FILE(SYS(5) + SYS(2003) + "\身份证信息.dbf")
    CREATE TABLE 身份证信息 FREE (身份证号 C(18),姓名 C(32),性别 C(2),民族 C(10),出生日期 D,地址 C(72),发证机关 C(32),有效期始 D,有效期止 D,照片路径 C(254))
    INDEX ON 身份证号 TO  身份证信息 ASCENDING
ELSE 
    USE 身份证信息
    INDEX ON 身份证号 TO  身份证信息 ASCENDING
ENDIF
*SEEK sfzhm_read
IF 身份证号=sfzhm_read then
   MESSAGEBOX("该生身份证号已经存在!",0,"提示")
else
  IF NOT FOUND() THEN
      INSERT INTO 身份证信息 VALUES (sfzhm_read,xm_read,xb_read,mz_read,csrq_read,dz_read,qfjg_read,yxqq_read,yxqz_read,photo_jpg)
  ENDIF
endif
USE
搜索更多相关主题的帖子: 身份证 信息 Integer String CASE 
2018-03-02 13:05
mywisdom88
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:191
帖 子:3147
专家分:8408
注 册:2015-3-25
收藏
得分:0 
循环,判断
2018-03-02 13:37
bcly0808
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2013-3-22
收藏
得分:0 
回复 2楼 mywisdom88
老师,三种循环用哪种比较好
2018-03-02 13:51
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10608
专家分:43190
注 册:2014-5-20
收藏
得分:0 
用一个按钮切换“开启/停止”,用个定时器监视“开启”或“停止”执行读卡过程。
2018-03-02 15:41
bcly0808
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2013-3-22
收藏
得分:0 
回复 4楼 吹水佬
老师您好!能具体说一下吧,好像明白你说的大体意思了,定时器里具体怎么写呢?
2018-03-02 16:19
mywisdom88
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:191
帖 子:3147
专家分:8408
注 册:2015-3-25
收藏
得分:0 
步骤:
1.初始化读卡器部分,如 declare ....
  把这部分内容放到自定义事件去,如 thisform.sdt_open

2.读资料部分,如:
把下面的部分内容放到自定义 事件去 如,thisform.sdt_read

thisform.timer1.Enabled =.f.
thisform.timer1.tag="0"
DO WHILE .T. && 找卡
...
...
...

="连续读卡"
="停止读卡"
thisform.timer1.Enabled =.t.
thisform.timer1.tag="1"


3.循环部分,用1个定时器,目的为了读完1次后,停顿N秒,同时,可以按 command2退出
循环 2.读卡部分

**定时器部分 设置
* thisform.timer1.init
this.tag=0
* thisform.timer1.timer
if this.tag="1"
   thisform.sdt_read
endif

2018-03-02 17:32
bcly0808
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2013-3-22
收藏
得分:0 
回复 6楼 mywisdom88
还请老师帮助看一看,这个功能卡两天了,还没有进展
身份证读卡器.rar (6.1 KB)
2018-03-02 18:08
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10608
专家分:43190
注 册:2014-5-20
收藏
得分:0 
以下是引用bcly0808在2018-3-2 16:19:27的发言:

老师您好!能具体说一下吧,好像明白你说的大体意思了,定时器里具体怎么写呢?

大概意思是这样:
of = CREATEOBJECT("form1")
of.show(1)

DEFINE CLASS form1 as Form
    ADD OBJECT cmd as commandbutton WITH top=10,left=10,height=22,caption="启动"
    ADD OBJECT timer1 as timer WITH Interval=1000,Enabled=.F.
   
    PROCEDURE cmd.click
        thisform.timer1.Enabled = this.caption=="启动"
        this.caption = IIF(this.caption=="启动", "停止", "启动")
    ENDPROC

    PROCEDURE timer1.timer
        ** 读卡处理过程
        thisform.caption = TIME()
    ENDPROC
ENDDEFINE
2018-03-02 20:53
hu9jj
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:红土地
等 级:贵宾
威 望:400
帖 子:11857
专家分:43421
注 册:2006-5-13
收藏
得分:0 
试试加个循环,在循环结束之前加个捕捉键盘按键的函数inkey(),约定按某个按键(例如空格)就结束循环,只要inkey()函数的延时参数合适,就可以实现结束自动循环。
do while .t.
    ....
    if inkey(x)=32 &&延时x的值需要根据实际调整
        exit
    endif
enddo

活到老,学到老!http://www.(该域名已经被ISP盗卖了)E-mail:hu-jj@
2018-03-03 08:30
快速回复:求助一个按钮控件的问题!
数据加载中...
 
   



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

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