[已解决]INI中查询问题
本帖最后由 jycel 于 2010-4-26 21:38 编辑mdb.ini格式如下
[会员档案]
1=张三|身份证|5107221982010510163057|24|2010-12-13|472891322|E:\20100424\SDC11508.JPG
2=123|身份证|13|234|2010-4-26|1234124|E:\20100424\SDC11509.JPG
3=341|身份证|234|234|2010-4-26||E:\20100424\IMG0039A.jpg
;说明:等号前为编号,后面是姓名、身份类型、证件号码、年龄、时间、卡号码、照片路径
查询编号很简单,在查询对应的如后面身份证号码,卡号码不知道怎么来分辨
我的代码如下:#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Local $file=@ScriptDir&"\mdb.ini"
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("条件查询", 347, 312, 192, 114)
GUICtrlCreateLabel("查询条件:", 40, 64, 64, 17)
$Combo1 = GUICtrlCreateCombo("", 128, 64, 145, 25,BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1,"会员编号|证件号码|会员卡号","会员编号")
GUICtrlCreateLabel("查询内容:", 40, 128, 64, 17)
$Input1 = GUICtrlCreateInput("", 128, 120, 145, 21)
$Button1 = GUICtrlCreateButton("查询", 128, 168, 147, 25)
$Label = GUICtrlCreateLabel("查询结果显示", 32, 224, 307, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
_dir()
EndSwitch
WEnd
Func _dir()
$dirlr=GUICtrlRead($Input1)
If $dirlr="" Then
MsgBox(16,"错误提示","请输入查询内容",2)
Else
$cxtj=GUICtrlRead($Combo1)
If $cxtj="会员编号" Then
$fjdate=IniRead($file,"会员档案",$dirlr,"")
If Not @error Then
If $fjdate<>"" Then
;$dirjg = StringSplit($fjdate, "|")
MsgBox(64,"查询提示",$fjdate)
Else
MsgBox(64,"查询提示","数据库中未找到相关数据")
EndIf
EndIf
ElseIf $cxtj="证件号码" Then
$hyxm=GUICtrlRead($Input1)
$var=IniReadSection($file,"会员档案")
If Not @error Then
For $i=1 To $var
$db=StringSplit(IniRead($file,"会员档案",$var[$i],""),"|")
$fjdate=IniRead($file,"会员档案",$var[$i],"")
If $db=$hyxm Then
MsgBox(0,"提示","存在"&$fjdate)
Else
MsgBox(0,"提示","不存在")
EndIf
Next
EndIf
ElseIf $cxtj="会员卡号" Then
EndIf
EndIf
EndFunc 大大们请指点下!
下面这句搞不懂为什么在对比时会不正确 $hyxm=GUICtrlRead($Input1)
$var=IniReadSection($file,"会员档案")
If Not @error Then
For $i=1 To $var
$db=StringSplit(IniRead($file,"会员档案",$var[$i],""),"|")
$fjdate=IniRead($file,"会员档案",$var[$i],"")
If $db=$hyxm Then
MsgBox(0,"提示","存在"&$fjdate)
Else
MsgBox(0,"提示","不存在")
EndIf
Next
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Dim $file = @ScriptDir & '\mdb.ini'
GUICreate('条件查询', 347, 312)
GUICtrlCreateLabel('查询条件:', 40, 64, 64, 17)
$Combo1 = GUICtrlCreateCombo('', 128, 64, 145, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, '会员编号|证件号码|会员卡号', '会员编号')
GUICtrlCreateLabel('查询内容:', 40, 128, 64, 17)
$Input1 = GUICtrlCreateInput('', 128, 120, 145, 21)
$Button1 = GUICtrlCreateButton('查询', 128, 168, 147, 25)
$Label = GUICtrlCreateLabel('查询结果显示', 32, 224, 307, 17)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
_dir()
EndSwitch
WEnd
Func _dir()
Local $dirlr = GUICtrlRead($Input1)
If $dirlr = '' Then Return MsgBox(16, '错误提示', '请输入查询内容', 2)
Local $cxtj = GUICtrlRead($Combo1)
Switch $cxtj
Case '会员编号'
Local $fjdate = IniRead($file, '会员档案', $dirlr, '')
If $fjdate <> '' Then
MsgBox(64, '查询提示', $fjdate)
Else
MsgBox(48, '查询提示', '数据库中未找到相关数据')
EndIf
Case '证件号码'
cx($dirlr, $cxtj, 3)
Case '会员卡号'
cx($dirlr, $cxtj, 6)
EndSwitch
EndFunc ;==>_dir
Func cx($dirlr, $cx, $xh)
Local $var = IniReadSection($file, '会员档案'), $x, $i
If @error Then Return MsgBox(16, '错误提示', '字段读取错误', 2)
For $i = 1 To $var
Local $db = StringSplit($var[$i], '|')
If $db[$xh] = $dirlr Then
$x = 1
MsgBox(64, '提示', '存在' & $var[$i])
ExitLoop
EndIf
Next
If $x = 0 Then MsgBox(48, '提示', '不存在')
EndFunc ;==>cx
页:
[1]