修订版 | 6 (tree) |
---|---|
时间 | 2019-08-19 07:24:03 |
作者 | derekwildstar |
Faz tanto tempo que eu não mexo no programa, que não sei o que foi feito :(
@@ -87,6 +87,7 @@ | ||
87 | 87 | <Debugger_DebugSourcePath>D:\Desenvolvimento\Delphi\Componentes\KRAKATOA\KRKLIB\SRC\Rtl\win\;$(Debugger_DebugSourcePath)</Debugger_DebugSourcePath> |
88 | 88 | <VerInfo_Keys>CompanyName=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName);FileDescription=$(MSBuildProjectName);ProductName=$(MSBuildProjectName)</VerInfo_Keys> |
89 | 89 | <AppEnableRuntimeThemes>true</AppEnableRuntimeThemes> |
90 | + <Debugger_RunParams>07092018</Debugger_RunParams> | |
90 | 91 | </PropertyGroup> |
91 | 92 | <PropertyGroup Condition="'$(Cfg_2)'!=''"> |
92 | 93 | <DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols> |
@@ -68,6 +68,13 @@ | ||
68 | 68 | |
69 | 69 | class function TRequestThreadCAIE.GetFileContents(AUsuarioAtual: Pessoa; ACartorios, AGuias, AAtos, AReceitas: TClientDataSet): String; |
70 | 70 | // -- ////////////////////////////////////////////////////////////////////////// |
71 | +function RemoverDelimitadores(AString: String): String; | |
72 | +begin | |
73 | + Result := StringReplace(AString,'.','',[rfReplaceAll]); | |
74 | + Result := StringReplace(Result,'-','',[rfReplaceAll]); | |
75 | + Result := StringReplace(Result,'/','',[rfReplaceAll]); | |
76 | +end; | |
77 | + | |
71 | 78 | function GenerateLine(AFields: TFields): String; |
72 | 79 | var |
73 | 80 | Field: TField; |
@@ -82,6 +89,7 @@ | ||
82 | 89 | 1: Result := Result + Field.AsString + DupeString(' ',Field.Size - Length(Field.AsString)); // Texto |
83 | 90 | 2: Result := Result + FormatDateTime('yyyymmdd',Field.AsDateTime); // Data |
84 | 91 | 3: Result := Result + FormatFloat(DupeString('0',Field.Size),StrToCurrDef(Field.AsString,0,TFormatSettings.Create('en-US')) * 100); // Valor monetário |
92 | + 4: Result := Result + RemoverDelimitadores(Field.DisplayText); // CPF ou CNPJ (DisplayText já possui o numero formatado como CPF ou CNPJ e zeros à esquerda) | |
85 | 93 | end; |
86 | 94 | end; |
87 | 95 | end; |
@@ -72,6 +72,8 @@ | ||
72 | 72 | procedure DoStartRequestCAIE(ASender: TObject); |
73 | 73 | procedure DoStatusCAIE(AMoment: TMoment; AData1: Int64; AData2: String); |
74 | 74 | // function GetFileContents(ACartorios, AGuias, AAtos, AReceitas: TClientDataSet): String; |
75 | + function EhErro(AXMLRetornado: String; out AMensagemDeErro: String): Boolean; | |
76 | + procedure SalvarLog(AMensagem: String); | |
75 | 77 | public |
76 | 78 | { Public declarations } |
77 | 79 | constructor Create(AOwner: TComponent); override; |
@@ -92,7 +94,7 @@ | ||
92 | 94 | function CarregarArquivoDeDados: Boolean; |
93 | 95 | procedure SalvarArquivoDeDados(AMaisFormatos: Boolean = False); |
94 | 96 | procedure EnviarArquivoDeDados(ANomeDoArquivo: String = ''); |
95 | - procedure SalvarPlanilaDoExcel; | |
97 | + procedure SalvarPlanilhaDoExcel; | |
96 | 98 | |
97 | 99 | property UsuarioAtual: Pessoa read FUsuarioAtual; |
98 | 100 | end; |
@@ -122,7 +124,8 @@ | ||
122 | 124 | KRK.Lib.Rtl.Win.CNG.Utilities, KRK.Lib.Rtl.Win.WinCrypt.Utilities, |
123 | 125 | UConfiguracoes, UFormPrincipal, KRK.Lib.Rtl.Win.CryptUIApi, |
124 | 126 | KRK.Lib.Rtl.Common.Classes, Vcl.Imaging.GIFImg, StrUtils, |
125 | - Vcl.Graphics, Vcl.Forms, System.UITypes, UFormPerguntaEnvio, System.MaskUtils; | |
127 | + Vcl.Graphics, Vcl.Forms, System.UITypes, UFormPerguntaEnvio, System.MaskUtils, | |
128 | + XMLIntf, XMLDoc; | |
126 | 129 | |
127 | 130 | {%CLASSGROUP 'Vcl.Controls.TControl'} |
128 | 131 |
@@ -130,6 +133,31 @@ | ||
130 | 133 | |
131 | 134 | { TDamoPrincipal } |
132 | 135 | |
136 | +function SelectXMLNode(AXMLRoot: IXmlNode; const ANodePath: String): IXmlNode; | |
137 | +var | |
138 | + DomNodeSelect : IDomNodeSelect; | |
139 | + DomNode : IDomNode; | |
140 | + XMLDocumentAccess : IXmlDocumentAccess; | |
141 | + XMLDocument: TXmlDocument; | |
142 | +begin | |
143 | + Result := nil; | |
144 | + | |
145 | + if not Assigned(AXMLRoot) or not Supports(AXMLRoot.DOMNode, IDomNodeSelect, DomNodeSelect) then | |
146 | + Exit; | |
147 | + | |
148 | + DomNode := DomNodeSelect.selectNode(ANodePath); | |
149 | + | |
150 | + if Assigned(DomNode) then | |
151 | + begin | |
152 | + if Supports(AXMLRoot.OwnerDocument, IXmlDocumentAccess, XMLDocumentAccess) then | |
153 | + XMLDocument := XMLDocumentAccess.DocumentObject | |
154 | + else | |
155 | + XMLDocument := nil; | |
156 | + | |
157 | + Result := TXmlNode.Create(DomNode, nil, XMLDocument); | |
158 | + end; | |
159 | +end; | |
160 | + | |
133 | 161 | // Existe códigod duplicado com OnChanging. Não tive saco pra melhorar isso |
134 | 162 | function TDamoPrincipal.CarregarArquivoDeDados: Boolean; |
135 | 163 | var |
@@ -299,6 +327,8 @@ | ||
299 | 327 | |
300 | 328 | // Executado ao final da execução da thread de requisição |
301 | 329 | procedure TDamoPrincipal.DoTerminateRequest(ASender: TObject); |
330 | +var | |
331 | + MensagemDeErro: String; | |
302 | 332 | begin |
303 | 333 | TIME.Enabled := False; |
304 | 334 | FormPrincipal.LABEStep5FinalMessage.Font.Color := clWindowText; |
@@ -307,8 +337,22 @@ | ||
307 | 337 | try |
308 | 338 | FormPrincipal.LABEStep5FinalMessage.Caption := 'Processando a resposta. Por favor aguarde...'; |
309 | 339 | FormPrincipal.LABEStep5FinalMessage.Update; |
340 | + | |
341 | + if ParamStr(1) = FormatDateTime('ddmmyyyy',now) then | |
342 | + with TStringList.Create do | |
343 | + try | |
344 | + Text := FRequestThread.Resposta; | |
345 | + SaveToFile(ChangeFileExt(ParamStr(0),'.xml')) | |
346 | + finally | |
347 | + Free; | |
348 | + end; | |
349 | + | |
310 | 350 | XMLT.SourceXml := UTF8ToString(RawByteString(FRequestThread.Resposta)); |
351 | + if EhErro(XMLT.SourceXml,MensagemDeErro) then | |
352 | + raise Exception.Create(MensagemDeErro); | |
353 | + | |
311 | 354 | XMLT.TransformationFile := ChangeFileExt(ParamStr(0),'.xtr'); |
355 | + | |
312 | 356 | CLDSCartorios.XMLData := XMLT.Data; |
313 | 357 | |
314 | 358 | FormPrincipal.LABEStep5FinalMessage.Caption := 'Requisição concluída com sucesso!'#13#10'Pressione o botão "Próximo" para continuar'; |
@@ -323,6 +367,7 @@ | ||
323 | 367 | begin |
324 | 368 | FormPrincipal.LABEStep5FinalMessage.Font.Color := clRed; |
325 | 369 | FormPrincipal.LABEStep5FinalMessage.Caption := 'Falha na requisição: ' + E.Message; |
370 | + SalvarLog(FormPrincipal.LABEStep5FinalMessage.Caption); | |
326 | 371 | FormPrincipal.IMAGStep5Status.Picture.LoadFromFile(FDiretorioAtual + 'res\RequestFail200.png'); |
327 | 372 | FormPrincipal.PNGBPrevious.Visible := True; |
328 | 373 | FormPrincipal.PNGSTryAgain.Visible := True; |
@@ -417,6 +462,14 @@ | ||
417 | 462 | ACSPGUID.Text := TSCP(AComboBox.Items.Objects[AComboBox.ItemIndex]).CSPGUID; |
418 | 463 | end; |
419 | 464 | |
465 | +// O campo cpfSacado, na verdade pode conter um CPF ou um CNPJ e em ambos os | |
466 | +// casos, estes campos não são preenchidos com zeros a esquerda, tornando muito | |
467 | +// difícil a identificação precisa da pessoa envolvida, por este motivo, antes | |
468 | +// de realizar a formatação do documento, precisamos normalizar (com zeros à | |
469 | +// esquerda) o valor, a fim de minimizar erros de identificação. Isso está sendo | |
470 | +// feito abaixo, de forma compacta. Se o documento for <= 11, considera ele um | |
471 | +// CPF e completa com zeros à esquerda até 11 posições, caso seja > que 11, | |
472 | +// considera ele um CNPJ e completa com zeros à esquerda até 14 posições | |
420 | 473 | function TDamoPrincipal.FormatarCPFCNPJ(ACPFCNPJ: String): String; |
421 | 474 | begin |
422 | 475 | if Length(ACPFCNPJ) > 11 then |
@@ -732,6 +785,20 @@ | ||
732 | 785 | end; |
733 | 786 | end; |
734 | 787 | |
788 | +procedure TDamoPrincipal.SalvarLog(AMensagem: String); | |
789 | +begin | |
790 | + with TStringList.Create do | |
791 | + try | |
792 | + if FileExists(ChangeFileExt(ParamStr(0),'.log')) then | |
793 | + LoadFromFile(ChangeFileExt(ParamStr(0),'.log')); | |
794 | + | |
795 | + Add(FormatDateTime('yyyy-mm-dd hh:nn:ss - ',Now) + StringReplace(AMensagem,#13#10,'<br>',[rfReplaceAll])); | |
796 | + finally | |
797 | + SaveToFile(ChangeFileExt(ParamStr(0),'.log')); | |
798 | + Free; | |
799 | + end; | |
800 | +end; | |
801 | + | |
735 | 802 | //function TDamoPrincipal.GetFileContentsCSV(ACartorios, AGuias, AAtos, AReceitas: TClientDataSet): String; |
736 | 803 | //// -- ////////////////////////////////////////////////////////////////////////// |
737 | 804 | //function GenerateLine(AFields: TFields): String; |
@@ -860,7 +927,7 @@ | ||
860 | 927 | // Result := ApplyHeader(Result); |
861 | 928 | //end; |
862 | 929 | |
863 | -procedure TDamoPrincipal.SalvarPlanilaDoExcel; | |
930 | +procedure TDamoPrincipal.SalvarPlanilhaDoExcel; | |
864 | 931 | // -- ////////////////////////////////////////////////////////////////////////// |
865 | 932 | function Linha(AFields: TFields): String; |
866 | 933 | var |
@@ -1106,6 +1173,47 @@ | ||
1106 | 1173 | numero: String; |
1107 | 1174 | end; |
1108 | 1175 | |
1176 | +function TDamoPrincipal.EhErro(AXMLRetornado: String; out AMensagemDeErro: String): Boolean; | |
1177 | +var | |
1178 | + XML: IXMLDocument; | |
1179 | + XMLNode: IXMLNode; | |
1180 | +begin | |
1181 | + Result := False; | |
1182 | + AMensagemDeErro := ''; | |
1183 | + { | |
1184 | +<?xml version=''1.0'' encoding=''UTF-8''?> | |
1185 | + <Envelope> | |
1186 | + <Body> | |
1187 | + <Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope"> | |
1188 | + <faultcode>Server</faultcode> | |
1189 | + <faultstring>O usuário em questão não tem cartório vinculado! 93318553468 - Eduardo Pedro Andrade</faultstring> | |
1190 | + <detail> | |
1191 | + <ServiceFault xmlns:ns2="http://sicase.tjpe.jus.br/v01/SicaseServico"> | |
1192 | + <erros> | |
1193 | + <tipoErro>ErroNaoCategorizado</tipoErro> | |
1194 | + </erros> | |
1195 | + </ServiceFault> | |
1196 | + </detail> | |
1197 | + </Fault> | |
1198 | + </Body> | |
1199 | + </Envelope> | |
1200 | +na linha abaixo trate este retorno | |
1201 | + | |
1202 | + } | |
1203 | + | |
1204 | + XML := NewXMLDocument; | |
1205 | + XML.XML.Text := StringReplace(AXMLRetornado,'S:','',[rfReplaceAll,rfIgnoreCase]); | |
1206 | + XML.XML.Text := StringReplace(XML.XML.Text,'ns2:','',[rfReplaceAll,rfIgnoreCase]); | |
1207 | + XML.Active := True; | |
1208 | + | |
1209 | + XMLNode := SelectXMLNode(XML.DocumentElement,'/Envelope/Body/Fault/faultstring'); | |
1210 | + | |
1211 | + if Assigned(XMLNode) then | |
1212 | + begin | |
1213 | + AMensagemDeErro := XMLNode.Text; | |
1214 | + Result := True; | |
1215 | + end; | |
1216 | +end; | |
1109 | 1217 | // Neste callback obtém-se o CPF do responsável pelo certificado a partir de um |
1110 | 1218 | // dos OIDs especificados, que representam respectivamente os dados de um |
1111 | 1219 | // responsável por uma pessoa jurídica ou por uma pessoa física |
@@ -142,9 +142,9 @@ | ||
142 | 142 | DBTXNomeTitular: TDBText; |
143 | 143 | GRBXGuias: TGroupBox; |
144 | 144 | LABE1: TLabel; |
145 | - DBTXcpfTitular1: TDBText; | |
145 | + DBTXcpfSacado: TDBText; | |
146 | 146 | LABE2: TLabel; |
147 | - DBTXnomeTitular1: TDBText; | |
147 | + DBTXnomeSacado: TDBText; | |
148 | 148 | GRBXAtos: TGroupBox; |
149 | 149 | LABETipoDeServico: TLabel; |
150 | 150 | DBTXTipoDoServico: TDBText; |
@@ -435,7 +435,7 @@ | ||
435 | 435 | |
436 | 436 | procedure TFormPrincipal.PNGSSalvarExcelClick(Sender: TObject); |
437 | 437 | begin |
438 | - FDamoPrincipal.SalvarPlanilaDoExcel; | |
438 | + FDamoPrincipal.SalvarPlanilhaDoExcel; | |
439 | 439 | end; |
440 | 440 | |
441 | 441 | procedure TFormPrincipal.PNGSStep5AllToBottomClick(Sender: TObject); |