A classe TspdMDFeDataSetX cria e gerencia uma lista de subdatasets que, por sua vez, armazenam os dados organizados em uma estrutura fixa de campos podendo serem utilizados tanto para gerar o XML de envio quanto para impressão dos dados no DAMDFE .

 

Segue um exemplo de como preencher os datasets para gerar um xml de envio para o modal Rodoviário:

 

// Construtor da classe que ja inicializa os datasets através do método CreateDataSets chamado internamente.

FspdMDFeDataSet := TspdMDFeDataSetX.Create(nil);

 

FspdMDFeDataset.MappingFileName := 'C:\Arquivos de programas\Tecnospeed\spdMDFe\Esquemas\Mapping.txt’;

 

FspdMDFeDataset.ConfigSection := 'XMLENVIO’;

 

FspdMDFeDataSet.EmptyDataSets;

 

FspdMDFeDataSet.Versao := '1.00';

FspdMDFeDataSet.IdLote := '1';

FspdMDFeDataSet.Include;

 

// Preenche o corpo principal do XML com as seguintes informações

FspdMDFeDataSet.SetFieldAsString('versao_2' , '1.00');

FspdMDFeDataSet.SetFieldAsString('cUF_5','41');

FspdMDFeDataSet.SetFieldAsString('tpAmb_6','2');

FspdMDFeDataSet.SetFieldAsString('tpEmit_7','1');

FspdMDFeDataSet.SetFieldAsString('mod_8','58');

FspdMDFeDataSet.SetFieldAsString('serie_9','1');

FspdMDFeDataSet.SetFieldAsString('nMDF_10','14');

FspdMDFeDataSet.SetFieldAsString('cMDF_11','00000001');

FspdMDFeDataSet.SetFieldAsString('cDV_12','1');

FspdMDFeDataSet.SetFieldAsString('modal_13',‘1’);

FspdMDFeDataSet.SetFieldAsString('dhEmi_14','2013-03-27T08:29:29');

FspdMDFeDataSet.SetFieldAsString('tpEmis_15','2');

FspdMDFeDataSet.SetFieldAsString('procEmi_16','0');

FspdMDFeDataSet.SetFieldAsString('verProc_17','1.0');

FspdMDFeDataSet.SetFieldAsString('UFIni_18','PR');

FspdMDFeDataSet.SetFieldAsString('UFFim_19','PR');

FspdMDFeDataSet.SetFieldAsString('CNPJ_26','08187168000160');

FspdMDFeDataSet.SetFieldAsString('IE_27',‘9044016688’);

FspdMDFeDataSet.SetFieldAsString('xNome_28','TECNOSPEED');

FspdMDFeDataSet.SetFieldAsString('xFant_29','TECNOSPEED');

FspdMDFeDataSet.SetFieldAsString('xLgr_31','RUA DUQUE DE CAXIAS');

FspdMDFeDataSet.SetFieldAsString('nro_32','882');

FspdMDFeDataSet.SetFieldAsString('xCpl_33','SALA 102 E 909');

FspdMDFeDataSet.SetFieldAsString('xBairro_34','CENTRO');

FspdMDFeDataSet.SetFieldAsString('cMun_35','4115200');

FspdMDFeDataSet.SetFieldAsString('xMun_36','Maringá');

FspdMDFeDataSet.SetFieldAsString('CEP_37',‘87020025’);

FspdMDFeDataSet.SetFieldAsString('UF_38','PR');

FspdMDFeDataSet.SetFieldAsString('fone_39','4430283749');

FspdMDFeDataSet.SetFieldAsString('email_40','testedanfe@gmail.com');

FspdMDFeDataSet.SetFieldAsString('versaoModal_42','1.00');

FspdMDFeDataSet.SetFieldAsString('qCTe_69','2');

FspdMDFeDataSet.SetFieldAsString('qCT_70','');

FspdMDFeDataSet.SetFieldAsString('qNFe_71','');

FspdMDFeDataSet.SetFieldAsString('qNF_72','');

FspdMDFeDataSet.SetFieldAsString('vCarga_73','3500.00');

FspdMDFeDataSet.SetFieldAsString('cUnid_74','02');

FspdMDFeDataSet.SetFieldAsString('qCarga_75','2.8000');

FspdMDFeDataSet.SetFieldAsString('infAdFisco_79','');

FspdMDFeDataSet.SetFieldAsString('infCpl_80','INFORMACOES COMPLEMENTARES');

 

FspdMDFeDataSet.IncludePart('infMunCarrega');

