baigehy520 发表于 2009-11-10 14:13:50

如何让他读取INI文件后自动填写到指定的区域

#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>

$dir = @ScriptDir&"\config.ini"

$Form1 = GUICreate("列表框操作", 350, 320)
$ListView1 = GUICtrlCreateListView("姓名   |身份证   | 卡号   |", 20, 20, 300, 200)
$Button1 = GUICtrlCreateButton("添加", 260, 240, 75, 25, $WS_GROUP)
$Input1 = GUICtrlCreateInput("", 60, 180, 120, 21)
$Input1 = GUICtrlCreateInput("", 60, 220, 120, 21)
$Input2 = GUICtrlCreateInput("", 60, 260, 120, 21)
$Label1 = GUICtrlCreateLabel("姓名:", 30, 183, 36, 17)
$Label2 = GUICtrlCreateLabel("身份证:", 30, 223, 36, 17)
$Label2 = GUICtrlCreateLabel("卡号:", 40, 223, 36, 17)
$Label3 = GUICtrlCreateLabel("数据", 200, 223, 36, 17)
$Label4 = GUICtrlCreateLabel("0", 230, 223, 36, 17)
GUISetState(@SW_SHOW)
Read()

While 1
      $nMsg = GUIGetMsg()
      Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        tian()
      EndSwitch
WEnd

Func Read()
      $z = 0
      _GUICtrlListView_DeleteAllItems($ListView1)
      $read = IniReadSection($dir,"config")
      If Not @error Then
                For $i = 1 To $read
                        GUICtrlCreateListViewItem($read[$i], $ListView1)
                        _GUICtrlListView_AddSubItem($ListView1, $z, $read[$i], 1, $z+1)
                        GUICtrlSetData($Label4,$z+1)
                        $z += 1               
                Next
      EndIf
EndFunc

Func tian()
      $z = GUICtrlRead($Label4)
      $a = GUICtrlRead($Input1)
      $b = GUICtrlRead($Input2)      
      If $a <> "" And $b <> "" Then
                IniWrite($dir,"config",$a,$b)
                GUICtrlCreateListViewItem($a, $ListView1)               
                _GUICtrlListView_AddSubItem($ListView1, $z, $b, 1, $z+1)
                MsgBox(0,"提示"," 账号: "&$a&" 密码: "&$b&" 保存成功 ")               
                GUICtrlSetData($Input1,"")
                GUICtrlSetData($Input2,"")
                GUICtrlSetData($Label4,$z+1)
      EndIf      
EndFunc      如何让他读取INI文件后自动填写到指定的区域。比如姓名和身份证和卡号填到不同的地方

baigehy520 发表于 2009-11-10 14:15:04

比如姓名指定一个区域。身份证指定到一个区域。卡号也一样。
1024*768的分辨率

baigehy520 发表于 2009-11-10 14:47:24

人呢。。有偿求助啊

水木子 发表于 2009-11-10 16:04:54

呵呵!上面的代码是我之前写的吧!:face (17):

水木子 发表于 2009-11-10 16:07:43

本帖最后由 水木子 于 2009-11-10 16:12 编辑

原来好像是"帐号   |密码   |"吧?

你现在的意思是要改成"姓名   |身份证   | 卡号   |" 并且全部依依显示出来?

只需稍做修改即可

水木子 发表于 2009-11-10 19:24:56

本帖最后由 水木子 于 2009-11-10 19:28 编辑

本想直接帮你改下的,由于时间仓促最近很忙。
就把我平时练习写的“作业”给你看看吧!
仅供参考因为有很多不足的地方,(还希望大家多多指点我啊!)不过解决你的疑问完全够了。
希望对你有所启发。#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
Opt("TrayMenuMode",1)
$dir = @ScriptDir&"\Database.ini"
$pei = @ScriptDir&"\config.ini"

$Form1 = GUICreate("用户资料管理", 800, 600, -1, -1, BitOR($WS_MINIMIZEBOX,$WS_CAPTION,$WS_POPUP,$WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS))
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$hListView = GUICtrlCreateListView("主机序号|主机型号|销售部门|销售日期    |服务人员 |用户姓名 |用户电话|用户手机|用户地址                  |销售备注                  | ", _
10, 10, 780, 500,-1, BitOR($WS_EX_CLIENTEDGE,$LVS_EX_FULLROWSELECT,$LVS_REPORT))

