Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmteste
	Inherits System.Windows.Forms.Form
	
	
	'Private Declare Function GetIpAddrTable_API Lib "IpHlpApi" Alias "GetIpAddrTable" (pIPAddrTable As Any, pdwSize As Long, ByVal bOrder As Long) As Long
	
	Dim aux As String
	Dim vlr1 As Double
	Dim vlr2 As Double
	Dim vlr3 As Double
	Dim vlr4 As Double
	Dim vlr5 As Double
	
	Dim tamanho_inicial As Double
	
	Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Integer)
	
	Private Sub btFaturasNET_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles btFaturasNET.Click
		Call CriaTabelaFaturasNet()
		Call InsereDadosFaturasNet()
	End Sub
	
	Private Sub CriaTabelaFaturasNet()
		Dim lstrSql As String
		'  lstrSql = ""
		'  lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS `unidadesnet` ("
		'  lstrSql = lstrSql & "  `cpf_cnpj` varchar(18) default NULL, "
		'  lstrSql = lstrSql & "  `zona`  char(3) default NULL, "
		'  lstrSql = lstrSql & "  `livro` char(2) default NULL, "
		'  lstrSql = lstrSql & "  `conta` varchar(8) default NULL, "
		'  lstrSql = lstrSql & "  `grupo` char(1) default NULL, "
		'  lstrSql = lstrSql & "  `nomecons` varchar(85) default NULL, "
		'  lstrSql = lstrSql & " PRIMARY KEY  (`cpf_cnpj`, `zona`, `livro`, `conta`, `grupo`), "
		'  lstrSql = lstrSql & " KEY `keyzona` (`zona`), "
		'  lstrSql = lstrSql & " KEY `keylivro` (`livro`), "
		'  lstrSql = lstrSql & " KEY `keyconta` (`conta`), "
		'  lstrSql = lstrSql & " KEY `keygrupo` (`grupo`), "
		'  lstrSql = lstrSql & " KEY `keycpf_cnpj` (`cpf_cnpj`) "
		'  lstrSql = lstrSql & " ) ENGINE=InnoDB DEFAULT CHARSET=latin1 "
		'  Call Executar(lstrSql)
		lstrSql = ""
		lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS `faturasnet` ("
		lstrSql = lstrSql & "  `numnf`   double NOT NULL default '0', "
		lstrSql = lstrSql & "  `mesano`  varchar(7) NOT NULL default '', "
		lstrSql = lstrSql & "  `cfop`    double(4, 3) default NULL, "
		lstrSql = lstrSql & "  `codclas` varchar(4) default NULL, "
		lstrSql = lstrSql & "  `ta` varchar(6) default NULL, "
		lstrSql = lstrSql & "  `zona`  char(3) default NULL, "
		lstrSql = lstrSql & "  `livro` char(2) default NULL, "
		lstrSql = lstrSql & "  `conta` varchar(8) default NULL, "
		lstrSql = lstrSql & "  `rota`  varchar(10) default NULL, "
		lstrSql = lstrSql & "  `banco_fatur` varchar(40) default NULL, "
		lstrSql = lstrSql & "  `banident` varchar(40) default NULL, "
		lstrSql = lstrSql & "  `agenc` varchar(4) default NULL, "
		lstrSql = lstrSql & "  `cc` varchar(12) default NULL, "
		lstrSql = lstrSql & "  `pagto_governo` char(1) NOT NULL default 'N', "
		lstrSql = lstrSql & "  `cpf_cnpj` varchar(18) default NULL, "
		lstrSql = lstrSql & "  `insc` varchar(25) default NULL, "
		lstrSql = lstrSql & "  `rg` varchar(35) default NULL, "
		lstrSql = lstrSql & "  `nomecons` varchar(85) default NULL, "
		lstrSql = lstrSql & "  `refcons` varchar(60) default NULL, "
		lstrSql = lstrSql & "  `uf` char(2) default NULL, "
		lstrSql = lstrSql & "  `cidade` varchar(60) default NULL, "
		lstrSql = lstrSql & "  `distrito` varchar(60) default NULL, "
		lstrSql = lstrSql & "  `bairro` varchar(60) default NULL, "
		lstrSql = lstrSql & "  `logradouro` varchar(60) default NULL, "
		lstrSql = lstrSql & "  `complemento` varchar(140) default NULL, "
		lstrSql = lstrSql & "  `cep` varchar(10) default NULL, "
		lstrSql = lstrSql & "  `entrega` int(11) default NULL, "
		lstrSql = lstrSql & "  `uf_entrega` varchar(2) default NULL, "
		lstrSql = lstrSql & "  `cid_entrega` varchar(60) default NULL, "
		lstrSql = lstrSql & "  `dis_entrega` varchar(60) default NULL, "
		lstrSql = lstrSql & "  `bai_entrega` varchar(60) default NULL, "
		lstrSql = lstrSql & "  `log_entrega` varchar(60) default NULL, "
		lstrSql = lstrSql & "  `com_entrega` varchar(100) NOT NULL default '', "
		lstrSql = lstrSql & "  `cep_entrega` varchar(10) default NULL, "
		lstrSql = lstrSql & "  `valortot` decimal(14, 2) default NULL, "
		lstrSql = lstrSql & "  `valorliq` decimal(14, 2) default NULL, "
		lstrSql = lstrSql & "  `vlrconsutrib` decimal(10, 2) default NULL, "
		lstrSql = lstrSql & "  `datavenc` date default '0000-00-00', "
		lstrSql = lstrSql & "  `dataapr` date default '0000-00-00', "
		lstrSql = lstrSql & "  `dataemissao` date default '0000-00-00', "
		lstrSql = lstrSql & "  `dataproxleit` date default '0000-00-00', "
		lstrSql = lstrSql & "  `dataleit` date default '0000-00-00', "
		lstrSql = lstrSql & "  `dataleitant` date default '0000-00-00', "
		lstrSql = lstrSql & "  `datapag` date default '0000-00-00', "
		lstrSql = lstrSql & "  `num_med` varchar(18) default NULL, "
		lstrSql = lstrSql & "  `const_med` double default NULL, "
		lstrSql = lstrSql & "  `fase` char(1) default NULL, "
		lstrSql = lstrSql & "  `tensao` varchar(10) default NULL, "
		lstrSql = lstrSql & "  `codhash` varchar(50) default NULL, "
		lstrSql = lstrSql & "  `codbarra` varchar(50) default NULL, "
		lstrSql = lstrSql & "  `dvcodbarra` varchar(4) default NULL, "
		lstrSql = lstrSql & "  `leit` double default NULL, "
		lstrSql = lstrSql & "  `leituraant` varchar(10) default NULL, "
		lstrSql = lstrSql & "  `consfaturado` double default NULL, "
		lstrSql = lstrSql & "  `conslido` double default NULL, "
		lstrSql = lstrSql & "  `valorconsumo` double default NULL, "
		lstrSql = lstrSql & "  `leitura_kvarh_atual` double default NULL, "
		lstrSql = lstrSql & "  `leitura_kvarh_anterior` double default NULL, "
		lstrSql = lstrSql & "  `consumo_kvarh` double default NULL, "
		lstrSql = lstrSql & "  `LeitReservadoAtu` double default '0', "
		lstrSql = lstrSql & "  `LeitReservadoAnt` double default '0', "
		lstrSql = lstrSql & "  `consumoreservado` double default NULL, "
		lstrSql = lstrSql & "  `vlrConsumoReservado` double default NULL, "
		lstrSql = lstrSql & "  `saldo_arred` double default '0', "
		lstrSql = lstrSql & "  `diasconsumo` varchar(2) default NULL, "
		lstrSql = lstrSql & "  `vlrdiario` double default NULL, "
		lstrSql = lstrSql & "  `mediaconsumodiario` double default NULL, "
		lstrSql = lstrSql & "  `mesmaiorconsumo` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `mesmenorconsumo` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `maiorconsumo` double default NULL, "
		lstrSql = lstrSql & "  `menorconsumo` double default NULL, "
		lstrSql = lstrSql & "  `mediaconsumo3meses` double default NULL, "
		lstrSql = lstrSql & "  `ocorrencia` varchar(5) default NULL, "
		lstrSql = lstrSql & "  `descocorrencia` varchar(25) default NULL, "
		lstrSql = lstrSql & "  `valorpend` double default '0', "
		lstrSql = lstrSql & "  `totalpend` int(11) default '0', "
		lstrSql = lstrSql & "  `descclasse` varchar(100) default NULL, "
		lstrSql = lstrSql & "  `fp` double(3, 2) default NULL, "
		lstrSql = lstrSql & "  `baseicms` double default NULL, "
		lstrSql = lstrSql & "  `aliqicms` double default NULL, "
		lstrSql = lstrSql & "  `vlricms` double default NULL, "
		lstrSql = lstrSql & "  `baseicms1` double default NULL, "
		lstrSql = lstrSql & "  `aliqicms1` double default NULL, "
		lstrSql = lstrSql & "  `vlricms1` double default NULL, "
		lstrSql = lstrSql & "  `baseicmstotal` double default '0', "
		lstrSql = lstrSql & "  `vlricmstotal` double default '0', "
		lstrSql = lstrSql & "  `basepis` double default NULL, "
		lstrSql = lstrSql & "  `aliqpis` double default NULL, "
		lstrSql = lstrSql & "  `vlrpis` double default NULL, "
		lstrSql = lstrSql & "  `basecofins` double default NULL, "
		lstrSql = lstrSql & "  `aliqcofins` double default NULL, "
		lstrSql = lstrSql & "  `vlrcofins` double default NULL, "
		lstrSql = lstrSql & "  `mensagem` varchar(255) default NULL, "
		lstrSql = lstrSql & "  `dec_meta` double default NULL, "
		lstrSql = lstrSql & "  `dec_rea` double default NULL, "
		lstrSql = lstrSql & "  `fec_meta` double default NULL, "
		lstrSql = lstrSql & "  `fec_rea` double default NULL, "
		lstrSql = lstrSql & "  `dic_meta` double default NULL, "
		lstrSql = lstrSql & "  `dic_rea` double default NULL, "
		lstrSql = lstrSql & "  `fic_meta` double default NULL, "
		lstrSql = lstrSql & "  `fic_rea` double default NULL, "
		lstrSql = lstrSql & "  `dmic` double default NULL, "
		lstrSql = lstrSql & "  `dmicM` double default NULL, "
		lstrSql = lstrSql & "  `refindicador` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `conjunto` varchar(255) default NULL, "
		lstrSql = lstrSql & "  `ret_irpj` double default '0', "
		lstrSql = lstrSql & "  `ret_pis` double default '0', "
		lstrSql = lstrSql & "  `ret_csll` double default '0', "
		lstrSql = lstrSql & "  `ret_cofins` double default '0', "
		lstrSql = lstrSql & "  `comp_energia` double default NULL, "
		lstrSql = lstrSql & "  `comp_transmissao` double default NULL, "
		lstrSql = lstrSql & "  `comp_distribuicao` double default NULL, "
		lstrSql = lstrSql & "  `comp_encargos_setoriais` double default NULL, "
		lstrSql = lstrSql & "  `comp_outros` double default NULL, "
		lstrSql = lstrSql & "  `itens_fatura` text default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano01` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon01` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto01` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo01` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura01` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu01` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren01` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano02` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon02` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto02` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo02` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura02` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu02` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren02` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano03` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon03` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto03` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo03` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura03` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu03` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren03` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano04` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon04` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto04` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo04` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura04` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu04` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren04` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano05` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon05` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto05` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo05` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura05` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu05` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren05` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano06` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon06` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto06` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo06` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura06` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu06` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren06` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano07` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon07` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto07` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo07` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura07` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu07` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren07` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano08` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon08` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto08` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo08` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura08` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu08` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren08` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano09` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon09` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto09` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo09` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura09` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu09` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren09` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano10` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon10` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto10` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo10` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura10` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu10` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren10` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano11` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon11` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto11` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo11` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura11` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu11` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren11` int default NULL, "
		lstrSql = lstrSql & "  `hist_mes_ano12` varchar(7) default NULL, "
		lstrSql = lstrSql & "  `hist_diascon12` int default NULL, "
		lstrSql = lstrSql & "  `hist_datpgto12` date default NULL, "
		lstrSql = lstrSql & "  `hist_consumo12` double default NULL, "
		lstrSql = lstrSql & "  `hist_leitura12` double default NULL, "
		lstrSql = lstrSql & "  `hist_vlrfatu12` double default NULL, "
		lstrSql = lstrSql & "  `hist_ocorren12` int default NULL, "
		lstrSql = lstrSql & " PRIMARY KEY  (`numnf`, `mesano`), "
		lstrSql = lstrSql & " KEY `keyzona` (`zona`), "
		lstrSql = lstrSql & " KEY `keylivro` (`livro`), "
		lstrSql = lstrSql & " KEY `keyconta` (`conta`), "
		lstrSql = lstrSql & " KEY `keyrota` (`rota`), "
		lstrSql = lstrSql & " KEY `keyvalortot` (`valortot`), "
		lstrSql = lstrSql & " KEY `keycpf_cnpj` (`cpf_cnpj`) "
		lstrSql = lstrSql & " ) ENGINE=InnoDB DEFAULT CHARSET=latin1 "
		Call Executar(lstrSql)
	End Sub
	Private Sub InsereDadosFaturasNet()
		'dados da fatura
		Dim lstrMesAno As String
		Dim ldblNumNf As Double
		Dim lstrItens As String
		Dim lstrIteImp As String
		Dim lstrIteRef As String
		Dim lstrIteImpCon As String
		Dim lstrIteImpPis As String
		Dim lstrIteImpCof As String
		Dim lstrIteImpIcm As String
		Dim lstrIteImpIlu As String
		Dim lstrIteImpDiv As String
		Dim ldblCfop As Double
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim lstrRota As String
		Dim lstrBancoFatur As String
		Dim lstrBanIdent As String
		Dim lstrCpfCnpj As String
		Dim lstrNumMedidor As String
		Dim ldblConstMedid As Double
		Dim lstrFase As String
		Dim lstrTa As String
		Dim lstrTensao As String
		Dim lstrCodHash As String
		Dim ldblValorTot As Double
		Dim ldblValorLiq As Double
		Dim lstrCodBarra As String
		Dim lstrDvCodBar As String
		Dim lstrCodClas As String
		Dim lintDias As Short
		'dados da tabela de classe
		Dim lstrDsClas As String
		'datas da fatura
		Dim ldteVcto As Date
		Dim ldteEmissao As Date
		Dim ldteApreset As Date
		Dim ldteProxLeit As Date
		Dim ldteLeitAtu As Date
		Dim ldteLeitAnt As Date
		'dados de leitura
		Dim ldblLeituraAnt As Double
		Dim ldblLeituraAtu As Double
		Dim ldblLeituraKvarhAnt As Double
		Dim ldblLeituraKvarhAtu As Double
		Dim ldblConsumoKvarh As Double
		Dim ldblFp As Double
		Dim lintMedOcorrencia As Short
		Dim lstrDesOcorrencia As String
		Dim ldblLeitReservadoAtu As Double
		Dim ldblLeitReservadoAnt As Double
		Dim ldblVlrConsumoReserv As Double
		'dados de consumo
		Dim ldblConsumo As Double
		Dim ldblReservado As Double
		Dim ldblConsumFat As Double
		Dim ldblVlrConFat As Double
		'Dados da unidade consumidora
		Dim lstrAgenc As String
		Dim lstrCc As String
		Dim lstrPagtoGov As String
		Dim lstrNome As String
		Dim lstrInsc As String
		Dim lstrRg As String
		Dim lstrRgOrgao As String
		Dim lstrRgUf As String
		Dim ldblSldArred As Double
		'dados do logradouro
		Dim lstrUf As String
		Dim lstrCidade As String
		Dim lstrDistrito As String
		Dim lstrBairro As String
		Dim lstrEnd As String
		Dim lstrCompl As String
		Dim lstrQuadra As String
		Dim lstrLote As String
		Dim lstrNumero As String
		Dim lstrCep As String
		Dim lintEntrega As Short
		Dim lstrUfEnt As String
		Dim lstrCidEnt As String
		Dim lstrDisEnt As String
		Dim lstrBaiEnt As String
		Dim lstrEndEnt As String
		Dim lstrComEnt As String
		Dim lstrQuaEnt As String
		Dim lstrLotEnt As String
		Dim lstrNumEnt As String
		Dim lstrCepEnt As String
		'dados de tributação
		Dim ldblVlrCofins As Double
		Dim ldblVlrPis As Double
		Dim ldblVlrIcms As Double
		Dim ldblVlrIcms1 As Double
		Dim ldblBaseIcms As Double
		Dim ldblAliqIcms As Double
		Dim ldblBaseIcms1 As Double
		Dim ldblAliqIcms1 As Double
		Dim ldblBasePis As Double
		Dim ldblAliqPis As Double
		Dim ldblBaseCofins As Double
		Dim ldblAliqCofins As Double
		Dim ldblBasIcmsTotal As Double
		Dim ldblVlrIcmsTotal As Double
		'dados de retenção
		Dim ldblRetIrpj As Double
		Dim ldblRetPis As Double
		Dim ldblRetCsll As Double
		Dim ldblRetCofins As Double
		'dados da composição da tarifa
		Dim ldblCompEnergia As Double
		Dim ldblCompTransmissao As Double
		Dim ldblCompDistribuicao As Double
		Dim ldblCompEncargosSetoriais As Double
		Dim ldblCompOutros As Double
		'dados dos indicadores
		Dim ldblDecMeta As Double
		Dim ldblDecReal As Double
		Dim ldblFecMeta As Double
		Dim ldblFecReal As Double
		Dim ldblDicMeta As Double
		Dim ldblDicReal As Double
		Dim ldblFicMeta As Double
		Dim ldblFicReal As Double
		Dim ldblDmicRea As Double
		Dim ldblDmicMet As Double
		Dim lstrRefIndi As String
		'Historico da unidade consumidora
		Dim ldblMaiorCons As Double
		Dim ldblMenorCons As Double
		Dim lstrMesMaiorC As String
		Dim lstrMesMenorC As String
		Dim ldblMed3Meses As Double
		Dim ldblValorPed As Double
		Dim lintCtrl As Short
		Dim lintQutdePed As Short
		Dim lintMed3Meses As Short
		Dim lstrMesAnoH As String
		Dim ldtePgentoH As Date
		Dim ldblVlrFatH As Double
		Dim lintDiasCoH As Short
		Dim ldblConsumH As Double
		Dim ldblLeiturH As Double
		Dim lintOcMediH As Short
		'UPGRADE_WARNING: Lower bound of array lstrHMesAno was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lstrHMesAno(12) As String
		'UPGRADE_WARNING: Lower bound of array lintHDiasCo was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lintHDiasCo(12) As Short
		'UPGRADE_WARNING: Lower bound of array lintHOMedia was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim lintHOMedia(12) As Short
		'UPGRADE_WARNING: Lower bound of array ldteHPagame was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldteHPagame(12) As Date
		'UPGRADE_WARNING: Lower bound of array ldblHConsum was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblHConsum(12) As Double
		'UPGRADE_WARNING: Lower bound of array ldblHLeitur was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblHLeitur(12) As Double
		'UPGRADE_WARNING: Lower bound of array ldblHVlrFat was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblHVlrFat(12) As Double
		
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Dim lrstUnC As ADODB.Recordset
		lrstUnC = New ADODB.Recordset
		Dim lrstCla As ADODB.Recordset
		lrstCla = New ADODB.Recordset
		Dim lrstHis As ADODB.Recordset
		lrstHis = New ADODB.Recordset
		Dim lrstNet As ADODB.Recordset
		lrstNet = New ADODB.Recordset
		Dim lblnContinua As Boolean
		
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM `nf` "
		lstrSql = lstrSql & " WHERE flgst = '' "
		lstrSql = lstrSql & "   AND grupo = 'B' "
		' If ablnRecria = False Then
		lstrSql = lstrSql & "   AND NOT EXISTS(SELECT * FROM `nss_faturasnet` "
		lstrSql = lstrSql & "                   WHERE `nss_faturasnet`.`numnf` = `nf`.`numnf` "
		lstrSql = lstrSql & "                     AND `nss_faturasnet`.`mesano` = `nf`.`mesano`  "
		lstrSql = lstrSql & "                     AND `nss_faturasnet`.`valortot` = `nf`.`valortot` )"
		' End If
		'If Strings.Len(Strings.Trim(astrFiltro)) > 0 Then
		'  lstrsql = lstrsql & "   AND " & astrFiltro
		' End If
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					Call BarraProgresso(ProgressBarFaturasnet, lblporcentagem, lblOutros, 0, .RecordCount, " faturas NET")
					While Not .EOF
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblNumNf = CDbl(IIf(IsDbNull(.Fields("numnf").value), 0, .Fields("numnf").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrMesAno = Trim(IIf(IsDbNull(.Fields("mesano").value), "00/0000", .Fields("mesano").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblValorTot = CDbl(IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblValorLiq = CDbl(IIf(IsDbNull(.Fields("valorliq").value), 0, .Fields("valorliq").value))
						
						
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrItens = IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrTa = Trim(IIf(IsDbNull(.Fields("ta").value), "01B1", .Fields("ta").value))
						'Convenios, Diversos e Taxados
						lstrIteImp = ""
						lstrIteImpCon = ""
						lstrIteImpPis = ""
						lstrIteImpCof = ""
						lstrIteImpIcm = ""
						lstrIteImpIlu = ""
						lstrIteImpDiv = ""
						For IndCodServ = 1 To Len(Trim(lstrItens))
							Call BuscaCodItem(IndCodServ, lstrItens)
							lstrIteRef = Trim(RefCodServ)
							If Len(lstrIteRef) > 0 Then
								If InStr(1, lstrIteRef, ")") > 0 Then
									lstrIteRef = VB.Left(lstrIteRef, InStr(1, lstrIteRef, ")"))
								End If
							End If
							'Consumo ou Reativo
							If IsNumeric(VlrCodServ) Then
								If CDbl(VlrCodServ) <> 0 Then
									If VB.Left(codserv, 9) = "030202009" Or VB.Left(codserv, 10) = "0302020012" Then
										lstrIteImpCon = lstrIteImpCon & IIf(Len(lstrIteImpCon) > 0, ";", "")
										lstrIteImpCon = lstrIteImpCon & codTodescri(codserv) & ";"
										lstrIteImpCon = lstrIteImpCon & lstrIteRef & ";"
										lstrIteImpCon = lstrIteImpCon & FormatNumber(BuscaVlrItem(lstrItens, codserv), 2)
									End If
									'Pis
									If VB.Left(codserv, 10) = "0302020029" Then
										lstrIteImpPis = lstrIteImpPis & IIf(Len(lstrIteImpPis) > 0, ";", "")
										lstrIteImpPis = lstrIteImpPis & codTodescri(codserv) & ";"
										lstrIteImpPis = lstrIteImpPis & lstrIteRef & ";"
										lstrIteImpPis = lstrIteImpPis & FormatNumber(BuscaVlrItem(lstrItens, codserv), 2)
									End If
									'Cofins
									If VB.Left(codserv, 10) = "0302020030" Then
										lstrIteImpCof = lstrIteImpCof & IIf(Len(lstrIteImpCof) > 0, ";", "")
										lstrIteImpCof = lstrIteImpCof & codTodescri(codserv) & ";"
										lstrIteImpCof = lstrIteImpCof & lstrIteRef & ";"
										lstrIteImpCof = lstrIteImpCof & FormatNumber(BuscaVlrItem(lstrItens, codserv), 2)
									End If
									'Icms
									If VB.Left(codserv, 10) = "0302030014" Then
										lstrIteImpIcm = lstrIteImpIcm & IIf(Len(lstrIteImpIcm) > 0, ";", "")
										lstrIteImpIcm = lstrIteImpIcm & codTodescri(codserv) & ";"
										lstrIteImpIcm = lstrIteImpIcm & lstrIteRef & ";"
										lstrIteImpIcm = lstrIteImpIcm & FormatNumber(BuscaVlrItem(lstrItens, codserv), 2)
									End If
									'Iluminação
									If VB.Left(codserv, 10) = "0301000003" Then
										lstrIteImpIlu = lstrIteImpIlu & IIf(Len(lstrIteImpIlu) > 0, ";", "")
										lstrIteImpIlu = lstrIteImpIlu & codTodescri(codserv) & ";"
										lstrIteImpIlu = lstrIteImpIlu & lstrIteRef & ";"
										lstrIteImpIlu = lstrIteImpIlu & FormatNumber(BuscaVlrItem(lstrItens, codserv), 2)
									End If
									'Diversos, taxas e convênios
									If VB.Left(codserv, 4) = "9030" Or VB.Left(codserv, 4) = "9040" Or VB.Left(codserv, 4) = "9070" Or VB.Left(codserv, 4) = "9080" Then
										lstrIteImpDiv = lstrIteImpDiv & IIf(Len(lstrIteImpDiv) > 0, ";", "")
										lstrIteImpDiv = lstrIteImpDiv & codTodescri(codserv) & ";"
										lstrIteImpDiv = lstrIteImpDiv & lstrIteRef & ";"
										lstrIteImpDiv = lstrIteImpDiv & FormatNumber(CDbl(Replace(VlrCodServ, ".", ",")), 2)
									End If
								End If
							End If
						Next IndCodServ
						If UCase(Mid(lstrTa, 3, 1)) = "B" Then
							lstrIteImp = lstrIteImp & lstrIteImpCon
							lstrIteImp = lstrIteImp & IIf(Len(lstrIteImpPis) > 0, ";", "") & lstrIteImpPis
							lstrIteImp = lstrIteImp & IIf(Len(lstrIteImpCof) > 0, ";", "") & lstrIteImpCof
							lstrIteImp = lstrIteImp & IIf(Len(lstrIteImpIcm) > 0, ";", "") & lstrIteImpIcm
							lstrIteImp = lstrIteImp & IIf(Len(lstrIteImpIlu) > 0, ";", "") & lstrIteImpIlu
							lstrIteImp = lstrIteImp & IIf(Len(lstrIteImpDiv) > 0, ";", "") & lstrIteImpDiv
							lstrIteImp = lstrIteImp & ";"
						End If
						ldblConsumo = Arredondar(BuscaVlrItem(lstrItens, "030201008"), 2)
						ldblReservado = Arredondar(BuscaVlrItem(lstrItens, "0302010044"), 2)
						ldblConsumFat = Arredondar(BuscaVlrItem(lstrItens, "030201009"), 2)
						ldblVlrConFat = Arredondar(BuscaVlrItem(lstrItens, "030202009"), 2)
						
						ldblLeituraAnt = Arredondar(BuscaVlrItem(lstrItens, "0302990040"), 2)
						ldblLeituraAtu = Arredondar(BuscaVlrItem(lstrItens, "0302990039"), 2)
						ldblLeituraKvarhAnt = Arredondar(BuscaVlrItem(lstrItens, "0302010046"), 2)
						ldblLeituraKvarhAtu = Arredondar(BuscaVlrItem(lstrItens, "0302010045"), 2)
						ldblConsumoKvarh = Arredondar(BuscaVlrItem(lstrItens, "0302010047"), 2)
						ldblFp = Arredondar(BuscaVlrItem(lstrItens, "0302030099"), 2)
						
						ldblVlrCofins = Arredondar(BuscaVlrItem(lstrItens, "0302020030"), 2)
						ldblVlrPis = Arredondar(BuscaVlrItem(lstrItens, "0302020029"), 2)
						ldblVlrIcms = Arredondar(BuscaVlrItem(lstrItens, "0302030009"), 2)
						ldblVlrIcms1 = Arredondar(BuscaVlrItem(lstrItens, "0302030010"), 2)
						ldblBaseIcms = Arredondar(BuscaVlrItem(lstrItens, "0302030001"), 2)
						ldblAliqIcms = Arredondar(BuscaVlrItem(lstrItens, "0302030002"), 2)
						ldblBaseIcms1 = Arredondar(BuscaVlrItem(lstrItens, "0302030003"), 2)
						ldblAliqIcms1 = Arredondar(BuscaVlrItem(lstrItens, "0302030013"), 2)
						ldblBasePis = Arredondar(BuscaVlrItem(lstrItens, "0302020033"), 2)
						ldblAliqPis = Arredondar(BuscaVlrItem(lstrItens, "0302990303"), 2)
						ldblBaseCofins = Arredondar(BuscaVlrItem(lstrItens, "0302020034"), 2)
						ldblAliqCofins = Arredondar(BuscaVlrItem(lstrItens, "0302990304"), 2)
						ldblBasIcmsTotal = Arredondar(BuscaVlrItem(lstrItens, "0302030015"), 2)
						ldblVlrIcmsTotal = Arredondar(BuscaVlrItem(lstrItens, "0302030014"), 2)
						
						lintMedOcorrencia = BuscaVlrItem(lstrItens, "90410000")
						lstrDesOcorrencia = BuscaRefItem(lstrItens, "90410000")
						ldblLeitReservadoAtu = Arredondar(BuscaVlrItem(lstrItens, "0302040019"), 2)
						ldblLeitReservadoAnt = Arredondar(BuscaVlrItem(lstrItens, "0302040020"), 2)
						ldblVlrConsumoReserv = Arredondar(BuscaVlrItem(lstrItens, "0302990044"), 2)
						
						ldblRetIrpj = Arredondar(BuscaVlrItem(lstrItens, "9090000004"), 2)
						ldblRetPis = Arredondar(BuscaVlrItem(lstrItens, "9090000001"), 2)
						ldblRetCsll = Arredondar(BuscaVlrItem(lstrItens, "9090000003"), 2)
						ldblRetCofins = Arredondar(BuscaVlrItem(lstrItens, "9090000002"), 2)
						
						ldblCompEnergia = Arredondar(BuscaVlrItem(lstrItens, "0302090001"), 2)
						ldblCompTransmissao = Arredondar(BuscaVlrItem(lstrItens, "0302090002"), 2)
						ldblCompDistribuicao = Arredondar(BuscaVlrItem(lstrItens, "0302090003"), 2)
						ldblCompEncargosSetoriais = Arredondar(BuscaVlrItem(lstrItens, "0302090004"), 2)
						ldblCompOutros = Arredondar(BuscaVlrItem(lstrItens, "0302090005"), 2)
						
						
						ldblDecMeta = Arredondar(BuscaVlrItem(lstrItens, "0302080101"), 2)
						ldblDecReal = Arredondar(BuscaVlrItem(lstrItens, "0302080001"), 2)
						ldblFecMeta = Arredondar(BuscaVlrItem(lstrItens, "0302080102"), 2)
						ldblFecReal = Arredondar(BuscaVlrItem(lstrItens, "0302080002"), 2)
						ldblDicMeta = Arredondar(BuscaVlrItem(lstrItens, "0302080103"), 2)
						ldblDicReal = Arredondar(BuscaVlrItem(lstrItens, "0302080003"), 2)
						ldblFicMeta = Arredondar(BuscaVlrItem(lstrItens, "0302080104"), 2)
						ldblFicReal = Arredondar(BuscaVlrItem(lstrItens, "0302080004"), 2)
						ldblDmicRea = Arredondar(BuscaVlrItem(lstrItens, "0302080105"), 2)
						ldblDmicMet = Arredondar(BuscaVlrItem(lstrItens, "0302080005"), 2)
						lstrRefIndi = BuscaRefItem(lstrItens, "0302080099")
						
						
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblCfop = CDbl(IIf(IsDbNull(.Fields("cfop").value), 0, .Fields("cfop").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrZona = VB6.Format(Trim(IIf(IsDbNull(.Fields("zona").value), "0", .Fields("zona").value)), "000")
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrLivro = VB6.Format(Trim(IIf(IsDbNull(.Fields("livro").value), "0", .Fields("livro").value)), "00")
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrConta = VB6.Format(Trim(IIf(IsDbNull(.Fields("conta").value), "0", .Fields("conta").value)), "000000")
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrRota = VB6.Format(Trim(IIf(IsDbNull(.Fields("rota").value), "0", .Fields("rota").value)), "00000000")
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrCodClas = Trim(IIf(IsDbNull(.Fields("codclas").value), "0", .Fields("codclas").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lintDias = CShort(IIf(IsDbNull(.Fields("dias").value), 0, .Fields("dias").value))
						
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldteVcto = CDate(Trim(IIf(IsDbNull(.Fields("datavenc").value), "1900-01-01", .Fields("datavenc").value)))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldteEmissao = CDate(Trim(IIf(IsDbNull(.Fields("dataem").value), "1900-01-01", .Fields("dataem").value)))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldteApreset = CDate(Trim(IIf(IsDbNull(.Fields("dataapr").value), "1900-01-01", .Fields("dataapr").value)))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldteProxLeit = CDate(Trim(IIf(IsDbNull(.Fields("dataproxleit").value), "1900-01-01", .Fields("dataproxleit").value)))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldteLeitAtu = CDate(Trim(IIf(IsDbNull(.Fields("dataleit").value), "1900-01-01", .Fields("dataleit").value)))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldteLeitAnt = CDate(Trim(IIf(IsDbNull(.Fields("dataleitant").value), "1900-01-01", .Fields("dataleitant").value)))
						
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrBancoFatur = Trim(IIf(IsDbNull(.Fields("banco_fatur").value), "0", .Fields("banco_fatur").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrBanIdent = Trim(IIf(IsDbNull(.Fields("banident").value), "0", .Fields("banident").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrCpfCnpj = Trim(IIf(IsDbNull(.Fields("cpf_cnpj").value), "", .Fields("cpf_cnpj").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrNumMedidor = Trim(IIf(IsDbNull(.Fields("num_med").value), "", .Fields("num_med").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblConstMedid = CDbl(IIf(IsDbNull(.Fields("const_med").value), 0, .Fields("const_med").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrFase = Trim(IIf(IsDbNull(.Fields("fase").value), "M", .Fields("fase").value))
						
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrTensao = Trim(IIf(IsDbNull(.Fields("tensao").value), "220", .Fields("tensao").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrCodHash = Trim(IIf(IsDbNull(.Fields("codhash").value), "", .Fields("codhash").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrCodBarra = Trim(IIf(IsDbNull(.Fields("codbarra").value), "", .Fields("codbarra").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrDvCodBar = Trim(IIf(IsDbNull(.Fields("dvcodbarra").value), "", .Fields("dvcodbarra").value))
						
						If lstrCodBarra = "" Then
							Call MontaCodBarras(ldblNumNf, lstrMesAno, ldblValorLiq, lstrZona, lstrLivro, lstrConta, lstrCodBarra, lstrDvCodBar)
						End If
						
						
						lstrSql = ""
						If Mid(lstrTa, 3, 1) = "A" Then
							lstrSql = lstrSql & "SELECT `agenc`, `cc`, `pagto_governo`, `nome`, `insc`, `rg`, `rg_orgao`, `rg_uf`, `arredonda` AS `arredonda_temp`, "
							lstrSql = lstrSql & "       `uf`, `cidade`, `distrito`, `bairro`, `end`, `complement`, `quadra`, `lote`, `numero`, `cep`, `entrega`, "
							lstrSql = lstrSql & "       `uf_entrega`, `cid_entrega`, `dis_entrega`, `bai_entrega`, `end_entrega`, `compl_entrega`, `qua_entrega`, `lot_entrega`, `num_entrega`, `cep_entrega` "
							lstrSql = lstrSql & "  FROM `unida`"
							lstrSql = lstrSql & " WHERE `unida`.`zona`  = '" & lstrZona & "' "
							lstrSql = lstrSql & "   AND `unida`.`livro` = '" & lstrLivro & "' "
							lstrSql = lstrSql & "   AND `unida`.`conta` = '" & lstrConta & "' "
							lstrSql = lstrSql & " LIMIT 0, 1 "
						Else
							lstrSql = lstrSql & "SELECT `agenc`, `cc`, `pagto_governo`, `nome`, `insc`, `rg`, `rg_orgao`, `rg_uf`, `arredonda_temp`, "
							lstrSql = lstrSql & "       `uf`, `cidade`, `distrito`, `bairro`, `end`, `complement`, `quadra`, `lote`, `numero`, `cep`, `entrega`, "
							lstrSql = lstrSql & "       `uf_entrega`, `cid_entrega`, `dis_entrega`, `bai_entrega`, `end_entrega`, `compl_entrega`, `qua_entrega`, `lot_entrega`, `num_entrega`, `cep_entrega` "
							lstrSql = lstrSql & "  FROM `unidb`"
							lstrSql = lstrSql & " WHERE `unidb`.`zona`  = '" & lstrZona & "' "
							lstrSql = lstrSql & "   AND `unidb`.`livro` = '" & lstrLivro & "' "
							lstrSql = lstrSql & "   AND `unidb`.`conta` = '" & lstrConta & "' "
							lstrSql = lstrSql & " LIMIT 0, 1 "
						End If
						
						Call Conectar(lstrSql, lrstUnC)
						With lrstUnC
							If .State = ADODB.ObjectStateEnum.adStateOpen Then
								If .RecordCount > 0 Then
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrAgenc = Trim(IIf(IsDbNull(.Fields("agenc").value), "", .Fields("agenc").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrCc = Trim(IIf(IsDbNull(.Fields("cc").value), "", .Fields("cc").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrPagtoGov = Trim(IIf(IsDbNull(.Fields("pagto_governo").value), "N", .Fields("pagto_governo").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrNome = Trim(IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrInsc = Trim(IIf(IsDbNull(.Fields("insc").value), "", .Fields("insc").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrRg = Trim(IIf(IsDbNull(.Fields("rg").value), "", .Fields("rg").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrRgOrgao = Trim(IIf(IsDbNull(.Fields("rg_orgao").value), "", .Fields("rg_orgao").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrRgUf = Trim(IIf(IsDbNull(.Fields("rg_uf").value), "", .Fields("rg_uf").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									ldblSldArred = CDbl(IIf(IsDbNull(.Fields("arredonda_temp").value), 0, .Fields("arredonda_temp").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrUf = Trim(IIf(IsDbNull(.Fields("uf").value), "", .Fields("uf").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrCidade = Trim(IIf(IsDbNull(.Fields("cidade").value), "", .Fields("cidade").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrDistrito = Trim(IIf(IsDbNull(.Fields("distrito").value), "", .Fields("distrito").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrBairro = Trim(IIf(IsDbNull(.Fields("bairro").value), "", .Fields("bairro").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrEnd = Trim(IIf(IsDbNull(.Fields("end").value), "", .Fields("end").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrCompl = Trim(IIf(IsDbNull(.Fields("complement").value), "", .Fields("complement").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrQuadra = Trim(IIf(IsDbNull(.Fields("quadra").value), "", .Fields("quadra").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrLote = Trim(IIf(IsDbNull(.Fields("lote").value), "", .Fields("lote").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrNumero = Trim(IIf(IsDbNull(.Fields("numero").value), "", .Fields("numero").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrCep = Trim(IIf(IsDbNull(.Fields("cep").value), "", .Fields("cep").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lintEntrega = CShort(IIf(IsDbNull(.Fields("entrega").value), 0, .Fields("entrega").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrUfEnt = Trim(IIf(IsDbNull(.Fields("uf_entrega").value), "", .Fields("uf_entrega").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrCidEnt = Trim(IIf(IsDbNull(.Fields("cid_entrega").value), "", .Fields("cid_entrega").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrDisEnt = Trim(IIf(IsDbNull(.Fields("dis_entrega").value), "", .Fields("dis_entrega").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrBaiEnt = Trim(IIf(IsDbNull(.Fields("bai_entrega").value), "", .Fields("bai_entrega").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrEndEnt = Trim(IIf(IsDbNull(.Fields("end_entrega").value), "", .Fields("end_entrega").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrComEnt = Trim(IIf(IsDbNull(.Fields("compl_entrega").value), "", .Fields("compl_entrega").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrQuaEnt = Trim(IIf(IsDbNull(.Fields("qua_entrega").value), "", .Fields("qua_entrega").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrLotEnt = Trim(IIf(IsDbNull(.Fields("lot_entrega").value), "", .Fields("lot_entrega").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrNumEnt = Trim(IIf(IsDbNull(.Fields("num_entrega").value), "", .Fields("num_entrega").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrCepEnt = Trim(IIf(IsDbNull(.Fields("cep_entrega").value), "", .Fields("cep_entrega").value))
								End If
								Call .Close()
							End If
						End With
						lstrSql = ""
						lstrSql = lstrSql & "SELECT `descricao` "
						lstrSql = lstrSql & "  FROM `classe` "
						lstrSql = lstrSql & " WHERE `codigo` = '" & lstrCodClas & "' "
						lstrSql = lstrSql & " LIMIT 0, 1"
						Call Conectar(lstrSql, lrstCla)
						With lrstCla
							If .State = ADODB.ObjectStateEnum.adStateOpen Then
								If .RecordCount > 0 Then
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrDsClas = Trim(IIf(IsDbNull(.Fields("descricao").value), "", .Fields("descricao").value))
								End If
								Call .Close()
							End If
						End With
						ldblMaiorCons = 0
						ldblMenorCons = 99999999
						ldblValorPed = 0
						lintQutdePed = 0
						ldblMed3Meses = 0
						lintMed3Meses = 0
						For lintCtrl = 1 To 12
							lstrHMesAno(lintCtrl) = "00/0000"
							lintHDiasCo(lintCtrl) = 0
							lintHOMedia(lintCtrl) = 0
							ldteHPagame(lintCtrl) = CDate("01/01/1900")
							ldblHConsum(lintCtrl) = 0
							ldblHLeitur(lintCtrl) = 0
							ldblHVlrFat(lintCtrl) = 0
						Next lintCtrl
						lintCtrl = 1
						lstrSql = ""
						lstrSql = lstrSql & "  SELECT nf.mesano, "
						lstrSql = lstrSql & "         IF(nf.valorliq<>0,nf.valorliq,nf.valortot) AS valorfat, "
						lstrSql = lstrSql & "         nf.datapag, "
						lstrSql = lstrSql & "         (nf.dias)+0 as dias, "
						lstrSql = lstrSql & "         nf.itensserv"
						lstrSql = lstrSql & "    FROM nf "
						lstrSql = lstrSql & "   WHERE nf.flgst <> 'C'"
						lstrSql = lstrSql & "     AND nf.zona  = '" & lstrZona & "' "
						lstrSql = lstrSql & "     AND nf.livro = '" & lstrLivro & "' "
						lstrSql = lstrSql & "     AND nf.conta = '" & lstrConta & "' "
						lstrSql = lstrSql & "     AND nf.mesano_ref <> '" & CInt(VB.Right(lstrMesAno, 4) & VB.Left(lstrMesAno, 2)) & "' "
						lstrSql = lstrSql & "     AND mesano_ref <= " & CInt(VB.Right(lstrMesAno, 4) & VB.Left(lstrMesAno, 2)) & " "
						lstrSql = lstrSql & "ORDER BY mesano_ref DESC "
						lstrSql = lstrSql & "   LIMIT 0, 12"
						Call Conectar(lstrSql, lrstHis)
						With lrstHis
							If .State = ADODB.ObjectStateEnum.adStateOpen Then
								If .RecordCount > 0 Then
									While Not .EOF
										'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
										lstrMesAnoH = Trim(IIf(IsDbNull(.Fields("mesano").value), "00/0000", .Fields("mesano").value))
										'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
										ldblVlrFatH = CDbl(IIf(IsDbNull(.Fields("valorfat").value), 0, .Fields("valorfat").value))
										'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
										ldtePgentoH = CDate(IIf(IsDbNull(.Fields("datapag").value Or .Fields("datapag").Value = "0000-00-00"), "1900-01-01", .Fields("datapag").value))
										'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
										lintDiasCoH = CShort(IIf(IsDbNull(.Fields("dias").value), 0, .Fields("dias").value))
										'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
										lstrItens = Trim(IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").value))
										If Len(Trim(lstrItens)) > 0 Then
											ldblConsumH = BuscaVlrItem(lstrItens, "030201008") + BuscaVlrItem(lstrItens, "0302010044")
											ldblLeiturH = BuscaVlrItem(lstrItens, "0302990039")
											lintOcMediH = BuscaVlrItem(lstrItens, "90410000")
											If ldblConsumH > ldblMaiorCons Then
												ldblMaiorCons = ldblConsumH
												lstrMesMaiorC = lstrMesAnoH
											End If
											If ldblConsumH < ldblMenorCons Then
												ldblMenorCons = ldblConsumH
												lstrMesMenorC = lstrMesAnoH
											End If
										Else
											ldblConsumH = 0
											ldblLeiturH = 0
											lintOcMediH = 0
										End If
										If ldtePgentoH = CDate("01/01/1900") Then
											ldblValorPed = ldblValorPed + ldblVlrFatH
											lintQutdePed = lintQutdePed + 1
										End If
										If lintCtrl <= 2 Then
											ldblMed3Meses = ldblMed3Meses + ldblConsumH
											lintMed3Meses = lintMed3Meses + 1
										End If
										lstrHMesAno(lintCtrl) = lstrMesAnoH
										lintHDiasCo(lintCtrl) = lintDiasCoH
										lintHOMedia(lintCtrl) = lintOcMediH
										ldteHPagame(lintCtrl) = ldtePgentoH
										ldblHConsum(lintCtrl) = ldblConsumH
										ldblHLeitur(lintCtrl) = ldblLeiturH
										ldblHVlrFat(lintCtrl) = ldblVlrFatH
										Call .MoveNext()
										lintCtrl = lintCtrl + 1
									End While
								End If
								Call .Close()
							End If
						End With
						If (ldblConsumo + ldblReservado) > ldblMaiorCons Then
							ldblMaiorCons = (ldblConsumo + ldblReservado)
						End If
						If (ldblConsumo + ldblReservado) < ldblMenorCons Then
							ldblMenorCons = (ldblConsumo + ldblReservado)
						End If
						ldblMed3Meses = ldblMed3Meses + (ldblConsumo + ldblReservado)
						lintMed3Meses = lintMed3Meses + 1
						If IsNumeric(lstrCpfCnpj) Then
							If Valida_CPF_CGC(lstrCpfCnpj) Then
								Call Executar("DELETE FROM faturasnet WHERE numnf = " & ldblNumNf & " AND mesano = '" & lstrMesAno & "' ")
								
								lstrSql = ""
								lstrSql = lstrSql & "INSERT INTO nss_faturasnet SET " & vbCrLf
								lstrSql = lstrSql & "            numnf          = " & ldblNumNf & ", " & vbCrLf
								lstrSql = lstrSql & "            mesano         = '" & lstrMesAno & "', " & vbCrLf
								lstrSql = lstrSql & "            cfop           = " & Replace(CStr(ldblCfop), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            zona           = '" & lstrZona & "', " & vbCrLf
								lstrSql = lstrSql & "            livro          = '" & lstrLivro & "', " & vbCrLf
								lstrSql = lstrSql & "            conta          = '" & lstrConta & "', " & vbCrLf
								lstrSql = lstrSql & "            rota           = '" & lstrRota & "', " & vbCrLf
								lstrSql = lstrSql & "            codclas        = '" & lstrCodClas & "', " & vbCrLf
								lstrSql = lstrSql & "            datavenc       = '" & VB6.Format(IIf(ldteVcto = CDate("01/01/1900"), "0000-00-00", ldteVcto), "yyyy-MM-dd") & "', " & vbCrLf
								lstrSql = lstrSql & "            dataemissao    = '" & VB6.Format(IIf(ldteEmissao = CDate("01/01/1900"), "0000-00-00", ldteEmissao), "yyyy-MM-dd") & "', " & vbCrLf
								lstrSql = lstrSql & "            dataapr        = '" & VB6.Format(IIf(ldteApreset = CDate("01/01/1900"), "0000-00-00", ldteApreset), "yyyy-MM-dd") & "', " & vbCrLf
								lstrSql = lstrSql & "            dataproxleit   = '" & VB6.Format(IIf(ldteProxLeit = CDate("01/01/1900"), "0000-00-00", ldteProxLeit), "yyyy-MM-dd") & "', " & vbCrLf
								lstrSql = lstrSql & "            dataleit       = '" & VB6.Format(IIf(ldteLeitAtu = CDate("01/01/1900"), "0000-00-00", ldteLeitAtu), "yyyy-MM-dd") & "', " & vbCrLf
								lstrSql = lstrSql & "            dataleitant    = '" & VB6.Format(IIf(ldteLeitAnt = CDate("01/01/1900"), "0000-00-00", ldteLeitAnt), "yyyy-MM-dd") & "', " & vbCrLf
								lstrSql = lstrSql & "            banco_fatur    = '" & lstrBancoFatur & "', " & vbCrLf
								lstrSql = lstrSql & "            banident       = """ & lstrBanIdent & """, " & vbCrLf
								lstrSql = lstrSql & "            cpf_cnpj       = '" & lstrCpfCnpj & "', " & vbCrLf
								lstrSql = lstrSql & "            num_med        = '" & lstrNumMedidor & "', " & vbCrLf
								lstrSql = lstrSql & "            const_med      = " & Replace(CStr(ldblConstMedid), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            fase           = '" & lstrFase & "', " & vbCrLf
								lstrSql = lstrSql & "            ta             = '" & lstrTa & "', " & vbCrLf
								lstrSql = lstrSql & "            tensao         = '" & lstrTensao & "', " & vbCrLf
								lstrSql = lstrSql & "            codhash        = '" & lstrCodHash & "', " & vbCrLf
								lstrSql = lstrSql & "            valortot       = " & Replace(CStr(ldblValorTot), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            valorliq       = " & Replace(CStr(ldblValorLiq), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            codbarra       = '" & lstrCodBarra & "', " & vbCrLf
								lstrSql = lstrSql & "            dvcodbarra     = '" & lstrDvCodBar & "', " & vbCrLf
								
								lstrSql = lstrSql & "            diasconsumo        = " & lintDias & ", " & vbCrLf
								lstrSql = lstrSql & "            vlrdiario          = " & Replace(CStr(Arredondar(ldblVlrConFat / IIf(lintDias = 0, 1, lintDias), 2)), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            mediaconsumodiario = " & Replace(CStr(Arredondar(ldblConsumFat / IIf(lintDias = 0, 1, lintDias), 2)), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            maiorconsumo       = " & Replace(CStr(ldblMaiorCons), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            menorconsumo       = " & Replace(CStr(ldblMenorCons), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            mesmaiorconsumo    = '" & lstrMesMaiorC & "', " & vbCrLf
								lstrSql = lstrSql & "            mesmenorconsumo    = '" & lstrMesMenorC & "', " & vbCrLf
								lstrSql = lstrSql & "            valorpend          = " & Replace(CStr(ldblValorPed), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            totalpend          = " & lintQutdePed & ", " & vbCrLf
								lstrSql = lstrSql & "            mediaconsumo3meses = " & Replace(CStr(Arredondar(ldblMed3Meses / lintMed3Meses, 2)), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            ocorrencia         = " & lintMedOcorrencia & ", " & vbCrLf
								lstrSql = lstrSql & "            descocorrencia     = '" & lstrDesOcorrencia & "', " & vbCrLf
								
								lstrSql = lstrSql & "            consfaturado        = " & Replace(CStr(ldblConsumFat), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            conslido            = " & Replace(CStr(ldblConsumo), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            valorconsumo        = " & Replace(CStr(ldblVlrConFat), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            consumoreservado    = " & Replace(CStr(ldblReservado), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            LeitReservadoAtu    = " & Replace(CStr(ldblLeitReservadoAtu), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            LeitReservadoAnt    = " & Replace(CStr(ldblLeitReservadoAnt), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            vlrconsumoreservado = " & Replace(CStr(ldblVlrConsumoReserv), ",", ".") & ", " & vbCrLf
								
								lstrSql = lstrSql & "            baseicms      = " & Replace(CStr(ldblBaseIcms), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            aliqicms      = " & Replace(CStr(ldblAliqIcms), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            vlricms       = " & Replace(CStr(ldblVlrIcms), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            baseicms1     = " & Replace(CStr(ldblBaseIcms1), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            aliqicms1     = " & Replace(CStr(ldblAliqIcms1), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            vlricms1      = " & Replace(CStr(ldblVlrIcms1), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            basepis       = " & Replace(CStr(ldblBasePis), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            aliqpis       = " & Replace(CStr(ldblAliqPis), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            vlrpis        = " & Replace(CStr(ldblVlrPis), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            basecofins    = " & Replace(CStr(ldblBaseCofins), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            aliqcofins    = " & Replace(CStr(ldblAliqCofins), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            vlrcofins     = " & Replace(CStr(ldblVlrCofins), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            vlrconsutrib  = " & Replace(CStr(ldblVlrIcms + ldblVlrIcms1 + ldblVlrPis + ldblVlrCofins + ldblVlrConFat), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            baseicmstotal = " & Replace(CStr(ldblBasIcmsTotal), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            vlricmstotal  = " & Replace(CStr(ldblVlrIcmsTotal), ",", ".") & ", " & vbCrLf
								'indicadodres de continuidade
								lstrSql = lstrSql & "            dec_meta     = " & Replace(CStr(ldblDecMeta), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            dec_rea      = " & Replace(CStr(ldblDecReal), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            fec_meta     = " & Replace(CStr(ldblFecMeta), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            fec_rea      = " & Replace(CStr(ldblFecReal), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            dic_meta     = " & Replace(CStr(ldblDicMeta), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            dic_rea      = " & Replace(CStr(ldblDicReal), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            fic_meta     = " & Replace(CStr(ldblFicMeta), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            fic_rea      = " & Replace(CStr(ldblFicReal), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            dmic         = " & Replace(CStr(ldblDmicMet), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            dmicM        = " & Replace(CStr(ldblDmicRea), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            refindicador = '" & lstrRefIndi & "', " & vbCrLf
								lstrSql = lstrSql & "            conjunto     = 'eflul'," & vbCrLf
								'rentenção
								lstrSql = lstrSql & "            ret_irpj   = " & Replace(CStr(ldblRetIrpj), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            ret_pis    = " & Replace(CStr(ldblRetPis), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            ret_csll   = " & Replace(CStr(ldblRetCsll), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            ret_cofins = " & Replace(CStr(ldblRetCofins), ",", ".") & ", " & vbCrLf
								'componentes da tarifa e da fatura
								lstrSql = lstrSql & "            comp_energia            = " & Replace(CStr(ldblCompEnergia), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            comp_transmissao        = " & Replace(CStr(ldblCompTransmissao), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            comp_distribuicao       = " & Replace(CStr(ldblCompDistribuicao), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            comp_encargos_setoriais = " & Replace(CStr(ldblCompEncargosSetoriais), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            comp_outros             = " & Replace(CStr(ldblCompOutros), ",", ".") & ", " & vbCrLf
								
								lstrSql = lstrSql & "            leituraant             = " & Replace(CStr(ldblLeituraAnt), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            leit                   = " & Replace(CStr(ldblLeituraAtu), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            leitura_kvarh_anterior = " & Replace(CStr(ldblLeituraKvarhAnt), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            leitura_kvarh_atual    = " & Replace(CStr(ldblLeituraKvarhAtu), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            consumo_kvarh          = " & Replace(CStr(ldblConsumoKvarh), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            fp                     = " & Replace(CStr(ldblFp), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            agenc = '" & lstrAgenc & "', " & vbCrLf
								lstrSql = lstrSql & "            cc    = '" & lstrCc & "' , " & vbCrLf
								lstrSql = lstrSql & "            pagto_governo = '" & lstrPagtoGov & "', " & vbCrLf
								lstrSql = lstrSql & "            NomeCons    = """ & lstrNome & """, " & vbCrLf
								lstrSql = lstrSql & "            RefCons     = """ & lstrNome & """, " & vbCrLf
								lstrSql = lstrSql & "            insc        = '" & lstrInsc & "', " & vbCrLf
								lstrSql = lstrSql & "            rg          = '" & lstrRg & " " & lstrRgOrgao & " " & lstrRgUf & "', " & vbCrLf
								lstrSql = lstrSql & "            saldo_arred = " & Replace(CStr(ldblSldArred), ",", ".") & ", " & vbCrLf
								lstrSql = lstrSql & "            uf          = '" & lstrUf & "', " & vbCrLf
								lstrSql = lstrSql & "            cidade      = """ & lstrCidade & """, " & vbCrLf
								lstrSql = lstrSql & "            distrito    = """ & lstrDistrito & """, " & vbCrLf
								lstrSql = lstrSql & "            Bairro      = """ & lstrBairro & """, " & vbCrLf
								lstrSql = lstrSql & "            logradouro  = """ & lstrEnd & """, " & vbCrLf
								lstrSql = lstrSql & "            complemento = """ & lstrCompl & IIf(Len(lstrQuadra) > 0, " Q- " & lstrQuadra, "") & IIf(Len(lstrLote) > 0, " L- " & lstrLote, "") & IIf(Len(lstrNumero) > 0, " Nº " & lstrNumero, "") & """, " & vbCrLf
								lstrSql = lstrSql & "            cep         = '" & lstrCep & "', " & vbCrLf
								lstrSql = lstrSql & "            entrega     = " & lintEntrega & ", " & vbCrLf
								lstrSql = lstrSql & "            uf_entrega  = '" & lstrUfEnt & "', " & vbCrLf
								lstrSql = lstrSql & "            cid_entrega = """ & lstrCidEnt & """, " & vbCrLf
								lstrSql = lstrSql & "            dis_entrega = """ & lstrDisEnt & """, " & vbCrLf
								lstrSql = lstrSql & "            bai_entrega = """ & lstrBaiEnt & """, " & vbCrLf
								lstrSql = lstrSql & "            log_entrega = """ & lstrEndEnt & """, " & vbCrLf
								lstrSql = lstrSql & "            com_entrega = """ & lstrComEnt & IIf(Len(lstrQuaEnt) > 0, " Q- " & lstrQuaEnt, "") & IIf(Len(lstrLotEnt) > 0, " L- " & lstrLotEnt, "") & IIf(Len(lstrNumEnt) > 0, " Nº " & lstrNumEnt, "") & """, " & vbCrLf
								lstrSql = lstrSql & "            cep_entrega = '" & lstrCepEnt & "', " & vbCrLf
								lstrSql = lstrSql & "            itens_fatura = '" & lstrIteImp & "', " & vbCrLf
								For lintCtrl = 1 To 12
									lstrSql = lstrSql & "            hist_mes_ano" & VB6.Format(lintCtrl, "00") & " = '" & lstrHMesAno(lintCtrl) & "', " & vbCrLf
									lstrSql = lstrSql & "            hist_diascon" & VB6.Format(lintCtrl, "00") & " = " & lintHDiasCo(lintCtrl) & ", " & vbCrLf
									lstrSql = lstrSql & "            hist_datpgto" & VB6.Format(lintCtrl, "00") & " = '" & VB6.Format(IIf(ldteHPagame(lintCtrl) = CDate("01/01/1900"), "0000-00-00", ldteHPagame(lintCtrl)), "yyyy-MM-dd") & "', " & vbCrLf
									lstrSql = lstrSql & "            hist_consumo" & VB6.Format(lintCtrl, "00") & " = " & Replace(CStr(ldblHConsum(lintCtrl)), ",", ".") & ", " & vbCrLf
									lstrSql = lstrSql & "            hist_leitura" & VB6.Format(lintCtrl, "00") & " = " & Replace(CStr(ldblHLeitur(lintCtrl)), ",", ".") & ", " & vbCrLf
									lstrSql = lstrSql & "            hist_vlrfatu" & VB6.Format(lintCtrl, "00") & " = " & Replace(CStr(ldblHVlrFat(lintCtrl)), ",", ".") & ", " & vbCrLf
									lstrSql = lstrSql & "            hist_ocorren" & VB6.Format(lintCtrl, "00") & " = " & lintHOMedia(lintCtrl) & ", " & vbCrLf
								Next lintCtrl
								lstrSql = lstrSql & "            descclasse  = """ & lstrDsClas & """ "
								Call Executar(lstrSql)
								'Call FaturasNetUnidades(lstrZona, lstrLivro, lstrConta, lstrCpfCnpj, UCase(Mid(lstrTa, 3, 1)), lstrNome)
							End If
						End If
						
						Call .MoveNext()
						Call BarraProgresso(ProgressBarFaturasnet, lblporcentagem, lblOutros, 1,  , " faturas NET")
						System.Windows.Forms.Application.DoEvents()
					End While
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
		'UPGRADE_NOTE: Object lrstUnC may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstUnC = Nothing
		'UPGRADE_NOTE: Object lrstCla may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstCla = Nothing
		'UPGRADE_NOTE: Object lrstHis may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstHis = Nothing
		'UPGRADE_NOTE: Object lrstNet may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstNet = Nothing
	End Sub
	
	
	Private Sub cmdArquivo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdArquivo.Click
		Dim lstrMesAno As String
		'UPGRADE_WARNING: CommonDialog variable was not upgraded Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="671167DC-EA81-475D-B690-7A40C7BF4A23"'
		With Me.dialArq
			.DefaultExt = "CSV"
			'UPGRADE_WARNING: Filter has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
			.Filter = "*." & .DefaultExt
			.FileName = "E:\Discos\vb\OpenGl\shape\Eflul\SIRG_R_EFLUL_2016_08_15_VS_01\CSV\GrupoB.csv"
			.Title = "Importar arquivos CSV"
			Call .ShowDialog()
			Me.txtArq1.Text = .FileName
		End With
		
	End Sub
	
	Private Sub cmdArrumaItens_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdArrumaItens.Click
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		Dim lintQtd As Short
		Dim lintCta As Short
		Dim ldblNNf As Double
		Dim lstrCodigo As String
		Dim ldblValor As Double
		Dim lstrValor As String
		Dim lstrNwVlr As String
		Dim lintTamOr As Short
		Dim lintTamNw As Short
		Dim lstrMesAno As String
		Dim lstrGrupo As String
		
		Dim lintTeste As Short
		
		lrstAux = New ADODB.Recordset
		For lintTeste = 1 To 1
			lintCta = 1
			lintQtd = 16
			lstrMesAno = "03/2010"
			lstrGrupo = "B"
			'lstrCodigo = "0302030001" 'Base do Icms
			'lstrCodigo = "0302030009" 'Valor do Icms
			lstrCodigo = "0302030003" 'Base do Icms
			'lstrCodigo = "0302030010" 'Valor do Icms
			
			Me.lblItensIn.Text = ""
			Me.lblItensOut.Text = ""
			System.Windows.Forms.Application.DoEvents()
			
			lstrSql = ""
			lstrSql = lstrSql & "SELECT * FROM `nf`"
			lstrSql = lstrSql & " WHERE `nf`.`mesano` = '" & lstrMesAno & "'"
			lstrSql = lstrSql & "   AND LEFT(`nf`.`codclas`,1) = 5 "
			lstrSql = lstrSql & "   AND MID(`nf`.`ta`,3,1) = '" & lstrGrupo & "' "
			lstrSql = lstrSql & "   AND INSTR(`nf`.`itensserv`,'" & lstrCodigo & "?') > 0 "
			lstrSql = lstrSql & "   AND INSTR(`nf`.`itensserv`,'" & lstrCodigo & "?0.00')=0 "
			'lstrSql = lstrSql & "   AND `nf`.`flgst` = '' "
			'lstrSql = lstrSql & "   AND `nf`.`flgst` <> '' "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State > 0 Then
					If .RecordCount > 0 Then
						While Not .EOF And lintCta <= lintQtd
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							ldblNNf = IIf(IsDbNull(.Fields("numnf").value), 0, .Fields("numnf").value)
							lblItensInfo.Text = lintTeste & " - [" & lintCta & " de " & lintQtd & "] - " & ldblNNf & " " & lstrMesAno
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							Me.lblItensIn.Text = IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").value)
							ldblValor = BuscaVlrItem(Me.lblItensIn.Text, lstrCodigo)
							lstrValor = Replace(Replace(VB6.Format(ldblValor, "#,##0.00"), ".", ""), ",", ".")
							lintTamOr = Len(lstrValor)
							ldblValor = ldblValor - 0.01
							'ldblValor = ldblValor + 0.01
							lstrNwVlr = Replace(Replace(VB6.Format(ldblValor, "#,##0.00"), ".", ""), ",", ".")
							lintTamNw = Len(lstrNwVlr)
							Me.lblItensOut.Text = Replace(Me.lblItensIn.Text, lstrCodigo & "?" & lstrValor, lstrCodigo & "?" & lstrNwVlr)
							
							Call .MoveNext()
							lintCta = lintCta + 1
							lstrSql = ""
							lstrSql = lstrSql & "UPDATE `nf` SET `nf`.`itensserv` = '" & Me.lblItensOut.Text & "' "
							lstrSql = lstrSql & " WHERE `nf`.`mesano` = '" & lstrMesAno & "'"
							lstrSql = lstrSql & "   AND `nf`.`numnf` = " & ldblNNf
							Call myConC.BeginTrans()
							Call Executar(lstrSql)
							Call myConC.CommitTrans()
							System.Windows.Forms.Application.DoEvents()
						End While
					End If
				End If
				Call .Close()
			End With
		Next lintTeste
		
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
		
		Call MsgBox("Pronto")
	End Sub
	
	Private Sub cmdArrumaItens2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdArrumaItens2.Click
		Dim lstrAuxOld As String
		Dim lstrAuxNew As String
		Dim lstrClasse As String
		Dim lstrGruTar As String
		Dim lstrMesAno As String
		Dim ldblNumeNf As Double
		Dim ldblVlrkWh As Double
		Dim ldblVlrkVa As Double
		Dim ldblVlrIc1 As Double
		Dim ldblVlrIc2 As Double
		Dim ldblVlrPis As Double
		Dim ldblVlrCof As Double
		Dim ldblTotBas As Double
		Dim ldblBasIc1 As Double
		Dim ldblBasIc2 As Double
		Dim ldblBasPis As Double
		Dim ldblBasCof As Double
		Dim ldblBNwIc1 As Double
		Dim ldblBNwIc2 As Double
		Dim ldblBNwPis As Double
		Dim ldblBNwCof As Double
		Dim ldblDifere As Double
		Dim ldblVCCons As Double
		Dim ldblVCDema As Double
		Dim ldblVCKwUl As Double
		Dim ldblVCUfer As Double
		Dim ldblVCDmcr As Double
		Dim ldblVHKwhP As Double
		Dim ldblVHKwhF As Double
		Dim ldblVHDemP As Double
		Dim ldblVHDemF As Double
		Dim ldblVHKwUP As Double
		Dim ldblVHKwUF As Double
		Dim ldblVHUfrP As Double
		Dim ldblVHUfrF As Double
		Dim ldblVHDmcP As Double
		Dim ldblVHDmcF As Double
		Dim ldblVDevoP As Double
		Dim ldblVDevoF As Double
		Dim ldblVUltrP As Double
		Dim ldblVUltrF As Double
		Dim lintPosIni As Short
		Dim lintPosFim As Short
		Dim lstrTabela As String
		Dim lintConvenioSefaz As Short
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrMesAno = "11/2019"
		lstrTabela = "`nf`"
		lstrSql = ""
		lstrSql = lstrSql & "SELECT mesano, numnf, itensserv, codclas, ta, micro_geracao_convenio_sefaz "
		lstrSql = lstrSql & "  FROM " & lstrTabela
		lstrSql = lstrSql & " WHERE `mesano` = '" & lstrMesAno & "'"
		lstrSql = lstrSql & "   AND `grupo` = 'B' "
		lstrSql = lstrSql & "   AND (`micro_geracao` = 1 or `micro_geracao_distribuida` = 1) AND micro_geracao_convenio_sefaz = 0 "
		'lstrSql = lstrSql & "   AND `grupo` = 'A' "
		'lstrSql = lstrSql & "   AND `ta` not IN('01AL00') "
		'lstrSql = lstrSql & "   AND zona = '001' and livro = '99' and conta NOT IN('000035','000040') "
		'lstrSql = lstrSql & "   AND conta <> '000040' "
		'lstrSql = lstrSql & "   AND `ta` NOT IN('01AL00','01AS00') "
		'lstrSql = lstrSql & "   AND `numnf` not in(21,22, 23) "
		
		'  lstrSql = lstrSql & "and ((livro='01' and conta='000400') or"
		'  lstrSql = lstrSql & "   (livro='03' and conta='001810') or"
		'  lstrSql = lstrSql & "   (livro='05' and conta='002460') or"
		'  lstrSql = lstrSql & "   (livro='07' and conta IN('000925','000511')) or"
		'  lstrSql = lstrSql & "   (livro='09' and conta='001580') or"
		'  lstrSql = lstrSql & "   (livro='10' and conta='002290') or"
		'  lstrSql = lstrSql & "   (livro='11' and conta IN('000846','000148')) or"
		'  lstrSql = lstrSql & "   (livro='12' and conta IN('001140','000940','001414')) or"
		'  lstrSql = lstrSql & "   (livro='13' and conta IN('001041','001993','001649','002133','000129','000553')))"
		
		
		
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State > 0 Then
				If .RecordCount > 0 Then
					While Not .EOF
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lintConvenioSefaz = IIf(IsDbNull(.Fields("micro_geracao_convenio_sefaz").value), 0, .Fields("micro_geracao_convenio_sefaz").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblNumeNf = IIf(IsDbNull(.Fields("numnf").value), 0, .Fields("numnf").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrClasse = IIf(IsDbNull(.Fields("codclas").value), "", .Fields("codclas").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrGruTar = UCase(Mid(IIf(IsDbNull(.Fields("ta").value), "01B1", .Fields("ta").value), 3, 1))
						lblItensInfo.Text = ldblNumeNf & " " & lstrMesAno
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						Me.lblItensIn.Text = IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").value)
						Me.lblItensOut.Text = Me.lblItensIn.Text
						'          ldblVCCons = IIf(lstrGruTar = "A", BuscaVlrItem(Me.lblItensIn.Caption, "0302020009"), 0)
						'          ldblVCDema = IIf(lstrGruTar = "A", BuscaVlrItem(Me.lblItensIn.Caption, "0302020015"), 0)
						'          ldblVCKwUl = IIf(lstrGruTar = "A", BuscaVlrItem(Me.lblItensIn.Caption, "0302020018"), 0)
						'          ldblVCUfer = IIf(lstrGruTar = "A", BuscaVlrItem(Me.lblItensIn.Caption, "0302020012"), 0)
						'          ldblVCDmcr = IIf(lstrGruTar = "A", BuscaVlrItem(Me.lblItensIn.Caption, "0302020031"), 0)
						'          ldblVHKwhP = IIf(lstrGruTar = "A", BuscaVlrItem(Me.lblItensIn.Caption, "0302020010"), 0)
						'          ldblVHKwhF = IIf(lstrGruTar = "A", BuscaVlrItem(Me.lblItensIn.Caption, "0302020011"), 0)
						'          ldblVHDemP = IIf(lstrGruTar = "A", BuscaVlrItem(Me.lblItensIn.Caption, "0302020021"), 0)
						'          ldblVHDemF = IIf(lstrGruTar = "A", BuscaVlrItem(Me.lblItensIn.Caption, "0302020023"), 0)  '+ BuscaVlrItem(Me.lblItensIn.Caption, "0302020072")
						'          ldblVHKwUP = IIf(lstrGruTar = "A", BuscaVlrItem(Me.lblItensIn.Caption, "0302020022"), 0)
						'          ldblVHKwUF = IIf(lstrGruTar = "A", BuscaVlrItem(Me.lblItensIn.Caption, "0302020026"), 0)
						'          ldblVHUfrP = IIf(lstrGruTar = "A", BuscaVlrItem(Me.lblItensIn.Caption, "0302020013"), 0)
						'          ldblVHUfrF = IIf(lstrGruTar = "A", BuscaVlrItem(Me.lblItensIn.Caption, "0302020014"), 0)
						'          ldblVHDmcP = IIf(lstrGruTar = "A", BuscaVlrItem(Me.lblItensIn.Caption, "0302020027"), 0)
						'          ldblVHDmcF = IIf(lstrGruTar = "A", BuscaVlrItem(Me.lblItensIn.Caption, "0302020028"), 0)
						'          ldblVDevoP = IIf(lstrGruTar = "A", BuscaVlrItem(Me.lblItensIn.Caption, "0302020041"), 0)
						'          ldblVDevoF = IIf(lstrGruTar = "A", BuscaVlrItem(Me.lblItensIn.Caption, "0302020042"), 0)
						'          ldblVUltrP = IIf(lstrGruTar = "A", BuscaVlrItem(Me.lblItensIn.Caption, "0302020043"), 0)
						'          ldblVUltrF = IIf(lstrGruTar = "A", BuscaVlrItem(Me.lblItensIn.Caption, "0302020044"), 0)
						ldblVlrkWh = IIf(lstrGruTar = "B", BuscaVlrItem(Me.lblItensIn.Text, "030202009"), 0)
						ldblVlrkWh = ldblVlrkWh + IIf(lstrGruTar = "B", BuscaVlrItem(Me.lblItensIn.Text, "030212009"), 0)
						If lintConvenioSefaz = 0 Then
							ldblVlrkWh = ldblVlrkWh + BuscaVlrItem(Me.lblItensIn.Text, "0302020993") + BuscaVlrItem(Me.lblItensIn.Text, "0302020994") 'Para MG sem SEFAZ soma valor reverso
						End If
						
						
						
						ldblVlrkVa = IIf(lstrGruTar = "B", BuscaVlrItem(Me.lblItensIn.Text, "0302020012"), 0)
						ldblVlrIc1 = BuscaVlrItem(Me.lblItensIn.Text, "0302030009")
						ldblVlrIc2 = BuscaVlrItem(Me.lblItensIn.Text, "0302030010")
						ldblVlrPis = BuscaVlrItem(Me.lblItensIn.Text, "0302020029")
						ldblVlrCof = BuscaVlrItem(Me.lblItensIn.Text, "0302020030")
						ldblTotBas = ldblVlrkWh + ldblVlrkVa + ldblVCCons + ldblVCDema + ldblVCKwUl + ldblVCUfer + ldblVCDmcr + ldblVHKwhP + ldblVHKwhF + ldblVHDemP + ldblVHDemF + ldblVHKwUP + ldblVHKwUF + ldblVHUfrP + ldblVHUfrF + ldblVHDmcP + ldblVHDmcF + ldblVDevoP + ldblVDevoF + ldblVUltrP + ldblVUltrF + ldblVlrIc1 + ldblVlrIc2 + ldblVlrPis + ldblVlrCof
						ldblBasIc1 = BuscaVlrItem(Me.lblItensIn.Text, "0302030001")
						ldblBasIc2 = BuscaVlrItem(Me.lblItensIn.Text, "0302030003")
						ldblBasPis = BuscaVlrItem(Me.lblItensIn.Text, "0302020033")
						ldblBasCof = BuscaVlrItem(Me.lblItensIn.Text, "0302020034")
						ldblBNwIc1 = 0
						ldblBNwIc2 = 0
						ldblBNwPis = 0
						ldblBNwCof = 0
						If ldblBasIc2 > 0 Then
							ldblDifere = Arredondar(ldblTotBas - (ldblBasIc1 + ldblBasIc2), 2)
							ldblBNwIc2 = ldblBasIc2 + ldblDifere
						ElseIf ldblBasIc1 > 0 Then 
							ldblDifere = Arredondar(ldblTotBas - ldblBasIc1, 2)
							ldblBNwIc1 = ldblBasIc1 + ldblDifere
						End If
						If ldblBasPis > 0 Then
							ldblDifere = Arredondar(ldblTotBas - ldblBasPis, 2)
							ldblBNwPis = ldblBasPis + ldblDifere
						End If
						If ldblBasCof > 0 Then
							ldblDifere = Arredondar(ldblTotBas - ldblBasCof, 2)
							ldblBNwCof = ldblBasCof + ldblDifere
						End If
						If ldblBNwIc1 > 0 Then
							lintPosIni = InStr(1, Me.lblItensOut.Text, "0302030001")
							lintPosFim = InStr(lintPosIni, Me.lblItensOut.Text, ";")
							lstrAuxOld = Mid(Me.lblItensOut.Text, lintPosIni, (lintPosFim - lintPosIni) + 1)
							lstrAuxNew = "0302030001?" & Replace(Replace(CStr(ldblBNwIc1), ".", ""), ",", ".") & ";"
							Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrAuxOld, lstrAuxNew)
						End If
						If ldblBNwIc2 > 0 Then
							lintPosIni = InStr(1, Me.lblItensOut.Text, "0302030003")
							lintPosFim = InStr(lintPosIni, Me.lblItensOut.Text, ";")
							lstrAuxOld = Mid(Me.lblItensOut.Text, lintPosIni, (lintPosFim - lintPosIni) + 1)
							lstrAuxNew = "0302030003?" & Replace(Replace(CStr(ldblBNwIc2), ".", ""), ",", ".") & ";"
							Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrAuxOld, lstrAuxNew)
						End If
						If ldblBNwPis > 0 Then
							lintPosIni = InStr(1, Me.lblItensOut.Text, "0302020033")
							lintPosFim = InStr(lintPosIni, Me.lblItensOut.Text, ";")
							lstrAuxOld = Mid(Me.lblItensOut.Text, lintPosIni, (lintPosFim - lintPosIni) + 1)
							lstrAuxNew = "0302020033?" & Replace(Replace(CStr(ldblBNwPis), ".", ""), ",", ".") & ";"
							Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrAuxOld, lstrAuxNew)
						End If
						If ldblBNwPis > 0 Then
							lintPosIni = InStr(1, Me.lblItensOut.Text, "0302020034")
							lintPosFim = InStr(lintPosIni, Me.lblItensOut.Text, ";")
							lstrAuxOld = Mid(Me.lblItensOut.Text, lintPosIni, (lintPosFim - lintPosIni) + 1)
							lstrAuxNew = "0302020034?" & Replace(Replace(CStr(ldblBNwCof), ".", ""), ",", ".") & ";"
							Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrAuxOld, lstrAuxNew)
						End If
						Call .MoveNext()
						If Me.lblItensOut.Text <> Me.lblItensIn.Text Then
							lstrSql = ""
							lstrSql = lstrSql & "UPDATE " & lstrTabela & " SET `itensserv` = '" & Me.lblItensOut.Text & "' "
							lstrSql = lstrSql & " WHERE `mesano` = '" & lstrMesAno & "'"
							lstrSql = lstrSql & "   AND `numnf` = " & ldblNumeNf
							Call myConC.BeginTrans()
							Call Executar(lstrSql)
							Call myConC.CommitTrans()
						End If
						System.Windows.Forms.Application.DoEvents()
					End While
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Sub
	
	Private Sub cmdArrumaItensBandeiras_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdArrumaItensBandeiras.Click
		Dim llngMesano As Integer
		Dim lstrMesAno As String
		Dim ldblNumeNf As Double
		Dim lstrGruTar As String
		Dim lintParCat As Short
		'
		Dim ldblAux As Double
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		Dim lrstBan As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lrstBan = New ADODB.Recordset
		'
		Dim ldbl_Tar_Vd_Ponta As Double
		Dim ldbl_Tar_Vd_ForaP As Double
		Dim ldbl_Tar_Vm_Ponta As Double
		Dim ldbl_Tar_Vm_ForaP As Double
		'
		Dim ldbl_Vlr_Ver_Ponta As Double
		Dim ldbl_Vlr_Ver_ForaP As Double
		Dim ldbl_Vlr_Rec_Ponta As Double
		Dim ldbl_Vlr_Rec_ForaP As Double
		'Convencional
		Dim lstrCon_Cod_Qtd_Lido As String
		Dim lstrCon_Cod_Qtd_Fatu As String
		Dim lstrCon_Cod_Vlr_Lido As String
		Dim lstrCon_Cod_Vlr_Fatu As String
		Dim lstrCon_Cod_Tar_Cons As String
		'Horossazonal
		Dim lstrHor_Cod_Qtd_Ponta As String
		Dim lstrHor_Cod_Qtd_ForaP As String
		Dim lstrHor_Cod_Vlr_Ponta As String
		Dim lstrHor_Cod_Vlr_ForaP As String
		Dim lstrHor_Cod_Ta1_Ponta As String
		Dim lstrHor_Cod_Ta1_ForaP As String
		Dim lstrHor_Cod_Ta2_Ponta As String
		Dim lstrHor_Cod_Ta2_ForaP As String
		'Parcialmente cativo
		Dim lstrPar_Cod_Qtd_Ponta As String
		Dim lstrPar_Cod_Qtd_ForaP As String
		Dim lstrPar_Cod_Ta1_Ponta As String
		Dim lstrPar_Cod_Ta1_ForaP As String
		Dim lstrPar_Cod_Ta2_Ponta As String
		Dim lstrPar_Cod_Ta2_ForaP As String
		'Convencional
		Dim lstrCon_Tex_Qtd_Lido As String
		Dim lstrCon_Tex_Qtd_Fatu As String
		Dim lstrCon_Tex_Vlr_Lido As String
		Dim lstrCon_Tex_Vlr_Fatu As String
		Dim lstrCon_Tex_Tar_Cons As String
		'Horossazonal
		Dim lstrHor_Tex_Qtd_Ponta As String
		Dim lstrHor_Tex_Qtd_ForaP As String
		Dim lstrHor_Tex_Vlr_Ponta As String
		Dim lstrHor_Tex_Vlr_ForaP As String
		Dim lstrHor_Tex_Ta1_Ponta As String
		Dim lstrHor_Tex_Ta1_ForaP As String
		Dim lstrHor_Tex_Ta2_Ponta As String
		Dim lstrHor_Tex_Ta2_ForaP As String
		'Parcialmente cativo
		Dim lstrPar_Tex_Qtd_Ponta As String
		Dim lstrPar_Tex_Qtd_ForaP As String
		Dim lstrPar_Tex_Ta1_Ponta As String
		Dim lstrPar_Tex_Ta1_ForaP As String
		Dim lstrPar_Tex_Ta2_Ponta As String
		Dim lstrPar_Tex_Ta2_ForaP As String
		'Convencional
		Dim lstrCon_New_Qtd_Lido As String
		Dim lstrCon_New_Qtd_Fatu As String
		Dim lstrCon_New_Vlr_Lido As String
		Dim lstrCon_New_Vlr_Fatu As String
		Dim lstrCon_New_Tar_Cons As String
		'Horossazonal
		Dim lstrHor_New_Qtd_Ponta As String
		Dim lstrHor_New_Qtd_ForaP As String
		Dim lstrHor_New_Vlr_Ponta As String
		Dim lstrHor_New_Vlr_ForaP As String
		Dim lstrHor_New_Ta1_Ponta As String
		Dim lstrHor_New_Ta1_ForaP As String
		Dim lstrHor_New_Ta2_Ponta As String
		Dim lstrHor_New_Ta2_ForaP As String
		'Parcialmente cativo
		Dim lstrPar_New_Ta1_Ponta As String
		Dim lstrPar_New_Ta1_ForaP As String
		Dim lstrPar_New_Ta2_Ponta As String
		Dim lstrPar_New_Ta2_ForaP As String
		'
		lstrMesAno = "01/2015"
		llngMesano = 201501
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM `nf_bandeira_a` "
		lstrSql = lstrSql & " WHERE `mesano_ref` = " & llngMesano & " "
		Call Conectar(lstrSql, lrstBan)
		With lrstBan
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount)
					While Not .EOF
						'Dados
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblNumeNf = IIf(IsDbNull(.Fields("numnf").value), 0, .Fields("numnf").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrGruTar = IIf(IsDbNull(.Fields("ta").value), "A4", .Fields("ta").value)
						Me.lblItensInfo.Text = ldblNumeNf & " " & lstrMesAno
						'Tarifa Verde
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldbl_Tar_Vd_Ponta = IIf(IsDbNull(.Fields("tar_vd_ponta").value), 0, .Fields("tar_vd_ponta").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldbl_Tar_Vd_ForaP = IIf(IsDbNull(.Fields("tar_vd_forap").value), 0, .Fields("tar_vd_forap").value)
						'Tarifa Vermelha
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldbl_Tar_Vm_Ponta = IIf(IsDbNull(.Fields("tar_vm_ponta").value), 0, .Fields("tar_vm_ponta").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldbl_Tar_Vm_ForaP = IIf(IsDbNull(.Fields("tar_vm_forap").value), 0, .Fields("tar_vm_forap").value)
						'Valor Verde
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldbl_Vlr_Ver_Ponta = IIf(IsDbNull(.Fields("vlr_ver_ponta").value), 0, .Fields("vlr_ver_ponta").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldbl_Vlr_Ver_ForaP = IIf(IsDbNull(.Fields("vlr_ver_forap").value), 0, .Fields("vlr_ver_forap").value)
						'Receita bandeira
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldbl_Vlr_Rec_Ponta = IIf(IsDbNull(.Fields("vlr_rec_ponta").value), 0, .Fields("vlr_rec_ponta").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldbl_Vlr_Rec_ForaP = IIf(IsDbNull(.Fields("vlr_rec_forap").value), 0, .Fields("vlr_rec_forap").value)
						'Convenional
						lstrCon_Cod_Qtd_Lido = "0302010008"
						lstrCon_Cod_Qtd_Fatu = "0302010009"
						lstrCon_Cod_Vlr_Lido = "0302020008"
						lstrCon_Cod_Vlr_Fatu = "0302020009"
						lstrCon_Cod_Tar_Cons = "01" & lstrGruTar & "011101"
						'Horossazonal
						lstrHor_Cod_Qtd_Ponta = "0302010010"
						lstrHor_Cod_Qtd_ForaP = "0302010011"
						lstrHor_Cod_Vlr_Ponta = "0302020010"
						lstrHor_Cod_Vlr_ForaP = "0302020011"
						lstrHor_Cod_Ta1_Ponta = "01" & lstrGruTar & "011101"
						lstrHor_Cod_Ta1_ForaP = "01" & lstrGruTar & "011102"
						lstrHor_Cod_Ta2_Ponta = "01" & lstrGruTar & "011105"
						lstrHor_Cod_Ta2_ForaP = "01" & lstrGruTar & "011106"
						'Parcilamente cativ o
						lstrPar_Cod_Qtd_Ponta = "0302010060"
						lstrPar_Cod_Qtd_ForaP = "0302010061"
						lstrPar_Cod_Ta1_Ponta = "01AA011101"
						lstrPar_Cod_Ta1_ForaP = "01AA011102"
						lstrPar_Cod_Ta2_Ponta = "01AA011105"
						lstrPar_Cod_Ta2_ForaP = "01AA011106"
						'Instrunção
						lstrSql = ""
						lstrSql = lstrSql & "SELECT "
						'Convencional
						lstrSql = lstrSql & "  MID(itensserv, INSTR(itensserv, '" & lstrCon_Cod_Qtd_Lido & "'), LOCATE(';', MID(itensserv, INSTR(itensserv, '" & lstrCon_Cod_Qtd_Lido & "')))) con_tex_qtd_lido, "
						lstrSql = lstrSql & "  MID(itensserv, INSTR(itensserv, '" & lstrCon_Cod_Qtd_Fatu & "'), LOCATE(';', MID(itensserv, INSTR(itensserv, '" & lstrCon_Cod_Qtd_Fatu & "')))) con_tex_qtd_fatu, "
						lstrSql = lstrSql & "  MID(itensserv, INSTR(itensserv, '" & lstrCon_Cod_Vlr_Lido & "'), LOCATE(';', MID(itensserv, INSTR(itensserv, '" & lstrCon_Cod_Vlr_Lido & "')))) con_tex_vlr_lido, "
						lstrSql = lstrSql & "  MID(itensserv, INSTR(itensserv, '" & lstrCon_Cod_Vlr_Fatu & "'), LOCATE(';', MID(itensserv, INSTR(itensserv, '" & lstrCon_Cod_Vlr_Fatu & "')))) con_tex_vlr_fatu, "
						lstrSql = lstrSql & "  MID(itensserv, INSTR(itensserv, '" & lstrCon_Cod_Tar_Cons & "'), LOCATE(';', MID(itensserv, INSTR(itensserv, '" & lstrCon_Cod_Tar_Cons & "')))) con_tex_tar_cons, "
						'Horosazonal
						lstrSql = lstrSql & "  MID(itensserv, INSTR(itensserv, '" & lstrHor_Cod_Qtd_Ponta & "'), LOCATE(';', MID(itensserv, INSTR(itensserv, '" & lstrHor_Cod_Qtd_Ponta & "')))) hor_tex_qtd_ponta, "
						lstrSql = lstrSql & "  MID(itensserv, INSTR(itensserv, '" & lstrHor_Cod_Qtd_ForaP & "'), LOCATE(';', MID(itensserv, INSTR(itensserv, '" & lstrHor_Cod_Qtd_ForaP & "')))) hor_tex_qtd_foraP, "
						lstrSql = lstrSql & "  MID(itensserv, INSTR(itensserv, '" & lstrHor_Cod_Vlr_Ponta & "'), LOCATE(';', MID(itensserv, INSTR(itensserv, '" & lstrHor_Cod_Vlr_Ponta & "')))) hor_tex_vlr_ponta, "
						lstrSql = lstrSql & "  MID(itensserv, INSTR(itensserv, '" & lstrHor_Cod_Vlr_ForaP & "'), LOCATE(';', MID(itensserv, INSTR(itensserv, '" & lstrHor_Cod_Vlr_ForaP & "')))) hor_tex_vlr_forap, "
						lstrSql = lstrSql & "  MID(itensserv, INSTR(itensserv, '" & lstrHor_Cod_Ta1_Ponta & "'), LOCATE(';', MID(itensserv, INSTR(itensserv, '" & lstrHor_Cod_Ta1_Ponta & "')))) hor_tex_ta1_ponta, "
						lstrSql = lstrSql & "  MID(itensserv, INSTR(itensserv, '" & lstrHor_Cod_Ta1_ForaP & "'), LOCATE(';', MID(itensserv, INSTR(itensserv, '" & lstrHor_Cod_Ta1_ForaP & "')))) hor_tex_ta1_forap, "
						lstrSql = lstrSql & "  MID(itensserv, INSTR(itensserv, '" & lstrHor_Cod_Ta2_Ponta & "'), LOCATE(';', MID(itensserv, INSTR(itensserv, '" & lstrHor_Cod_Ta2_Ponta & "')))) hor_tex_ta2_ponta, "
						lstrSql = lstrSql & "  MID(itensserv, INSTR(itensserv, '" & lstrHor_Cod_Ta2_ForaP & "'), LOCATE(';', MID(itensserv, INSTR(itensserv, '" & lstrHor_Cod_Ta2_ForaP & "')))) hor_tex_ta2_forap, "
						'Parcipalmente Cativo
						lstrSql = lstrSql & "  MID(itensserv, INSTR(itensserv, '" & lstrPar_Cod_Qtd_Ponta & "'), LOCATE(';', MID(itensserv, INSTR(itensserv, '" & lstrPar_Cod_Qtd_Ponta & "')))) par_tex_qtd_ponta,"
						lstrSql = lstrSql & "  MID(itensserv, INSTR(itensserv, '" & lstrPar_Cod_Qtd_ForaP & "'), LOCATE(';', MID(itensserv, INSTR(itensserv, '" & lstrPar_Cod_Qtd_ForaP & "')))) par_tex_qtd_foraP,"
						lstrSql = lstrSql & "  MID(itensserv, INSTR(itensserv, '" & lstrPar_Cod_Ta1_Ponta & "'), LOCATE(';', MID(itensserv, INSTR(itensserv, '" & lstrPar_Cod_Ta1_Ponta & "')))) par_tex_ta1_ponta, "
						lstrSql = lstrSql & "  MID(itensserv, INSTR(itensserv, '" & lstrPar_Cod_Ta1_ForaP & "'), LOCATE(';', MID(itensserv, INSTR(itensserv, '" & lstrPar_Cod_Ta1_ForaP & "')))) par_tex_ta1_forap, "
						lstrSql = lstrSql & "  MID(itensserv, INSTR(itensserv, '" & lstrPar_Cod_Ta2_Ponta & "'), LOCATE(';', MID(itensserv, INSTR(itensserv, '" & lstrPar_Cod_Ta2_Ponta & "')))) par_tex_ta2_ponta, "
						lstrSql = lstrSql & "  MID(itensserv, INSTR(itensserv, '" & lstrPar_Cod_Ta2_ForaP & "'), LOCATE(';', MID(itensserv, INSTR(itensserv, '" & lstrPar_Cod_Ta2_ForaP & "')))) par_tex_ta2_forap, "
						'Tabela
						lstrSql = lstrSql & "       `nf`.* "
						lstrSql = lstrSql & "  FROM `nf` "
						lstrSql = lstrSql & " WHERE `mesano_ref` = " & llngMesano & " "
						lstrSql = lstrSql & "   AND `numnf` = " & ldblNumeNf & " "
						lstrSql = lstrSql & "   AND `mesano` = '" & lstrMesAno & "' "
						Call Conectar(lstrSql, lrstAux)
						With lrstAux
							If .State = ADODB.ObjectStateEnum.adStateOpen Then
								If .RecordCount > 0 Then
									lstrCon_New_Qtd_Lido = ""
									lstrCon_New_Qtd_Fatu = ""
									lstrCon_New_Vlr_Lido = ""
									lstrCon_New_Vlr_Fatu = ""
									lstrCon_New_Tar_Cons = ""
									lstrHor_New_Qtd_Ponta = ""
									lstrHor_New_Qtd_ForaP = ""
									lstrHor_New_Vlr_Ponta = ""
									lstrHor_New_Vlr_ForaP = ""
									lstrHor_New_Ta1_Ponta = ""
									lstrHor_New_Ta1_ForaP = ""
									lstrHor_New_Ta2_Ponta = ""
									lstrHor_New_Ta2_ForaP = ""
									lstrPar_New_Ta1_Ponta = ""
									lstrPar_New_Ta1_ForaP = ""
									lstrPar_New_Ta2_Ponta = ""
									lstrPar_New_Ta2_ForaP = ""
									'Dados
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lintParCat = IIf(IsDbNull(.Fields("parcialmente_cativo").value), 0, .Fields("parcialmente_cativo").value)
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									Me.lblItensIn.Text = IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").value)
									Me.lblItensOut.Text = Me.lblItensIn.Text
									'Convenional
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrCon_Tex_Qtd_Lido = Trim(IIf(IsDbNull(.Fields("con_tex_qtd_lido").value), "", .Fields("con_tex_qtd_lido").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrCon_Tex_Qtd_Fatu = Trim(IIf(IsDbNull(.Fields("con_tex_qtd_fatu").value), "", .Fields("con_tex_qtd_fatu").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrCon_Tex_Vlr_Lido = Trim(IIf(IsDbNull(.Fields("con_tex_vlr_lido").value), "", .Fields("con_tex_vlr_lido").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrCon_Tex_Vlr_Fatu = Trim(IIf(IsDbNull(.Fields("con_tex_vlr_fatu").value), "", .Fields("con_tex_vlr_fatu").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrCon_Tex_Tar_Cons = Trim(IIf(IsDbNull(.Fields("con_tex_tar_cons").value), "", .Fields("con_tex_tar_cons").value))
									'Horossazonal
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrHor_Tex_Qtd_Ponta = Trim(IIf(IsDbNull(.Fields("hor_tex_qtd_ponta").value), "", .Fields("hor_tex_qtd_ponta").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrHor_Tex_Qtd_ForaP = Trim(IIf(IsDbNull(.Fields("hor_tex_qtd_forap").value), "", .Fields("hor_tex_qtd_forap").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrHor_Tex_Vlr_Ponta = Trim(IIf(IsDbNull(.Fields("hor_tex_vlr_ponta").value), "", .Fields("hor_tex_vlr_ponta").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrHor_Tex_Vlr_ForaP = Trim(IIf(IsDbNull(.Fields("hor_tex_vlr_forap").value), "", .Fields("hor_tex_vlr_forap").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrHor_Tex_Ta1_Ponta = Trim(IIf(IsDbNull(.Fields("hor_tex_ta1_ponta").value), "", .Fields("hor_tex_ta1_ponta").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrHor_Tex_Ta1_ForaP = Trim(IIf(IsDbNull(.Fields("hor_tex_ta1_forap").value), "", .Fields("hor_tex_ta1_forap").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrHor_Tex_Ta2_Ponta = Trim(IIf(IsDbNull(.Fields("hor_tex_ta2_ponta").value), "", .Fields("hor_tex_ta2_ponta").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrHor_Tex_Ta2_ForaP = Trim(IIf(IsDbNull(.Fields("hor_tex_ta2_forap").value), "", .Fields("hor_tex_ta2_forap").value))
									'Parcialmente cativo
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrPar_Tex_Qtd_Ponta = Trim(IIf(IsDbNull(.Fields("par_tex_qtd_ponta").value), "", .Fields("par_tex_qtd_ponta").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrPar_Tex_Qtd_ForaP = Trim(IIf(IsDbNull(.Fields("par_tex_qtd_forap").value), "", .Fields("par_tex_qtd_forap").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrPar_Tex_Ta1_Ponta = Trim(IIf(IsDbNull(.Fields("par_tex_ta1_ponta").value), "", .Fields("par_tex_ta1_ponta").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrPar_Tex_Ta1_ForaP = Trim(IIf(IsDbNull(.Fields("par_tex_ta1_forap").value), "", .Fields("par_tex_ta1_forap").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrPar_Tex_Ta2_Ponta = Trim(IIf(IsDbNull(.Fields("par_tex_ta2_ponta").value), "", .Fields("par_tex_ta2_ponta").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									lstrPar_Tex_Ta2_ForaP = Trim(IIf(IsDbNull(.Fields("par_tex_ta2_forap").value), "", .Fields("par_tex_ta2_forap").value))
									'
									'Aqui começa a mandinga
									If lstrCon_Tex_Qtd_Lido <> "" Then 'Convencional
										If ldbl_Vlr_Rec_ForaP <> 0 Then
											'Quantidade
											lstrCon_New_Qtd_Lido = lstrCon_Tex_Qtd_Lido & Replace(lstrCon_Tex_Qtd_Lido, "0302010008", "0302110008")
											lstrCon_New_Qtd_Fatu = lstrCon_Tex_Qtd_Fatu & Replace(lstrCon_Tex_Qtd_Fatu, "0302010009", "0302110009")
											'Valor
											lstrCon_New_Vlr_Lido = lstrCon_Cod_Vlr_Lido & "?" & ldbl_Vlr_Ver_ForaP & "$( " & BuscaValorItem(Me.lblItensIn.Text, lstrCon_Cod_Qtd_Lido) & " x " & ldbl_Tar_Vd_ForaP & " );"
											lstrCon_New_Vlr_Lido = lstrCon_New_Vlr_Lido & "0302120008?" & ldbl_Vlr_Rec_ForaP & ";"
											lstrCon_New_Vlr_Fatu = lstrCon_Cod_Vlr_Fatu & "?" & ldbl_Vlr_Ver_ForaP & ";"
											lstrCon_New_Vlr_Fatu = lstrCon_New_Vlr_Fatu & "0302120009?" & ldbl_Vlr_Rec_ForaP & ";"
											'Tarifa
											lstrCon_New_Tar_Cons = lstrCon_Cod_Tar_Cons & "?" & ldbl_Tar_Vd_ForaP & ";" & Replace(lstrCon_Cod_Tar_Cons, "11101", "11111") & "?" & ldbl_Tar_Vm_ForaP & ";"
											'
											'Muda Itensserv
											Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrCon_Tex_Qtd_Lido, lstrCon_New_Qtd_Lido)
											Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrCon_Tex_Qtd_Fatu, lstrCon_New_Qtd_Fatu)
											Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrCon_Tex_Vlr_Lido, lstrCon_New_Vlr_Lido)
											Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrCon_Tex_Vlr_Fatu, lstrCon_New_Vlr_Fatu)
											Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrCon_Tex_Tar_Cons, lstrCon_New_Tar_Cons)
											'
										End If
									ElseIf lstrHor_Tex_Qtd_Ponta <> "" Or lstrHor_Tex_Qtd_ForaP <> "" Then  'Horossazonal
										If lintParCat = 0 Then
											If ldbl_Vlr_Rec_Ponta <> 0 Then
												'Quantidade
												lstrHor_New_Qtd_Ponta = lstrHor_Tex_Qtd_Ponta & Replace(lstrHor_Tex_Qtd_Ponta, "0302010010", "0302110010")
												'Valor
												lstrHor_New_Vlr_Ponta = lstrHor_Cod_Vlr_Ponta & "?" & ldbl_Vlr_Ver_Ponta & "$( " & BuscaValorItem(Me.lblItensIn.Text, lstrHor_Cod_Qtd_Ponta) & " x " & ldbl_Tar_Vd_Ponta & " );"
												lstrHor_New_Vlr_Ponta = lstrHor_New_Vlr_Ponta & "0302120010?" & ldbl_Vlr_Rec_Ponta & ";"
												'
												Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrHor_Tex_Qtd_Ponta, lstrHor_New_Qtd_Ponta)
												Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrHor_Tex_Vlr_Ponta, lstrHor_New_Vlr_Ponta)
												'Tarifa
												If lstrHor_Tex_Ta1_Ponta <> "" Then
													lstrHor_New_Ta1_Ponta = lstrHor_Cod_Ta1_Ponta & "?" & ldbl_Tar_Vd_Ponta & ";" & Replace(lstrHor_Cod_Ta1_Ponta, "11101", "11111") & "?" & ldbl_Tar_Vm_Ponta & ";"
													'
													Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrHor_Tex_Ta1_Ponta, lstrHor_New_Ta1_Ponta)
												ElseIf lstrHor_Tex_Ta2_Ponta <> "" Then 
													lstrHor_New_Ta2_Ponta = lstrHor_Cod_Ta2_Ponta & "?" & ldbl_Tar_Vd_Ponta & ";" & Replace(lstrHor_Cod_Ta2_Ponta, "11105", "11115") & "?" & ldbl_Tar_Vm_Ponta & ";"
													'
													Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrHor_Tex_Ta2_Ponta, lstrHor_New_Ta2_Ponta)
												End If
												'
											End If
											If ldbl_Vlr_Rec_ForaP <> 0 Then
												'Quantidade
												lstrHor_New_Qtd_ForaP = lstrHor_Tex_Qtd_ForaP & Replace(lstrHor_Tex_Qtd_ForaP, "0302010011", "0302110011")
												'Valor
												lstrHor_New_Vlr_ForaP = lstrHor_Cod_Vlr_ForaP & "?" & ldbl_Vlr_Ver_ForaP & "$( " & BuscaValorItem(Me.lblItensIn.Text, lstrHor_Cod_Qtd_ForaP) & " x " & ldbl_Tar_Vd_ForaP & " );"
												lstrHor_New_Vlr_ForaP = lstrHor_New_Vlr_ForaP & "0302120011?" & ldbl_Vlr_Rec_ForaP & ";"
												'
												Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrHor_Tex_Qtd_ForaP, lstrHor_New_Qtd_ForaP)
												Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrHor_Tex_Vlr_ForaP, lstrHor_New_Vlr_ForaP)
												'Tarifa
												If lstrHor_Tex_Ta1_ForaP <> "" Then
													lstrHor_New_Ta1_ForaP = lstrHor_Cod_Ta1_ForaP & "?" & ldbl_Tar_Vd_ForaP & ";" & Replace(lstrHor_Cod_Ta1_ForaP, "11102", "11112") & "?" & ldbl_Tar_Vm_ForaP & ";"
													'
													Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrHor_Tex_Ta1_ForaP, lstrHor_New_Ta1_ForaP)
												ElseIf lstrHor_Tex_Ta2_ForaP <> "" Then 
													lstrHor_New_Ta2_ForaP = lstrHor_Cod_Ta2_ForaP & "?" & ldbl_Tar_Vd_ForaP & ";" & Replace(lstrHor_Cod_Ta2_ForaP, "11106", "11116") & "?" & ldbl_Tar_Vm_ForaP & ";"
													'
													Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrHor_Tex_Ta2_ForaP, lstrHor_New_Ta2_ForaP)
												End If
												'
											End If
											'
										Else
											'Parcilamente Cativo
											If ldbl_Vlr_Rec_Ponta <> 0 Then
												'Quantidade
												ldblAux = BuscaValorItem(Me.lblItensIn.Text, lstrHor_Cod_Qtd_Ponta) - BuscaValorItem(Me.lblItensIn.Text, lstrPar_Cod_Qtd_Ponta)
												lstrHor_New_Qtd_Ponta = lstrHor_Tex_Qtd_Ponta & "0302110010?" & ldblAux & ";"
												'Valor
												lstrHor_New_Vlr_Ponta = lstrHor_Cod_Vlr_Ponta & "?" & ldbl_Vlr_Ver_Ponta & "$( " & ldblAux & " x " & ldbl_Tar_Vd_Ponta & " );"
												lstrHor_New_Vlr_Ponta = lstrHor_New_Vlr_Ponta & "0302120010?" & ldbl_Vlr_Rec_Ponta & ";"
												'
												Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrHor_Tex_Qtd_Ponta, lstrHor_New_Qtd_Ponta)
												Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrHor_Tex_Vlr_Ponta, lstrHor_New_Vlr_Ponta)
												'Tarifa
												If lstrPar_Tex_Ta1_Ponta <> "" Then
													lstrPar_New_Ta1_Ponta = lstrPar_Cod_Ta1_Ponta & "?" & ldbl_Tar_Vd_Ponta & ";" & Replace(lstrPar_Cod_Ta1_Ponta, "11101", "11111") & "?" & ldbl_Tar_Vm_Ponta & ";"
													'
													Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrPar_Tex_Ta1_Ponta, lstrPar_New_Ta1_Ponta)
												ElseIf lstrPar_Tex_Ta2_Ponta <> "" Then 
													lstrPar_New_Ta2_Ponta = lstrPar_Cod_Ta2_Ponta & "?" & ldbl_Tar_Vd_Ponta & ";" & Replace(lstrPar_Cod_Ta2_Ponta, "11105", "11115") & "?" & ldbl_Tar_Vm_Ponta & ";"
													'
													Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrPar_Tex_Ta2_Ponta, lstrPar_New_Ta2_Ponta)
												End If
											End If
											If ldbl_Vlr_Rec_ForaP <> 0 Then
												'Quantidade
												ldblAux = BuscaValorItem(Me.lblItensIn.Text, lstrHor_Cod_Qtd_ForaP) - BuscaValorItem(Me.lblItensIn.Text, lstrPar_Cod_Qtd_ForaP)
												lstrHor_New_Qtd_ForaP = lstrHor_Tex_Qtd_ForaP & "0302110011?" & ldblAux & ";"
												'
												Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrHor_Tex_Qtd_ForaP, lstrHor_New_Qtd_ForaP)
												Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrHor_Tex_Vlr_ForaP, lstrHor_New_Vlr_ForaP)
												'Valor
												lstrHor_New_Vlr_ForaP = lstrHor_Cod_Vlr_ForaP & "?" & ldbl_Vlr_Ver_ForaP & "$( " & ldblAux & " x " & ldbl_Tar_Vd_ForaP & " );"
												lstrHor_New_Vlr_ForaP = lstrHor_New_Vlr_ForaP & "0302120011?" & ldbl_Vlr_Rec_ForaP & ";"
												'Tarifa
												If lstrPar_Tex_Ta1_ForaP <> "" Then
													lstrPar_New_Ta1_ForaP = lstrPar_Cod_Ta1_ForaP & "?" & ldbl_Tar_Vd_ForaP & ";" & Replace(lstrPar_Cod_Ta1_ForaP, "11102", "11112") & "?" & ldbl_Tar_Vm_ForaP & ";"
													'
													Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrPar_Tex_Ta1_ForaP, lstrPar_New_Ta1_ForaP)
												ElseIf lstrPar_Tex_Ta2_ForaP <> "" Then 
													lstrPar_New_Ta2_ForaP = lstrPar_Cod_Ta2_ForaP & "?" & ldbl_Tar_Vd_ForaP & ";" & Replace(lstrPar_Cod_Ta2_ForaP, "11106", "11116") & "?" & ldbl_Tar_Vm_ForaP & ";"
													'
													Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrPar_Tex_Ta2_ForaP, lstrPar_New_Ta2_ForaP)
												End If
											End If
										End If 'Parcialmente cativo
									End If 'Convencional ou Horossazonal
								End If 'Recordcount
								Call .Close()
							End If
						End With 'nf
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
					End While
				End If
				Call .Close()
			End If
		End With
		'Grupo B
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM `nf_bandeira_a` "
		lstrSql = lstrSql & " WHERE `mesano_ref` = " & llngMesano & " "
		Call Conectar(lstrSql, lrstBan)
		With lrstBan
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount)
					While Not .EOF
						'Dados
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblNumeNf = IIf(IsDbNull(.Fields("numnf").value), 0, .Fields("numnf").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrGruTar = IIf(IsDbNull(.Fields("ta").value), "B1", .Fields("ta").value)
						Me.lblItensInfo.Text = ldblNumeNf & " " & lstrMesAno
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
					End While
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
		'UPGRADE_NOTE: Object lrstBan may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstBan = Nothing
	End Sub
	
	Private Sub cmdArrumaItensIcmsPisCofins_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdArrumaItensIcmsPisCofins.Click
		Dim ldblNNf As Double
		Dim lstrMAn As String
		Dim lstrIte As String
		'
		Dim ldblkWh As Double
		Dim ldblKwh1 As Double
		Dim ldblKwh2 As Double
		Dim ldblKwh3 As Double
		Dim ldblKwh4 As Double
		Dim ldblKwh5 As Double
		Dim lstrSql As String
		Dim lrstAux As New ADODB.Recordset
		
		lstrSql = "SELECT * FROM `nf` WHERE `mesano_ref` >= 201201 AND `codclas` = '9105' "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount)
					While Not .EOF
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblNNf = IIf(IsDbNull(.Fields("numnf").value), 0, .Fields("numnf").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrMAn = IIf(IsDbNull(.Fields("mesano").value), "", .Fields("mesano").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrIte = IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").value)
						ldblkWh = BuscaValorItem(lstrIte, "030201009")
						
						
						Call .MoveNext()
					End While
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Sub
	
	Private Sub cmdArrumaItensIndicadores_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdArrumaItensIndicadores.Click
		Dim lintPosIni As Short
		Dim lintPosFim As Short
		Dim lstrAuxOld As String
		Dim lstrAuxNew As String
		'
		Dim lstrMesAno As String
		Dim ldblNumeNf As Double
		Dim lstrTabela As String
		'
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim lstrGrupo As String
		'
		Dim ldblIndMetaDec As Double
		Dim ldblIndMetaFec As Double
		Dim ldblIndMetaDic As Double
		Dim ldblIndMetaFic As Double
		Dim ldblIndMetaMic As Double
		Dim ldblIndRealDec As Double
		Dim ldblIndRealFec As Double
		Dim ldblIndRealDic As Double
		Dim ldblIndRealFic As Double
		Dim ldblIndRealMic As Double
		Dim ldblIndVCM As Double
		'
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Dim lrstAux2 As ADODB.Recordset
		lrstAux2 = New ADODB.Recordset
		lstrMesAno = "01/2013"
		lstrTabela = "`nf`"
		lstrSql = ""
		lstrSql = lstrSql & "SELECT numnf,mesano,mesano_ref,zona,livro,conta,unid_id,cons_id,grupo,itensserv  "
		lstrSql = lstrSql & "  FROM " & lstrTabela
		lstrSql = lstrSql & " WHERE `mesano` = '" & lstrMesAno & "'"
		lstrSql = lstrSql & "   AND `grupo` = 'A' "
		lstrSql = lstrSql & "   AND INSTR(itensserv,'0302080101')>0 "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					While Not .EOF
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblNumeNf = IIf(IsDbNull(.Fields("numnf").value), 0, .Fields("numnf").value)
						lblItensInfo.Text = ldblNumeNf & " " & lstrMesAno
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						Me.lblItensIn.Text = IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").value)
						Me.lblItensOut.Text = Me.lblItensIn.Text
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrZona = IIf(IsDbNull(.Fields("zona").value), 0, .Fields("zona").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrLivro = IIf(IsDbNull(.Fields("livro").value), 0, .Fields("livro").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrConta = IIf(IsDbNull(.Fields("conta").value), 0, .Fields("conta").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrGrupo = IIf(IsDbNull(.Fields("grupo").value), 0, .Fields("grupo").value)
						lstrSql = ""
						lstrSql = lstrSql & "SELECT `indicadores`.`mesanoref`, "
						lstrSql = lstrSql & "       `indicadores`.`mdec`, "
						lstrSql = lstrSql & "       `indicadores`.`mfec`, "
						lstrSql = lstrSql & "       `indicadores`.`mdic`, "
						lstrSql = lstrSql & "       `indicadores`.`mfic`, "
						lstrSql = lstrSql & "       `indicadores`.`mdmic`, "
						lstrSql = lstrSql & "       `indicadores`.`rdec`, "
						lstrSql = lstrSql & "       `indicadores`.`rfec`, "
						lstrSql = lstrSql & "       `indicadores`.`rdic`, "
						lstrSql = lstrSql & "       `indicadores`.`rfic`, "
						lstrSql = lstrSql & "       `indicadores`.`rdmic`, "
						lstrSql = lstrSql & "       `indicadores`.`tipo`, "
						lstrSql = lstrSql & "       `indicadores`.`vdic`, "
						lstrSql = lstrSql & "       `indicadores`.`vfic`, "
						lstrSql = lstrSql & "       `indicadores`.`vdmic`, "
						lstrSql = lstrSql & "       `indicadores`.`vcm`"
						lstrSql = lstrSql & "  FROM `" & gstrDataBase & "`.`indicadores` "
						lstrSql = lstrSql & " WHERE `indicadores`.`zona`   = """ & lstrZona & """ "
						lstrSql = lstrSql & "   AND `indicadores`.`livro`  = """ & lstrLivro & """ "
						lstrSql = lstrSql & "   AND `indicadores`.`conta`  = """ & lstrConta & """ "
						lstrSql = lstrSql & "   AND `indicadores`.`grupo`  = """ & lstrGrupo & """ "
						lstrSql = lstrSql & "   AND `indicadores`.`mesano` = """ & lstrMesAno & """ "
						lstrSql = lstrSql & "   AND `indicadores`.`tipo` = ""M"" "
						Call Conectar(lstrSql, lrstAux2)
						With lrstAux2
							If .State = ADODB.ObjectStateEnum.adStateOpen Then
								If .RecordCount > 0 Then
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									ldblIndMetaDec = CDbl(IIf(IsDbNull(.Fields("mdec").value), 0, .Fields("mdec").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									ldblIndMetaFec = CDbl(IIf(IsDbNull(.Fields("mfec").value), 0, .Fields("mfec").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									ldblIndMetaDic = CDbl(IIf(IsDbNull(.Fields("mdic").value), 0, .Fields("mdic").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									ldblIndMetaFic = CDbl(IIf(IsDbNull(.Fields("mfic").value), 0, .Fields("mfic").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									ldblIndMetaMic = CDbl(IIf(IsDbNull(.Fields("mdmic").value), 0, .Fields("mdmic").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									ldblIndRealDec = CDbl(IIf(IsDbNull(.Fields("rdec").value), 0, .Fields("rdec").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									ldblIndRealFec = CDbl(IIf(IsDbNull(.Fields("rfec").value), 0, .Fields("rfec").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									ldblIndRealDic = CDbl(IIf(IsDbNull(.Fields("rdic").value), 0, .Fields("rdic").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									ldblIndRealFic = CDbl(IIf(IsDbNull(.Fields("rfic").value), 0, .Fields("rfic").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									ldblIndRealMic = CDbl(IIf(IsDbNull(.Fields("rdmic").value), 0, .Fields("rdmic").value))
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									ldblIndVCM = CDbl(IIf(IsDbNull(.Fields("vcm").value), 0, .Fields("vcm").value))
									'
									lintPosIni = InStr(1, Me.lblItensOut.Text, "0302080101")
									lintPosFim = InStr(lintPosIni, Me.lblItensOut.Text, "$")
									lstrAuxOld = Mid(Me.lblItensOut.Text, lintPosIni, (lintPosFim - lintPosIni) + 1)
									lstrAuxNew = "0302080101?" & Replace(Replace(CStr(ldblIndMetaDec), ".", ""), ",", ".") & "$"
									Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrAuxOld, lstrAuxNew)
									'
									lintPosIni = InStr(1, Me.lblItensOut.Text, "0302080102")
									lintPosFim = InStr(lintPosIni, Me.lblItensOut.Text, "$")
									lstrAuxOld = Mid(Me.lblItensOut.Text, lintPosIni, (lintPosFim - lintPosIni) + 1)
									lstrAuxNew = "0302080102?" & Replace(Replace(CStr(ldblIndMetaFec), ".", ""), ",", ".") & "$"
									Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrAuxOld, lstrAuxNew)
									'
									lintPosIni = InStr(1, Me.lblItensOut.Text, "0302080103")
									lintPosFim = InStr(lintPosIni, Me.lblItensOut.Text, "$")
									lstrAuxOld = Mid(Me.lblItensOut.Text, lintPosIni, (lintPosFim - lintPosIni) + 1)
									lstrAuxNew = "0302080103?" & Replace(Replace(CStr(ldblIndMetaDic), ".", ""), ",", ".") & "$"
									Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrAuxOld, lstrAuxNew)
									'
									lintPosIni = InStr(1, Me.lblItensOut.Text, "0302080104")
									lintPosFim = InStr(lintPosIni, Me.lblItensOut.Text, "$")
									lstrAuxOld = Mid(Me.lblItensOut.Text, lintPosIni, (lintPosFim - lintPosIni) + 1)
									lstrAuxNew = "0302080104?" & Replace(Replace(CStr(ldblIndMetaFic), ".", ""), ",", ".") & "$"
									Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrAuxOld, lstrAuxNew)
									'
									lintPosIni = InStr(1, Me.lblItensOut.Text, "0302080105")
									lintPosFim = InStr(lintPosIni, Me.lblItensOut.Text, "$")
									lstrAuxOld = Mid(Me.lblItensOut.Text, lintPosIni, (lintPosFim - lintPosIni) + 1)
									lstrAuxNew = "0302080105?" & Replace(Replace(CStr(ldblIndMetaMic), ".", ""), ",", ".") & "$"
									Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrAuxOld, lstrAuxNew)
									'
									lintPosIni = InStr(1, Me.lblItensOut.Text, "0302080001")
									lintPosFim = InStr(lintPosIni, Me.lblItensOut.Text, "$")
									lstrAuxOld = Mid(Me.lblItensOut.Text, lintPosIni, (lintPosFim - lintPosIni) + 1)
									lstrAuxNew = "0302080001?" & Replace(Replace(CStr(ldblIndRealDec), ".", ""), ",", ".") & "$"
									Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrAuxOld, lstrAuxNew)
									'
									lintPosIni = InStr(1, Me.lblItensOut.Text, "0302080002")
									lintPosFim = InStr(lintPosIni, Me.lblItensOut.Text, "$")
									lstrAuxOld = Mid(Me.lblItensOut.Text, lintPosIni, (lintPosFim - lintPosIni) + 1)
									lstrAuxNew = "0302080002?" & Replace(Replace(CStr(ldblIndRealFec), ".", ""), ",", ".") & "$"
									Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrAuxOld, lstrAuxNew)
									'
									lintPosIni = InStr(1, Me.lblItensOut.Text, "0302080003")
									lintPosFim = InStr(lintPosIni, Me.lblItensOut.Text, "$")
									lstrAuxOld = Mid(Me.lblItensOut.Text, lintPosIni, (lintPosFim - lintPosIni) + 1)
									lstrAuxNew = "0302080003?" & Replace(Replace(CStr(ldblIndRealDic), ".", ""), ",", ".") & "$"
									Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrAuxOld, lstrAuxNew)
									'
									lintPosIni = InStr(1, Me.lblItensOut.Text, "0302080004")
									lintPosFim = InStr(lintPosIni, Me.lblItensOut.Text, "$")
									lstrAuxOld = Mid(Me.lblItensOut.Text, lintPosIni, (lintPosFim - lintPosIni) + 1)
									lstrAuxNew = "0302080004?" & Replace(Replace(CStr(ldblIndRealFic), ".", ""), ",", ".") & "$"
									Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrAuxOld, lstrAuxNew)
									'
									lintPosIni = InStr(1, Me.lblItensOut.Text, "0302080005")
									lintPosFim = InStr(lintPosIni, Me.lblItensOut.Text, "$")
									lstrAuxOld = Mid(Me.lblItensOut.Text, lintPosIni, (lintPosFim - lintPosIni) + 1)
									lstrAuxNew = "0302080005?" & Replace(Replace(CStr(ldblIndRealMic), ".", ""), ",", ".") & "$"
									Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrAuxOld, lstrAuxNew)
									'
									lintPosIni = InStr(1, Me.lblItensOut.Text, "0302080097")
									lintPosFim = InStr(lintPosIni, Me.lblItensOut.Text, "$")
									lstrAuxOld = Mid(Me.lblItensOut.Text, lintPosIni, (lintPosFim - lintPosIni) + 1)
									lstrAuxNew = "0302080097?" & Replace(Replace(CStr(ldblIndVCM), ".", ""), ",", ".") & "$"
									Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrAuxOld, lstrAuxNew)
								End If
								Call .Close()
							End If
						End With
						Call .MoveNext()
						If Me.lblItensOut.Text <> Me.lblItensIn.Text Then
							lstrSql = ""
							lstrSql = lstrSql & "UPDATE " & lstrTabela & " SET `itensserv` = '" & Me.lblItensOut.Text & "' "
							lstrSql = lstrSql & " WHERE `mesano` = '" & lstrMesAno & "'"
							lstrSql = lstrSql & "   AND `numnf` = " & ldblNumeNf
							Call myConC.BeginTrans()
							Call Executar(lstrSql)
							Call myConC.CommitTrans()
						End If
						System.Windows.Forms.Application.DoEvents()
					End While
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
		'UPGRADE_NOTE: Object lrstAux2 may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux2 = Nothing
	End Sub
	
	Private Sub cmdArrumaItensMicroGeracao_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdArrumaItensMicroGeracao.Click
		Dim lstrMesAno As String
		Dim ldblNumeNf As Double
		'
		Dim ldblRevRes As Double
		Dim ldblRevLid As Double
		Dim ldblConLid As Double
		Dim ldblConFat As Double
		Dim ldblTarKwh As Double
		Dim ldblTarBan As Double
		Dim ldblRecKwh As Double
		Dim ldblRecBan As Double
		'
		Dim ldblUtiliz As Double
		'
		Dim lintPosIni As Short
		Dim lintPosFim As Short
		Dim lstrAuxOld As String
		Dim lstrAuxNew As String
		'
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		
		lstrSql = "SELECT * FROM `nf` WHERE mesano='11/2019' and grupo = 'B' and (micro_geracao = 1 or micro_geracao_distribuida = 1)"
		Call MDcomum.Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					While Not .EOF
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrMesAno = IIf(IsDbNull(.Fields("mesano").value), "", .Fields("mesano").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblNumeNf = IIf(IsDbNull(.Fields("numnf").value), 0, .Fields("numnf").value)
						'
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						Me.lblItensIn.Text = IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").value)
						Me.lblItensOut.Text = Me.lblItensIn.Text
						'
						ldblRevRes = BuscaValorItem(Me.lblItensIn.Text, "0302020997")
						ldblRevLid = BuscaValorItem(Me.lblItensIn.Text, "0302020996")
						ldblConLid = BuscaValorItem(Me.lblItensIn.Text, "030201008")
						ldblConFat = BuscaValorItem(Me.lblItensIn.Text, "030201009")
						'
						ldblTarKwh = CDbl(VB.Left(VB.Right(BuscaRefItem(Me.lblItensIn.Text, "0302020090"), 10), 8))
						ldblTarBan = CDbl(VB.Left(VB.Right(BuscaRefItem(Me.lblItensIn.Text, "0302120090"), 10), 8))
						
						ldblRecKwh = 0
						ldblRecBan = 0
						ldblUtiliz = 0
						If (ldblRevRes + ldblRevLid) > 0 Then
							If ldblConLid > ldblConFat Then
								ldblUtiliz = (ldblConLid - ldblConFat)
								ldblRecKwh = Arredondar(ldblUtiliz * ldblTarKwh, 2)
								ldblRecBan = Arredondar(ldblUtiliz * ldblTarBan, 2)
							End If
						End If
						lintPosIni = InStr(1, Me.lblItensOut.Text, "0302020994")
						If lintPosIni > 0 Then
							lintPosFim = InStr(lintPosIni, Me.lblItensOut.Text, ";")
							lstrAuxOld = Mid(Me.lblItensOut.Text, lintPosIni, (lintPosFim - lintPosIni) + 1)
							lstrAuxNew = "0302020994?" & Replace(Replace(CStr(ldblRecKwh), ".", ""), ",", ".") & ";"
							Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrAuxOld, lstrAuxNew)
							Me.lblItensOut.Refresh()
						Else
							Me.lblItensOut.Text = Me.lblItensOut.Text & "0302020994?" & Replace(Replace(CStr(ldblRecKwh), ".", ""), ",", ".") & ";"
						End If
						System.Windows.Forms.Application.DoEvents()
						
						lintPosIni = InStr(1, Me.lblItensOut.Text, "0302020993")
						If lintPosIni > 0 Then
							lintPosFim = InStr(lintPosIni, Me.lblItensOut.Text, ";")
							lstrAuxOld = Mid(Me.lblItensOut.Text, lintPosIni, (lintPosFim - lintPosIni) + 1)
							lstrAuxNew = "0302020993?" & Replace(Replace(CStr(ldblRecBan), ".", ""), ",", ".") & ";"
							Me.lblItensOut.Text = Replace(Me.lblItensOut.Text, lstrAuxOld, lstrAuxNew)
							Me.lblItensOut.Refresh()
						Else
							Me.lblItensOut.Text = Me.lblItensOut.Text & "0302020993?" & Replace(Replace(CStr(ldblRecBan), ".", ""), ",", ".") & ";"
						End If
						Me.lblItensOut.Text = Me.lblItensOut.Text & "0302020992?" & Replace(Replace(CStr(ldblUtiliz), ".", ""), ",", ".") & ";"
						
						System.Windows.Forms.Application.DoEvents()
						
						'Clipboard.Clear
						'Clipboard.SetText Me.lblItensIn.Caption & vbCrLf & vbCrLf & vbCrLf & Me.lblItensOut.Caption
						If Me.lblItensOut.Text <> Me.lblItensIn.Text Then
							lstrSql = ""
							lstrSql = lstrSql & "UPDATE nf SET `itensserv` = '" & Me.lblItensOut.Text & "' "
							lstrSql = lstrSql & " WHERE `mesano` = '" & lstrMesAno & "'"
							lstrSql = lstrSql & "   AND `numnf` = " & ldblNumeNf
							Call myConC.Execute(lstrSql)
						End If
						
						Call .MoveNext()
					End While
				End If
			End If
		End With
		Call MsgBox("OK")
		
	End Sub
	
	Private Sub cmdArrumaOcorrencia_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdArrumaOcorrencia.Click
		Dim ldblNumNf As Double
		Dim lstrMesAno As String
		Dim lstrItens As String
		Dim lstrNewItens As String
		Dim lstrSql As String
		Dim lintMedia As Short
		Dim lrstConsulta As ADODB.Recordset
		
		lrstConsulta = New ADODB.Recordset
		
		lstrSql = "SELECT numnf, mesano, itensserv " & "  FROM nf " & " WHERE nf.itensserv LIKE ""%90410000%"""
		Call Conectar(lstrSql, lrstConsulta)
		With lrstConsulta
			While Not .EOF
				If .RecordCount > 0 Then
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					ldblNumNf = IIf(IsDbNull(.Fields("numnf").value), 0, .Fields("numnf").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					lstrMesAno = IIf(IsDbNull(.Fields("mesano").value), "", .Fields("mesano").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					lstrItens = IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").value)
					Me.lblArrumaNumNF.Text = CStr(ldblNumNf)
					Call Me.lblArrumaNumNF.Refresh()
					Me.lblArrumaMesAno.Text = lstrMesAno
					Call Me.lblArrumaMesAno.Refresh()
					codserv = ""
					For IndCodServ = 1 To Len(Trim(lstrItens))
						VlrCodServ = CStr(0)
						Call BuscaCodItem(IndCodServ, Trim(lstrItens))
						Select Case Mid(codserv, 1, 4)
							Case CStr(9041)
								lintMedia = PegaOcorrMedia(codserv)
								lstrNewItens = Replace(lstrItens, codserv & "?" & VlrCodServ & "$" & RefCodServ, codserv & "?" & lintMedia & "$" & RefCodServ)
								lstrSql = "UPDATE nf " & "   SET itensserv = """ & lstrNewItens & """ " & " WHERE numnf = " & ldblNumNf & "   AND mesano = """ & lstrMesAno & """ "
								Call Executar(lstrSql)
						End Select
					Next IndCodServ
				End If
				Call .MoveNext()
				System.Windows.Forms.Application.DoEvents()
			End While
			If .State = 1 Then Call .Close()
		End With
	End Sub
	
	Private Function PegaOcorrMedia(ByVal astrCodigo As Object) As Short
		Dim lstrSql As String
		Dim lrstOcorr As ADODB.Recordset
		lrstOcorr = New ADODB.Recordset
		'UPGRADE_WARNING: Couldn't resolve default property of object astrCodigo. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
		lstrSql = "SELECT media FROM ocorrencias WHERE cod = """ & VB.Right(astrCodigo, 2) & """ LIMIT 0, 1 "
		Call Conectar(lstrSql, lrstOcorr)
		If lrstOcorr.RecordCount > 0 Then
			'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
			PegaOcorrMedia = IIf(IsDbNull(lrstOcorr.Fields("media").value), 0, lrstOcorr.Fields("media").value)
		Else
			PegaOcorrMedia = 0
		End If
		If lrstOcorr.State = 1 Then Call lrstOcorr.Close()
	End Function
	
	Private Sub cmdCalculoFatura_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCalculoFatura.Click
		Dim ifrmCalculoRefaturamento As FrmVerifContaGBNovo
		ifrmCalculoRefaturamento = New FrmVerifContaGBNovo
		Call ifrmCalculoRefaturamento.SetaParamentros("R")
		ifrmCalculoRefaturamento.Text = "Refaturamento"
		Call ifrmCalculoRefaturamento.Show()
	End Sub
	
	Private Sub cmdCancelaFatura_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCancelaFatura.Click
		Call frmCancelaNFNovo.Show()
	End Sub
	
	Private Sub cmdCarregar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCarregar.Click
		Dim lintCon As Short
		Dim lstrAux As String
		Dim lintARQ As Short
		Dim lstrLin As String
		Dim lstrZon As String
		Dim lstrLiv As String
		Dim lstrCon As String
		Dim ldblVlr As Double
		Dim ldblVlN As Double
		Dim ldblNNf As Double
		Dim lstrSql As String
		Dim ldblDif As Double
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lintARQ = FreeFile
		FileOpen(lintARQ, Me.txtArq.Text, OpenMode.Input)
		With Me.mfgDados
			.Clear()
			.Rows = 1
			.Redraw = False
			lintCon = 0
			While Not EOF(lintARQ)
				lstrLin = LineInput(lintARQ)
				lstrLin = Trim(lstrLin)
				lstrAux = ""
				If Len(lstrLin) > 0 Then
					If VB.Left(lstrLin, 1) = "F" Then
						lintCon = lintCon + 1
						lstrZon = Mid(lstrLin, 2, 3)
						lstrLiv = Mid(lstrLin, 5, 2)
						ldblNNf = CDbl(Trim(Mid(lstrLin, 383, 5)))
						lstrCon = "00" & Mid(lstrLin, 7, 4)
						'          ldblVlr = CDbl(Mid(lstrLin, 313, 17))
						'          lstrSql = ""
						'          lstrSql = lstrSql & "SELECT zona,livr,conta, mesano_ref "
						'          lstrSql = lstrSql & "  FROM nf  "
						'          lstrSql = lstrSql & " WHERE nf.zona  = '" & lstrZon & "' "
						'          lstrSql = lstrSql & "   AND nf.livro = '" & lstrLiv & "' "
						'          lstrSql = lstrSql & "   AND nf.conta = '" & lstrCon & "' "
						'          lstrSql = lstrSql & "   AND nf.mesano_ref = 201108 "
						'          Call Conectar(lstrSql, lrstAux)
						'          With lrstAux
						'            If .State > 0 Then
						'              If .RecordCount > 0 Then
						'                ldblVlN = CDbl(IIf(IsNull(.Fields("valorliq").Value), 0, .Fields("valorliq").Value))
						'              End If
						'              Call .Close
						'            End If
						'          End With
						'          ldblDif = (ldblVlr - ldblVlN)
						'          If ldblDif <> 0 Then
						.Rows = .Rows + 1
						.set_TextMatrix(.Rows - 1, 0, lstrZon)
						.set_TextMatrix(.Rows - 1, 1, lstrLiv)
						.set_TextMatrix(.Rows - 1, 2, lstrCon)
						.set_TextMatrix(.Rows - 1, 3, ldblNNf)
						'.TextMatrix(.Rows - 1, 4) = ldblVlN
						'.TextMatrix(.Rows - 1, 5) = ldblDif
						'          End If
						Me.lblContArq.Text = CStr(lintCon)
						Me.lblContArq.Refresh()
					End If
				End If
				System.Windows.Forms.Application.DoEvents()
			End While
			.Redraw = True
		End With
		FileClose(lintARQ)
		
	End Sub
	
	Private Sub cmdCarregarCergal_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCarregarCergal.Click
		Dim lintCon As Short
		Dim lstrAux As String
		Dim lintARQ As Short
		Dim lstrLin As String
		Dim lstrZon As String
		Dim lstrLiv As String
		Dim lstrCon As String
		Dim lstrRot As String
		Dim ldblVlr As Double
		Dim ldblVlN As Double
		Dim lstrSql As String
		Dim ldblDif As Double
		Dim llngRow As Integer
		Dim llngPos As Integer
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lintARQ = FreeFile
		FileOpen(lintARQ, Me.txtArq.Text, OpenMode.Input)
		With Me.mfgDados
			.Clear()
			.Rows = 1
			.Redraw = False
			lintCon = 0
			While Not EOF(lintARQ)
				lstrLin = LineInput(lintARQ)
				lstrLin = Trim(lstrLin)
				lstrAux = ""
				If Len(lstrLin) > 0 Then
					If VB.Left(lstrLin, 1) = "F" Then
						lintCon = lintCon + 1
						lstrZon = Mid(lstrLin, 2, 3)
						lstrLiv = Mid(lstrLin, 5, 2)
						lstrCon = Mid(lstrLin, 7, 6)
						lstrRot = Mid(lstrLin, 595, 2)
						llngPos = 0
						If .Rows > 1 Then
							For llngRow = 1 To .Rows - 1
								If .get_TextMatrix(llngRow, 0) = lstrRot Then
									llngPos = llngRow
									llngRow = .Rows - 1
								End If
							Next llngRow
						End If
						If llngPos = 0 Then
							.Rows = .Rows + 1
							llngPos = .Rows - 1
							.set_TextMatrix(llngPos, 0, lstrRot)
						End If
						.set_TextMatrix(llngPos, 1, CInt(IIf(.get_TextMatrix(llngPos, 1) = "", 0, .get_TextMatrix(llngPos, 1))) + 1)
						Me.lblContArq.Text = CStr(lintCon)
						Me.lblContArq.Refresh()
					End If
				End If
				System.Windows.Forms.Application.DoEvents()
			End While
			.Redraw = True
			.Col = 0
			.Sort = MSFlexGridLib.SortSettings.flexSortNumericAscending
		End With
		FileClose(lintARQ)
		
	End Sub
	
	Private Sub cmdCarregarExporta_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCarregarExporta.Click
		Dim lstrLin As String
		Dim lintARQ As Short
		Dim llngRow As Integer
		Dim llngCol As Integer
		lintARQ = FreeFile
		FileOpen(lintARQ, "E:\atuallizacao\Faturas.txt", OpenMode.Output)
		With Me.mfgDados
			For llngRow = 0 To .Rows - 1
				lstrLin = ""
				For llngCol = 0 To .Cols - 1
					lstrLin = lstrLin & .get_TextMatrix(llngRow, llngCol) & ";"
				Next llngCol
				PrintLine(lintARQ, lstrLin)
			Next llngRow
		End With
		FileClose(lintARQ)
	End Sub
	
	Private Sub cmdCodBarras_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCodBarras.Click
		Call frmRelExtratoConsumidor.Show()
		'  Dim lstrbarras As String
		'  Dim lstrdigito As String
		'  Call MontaCodBarras(6275, "04/2015", 1477.06, "001", "02", "000020", lstrbarras, lstrdigito)
		'  Call MsgBox("Barras: " & lstrbarras & vbCrLf & "digito: " & lstrdigito)
		'  Clipboard.Clear
		'  Clipboard.SetText lstrbarras & vbCrLf & " " & lstrdigito
	End Sub
	
	Private Sub cmdDesenho_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdDesenho.Click
		Dim lstrLin As String
		Dim llngY1 As Integer
		Dim llngY2 As Integer
		Dim llngX1 As Integer
		Dim llngX2 As Integer
		Dim llngAux1 As Integer
		Dim llngAux2 As Integer
		Dim lstrTeste As String
		Dim lfrmRelDesenho As FrmRelatorio
		lfrmRelDesenho = New FrmRelatorio
		With lfrmRelDesenho
			.quem_chama = Me
			With .VS
				.Font = VB6.FontChangeSize(.Font, 9)
				.TableBorder = VSVIEW6.TableBorderSettings.tbNone
				.PageBorder = VSVIEW6.PageBorderSettings.pbNone
				.ShowGuides = VSVIEW6.ShowGuideSettings.gdShow
				.Orientation = VSVIEW6.OrientationSettings.orLandscape
				.PhysicalPage = True
				.PaperSize = VSVIEW6.PaperSizeSettings.pprA4
				.MarginTop = "7mm"
				.MarginRight = "7mm"
				.MarginLeft = "7mm"
				.MarginBottom = "5mm"
				.MarginFooter = "0mm"
				.MarginHeader = "0mm"
				.TextColor = System.Drawing.Color.Black
				.BrushStyle = VSVIEW6.BrushStyleSettings.bsSolid
				.Font = VB6.FontChangeBold(.Font, False)
				Call .StartDoc()
				'x = coluna
				'y = linha
				'Call .DrawLine(3100, 3000, 3100, 5000)
			End With
		End With
		
		
		FileOpen(1, "E:\Teste.txt", OpenMode.Input)
		While Not EOF(1)
			Input(1, lstrLin)
			If CInt(Len(lstrLin)) > 0 Then
				If VB.Left(lstrLin, 2) <> "\\" Then
					llngAux1 = CInt(InStr(1, lstrLin, ";"))
					llngX1 = CInt(Mid(lstrLin, 1, llngAux1 - 1))
					llngAux2 = CInt(InStr(llngAux1 + 1, lstrLin, ";")) - llngAux1
					llngX2 = CInt(Mid(lstrLin, llngAux1 + 1, llngAux2 - 1))
					llngAux1 = llngAux1 + llngAux2
					llngAux2 = CInt(InStr(llngAux1 + 1, lstrLin, ";")) - llngAux1
					llngY1 = CInt(Mid(lstrLin, llngAux1 + 1, llngAux2 - 1))
					llngAux1 = llngAux1 + llngAux2
					llngAux2 = CInt(InStr(llngAux1 + 1, lstrLin, ";")) - llngAux1
					llngY2 = CInt(Mid(lstrLin, llngAux1 + 1, llngAux2 - 1))
					Call lfrmRelDesenho.VS.DrawLine(llngX1, llngY1, llngX2, llngY2)
				End If
			End If
		End While
		FileClose(1)
		lfrmRelDesenho.VS.Zoom = 150
		Call lfrmRelDesenho.VS.EndDoc()
		Call lfrmRelDesenho.Show()
		
		'UPGRADE_NOTE: Object lfrmRelDesenho may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lfrmRelDesenho = Nothing
		
	End Sub
	
	Private Sub cmdFaltouFatura_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFaltouFatura.Click
		Dim llngAux As Integer
		Dim lstrAux As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		With Me.mfgDados
			lstrAux = ""
			For llngAux = 1 To .Rows - 1
				lstrAux = lstrAux & .get_TextMatrix(llngAux, 3) & ","
			Next llngAux
		End With
		lstrAux = VB.Left(lstrAux, Len(lstrAux) - 1)
		lstrSql = ""
		lstrSql = lstrSql & "SELECT zona,livro,conta, mesano_ref,numnf "
		lstrSql = lstrSql & "  FROM nf  "
		lstrSql = lstrSql & " WHERE nf.mesano_ref = 201108 "
		lstrSql = lstrSql & "   AND nf.numnf NOT IN(" & lstrAux & ") "
		lstrSql = lstrSql & "   AND left(nf.rota,2)='20' "
		Call Conectar(lstrSql, lrstAux)
		lstrAux = ""
		With lrstAux
			If .State > 0 Then
				If .RecordCount > 0 Then
					While Not .EOF
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrAux = lstrAux & IIf(IsDbNull(.Fields("livro").value), "", .Fields("livro").value) & IIf(IsDbNull(.Fields("conta").value), "", .Fields("conta").value) & ", "
						Call .MoveNext()
					End While
				End If
				Call .Close()
			End If
		End With
	End Sub
	
	Private Sub cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click
		Me.Close()
	End Sub
	
	Private Sub cmdGravaMenus_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdGravaMenus.Click
		Dim lstrCap As String
		Dim lstrNam As String
		Dim lstrSql As String
		Dim vcontrole As Object
		lstrSql = "drop table IF EXISTS tabela_menu "
		Call Executar(lstrSql)
		lstrSql = "create table tabela_menu (`id` int(11) NOT NULL auto_increment, old_name varchar(255) default null, old_descr varchar(255) default null, new_name varchar(255) default null, new_descr varchar(255) default null, PRIMARY KEY  (`id`))"
		Call Executar(lstrSql)
		lstrSql = ""
		lstrSql = lstrSql & "INSERT INTO tabela_menu(old_name,old_descr) VALUES "
		For	Each vcontrole In FrmAtPrincipal.Controls
			If TypeOf vcontrole Is System.Windows.Forms.ToolStripMenuItem Then
				'UPGRADE_WARNING: Couldn't resolve default property of object vcontrole.Caption. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				lstrCap = Str_Retira(vcontrole.Caption, "&")
				'UPGRADE_WARNING: Couldn't resolve default property of object vcontrole.Name. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				lstrNam = vcontrole.Name
				If lstrCap <> "" And lstrCap <> "-" Then
					lstrSql = lstrSql & "('" & lstrNam & "','" & lstrCap & "'),"
				End If
			End If
		Next vcontrole
		lstrSql = VB.Left(lstrSql, Len(lstrSql) - 1)
		Call Executar(lstrSql)
		Call MsgBox("OK")
	End Sub
	
	Private Sub cmdImportaCoordenadas_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdImportaCoordenadas.Click
		Dim lstrLatitude As String
		Dim lstrLongitude As String
		Dim lstrZLC As String
		Dim lintPosLatitude As Short
		Dim lintPosLongitude As Short
		Dim lintPosZlc As Short
		Dim llngRow As Integer
		Dim llngNRows As Integer
		Dim larrItens() As String
		Dim lstrLinha As String
		Dim lintARQ As Short
		Dim lstrArq As String
		Dim lintAux As Short
		Dim lstrSql As String
		On Error GoTo ErroImportaCSV
		lintPosLatitude = 0
		lintPosLongitude = 0
		lintPosZlc = 0
		lstrArq = txtArq1.Text
		llngNRows = getNumRows(Me.txtArq1.Text)
		llngRow = 0
		If (llngNRows > 1) Then
			Call Executar("START TRANSACTION",  ,  ,  , False)
			Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, llngNRows - 1)
			'Abre arquivo externo
			lintARQ = FreeFile
			FileOpen(lintARQ, lstrArq, OpenMode.Input)
			While Not EOF(lintARQ)
				'Passa os dados da linha atual para variável lstrLinha
				lstrLinha = LineInput(lintARQ)
				'Retira os espaços desnecessários
				lstrLinha = Trim(lstrLinha)
				'Transforma em um array
				larrItens = TrataCSV(lstrLinha)
				llngRow = llngRow + 1
				If llngRow = 1 Then
					'Pega as posições de cada coluna
					For lintAux = LBound(larrItens) To UBound(larrItens)
						Select Case LCase(larrItens(lintAux))
							Case Is = "longitude" : lintPosLongitude = lintAux
							Case Is = "latitude" : lintPosLatitude = lintAux
							Case Is = "poi" : lintPosZlc = lintAux
						End Select
					Next lintAux
				Else
					If lintPosLongitude < 9999 Then lstrLatitude = IIf(IsNumeric(larrItens(lintPosLongitude)), larrItens(lintPosLongitude), 0) Else  : lstrLatitude = ""
					If lintPosLatitude < 9999 Then lstrLongitude = IIf(IsNumeric(larrItens(lintPosLatitude)), larrItens(lintPosLatitude), 0) Else  : lstrLongitude = ""
					If lintPosZlc < 9999 Then lstrZLC = IIf(IsNumeric(larrItens(lintPosZlc)), larrItens(lintPosZlc), 0) Else  : lstrZLC = ""
					lstrSql = ""
					lstrSql = lstrSql & "UPDATE falcon_eflul.consumidor_lt SET "
					lstrSql = lstrSql & "       latidude = '" & lstrLatitude & "', "
					lstrSql = lstrSql & "       longitude = '" & lstrLongitude & "' "
					lstrSql = lstrSql & " WHERE conta = '" & lstrZLC & "' "
					Call Executar(lstrSql,  ,  ,  , False)
				End If
				Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
			End While
			FileClose(lintARQ)
			Call Executar("COMMIT",  ,  ,  , False)
		End If
ErroImportaCSV: 
		If myConC.Errors.Count > 0 Then
			Call MsgBox("Código: " & myConC.Errors.Item(myConC.Errors.Count - 1).NativeError & vbCrLf & "Descrição: " & myConC.Errors.Item(myConC.Errors.Count - 1).Description, MsgBoxStyle.Critical, gstrTituloMensagem)
			Call Executar("ROLLBACK",  ,  ,  , False)
		ElseIf Err.Number > 0 Then 
			Call MsgBox(Err.Number & " - " & GetErrosVB(Err.Number, Err.Description), MsgBoxStyle.Information, gstrTituloMensagem)
			Call Executar("ROLLBACK",  ,  ,  , False)
		End If
		
	End Sub
	
	Private Function TrataCSV(ByVal astrLinha As String) As String()
		Dim larrItens() As String
		Dim lstrTemp As String
		Dim lintAux As Short
		Dim lblnAspa As Boolean
		On Error GoTo ErrogetTrataCSV
		lblnAspa = False
		lstrTemp = ""
		larrItens = Split(astrLinha, ";")
		For lintAux = 0 To UBound(larrItens)
			If Not lblnAspa Then
				If (VB.Left(larrItens(lintAux), 1) = """" And VB.Right(larrItens(lintAux), 1) = """") Or (VB.Left(larrItens(lintAux), 1) <> """" And VB.Right(larrItens(lintAux), 1) <> """") Then
					lstrTemp = lstrTemp & "$$$" & Replace(larrItens(lintAux), """", "")
				ElseIf VB.Left(larrItens(lintAux), 1) = """" Then 
					lblnAspa = True
					lstrTemp = lstrTemp & "$$$" & Replace(larrItens(lintAux), """", "")
				End If
			Else
				lstrTemp = lstrTemp & "," & Replace(larrItens(lintAux), """", "")
				If VB.Right(larrItens(lintAux), 1) = """" Then lblnAspa = False
			End If
		Next 
		TrataCSV = Split(IIf(VB.Left(lstrTemp, 3) = "$$$", VB.Right(lstrTemp, Len(lstrTemp) - 3), ""), "$$$")
ErrogetTrataCSV: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & GetErrosVB(Err.Number, Err.Description), MsgBoxStyle.Information, gstrTituloMensagem)
		End If
	End Function
	
	Private Function getNumRows(ByVal astrFile As String) As Integer
		Dim lintARQ As Short
		Dim llngRows As Integer
		Dim lstrTemp As String
		On Error GoTo ErrogetNumRows
		llngRows = 0
		lintARQ = FreeFile
		FileOpen(lintARQ, astrFile, OpenMode.Input)
		While Not EOF(lintARQ)
			lstrTemp = LineInput(lintARQ)
			llngRows = llngRows + 1
			System.Windows.Forms.Application.DoEvents()
		End While
ErrogetNumRows: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & GetErrosVB(Err.Number, Err.Description), MsgBoxStyle.Information, gstrTituloMensagem)
		End If
		FileClose(lintARQ)
		getNumRows = llngRows
	End Function
	
	Private Sub cmdIp_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdIp.Click
		'  Dim IpAddrs
		'Me.txtIP.Text = Winsock1.LocalIP
		'Me.txtIP.Text = Winsock1.RemoteHostIP
		'  IpAddrs = GetIpAddrTable
		'  Me.txtIP.Text = "Nr of IP addresses: " & UBound(IpAddrs) - LBound(IpAddrs) + 1
		'  Dim I As Integer
		'  For I = LBound(IpAddrs) To UBound(IpAddrs)
		'     Me.txtIP.Text = Me.txtIP.Text & vbCrLf & IpAddrs(I)
		'  Next
	End Sub
	
	Private Sub cmdMicroGeracao_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdMicroGeracao.Click
		Dim ldblNumNf As Double
		Dim llngAnoMes As Integer
		Dim lstrItens As String
		Dim llngConsId As Integer
		Dim llngUnidId As Integer
		Dim lstrZona As String
		Dim lstrConta As String
		Dim lstrLivro As String
		Dim lstrGrupo As String
		Dim lstrGruTar As String
		Dim lstrFase As String
		Dim lstrClasse As String
		Dim ldteLeituraAtual As Date
		Dim ldteLeituraAntes As Date
		Dim ldtePagamento As Date
		Dim lintTarifaBranca As Short
		Dim lintMicroGeracaoDistribuida As Short
		Dim lintMicroGeracaoConvenioSefaz As Short
		Dim lintCustoDisponibilidade As Short
		'Leitura Normal
		Dim lstrNLeituraAtual_P As String
		Dim lstrNLeituraAntes_P As String
		Dim lstrNLeituraAtual_I As String
		Dim lstrNLeituraAntes_I As String
		Dim lstrNLeituraAtual_F As String
		Dim lstrNLeituraAntes_F As String
		'Leitura Micro Geracao
		Dim lstrMLeituraAtual_P As String
		Dim lstrMLeituraAntes_P As String
		Dim lstrMLeituraAtual_I As String
		Dim lstrMLeituraAntes_I As String
		Dim lstrMLeituraAtual_F As String
		Dim lstrMLeituraAntes_F As String
		'Constantes
		Dim ldblConstante_P As Double
		Dim ldblConstante_I As Double
		Dim ldblConstante_F As Double
		'Consumo Lido
		Dim ldblNConsumo_L_P As Double
		Dim ldblNConsumo_L_I As Double
		Dim ldblNConsumo_L_F As Double
		'Consumo Faturado
		Dim ldblNConsumo_F_P As Double
		Dim ldblNConsumo_F_I As Double
		Dim ldblNConsumo_F_F As Double
		'Consumo Lido Real
		Dim ldblNConsumo_R_P As Double
		Dim ldblNConsumo_R_I As Double
		Dim ldblNConsumo_R_F As Double
		'Residuo de Consumo
		Dim ldblRConsumo_P As Double
		Dim ldblRConsumo_I As Double
		Dim ldblRConsumo_F As Double
		'Reverso Micro Geracao
		Dim ldblMConsumo_P As Double
		Dim ldblMConsumo_I As Double
		Dim ldblMConsumo_F As Double
		'Reverso Residuo
		Dim ldblMResiduo_P As Double
		Dim ldblMResiduo_I As Double
		Dim ldblMResiduo_F As Double
		'Residuo Utilizado
		Dim ldblMUtilizado_P As Double
		Dim ldblMUtilizado_I As Double
		Dim ldblMUtilizado_F As Double
		'Tarifa Consumo
		Dim ldblTarifa_kWh_P As Double
		Dim ldblTarifa_kWh_I As Double
		Dim ldblTarifa_kWh_F As Double
		'Tarifa Bandeira
		Dim ldblTarifa_Ban_P As Double
		Dim ldblTarifa_Ban_I As Double
		Dim ldblTarifa_Ban_F As Double
		'
		Dim ldblId As Double
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		Dim lrstReg As ADODB.Recordset
		
		lrstAux = New ADODB.Recordset
		lrstReg = New ADODB.Recordset
		
		Call myConC.Execute("DROP TRIGGER IF EXISTS `tbi_micro_geracao_movto`")
		Call myConC.Execute("DROP TABLE IF EXISTS `micro_geracao_movto`")
		
		Call myConC.Execute("DROP TABLE IF EXISTS `micro_geracao`")
		
		lstrSql = ""
		lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS `micro_geracao` ("
		lstrSql = lstrSql & "  `id` int(11) NOT NULL AUTO_INCREMENT,"
		lstrSql = lstrSql & "  `grupo` char(1) NOT NULL DEFAULT 'B',"
		lstrSql = lstrSql & "  `grutar` char(2) NOT NULL DEFAULT 'B',"
		lstrSql = lstrSql & "  `fase` char(1) NOT NULL DEFAULT 'M',"
		lstrSql = lstrSql & "  `classe` varchar(4) NOT NULL DEFAULT '0000',"
		lstrSql = lstrSql & "  `cons_id` int(11) NOT NULL DEFAULT '0',"
		lstrSql = lstrSql & "  `unid_id` int(11) NOT NULL DEFAULT '0',"
		lstrSql = lstrSql & "  `zona` char(3) NOT NULL DEFAULT '000',"
		lstrSql = lstrSql & "  `livro` char(2) NOT NULL DEFAULT '00',"
		lstrSql = lstrSql & "  `conta` char(6) NOT NULL DEFAULT '000000',"
		'
		lstrSql = lstrSql & "  `micro_geracao_distribuida` int(11) DEFAULT '0',"
		lstrSql = lstrSql & "  `micro_geracao_convenio_sefaz` int(11) DEFAULT '0',"
		'
		lstrSql = lstrSql & "  `dt_leitura_atual` date DEFAULT '0000-00-00',"
		lstrSql = lstrSql & "  `dt_leitura_antes` date DEFAULT '0000-00-00',"
		lstrSql = lstrSql & "  `dt_validade` date DEFAULT '0000-00-00',"
		'Micro Geração Leitura
		lstrSql = lstrSql & "  `leitura_atual_p` double DEFAULT '0',"
		lstrSql = lstrSql & "  `leitura_antes_p` double DEFAULT '0',"
		lstrSql = lstrSql & "  `leitura_atual_i` double DEFAULT '0',"
		lstrSql = lstrSql & "  `leitura_antes_i` double DEFAULT '0',"
		lstrSql = lstrSql & "  `leitura_atual_f` double DEFAULT '0',"
		lstrSql = lstrSql & "  `leitura_antes_f` double DEFAULT '0',"
		'Constante
		lstrSql = lstrSql & "  `constante_p` double DEFAULT '0',"
		lstrSql = lstrSql & "  `constante_i` double DEFAULT '0',"
		lstrSql = lstrSql & "  `constante_f` double DEFAULT '0',"
		'Injetado
		lstrSql = lstrSql & "  `injetado_p` double DEFAULT '0',"
		lstrSql = lstrSql & "  `injetado_i` double DEFAULT '0',"
		lstrSql = lstrSql & "  `injetado_f` double DEFAULT '0',"
		'Residuo
		lstrSql = lstrSql & "  `residuo_p` double DEFAULT '0',"
		lstrSql = lstrSql & "  `residuo_i` double DEFAULT '0',"
		lstrSql = lstrSql & "  `residuo_f` double DEFAULT '0',"
		'Injetado Utilizado
		lstrSql = lstrSql & "  `utilizado_p` double DEFAULT '0',"
		lstrSql = lstrSql & "  `utilizado_i` double DEFAULT '0',"
		lstrSql = lstrSql & "  `utilizado_f` double DEFAULT '0',"
		'Tarifa kWh
		lstrSql = lstrSql & "  `tarifa_kwh_p` double DEFAULT '0',"
		lstrSql = lstrSql & "  `tarifa_kwh_i` double DEFAULT '0',"
		lstrSql = lstrSql & "  `tarifa_kwh_f` double DEFAULT '0',"
		'Tarifa Ban
		lstrSql = lstrSql & "  `tarifa_ban_p` double DEFAULT '0',"
		lstrSql = lstrSql & "  `tarifa_ban_i` double DEFAULT '0',"
		lstrSql = lstrSql & "  `tarifa_ban_f` double DEFAULT '0',"
		'Valor Injetado Utilizado
		lstrSql = lstrSql & "  `vlr_utilizado_p` double DEFAULT '0',"
		lstrSql = lstrSql & "  `vlr_utilizado_i` double DEFAULT '0',"
		lstrSql = lstrSql & "  `vlr_utilizado_f` double DEFAULT '0',"
		'
		lstrSql = lstrSql & "  `anomes_referencia` int(6) DEFAULT '0',"
		'Saldo Atualizado no Encerramento Mensal
		lstrSql = lstrSql & "  `saldo_p` double DEFAULT '0',"
		lstrSql = lstrSql & "  `saldo_i` double DEFAULT '0',"
		lstrSql = lstrSql & "  `saldo_f` double DEFAULT '0',"
		'
		lstrSql = lstrSql & "  `vlr_saldo_p` double DEFAULT '0',"
		lstrSql = lstrSql & "  `vlr_saldo_i` double DEFAULT '0',"
		lstrSql = lstrSql & "  `vlr_saldo_f` double DEFAULT '0',"
		
		
		lstrSql = lstrSql & "  PRIMARY KEY (`id`),"
		lstrSql = lstrSql & "  KEY `idx_cons_id` (`cons_id`),"
		lstrSql = lstrSql & "  KEY `idx_unid_id` (`unid_id`),"
		lstrSql = lstrSql & "  KEY `idx_zona` (`zona`),"
		lstrSql = lstrSql & "  KEY `idx_livro` (`livro`),"
		lstrSql = lstrSql & "  KEY `idx_conta` (`conta`),"
		lstrSql = lstrSql & "  KEY `idx_dt_leitura_atual` (`dt_leitura_atual`),"
		lstrSql = lstrSql & "  KEY `idx_dt_leitura_antes` (`dt_leitura_antes`),"
		lstrSql = lstrSql & "  KEY `idx_dt_validade` (`dt_validade`),"
		lstrSql = lstrSql & "  KEY `idx_anomes_referencia` (`anomes_referencia`),"
		lstrSql = lstrSql & "  KEY `idx_grupo` (`grupo`),"
		lstrSql = lstrSql & "  KEY `idx_classe` (`classe`),"
		lstrSql = lstrSql & "  KEY `idx_fase` (`fase`)"
		lstrSql = lstrSql & ") ENGINE=InnoDB DEFAULT CHARSET=latin1"
		Call myConC.Execute(lstrSql)
		lstrSql = "CREATE TABLE `micro_geracao_movto`("
		lstrSql = lstrSql & " `id` bigint(1) AUTO_INCREMENT,"
		lstrSql = lstrSql & " `id_micro_geracao_controle` int(11) DEFAULT 0,"
		lstrSql = lstrSql & " `dt_movimento` date NOT NULL DEFAULT '0000-00-00',"
		'Se foi a Crédito ou a Débito pra U.C. (0 ou 1)
		lstrSql = lstrSql & " `unidade` tinyint(1) NOT NULL DEFAULT '0',"
		'Caso o Saldo do Injeto Vence é feito lançamento para zerar o saldo do injetado sendo a crédito da distribuidora (0 ou 1)
		lstrSql = lstrSql & " `distribuidora` tinyint(1) NOT NULL DEFAULT '0',"
		'Dados da U.C.
		lstrSql = lstrSql & " `grupo` char(1) NOT NULL DEFAULT 'B',"
		lstrSql = lstrSql & " `grutar` char(2) NOT NULL DEFAULT 'B',"
		lstrSql = lstrSql & " `cons_id` int(11) NOT NULL DEFAULT 0,"
		lstrSql = lstrSql & " `unid_id` int(11) NOT NULL DEFAULT 0,"
		lstrSql = lstrSql & " `zona` char(3) NOT NULL DEFAULT '000',"
		lstrSql = lstrSql & " `livro` char(2) NOT NULL DEFAULT '00',"
		lstrSql = lstrSql & " `conta` char(6) NOT NULL DEFAULT '000000',"
		lstrSql = lstrSql & " `fase` char(1) NOT NULL DEFAULT 'M',"
		lstrSql = lstrSql & " `classe` varchar(4) NOT NULL DEFAULT '0000',"
		'Crédito(+) ou Débito(-) dos kWh Injetados
		lstrSql = lstrSql & " `kwh_p` double(14,5) NOT NULL DEFAULT '0.00000',"
		lstrSql = lstrSql & " `kwh_i` double(14,5) NOT NULL DEFAULT '0.00000',"
		lstrSql = lstrSql & " `kwh_f` double(14,5) NOT NULL DEFAULT '0.00000',"
		'Dados de faturamento
		lstrSql = lstrSql & " `anomes_faturado` int(11) NOT NULL DEFAULT 0,"
		lstrSql = lstrSql & " `dt_leitura_atual` date DEFAULT '0000-00-00',"
		lstrSql = lstrSql & " `dt_leitura_antes` date DEFAULT '0000-00-00',"
		lstrSql = lstrSql & " `dt_pagamento` date DEFAULT '0000-00-00',"
		'Leituras
		lstrSql = lstrSql & " `leitura_atual_p` double DEFAULT '0',"
		lstrSql = lstrSql & " `leitura_antes_p` double DEFAULT '0',"
		lstrSql = lstrSql & " `leitura_atual_i` double DEFAULT '0',"
		lstrSql = lstrSql & " `leitura_antes_i` double DEFAULT '0',"
		lstrSql = lstrSql & " `leitura_atual_f` double DEFAULT '0',"
		lstrSql = lstrSql & " `leitura_antes_f` double DEFAULT '0',"
		'Constantes
		lstrSql = lstrSql & " `constante_p` double DEFAULT '0',"
		lstrSql = lstrSql & " `constante_i` double DEFAULT '0',"
		lstrSql = lstrSql & " `constante_f` double DEFAULT '0',"
		'Consumo Lido
		lstrSql = lstrSql & " `kwh_lido_p` double(14,5) NOT NULL DEFAULT '0.00000',"
		lstrSql = lstrSql & " `kwh_lido_i` double(14,5) NOT NULL DEFAULT '0.00000',"
		lstrSql = lstrSql & " `kwh_lido_f` double(14,5) NOT NULL DEFAULT '0.00000',"
		'Residuo de Consumo
		lstrSql = lstrSql & " `kwh_residuo_p` double(14,5) NOT NULL DEFAULT '0.00000',"
		lstrSql = lstrSql & " `kwh_residuo_i` double(14,5) NOT NULL DEFAULT '0.00000',"
		lstrSql = lstrSql & " `kwh_residuo_f` double(14,5) NOT NULL DEFAULT '0.00000',"
		'Se foi pelo custo de disponibilidade (0 ou 1)
		lstrSql = lstrSql & " `custo_disponibilidade` tinyint(1) NOT NULL DEFAULT '0',"
		'Consumo Faturado
		lstrSql = lstrSql & " `kwh_faturado_p` double(14,5) NOT NULL DEFAULT '0.00000',"
		lstrSql = lstrSql & " `kwh_faturado_i` double(14,5) NOT NULL DEFAULT '0.00000',"
		lstrSql = lstrSql & " `kwh_faturado_f` double(14,5) NOT NULL DEFAULT '0.00000',"
		'Tarifa Consumo
		lstrSql = lstrSql & " `tarifa_kwh_p` double(14,5) NOT NULL DEFAULT '0.00000',"
		lstrSql = lstrSql & " `tarifa_kwh_i` double(14,5) NOT NULL DEFAULT '0.00000',"
		lstrSql = lstrSql & " `tarifa_kwh_f` double(14,5) NOT NULL DEFAULT '0.00000',"
		'Tarifa Bandeira
		lstrSql = lstrSql & " `tarifa_ban_p` double(14,5) NOT NULL DEFAULT '0.00000',"
		lstrSql = lstrSql & " `tarifa_ban_i` double(14,5) NOT NULL DEFAULT '0.00000',"
		lstrSql = lstrSql & " `tarifa_ban_f` double(14,5) NOT NULL DEFAULT '0.00000',"
		'
		lstrSql = lstrSql & " PRIMARY KEY (`id`, `id_micro_geracao_controle`),"
		lstrSql = lstrSql & " KEY `idx_dt_movimento` (`dt_movimento`),"
		lstrSql = lstrSql & " KEY `idx_unidade` (`unidade`),"
		lstrSql = lstrSql & " KEY `idx_distribuidora` (`distribuidora`),"
		lstrSql = lstrSql & " KEY `idx_grupo` (`grupo`),"
		lstrSql = lstrSql & " KEY `idx_cons_id` (`cons_id`),"
		lstrSql = lstrSql & " KEY `idx_unid_id` (`unid_id`),"
		lstrSql = lstrSql & " KEY `idx_zona` (`zona`),"
		lstrSql = lstrSql & " KEY `idx_livro` (`livro`),"
		lstrSql = lstrSql & " KEY `idx_conta` (`conta`),"
		lstrSql = lstrSql & " KEY `idx_fase` (`fase`),"
		lstrSql = lstrSql & " KEY `idx_classe` (`classe`),"
		lstrSql = lstrSql & " KEY `idx_anomes_faturado` (`anomes_faturado`),"
		lstrSql = lstrSql & " KEY `idx_custo_disponibilidade` (`custo_disponibilidade`),"
		lstrSql = lstrSql & " KEY `ifk_id_micro_geracao_controle` (`id_micro_geracao_controle`),"
		lstrSql = lstrSql & " CONSTRAINT `fk_micro_geracao_movto_micro_geracao` FOREIGN KEY (`id_micro_geracao_controle`) REFERENCES `micro_geracao` (`id`)"
		lstrSql = lstrSql & ") ENGINE=InnoDB DEFAULT CHARSET=latin1"
		Call myConC.Execute(lstrSql)
		lstrSql = ""
		lstrSql = lstrSql & "CREATE DEFINER=`nss`@`%` TRIGGER `tbi_micro_geracao_movto` BEFORE INSERT ON `micro_geracao_movto`"
		lstrSql = lstrSql & "  FOR EACH ROW BEGIN   "
		lstrSql = lstrSql & "           DECLARE binId1 BIGINT;"
		lstrSql = lstrSql & "           DECLARE binId2 BIGINT;"
		lstrSql = lstrSql & "           SELECT AUTO_INCREMENT INTO binId1 FROM `information_schema`.`TABLES` WHERE `table_schema` = DATABASE() AND `table_name` = 'micro_geracao_movto';"
		lstrSql = lstrSql & "           SELECT IFNULL(MAX(`id`),0) + 1 INTO binId2 FROM `micro_geracao_movto` WHERE `id_micro_geracao_controle` = NEW.id_micro_geracao_controle;"
		lstrSql = lstrSql & "           IF (binId1 > binId2) THEN"
		lstrSql = lstrSql & "              SET NEW.id = binId2;"
		lstrSql = lstrSql & "           END IF;"
		lstrSql = lstrSql & "       END;"
		Call myConC.Execute(lstrSql)
		
		lstrSql = "SELECT * FROM `nf` WHERE `micro_geracao` = 1 or `micro_geracao_distribuida` = 1 ORDER BY `mesano_ref` ASC, `grupo` DESC, `cons_id` ASC, `unid_id` ASC"
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount)
					While Not .EOF
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblNumNf = IIf(IsDbNull(.Fields("numnf").value), 0, .Fields("numnf").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						llngAnoMes = IIf(IsDbNull(.Fields("mesano_ref").value), 0, .Fields("mesano_ref").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrItens = IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						llngConsId = IIf(IsDbNull(.Fields("cons_id").value), 0, .Fields("cons_id").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						llngUnidId = IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lintTarifaBranca = IIf(IsDbNull(.Fields("tarifa_branca").value), 0, .Fields("tarifa_branca").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrGrupo = IIf(IsDbNull(.Fields("grupo").value), "", .Fields("grupo").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrGruTar = Mid(IIf(IsDbNull(.Fields("ta").value), "01B100", .Fields("ta").value), 3, 2)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrZona = IIf(IsDbNull(.Fields("zona").value), "", .Fields("zona").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrLivro = IIf(IsDbNull(.Fields("livro").value), "", .Fields("livro").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrConta = IIf(IsDbNull(.Fields("conta").value), "", .Fields("conta").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrFase = IIf(IsDbNull(.Fields("fase").value), "", .Fields("fase").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrClasse = IIf(IsDbNull(.Fields("codclas").value), "", .Fields("codclas").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldteLeituraAtual = IIf(IsDbNull(.Fields("dataleit").value), "1900-01-01", .Fields("dataleit").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldteLeituraAntes = IIf(IsDbNull(.Fields("dataleitant").value), "1900-01-01", .Fields("dataleitant").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldtePagamento = IIf(IsDbNull(.Fields("datapag").value), "1900-01-01", .Fields("datapag").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lintMicroGeracaoDistribuida = IIf(IsDbNull(.Fields("micro_geracao_distribuida").value), 0, .Fields("micro_geracao_distribuida").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lintMicroGeracaoConvenioSefaz = IIf(IsDbNull(.Fields("micro_geracao_convenio_sefaz").value), 0, .Fields("micro_geracao_convenio_sefaz").value)
						
						'
						
						'            If lintTarifaBranca = 1 Then
						'              lstrNLeituraAtual_P = BuscaValorItem(lstrItens, "0302990062")
						'              lstrNLeituraAntes_P = BuscaValorItem(lstrItens, "0302990061")
						'              lstrNLeituraAtual_I = BuscaValorItem(lstrItens, "0302990064")
						'              lstrNLeituraAntes_I = BuscaValorItem(lstrItens, "0302990063")
						'              lstrNLeituraAtual_F = BuscaValorItem(lstrItens, "0302990066")
						'              lstrNLeituraAntes_F = BuscaValorItem(lstrItens, "0302990065")
						'            End If
						lintCustoDisponibilidade = 0
						If lstrGrupo = "B" Then
							'Leitura Consumo
							lstrNLeituraAtual_P = "0"
							lstrNLeituraAntes_P = "0"
							lstrNLeituraAtual_I = "0"
							lstrNLeituraAntes_I = "0"
							lstrNLeituraAtual_F = CStr(BuscaValorItem(lstrItens, "0302990039"))
							lstrNLeituraAntes_F = CStr(BuscaValorItem(lstrItens, "0302990040"))
							'Leitura Micro Geracao
							lstrMLeituraAtual_P = "0"
							lstrMLeituraAntes_P = "0"
							lstrMLeituraAtual_I = "0"
							lstrMLeituraAntes_I = "0"
							lstrMLeituraAtual_F = CStr(BuscaValorItem(lstrItens, "0302990049"))
							lstrMLeituraAntes_F = CStr(BuscaValorItem(lstrItens, "0302990050"))
							'Constantes
							ldblConstante_P = 0
							ldblConstante_I = 0
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							ldblConstante_F = IIf(IsDbNull(.Fields("const_med").value), 0, .Fields("const_med").value)
							'Injetado
							ldblMConsumo_P = 0
							ldblMConsumo_I = 0
							ldblMConsumo_F = BuscaValorItem(lstrItens, "0302020996")
							'Injetado Residuo
							ldblMResiduo_P = 0
							ldblMResiduo_I = 0
							ldblMResiduo_F = BuscaValorItem(lstrItens, "0302020997")
							'Injetado Utilizado
							ldblMUtilizado_P = 0
							ldblMUtilizado_I = 0
							ldblMUtilizado_F = BuscaValorItem(lstrItens, "0302020992")
							'Consumo Lido
							ldblNConsumo_L_P = 0
							ldblNConsumo_L_I = 0
							ldblNConsumo_L_F = BuscaValorItem(lstrItens, "030201008")
							'Consumo Faturado
							ldblNConsumo_F_P = 0
							ldblNConsumo_F_I = 0
							ldblNConsumo_F_F = BuscaValorItem(lstrItens, "030201009")
							'Consumo Reiduo
							ldblRConsumo_P = 0
							ldblRConsumo_I = 0
							ldblRConsumo_F = BuscaValorItem(lstrItens, "0302020998")
							
							Select Case lstrFase
								Case Is = "M"
									If ldblNConsumo_F_F <= 30 Then
										lintCustoDisponibilidade = 1
									Else
										lintCustoDisponibilidade = 0
									End If
								Case Is = "B"
									If ldblNConsumo_F_F <= 50 Then
										lintCustoDisponibilidade = 1
									Else
										lintCustoDisponibilidade = 0
									End If
								Case Is = "T"
									If ldblNConsumo_F_F <= 100 Then
										lintCustoDisponibilidade = 1
									Else
										lintCustoDisponibilidade = 0
									End If
								Case Else
									lintCustoDisponibilidade = 0
							End Select
							
							
							'Tarifa Consumo
							ldblTarifa_kWh_P = 0
							ldblTarifa_kWh_I = 0
							ldblTarifa_kWh_F = BuscaValorItem(lstrItens, "01" & lstrGruTar & "011101")
							If ldblTarifa_kWh_F = 0 Then
								ldblTarifa_kWh_F = BuscaValorItem(lstrItens, "01" & lstrGruTar & "301101")
							End If
							If ldblTarifa_kWh_F = 0 Then
								ldblTarifa_kWh_F = BuscaValorItem(lstrItens, "01" & lstrGruTar & "501101")
							End If
							If ldblTarifa_kWh_F = 0 Then
								ldblTarifa_kWh_F = BuscaValorItem(lstrItens, "01" & lstrGruTar & "401101")
							End If
							'Tarifa Bandeira
							ldblTarifa_Ban_P = 0
							ldblTarifa_Ban_I = 0
							ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "10" & lstrGruTar & "011101")
							If ldblTarifa_Ban_F = 0 Then
								ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "20" & lstrGruTar & "011101")
							End If
							If ldblTarifa_Ban_F = 0 Then
								ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "30" & lstrGruTar & "011101")
							End If
							
							If ldblTarifa_Ban_F = 0 Then
								ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "10" & lstrGruTar & "301101")
							End If
							If ldblTarifa_Ban_F = 0 Then
								ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "20" & lstrGruTar & "301101")
							End If
							If ldblTarifa_Ban_F = 0 Then
								ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "30" & lstrGruTar & "301101")
							End If
							
							If ldblTarifa_Ban_F = 0 Then
								ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "10" & lstrGruTar & "501101")
							End If
							If ldblTarifa_Ban_F = 0 Then
								ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "20" & lstrGruTar & "501101")
							End If
							If ldblTarifa_Ban_F = 0 Then
								ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "30" & lstrGruTar & "501101")
							End If
							
							If ldblTarifa_Ban_F = 0 Then
								ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "10" & lstrGruTar & "401101")
							End If
							If ldblTarifa_Ban_F = 0 Then
								ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "20" & lstrGruTar & "401101")
							End If
							If ldblTarifa_Ban_F = 0 Then
								ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "30" & lstrGruTar & "401101")
							End If
							
							
						ElseIf lstrGrupo = "A" Then 
							'Leitura Consumo
							lstrNLeituraAtual_P = CStr(BuscaValorItem(lstrItens, "0302040008"))
							lstrNLeituraAntes_P = CStr(BuscaValorItem(lstrItens, "0302040007"))
							lstrNLeituraAtual_I = "0"
							lstrNLeituraAntes_I = "0"
							lstrNLeituraAtual_F = CStr(BuscaValorItem(lstrItens, "0302040009"))
							lstrNLeituraAntes_F = CStr(BuscaValorItem(lstrItens, "0302040010"))
							'Leitura Micro Geracao
							lstrMLeituraAtual_P = CStr(BuscaValorItem(lstrItens, "0302040022"))
							lstrMLeituraAntes_P = CStr(BuscaValorItem(lstrItens, "0302040021"))
							lstrMLeituraAtual_I = "0"
							lstrMLeituraAntes_I = "0"
							lstrMLeituraAtual_F = CStr(BuscaValorItem(lstrItens, "0302040024"))
							lstrMLeituraAntes_F = CStr(BuscaValorItem(lstrItens, "0302040023"))
							'Constantes
							ldblConstante_P = Arredondar(BuscaValorItem(lstrItens, "0302020010") / IIf(BuscaValorItem(lstrItens, "0302010010") = 0, 1, BuscaValorItem(lstrItens, "0302010010")), 5)
							ldblConstante_I = 0
							ldblConstante_F = Arredondar(BuscaValorItem(lstrItens, "0302020011") / IIf(BuscaValorItem(lstrItens, "0302010011") = 0, 1, BuscaValorItem(lstrItens, "0302010011")), 5)
							If ldblConstante_F = 0 Then
								ldblConstante_F = ldblConstante_P
							End If
							If ldblConstante_P = 0 Then
								ldblConstante_P = ldblConstante_F
							End If
							If ldblConstante_P < ldblConstante_F Then
								ldblConstante_P = ldblConstante_F
							End If
							If ldblConstante_F < ldblConstante_P Then
								ldblConstante_F = ldblConstante_P
							End If
							'Injetado
							ldblMConsumo_P = BuscaValorItem(lstrItens, "0302012010")
							ldblMConsumo_I = 0
							ldblMConsumo_F = BuscaValorItem(lstrItens, "0302012011")
							'Injetado Residuo
							ldblMResiduo_P = BuscaValorItem(lstrItens, "0302013010")
							ldblMResiduo_I = 0
							ldblMResiduo_F = BuscaValorItem(lstrItens, "0302013011")
							'Injetado Utilizado
							ldblMUtilizado_P = 0
							ldblMUtilizado_I = 0
							ldblMUtilizado_F = 0
							'Consumo Lido
							ldblNConsumo_L_P = BuscaValorItem(lstrItens, "0302010010")
							ldblNConsumo_L_I = 0
							ldblNConsumo_L_F = BuscaValorItem(lstrItens, "0302010011")
							'Consumo Faturado
							ldblNConsumo_F_P = BuscaValorItem(lstrItens, "0302010010")
							ldblNConsumo_F_I = 0
							ldblNConsumo_F_F = BuscaValorItem(lstrItens, "0302010011")
							'Consumo Residuo
							ldblRConsumo_P = 0
							ldblRConsumo_I = 0
							ldblRConsumo_F = 0
							'Tarifa Consumo
							ldblTarifa_kWh_P = BuscaValorItem(lstrItens, "01" & lstrGruTar & "011105")
							If ldblTarifa_kWh_P = 0 Then
								ldblTarifa_kWh_P = BuscaValorItem(lstrItens, "01" & lstrGruTar & "011101")
							End If
							ldblTarifa_kWh_I = 0
							ldblTarifa_kWh_F = BuscaValorItem(lstrItens, "01" & lstrGruTar & "011106")
							If ldblTarifa_kWh_F = 0 Then
								ldblTarifa_kWh_F = BuscaValorItem(lstrItens, "01" & lstrGruTar & "011102")
							End If
							'Tarifa Bandeira
							'01AV011121
							ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "10" & lstrGruTar & "011115")
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "10" & lstrGruTar & "011125")
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "10" & lstrGruTar & "011135")
							
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "20" & lstrGruTar & "011115")
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "20" & lstrGruTar & "011125")
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "20" & lstrGruTar & "011135")
							
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "30" & lstrGruTar & "011115")
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "30" & lstrGruTar & "011125")
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "30" & lstrGruTar & "011135")
							
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "01" & lstrGruTar & "011115")
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "01" & lstrGruTar & "011125")
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "01" & lstrGruTar & "011135")
							
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "10" & lstrGruTar & "011111")
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "10" & lstrGruTar & "011121")
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "10" & lstrGruTar & "011131")
							
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "20" & lstrGruTar & "011111")
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "20" & lstrGruTar & "011121")
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "20" & lstrGruTar & "011131")
							
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "30" & lstrGruTar & "011111")
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "30" & lstrGruTar & "011121")
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "30" & lstrGruTar & "011131")
							
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "01" & lstrGruTar & "011111")
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "01" & lstrGruTar & "011121")
							If ldblTarifa_Ban_P = 0 Then ldblTarifa_Ban_P = BuscaValorItem(lstrItens, "01" & lstrGruTar & "011131")
							
							
							ldblTarifa_Ban_I = 0
							ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "10" & lstrGruTar & "011116")
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "10" & lstrGruTar & "011126")
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "10" & lstrGruTar & "011136")
							
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "20" & lstrGruTar & "011116")
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "20" & lstrGruTar & "011126")
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "20" & lstrGruTar & "011136")
							
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "30" & lstrGruTar & "011116")
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "30" & lstrGruTar & "011126")
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "30" & lstrGruTar & "011136")
							
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "01" & lstrGruTar & "011116")
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "01" & lstrGruTar & "011126")
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "01" & lstrGruTar & "011136")
							
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "10" & lstrGruTar & "011112")
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "10" & lstrGruTar & "011122")
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "10" & lstrGruTar & "011132")
							
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "20" & lstrGruTar & "011112")
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "20" & lstrGruTar & "011122")
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "20" & lstrGruTar & "011132")
							
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "30" & lstrGruTar & "011112")
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "30" & lstrGruTar & "011122")
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "30" & lstrGruTar & "011132")
							
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "01" & lstrGruTar & "011112")
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "01" & lstrGruTar & "011122")
							If ldblTarifa_Ban_F = 0 Then ldblTarifa_Ban_F = BuscaValorItem(lstrItens, "01" & lstrGruTar & "011132")
							
						End If
						
						
						lstrSql = "INSERT INTO `micro_geracao` SET "
						lstrSql = lstrSql & "  `grupo` = '" & lstrGrupo & "' "
						lstrSql = lstrSql & " ,`grutar` = '" & lstrGruTar & "' "
						lstrSql = lstrSql & " ,`fase` = '" & lstrFase & "' "
						lstrSql = lstrSql & " ,`classe` = '" & lstrClasse & "' "
						lstrSql = lstrSql & " ,`cons_id` = " & llngConsId
						lstrSql = lstrSql & " ,`unid_id` = " & llngUnidId
						lstrSql = lstrSql & " ,`zona` = '" & lstrZona & "' "
						lstrSql = lstrSql & " ,`livro` = '" & lstrLivro & "' "
						lstrSql = lstrSql & " ,`conta` = '" & lstrConta & "' "
						lstrSql = lstrSql & " ,`micro_geracao_distribuida` = " & lintMicroGeracaoDistribuida & " "
						lstrSql = lstrSql & " ,`micro_geracao_convenio_sefaz` = " & lintMicroGeracaoConvenioSefaz & " "
						lstrSql = lstrSql & " ,`dt_leitura_atual` = '" & VB6.Format(ldteLeituraAtual, "yyyy-MM-dd") & "' "
						lstrSql = lstrSql & " ,`dt_leitura_antes` = '" & VB6.Format(ldteLeituraAntes, "yyyy-MM-dd") & "' "
						lstrSql = lstrSql & " ,`dt_validade` = '" & VB6.Format(DateAdd(Microsoft.VisualBasic.DateInterval.Month, 60, ldteLeituraAtual), "yyyy-MM-dd") & "' "
						'Micro Geração Leitura
						lstrSql = lstrSql & " ,`leitura_atual_p` = '" & lstrMLeituraAtual_P & "' "
						lstrSql = lstrSql & " ,`leitura_antes_p` = '" & lstrMLeituraAntes_P & "' "
						lstrSql = lstrSql & " ,`leitura_atual_i` = '" & lstrMLeituraAtual_I & "' "
						lstrSql = lstrSql & " ,`leitura_antes_i` = '" & lstrMLeituraAntes_I & "' "
						lstrSql = lstrSql & " ,`leitura_atual_f` = '" & lstrMLeituraAtual_F & "' "
						lstrSql = lstrSql & " ,`leitura_antes_f` = '" & lstrMLeituraAntes_F & "' "
						'Constante
						lstrSql = lstrSql & " ,`constante_p` = " & Replace(CStr(ldblConstante_P), ",", ".") & ""
						lstrSql = lstrSql & " ,`constante_i` = " & Replace(CStr(ldblConstante_I), ",", ".") & ""
						lstrSql = lstrSql & " ,`constante_f` = " & Replace(CStr(ldblConstante_F), ",", ".") & ""
						'Injetado
						lstrSql = lstrSql & " ,`injetado_p` = " & Replace(CStr(ldblMConsumo_P), ",", ".") & ""
						lstrSql = lstrSql & " ,`injetado_i` = " & Replace(CStr(ldblMConsumo_I), ",", ".") & ""
						lstrSql = lstrSql & " ,`injetado_f` = " & Replace(CStr(ldblMConsumo_F), ",", ".") & ""
						'Residuo
						lstrSql = lstrSql & " ,`residuo_p` = " & Replace(CStr(ldblMResiduo_P), ",", ".") & ""
						lstrSql = lstrSql & " ,`residuo_i` = " & Replace(CStr(ldblMResiduo_I), ",", ".") & ""
						lstrSql = lstrSql & " ,`residuo_f` = " & Replace(CStr(ldblMResiduo_F), ",", ".") & ""
						'Utilizado
						lstrSql = lstrSql & " ,`utilizado_p` = " & Replace(CStr(ldblMUtilizado_P), ",", ".") & ""
						lstrSql = lstrSql & " ,`utilizado_i` = " & Replace(CStr(ldblMUtilizado_I), ",", ".") & ""
						lstrSql = lstrSql & " ,`utilizado_f` = " & Replace(CStr(ldblMUtilizado_F), ",", ".") & ""
						'Tarifa Consumo
						lstrSql = lstrSql & ", `tarifa_kwh_p` = " & Replace(CStr(ldblTarifa_kWh_P), ",", ".") & ""
						lstrSql = lstrSql & ", `tarifa_kwh_i` = " & Replace(CStr(ldblTarifa_kWh_I), ",", ".") & ""
						lstrSql = lstrSql & ", `tarifa_kwh_f` = " & Replace(CStr(ldblTarifa_kWh_F), ",", ".") & ""
						'Tarifa Bandeira
						lstrSql = lstrSql & ", `tarifa_ban_p` = " & Replace(CStr(ldblTarifa_Ban_P), ",", ".") & ""
						lstrSql = lstrSql & ", `tarifa_ban_i` = " & Replace(CStr(ldblTarifa_Ban_I), ",", ".") & ""
						lstrSql = lstrSql & ", `tarifa_ban_f` = " & Replace(CStr(ldblTarifa_Ban_F), ",", ".") & ""
						'
						lstrSql = lstrSql & " ,`anomes_referencia` = " & llngAnoMes
						Call myConC.Execute(lstrSql)
						
						Call Conectar("SELECT LAST_INSERT_ID() ", lrstReg)
						With lrstReg
							If .State = ADODB.ObjectStateEnum.adStateOpen Then
								If .RecordCount > 0 Then
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									ldblId = IIf(IsDbNull(.Fields(0).value), 1, .Fields(0).value)
								End If
								Call .Close()
							End If
						End With
						
						
						lstrSql = "INSERT INTO `micro_geracao_movto` SET"
						lstrSql = lstrSql & "  `id_micro_geracao_controle` = " & ldblId & " "
						lstrSql = lstrSql & ", `dt_movimento` = '" & VB6.Format(ldteLeituraAtual, "yyyy-MM-dd") & "' "
						'Se foi a Crédito ou a Débito pra U.C. (0 ou 1)
						lstrSql = lstrSql & ", `unidade` = 0 "
						'Caso o Saldo do Injeto Vence é feito lançamento para zerar o saldo do injetado sendo a crédito da distribuidora (0 ou 1)
						lstrSql = lstrSql & ", `distribuidora` = 0 "
						'Dados da U.C.
						lstrSql = lstrSql & ", `grupo` = '" & lstrGrupo & "' "
						lstrSql = lstrSql & ", `grutar` = '" & lstrGruTar & "' "
						lstrSql = lstrSql & ", `cons_id` = " & llngConsId
						lstrSql = lstrSql & ", `unid_id` = " & llngUnidId
						lstrSql = lstrSql & ", `zona` = '" & lstrZona & "' "
						lstrSql = lstrSql & ", `livro` = '" & lstrLivro & "' "
						lstrSql = lstrSql & ", `conta` = '" & lstrConta & "' "
						lstrSql = lstrSql & ", `fase` = '" & lstrFase & "' "
						lstrSql = lstrSql & ", `classe` = '" & lstrClasse & "' "
						
						'Crédito(+) ou Débito(-) dos kWh Injetados
						lstrSql = lstrSql & ", `kwh_p` = " & Replace(CStr(ldblMConsumo_P), ",", ".") & ""
						lstrSql = lstrSql & ", `kwh_i` = " & Replace(CStr(ldblMConsumo_I), ",", ".") & ""
						lstrSql = lstrSql & ", `kwh_f` = " & Replace(CStr(ldblMConsumo_F), ",", ".") & ""
						'Dados de faturamento
						lstrSql = lstrSql & ", `anomes_faturado` = " & llngAnoMes
						lstrSql = lstrSql & ", `dt_leitura_atual` = '" & VB6.Format(ldteLeituraAtual, "yyyy-MM-dd") & "' "
						lstrSql = lstrSql & ", `dt_leitura_antes` = '" & VB6.Format(ldteLeituraAntes, "yyyy-MM-dd") & "' "
						lstrSql = lstrSql & ", `dt_pagamento` = '" & VB6.Format(ldtePagamento, "yyyy-MM-dd") & "' "
						
						'Leituras
						lstrSql = lstrSql & ", `leitura_atual_p` = '" & lstrNLeituraAtual_P & "' "
						lstrSql = lstrSql & ", `leitura_antes_p` = '" & lstrNLeituraAntes_P & "' "
						lstrSql = lstrSql & ", `leitura_atual_i` = '" & lstrNLeituraAtual_I & "' "
						lstrSql = lstrSql & ", `leitura_antes_i` = '" & lstrNLeituraAntes_I & "' "
						lstrSql = lstrSql & ", `leitura_atual_f` = '" & lstrNLeituraAtual_F & "' "
						lstrSql = lstrSql & ", `leitura_antes_f` = '" & lstrNLeituraAntes_F & "' "
						'Constantes
						lstrSql = lstrSql & ", `constante_p` = " & Replace(CStr(ldblConstante_P), ",", ".") & ""
						lstrSql = lstrSql & ", `constante_i` = " & Replace(CStr(ldblConstante_I), ",", ".") & ""
						lstrSql = lstrSql & ", `constante_f` = " & Replace(CStr(ldblConstante_F), ",", ".") & ""
						'Consumo Lido
						lstrSql = lstrSql & ", `kwh_lido_p` = " & Replace(CStr(ldblNConsumo_L_P), ",", ".") & ""
						lstrSql = lstrSql & ", `kwh_lido_i` = " & Replace(CStr(ldblNConsumo_L_I), ",", ".") & ""
						lstrSql = lstrSql & ", `kwh_lido_f` = " & Replace(CStr(ldblNConsumo_L_F), ",", ".") & ""
						'Residuo de Consumo
						lstrSql = lstrSql & ", `kwh_residuo_p` = " & Replace(CStr(ldblRConsumo_P), ",", ".") & ""
						lstrSql = lstrSql & ", `kwh_residuo_i` = " & Replace(CStr(ldblRConsumo_I), ",", ".") & ""
						lstrSql = lstrSql & ", `kwh_residuo_f` = " & Replace(CStr(ldblRConsumo_F), ",", ".") & ""
						'Se foi pelo custo de disponibilidade (0 ou 1)
						lstrSql = lstrSql & ", `custo_disponibilidade` = " & lintCustoDisponibilidade
						'Consumo Faturado
						lstrSql = lstrSql & ", `kwh_faturado_p` = " & Replace(CStr(ldblNConsumo_F_P), ",", ".") & ""
						lstrSql = lstrSql & ", `kwh_faturado_i` = " & Replace(CStr(ldblNConsumo_F_I), ",", ".") & ""
						lstrSql = lstrSql & ", `kwh_faturado_f` = " & Replace(CStr(ldblNConsumo_F_F), ",", ".") & ""
						'Tarifa Consumo
						lstrSql = lstrSql & ", `tarifa_kwh_p` = " & Replace(CStr(ldblTarifa_kWh_P), ",", ".") & ""
						lstrSql = lstrSql & ", `tarifa_kwh_i` = " & Replace(CStr(ldblTarifa_kWh_I), ",", ".") & ""
						lstrSql = lstrSql & ", `tarifa_kwh_f` = " & Replace(CStr(ldblTarifa_kWh_F), ",", ".") & ""
						'Tarifa Bandeira
						lstrSql = lstrSql & ", `tarifa_ban_p` = " & Replace(CStr(ldblTarifa_Ban_P), ",", ".") & ""
						lstrSql = lstrSql & ", `tarifa_ban_i` = " & Replace(CStr(ldblTarifa_Ban_I), ",", ".") & ""
						lstrSql = lstrSql & ", `tarifa_ban_f` = " & Replace(CStr(ldblTarifa_Ban_F), ",", ".") & ""
						
						Call myConC.Execute(lstrSql)
						
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
					End While
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Sub
	
	Private Sub cmdModulo2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdModulo2.Click
		Dim lintARQ As Short
		Dim lstrTab As String
		
		Dim lstrNome As String
		Dim lstrNomeC As String
		Dim lstrRegiao As String
		Dim llngUnidId As Integer
		Dim llngConsId As Integer
		Dim llngConsIdu As Integer
		Dim lstrBairro As String
		Dim lstrLogradouro As String
		Dim lstrNumero As String
		Dim lstrSituacao As String
		Dim lstrMesAno As String
		Dim llngAnoMes As Integer
		Dim ldblNumNf As Double
		Dim lstrItens As String
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim llngCaderno As Integer
		Dim llngSequencia As Integer
		Dim lstrGrupo As String
		Dim lstrGrTar As String
		Dim lstrCodClas As String
		Dim lstrClasse As String
		Dim lstrFase As String
		Dim ldblValorTot As Double
		Dim ldblValorLiq As Double
		Dim ldblQtdMeses As Double
		Dim ldblkWhLido As Double
		Dim ldblkWhFaturado As Double
		
		Dim ldblKwLidoP As Double
		Dim ldblKwContratoP As Double
		Dim ldblKwFaturadoP As Double
		
		Dim ldblKwLidoFP As Double
		Dim ldblKwContratoFP As Double
		Dim ldblKwFaturadoFP As Double
		
		Dim ldblkWhVlr As Double
		Dim ldblkWh As Double
		Dim ldblKwhP As Double
		Dim ldblKwhFP As Double
		Dim lintTarifaBranca As Short
		Dim llngIdAlimentador As Integer
		Dim lstrInstalacao As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Dim lrstHis As ADODB.Recordset
		lrstHis = New ADODB.Recordset
		Dim lrstMes As ADODB.Recordset
		lrstMes = New ADODB.Recordset
		lstrMesAno = "04/2020"
		Me.lblInfo.Text = " Buscando as faturas... " & lstrMesAno & " "
		Call Me.lblInfo.Refresh()
		lstrSql = ""
		lstrSql = lstrSql & "SELECT `nfa`.*, " & vbCrLf
		lstrSql = lstrSql & "       IFNULL(`unidb`.`nome`,`unida`.`nome`) `nome_u`, " & vbCrLf
		lstrSql = lstrSql & "       IFNULL(`unidb`.`regiao`,`unida`.`regiao`) `regiao`, " & vbCrLf
		lstrSql = lstrSql & "       IFNULL(`unidb`.`cons_id`,`unida`.`cons_id`) `cons_id_u`, " & vbCrLf
		lstrSql = lstrSql & "       IFNULL(`unidb`.`bairro`,`unida`.`bairro`) `bairro`, " & vbCrLf
		lstrSql = lstrSql & "       IFNULL(`unidb`.`end`,`unida`.`end`) `logradouro`, " & vbCrLf
		lstrSql = lstrSql & "       IFNULL(`unidb`.`numero`,`unida`.`numero`) `numero`, " & vbCrLf
		lstrSql = lstrSql & "       IFNULL(`unidb`.`situacao`,`unida`.`situacao`) `situacao`, " & vbCrLf
		lstrSql = lstrSql & "       IFNULL(`unidb`.`idalimentador`,`unida`.`idalimentador`) `idalimentador`, " & vbCrLf
		lstrSql = lstrSql & "       IFNULL(`unidb`.`instal`,`unida`.`instal`) `instalacao`, " & vbCrLf
		lstrSql = lstrSql & "       `consum`.`nome` `nome_c` " & vbCrLf
		'  lstrSql = lstrSql & "       (SELECT COUNT(*) " & vbCrLf
		'  lstrSql = lstrSql & "          FROM `nf` `nfb` " & vbCrLf
		'  lstrSql = lstrSql & "         WHERE `nfb`.`mesano_ref` < `nfa`.`mesano_ref` " & vbCrLf
		'  lstrSql = lstrSql & "           AND `nfb`.`zona` = `nfa`.`zona` " & vbCrLf
		'  lstrSql = lstrSql & "           AND `nfb`.`livro` = `nfa`.`livro` " & vbCrLf
		'  lstrSql = lstrSql & "           AND `nfb`.`conta` = `nfa`.`conta` " & vbCrLf
		'  lstrSql = lstrSql & "           AND `nfb`.`cons_id` = `nfa`.`cons_id` " & vbCrLf
		'  lstrSql = lstrSql & "           AND `nfb`.`unid_id` = `nfa`.`unid_id`" & vbCrLf
		'  lstrSql = lstrSql & "           AND `nfb`.`grupo` = `nfa`.`grupo`) `qtde_meses`" & vbCrLf
		lstrSql = lstrSql & "  FROM `nf` `nfa`" & vbCrLf
		lstrSql = lstrSql & " LEFT JOIN `unidb` ON(`unidb`.`unid_id` = `nfa`.`unid_id` AND `nfa`.`grupo` = 'B') " & vbCrLf
		lstrSql = lstrSql & " LEFT JOIN `unida` ON(`unida`.`unid_id` = `nfa`.`unid_id` AND `nfa`.`grupo` = 'A') " & vbCrLf
		lstrSql = lstrSql & " LEFT JOIN `consum` ON(`consum`.`consreg` = `nfa`.`cons_id`) " & vbCrLf
		lstrSql = lstrSql & " WHERE `nfa`.`mesano` = '" & lstrMesAno & "' " & vbCrLf
		lstrSql = lstrSql & " ORDER BY `nfa`.`grupo` ASC, `nfa`.`codclas` ASC "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount, " Gerando Arquivo ")
					lintARQ = FreeFile
					FileOpen(lintARQ, "E:\Dados_modulo2_" & (VB.Right(lstrMesAno, 4) & VB.Left(lstrMesAno, 2)) & ".CSV", OpenMode.Output)
					
					lstrTab = ""
					lstrTab = lstrTab & "Fatura;"
					lstrTab = lstrTab & "Mes/Ano;"
					lstrTab = lstrTab & "Zona;"
					lstrTab = lstrTab & "Livro;"
					lstrTab = lstrTab & "Conta;"
					lstrTab = lstrTab & "Nome;"
					lstrTab = lstrTab & "Bairro;"
					lstrTab = lstrTab & "Logradouro;"
					lstrTab = lstrTab & "Numero;"
					lstrTab = lstrTab & "Situacao;"
					lstrTab = lstrTab & "Rota;"
					lstrTab = lstrTab & "Seq.;"
					lstrTab = lstrTab & "Grupo;"
					lstrTab = lstrTab & "Tar.;"
					lstrTab = lstrTab & "Cod.Clas.;"
					lstrTab = lstrTab & "Des.Classe;"
					lstrTab = lstrTab & "Fase;"
					lstrTab = lstrTab & "Regiao;"
					lstrTab = lstrTab & "Alimentador;"
					lstrTab = lstrTab & "Instalacao;"
					lstrTab = lstrTab & "kwh_Lido_Total;"
					lstrTab = lstrTab & "kwh_Faturado_Total;"
					lstrTab = lstrTab & "kwh_Reais_Total;"
					lstrTab = lstrTab & "Total Fatura;"
					lstrTab = lstrTab & "Liquido Fatura;"
					
					lstrTab = lstrTab & "kw_Lido_Ponta;"
					lstrTab = lstrTab & "kw_Contrato_Ponta;"
					lstrTab = lstrTab & "kw_Faturado_Ponta;"
					
					lstrTab = lstrTab & "kw_Lido_Fora_Ponta;"
					lstrTab = lstrTab & "kw_Contrato_Fora_Ponta;"
					lstrTab = lstrTab & "kw_Faturado_Fora_Ponta;"
					
					
					lstrTab = lstrTab & "Qtd. Meses;"
					lstrTab = lstrTab & "Mes 1;Mes 2;Mes 3;Mes 4;Mes 5;Mes 6;Mes 7;Mes 8;Mes 9;Mes 10;Mes 11;Mes 12;"
					PrintLine(lintARQ, lstrTab)
					While Not .EOF
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblNumNf = IIf(IsDbNull(.Fields("numnf").value), 0, .Fields("numnf").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrMesAno = IIf(IsDbNull(.Fields("mesano").value), "", .Fields("mesano").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						llngAnoMes = IIf(IsDbNull(.Fields("mesano_ref").value), 0, .Fields("mesano_ref").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrZona = IIf(IsDbNull(.Fields("zona").value), "", .Fields("zona").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrLivro = IIf(IsDbNull(.Fields("livro").value), "", .Fields("livro").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrConta = IIf(IsDbNull(.Fields("conta").value), "", .Fields("conta").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						llngCaderno = IIf(IsDbNull(.Fields("caderno").value), 0, .Fields("caderno").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						llngSequencia = IIf(IsDbNull(.Fields("caderno_sequencia").value), 0, .Fields("caderno_sequencia").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrGrupo = IIf(IsDbNull(.Fields("grupo").value), "B", .Fields("grupo").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrGrTar = Mid(IIf(IsDbNull(.Fields("ta").value), "01B100", .Fields("ta").value), 3, 2)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						llngUnidId = IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						llngConsId = IIf(IsDbNull(.Fields("cons_id").value), 0, .Fields("cons_id").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrCodClas = IIf(IsDbNull(.Fields("codclas").value), "0000", .Fields("codclas").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrItens = IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrFase = IIf(IsDbNull(.Fields("fase").value), "M", .Fields("fase").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrRegiao = IIf(IsDbNull(.Fields("regiao").value), "U", .Fields("regiao").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrBairro = IIf(IsDbNull(.Fields("bairro").value), "", .Fields("bairro").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrLogradouro = IIf(IsDbNull(.Fields("logradouro").value), "", .Fields("logradouro").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrNumero = IIf(IsDbNull(.Fields("numero").value), "", .Fields("numero").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrSituacao = IIf(IsDbNull(.Fields("situacao").value), "I", .Fields("situacao").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblValorTot = IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblValorLiq = IIf(IsDbNull(.Fields("valorliq").value), 0, .Fields("valorliq").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lintTarifaBranca = IIf(IsDbNull(.Fields("tarifa_branca").value), 0, .Fields("tarifa_branca").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						llngIdAlimentador = IIf(IsDbNull(.Fields("idalimentador").value), 0, .Fields("idalimentador").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrInstalacao = IIf(IsDbNull(.Fields("instalacao").value), 0, .Fields("instalacao").value)
						'ldblQtdMeses = IIf(IsNull(.Fields("qtde_meses").value), 0, .Fields("qtde_meses").value)
						System.Windows.Forms.Application.DoEvents()
						'          lstrSql = ""
						'          lstrSql = lstrSql & "SELECT COUNT(*) `qtde_meses` " & vbCrLf
						'          lstrSql = lstrSql & "  FROM `nf` " & vbCrLf
						'          lstrSql = lstrSql & " WHERE `mesano_ref` < " & llngAnoMes & " " & vbCrLf
						'          lstrSql = lstrSql & "   AND `zona` = '" & lstrZona & "' " & vbCrLf
						'          lstrSql = lstrSql & "   AND `livro` = '" & lstrLivro & "' " & vbCrLf
						'          lstrSql = lstrSql & "   AND `conta` = '" & lstrConta & "' " & vbCrLf
						'          lstrSql = lstrSql & "   AND `cons_id` = " & llngConsId & " " & vbCrLf
						'          lstrSql = lstrSql & "   AND `unid_id` = " & llngUnidId & " " & vbCrLf
						'          lstrSql = lstrSql & "   AND `grupo` = '" & lstrGrupo & "' " & vbCrLf
						'          Call Conectar(lstrSql, lrstMes)
						'          With lrstMes
						'            If .State = adodb.ObjectStateEnum.adStateOpen Then
						'              If .RecordCount > 0 Then
						'                ldblQtdMeses = IIf(IsNull(.Fields("qtde_meses").value), 0, .Fields("qtde_meses").value)
						'              End If
						'              Call .Close
						'            End If
						'          End With
						System.Windows.Forms.Application.DoEvents()
						ldblkWhLido = 0
						ldblkWhFaturado = 0
						ldblkWhVlr = 0
						ldblKwLidoP = 0
						ldblKwContratoP = 0
						ldblKwFaturadoP = 0
						ldblKwLidoFP = 0
						ldblKwContratoFP = 0
						ldblKwFaturadoFP = 0
						If lstrGrupo = "B" Then
							If lintTarifaBranca = 1 Then
								ldblkWhLido = ldblkWhLido + BuscaValorItem(lstrItens, "030201018") + BuscaValorItem(lstrItens, "030201028") + BuscaValorItem(lstrItens, "030201038")
								ldblkWhFaturado = ldblkWhFaturado + BuscaValorItem(lstrItens, "030201019") + BuscaValorItem(lstrItens, "030201029") + BuscaValorItem(lstrItens, "030201039")
								ldblkWhVlr = ldblkWhVlr + BuscaValorItem(lstrItens, "030202019") + BuscaValorItem(lstrItens, "030202029") + BuscaValorItem(lstrItens, "030202039")
							Else
								ldblkWhLido = ldblkWhLido + BuscaValorItem(lstrItens, "030201008")
								ldblkWhFaturado = ldblkWhFaturado + BuscaValorItem(lstrItens, "030201009")
								ldblkWhVlr = ldblkWhVlr + BuscaValorItem(lstrItens, "030202009")
							End If
						Else
							If lstrGrTar = "A4" Or lstrGrTar = "AS" Then
								ldblkWhLido = ldblkWhLido + BuscaValorItem(lstrItens, "0302010009")
								ldblkWhFaturado = ldblkWhFaturado + BuscaValorItem(lstrItens, "0302010009")
								ldblkWhVlr = ldblkWhVlr + BuscaValorItem(lstrItens, "0302020009")
								'
								ldblKwLidoFP = BuscaValorItem(lstrItens, "0302010015") 'demanda lida
								ldblKwContratoFP = BuscaValorItem(lstrItens, "0302010016") 'demanda contrata
								ldblKwFaturadoFP = BuscaValorItem(lstrItens, "0302010017") 'demanda faturada
							Else
								ldblKwhP = (BuscaValorItem(lstrItens, "0302010010") + BuscaValorItem(lstrItens, "0302010060"))
								ldblkWhLido = ldblkWhLido + ldblKwhP
								ldblkWhFaturado = ldblkWhFaturado + ldblKwhP
								ldblKwhFP = (BuscaValorItem(lstrItens, "0302010011") + BuscaValorItem(lstrItens, "0302010061"))
								ldblkWhLido = ldblkWhLido + ldblKwhFP
								ldblkWhFaturado = ldblkWhFaturado + ldblKwhFP
								ldblKwhP = (BuscaValorItem(lstrItens, "0302020010") + BuscaValorItem(lstrItens, "0302020060"))
								ldblkWhVlr = ldblkWhVlr + ldblKwhP
								ldblKwhFP = (BuscaValorItem(lstrItens, "0302020011") + BuscaValorItem(lstrItens, "0302020061"))
								ldblkWhVlr = ldblkWhVlr + ldblKwhFP
								'
								ldblKwLidoP = BuscaValorItem(lstrItens, "0302010019") 'demanda lida
								ldblKwContratoP = BuscaValorItem(lstrItens, "0302010020") 'demanda contrata
								ldblKwFaturadoP = BuscaValorItem(lstrItens, "0302010021") 'demanda faturada
								'
								ldblKwLidoFP = BuscaValorItem(lstrItens, "0302010023") 'demanda lida
								ldblKwContratoFP = BuscaValorItem(lstrItens, "0302010024") 'demanda contrata
								ldblKwFaturadoFP = BuscaValorItem(lstrItens, "0302010025") 'demanda faturada
							End If
						End If
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						llngConsIdu = IIf(IsDbNull(.Fields("cons_id_u").value), 0, .Fields("cons_id_u").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrNome = IIf(IsDbNull(.Fields("nome_u").value), "", .Fields("nome_u").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrNomeC = IIf(IsDbNull(.Fields("nome_c").value), "", .Fields("nome_c").value)
						If llngConsIdu <> llngConsId Then
							lstrNome = lstrNomeC
						End If
						Select Case (CDbl(VB.Left(lstrCodClas, 1)) + 0)
							Case Is < 4
								lstrClasse = "Industrial"
							Case Is = 4
								lstrClasse = "Comercial"
							Case Is = 5
								lstrClasse = "Rural"
							Case Is = 6
								lstrClasse = "Pode Público"
								If VB.Left(lstrCodClas, 2) = "61" Then
									lstrClasse = lstrClasse & " Municipal"
								ElseIf VB.Left(lstrCodClas, 2) = "62" Then 
									lstrClasse = lstrClasse & " Estadual"
								ElseIf VB.Left(lstrCodClas, 2) = "63" Then 
									lstrClasse = lstrClasse & " Federal"
								ElseIf VB.Left(lstrCodClas, 2) = "64" Then 
									lstrClasse = "Iluminação Pública"
								End If
							Case Is = 7
								lstrClasse = "Serviço Público"
							Case Is = 8
								lstrClasse = "Consumo Próprio"
							Case Is = 9
								lstrClasse = "Residencial"
							Case Else
								lstrClasse = "Indefinido"
						End Select
						'If ldblkWhLido > 0 Then
						lstrTab = ""
						lstrTab = lstrTab & ldblNumNf & ";"
						lstrTab = lstrTab & lstrMesAno & ";"
						lstrTab = lstrTab & lstrZona & ";"
						lstrTab = lstrTab & lstrLivro & ";"
						lstrTab = lstrTab & lstrConta & ";"
						lstrTab = lstrTab & lstrNome & ";"
						lstrTab = lstrTab & lstrBairro & ";"
						lstrTab = lstrTab & lstrLogradouro & ";"
						lstrTab = lstrTab & lstrNumero & ";"
						
						lstrTab = lstrTab & IIf(lstrSituacao = "L", "Ligado", IIf(lstrSituacao = "D", "Desligado", IIf(lstrSituacao = "C", "Cortado", "Desativado"))) & ";"
						
						lstrTab = lstrTab & llngCaderno & ";"
						lstrTab = lstrTab & llngSequencia & ";"
						lstrTab = lstrTab & lstrGrupo & ";"
						lstrTab = lstrTab & lstrGrTar & ";"
						
						lstrTab = lstrTab & lstrCodClas & ";"
						lstrTab = lstrTab & lstrClasse & ";"
						
						lstrTab = lstrTab & lstrFase & ";"
						lstrTab = lstrTab & lstrRegiao & ";"
						
						lstrTab = lstrTab & GetValorTabela("alimentador", "descricao", "id=" & llngIdAlimentador, "") & ";"
						lstrTab = lstrTab & lstrInstalacao & ";"
						
						lstrTab = lstrTab & VB6.Format(ldblkWhLido, "#,0") & ";"
						lstrTab = lstrTab & VB6.Format(ldblkWhFaturado, "#,0") & ";"
						lstrTab = lstrTab & VB6.Format(ldblkWhVlr, "#,##0.00") & ";"
						lstrTab = lstrTab & VB6.Format(ldblValorTot, "#,##0.00") & ";"
						lstrTab = lstrTab & VB6.Format(ldblValorLiq, "#,##0.00") & ";"
						
						lstrTab = lstrTab & VB6.Format(ldblKwLidoP, "#,0") & ";"
						lstrTab = lstrTab & VB6.Format(ldblKwContratoP, "#,0") & ";"
						lstrTab = lstrTab & VB6.Format(ldblKwFaturadoP, "#,0") & ";"
						lstrTab = lstrTab & VB6.Format(ldblKwLidoFP, "#,0") & ";"
						lstrTab = lstrTab & VB6.Format(ldblKwContratoFP, "#,0") & ";"
						lstrTab = lstrTab & VB6.Format(ldblKwFaturadoFP, "#,0") & ";"
						
						lstrTab = lstrTab & VB6.Format(ldblQtdMeses, "#,0") & ";"
						
						System.Windows.Forms.Application.DoEvents()
						Me.lblInfo2.Text = " Pegando o historico... "
						Call Me.lblInfo2.Refresh()
						
						'loop ultimos 11 meses
						lstrSql = ""
						lstrSql = lstrSql & "SELECT `nf`.*  "
						lstrSql = lstrSql & "  FROM `nf` "
						lstrSql = lstrSql & " WHERE `mesano_ref` <= " & llngAnoMes & " "
						lstrSql = lstrSql & "   AND `cons_id` = " & llngConsId & " "
						lstrSql = lstrSql & "   AND `unid_id` = " & llngUnidId & " "
						lstrSql = lstrSql & "   AND `grupo` = '" & lstrGrupo & "' "
						lstrSql = lstrSql & "   AND `zona` = '" & lstrZona & "' "
						lstrSql = lstrSql & "   AND `livro` = '" & lstrLivro & "' "
						lstrSql = lstrSql & "   AND `conta` = '" & lstrConta & "' "
						lstrSql = lstrSql & " ORDER BY `mesano_ref` DESC LIMIT 0, 12 "
						Call Conectar(lstrSql, lrstHis)
						With lrstHis
							If .State = ADODB.ObjectStateEnum.adStateOpen Then
								If .RecordCount > 0 Then
									Call BarraProgresso((Me.ProgressBar2), (Me.lblPerc2), (Me.lblInfo2), 0, .RecordCount)
									While Not .EOF
										'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
										lintTarifaBranca = IIf(IsDbNull(.Fields("tarifa_branca").value), 0, .Fields("tarifa_branca").value)
										'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
										lstrItens = IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").value)
										If lstrGrupo = "B" Then
											If lintTarifaBranca = 1 Then
												ldblkWh = BuscaValorItem(lstrItens, "030201019") + BuscaValorItem(lstrItens, "030201029") + BuscaValorItem(lstrItens, "030201039")
											Else
												ldblkWh = BuscaValorItem(lstrItens, "030201009")
											End If
										Else
											ldblkWh = BuscaValorItem(lstrItens, "0302010009")
										End If
										ldblKwhP = BuscaValorItem(lstrItens, "0302010010") + BuscaValorItem(lstrItens, "0302010060")
										ldblKwhFP = BuscaValorItem(lstrItens, "0302010011") + BuscaValorItem(lstrItens, "0302010061")
										lstrTab = lstrTab & VB6.Format(ldblkWh + ldblKwhP + ldblKwhFP, "#,#####0.00000") & ";"
										Call .MoveNext()
										Call BarraProgresso((Me.ProgressBar2), (Me.lblPerc2), (Me.lblInfo2), 1)
									End While
								End If
								Call .Close()
							End If
						End With
						System.Windows.Forms.Application.DoEvents()
						PrintLine(lintARQ, lstrTab)
						'End If
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " Gerando Arquivo ")
					End While
					FileClose(lintARQ)
					Call MsgBox("Arquivo gerado com sucesso!", MsgBoxStyle.Information, gstrTituloMensagem)
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
		'UPGRADE_NOTE: Object lrstHis may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstHis = Nothing
		'UPGRADE_NOTE: Object lrstMes may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstMes = Nothing
	End Sub
	
	Private Sub cmdOficio202017_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdOficio202017.Click
		Call frmIndContinuidadeNovo.Show()
	End Sub
	
	Private Sub cmdRecalculoTributacao_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdRecalculoTributacao.Click
		Dim ldblNumNf As Double
		Dim lstrMesAno As String
		Dim llngAnoMes As Integer
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim llngConsId As Integer
		Dim llngUnidId As Integer
		Dim lstrCodClas As String
		Dim lstrItens As String
		Dim ldteAtual As Date
		Dim ldteAnter As Date
		Dim ldteBandeira As Date
		'UPGRADE_WARNING: Lower bound of array ldblQkWh was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblQkWh(4) As Double 'Qtde Consumo
		'UPGRADE_WARNING: Lower bound of array ldblVkWh was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblVkWh(4) As Double 'Valor Consumo
		'UPGRADE_WARNING: Lower bound of array ldblVBan was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblVBan(4) As Double 'Valor Bandeira
		'UPGRADE_WARNING: Lower bound of array ldblVTar was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblVTar(4) As Double 'Tarifa
		'UPGRADE_WARNING: Lower bound of array ldblVTarT was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblVTarT(5) As Double 'Tributada
		'UPGRADE_WARNING: Lower bound of array ldblBTar was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblBTar(4) As Double 'Bandeira
		'UPGRADE_WARNING: Lower bound of array ldblBTarT was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblBTarT(5) As Double 'Tributada Bandeira
		Dim ldblRTar As Double 'Residencial
		'UPGRADE_WARNING: Lower bound of array ldblRTarT was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblRTarT(2) As Double 'Tributada Residencial
		Dim ldblRBan As Double 'Residencial
		'UPGRADE_WARNING: Lower bound of array ldblRBanT was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblRBanT(2) As Double 'Tributada Residencial
		'
		'UPGRADE_WARNING: Lower bound of array ldblCoef was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblCoef(2) As Double
		'UPGRADE_WARNING: Lower bound of array ldblAIcms was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblAIcms(2) As Double
		Dim ldblAPis As Double
		Dim ldblACof As Double
		'UPGRADE_WARNING: Lower bound of array ldblIcms was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblIcms(2) As Double
		Dim ldblPis As Double
		Dim ldblCof As Double
		'UPGRADE_WARNING: Lower bound of array ldblBIcms was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblBIcms(2) As Double
		'UPGRADE_WARNING: Lower bound of array ldblNBIcms was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblNBIcms(2) As Double
		Dim ldblBPis As Double
		Dim ldblBCof As Double
		'
		'UPGRADE_WARNING: Lower bound of array ldblNVkWh was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblNVkWh(4) As Double
		'UPGRADE_WARNING: Lower bound of array ldblNVkWhT was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblNVkWhT(5) As Double
		'UPGRADE_WARNING: Lower bound of array ldblNVBan was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblNVBan(4) As Double
		'UPGRADE_WARNING: Lower bound of array ldblNVBanT was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblNVBanT(5) As Double
		'
		'UPGRADE_WARNING: Lower bound of array ldblNVRkWh was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblNVRkWh(2) As Double
		'UPGRADE_WARNING: Lower bound of array ldblNVRkWhT was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblNVRkWhT(2) As Double
		'UPGRADE_WARNING: Lower bound of array ldblNVRBan was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblNVRBan(2) As Double
		'UPGRADE_WARNING: Lower bound of array ldblNVRBanT was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblNVRBanT(2) As Double
		'UPGRADE_WARNING: Lower bound of array ldblNBRIcms was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblNBRIcms(2) As Double
		Dim ldblNBRPis As Double
		Dim ldblNBRCof As Double
		'UPGRADE_WARNING: Lower bound of array ldblNVRIcms was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
		Dim ldblNVRIcms(2) As Double
		Dim ldblNVRPis As Double
		Dim ldblNVRCof As Double
		'
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrSql = ""
		lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS recalculo_icms_pis_cofins("
		lstrSql = lstrSql & "zona varchar(3) DEFAULT '000',"
		lstrSql = lstrSql & "livro varchar(2) DEFAULT '00',"
		lstrSql = lstrSql & "conta varchar(6) DEFAULT '000000',"
		lstrSql = lstrSql & "cons_id integer(11) DEFAULT 0,"
		lstrSql = lstrSql & "unid_id integer(11) DEFAULT 0,"
		lstrSql = lstrSql & "codclas varchar(4) DEFAULT '0000',"
		lstrSql = lstrSql & "numnf double DEFAULT 0,"
		lstrSql = lstrSql & "mesano varchar(7) DEFAULT '00/0000',"
		lstrSql = lstrSql & "anomes integer(6) DEFAULT 0,"
		lstrSql = lstrSql & "leitura_atual date DEFAULT '1900-01-01',"
		lstrSql = lstrSql & "leitura_anterior date DEFAULT '1900-01-01',"
		lstrSql = lstrSql & "qtde_consumo_bx_total double DEFAULT 0,"
		lstrSql = lstrSql & "qtde_consumo_bx_1 double DEFAULT 0,"
		lstrSql = lstrSql & "qtde_consumo_bx_2 double DEFAULT 0,"
		lstrSql = lstrSql & "qtde_consumo_bx_3 double DEFAULT 0,"
		lstrSql = lstrSql & "qtde_consumo_bx_4 double DEFAULT 0,"
		lstrSql = lstrSql & "valor_consumo_bx_total double DEFAULT 0,"
		lstrSql = lstrSql & "valor_consumo_bx_1 double DEFAULT 0,"
		lstrSql = lstrSql & "valor_consumo_bx_2 double DEFAULT 0,"
		lstrSql = lstrSql & "valor_consumo_bx_3 double DEFAULT 0,"
		lstrSql = lstrSql & "valor_consumo_bx_4 double DEFAULT 0,"
		lstrSql = lstrSql & "valor_bandeira_bx_total double DEFAULT 0,"
		lstrSql = lstrSql & "valor_bandeira_bx_1 double DEFAULT 0,"
		lstrSql = lstrSql & "valor_bandeira_bx_2 double DEFAULT 0,"
		lstrSql = lstrSql & "valor_bandeira_bx_3 double DEFAULT 0,"
		lstrSql = lstrSql & "valor_bandeira_bx_4 double DEFAULT 0,"
		lstrSql = lstrSql & "base_icms_bx_1 double DEFAULT 0,"
		lstrSql = lstrSql & "base_icms_bx_2 double DEFAULT 0,"
		lstrSql = lstrSql & "base_pis_bx double DEFAULT 0,"
		lstrSql = lstrSql & "base_cofins_bx double DEFAULT 0,"
		lstrSql = lstrSql & "aliquota_icms_1 double DEFAULT 0,"
		lstrSql = lstrSql & "aliquota_icms_2 double DEFAULT 0,"
		lstrSql = lstrSql & "aliquota_pis double DEFAULT 0,"
		lstrSql = lstrSql & "aliquota_cofins double DEFAULT 0,"
		lstrSql = lstrSql & "valor_icms_bx_1 double DEFAULT 0,"
		lstrSql = lstrSql & "valor_icms_bx_2 double DEFAULT 0,"
		lstrSql = lstrSql & "valor_pis_bx double DEFAULT 0,"
		lstrSql = lstrSql & "valor_cofins_bx double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_bx_1 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_bx_2 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_bx_3 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_bx_4 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_ban_bx_1 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_ban_bx_2 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_ban_bx_3 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_ban_bx_4 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_bx_tri_1 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_bx_tri_2 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_bx_tri_3 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_bx_tri_4 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_bx_tri_5 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_ban_bx_tri_1 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_ban_bx_tri_2 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_ban_bx_tri_3 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_ban_bx_tri_4 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_ban_bx_tri_5 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_residencial double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_residencial_tri_1 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_residencial_tri_2 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_residencial_ban double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_residencial_ban_tri_1 double DEFAULT 0,"
		lstrSql = lstrSql & "tarifa_residencial_ban_tri_2 double DEFAULT 0,"
		lstrSql = lstrSql & "base_icms_residencial_1 double DEFAULT 0,"
		lstrSql = lstrSql & "base_icms_residencial_2 double DEFAULT 0,"
		lstrSql = lstrSql & "base_pis_residencial double DEFAULT 0,"
		lstrSql = lstrSql & "base_cofins_residencial double DEFAULT 0,"
		lstrSql = lstrSql & "valor_icms_residencial_1 double DEFAULT 0,"
		lstrSql = lstrSql & "valor_icms_residencial_2 double DEFAULT 0,"
		lstrSql = lstrSql & "valor_pis_residencial double DEFAULT 0,"
		lstrSql = lstrSql & "valor_cofins_residencial double DEFAULT 0,"
		lstrSql = lstrSql & "valor_consumo_residencial_total double DEFAULT 0,"
		lstrSql = lstrSql & "valor_consumo_residencial_1 double DEFAULT 0,"
		lstrSql = lstrSql & "valor_consumo_residencial_2 double DEFAULT 0,"
		lstrSql = lstrSql & "valor_bandeira_residencial_total double DEFAULT 0,"
		lstrSql = lstrSql & "valor_bandeira_residencial_1 double DEFAULT 0,"
		lstrSql = lstrSql & "valor_bandeira_residencial_2 double DEFAULT 0,"
		lstrSql = lstrSql & "PRIMARY KEY (numnf,anomes)"
		lstrSql = lstrSql & ")"
		Call Executar(lstrSql, False)
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM `nf` "
		lstrSql = lstrSql & " WHERE `mesano` = '01/2016'"
		lstrSql = lstrSql & "   AND `codclas` = 9105 "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount)
					While Not .EOF
						'Outros dados da fatura
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblNumNf = IIf(IsDbNull(.Fields("numnf").value), 0, .Fields("numnf").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrMesAno = IIf(IsDbNull(.Fields("mesano").value), "", .Fields("mesano").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						llngAnoMes = IIf(IsDbNull(.Fields("mesano_ref").value), 0, .Fields("mesano_ref").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrZona = IIf(IsDbNull(.Fields("zona").value), "", .Fields("zona").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrLivro = IIf(IsDbNull(.Fields("livro").value), "", .Fields("livro").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrConta = IIf(IsDbNull(.Fields("conta").value), "", .Fields("conta").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						llngConsId = IIf(IsDbNull(.Fields("cons_id").value), 0, .Fields("cons_id").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						llngUnidId = IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrItens = IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrCodClas = IIf(IsDbNull(.Fields("codclas").value), "0000", .Fields("codclas").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldteAtual = IIf(IsDbNull(.Fields("dataleit").value), "1900-01-01", .Fields("dataleit").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldteAnter = IIf(IsDbNull(.Fields("dataleitant").value), "1900-01-01", .Fields("dataleitant").value)
						'Icms, Pis e Cofins (base, aliquotas e valores
						ldblAIcms(1) = 12
						ldblAIcms(2) = 25
						ldblBIcms(1) = BuscaValorItem(lstrItens, "0302030001")
						ldblBIcms(2) = BuscaValorItem(lstrItens, "0302030003")
						ldblIcms(1) = BuscaValorItem(lstrItens, "0302030009")
						ldblIcms(2) = BuscaValorItem(lstrItens, "0302030010")
						ldblAPis = BuscaValorItem(lstrItens, "0302990303")
						ldblPis = BuscaValorItem(lstrItens, "0302020029")
						ldblBPis = BuscaValorItem(lstrItens, "0302020033")
						ldblACof = BuscaValorItem(lstrItens, "0302990304")
						ldblCof = BuscaValorItem(lstrItens, "0302020030")
						ldblBCof = BuscaValorItem(lstrItens, "0302020034")
						'Coeficiente para tributação
						ldblCoef(1) = Truncate(1 - (((ldblAPis / 100) + (ldblACof / 100)) / (1 - (ldblAIcms(1) / 100))), 11)
						ldblCoef(2) = Truncate(1 - (((ldblAPis / 100) + (ldblACof / 100)) / (1 - (ldblAIcms(2) / 100))), 11)
						'Tarifa do baixa renda
						ldblVTar(1) = TarifaProporcional(ldteAnter, ldteAtual, "01B1021101", 3) / 1000
						ldblVTar(2) = TarifaProporcional(ldteAnter, ldteAtual, "01B1021102", 3) / 1000
						ldblVTar(3) = TarifaProporcional(ldteAnter, ldteAtual, "01B1021103", 3) / 1000
						ldblVTar(4) = TarifaProporcional(ldteAnter, ldteAtual, "01B1021104", 3) / 1000
						'Tarifa do baixa renda tributada
						ldblVTarT(1) = Arredondar(ldblVTar(1) / ldblCoef(1), 5)
						ldblVTarT(2) = Arredondar(ldblVTar(2) / ldblCoef(1), 5)
						ldblVTarT(3) = Arredondar(ldblVTar(3) / ldblCoef(1), 5)
						ldblVTarT(4) = Arredondar(ldblVTar(3) / ldblCoef(2), 5)
						ldblVTarT(5) = Arredondar(ldblVTar(4) / ldblCoef(2), 5)
						'Tarifa da bandeira do baixa renda
						ldblBTar(4) = TarifaProporcionalBandeira(ldteAnter, ldteAtual, 1, ldteBandeira) / 1000
						ldblBTar(1) = Arredondar(ldblBTar(4) - (ldblBTar(4) * (65 / 100)), 5)
						ldblBTar(2) = Arredondar(ldblBTar(4) - (ldblBTar(4) * (40 / 100)), 5)
						ldblBTar(3) = Arredondar(ldblBTar(4) - (ldblBTar(4) * (10 / 100)), 5)
						'Tarifa da bandeira do baixa renda tributada
						ldblBTarT(1) = Arredondar(ldblBTar(1) / ldblCoef(1), 5)
						ldblBTarT(2) = Arredondar(ldblBTar(2) / ldblCoef(1), 5)
						ldblBTarT(3) = Arredondar(ldblBTar(3) / ldblCoef(1), 5)
						ldblBTarT(4) = Arredondar(ldblBTar(3) / ldblCoef(2), 5)
						ldblBTarT(5) = Arredondar(ldblBTar(4) / ldblCoef(2), 5)
						'Tarifa residencial e tariga bandeira residencial
						ldblRTar = TarifaProporcional(ldteAnter, ldteAtual, "01B1011101", 3) / 1000
						ldblRTarT(1) = Arredondar(ldblRTar / ldblCoef(1), 5)
						ldblRTarT(2) = Arredondar(ldblRTar / ldblCoef(2), 5)
						ldblRBan = ldblBTar(4)
						ldblRBanT(1) = Arredondar(ldblRBan / ldblCoef(1), 5)
						ldblRBanT(2) = Arredondar(ldblRBan / ldblCoef(2), 5)
						'Quantidade e valores do consumo da fatura
						ldblQkWh(1) = BuscaValorItem(lstrItens, "0302010090")
						ldblQkWh(2) = BuscaValorItem(lstrItens, "0302010091")
						ldblQkWh(3) = BuscaValorItem(lstrItens, "0302010092")
						ldblQkWh(4) = BuscaValorItem(lstrItens, "0302010093")
						ldblVkWh(1) = BuscaValorItem(lstrItens, "0302020090")
						ldblVkWh(2) = BuscaValorItem(lstrItens, "0302020091")
						ldblVkWh(3) = BuscaValorItem(lstrItens, "0302020092")
						ldblVkWh(4) = BuscaValorItem(lstrItens, "0302020093")
						ldblVBan(1) = BuscaValorItem(lstrItens, "0302120090")
						ldblVBan(2) = BuscaValorItem(lstrItens, "0302120091")
						ldblVBan(3) = BuscaValorItem(lstrItens, "0302120092")
						ldblVBan(4) = BuscaValorItem(lstrItens, "0302120093")
						'Recalculo do baixa renda somente para validar com o que foi gravado na fatura
						ldblNVkWh(1) = Truncate(ldblQkWh(1) * ldblVTar(1), 2)
						ldblNVkWh(2) = Truncate(ldblQkWh(2) * ldblVTar(2), 2)
						ldblNVkWh(3) = Truncate(ldblQkWh(3) * ldblVTar(3), 2)
						ldblNVkWh(4) = Truncate(ldblQkWh(4) * ldblVTar(4), 2)
						'
						ldblNVkWhT(1) = (ldblQkWh(1) * ldblVTarT(1)) / (1 - (ldblAIcms(1) / 100))
						ldblNVkWhT(2) = ldblQkWh(2) * ldblVTarT(2) / (1 - (ldblAIcms(1) / 100))
						If (ldblQkWh(1) + ldblQkWh(2) + ldblQkWh(3)) > 150 Then
							ldblNVkWhT(3) = (50 * ldblVTarT(3)) / (1 - (ldblAIcms(1) / 100))
							ldblNVkWhT(4) = ((ldblQkWh(1) + ldblQkWh(2) + ldblQkWh(3) - 150) * ldblVTarT(4)) / (1 - (ldblAIcms(2) / 100))
						Else
							ldblNVkWhT(3) = (ldblQkWh(3) * ldblVTarT(3)) / (1 - (ldblAIcms(1) / 100))
							ldblNVkWhT(4) = 0
						End If
						ldblNVkWhT(5) = (ldblQkWh(4) * ldblVTarT(5)) / (1 - (ldblAIcms(2) / 100))
						'
						ldblNVBanT(1) = (ldblQkWh(1) * ldblBTarT(1)) / (1 - (ldblAIcms(1) / 100))
						ldblNVBanT(2) = ldblQkWh(2) * ldblBTarT(2) / (1 - (ldblAIcms(1) / 100))
						If (ldblQkWh(1) + ldblQkWh(2) + ldblQkWh(3)) > 150 Then
							ldblNVBanT(3) = (50 * ldblBTarT(3)) / (1 - (ldblAIcms(1) / 100))
							ldblNVBanT(4) = ((ldblQkWh(1) + ldblQkWh(2) + ldblQkWh(3) - 150) * ldblBTarT(4)) / (1 - (ldblAIcms(2) / 100))
						Else
							ldblNVBanT(3) = (ldblQkWh(3) * ldblBTarT(3)) / (1 - (ldblAIcms(1) / 100))
							ldblNVBanT(4) = 0
						End If
						ldblNVBanT(5) = (ldblQkWh(4) * ldblBTarT(5)) / (1 - (ldblAIcms(2) / 100))
						'
						ldblNBIcms(1) = ldblNVkWhT(1) + ldblNVkWhT(2) + ldblNVkWhT(3) + ldblNVBanT(1) + ldblNVBanT(2) + ldblNVBanT(3)
						ldblNBIcms(2) = ldblNVkWhT(4) + ldblNVkWhT(5) + ldblNVBanT(4) + ldblNVBanT(5)
						'
						'Pela tarifa residencial normal
						If (ldblQkWh(1) + ldblQkWh(2) + ldblQkWh(3)) > 150 Then
							ldblNVRkWh(1) = Truncate(150 * ldblRTar, 2)
							ldblNVRkWh(2) = Truncate((ldblQkWh(1) + ldblQkWh(2) + ldblQkWh(3) + ldblQkWh(4) - 150) * ldblRTar, 2)
							'
							ldblNVRkWhT(1) = (150 * ldblRTarT(1)) / (1 - (ldblAIcms(1) / 100))
							ldblNVRkWhT(2) = ((ldblQkWh(1) + ldblQkWh(2) + ldblQkWh(3) + ldblQkWh(4) - 150) * ldblRTarT(2)) / (1 - (ldblAIcms(2) / 100))
							'
							ldblNVRBan(1) = Truncate(150 * ldblRBan, 2)
							ldblNVRBan(2) = Truncate((ldblQkWh(1) + ldblQkWh(2) + ldblQkWh(3) + ldblQkWh(4) - 150) * ldblRBan, 2)
							'
							ldblNVRBanT(1) = (150 * ldblRBanT(1)) / (1 - (ldblAIcms(1) / 100))
							ldblNVRBanT(2) = ((ldblQkWh(1) + ldblQkWh(2) + ldblQkWh(3) + ldblQkWh(4) - 150) * ldblRBanT(2)) / (1 - (ldblAIcms(2) / 100))
						Else
							ldblNVRkWh(1) = Truncate((ldblQkWh(1) + ldblQkWh(2) + ldblQkWh(3) + ldblQkWh(4)) * ldblRTar, 2)
							ldblNVRkWh(2) = 0
							'
							ldblNVRkWhT(1) = ((ldblQkWh(1) + ldblQkWh(2) + ldblQkWh(3) + ldblQkWh(4)) * ldblRTarT(1)) / (1 - (ldblAIcms(1) / 100))
							ldblNVRkWhT(2) = 0
							'
							ldblNVRBan(1) = Truncate((ldblQkWh(1) + ldblQkWh(2) + ldblQkWh(3) + ldblQkWh(4)) * ldblRBan, 2)
							ldblNVRBan(2) = 0
							'
							ldblNVRBanT(1) = ((ldblQkWh(1) + ldblQkWh(2) + ldblQkWh(3) + ldblQkWh(4)) * ldblRBanT(1)) / (1 - (ldblAIcms(1) / 100))
							ldblNVRBanT(2) = 0
						End If
						ldblNBRIcms(1) = ldblNVRkWhT(1) + ldblNVRBanT(1)
						ldblNBRIcms(2) = ldblNVRkWhT(2) + ldblNVRBanT(2)
						ldblNBRPis = ldblNBRIcms(1) + ldblNBRIcms(2)
						ldblNBRCof = ldblNBRPis
						'
						ldblNVRIcms(1) = Truncate(ldblNBRIcms(1) * (ldblAIcms(1) / 100), 2)
						ldblNVRIcms(2) = Truncate(ldblNBRIcms(2) * (ldblAIcms(2) / 100), 2)
						ldblNVRPis = Truncate(ldblNBRPis * (ldblAPis / 100), 2)
						ldblNVRCof = Truncate(ldblNBRCof * (ldblACof / 100), 2)
						'
						lstrSql = ""
						lstrSql = lstrSql & "INSERT INTO recalculo_icms_pis_cofins VALUES ("
						lstrSql = lstrSql & "'" & lstrZona & "', "
						lstrSql = lstrSql & "'" & lstrLivro & "', "
						lstrSql = lstrSql & "'" & lstrConta & "', "
						lstrSql = lstrSql & "" & llngConsId & ", "
						lstrSql = lstrSql & "" & llngUnidId & ", "
						lstrSql = lstrSql & "'" & lstrCodClas & "', "
						lstrSql = lstrSql & "" & ldblNumNf & ", "
						lstrSql = lstrSql & "'" & lstrMesAno & "', "
						lstrSql = lstrSql & "" & llngAnoMes & ", "
						lstrSql = lstrSql & "'" & VB6.Format(ldteAtual, "yyyy-MM-dd") & "', "
						lstrSql = lstrSql & "'" & VB6.Format(ldteAnter, "yyyy-MM-dd") & "', "
						'Quantidade de consumo
						lstrSql = lstrSql & "" & Replace(CStr(ldblQkWh(1) + ldblQkWh(2) + ldblQkWh(3) + ldblQkWh(4)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblQkWh(1)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblQkWh(2)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblQkWh(3)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblQkWh(4)), ",", ".") & ", "
						'Valor de consumo
						lstrSql = lstrSql & "" & Replace(CStr(ldblVkWh(1) + ldblVkWh(2) + ldblVkWh(3) + ldblVkWh(4)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblVkWh(1)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblVkWh(2)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblVkWh(3)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblVkWh(4)), ",", ".") & ", "
						'Valor da receita de bandeira
						lstrSql = lstrSql & "" & Replace(CStr(ldblVBan(1) + ldblVBan(2) + ldblVBan(3) + ldblVBan(4)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblVBan(1)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblVBan(2)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblVBan(3)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblVBan(4)), ",", ".") & ", "
						'Base de Icms, Pis e Cofins
						lstrSql = lstrSql & "" & Replace(CStr(ldblBIcms(1)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblBIcms(2)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblBPis), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblBCof), ",", ".") & ", "
						'Aliquotas de Icms, Pis e Cofins
						lstrSql = lstrSql & "" & Replace(CStr(ldblAIcms(1)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblAIcms(2)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblAPis), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblACof), ",", ".") & ", "
						'Valort de Icms, Pis e Cofins
						lstrSql = lstrSql & "" & Replace(CStr(ldblIcms(1)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblIcms(2)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblPis), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblCof), ",", ".") & ", "
						'Valor da tarifa do baixa renda
						lstrSql = lstrSql & "" & Replace(CStr(ldblVTar(1)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblVTar(2)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblVTar(3)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblVTar(4)), ",", ".") & ", "
						'Valor da tarifa da bandeira do baixa renda
						lstrSql = lstrSql & "" & Replace(CStr(ldblBTar(1)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblBTar(2)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblBTar(3)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblBTar(4)), ",", ".") & ", "
						'Valor da tarifa do baixa renda tributada
						lstrSql = lstrSql & "" & Replace(CStr(ldblVTarT(1)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblVTarT(2)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblVTarT(3)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblVTarT(4)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblVTarT(5)), ",", ".") & ", "
						'Valor da tarifa da bandeira do baixa renda tributada
						lstrSql = lstrSql & "" & Replace(CStr(ldblBTarT(1)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblBTarT(2)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblBTarT(3)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblBTarT(4)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblBTarT(5)), ",", ".") & ", "
						'Valor da tarifa do Residencial
						lstrSql = lstrSql & "" & Replace(CStr(ldblRTar), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblRTarT(1)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblRTarT(2)), ",", ".") & ", "
						'Va;pr da tarifa da bandeira do residencial
						lstrSql = lstrSql & "" & Replace(CStr(ldblRBan), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblRBanT(1)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblRBanT(2)), ",", ".") & ", "
						'Base do Icms, Pis, Cofins com tarifa residencial
						lstrSql = lstrSql & "" & Replace(CStr(Truncate(ldblNBRIcms(1), 2)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(Truncate(ldblNBRIcms(2), 2)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(Truncate(ldblNBRPis, 2)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(Truncate(ldblNBRCof, 2)), ",", ".") & ", "
						'Valor do icms, pis e cofins com tarifa residencial
						lstrSql = lstrSql & "" & Replace(CStr(ldblNVRIcms(1)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblNVRIcms(2)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblNVRPis), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblNVRCof), ",", ".") & ", "
						'Valor do residencial normal
						lstrSql = lstrSql & "" & Replace(CStr(ldblNVRkWh(1) + ldblNVRkWh(2)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblNVRkWh(1)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblNVRkWh(2)), ",", ".") & ", "
						'Valor de receita da bandeira do residencial normal
						lstrSql = lstrSql & "" & Replace(CStr(ldblNVRBan(1) + ldblNVRBan(2)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblNVRBan(1)), ",", ".") & ", "
						lstrSql = lstrSql & "" & Replace(CStr(ldblNVRBan(2)), ",", ".") & ") "
						Call Executar(lstrSql)
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
					End While
				End If
				Call .Close()
				Me.lblInfo.Text = " Finalizado...."
				Call Me.lblInfo.Refresh()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Sub
	
	Private Sub cmdReceitaBandeira_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdReceitaBandeira.Click
		Call frmRelReceitaBandeira.Show()
		Call Me.Close()
	End Sub
	
	
	
	
	Private Sub cmdRelAlimentador_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdRelAlimentador.Click
		'  Dim llngIdA As Long
		'  Dim llngUId As Long
		'  Dim lstrZona As String
		'  Dim lstrLivro As String
		'  Dim lstrConta As String
		'  Dim lstrSql As String
		'  Dim lrstAli As adodb.Recordset
		'  Dim lrstAux As adodb.Recordset
		'  Set lrstAux = New adodb.Recordset
		'  Set lrstAli = New adodb.Recordset
		'
		'  lstrSql = "SELECT zona,livro,conta, unid_id from unidb WHERE idalimentador=0 ORDER BY zona ASC,livro ASC,conta ASC "
		'  Call Conectar(lstrSql, lrstAux)
		'  With lrstAux
		'    If .State = adodb.ObjectStateEnum.adStateOpen Then
		'      If .RecordCount > 0 Then
		'        While Not .EOF
		'          llngUId = IIf(IsNull(.Fields("unid_id").value), 0, .Fields("unid_id").value)
		'          lstrZona = IIf(IsNull(.Fields("zona").value), "", .Fields("zona").value)
		'          lstrLivro = IIf(IsNull(.Fields("livro").value), "", .Fields("livro").value)
		'          lstrConta = IIf(IsNull(.Fields("conta").value), "", .Fields("conta").value)
		'          lstrSql = "SELECT idalimentador FROM unidb WHERE idalimentador>0 AND concat(zona,livro,conta)+0<=" & CDbl(lstrZona & lstrLivro & lstrConta) & " ORDER BY CONCAT(zona,livro,conta) DESC LIMIT 1 "
		'          Call Conectar(lstrSql, lrstAli)
		'          With lrstAli
		'            If .State = adodb.ObjectStateEnum.adStateOpen Then
		'              If .RecordCount > 0 Then
		'                llngIdA = IIf(IsNull(.Fields("idalimentador").value), 0, .Fields("idalimentador").value)
		'                If llngIdA > 0 Then
		'                  lstrSql = "UPDATE unidb set idalimentador = " & llngIdA & " WHERE unid_id = " & llngUId & " AND idalimentador = 0"
		'                  Call Executar(lstrSql)
		'                End If
		'              End If
		'              Call .Close
		'            End If
		'          End With
		'          Call .MoveNext
		'        Wend
		'      End If
		'      Call .Close
		'    End If
		'  End With
		'  Set lrstAux = Nothing
		'  Set lrstAli = Nothing
		
		
		Call frmRelConsumoAlimentador.Show()
	End Sub
	
	Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
		frmRelMicroGeracao.Show()
	End Sub
	
	'Private Function GetIpAddrTable()
	'   Dim Buf(0 To 511) As Byte
	'   Dim BufSize As Long: BufSize = UBound(Buf) + 1
	'   Dim rc As Long
	'   rc = GetIpAddrTable_API(Buf(0), BufSize, 1)
	'   If rc <> 0 Then Err.Raise vbObjectError, , "GetIpAddrTable failed with return value " & rc
	'   Dim NrOfEntries As Integer: NrOfEntries = Buf(1) * 256 + Buf(0)
	'   If NrOfEntries = 0 Then GetIpAddrTable = Array(): Exit Function
	'   ReDim IpAddrs(0 To NrOfEntries - 1) As String
	'   Dim I As Integer
	'   For I = 0 To NrOfEntries - 1
	'      Dim J As Integer, s As String: s = ""
	'      For J = 0 To 3: s = s & IIf(J > 0, ".", "") & Buf(4 + I * 24 + J): Next
	'      IpAddrs(I) = s
	'      Next
	'   GetIpAddrTable = IpAddrs
	'End Function
	
	Private Sub Command12_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command12.Click
		Dim lstrAuxiliar As String
		Dim lstrPrepara As String
		Dim lstrCodigo As String
		Dim lstrDescricao As String
		Dim lstrReferencia As String
		Dim lstrValor As String
		Dim lstrTexto As String
		Dim llngConta As Integer
		Dim lstrSql As String
		Dim ldblNumNf As Double
		Dim lstrMesAno As String
		Dim lrstConsulta As ADODB.Recordset
		
		'lstrMesAno = "11/2008"
		Me.Command12.Enabled = False
		lrstConsulta = New ADODB.Recordset
		Me.lblInfo.Text = " Carregando Faturas, Aguarde..."
		Me.lblInfo.Refresh()
		lstrSql = "SELECT numnf, mesano, itensserv, itensimp " & "  FROM nf " & " WHERE mesano_ref BETWEEN 200101 AND 200703 " & "   AND grupo = 'B' AND itensimp is null and unid_id not in(477,479) " & " ORDER BY mesano_ref ASC, numnf ASC "
		'          & " ORDER BY CONCAT(RIGHT(mesano,4),LEFT(mesano,2)) ASC "
		'  lstrSql = "SELECT numnf, mesano, itensserv, itensimp " _
		''          & "  FROM nf " _
		''          & " WHERE CONCAT(RIGHT(mesano,4),LEFT(mesano,2)) BETWEEN 200811 AND 200811 " _
		''          & "   AND MID(TA,3,1) = ""B"" and numnf = 2410"
		Call Conectar(lstrSql, lrstConsulta)
		If lrstConsulta.RecordCount > 0 Then
			Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, lrstConsulta.RecordCount)
			While Not lrstConsulta.EOF
				Call lblFaturas.Refresh()
				Me.mfgItensFatura.Clear()
				Me.mfgItensFatura.Rows = 0
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				lstrTexto = Trim(IIf(IsDbNull(lrstConsulta.Fields("itensserv").value), "", lrstConsulta.Fields("itensserv").value))
				'      lstrTexto = Replace(Trim(IIf(IsNull(lrstConsulta.Fields("itensimp").Value), "", lrstConsulta.Fields("itensimp").Value)), vbCrLf, "")
				'      lstrAuxiliar = ""
				'      llngConta = 1
				'      While llngConta <= Len(lstrTexto)
				'        If Len(Trim(lstrAuxiliar)) > 0 Then lstrAuxiliar = lstrAuxiliar & vbCrLf
				'        lstrPrepara = Mid(lstrTexto, llngConta, 65)
				'        lstrPrepara = Left(Left(lstrPrepara, Len(lstrPrepara) - 15), 45) & " " & Right("          " & Format(Right(lstrPrepara, 15), "Standard"), 10)
				'        lstrAuxiliar = lstrAuxiliar & "I" & lstrPrepara
				'        llngConta = llngConta + 65
				'      Wend
				
				With Me.mfgItensFatura
					.set_ColWidth(0, 2000)
					.set_ColWidth(1, 4000)
					.set_ColWidth(2, 3000)
					.set_ColWidth(3, 1000)
					For IndCodServ = 1 To Len(lstrTexto)
						Call BuscaCodItem(IndCodServ, lstrTexto)
						If Mid(codserv, 1, 9) = "030202009" Then
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, "01 - " & codserv)
							.set_TextMatrix(.Rows - 1, 1, codTodescri(codserv))
							.set_TextMatrix(.Rows - 1, 2, RefCodServ)
							.set_TextMatrix(.Rows - 1, 3, VB6.Format(Replace(VlrCodServ, ".", ","), "Standard"))
						End If
						If Mid(codserv, 1, 10) = "0302020012" Then
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, "02 - " & codserv)
							.set_TextMatrix(.Rows - 1, 1, codTodescri(codserv))
							.set_TextMatrix(.Rows - 1, 2, RefCodServ)
							.set_TextMatrix(.Rows - 1, 3, VB6.Format(Replace(VlrCodServ, ".", ","), "Standard"))
						End If
						If Mid(codserv, 1, 10) = "0302020029" Then
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, "03 - " & codserv)
							.set_TextMatrix(.Rows - 1, 1, codTodescri(codserv))
							.set_TextMatrix(.Rows - 1, 2, RefCodServ)
							.set_TextMatrix(.Rows - 1, 3, VB6.Format(Replace(VlrCodServ, ".", ","), "Standard"))
						End If
						If Mid(codserv, 1, 10) = "0302020030" Then
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, "04 - " & codserv)
							.set_TextMatrix(.Rows - 1, 1, codTodescri(codserv))
							.set_TextMatrix(.Rows - 1, 2, RefCodServ)
							.set_TextMatrix(.Rows - 1, 3, VB6.Format(Replace(VlrCodServ, ".", ","), "Standard"))
						End If
						If Mid(codserv, 1, 10) = "0302030014" Then
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, "05 - " & codserv)
							.set_TextMatrix(.Rows - 1, 1, codTodescri(codserv))
							.set_TextMatrix(.Rows - 1, 2, RefCodServ)
							.set_TextMatrix(.Rows - 1, 3, VB6.Format(Replace(VlrCodServ, ".", ","), "Standard"))
						End If
						If Mid(codserv, 1, 10) = "0302030009" Then
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, "06 - " & codserv)
							.set_TextMatrix(.Rows - 1, 1, codTodescri(codserv))
							.set_TextMatrix(.Rows - 1, 2, RefCodServ)
							.set_TextMatrix(.Rows - 1, 3, VB6.Format(Replace(VlrCodServ, ".", ","), "Standard"))
						End If
						If Mid(codserv, 1, 4) = "9030" Then
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, "07 - " & codserv)
							.set_TextMatrix(.Rows - 1, 1, codTodescri(codserv))
							.set_TextMatrix(.Rows - 1, 2, RefCodServ)
							.set_TextMatrix(.Rows - 1, 3, VB6.Format(Replace(VlrCodServ, ".", ","), "Standard"))
						End If
						If Mid(codserv, 1, 4) = "9040" Or Mid(codserv, 1, 4) = "9050" Then
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, "08 - " & codserv)
							.set_TextMatrix(.Rows - 1, 1, codTodescri(codserv))
							.set_TextMatrix(.Rows - 1, 2, RefCodServ)
							.set_TextMatrix(.Rows - 1, 3, VB6.Format(Replace(VlrCodServ, ".", ","), "Standard"))
						End If
						If Mid(codserv, 1, 4) = "9070" Then
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, "09 - " & codserv)
							.set_TextMatrix(.Rows - 1, 1, codTodescri(codserv))
							.set_TextMatrix(.Rows - 1, 2, RefCodServ)
							.set_TextMatrix(.Rows - 1, 3, VB6.Format(Replace(VlrCodServ, ".", ","), "Standard"))
						End If
						If Mid(codserv, 1, 4) = "9080" Then
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, "10 - " & codserv)
							.set_TextMatrix(.Rows - 1, 1, codTodescri(codserv))
							.set_TextMatrix(.Rows - 1, 2, RefCodServ)
							.set_TextMatrix(.Rows - 1, 3, VB6.Format(Replace(VlrCodServ, ".", ","), "Standard"))
						End If
						If Mid(codserv, 1, 10) = "0301000003" Then
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, "11 - " & codserv)
							.set_TextMatrix(.Rows - 1, 1, codTodescri(codserv))
							.set_TextMatrix(.Rows - 1, 2, RefCodServ)
							.set_TextMatrix(.Rows - 1, 3, VB6.Format(Replace(VlrCodServ, ".", ","), "Standard"))
						End If
					Next IndCodServ
				End With
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				ldblNumNf = IIf(IsDbNull(lrstConsulta.Fields("numnf").value), 0, lrstConsulta.Fields("numnf").value)
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				lstrMesAno = IIf(IsDbNull(lrstConsulta.Fields("mesano").value), "", lrstConsulta.Fields("mesano").value)
				lblFaturas.Text = lstrMesAno & VB.Right("            " & ldblNumNf, 9)
				lblFaturas.Refresh()
				
				With Me.mfgItensFatura
					.Col = 0
					.Sort = MSFlexGridLib.SortSettings.flexSortStringAscending
					lstrAuxiliar = ""
					For llngConta = 0 To Me.mfgItensFatura.Rows - 1
						If Len(lstrAuxiliar) <> 0 Then lstrAuxiliar = lstrAuxiliar & "\r\n"
						lstrPrepara = VB.Left(.get_TextMatrix(llngConta, 1) & .get_TextMatrix(llngConta, 2) & New String(" ", 50), 50) & VB.Right(New String(" ", 15) & VB6.Format(.get_TextMatrix(llngConta, 3), "Standard"), 15)
						lstrAuxiliar = lstrAuxiliar & lstrPrepara
					Next llngConta
				End With
				Call Executar("UPDATE nf SET itensImp = """ & lstrAuxiliar & """ WHERE numnf = " & ldblNumNf & " AND mesano = '" & lstrMesAno & "' ")
				Call lrstConsulta.MoveNext()
				Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
				System.Windows.Forms.Application.DoEvents()
			End While
		End If
		Me.lblInfo.Text = Me.lblInfo.Text & " FINALIZADO "
		Me.lblInfo.Refresh()
		Me.Command12.Enabled = True
		If lrstConsulta.State = 1 Then Call lrstConsulta.Close()
	End Sub
	
	Private Sub Command13_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command13.Click
		Dim lstrSql As String
		Dim ldteBas As Date
		Dim ldblRow As Double
		ldteBas = CDate(VB6.Format(BuscaDataBD, "dd/MM/yyyy hh:mm:ss"))
		ldteBas = DateAdd(Microsoft.VisualBasic.DateInterval.Day, -30, ldteBas)
		Call myConC.Execute("DELETE FROM " & gstrDataBase & ".`interface_log` WHERE `referencia` <'" & VB6.Format(ldteBas, "yyyy-MM-dd hh:mm:ss") & "';", ldblRow)
		If ldblRow > 0 Then
			Call myConC.Execute("DROP TEMPORARY TABLE IF EXISTS " & gstrDataBase & ".`interface_log_tmp`;")
			lstrSql = ""
			lstrSql = lstrSql & "CREATE TEMPORARY TABLE " & gstrDataBase & ".`interface_log_tmp` "
			lstrSql = lstrSql & "(SELECT `referencia`, `codigo`, `tipo` FROM " & gstrDataBase & ".`interface_log`);"
			Call myConC.Execute(lstrSql)
			Call myConC.Execute("DELETE FROM " & gstrDataBase & ".`interface_log`;")
			Call myConC.Execute("ALTER TABLE " & gstrDataBase & ".`interface_log` AUTO_INCREMENT = 1;")
			lstrSql = ""
			lstrSql = lstrSql & "INSERT INTO " & gstrDataBase & ".`interface_log` (`referencia`, `codigo`, `tipo`) "
			lstrSql = lstrSql & "(SELECT `referencia`, `codigo`, `tipo` FROM " & gstrDataBase & ".`interface_log_tmp`);"
			Call myConC.Execute(lstrSql)
			Call myConC.Execute("DROP TEMPORARY TABLE IF EXISTS " & gstrDataBase & ".`interface_log_tmp`;")
		End If
		
		'  Dim llngConta As Long
		'  Dim lstrErro As String
		'  Dim lstrAux As String
		'  Me.mfgErros.ColWidth(1) = 8000
		'  lstrAux = ""
		'  For llngConta = 0 To 800
		'    lstrErro = Error(llngConta)
		'    If lstrErro <> "Application-defined or object-defined error" Then
		'      With Me.mfgErros
		'        .Rows = .Rows + 1
		'        .TextMatrix(.Rows - 1, 0) = llngConta
		'        .TextMatrix(.Rows - 1, 1) = lstrErro
		'        lstrAux = lstrAux & "gstrErro(" & llngConta & ")=""" & lstrErro & """ " & vbCrLf
		'      End With
		'    End If
		'  Next llngConta
		'  Me.txtErro.Text = lstrAux
	End Sub
	
	Private Sub Command17_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command17.Click
		Dim lstrSql As String
		Dim lstrItens As String
		Dim lrstConsulta As ADODB.Recordset
		lrstConsulta = New ADODB.Recordset
		Me.mfgItens.Clear()
		Me.mfgItens.Rows = 0
		Me.mfgItens.Redraw = False
		mfgItens.set_ColWidth(0, 1000)
		mfgItens.set_ColWidth(1, 1000)
		lstrSql = "SELECT * FROM nf where mesano = '09/2009' and left(codclas,4) = '9101' "
		Call Conectar(lstrSql, lrstConsulta)
		With lrstConsulta
			If .State > 0 Then
				If .RecordCount > 0 Then
					While Not .EOF
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrItens = IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").value)
						With mfgItens
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, BuscaVlrItem(lstrItens, "0302030001"))
						End With
						Call .MoveNext()
					End While
				End If
			End If
		End With
		Me.mfgItens.Redraw = True
	End Sub
	
	Private Sub Command19_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command19.Click
		Dim dtMesAno As Date
		Dim dtPgto As Date
		Dim dtVcto As Date
		Dim diasAtraso As Short
		Dim percMulta As Double
		Dim vlrMulta As Double
		Dim percJuros As Double
		Dim vlrJuros As Double
		Dim vlrCM As Double
		Dim vlrNota As Double
		Dim strsql As String
		Dim dtLoop As Date
		Dim vlrIlum As Double
		Dim vlrConv As Double
		Dim vlrMultAnt As Double
		Dim vlrJuroAnt As Double
		Dim vlrCorrAnt As Double
		Dim strZona As String
		Dim strLivro As String
		Dim strConta As String
		Dim lngId As Integer
		Dim rsFatura As ADODB.Recordset
		rsFatura = New ADODB.Recordset
		
		strsql = "SELECT * FROM daniel order by zona,livro,conta"
		Call Conectar(strsql, rsFatura)
		With rsFatura
			If .RecordCount > 0 Then
				Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount)
				While Not .EOF
					vlrCM = 0
					vlrJuros = 0
					vlrMulta = 0
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					vlrIlum = IIf(IsDbNull(.Fields("iluminacao").value), 0, .Fields("iluminacao").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					vlrConv = IIf(IsDbNull(.Fields("convenios").value), 0, .Fields("convenios").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					vlrMultAnt = IIf(IsDbNull(.Fields("ant_multa").value), 0, .Fields("ant_multa").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					vlrJuroAnt = IIf(IsDbNull(.Fields("ant_juro").value), 0, .Fields("ant_juro").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					vlrCorrAnt = IIf(IsDbNull(.Fields("ant_cm").value), 0, .Fields("ant_cm").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					vlrNota = IIf(IsDbNull(.Fields("valor_nota").value), 0, .Fields("valor_nota").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					dtMesAno = IIf(IsDbNull(.Fields("mesano").value), "1951-01-01", .Fields("mesano").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					strZona = IIf(IsDbNull(.Fields("zona").value), "", .Fields("zona").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					strLivro = IIf(IsDbNull(.Fields("livro").value), "", .Fields("livro").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					strConta = IIf(IsDbNull(.Fields("conta").value), "", .Fields("conta").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					lngId = IIf(IsDbNull(.Fields("id").value), "", .Fields("id").value)
					If vlrNota > 0 Then
						vlrNota = vlrNota - (vlrIlum + vlrConv + vlrMultAnt + vlrJuroAnt + vlrCorrAnt)
					End If
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					dtPgto = IIf(IsDbNull(.Fields("pagto").value), "1951-01-01", .Fields("pagto").value)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					dtVcto = IIf(IsDbNull(.Fields("vecto").value), "1951-01-01", .Fields("vecto").value)
					'UPGRADE_WARNING: DateDiff behavior may be different. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6B38EC3F-686D-4B2E-B5A5-9E8E7A762E32"'
					diasAtraso = DateDiff(Microsoft.VisualBasic.DateInterval.Day, dtVcto, dtPgto)
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					percJuros = (CDbl(IIf(IsDbNull(.Fields("juros").value), 0, .Fields("juros").value)) / 100)
					vlrJuros = ((vlrNota * percJuros) / 365) * diasAtraso
					dtLoop = dtVcto
					While dtLoop <= dtPgto
						vlrCM = vlrCM + (vlrNota * IndiceCMDia(CShort(VB6.Format(dtLoop, "mm")), CShort(VB6.Format(dtLoop, "yyyy"))))
						dtLoop = System.Date.FromOADate(dtLoop.ToOADate + 1)
						System.Windows.Forms.Application.DoEvents()
					End While
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					percMulta = (CDbl(IIf(IsDbNull(.Fields("multa").value), 0, .Fields("multa").value)) / 100)
					vlrMulta = vlrNota * percMulta
					strsql = "update daniel set "
					strsql = strsql & "     vlrmulta = " & Replace(CStr(Arredondar(vlrMulta, 2)), ",", ".") & ", "
					strsql = strsql & "     vlrjuro  = " & Replace(CStr(Arredondar(vlrJuros, 2)), ",", ".") & ", "
					strsql = strsql & "     vlrcm    = " & Replace(CStr(Arredondar(vlrCM, 2)), ",", ".")
					strsql = strsql & " where id   = " & lngId & " "
					
					Call Executar(strsql)
					Call .MoveNext()
					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
				End While
			End If
			If .State = 1 Then Call .Close()
		End With
		'UPGRADE_NOTE: Object rsFatura may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		rsFatura = Nothing
	End Sub
	
	Private Sub Command22_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command22.Click
		Dim lstrLin As String
		Dim lstrTar As String
		Dim llngRow As Integer
		Dim llngCol As Integer
		Dim lintARQ As Short
		Dim lstrCla As String
		Dim lstrIte As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM nf "
		lstrSql = lstrSql & " WHERE nf.mesano = '01/2014' "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount)
			While Not .EOF
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				lstrIte = IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").value)
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				lstrCla = IIf(IsDbNull(.Fields("codclas").value), "", .Fields("codclas").value)
				'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
				lstrTar = Mid(IIf(IsDbNull(.Fields("ta").value), "01B1", .Fields("ta").value), 3, 1)
				With mfgDadosItens
					For IndCodServ = 1 To Len(Trim(lstrIte))
						Call BuscaCodItem(IndCodServ, lstrIte)
						If Mid(codserv, 1, 4) = "9040" Then
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, lstrCla)
							.set_TextMatrix(.Rows - 1, 1, codserv)
							.set_TextMatrix(.Rows - 1, 2, Replace(VlrCodServ, ".", ","))
							.set_TextMatrix(.Rows - 1, 3, lstrTar)
							'UPGRADE_ISSUE: Form method frmteste.Print was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
							Print()
						End If
						'diversos
						If Mid(codserv, 1, 4) = "9080" Then
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, lstrCla)
							.set_TextMatrix(.Rows - 1, 1, codserv)
							.set_TextMatrix(.Rows - 1, 2, Replace(VlrCodServ, ".", ","))
							.set_TextMatrix(.Rows - 1, 3, lstrTar)
						End If
						'convenios
						If Mid(codserv, 1, 4) = "9030" Then
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, lstrCla)
							.set_TextMatrix(.Rows - 1, 1, codserv)
							.set_TextMatrix(.Rows - 1, 2, Replace(VlrCodServ, ".", ","))
							.set_TextMatrix(.Rows - 1, 3, lstrTar)
						End If
						'EUSD - must
						If Mid(codserv, 1, 10) = "0302020032" Then
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, lstrCla)
							.set_TextMatrix(.Rows - 1, 1, codserv)
							.set_TextMatrix(.Rows - 1, 2, Replace(VlrCodServ, ".", ","))
							.set_TextMatrix(.Rows - 1, 3, lstrTar)
						End If
						'retencoes
						If Mid(codserv, 1, 10) = "9070000088" Then 'Não será mais usado (futuro)
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, lstrCla)
							.set_TextMatrix(.Rows - 1, 1, codserv)
							.set_TextMatrix(.Rows - 1, 2, Replace(VlrCodServ, ".", ","))
							.set_TextMatrix(.Rows - 1, 3, lstrTar)
						End If
						If Mid(codserv, 1, 4) = "9090" Then
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, lstrCla)
							.set_TextMatrix(.Rows - 1, 1, codserv)
							.set_TextMatrix(.Rows - 1, 2, Replace(VlrCodServ, ".", ","))
							.set_TextMatrix(.Rows - 1, 3, lstrTar)
						End If
						'Devoluções
						If Mid(codserv, 1, 4) = "9070" And Mid(codserv, 1, 10) <> "9070000088" Then
							.Rows = .Rows + 1
							.set_TextMatrix(.Rows - 1, 0, lstrCla)
							.set_TextMatrix(.Rows - 1, 1, codserv)
							.set_TextMatrix(.Rows - 1, 2, Replace(VlrCodServ, ".", ","))
							.set_TextMatrix(.Rows - 1, 3, lstrTar)
						End If
					Next IndCodServ
				End With
				Call .MoveNext()
				Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
			End While
			Me.mfgDadosItens.Col = 0
			Me.mfgDadosItens.Sort = MSFlexGridLib.SortSettings.flexSortGenericAscending
		End With
		lintARQ = FreeFile
		FileOpen(lintARQ, "E:\Itens.txt", OpenMode.Output)
		With Me.mfgDadosItens
			For llngRow = 0 To .Rows - 1
				lstrLin = ""
				For llngCol = 0 To .Cols - 1
					lstrLin = lstrLin & .get_TextMatrix(llngRow, llngCol) & ";"
				Next llngCol
				PrintLine(lintARQ, lstrLin)
			Next llngRow
		End With
		FileClose(lintARQ)
		Call MsgBox("OK")
		
	End Sub
	
	
	Private Sub Command25_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command25.Click
		frmTseeBxRenda.Show()
		'Dim lstrsql As String
		'Dim rsConsulta As New ADODB.Recordset
		'Dim istrTabela As String
		'
		'  istrTabela = "TSEE_OFICIO_062014"
		'
		'  'DELETA A TABELA
		'  lstrsql = "DROP TABLE IF EXISTS " & istrTabela
		'  Call Executar(lstrsql)
		'
		'  'CRIA A TABELA
		'  lstrsql = ""
		'  lstrsql = lstrsql & "CREATE TABLE " & istrTabela & " ( "
		'  lstrsql = lstrsql & "`codigo_uc` varchar(20) default NULL, "
		'  lstrsql = lstrsql & "`nome` varchar(200) default NULL, "
		'  lstrsql = lstrsql & "`nis_origem` (50) default '0', "
		'  lstrsql = lstrsql & "`nis_11` (50) default '0', "
		'  lstrsql = lstrsql & "`cpf` varchar (20) default NULL, "
		'  lstrsql = lstrsql & "`nis` int(50) default NULL, "
		'  lstrsql = lstrsql & "`V1  int(3)  default '0', "
		'  lstrsql = lstrsql & "`V2` int(3)  default '0', "
		'  lstrsql = lstrsql & "`V3` int(3)  default '0', "
		'  lstrsql = lstrsql & "`V4` int(3)  default '0', "
		'  lstrsql = lstrsql & "`V5` int(3)  default '0', "
		'  lstrsql = lstrsql & "`V6` int(3 )  default '0', "
		'  lstrsql = lstrsql & ") ENGINE=InnoDB DEFAULT CHARSET=latin1; "
		'  Call Executar(lstrsql)
		'
		'
		'
		'    Dim lstrCodigoUc As String
		'    Dim lstrNome  As String
		'    Dim lintNisOrigem  As Integer
		'    Dim lintNis_11 As Integer
		'    Dim lintNis As Integer
		'    Dim lstrCpf As String
		'    Dim lintV1 As Integer
		'    Dim lintV2 As Integer
		'    Dim lintV3 As Integer
		'    Dim lintV4 As Integer
		'    Dim lintV5 As Integer
		'    Dim lintV6 As Integer
		'    Dim verifica As Boolean
		'
		'   'Variáveis Excel
		'
		'    Dim Excel_App As New Excel.Application
		'    Dim Excel_Book As Excel.Workbook
		'    Dim Excel_Sheet As Excel.Worksheet
		'    Dim linha As Long
		'
		'   'Abrir Planilha Excel
		'
		'    Excel_App.Visible = False
		'    Excel_App.Workbooks.Open "E:\ID_86.xls"
		'    Set Excel_Book = Excel_App.Workbooks(1)
		'    Set Excel_Sheet = Excel_Book.Worksheets("ID_86")
		'    Excel_Sheet.Select
		'    linha = True
		'    verifica = True
		'
		'    While verifica = True
		'      If Excel_App.Range("A" & linha).Value <> "" Then
		'        lstrCodigoUc = Excel_App.Range("D" & linha).Value ' CODIGO UC
		'        lstrNome = Excel_App.Range("P" & linha).Value '
		'        lNisOrigem = Excel_App.Range("Q" & linha).Value '
		'        lintNis_11 = Excel_App.Range("R" & linha).Value '
		'        lintNis = Excel_App.Range("Y" & linha).Value '
		'        lstrCpf = Excel_App.Range("S" & linha).Value '
		'        lintV1 = Excel_App.Range("AV" & linha).Value '
		'        lintV2 = Excel_App.Range("AW" & linha).Value '
		'        lintV3 = Excel_App.Range("AX" & linha).Value '
		'        lintV4 = Excel_App.Range("AY" & linha).Value '
		'        lintV5 = Excel_App.Range("AZ" & linha).Value '
		'        lintV6 = Excel_App.Range("BA" & linha).Value '
		'
		'
		'        lstrsql = ""
		'        lstrsql = lstrsql & "INSERT INTO istrTabela SET "
		'        lstrsql = lstrsql & " codigo_uc          = '" & lstrCodigoUc & "', "
		'        lstrsql = lstrsql & " nome           = '" & lstrNome & "', "
		'        lstrsql = lstrsql & " nis_origem          = '" & lintNisOrigem & "', "
		'        lstrsql = lstrsql & " nis11          = '" & lintNis_11 & "', "
		'        lstrsql = lstrsql & " cpf       = '" & lstrCpf & "', "
		'        lstrsql = lstrsql & " nis       = " & lintNis & ", "
		'        lstrsql = lstrsql & " v1       = " & lintV1 & ", "
		'        lstrsql = lstrsql & " v2       = " & lintV2 & ", "
		'        lstrsql = lstrsql & " v3       = " & lintV3 & ", "
		'        lstrsql = lstrsql & " v4       = " & lintV4 & ", "
		'        lstrsql = lstrsql & " v5       = " & lintV5 & ", "
		'        lstrsql = lstrsql & " v6       = " & lintV6 & " "
		'        Executar (lstrsql)
		'
		'        linha = linha + 1
		'      Else
		'        verifica = False
		'      End If
		'    Wend
		'    Excel_App.ActiveWorkbook.Save
		'    Excel_App.Quit
		'    Set Excel_App = Nothing
	End Sub
	
	Private Sub frmteste_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		'Call MsgBox("teste", vbYesNoCancel + vbExclamation, gstrTituloMensagem)
		'tamanho_inicial = btPb.Width
		'Call SetaStatusFrame(Frame1, False)
	End Sub
	
	Private Sub mfgDados_DblClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mfgDados.DblClick
		With Me.mfgDados
			.RemoveItem((.RowSel))
		End With
	End Sub
End Class