FspdMDFeDataSet.SetFieldAsString('cMunCarrega_21','4115200');

FspdMDFeDataSet.SetFieldAsString('xMunCarrega_22','Maringá');

FspdMDFeDataSet.SavePart('infMunCarrega');

 

FspdMDFeDataSet.IncludePart('infPercurso');

FspdMDFeDataSet.SetFieldAsString('UFPer_24','');

FspdMDFeDataSet.SavePart('infPercurso');

 

FspdMDFeDataSet.IncludePart('infMunDescarga');

FspdMDFeDataSet.SetFieldAsString('cMunDescarga_45','4115200');

FspdMDFeDataSet.SetFieldAsString('xMunDescarga_47','Maringá');

FspdMDFeDataSet.SavePart('infMunDescarga');

 

FspdMDFeDataSet.IncludePart('infCTe');

FspdMDFeDataSet.SetFieldAsString('chCTe_49',‘42130105793827000113571010000010021000000011’);

FspdMDFeDataSet.SavePart('infCTe');

 

FspdMDFeDataSet.IncludePart('infCTe');

FspdMDFeDataSet.SetFieldAsString('chCTe_49',‘42130105793827000113571010000010301123456468’);

FspdMDFeDataSet.SetFieldAsString('SegCodBarra_50','');

FspdMDFeDataSet.SavePart('infCTe');


 

FspdMDFeDataSet.IncludePart('infCT');

FspdMDFeDataSet.SetFieldAsString('nCT_52','');

FspdMDFeDataSet.SetFieldAsString('serie_53','');

FspdMDFeDataSet.SetFieldAsString('subser_54','');

FspdMDFeDataSet.SetFieldAsString('dEmi_55','');

FspdMDFeDataSet.SetFieldAsString('vCarga_56','');

FspdMDFeDataSet.SavePart('infCT');

 

FspdMDFeDataSet.IncludePart('infNFe');

FspdMDFeDataSet.SetFieldAsString('chNFe_58','');

FspdMDFeDataSet.SetFieldAsString('SegCodBarra_59','');

FspdMDFeDataSet.SavePart('infNFe');

 

FspdMDFeDataSet.IncludePart('infNF');

FspdMDFeDataSet.SetFieldAsString('CNPJ_61','');

FspdMDFeDataSet.SetFieldAsString('UF_62','');

FspdMDFeDataSet.SetFieldAsString('nNF_63','');

FspdMDFeDataSet.SetFieldAsString('serie_64','');

FspdMDFeDataSet.SetFieldAsString('dEmi_65','');

FspdMDFeDataSet.SetFieldAsString('vNF_66','');

FspdMDFeDataSet.SetFieldAsString('PIN_67','');

FspdMDFeDataSet.SavePart('infNF');

 

FspdMDFeDataSet.IncludePart('lacres');

FspdMDFeDataSet.SetFieldAsString('nLacre_77','123');

FspdMDFeDataSet.SavePart('lacres');


 

// Preenche as informações do modal Rodoviário

FspdMDFeDataSet.IncludePart('rodo');

FspdMDFeDataSet.SetFieldAsString('RNTRC_rodo_2','12345678');

FspdMDFeDataSet.SetFieldAsString('CIOT_rodo_3','123456789012');

FspdMDFeDataSet.SetFieldAsString('cInt_rodo_5','001');

FspdMDFeDataSet.SetFieldAsString('placa_rodo_6','ABC1234');

FspdMDFeDataSet.SetFieldAsString('tara_rodo_7','5000');

FspdMDFeDataSet.SetFieldAsString('capKG_rodo_8','4500');

FspdMDFeDataSet.SetFieldAsString('capM3_rodo_9','400');

FspdMDFeDataSet.SetFieldAsString('RNTRC_rodo_11','12345678');

FspdMDFeDataSet.SavePart('rodo');

 

FspdMDFeDataSet.IncludePart('condutor');

FspdMDFeDataSet.SetFieldAsString('xNome_rodo_13','JOAO');

FspdMDFeDataSet.SetFieldAsString('CPF_rodo_14','12345678912');

FspdMDFeDataSet.SavePart('condutor');

 

FspdMDFeDataSet.IncludePart('veicReboque');

FspdMDFeDataSet.SetFieldAsString('cInt_rodo_16','002');

FspdMDFeDataSet.SetFieldAsString('placa_rodo_17','XYZ4567');

FspdMDFeDataSet.SetFieldAsString('tara_rodo_18','4000');

FspdMDFeDataSet.SetFieldAsString('capKG_rodo_19','3000');

