找回密码
 加入
搜索
查看: 2705|回复: 6

[AU3基础] 数据库 执行update更新相隔时间无响应。[已解决]

[复制链接]
发表于 2012-6-13 00:13:58 | 显示全部楼层 |阅读模式
本帖最后由 xuanfeng1234567 于 2012-6-13 21:18 编辑

$addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &$mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_password)
        $addfld.execute("update  "&$tblname& " set shengy = datediff(d,date(),daoqi)")
        $addfld.Close

shengy 就是剩余的天数    daoqi就是到期时间。
我想在程序启动之后,会自动更新数据库中shengy这一列的数据,自动求出剩余的天数,然后写进listview里边。
shengy这一列的数据不是一样的,因为到期时间不同。
为什么这一句执行的时候没有任何响应?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2012-6-13 09:52:50 | 显示全部楼层
高手们帮忙看一下哦。 不知道是哪里错了。郁闷中。。。。
发表于 2012-6-13 10:22:48 | 显示全部楼层
本帖最后由 yeqing880 于 2012-6-13 12:24 编辑

数据库没必要存在这么个列 只要有了注册时间和到期时间

读取下来以后用au3计算就可以了

就算要更新 也用au3 函数计算上修改就可以了
 楼主| 发表于 2012-6-13 12:50:51 | 显示全部楼层
回复 3# yeqing880

