Quer obter os dados das tabelas do Protheus via WebService? Eis um exemplo fornecido por BlackTDN.
1 #include "set.ch"
2 #include "apwebsrv.ch"
3 #include "protheus.ch"
4 #include "dbstruct.ch"
5 #include "topconn.ch"
6 #include "wsubtdnTView.ch"
7 #include "tryexception.ch"
8
9 Static __lAS400 := ( TCSrvType() == "AS/400" )
10 Static __cTCGetDB := Upper(AllTrim(TCGetDB()))
11
12 /*
13 Progama: wsubtdnTView.prg
14 WebStruct: uFieldStruct
15 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
16 Data: 21/11/2013
17 Descricao: Deriva de FieldStruct e carrega informacoes complementares
18 Uso: WebServices
19 */
20 WSSTRUCT uFieldStruct
21 WSDATA FldName AS STRING
22 WSDATA FldType AS STRING
23 WSDATA FldSize AS INTEGER
24 WSDATA FldDec AS INTEGER
25 WSDATA FldTitle AS STRING
26 WSDATA FldMandatory AS BOOLEAN
27 WSDATA FldDescription AS STRING
28 ENDWSSTRUCT
29
30 /*
31 Progama: wsubtdnTView.prg
32 WebStruct: uFieldsName
33 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
34 Data: 21/11/2013
35 Descricao: Deriva de FieldStruct e carrega informacoes complementares
36 Uso: WebServices
37 */
38 WSSTRUCT uFieldsName
39 WSDATA uFldName AS ARRAY OF STRING
40 ENDWSSTRUCT
41
42 /*
43 Progama: wsubtdnTView.prg
44 WebStruct: uFieldView
45 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
46 Data: 21/11/2013
47 Descricao: Semelhanete a FieldView
48 Uso: WebServices
49 */
50 WSSTRUCT uFieldView
51 WSDATA FldTag AS ARRAY OF STRING
52 ENDWSSTRUCT
53
54 /*
55 Progama: wsubtdnTView.prg
56 WebStruct: uAnyCodeDesc
57 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
58 Data: 21/11/2013
59 Descricao: Codigo e Descricao
60 Uso: WebServices
61 */
62 WSSTRUCT uAnyCodeDesc
63 WSDATA Code AS STRING
64 WSDATA Description AS STRING
65 ENDWSSTRUCT
66
67 /*
68 Progama: wsubtdnTView.prg
69 WebStruct: uTAliases
70 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
71 Data: 21/11/2013
72 Descricao: Estrutura para dados do SX2
73 Uso: WebServices
74 */
75 WSSTRUCT uTAliases
76 WSDATA TAliases AS ARRAY OF uAnyCodeDesc
77 ENDWSSTRUCT
78
79 /*
80 Progama: wsubtdnTView.prg
81 WebStruct: uTableView
82 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
83 Data: 21/11/2013
84 Descricao: Deriva de TableView e carrega informacoes complementares
85 Uso: WebServices
86 */
87 WSSTRUCT uTableView
88 WSDATA TableData AS ARRAY OF /*u*/FieldView
89 WSDATA TableStruct AS ARRAY OF uFieldStruct
90 ENDWSSTRUCT
91
92 /*
93 Progama: wsubtdnTView.prg
94 WebService: ubtdnTView
95 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
96 Data: 21/11/2013
97 Descricao: Obter dados de uma tabela do Protheus
98 Uso: WebServices
99 */
100 WSSERVICE ubtdnTView DESCRIPTION STR0001 NAMESPACE "http://www.blacktdn.com.br" //"Obter informacoes de uma tabela do Protheus"
101
102 WSDATA Table AS uTableView
103
104 WSDATA Alias AS STRING
105 WSDATA TAlias AS uTAliases
106
107 WSDATA Where AS STRING
108
109 WSDATA rInit AS INTEGER
110 WSDATA rEnd AS INTEGER
111 WSDATA rMax AS INTEGER
112
113 WSDATA FieldsName AS uFieldsName
114
115 WSDATA TableData AS ARRAY OF /*u*/FieldView
116 WSDATA TableStruct AS ARRAY OF uFieldStruct
117
118 WSDATA rDeleted AS BOOLEAN
119 WSDATA rRecno AS BOOLEAN
120
121 WSMETHOD getTRMax DESCRIPTION STR0004 //"Obter o maior registro em uma Tabela"
122 WSMETHOD getTAlias DESCRIPTION STR0017 //"Obter Aliases validos para recuperação de dados"
123
124 WSMETHOD getTable DESCRIPTION STR0002 //"Obter informacoes de uma Tabela"
125 WSMETHOD getTbyWhere DESCRIPTION STR0003 //"Obter informacoes de uma Tabela (Usando Filtro)"
126
127 WSMETHOD getTData DESCRIPTION STR0006 //"Obter os dados da Tabela"
128 WSMETHOD getTStruct DESCRIPTION STR0005 //"Obter a estrutura da Tabela"
129 WSMETHOD getTFieldsName DESCRIPTION STR0016 //"Obter os campos de uma Tabela"
130
131 WSMETHOD getTablebyFieldsName DESCRIPTION STR0012 //"Obter informacoes de uma Tabela baseado na selecao de campos"
132 WSMETHOD getTbyWhereAndFieldsName DESCRIPTION STR0013 //"Obter informacoes de uma Tabela (Usando Filtro) e baseado na selecao de campos"
133
134 WSMETHOD getTDatabyFieldsName DESCRIPTION STR0014 //"Obter os dados da Tabela baseado na selecao de campos"
135 WSMETHOD getTStructbyFieldsName DESCRIPTION STR0015 //"Obter a estrutura da Tabela baseado na selecao de campos"
136
137 ENDWSSERVICE
138
139 /*
140 Progama: wsubtdnTView.prg
141 WsMethod: getTRMax
142 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
143 Data: 21/11/2013
144 Descricao: Obtem o maior registro em uma tabela
145 Uso: WebServices
146 */
147 WSMETHOD getTRMax WSRECEIVE Alias , rDeleted WSSEND rMax WSSERVICE ubtdnTView
148
149 Local adbQuery := Array(0)
150
151 Local cAlias
152 Local cSQLName
153 Local cRddName
154
155 Local lQuery := .T.
156 Local lWsMethodRet := .T.
157 Local lSetDeleted := Set(_SET_DELETED,"ON")
158
159 Local oException
160
161 TRYEXCEPTION
162
163 IF .NOT.(Empty(self:Alias))
164 self:Alias := Upper(AllTrim(self:Alias))
165 DEFAULT Alias := self:Alias
166 EndIF
167
168 IF .NOT.(Empty(Alias))
169 Alias := Upper(AllTrim(Alias))
170 EndIF
171
172 IF (Empty(self:Alias) .and. .NOT.(Empty(Alias)))
173 self:Alias := Alias
174 EndIF
175
176 DEFAULT self:rDeleted := .T.
177 DEFAULT rDeleted := self:rDeleted
178 IF .NOT.( rDeleted == self:rDeleted )
179 self:rDeleted := rDeleted
180 EndIF
181
182 Set(_SET_DELETED,IF(self:rDeleted,"OFF","ON"))
183
184 IF ( Select(self:Alias) == 0 )
185 TRYEXCEPTION
186 ChkFile(self:Alias)
187 ENDEXCEPTION
188 EndIF
189
190 TRYEXCEPTION
191 cRddName := (self:Alias)->( RddName() )
192 ENDEXCEPTION
193
194 lQuery := ( cRddName == "TOPCONN" )
195 IF .NOT.( lQuery )
196 rMax := (self:Alias)->(RecCount())
197 EndIF
198
199 IF ( lQuery )
200
201 cSQLName := RetSQLName(self:Alias)
202
203 IF .NOT.( MsFile( cSQLName ) )
204 IF .NOT.( ChkFile(self:Alias) )
205 UserException( STR0007 + self:Alias ) //"Problema na abertura da Tabela: "
206 EndIF
207 EndIF
208
209 IF ( __lAS400 )
210 cQuery := "SELECT MAX(RRN("+cSQLName+")) MAXRECNO "
211 Else
212 cQuery := "SELECT MAX("+self:Alias+".R_E_C_N_O_) MAXRECNO "
213 EndIF
214 cQuery += " FROM "+cSQLName+" "+self:Alias
215 IF .NOT.(self:rDeleted)
216 IF ( __lAS400 )
217 cQuery += " WHERE "+self:Alias+".@DELETED@<>'*'"
218 Else
219 cQuery += " WHERE "+self:Alias+".D_E_L_E_T_<>'*'"
220 EndIf
221 EndIF
222
223 IF .NOT.( dbQuery(@adbQuery,cQuery,@cAlias) )
224 rMax := 0
225 ENDIF
226
227 rMax := (cAlias)->MAXRECNO
228
229 EndIF
230
231 self:rMax := rMax
232
233 CATCHEXCEPTION USING oException
234
235 lWsMethodRet := .F.
236
237 SetSoapFault( ProcName() , oException:Description + CRLF + oException:ErrorStack )
238
239 ENDEXCEPTION
240
241 aEval( adbQuery , { |cAlias| IF( ( Select( cAlias ) > 0 ) , (cAlias)->( dbCloseArea() ) , NIL ) } )
242
243 Set(_SET_DELETED,IF(lSetDeleted,"ON","OFF"))
244
245 Return( lWsMethodRet )
246
247 /*
248 Progama: wsubtdnTView.prg
249 WsMethod: getTAlias
250 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
251 Data: 21/11/2013
252 Descricao: Obter Aliases validos para recuperação de dados
253 Uso: WebServices
254 */
255 WSMETHOD getTAlias WSRECEIVE rInit , rEnd WSSEND TAlias WSSERVICE ubtdnTView
256
257 Local lWsMethodRet := .T.
258
259 Local nAlias := 0
260 Local nRecno
261
262 Local oException
263
264 TRYEXCEPTION
265
266 DEFAULT self:rInit := 0
267 DEFAULT rInit := self:rInit
268 IF (Empty(self:rInit) .and. .NOT.(Empty(rInit)))
269 self:rInit := rInit
270 EndIF
271
272 DEFAULT self:rEnd := 0
273 DEFAULT rEnd := self:rEnd
274 IF (Empty(self:rEnd) .and. .NOT.(Empty(rEnd)))
275 self:rEnd := rEnd
276 EndIF
277
278 TAlias := WsClassNew("uTAliases")
279 self:TAlias := TAlias
280 TAlias:TAliases := Array(0)
281
282 For nRecno := self:rInit To self:rEnd
283 SX2->( dbGoTo(nRecno) )
284 IF SX2->( Eof() .or. Bof() )
285 Loop
286 EndIF
287 ++nAlias
288 aAdd(TAlias:TAliases,WsClassNew("uAnyCodeDesc"))
289 TAlias:TAliases[nAlias]:Code := SX2->X2_CHAVE
290 TAlias:TAliases[nAlias]:Description := __UTF8(AllTrim(X2Nome()))
291 Next nRecno
292
293 CATCHEXCEPTION USING oException
294
295 lWsMethodRet := .F.
296
297 SetSoapFault( ProcName() , oException:Description + CRLF + oException:ErrorStack )
298
299 ENDEXCEPTION
300
301 Return( lWsMethodRet )
302
303 /*
304 Progama: wsubtdnTView.prg
305 WsMethod: getTable
306 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
307 Data: 21/11/2013
308 Descricao: Obtendo dados e estrutura de uma tabela
309 Uso: WebServices
310 */
311 WSMETHOD getTable WSRECEIVE Alias , rInit , rEnd , rDeleted , rRecno WSSEND Table WSSERVICE ubtdnTView
312
313 Local cSQLName
314
315 Local lWsMethodRet := .T.
316
317 Local obtdnTView
318 Local oException
319
320 TRYEXCEPTION
321
322 IF .NOT.(Empty(self:Alias))
323 self:Alias := Upper(AllTrim(self:Alias))
324 DEFAULT Alias := self:Alias
325 EndIF
326
327 IF .NOT.(Empty(Alias))
328 Alias := Upper(AllTrim(Alias))
329 EndIF
330
331 IF (Empty(self:Alias) .and. .NOT.(Empty(Alias)))
332 self:Alias := Alias
333 EndIF
334
335 IF Empty(self:Alias)
336 UserException( STR0010 + self:Alias ) //"Alias invalido: "
337 EndIF
338
339 cSQLName := RetSQLName(self:Alias)
340
341 IF ( Select(self:Alias) == 0 )
342 IF .NOT.( MsFile( cSQLName ) )
343 IF .NOT.( ChkFile(self:Alias) )
344 UserException( STR0007 + self:Alias ) //"Problema na abertura da Tabela: "
345 EndIF
346 Else
347 IF .NOT.( ChkFile(self:Alias) )
348 UserException( STR0007 + self:Alias ) //"Problema na abertura da Tabela: "
349 EndIF
350 EndIF
351 EndIF
352
353 DEFAULT self:rInit := 0
354 DEFAULT rInit := self:rInit
355 IF (Empty(self:rInit) .and. .NOT.(Empty(rInit)))
356 self:rInit := rInit
357 EndIF
358
359 DEFAULT self:rEnd := 0
360 DEFAULT rEnd := self:rEnd
361 IF (Empty(self:rEnd) .and. .NOT.(Empty(rEnd)))
362 self:rEnd := rEnd
363 EndIF
364
365 DEFAULT self:rDeleted := .T.
366 DEFAULT rDeleted := self:rDeleted
367 IF .NOT.( rDeleted == self:rDeleted )
368 self:rDeleted := rDeleted
369 EndIF
370
371 DEFAULT self:rRecno := .T.
372 DEFAULT rRecno := self:rRecno
373 IF .NOT.( rRecno == self:rRecno )
374 self:rRecno := rRecno
375 EndIF
376
377 Table := WsClassNew("uTableView")
378 self:Table := Table
379
380 obtdnTView := WsClassNew("ubtdnTView")
381 obtdnTView:Alias := self:Alias
382 obtdnTView:rInit := self:rInit
383 obtdnTView:rEnd := self:rEnd
384 obtdnTView:FieldsName := self:FieldsName
385 obtdnTView:rDeleted := self:rDeleted
386 obtdnTView:rRecno := self:rRecno
387
388 IF .NOT.( obtdnTView:getTStruct(@Alias,@rDeleted,@rRecno) )
389 UserException( STR0008 + self:Alias ) //"Estrutura invalida: "
390 EndIF
391
392 Table:TableStruct := obtdnTView:TableStruct
393 self:Table:TableStruct := Table:TableStruct
394
395 IF .NOT.( obtdnTView:getTData(@Alias,@rInit,@rEnd,@rDeleted,@rRecno) )
396 UserException( STR0009 + self:Alias ) //"Nao Existem Registros a Serem Apresentados para a Tabela: "
397 EndIF
398
399 Table:TableData := obtdnTView:TableData
400 self:Table:TableData := Table:TableData
401
402 CATCHEXCEPTION USING oException
403
404 lWsMethodRet := .F.
405
406 SetSoapFault( ProcName() , oException:Description + CRLF + oException:ErrorStack )
407
408 ENDEXCEPTION
409
410 Return( lWsMethodRet )
411
412 /*
413 Progama: wsubtdnTView.prg
414 WsMethod: getTbyWhere
415 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
416 Data: 21/11/2013
417 Descricao: Obtem dados e estrutura da tabela baseada em condição
418 Uso: WebServices
419 */
420 WSMETHOD getTbyWhere WSRECEIVE Alias , Where , rInit , rEnd, rDeleted , rRecno WSSEND Table WSSERVICE ubtdnTView
421
422 Local adbQuery := Array(0)
423
424 Local bWhere
425
426 Local cAlias
427 Local cQuery
428 Local cRecno
429 Local cSQLName
430 Local cRddName
431
432 Local lEXIT
433 Local lQuery := .T.
434 Local lWsMethodRet := .T.
435
436 Local nOrder
437 Local nRecno
438 Local nNextRecno
439
440 Local obtdnTView
441 Local oException
442
443 TRYEXCEPTION
444
445 IF .NOT.(Empty(self:Alias))
446 self:Alias := Upper(AllTrim(self:Alias))
447 DEFAULT Alias := self:Alias
448 EndIF
449
450 IF .NOT.(Empty(Alias))
451 Alias := Upper(AllTrim(Alias))
452 EndIF
453
454 IF (Empty(self:Alias) .and. .NOT.(Empty(Alias)))
455 self:Alias := Alias
456 EndIF
457
458 IF Empty(self:Alias)
459 UserException( STR0010 + self:Alias ) //"Alias invalido: "
460 EndIF
461
462 cSQLName := RetSQLName(self:Alias)
463
464 IF ( Select(self:Alias) == 0 )
465 IF .NOT.( MsFile( cSQLName ) )
466 IF .NOT.( ChkFile(self:Alias) )
467 UserException( STR0007 + self:Alias ) //"Problema na abertura da Tabela: "
468 EndIF
469 Else
470 IF .NOT.( ChkFile(self:Alias) )
471 UserException( STR0007 + self:Alias ) //"Problema na abertura da Tabela: "
472 EndIF
473 EndIF
474 EndIF
475
476 cRddName := (self:Alias)->( RddName() )
477 lQuery := ( cRddName == "TOPCONN" )
478
479 self:Where := AllTrim( self:Where )
480 DEFAULT Where := self:Where
481 Where := AllTrim( Where )
482
483 IF ( Empty(self:Where) .and. .NOT.( Empty( Where ) ) )
484 self:Where := Where
485 EndIF
486
487 IF Empty(self:Where)
488 UserException( STR0011 + self:Where ) //"Condicao invalida: "
489 EndIF
490
491 DEFAULT self:rInit := 0
492 DEFAULT rInit := self:rInit
493 IF (Empty(self:rInit) .and. .NOT.(Empty(rInit)))
494 self:rInit := rInit
495 EndIF
496
497 DEFAULT self:rEnd := 0
498 DEFAULT rEnd := self:rEnd
499 IF (Empty(self:rEnd) .and. .NOT.(Empty(rEnd)))
500 self:rEnd := rEnd
501 EndIF
502
503 DEFAULT self:rDeleted := .T.
504 DEFAULT rDeleted := self:rDeleted
505 IF .NOT.( rDeleted == self:rDeleted )
506 self:rDeleted := rDeleted
507 EndIF
508
509 DEFAULT self:rRecno := .T.
510 DEFAULT rRecno := self:rRecno
511 IF .NOT.( rRecno == self:rRecno )
512 self:rRecno := rRecno
513 EndIF
514
515 obtdnTView := WsClassNew("ubtdnTView")
516 obtdnTView:Alias := self:Alias
517 obtdnTView:FieldsName := self:FieldsName
518 obtdnTView:rDeleted := self:rDeleted
519 obtdnTView:rRecno := self:rRecno
520
521 IF .NOT.( obtdnTView:getTStruct(@Alias,@rDeleted,@rRecno) )
522 UserException( STR0008 + self:Alias ) //"Estrutura invalida: "
523 EndIF
524
525 IF ( lQuery )
526 IF ( __lAS400 )
527 cQuery := "SELECT RRN("+cSQLName+") NRECNO "
528 Else
529 cQuery := "SELECT "+self:Alias+".R_E_C_N_O_ NRECNO"
530 EndIF
531 cQuery += " FROM "+cSQLName+" "+self:Alias
532 IF ( __lAS400 )
533 cQuery += " WHERE "+"RRN("+cSQLName+") BETWEEN "+AllTrim(Str(self:rInit))+" AND "+AllTrim(Str(self:rEnd))
534 Else
535 cQuery += " WHERE "+self:Alias+".R_E_C_N_O_ BETWEEN "+AllTrim(Str(self:rInit))+" AND "+AllTrim(Str(self:rEnd))
536 EndIF
537 IF .NOT.(self:rDeleted)
538 IF ( __lAS400 )
539 cQuery += " AND "+self:Alias+".@DELETED@<>'*'"
540 Else
541 cQuery += " AND "+self:Alias+".D_E_L_E_T_<>'*'"
542 EndIF
543 EndIF
544 cQuery += " AND "+self:Where
545 IF .NOT.( dbQuery(@adbQuery,cQuery,@cAlias) )
546 UserException( STR0009 + self:Alias ) //"Nao Existem Registros a Serem Apresentados para a Tabela: "
547 ENDIF
548 Else
549 bWhere := &("{||"+self:Where+"}")
550 cAlias := self:Alias
551 (cAlias)->( dbGoTop() )
552 EndIF
553
554 Table := WsClassNew("uTableView")
555 self:Table := Table
556
557 self:Table:TableStruct := obtdnTView:TableStruct
558 self:Table:TableData := Array(0)
559
560 While (cAlias)->( .NOT.( Eof() ) )
561
562 IF ( lQuery )
563 nRecno := (cAlias)->NRECNO
564 Else
565 lEXIT := .NOT.(GetNextRecno(@cAlias,@nNextRecno,@nRecno,@nOrder))
566 IF (lEXIT)
567 EXIT
568 ENDIF
569 IF (cAlias)->( .NOT.( Eval( bWhere ) ) )
570 lExit := .NOT.(GotoNextRecno(@cAlias,@nNextRecno,@nOrder))
571 IF ( lExit )
572 EXIT
573 EndIF
574 Loop
575 EndIF
576 EndIF
577
578 IF ( nRecno > 0 )
579 obtdnTView:rInit := nRecno
580 obtdnTView:rEnd := nRecno
581 IF ( obtdnTView:getTData(@Alias,@nRecno,@nRecno,@rDeleted,@rRecno) )
582 aEval( obtdnTView:TableData , { |e| aAdd( self:Table:TableData , e ) } )
583 EndIF
584 EndIF
585
586 IF ( lQuery )
587 (cAlias)->(dbSkip())
588 Else
589 lExit := .NOT.(GotoNextRecno(@cAlias,@nNextRecno,@nOrder))
590 IF ( lExit )
591 EXIT
592 EndIF
593 EndIF
594
595 End While
596
597 CATCHEXCEPTION USING oException
598
599 lWsMethodRet := .F.
600
601 SetSoapFault( ProcName() , oException:Description + CRLF + oException:ErrorStack )
602
603 ENDEXCEPTION
604
605 aEval( adbQuery , { |cAlias| IF( ( Select( cAlias ) > 0 ) , (cAlias)->( dbCloseArea() ) , NIL ) } )
606
607 Return( lWsMethodRet )
608
609 /*
610 Progama: wsubtdnTView.prg
611 WsMethod: getTStruct
612 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
613 Data: 21/11/2013
614 Descricao: Obtem a estrutura da tabela
615 Uso: WebServices
616 */
617 WSMETHOD getTStruct WSRECEIVE Alias , rDeleted , rRecno WSSEND TableStruct WSSERVICE ubtdnTView
618
619 Local aFields
620 Local adbStruct
621 Local aFieldsName
622
623 Local cAlias
624 Local cDBSType
625 Local cSQLName
626
627 Local cX3Titulo
628 Local cX3Descric
629
630 Local lWsMethodRet := .T.
631
632 Local nAT
633 Local nField
634 Local nFields
635
636 Local oException
637
638 TRYEXCEPTION
639
640 IF .NOT.(Empty(self:Alias))
641 self:Alias := Upper(AllTrim(self:Alias))
642 DEFAULT Alias := self:Alias
643 EndIF
644
645 IF .NOT.(Empty(Alias))
646 Alias := Upper(AllTrim(Alias))
647 EndIF
648
649 IF (Empty(self:Alias) .and. .NOT.(Empty(Alias)))
650 self:Alias := Alias
651 EndIF
652
653 IF Empty(self:Alias)
654 UserException( STR0010 + self:Alias ) //"Alias invalido: "
655 EndIF
656
657 DEFAULT self:rDeleted := .T.
658 DEFAULT rDeleted := self:rDeleted
659 IF .NOT.( rDeleted == self:rDeleted )
660 self:rDeleted := rDeleted
661 EndIF
662
663 DEFAULT self:rRecno := .T.
664 DEFAULT rRecno := self:rRecno
665 IF .NOT.( rRecno == self:rRecno )
666 self:rRecno := rRecno
667 EndIF
668
669 cSQLName := RetSQLName(self:Alias)
670
671 IF ( Select(self:Alias) == 0 )
672 IF .NOT.( MsFile( cSQLName ) )
673 IF .NOT.( ChkFile(self:Alias) )
674 UserException( STR0007 + self:Alias ) //"Problema na abertura da Tabela: "
675 EndIF
676 Else
677 IF .NOT.( ChkFile(self:Alias) )
678 UserException( STR0007 + self:Alias ) //"Problema na abertura da Tabela: "
679 EndIF
680 EndIF
681 EndIF
682
683 TableStruct := Array(0)
684 self:TableStruct := TableStruct
685
686 adbStruct := (self:Alias)->(dbStruct())
687
688 DEFAULT self:FieldsName := WsClassNew("uFieldsName")
689 aFieldsName := self:FieldsName:uFldName
690 IF (ValType(aFieldsName)=="A") .and. .NOT.(Empty(aFieldsName))
691 aFields := Array(0)
692 nFields := Len(aFieldsName)
693 For nField := 1 To nFields
694 nAT := aScan(adbStruct,{|e|AllTrim(e[DBS_NAME])==Upper(AllTrim(aFieldsName[nField]))})
695 IF ( nAT > 0 )
696 aAdd(aFields,adbStruct[nAT])
697 EndIF
698 Next nField
699 IF Empty(aFields)
700 aFields := adbStruct
701 EndIF
702 Else
703 aFields := adbStruct
704 EndIF
705
706 nFields := Len(aFields)
707
708 #IFDEF SPANISH
709 cX3Titulo := "X3_TITSPA"
710 cX3Descric := "X3_DESCSPA"
711 #ELSE
712 #IFDEF ENGLISH
713 cX3Titulo := "X3_TITENG"
714 cX3Descric := "X3_DESCENG"
715 #ELSE
716 cX3Titulo := "X3_TITULO"
717 cX3Descric := "X3_DESCRIC"
718 #ENDIF
719 #ENDIF
720
721 For nField := 1 To nFields
722 aAdd( self:TableStruct , WsClassNew("uFieldStruct") )
723 self:TableStruct[nField]:FldName := aFields[nField][DBS_NAME]
724 self:TableStruct[nField]:FldType := aFields[nField][DBS_TYPE]
725 self:TableStruct[nField]:FldSize := aFields[nField][DBS_LEN ]
726 self:TableStruct[nField]:FldDec := aFields[nField][DBS_DEC ]
727 self:TableStruct[nField]:FldTitle := __UTF8(GetSx3Cache(aFields[nField][DBS_NAME],cX3Titulo))
728 IF Empty(self:TableStruct[nField]:FldTitle)
729 self:TableStruct[nField]:FldTitle := aFields[nField][DBS_NAME]
730 self:TableStruct[nField]:FldMandatory := .F.
731 self:TableStruct[nField]:FldDescription := aFields[nField][DBS_NAME]
732 Else
733 self:TableStruct[nField]:FldMandatory := X3Obrigat(aFields[nField][DBS_NAME])
734 self:TableStruct[nField]:FldDescription := __UTF8(GetSx3Cache(aFields[nField][DBS_NAME],cX3Descric))
735 EndIF
736 Next nField
737
738 nField := Len(self:TableStruct)
739
740 IF ( self:rDeleted )
741 ++nField
742 aAdd( self:TableStruct , WsClassNew("uFieldStruct") )
743 self:TableStruct[nField]:FldName := "DELETED"
744 self:TableStruct[nField]:FldType := "C"
745 self:TableStruct[nField]:FldSize := 1
746 self:TableStruct[nField]:FldDec := 0
747 self:TableStruct[nField]:FldTitle := "DELETED"
748 self:TableStruct[nField]:FldMandatory := .F.
749 self:TableStruct[nField]:FldDescription := "DELETED"
750 EndIF
751
752 IF ( self:rRecno )
753 ++nField
754 aAdd( self:TableStruct , WsClassNew("uFieldStruct") )
755 self:TableStruct[nField]:FldName := "RECNO"
756 self:TableStruct[nField]:FldType := "N"
757 self:TableStruct[nField]:FldSize := 18
758 self:TableStruct[nField]:FldDec := 0
759 self:TableStruct[nField]:FldTitle := "RECNO"
760 self:TableStruct[nField]:FldMandatory := .F.
761 self:TableStruct[nField]:FldDescription := "RECNO"
762 EndIF
763
764 CATCHEXCEPTION USING oException
765
766 lWsMethodRet := .F.
767
768 SetSoapFault( ProcName() , oException:Description + CRLF + oException:ErrorStack )
769
770 ENDEXCEPTION
771
772 Return( lWsMethodRet )
773
774 /*
775 Progama: wsubtdnTView.prg
776 WsMethod: getTFieldsName
777 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
778 Data: 21/11/2013
779 Descricao: Obtem os campos da tabela
780 Uso: WebServices
781 */
782 WSMETHOD getTFieldsName WSRECEIVE Alias WSSEND FieldsName WSSERVICE ubtdnTView
783
784 Local adbStruct
785
786 Local cAlias
787 Local cDBSType
788 Local cSQLName
789
790 Local lWsMethodRet := .T.
791
792 Local nField
793 Local nFields
794
795 Local oException
796
797 TRYEXCEPTION
798
799 IF .NOT.(Empty(self:Alias))
800 self:Alias := Upper(AllTrim(self:Alias))
801 DEFAULT Alias := self:Alias
802 EndIF
803
804 IF .NOT.(Empty(Alias))
805 Alias := Upper(AllTrim(Alias))
806 EndIF
807
808 IF (Empty(self:Alias) .and. .NOT.(Empty(Alias)))
809 self:Alias := Alias
810 EndIF
811
812 IF Empty(self:Alias)
813 UserException( STR0010 + self:Alias ) //"Alias invalido: "
814 EndIF
815
816 cSQLName := RetSQLName(self:Alias)
817
818 IF ( Select(self:Alias) == 0 )
819 IF .NOT.( MsFile( cSQLName ) )
820 IF .NOT.( ChkFile(self:Alias) )
821 UserException( STR0007 + self:Alias ) //"Problema na abertura da Tabela: "
822 EndIF
823 Else
824 IF .NOT.( ChkFile(self:Alias) )
825 UserException( STR0007 + self:Alias ) //"Problema na abertura da Tabela: "
826 EndIF
827 EndIF
828 EndIF
829
830 FieldsName := WsClassNew("uFieldsName")
831 FieldsName:uFldName := Array(0)
832 self:FieldsName := FieldsName
833
834 adbStruct := (self:Alias)->(dbStruct())
835 nFields := Len( adbStruct )
836
837 For nField := 1 To nFields
838 aAdd( self:FieldsName:uFldName , adbStruct[nField][DBS_NAME] )
839 Next nField
840
841 CATCHEXCEPTION USING oException
842
843 lWsMethodRet := .F.
844
845 SetSoapFault( ProcName() , oException:Description + CRLF + oException:ErrorStack )
846
847 ENDEXCEPTION
848
849 Return( lWsMethodRet )
850
851 /*
852 Progama: wsubtdnTView.prg
853 WsMethod: getTData
854 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
855 Data: 21/11/2013
856 Descricao: Obtem os registros da Tabela
857 Uso: WebServices
858 */
859 WSMETHOD getTData WSRECEIVE Alias , rInit , rEnd , rDeleted , rRecno WSSEND TableData WSSERVICE ubtdnTView
860
861 Local adbQuery := Array(0)
862
863 Local aFields
864 Local adbStruct
865 Local aFieldsAT
866 Local aFieldsName
867
868 Local cValue
869 Local cAlias
870 Local cQuery
871 Local cRecno
872 Local cField
873 Local cDBSType
874 Local cSQLName
875 Local cRDDName
876
877 Local lQuery := .T.
878 Local lSetDeleted := Set(_SET_DELETED,"ON")
879 Local lWsMethodRet := .T.
880
881 Local nAT
882 Local nItens
883 Local nRecno
884 Local nField
885 Local nFields
886
887 Local oException
888
889 Local uValue
890
891 TRYEXCEPTION
892
893 IF .NOT.(Empty(self:Alias))
894 self:Alias := Upper(AllTrim(self:Alias))
895 DEFAULT Alias := self:Alias
896 EndIF
897
898 IF .NOT.(Empty(Alias))
899 Alias := Upper(AllTrim(Alias))
900 EndIF
901
902 IF (Empty(self:Alias) .and. .NOT.(Empty(Alias)))
903 self:Alias := Alias
904 EndIF
905
906 IF Empty(self:Alias)
907 UserException( STR0010 + self:Alias ) //"Alias invalido: "
908 EndIF
909
910 cSQLName := RetSQLName(self:Alias)
911
912 IF ( Select(self:Alias) == 0 )
913 IF .NOT.( MsFile( cSQLName ) )
914 IF .NOT.( ChkFile(self:Alias) )
915 UserException( STR0007 + self:Alias ) //"Problema na abertura da Tabela: "
916 EndIF
917 Else
918 IF .NOT.( ChkFile(self:Alias) )
919 UserException( STR0007 + self:Alias ) //"Problema na abertura da Tabela: "
920 EndIF
921 EndIF
922 EndIF
923
924 cRDDName := (self:Alias)->( RddName() )
925 lQuery := ( cRDDName == "TOPCONN" )
926
927 DEFAULT self:rInit := 0
928 DEFAULT rInit := self:rInit
929 IF (Empty(self:rInit) .and. .NOT.(Empty(rInit)))
930 self:rInit := rInit
931 EndIF
932
933 DEFAULT self:rEnd := 0
934 DEFAULT rEnd := self:rEnd
935 IF (Empty(self:rEnd) .and. .NOT.(Empty(rEnd)))
936 self:rEnd := rEnd
937 EndIF
938
939 IF ( self:rEnd < self:rInit )
940 uValue := self:rInit
941 self:rInit := self:rEnd
942 rInit := self:rInit
943 self:rEnd := uValue
944 rEnd := self:rEnd
945 EndIF
946
947 DEFAULT self:rDeleted := .T.
948 DEFAULT rDeleted := self:rDeleted
949 IF .NOT.( rDeleted == self:rDeleted )
950 self:rDeleted := rDeleted
951 EndIF
952
953 DEFAULT self:rRecno := .T.
954 DEFAULT rRecno := self:rRecno
955 IF .NOT.( rRecno == self:rRecno )
956 self:rRecno := rRecno
957 EndIF
958
959 Set(_SET_DELETED,IF(self:rDeleted,"OFF","ON"))
960
961 IF ( lQuery )
962
963 cQuery := "SELECT COUNT(1) ITENS "
964 cQuery += " FROM "+cSQLName+" "+self:Alias
965 IF ( __lAS400 )
966 cQuery += " WHERE "+"RRN("+cSQLName+") BETWEEN "+AllTrim(Str(self:rInit))+" AND "+AllTrim(Str(self:rEnd))
967 Else
968 cQuery += " WHERE "+self:Alias+".R_E_C_N_O_ BETWEEN "+AllTrim(Str(self:rInit))+" AND "+AllTrim(Str(self:rEnd))
969 EndIF
970 IF .NOT.(self:rDeleted)
971 IF ( __lAS400 )
972 cQuery += " AND "+self:Alias+".@DELETED@<>'*'"
973 Else
974 cQuery += " AND "+self:Alias+".D_E_L_E_T_<>'*'"
975 EndIF
976 EndIF
977
978 IF .NOT.( dbQuery(@adbQuery,cQuery,@cAlias) )
979 UserException( STR0009 + self:Alias ) //"Nao Existem Registros a Serem Apresentados para a Tabela: "
980 ENDIF
981
982 nItens := (cAlias)->ITENS
983
984 Else
985
986 nItens := (self:Alias)->(RecCount())
987
988 EndIF
989
990 IF ( nItens == 0 )
991 UserException( STR0009 + self:Alias ) //"Nao Existem Registros a Serem Apresentados para a Tabela: "
992 EndIF
993
994 TableData := Array(0)
995 self:TableData := TableData
996
997 adbStruct := (self:Alias)->(dbStruct())
998
999 DEFAULT self:FieldsName := WsClassNew("uFieldsName")
1000 aFieldsName := self:FieldsName:uFldName
1001 IF (ValType(aFieldsName)=="A") .and. .NOT.(Empty(aFieldsName))
1002 aFields := Array(0)
1003 aFieldsAT := Array(0)
1004 nFields := Len(aFieldsName)
1005 For nField := 1 To nFields
1006 nAT := aScan(adbStruct,{|e|AllTrim(e[DBS_NAME])==Upper(AllTrim(aFieldsName[nField]))})
1007 IF ( nAT > 0 )
1008 aAdd(aFields,adbStruct[nAT])
1009 aAdd(aFieldsAT,nAT)
1010 EndIF
1011 Next nField
1012 IF Empty(aFields)
1013 aFields := adbStruct
1014 aFieldsAT := Array(0)
1015 aEval(aFields,{|x,y|aAdd(aFieldsAT,y)})
1016 EndIF
1017 Else
1018 aFields := adbStruct
1019 aFieldsAT := Array(0)
1020 aEval(aFields,{|x,y|aAdd(aFieldsAT,y)})
1021 EndIF
1022
1023 nFields := Len(aFields)
1024
1025 IF ( self:rDeleted )
1026 nAT := ++nFields
1027 aAdd(aFieldsAT,nAT)
1028 aAdd(aFields,Array(DBS_ALEN))
1029 aFields[nFields][DBS_NAME] := "DELETED"
1030 aFields[nFields][DBS_TYPE] := "C"
1031 aFields[nFields][DBS_LEN ] := 1
1032 aFields[nFields][DBS_DEC ] := 0
1033 EndIF
1034
1035 IF ( self:rRecno )
1036 nAT := ++nFields
1037 aAdd(aFieldsAT,nAT)
1038 aAdd(aFields,Array(DBS_ALEN))
1039 aFields[nFields][DBS_NAME] := "RECNO"
1040 aFields[nFields][DBS_TYPE] := "N"
1041 aFields[nFields][DBS_LEN ] := 18
1042 aFields[nFields][DBS_DEC ] := 0
1043 EndIF
1044
1045 nItens := 0
1046
1047 For nRecno := self:rInit To self:rEnd
1048 IF ( lQuery )
1049 cRecno := AllTrim(Str(nRecno))
1050 cQuery := "SELECT "+cRecno+" NRECNO "
1051 cQuery += " FROM "+cSQLName+" "+self:Alias
1052 IF ( __lAS400 )
1053 cQuery += " WHERE "+"RRN("+cSQLName+")="+cRecno
1054 Else
1055 cQuery += " WHERE "+self:Alias+".R_E_C_N_O_="+cRecno
1056 EndIF
1057 IF .NOT.(self:rDeleted)
1058 IF .NOT.(self:rDeleted)
1059 IF ( __lAS400 )
1060 cQuery += " AND "+self:Alias+".@DELETED@<>'*'"
1061 Else
1062 cQuery += " AND "+self:Alias+".D_E_L_E_T_<>'*'"
1063 EndIF
1064 EndIF
1065 EndIF
1066 IF .NOT.( dbQuery(@adbQuery,cQuery,@cAlias) )
1067 Loop
1068 ENDIF
1069 EndIF
1070 (self:Alias)->( dbGoto( nRecno ) )
1071 IF (self:Alias)->( Eof() .or. Bof() )
1072 Loop
1073 EndIF
1074 ++nItens
1075 aAdd( self:TableData , WsClassNew(/*u*/"FieldView") )
1076 self:TableData[nItens]:FldTag := Array( nFields )
1077 For nField := 1 To nFields
1078 cField := aFields[nField][DBS_NAME]
1079 nAT := aFieldsAT[nField]
1080 IF ( cField == "DELETED" )
1081 uValue := (self:Alias)->(IF(Deleted(),"*",""))
1082 ElseIF ( cField == "RECNO" )
1083 uValue := nRecno
1084 Else
1085 uValue := (self:Alias)->(FieldGet(nAT))
1086 IF ( ( "_USERLG" $ cField ) .or. ( "_USERG" $ cField ) )
1087 IF .NOT.( Empty(uValue) )
1088 uValue := (self:Alias)->(FWLeUserLG(cField,1)+"-"+FWLeUserLG(cField,2))
1089 EndIF
1090 EndIF
1091 EndIF
1092 cDBSType := aFields[nField][DBS_TYPE]
1093 Do Case
1094 Case ( cDBSType == "N" )
1095 cValue := Str(uValue,aFields[nAT][DBS_LEN],aFields[nAT][DBS_DEC])
1096 Case ( cDBSType == "D" )
1097 cValue := Dtos( uValue )
1098 Case ( cDBSType == "L" )
1099 cValue := IF(uValue,".T.",".F.")
1100 OtherWise
1101 cValue := __UTF8(uValue)
1102 EndCase
1103 self:TableData[nItens]:FldTag[nField] := AllTrim(cValue)
1104 Next nField
1105 Next nLoop
1106
1107 IF ( nItens == 0 )
1108 UserException( STR0009 + self:Alias ) //"Nao Existem Registros a Serem Apresentados para a Tabela: "
1109 EndIF
1110
1111 CATCHEXCEPTION USING oException
1112
1113 lWsMethodRet := .F.
1114
1115 SetSoapFault( ProcName() , oException:Description + CRLF + oException:ErrorStack )
1116
1117 ENDEXCEPTION
1118
1119 aEval( adbQuery , { |cAlias| IF( ( Select( cAlias ) > 0 ) , (cAlias)->( dbCloseArea() ) , NIL ) } )
1120
1121 Set(_SET_DELETED,IF(lSetDeleted,"ON","OFF"))
1122
1123 Return( lWsMethodRet )
1124
1125 /*
1126 Progama: wsubtdnTView.prg
1127 WsMethod: getTablebyFieldsName
1128 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
1129 Data: 21/11/2013
1130 Descricao: Obtendo dados e estrutura de uma tabela
1131 Uso: WebServices
1132 */
1133 WSMETHOD getTablebyFieldsName WSRECEIVE Alias , rInit , rEnd , FieldsName , rDeleted , rRecno WSSEND Table WSSERVICE ubtdnTView
1134
1135 Local lWsMethodRet := .T.
1136
1137 Local obtdnTView
1138 Local oException
1139
1140 TRYEXCEPTION
1141
1142 IF .NOT.(Empty(self:Alias))
1143 self:Alias := Upper(AllTrim(self:Alias))
1144 DEFAULT Alias := self:Alias
1145 EndIF
1146
1147 IF .NOT.(Empty(Alias))
1148 Alias := Upper(AllTrim(Alias))
1149 EndIF
1150
1151 IF (Empty(self:Alias) .and. .NOT.(Empty(Alias)))
1152 self:Alias := Alias
1153 EndIF
1154
1155 DEFAULT self:rInit := 0
1156 DEFAULT rInit := self:rInit
1157 IF (Empty(self:rInit) .and. .NOT.(Empty(rInit)))
1158 self:rInit := rInit
1159 EndIF
1160
1161 DEFAULT self:rEnd := 0
1162 DEFAULT rEnd := self:rEnd
1163 IF (Empty(self:rEnd) .and. .NOT.(Empty(rEnd)))
1164 self:rEnd := rEnd
1165 EndIF
1166
1167 DEFAULT self:rDeleted := .T.
1168 DEFAULT rDeleted := self:rDeleted
1169 IF .NOT.( rDeleted == self:rDeleted )
1170 self:rDeleted := rDeleted
1171 EndIF
1172
1173 DEFAULT self:rRecno := .T.
1174 DEFAULT rRecno := self:rRecno
1175 IF .NOT.( rRecno == self:rRecno )
1176 self:rRecno := rRecno
1177 EndIF
1178
1179 DEFAULT self:FieldsName := WsClassNew("uFieldsName")
1180 DEFAULT FieldsName := self:FieldsName
1181
1182 IF (Empty(self:FieldsName:uFldName) .and. .NOT.(Empty(FieldsName:uFldName)))
1183 self:FieldsName := FieldsName
1184 EndIF
1185
1186 IF (Empty(self:FieldsName:uFldName) .or. .NOT.(ValType(self:FieldsName:uFldName)=="A"))
1187 xmlGetFields(self:FieldsName)
1188 EndIF
1189
1190 obtdnTView := WsClassNew("ubtdnTView")
1191 obtdnTView:Alias := self:Alias
1192 obtdnTView:rInit := self:rInit
1193 obtdnTView:rEnd := self:rEnd
1194 obtdnTView:FieldsName := self:FieldsName
1195 obtdnTView:rDeleted := self:rDeleted
1196 obtdnTView:rRecno := self:rRecno
1197
1198 IF .NOT.( obtdnTView:getTable(@Alias,@rInit,@rEnd,@rDeleted,@rRecno) )
1199 UserException( STR0009 + self:Alias ) //"Nao Existem Registros a Serem Apresentados para a Tabela: "
1200 EndIF
1201
1202 Table := obtdnTView:Table
1203 self:Table := Table
1204
1205 CATCHEXCEPTION USING oException
1206
1207 lWsMethodRet := .F.
1208
1209 SetSoapFault( ProcName() , oException:Description + CRLF + oException:ErrorStack )
1210
1211 ENDEXCEPTION
1212
1213 Return( lWsMethodRet )
1214
1215 /*
1216 Progama: wsubtdnTView.prg
1217 WsMethod: getTbyWhereAndFieldsName
1218 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
1219 Data: 21/11/2013
1220 Descricao: Obtem dados e estrutura da tabela baseada em condição
1221 Uso: WebServices
1222 */
1223 WSMETHOD getTbyWhereAndFieldsName WSRECEIVE Alias , Where , rInit , rEnd, FieldsName , rDeleted , rRecno WSSEND Table WSSERVICE ubtdnTView
1224
1225 Local lWsMethodRet := .T.
1226
1227 Local obtdnTView
1228 Local oException
1229
1230 TRYEXCEPTION
1231
1232 IF .NOT.(Empty(self:Alias))
1233 self:Alias := Upper(AllTrim(self:Alias))
1234 DEFAULT Alias := self:Alias
1235 EndIF
1236
1237 IF .NOT.(Empty(Alias))
1238 Alias := Upper(AllTrim(Alias))
1239 EndIF
1240
1241 IF (Empty(self:Alias) .and. .NOT.(Empty(Alias)))
1242 self:Alias := Alias
1243 EndIF
1244
1245 self:Where := AllTrim( self:Where )
1246 DEFAULT Where := self:Where
1247 Where := AllTrim( Where )
1248
1249 IF ( Empty(self:Where) .and. .NOT.( Empty( Where ) ) )
1250 self:Where := Where
1251 EndIF
1252
1253 DEFAULT self:rInit := 0
1254 DEFAULT rInit := self:rInit
1255 IF (Empty(self:rInit) .and. .NOT.(Empty(rInit)))
1256 self:rInit := rInit
1257 EndIF
1258
1259 DEFAULT self:rEnd := 0
1260 DEFAULT rEnd := self:rEnd
1261 IF (Empty(self:rEnd) .and. .NOT.(Empty(rEnd)))
1262 self:rEnd := rEnd
1263 EndIF
1264
1265 DEFAULT self:rDeleted := .T.
1266 DEFAULT rDeleted := self:rDeleted
1267 IF .NOT.( rDeleted == self:rDeleted )
1268 self:rDeleted := rDeleted
1269 EndIF
1270
1271 DEFAULT self:rRecno := .T.
1272 DEFAULT rRecno := self:rRecno
1273 IF .NOT.( rRecno == self:rRecno )
1274 self:rRecno := rRecno
1275 EndIF
1276
1277 DEFAULT self:FieldsName := WsClassNew("uFieldsName")
1278 DEFAULT FieldsName := self:FieldsName
1279
1280 IF (Empty(self:FieldsName:uFldName) .and. .NOT.(Empty(FieldsName:uFldName)))
1281 self:FieldsName := FieldsName
1282 EndIF
1283
1284 IF (Empty(self:FieldsName:uFldName) .or. .NOT.(ValType(self:FieldsName:uFldName)=="A"))
1285 xmlGetFields(self:FieldsName)
1286 EndIF
1287
1288 obtdnTView := WsClassNew("ubtdnTView")
1289 obtdnTView:Alias := self:Alias
1290 obtdnTView:rInit := self:rInit
1291 obtdnTView:rEnd := self:rEnd
1292 obtdnTView:FieldsName := self:FieldsName
1293 obtdnTView:rDeleted := self:rDeleted
1294 obtdnTView:rRecno := self:rRecno
1295
1296 IF .NOT.( obtdnTView:getTbyWhere(@Alias,@Where,@rInit,@rEnd,@rDeleted,@rRecno) )
1297 UserException( STR0009 + self:Alias ) //"Nao Existem Registros a Serem Apresentados para a Tabela: "
1298 EndIF
1299
1300 Table := obtdnTView:Table
1301 self:Table := Table
1302
1303 CATCHEXCEPTION USING oException
1304
1305 lWsMethodRet := .F.
1306
1307 SetSoapFault( ProcName() , oException:Description + CRLF + oException:ErrorStack )
1308
1309 ENDEXCEPTION
1310
1311 Return( lWsMethodRet )
1312
1313 /*
1314 Progama: wsubtdnTView.prg
1315 WsMethod: getTStructbyFieldsName
1316 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
1317 Data: 21/11/2013
1318 Descricao: Obtem a estrutura da tabela
1319 Uso: WebServices
1320 */
1321 WSMETHOD getTStructbyFieldsName WSRECEIVE Alias , FieldsName , rDeleted , rRecno WSSEND TableStruct WSSERVICE ubtdnTView
1322
1323 Local lWsMethodRet := .T.
1324
1325 Local obtdnTView
1326 Local oException
1327
1328 TRYEXCEPTION
1329
1330 IF .NOT.(Empty(self:Alias))
1331 self:Alias := Upper(AllTrim(self:Alias))
1332 DEFAULT Alias := self:Alias
1333 EndIF
1334
1335 IF .NOT.(Empty(Alias))
1336 Alias := Upper(AllTrim(Alias))
1337 EndIF
1338
1339 IF (Empty(self:Alias) .and. .NOT.(Empty(Alias)))
1340 self:Alias := Alias
1341 EndIF
1342
1343 DEFAULT self:rDeleted := .T.
1344 DEFAULT rDeleted := self:rDeleted
1345 IF .NOT.( rDeleted == self:rDeleted )
1346 self:rDeleted := rDeleted
1347 EndIF
1348
1349 DEFAULT self:rRecno := .T.
1350 DEFAULT rRecno := self:rRecno
1351 IF .NOT.( rRecno == self:rRecno )
1352 self:rRecno := rRecno
1353 EndIF
1354
1355 DEFAULT self:FieldsName := WsClassNew("uFieldsName")
1356 DEFAULT FieldsName := self:FieldsName
1357
1358 IF (Empty(self:FieldsName:uFldName) .and. .NOT.(Empty(FieldsName:uFldName)))
1359 self:FieldsName := FieldsName
1360 EndIF
1361
1362 IF (Empty(self:FieldsName:uFldName) .or. .NOT.(ValType(self:FieldsName:uFldName)=="A"))
1363 xmlGetFields(self:FieldsName)
1364 EndIF
1365
1366 obtdnTView := WsClassNew("ubtdnTView")
1367 obtdnTView:Alias := self:Alias
1368 obtdnTView:FieldsName := self:FieldsName
1369
1370 IF .NOT.( obtdnTView:getTStruct(@Alias,@rDeleted,@rRecno) )
1371 UserException( STR0008 + self:Alias ) //"Estrutura invalida: "
1372 EndIF
1373
1374 TableStruct := obtdnTView:TableStruct
1375 self:TableStruct := TableStruct
1376
1377 CATCHEXCEPTION USING oException
1378
1379 lWsMethodRet := .F.
1380
1381 SetSoapFault( ProcName() , oException:Description + CRLF + oException:ErrorStack )
1382
1383 ENDEXCEPTION
1384
1385 Return( lWsMethodRet )
1386
1387 /*
1388 Progama: wsubtdnTView.prg
1389 WsMethod: getTDatabyFieldsName
1390 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
1391 Data: 21/11/2013
1392 Descricao: Obtem os registros da Tabela
1393 Uso: WebServices
1394 */
1395 WSMETHOD getTDatabyFieldsName WSRECEIVE Alias , rInit , rEnd , FieldsName , rDeleted , rRecno WSSEND TableData WSSERVICE ubtdnTView
1396
1397 Local lWsMethodRet := .T.
1398
1399 Local obtdnTView
1400 Local oException
1401
1402 TRYEXCEPTION
1403
1404 IF .NOT.(Empty(self:Alias))
1405 self:Alias := Upper(AllTrim(self:Alias))
1406 DEFAULT Alias := self:Alias
1407 EndIF
1408
1409 IF .NOT.(Empty(Alias))
1410 Alias := Upper(AllTrim(Alias))
1411 EndIF
1412
1413 IF (Empty(self:Alias) .and. .NOT.(Empty(Alias)))
1414 self:Alias := Alias
1415 EndIF
1416
1417 DEFAULT self:rInit := 0
1418 DEFAULT rInit := self:rInit
1419 IF (Empty(self:rInit) .and. .NOT.(Empty(rInit)))
1420 self:rInit := rInit
1421 EndIF
1422
1423 DEFAULT self:rEnd := 0
1424 DEFAULT rEnd := self:rEnd
1425 IF (Empty(self:rEnd) .and. .NOT.(Empty(rEnd)))
1426 self:rEnd := rEnd
1427 EndIF
1428
1429 DEFAULT self:rDeleted := .T.
1430 DEFAULT rDeleted := self:rDeleted
1431 IF .NOT.( rDeleted == self:rDeleted )
1432 self:rDeleted := rDeleted
1433 EndIF
1434
1435 DEFAULT self:rRecno := .T.
1436 DEFAULT rRecno := self:rRecno
1437 IF .NOT.( rRecno == self:rRecno )
1438 self:rRecno := rRecno
1439 EndIF
1440
1441 DEFAULT self:FieldsName := WsClassNew("uFieldsName")
1442 DEFAULT FieldsName := self:FieldsName
1443
1444 IF (Empty(self:FieldsName:uFldName) .and. .NOT.(Empty(FieldsName:uFldName)))
1445 self:FieldsName := FieldsName
1446 EndIF
1447
1448 IF (Empty(self:FieldsName:uFldName) .or. .NOT.(ValType(self:FieldsName:uFldName)=="A"))
1449 xmlGetFields(self:FieldsName)
1450 EndIF
1451
1452 obtdnTView := WsClassNew("ubtdnTView")
1453 obtdnTView:Alias := self:Alias
1454 obtdnTView:rInit := self:rInit
1455 obtdnTView:rEnd := self:rEnd
1456 obtdnTView:FieldsName := self:FieldsName
1457 obtdnTView:rDeleted := self:rDeleted
1458 obtdnTView:rRecno := self:rRecno
1459
1460 IF .NOT.( obtdnTView:getTData(@Alias,@rInit,@rEnd,@rDeleted,@rRecno) )
1461 UserException( STR0009 + self:Alias ) //"Nao Existem Registros a Serem Apresentados para a Tabela: "
1462 EndIF
1463
1464 TableData := obtdnTView:TableData
1465 self:TableData := TableData
1466
1467 CATCHEXCEPTION USING oException
1468
1469 lWsMethodRet := .F.
1470
1471 SetSoapFault( ProcName() , oException:Description + CRLF + oException:ErrorStack )
1472
1473 ENDEXCEPTION
1474
1475 Return( lWsMethodRet )
1476
1477 /*
1478 Progama: wsubtdnTView.prg
1479 Funcao: xmlGetFields
1480 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
1481 Data: 06/11/2013
1482 Descricao: Obtem os campos baseado na XMLString obtida a partir da WSEXECUTE
1483 Sintaxe: xmlGetFields(FieldsName)
1484 */
1485 Static Function xmlGetFields(FieldsName)
1486
1487 Local axmlFields
1488 Local aStackParameters
1489
1490 Local cXMLError
1491 Local cXMLReplace
1492 Local cXMLWarning
1493 Local cXMLString
1494
1495 Local nNode
1496 Local nItem
1497 Local nNodes
1498 Local nItens
1499
1500 Local oXMLString
1501
1502 IF .NOT.(ValType(FieldsName:uFldName)=="A")
1503 FieldsName:uFldName := Array(0)
1504 EndIF
1505
1506 cXMLString := StaticCall(NDJLIB006,ReadStackParameters,"WSEXECUTE","CXMLSTRING","PARAM",NIL,@aStackParameters)
1507 IF ( ValType(cXMLString) == "C" )
1508 cXMLString := AllTrim(cXMLString)
1509 IF .NOT.(Empty(cXMLString))
1510 cXMLReplace := "_"
1511 cXMLError := ""
1512 cXMLWarning := ""
1513 oXMLString := XmlParser(cXMLString,cXMLReplace,@cXMLError,@cXMLWarning)
1514 axmlFields := Array(0)
1515 IF xmlFieldsName(oXMLString,@axmlFields)
1516 nNodes := Len(axmlFields)
1517 For nNode := 1 To nNodes
1518 IF (ValType(axmlFields[nNode])=="A")
1519 nItens := Len(axmlFields[nNode])
1520 For nItem := 1 To nItens
1521 aAdd(FieldsName:uFldName,axmlFields[nNode][nItem]:TEXT)
1522 Next nItem
1523 ElseIF (ValType(axmlFields[nNode])=="O")
1524 aAdd(FieldsName:uFldName,axmlFields[nNode]:TEXT)
1525 EndIF
1526 Next nNode
1527 EndIF
1528 EndIF
1529 EndIF
1530
1531 Return(NIL)
1532
1533 /*
1534 Progama: wsubtdnTView.prg
1535 Funcao: xmlFieldsName
1536 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
1537 Data: 06/11/2013
1538 Descricao: Retorna o Node correspondente a "UFLDNAME"
1539 Sintaxe: xmlFieldsName(oXML,axmlFields)
1540 */
1541 Static Function xmlFieldsName(oXML,axmlFields,cNodeSup)
1542
1543 Local aXML
1544
1545 Local nNode
1546 Local nNodes
1547
1548 BEGIN SEQUENCE
1549
1550 IF .NOT.(ValType(oXML)=="O")
1551 BREAK
1552 EndIF
1553
1554 aXML := ClassDataArray(oXML)
1555
1556 DEFAULT cNodeSup := "__cNodeSup__"
1557
1558 IF ("UFLDNAME"$cNodeSup)
1559 IF ((Len(aXML)>=1) .and. ("STRING"$aXML[1][1]) .and. .NOT.(ValType(aXML[1][2])=="A"))
1560 aAdd(axmlFields,aXML[1][2])
1561 BREAK
1562 EndIF
1563 EndIF
1564
1565 nNodes := Len(aXML)
1566 For nNode := 1 To nNodes
1567 IF (ValType(aXML[nNode][2])=="O")
1568 xmlFieldsName(aXML[nNode][2],@axmlFields,aXML[nNode][1])
1569 IF ("UFLDNAME"$cNodeSup)
1570 BREAK
1571 EndIF
1572 ElseIF (ValType(cNodeSup)=="C")
1573 IF ("UFLDNAME"$cNodeSup)
1574 aAdd(axmlFields,aXML[nNode][2])
1575 EndIF
1576 EndIF
1577 Next nNode
1578
1579 END SEQUENCE
1580
1581 Return(.NOT.(Empty(axmlFields)))
1582
1583 /*
1584 Progama: wsubtdnTView.prg
1585 Funcao: dbQuery()
1586 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
1587 Data: 06/11/2013
1588 Descricao: Providenciar um Alias Valido para Abertura da View
1589 Sintaxe: dbQuery(adbQuery,cQuery,cAlias)
1590 */
1591 Static Function dbQuery(adbQuery,cQuery,cAlias)
1592 DEFAULT adbQuery := Array(0)
1593 DEFAULT cAlias := GetNextAlias()
1594 IF ( Select( @cAlias ) > 0 )
1595 ( cAlias )->( dbCloseArea() )
1596 EndIF
1597 TCQUERY ( cQuery ) ALIAS ( cAlias ) NEW
1598 IF ( ValType(adbQuery)=="A" )
1599 IF ( aScan( adbQuery , { |e| ( e == cAlias ) } ) == 0 )
1600 aAdd( adbQuery , cAlias )
1601 EndIF
1602 EndIF
1603 Return( .NOT.( ( cAlias )->( Bof() .and. Eof() ) ) )
1604
1605 /*
1606 Progama: wsubtdnTView.prg
1607 Funcao: __UTF8
1608 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
1609 Data: 06/11/2013
1610 Descricao: Retira acentuacao e Converte string para UTF8
1611 Sintaxe: __UTF8(s)
1612 */
1613 Static Function __UTF8(s)
1614 Local cAsc129 := Chr(129)
1615 Local cAsc141 := Chr(141)
1616 Local cAsc143 := Chr(143)
1617 Local cAsc144 := Chr(144)
1618 Local cAsc157 := Chr(157)
1619 s := OemToAnsi(s)
1620 s := __TAcento(s)
1621 s := fTAcento(s)
1622 s := NoAcento(s)
1623 While ( "<" $ s )
1624 s := StrTran(s,"<","(")
1625 End While
1626 While ( ">" $ s )
1627 s := StrTran(s,">",")")
1628 End While
1629 While ( cAsc129 $ s )
1630 s := StrTran(s,cAsc129,"u")
1631 End While
1632 While ( cAsc141 $ s )
1633 s := StrTran(s,cAsc141,"i")
1634 End While
1635 While ( cAsc143 $ s )
1636 s := StrTran(s,cAsc143,"a")
1637 End While
1638 While ( cAsc144 $ s )
1639 s := StrTran(s,cAsc144,"e")
1640 End While
1641 While ( cAsc157 $ s )
1642 s := StrTran(s,cAsc157,"o")
1643 End While
1644 s := EncodeUTF8(s)
1645 Return(s)
1646
1647 /*
1648 Progama: wsubtdnTView.prg
1649 Funcao: __TAcento
1650 Autor: Marinaldo de Jesus [http://www.blacktdn.com.br]
1651 Data: 06/11/2013
1652 Descricao: Retira acentuacao
1653 Sintaxe: ClearChar( cString )
1654 */
1655 Static Function __TAcento( cStrAnsi ) //Devera estar no Padrao ANSI utilizar a funcao OemToAnsi() para a conversao
1656
1657 Local cAcento
1658 Local cNoAcento
1659 Local cStrAnsiNoAc
1660
1661 Local nAcento
1662
1663 Static __aAcentos := {;
1664 {Chr(195),"A"},;
1665 {Chr(196),"A"},;
1666 {Chr(197),"A"},;
1667 {Chr(192),"A"},;
1668 {Chr(224),"a"},;
1669 {Chr(229),"a"},;
1670 {Chr(225),"a"},;
1671 {Chr(228),"a"},;
1672 {Chr(226),"a"},;
1673 {Chr(227),"a"},;
1674 {Chr(166),"a"},;
1675 {Chr(226),"a"},;
1676 {Chr(203),"E"},;
1677 {Chr(200),"E"},;
1678 {Chr(201),"E"},;
1679 {Chr(234),"e"},;
1680 {Chr(233),"e"},;
1681 {Chr(232),"e"},;
1682 {Chr(235),"e"},;
1683 {Chr(232),"e"},;
1684 {Chr(207),"I"},;
1685 {Chr(205),"I"},;
1686 {Chr(204),"I"},;
1687 {Chr(237),"i"},;
1688 {Chr(236),"i"},;
1689 {Chr(239),"i"},;
1690 {Chr(238),"i"},;
1691 {Chr(210),"O"},;
1692 {Chr(211),"O"},;
1693 {Chr(214),"O"},;
1694 {Chr(213),"O"},;
1695 {Chr(245),"o"},;
1696 {Chr(244),"o"},;
1697 {Chr(246),"o"},;
1698 {Chr(242),"o"},;
1699 {Chr(243),"o"},;
1700 {Chr(220),"U"},;
1701 {Chr(250),"u"},;
1702 {Chr(252),"u"},;
1703 {Chr(249),"u"},;
1704 {Chr(251),"u"},;
1705 {Chr(209),"N"},;
1706 {Chr(241),"n"},;
1707 {Chr(199),"C"},;
1708 {Chr(231),"c"};
1709 }
1710
1711 Static __nAcentos := Len(__aAcentos)
1712
1713 BEGIN SEQUENCE
1714
1715 IF Empty( cStrAnsi )
1716 cStrAnsiNoAc := cStrAnsi
1717 BREAK
1718 EndIF
1719
1720 cStrAnsiNoAc := cStrAnsi
1721
1722 For nAcento := 1 To __nAcentos
1723 cAcento := __aAcentos[nAcento][1]
1724 While ( cAcento $ cStrAnsiNoAc )
1725 cNoAcento := __aAcentos[nAcento][2]
1726 cStrAnsiNoAc := StrTran(cStrAnsiNoAc,cAcento,cNoAcento)
1727 End While
1728 Next nAcento
1729
1730 END SEQUENCE
1731
1732 Return( cStrAnsiNoAc )
Obs.: Existe dependencia do programa NDJLIB006.prg que pode ser obtido ao clicar aqui.
Comentários
Postar um comentário