$hImage = _GUIImageList_Create(1, 25)
_GUICtrlListView_SetImageList($hListView, $hImage, 1)

$Button1 = GUICtrlCreateButton("刷新", 600, 530, 70, 30, $WS_GROUP)
$Button2 = GUICtrlCreateButton("退出", 700, 530, 70, 30, $WS_GROUP)
$Button3 = GUICtrlCreateButton("开始搜索", 483, 533, 60, 26, $WS_GROUP)
Dim $AccelKeys = [["{Enter}", $Button3]]
GUISetAccelerators($AccelKeys)

$Input1 = GUICtrlCreateInput("输入搜索内容", 302, 535, 180, 21)

$shuju = GUICtrlCreateLabel("目前共有0条数据", 10, 533, 180, 20)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")


$caidan = GUICtrlCreateMenu("设置")
$daoru = GUICtrlCreateMenuItem("控制面板", $caidan)
$tuichu = GUICtrlCreateMenuItem("关闭程序", $caidan)
GUICtrlSetState(-1, $GUI_DEFBUTTON)

;右键菜单
$zhucaidan = GUICtrlCreateContextMenu($hListView)
$tianjia = GUICtrlCreateMenuItem("添加数据      ", $zhucaidan)
$shanchu = GUICtrlCreateMenuItem("删除数据", $zhucaidan)
$xiugai = GUICtrlCreateMenuItem("修改数据", $zhucaidan)
$shuaxin = GUICtrlCreateMenuItem("刷新数据", $zhucaidan)
$sousuo = GUICtrlCreateMenuItem("搜索数据", $zhucaidan)
GUICtrlCreateMenuItem("", $zhucaidan)

$pailie = GUICtrlCreateMenu("排列方式", $zhucaidan)
$plshijian = GUICtrlCreateMenuItem("录入时间", $pailie)
$plriqi = GUICtrlCreateMenuItem("销售日期", $pailie)

$fileitem = GUICtrlCreateMenuItem("控制面板", $zhucaidan)
GUICtrlCreateMenuItem("", $zhucaidan)   

$infoitem = GUICtrlCreateMenuItem("关闭程序", $zhucaidan)
;===>右键菜单

;托盘菜单
$xscx = TrayCreateItem("显示程序")
$yccx = TrayCreateItem("隐藏程序")
$gycx = TrayCreateItem("关于程序")
TrayCreateItem("")
$gbcx = TrayCreateItem("关闭程序")
;===>托盘菜单
GUISetState(@SW_SHOW)
xian()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3,$Button2,$tuichu,$infoitem
                        Exit
                Case $tianjia
                        tianjia()                       
                Case $shanchu
                        shanchu()
                Case $Button1,$shuaxin
                        xian()
                Case $sousuo,$Button3
                        sousuo()
                Case $xiugai

        EndSwitch       
       
        $msg = TrayGetMsg()
        Switch $msg
                Case $xscx
                        GUISetState(@SW_SHOW)
                Case $yccx
                        GUISetState(@SW_HIDE)
                Case $gycx
                        MsgBox(64,"关于程序","《用户资料管理》此程序为内江英特公司专用!")
                Case $gbcx
                        Exit
        EndSwitch

WEnd


Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)

      Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
      Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
      If @error Then Return $GUI_RUNDEFMSG
      $IDFrom = DllStructGetData($tagNMHDR, 2)
      $Event = DllStructGetData($tagNMHDR, 3)
      $tagNMHDR = 0
      Switch $IDFrom;选择产生事件的控件

                        Case $hListView

                                Switch $Event; 选择产生的事件

                                        Case $NM_CLICK ; 左击
;~                                       ...
                                        Case $NM_DBLCLK ; 双击
                                                        shuangji()
                                        Case $NM_RCLICK ; 右击

                                EndSwitch
      EndSwitch
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY


