Перейти из форума на сайт.

НовостиФайловые архивы
ПоискАктивные темыТоп лист
ПравилаКто в on-line?
Вход Забыли пароль? Первый раз на этом сайте? Регистрация
Компьютерный форум Ru.Board » Компьютеры » Программы » AutoIT (Часть 2)

Модерирует : gyra, Maz

Widok (01-06-2010 13:08): Лимит страниц. Продолжаем здесь.  Версия для печати • ПодписатьсяДобавить в закладки
На первую страницук этому сообщениюк последнему сообщению

   

MoBiRo

Junior Member
Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору

Код:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
 
Global $tv_Menu ; TreeView
Global $Array [99999][2] ; Массив, в котором будут храниться значение полей TreeViewItem и их хэндлы
Global $Num = 0 ; Сётчик TreeViewItem'ов. Нужен для работы $Array
Global $db_Start = "names" ; Название тэйбла, откуда начинается всё дерево
Global $db = "Test.db" ; До открытия SQL - Имя файла Базы данных, после - хэндл SQL
 
$fr_Main = GUICreate("Test", 166, 384, 300, 100, -1, $WS_EX_TOOLWINDOW) ; создаём главное окно GUI
$tv_Menu = GUICtrlCreateTreeView(8, 8, 150, 350, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$bt_Load_From_SQL = GUICtrlCreateButton("Load", 8, 364, 51, 17) ; создаём кнопку
$bt_Add_In_SQL = GUICtrlCreateButton("Create SQL", 76, 364, 83, 17) ; создаём кнопку
 
GUISetState(@SW_SHOW)
 
_OpenSQL ()
 
while 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _CloseSQL ()
        Case $bt_Add_In_SQL
            _Add_In_SQL ()
        Case $bt_Load_From_SQL
            _Load_From_SQL ()
        EndSwitch
WEnd
 
Func
_OpenSQL ()
    _SQLite_Startup () ; загружаем SQLite.dll
    If @error Then
        MsgBox(16, "SQLite Error", "SQLite.dll Can't be Loaded!")
        Exit - 1
    EndIf
    $db = _SQLite_Open ($db) ; открываем Базу данных, если её не существует, то создаём
    If @error Then
        MsgBox(16, "SQLite Error", "Can't Load Database!")
        Exit - 1
    EndIf
EndFunc
 
Func
_Add_In_SQL ()
    If Not _SQLite_Exec ($db, "CREATE TABLE 'names' ('FirstGame', 'SecondGame', 'ThirdGame');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
    ; Создаём таблицу "names" с столбиками 'FirstGame', 'SecondGame', 'ThirdGame'
    ; Дальше всё по аналогии
    ; обратите внимание, что имена таблиц выбранны специально для использования их в рекурсии

 
    If Not _SQLite_Exec ($db, "CREATE TABLE 'names.FirstGame' ('Maps', 'Patch', 'Demos');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
    If Not _SQLite_Exec ($db, "CREATE TABLE 'names.FirstGame.Maps' ('DM', 'CTF');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
    If Not _SQLite_Exec ($db, "CREATE TABLE 'names.FirstGame.Maps.DM' ('FirstMap', 'SecondMap', 'ThirdMap', 'FourthMap');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
    If Not _SQLite_Exec ($db, "CREATE TABLE 'names.FirstGame.Maps.CTF' ('FirstMap', 'SecondMap');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
    If Not _SQLite_Exec ($db, "CREATE TABLE 'names.FirstGame.Demos' ('New', 'Old');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
    If Not _SQLite_Exec ($db, "CREATE TABLE 'names.FirstGame.Demos.New' ('FirstDemo', 'SecondDemo');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
    If Not _SQLite_Exec ($db, "CREATE TABLE 'names.FirstGame.Demos.Old' ('FirstDemo', 'SecondDemo', 'ThirdDemo');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
 
    If Not _SQLite_Exec ($db, "CREATE TABLE 'names.SecondGame' ('Mobs', 'Chat');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
    If Not _SQLite_Exec ($db, "CREATE TABLE 'names.SecondGame.Mobs' ('FirstList', 'SecondList');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
    If Not _SQLite_Exec ($db, "CREATE TABLE 'names.SecondGame.Mobs.FirstList' ('MobOne', 'MobTwo');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
    If Not _SQLite_Exec ($db, "CREATE TABLE 'names.SecondGame.Mobs.FirstList.MobOne' ('One', 'Two');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
    If Not _SQLite_Exec ($db, "CREATE TABLE 'names.SecondGame.Mobs.FirstList.MobTwo' ('One', 'Two');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
    If Not _SQLite_Exec ($db, "CREATE TABLE 'names.SecondGame.Chat' ('NewVersion', 'OldVersion');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
 
    If Not _SQLite_Exec ($db, "CREATE TABLE 'names.ThirdGame' ('Help', 'About');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
    If Not _SQLite_Exec ($db, "CREATE TABLE 'names.ThirdGame.Help' ('Russian', 'English');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
    If Not _SQLite_Exec ($db, "CREATE TABLE 'names.ThirdGame.Help.Russian' ('FirstVersion', 'SecondVersion');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
    If Not _SQLite_Exec ($db, "CREATE TABLE 'names.ThirdGame.About' ('Programmers', 'Designers');") = $SQLITE_OK Then _
        MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
EndFunc
 
Func
_Load_From_SQL ()
    Dim $k ; Число подItem'ов в данном Item'е
    Dim $TempArray ; Временный массив
    $iRval = _SQLite_GetTable ($db, "SELECT * FROM '" & $db_Start & "';", $TempArray, '', $k) ; Считывает тэйбл в массив
    If $iRval = $SQLITE_OK Then ; если такой тэйбл существует, то
        For $i = 1 To $k
            $num
= $num + 1 ; увеличить счётчик TreeViewItem'ов
            $Array [$num][0] = $TempArray [$i] ; добавляем в глобальный массив название Item'а
            $Array [$num][1] = GUICtrlCreateTreeViewItem($TempArray [$i], $tv_Menu) ; добавляем в глобальный массив хэндл Item'а, а так же создаём Item в TreeView
            GUICtrlSetColor(-1, 0x0000C0) ; меняем цвет Item'а в TreeView'е
            $db_Start = $db_Start & "." & $TempArray[$i] ; меняем стартовую точку на текущий Item (например, при первом вызове будет 'names.FirstGame'), чтобы в будущем воспользоваться рекурсией и вызвать эту же функцию и найти остальные Item'ы
            _Load_From_SQL () ; рекурсия
        Next
    Else
; если таблицы не существует, то значит в данном Iteme нету подIteme
;~      msgbox('','',$db_Start)
;~      $var = StringRegExp($db_Start, "(^.*)\.(.*)$", 3) ; возврящаемся к предыдущему Iteme (например, был 'names.FirstGame.Maps', мы возврящаемся к 'names.FirstGame')
;~      $db_Start = $var[0]
;~      msgbox('','',$db_Start)

    EndIf
EndFunc

 
;~ В итоге должно получиться вот такое древо
 
;~      +---FirstGame
;~      |   +---Demos
;~      |   |   +---New
;~      |   |   |   +---FirstDemo
;~      |   |   |   +---SecondDemo
;~      |   |   +---Old
;~      |   |       +---FirstDemo
;~      |   |       +---SecondDemo
;~      |   |       +---ThirdDemo
;~      |   +---Maps
;~      |   |   +---CTF
;~      |   |   |   +---FirstMap
;~      |   |   |   +---SecondMap
;~      |   |   +---DM
;~      |   |       +---FirstMap
;~      |   |       +---FourthMap
;~      |   |       +---SecondMap
;~      |   |       +---ThirdMap
;~      |   +---Patch
;~      |       +---NewPatch
;~      |       +---OldPatch
;~      +---SecondGame
;~      |   +---Chat
;~      |   |   +---NewVersion
;~      |   |   +---OldVersion
;~      |   +---Mobs
;~      |       +---FirstList
;~      |       |   +---MobOne
;~      |       |   |   +---One
;~      |       |   |   +---Two
;~      |       |   +---MobTwo
;~      |       |       +---One
;~      |       |       +---Two
;~      |       +---SecondList
;~      +---ThirdGame
;~          +---About
;~          |   +---Designers
;~          |   +---Programmers
;~          +---Help
;~              +---English
;~              +---Russian
;~                  +---FirstVersion
;~                  +---SecondVersion

 
Func _Close_SQL ()
    _SQLite_Close ($db) ; закрываем Базу данных
    _SQLite_Shutdown () ; выгружаем SQLite.dll
    Exit ; завершаем программу
EndFunc

Всего записей: 68 | Зарегистр. 11-11-2009 | Отправлено: 23:00 21-02-2010 | Исправлено: MoBiRo, 02:27 22-02-2010
   

На первую страницук этому сообщениюк последнему сообщению

Компьютерный форум Ru.Board » Компьютеры » Программы » AutoIT (Часть 2)
Widok (01-06-2010 13:08): Лимит страниц. Продолжаем здесь.


Реклама на форуме Ru.Board.

Powered by Ikonboard "v2.1.7b" © 2000 Ikonboard.com
Modified by Ru.B0ard
© Ru.B0ard 2000-2024

BitCoin: 1NGG1chHtUvrtEqjeerQCKDMUi6S6CG4iC

Рейтинг.ru