本帖最后由 q410225 于 2016-12-29 19:08 编辑
回复 11# ipmitool
好了,就是这意思了, 你的意思我也差不多明白了,但实话说,这个程序的结构是不是有问题啊,总觉得不合理,
#include <ini.au3>
#include <File.au3>
#include <Date.au3>
#include <Array.au3>
#include <Excel.au3>
#include <Constants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <GuiStatusBar.au3>
#include <FileConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
Global $g_hTimer0, $g_iSecs0, $g_iMins0, $g_iHour0, $g_sTime0
Global $g_hTimer1, $g_iSecs1, $g_iMins1, $g_iHour1, $g_sTime1
Global $g_hTimer2, $g_iSecs2, $g_iMins2, $g_iHour2, $g_sTime2
Global $g_hTimer3, $g_iSecs3, $g_iMins3, $g_iHour3, $g_sTime3
Global $g_hTimer4, $g_iSecs4, $g_iMins4, $g_iHour4, $g_sTime4
$Form1_1 = GUICreate("Test Schedule Management", 350, 330)
$hListView = GUICtrlCreateListView("", 5, 5, 335, 245) ;, $LVS_SHOWSELALWAYS, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT + $LVS_EX_DOUBLEBUFFER
Global $sItemText ;this will store the text of the last right-clicked item.
Global $sItemTextFilename111
Global $sItemTextFilenameTester
Global $sItemTextFilename1
Global $sItemTextFilename4
Global $sItemTextFilename5
Global $sItemTextFilename7
Global $aNewList[1000][1000]
$aNewList[0][0] = 300
;===================================================================
$Button1 = GUICtrlCreateButton("View", 360, 15, 73, 33)
;$Button2 = GUICtrlCreateButton("Done", 300, 362, 73, 33)
$export = GUICtrlCreateButton("Export to Excel", 100, 562, 100, 33)
$export2 = GUICtrlCreateButton("Export to HTML", 220, 562, 100, 33)
$cInput_Filter = GUICtrlCreateInput("", 11, 620, 140, 20)
$cButton_Filter = GUICtrlCreateButton("Filter", 160, 618, 75, 23)
$cButton_All = GUICtrlCreateButton("Refresh", 360, 60, 73, 33)
GUICtrlCreateLabel('Input Test Case, Product, Serial Number or Tester to filter data', 11, 650, 300, 100)
;===================================================================
$idComboBox = GUICtrlCreateCombo("", 17, 1000, 135, 33)
;$analyze = GUICtrlCreateButton("Analyze", 940, 562, 100, 33)
Local $hGUI, $ahIcons[2], $StatusBar0
Local $aParts[4] = [900, 1160, 1380, 2500]
$StatusBar0 = _GUICtrlStatusBar_Create($Form1_1)
_GUICtrlStatusBar_SetParts($StatusBar0, $aParts)
_GUICtrlStatusBar_SetText($StatusBar0, 'Tool will auto execute!!!')
_GUICtrlStatusBar_SetText($StatusBar0, 'Foxconn@SIT1', 1)
_GUICtrlStatusBar_SetText($StatusBar0, " Version: v1.0 ", 2)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_SUBITEMIMAGES))
;;;;;;;;; Read testconfig.ini ;;;;;;;;;
;;;;;;;;; Read testconfig.ini ;;;;;;;;;
;;;;;;;;; Read testconfig.ini ;;;;;;;;;
$testerread = _IniReadSection_line(@ScriptDir & '\testconfig.ini', 'TestConfig')
$tester = $testerread[1]
;;;;;;;;; Read testconfig.ini ;;;;;;;;;
;;;;;;;;; Read testconfig.ini ;;;;;;;;;
;;;;;;;;; Read testconfig.ini ;;;;;;;;;
GUISetState()
_GUICtrlListView_RegisterSortCallBack($hListView)
_GUICtrlListView_AddColumn($hListView, "File Name", 0) ;disappear file name
_GUICtrlListView_AddColumn($hListView, "Test Case", 140)
_GUICtrlListView_AddColumn($hListView, "Status", 80)
_GUICtrlListView_AddColumn($hListView, "Process Time", 100)
_GUICtrlListView_SetItemCount($hListView, 5000)
ControlClick("Test Schedule Management", "", "[CLASS:Button; TEXT:View; INSTANCE:1]")
While 1
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;Double click value get
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit (_GUICtrlListView_UnRegisterSortCallBack($hListView))
ExitLoop
Case $hListView
_GUICtrlListView_SortItems($hListView, GUICtrlGetState($hListView))
Case $Button1
$g_hTimer0 = TimerInit()
$g_hTimer1=TimerInit()
$g_hTimer2=TimerInit()
$g_hTimer3=TimerInit()
$g_hTimer4=TimerInit()
;GUICtrlSetState($Button1,$gui_disable)
GUICtrlSetState($cButton_All, $gui_enable)
ProgressOn("Test Management Progress Meter", "Progress...", "0%")
Sleep(100)
ProgressSet(0, "0%")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 10mins time count
Dim $tl = GUICtrlCreateLabel('00 min, 00 sec', 10000, 10000, 150, 15)
GUISetState()
Dim $timer = TimerInit(), $Day = 0
AdlibRegister('Timer0', 500)
AdlibRegister("Timer1",500)
AdlibRegister("Timer2",500)
AdlibRegister("Timer3",500)
AdlibRegister("Timer4",500)
Local $hGUI, $ahIcons[2], $StatusBar1
Local $aParts[4] = [900, 1160, 1380, 2500]
$StatusBar1 = _GUICtrlStatusBar_Create($Form1_1)
_GUICtrlStatusBar_SetParts($StatusBar1, $aParts)
_GUICtrlStatusBar_SetText($StatusBar1, 'Tool will auto execute!!!')
_GUICtrlStatusBar_SetText($StatusBar1, 'Foxconn@SIT1', 1)
_GUICtrlStatusBar_SetText($StatusBar1, " Version: v1.0 ", 2)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 10 mins time count
Dim $OldList = "", $aNewList2 = ""
AdlibRegister('_add_report_items111', 5000) ;reflash every 10min is 59925
ProgressSet(100, "100%")
Sleep(500)
ProgressOff()
Case $export
MsgBox(0, "Export", "Export list view data to Excel", 1)
exporttoexcel()
Case $export2
FileChangeDir(@DesktopDir)
FileWrite("TestStatus_Export_" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & ".html", _ListViewToHTMLTable($hListView))
MsgBox(0, "", "Dump html file to: " & @DesktopDir & "\" & "table" & @YEAR & @MON & @MDAY & @HOUR & @MIN & ".html", 1)
EndSwitch
WEnd
Func Timer1()
_TicksToTime(Int(TimerDiff($g_hTimer1)), $g_iHour1, $g_iMins1, $g_iSecs1)
Local $sTime1 = $g_sTime1 ; save current time to be able to test and avoid flicker..
$g_sTime1 = StringFormat("%02i:%02i:%02i", $g_iHour1, $g_iMins1, $g_iSecs1)
If $sTime1 <> $g_sTime1 Then _GUICtrlListView_SetItemText($hListView, 1, $g_sTime1, 3)
EndFunc ;==>Timer1
Func Timer2()
_TicksToTime(Int(TimerDiff($g_hTimer2)), $g_iHour2, $g_iMins2, $g_iSecs2)
Local $sTime2 = $g_sTime2 ; save current time to be able to test and avoid flicker..
$g_sTime2 = StringFormat("%02i:%02i:%02i", $g_iHour2, $g_iMins2, $g_iSecs2)
If $sTime2 <> $g_sTime2 Then _GUICtrlListView_SetItemText($hListView, 2, $g_sTime2, 3)
EndFunc ;==>Timer2
Func Timer3()
_TicksToTime(Int(TimerDiff($g_hTimer3)), $g_iHour3, $g_iMins3, $g_iSecs3)
Local $sTime3 = $g_sTime3 ; save current time to be able to test and avoid flicker..
$g_sTime3 = StringFormat("%02i:%02i:%02i", $g_iHour3, $g_iMins3, $g_iSecs3)
If $sTime3 <> $g_sTime3 Then _GUICtrlListView_SetItemText($hListView, 3, $g_sTime3, 3)
EndFunc ;==>Timer3
Func Timer4()
_TicksToTime(Int(TimerDiff($g_hTimer4)), $g_iHour4, $g_iMins4, $g_iSecs4)
Local $sTime4 = $g_sTime4 ; save current time to be able to test and avoid flicker..
$g_sTime4 = StringFormat("%02i:%02i:%02i", $g_iHour4, $g_iMins4, $g_iSecs4)
If $sTime4 <> $g_sTime4 Then _GUICtrlListView_SetItemText($hListView, 4, $g_sTime4, 3)
EndFunc ;==>Timer4
Func _ListViewToHTMLTable($hList)
Local $sHTML, $iColCount, $iRowCount
$iColCount = _GUICtrlListView_GetColumnCount($hList)
$sHTML = "<P></P><B>Test Management Tool Report</B>" & "<P></P>" & "<table width='1500' border='2' BGColor='#c4d6f6'>" & @LF & "<tr>" & @LF
;创建表头
For $i = 0 To $iColCount - 1
$aInfo = _GUICtrlListView_GetColumn($hList, $i)
$sHTML = $sHTML & "<th scope='col' BGColor='#FFFFFF'>" & $aInfo[5] & "</th>" & @LF
Next
;添加数据
$iRowCount = _GUICtrlListView_GetItemCount($hList)
For $i = 0 To $iRowCount - 1
$sHTML = $sHTML & "<tr>" & @LF
For $j = 0 To $iColCount - 1
$aInfo = _GUICtrlListView_GetItem($hList, $i, $j)
$sHTML = $sHTML & "<th>" & $aInfo[3] & "</th>" & @LF
Next
$sHTML = $sHTML & "</tr>" & @LF
Next
$sHTML = $sHTML & "</table>"
;MsgBox(0,"",$sHTMl)
Return $sHTML
EndFunc ;==>_ListViewToHTMLTable
Func _add_report_items111()
FileChangeDir("\")
Local $path, $aFileList, $aNewList[1][2]
$path = "\"
$aFileList = _FileListToArray($path, "*.txt")
If IsArray($aFileList) Then
ReDim $aNewList[UBound($aFileList)][17] ;;;[Col count]
Local $sComboTxt = "All Member"
GUICtrlSetData($idComboBox, "")
For $i = 1 To UBound($aFileList) - 1 Step 1
$aNewList[0][1] = $i
;$aNewList[$i][0] = $aFileList[$i]
$aNewList[$i][1] = FileReadLine($aFileList[$i], 1)
$aNewList[$i][2] = FileReadLine($aFileList[$i], 2)
$aNewList[$i][3] = "---"
$aNewList[$i][4] = FileReadLine($aFileList[$i], 4)
$aNewList[$i][5] = FileReadLine($aFileList[$i], 5)
$aNewList[$i][6] = FileReadLine($aFileList[$i], 6)
$aNewList[$i][7] = FileReadLine($aFileList[$i], 7)
$aNewList[$i][8] = FileReadLine($aFileList[$i], 8)
If Not StringInStr($sComboTxt, $aNewList[$i][13]) Then $sComboTxt &= "|" & $aNewList[$i][13]
Next
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hListView))
_GUICtrlListView_AddArray($hListView, $aNewList)
For $j = 0 To UBound($aNewList) - 1 Step 1
_GUICtrlListView_SetItemText($hListView, $j + 1, " ", 7)
Next
;~ $aNewList=$aNewList2
GUICtrlSetData($idComboBox, $sComboTxt, "All Member")
EndIf
$j = UBound($aNewList) - 1
If $aNewList[$j][2] = 'done' Then
MsgBox(0, "", "全部是done了,可以注销了")
AdlibUnRegister('_add_report_items111')
EndIf
$aNewList[0][2] = 'done'
For $j = 1 To UBound($aNewList) - 1
If $aNewList[$j][2] = "done" Then
AdlibUnRegister("Timer" & $j)
_GUICtrlListView_SetItemText($hListView, $j, "完成", 3)
EndIf
If $aNewList[$j][2] = "---" And $aNewList[$j - 1][2] = "done" Then
MsgBox(0, "", "程序准备完成,可以运行" & $aNewList[$j][1])
ExitLoop
EndIf
Next
EndFunc ;==>_add_report_items111
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
$hWndListView = GUICtrlGetHandle($hListView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
;$Index = GUICtrlRead($hListView)
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_DBLCLK
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$Index = DllStructGetData($tInfo, "Index")
$DoubleClick = _GUICtrlListView_GetItemText($hListView, $Index, 1) ;GetItemText IP address
MsgBox(0, "Message", $DoubleClick)
Case $NM_RCLICK
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$Index = DllStructGetData($tInfo, "Index")
$SubItem = DllStructGetData($tInfo, "SubItem")
;$sItemText = _GUICtrlListView_GetItemText($hWndListView, $Index, $SubItem) ;GetItemText every location
$sItemText = _GUICtrlListView_GetItemText($hListView, $Index, 12)
$sItemTextFilename111 = _GUICtrlListView_GetItemText($hListView, $Index, 3)
$sItemTextFilenameTester = _GUICtrlListView_GetItemText($hListView, $Index, 13)
$sItemTextFilename1 = _GUICtrlListView_GetItemText($hListView, $Index, 1)
$sItemTextFilename4 = _GUICtrlListView_GetItemText($hListView, $Index, 4)
$sItemTextFilename5 = _GUICtrlListView_GetItemText($hListView, $Index, 5)
$sItemTextFilename7 = _GUICtrlListView_GetItemText($hListView, $Index, 7)
Case $NM_CUSTOMDRAW
Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam)
Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage")
If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW
Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec")
Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem")
Local $sComboRead = GUICtrlRead($idComboBox)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _ShowText()
If $sItemText <> "" Then MsgBox(0, "Test", $sItemText)
EndFunc ;==>_ShowText
Func exporttoexcel() ;EXPORT TO EXCEL
$col = 0
$count = _GUICtrlListView_GetItemCount($hListView)
GUICtrlSetState($export, $gui_enable)
$excel = _ExcelBookNew()
$oWorkbook = _Excel_BookNew($excel)
_ExcelWriteCell($excel, "1", 2, 2)
_ExcelWriteCell($excel, "2", 2, 3)
_ExcelWriteCell($excel, "3", 2, 4)
_ExcelWriteCell($excel, "4", 2, 5)
_ExcelWriteCell($excel, "5", 2, 6)
_ExcelWriteCell($excel, "6", 2, 7)
_ExcelWriteCell($excel, "7", 2, 8)
_ExcelWriteCell($excel, "8", 2, 9)
_ExcelWriteCell($excel, "9", 2, 10)
For $colexcel = 0 To $col
$i = 0
Do
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($hListView, $i, 0), 3 + $i, 1)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($hListView, $i, 1), 3 + $i, 2)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($hListView, $i, 2), 3 + $i, 3)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($hListView, $i, 3), 3 + $i, 4)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($hListView, $i, 4), 3 + $i, 5)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($hListView, $i, 5), 3 + $i, 6)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($hListView, $i, 6), 3 + $i, 7)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($hListView, $i, 7), 3 + $i, 8)
_ExcelWriteCell($excel, _GUICtrlListView_GetItemText($hListView, $i, 8), 3 + $i, 9)
$i = $i + 1
Until $i = $count
Next
MsgBox(64, "Message", "Export completed!" & @CRLF _
& " " & @CRLF _
& "Output excel file on your Desktop!", 2)
_Excel_BookSaveAs($oWorkbook, @DesktopDir & "\TestStatus_Export_" & @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC & ".xlsx", Default, False)
_Excel_Close($excel, True, True)
EndFunc ;==>exporttoexcel
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 Timer0()
_TicksToTime(Int(TimerDiff($g_hTimer0)), $g_iHour0, $g_iMins0, $g_iSecs0)
Local $sTime0 = $g_sTime0 ; save current time to be able to test and avoid flicker..
$g_sTime0 = StringFormat("Total Time: %02s hour, %02s min, %02s sec", $g_iHour0, $g_iMins0, $g_iSecs0)
If $sTime0 <> $g_sTime0 Then _GUICtrlStatusBar_SetText($StatusBar1, $g_sTime0)
EndFunc ;==>Timer0
|