#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <GUIListView.au3>
#include <Array.au3>
#include <GuiEdit.au3>
#include <GuiMenu.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
#include <FontConstants.au3>
#include <Excel.au3>
#include <ScreenCapture.au3>
HotKeySet('{esc}', '_Exit')
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("鋒哥義大利麵", 700, 520, -1, -1)
$ListView1 = GUICtrlCreateListView("ID|名稱|價錢", 24, 23, 200, 157)
GUICtrlCreateListViewItem("1|青醬(大)|70|1", $ListView1)
GUICtrlCreateListViewItem("2|白醬(大)|70", $ListView1)
GUICtrlCreateListViewItem("3|青醬(小)|60", $ListView1)
GUICtrlCreateListViewItem("4|白醬(小)|60", $ListView1)
GUICtrlCreateListViewItem("5|玉米濃湯(大)|40", $ListView1)
GUICtrlCreateListViewItem("6|玉米濃湯(小)|30", $ListView1)
;$ListView1A = GUICtrlCreateListView("ID|名稱|價錢", 254, 30, 200, 157)
;GUICtrlCreateListViewItem("1|玉米濃湯(大)|40", $ListView1A)
;GUICtrlCreateListViewItem("2|玉米濃湯(小)|30", $ListView1A)
$Label6 = GUICtrlCreateLabel("名稱", 250, 30, 40, 17)
$Input5 = GUICtrlCreateInput("", 280, 26, 80, 21)
$Label9 = GUICtrlCreateLabel("價錢", 250, 60, 40, 17)
$Input8 = GUICtrlCreateInput("", 280, 56, 80, 21)
$Label11 = GUICtrlCreateLabel("數量", 250, 90, 28, 17)
$Input10 = _GUICtrlEdit_Create($Form1, "", 280, 86, 80, 21, $ES_NUMBER)
;$Input10 = GUICtrlCreateCombo("",500, 212, 89, 21)
;GUICtrlSetData($Input10, "1|2|3|4|5", "1")
$Button2 = GUICtrlCreateButton("確定", 249, 116, 112, 32, $BS_DEFPUSHBUTTON)
;$totalmoney=GUICtrlCreateButton("總金額", 249, 148, 112, 32, $BS_DEFPUSHBUTTON)
$export = GUICtrlCreateButton("匯出", 220, 450, 55, 25)
$print = GUICtrlCreateButton("列印", 220, 478, 55, 25)
$export_all = GUICtrlCreateButton("匯出+列印", 278, 450, 80, 53)
$ListView2 = GUICtrlCreateListView("名稱 |數量 |價錢 ", 24, 200, 334, 241)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global Enum $idOpen = 1000, $idSave, $idInfo
Global $hCMenu = GUICtrlCreateContextMenu($ListView2)
Global $hCMenuText1 = GUICtrlCreateMenuItem("Delete", $hCMenu)
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")
GUICtrlCreateLabel("總金額: ", 25,460,100,100)
;Local $Gif = @ScriptDir & '\gif\ld.jpg'
;Local $oIE = ObjCreate('Shell.Explorer.2')
;GUICtrlCreateObj($oIE, 25, 515, 300, 190)
;$oIE.navigate($Gif)
;GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button2
GUICtrlSetState($ListView1, $GUI_FOCUS)
$mc = GUICtrlRead($Input5)
$jg = GUICtrlRead($Input8)
$num = _GUICtrlEdit_GetText($Input10)
GUICtrlCreateListViewItem($mc & "|" & $num & "|" & $num * $jg, $ListView2)
GUICtrlSetData($Input10, "")
GUISetFont(40, $FW_NORMAL, $GUI_FONTUNDER, "Comic Sans MS")
Local $itemCounts = _GUICtrlListView_GetItemCount($ListView2)
Local $totalPrice = 0
Local $tArr
For $i=0 To $itemCounts-1
$tArr = _GUICtrlListView_GetItemTextArray($ListView2, $i) ;get each item to the array
$totalPrice = $totalPrice + $tArr[ $tArr[0] ] ;the last element is the price
Next
;MsgBox(0,"111",$tArr[ $tArr[0] ])
;show the total price
GUICtrlCreateLabel($totalPrice, 70,435,150,100)
case $hCMenuText1 ;delete
_GUICtrlListView_DeleteItemsSelected($ListView2)
Case $export
If $jg="" Then
MsgBox(16, "Failure", "Failure")
Else
exporttoexcel()
EndIf
Case $print
If $jg="" Then
MsgBox(16, "Failure", "Failure")
Else
print()
EndIf
Case $export_all
If $jg="" Then
MsgBox(16, "Failure", "Failure")
Else
print()
exporttoexcel()
EndIf
EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView1, $tInfo
;If Not IsHWnd($ListView2) Then $hWndListView = GUICtrlGetHandle($ListView2)
;$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
;$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
;$iCode = DllStructGetData($tNMHDR, "Code")
$hWndListView1 = GUICtrlGetHandle($ListView1)
$hWndListView2 = GUICtrlGetHandle($ListView2)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView1
Switch $iCode
Case $NM_RCLICK
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$Index = DllStructGetData($tInfo, "Index")
$SubItem = DllStructGetData($tInfo, "SubItem")
$sItemText = _GUICtrlListView_GetItemText($ListView2, $Index, $SubItem)
;MsgBox(0,"DD",$Index)
Case $NM_DBLCLK
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$Index = DllStructGetData($tInfo, "Index")
$sItemText = _GUICtrlListView_GetItemText($ListView2, $Index, $SubItem)
MsgBox(0,"DD","DD")
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
#forceref $hWndGUI, $MsgID, $wParam
Local $hWndFrom, $hWndListView1, $NMHDR, $NMLVDISPINFO, $NMLISTVIEW, $event
$hWndListView = $ListView1
If Not IsHWnd($ListView1) Then $hWndListView = GUICtrlGetHandle($ListView1)
$NMHDR = DllStructCreate($tagNMHDR, $lParam)
$event = DllStructGetData($NMHDR, 'Code')
$hWndFrom = HWnd(DllStructGetData($NMHDR, "hWndFrom"))
Switch $hWndFrom
Case $hWndListView
Switch $event
Case $LVN_ITEMCHANGED
$NMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam)
If BitAND(DllStructGetData($NMLISTVIEW, "Changed"), $LVIF_STATE) = $LVIF_STATE And _
DllStructGetData($NMLISTVIEW, "NewState") <> DllStructGetData($NMLISTVIEW, "OldState") Then OnStateChange()
Case $LVN_KEYDOWN
$tInfo = DllStructCreate($tagNMLVKEYDOWN, $lParam)
$Key=DllStructGetData($tInfo, "VKey")
Switch $Key
Case 0x30 To 0x39
_GUICtrlEdit_AppendText($Input10, DllStructGetData($tInfo, "VKey") - 0x30)
Case 0x60 to 0x69
_GUICtrlEdit_AppendText($Input10, DllStructGetData($tInfo, "VKey") - 0x60)
EndSwitch
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_Notify_Events
Func OnStateChange()
$cur_sel = _GUICtrlListView_GetNextItem($ListView1) ; current selected
_GUICtrlEdit_SetText($Input10, "1")
GUICtrlSetData($Input5, _GUICtrlListView_GetItemText($ListView1, $cur_sel, 1))
GUICtrlSetData($Input8, _GUICtrlListView_GetItemText($ListView1, $cur_sel, 2))
EndFunc ;==>OnStateChange
Func exporttoexcel();EXPORT TO EXCEL
$col = 0
$count = _GUICtrlListView_GetItemCount($ListView2)
GUICtrlSetState($export,$gui_enable)
$excel = _ExcelBookNew()
$oWorkbook = _Excel_BookNew($excel)
_ExcelWriteCell($excel,"名稱",2,2)
_ExcelWriteCell($excel,"數量",2,3)
_ExcelWriteCell($excel,"金額",2,4)
_ExcelWriteCell($excel," ",2,5)
_ExcelWriteCell($excel," ",2,6)
_ExcelWriteCell($excel," ",2,7)
_ExcelWriteCell($excel," ",2,8)
_ExcelWriteCell($excel," ",2,9)
_ExcelWriteCell($excel," ",2,10)
_ExcelWriteCell($excel," ",2,11)
_ExcelWriteCell($excel," ",2,12)
_ExcelWriteCell($excel," ",2,13)
_ExcelWriteCell($excel," ",2,14)
_ExcelWriteCell($excel," ",2,15)
_ExcelWriteCell($excel," ",2,16)
_ExcelWriteCell($excel," ",2,17)
For $colexcel = 0 To $col
$i = 0
do
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($ListView2,$i,0),3 + $i,2)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($ListView2,$i,1),3 + $i,3)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($ListView2,$i,2),3 + $i,4)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($ListView2,$i,3),3 + $i,5)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($ListView2,$i,4),3 + $i,6)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($ListView2,$i,5),3 + $i,7)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($ListView2,$i,6),3 + $i,8)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($ListView2,$i,7),3 + $i,9)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($ListView2,$i,8),3 + $i,10)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($ListView2,$i,9),3 + $i,11)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($ListView2,$i,10),3 + $i,12)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($ListView2,$i,11),3 + $i,13)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($ListView2,$i,12),3 + $i,14)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($ListView2,$i,13),3 + $i,15)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($ListView2,$i,14),3 + $i,16)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($ListView2,$i,15),3 + $i,17)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($ListView2,$i,16),3 + $i,18)
$i = $i + 1
Until $i = $count
Next
;MsgBox(64,"Message","Export completed!" & @CRLF _
; & " "& @CRLF _
; & "Output excel file on your Desktop!",2)
DirCreate(@ScriptDir & "\Excel")
_Excel_BookSaveAs($oWorkbook, @ScriptDir & "\Excel"& @YEAR & @MON & @MDAY &"_" & @HOUR & @MIN & @SEC & ".xlsx", Default,False)
_Excel_Close($excel,True,True)
EndFunc
Func _ExcelBookNew($fVisible = 0)
Local $oExcel = ObjCreate("Excel.Application")
If NOT IsObj($oExcel) Then Return SetError(1, 0, 0)
If NOT IsNumber($fVisible) Then Return SetError(2, 0, 0)
If $fVisible > 1 Then $fVisible = 1
If $fVisible < 0 Then $fVisible = 0
With $oExcel
.Visible = $fVisible
.WorkBooks.Add
.ActiveWorkbook.Sheets(1).Select()
EndWith
Return $oExcel
EndFunc ;==>_ExcelBookNew
Func _ExcelWriteCell($oExcel, $sValue, $sRangeOrRow, $iColumn = 1)
If NOT IsObj($oExcel) Then Return SetError(1, 0, 0)
If NOT StringRegExp($sRangeOrRow, "[A-Z,a-z]", 0) Then
If $sRangeOrRow < 1 Then Return SetError(2, 0, 0)
If $iColumn < 1 Then Return SetError(2, 1, 0)
$oExcel.Activesheet.Cells($sRangeOrRow, $iColumn).Value = $sValue
Return 1
Else
$oExcel.Activesheet.Range($sRangeOrRow).Value = $sValue
Return 1
EndIf
EndFunc ;==>_ExcelWriteCell
Func print()
DirCreate(@ScriptDir & "\PrintIMG")
;FileDelete(@ScriptDir & "\Table_Screenshot.jpg")
_ScreenCapture_CaptureWnd(@ScriptDir & "\PrintIMG"&@YEAR&"-"&@mon&"-"&@MDAY&" "&@HOUR&@MIN&".jpg", $Form1)
;sleep(2000)
ShellExecute(@ScriptDir & "\PrintIMG"&@YEAR&"-"&@mon&"-"&@MDAY&" "&@HOUR&@MIN&".jpg", "", "","print")
; Capture full screen
;_ScreenCapture_Capture(@ScriptDir & "\GDIPlus_Image1.jpg")
;ShellExecute(@ScriptDir & "\GDIPlus_Image1.jpg")
; Capture region
;_ScreenCapture_Capture(@ScriptDir & "\GDIPlus_Image2.jpg", 0, 0, -1, -1)
;ShellExecute(@ScriptDir & "\GDIPlus_Image2.jpg")
EndFunc
Func _Exit()
Exit
EndFunc ;==>_Exit