Func xian()
        $z = 0
        _GUICtrlListView_DeleteAllItems($hListView)
        $bianhao = IniReadSectionNames($dir)
        If Not @error Then       
                For $i = 1 To $bianhao
                        GUICtrlCreateListViewItem($bianhao[$i], $hListView)
               
                        $xinghao = IniRead($dir,$bianhao[$i],"主机型号","NotFound")
                        _GUICtrlListView_AddSubItem($hListView, $z, $xinghao, 1, $z+1)
               
                        $bumen = IniRead($dir,$bianhao[$i],"销售部门","NotFound")
                        _GUICtrlListView_AddSubItem($hListView, $z, $bumen, 2, $z+1)
               
                        $riqi = IniRead($dir,$bianhao[$i],"销售日期","NotFound")
                        _GUICtrlListView_AddSubItem($hListView, $z, $riqi, 3, $z+1)
               
                        $fuwu = IniRead($dir,$bianhao[$i],"服务人员","NotFound")
                        _GUICtrlListView_AddSubItem($hListView, $z, $fuwu, 4, $z+1)
               
                        $xingming = IniRead($dir,$bianhao[$i],"用户姓名","NotFound")
                        _GUICtrlListView_AddSubItem($hListView, $z, $xingming, 5, $z+1)
               
                        $dianhua = IniRead($dir,$bianhao[$i],"用户电话","NotFound")
                        _GUICtrlListView_AddSubItem($hListView, $z, $dianhua, 6, $z+1)
               
                        $shouji = IniRead($dir,$bianhao[$i],"用户手机","NotFound")
                        _GUICtrlListView_AddSubItem($hListView, $z, $shouji, 7, $z+1)
               
                        $dizhi = IniRead($dir,$bianhao[$i],"用户地址","NotFound")
                        _GUICtrlListView_AddSubItem($hListView, $z, $dizhi, 8, $z+1)
               
                        $beizhu = IniRead($dir,$bianhao[$i],"销售备注","NotFound")
                        _GUICtrlListView_AddSubItem($hListView, $z, $beizhu, 9, $z+1)
                       
                        GUICtrlSetData($shuju,"当前共有"&$z+1&"条数据")
                        $z += 1
                Next
        EndIf
EndFunc       

