|
楼主 |
发表于 2018-8-4 02:03:22
|
显示全部楼层
又更新了..當然還是還沒寫完,放這邊給大家笑笑。
AU3 3.3.14.5
#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 <Excel.au3>
#include <FileConstants.au3>
#include <FontConstants.au3>
#include <GDIPlus.au3>
#include <GUIComboBox.au3>
#include <GUIConstantsEx.au3>
#include <GUIEdit.au3>
#include <GuiImageList.au3>
#include <GUIListBox.au3>
#Include <GuiListView.au3>
#include <GuiStatusBar.au3>
#include <ListViewConstants.au3>
#include <MsgBoxConstants.au3>
#include <ScreenCapture.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>
#include <WinAPIEx.au3>
#include <WindowsConstants.au3>
Opt("TrayIconHide", 1) ;0 = 顯示托盤圖標, 1 = 隱藏托盤圖標
Opt('MustDeclareVars', 1) ;0 = 變量不需預先聲明, 1 = 變量必需預先聲明
Opt("GUICloseOnESC", 0) ;0 = 點擊 Esc 鍵不關閉, 1 = 點擊 Esc 鍵關閉
Global $aRow, $hQuery ;資料庫查詢
Global $Form1 ,$selector_item1, $selector_item2, $q
Global $Checkbox1, $Date1, $Date2, $hlist, $Input1, $nwMsg
Global $Button1, $Button2, $Button3, $Button4, $Button5, $Button6, $Button7, $Button8
Global $Combo_1, $Combo_2, $Combo_3, $Combo_4, $Combo_5
Global $g_idListView, $hEdit, $hFont, $iHeight = 20
Global $SQLite_Data_Path = "assets.sqlite" ;sql資料庫路徑及名稱
_SQLite_Startup ("sqlite3.dll", TRUE, 0) ;加載SQLite3.dll,工作目錄下需有SQLite3.dll 如果沒有就從autoit 網站下載並放入同一目錄下
If @error Then ;如果沒有SQLite3.dll檔案則顯示錯誤訊息
MsgBox($MB_SYSTEMMODAL, "SQLite 錯誤", "SQLite3.dll 不能載入,請檢查SQLite3.dll,SQLite3.def檔案是否存在同一目錄下!")
Exit ;離開程式不執行
EndIf
If Not FileExists($SQLite_Data_Path) Then ;如果無資料庫或資料庫損毀要重建則執行以下命令
Local $QUERY = MsgBox(1,"錯誤","資料庫無法打開,請檢查""Assets.sqlite""檔是否存在或是檔案已損毀,如要建立新檔請按確定,否則取消。")
If $QUERY = 1 Then
SQLCreate() ;建立新資料庫,參考SQLCreate() 功能,在下面
Exit
Else
Exit
EndIf
EndIf
Func SQLCreate() ;建立資料庫
_SQLite_Open ($SQLite_Data_Path) ;建立資料庫,資產表單
_SQLite_Exec(-1, "Create Table IF NOT Exists Data_Form (Assets_Number Text PRIMARY KEY, Assets_Category Text," & _
" Assets_Name Text, Department Text, Custodian Text, Purchase_Date Date, UpData_Date Date, Quantity Integer," & _
" Unit Text, Price Integer, Total Integer, Status Text,Storage_space Text, Comment Text);") ;資產表單建立
_SQLite_Exec(-1, "Create Table IF NOT Exists Department_Form (Department Text);") ;部門表單建立
_SQLite_Exec(-1, "Create Table IF NOT Exists Custodian_Form (Department Text, Custodian Text);") ;使用人表單建立
_SQLite_Exec(-1, "Create Table IF NOT Exists Category_Form (Assets_Category Text);") ;類別表單建立
_SQLite_Exec(-1, "Create Table IF NOT Exists Assets_Form (Assets_Category Text, Assets_Name Text, Unit Text );") ;資產表單建立
_SQLite_Exec(-1, "Create Table IF NOT Exists Transfer_Form (Transfer_Date Date, Custodian Text, Devolution Text, Assets_Name Text, Quantity Integer);") ;轉移紀錄表單建立
;_SQLite_Exec(-1, "Create Table IF NOT Exists Consumption_Form ( Consumption_Date Date, Assets_name Text, Custodian Text, Use Integer, Unit Text, Quantity Integer);") ;消耗表單建
_SQLite_Close (-1) ;關閉資料庫
_SQLite_Shutdown ()
MsgBox(0,"資料庫","資料庫已建立,請重新執行程式")
Exit
EndFunc
_SQLite_Open ($SQLite_Data_Path) ;讀取資料庫,名稱為$SQLite_Data_Path 變數名稱
$Form1 = GUICreate("資產管理系統", 801, 601, -1, -1) ;視窗名稱
GUICtrlCreateLabel("資產類別:", 15, 15, 60, 17)
$Combo_1 = GUICtrlCreateCombo("", 75, 10, 100, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlCreateLabel("資產名稱:", 220, 15, 60, 17)
$Combo_2 = GUICtrlCreateCombo("", 280, 10, 100, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlCreateLabel("部門:", 412, 15, 36, 17)
$Combo_3 = GUICtrlCreateCombo("", 450, 10, 100, 30, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlCreateLabel("使用人:", 570, 15, 48, 17)
$Combo_4 = GUICtrlCreateCombo("", 620, 10, 100, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
$Checkbox1 = GUICtrlCreateCheckbox("按購置日期:", 15, 53, 90, 17)
$Date1 = GUICtrlCreateDate("", 105, 50, 105, 21,$DTS_SHORTDATEFORMAT)
Local $sStyle = "yyyy-MM-dd"
GUICtrlSendMsg($Date1, $DTM_SETFORMATW, 0, $sStyle)
GUICtrlCreateLabel("到", 220, 55, 16, 17)
$Date2 = GUICtrlCreateDate("", 240, 50, 105, 21,$DTS_SHORTDATEFORMAT)
GUICtrlSendMsg($Date2, $DTM_SETFORMATW, 0, $sStyle)
GUICtrlCreateLabel("資產狀況:", 370, 55, 60, 17)
$Combo_5 = GUICtrlCreateCombo("", 430, 50, 50, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
Global $Status = "全部|使用|閒置|維修|報廢|借出|消耗|其他"
GUICtrlSetData($Combo_5, $Status )
GUICtrlCreateLabel("資產編號:", 500, 55, 60, 17)
$Input1 = GUICtrlCreateInput("", 560, 50, 160, 21)
$Button1 = GUICtrlCreateButton("查詢", 20, 100, 75, 25)
$Button2 = GUICtrlCreateButton("編輯", 110, 100, 75, 25)
$Button3 = GUICtrlCreateButton("資產登記", 205, 100, 80, 25)
$Button4 = GUICtrlCreateButton("匯出目前內容", 305, 100, 85, 25)
$Button5 = GUICtrlCreateButton("匯總", 410, 100, 75, 25)
$Button6 = GUICtrlCreateButton("刪除", 505, 100, 75, 25)
$Button7 = GUICtrlCreateButton("設置", 600, 100, 75, 25)
$Button8 = GUICtrlCreateButton("檢視圖片", 695, 100, 80, 25)
Global $ListView1 = GUICtrlCreateListView("", 0, 150, 800, 450)
_GUICtrlListView_AddColumn ($ListView1,"資產編號",100)
_GUICtrlListView_AddColumn ($ListView1,"資產類別",100)
_GUICtrlListView_AddColumn ($ListView1,"資產名稱",100)
_GUICtrlListView_AddColumn ($ListView1,"部門",70)
_GUICtrlListView_AddColumn ($ListView1,"使用人",70)
_GUICtrlListView_AddColumn ($ListView1,"購置日期",80)
_GUICtrlListView_AddColumn ($ListView1,"數量",50)
_GUICtrlListView_AddColumn ($ListView1,"單位",50)
_GUICtrlListView_AddColumn ($ListView1,"單價",60)
_GUICtrlListView_AddColumn ($ListView1,"總值",70)
_GUICtrlListView_AddColumn ($ListView1,"狀態",50)
_GUICtrlListView_AddColumn ($ListView1,"儲位",70)
_GUICtrlListView_AddColumn ($ListView1,"備註",100)
$ListView1 = GUICtrlGetHandle($ListView1) ;回傳控件項目句柄,針對項目雙擊後選擇其它功能
_Combo_1() ;自動匯入資產類別
_Combo_3() ;自動匯入部門名稱
Global $hFont = _WinAPI_CreateFont($iHeight - 5, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, '新細明體') ;建立點擊項目後之顯示方式
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') ;註冊win消息ID-訊息通知,轉WM_NOTIFY函數處理,用於項目雙擊控制
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND') ;註冊win消息ID-訊息命令,轉WM_COMMAND函數處理,用於項目雙擊後,後續處理
GUISetState(@SW_SHOW,$Form1) ;GUI 顯示
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
_SQLite_Close(-1)
_SQLite_Shutdown()
EXIT
Case $Combo_1 ;自動帶入資產名稱
Local $idx=_GUICtrlComboBox_GetCurSel($Combo_1) - 1
If $idx >= 0 Then
Local $Str="全部" , $c = 0
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Assets_Name) FROM Assets_Form WHERE Assets_Category = '" & GUICtrlRead($Combo_1)& "';", $aRow) ;
Local $ary[Int($aRow[0])]
_SQLite_Query(-1, "SELECT Assets_Name FROM Assets_Form WHERE Assets_Category = '" & GUICtrlRead($Combo_1)& "';", $hQuery) ;查詢資料,並存入$hQuery 變數
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$ary[$c] = $aRow[0]
$c = $c + 1
WEnd
For $i=0 To UBound($ary)-1
$Str &= "|" & $ary[$i]
Next
GUICtrlSetData($Combo_2,"")
GUICtrlSetData($Combo_2, $Str )
Else
GUICtrlSetData($Combo_2,"")
EndIf
Case $Combo_3 ;自動帶入使用人名稱
Local $idx=_GUICtrlComboBox_GetCurSel($Combo_3) - 1
If $idx >= 0 Then
Local $Str = "", $c = 0
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Custodian) FROM Custodian_Form WHERE Department = '" & GUICtrlRead($Combo_3)& "';", $aRow) ;
Local $ary[Int($aRow[0])]
_SQLite_Query(-1, "SELECT Custodian FROM Custodian_Form WHERE Department = '" & GUICtrlRead($Combo_3)& "';", $hQuery) ;查詢資料,並存入$hQuery 變數
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$ary[$c] = $aRow[0]
$c = $c + 1
WEnd
For $i=0 To UBound($ary)-1
$Str &= "|" & $ary[$i]
Next
GUICtrlSetData($Combo_4,"")
GUICtrlSetData($Combo_4, $Str )
Else
GUICtrlSetData($Combo_4,"")
EndIf
Case $Button1 ;搜尋
_GetRecord()
Case $Button2
Local $idary=_GUICtrlListView_GetSelectedIndices($ListView1, True)
If $idary[0] = 1 Then
;MsgBox(48,"提示!","已選擇一個項目!" & $idary[1])
_edit($idary[1])
Else
MsgBox(48,"提示!","沒有選中需要修改的專案!")
EndIf
Case $Button3 ;建立資產資料
_newdata()
Case $Button4 ;輸出當前資料至excel
_To_Excel()
Case $Button5 ;匯總
_H_Z()
Case $Button6 ;資料刪除
Local $Input1 = InputBox("資料刪除","請輸入資產編號","")
If @error <> 1 Then
_SQLite_QuerySingleRow(-1, "SELECT Assets_Number FROM Data_Form WHERE Assets_Number = '" & $Input1 & "';", $aRow) ;
If $aRow[0] <> "" Then
_SQLite_Exec(-1, "DELETE FROM Data_Form WHERE Assets_Number = '" & $Input1 & "';") ;刪除該筆資料
MsgBox(0,"提示!","資產編號:" & $Input1 & "已刪除")
Else
MsgBox(0,"提示","無此筆資產編號,請重新輸入")
EndIf
EndIf
Case $Button7
_Setting() ;設置
Case $Button8
_content()
EndSwitch
WEnd
Func _GetRecord() ;查詢,顯示
_GUICtrlListView_DeleteAllItems($ListView1)
If GUICtrlRead($Input1) <> "" Then
Local $ArrayData[1][13]
_SQLite_QuerySingleRow(-1, "SELECT * FROM Data_Form WHERE Assets_Number = '" & GUICtrlRead($Input1) & "' ;", $aRow) ;查詢資料,並存入$hQuery 變數
If $aRow[0] <> "" Then
For $i = 0 To 12
$ArrayData[0][$i] = $aRow[$i]
Next
_GUICtrlListView_AddArray($ListView1,$ArrayData)
Else
MsgBox(0,"提示!","無此筆資產編號,請重新輸入。")
EndIf
Else
Local $Sqlstr="Select Count(*) From Data_Form where Assets_Number Like '%' "
Local $index=_GUICtrlComboBox_GetCurSel($Combo_1) - 1
If $index >= 0 Then $Sqlstr &= "And Assets_Category ='" & GUICtrlRead($Combo_1) & "'" ;加入資產類別
$index=_GUICtrlComboBox_GetCurSel($Combo_2) - 1
If $index >= 0 Then $Sqlstr &= "And Assets_Name ='" & GUICtrlRead($Combo_2) & "'" ;加入資產名稱
$index=_GUICtrlComboBox_GetCurSel($Combo_3) - 1
If $index >= 0 Then $Sqlstr &= "And Department ='" & GUICtrlRead($Combo_3) & "'" ;加入部門
$index=_GUICtrlComboBox_GetCurSel($Combo_4) - 1
If $index >= 0 Then $Sqlstr &= "And Custodian ='" & GUICtrlRead($Combo_4) & "'" ;加入使用人
$index=_GUICtrlComboBox_GetCurSel($Combo_5) - 1
If $index >= 0 Then $Sqlstr &= "And Status ='" & GUICtrlRead($Combo_5) & "'" ;加入使用人
If BitAND(GUICtrlRead($Checkbox1),$GUI_CHECKED) Then
$Sqlstr &= " And datetime(Purchase_Date) >= datetime('" & GUICtrlRead ($Date1) & _
"') AND datetime(Purchase_Date) <= datetime('" & GUICtrlRead ($Date2) & "')"
EndIf
_SQLite_QuerySingleRow(-1, $Sqlstr & ";" , $aRow) ;取出筆數
Local $ArrayData[$aRow[0]][13] ;設定陣列
$Sqlstr="Select * From Data_Form where Assets_Number Like '%' "
$index=_GUICtrlComboBox_GetCurSel($Combo_1) - 1
If $index >= 0 Then $Sqlstr &= "And Assets_Category ='" & GUICtrlRead($Combo_1) & "'" ;加入資產類別
$index=_GUICtrlComboBox_GetCurSel($Combo_2) - 1
If $index >= 0 Then $Sqlstr &= "And Assets_Name ='" & GUICtrlRead($Combo_2) & "'" ;加入資產名稱
$index=_GUICtrlComboBox_GetCurSel($Combo_3) - 1
If $index >= 0 Then $Sqlstr &= "And Department ='" & GUICtrlRead($Combo_3) & "'" ;加入部門
$index=_GUICtrlComboBox_GetCurSel($Combo_4) - 1
If $index >= 0 Then $Sqlstr &= "And Custodian ='" & GUICtrlRead($Combo_4) & "'" ;加入使用人
$index=_GUICtrlComboBox_GetCurSel($Combo_5) - 1
If $index >= 0 Then $Sqlstr &= "And Status ='" & GUICtrlRead($Combo_5) & "'" ;加入使用人
If BitAND(GUICtrlRead($Checkbox1),$GUI_CHECKED) Then
$Sqlstr &= " And datetime(Purchase_Date) >= datetime('" & GUICtrlRead ($Date1) & _
"') AND datetime(Purchase_Date) <= datetime('" & GUICtrlRead ($Date2) & "')"
EndIf
Local $c = 0
_SQLite_Query(-1, $Sqlstr, $hQuery) ;查詢資料,並存入$hQuery 變數
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$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]
$ArrayData[$c][5]=$aRow[5]
$ArrayData[$c][6]=$aRow[7]
$ArrayData[$c][7]=$aRow[8]
$ArrayData[$c][8]=$aRow[9]
$ArrayData[$c][9]=$aRow[10]
$ArrayData[$c][10]=$aRow[11]
$ArrayData[$c][11]=$aRow[12]
$ArrayData[$c][12]=$aRow[13]
$c = $c + 1
WEnd
_GUICtrlListView_AddArray($ListView1,$ArrayData)
EndIf
EndFunc
Func _To_Excel() ;匯出目前內容到excel
Dim $colname[13]=["資產編號","資產類別","資產名稱","部門","使用人","購買日期","數量","單位","單價","總價","資產狀況","儲位","備註"]
Local $aItem
Local $ListColumnCount = _GUICtrlListView_GetColumnCount($ListView1) ;讀取ListView表單項目數
Local $ListRowCount = _GUICtrlListView_GetItemCount($ListView1) ;讀取ListView 列數
IF $ListRowCount > 0 THEN ;當列數大於0 執行以下
Dim $ItemArray[1][$ListColumnCount] ;設定二維陣列
For $i = 0 To $ListRowCount
$aItem = _GUICtrlListView_GetItemTextString($ListView1, $i)
_ArrayAdd($ItemArray, $aItem, 0)
Next
_ArrayDelete($ItemArray, 0)
;_ArrayDisplay($ItemArray)
Sleep(500)
Local $oAppl = _Excel_Open()
Local $oWorkbook = _Excel_BookNew($oAppl)
Local $aArray2D[1][19] = [["資產編號","資產類別","資產名稱","部門","使用人","購買日期","數量","單位","單價","總價","資產狀況","儲位","備註"]]
_Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aArray2D, "A1")
$oWorkbook.activesheet.cells(2, 1).resize($ListRowCount, $ListColumnCount) = $oWorkbook.application.transpose($ItemArray)
MsgBox(0,"提示!","EXCEL匯出完成!")
EndIf
EndFunc
Func _edit($q)
;MsgBox(0,"$q",$q)
Local $aItem = _GUICtrlListView_GetItemText($ListView1, $q,0)
Local $F2 = GUICreate("資產更新", 415, 390, -1, -1)
GUICtrlCreateLabel("資產編號:", 10, 20, 55, 17)
Local $Input_1 = GUICtrlCreateInput("", 65, 18, 130, 17,$ES_READONLY)
GUICtrlSetColor(-1, 0x800080)
GUICtrlCreateLabel("資產類別:", 210, 20, 55, 17)
Local $Input_2 = GUICtrlCreateInput("", 265, 18, 130, 17,$ES_READONLY)
GUICtrlSetColor(-1, 0x800080)
GUICtrlCreateLabel("資產名稱:", 10, 50, 55, 17)
Local $Input_3 = GUICtrlCreateInput("", 65, 48, 130, 17,$ES_READONLY)
GUICtrlSetColor(-1, 0x800080)
GUICtrlCreateLabel("購置日期:", 210, 50, 55, 17)
Local $Input_4 = GUICtrlCreateInput("", 265, 48, 130, 17,$ES_READONLY)
GUICtrlSetColor(-1, 0x800080)
GUICtrlCreateLabel("單 價:", 10, 110, 55, 17)
Local $Input_5 = GUICtrlCreateInput("", 65, 108, 70, 17,$ES_NUMBER)
GUICtrlCreateLabel("更改日期:", 210, 110, 55, 17)
Local $Date_1 = GUICtrlCreateDate("", 265, 105, 110, 21)
GUICtrlCreateLabel("現有數量:", 160, 140, 55, 17)
Local $Input_6 = GUICtrlCreateInput("", 215, 138, 50, 17,$ES_READONLY)
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlCreateLabel("總值:", 280, 140, 30, 17)
Local $Input_7 = GUICtrlCreateInput("", 310, 138, 80, 17,$ES_READONLY)
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlCreateLabel("儲位:", 100, 170, 30, 17)
Local $Input_8 = GUICtrlCreateInput("", 130, 168, 100, 17)
GUICtrlCreateLabel("備註:", 250, 170, 31, 17)
Local $Edit_1 = GUICtrlCreateEdit("", 10, 190, 300, 70)
GUICtrlCreateLabel("轉移記錄:", 10, 265, 55, 17)
Local $L_2 = GUICtrlCreateListView("", 10, 285, 390, 95)
_GUICtrlListView_AddColumn ($L_2,"時間",90)
_GUICtrlListView_AddColumn ($L_2,"從",100)
_GUICtrlListView_AddColumn ($L_2,"到",100)
_GUICtrlListView_AddColumn ($L_2,"資產",100)
Local $Button_1 = GUICtrlCreateButton("修改資產", 330, 160, 75, 25)
Local $Button_2 = GUICtrlCreateButton("轉移資產", 330, 190, 75, 25)
Local $Button_3 = GUICtrlCreateButton("刪除資產", 330, 220, 75, 25)
Local $Button_4 = GUICtrlCreateButton("刪除記錄", 330, 250, 75, 25)
_SQLite_QuerySingleRow(-1, "SELECT * FROM Data_Form WHERE Assets_Number = '" & $aItem & "' ;", $aRow) ;查詢資料,並存入$hQuery 變數
If $aRow[0] <> "" Then
GUICtrlSetData($Input_1,$aRow[0])
GUICtrlSetData($Input_2,$aRow[1])
GUICtrlSetData($Input_3,$aRow[2])
GUICtrlSetData($Input_4,$aRow[5])
GUICtrlSetData($Input_5,$aRow[9])
GUICtrlSetData($Input_6,$aRow[7])
GUICtrlSetData($Input_7,$aRow[10])
GUICtrlSetData($Input_8,$aRow[12])
GUICtrlSetData($Edit_1,$aRow[13])
EndIf
GUICtrlCreateLabel("部 門:", 10, 80, 55, 17)
Local $Combo_F2_1 = GUICtrlCreateCombo($aRow[3], 65, 75, 130, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlCreateLabel("使 用 人:", 210, 80, 55, 17)
Local $Combo_F2_2 = GUICtrlCreateCombo($aRow[4], 265, 75, 100, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlCreateLabel("狀態:", 10, 170, 30, 17)
Local $Combo_F2_4 = GUICtrlCreateCombo($aRow[11], 40, 165, 50, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
Local $Status_F2 = "使用|閒置|維修|報廢|借出|消耗|其他"
GUICtrlSetData($Combo_F2_4, $Status_F2 )
Local $numlist="1"
For $i = 2 To GUICtrlRead($Input_6)
$numlist &= "|"&$i
Next
GUICtrlCreateLabel("修改/調換數量:", 10, 140, 85, 17)
Local $Combo_F2_3 = GUICtrlCreateCombo("", 95, 136, 50, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData($Combo_F2_3, $numlist )
GUISetState(@SW_SHOW)
While 1
Local $nnMsg = GUIGetMsg()
Switch $nnMsg
Case $GUI_EVENT_CLOSE
GUIDelete($F2)
ExitLoop
Case $Input_5,$Combo_F2_3
Local $zz=Number(GUICtrlRead($Input_6)) * Number(GUICtrlRead($Combo_F2_3))
GUICtrlSetData($Input_7,$zz)
Case $Button_1 ;修改
Case $Button_2 ;轉移
Case $Button_3 ;刪除
Case $Button_4 ;刪除轉移記錄
EndSwitch
WEnd
EndFunc
Func _content() ;檢視資產圖片
If $selector_item1 <> "" Then
Local $Image_File = @ScriptDir & "\PHOTO\" & $selector_item2 & "\" & $selector_item1 & ".jpg" ;設定圖片路徑
If FileExists($Image_File) = 1 Then ;判斷檔案是否存在
ShellExecute($Image_File)
$selector_item1 = ""
Else
MsgBox(0,"提示!","無此資產編號圖片,請建立圖片檔案。" & @CRLF & "建立範例:檔案目錄\PHOTO\資產類別名稱\資產編號.JPG")
$selector_item1 = ""
EndIf
EndIf
EndFunc
Func _H_Z() ;匯總窗口
Local $F5 = GUICreate("匯總導出", 364, 220, 286, 218)
GUICtrlSetColor(-1, 0x800080)
GUICtrlCreateLabel("選擇需要匯出表單的範圍", 20, 8, 246, 25)
GUICtrlSetFont(-1, 14, 400, 0, "細明體")
GUICtrlCreateLabel("部門:", 25, 40, 31, 17)
Local $CCB1 = GUICtrlCreateCombo("", 25, 60, 145, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlCreateLabel("員工:", 200, 40, 31, 17)
Local $CCB2 = GUICtrlCreateCombo("", 200, 60, 145, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
Local $BBT1 = GUICtrlCreateButton("匯出", 50, 100, 75, 25)
Local $BBT2 = GUICtrlCreateButton("選擇目錄", 150, 100, 75, 25)
Local $BBT3 = GUICtrlCreateButton("關閉", 250, 100, 75, 25)
Local $Lmsg = GUICtrlCreateLabel("匯出目錄:"&@ScriptDir, 25, 135, 300, 40)
GUICtrlSetData($CCB1, "" )
Local $Str="全部" , $c = 0
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Department) FROM Department_Form WHERE Department LIKE '%';", $aRow) ;
Local $ary[Int($aRow[0])]
_SQLite_Query(-1, "SELECT * FROM Department_Form WHERE Department LIKE '%' ;", $hQuery) ;查詢資料,並存入$hQuery 變數
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$ary[$c] = $aRow[0]
$c = $c + 1
WEnd
For $i=0 To UBound($ary)-1
$Str &= "|" & $ary[$i]
Next
GUICtrlSetData($CCB1, $Str,"全部" )
Local $fdir=@ScriptDir
GUISetState(@SW_SHOW)
While 1
Local $nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE,$BBT3
GUIDelete($F5)
ExitLoop
Case $BBT1 ;匯出資料
If GUICtrlRead($CCB1) = "全部" Then ;匯出全部資料
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Department) FROM Data_Form WHERE Department LIKE '%';", $aRow) ;建立全部資料陣列數量
Local $a = $aRow[0]
Local $ArrayData[$a][9]
Local $c = 0
_SQLite_Query(-1, "SELECT * FROM Data_Form WHERE Department LIKE '%' ;", $hQuery) ;查詢資料,並存入$hQuery 變數
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$ArrayData[$c][0]=$aRow[2] ;資產名稱
$ArrayData[$c][1]=$aRow[6] ;數量
$ArrayData[$c][2]=$aRow[7] ;單位
$ArrayData[$c][3]=$aRow[8] ;單價
$ArrayData[$c][4]=$aRow[9] ;總金額
$ArrayData[$c][5]=$aRow[5] ;購買日期
$ArrayData[$c][6]=$aRow[4] ;保管人
$ArrayData[$c][7]=$aRow[10] ;資產狀況。
$ArrayData[$c][8]=$aRow[12] ;備註
$c = $c + 1
WEnd
;_ArrayDisplay($ArrayData)
Local $sFilePath1 = @ScriptDir & "\mb.xls" ;這個檔應該已經存在
;MsgBox(0,'',$sFilePath1)
Local $oExcel = _Excel_Open()
Local $oExcel2 = _Excel_BookOpen($oExcel, $sFilePath1) ;開啟MB.XLS檔案
If @error = 1 Then
MsgBox(16, "錯誤!", "無法創建物件!")
_Excel_Close($oExcel)
ExitLoop
ElseIf @error = 2 Then
MsgBox(16, "錯誤!", "範本檔'mb.xls'不存在!")
_Excel_Close($oExcel)
ExitLoop
EndIf
$a = 4 + $a - 1
Local $inset = "4:" & $a
_Excel_RangeInsert($oExcel2.Worksheets(1), $inset )
_Excel_RangeWrite($oExcel2, $oExcel2.Activesheet, $ArrayData, "A4")
ElseIf GUICtrlRead($CCB1) <> "全部" And GUICtrlRead($CCB2) = "全部" Then ;匯出單一部門全部人資料
If GUICtrlRead($CCB2) = "全部" Then ;匯出全部資料
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Department) FROM Data_Form WHERE Department ='" & GUICtrlRead($CCB1) & "';'", $aRow) ;建立全部資料陣列數量
Local $a = $aRow[0]
Local $ArrayData[$a][9]
Local $c = 0
_SQLite_Query(-1, "SELECT * FROM Data_Form WHERE Department ='" & GUICtrlRead($CCB2) & "';'", $hQuery) ;查詢資料,並存入$hQuery 變數
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$ArrayData[$c][0]=$aRow[2] ;資產名稱
$ArrayData[$c][1]=$aRow[6] ;數量
$ArrayData[$c][2]=$aRow[7] ;單位
$ArrayData[$c][3]=$aRow[8] ;單價
$ArrayData[$c][4]=$aRow[9] ;總金額
$ArrayData[$c][5]=$aRow[5] ;購買日期
$ArrayData[$c][6]=$aRow[4] ;保管人
$ArrayData[$c][7]=$aRow[10] ;資產狀況。
$ArrayData[$c][8]=$aRow[12] ;備註
$c = $c + 1
WEnd
;_ArrayDisplay($ArrayData)
Local $sFilePath1 = @ScriptDir & "\mb.xls" ;這個檔應該已經存在
;MsgBox(0,'',$sFilePath1)
Local $oExcel = _Excel_Open()
Local $oExcel2 = _Excel_BookOpen($oExcel, $sFilePath1) ;開啟MB.XLS檔案
If @error = 1 Then
MsgBox(16, "錯誤!", "無法創建物件!")
_Excel_Close($oExcel)
ExitLoop
ElseIf @error = 2 Then
MsgBox(16, "錯誤!", "範本檔'mb.xls'不存在!")
_Excel_Close($oExcel)
ExitLoop
EndIf
$a = 4 + $a - 1
Local $inset = "4:" & $a
_Excel_RangeInsert($oExcel2.Worksheets(1), $inset )
_Excel_RangeWrite($oExcel2, $oExcel2.Activesheet, $ArrayData, "A4")
EndIf
Else
MsgBox(0,"","單一使用人匯出")
EndIf
GUICtrlSetData($Lmsg,"全部導出完成!")
Case $BBT2 ;選擇目錄
$fdir=FileSelectFolder("選擇匯出目錄.","")
If @error Then
$fdir=@ScriptDir
EndIf
GUICtrlSetData($Lmsg,"匯出目錄:"&$fdir)
Case $CCB1 ;自動匯入員工
Local $idx=_GUICtrlComboBox_GetCurSel($CCB1) - 1
If $idx >= 0 Then
Local $Str = "全部", $c = 0
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Custodian) FROM Custodian_Form WHERE Department = '" & GUICtrlRead($CCB1)& "';", $aRow) ;
Local $ary[Int($aRow[0])]
_SQLite_Query(-1, "SELECT Custodian FROM Custodian_Form WHERE Department = '" & GUICtrlRead($CCB1)& "';", $hQuery) ;查詢資料,並存入$hQuery 變數
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$ary[$c] = $aRow[0]
$c = $c + 1
WEnd
For $i=0 To UBound($ary)-1
$Str &= "|" & $ary[$i]
Next
GUICtrlSetData($CCB2,"")
GUICtrlSetData($CCB2, $Str )
Else
GUICtrlSetData($CCB2,"")
EndIf
EndSwitch
WEnd
EndFunc
Func _HuiZong1($dir,$a,$b="");未完成
EndFunc
#CS
Func _HuiZong($dir,$a,$b="") ;匯總資訊
Local $sFilePath1 = @ScriptDir & "\mb.xls" ;這個檔應該已經存在
Local $sqlstr, $znum = 0, $zp = 0
Local $oExcel = _ExcelBookOpen($sFilePath1,0,True)
If @error = 1 Then
MsgBox(16, "錯誤!", "無法建立物件!")
Return False
ElseIf @error = 2 Then
MsgBox(16, "錯誤!", "範例檔'mb.xls'不存在!")
Return False
EndIf
$sqlstr="select 資產名稱,單位,數量,單價,使用人,購置日期,狀態,總值,備註 from 資產記錄 where 部門='"&$a&"'"
If $b <> "" Then $sqlstr&=" and 使用人='"&$b&"'"
Local $DB_HZ=_SelectData($sqlstr)
If Not IsArray($DB_HZ) Then
;MsgBox(0,"提示!","沒有“"&$a&"-"&$b&"”的資產記錄!")
Return False
EndIf
Local $colnum=UBound($DB_HZ)
_ExcelWriteCell($oExcel,$a&" "&$b,2,3) ;寫入 部門 資訊
;#####################################################
For $i=0 To $colnum-1 ;格式化日期, 計算匯總金額
$DB_HZ[$i][5] = StringLeft($DB_HZ[$i][5],8)
$znum += Number($DB_HZ[$i][2])
$zp += Number($DB_HZ[$i][7])
Next
_ExcelWriteCell($oExcel,$znum,6,2)
_ExcelWriteCell($oExcel,"¥:"&$zp&"元",6,4)
_ExcelRowInsert($oExcel, 5, $colnum)
_ExcelWriteSheetFromArray($oExcel,$DB_HZ,4,1,0,0) ;添加資產記錄
;###################################################
If $b = "" Then
$sqlstr="select 日期,從,到,轉移資產 from 轉移記錄 where 從 like '%"&$a&":%' or 到 like '%"&$a&":%'"
Else
$sqlstr="select 日期,從,到,轉移資產 from 轉移記錄 where 從 like '%"&$a&":"&$b&"%' or 到 like '%"&$a&":"&$b&"%'"
EndIf
Local $DB_ZY=_SelectData($sqlstr)
If IsArray($DB_ZY) Then
$col2=UBound($DB_ZY)
$colx=$colnum+9
_ExcelRowInsert($oExcel, $colx, $col2) ;插入行
For $i=0 To $col2-1
$DB_ZY[$i][0] = StringLeft($DB_ZY[$i][0],8)
Next
For $i=$colx To $colx+$col2-1 ;合併單格
_MergeCells($oExcel,$i,1,1)
_MergeCells($oExcel,$i,3,2)
_MergeCells($oExcel,$i,6,2)
Next
_addzy_excel($oExcel,$DB_ZY,$colx)
EndIf
_ExcelBookSaveAs($oExcel,$dir, "xls", 0, 1)
_ExcelBookClose($oExcel)
Return True
EndFunc
#CE
Func _Combo_1() ;資產Combo自動載入
GUICtrlSetData($Combo_1, "")
Local $Str="全部" , $c = 0
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Assets_Category) FROM Category_Form WHERE Assets_Category LIKE '%';", $aRow) ;
Local $ary[Int($aRow[0])]
_SQLite_Query(-1, "SELECT * FROM Category_Form WHERE Assets_Category LIKE '%' ;", $hQuery) ;查詢資料,並存入$hQuery 變數
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$ary[$c] = $aRow[0]
$c = $c + 1
WEnd
For $i=0 To UBound($ary)-1
$Str &= "|" & $ary[$i]
Next
GUICtrlSetData($Combo_1, $Str )
EndFunc
Func _Combo_3() ;部門Combo自動載入
GUICtrlSetData($Combo_3, "" )
Local $Str="全部" , $c = 0
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Department) FROM Department_Form WHERE Department LIKE '%';", $aRow) ;
Local $ary[Int($aRow[0])]
_SQLite_Query(-1, "SELECT * FROM Department_Form WHERE Department LIKE '%' ;", $hQuery) ;查詢資料,並存入$hQuery 變數
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$ary[$c] = $aRow[0]
$c = $c + 1
WEnd
For $i=0 To UBound($ary)-1
$Str &= "|" & $ary[$i]
Next
GUICtrlSetData($Combo_3, $Str )
EndFunc
Func _Setting() ;設置視窗
Local $Form_Setting = GUICreate("設置", 370, 360, -1, -1)
GUICtrlCreateLabel("部門:", 10, 15, 55, 17)
Global $List_1 = GUICtrlCreateList("", 10, 35, 120, 97) ;部門欄位
GUICtrlSetFont(-1, 6, 400, 0, "MS Sans Serif")
Local $Button_del_1 = GUICtrlCreateButton("刪除", 135, 105, 30, 20)
Local $Input_1 = GUICtrlCreateInput("", 10, 140, 120, 21) ;輸入新增部門名稱
Local $Button_new_1 = GUICtrlCreateButton("新增", 135, 140, 30, 20)
GUICtrlCreateLabel("使用人:", 200, 15, 55, 17)
Local $List_2 = GUICtrlCreateList("", 200, 35, 120, 97)
GUICtrlSetFont(-1, 6, 400, 0, "MS Sans Serif")
Local $Button_del_2 = GUICtrlCreateButton("刪除", 325, 105, 30, 20)
Local $Input_2 = GUICtrlCreateInput("", 200, 140, 120, 21)
Local $Button_new_2 = GUICtrlCreateButton("新增", 325, 140, 30, 20)
GUICtrlCreateLabel("類別:", 10, 180, 55, 17)
Global $List_3 = GUICtrlCreateList("", 10, 200, 120, 97)
GUICtrlSetFont(-1, 6, 400, 0, "MS Sans Serif")
Local $Button_del_3 = GUICtrlCreateButton("刪除", 135, 270, 30, 20)
Local $Input_3 = GUICtrlCreateInput("", 10, 305, 120, 21)
Local $Button_new_3 = GUICtrlCreateButton("新增", 135, 305, 30, 20)
GUICtrlCreateLabel("資產名稱:", 180, 180, 55, 17)
Local $List_4 = GUICtrlCreateListView ("", 180, 200, 140, 97)
_GUICtrlListView_AddColumn ($List_4,"資產名稱",85)
_GUICtrlListView_AddColumn ($List_4,"單位",40)
Global $hL4=GUICtrlGetHandle($List_4)
Local $Button_del_4 = GUICtrlCreateButton("刪除", 325, 270, 30, 20)
Global $Input_4 = GUICtrlCreateInput("", 180, 305, 110, 21)
Global $Input_5 = GUICtrlCreateInput("", 295, 305, 25, 21)
Local $Button_new_4 = GUICtrlCreateButton("新增", 325, 305, 30, 20)
Global $Str, $s
_input_1()
GUICtrlSetData($List_1,$Str,"")
_input_3()
GUICtrlSetData($List_3,$Str,"")
GUISetState(@SW_SHOW, $Form_Setting)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $Button_new_1 ;新增部門
If GUICtrlRead($Input_1) <> "" Then
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Department) FROM Department_Form WHERE Department = '" & GUICtrlRead($Input_1)&"';", $aRow) ;
If Int($aRow[0]) = 0 Then
_SQLite_Exec(-1, "Insert into Department_Form (Department) values ('" & GUICtrlRead($Input_1) & "');")
_input_1()
GUICtrlSetData($List_1,"")
GUICtrlSetData($List_1,$Str)
GUICtrlSetData($Input_1,"")
Else
MsgBox(0,"提示!","該部門已存在!")
GUICtrlSetData($Input_1,"")
EndIf
Else
MsgBox(0,"提示!","未輸入部門名稱。")
EndIf
Case $Button_del_1 ;刪除部門
If GUICtrlRead($List_1) <> "" Then
Local $q = MsgBox(1,"提示!","該部門刪除會連帶使用人一併刪除!")
If $q = 1 Then
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Department) FROM Department_Form WHERE Department = '" & GUICtrlRead($List_1)&"';", $aRow) ;
If Int($aRow[0]) <> 0 Then
_SQLite_Exec(-1, "DELETE FROM Custodian_Form WHERE Department = '" & GUICtrlRead($List_1) & "';") ;
_SQLite_Exec(-1, "DELETE FROM Department_Form WHERE Department = '" & GUICtrlRead($List_1) & "';") ;
_input_1()
GUICtrlSetData($List_1,"")
GUICtrlSetData($List_1,$Str)
GUICtrlSetData($List_2,"")
EndIf
EndIf
EndIf
Case $Button_new_2 ;新增使用人
If GUICtrlRead($Input_2) <> "" AND GUICtrlRead($List_1) <> "" Then
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Custodian) FROM Custodian_Form WHERE Custodian = '" & GUICtrlRead($Input_2)&"';", $aRow) ;
If Int($aRow[0]) = 0 Then
_SQLite_Exec(-1, "Insert into Custodian_Form (Department,Custodian) values ('" & GUICtrlRead($List_1) & "','" & GUICtrlRead($Input_2) & "');")
_input_2()
GUICtrlSetData($List_2,"")
GUICtrlSetData($List_2,$Str)
GUICtrlSetData($Input_2,"")
Else
MsgBox(0,"提示!","該人員已存在,如有同名請設置別名,如“張三1”")
EndIf
Else
MsgBox(0,"提示!","尚未點選部門或輸入使用人姓名,請點選部門及輸入使用人姓名。")
EndIf
Case $Button_del_2 ;刪除使用人
If GUICtrlRead($List_2) <> "" Then ;確認是否點選使用人
Local $q = MsgBox(1,"提示!","是否刪除該使用人!")
If $q = 1 Then
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Custodian) FROM Custodian_Form WHERE Custodian = '" & GUICtrlRead($List_2)&"';", $aRow) ;
If Int($aRow[0]) <> 0 Then
_SQLite_Exec(-1, "DELETE FROM Custodian_form WHERE Custodian = '" & GUICtrlRead($List_2) & "';") ;
_input_2()
GUICtrlSetData($List_2,"")
GUICtrlSetData($List_2,$Str)
GUICtrlSetData($Input_2,"")
EndIf
EndIf
EndIf
Case $Button_new_3 ;新增類別
If GUICtrlRead($Input_3) <> "" Then
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Assets_Category) FROM Category_Form WHERE Assets_Category = '" & GUICtrlRead($Input_3)&"';", $aRow) ;
If Int($aRow[0]) = 0 Then
_SQLite_Exec(-1, "Insert into Category_Form (Assets_Category) values ('" & GUICtrlRead($Input_3) & "');")
_input_3()
GUICtrlSetData($List_3,"")
GUICtrlSetData($List_3,$Str)
GUICtrlSetData($Input_3,"")
Else
MsgBox(0,"提示!","該類別已存在!")
GUICtrlSetData($Input_1,"")
EndIf
Else
MsgBox(0,"提示!","未輸入類別名稱。")
EndIf
Case $Button_del_3 ;刪除類別
If GUICtrlRead($List_3) <> "" Then
Local $q = MsgBox(1,"提示!","該類別刪除會連帶資產名稱一併刪除!")
If $q = 1 Then
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Assets_Category) FROM Category_Form WHERE Assets_Category = '" & GUICtrlRead($List_3)&"';", $aRow) ;
If Int($aRow[0]) <> 0 Then
_SQLite_Exec(-1, "DELETE FROM Assets_Form WHERE Assets_Category = '" & GUICtrlRead($List_3) & "';") ;
_SQLite_Exec(-1, "DELETE FROM Category_Form WHERE Assets_Category = '" & GUICtrlRead($List_3) & "';") ;
_input_3()
GUICtrlSetData($List_3,"")
GUICtrlSetData($List_3,$Str)
_GUICtrlListView_DeleteAllItems($hL4)
EndIf
EndIf
EndIf
Case $Button_new_4 ;新增資產名稱
If GUICtrlRead($List_3) And GUICtrlRead($Input_4) <> "" And GUICtrlRead($Input_5) <> "" Then
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Assets_Name) FROM Assets_Form WHERE Assets_Name = '" & GUICtrlRead($Input_4)&"';", $aRow) ;
If Int($aRow[0]) = 0 Then
_SQLite_Exec(-1, "Insert into Assets_Form (Assets_Category,Assets_Name,Unit) values ('" & GUICtrlRead($List_3) & _
"','" & GUICtrlRead($Input_4) & "','" & GUICtrlRead($Input_5) & "');")
_input_4()
Else
MsgBox(0,"提示!","該資產名稱已存在,如有同名請設置別名,如“桌子1”")
GUICtrlSetData($Input_1,"")
EndIf
Else
MsgBox(0,"提示!","輸入不完全,請點選列別名稱及將資產名稱和單位填入欄位內。")
EndIf
Case $Button_del_4 ;刪除資產名稱
Local $gstr=_GUICtrlListView_GetItemText(GUICtrlGetHandle($List_4),Number(_GUICtrlListView_GetSelectedIndices(GUICtrlGetHandle($List_4))),0)
If $gstr <> "" Then
Local $q = MsgBox(1,"提示!","是否刪除該筆資產:" & $gstr)
If $q = 1 Then
If $gstr <> "" Then
_SQLite_Exec(-1, "DELETE FROM Assets_Form WHERE Assets_Name = '" & $gstr & "';") ;
_input_4()
EndIf
EndIf
EndIf
Case $List_1 ;點選部門後自動更新使用人表單
If GUICtrlRead($List_1) <> "" Then ;點選部門名稱後
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Custodian) FROM Custodian_Form WHERE Department = '" & GUICtrlRead($List_1)&"';", $aRow) ;搜尋該部門有哪些使用人
If Int($aRow[0]) <> 0 Then ;搜尋到一筆以上使用人資料
Local $ArrayData[Int($aRow[0])]
Local $c = 0
_SQLite_Query(-1, "SELECT Custodian FROM Custodian_Form WHERE Department = '" & GUICtrlRead($List_1)&"' ;",$hQuery) ;讀取全部資料筆數,並存入$hQuery 變數
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$ArrayData[$c]=$aRow[0]
$c = $c +1
WEnd
If IsArray($ArrayData) Then
$Str=""
For $i = 0 To UBound($ArrayData) - 1
$Str &= "|" & $ArrayData[$i]
Next
EndIf
GUICtrlSetData($List_2,"")
GUICtrlSetData($List_2,$Str)
Else
GUICtrlSetData($List_2,"")
EndIf
EndIf
Case $List_3 ;點選類別後自動更新資產名稱
If GUICtrlRead($List_3) <> "" Then
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Assets_Name) FROM Assets_Form WHERE Assets_Category = '" & GUICtrlRead($List_3)&"';", $aRow) ;搜尋該類別有哪些資產
If Int($aRow[0]) <> 0 Then ;搜尋到一筆以上使用人資料
Local $ArrayData[Int($aRow[0])][2]
Local $c = 0
_SQLite_Query(-1, "SELECT * FROM Assets_Form WHERE Assets_Category = '" & GUICtrlRead($List_3) & "' AND Assets_Name LIKE '%' ;", $hQuery) ;查詢資料,並存入$hQuery 變數
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$ArrayData[$c][0]=$aRow[1]
$ArrayData[$c][1]=$aRow[2]
$c = $c +1
WEnd
_GUICtrlListView_DeleteAllItems($hL4)
_GUICtrlListView_AddArray($hL4,$ArrayData)
Else
_GUICtrlListView_DeleteAllItems($hL4)
EndIf
EndIf
EndSwitch
WEnd
GUIDelete($Form_Setting)
_Combo_1()
GUICtrlSetData($Combo_2, "")
_Combo_3()
GUICtrlSetData($Combo_4, "")
EndFunc
Func _input_1() ;填入欄位資料
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Department) FROM Department_Form WHERE Department Like '%';",$aRow) ;
Local $a = Int($aRow[0])
Local $ArrayData[$a]
Local $c =0
_SQLite_Query(-1, "SELECT Department FROM Department_Form WHERE Department LIKE '%' ;", $hQuery) ;查詢資料,並存入$hQuery 變數
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$ArrayData[$c]=$aRow[0]
$c = $c +1
WEnd
If IsArray($ArrayData) Then
$Str=""
For $i=0 To UBound($ArrayData)-1
$Str &= "|" & $ArrayData[$i]
Next
$Str=StringTrimLeft($Str,1)
EndIf
EndFunc
Func _input_2() ;填入使用人資料
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Custodian) FROM Custodian_Form WHERE Department = '" & GUICtrlRead($List_1) & "' AND Custodian Like '%';",$aRow) ;
Local $a = Int($aRow[0])
Local $ArrayData[$a][2]
Local $c =0
_SQLite_Query(-1, "SELECT * FROM Custodian_Form WHERE Department = '" & GUICtrlRead($List_1) & "' AND Custodian LIKE '%' ;", $hQuery) ;查詢資料,並存入$hQuery 變數
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$ArrayData[$c][0]=$aRow[0]
$ArrayData[$c][1]=$aRow[1]
$c = $c +1
WEnd
If IsArray($ArrayData) Then
$Str=""
For $i=0 To UBound($ArrayData)-1
$Str &= "|" & $ArrayData[$i][1]
Next
$Str=StringTrimLeft($Str,1)
EndIf
EndFunc
Func _input_3() ;填入類別資料
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Assets_Category) FROM Category_Form WHERE Assets_Category Like '%';",$aRow) ;讀取全部資料筆數,並存入$hQuery 變數
Local $ArrayData[Int($aRow[0])]
Local $c =0
_SQLite_Query(-1, "SELECT Assets_Category FROM Category_Form WHERE Assets_Category LIKE '%' ;", $hQuery) ;查詢資料,並存入$hQuery 變數
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$ArrayData[$c]=$aRow[0]
$c = $c +1
WEnd
If IsArray($ArrayData) Then
$Str=""
For $i=0 To UBound($ArrayData)-1
$Str &= "|" & $ArrayData[$i]
Next
$Str=StringTrimLeft($Str,1)
EndIf
EndFunc
Func _input_4() ;填入資產名稱
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Assets_Name) FROM Assets_Form WHERE Assets_Category = '" & GUICtrlRead($List_3) & "' AND Assets_Name Like '%';",$aRow) ;
Local $ArrayData[Int($aRow[0])][2]
Local $c = 0
_SQLite_Query(-1, "SELECT * FROM Assets_Form WHERE Assets_Category = '" & GUICtrlRead($List_3) & "' AND Assets_Name LIKE '%' ;", $hQuery) ;查詢資料,並存入$hQuery 變數
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$ArrayData[$c][0]=$aRow[1]
$ArrayData[$c][1]=$aRow[2]
$c = $c +1
WEnd
GUICtrlSetData($Input_4,"")
GUICtrlSetData($Input_5,"")
_GUICtrlListView_DeleteAllItems($hL4)
_GUICtrlListView_AddArray($hL4,$ArrayData)
EndFunc
Func _newdata() ;資產登記
Local $idx
Local $F1 = GUICreate("資產登記", 406, 301, -1, -1)
GUICtrlCreateLabel("資產類別:", 10, 20, 60, 17)
Local $C1 = GUICtrlCreateCombo("", 70, 15, 100, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlCreateLabel("資產名稱:", 180, 20, 60, 17)
Local $C2 = GUICtrlCreateCombo("", 240, 15, 130, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlCreateLabel("部門:", 35, 50, 40, 17)
Local $C3 = GUICtrlCreateCombo("", 70, 45, 100, 30, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlCreateLabel("使用人:", 191, 50, 50, 17)
Local $C4 = GUICtrlCreateCombo("", 240, 45, 100, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlCreateLabel("數量:", 35, 80, 40, 17)
Local $IN1 = GUICtrlCreateInput("", 70, 75,45, 21,$ES_NUMBER)
GUICtrlCreateLabel("單位:", 120, 80, 40, 17)
Local $IN2 = GUICtrlCreateInput("",160, 75, 30, 21,$ES_READONLY)
GUICtrlCreateLabel("單價:", 205, 80, 40, 17)
Local $IN3 = GUICtrlCreateInput("", 240, 75, 65, 21,$ES_NUMBER)
GUICtrlCreateLabel("購置日期:", 10, 110, 60, 17)
Local $DT1 = GUICtrlCreateDate("", 70, 105, 105, 21,$DTS_SHORTDATEFORMAT)
Local $sStyle = "yyyy-MM-dd"
GUICtrlSendMsg($DT1, $DTM_SETFORMATW, 0, $sStyle)
GUICtrlCreateLabel("資產編號:", 180, 110, 60, 17)
Local $IN4 = GUICtrlCreateInput("", 240, 105, 100, 21)
GUICtrlCreateLabel("資產狀態:", 10, 140, 60, 17)
Local $C5 = GUICtrlCreateCombo("", 70, 135, 60, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlSetData($C5, "使用|閒置|維修|報廢|借出|消耗|其他" )
GUICtrlCreateLabel("儲存位置:", 180, 140, 60, 17)
Local $IN5 = GUICtrlCreateInput("", 240, 135, 100, 21)
GUICtrlCreateLabel("備註:", 30, 165, 40, 17)
Local $E1 = GUICtrlCreateEdit("", 30, 185, 270, 110)
Local $E1_Text = "廠牌:" & @CRLF & "型號:" & @CRLF &"經銷商:"
GUICtrlSetData($E1,$E1_Text)
Local $B1 = GUICtrlCreateButton("存檔", 320, 200, 60, 60)
;------ 以下帶入參數
GUICtrlSetData($C1, "") ;設定資產類別
Local $Str="" , $c = 0
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Assets_Category) FROM Category_Form WHERE Assets_Category LIKE '%';", $aRow) ;
Local $ary[Int($aRow[0])]
_SQLite_Query(-1, "SELECT * FROM Category_Form WHERE Assets_Category LIKE '%' ;", $hQuery) ;查詢資料,並存入$hQuery 變數
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$ary[$c] = $aRow[0]
$c = $c + 1
WEnd
For $i=0 To UBound($ary)-1
$Str &= "|" & $ary[$i]
Next
GUICtrlSetData($C1, $Str )
GUICtrlSetData($C3, "" ) ;設定部門類別
Local $Str="" , $c = 0
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Department) FROM Department_Form WHERE Department LIKE '%';", $aRow) ;
Local $ary[Int($aRow[0])]
_SQLite_Query(-1, "SELECT * FROM Department_Form WHERE Department LIKE '%' ;", $hQuery) ;查詢資料,並存入$hQuery 變數
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$ary[$c] = $aRow[0]
$c = $c + 1
WEnd
For $i=0 To UBound($ary)-1
$Str &= "|" & $ary[$i]
Next
GUICtrlSetData($C3, $Str )
GUISetState(@SW_SHOW,$F1)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $B1
_SQLite_QuerySingleRow(-1, "SELECT Assets_Number FROM Data_Form WHERE Assets_Number = '" & GUICtrlRead($IN4) & "';", $aRow) ;
If $aRow[0] = "" Then
If GUICtrlRead($C1) <> "" And GUICtrlRead($C2) <> "" And GUICtrlRead($C3) <> "" And GUICtrlRead($C4) <> "" _
And GUICtrlRead($C5) <> "" And GUICtrlRead($IN1) <> "" And GUICtrlRead($IN3) <> "" And GUICtrlRead($IN4) <> "" _
And GUICtrlRead($IN5) Then
Local $Total = GUICtrlRead($IN1) * GUICtrlRead($IN3)
_SQLite_Exec(-1, "Insert Into Data_Form (Assets_Number,Assets_Category,Assets_Name,Department,Custodian,Purchase_date," & _
"Quantity,Unit,Price,Total,Status,Storage_space,Comment) values ('" & GUICtrlRead($IN4) & "','" & _
GUICtrlRead($C1) & "','" & GUICtrlRead($C2) & "','" & GUICtrlRead($C3) & "','" & GUICtrlRead($C4) & "','" & _
GUICtrlRead($DT1) & "','" & GUICtrlRead($IN1) & "','" & GUICtrlRead($IN2) & "','" & GUICtrlRead($IN3) & "','" & _
$Total & "','" & GUICtrlRead($C5) & "','" & GUICtrlRead($IN5) & "','" & GUICtrlRead($E1) & "');") ;
MsgBox(0,"提示!","資產編號:" & GUICtrlRead($IN4) & "已建立完成。" )
ExitLoop
Else
MsgBox(0,"提示!","輸入資料不齊全,請檢查各欄位是否未填寫。")
EndIf
Else
MsgBox(0,"提示!","資產編號重複,請重新輸入")
EndIf
Case $C1
Local $idx=_GUICtrlComboBox_GetCurSel($C1)
If $idx >= 0 Then
Local $Str="" , $c = 0
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Assets_Name) FROM Assets_Form WHERE Assets_Category = '" & GUICtrlRead($C1)& "';", $aRow) ;
Local $ary[Int($aRow[0])]
_SQLite_Query(-1, "SELECT Assets_Name FROM Assets_Form WHERE Assets_Category = '" & GUICtrlRead($C1)& "';", $hQuery) ;查詢資料,並存入$hQuery 變數
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$ary[$c] = $aRow[0]
$c = $c + 1
WEnd
For $i=0 To UBound($ary)-1
$Str &= "|" & $ary[$i]
Next
GUICtrlSetData($C2,"")
GUICtrlSetData($C2, $Str )
GUICtrlSetData($IN2,"")
Else
GUICtrlSetData($C2,"")
GUICtrlSetData($IN2,"")
EndIf
Case $C2
If GUICtrlRead($C2) <> "" Then
_SQLite_QuerySingleRow(-1, "SELECT Unit FROM Assets_Form WHERE Assets_Name = '" & GUICtrlRead($C2)& "';", $aRow) ;查詢資料,並存入$hQuery 變數
GUICtrlSetData($IN2,"")
GUICtrlSetData($IN2,$aRow[0])
Else
GUICtrlSetData($IN2,"")
EndIf
Case $C3
Local $idx=_GUICtrlComboBox_GetCurSel($C3)
If $idx >= 0 Then
Local $Str = "", $c = 0
_SQLite_QuerySingleRow(-1, "SELECT COUNT(Custodian) FROM Custodian_Form WHERE Department = '" & GUICtrlRead($C3)& "';", $aRow) ;
Local $ary[Int($aRow[0])]
_SQLite_Query(-1, "SELECT Custodian FROM Custodian_Form WHERE Department = '" & GUICtrlRead($C3)& "';", $hQuery) ;查詢資料,並存入$hQuery 變數
While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
$ary[$c] = $aRow[0]
$c = $c + 1
WEnd
For $i=0 To UBound($ary)-1
$Str &= "|" & $ary[$i]
Next
GUICtrlSetData($C4,"")
GUICtrlSetData($C4, $Str )
Else
GUICtrlSetData($C4,"")
EndIf
EndSwitch
WEnd
GUIDelete($F1)
EndFunc
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) ;滑鼠點擊事件
Local $tNMHDR, $hWndFrom, $iCode,$hWndListView
$hWndListView = $ListView1
If Not IsHWnd($ListView1) Then $hWndListView = GUICtrlGetHandle($g_idListView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = DllStructGetData($tNMHDR, 'hWndFrom')
$iCode = DllStructGetData($tNMHDR, 'Code')
Switch $iCode
Case $NM_DBLCLK
Local $aHit = _GUICtrlListView_SubItemHitTest($ListView1)
If $aHit[0] <> -1 Then
Local $aRect = _GUICtrlListView_GetSubItemRect($ListView1, $aHit[0], $aHit[1])
Local $sItemText = _GUICtrlListView_GetItemText($ListView1, $aHit[0], $aHit[1])
Local $aPos = ControlGetPos($hWnd, '', $ListView1)
Local $iStyle = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)
$hEdit = _GUICtrlEdit_Create($hWnd, $sItemText, $aPos[0] + $aRect[0], $aPos[1] + $aRect[1], _GUICtrlListView_GetColumnWidth($ListView1, $aHit[1]), $iHeight, $iStyle)
_WinAPI_BringWindowToTop($hEdit)
_WinAPI_SetFont($hEdit, $hFont, True)
_GUICtrlEdit_SetMargins($hEdit, $EC_LEFTMARGIN, 4)
_WinAPI_SetFocus($hEdit)
_GUICtrlEdit_SetSel($hEdit, 0, -1)
$sItemText = _GUICtrlListView_GetItemTextArray($ListView1, $aHit[0]) ;拋送基底項目資料列1資料
$selector_item1 = $sItemText[1]
$selector_item2 = $sItemText[2]
EndIf
Case $NM_CLICK
Local $aHit = _GUICtrlListView_SubItemHitTest($ListView1)
If $aHit[0] <> -1 Then
Local $sItemText = _GUICtrlListView_GetItemTextArray($ListView1, $aHit[0]) ;拋送基底項目資料列1資料
$selector_item1 = $sItemText[1]
$selector_item2 = $sItemText[2]
EndIf
Case $NM_RCLICK ;滑鼠右鍵點擊
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $a = DllStructGetData($tInfo, "Index") ;取得listview 游標id-index
Example($a)
EndSwitch
EndFunc ;==>WM_NOTIFY
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) ;滑鼠左鍵編選事件
Local $iCode = BitShift($iwParam, 16)
Local $nMsgID = BitAND($iwParam, 0x0000FFFF)
Switch $ilParam
Case $hEdit
Switch $iCode
Case $EN_KILLFOCUS
Local $sItemText = _GUICtrlEdit_GetText($hEdit)
_WinAPI_DestroyWindow($hEdit)
EndSwitch
EndSwitch
If $nMsgID = 1 And $hEdit <> '' Then
Local $sItemText = _GUICtrlEdit_GetText($hEdit)
_WinAPI_DestroyWindow($hEdit)
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
Func Example($a) ;滑鼠右鍵跳出詳細資料
Local $aItem, $sText, $i
$aItem = _GUICtrlListView_GetItemTextArray($ListView1, $a) ;讀取指定LIST 內容
For $i = 1 To $aItem[0]
If $i = 1 then $sText &= StringFormat("[%2d]資產編號: %s", $i, $aItem[$i]) & @CRLF
If $i = 2 then $sText &= StringFormat("[%2d]資產類別: %s", $i, $aItem[$i]) & @CRLF
If $i = 3 then $sText &= StringFormat("[%2d]資產名稱: %s", $i, $aItem[$i]) & @CRLF
If $i = 4 then $sText &= StringFormat("[%2d]部門: %s", $i, $aItem[$i]) & @CRLF
If $i = 5 then $sText &= StringFormat("[%2d]使用人: %s", $i, $aItem[$i]) & @CRLF
If $i = 6 then $sText &= StringFormat("[%2d]購買日期: %s", $i, $aItem[$i]) & @CRLF
If $i = 7 then $sText &= StringFormat("[%2d]數量: %s", $i, $aItem[$i]) & @CRLF
If $i = 8 then $sText &= StringFormat("[%2d]單位: %s", $i, $aItem[$i]) & @CRLF
If $i = 9 then $sText &= StringFormat("[%2d]單價: %s", $i, $aItem[$i]) & @CRLF
If $i = 10 then $sText &= StringFormat("[%2d]總價: %s", $i, $aItem[$i]) & @CRLF
If $i = 11 then $sText &= StringFormat("[%2d]資產狀況: %s", $i, $aItem[$i]) & @CRLF
If $i = 12 then $sText &= StringFormat("[%2d]儲位: %s", $i, $aItem[$i]) & @CRLF
If $i = 13 then $sText &= StringFormat("[%2d]備註: %s", $i, $aItem[$i]) & @CRLF
Next
$aItem = _GUICtrlListView_GetItemTextArray($ListView1, $a) ;讀取指定LIST 內容
IF $aItem[1] <> "" Then ;如果項目有資料則顯示
MsgBox($MB_SYSTEMMODAL, "BM工單內容",$sText)
EndIf
EndFunc ;==>Example |
|