1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
/****************************************************************************
** Form implementation generated from reading ui file 'book.ui'
**
** Created: Wed Aug 8 03:34:02 2001
** by: The User Interface Compiler (uic)
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/
import org.kde.qt.*;
public class BookForm extends TQWidget {
TQDataTable AuthorDataTable;
TQDataTable BookDataTable;
TQPushButton connectButton;
TQPushButton editButton;
TQGridLayout BookFormLayout;
TQSizePolicy policy_1;
TQSizePolicy policy_2;
TQSpacerItem spacer;
TQSpacerItem spacer_2;
TQSqlCursor authorCursor;
TQSqlCursor bookCursor;
/*
* Constructs a BookForm which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
*/
BookForm( TQWidget parent, String name, int fl )
{
super( parent, name, fl );
if ( name == null )
setName( "BookForm" );
resize( 478, 498 );
setCaption( trUtf8( "Book" ) );
BookFormLayout = new TQGridLayout( this );
BookFormLayout.setSpacing( 6 );
BookFormLayout.setMargin( 11 );
AuthorDataTable = new TQDataTable( this, "AuthorDataTable" );
AuthorDataTable.addColumn( "surname", trUtf8( "Surname", "" ) );
AuthorDataTable.addColumn( "forename", trUtf8( "Forename", "" ) );
AuthorDataTable.setSorting( true );
AuthorDataTable.setConfirmDelete( true );
AuthorDataTable.setSort( new String[] { "surname ASC", "forename ASC" } );
BookFormLayout.addMultiCellWidget( AuthorDataTable, 1, 1, 0, 2 );
spacer = new TQSpacerItem( 20, 20, TQSizePolicy.Expanding, TQSizePolicy.Minimum );
BookFormLayout.addMultiCell( spacer, 0, 0, 1, 2 );
BookDataTable = new TQDataTable( this, "BookDataTable" );
BookDataTable.addColumn( "title", trUtf8( "Title", "" ) );
BookDataTable.addColumn( "price", trUtf8( "Price", "" ) );
BookDataTable.addColumn( "notes", trUtf8( "Notes", "" ) );
BookDataTable.setReadOnly( true );
BookDataTable.setSorting( true );
BookDataTable.setSort( new String[] { "title ASC" } );
BookFormLayout.addMultiCellWidget( BookDataTable, 2, 2, 0, 2 );
spacer_2 = new TQSpacerItem( 20, 20, TQSizePolicy.Expanding, TQSizePolicy.Minimum );
BookFormLayout.addMultiCell( spacer_2, 3, 3, 0, 1 );
connectButton = new TQPushButton( this, "connectButton" );
policy_1 = new TQSizePolicy( (int)0, (int)0, connectButton.sizePolicy().hasHeightForWidth() );
connectButton.setSizePolicy( policy_1 );
connectButton.setText( trUtf8( "&Connect..." ) );
BookFormLayout.addWidget( connectButton, 0, 0 );
editButton = new TQPushButton( this, "editButton" );
editButton.setEnabled( false );
policy_2 = new TQSizePolicy( (int)0, (int)0, editButton.sizePolicy().hasHeightForWidth() );
editButton.setSizePolicy( policy_2 );
editButton.setText( trUtf8( "&Edit Books" ) );
BookFormLayout.addWidget( editButton, 3, 2 );
// database support
// signals and slots connections
connect( editButton, SIGNAL( "clicked()" ), this, SLOT( "editClicked()" ) );
connect( AuthorDataTable, SIGNAL( "primeInsert(TQSqlRecord)" ), this, SLOT( "primeInsertAuthor(TQSqlRecord)" ) );
connect( AuthorDataTable, SIGNAL( "currentChanged(TQSqlRecord)" ), this, SLOT( "newCurrentAuthor(TQSqlRecord)" ) );
connect( connectButton, SIGNAL( "clicked()" ), this, SLOT( "connectClicked()" ) );
// tab order
setTabOrder( connectButton, editButton );
init();
}
BookForm( TQWidget parent, String name )
{
this(parent, name, 0);
}
BookForm( TQWidget parent )
{
this(parent, null, 0);
}
BookForm( )
{
this(null, null, 0);
}
void init()
{
}
public void destroy()
{
}
void editClicked()
{
EditBookForm dialog = new EditBookForm( this, "Edit Book Form", true, 0 );
TQSqlCursor cur = new TQSqlCursor( "book" );
dialog.BookDataBrowser.setSqlCursor( cur );
dialog.BookDataBrowser.setFilter( BookDataTable.filter() );
String[] sort = new String[BookDataTable.sort().size()];
sort = (String[]) BookDataTable.sort().toArray(sort);
dialog.BookDataBrowser.setSort(TQSqlIndex.fromStringList(
sort, cur ) );
dialog.BookDataBrowser.refresh();
int i = BookDataTable.currentRow();
if ( i == -1 ) i = 0; // Always use the first row
dialog.BookDataBrowser.seek( i );
dialog.exec();
dialog = null;
BookDataTable.refresh();
}
void connectClicked()
{
boolean ok = false;
ConnectDialog dialog = new ConnectDialog( this, "Connect", true, 0 );
String[] drivers = new String[TQSqlDatabase.drivers().size()];;
drivers = (String[]) TQSqlDatabase.drivers().toArray(drivers);
dialog.comboDriver.insertStringList( drivers );
dialog.editDatabase.setText( "book" );
if ( dialog.exec() == TQDialog.Accepted ) {
// TQSqlDatabase.removeDatabase( TQSqlDatabase.defaultConnection() );
TQSqlDatabase db = TQSqlDatabase.addDatabase( dialog.comboDriver.currentText() );
db.setDatabaseName( dialog.editDatabase.text() );
db.setUserName( dialog.editUsername.text() );
db.setPassword( dialog.editPassword.text() );
db.setHostName( dialog.editHostname.text() );
if ( !db.open() ) {
//## warning?
ok= false;
} else
ok = true;
}
if ( !ok ) {
editButton.setEnabled( false );
BookDataTable.setSqlCursor( (TQSqlCursor) null );
AuthorDataTable.setSqlCursor( (TQSqlCursor) null );
} else {
editButton.setEnabled( true );
authorCursor = new TQSqlCursor( "author" );
AuthorDataTable.setSqlCursor( authorCursor, false, true );
bookCursor = new TQSqlCursor( "book" );
BookDataTable.setSqlCursor( bookCursor, false, true );
AuthorDataTable.refresh( TQDataTable.RefreshAll );
BookDataTable.refresh( TQDataTable.RefreshAll );
}
dialog = null;
}
void newCurrentAuthor(TQSqlRecord author)
{
BookDataTable.setFilter( "authorid=" + author.value( "id" ).toString() );
BookDataTable.refresh();
}
void primeInsertAuthor(TQSqlRecord buffer)
{
TQSqlQuery q = new TQSqlQuery();
q.exec( "UPDATE sequence SET sequence = sequence + 1 WHERE tablename='author';" );
q.exec( "SELECT sequence FROM sequence WHERE tablename='author';" );
if ( q.next() ) {
buffer.setValue( "id", q.value( 0 ) );
}
}
}
|