#Include <GuiListView.au3>
#Include <GUIConstantsEx.au3>
#Include <GuiButton.au3>
#Include <File.au3>
#Include <WindowsConstants.au3>
Global $iIndex, $EditLine = 0
$hGUI = GUICreate("Форма", 435, 350)
$iListView = GUICtrlCreateListView("№|Название Фирмы|ИНН|Адрес|Иное поле", 2, 2, 430, 200, $LVS_EDITLABELS, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
GUISetState()
_GUICtrlListView_SetColumnWidth($iListView, 0, 30)
For $i = 1 To 4
_GUICtrlListView_SetColumnWidth($iListView, $i, 100)
Next
$Name = GUICtrlCreateInput('Название Фирмы', 5, 250, 210, 30)
$INN = GUICtrlCreateInput('ИНН', 220, 250, 210, 30)
$Adres = GUICtrlCreateInput('Адрес', 5, 290, 210, 30)
$Else = GUICtrlCreateInput('Иное поле', 220, 290, 210, 30)
$AddBut = GUICtrlCreateButton('Добавить Запись', 10, 210, 110, 30)
$SaveBut = GUICtrlCreateButton('Запись в Файл', 130, 210, 110, 30)
$ReadBut = GUICtrlCreateButton('Прочитать из файла', 250, 210, 110, 30)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $AddBut
GUICtrlCreateListViewItem(_GUICtrlListView_GetItemCount($iListView) + 1 & '|' & GUICtrlRead($Name) & '|' & GUICtrlRead($INN) & '|' & GUICtrlRead($Adres) & '|' & GUICtrlRead($Else), $iListView)
Case $msg = $SaveBut
$Path = FileSaveDialog("Выберите имя.", @ScriptDir, "Текстовый файл (*.txt)", 2)
If Not @Error Then
$hFile = FileOpen($Path, 2)
For $i = 0 To _GUICtrlListView_GetItemCount($iListView) - 1
$Text = ''
For $j = 1 To _GUICtrlListView_GetColumnCount($iListView) - 1
$Text = $Text & _GUICtrlListView_GetItemText($iListView, $i, $j) & ';'
Next
FileWriteLine($hFile, $Text)
Next
FileClose($hFile)
EndIf
Case $msg = $ReadBut
_GUICtrlListView_DeleteAllItems($iListView)
$OpenPath = FileOpenDialog('Открыть файл', @ScriptDir, 'Текстовый файл (*.txt)', 1 + 2)
If Not @Error Then
$hFile = FileOpen($OpenPath, 0)
For $i = 1 To _FileCountLines($OpenPath)
$Text = StringReplace(FileReadLine($hFile, $i), ';', '|')
$Text = $i & '|' & StringTrimRight($Text, 1)
GUICtrlCreateListViewItem($Text, $iListView)
Next
FileClose($hFile)
EndIf
EndSelect
If $EditLine = 1 Then _AditLine($hGUI)
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
$hWndListView = $iListView
If Not IsHWnd($iListView) Then $hWndListView = GUICtrlGetHandle($iListView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, 'hWndFrom'))
$iCode = DllStructGetData($tNMHDR, 'Code')
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_RCLICK
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$iIndex = DllStructGetData($tInfo, 'Index')
If $iIndex <> -1 Then
$EditLine = 1
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Func _AditLine($hParent = 0)
Local $hSettings, $iGOEM_Opt
$hAditLine_GUI = GUICreate('Редактировать данные', 280, 170, -1, -1, -1, -1, $hParent)
GUICtrlCreateLabel('Название', 5, 7, 60, 20)
$Name = GUICtrlCreateInput(_GUICtrlListView_GetItemText($iListView, $iIndex, 1), 70, 5, 200, 20)
GUICtrlCreateLabel('ИНН', 5, 32, 60, 20)
$INN = GUICtrlCreateInput(_GUICtrlListView_GetItemText($iListView, $iIndex, 2), 70, 30, 200, 20)
GUICtrlCreateLabel('Адрес', 5, 57, 60, 20)
$adres = GUICtrlCreateInput(_GUICtrlListView_GetItemText($iListView, $iIndex, 3), 70, 55, 200, 20)
GUICtrlCreateLabel('Иное поле', 5, 84, 60, 20)
$Else = GUICtrlCreateInput(_GUICtrlListView_GetItemText($iListView, $iIndex, 4), 70, 80, 200, 20)
$SaveBut = GUICtrlCreateButton('Сохранить', 80, 120, 120, 30)
GUISetState(@SW_DISABLE, $hParent)
GUISetState(@SW_SHOW, $hAditLine_GUI)
$EditLine = 0
While 1
$msg1 = GUIGetMsg()
Switch $msg1
Case $GUI_EVENT_CLOSE
ExitLoop
Case $SaveBut
_GUICtrlListView_SetItemText($iListView, $iIndex, GUICtrlRead($Name), 1)
_GUICtrlListView_SetItemText($iListView, $iIndex, GUICtrlRead($INN), 2)
_GUICtrlListView_SetItemText($iListView, $iIndex, GUICtrlRead($adres), 3)
_GUICtrlListView_SetItemText($iListView, $iIndex, GUICtrlRead($Else), 4)
ExitLoop
EndSwitch
WEnd
Opt("GUIOnEventMode", $iGOEM_Opt)
GUISetState(@SW_ENABLE, $hParent)
GUIDelete($hAditLine_GUI)
EndFunc