-
Notifications
You must be signed in to change notification settings - Fork 7
/
Demo.bbj
157 lines (121 loc) · 3.69 KB
/
Demo.bbj
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
use ::BBjGridExWidget/BBjGridExWidget.bbj::BBjGridExWidget
use com.basiscomponents.bc.SqlQueryBC
declare auto BBjTopLevelWindow wnd!
declare auto BBjListButton lb_db!
declare auto BBjListButton lb_tbl!
declare auto BBjToolButton btn_fit!
declare BBjGridExWidget grid!
? 'HIDE'
BBjGridExWidget.setDebug(1)
wnd! = BBjAPI().openSysGui("X0").addWindow(10,10,900,600,"BBj Grid Ex Demo")
wnd!.addStaticText(200,5,10,60,25,"Database:")
lb_db! = wnd!.addListButton(201,65,5,160,250,"")
wnd!.addStaticText(202,270,10,60,25,"Table:")
lb_tbl! = wnd!.addListButton(203,310,5,160,250,"")
btn_query! = wnd!.addButton(204,500,5,100,25,"Query")
lb_theme! = wnd!.addListButton(211,610,5,85,250,"")
btn_fit! = wnd!.addToolButton(205,765,5,25,25,"[/]")
grid! = new BBjGridExWidget(wnd!,100,0,35,900,563)
grid!.setEnableFilter(1)
lb_db! .setCallback(BBjAPI.ON_LIST_SELECT,"loadTables")
btn_query! .setCallback(BBjAPI.ON_BUTTON_PUSH,"doQuery")
lb_theme! .setCallback(BBjAPI.ON_LIST_SELECT,"setTheme")
wnd! .setCallback(BBjAPI.ON_CLOSE,"byebye")
wnd! .setCallback(BBjAPI.ON_RESIZE,"resize")
btn_fit!.setToggleable(1)
btn_fit!.setCallback(BBjAPI.ON_TOOL_BUTTON_PUSH,"toggleFitToGrid")
if (info(3,6)<>"5") then
wnd!.setCallback(BBjAPI.ON_KEYPRESS,"onWinKeypress")
fi
gosub loadDatabases
gosub doQuery
rem disable the selection by default to avoid a backdoor if this demo is installed
rem enable to get the full db browsing functionality
rem lb_db!.setEnabled(0)
lb_theme!.insertItems(0,grid!.getThemes())
lb_theme!.selectIndex(0)
process_events
loadData:
return
byebye:
bye
resize:
ev! = BBjAPI().getLastEvent()
grid!.setSize(ev!.getWidth(),ev!.getHeight()-35)
return
loadDatabases:
j=0
i=0
x$ = sqllist(-1)
while x$>""
db$=x$(1,pos($0a$=x$)-1)
x$=x$(pos($0a$=x$)+1)
lb_db!.addItem(db$)
if db$="ChileCompany" then
j=i
fi
i=i+1
wend
lb_db!.selectIndex(j)
gosub loadTables
return
loadTables:
lb_tbl!.removeAllItems()
db$ = lb_db!.getSelectedItem()
sqlopen (1,err=no_db)db$
x$=sqltables(1)
sqlclose(1)
j=0
i=0
while x$>""
tbl$=x$(1,pos($0a$=x$)-1)
x$=x$(pos($0a$=x$)+1)
lb_tbl!.addItem(tbl$)
if tbl$="CUSTOMER" then
j=i
fi
i=i+1
wend
lb_tbl!.selectIndex(j)
return
no_db:
a=msgbox("Database "+db$+" does not exist!",16,"Error")
return
doQuery:
db$ = lb_db!.getSelectedItem()
tbl$ = lb_tbl!.getSelectedItem()
if (db$>"" and tbl$>"") then
if rev<"REV 17.10" then
url! = "jdbc:basis:localhost?DATABASE=ChileCompany&SSL=false"
con! = java.sql.DriverManager.getConnection(url!, "admin", "admin123")
else
bc! = new SqlQueryBC(BBjAPI().getJDBCConnection(db$))
fi
rs! = bc!.retrieve("SELECT * FROM "+tbl$,err=error_sql)
grid!.setData(rs!)
if db$="ChileCompany" AND tbl$="CUSTOMER" then
rs!.setAttribute(23,"MASK","%Y-%Mz-%Dz")
rs!.setAttribute(24,"MASK","%Y/%Mz/%Dz")
fi
fi
return
error_sql:
a=msgbox(BBjAPI().getLastException().getMessage() ,0,"ERROR")
return
toggleFitToGrid:
declare auto BBjToolButtonPushEvent toogle_ev!
toggle_ev! = BBjAPI().getLastEvent()
grid!.setFitToGrid()
return
onWinKeypress:
declare auto BBjKeypressEvent key_ev!
key_ev! = BBjAPI().getLastEvent()
if key_ev!.getKeyCode() = 342 then
grid!.showDeveloperConsole()
fi
return
setTheme:
ev! = BBjAPI().getLastEvent()
theme$ = ev!.getSelectedItem()
grid!.setTheme(theme$)
return