找回密码
 加入
搜索
查看: 7267|回复: 11

[效率算法] 关于一个表格查询的问题

 火.. [复制链接]
发表于 2013-7-22 11:33:58 | 显示全部楼层 |阅读模式
各位大侠好,想请问一下。在一个表格查询中怎么添加一个日期查询。也就是说在查询的时候可以选择日期查询。
想在设置的那个按钮,一按就弹出一个设置选择日期的控件。请问怎么弄?
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#PRE_Icon=1.ico
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
#include <Access.au3>
#include <Excel.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("作业量抽查系统", 800, 649, 260, 30)
$Label1 = GUICtrlCreateLabel("车牌号码", 20, 10, 68, 27)
GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
$Label2 = GUICtrlCreateLabel("号牌种类", 220, 10, 68, 27)
GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
$Label3 = GUICtrlCreateLabel("车辆状态", 420, 10, 70, 27)
GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
$Label4 = GUICtrlCreateLabel("名字", 600, 10, 40, 27)
GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
$Label5 = GUICtrlCreateLabel("车辆不合格理由", 20, 50, 120, 27)
GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
$Label6 = GUICtrlCreateLabel("日 期", 375, 50, 60, 27)
GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
$Label7 = GUICtrlCreateLabel("名字查询:", 520, 93, 85, 27)
GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
$Input1 = GUICtrlCreateInput("", 90, 11, 97, 21)
$Input2 = GUICtrlCreateInput("", 290, 11, 97, 21)
$Input3 = GUICtrlCreateInput("", 490, 11, 90, 21)
$Input4 = GUICtrlCreateInput("", 640, 11, 110, 21)
$Input5 = GUICtrlCreateInput("", 138, 52, 200, 21)
$Input6 = GUICtrlCreateInput("", 420, 52, 160, 21)
$Input7 = GUICtrlCreateInput("", 600, 93, 100, 21)
$Button1 = GUICtrlCreateButton("设  置", 600, 52, 75, 25)
GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
$Button2 = GUICtrlCreateButton("汇  总", 690, 52, 75, 25)
GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
$Button3 = GUICtrlCreateButton("创  建", 20, 92, 75, 25)
GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
$Button4 = GUICtrlCreateButton("查  看", 120, 92, 75, 25)
GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
$Button5 = GUICtrlCreateButton("添  加", 220, 92, 75, 25)
GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
$Button6 = GUICtrlCreateButton("删  除", 320, 92, 75, 25)
GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
$Button7 = GUICtrlCreateButton("导出Excel", 420, 92, 75, 25)
GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
$Button8 = GUICtrlCreateButton("查  询", 710, 92, 75, 25)
GUICtrlSetFont(-1, 12, 400, 0, "微软雅黑")
$ListView1 = GUICtrlCreateListView("序号|车牌号码|号牌种类|车辆状态|名字|车辆不合格理由|日 期", 4, 130, 795, 518 ,BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
GUICtrlSendMsg(-1, 0x101E, 0, 70)
GUICtrlSendMsg(-1, 0x101E, 1, 100)
GUICtrlSendMsg(-1, 0x101E, 2, 100)
GUICtrlSendMsg(-1, 0x101E, 3, 90)
GUICtrlSendMsg(-1, 0x101E, 4, 110)
GUICtrlSendMsg(-1, 0x101E, 5, 200)
GUICtrlSendMsg(-1, 0x101E, 6, 130)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$mdb_data_path = @ScriptDir & "\choucha.mdb"
$mdb_data_pwd='vpte'
$adTable = "Receipt"
$t='*'

shuaxin()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                 Case $Button3       ;新建数据库
                   If Not FileExists($mdb_data_path) Then
                           new()
                        Else
                                MsgBox(0,'关于···','本系统由云腾科技自主开发'&@CR&''&@CR&'版本:KF-0378-T1'&@CR&''&@CR&'@ 版权公有 传播不究')
                        EndIf
                Case $Button4  ;查看
                        chakan()
                Case $Button5  ;添加
                        xieru()
                Case $Button6  ;删除
                        
                Case $Button7  ;导出Excel表
                                $LL=_GUICtrlListView_GetSelectedCount($ListView1)
                        If $LL=0 Then
                                MsgBox(48,'提示:','请至少选定一条记录,按 Ctrl 或 Shift 可以多选')
                        Else
                                newxls()
                                        EndIf
                Case $Button8 ;查询
                        If Not GUICtrlRead($Input7)='' Then
                                xun()
                        Else
                                MsgBox(48,'提示:','请输入你要查询的名称')
                        EndIf                                        
                        EndSwitch
WEnd

Func shuaxin()  ;刷新选择框
                If Not FileExists($mdb_data_path) Then
                $msg=MsgBox(1,'欢迎使用','没有找到数据库文件,是否创建?')
                If $msg=1 Then
                        new()
                Else
                        Exit
                EndIf
        EndIf                
EndFunc 

Func new()   ;新建数据库和表
        $time=@MIN&@SEC&'-'&@MDAY&@HOUR&'-'&@YEAR
        $newMdb = ObjCreate('ADOX.Catalog')
        $newMdb.Create("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $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_data_pwd)
        $addTbl.Execute("CREATE TABLE " & $adTable)
        $addtbl.Close;建表
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $addfld.Execute("ALTER TABLE " & $adTable & " ADD ID identity(1, 1) primary key,chepaihao text(255),haopai text(255),zhuangtai text(255),mingzi text(255),buhege text(255),riqi text(255)")
        $addfld.Close;建列表名
        MsgBox(0,'提示','数据库创建成功!'&@CR&''&@CR&'系统授权号:KF-'&$time&@CR&''&@CR&'@ 版权公有 传播不究')
EndFunc
        
Func xieru() ;往数据库中添加新的条目
        If GUICtrlRead($Input1)<>'' And GUICtrlRead($Input2)<>''And GUICtrlRead($Input3)<>'' And GUICtrlRead($Input4)<>'' And GUICtrlRead($Input5)<>''And GUICtrlRead($Input6)<>'' Then
                $read1=GUICtrlRead($Input1)
                $read2=GUICtrlRead($Input2)
                $read3=GUICtrlRead($Input3)
                $read4=GUICtrlRead($Input4)
                $read5=GUICtrlRead($Input5)
                                $read6=GUICtrlRead($Input6)
                $addfld = ObjCreate("ADODB.Connection")
                $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)  ;要写数据,首先要连接到数据库
                $addfld.Execute("insert into "&$adTable&" (chepaihao,haopai,zhuangtai,mingzi,buhege,riqi) values('"&$read1&"','"&$read2&"','"&$read3&"','"&$read4&"','"&$read5&"','"&$read6&"')")  ;这里是告诉数据库要写到什么位置。要写什么值,
                $addfld.close  ;写完结束所有的连接
                                MsgBox(48,'提示','添加和发送记录成功!')
                                GUICtrlSetData($Input1,'')
                                GUICtrlSetData($Input2,'')
                                GUICtrlSetData($Input3,'')
                                GUICtrlSetData($Input4,'')
                                GUICtrlSetData($Input5,'')
                                                                GUICtrlSetData($Input6,'')
                                GUICtrlSetState($Input1,$GUI_FOCUS)
                        Else
                MsgBox(48, "提示", "添加失败,请检查项目填写格式是否正确!请输入完整或车牌号")
                GUICtrlSetState($Input5,$GUI_FOCUS)
        EndIf
        
EndFunc

Func chakan() ;查看数据库中所有的记录
        GUICtrlSendMsg($ListView1, $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_data_pwd)  ;这句话和上一句一起是连接到数据库
     $RS =ObjCreate("ADODB.Recordset")
         $RS.ActiveConnection = $addfld
         $RS.Open ("Select "&$t & " From " & $adTable )     ;$t : 表示一个连接  $adtable :表示的是这个表的名称   这句话是:从$adtable表的第一条开始读取,直到结束  $t的星号是所有的意思
      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&"|"& $RS.Fields (6).value,$ListView1 ) 
              ; $RS.Fields (0).value;表示的是第一个数据,往后依此类推,第二个第三个···把读取到的值用 | 隔开,并把他们放到对应的ListView下面。
             $rs.movenext  ;
              WEnd
               $rs.close
              $addfld.Close  ;读取结束后结束所有的连接,并把缓存的数据清空。
