找回密码
 加入
搜索
查看: 25492|回复: 26

[交流] Autoit|用户登入&注册窗口|Access数据库操作(网上搜到的)

 火... [复制链接]
发表于 2011-8-23 20:44:27 | 显示全部楼层 |阅读模式
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Dim $Uid
$mdb_pwd=""
$mdb_path="z.mdb"
$tblname="zzm"
#Region ### START Koda GUI section ###
$Form1 = GUICreate("登入框", 186, 131, -1, -1)
$Input1 = GUICtrlCreateInput("", 16, 16, 153, 21)
$Input2 = GUICtrlCreateInput("", 16, 52, 153, 21,$ES_PASSWORD)
$Button1 = GUICtrlCreateButton("注  册", 16, 88, 65, 25)
$Button2 = GUICtrlCreateButton("登  入", 104, 88, 65, 25)

$Form2 = GUICreate("注册框", 204, 215, -1, -1)
$Input01 = GUICtrlCreateInput("", 64, 16, 121, 21)
$Input02 = GUICtrlCreateInput("", 64, 54, 121, 21)
$Input03 = GUICtrlCreateInput("", 64, 93, 121, 21)
$Input04 = GUICtrlCreateInput("", 64, 131, 121, 21)
$Label1 = GUICtrlCreateLabel("用户名", 16, 20, 40, 17)
$Label2 = GUICtrlCreateLabel("密码", 16, 57, 28, 17)
$Label3 = GUICtrlCreateLabel("Q  Q", 16, 95, 26, 17)
$Label4 = GUICtrlCreateLabel("E-mail", 16, 132, 34, 17)
$Button01 = GUICtrlCreateButton("提  交", 16, 168, 75, 25)
$Button02 = GUICtrlCreateButton("取  消", 112, 168, 75, 25)

#EndRegion ### END Koda GUI section #
GUISwitch($form1)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
         Case $GUI_EVENT_CLOSE
             Exit
   Case $Button1
    GUISetState(@sw_show,$form2)
         Case $Button2
    if guictrlread($input1)=""  Then
       MsgBox(64,"提示","请输入用户名!",5)
    ElseIf guictrlread($input2)="" Then
                MsgBox(64,"提示","请输入密码!",5)      
    Else
    login()
    EndIf
   Case $Button02
    GUISetState(@SW_HIDE,$form2)
   Case $Button01
    reg()
  EndSwitch
WEnd
func login()
     $user1=guictrlread($input1)
     $pass1=guictrlread($input2)
     $addfld=ObjCreate("ADODB.Connection")
     $addfld.open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="&$mdb_path)
     $RS=ObjCreate("ADODB.Recordset")
     $RS.ActiveConnection = $addfld
     $RS.Open ("SELECT zzm.name, zzm.pass FROM zzm WHERE zzm.name=" &"'" & $user1 & "'")
  If $RS.bof <0 Then
   Msgbox(64,"提示","未注册用户,请先注册!",5)
  Else
       $user2=StringReplace($RS.Fields (0).value," ","")
          $pass2=StringReplace($RS.Fields (1).value," ","")
       while Not $RS.eof And Not $RS.bof
              if @error =1 Then ExitLoop
        if $user1=$user2 and $pass1=$pass2 Then
        $Uid=$user1
        MsgBox(64,"登入口","欢迎回来尊敬的 " & $Uid,5)
        GUISetState(@SW_HIDE,$form1)
        main()
       Else
        MsgBox(64,"错误","密码错误!",5)
     EndIf
                 $rs.movenext
  WEnd
     $rs.close
                 $addfld.Close
  EndIf
EndFunc
func reg()
  $reg_user=guictrlread($input01)
     $reg_pass=guictrlread($Input02)
     $reg_qq=guictrlread($Input03)
     $reg_email=guictrlread($Input04)
     $addfld = ObjCreate("ADODB.Connection")
     $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & $mdb_path & ";Jet Oledb:Database Password=" & $mdb_pwd)
  $addfld.Execute("insert into zzm (name,pass,qq,e_mail) values('"&$reg_user&"','"&$reg_pass&"','"&$reg_qq&"','"&$reg_email&"')")
  $addfld.close
         MsgBox(4096, "提示:"," 注册成功!")
         GUISetState(@SW_HIDE,$form2)
   GUICtrlSetData ( $Input01 ,'')
   GUICtrlSetData ( $Input02 ,'')
   GUICtrlSetData ( $Input03 ,'')
   GUICtrlSetData ( $Input04 ,'')

EndFunc
func main()
$Form3 = GUICreate("主窗体  " & "当前用户: " & $Uid, 633, 447, -1, -1)
    $Button001 = GUICtrlCreateButton("我只是个测试的!", 128, 120, 377, 161)
    GUICtrlSetFont(-1, 24, 400, 0, "黑体")
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
         Case $GUI_EVENT_CLOSE
             Exit
   Case $Button001
    exit
  EndSwitch
WEnd
EndFunc



数据库z.mdb|表zzm|id(主键自动编号),name(char),pass(char),qq(int),e_mail(char)
发表于 2011-8-24 01:39:41 | 显示全部楼层
ACCESS数据库操作中尽量把name(char),pass(char),qq(int),e_mail(char) 中的CHAR 修改为text(255) 这样在没有安装ACCESS数据库的机器运行就不会出现数据后面很多 “···”
 楼主| 发表于 2011-8-28 15:30:12 | 显示全部楼层
多谢指教!
发表于 2011-8-29 09:16:18 | 显示全部楼层
灌水的么  怎么两个帖子一样
http://www.autoitx.com/thread-27094-1-1.html
发表于 2011-8-29 09:42:41 | 显示全部楼层
这个是单机版的,有网络版的没呀?
发表于 2011-9-27 09:19:13 | 显示全部楼层
收下來慢慢學習。
发表于 2011-9-30 22:35:50 | 显示全部楼层
谢谢分享!
发表于 2011-10-11 18:34:49 | 显示全部楼层
正在学习多窗体跳转,你这源码可以用来学习,借鉴,非常感谢分享
发表于 2012-4-18 20:11:25 | 显示全部楼层
借鉴,非常感谢分享
发表于 2012-4-22 15:58:02 | 显示全部楼层
用户名如何直接显示
#Region ### START Koda GUI section ###
$Form1 = GUICreate("登入框", 186, 131, -1, -1)
$Input1 = GUICtrlCreateInput("", 16, 16, 153, 21)
$Combo1 = GUICtrlCreateCombo("", 16, 52, 153, 21);用户名如何直接显示

$Button1 = GUICtrlCreateButton("注  册", 16, 88, 65, 25)
$Button2 = GUICtrlCreateButton("登  入", 104, 88, 65, 25)
发表于 2012-9-28 13:34:13 | 显示全部楼层
这个是单机版的,有网络版的没呀
发表于 2012-11-1 09:32:38 | 显示全部楼层
嗯,不错,正在在研究GUI,感觉从LZ这里学到很多!
发表于 2013-3-18 18:17:43 | 显示全部楼层
谢谢分享。
发表于 2013-6-23 17:56:08 | 显示全部楼层
好东西,学习
发表于 2013-6-23 17:56:14 | 显示全部楼层
好东西,学习
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-26 06:46 , Processed in 0.073822 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表