Func tianjia()
        GUISetState(@SW_DISABLE,$Form1)
        $Form2 = GUICreate("请输入需要添加的数据", 400, 280, -1, -1, BitOR _
        ($WS_MINIMIZEBOX,$WS_CAPTION,$WS_POPUP,$WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS))
        $Button11 = GUICtrlCreateButton("保存", 200, 230, 80, 30, $WS_GROUP)
        $Button12 = GUICtrlCreateButton("退出", 300, 230, 80, 30, $WS_GROUP)

        $Label1 = GUICtrlCreateLabel("主机序号:", 20, 23, 55, 17)
        $Label2 = GUICtrlCreateLabel("主机型号:", 20, 53, 55, 17)
        $Label3 = GUICtrlCreateLabel("用户姓名:", 20, 83, 55, 17)
        $Label4 = GUICtrlCreateLabel("用户电话:", 20, 113, 55, 17)
        $Label5 = GUICtrlCreateLabel("销售部门:", 200, 23, 55, 17)
        $Label6 = GUICtrlCreateLabel("销售日期:", 200, 53, 55, 17)
        $Label7 = GUICtrlCreateLabel("服务人员:", 200, 83, 55, 17)
        $Label8 = GUICtrlCreateLabel("用户手机:", 200, 113, 55, 17)
        $Label9 = GUICtrlCreateLabel("用户地址:", 20, 143, 55, 17)
        $Label10 = GUICtrlCreateLabel("销售备注:", 20, 173, 55, 17)

        $Input1 = GUICtrlCreateInput("", 80, 20, 100, 21)
        GUICtrlSetState(-1, $GUI_FOCUS)
        $Input2 = GUICtrlCreateInput("", 80, 50, 100, 21)
        $Input3 = GUICtrlCreateInput("", 80, 80, 100, 21)
        $Input4 = GUICtrlCreateInput("", 80, 110, 100, 21)
        $Input5 = GUICtrlCreateCombo("", 260, 20, 120, 21)
        GUICtrlSetData(-1, "天津店|惠川店|售后部|行业组", "天津店")
        $Input6 = GUICtrlCreateDate("", 260, 50, 120, 21)
        $Input7 = GUICtrlCreateCombo("", 260, 80, 120, 21)
        GUICtrlSetData(-1, "罗庆|吴英|何利|李娇|小韦", "罗庆")
        $Input8 = GUICtrlCreateInput("", 260, 110, 120, 21)
        $Input9 = GUICtrlCreateInput("", 80, 140, 300, 21)
        $Input10 = GUICtrlCreateInput("", 80, 170, 300, 21)
        GUISetState(@SW_SHOW)

        While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                        Case -3,$Button12
                                        GUISetState(@SW_ENABLE,$Form1)         ;启用父窗口
                                        GUIDelete($Form2)                      ;;删除指定窗口和它包含的所有控件.
                                        ExitLoop   
                                        ;Exit
                        Case $Button11
                                        $z = _GUICtrlListView_GetItemCount($hListView)
                                        $xuhao = GUICtrlRead($Input1)
                                        $xinghao = GUICtrlRead($Input2)
                                        $xingming = GUICtrlRead($Input3)
                      $dianhua = GUICtrlRead($Input4)
                                        $bumen = GUICtrlRead($Input5)
                      $riqi = GUICtrlRead($Input6)
                       $fuwu = GUICtrlRead($Input7)
                      $shouji = GUICtrlRead($Input8)
                        $dizhi = GUICtrlRead($Input9)
                      $beizhu = GUICtrlRead($Input10)
       
                                        If $xuhao <> "" And $xinghao <> "" Then
                                                IniWrite($dir,$xuhao,"主机型号",$xinghao)
                                                IniWrite($dir,$xuhao,"销售部门",$bumen)
                            IniWrite($dir,$xuhao,"销售日期",$riqi)
                                                IniWrite($dir,$xuhao,"服务人员",$fuwu)
                                                IniWrite($dir,$xuhao,"用户姓名",$xingming)
                            IniWrite($dir,$xuhao,"用户电话",$dianhua)
                            IniWrite($dir,$xuhao,"用户手机",$shouji)
                                                IniWrite($dir,$xuhao,"用户地址",$dizhi)
                            IniWrite($dir,$xuhao,"销售备注",$beizhu&@CRLF)
                                               
                                                GUICtrlCreateListViewItem($xuhao, $hListView)
                                                _GUICtrlListView_AddSubItem($hListView, $z, $xinghao, 1, $z+1)               
                                                _GUICtrlListView_AddSubItem($hListView, $z, $bumen, 2, $z+1)               
                                                _GUICtrlListView_AddSubItem($hListView, $z, $riqi, 3, $z+1)
                                                _GUICtrlListView_AddSubItem($hListView, $z, $fuwu, 4, $z+1)
                                                _GUICtrlListView_AddSubItem($hListView, $z, $xingming, 5, $z+1)
                                                _GUICtrlListView_AddSubItem($hListView, $z, $dianhua, 6, $z+1)
                                                _GUICtrlListView_AddSubItem($hListView, $z, $shouji, 7, $z+1)
                                                _GUICtrlListView_AddSubItem($hListView, $z, $dizhi, 8, $z+1)
                                                _GUICtrlListView_AddSubItem($hListView, $z, $beizhu, 9, $z+1)
                                                GUICtrlSetData($shuju,"当前共有"&$z+1&"条数据")
       
                                                MsgBox(0,"保存成功","主机序号:"&$xuhao&@CRLF&@CRLF&"主机型号:"&$xinghao&@CRLF&@CRLF& _
                                                "销售部门:"&$bumen&@CRLF&@CRLF&"销售日期:"&$riqi&@CRLF&@CRLF&"服务人员:"&$fuwu&@CRLF&@CRLF& _
                                                "用户姓名:"&$xingming&@CRLF&@CRLF&"用户电话:"&$dianhua&@CRLF&@CRLF&"用户手机:"&$shouji&@CRLF&@CRLF& _
                                                "用户地址:"&$dizhi&@CRLF&@CRLF&"销售备注:"&$beizhu)
                                        Else
                                                MsgBox(64,"提示","请正确输入相关内容,否则无法添加项目!")
                                        EndIf
                EndSwitch
        WEnd
EndFunc

