Pular para o conteúdo principal

Postagem em destaque

BlackTDN :: LeetCode :: Zigzag Conversion: Implementando Soluções em xBase (Harbour) e TL++

_Créditos das imagens: ChatGPT_ ### LeetCode :: Zigzag Conversion: Implementando Soluções em xBase (Harbour) e TL++ A ["Zigzag Conversion"](https://leetcode.com/problems/zigzag-conversion/description/) é um problema popular do LeetCode que desafia desenvolvedores a transformar uma string em um padrão zigzag com base no número de linhas especificado, para então reconstruir a string seguindo a leitura linha a linha do padrão. Aqui, apresento soluções desenvolvidas em Harbour (XBase) e TL++ com melhorias e detalhes adicionais. --- ### **O Problema** Dado uma string e um número de linhas, distribua os caracteres em um padrão zigzag. Leia as linhas do padrão sequencialmente para obter o resultado: Exemplo: **Input:** String: "PAYPALISHIRING" Linhas: 3 **Padrão Zigzag:** ``` P A H N A P L S I I G Y I R ``` **Output:** "PAHNAPLSIIGYIR" --- ### **Implementação em Harbour** As soluções estão organizadas em dois arquivos principai...

BlackTDN :: Protheus WebService e PHP SoapFault

 

1 <html>
2 <head>
3 <title>BlackTDN :: UBTDNTBLVIEW.php</title>
4 </head>
5 <body>
6 <?php
7 $wsdl = "http://BlackTDN:8088/ws02/UBTDNTVIEW.apw?WSDL";
8 try { // exceptions -> http://php.net/manual/en/language.exceptions.php
9 // SoapClient and WSDL_CACHE_NONE -> http://php.net/manual/en/soapclient.soapclient.php
10 $client = new SoapClient($wsdl,array("cache_wsdl"=>WSDL_CACHE_NONE));
11 $alias = "SRA";
12 $deleted = false;
13 $recno = false;
14 $param = array("ALIAS"=>$alias,"RDELETED"=>$deleted);
15 try { // try -> http://php.net/manual/en/language.exceptions.php
16 $result = $client->GETTRMAX($param);
17 $tRMax = $result->GETTRMAXRESULT/10;
18 } catch (SoapFault $fault) { //SoapFault -> http://php.net/manual/en/function.is-soap-fault.php
19 $tRMax = 0;
20 }
21 //Control Structures (if) -> http://www.php.net/manual/en/control-structures.if.php
22 if ($tRMax>0){
23 $step = $tRMax%10;
24 //array -> http://php.net/manual/en/ref.array.php
25 $results = array();
26 //control Structures (for) -> http://php.net/manual/en/control-structures.for.php
27 for ($i = 1; $i <= $tRMax; $i+=$step) {
28 $e = min($i+$step,$tRMax);
29 $param = array("ALIAS"=>$alias,"RINIT"=>$i,"REND"=>$e,"RDELETED"=>$deleted,"RRECNO"=>$recno);
30 $result = $client->GETTABLE($param);
31 // exceptions -> http://php.net/manual/en/language.exceptions.php
32 if (!is_soap_fault($result)){ //is_soap_fault -> http://php.net/manual/en/function.is-soap-fault.php
33 array_push ($results,$result); //array_push -> http://php.net/manual/en/ref.array.php
34 }
35 }
36 //sizeof -> http://www.php.net/manual/en/function.sizeof.php
37 if (sizeof($results)>0 ){
38 $result = $results[0];
39 } else {
40 //throw - > http://php.net/manual/en/language.exceptions.php
41 throw new Exception('No Results');
42 }
43 echo "<table border='1' align='left'>";
44 echo "<thead>";
45 echo "<tr align='left'>";
46 echo "<th>FLDNAME</th>";
47 echo "<th>FLDTYPE</th>";
48 echo "<th>FLDSIZE</th>";
49 echo "<th>FLDDEC</th>";
50 echo "<th>FLDTITLE</th>";
51 echo "<th>FLDDESCRIPTION</th>";
52 echo "<th>FLDMANDATORY</th>";
53 echo "</tr>";
54 echo "</thead>";
55 echo "<tbody>";
56 // is_array -> //array -> http://php.net/manual/en/ref.array.php
57 if (is_array($result->GETTABLERESULT->TABLESTRUCT->UFIELDSTRUCT)){
58 //Control Structures (foreach) -> http://www.php.net/manual/en/control-structures.foreach.php
59 foreach ($result->GETTABLERESULT->TABLESTRUCT->UFIELDSTRUCT as $item) {
60 echo "<tr>";
61 echo "<td><pre>".print_r($item->FLDNAME,true)."</pre></td>";
62 echo "<td><pre>".print_r($item->FLDTYPE,true)."</pre></td>";
63 echo "<td><pre>".print_r($item->FLDSIZE,true)."</pre></td>";
64 echo "<td><pre>".print_r($item->FLDDEC,true)."</pre></td>";
65 echo "<td><pre>".print_r($item->FLDTITLE,true)."</pre></td>";
66 echo "<td><pre>".print_r($item->FLDDESCRIPTION,true)."</pre></td>";
67 echo "<td><pre>".print_r($item->FLDMANDATORY,true)."</pre></td>";
68 echo "</tr>";
69 }
70 } else {
71 echo "<tr>";
72 //Control Structures (foreach) -> http://www.php.net/manual/en/control-structures.foreach.php
73 foreach ($result->GETTABLERESULT->TABLESTRUCT as $item) {
74 echo "<td><pre>".print_r($item->FLDNAME,true)."</pre></td>";
75 echo "<td><pre>".print_r($item->FLDTYPE,true)."</pre></td>";
76 echo "<td><pre>".print_r($item->FLDSIZE,true)."</pre></td>";
77 echo "<td><pre>".print_r($item->FLDDEC,true)."</pre></td>";
78 echo "<td><pre>".print_r($item->FLDTITLE,true)."</pre></td>";
79 echo "<td><pre>".print_r($item->FLDDESCRIPTION,true)."</pre></td>";
80 echo "<td><pre>".print_r($item->FLDMANDATORY,true)."</pre></td>";
81 }
82 echo "</tr>";
83 }
84 echo "<tbody>";
85 echo "</table>";
86 echo "<br />";
87 echo "<table border='1' align='left'>";
88 echo "<thead>";
89 echo "<tr align='left'>";
90 //Control Structures (if) -> http://www.php.net/manual/en/control-structures.if.php
91 // is_array -> //array -> http://php.net/manual/en/ref.array.php
92 if (is_array($result->GETTABLERESULT->TABLESTRUCT->UFIELDSTRUCT)){
93 //Control Structures (foreach) -> http://www.php.net/manual/en/control-structures.foreach.php
94 foreach ($result->GETTABLERESULT->TABLESTRUCT->UFIELDSTRUCT as $item) {
95 echo "<th><pre>".print_r($item->FLDNAME,true)."</pre></th>";
96 }
97 } else {
98 //Control Structures (foreach) -> http://www.php.net/manual/en/control-structures.foreach.php
99 foreach ($result->GETTABLERESULT->TABLESTRUCT as $item) {
100 echo "<th><pre>".print_r($item->FLDNAME,true)."</pre></th>";
101 }
102 }
103 echo "</tr>";
104 echo "</thead>";
105 echo "<tbody>";
106 //Control Structures (foreach) -> http://www.php.net/manual/en/control-structures.foreach.php
107 foreach ($results as $result){
108 // is_array -> //array -> http://php.net/manual/en/ref.array.php
109 if (is_array($result->GETTABLERESULT->TABLEDATA->FIELDVIEW)){
110 //Control Structures (foreach) -> http://www.php.net/manual/en/control-structures.foreach.php
111 foreach ($result->GETTABLERESULT->TABLEDATA->FIELDVIEW as $itens) {
112 echo "<tr align='left'>";
113 if (is_array($itens->FLDTAG->STRING)){
114 foreach ($itens->FLDTAG->STRING as $item) {
115 echo "<td><pre>".print_r($item,true)."</pre></td>";
116 }
117 } else {
118 foreach ($itens->FLDTAG as $item) {
119 echo "<td><pre>".print_r($item,true)."</pre></td>";
120 }
121 }
122 echo "</tr>";
123 }
124 } else{
125 echo "<tr align='left'>";
126 if (is_array($result->GETTABLERESULT->TABLEDATA->FIELDVIEW->FLDTAG->STRING)){
127 foreach ($result->GETTABLERESULT->TABLEDATA->FIELDVIEW->FLDTAG->STRING as $item) {
128 echo "<td><pre>".print_r($item,true)."</pre></td>";
129 }
130 } else {
131 $item = $result->GETTABLERESULT->TABLEDATA->FIELDVIEW->FLDTAG->STRING;
132 echo "<td><pre>".print_r($item,true)."</pre></td>";
133 }
134 echo "<tr>";
135 }
136 }
137 echo "</tbody>";
138 echo "</table>";
139 }
140 } catch (SoapFault $fault) { //SoapFault -> http://php.net/manual/en/function.is-soap-fault.php
141 trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR);
142 } catch (Exception $e) { //Exception -> http://php.net/manual/en/language.exceptions.php
143 echo "Caught Exception ('{$e->getMessage()}')\n{$e}\n";
144 }
145 die();
146 ?>
147 </body>
148 </html>


O código do WS em advpl bem como os demais exemplos em PHP poderão ser obtidos aqui.

Obs.: Existe dependencia do programa NDJLIB006.prg que pode ser obtido ao clicar aqui.

[]s
иαldσ dj

Comentários

Postagens mais visitadas