PowerBuilder Dynamic Datawindow With Arguments
Source Code
nvo_dwgenerator from nonvisualobject
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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
forward global type nvo_dwgenerator from nonvisualobject end type type st_data_arg from structure within nvo_dwgenerator end type end forward type st_data_arg from structure string arg_name string arg_type end type global type nvo_dwgenerator from nonvisualobject end type global nvo_dwgenerator nvo_dwgenerator type variables public: CONSTANT STRING STRING_TYPE = 'string' CONSTANT STRING NUMBER_TYPE = 'number' CONSTANT STRING DATE_TYPE = 'date' CONSTANT STRING TIME_TYPE = 'time' CONSTANT STRING DATETIME_TYPE = 'datetime' CONSTANT STRING DECIMAL_TYPE = 'decimal' CONSTANT STRING STRINGARRAY_TYPE = 'stringlist' CONSTANT STRING NUMBERARRAY_TYPE = 'numberlist' CONSTANT STRING DATEARRAY_TYPE = 'datelist' CONSTANT STRING TIMEARRAY_TYPE = 'timelist' CONSTANT STRING DATETIMEARRAY_TYPE = 'datetimelist' CONSTANT STRING DECIMALARRAY_TYPE = 'decimallist' private: string sql_syntax boolean proc_flag st_data_arg args[] string presentation = 'style(type=grid)' transaction trs end variables forward prototypes public function integer set_argument (integer position, string arg_name, string arg_type) public function integer create_datastore (ref datastore ds) public subroutine reset () public subroutine set_sql (string sql) public subroutine set_procedure (string proc) public function integer create_datawindow (datawindow dw) public subroutine set_presentation (string p) public subroutine set_transobject (transaction t) public function integer create_syntax (ref string syntax) public subroutine get_arguments (datawindow adw, ref string as_arg_name[], ref string as_arg_type[], ref string as_arg_value[]) end prototypes public function integer set_argument (integer position, string arg_name, string arg_type);//==================================================================== // Function: nvo_dwgenerator.set_argument() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value integer position // value string arg_name // value string arg_type //-------------------------------------------------------------------- // Returns: integer //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2021/06/23 //-------------------------------------------------------------------- // Usage: nvo_dwgenerator.set_argument ( integer position, string arg_name, string arg_type ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== st_data_arg arg If Position < 1 Then Return -1 If Not (arg_type = STRING_TYPE Or & arg_type = NUMBER_TYPE Or & arg_type = DATE_TYPE Or & arg_type = TIME_TYPE Or & arg_type = DATETIME_TYPE Or & arg_type = DECIMAL_TYPE Or & arg_type = STRINGARRAY_TYPE Or & arg_type = NUMBERARRAY_TYPE Or & arg_type = DATEARRAY_TYPE Or & arg_type = TIMEARRAY_TYPE Or & arg_type = DATETIMEARRAY_TYPE Or & arg_type = DECIMALARRAY_TYPE) Then Return -1 End If arg.arg_name = arg_name arg.arg_type = arg_type args[Position] = arg Return 0 end function public function integer create_datastore (ref datastore ds);//==================================================================== // Function: nvo_dwgenerator.create_datastore() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // reference datastore ds //-------------------------------------------------------------------- // Returns: integer //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2021/06/23 //-------------------------------------------------------------------- // Usage: nvo_dwgenerator.create_datastore ( ref datastore ds ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== String dwsyntax If create_syntax(dwsyntax) < 0 Then Return -1 If Not IsValid(ds) Then ds = Create datastore End If Return ds.Create(dwsyntax) end function public subroutine reset ();//==================================================================== // Function: nvo_dwgenerator.reset() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: //-------------------------------------------------------------------- // Returns: (none) //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2021/06/23 //-------------------------------------------------------------------- // Usage: nvo_dwgenerator.reset ( ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== st_data_arg empty_args[] args = empty_args sql_syntax = '' presentation = 'style(type=grid)' trs = sqlca end subroutine public subroutine set_sql (string sql); sql_syntax = sql proc_flag = False end subroutine public subroutine set_procedure (string proc); sql_syntax = Proc proc_flag = True end subroutine public function integer create_datawindow (datawindow dw);//==================================================================== // Function: nvo_dwgenerator.create_datawindow() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value datawindow dw //-------------------------------------------------------------------- // Returns: integer //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2021/06/23 //-------------------------------------------------------------------- // Usage: nvo_dwgenerator.create_datawindow ( datawindow dw ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== If Not IsValid(dw) Then Return -1 String dwsyntax If create_syntax(dwsyntax) < 0 Then Return -1 Return dw.Create(dwsyntax) end function public subroutine set_presentation (string p);presentation = p end subroutine public subroutine set_transobject (transaction t);trs = t end subroutine public function integer create_syntax (ref string syntax);//==================================================================== // Function: nvo_dwgenerator.create_syntax() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // reference string syntax //-------------------------------------------------------------------- // Returns: integer //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2021/06/23 //-------------------------------------------------------------------- // Usage: nvo_dwgenerator.create_syntax ( ref string syntax ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Int i Long ll_pos, ll_pos_start, ll_pos_end String ls_sql Char lc_sql[] String param String ls_str Char lc_syntax[] Long j, k String ls_dwsyntax, ls_err Char lc_dwsql[] String ls_arguments ls_sql = sql_syntax lc_sql = ls_sql For i = 1 To UpperBound(args) ll_pos_start = 1 Do While True ll_pos = Pos(ls_sql, ':'+args[i].arg_name, ll_pos_start) If ll_pos <= 0 Then Exit ll_pos_end = ll_pos + Len(args[i].arg_name) If ll_pos_end < Len(ls_sql) Then If Not (lc_sql[ll_pos_end + 1] = ' ' Or & lc_sql[ll_pos_end + 1] = '~r' Or & lc_sql[ll_pos_end + 1] = '~n' Or & lc_sql[ll_pos_end + 1] = '~t' Or & lc_sql[ll_pos_end + 1] = ')') Then ll_pos_start = ll_pos_end + 1 Continue End If End If Choose Case args[i].arg_type Case STRING_TYPE, STRINGARRAY_TYPE param = "'"+Space(255)+"'" Case NUMBER_TYPE, NUMBERARRAY_TYPE param = '0' Case DECIMAL_TYPE, DECIMALARRAY_TYPE param = '0.0' Case Else param = '' End Choose ls_sql = Replace(ls_sql, ll_pos, Len(args[i].arg_name) + 1, param) lc_sql = ls_sql ll_pos_start = ll_pos Loop Next //Create SyntaxFromSQL ls_dwsyntax = trs.SyntaxFromSQL( ls_sql, presentation, ls_err) If Len(ls_err) > 0 Then Messagebox("Warning", "Create Syntax ls_error " + ls_err) Return -1 End If //Retrieve lc_syntax = ls_dwsyntax If proc_flag Then ls_str = 'procedure="' Else ls_str = 'retrieve="' End If ll_pos = Pos(ls_dwsyntax, ls_str) j = ll_pos + Len(ls_str) Do While j < UpperBound(lc_syntax) If lc_syntax[j] = '"' Then ll_pos_end = j Exit End If If lc_syntax[j] = '~~' Then j += 2 Continue End If j ++ Loop //ls_arguments For i = 1 To UpperBound(args) ls_arguments += '("' + args[i].arg_name + '", ' + args[i].arg_type + ')' If i < UpperBound(args) Then ls_arguments += ',' End If Next ls_arguments = ' arguments=(' + ls_arguments + ')' ls_dwsyntax = Replace(ls_dwsyntax, ll_pos_end + 1, 0, ls_arguments) //Generator Syntax lc_sql = sql_syntax For j = 1 To UpperBound(lc_sql) If lc_sql[j] = '~~' Or lc_sql[j] = '"' Then k++ lc_dwsql[k] = '~~' End If k++ lc_dwsql[k] = lc_sql[j] Next ls_dwsyntax = Replace(ls_dwsyntax, ll_pos + Len(ls_str), ll_pos_end - ll_pos - Len(ls_str), lc_dwsql) Syntax = ls_dwsyntax Return 0 end function public subroutine get_arguments (datawindow adw, ref string as_arg_name[], ref string as_arg_type[], ref string as_arg_value[]);//==================================================================== // Function: nvo_dwgenerator.get_arguments() //-------------------------------------------------------------------- // Description: //-------------------------------------------------------------------- // Arguments: // value datawindow adw // reference string as_arg_name[] // reference string as_arg_type[] //-------------------------------------------------------------------- // Returns: (none) //-------------------------------------------------------------------- // Author: PB.BaoGa Date: 2021/06/23 //-------------------------------------------------------------------- // Usage: nvo_dwgenerator.get_arguments ( datawindow adw, ref string as_arg_name[], ref string as_arg_type[] ) //-------------------------------------------------------------------- // Copyright (c) PB.BaoGa(TM), All rights reserved. //-------------------------------------------------------------------- // Modify History: // //==================================================================== Long ll_pos_tab, ll_pos_new_line, li_i String ls_arg_full_text, ls_arguments, ls_arg_name[], ls_arg_type[], ls_arg_value[] String ls_TAB = Char(9), ls_new_line = Char(10) ls_arg_full_text = adw.Describe("DataWindow.table.arguments") If ls_arg_full_text = '?' Or ls_arg_full_text = '!' Then ls_arg_full_text = '' Do While ls_arg_full_text <> '' li_i++ ll_pos_tab = Pos(ls_arg_full_text, ls_TAB) ls_arg_name[li_i] = Left(ls_arg_full_text, ll_pos_tab - 1) ls_arg_value[li_i] = adw.Describe("Evaluate('" + ls_arg_name[li_i] + "', 0)") ll_pos_new_line = Pos(ls_arg_full_text, ls_new_line, ll_pos_tab + 1) If ll_pos_new_line = 0 Then ll_pos_new_line = Len(ls_arg_full_text) + 1 ls_arg_type[li_i] = Mid(ls_arg_full_text, ll_pos_tab + 1, ll_pos_new_line - ll_pos_tab - 1) ls_arg_full_text = Mid(ls_arg_full_text, ll_pos_new_line + 1) /* ls_arguments = ls_arguments + ls_new_line + Char(13) + & ls_arg_name[li_i] + Fill(' ', 25 - Len(ls_arg_name[li_i])) + ls_TAB + & ls_arg_type[li_i] + Fill(' ', 15 - Len(ls_arg_type[li_i])) + ls_TAB + & ls_arg_value[li_i] */ Loop as_arg_name = ls_arg_name as_arg_type = ls_arg_type as_arg_value = ls_arg_value //MessageBox('Arg', ls_arguments ) //'Datawindow.Table.Arguments' = id number~r~n data_start datetime~r~n data_end datetime //'Datawindow.Table.Procedure' = 1 execute dbo.sp_name @id = :id, @data_start = :data_start, @data_end = :data_end end subroutine on nvo_dwgenerator.create call super::create TriggerEvent( this, "constructor" ) end on on nvo_dwgenerator.destroy TriggerEvent( this, "destructor" ) call super::destroy end on event constructor;trs = sqlca end event |
w_main from window
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 |
forward global type w_main from window end type type cb_1 from commandbutton within w_main end type type cb_4 from commandbutton within w_main end type type dw_emp from datawindow within w_main end type type cb_2 from commandbutton within w_main end type end forward global type w_main from window integer width = 1801 integer height = 1420 boolean titlebar = true string title = "Dynamic Datawindow Arguments" boolean controlmenu = true boolean minbox = true boolean maxbox = true boolean resizable = true long backcolor = 67108864 string icon = "AppIcon!" boolean center = true cb_1 cb_1 cb_4 cb_4 dw_emp dw_emp cb_2 cb_2 end type global w_main w_main on w_main.create this.cb_1=create cb_1 this.cb_4=create cb_4 this.dw_emp=create dw_emp this.cb_2=create cb_2 this.Control[]={this.cb_1,& this.cb_4,& this.dw_emp,& this.cb_2} end on on w_main.destroy destroy(this.cb_1) destroy(this.cb_4) destroy(this.dw_emp) destroy(this.cb_2) end on type cb_1 from commandbutton within w_main integer x = 585 integer y = 32 integer width = 443 integer height = 112 integer taborder = 30 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Get Arguments" end type event clicked;String ls_arg_name[], ls_arg_type[], ls_arg_value[] nvo_dwgenerator ldwgen ldwgen = Create nvo_dwgenerator ldwgen.get_arguments(dw_emp, ls_arg_name, ls_arg_type, ls_arg_value) end event type cb_4 from commandbutton within w_main integer x = 1061 integer y = 32 integer width = 667 integer height = 112 integer taborder = 30 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Create From Procedure" end type event clicked;/* create or replace procedure pro_get_emp_list(p_job in varchar2, p_sal in number, emp_list out sys_refcursor) is begin open emp_list for select empno, ename, job, mgr, hiredate, sal from scott.emp where job = p_job and sal > p_sal; end pro_get_emp_list; */ /* nvo_dwgenerator dsgen dsgen = Create nvo_dwgenerator dsgen.set_procedure('execute pro_get_emp_list; p_job=:p_job ,p_sal=:p_sal') dsgen.set_argument( 1, 'p_job', dsgen.STRING_TYPE) dsgen.set_argument( 2, 'p_sal', dsgen.NUMBER_TYPE) dsgen.create_datawindow( dw_emp) dw_emp.SetTransObject(SQLCA) dw_emp.Retrieve('CLERK', 1000) Return 0 */ /* create procedure DBA.sp_customer_products(inout customer_id integer) result(id integer,quantity_ordered integer) begin select product.id,sum(sales_order_items.quantity) from product,sales_order_items,sales_order where sales_order.cust_id = customer_id and sales_order.id = sales_order_items.id and sales_order_items.prod_id = product.id group by product.id end */ nvo_dwgenerator dsgen dsgen = Create nvo_dwgenerator dsgen.set_procedure("execute sp_customer_products; customer_id=:customer_id") dsgen.set_argument( 1, 'customer_id', dsgen.number_type ) dsgen.create_datawindow( dw_emp) dw_emp.SetTransObject(SQLCA) dw_emp.Retrieve(103) Return 0 end event type dw_emp from datawindow within w_main integer x = 37 integer y = 160 integer width = 1682 integer height = 1088 integer taborder = 40 string title = "none" boolean hscrollbar = true boolean vscrollbar = true boolean livescroll = true borderstyle borderstyle = stylelowered! end type type cb_2 from commandbutton within w_main integer x = 37 integer y = 32 integer width = 485 integer height = 112 integer taborder = 20 integer textsize = -10 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Tahoma" string text = "Create From Sql" end type event clicked;nvo_dwgenerator dsgen dsgen = Create nvo_dwgenerator dsgen.set_sql("select dept_id, dept_name, dept_head_id from department where dept_id = :as_dept_id") dsgen.set_argument( 1, 'as_dept_id', dsgen.number_type ) dsgen.create_datawindow( dw_emp) dw_emp.SetTransObject(SQLCA) dw_emp.Retrieve(100) Return 0 end event |
Find Projects On Github click here
Good Luck!
Subscribe
Login
0 Comments
Oldest