EndFunc

Func xun()   ;根据物品名称查找符合的记录,并显示
        $output4=GUICtrlRead($Input7)
     GUICtrlSendMsg($ListView1, $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_data_pwd)
         $RS =ObjCreate("ADODB.Recordset")
          $RS.ActiveConnection = $addfld
            $RS.Open ("Select * From "& $adTable & " WHERE mingzi" & " ='"&$output4&"'")   ;根据关键字查找数据库内所有的记录,看有没有记录
           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&"|"& $RS.Fields (6).value,$ListView1 )
              ;如果找到了就把找到的显示在ListView
             $rs.movenext
             WEnd
               $rs.close
              $addfld.Close
EndFunc

Func newxls()  
        Local $array[1],$L
        $L='序号|车牌号码|号牌种类|车辆状态|名字|车辆不合格理由|日 期'
        $Selected = _GUICtrlListView_GetSelectedIndices($ListView1, 1)
        _ArrayAdd($array,$L)
        For $I = 1 To $Selected[0]
                $SelectedItem = _GUICtrlListView_GetItemTextString($ListView1, $Selected[$I])
                ;MsgBox(0, 0, $SelectedItem)
                _ArrayAdd($array,$SelectedItem)
        Next
        $excel=_ExcelBookNew(1)  ;创建一个新的工作表并设置显示,(0=不可见, 1=可见)
        For $i=0 To UBound($array)-1   ;返回数组维度的大小
                $htest=StringSplit($array[$i],'|')  ;以指定分隔符把字符串拆分成若干子串
                For $ii=0 To $htest[0]
                        _ExcelWriteCell($excel,$htest[$ii],$i,$ii)  ;添加一个数据到打开的EXCEL(打开的excel,要添加的数据,要写入的行,要写入的列)
                Next
        Next