Func shanchu()
        $a = _GUICtrlListView_GetSelectedIndices($hListView)
        $b = _GUICtrlListView_GetItemTextString($hListView, Number($a))
        $chaifen = StringSplit($b,"|")

        $a = MsgBox(32+1,"提示","请确认是否要删除以下数据      "&@CRLF&@CRLF&"主机序号:"&$chaifen&@CRLF&@CRLF&"主机型号:"&$chaifen&@CRLF&@CRLF& _
        "销售部门:"&$chaifen&@CRLF&@CRLF&"销售日期:"&$chaifen&@CRLF&@CRLF&"服务人员:"&$chaifen&@CRLF&@CRLF& _
        "用户姓名:"&$chaifen&@CRLF&@CRLF&"用户电话:"&$chaifen&@CRLF&@CRLF&"用户手机:"&$chaifen&@CRLF&@CRLF& _
        "用户地址:"&$chaifen&@CRLF&@CRLF&"销售备注:"&$chaifen)
        If $a = 1 Then
                _GUICtrlListView_DeleteItemsSelected($hListView) ;删除选定项目
                IniDelete($dir,$chaifen)
                $z = _GUICtrlListView_GetItemCount($hListView)
                GUICtrlSetData($shuju,"当前共有"&$z&"条数据")
                ;MsgBox(48, "提示", "数据删除成功")
        EndIf
EndFunc   ;==>shanchu

Func shuangji()
        $a = _GUICtrlListView_GetSelectedIndices($hListView)
        $b = _GUICtrlListView_GetItemTextString($hListView, Number($a))
        $chaifen = StringSplit($b,"|")
        If Not StringLen($a) Then; 这里用以判断是否选定了ListViewItem
                ;MsgBox(48, "提示", "请选择你要删除的号码")
        Return
        EndIf
                $a = MsgBox(64,"数据查看","本行数据如下:                  "&@CRLF&@CRLF&"主机序号:"&$chaifen&@CRLF&@CRLF&"主机型号:"&$chaifen&@CRLF&@CRLF& _
                "销售部门:"&$chaifen&@CRLF&@CRLF&"销售日期:"&$chaifen&@CRLF&@CRLF&"服务人员:"&$chaifen&@CRLF&@CRLF& _
                "用户姓名:"&$chaifen&@CRLF&@CRLF&"用户电话:"&$chaifen&@CRLF&@CRLF&"用户手机:"&$chaifen&@CRLF&@CRLF& _
                "用户地址:"&$chaifen&@CRLF&@CRLF&"销售备注:"&$chaifen)
EndFunc       
       
Func sousuo()       
        $a = GUICtrlRead($Input1)
        $sou = _GUICtrlListView_FindInText($hListView,$a)
        _GUICtrlListView_ClickItem($hListView,$sou)
        ;MsgBox(0,"",$sou)               
EndFunc               

sxd 发表于 2009-11-10 23:00:54

这个'稍作修改' 我滚了好久 囧

水木子 发表于 2009-11-11 09:19:19

这个'稍作修改' 我滚了好久 囧
sxd 发表于 2009-11-10 23:00 http://www.autoitx.com/images/common/back.gif

时间来不及啦!没改,直接发的我平时的“作业”:face (32):

kn007 发表于 2009-11-11 09:28:39

呵呵,辛苦了

水木子 发表于 2009-11-11 09:38:49

呵呵,辛苦了
kn007 发表于 2009-11-11 09:28 http://www.autoitx.com/images/common/back.gif

呵呵!没什么,举手之劳嘛,互相帮助。

baigehy520 发表于 2009-11-13 19:16:18

谢谢水木子

水木子 发表于 2009-11-13 19:23:58

本帖最后由 水木子 于 2009-11-13 19:28 编辑

谢谢水木子
baigehy520 发表于 2009-11-13 19:16 http://www.autoitx.com/images/common/back.gif

呵呵!没什么,互相帮助嘛,希望能帮上点儿什么。
主要是要明白其中的思路和方法。:face (22):

wangwen916 发表于 2009-11-13 20:33:23

无语中.....................

rikthhpgf2005 发表于 2009-11-17 13:01:44

设置数据到变量就ok了
页: [1]
查看完整版本: 如何让他读取INI文件后自动填写到指定的区域