Что нового

Заполнение формы в GUI, с передачей данных в конфиг-файл

vld-k

Новичок
Сообщения
39
Репутация
0
Пожалуйста, помогите разобраться.
В KODA создал форму, в которой предполагается заполнять данные (IP) адреса, после чего указанные адреса будут сохраняться в файл. Сложность в понимании процесса, когда я заполняю "ip adress input box", как мне передать данные конфигу в нужную строку, после определенных параметров, т.е. как привязать данные вводимые в полях определенным значениям конфиг-файла?

DHCPRange=$IPAddress3-$IPAddress4
NextServer=$IPAddress1
и так далее.

Код формы:
Код:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Users\vld\Desktop\Form1.kxf
$Form1 = GUICreate("Form1", 381, 298, 286, 164)
$Group1 = GUICtrlCreateGroup("Настройка DHCP сервера", 32, 32, 313, 233)
$Label1 = GUICtrlCreateLabel("Пул IP адрессов", 40, 64, 87, 17)
$Label2 = GUICtrlCreateLabel("Шлюз", 40, 128, 33, 17)
$Label3 = GUICtrlCreateLabel("Адрес TFT-сервера", 40, 192, 103, 17)
$Button1 = GUICtrlCreateButton("Запуск DHCP-сервера", 184, 144, 131, 89)
$IPAddress2 = _GUICtrlIpAddress_Create($Form1, 44, 152, 124, 21)
_GUICtrlIpAddress_Set($IPAddress2, "0.0.0.0")
$IPAddress4 = _GUICtrlIpAddress_Create($Form1, 186, 93, 130, 21)
_GUICtrlIpAddress_Set($IPAddress4, "0.0.0.0")
$IPAddress3 = _GUICtrlIpAddress_Create($Form1, 41, 93, 130, 21)
_GUICtrlIpAddress_Set($IPAddress3, "0.0.0.0")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$IPAddress1 = _GUICtrlIpAddress_Create($Form1, 48, 216, 118, 26)
_GUICtrlIpAddress_Set($IPAddress1, "0.0.0.0")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit

	EndSwitch
WEnd


Часть конфига, который буду заполнять:
[RANGE_SET]
DHCPRange=192.168.0.20-192.168.0.254
SubnetMask=255.255.255.0
Router=192.168.0.1
[GLOBAL_OPTIONS]
NextServer=192.168.0.3
 

Garrett

Модератор
Локальный модератор
Сообщения
3,999
Репутация
967
Читайте эти функции:
Код:
GUICtrlRead()
;...
IniRead()
IniReadSection()
IniReadSectionNames()
IniRenameSection()
IniWrite()
IniWriteSection()
 
Автор
V

vld-k

Новичок
Сообщения
39
Репутация
0
Garrett сказал(а):
Читайте эти функции:
Код:
GUICtrlRead()
;...
IniRead()
IniReadSection()
IniReadSectionNames()
IniRenameSection()
IniWrite()
IniWriteSection()

Насколько я понял, если я хочу изменить параметр "NextServer=", в своем ини файле, я должен сделать так?

IniWrite($sPath_ini, "MY-Section", "NextServer=", "$IPAddress1")?
и будет ли перезаписывать данная функция значения в рабочем конфиге?
 

Garrett

Модератор
Локальный модератор
Сообщения
3,999
Репутация
967
Вот так:
Код:
IniWrite($sPath_ini, "MY-Section", "NextServer", "$IPAddress1")


vld-k [?]
и будет ли перезаписывать данная функция значения в рабочем конфиге?
Да.
 
Автор
V

vld-k

Новичок
Сообщения
39
Репутация
0
вот мой скрипт, подскажите, пожалуйста, где я делаю ошибку?

Код:
$sPath_ini = @ScriptDir & "\OpenDHCPServer.ini"

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
	
	
IniWrite($sPath_ini, "[GLOBAL_OPTIONS]", "NextServer=", "$IPAddress1")
	
		 Case $Button1
			Run('RunStandAloneMT.bat')

		Case $GUI_EVENT_CLOSE
			Exit

	EndSwitch
WEnd


ini-файл:

[GLOBAL_OPTIONS]
.........
DomainServer=192.168.0.3
NextServer=192.168.0.3
.......
 

Garrett

Модератор
Локальный модератор
Сообщения
3,999
Репутация
967
Код:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$sPath_ini = @ScriptDir & "\OpenDHCPServer.ini"

$Form1 = GUICreate("Form1", 381, 298, 286, 164)
$Group1 = GUICtrlCreateGroup("Настройка DHCP сервера", 32, 32, 313, 233)
$Label1 = GUICtrlCreateLabel("Пул IP адрессов", 40, 64, 87, 17)
$Label2 = GUICtrlCreateLabel("Шлюз", 40, 128, 33, 17)
$Label3 = GUICtrlCreateLabel("Адрес TFT-сервера", 40, 192, 103, 17)
$Button1 = GUICtrlCreateButton("Запуск DHCP-сервера", 184, 144, 131, 89)
$IPAddress2 = _GUICtrlIpAddress_Create($Form1, 44, 152, 124, 21)
_GUICtrlIpAddress_Set($IPAddress2, "0.0.0.0")
$IPAddress4 = _GUICtrlIpAddress_Create($Form1, 186, 93, 130, 21)
_GUICtrlIpAddress_Set($IPAddress4, "0.0.0.0")
$IPAddress3 = _GUICtrlIpAddress_Create($Form1, 41, 93, 130, 21)
_GUICtrlIpAddress_Set($IPAddress3, "0.0.0.0")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$IPAddress1 = _GUICtrlIpAddress_Create($Form1, 48, 216, 118, 26)
_GUICtrlIpAddress_Set($IPAddress1, "0.0.0.0")
GUISetState(@SW_SHOW)

