#include <GUIConstants.au3>
#include <ListboxConstants.au3>
#include <GuiListBox.au3>
#include <GuiListView.au3>
#include <File.au3>
#include <Array.au3>
Global $ListView, $ContextMenu, $ListView_GUI, $EditObject_GUI, $EditParam = 0, $Name, $NameParam, $path, $Param, $line, $ListOll, $ListNew, $CreateData
Global $PathIni = @ScriptDir & '\Temp\Temp.ini'
If FileExists(@ScriptDir & '/Temp') Then FileDelete(@ScriptDir & '/Temp')
If FileExists(@ScriptDir & '/Temp') Then DirRemove(@ScriptDir & '/Temp', 1)
$Main = GUICreate("", 850, 500, -1, -1, $WS_OVERLAPPEDWINDOW)
$Group1 = GUICtrlCreateGroup('Файл', 5, 2, 240, 90)
GUICtrlSetFont(-1, 12, 600, 0, "MS Sans Serif")
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$OpenBut = GUICtrlCreateButton('Открыть', 15, 20, 70, 60, $BS_MULTILINE)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$SaveBut = GUICtrlCreateButton('Сохранить', 90, 20, 70, 60, $BS_MULTILINE)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUICtrlSetStyle(-1, $BS_VCENTER)
$NewBaseBut = GUICtrlCreateButton('Новый файл', 165, 20, 70, 60, $BS_MULTILINE)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$Group2 = GUICtrlCreateGroup('Предмет', 265, 2, 315, 90)
GUICtrlSetFont(-1, 12, 600, 0, "MS Sans Serif")
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$AddBut = GUICtrlCreateButton('Добавить', 275, 20, 70, 60, $BS_MULTILINE)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$CopyBut = GUICtrlCreateButton('Копировать', 350, 20, 70, 60, $BS_MULTILINE)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$EditBut = GUICtrlCreateButton('Редактиро-' & @CR & 'вать', 425, 20, 70, 60, $BS_MULTILINE)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$DelBut = GUICtrlCreateButton('Удалить', 500, 20, 70, 60, $BS_MULTILINE)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$Group3 = GUICtrlCreateGroup('Список', 600, 2, 240, 90)
GUICtrlSetFont(-1, 12, 600, 0, "MS Sans Serif")
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$AddListBut = GUICtrlCreateButton('Добавить в список', 610, 20, 70, 60, $BS_MULTILINE)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$RemoveListBut = GUICtrlCreateButton('Удалить из' & @CR & 'списка', 685, 20, 70, 60, $BS_MULTILINE)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$ReportBut = GUICtrlCreateButton('Отчёт', 760, 20, 70, 60, $BS_MULTILINE)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
$ListOll = GUICtrlCreateList('', 10, 100, 410, 395, BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOINTEGRALHEIGHT))
GUICtrlSetFont(-1, 12, 600, 0, "MS Sans Serif")
GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKBOTTOM))
$ListNew = GUICtrlCreateList('', 430, 100, 410, 395, BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOINTEGRALHEIGHT))
GUICtrlSetFont(-1, 12, 600, 0, "MS Sans Serif")
GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKBOTTOM))
GUISetState(@SW_SHOW, $Main)
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
DirRemove(@ScriptDir & '/Temp', 1)
Exit
Case $msg = $CopyBut
_Copy()
Case $msg = $NewBaseBut
NewBase()
Case $msg = $AddBut
_Add()
Case $msg = $OpenBut
_Open()
Case $msg = $AddListBut
_AddList()
Case $msg = $RemoveListBut
_Remove()
Case $msg = $EditBut
_Edit($Main)
Case $msg = $DelBut
_Del()
Case $msg = $SaveBut
SaveBase()
Case $msg = $ReportBut
Report()
EndSelect
_PaintBut()
_HotKey()
WEnd
Func _Open()
$path = FileOpenDialog('Выбор файла каталога', @ScriptDir, 'ini file (*.ini)')
If Not @error Then
WinSetTitle('', '', $path)
DirRemove(@ScriptDir & '/Temp', 1)
DirCreate(@ScriptDir & '\Temp')
FileCopy($path, @ScriptDir & '\Temp', 1)
StringRegExpReplace($path, '^.*\\', '')
FileMove(@ScriptDir & '\Temp\' & StringRegExpReplace($path, '^.*\\', ''), $PathIni, 1)
$CreateData = FileGetTime($PathIni, 0, 1)
GUICtrlSetBkColor($SaveBut, 0xE8E8E8)
_GUICtrlListBox_ResetContent($ListOll)
_GUICtrlListBox_ResetContent($ListNew)
$Catalog = IniReadSectionNames($path)
If Not @error Then
For $i = 1 To UBound($Catalog) - 1
GUICtrlSetData($ListOll, $Catalog[$i])
Next
_GUICtrlListBox_SetCurSel($ListOll, 0)
ControlFocus($Main, '', $ListOll)
Else
MsgBox(48, 'Ошибка !', 'Ошибка чтения файла каталога !')
EndIf
EndIf
EndFunc ;==>_Open
Func _AddList()
$ReportIni = @ScriptDir & '\Temp\report.ini'
If Not FileExists($ReportIni) Then _FileCreate($ReportIni)
$Subject = GUICtrlRead($ListOll)
If IniRead($ReportIni, 'Предмет', $Subject, '-1') < 0 Then
IniWrite($ReportIni, 'Предмет', $Subject, 1)
Else
IniWrite($ReportIni, 'Предмет', $Subject, IniRead($ReportIni, 'Предмет', $Subject, '') + 1)
EndIf
$Parametr = IniReadSection($PathIni, $Subject)
For $i = 1 To $Parametr[0][0]
$Znach = IniRead($ReportIni, 'Параметр', $Parametr[$i][0], '0')
If $Parametr[$i][1] > 0 Then IniWrite($ReportIni, 'Параметр', $Parametr[$i][0], $Znach + $Parametr[$i][1])
Next
_GUICtrlListBox_BeginUpdate($ListNew)
$Item = _GUICtrlListBox_FindString($ListNew, $Subject & ' X' & IniRead($ReportIni, 'Предмет', $Subject, '') - 1, True)
If $Item >= 0 Then
_GUICtrlListBox_DeleteString($ListNew, $Item)
_GUICtrlListBox_InsertString($ListNew, $Subject & ' X' & IniRead($ReportIni, 'Предмет', $Subject, ''), $Item)
_GUICtrlListBox_EndUpdate($ListNew)
Else
_GUICtrlListBox_AddString($ListNew, $Subject & ' X' & IniRead($ReportIni, 'Предмет', $Subject, ''))
EndIf
_GUICtrlListBox_EndUpdate($ListNew)
EndFunc ;==>_AddList
Func _Remove()
$ReportIni = @ScriptDir & '\Temp\report.ini'
$index = _GUICtrlListBox_GetCurSel($ListNew)
$SubjectX = StringInStr(GUICtrlRead($ListNew), 'X', 1, -1)
$Subject = StringLeft(GUICtrlRead($ListNew), $SubjectX - 3)
If $index >= 0 Then
$ZnachPredm = IniRead($ReportIni, 'Предмет', $Subject, '') - 1
If $ZnachPredm == 0 Then
IniDelete($ReportIni, 'Предмет', $Subject)
Else
IniWrite($ReportIni, 'Предмет', $Subject, $ZnachPredm)
EndIf
$Parametr = IniReadSection($PathIni, $Subject)
For $i = 1 To $Parametr[0][0]
$Znach = IniRead($ReportIni, 'Параметр', $Parametr[$i][0], '0') - $Parametr[$i][1]
If $Znach == 0 Then
IniDelete($ReportIni, 'Параметр', $Parametr[$i][0])
Else
IniWrite($ReportIni, 'Параметр', $Parametr[$i][0], $Znach)
EndIf
Next
_GUICtrlListBox_BeginUpdate($ListNew)
_GUICtrlListBox_DeleteString($ListNew, $index)
If IniRead($ReportIni, 'Предмет', $Subject, '0') > 0 Then
$string = $Subject & ' X' & IniRead($ReportIni, 'Предмет', $Subject, '')
_GUICtrlListBox_InsertString($ListNew, $string, $index)
_GUICtrlListBox_ClickItem($ListNew, $index)
EndIf
_GUICtrlListBox_EndUpdate($ListNew)
EndIf
EndFunc ;==>_Remove
Func _Del()
If Not FileExists($PathIni) Then
DirCreate(@ScriptDir & '\Temp')
FileCopy($path, @ScriptDir & '\Temp', 1)
StringRegExpReplace($path, '^.*\\', '')
FileMove(@ScriptDir & '\Temp\' & StringRegExpReplace($path, '^.*\\', ''), $PathIni, 1)
$CreateData = FileGetTime($PathIni, 0, 1)
EndIf
_GUICtrlListBox_BeginUpdate($ListOll)
$index = GUICtrlSendMsg($ListOll, $LB_GETCURSEL, 0, 0)
$DelName = GUICtrlRead($ListOll)
If MsgBox(32 + 1, 'Внимание !', 'Вы действительно хотите удалить ' & $DelName & '?') = 1 Then
_GUICtrlListBox_DeleteString($ListOll, $index)
IniDelete($PathIni, $DelName)
EndIf
_GUICtrlListBox_EndUpdate($ListOll)
EndFunc ;==>_Del
Func _PaintBut()
$NewFileIniData = FileGetTime($PathIni, 0, 1)
If $CreateData <> $NewFileIniData Then
$CreateData = $NewFileIniData
GUICtrlSetBkColor($SaveBut, 0xFF4500)
EndIf
EndFunc ;==>_PaintBut
Func _HotKey()
If WinActive($Main) Then
$Fokus = ControlGetFocus($path)
Switch $Fokus
Case 'Button1'
HotKeySet("{Enter}")
Case 'Button2'
HotKeySet("{Enter}")
Case 'Button3'
HotKeySet("{Enter}")
Case 'Button6'
HotKeySet("{Enter}")
Case 'Button7'
HotKeySet("{Enter}")
Case 'Button8'
HotKeySet("{Enter}")
Case 'Button10'
HotKeySet("{Enter}")
Case 'Button11'
HotKeySet("{Enter}")
Case 'Button12'
HotKeySet("{Enter}")
Case 'ListBox1'
$line = _GUICtrlListBox_GetCurSel($ListOll)
If $line >= 0 Then HotKeySet("{Enter}", "_Edit_")
Case 'ListBox2'
HotKeySet("{Enter}")
EndSwitch
Else
HotKeySet("{Enter}")
EndIf
EndFunc ;==>_HotKey
Func _Add()
If Not FileExists($PathIni) Then
DirCreate(@ScriptDir & '\Temp')
FileCopy($path, @ScriptDir & '\Temp', 1)
FileMove(@ScriptDir & '\Temp\' & StringRegExpReplace($path, '^.*\\', ''), $PathIni, 1)
$CreateData = FileGetTime($PathIni, 0, 1)
EndIf
_GUICtrlListBox_SetCurSel($ListOll, _AddObject($Main))
ControlFocus($Main, '', $ListOll)
EndFunc ;==>_Add
Func _Copy()
If Not FileExists($PathIni) Then
DirCreate(@ScriptDir & '\Temp')
FileCopy($path, @ScriptDir & '\Temp', 1)
FileMove(@ScriptDir & '\Temp\' & StringRegExpReplace($path, '^.*\\', ''), $PathIni, 1)
$CreateData = FileGetTime($PathIni, 0, 1)
EndIf
_GUICtrlListBox_SetCurSel($ListOll, _AddObject($Main, 1))
ControlFocus($Main, '', $ListOll)
EndFunc ;==>_Copy
Func _Edit_()
HotKeySet("{Enter}")
_Edit($Main)
GUICtrlSetState($ListOll, $GUI_FOCUS)
EndFunc ;==>_Edit_
Func SaveBase()
$NewBaseFile = FileSaveDialog('Выберите название нового файла базы ', @ScriptDir, 'ini файл(*.ini)', 0, 'Новая база')
If Not @error Then
If FileExists($PathIni) Then
_SortTempIni($PathIni);Функция сортировки секций ини файла по алфавиту
If FileExists($NewBaseFile) Then
$answer = MsgBox(48 + 3, 'Внимание !', 'Файл базы ' & @CR & $NewBaseFile & @CR & 'уже существует , заменить ?' & @CR & 'Нет - сохранить отчёт под другим именем')
Select
Case $answer = 6
FileCopy($PathIni, $NewBaseFile, 1)
If Not @error Then GUICtrlSetBkColor($SaveBut, 0x00CD00)
$CreateData = FileGetTime($PathIni, 0, 1)
Case $answer = 7
SaveBase()
EndSelect
Else
FileCopy($PathIni, $NewBaseFile, 1)
If Not @error Then GUICtrlSetBkColor($SaveBut, 0x00CD00)
$CreateData = FileGetTime($PathIni, 0, 1)
EndIf
Else
MsgBox(48, 'Ошибка !', 'Невозможно сохранить файл,' & @CR & 'так как никаких изменнений небыло.')
EndIf
EndIf
EndFunc ;==>SaveBase
Func _SortTempIni($PathFile)
$NewIni = @ScriptDir & '\Temp\Temp1.ini'
$aSections = IniReadSectionNames($PathFile)
_ArraySort($aSections)
_FileCreate($NewIni)
For $i = 1 To $aSections[0]
$aKey = IniReadSection($PathFile, $aSections[$i])
For $j = 1 To $aKey[0][0]
IniWrite($NewIni, $aSections[$i], $aKey[$j][0], $aKey[$j][1])
Next
Next
FileDelete($PathFile)
FileMove($NewIni, $PathFile)
EndFunc ;==>_SortTempIni
Func NewBase()
$NewFile = FileSaveDialog('Укажите новый файл базы', @ScriptDir, 'ini файл(*.ini)', 0, 'Новая база')
If Not @error Then
If Not FileExists($NewFile) Then
DirRemove(@ScriptDir & '\Temp', 1)
_FileCreate($NewFile)
DirCreate(@ScriptDir & '\Temp')
FileCopy($NewFile, @ScriptDir & '\Temp\' & StringRegExpReplace($path, '^.*\\', ''), 0)
WinSetTitle('', '', $NewFile)
_GUICtrlListBox_ResetContent($ListOll)
_GUICtrlListBox_ResetContent($ListNew)
GUICtrlSetBkColor($SaveBut, 0xE8E8E8)
Else
MsgBox(48, 'Ошибка !', 'Такой файл уже существует !' & @CR & 'Укажите другое имя файла !')
NewBase()
EndIf
EndIf
EndFunc ;==>NewBase
Func Report()
$RepIni = @ScriptDir & '\Temp\report.ini'
If FileExists($RepIni) Then
$ReportFile = FileSaveDialog('Выберите файл отчёта', @ScriptDir, 'Текстовый файл(*.txt)', 0, 'Отчёт')
If FileExists($ReportFile) Then
$answer = MsgBox(48 + 3, 'Внимание !', 'Файл отчёта ' & @CR & $ReportFile & @CR & 'уже существует , заменить ?' & @CR & 'Нет - сохранить отчёт под другим именем')
Select
Case $answer = 6 ;Да
CreateRepport($ReportFile)
Case $answer = 7 ;Нет
Report()
EndSelect
Else
CreateRepport($ReportFile)
EndIf
Else
MsgBox(48, 'Ошибка !', 'Не найден временный файл отчёта !')
EndIf
EndFunc ;==>Report
Func CreateRepport($ReportFile)
$RepIni = @ScriptDir & '\Temp\report.ini'
$RepSub = IniReadSection($RepIni, 'Предмет')
If Not @error Then
Dim $text[UBound($RepSub)][1]
For $i = 1 To UBound($RepSub) - 1
$text[$i][0] = $RepSub[$i][0] & ' = ' & $RepSub[$i][1]
Next
EndIf
$RepParam = IniReadSection($RepIni, 'Параметр')
If Not @error Then
ReDim $text[UBound($RepParam) + $i][1]
For $j = 1 To UBound($RepParam) - 1
$text[$j + $i][0] = 'Сумма ' & $RepParam[$j][0] & ' = ' & $RepParam[$j][1]
Next
_FileWriteFromArray($ReportFile, $text)
EndIf
EndFunc ;==>CreateRepport
Func _AddObject($hParent = 0, $CopyName = 0)
$Opt = Opt("GUIOnEventMode", 0)
$Result = 0
$ListView_GUI = GUICreate('Добавить новый предмет', 300, 400, -1, -1, -1, -1, $hParent)
$EditName = GUICtrlCreateInput('Название предмета', 10, 10, 280, 30)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
$ListView = GUICtrlCreateListView('Название параметра|Значение параметра', 10, 50, 280, 300, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
If $CopyName Then
$Items = IniReadSection($PathIni, GUICtrlRead($ListOll))
For $i = 1 To UBound($Items) - 1
_GUICtrlListView_AddItem($ListView, $Items[$i][0])
_GUICtrlListView_AddSubItem($ListView, $i - 1, $Items[$i][1], 1, 2)
Next
EndIf
$DummyMenu = GUICtrlCreateDummy()
$ContextMenu = GUICtrlCreateContextMenu($DummyMenu)
$ItemCreate = GUICtrlCreateMenuItem("Создать параметр", $ContextMenu)
$ItemDelete = GUICtrlCreateMenuItem("Удалить параметр", $ContextMenu)
$OkBut = GUICtrlCreateButton('Добавить', 100, 355, 100, 40)
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
GUISetState(@SW_DISABLE, $hParent)
GUISetState(@SW_SHOW, $ListView_GUI)
$EditParam = 0
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
ExitLoop
Case $OkBut
$Name = GUICtrlRead($EditName)
$Items = _GUICtrlListView_GetItemCount($ListView)
If $Items > 0 Then
For $i = 0 To $Items - 1
IniWrite($PathIni, $Name, _GUICtrlListView_GetItemText($ListView, $i, 0), _GUICtrlListView_GetItemText($ListView, $i, 1))
Next
Else
MsgBox(48, 'Ошибка !', 'Невозможно добавить предмет без параметров !', 3)
ExitLoop
EndIf
_SortTempIni($PathIni)
$Result = _CreateListFromIni($Name)
;$Result = _GUICtrlListBox_AddString($ListOll, $Name)
ExitLoop
Case $ItemCreate
AddLine($ListView, GUICtrlRead($EditName), $ListView_GUI)
Case $ItemDelete
DelLine($ListView, GUICtrlRead($EditName), $hParent)
EndSwitch
If $EditParam Then NewObject($ListView, $ListView_GUI)
$Fokus = ControlGetFocus('Добавить новый предмет')
; ConsoleWrite($Fokus&@CR)
If $Fokus == 'SysListView321' Then
HotKeySet("{Enter}", "_Add_")
Else
HotKeySet("{Enter}")
EndIf
WEnd
HotKeySet("{Enter}")
Opt("GUIOnEventMode", $Opt)
GUISetState(@SW_ENABLE, $hParent)
GUIDelete($ListView_GUI)
Return $Result
EndFunc ;==>_AddObject
Func _CreateListFromIni($Name)
_GUICtrlListBox_ResetContent($ListOll)
$aSection = IniReadSectionNames($PathIni)
For $i = 1 To $aSection[0]
_GUICtrlListBox_AddString($ListOll, $aSection[$i])
If $Name = $aSection[$i] Then $Item = $i - 1
Next
_GUICtrlListBox_SetCurSel($ListOll, $Item)
Return $Item
EndFunc ;==>_CreateListFromIni
Func _Add_()
HotKeySet("{Enter}")
NewObject($ListView, $ListView_GUI)
EndFunc ;==>_Add_
Func WriteIni($Temppath, $WriteListView, $WriteName)
For $i = 0 To ControlListView("", "", $WriteListView, "GetItemCount") - 1
IniWrite($Temppath, $WriteName, ControlListView("", "", $WriteListView, "GetText", $i, 0), ControlListView("", "", $ListView, "GetText", $i, 1))
Next
EndFunc ;==>WriteIni
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
$hWndListView = $ListView
If Not IsHWnd($ListView) Then $hWndListView = GUICtrlGetHandle($ListView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, 'hWndFrom'))
$iCode = DllStructGetData($tNMHDR, 'Code')
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_DBLCLK ;двойной клик левой кнопки мыши
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$iIndex = DllStructGetData($tInfo, 'Index')
If $iIndex <> -1 Then
$iLast_LV_Index = $iIndex
$NameParam = ControlListView("", "", $ListView, "GetText", $iLast_LV_Index, 0)
$Param = ControlListView("", "", $ListView, "GetText", $iLast_LV_Index, 1)
$line = $iLast_LV_Index + 1
$EditParam = 1
EndIf
Case $NM_RCLICK ;один клик правой кнопки мыши
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$iIndex = DllStructGetData($tInfo, 'Index')
If $iIndex <> -1 Then
$iLast_LV_Index = $iIndex
$NameParam = ControlListView("", "", $ListView, "GetText", $iLast_LV_Index, 0)
$line = $iLast_LV_Index + 1
EndIf
ShowMenu($hWnd, $ContextMenu, $ListView, 1)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func ShowMenu($hWnd, $nContextID, $nContextControlID, $iMouse = 0)
Local $hMenu = GUICtrlGetHandle($nContextID)
Local $iCtrlPos = ControlGetPos($hWnd, "", $nContextControlID)
Local $X = $iCtrlPos[0]
Local $Y = $iCtrlPos[1] + $iCtrlPos[3]
ClientToScreen($hWnd, $X, $Y)
If $iMouse Then
$X = MouseGetPos(0)
$Y = MouseGetPos(1)
EndIf
DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $X, "int", $Y, "hwnd", $hWnd, "ptr", 0)
EndFunc ;==>ShowMenu
Func ClientToScreen($hWnd, ByRef $X, ByRef $Y)
Local $stPoint = DllStructCreate("int;int")
DllStructSetData($stPoint, 1, $X)
DllStructSetData($stPoint, 2, $Y)
DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint))
$X = DllStructGetData($stPoint, 1)
$Y = DllStructGetData($stPoint, 2)
$stPoint = 0
EndFunc ;==>ClientToScreen
Func NewObject($ListView, $hParent1 = 0)
$EditParam = 0
$Item = _GUICtrlListView_GetSelectedIndices($ListView, True)
If $Item[0] > 0 Then
$Name = _GUICtrlListView_GetItemText($ListView, $Item[1])
$Param = _GUICtrlListView_GetItemText($ListView, $Item[1], 1)
Local $NewParam_GUI, $iGOEM_Opt
$iGOEM_Opt = Opt("GUIOnEventMode", 0)
$NewParam_GUI = GUICreate($Name, 150, 150, -1, -1, $WS_BORDER, -1, $hParent1)
$NewParam = GUICtrlCreateInput($Param, 20, 20, 100, 30)
GUICtrlSetFont(-1, 12, 600, 0, "MS Sans Serif")
$OK = GUICtrlCreateButton('OK', 10, 70, 60, 30)
$Cancel = GUICtrlCreateButton('Exit', 75, 70, 60, 30)
GUISetState(@SW_DISABLE, $hParent1)
GUISetState(@SW_SHOW, $NewParam_GUI)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
ExitLoop
Case $Cancel
ExitLoop
Case $OK
$sText = StringReplace(GUICtrlRead($NewParam), ',', '.')
$iDec = StringInStr($sText, '.', Default, 2);Количество точек в строке, кроме первой
If $iDec > 0 Then $sText = StringReplace($sText, '.', '', 1 - $iDec);Убрать все точки, кроме первой
$sText = StringRegExp($sText, '(\d+(\.(\d+)?)?)', 2)
If @error Then
_GUICtrlListView_SetItem($ListView, '', $Item[1], 1)
Else
_GUICtrlListView_SetItem($ListView, $sText[0], $Item[1], 1)
EndIf
ExitLoop
EndSwitch
WEnd
Opt("GUIOnEventMode", $iGOEM_Opt)
GUISetState(@SW_ENABLE, $hParent1)
GUIDelete($NewParam_GUI)
Else
MsgBox(48, 'Ошибка !', 'Не выделена строка с параметром !')
EndIf
EndFunc ;==>NewObject
Func _Edit($hParent = 0)
$EditParam = 0
If Not FileExists($PathIni) Then
DirCreate(@ScriptDir & '\Temp')
FileCopy($path, @ScriptDir & '\Temp', 1)
StringRegExpReplace($path, '^.*\\', '')
FileMove(@ScriptDir & '\Temp\' & StringRegExpReplace($path, '^.*\\', ''), $PathIni, 1)
EndIf
$Subject = GUICtrlRead($ListOll)
$iGOEM_Opt = Opt("GUIOnEventMode", 0)
$EditObject_GUI = GUICreate('Редактирование предмета', 300, 410, -1, -1, -1, -1, $hParent)
$EditName = GUICtrlCreateInput($Subject, 10, 10, 280, 30)
GUICtrlSetFont(-1, 12, 600, 0, "MS Sans Serif")
$ListView = GUICtrlCreateListView('Название параметра|Значение параметра', 10, 45, 280, 300, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_REPORT))
$Items = IniReadSection($PathIni, $Subject)
If Not @error Then
For $i = 1 To UBound($Items) - 1
_GUICtrlListView_AddItem($ListView, $Items[$i][0])
_GUICtrlListView_AddSubItem($ListView, $i - 1, $Items[$i][1], 1, 2)
Next
ControlFocus($EditObject_GUI, 'Редактирование предмета', $ListView)
_GUICtrlListView_SetItemSelected($ListView, 0)
EndIf
$DummyMenu = GUICtrlCreateDummy()
$ContextMenu = GUICtrlCreateContextMenu($DummyMenu)
$ItemCreate = GUICtrlCreateMenuItem("Создать параметр", $ContextMenu)
$ItemDelete = GUICtrlCreateMenuItem("Удалить параметр", $ContextMenu)
$ItemRename = GUICtrlCreateMenuItem("Переименовать параметр", $ContextMenu)
$OK = GUICtrlCreateButton('OK', 110, 355, 80, 40)
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
GUISetState(@SW_DISABLE, $hParent)
GUISetState(@SW_SHOW, $EditObject_GUI)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
ExitLoop
Case $ItemRename
_RenameParam($ListView, $Subject, $EditObject_GUI)
Case $OK
$NewSubject = GUICtrlRead($EditName)
WriteIni($PathIni, $ListView, $NewSubject)
If $NewSubject <> $Subject Then
IniDelete($PathIni, $Subject)
_SortTempIni($PathIni)
_CreateListFromIni($NewSubject)
EndIf
ExitLoop
Case $ItemCreate
AddLine($ListView, $Subject, $EditObject_GUI)
Case $ItemDelete
DelLine($ListView, $Subject, $EditObject_GUI)
EndSwitch
If $EditParam Then NewObject($ListView, $EditObject_GUI)
$Fokus = ControlGetFocus($EditObject_GUI)
If $Fokus == 'Button1' Then
HotKeySet("{Enter}")
Else
HotKeySet("{Enter}", "_EditParam_")
EndIf
WEnd
HotKeySet("{Enter}")
Opt("GUIOnEventMode", $iGOEM_Opt)
GUISetState(@SW_ENABLE, $hParent)
GUIDelete($EditObject_GUI)
ControlFocus($Main, '', $ListOll)
EndFunc ;==>_Edit
Func _RenameParam($ListView, $ObjName, $hParent)
Local $NewLine_GUI, $iGOEM_Opt
$iGOEM_Opt = Opt("GUIOnEventMode", 0)
$EditParamName = _GUICtrlListView_GetItemText($ListView, $line - 1)
$EditLine_GUI = GUICreate('Переименовать параметр ' & $EditParamName, 260, 160, -1, -1, $WS_BORDER, -1, $hParent)
$NewParamName = GUICtrlCreateInput($EditParamName, 10, 10, 240, 30)
GUICtrlSetFont(-1, 12, 600, 0, "MS Sans Serif")
$EditForAll = GUICtrlCreateCheckbox('Для всех', 15, 55, 100, 30)
GUICtrlSetFont(-1, 12, 600, 0, "MS Sans Serif")
$OK = GUICtrlCreateButton('OK', 10, 90, 60, 30)
$Cancel = GUICtrlCreateButton('Exit', 75, 90, 60, 30)
GUISetState(@SW_DISABLE, $hParent)
GUISetState(@SW_SHOW, $EditLine_GUI)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Cancel
ExitLoop
Case $OK
$NewName = GUICtrlRead($NewParamName)
If $EditParamName <> $NewName Then
If GUICtrlRead($EditForAll) = $GUI_CHECKED Then
$text = 'Вы действительно хотите переименовать параметр "' & $EditParamName & '"' & @CRLF & 'для ВСЕХ предметов на новое "' & $NewName & '" ?'
Else
$text = 'Вы действительно хотите переименовать параметр "' & $EditParamName & '"' & @CRLF & 'в "' & $ObjName & '" на новое "' & $NewName & '" ?'
EndIf
If MsgBox(48 + 1, 'Внимание !', $text) == 1 Then
_ReWriteOneIni($EditParamName, $ObjName, $NewName, $ListView)
If GUICtrlRead($EditForAll) = $GUI_CHECKED Then
_ReWriteOllIni($EditParamName, $NewName, $ObjName)
EndIf
EndIf
Else
MsgBox(48, 'Ошибка !', 'Имя параметра "' & $NewName & '" не изменилось !', 3)
EndIf
ExitLoop
EndSwitch
WEnd
Opt("GUIOnEventMode", $iGOEM_Opt)
GUISetState(@SW_ENABLE, $hParent)
GUIDelete($EditLine_GUI)
ControlFocus($EditObject_GUI, '', $ListView)
EndFunc ;==>_RenameParam
Func _ReWriteOllIni($EditParamName, $NewName, $ObjName)
$AllIni = IniReadSectionNames($PathIni)
For $i = 1 To $AllIni[0]
If $AllIni[$i] <> $ObjName Then
;Проверка наличия параметра в предмете
If IniRead($PathIni, $AllIni[$i], $EditParamName, -1) >= 0 Then
;Чтение параметров в массив и очистка
$AllParam = IniReadSection($PathIni, $AllIni[$i])
Local $aParam[$AllParam[0][0]][2]
For $j = 1 To $AllParam[0][0]
$aParam[$j - 1][0] = $AllParam[$j][0]
$aParam[$j - 1][1] = $AllParam[$j][1]
If $AllParam[$j][0] = $EditParamName Then $aParam[$j - 1][0] = $NewName
IniDelete($PathIni, $AllIni[$i], $AllParam[$j][0])
Next
;Запись новых значений в ini файлл
For $Y = 0 To $AllParam[0][0] - 1
IniWrite($PathIni, $AllIni[$i], $aParam[$Y][0], $aParam[$Y][1])
Next
EndIf
EndIf
Next
EndFunc ;==>_ReWriteOllIni
Func _ReWriteOneIni($EditParamName, $ObjName, $NewName, $ListView)
$sum = _GUICtrlListView_GetItemText($ListView, $line - 1, 1)
_GUICtrlListView_InsertItem($ListView, $NewName, $line)
_GUICtrlListView_AddSubItem($ListView, $line, $sum, 1)
_GUICtrlListView_DeleteItem($ListView, $line - 1)
$OllParam = IniReadSection($PathIni, $ObjName)
If Not @error Then
;Удалить все названия параметров предмета
For $i = 1 To $OllParam[0][0]
IniDelete($PathIni, $ObjName, $OllParam[$i][0])
Next
;Создать параметры заново из $ListView
For $i = 0 To _GUICtrlListView_GetItemCount($ListView) - 1
IniWrite($PathIni, $ObjName, _GUICtrlListView_GetItemText($ListView, $i), _GUICtrlListView_GetItemText($ListView, $i, 1))
Next
EndIf
EndFunc ;==>_ReWriteOneIni
Func _EditParam_()
HotKeySet("{Enter}")
NewObject($ListView, $EditObject_GUI)
EndFunc ;==>_EditParam_
Func DelLine($ListView, $ObjName, $hParent)
Local $NewLine_GUI, $iGOEM_Opt
$iGOEM_Opt = Opt("GUIOnEventMode", 0)
$DelParamName = _GUICtrlListView_GetItemText($ListView, $line - 1)
$DelLine_GUI = GUICreate('Удалить параметр', 260, 160, -1, -1, $WS_BORDER, -1, $hParent)
GUICtrlCreateLabel('Удалить "' & $DelParamName & '"', 10, 10, 240, 50)
GUICtrlSetFont(-1, 12, 600, 0, "MS Sans Serif")
$DellForAll = GUICtrlCreateCheckbox('Для всех', 15, 55, 100, 30)
GUICtrlSetFont(-1, 12, 600, 0, "MS Sans Serif")
$OK = GUICtrlCreateButton('OK', 10, 90, 60, 30)
$Cancel = GUICtrlCreateButton('Exit', 75, 90, 60, 30)
GUISetState(@SW_DISABLE, $hParent)
GUISetState(@SW_SHOW, $DelLine_GUI)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Cancel
ExitLoop
Case $OK
If GUICtrlRead($DellForAll) = $GUI_CHECKED Then
If MsgBox(48 + 1, 'Внимание !', 'Вы действительно хотите удалить параметр ' & $DelParamName & @CRLF & 'для ВСЕХ предметов ?') == 1 Then
_GUICtrlListView_DeleteItem($ListView, $line - 1)
$OllName = IniReadSectionNames($PathIni)
If Not @error Then
For $i = 1 To $OllName[0]
IniDelete($PathIni, $OllName[$i], $DelParamName)
Next
EndIf
EndIf
Else
If MsgBox(48 + 1, 'Внимание !', 'Вы действительно хотите удалить параметр ' & $DelParamName & @CRLF & 'в ' & $ObjName & ' ?') == 1 Then
_GUICtrlListView_DeleteItem($ListView, $line - 1)
IniDelete($PathIni, $ObjName, $DelParamName)
EndIf
EndIf
ExitLoop
EndSwitch
WEnd
Opt("GUIOnEventMode", $iGOEM_Opt)
GUISetState(@SW_ENABLE, $hParent)
GUIDelete($DelLine_GUI)
ControlFocus($EditObject_GUI, '', $ListView)
EndFunc ;==>DelLine
Func AddLine($ListView, $ObjName, $hParent)
Local $NewLine_GUI, $iGOEM_Opt
$iGOEM_Opt = Opt("GUIOnEventMode", 0)
$NewLine_GUI = GUICreate('Добавить новый параметр', 260, 150, -1, -1, $WS_BORDER, -1, $hParent)
$NewParam = GUICtrlCreateInput('Название параметра', 10, 10, 240, 30)
GUICtrlSetFont(-1, 12, 600, 0, "MS Sans Serif")
$AddForAll = GUICtrlCreateCheckbox('Для всех', 15, 45, 100, 30)
GUICtrlSetFont(-1, 12, 600, 0, "MS Sans Serif")
$OK = GUICtrlCreateButton('OK', 10, 80, 60, 30)
$Cancel = GUICtrlCreateButton('Exit', 75, 80, 60, 30)
GUISetState(@SW_DISABLE, $hParent)
GUISetState(@SW_SHOW, $NewLine_GUI)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Cancel
ExitLoop
Case $OK
$NewParamName = GUICtrlRead($NewParam)
$id = _GUICtrlListView_FindText($ListView, $NewParamName, -1, False, True)
If $id < 0 Then
$ind = _GUICtrlListView_AddItem($ListView, $NewParamName)
_GUICtrlListView_AddSubItem($ListView, $ind, 0, 1)
Else
MsgBox(48, 'Внимание !', 'Имя параметра "' & $NewParamName & @CRLF & '"' & 'уже есть в "' & $ObjName & '"' & ' !', 3)
EndIf
If GUICtrlRead($AddForAll) = $GUI_CHECKED Then
;Запись во все секции, кроме текущей
$Sections = IniReadSectionNames($PathIni)
If Not @error Then
For $i = 1 To $Sections[0]
If $ObjName <> $Sections[$i] Then
If IniRead($PathIni, $Sections[$i], $NewParamName, -1) < 0 Then
IniWrite($PathIni, $Sections[$i], $NewParamName, 0)
Else
MsgBox(48, 'Внимание !', 'Имя параметра "' & $NewParamName & @CRLF & '"' & ' уже есть в "' & $Sections[$i] & '" !', 3)
EndIf
EndIf
Next
EndIf
EndIf
ExitLoop
EndSwitch
WEnd
Opt("GUIOnEventMode", $iGOEM_Opt)
GUISetState(@SW_ENABLE, $hParent)
GUIDelete($NewLine_GUI)
ControlFocus($EditObject_GUI, '', $ListView)
EndFunc ;==>AddLine