jackylee0908 Posted January 2, 2019 Posted January 2, 2019 (edited) Hi sir, Here is my code: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form= Global $hGUI = GUICreate("Parameter Generator", 1059, 576, 241, 156) ;Global $hPic_background = GUICtrlCreatePic("d:\3.jpg", 0, 0, 1059, 576, $WS_CLIPSIBLINGS) ;GUICtrlSetState($hPic_background, $GUI_DISABLE) Global $TestTarget = GUICtrlCreateGroup("Test Target", 40, 48, 457, 73) Global $AC = GUICtrlCreateRadio("AC Cycle", 64, 80, 73, 17) Global $DC = GUICtrlCreateRadio("DC Cycle", 168, 80, 73, 17) GUICtrlSetState(-1, $GUI_CHECKED) Global $Reboot = GUICtrlCreateRadio("Reboot Cycle", 272, 80, 97, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) Global $Label1 = GUICtrlCreateLabel("1. Please Select Test", 40, 24, 105, 17) Global $Label2 = GUICtrlCreateLabel("2. Please Select Node(s)", 40, 152, 121, 17) Global $NodeSelection = GUICtrlCreateGroup("Node Selection", 40, 176, 457, 73) Global $SingleNode = GUICtrlCreateRadio("Single Node", 64, 208, 73, 17) GUICtrlSetState(-1, $GUI_CHECKED) Global $TwoNodes = GUICtrlCreateRadio("Two Nodes", 168, 208, 73, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) Global $Label3 = GUICtrlCreateLabel("3. Please input parameters", 552, 24, 129, 17) Global $ParameterInput = GUICtrlCreateGroup("Parameter Input", 552, 56, 457, 489) Global $Label4 = GUICtrlCreateLabel("Node#1 BMC LAN Port IP Address", 576, 96, 169, 25, $SS_CENTERIMAGE) Global $N1BMCLANIP = GUICtrlCreateInput("", 752, 96, 161, 21) Global $Label5 = GUICtrlCreateLabel("Node#1 BMC Login Account", 576, 136, 141, 25, $SS_CENTERIMAGE) Global $N1BMCAC = GUICtrlCreateInput("", 752, 136, 161, 21) Global $Label6 = GUICtrlCreateLabel("Node#1 BMC Login Password", 576, 176, 147, 25, $SS_CENTERIMAGE) Global $N1BMCPW = GUICtrlCreateInput("", 752, 176, 161, 21) Global $Label7 = GUICtrlCreateLabel("Number of Cycle", 576, 216, 82, 25, $SS_CENTERIMAGE) Global $NumberCycle = GUICtrlCreateInput("", 752, 216, 161, 21) Global $Label8 = GUICtrlCreateLabel("PDU IP Address", 576, 256, 81, 25, $SS_CENTERIMAGE) Global $PDUIP = GUICtrlCreateInput("", 752, 256, 161, 21) GUICtrlSetState(-1, $GUI_DISABLE) Global $Label9 = GUICtrlCreateLabel("PDU Port Number", 576, 296, 89, 25, $SS_CENTERIMAGE) Global $PDUPort = GUICtrlCreateInput("", 752, 296, 161, 21) GUICtrlSetState(-1, $GUI_DISABLE) Global $Label20 = GUICtrlCreateLabel("Node#1 OS Login Account", 576, 336, 133, 25, $SS_CENTERIMAGE) Global $N1OSAC = GUICtrlCreateInput("", 752, 336, 161, 21) GUICtrlSetState(-1, $GUI_DISABLE) Global $Label11 = GUICtrlCreateLabel("Node#1 OS Login Password", 576, 376, 139, 25, $SS_CENTERIMAGE) Global $N1OSPW = GUICtrlCreateInput("", 752, 376, 161, 21) GUICtrlSetState(-1, $GUI_DISABLE) Global $Label12 = GUICtrlCreateLabel("Node#1 OS LAN Port IP Address", 576, 416, 161, 25, $SS_CENTERIMAGE) Global $N1OSLANIP = GUICtrlCreateInput("", 752, 416, 161, 21) GUICtrlSetState(-1, $GUI_DISABLE) Global $Label13 = GUICtrlCreateLabel("Node#2 BMC LAN Port IP Address", 576, 456, 169, 25, $SS_CENTERIMAGE) Global $N2BMCLANIP = GUICtrlCreateInput("", 752, 456, 161, 21) GUICtrlSetState(-1, $GUI_DISABLE) Global $Label14 = GUICtrlCreateLabel("Node#2 OS LAN Port IP Address", 576, 496, 161, 25, $SS_CENTERIMAGE) Global $N2OSLANIP = GUICtrlCreateInput("", 752, 496, 161, 21) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateGroup("", -99, -99, 1, 1) Global $LoadButton = GUICtrlCreateButton("Load", 50, 296, 75, 25) Global $SaveButton = GUICtrlCreateButton("Save", 150, 296, 75, 25) Global $DelButton = GUICtrlCreateButton("Delete", 250, 296, 75, 25) Global $ClearButton = GUICtrlCreateButton("Clear", 350, 296, 75, 25) Global $ExitButton = GUICtrlCreateButton("Exit", 450, 296, 75, 25) Global $GoButton = GUICtrlCreateButton("Go", 232, 512, 75, 33) GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x0078D7) Global $ParamPreview = GUICtrlCreateList("", 40, 400, 457, 89) GUICtrlSetData(-1, "") GUICtrlSetState(-1, $GUI_DISABLE) Global $Label15 = GUICtrlCreateLabel("Parameter Preview", 40, 376, 93, 17) Global $hPic_background = GUICtrlCreatePic("c:\Jacky\3.jpg", 0, 0, 1059, 576, $WS_CLIPSIBLINGS) GUICtrlSetState($hPic_background, $GUI_DISABLE) GUISetState(@SW_SHOW, $hGUI) #EndRegion ### END Koda GUI section ### $sFile = "parameter.conf" If FileExists($sFile) Then $sText = FileRead($sFile) GUICtrlSetData($ParamPreview, $sText) MsgBox($MB_ICONWARNING, "Warning", "Parameter file already exist! Please close the window by clicking 'Exit' button to continue the test with old parameter, or, please delete it by clicking 'Delete' button and create a new one if needed.") Else MsgBox($MB_ICONWARNING, "Warning", "Parameter file isn't exist, please create a new one.") EndIf While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE If FileExists($sFile) Then ExitLoop Else MsgBox($MB_ICONSTOP, "Stop", "Parameter file is not generated! Please input necessary parameter and click 'Save' button before exiting the window.") EndIf Case $AC If BitAND(GUICtrlRead($AC), $GUI_CHECKED) = $GUI_CHECKED Then If BitAND(GUICtrlRead($SingleNode), $GUI_CHECKED) = $GUI_CHECKED Then Clear() GUICtrlSetState($PDUIP, 64) GUICtrlSetState($PDUPort, 64) GUICtrlSetState($N1OSAC, 128) GUICtrlSetState($N1OSPW, 128) GUICtrlSetState($N1OSLANIP, 128) GUICtrlSetState($N2BMCLANIP, 128) GUICtrlSetState($N2OSLANIP, 128) ElseIf BitAND(GUICtrlRead($TwoNodes), $GUI_CHECKED) = $GUI_CHECKED Then Clear() GUICtrlSetState($PDUIP, 64) GUICtrlSetState($PDUPort, 64) GUICtrlSetState($N1OSAC, 128) GUICtrlSetState($N1OSPW, 128) GUICtrlSetState($N1OSLANIP, 128) GUICtrlSetState($N2BMCLANIP, 64) GUICtrlSetState($N2OSLANIP, 128) EndIf EndIf Case $DC If BitAND(GUICtrlRead($DC), $GUI_CHECKED) = $GUI_CHECKED Then If BitAND(GUICtrlRead($SingleNode), $GUI_CHECKED) = $GUI_CHECKED Then Clear() GUICtrlSetState($PDUIP, 128) GUICtrlSetState($PDUPort, 128) GUICtrlSetState($N1OSAC, 128) GUICtrlSetState($N1OSPW, 128) GUICtrlSetState($N1OSLANIP, 128) GUICtrlSetState($N2BMCLANIP, 128) GUICtrlSetState($N2OSLANIP, 128) ElseIf BitAND(GUICtrlRead($TwoNodes), $GUI_CHECKED) = $GUI_CHECKED Then Clear() GUICtrlSetState($PDUIP, 128) GUICtrlSetState($PDUPort, 128) GUICtrlSetState($N1OSAC, 128) GUICtrlSetState($N1OSPW, 128) GUICtrlSetState($N1OSLANIP, 128) GUICtrlSetState($N2BMCLANIP, 64) GUICtrlSetState($N2OSLANIP, 128) EndIf EndIf Case $Reboot If BitAND(GUICtrlRead($Reboot), $GUI_CHECKED) = $GUI_CHECKED Then If BitAND(GUICtrlRead($SingleNode), $GUI_CHECKED) = $GUI_CHECKED Then Clear() GUICtrlSetState($PDUIP, 128) GUICtrlSetState($PDUPort, 128) GUICtrlSetState($N1OSAC, 64) GUICtrlSetState($N1OSPW, 64) GUICtrlSetState($N1OSLANIP, 64) GUICtrlSetState($N2BMCLANIP, 128) GUICtrlSetState($N2OSLANIP, 128) ElseIf BitAND(GUICtrlRead($TwoNodes), $GUI_CHECKED) = $GUI_CHECKED Then Clear() GUICtrlSetState($PDUIP, 128) GUICtrlSetState($PDUPort, 128) GUICtrlSetState($N1OSAC, 64) GUICtrlSetState($N1OSPW, 64) GUICtrlSetState($N1OSLANIP, 64) GUICtrlSetState($N2BMCLANIP, 64) GUICtrlSetState($N2OSLANIP, 64) EndIf EndIf Case $SingleNode If BitAND(GUICtrlRead($SingleNode), $GUI_CHECKED) = $GUI_CHECKED Then If BitAND(GUICtrlRead($AC), $GUI_CHECKED) = $GUI_CHECKED Then Clear() GUICtrlSetState($PDUIP, 64) GUICtrlSetState($PDUPort, 64) GUICtrlSetState($N1OSAC, 128) GUICtrlSetState($N1OSPW, 128) GUICtrlSetState($N1OSLANIP, 128) GUICtrlSetState($N2BMCLANIP, 128) GUICtrlSetState($N2OSLANIP, 128) ElseIf BitAND(GUICtrlRead($DC), $GUI_CHECKED) = $GUI_CHECKED Then Clear() GUICtrlSetState($PDUIP, 128) GUICtrlSetState($PDUPort, 128) GUICtrlSetState($N1OSAC, 128) GUICtrlSetState($N1OSPW, 128) GUICtrlSetState($N1OSLANIP, 128) GUICtrlSetState($N2BMCLANIP, 128) GUICtrlSetState($N2OSLANIP, 128) ElseIf BitAND(GUICtrlRead($Reboot), $GUI_CHECKED) = $GUI_CHECKED Then Clear() GUICtrlSetState($PDUIP, 128) GUICtrlSetState($PDUPort, 128) GUICtrlSetState($N1OSAC, 64) GUICtrlSetState($N1OSPW, 64) GUICtrlSetState($N1OSLANIP, 64) GUICtrlSetState($N2BMCLANIP, 128) GUICtrlSetState($N2OSLANIP, 128) EndIf EndIf Case $TwoNodes If BitAND(GUICtrlRead($TwoNodes), $GUI_CHECKED) = $GUI_CHECKED Then If BitAND(GUICtrlRead($AC), $GUI_CHECKED) = $GUI_CHECKED Then Clear() GUICtrlSetState($PDUIP, 64) GUICtrlSetState($PDUPort, 64) GUICtrlSetState($N1OSAC, 128) GUICtrlSetState($N1OSPW, 128) GUICtrlSetState($N1OSLANIP, 128) GUICtrlSetState($N2BMCLANIP, 64) GUICtrlSetState($N2OSLANIP, 128) ElseIf BitAND(GUICtrlRead($DC), $GUI_CHECKED) = $GUI_CHECKED Then Clear() GUICtrlSetState($PDUIP, 128) GUICtrlSetState($PDUPort, 128) GUICtrlSetState($N1OSAC, 128) GUICtrlSetState($N1OSPW, 128) GUICtrlSetState($N1OSLANIP, 128) GUICtrlSetState($N2BMCLANIP, 64) GUICtrlSetState($N2OSLANIP, 128) ElseIf BitAND(GUICtrlRead($Reboot), $GUI_CHECKED) = $GUI_CHECKED Then Clear() GUICtrlSetState($PDUIP, 128) GUICtrlSetState($PDUPort, 128) GUICtrlSetState($N1OSAC, 64) GUICtrlSetState($N1OSPW, 64) GUICtrlSetState($N1OSLANIP, 64) GUICtrlSetState($N2BMCLANIP, 64) GUICtrlSetState($N2OSLANIP, 64) EndIf EndIf Case $LoadButton MsgBox($MB_ICONSTOP, "Stop", "Under construction") Case $SaveButton If FileExists($sFile) Then MsgBox($MB_ICONSTOP, "Stop", "Parameter file existed: You have already saved it.") Else FileWrite("parameter.conf", GUICtrlRead($N1BMCLANIP)) FileWrite("parameter.conf", " ") FileWrite("parameter.conf", GUICtrlRead($N1BMCAC)) FileWrite("parameter.conf", " ") FileWrite("parameter.conf", GUICtrlRead($N1BMCPW)) FileWrite("parameter.conf", " ") FileWrite("parameter.conf", GUICtrlRead($NumberCycle)) FileWrite("parameter.conf", " ") FileWrite("parameter.conf", GUICtrlRead($PDUIP)) FileWrite("parameter.conf", " ") FileWrite("parameter.conf", GUICtrlRead($PDUPort)) FileWrite("parameter.conf", " ") FileWrite("parameter.conf", GUICtrlRead($N1OSAC)) FileWrite("parameter.conf", " ") FileWrite("parameter.conf", GUICtrlRead($N1OSPW)) FileWrite("parameter.conf", " ") FileWrite("parameter.conf", GUICtrlRead($N1OSLANIP)) FileWrite("parameter.conf", " ") FileWrite("parameter.conf", GUICtrlRead($N2BMCLANIP)) FileWrite("parameter.conf", " ") FileWrite("parameter.conf", GUICtrlRead($N2OSLANIP)) $sText = FileRead($sFile) GUICtrlSetData($ParamPreview, $sText) MsgBox($MB_ICONINFORMATION, "Message", "Parameter file saved.") EndIf Case $DelButton If FileExists($sFile) Then FileRecycle($sFile) GUICtrlSetData($ParamPreview, "") MsgBox($MB_ICONINFORMATION, "Message", "Parameter file deleted.") Else MsgBox($MB_ICONSTOP, "Stop", "Parameter file isn't exist.") EndIf Case $ClearButton Clear() MsgBox($MB_ICONINFORMATION, "Message", "Parameter fields cleared.") Case $ExitButton If FileExists($sFile) Then ExitLoop Else MsgBox($MB_ICONSTOP, "Stop", "Parameter file is not generated! Please input necessary parameter and click 'Save' before exiting the window.") EndIf Case $GoButton If GUICtrlRead($AC) = 1 Then If GUICtrlRead($SingleNode) = 1 Then MsgBox(0, "Test", "AC with Single Node was selected!") Else MsgBox(0, "Test", "AC with Two Nodes was selected!") EndIf ElseIf GUICtrlRead($DC) = 1 Then If GUICtrlRead($SingleNode) = 1 Then MsgBox(0, "Test", "DC with Single Node was selected!") Else MsgBox(0, "Test", "DC with Two Nodes was selected!") EndIf ElseIf GUICtrlRead($Reboot) = 1 Then If GUICtrlRead($SingleNode) = 1 Then MsgBox(0, "Test", "Reboot with Single Node was selected!") Else MsgBox(0, "Test", "Reboot with Two Nodes was selected!") EndIf EndIf EndSwitch WEnd Func Clear() GUICtrlSetData($N1BMCLANIP, "") GUICtrlSetData($N1BMCAC, "") GUICtrlSetData($N1BMCPW, "") GUICtrlSetData($NumberCycle, "") GUICtrlSetData($PDUIP, "") GUICtrlSetData($PDUPort, "") GUICtrlSetData($N1OSAC, "") GUICtrlSetData($N1OSPW, "") GUICtrlSetData($N1OSLANIP, "") GUICtrlSetData($N2BMCLANIP, "") GUICtrlSetData($N2OSLANIP, "") EndFunc What the problem I need to resolve: 1. Because of the parameter which require user to input for batch script uses, so when clicking the save button all input data will be saved in single line, and now I'd want to load all the data from saved file into corresponding input fields, how can I do it? Please note that different test selection makes different input fields for user input. 2. Before user click the save button, I'd want to the script check if all required input fields which the fields are with enabled state are with data input by user, if there is any one input field is with empty data then script pops msgbox to remind the user to fill it. Thanks in advance, your support is highly appreciated! Jacky Edited January 3, 2019 by jackylee0908
Trong Posted January 2, 2019 Posted January 2, 2019 1. Get Data from file like: StringSplit(FileRead($SaveFile),"|") Data saved like: Data 1|Data 2|Data 3|Data 4|Data 5|Data n 2. Use: GUICtrlRead() for al control Regards,
jackylee0908 Posted January 2, 2019 Author Posted January 2, 2019 (edited) Thanks, @VIP. For my first question, may I have more detailed information from you? Say that, there are 11 input fields totally but for each input status it will depend on which radio option user selected, for example, when user select 'DC Cycle' and 'Single Node', then only first 4 input fields are enabled / required for user input, in other words, the saved file will have different data length depends on different radio option. Another challenge for me is, if someone save the settings into file, and then another one execute and load the saved file, how the GUI tool know which radio option that saved by last time, and the saved data should load to which corresponding input fields, for example: If an user select the radio option 'AC Cycle' and 'Two Nodes', then the 1~6, and 10th input fields(7 data strings) auto switch to enabled state for user input, and then the user input and save it to file, after couple days, another user use the tool, he try to load the data from saved file, how the tool can recognize the last saved option is with 'AC Cycle' and 'Two Nodes', and how the tool can load the 7 data strings into 1~6, and 10th input fields corresponded? Thanks in advance. Edited January 2, 2019 by jackylee0908
jackylee0908 Posted January 3, 2019 Author Posted January 3, 2019 (edited) Hi @VIP, Just tried your suggestions, but I got another problem on first question. Code for saving data. expandcollapse popupFunc Save() If GUICtrlRead($AC) = 1 Then If GUICtrlRead($SingleNode) = 1 Then FileWrite("parameter.conf", "AC | Single | ") Else FileWrite("parameter.conf", "AC | Two | ") EndIf ElseIf GUICtrlRead($DC) = 1 Then If GUICtrlRead($SingleNode) = 1 Then FileWrite("parameter.conf", "DC | Single | ") Else FileWrite("parameter.conf", "AC | Two | ") EndIf ElseIf GUICtrlRead($Reboot) = 1 Then If GUICtrlRead($SingleNode) = 1 Then FileWrite("parameter.conf", "Reboot | Single | ") Else FileWrite("parameter.conf", "Reboot | Two | ") EndIf EndIf FileWrite("parameter.conf", GUICtrlRead($N1BMCLANIP)) FileWrite("parameter.conf", " ") FileWrite("parameter.conf", "|") FileWrite("parameter.conf", " ") FileWrite("parameter.conf", GUICtrlRead($N1BMCAC)) FileWrite("parameter.conf", " ") FileWrite("parameter.conf", "|") FileWrite("parameter.conf", " ") FileWrite("parameter.conf", GUICtrlRead($N1BMCPW)) FileWrite("parameter.conf", " ") FileWrite("parameter.conf", "|") FileWrite("parameter.conf", " ") FileWrite("parameter.conf", GUICtrlRead($NumberCycle)) FileWrite("parameter.conf", " ") FileWrite("parameter.conf", "|") FileWrite("parameter.conf", " ") FileWrite("parameter.conf", GUICtrlRead($PDUIP)) FileWrite("parameter.conf", " ") FileWrite("parameter.conf", "|") FileWrite("parameter.conf", " ") FileWrite("parameter.conf", GUICtrlRead($PDUPort)) FileWrite("parameter.conf", " ") FileWrite("parameter.conf", "|") FileWrite("parameter.conf", " ") FileWrite("parameter.conf", GUICtrlRead($N1OSAC)) FileWrite("parameter.conf", " ") FileWrite("parameter.conf", "|") FileWrite("parameter.conf", " ") FileWrite("parameter.conf", GUICtrlRead($N1OSPW)) FileWrite("parameter.conf", " ") FileWrite("parameter.conf", "|") FileWrite("parameter.conf", " ") FileWrite("parameter.conf", GUICtrlRead($N1OSLANIP)) FileWrite("parameter.conf", " ") FileWrite("parameter.conf", "|") FileWrite("parameter.conf", " ") FileWrite("parameter.conf", GUICtrlRead($N2BMCLANIP)) FileWrite("parameter.conf", " ") FileWrite("parameter.conf", "|") FileWrite("parameter.conf", " ") FileWrite("parameter.conf", GUICtrlRead($N2OSLANIP)) EndFunc Code for loading data. Func Load() Global $aParms = StringSplit(FileRead($sFile), "|") ;For $i = 1 To 13 ;MsgBox($MB_SYSTEMMODAL, "", "$aParms[" & $i & "] - " & $aParms[$i]) ;Next If $aParms[1] = "AC" Then GUICtrlSetState($AC, $GUI_CHECKED) ElseIf $aParms[1] = "DC" Then GUICtrlSetState($DC, $GUI_CHECKED) Else GUICtrlSetState($Reboot, $GUI_CHECKED) EndIf If $aParms[2] = "Single" Then GUICtrlSetState($SingleNode, $GUI_CHECKED) Else GUICtrlSetState($TwoNodes, $GUI_CHECKED) EndIf GUICtrlSetData($N1BMCLANIP, $aParms[3]) GUICtrlSetData($N1BMCAC, $aParms[4]) GUICtrlSetData($N1BMCPW, $aParms[5]) GUICtrlSetData($NumberCycle, $aParms[6]) GUICtrlSetData($PDUIP, $aParms[7]) GUICtrlSetData($PDUPort, $aParms[8]) GUICtrlSetData($N1OSAC, $aParms[9]) GUICtrlSetData($N1OSPW, $aParms[10]) GUICtrlSetData($N1OSLANIP, $aParms[11]) GUICtrlSetData($N2BMCLANIP, $aParms[12]) GUICtrlSetData($N2OSLANIP, $aParms[13]) EndFunc When loading data the If $aParms[1] = "AC" and If $aParms[2] = "Single" don't work for me, say that it always jump to last condition which is "GUICtrlSetState($Reboot, $GUI_CHECKED)" and "GUICtrlSetState($TwoNodes, for example, I select the "AC Cycle" and "Single Node" from radio option and save it to file so the saved file contains "AC | Single | .......etc.", when I click on the Load button to execute load function but the radio state always change to last one which is "Reboot Cycle" and "Two Nodes", seems the "If" statement is not work, please advise what is the problem, thanks much. Edited January 3, 2019 by jackylee0908
Trong Posted January 3, 2019 Posted January 3, 2019 Please give me the standard data so I can help you quickly. As well as helping you to get things you want the fastest! And save data on one line in 1 file is necessary? Data is saved by date? Data is stored separately by each person, each session? When writing a program you need to figure out how to store the data, also retrieve the saved data. Things like: -The user data entered. -The output file you desire. Regards,
jackylee0908 Posted January 3, 2019 Author Posted January 3, 2019 Thanks, @VIP, I have solved the two problems followed your suggestions.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now