While 1

   $nMsg = GUIGetMsg()
   Switch $nMsg
;~ 	  Case $Button1
;~             Run('RunStandAloneMT.bat')
	  Case $Button1
		 IniWriteSection($sPath_ini, "GLOBAL_OPTIONS", _
									StringFormat('Address1=%s\r\nAddress2=%s\r\nAddress3=%s\r\nAddress4=%s\r\n', _
									_GUICtrlIpAddress_Get($IPAddress1), _GUICtrlIpAddress_Get($IPAddress2), _
									_GUICtrlIpAddress_Get($IPAddress3), _GUICtrlIpAddress_Get($IPAddress4)))
	  Case $GUI_EVENT_CLOSE
		 Exit
    EndSwitch
WEnd


Добавлено:
Сообщение автоматически объединено:

GuiIPAddress user defined functions Reference
 
Автор
V

vld-k

Новичок
Сообщения
39
Репутация
0
Большое спасибо за помощь и желание помочь.
Буду пробовать.
 
Автор
V

vld-k

Новичок
Сообщения
39
Репутация
0
Все сделал, спасибо за помощь.
Вот что у меня получилось:

Код:
$sPath_ini = @ScriptDir & "\OpenDHCPServer.ini"
$Form1_1 = GUICreate("TORM Deploy", 234, 488, 362, 140)
$MenuItem1 = GUICtrlCreateMenu("Инфо")
$MenuItem2 = GUICtrlCreateMenuItem("Как пользоваться сервисом"&@TAB&"F1", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenuItem("О программе"&@TAB&"F2", $MenuItem1)
GUISetIcon("D:\Downloads\tux_6839.ico", -1)
$Group1 = GUICtrlCreateGroup("Настройка параметров DHCP сервера", 8, 8, 217, 361)
$Label1 = GUICtrlCreateLabel("Пул IP адрессов", 48, 40, 87, 17)
$Label2 = GUICtrlCreateLabel("Шлюз", 48, 136, 33, 17)
$Label3 = GUICtrlCreateLabel("Адрес TFTP-сервера", 48, 200, 110, 17)
$Button1 = GUICtrlCreateButton("1 . Сохранить изменения", 32, 264, 163, 33)
$IPAddress1 = _GUICtrlIpAddress_Create($Form1_1, 48, 64, 130, 21)
_GUICtrlIpAddress_Set($IPAddress1, "0.0.0.0")
$IPAddress2 = _GUICtrlIpAddress_Create($Form1_1, 48, 96, 130, 21)
_GUICtrlIpAddress_Set($IPAddress2, "0.0.0.0")
$IPAddress3 = _GUICtrlIpAddress_Create($Form1_1, 48, 160, 130, 21)
_GUICtrlIpAddress_Set($IPAddress3, "0.0.0.0")
$IPAddress4 = _GUICtrlIpAddress_Create($Form1_1, 48, 224, 130, 21)
_GUICtrlIpAddress_Set($IPAddress4, "0.0.0.0")
$Button2 = GUICtrlCreateButton("2. Запуск DHCP+TFTP", 32, 312, 163, 33)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("  Локальный IP адрес", 48, 376, 137, 81)
$Label4 = GUICtrlCreateLabel(@IPAddress1, 64, 400, 140, 20)
$Label5 = GUICtrlCreateLabel(@IPAddress2, 64, 424, 140, 20)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Dim $Form1_1_AccelTable[2][2] = [["{F1}", $MenuItem2],["{F2}", $MenuItem3]]
GUISetAccelerators($Form1_1_AccelTable)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
	
	Case $Button2
            Run('RunStandAlone.bat')
      Case $Button1
         IniWriteSection($sPath_ini, "RANGE_SET", _
                                      StringFormat('DHCPRange=%s-%s\nRouter=%s\nNextServer=%s', _
                                    _GUICtrlIpAddress_Get($IPAddress1), _GUICtrlIpAddress_Get($IPAddress2), _
                                    _GUICtrlIpAddress_Get($IPAddress3), _GUICtrlIpAddress_Get($IPAddress4)))
		   ;IniWriteSection($sPath_ini, "MY_OPTIONS", _
            ;                        StringFormat('NextServer=%s-%s\r\nAddress3=%s\r\nAddress4=%s\', _
             ;                       _GUICtrlIpAddress_Get($IPAddress1), _GUICtrlIpAddress_Get($IPAddress2), _
              ;                      _GUICtrlIpAddress_Get($IPAddress3), _GUICtrlIpAddress_Get($IPAddress4)))
		   
		Case $GUI_EVENT_CLOSE
			Exit

		Case $MenuItem2
		Case $MenuItem3
	EndSwitch
WEnd
 
Верх