EndFunc        
发表于 2013-7-22 13:37:37 | 显示全部楼层
本帖最后由 chzj589 于 2013-7-22 16:41 编辑

本帖子中包含更多资源

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

×
 楼主| 发表于 2013-7-22 19:27:11 | 显示全部楼层
回复 2# chzj589


    麻烦给代码我看看
 楼主| 发表于 2013-7-22 20:31:27 | 显示全部楼层
回复 2# chzj589


    我刚才看了,这是单项查询,我需要得是日期跟名字一起查询,因为一天录入的车辆很多,有时只想看人名和一天的数量。
发表于 2013-7-22 21:01:48 | 显示全部楼层
回复 4# huangwei


    建议你花半个钟或更多一点的时间去学一学SQL的基础语法.
然后你就不用问别人了.
下面是一些SQL语法的应用例子.

查询名字为 Alam 以及日期为 2013-07-20 的记录, 返回所有字段
Select * From Receipt Where mingzi = 'alam' And riqi = '2013-07-20'

查询日期为 2013-07-20 的记录, 只返回名字
Select mingzi From Receipt Where  riqi = '2013-07-20'

查询 2013-07-20 那天的记录总数
Select count(riqi) From Receipt Where riqi = '2013-07-20'
发表于 2013-7-22 22:38:01 | 显示全部楼层

本帖子中包含更多资源

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

×
发表于 2013-7-23 07:55:27 | 显示全部楼层
回复 2# chzj589


你这GUI下面的那个分组框内与头部一样的,可以不要的了.
发表于 2013-7-23 08:43:03 | 显示全部楼层
回复 7# 绿色风
谢谢帮助

本帖子中包含更多资源

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

×
发表于 2013-7-24 10:48:43 | 显示全部楼层
坛子上 有个仓库管理的例子  有源码 可以参考下的  基本操作都差不多的
发表于 2013-7-29 10:05:04 | 显示全部楼层
楼主是要点击输入框弹出日期选择控件,用户选择日期后返回到输入框中。是不是这样的?
 楼主| 发表于 2013-7-31 07:03:05 | 显示全部楼层
回复 10# gczxhzb


    难道你会,不妨试试。试好了给我看看
发表于 2013-8-1 03:41:50 | 显示全部楼层
学习了~~~~~~~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-3 15:00 , Processed in 0.084256 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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