|
#include <GUIconstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiToolbar.au3>
#include <StaticConstants.au3>
#include <ToolbarConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>
#include <DateTimeConstants.au3>
#include <IPAddressConstants.au3>
#include <ListViewConstants.au3>
#include <StatusBarConstants.au3>
#include <GuiIPAddress.au3>
#include <GuiStatusBar.au3>
#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WinAPI.au3>
#include <GuiDateTimePicker.au3>
#include <Date.au3>
#include <GuiStatusBar.au3>
#Region ### START Koda GUI section ### Form=
$xiaoluo = "luoligangmusic"
If WinExists($xiaoluo) Then Exit ; 此脚本已经运行了
AutoItWinSetTitle($xiaoluo)
TraySetState (2)
Local $aParts[4] = [0,90,180,600] ;定义状态栏宽度
Local $datadir = "musicdata.mdb"
local $acc_pwd = ""
$T="*"
$Table="musiclist"
$Form1 = GUICreate("Form1", 346, 454, 192, 124)
; GUISetBkColor(0x00cccccc) ; 将改变背景色
$Group1 = GUICtrlCreateGroup("", 8, 0, 321, 49)
$Search_Button = GUICtrlCreateButton("查找", 248, 16, 75, 25, 0)
$Keys_Input = GUICtrlCreateInput("请输入查询条件", 16, 16, 130, 21)
$Combo1 = GUICtrlCreateCombo("按歌名", 157, 16, 80, 21)
GUICtrlSetData(-1, "按字母|按歌手|按专集")
$admin_Button = GUICtrlCreateButton("后台管理", 8, 400, 75, 25, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$ListView1 = GUICtrlCreateListView(" ID | 歌曲",8, 56, 321, 337)
GUICtrlSendMsg($ListView1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
_GUICtrlListView_SetColumnWidth($ListView1, 0, 50)
_GUICtrlListView_SetColumnWidth($ListView1, 1, 270)
$menu1 = GUICtrlCreateContextMenu($ListView1)
$Listen = GUICtrlCreateMenuItem("试听", $menu1)
GUICtrlCreateMenuItem("", $menu1)
$download = GUICtrlCreateMenuItem("下载", $menu1)
$ToolBar1 = _GUICtrlToolbar_Create($Form1, 0)
$StatusBar1 = _GUICtrlStatusBar_Create($Form1)
_GUICtrlStatusBar_SetMinHeight($StatusBar1, 20)
_GUICtrlStatusBar_SetParts ($StatusBar1, $aParts)
_GUICtrlStatusBar_SetText ($StatusBar1, " 作者: 爱的幻觉 ",1)
_GUICtrlStatusBar_SetText ($StatusBar1, " QQ: 82015930 ",2)
_GUICtrlStatusBar_SetText ($StatusBar1, " E-mail:103007xp@163.com ",3)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$Msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $Listen
_Listen();试听
Case $msg = $download
_download();下载
Case $msg = $admin_Button
_admin();调用数据库管理函数,含窗口GUI函数
Case $msg = $Search_Button
$Combo1data = GUICtrlRead($Combo1)
$keys = GUICtrlRead($Keys_Input)
if $keys<> "" and $keys <> "请输入查询条件" then
_sql_Search($Combo1data,$keys);调用数据库搜索函数
Else
MsgBox(64,"提示:","请输入查询条件")
EndIf
EndSelect
WEnd
Func _sql_Search($Combo1data,$keys);数据库搜索函数
Local $date2_data,$State_data
_GUICtrlListView_DeleteAllItems($ListView1)
$conn = ObjCreate("ADODB.Connection")
$RS = ObjCreate("ADODB.Recordset")
$conn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & $datadir& ";Jet Oledb:Database Password="&$acc_pwd)
$RS.ActiveConnection = $conn
if $Combo1data = "按歌手" then $RS.Open ('Select * From musiclist where ' & "Singer" & ' = '& '"' & $keys & '"')
if $Combo1data = "按字母" then $RS.Open ('Select * From musiclist where ' & "zm" & ' = '& '"' & $keys & '"')
if $Combo1data = "按歌名" then $RS.Open ('Select * From musiclist where ' & "Name" & ' like' & '"%' & $keys & '%"');姓名按模糊查找
if $Combo1data = "按专集" then $RS.Open ('Select * From musiclist where ' & "Album" & ' = '& '"' & $keys & '"')
While (Not $RS.eof And Not $RS.bof)
$date2_data = $RS.Fields (2).value
$CLR_MONEYGREEN =0xFF0000
GUICtrlCreateListViewItem($RS.Fields (0).value & '|' & $RS.Fields (1).value & '|' & $State_data, $ListView1 )
_GUICtrlListView_SetTextColor($listview1,GUICtrlSetColor(-1, $CLR_MONEYGREEN))
GUICtrlSetImage(-1, "shell32.dll", 41)
$RS.movenext
WEnd
$RS.close
$conn.close
EndFunc
Func _Listen();试听
$Strn=GUICtrlRead(GUICtrlRead($ListView1))
$Strnspin=StringSplit($Strn,"|")
$ak = $Strnspin[1]
_sql_Search($Combo1data,$ak);数据库搜索函数
$Combo1data = GUICtrlRead($Combo1)
Local $date2_data,$State_data
$conn = ObjCreate("ADODB.Connection")
$RS = ObjCreate("ADODB.Recordset")
$conn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & $datadir& ";Jet Oledb:Database Password="&$acc_pwd)
$RS.ActiveConnection = $conn
$RS.Open ('Select * From musiclist where id ='& $ak)
While (Not $RS.eof And Not $RS.bof)
$date2_data = $RS.Fields (2).value
$mu = $RS.Fields (5).value
; $play='"'&$mu&'"'
; MsgBox(0, "", $RS.Fields (5).value);显示表第一个数据
$RS.movenext
WEnd
$RS.close
$conn.close
;SoundPlay ($mu,1)
EndFunc
Func _download();下载
$Strn=GUICtrlRead(GUICtrlRead($ListView1))
$Strnspin=StringSplit($Strn,"|")
$ak = $Strnspin[1]
_sql_Search($Combo1data,$ak);数据库搜索函数
$Combo1data = GUICtrlRead($Combo1)
Local $date2_data,$State_data
$conn = ObjCreate("ADODB.Connection")
$RS = ObjCreate("ADODB.Recordset")
$conn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & $datadir& ";Jet Oledb:Database Password="&$acc_pwd)
$RS.ActiveConnection = $conn
$RS.Open ('Select * From musiclist where id ='& $ak)
While (Not $RS.eof And Not $RS.bof)
$date2_data = $RS.Fields (2).value
$mu = $RS.Fields (5).value
$RS.movenext
WEnd
$RS.close
$conn.close
$s=StringSplit($mu,"\")
$sTo = FileSaveDialog("保存到", "d:", "所有文件(*.*)", 2, $s[$s[0]])
If @error Then
Else
;FileCopy($mu,$sTo,9)
$tagSHFileOperation = "hwnd hwndOwner;uint wFunc;ptr From;ptr To;" & _
"dword Flags;int AnyOperationAborted;" & _
"hwnd NameMapping;ptr ProgressTitle"
$tFileOperation = DllStructCreate($tagSHFileOperation)
$From = DllStructCreate("wchar[" & StringLen($mu) + 2 & "]")
DllStructSetData($From, 1, $mu)
$pFrom = DllStructGetPtr($From)
$To = DllStructCreate("wchar[" & StringLen($sTo) + 2 & "]")
DllStructSetData($To, 1, $sTo)
$pTo = DllStructGetPtr($To)
DllStructSetData($tFileOperation, 1, 0)
DllStructSetData($tFileOperation, 2, 0x2) ; $fo_copy = 0x2
DllStructSetData($tFileOperation, "From", $pFrom)
DllStructSetData($tFileOperation, "To", $pTo)
DllStructSetData($tFileOperation, "Flags", 0x40) ; $fof_allowundo = 0x40
DllCall("shell32.dll", "int", "SHFileOperationW", _
"ptr", DllStructGetPtr($tFileOperation))
EndIf
EndFunc
;==================================================================================
Func _admin();后台管理
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("后台管理", 389, 130, 192, 124, -1, $WS_EX_ACCEPTFILES)
GUISetBkColor(0x00E9cccc) ; 将改变背景色
$Label1 = GUICtrlCreateLabel("歌曲名字:", 8, 12, 69, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("歌曲字母:", 233, 12, 69, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("歌曲演唱:", 8, 42, 69, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("歌曲专集:", 192, 42, 69, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("歌曲地址:", 8, 72, 69, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Name = GUICtrlCreateInput("", 72, 8, 150, 21)
$zm = GUICtrlCreateInput("", 296, 8, 81, 21)
$Singer = GUICtrlCreateInput("", 72, 39, 115, 21)
$Album = GUICtrlCreateInput("", 262, 39, 115, 21)
$url = GUICtrlCreateInput("", 69, 69, 310, 21)
GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; 允许拖放
$Button1 = GUICtrlCreateButton("添加歌曲", 8, 96, 75, 25, 0)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("建数据库", 304, 96, 75, 25, 0)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUISetState(@SW_DISABLE,$Form1)
GUISetState(@SW_SHOW,$Form2)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
GUISetState(@SW_HIDE,$Form2)
GUISetState(@SW_ENABLE,$Form1)
WinActivate($Form1)
ExitLoop
Case $Button1;写入
if FileExists($datadir) Then
$zm1=GUICtrlRead($zm)
$Name1=GUICtrlRead($Name)
$Singer1=GUICtrlRead($Singer)
$Album1=GUICtrlRead($Album)
$url1=GUICtrlRead($url)
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & $datadir & ";Jet Oledb:Database Password=" & $acc_pwd)
$x=0
While 1
$x+=1
if $x >1 Then ExitLoop
$addfld.Execute("insert into musiclist (Name,zm,Singer,Album,url) values('"&$Name1&"','"&$zm1&"','"&$Singer1&"','"&$Album1&"','"&$url1&"')")
WEnd
$addfld.close
MsgBox(4096, "提示:"," 成功写入数据库!")
Else
MsgBox(64,"提示","你还没有数据库",5)
EndIf
Case $Button2
if not FileExists($datadir) Then
$newMdb = ObjCreate("ADOX.Catalog")
$newMdb.Create("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $datadir)
$newmdb.ActiveConnection.Close;建数据库
$addtbl = ObjCreate("ADODB.Connection")
$addTbl.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $datadir)
$addTbl.Execute("CREATE TABLE " & $Table)
;$addTbl.Execute("CREATE TABLE " & $Table1)
$addtbl.Close;建表
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $datadir)
$addfld.Execute("ALTER TABLE " & $Table & " ADD id identity(1, 1) primary key, Name char,zm char, Singer char, Album char, url char");id identity(1, 1) primary key为自动编号和主键
;$addfld.Execute("ALTER TABLE " & $Table1 & " ADD id identity(1, 1) primary key,Name char ,zm int ,Singer char,Album char,url char")
$addfld.Close;建列表名
MsgBox(64,"提示","建立数据库成功",5)
Else
MsgBox(64,"提示","你已经建立了一个数据库了",5)
EndIf
EndSwitch
WEnd
EndFunc
[ 本帖最后由 qq82015930 于 2009-2-24 18:35 编辑 ] |
|