作者yohoboy (小宝包是天使与恶魔)
看板EzHotKey
标题[-AI-] 猪头记帐搜寻
时间Mon Jul 24 22:31:48 2017
又来发表 autoit 了,此次因常用猪头记帐来管理收支,
有时看记帐偶而会发现当初纪录时错误的地方,
例如用现金支付,但是选择使用信用卡支付,因而造成统计资料错误。
因此自己撰写搜寻,找到那笔资料後再回头使用猪头记帐修改。
至於为什麽不直接编辑就好,就说了猪头也能使用,不改太多功能,
避免越改越大,失去当初写的美意。
好了以下是原始程式码
下载网址
http://doora.qiniudn.com/R2uHF.au3
-------------------------------------------------------------
#NoTrayIcon
#include <array.au3>
#include <ButtonConstants.au3>
#include <Color.au3>
#include <ColorConstantS.au3>
#include <ComboConstants.au3>
#include <Date.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <FileConstants.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIEdit.au3>
#include <GUIListBox.au3>
#Include <GuiListView.au3>
#include <GuiStatusBar.au3>
#include <ListViewConstants.au3>
#include <MsgBoxConstants.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>
#include <WinAPIEx.au3>
#include <WindowsConstants.au3>
Global $hQuery, $aRow, $aRow2, $a
Global $GUI_ListBox
Global $GUI_Combo1, $GUI_Input1, $GUI_Input2, $GUI_Combo2, $GUI_Combo3,
$GUI_Combo4, $GUI_Button4
Global $USER_ID, $subjetc_ID
Global $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES,
$LVS_EX_DOUBLEBUFFER);项目选中显示高亮度题示,显示项目横列线条,缓冲控键显示
_SQLite_Startup ("sqlite3.dll", TRUE, 0) ;加载SQLite3.dll,工作目录下需有
SQLite3.dll 如果没有就从autoit 网站下载并放入同一目录下
If @error Then
MsgBox($MB_SYSTEMMODAL, "SQLite错误", "SQLite3.dll不能载入!")
Exit -1
EndIf
$GUI_Form = GUICreate("猪头记帐搜寻", 400, 480, -1, -1) ;建立主视窗GUI样式
GUISetBkColor(0xECE9C8) ; 设定视窗背景颜色
$GUI_ListBox = GUICtrlCreateListView(" 日 期 | 支出/收入 | 花 费 |
备注 ", 2, 167, 397, 310, BitOR($LVS_REPORT,
$WS_BORDER), BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT))
;上面设定ListView内容
_GUICtrlListView_SetExtendedListViewStyle($GUI_ListBox,$iExListViewStyle) ;将
视窗设定风格显示
$GUI_ListBox = GUICtrlGetHandle($GUI_ListBox) ;回传控件项目句柄,针对项目双击後
选择其它功能
; 以下视窗显示
$GUI_Button1 = GUICtrlCreateButton("读取", 2, 2, 48, 22, 0)
GUICtrlCreateLabel("使用者帐号:",60, 8, 72, 15)
$GUI_Combo1 = GUICtrlCreateCombo("", 132, 2, 90, 50,$CBS_DROPDOWNLIST);显示使
用者名称用
GUICtrlCreateLabel("搜寻日期:", 8, 35, 72, 15)
$GUI_Input1 = GUICtrlCreateInput("",68,32,70,20,$ES_READONLY) ;搜寻起始日期
$GUI_Button2 = GUICtrlCreateButton("日期起点", 140, 30, 60, 22, 0)
$GUI_Input2 = GUICtrlCreateInput("",210,32,70,20,$ES_READONLY) ;搜寻最後日期
$GUI_Button3 = GUICtrlCreateButton("日期终点", 283, 30, 60, 22, 0)
GUICtrlCreateLabel("支出/收入:", 8, 65, 75, 15)
$GUI_Combo2 = GUICtrlCreateCombo("", 73, 60, 90, 50,$CBS_DROPDOWNLIST);显示收
支来源
GUICtrlSetData($GUI_Combo2, "现金支出|信用卡支出|收入", "")
GUICtrlCreateLabel("类别:", 8, 94, 38, 15)
$GUI_Combo3 = GUICtrlCreateCombo("", 47, 90, 90, 50,$CBS_DROPDOWNLIST);显示类
别
GUICtrlCreateLabel("子项目:", 145, 94, 50, 15)
$GUI_Combo4 = GUICtrlCreateCombo("", 195, 90, 90, 50,$CBS_DROPDOWNLIST);显示子
项目
$GUI_Button4 = GUICtrlCreateButton("搜寻", 50,130, 60, 22, 0)
GUISetState(@SW_SHOW,$GUI_Form) ;GUI 显示
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE ;视窗关闭
_SQLite_Close(-1)
_SQLite_Shutdown () ;本程式关闭时shutdown sqlite.dll
ExitLoop
Case $GUI_Button1
Local $SQLite_Data_Path = FileOpenDialog("选择档案", @ScriptDir & "\",
"(*.sqlite)", $FD_FILEMUSTEXIST + $FD_MULTISELECT)
If Not FileExists($SQLite_Data_Path) Then ;如果无资料库档案则执行以下命令
MsgBox(0,"错误","资料库无法打开,请检查档案是否存在或是档案已损毁。")
Exit
EndIf
_SQLite_Open ($SQLite_Data_Path) ;读取资料库,名称为$SQLite_Data_Path 变数
名称
If @error Then
MsgBox($MB_SYSTEMMODAL, "资料库无法载入", "载入失败!")
Exit
EndIf
SQLiteRead()
Case $GUI_Button2 ;搜寻起始日期
Local $BMDATETEMP = GUICreate("日期起点", 200, 50, -1, -1)
Local $idDate = GUICtrlCreateDate("", 10, 10, 185, 20,
$DTS_SHORTDATEFORMAT)
; 选择特定的默认格式
Local $sStyle = "yyyy-MM-dd"
GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle)
GUISetState(@SW_SHOW)
; 循环到用户退出.
While 1
SWITCH GUIGetMsg()
Case $GUI_EVENT_CLOSE
GUICtrlSetData($GUI_Input1, GUICtrlRead($idDate))
ExitLoop
EndSwitch
WEnd
GUIDelete($BMDATETEMP)
Case $GUI_Button3 ;搜寻最後日期
Local $BMDATETEMP = GUICreate("日期终点", 200, 50, -1, -1)
Local $idDate = GUICtrlCreateDate("", 10, 10, 185, 20,
$DTS_SHORTDATEFORMAT)
; 选择特定的默认格式
Local $sStyle = "yyyy-MM-dd"
GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle)
GUISetState(@SW_SHOW)
; 循环到用户退出.
While 1
SWITCH GUIGetMsg()
Case $GUI_EVENT_CLOSE
GUICtrlSetData($GUI_Input2, GUICtrlRead($idDate))
ExitLoop
EndSwitch
WEnd
GUIDelete($BMDATETEMP)
Case $GUI_Combo1 ;显示使用者名称
user_data()
Case $GUI_Combo3 ;显示类别
class_data()
Case $GUI_Button4 ;搜寻
forage()
EndSwitch
WEnd
Func forage() ; 开始搜寻
GUICtrlSetState($GUI_Button4, $GUI_DISABLE) ;将搜寻钮禁制避免重复搜寻
If GUICtrlRead ($GUI_Combo1) = "" Then ;如果未选择帐号
MsgBox(0,"操作错误","尚未选择帐号,请重新点选读取档案")
ElseIf GUICtrlRead ($GUI_Combo2) = "" Then ;如果未选择支出及收入类别
MsgBox(0,"操作错误","尚未选择支出及收入选项,请重新点选支出及收入选项")
ElseIf GUICtrlRead ($GUI_Combo3) = "" Or GUICtrlRead ($GUI_Combo4) = ""
Then ;如果未选择类别及子项目
MsgBox(0,"操作错误","尚未选择类别及子项目,请重新点选类别及子项目")
ElseIf GUICtrlRead ($GUI_Input1) <> "" AND GUICtrlRead($GUI_Input2) <> ""
Then ;输入起讫日期蒐寻
_GUICtrlListView_DeleteAllItems ($GUI_ListBox) ;清除旧资料显示
_SQLite_QuerySingleRow(-1, "SELECT uno FROM user WHERE uid = '" &
GUICtrlRead ($GUI_Combo1) & "' ;", $aRow ) ;查询user_uno值,使用者uno值
Local $uno = $aRow [0]
;MsgBox(0,"$uno","使用者$uno值" & $uno )
_SQLite_QuerySingleRow(-1, "SELECT cno FROM class WHERE name = '" &
GUICtrlRead ($GUI_Combo3) & "' AND uno = '" & $uno & "' ;", $aRow ) ;查询
class_cno值,使用者类别值
Local $c_cno = $aRow [0]
;MsgBox(0,"$c_cno","类别$c_cno值" & $c_cno )
_SQLite_QuerySingleRow(-1, "SELECT sno FROM subject WHERE name = '" &
GUICtrlRead ($GUI_Combo4) & "' AND uno = '" & $uno & "' AND cno = '" & $c_cno
& "' ;", $aRow ) ;查询subject_sno值,使用者子项目值
Local $s_sno = $aRow [0]
;MsgBox(0,"$s_sno","子项目$s_sno值" & $s_sno )
_SQLite_QuerySingleRow(-1, "SELECT count(),sum(spend) FROM money WHERE
datetime(date) >= '" & GUICtrlRead ($GUI_Input1) & "' AND datetime(date) <=
'" & GUICtrlRead ($GUI_Input2) & "' AND uno ='" & $uno & "' AND cno = '" &
$c_cno & "' AND sno = '" & $s_sno & "' AND mode = '" &
GUICtrlRead($GUI_Combo2) & "' ;", $aRow) ;查询资料,使用者及类别和子项目符合几
笔
$aRow2 = $aRow[0]
IF $aRow2 = 0 Then
Local $totalmoney = 0
Else
Local $totalmoney = $aRow[1]
EndIf
_SQLite_Query(-1, "SELECT * FROM money WHERE datetime(date) >= '" &
GUICtrlRead ($GUI_Input1) & "' AND datetime(date) <= '" & GUICtrlRead
($GUI_Input2) & "' AND uno ='" & $uno & "' AND cno = '" & $c_cno & "' AND sno
= '" & $s_sno & "' AND mode = '" & GUICtrlRead($GUI_Combo2) & "' ORDER BY mno
DESC ;", $hQuery) ;查询资料,并存入$hQuery 变数
sql_data_array()
MsgBox(0,"笔数","总共" & $aRow2 & "笔" & @CRLF & "合计:" & $totalmoney & "
元")
ElseIf GUICtrlRead ($GUI_Input1) <> "" Then
_GUICtrlListView_DeleteAllItems ($GUI_ListBox) ;清除旧资料显示
_SQLite_QuerySingleRow(-1, "SELECT uno FROM user WHERE uid = '" &
GUICtrlRead ($GUI_Combo1) & "' ;", $aRow ) ;查询user_uno值,使用者uno值
Local $uno = $aRow [0]
;MsgBox(0,"$uno","使用者$uno值" & $uno )
_SQLite_QuerySingleRow(-1, "SELECT cno FROM class WHERE name = '" &
GUICtrlRead ($GUI_Combo3) & "' AND uno = '" & $uno & "' ;", $aRow ) ;查询
class_cno值,使用者类别值
Local $c_cno = $aRow [0]
;MsgBox(0,"$c_cno","类别$c_cno值" & $c_cno )
_SQLite_QuerySingleRow(-1, "SELECT sno FROM subject WHERE name = '" &
GUICtrlRead ($GUI_Combo4) & "' AND uno = '" & $uno & "' AND cno = '" & $c_cno
& "' ;", $aRow ) ;查询subject_sno值,使用者子项目值
Local $s_sno = $aRow [0]
;MsgBox(0,"$s_sno","子项目$s_sno值" & $s_sno )
_SQLite_QuerySingleRow(-1, "SELECT count(),sum(spend) FROM money WHERE
datetime(date) >= '" & GUICtrlRead ($GUI_Input1) & "' AND uno ='" & $uno & "'
AND cno = '" & $c_cno & "' AND sno = '" & $s_sno & "' AND mode = '" &
GUICtrlRead($GUI_Combo2) & "' ;", $aRow) ;查询资料,使用者及类别和子项目符合几
笔
$aRow2 = $aRow[0]
IF $aRow2 = 0 Then
Local $totalmoney = 0
Else
Local $totalmoney = $aRow[1]
EndIf
_SQLite_Query(-1, "SELECT * FROM money WHERE datetime(date) >= '" &
GUICtrlRead ($GUI_Input1) & "' AND uno ='" & $uno & "' AND cno = '" & $c_cno
& "' AND sno = '" & $s_sno & "' AND mode = '" & GUICtrlRead($GUI_Combo2) & "'
ORDER BY mno DESC ;", $hQuery) ;查询资料,并存入$hQuery 变数
sql_data_array()
MsgBox(0,"笔数","总共" & $aRow2 & "笔" & @CRLF & "合计:" & $totalmoney & "
元")
Else
_GUICtrlListView_DeleteAllItems ($GUI_ListBox) ;清除旧资料显示
_SQLite_QuerySingleRow(-1, "SELECT uno FROM user WHERE uid = '" &
GUICtrlRead ($GUI_Combo1) & "' ;", $aRow ) ;查询user_uno值,使用者uno值
Local $uno = $aRow [0]
;MsgBox(0,"$uno","使用者$uno值" & $uno )
_SQLite_QuerySingleRow(-1, "SELECT cno FROM class WHERE name = '" &
GUICtrlRead ($GUI_Combo3) & "' AND uno = '" & $uno & "' ;", $aRow ) ;查询
class_cno值,使用者类别值
Local $c_cno = $aRow [0]
;MsgBox(0,"$c_cno","类别$c_cno值" & $c_cno )
_SQLite_QuerySingleRow(-1, "SELECT sno FROM subject WHERE name = '" &
GUICtrlRead ($GUI_Combo4) & "' AND uno = '" & $uno & "' AND cno = '" & $c_cno
& "' ;", $aRow ) ;查询subject_sno值,使用者子项目值
Local $s_sno = $aRow [0]
;MsgBox(0,"$s_sno","子项目$s_sno值" & $s_sno )
_SQLite_QuerySingleRow(-1, "SELECT count(),sum(spend) FROM money WHERE uno
='" & $uno & "' AND cno = '" & $c_cno & "' AND sno = '" & $s_sno & "' AND
mode = '" & GUICtrlRead($GUI_Combo2) & "' ;", $aRow) ;查询资料,使用者及类别和
子项目符合几笔
$aRow2 = $aRow[0]
IF $aRow2 = 0 Then
Local $totalmoney = 0
Else
Local $totalmoney = $aRow[1]
EndIf
_SQLite_Query(-1, "SELECT * FROM money WHERE uno ='" & $uno & "' AND cno =
'" & $c_cno & "' AND sno = '" & $s_sno & "' AND mode = '" &
GUICtrlRead($GUI_Combo2) & "' ORDER BY mno DESC ;", $hQuery) ;查询资料,并存入
$hQuery 变数
sql_data_array()
MsgBox(0,"笔数","总共" & $aRow2 & "笔" & @CRLF & "合计:" & $totalmoney & "
元")
EndIf
GUICtrlSetState($GUI_Button4, $GUI_ENABLE)
EndFunc
Func sql_data_array() ;取出之资料存入阵列
Local $ArrayData[$aRow2][4] ;设定二维阵列
Local $c = 0 ;初始二维阵列值
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$ArrayData[$c][0]=$aRow[5]
$ArrayData[$c][1]=$aRow[7]
$ArrayData[$c][2]=$aRow[4]
$ArrayData[$c][3]=$aRow[6]
$c = $c +1
WEnd
_GUICtrlListView_AddArray($GUI_ListBox, $ArrayData)
_SQLite_QueryFinalize($hQuery)
EndFunc
Func class_data() ;读取完类别後显示子项目
_SQLite_Query(-1, "SELECT * FROM user WHERE uid = '" & GUICtrlRead
($GUI_Combo1) & "' COLLATE NOCASE ;", $hQuery) ;查询user_uno
While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
Local $uno = $aRow[0]
WEnd
_SQLite_Query(-1, "SELECT * FROM class WHERE name = '" & GUICtrlRead
($GUI_Combo3) & "' AND uno = '" & $uno & "' COLLATE NOCASE ;", $hQuery) ;查询
class_cno
While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
Local $c_cno = $aRow[0]
WEnd
_SQLite_Query(-1, "SELECT COUNT(cno) FROM subject WHERE cno = '" & $c_cno &
"' AND uno = '" & $uno & "' ;",$hQuery) ;读取设定类别
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK ;将_SQLite_Query 查回的
$hQuery 变数存入$aRow阵列资料内
$a = Int($aRow[0]) ;取出资料,目前为资料笔数
WEnd
Local $ArrayData[$a][5] ;设定二维阵列
Local $c = 0 ;初始二维阵列值
_SQLite_Query(-1, "SELECT * FROM subject WHERE cno = '" & $c_cno & "' AND
uno = '" & $uno & "' COLLATE NOCASE ;",$hQuery) ;读取全部资料笔数,并存入
$hQuery 变数
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK ;将_SQLite_Query 查回的
$hQuery 变数存入$aRow阵列资料内
$ArrayData[$c][0]=$aRow[0]
$ArrayData[$c][1]=$aRow[1]
$ArrayData[$c][2]=$aRow[2]
$ArrayData[$c][3]=$aRow[3]
$ArrayData[$c][4]=$aRow[4]
$c = $c +1
WEnd
_SQLite_QueryFinalize($hQuery) ;结束SQLITE 查询
Local $subject_1 = $ArrayData[0][3]
Local $d =1
While $d < $a
$subject_1 = $subject_1 &"|" & $ArrayData[$d][3]
$d = $d + 1
WEnd
GUICtrlDelete($GUI_Combo4)
Sleep(100)
$GUI_Combo4 = GUICtrlCreateCombo("", 195, 90, 90, 50,$CBS_DROPDOWNLIST);显示
子项目
GUICtrlSetData($GUI_Combo4, $subject_1, "")
EndFunc
Func user_data() ;读取使用者资料,读取完後显示类别
_SQLite_Query(-1, "SELECT * FROM user WHERE uid = '" & GUICtrlRead
($GUI_Combo1) & "' COLLATE NOCASE ;", $hQuery) ;查询资料笔数,并存入$hQuery 变
数- 先取得使用者资料
While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK ;取得笔数资料
Local $uno = $aRow[0]
Local $uid = $aRow[1]
Local $passwd = $aRow[2]
Local $needPwd = $aRow[3]
WEnd
_SQLite_Query(-1, "SELECT COUNT(uno) FROM class WHERE uno = '" & $uno & "'
;",$hQuery) ;读取全部资料笔数,并存入$hQuery 变数- 设定类别
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK ;将_SQLite_Query 查回的
$hQuery 变数存入$aRow阵列资料内
$a = Int($aRow[0]) ;取出资料,目前为资料笔数
WEnd
Local $ArrayData[$a][4] ;设定二维阵列
Local $c = 0 ;初始二维阵列值
_SQLite_Query(-1, "SELECT * FROM class WHERE uno = '" & $uno & "' COLLATE
NOCASE ;",$hQuery) ;读取全部资料笔数,并存入$hQuery 变数
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK ;将_SQLite_Query 查回的
$hQuery 变数存入$aRow阵列资料内
$ArrayData[$c][0]=$aRow[0]
$ArrayData[$c][1]=$aRow[1]
$ArrayData[$c][2]=$aRow[2]
$ArrayData[$c][3]=$aRow[3]
$c = $c +1
WEnd
_SQLite_QueryFinalize($hQuery) ;结束SQLITE 查询
Local $class_1 = $ArrayData[0][2]
Local $d =1
While $d < $a
$class_1 = $class_1 &"|" & $ArrayData[$d][2]
$d = $d + 1
WEnd
GUICtrlDelete($GUI_Combo3)
Sleep(100)
$GUI_Combo3 = GUICtrlCreateCombo("", 47, 90, 90, 50,$CBS_DROPDOWNLIST);显示类
别
GUICtrlSetData($GUI_Combo3, $class_1, "")
EndFunc
Func SQLiteRead() ;读取使用者
_SQLite_Query(-1, "SELECT COUNT(uno) FROM user;",$hQuery) ;读取全部资料笔数,
并存入$hQuery 变数
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK ;将_SQLite_Query 查回的
$hQuery 变数存入$aRow阵列资料内
$a = Int($aRow[0]) ;取出资料,目前为资料笔数
WEnd
Local $ArrayData[$a][4] ;设定二维阵列
Local $c = 0 ;初始二维阵列值
_SQLite_Query(-1, "SELECT * FROM user;",$hQuery) ;读取全部资料笔数,并存入
$hQuery 变数
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK ;将_SQLite_Query 查回的
$hQuery 变数存入$aRow阵列资料内
$ArrayData[$c][0]=$aRow[0]
$ArrayData[$c][1]=$aRow[1]
$ArrayData[$c][2]=$aRow[2]
$ArrayData[$c][3]=$aRow[3]
$c = $c +1
WEnd
_SQLite_QueryFinalize($hQuery) ;结束SQLITE 查询
Local $userbunch = $ArrayData[0][1]
Local $d =1
While $d < $a
$userbunch = $userbunch &"|" & $ArrayData[$d][1]
$d = $d + 1
WEnd
GUICtrlDelete($GUI_Combo1)
Sleep(100)
$GUI_Combo1 = GUICtrlCreateCombo("", 132, 2, 90, 50,$CBS_DROPDOWNLIST )
GUICtrlSetData($GUI_Combo1, $userbunch, "")
EndFunc
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 36.236.21.243
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/EzHotKey/M.1500906711.A.AF9.html