FspdMDFeDataSet.SetFieldAsString('capM3_rodo_20','300');

FspdMDFeDataSet.SetFieldAsString('RNTRC_rodo_22','87654321');

FspdMDFeDataSet.SavePart('veicReboque');

 

FspdMDFeDataSet.IncludePart('disp');

FspdMDFeDataSet.SetFieldAsString('CNPJForn_rodo_25','12345678000199');

FspdMDFeDataSet.SetFieldAsString('CNPJPg_rodo_26','21543876000188');

FspdMDFeDataSet.SetFieldAsString('nCompra_rodo_27','789');

FspdMDFeDataSet.SavePart('disp');



 

FspdMDFeDataSet.Save;


 

Para preencher o dataset para outros modais deve-se alterar o campo 'modal_13' para o valor do respectivo modal e preencher o dataset com os campos abaixo. Lembrando que só é permitido um modal por nota, ou seja, deve-se utilizar o exemplo de apenas um modal para cada nota.  Segue o exemplo:

 

// Preenche as inforamções do modal aéreo

FspdMDFeDataSet.IncludePart('aereo');

FspdMDFeDataSet.SetFieldAsString('nac_aereo_2','BR');

FspdMDFeDataSet.SetFieldAsString('matr_aereo_3','123456');

FspdMDFeDataSet.SetFieldAsString('nVoo_aereo_4','123456789');

FspdMDFeDataSet.SetFieldAsString('cAerEmb_aereo_5','A000');

FspdMDFeDataSet.SetFieldAsString('cAerDes_aereo_6','A111');

FspdMDFeDataSet.SetFieldAsString('dVoo_aereo_7','2013-04-08');

FspdMDFeDataSet.SavePart('aereo');


 

// Preenche as inforamções do modal aquaviário

FspdMDFeDataSet.IncludePart('aquav');

FspdMDFeDataSet.SetFieldAsString('CNPJAgeNav_aquav_2','94814886000150');

FspdMDFeDataSet.SetFieldAsString('tpEmb_aquav_3','01');

FspdMDFeDataSet.SetFieldAsString('cEmbar_aquav_4','0123456789');

FspdMDFeDataSet.SetFieldAsString('nViagem_aquav_5','0123456789');

FspdMDFeDataSet.SetFieldAsString('cPrtEmb_aquav_6','12345');

FspdMDFeDataSet.SetFieldAsString('cPrtDest_aquav_7','12345');

FspdMDFeDataSet.SavePart('aquav');

 

FspdMDFeDataSet.IncludePart('infTermCarreg');

FspdMDFeDataSet.SetFieldAsString('cTermCarreg_aquav_9','12345678');

FspdMDFeDataSet.SavePart('infTermCarreg');

 

FspdMDFeDataSet.IncludePart('infTermDescarreg');

FspdMDFeDataSet.SetFieldAsString('cTermDescarreg_aquav_11','12345678');

FspdMDFeDataSet.SavePart('infTermDescarreg');

 

FspdMDFeDataSet.IncludePart('infEmbComb');

FspdMDFeDataSet.SetFieldAsString('cEmbComb_aquav_13','0123456789');

FspdMDFeDataSet.SavePart('infEmbComb');


 

// Preenche as inforamções do modal ferroviário

FspdMDFeDataSet.IncludePart('ferrov');

FspdMDFeDataSet.SetFieldAsString('xPref_ferrov_3','0123456789');

FspdMDFeDataSet.SetFieldAsString('dhTrem_ferrov_4','2013-04-08');

FspdMDFeDataSet.SetFieldAsString('xOri_ferrov_5','123');

FspdMDFeDataSet.SetFieldAsString('xDest_ferrov_6','123');

FspdMDFeDataSet.SetFieldAsString('qVag_ferrov_7','123');

FspdMDFeDataSet.SavePart('ferrov');

 

FspdMDFeDataSet.IncludePart('vag');

FspdMDFeDataSet.SetFieldAsString('serie_ferrov_9','123');

FspdMDFeDataSet.SetFieldAsString('nVag_ferrov_10','12345678');

FspdMDFeDataSet.SetFieldAsString('nSeq_ferrov_11','123');

FspdMDFeDataSet.SetFieldAsString('TU_ferrov_12','1234567');

FspdMDFeDataSet.SavePart('vag');

 

Após ter o datasets todo preenchido com seu respectivo modal o XML pode ser obtido pelo método LoteMDFe. Exemplo:


FspdMDFeDataSet.LoteMDFe;