Приложения с БД.

Маленькое приложение «Домашняя библиотека» с использованием базы данных.

<AppXML title="Домашняя библиотека"  default-class-name="Lib" log-modifying-date="true" language="ru">
	
    <connect type="h2" login="sa" password="" alias="file:.data/homeLib" connect="true"/>
	
    <database component-id="homeLibDatabase">
        <db version="1">
            create table genre ( id integer not null auto_increment,
                                 name varchar(50),
                                 modified_date datetime not null,
                                 primary key (id)
                                ); 

            create table authors (id integer not null auto_increment,
                                  name varchar(50),
                                  lastname varchar(20),
                                  firstname varchar(20),
                                  middlename varchar(20),
                                  modified_date datetime not null,
                                  primary key (id)
                                );
                                          
            create table books ( id integer not null auto_increment,
                                 name varchar(50),
                                 genre_id integer not null,
                                 author_id integer not null,
                                 modified_date datetime not null,
                                 primary key (id),
                                 constraint fk_books_genre
                                 foreign key (genre_id) references genre(id),
                                 constraint fk_books_author
                                 foreign key (author_id) references authors(id)
                               );
        </db>
    </database>

    <main>
        <window id="mainWindow"  title="Домашняя библиотека" location="center" height="600" width="800">
            <panel id="treeMenu" width="150" position="left" oncreated="booksView:mainPanel">
                <tree id="mainTree" title="Меню" margin="0">
                    <treeitem text="Список книг" onselected="booksView:mainPanel"/>
                    <treeitem text="Справочники">
                        <treeitem text="Жанр" onselected="genreView:mainPanel"/>
                        <treeitem text="Автор" onselected="authorView:mainPanel"/>
                    </treeitem>	 
                    <treeitem text="Выход" onselected="mainWindow.close = true"/>
                </tree>
            </panel>	
        	
            <panel id="mainPanel"/>
        </window>
    </main>
    
    <common>
        <view id="genreView" title="Справочник жанров" grid-mode="on"
                 statusbar-visible="false"
                 margin="0" 
                 sql="select id, name from genre #refresh# order by name"
                 table-name="genre" id-field="id">
            <toolbar visible="true"/>
            <columns>
                <column name="name" text="Название"/>
            </columns>
            <edit unique="name">
                <edititem id="name" text="Название жанра" db-field="name" required="true"/>
            </edit>
        </view>
        
        <view id="authorView" title="Справочник авторов" statusbar-visible="false" margin="0" grid-mode="on"
                 sql="select id, name, lastname, firstname, middlename  from authors #refresh# order by name"
                 table-name="authors" id-field="id">
            <toolbar visible="true"/>
            <columns>
                <column name="name" text="Фамилия И.О."/>
                <column name="lastname" text="Фамилия"/>
                <column name="firstname" text="Имя"/>
                <column name="middlename" text="Отчество"/>
            </columns>
            <edit>
                <edititem id="name" text="Сокращенное имя"	db-field="name"	required="true"/>
                <edititem id="lastname" text="Фамилия"	db-field="lastname"	required="true"/>
                <edititem id="firstname" text="Имя"	db-field="firstname"	required="true"/>>
                <edititem id="middlename" text="Отчество"	db-field="middlename"	required="false"/>
            </edit>
        </view>
	    
        <view id="booksView" title="Список книг" statusbar-visible="false" margin="0" grid-mode="on"
                 sql="select books.id as id, 
                             books.name as name, 
                             authors.name as author, 
                             genre.name as genre
                      from books 
                           LEFT JOIN authors ON (books.author_id=authors.id)
                           LEFT JOIN genre ON (books.genre_id=genre.id)
                      #refresh# order by name"
                 table-name="books" id-field="id">
            <toolbar visible="true"/>
            <columns>
                <column name="name" text="Название книги"/>
                <column name="author" text="Автор"/>
                <column name="genre" text="Жанр"/>
            </columns>
            <edit>
                <edititem id="name" text="Название книги" db-field="name" required="true"/>
                <edititem id="author" text="Автор" db-field="author_id" reference-id="authorView" required="true"/>
                <edititem id="genre_id" text="Жанр"	db-field="genre_id" reference-id="genreView" required="true"/>
            </edit>
        </view>
    </common>
</AppXML>
 
examples/app_db/home_lib.txt · Последние изменения: 29/10/2020 16:33 (внешнее изменение)
 
Recent changes RSS feed Valid XHTML 1.0 Valid CSS