我也 想过用 您说的 这个办法, 可是不知道读取到之后如何全部修改? 还请指教哦
发表于 2012-6-13 13:35:01 | 显示全部楼层
你把你的代码先贴上来..我帮你修改下
 楼主| 发表于 2012-6-13 13:58:17 | 显示全部楼层
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <Date.au3>
Global $qd1,$qd2,$qd3,$qd4,$qd5,$qd6,$Date21,$Date22
$mdb_data_path = @ScriptDir&"\daoqi.mdb"
$mdb_password = "test"
$T = "*"
$tblname = "myjishi"
If Not FileExists ($mdb_data_path) Then create()
;-----------------------------------------------------------------------------1
$Form1 = GUICreate("门店到期注册提示器", 690, 565, -1, -1)
$xinzeng = GUICtrlCreateButton("新增", 32, 8, 75, 25)
$xiugai = GUICtrlCreateButton("修改", 144, 8, 75, 25)
$shanchu = GUICtrlCreateButton("删除", 248, 8, 75, 25)
$shezhi = GUICtrlCreateButton("设置", 352, 8, 75, 25)
$List = GUICtrlCreateListView("", 0, 40, 489, 505,-1,BitOR($LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT))
GUICtrlSetBkColor(-1,0xFCFCFC)
_GUICtrlListView_AddColumn($list, "ID", 60)
_GUICtrlListView_AddColumn($list, "门店", 100)
_GUICtrlListView_AddColumn($list, "类别", 50)
_GUICtrlListView_AddColumn($list, "注册时间",100)
_GUICtrlListView_AddColumn($list, "剩余(天)", 70)
_GUICtrlListView_AddColumn($list, "到期时间", 100)
_GUICtrlListView_JustifyColumn($list,0,2)
_GUICtrlListView_JustifyColumn($list,1,2)
_GUICtrlListView_JustifyColumn($list,2,2)
_GUICtrlListView_JustifyColumn($list,3,2)
_GUICtrlListView_JustifyColumn($list,4,2)
_GUICtrlListView_JustifyColumn($list,5,2)
_GUICtrlListView_JustifyColumn($list,6,2)
$StatusBar1 = _GUICtrlStatusBar_Create($Form1)
$ipt = GUICtrlCreateInput("",490,40,200,25)
$list1 = GUICtrlCreateList("",490,66,200,485)
GUISetState(@SW_SHOW)
;------------------------------------------------------------------------2
$Form2 = GUICreate("添加门店信息", 234, 318, 210, 242)
$Label21 = GUICtrlCreateLabel("ID:", 48, 24, 32, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label22 = GUICtrlCreateLabel("门店:", 37, 67, 43, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label23 = GUICtrlCreateLabel("类别:", 37, 110, 43, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label24 = GUICtrlCreateLabel("注册时间:", 11, 154, 69, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label25 = GUICtrlCreateLabel("剩余天数:", 11, 197, 69, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label26 = GUICtrlCreateLabel("到期时间:", 11, 240, 69, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Input21 = GUICtrlCreateInput("", 80, 24, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
$Input22 = GUICtrlCreateInput("", 80, 66, 121, 21)
$Input23 = GUICtrlCreateInput("服务器", 80, 107, 121, 21)
$Input24 = GUICtrlCreateInput("", 80, 198, 121, 21)
GUICtrlSetState(-1,$GUI_DISABLE)
$Button21 = GUICtrlCreateButton("OK", 32, 280, 75, 25)
$Button22 = GUICtrlCreateButton("Cancle", 128, 280, 75, 25)
$Date21 = GUICtrlCreateDate("", 80, 152, 122, 21, $WS_BORDER)
$Date22 = GUICtrlCreateDate("", 80, 240, 122, 21, $WS_BORDER)
GUISetState(@SW_HIDE)
;------------------------------------------------------------------3
$Form3 = GUICreate("修改门店信息", 234, 318, 210, 242)
$Label31 = GUICtrlCreateLabel("ID:", 48, 24, 32, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label32 = GUICtrlCreateLabel("门店:", 37, 67, 43, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label33 = GUICtrlCreateLabel("类别:", 37, 110, 43, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label34 = GUICtrlCreateLabel("注册时间:", 11, 154, 69, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label35 = GUICtrlCreateLabel("剩余天数:", 11, 197, 69, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label36 = GUICtrlCreateLabel("到期时间:", 11, 240, 69, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Input31 = GUICtrlCreateInput("", 80, 24, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
$Input32 = GUICtrlCreateInput("", 80, 66, 121, 21)
$Input33 = GUICtrlCreateInput("服务器", 80, 107, 121, 21)
$Input34 = GUICtrlCreateInput("", 80, 198, 121, 21)
GUICtrlSetState(-1,$GUI_DISABLE)
$Button31 = GUICtrlCreateButton("OK", 32, 280, 75, 25)
$Button32 = GUICtrlCreateButton("Cancle", 128, 280, 75, 25)
$Date31 = GUICtrlCreateDate("", 80, 152, 122, 21, $WS_BORDER)
$Date32 = GUICtrlCreateDate("", 80, 240, 122, 21, $WS_BORDER)
GUISetState(@SW_HIDE)
If FileExists($mdb_data_path) Then du()


;--------------------------------------------------------------------4
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $xinzeng;新增
                        GUISetState(@SW_SHOW,$Form2)
                Case $xiugai;修改
                        GUISetState(@SW_SHOW,$Form3)
                Case $shanchu;删除
                        delete()
                        du()
                Case $shezhi;设置
                        sy()
                Case $Button21;确定新增
                        qdxz()
                Case $Button22;退出新增
                        GUISetState(@SW_HIDE,$Form2)
                Case $Button31;确定修改
                        qdxg()
                Case $Button32;退出修改
                        GUISetState(@SW_HIDE,$Form3)
        EndSwitch
WEnd


Func create()
        $newMdb = ObjCreate('ADOX.Catalog')
        $newMdb.Create("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_password)
        $newmdb.ActiveConnection.Close;建数据库
        $addtbl = ObjCreate("ADODB.Connection")
        $addTbl.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_password)
        $addTbl.Execute("CREATE TABLE " & $tblname)
        $addtbl.Close;建表
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_password)
        $addfld.Execute("ALTER TABLE "&$tblname&" ADD geshu int , mendian text(255) ,leibie text(255), zhuce text(50), shengy text(50), daoqi text(50)") 
        $addfld.Close;建列表名
        MsgBox(0,'提示:','数据库创建成功!!!')
        EndFunc
        
Func du()
     GUICtrlSendMsg($list, $LVM_DELETEALLITEMS, 0, 0)
          $addfld = ObjCreate("ADODB.Connection")
            $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &$mdb_data_path& ";Jet Oledb:Database Password=" & $mdb_password)
         $RS =ObjCreate("ADODB.Recordset")
          $RS.ActiveConnection = $addfld
            $RS.Open ("Select "&$T & " From " & $tblname&" order by shengy" )
           while Not $RS.eof And Not $RS.bof
           if @error =1 Then ExitLoop
            GUICtrlCreateListViewItem ($RS.Fields (0).value&"|" &$RS.Fields (1).value&"|"& $RS.Fields (2).value&"|"& $RS.Fields (3).value&"|"& $RS.Fields (4).value&"|"&$RS.Fields (5).value,$list)
             $rs.movenext
              WEnd
               $rs.close
              $addfld.Close
                  EndFunc  
Func baocun()
        If $qd5 >= $qd6 Then
                MsgBox(16,"","注册时间与到期时间填写不正确,请重新填写。")
        ElseIf $qd1 <> "" and $qd2 <> "" Then
                $addfld = ObjCreate("ADODB.Connection")
                $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &$mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_password)
                $addfld.execute("insert into "&$tblname&" (geshu,mendian,leibie,zhuce,daoqi) values('"&$qd1&"','"&$qd2&"','"&$qd3&"','"&$qd5&"','"&$qd6&"')")
                $addfld.close
                GUICtrlSetData($Date21,_NowDate())
                GUICtrlSetData($Date22,_NowTime())
                GUICtrlSetData($Input21,"")
                GUICtrlSetData($Input22,"")
                GUICtrlSetData($Input23,"服务器")
EndIf
EndFunc

Func delete()
 $read_1 = GUICtrlRead(GUICtrlRead($list))
 $read_2 = StringSplit($read_1,"|")
If $read_2[1] = '0' Then
        MsgBox(16,"","请选择您所要删除的行!")
else
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &$mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_password)
        $addfld.execute("delete from "&$tblname& " where geshu = "& $read_2[1])
        $addfld.Close
EndIf

EndFunc
        
Func qdxz() ;确定新增
        $qd1= GUICtrlRead($Input21)
        $qd2= GUICtrlRead($Input22)
        $qd3= GUICtrlRead($Input23)
        $qd5= GUICtrlRead($Date21)
        $qd6= GUICtrlRead($Date22)
        baocun()
        du()
EndFunc

Func sy()

        EndFunc

Func qdxg();确定修改

EndFunc
 楼主| 发表于 2012-6-13 21:18:00 | 显示全部楼层
$addfld.execute("update  "&$tblname& " set shengy = datediff('d',date(),daoqi)")
忘记加''了。 解决了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-19 02:10 , Processed in 0.089123 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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