Option Strict Off
Option Explicit On
Imports fatd_faturamento.BLL.Repositorio
Imports fatd_faturamento.ENTIDADE
Imports CrystalDecisions.CrystalReports.Engine
Imports vb = Microsoft.VisualBasic
Friend Class frmRelNovoPDD
	Inherits System.Windows.Forms.Form
	'Private ifrmAuxiliar As FrmRelatorio
	Private istrBranco As String
	Private istrCabec As String
	Private istrNomClass As Object
	Private istrCondicao As Object
	Private istrNmCabec As String
	Private istrTamCol As String
	Private istrTabela As String
	Private istrTemp As String
	Private dt, dt1, dt2 As DataTable
	Private objAtualizaBancoDados As New entidadeAtualizaBancoDados
	Private repositorioAtualizaBancoDados As New repositorioAtualizaBancoDados

	Private objExecAtualizaBancoDados As New entidadeAtualizaBancoDados
	Private repositorioExecAtualizaBancoDados As New repositorioAtualizaBancoDados
	Private LImagem() As Byte
	Private sNomeEmpresa As String
	Private sEnderecoEmpresa As String
	Private sCepEmpresa As String
	Private sCidadeEmpresa As String
	Private sUFempresa As String
	Private sBairroEmpresa As String
	Private sFoneEmpresa As String
	Private sWebEmpresa As String
	Private bValida As Boolean
	Private Sub chkComercial_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkComercial.CheckStateChanged
		Try
			With Me.txtLimiteComercial
				.Enabled = (Me.chkComercial.Enabled And Me.chkComercial.CheckState = 1)
				.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Enabled, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
				If .Enabled Then Call .Focus()
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: chkComercial_CheckStateChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub chkConsumoProprio_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkConsumoProprio.CheckStateChanged
		Try
			With Me.txtLimiteConsumoProprio
				.Enabled = (Me.chkConsumoProprio.Enabled And Me.chkConsumoProprio.CheckState = 1)
				.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Enabled, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
				If .Enabled Then Call .Focus()
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: chkConsumoProprio_CheckStateChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	Private Sub chkIluminacaoPublica_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkIluminacaoPublica.CheckStateChanged
		Try
			With Me.txtLimiteIluminacaoPublica
				.Enabled = (Me.chkIndustrial.Enabled And Me.chkIndustrial.CheckState = 1)
				.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Enabled, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
				If .Enabled Then Call .Focus()
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: chkIluminacaoPublica_CheckStateChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	Private Sub chkIndustrial_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkIndustrial.CheckStateChanged
		Try
			With Me.txtLimiteIndustrial
				.Enabled = (Me.chkIndustrial.Enabled And Me.chkIndustrial.CheckState = 1)
				.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Enabled, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
				If .Enabled Then Call .Focus()
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: chkIndustrial_CheckStateChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	Private Sub chkPoderPublico_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkPoderPublico.CheckStateChanged
		Try
			With Me.txtLimitePoderPublico
				.Enabled = (Me.chkPoderPublico.Enabled And Me.chkPoderPublico.CheckState = 1)
				.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Enabled, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
				If .Enabled Then Call .Focus()
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: chkPoderPublico_CheckStateChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	Private Sub chkResidencial_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkResidencial.CheckStateChanged
		Try
			With Me.txtLimiteResidencial
				.Enabled = (Me.chkResidencial.Enabled And Me.chkResidencial.CheckState = 1)
				.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Enabled, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
				If .Enabled Then Call .Focus()
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: chkResidencial_CheckStateChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	Private Sub chkResidencialBxRenda_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkResidencialBxRenda.CheckStateChanged
		Try
			With Me.txtLimiteResidencialBxRenda
				.Enabled = (Me.chkResidencialBxRenda.Enabled And Me.chkResidencialBxRenda.CheckState = 1)
				.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Enabled, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
				If .Enabled Then Call .Focus()
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: chkResidencialBxRenda_CheckStateChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	Private Sub chkRural_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkRural.CheckStateChanged
		Try
			With Me.txtLimiteRural
				.Enabled = (Me.chkRural.Enabled And Me.chkRural.CheckState = 1)
				.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Enabled, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
				If .Enabled Then Call .Focus()
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: chkRural_CheckStateChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try

	End Sub
	Private Sub chkServicoPublico_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkServicoPublico.CheckStateChanged
		Try
			With Me.txtLimiteServicoPublico
				.Enabled = (Me.chkServicoPublico.Enabled And Me.chkServicoPublico.CheckState = 1)
				.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Enabled, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
				If .Enabled Then Call .Focus()
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: chkServicoPublico_CheckStateChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	Private Sub cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click
		Call Me.Close()
	End Sub
	Private Sub cmdImprimir_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdImprimir.Click
		Try
			Dim lstrCodClas As String
			Dim ldblNumNF As Double
			Dim lstrMesAno As String
			Dim lstrZona As String
			Dim lstrLivro As String
			Dim lstrConta As String
			'
			Dim lstrSituacao As String
			Dim ldblDiasRe As Double
			Dim ldblDiasBx As Double
			Dim ldblDiasRu As Double
			Dim ldblDiasIn As Double
			Dim ldblDiasCo As Double
			Dim ldblDiasPP As Double
			Dim ldblDiasIP As Double
			Dim ldblDiasSP As Double
			Dim ldblDiasCP As Double
			Dim ldblTolerancia As Double
			Dim ldteIni As Date
			Dim ldteFim As Date
			'
			Dim lblnReserva As Boolean
			Dim lblnContinua As Boolean
			Dim lstrSql As String
			Dim lngConta As Integer

			lstrSituacao = ""
			If Me.chkLigados.CheckState = System.Windows.Forms.CheckState.Checked Then lstrSituacao = lstrSituacao & "L"
			If Me.chkDesligados.CheckState = System.Windows.Forms.CheckState.Checked Then lstrSituacao = lstrSituacao & "D"
			If Me.chkCortados.CheckState = System.Windows.Forms.CheckState.Checked Then lstrSituacao = lstrSituacao & "C"
			If Me.chkDesativados.CheckState = System.Windows.Forms.CheckState.Checked Then lstrSituacao = lstrSituacao & "I"
			ldblTolerancia = IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0)
			ldblDiasRe = IIf(Me.chkResidencial.CheckState = System.Windows.Forms.CheckState.Checked, IIf(IsNumeric(Me.txtLimiteResidencial.Text), Me.txtLimiteResidencial.Text, 0) + ldblTolerancia, -1)
			ldblDiasBx = IIf(Me.chkResidencialBxRenda.CheckState = System.Windows.Forms.CheckState.Checked, IIf(IsNumeric(Me.txtLimiteResidencialBxRenda.Text), Me.txtLimiteResidencialBxRenda.Text, 0) + ldblTolerancia, -1)
			ldblDiasRu = IIf(Me.chkRural.CheckState = System.Windows.Forms.CheckState.Checked, IIf(IsNumeric(Me.txtLimiteRural.Text), Me.txtLimiteRural.Text, 0) + ldblTolerancia, -1)
			ldblDiasIn = IIf(Me.chkIndustrial.CheckState = System.Windows.Forms.CheckState.Checked, IIf(IsNumeric(Me.txtLimiteIndustrial.Text), Me.txtLimiteIndustrial.Text, 0) + ldblTolerancia, -1)
			ldblDiasCo = IIf(Me.chkComercial.CheckState = System.Windows.Forms.CheckState.Checked, IIf(IsNumeric(Me.txtLimiteComercial.Text), Me.txtLimiteComercial.Text, 0) + ldblTolerancia, -1)
			ldblDiasPP = IIf(Me.chkPoderPublico.CheckState = System.Windows.Forms.CheckState.Checked, IIf(IsNumeric(Me.txtLimitePoderPublico.Text), Me.txtLimitePoderPublico.Text, 0) + ldblTolerancia, -1)
			ldblDiasIP = IIf(Me.chkIluminacaoPublica.CheckState = System.Windows.Forms.CheckState.Checked, IIf(IsNumeric(Me.txtLimiteIluminacaoPublica.Text), Me.txtLimiteIluminacaoPublica.Text, 0) + ldblTolerancia, -1)
			ldblDiasSP = IIf(Me.chkServicoPublico.CheckState = System.Windows.Forms.CheckState.Checked, IIf(IsNumeric(Me.txtLimiteServicoPublico.Text), Me.txtLimiteServicoPublico.Text, 0) + ldblTolerancia, -1)
			ldblDiasCP = IIf(Me.chkConsumoProprio.CheckState = System.Windows.Forms.CheckState.Checked, IIf(IsNumeric(Me.txtLimiteConsumoProprio.Text), Me.txtLimiteConsumoProprio.Text, 0) + ldblTolerancia, -1)
			'
			'istrTabela = "temp_pdd" & LCase(My.Computer.Name & vUsuario.LOGIN)


			lstrSql = ""
			lstrSql = "DELETE FROM AUX_PDD_SINTETICO"
			objExecAtualizaBancoDados.QUERY_NAME = lstrSql
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

			lstrSql = ""
			lstrSql = "DELETE FROM AUX_PDD_SINTETICO_ITENS"
			objExecAtualizaBancoDados.QUERY_NAME = lstrSql
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

			lstrSql = ""
			lstrSql = "DELETE FROM " & istrTabela
			objExecAtualizaBancoDados.QUERY_NAME = lstrSql
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

			lstrSql = ""
			lstrSql = "DELETE FROM " & istrTabela & "_itens"
			objExecAtualizaBancoDados.QUERY_NAME = lstrSql
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

			ldteIni = CDate("01/" & VB6.Format(dtpBase.Value, "MM/yyyy"))
			ldteFim = CDate(UltimoDiaMes(Month(dtpBase.Value), Year(dtpBase.Value)) & "/" & VB6.Format(dtpBase.Value, "MM/yyyy"))

			istrNmCabec = "Total Geral"
			Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
			Call LigDes(False)
			Call RelatorioPaisagemPadraoColunas(istrTamCol, istrCabec, istrTemp, istrBranco, istrNomClass, istrCondicao)
			Me.lblInfo.Text = " Localizando as faturas do período informado..."
			Call Me.lblInfo.Refresh()


			Call RelatorioPaisagemMontaTabela(0, istrTabela, (Me.ProgressBar), (Me.lblInfo), (Me.lblPerc), Me.dtpBase.Value, Me.dtpBase.Value, True, ldblDiasRe, ldblDiasBx, ldblDiasRu, ldblDiasIn, ldblDiasCo, ldblDiasPP, ldblDiasIP, ldblDiasSP, ldblDiasCP, lstrSituacao)

			If bValida Then
				Me.lblInfo.Text = " Montando Relatório..."
				Call Me.lblInfo.Refresh()
				Me.lblInfo.Text = " Imprimindo total geral "
				Call Me.lblInfo.Refresh()
				Call ImprimeTotalGeral()
				Me.lblInfo.Text = " Pronto!"
				Call Me.lblInfo.Refresh()
				Call LigDes(True)
			End If

			Me.Cursor = System.Windows.Forms.Cursors.Default
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdImprimir_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub ImprimeTotalGeral()
		Try

			Dim lstrTab As String
			Dim llngIni As Integer
			Dim llngFim As Integer
			Dim llngAux As Integer
			Dim lintTpRec As Short
			Dim lstrSql As String
			Dim lstrsqlWhere As String
			Dim lstrsqlPrincipal As String

			Dim sTA As String
			Dim dKwhfat As Double
			Dim dConsumo As Double
			Dim dBandeira As Double
			Dim dIcms As Double
			Dim dReativo As Double
			Dim dTip As Double
			Dim dDif_eltrbr As Double
			Dim dEce As Double
			Dim dIcms_ece As Double
			Dim dMulta_ece As Double
			Dim dPis As Double
			Dim dCofins As Double
			Dim dIcmsPisCof As Double
			Dim dTaxados As Double
			Dim dDiversos As Double
			Dim dConvenios As Double
			Dim dRetencao As Double
			Dim dvkwh_dev_p As Double
			Dim dvkwh_dev_fp As Double
			Dim dvkwh_utr_p As Double
			Dim dvkwh_utr_fp As Double
			Dim dicms_st As Double
			Dim dpis_st As Double
			Dim dCofins_st As Double
			Dim dReverso As Double
			Dim dReverso_importe As Double
			Dim dTotal As Double
			Dim dNcons As Double
			Dim dBanco As Double
			Dim ldtePtoPri As Date
			Dim ldtePtoAux As Date
			Dim lstrClasse As String
			Dim lstrBcoPri As String
			Dim sDataPag As String

			Dim dTotal1102 As Double

			llngIni = LBound(istrNomClass)
			llngFim = UBound(istrNomClass)
			istrNmCabec = ""
			'
			lstrsqlPrincipal = RelatorioPaisagemSelecionaDados(0, lstrSql, istrTabela)
			Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, llngFim, " Totalização " & istrNomClass(1))
			For llngAux = llngIni To llngFim - 1

				lstrsqlWhere = lstrsqlPrincipal & " WHERE " & istrCondicao(llngAux)
				objAtualizaBancoDados.QUERY_NAME = lstrsqlWhere
				dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

				If dt.Rows.Count > 0 Then
					For Each row As DataRow In dt.Rows

						'sDataPag = Trim(IIf(IsDBNull(row.Item("datapag")), "", row.Item("datapag")))
						dKwhfat = Trim(IIf(IsDBNull(row.Item("KWHF")), 0, row.Item("KWHF")))
						dConsumo = Trim(IIf(IsDBNull(row.Item("CONSUMO")), 0, row.Item("CONSUMO")))
						dBandeira = Trim(IIf(IsDBNull(row.Item("BANDEIRA")), 0, row.Item("BANDEIRA")))
						dIcms = Trim(IIf(IsDBNull(row.Item("ICMS")), 0, row.Item("ICMS")))
						dReativo = Trim(IIf(IsDBNull(row.Item("REATIVO")), 0, row.Item("REATIVO")))
						dTip = Trim(IIf(IsDBNull(row.Item("TIP")), 0, row.Item("TIP")))
						dDif_eltrbr = Trim(IIf(IsDBNull(row.Item("ELETROBRAS")), 0, row.Item("ELETROBRAS")))
						dEce = Trim(IIf(IsDBNull(row.Item("ECE")), 0, row.Item("ECE")))
						dPis = Trim(IIf(IsDBNull(row.Item("PIS")), 0, row.Item("PIS")))
						dCofins = Trim(IIf(IsDBNull(row.Item("COFINS")), 0, row.Item("COFINS")))
						dIcmsPisCof = Trim(IIf(IsDBNull(row.Item("KWHF")), 0, row.Item("KWHF")))
						dTaxados = Trim(IIf(IsDBNull(row.Item("TAXADOS")), 0, row.Item("TAXADOS")))
						dDiversos = Trim(IIf(IsDBNull(row.Item("DIVERSOS")), 0, row.Item("DIVERSOS")))
						dConvenios = Trim(IIf(IsDBNull(row.Item("CONVENIOS")), 0, row.Item("CONVENIOS")))
						dRetencao = Trim(IIf(IsDBNull(row.Item("RETENCAO")), 0, row.Item("RETENCAO")))
						dTotal1102 = Trim(IIf(IsDBNull(row.Item("importe")), 0, row.Item("importe")))

						'dvkwh_dev_p = Trim(IIf(IsDBNull(row.Item("vkwh_dev_p")), 0, row.Item("vkwh_dev_p")))
						'dvkwh_dev_fp = Trim(IIf(IsDBNull(row.Item("vkwh_dev_fp")), 0, row.Item("vkwh_dev_fp")))
						'dvkwh_utr_p = Trim(IIf(IsDBNull(row.Item("vkwh_utr_p")), 0, row.Item("vkwh_utr_p")))
						'dvkwh_utr_fp = Trim(IIf(IsDBNull(row.Item("vkwh_utr_fp")), 0, row.Item("vkwh_utr_fp")))
						'dIcms_ece = Trim(IIf(IsDBNull(row.Item("KWHF")), 0, row.Item("KWHF")))
						'dMulta_ece = Trim(IIf(IsDBNull(row.Item("KWHF")), 0, row.Item("KWHF")))
						'sTA = Trim(IIf(IsDBNull(row.Item("KWHF")), 0, row.Item("KWHF")))

						dvkwh_dev_p = 0
						dvkwh_dev_fp = 0
						dvkwh_utr_p = 0
						dvkwh_utr_fp = 0
						dIcms_ece = 0
						dMulta_ece = 0
						sTA = 0

						dicms_st = Trim(IIf(IsDBNull(row.Item("ICMS_ST")), 0, row.Item("ICMS_ST")))
						dpis_st = Trim(IIf(IsDBNull(row.Item("PIS_ST")), 0, row.Item("PIS_ST")))
						dCofins_st = Trim(IIf(IsDBNull(row.Item("COFINS_ST")), 0, row.Item("COFINS_ST")))
						dReverso = Trim(IIf(IsDBNull(row.Item("REVERSO")), 0, row.Item("REVERSO")))
						dReverso_importe = Trim(IIf(IsDBNull(row.Item("IMPORTE")), 0, row.Item("IMPORTE")))
						dTotal = Trim(IIf(IsDBNull(row.Item("TOTAL")), 0, row.Item("TOTAL")))
						dNcons = Trim(IIf(IsDBNull(row.Item("NCONS")), 0, row.Item("NCONS")))

						lstrSql = "INSERT INTO AUX_PDD_SINTETICO SET "
						lstrSql = lstrSql & "CLASSE = '" & istrNomClass(llngAux) & "',"
						lstrSql = lstrSql & "NCONS = '" & dNcons & "' ,"
						lstrSql = lstrSql & "KWHFAT = '" & dKwhfat & "',"
						lstrSql = lstrSql & "FORNLIQUIDO = '" & dConsumo & "',"
						lstrSql = lstrSql & "BANDEIRA = '" & dBandeira & "',"
						lstrSql = lstrSql & "ICMS = '" & dIcms & "',"
						lstrSql = lstrSql & "PIS = '" & dPis & "',"
						lstrSql = lstrSql & "COFINS = '" & dCofins & "',"
						lstrSql = lstrSql & "REATIVO = '" & dReativo & "',"

						lstrSql = lstrSql & "DIFDEMANDA = '" & dReverso & "' ,"
						lstrSql = lstrSql & "SUBSIDIO = '" & dRetencao & "',"
						lstrSql = lstrSql & "SUBTRIB = '" & dicms_st + dpis_st + dCofins_st & "',"
						lstrSql = lstrSql & "TOTAL1102 = '" & dTotal1102 & "',"
						lstrSql = lstrSql & "ILUMPUB = '" & dTip & "',"
						lstrSql = lstrSql & "JELETR= '" & dDif_eltrbr & "',"

						lstrSql = lstrSql & "TAXADOS = '" & dTaxados & "',"
						lstrSql = lstrSql & "DIVERSOS = '" & dDiversos & "',"
						lstrSql = lstrSql & "CONVENIOS = '" & dConvenios & "',"
						lstrSql = lstrSql & "TOTAL = '" & dTotal & "',"
						lstrSql = lstrSql & "TOTALLIQUIDO = '" & dReverso_importe & "',"
						lstrSql = lstrSql & "REVERSO = '" & dReverso & "'"
						objExecAtualizaBancoDados.QUERY_NAME = lstrSql
						repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

					Next
				End If

				Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " Totalização " & istrNomClass(llngAux))
			Next llngAux

			Call ImprimeDetalhamentosPaisagem2(istrTabela & "_itens", 0, 3, 2)

			Call sDadosEmpresa(LImagem, sNomeEmpresa, sEnderecoEmpresa, sCepEmpresa, sCidadeEmpresa, sUFempresa, sBairroEmpresa, sFoneEmpresa, sWebEmpresa)
			Call lPrint("rptRelPDDSintetico")

		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: ImprimeTotalGeral" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub frmRelNovoPDD_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
		Try
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = System.Windows.Forms.Keys.Escape Then
				Call cmdFechar_Click(cmdFechar, New System.EventArgs())
			ElseIf KeyAscii = System.Windows.Forms.Keys.Return Then
				'Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
				TabEnter(KeyAscii, eventArgs)
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: frmRelNovoPDD_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub frmRelNovoPDD_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Dim lstrFaixa As String
		Dim lintPos As Short
		Dim lstrSql As String

		Try
			'
			'Call CenterForm(Me)
			istrTabela = "temp_pdd" & LCase("_" & My.Computer.Name.Replace("-", "") & "_" & vUsuario.LOGIN)
			Me.txtResTol.Text = "000"
			'Monta as faixas de dias das classes
			lstrFaixa = Trim(GetConfig("pdd.limites"))
			If lstrFaixa <> "" And lstrFaixa <> "-1" Then
				lintPos = 1
				Me.txtLimiteResidencial.Text = Mid(lstrFaixa, lintPos, 3)
				lintPos = InStr(lintPos, lstrFaixa, ";") + 1
				Me.txtLimiteIndustrial.Text = Mid(lstrFaixa, lintPos, 3)
				lintPos = InStr(lintPos, lstrFaixa, ";") + 1
				Me.txtLimiteComercial.Text = Mid(lstrFaixa, lintPos, 3)
				lintPos = InStr(lintPos, lstrFaixa, ";") + 1
				Me.txtLimiteRural.Text = Mid(lstrFaixa, lintPos, 3)
				lintPos = InStr(lintPos, lstrFaixa, ";") + 1
				Me.txtLimitePoderPublico.Text = Mid(lstrFaixa, lintPos, 3)
				lintPos = InStr(lintPos, lstrFaixa, ";") + 1
				Me.txtLimiteIluminacaoPublica.Text = Mid(lstrFaixa, lintPos, 3)
				lintPos = InStr(lintPos, lstrFaixa, ";") + 1
				Me.txtLimiteConsumoProprio.Text = Mid(lstrFaixa, lintPos, 3)
				lintPos = InStr(lintPos, lstrFaixa, ";") + 1
				Me.txtLimiteServicoPublico.Text = Mid(lstrFaixa, lintPos, 3)
				lintPos = InStr(lintPos, lstrFaixa, ";") + 1
				Me.txtLimiteResidencialBxRenda.Text = Mid(lstrFaixa, lintPos, 3)
			End If
			Me.dtpBase.Value = Date.Now()
			Call sCriaTabelaAuxiliar()

		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: frmRelNovoPDD_Load" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	'Private Sub frmRelNovoPDD_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
	'	If istrTabela <> "" Then
	'		Call Executar("DROP TEMPORARY TABLE IF EXISTS " & istrTabela)
	'		Call Executar("DROP TEMPORARY TABLE IF EXISTS " & istrTabela & "_itens")
	'	End If
	'	'If irstFaturas.State = ADODB.ObjectStateEnum.adStateOpen Then Call irstFaturas.Close
	'	'UPGRADE_NOTE: Object irstFaturas 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"'
	'	irstFaturas = Nothing
	'	'UPGRADE_NOTE: Object ifrmAuxiliar 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"'
	'	ifrmAuxiliar = Nothing
	'End Sub

	Private Sub txtLimiteComercial_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteComercial.Enter
		Try
			With Me.txtLimiteComercial
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteComercial_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteComercial_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtLimiteComercial.KeyPress
		Try
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = System.Windows.Forms.Keys.Return Then
				'Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
				TabEnter(KeyAscii, eventArgs)
			ElseIf KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
				KeyAscii = 0
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteComercial_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteComercial_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteComercial.Leave
		Try
			With Me.txtLimiteComercial
				.Text = VB6.Format(.Text, "000")
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteComercial_Leave" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteConsumoProprio_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteConsumoProprio.Enter
		Try
			With Me.txtLimiteConsumoProprio
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteConsumoProprio_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteConsumoProprio_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtLimiteConsumoProprio.KeyPress
		Try
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = System.Windows.Forms.Keys.Return Then
				'Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
				TabEnter(KeyAscii, eventArgs)
			ElseIf KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
				KeyAscii = 0
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteConsumoProprio_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteConsumoProprio_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteConsumoProprio.Leave
		Try
			With Me.txtLimiteConsumoProprio
				.Text = VB6.Format(.Text, "000")
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteConsumoProprio_Leave" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteIluminacaoPublica_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteIluminacaoPublica.Enter
		Try
			With Me.txtLimiteIluminacaoPublica
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteIluminacaoPublica_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteIluminacaoPublica_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtLimiteIluminacaoPublica.KeyPress
		Try
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = System.Windows.Forms.Keys.Return Then
				'Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
				TabEnter(KeyAscii, eventArgs)
			ElseIf KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
				KeyAscii = 0
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteIluminacaoPublica_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteIluminacaoPublica_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteIluminacaoPublica.Leave
		Try
			With Me.txtLimiteIluminacaoPublica
				.Text = VB6.Format(.Text, "000")
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteIluminacaoPublica_Leave" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteIndustrial_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteIndustrial.Enter
		Try
			With Me.txtLimiteIndustrial
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteIndustrial_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteIndustrial_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtLimiteIndustrial.KeyPress
		Try
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = System.Windows.Forms.Keys.Return Then
				'Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
				TabEnter(KeyAscii, eventArgs)
			ElseIf KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
				KeyAscii = 0
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteIndustrial_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteIndustrial_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteIndustrial.Leave
		Try
			With Me.txtLimiteIndustrial
				.Text = VB6.Format(.Text, "000")
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteIndustrial_Leave" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimitePoderPublico_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimitePoderPublico.Enter
		Try
			With Me.txtLimitePoderPublico
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimitePoderPublico_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimitePoderPublico_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtLimitePoderPublico.KeyPress
		Try
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = System.Windows.Forms.Keys.Return Then
				'Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
				TabEnter(KeyAscii, eventArgs)
			ElseIf KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
				KeyAscii = 0
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimitePoderPublico_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimitePoderPublico_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimitePoderPublico.Leave
		Try
			With Me.txtLimitePoderPublico
				.Text = VB6.Format(.Text, "000")
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimitePoderPublico_Leave" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteResidencial_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteResidencial.Enter
		Try
			With Me.txtLimiteResidencial
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteResidencial_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteResidencial_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtLimiteResidencial.KeyPress
		Try
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = System.Windows.Forms.Keys.Return Then
				'Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
				TabEnter(KeyAscii, eventArgs)
			ElseIf KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
				KeyAscii = 0
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteResidencial_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteResidencial_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteResidencial.Leave
		Try
			With Me.txtLimiteResidencial
				.Text = VB6.Format(.Text, "000")
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteResidencial_Leave" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteResidencialBxRenda_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteResidencialBxRenda.Enter
		Try
			With Me.txtLimiteResidencialBxRenda
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteResidencialBxRenda_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteResidencialBxRenda_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtLimiteResidencialBxRenda.KeyPress
		Try
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = System.Windows.Forms.Keys.Return Then
				'Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
				TabEnter(KeyAscii, eventArgs)
			ElseIf KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
				KeyAscii = 0
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteResidencialBxRenda_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteResidencialBxRenda_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteResidencialBxRenda.Leave
		Try
			With Me.txtLimiteResidencialBxRenda
				.Text = VB6.Format(.Text, "000")
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteResidencialBxRenda_Leave" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteRural_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteRural.Enter
		Try
			With Me.txtLimiteRural
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteRural_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteRural_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtLimiteRural.KeyPress
		Try
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = System.Windows.Forms.Keys.Return Then
				'Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
				TabEnter(KeyAscii, eventArgs)
			ElseIf KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
				KeyAscii = 0
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteRural_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteRural_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteRural.Leave
		Try
			With Me.txtLimiteRural
				.Text = VB6.Format(.Text, "000")
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteRural_Leave" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteServicoPublico_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteServicoPublico.Enter
		Try
			With Me.txtLimiteServicoPublico
				.SelectionStart = 0
				.SelectionLength = Len(.Text)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: sCriaTabelaAuxiliar" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
		Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteServicoPublico_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtLimiteServicoPublico.KeyPress
		Try
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = System.Windows.Forms.Keys.Return Then
				'Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
				TabEnter(KeyAscii, eventArgs)
			ElseIf KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
				KeyAscii = 0
			End If
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteServicoPublico_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtLimiteServicoPublico_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteServicoPublico.Leave
		Try
			With Me.txtLimiteServicoPublico
				.Text = VB6.Format(.Text, "000")
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtLimiteServicoPublico_Leave" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtResTol_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtResTol.Enter
		Try
			With Me.txtResTol
				.SelectionStart = 0
				.SelectionLength = CInt(Len(.Text))
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtResTol_Enter" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtResTol_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtResTol.KeyPress
		Try
			Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
			If KeyAscii = System.Windows.Forms.Keys.Return Then
				'Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
				TabEnter(KeyAscii, eventArgs)
			ElseIf KeyAscii <> System.Windows.Forms.Keys.Back And (KeyAscii < System.Windows.Forms.Keys.D0 Or KeyAscii > System.Windows.Forms.Keys.D9) Then
				KeyAscii = 0
			End If

			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtResTol_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub txtResTol_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtResTol.Leave
		Try
			With Me.txtResTol
				If CInt(Len(Trim(.Text))) = 0 Then
					.Text = "0"
				End If
				.Text = VB6.Format(.Text, "000")
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: txtResTol_Leave" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub LigDes(ByVal ablnModo As Boolean)
		Try
			Me.cmdFechar.Enabled = ablnModo
			Me.cmdImprimir.Enabled = ablnModo
			Me.dtpBase.Enabled = ablnModo
			With Me.txtResTol
				.Enabled = ablnModo
				.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Enabled, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
			End With
			Me.chkComercial.Enabled = ablnModo
			Me.chkConsumoProprio.Enabled = ablnModo
			Me.chkIluminacaoPublica.Enabled = ablnModo
			Me.chkIndustrial.Enabled = ablnModo
			Me.chkJudice.Enabled = ablnModo
			Me.chkPoderPublico.Enabled = ablnModo
			Me.chkResidencial.Enabled = ablnModo
			Me.chkResidencialBxRenda.Enabled = ablnModo
			Me.chkRural.Enabled = ablnModo
			Me.chkServicoPublico.Enabled = ablnModo
			Me.chkLigados.Enabled = ablnModo
			Me.chkDesativados.Enabled = ablnModo
			Me.chkDesligados.Enabled = ablnModo
			Me.chkCortados.Enabled = ablnModo
			With Me.txtLimiteComercial
				.Enabled = (Me.chkComercial.Enabled And Me.chkComercial.CheckState = 1)
				.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Enabled, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
			End With
			With Me.txtLimiteConsumoProprio
				.Enabled = (Me.chkConsumoProprio.Enabled And Me.chkConsumoProprio.CheckState = 1)
				.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Enabled, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
			End With
			With Me.txtLimiteIluminacaoPublica
				.Enabled = (Me.chkIndustrial.Enabled And Me.chkIndustrial.CheckState = 1)
				.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Enabled, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
			End With
			With Me.txtLimiteIndustrial
				.Enabled = (Me.chkIndustrial.Enabled And Me.chkIndustrial.CheckState = 1)
				.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Enabled, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
			End With
			With Me.txtLimitePoderPublico
				.Enabled = (Me.chkPoderPublico.Enabled And Me.chkPoderPublico.CheckState = 1)
				.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Enabled, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
			End With
			With Me.txtLimiteResidencial
				.Enabled = (Me.chkResidencial.Enabled And Me.chkResidencial.CheckState = 1)
				.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Enabled, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
			End With
			With Me.txtLimiteResidencialBxRenda
				.Enabled = (Me.chkResidencialBxRenda.Enabled And Me.chkResidencialBxRenda.CheckState = 1)
				.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Enabled, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
			End With
			With Me.txtLimiteRural
				.Enabled = (Me.chkRural.Enabled And Me.chkRural.CheckState = 1)
				.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Enabled, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
			End With
			With Me.txtLimiteServicoPublico
				.Enabled = (Me.chkServicoPublico.Enabled And Me.chkServicoPublico.CheckState = 1)
				.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(.Enabled, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Control)))
			End With
			System.Windows.Forms.Application.DoEvents()

		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: LigDes" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try

	End Sub



	Public Sub RelatorioPaisagemMontaTabela(ByVal aintTipoRel As Integer, ByRef astrTabela As String, ByRef aProgressBar As ProgressBar, ByRef alblInfo As Label, ByRef alblPerc As Label, Optional ByVal adteBase As String = "", Optional ByVal adteFim As String = "",
Optional ByVal ablnPdd As Boolean = False, Optional ByVal adblDiasRe As Double = 0, Optional ByVal adblDiasBx As Double = 0, Optional ByVal adblDiasRu As Double = 0,
Optional ByVal adblDiasIn As Double = 0, Optional ByVal adblDiasCo As Double = 0, Optional ByVal adblDiasPP As Double = 0, Optional ByVal adblDiasIP As Double = 0,
Optional ByVal adblDiasSP As Double = 0, Optional ByVal adblDiasCP As Double = 0, Optional ByVal astrSituacao As String = "LDCI", Optional ByVal aintSomenteMicroGeradoras As Integer = 0)

		Dim lstrSql As String
		Dim lstrSqlIte As String
		Dim lstrSqlRes As String
		Dim llngSql As Long
		'
		Dim lblnContinua As Boolean
		Dim lblnInclui As Boolean
		Dim lintTpRec As Integer
		Dim ldblResNumNf As Double
		' Valores
		Dim lstrItens As String
		Dim ldblVlrAux As Double
		Dim ldblVkWhTU As Double
		Dim ldblVkWhTE As Double
		Dim ldblVkWhTEBan As Double
		Dim ldblVkWhNormal As Double
		Dim ldblVkWhNormalBan As Double
		Dim ldblVReverso As Double
		Dim ldblVReversoImporte As Double
		Dim ldblVlrTot As Double
		Dim ldblQkWhFatPo As Double
		Dim ldblQKwhFatfp As Double
		Dim ldblVkWhFatPo As Double
		Dim ldblVKwhFatfp As Double
		'
		Dim ldblQkWhFatPoBan As Double
		Dim ldblQKwhFatfpBan As Double
		Dim ldblVkWhFatPoBan As Double
		Dim ldblVKwhFatfpBan As Double
		'
		Dim ldblVlrDiv As Double
		Dim ldblVlrTax As Double
		Dim ldblVlrCov As Double
		Dim ldblVlrDes As Double
		Dim ldblVlrRet As Double
		Dim ldblVlrOut As Double
		Dim ldlbCodSrv As Double
		'PLD - antigo
		Dim ldblVkWhDevPo As Double
		Dim ldblVKwhDevfp As Double
		Dim ldblVkWhUtrPo As Double
		Dim ldblVKwhUtrfp As Double
		'Dados de identificação
		Dim ldblNumNF As Double
		Dim lstrMesAno As String
		Dim llngAnoMes As Long
		Dim lstrSituacao As String
		Dim lstrNome As String
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim llngUnidId As Long
		Dim llngConsId As String
		Dim lstrClas As String
		Dim lstrGrupo As String
		Dim ldtePgto As Date
		Dim ldteVcto As Date
		Dim llngDias As Long
		Dim lstrLivEsp As String
		Dim ldteFlgSt As Date
		Dim lstrFlgSt As String
		Dim lstrIdBanco As String
		Dim lstrNmBanco As String
		'Substituição Tributária
		Dim ldblIcmsSt As Double
		Dim ldblPisSt As Double
		Dim ldblCofinsSt As Double
		'cooperativas
		Dim ldblVConsCoperativaP As Double
		Dim ldblVConsCoperativaFP As Double
		Dim ldblVDemP As Double
		Dim ldblVDemFP As Double
		Dim ldblVPis As Double
		Dim ldblVCofins As Double
		'
		Dim lintMicroGeracaoConvenioSefaz As Integer
		'
		Dim ldteAux

		Try
			'
			'alblInfo.Caption = " Preparando as tabelas auxiliares..."
			'Call alblInfo.Refresh()
			ldteAux = Date.Now()
			llngSql = 0
			lblnContinua = True
			bValida = False

			'lstrSql = ""
			'lstrSql = lstrSql & "SELECT `nf`.*, "
			'lstrSql = lstrSql & "       0   `reserva_numnf`, " & vbCrLf
			'lstrSql = lstrSql & "       ''  `reserva_mesano`, " & vbCrLf
			'lstrSql = lstrSql & "       '0000-00-00' `reserva_datares` " & vbCrLf
			'lstrSql = lstrSql & "  FROM `nf` " & vbCrLf
			'lstrSql = lstrSql & " WHERE  `nf`.`datavenc` <= '" & VB6.Format(Me.dtpBase.Value, "yyyy-MM-dd") & "' " & vbCrLf
			'lstrSql = lstrSql & "   AND (`nf`.`datapag` = '0000-00-00' OR `nf`.`datapag` = '1900-01-01' OR `nf`.`datapag` > '" & VB6.Format(Me.dtpBase.Value, "yyyy-MM-dd") & "') " & vbCrLf
			'If Me.chkJudice.CheckState = 1 Then
			'	lstrSql = lstrSql & " AND (`nf`.`flgst` NOT IN('C','R') OR (`nf`.`flgst` = 'C' AND `nf`.`datast` > '" & VB6.Format(Me.dtpBase.Value, "yyyy-MM-dd") & "')) " & vbCrLf
			'Else
			'	lstrSql = lstrSql & " AND (`nf`.`flgst` NOT IN('C','R','J') OR (`nf`.`flgst` = 'C' AND `nf`.`datast` > '" & VB6.Format(Me.dtpBase.Value, "yyyy-MM-dd") & "')) " & vbCrLf
			'End If

			lstrSql = lstrSql & " AND  `nf`.`datavenc` <= '" & VB6.Format(Me.dtpBase.Value, "yyyy-MM-dd") & "' " & vbCrLf
			lstrSql = lstrSql & "   AND (`nf`.`datapag` = '0000-00-00' OR `nf`.`datapag` = '1900-01-01' OR `nf`.`datapag` > '" & VB6.Format(Me.dtpBase.Value, "yyyy-MM-dd") & "') " & vbCrLf

			If Me.chkJudice.CheckState = 1 Then
				lstrSql = lstrSql & " AND (`nf`.`flgst` NOT IN('C','R') OR (`nf`.`flgst` = 'C' AND `nf`.`datast` > '" & VB6.Format(Me.dtpBase.Value, "yyyy-MM-dd") & "')) " & vbCrLf
			Else
				lstrSql = lstrSql & " AND (`nf`.`flgst` NOT IN('C','R','J') OR (`nf`.`flgst` = 'C' AND `nf`.`datast` > '" & VB6.Format(Me.dtpBase.Value, "yyyy-MM-dd") & "')) " & vbCrLf
			End If

			lstrSql = lstrSql & " AND nf.codclas>= 5000 and nf.codclas <=5999"

			objAtualizaBancoDados.QUERY_NAME = fRetornaView_Recebimentos(lstrSql, "NF", True)
			dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

			If dt.Rows.Count > 0 Then
				bValida = True
				Call BarraProgresso(aProgressBar, alblPerc, alblInfo, 0, dt.Rows.Count)
				For Each row As DataRow In dt.Rows
					ldblNumNF = CDbl(IIf(IsDBNull(row.Item("numnf")), 0, row.Item("numnf")))
					lstrMesAno = Strings.Trim(IIf(IsDBNull(row.Item("mesano")), "", row.Item("mesano")))
					llngAnoMes = CLng(IIf(IsDBNull(row.Item("mesano_ref")), 0, row.Item("mesano_ref")))
					lstrZona = Strings.Trim(IIf(IsDBNull(row.Item("zona")), "", row.Item("zona")))
					lstrLivro = Strings.Trim(IIf(IsDBNull(row.Item("livro")), "", row.Item("livro")))
					lstrConta = Strings.Trim(IIf(IsDBNull(row.Item("conta")), "", row.Item("conta")))
					llngUnidId = CLng(IIf(IsDBNull(row.Item("unid_id")), 0, row.Item("unid_id")))
					llngConsId = CLng(IIf(IsDBNull(row.Item("cons_id")), 0, row.Item("cons_id")))
					ldtePgto = CDate(IIf(IsDBNull(row.Item("datapag")), ldteAux, row.Item("datapag")))
					ldteVcto = CDate(IIf(IsDBNull(row.Item("datavenc")), ldteAux, row.Item("datavenc")))
					lstrClas = Strings.Trim(IIf(IsDBNull(row.Item("codclas")), "0000", row.Item("codclas")))
					lstrGrupo = Strings.UCase(Strings.Mid(Strings.Trim(IIf(IsDBNull(row.Item("ta")), "00I0", row.Item("ta"))), 3, 2))
					lstrFlgSt = Trim(IIf(IsDBNull(row.Item("flgst")), "", row.Item("flgst")))
					ldteFlgSt = CDate(IIf(IsDBNull(row.Item("datast")), "1900-01-01", row.Item("datast")))
					lintMicroGeracaoConvenioSefaz = CInt(IIf(IsDBNull(row.Item("micro_geracao_convenio_sefaz")), 0, row.Item("micro_geracao_convenio_sefaz")))
					'
					lstrIdBanco = Strings.Trim(IIf(IsDBNull(row.Item("banarrec")), "000", row.Item("banarrec")))
					lstrNmBanco = BuscaNMBanco(lstrIdBanco)
					'
					lstrItens = Strings.Trim(IIf(IsDBNull(row.Item("itensserv")), "", row.Item("itensserv")))
					'Verifica se este recebimento estava na reserva
					ldblResNumNf = 0 'CDbl(IIf(IsDBNull(row.Item("reserva_numnf")), 0, row.Item("reserva_numnf")))
					lintTpRec = IIf((ldblResNumNf > 0), 2, 1)
					'lintTpRec = IIf(VerificaReserva(ldblNumNF, lstrMesAno, lstrZona, lstrLivro, lstrConta) = True, 2, 1)
					ldblVlrTot = CDbl(IIf(IsDBNull(row.Item("valorliq")), 0, row.Item("valorliq")))
					If ldblVlrTot = 0 Then
						ldblVlrTot = CDbl(IIf(IsDBNull(row.Item("valortot")), 0, row.Item("valortot")))
					End If
					'
					'Aqui começa o controle se for PDD
					If ablnPdd Then
						lstrNome = RetornaNomeConsumidor(lstrZona, lstrLivro, lstrConta, llngUnidId, llngConsId, lstrGrupo, lstrSituacao)
						llngDias = DateDiff("d", ldteVcto, adteBase)
						lstrSqlRes = ""
						lstrSqlRes = lstrSqlRes & "SELECT `numnf`,`mesano`,`zona`,`livro`,`conta`,`datares` " & vbCrLf
						lstrSqlRes = lstrSqlRes & "  FROM `reserva` " & vbCrLf
						lstrSqlRes = lstrSqlRes & " WHERE `numnf`    =  " & ldblNumNF & " " & vbCrLf
						lstrSqlRes = lstrSqlRes & "   AND `mesano`   = '" & lstrMesAno & "' " & vbCrLf
						lstrSqlRes = lstrSqlRes & "   AND `zona`     = '" & lstrZona & "' " & vbCrLf
						lstrSqlRes = lstrSqlRes & "   AND `livro`    = '" & lstrLivro & "' " & vbCrLf
						lstrSqlRes = lstrSqlRes & "   AND `conta`    = '" & lstrConta & "' " & vbCrLf
						lstrSqlRes = lstrSqlRes & "   AND `datares` <= '" & Strings.Format(adteBase, "yyyy-MM-dd") & "' "
						objAtualizaBancoDados.QUERY_NAME = lstrSqlRes
						dt1 = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

						'With lrstAuxRe
						'	If .State = ADODB.ObjectStateEnum.adStateOpen Then
						lblnContinua = (dt1.Rows.Count = 0)
						'		Call .Close
						'	End If
						'End With

						If lblnContinua Then
							If CInt(Strings.Left(lstrClas, 1)) = 9 Then
								If lstrClas = "9101" Then
									lblnContinua = (adblDiasRe >= 0 And llngDias > adblDiasRe)
								Else
									lblnContinua = (adblDiasBx >= 0 And llngDias > adblDiasBx)
								End If
							ElseIf CInt(Strings.Left(lstrClas, 1)) <= 3 Then
								lblnContinua = (adblDiasIn >= 0 And llngDias > adblDiasIn)
							ElseIf CInt(Strings.Left(lstrClas, 1)) = 4 Then
								lblnContinua = (adblDiasCo >= 0 And llngDias > adblDiasCo)
							ElseIf CInt(Strings.Left(lstrClas, 1)) = 5 Then
								lblnContinua = (adblDiasRu >= 0 And llngDias > adblDiasRu)
							ElseIf CInt(Strings.Left(lstrClas, 1)) = 6 Then
								If CInt(Strings.Left(lstrClas, 2)) = 64 Then
									lblnContinua = (adblDiasIP >= 0 And llngDias > adblDiasIP)
								Else
									lblnContinua = (adblDiasPP >= 0 And llngDias > adblDiasPP)
								End If
							ElseIf CInt(Strings.Left(lstrClas, 1)) = 7 Then
								lblnContinua = (adblDiasSP >= 0 And llngDias > adblDiasSP)
							ElseIf CInt(Strings.Left(lstrClas, 1)) = 8 Then
								lblnContinua = (adblDiasCP >= 0 And llngDias > adblDiasCP)
							End If
							If lblnContinua Then
								lblnContinua = (Strings.InStr(1, astrSituacao, lstrSituacao) > 0)
							End If
						End If
					End If
					If lblnContinua Then
						'
						ldblVkWhDevPo = BuscaVlrItem(lstrItens, "0302020041")  'Valor Consumo devolvido na p
						ldblVKwhDevfp = BuscaVlrItem(lstrItens, "0302020042") 'Valor Consumo devolvido na fp
						ldblVkWhUtrPo = BuscaVlrItem(lstrItens, "0302020043")  'Valor Consumo ultrapassado na p
						ldblVKwhUtrfp = BuscaVlrItem(lstrItens, "0302020044") 'Valor Consumo ultrapassado na fp
						'
						'Montando o script até 300 Inserções por vez no banco de dados
						If llngSql >= 300 Then
							objExecAtualizaBancoDados.QUERY_NAME = lstrSql
							repositorioAtualizaBancoDados.Execute(objExecAtualizaBancoDados)
							llngSql = 0
							lstrSql = ""
						End If
						If llngSql = 0 Then
							lstrSql = "INSERT INTO " & astrTabela & " VALUES ("
						Else
							lstrSql = lstrSql & ",("
						End If
						lstrSql = lstrSql & lintTpRec & ","
						'Resumo Diário
						If aintTipoRel = 1 Then
							lstrSql = lstrSql & "'" & Strings.Format(ldtePgto, "yyyy-MM-dd") & "'," 'datapag
						Else
							lstrSql = lstrSql & "'0000-00-00'," 'datapag
						End If
						lstrSql = lstrSql & "'" & lstrClas & "'," ' classe
						If Strings.Left(lstrGrupo, 2) = "AL" Then
							lstrLivEsp = BuscaLivreEspecial(llngUnidId)
						Else
							lstrLivEsp = ""
						End If
						lstrSql = lstrSql & "'" & lstrGrupo & lstrLivEsp & "'," 'ta
						'Banco
						lstrSql = lstrSql & "'" & CInt(IIf(IsNumeric(lstrIdBanco), lstrIdBanco, 0)) & "'," ' banco
						lstrSql = lstrSql & "'" & lstrNmBanco & "'," ' nome banco
						'

						'Quantidade de Consumo Faturado - kwh fat
						ldblVlrAux = 0
						If Strings.Left(lstrGrupo, 1) = "A" Then
							ldblVlrAux = BuscaVlrItem(lstrItens, "0302010009")
							ldblQkWhFatPo = BuscaVlrItem(lstrItens, "0302010010") + BuscaVlrItem(lstrItens, "0302010060") 'Consumo Lido na Ponta
							ldblQKwhFatfp = BuscaVlrItem(lstrItens, "0302010011") + BuscaVlrItem(lstrItens, "0302010061") 'Consumo Lido na Fora Ponta
							ldblVlrAux = ldblVlrAux + ldblQkWhFatPo + ldblQKwhFatfp
						Else
							ldblVlrAux = ldblVlrAux + BuscaVlrItem(lstrItens, "030201009") + BuscaVlrItem(lstrItens, "030201019") + BuscaVlrItem(lstrItens, "030201029") + BuscaVlrItem(lstrItens, "030201039") 'por Faixa de consumo Grupo B
						End If
						lstrSql = lstrSql & " " & Strings.Replace(ldblVlrAux, ",", ".") & ","
						'
						'Valor do Consumo Faturado - consumo
						ldblVlrAux = 0
						ldblVkWhNormal = 0
						ldblVReverso = 0
						ldblVReversoImporte = 0
						ldblVkWhNormalBan = 0
						ldblVkWhFatPoBan = 0
						ldblVKwhFatfpBan = 0
						If Strings.Left(lstrGrupo, 1) = "A" Then
							ldblVkWhFatPo = 0
							ldblVKwhFatfp = 0
							ldblVkWhFatPo = BuscaVlrItem(lstrItens, "0302020010") + BuscaVlrItem(lstrItens, "0302020060") 'Consumo faturado p
							ldblVKwhFatfp = BuscaVlrItem(lstrItens, "0302020011") + BuscaVlrItem(lstrItens, "0302020061") 'Consumo faturado fp
							ldblVkWhFatPoBan = BuscaVlrItem(lstrItens, "0302120010") 'bandeira
							ldblVKwhFatfpBan = BuscaVlrItem(lstrItens, "0302120011") 'bandeira
							'consumo
							ldblVlrAux = BuscaVlrItem(lstrItens, "0302020009") 'convecional
							ldblVkWhNormalBan = BuscaVlrItem(lstrItens, "0302120009")
							ldblVlrAux = ldblVlrAux + ldblVkWhFatPo 'na Ponta
							ldblVlrAux = ldblVlrAux + ldblVKwhFatfp 'Fora da Ponta
							'demanda
							ldblVlrAux = ldblVlrAux + BuscaVlrItem(lstrItens, "0302020015") 'convecional
							ldblVlrAux = ldblVlrAux + BuscaVlrItem(lstrItens, "0302020021") 'na Ponta
							ldblVlrAux = ldblVlrAux + BuscaVlrItem(lstrItens, "0302020023") '+ BuscaVlrItem(lstrItens, "0302020072") 'Fora da Ponta
							'demanda Ultrapassagem
							ldblVlrAux = ldblVlrAux + BuscaVlrItem(lstrItens, "0302020018") 'convencioal
							ldblVlrAux = ldblVlrAux + BuscaVlrItem(lstrItens, "0302020022") 'ponta
							ldblVlrAux = ldblVlrAux + BuscaVlrItem(lstrItens, "0302020026") 'fora ponta
							If lintMicroGeracaoConvenioSefaz = 0 Then
								ldblVReversoImporte = BuscaVlrItem(lstrItens, "0302020994")
								ldblVReversoImporte = ldblVReversoImporte + BuscaVlrItem(lstrItens, "0302020993")
								ldblVReversoImporte = ldblVReversoImporte + BuscaVlrItem(lstrItens, "0302022010")
								ldblVReversoImporte = ldblVReversoImporte + BuscaVlrItem(lstrItens, "0302022110")
								ldblVReversoImporte = ldblVReversoImporte + BuscaVlrItem(lstrItens, "0302022011")
								ldblVReversoImporte = ldblVReversoImporte + BuscaVlrItem(lstrItens, "0302022111")
							End If
						Else
							ldblVkWhTU = BuscaVlrItem(lstrItens, "030302009")
							ldblVkWhTE = BuscaVlrItem(lstrItens, "030402009")
							ldblVkWhTEBan = BuscaVlrItem(lstrItens, "030412009")
							ldblVkWhNormal = BuscaVlrItem(lstrItens, "030202009") + BuscaVlrItem(lstrItens, "030202019") + BuscaVlrItem(lstrItens, "030202029") + BuscaVlrItem(lstrItens, "030202039")
							ldblVkWhNormalBan = BuscaVlrItem(lstrItens, "030212009") + BuscaVlrItem(lstrItens, "0302120190") + BuscaVlrItem(lstrItens, "0302120290") + BuscaVlrItem(lstrItens, "0302120390")
							If lintMicroGeracaoConvenioSefaz = 0 Then
								ldblVReversoImporte = BuscaVlrItem(lstrItens, "0302020994")
								ldblVReversoImporte = ldblVReversoImporte + BuscaVlrItem(lstrItens, "0302020993")
								ldblVReversoImporte = ldblVReversoImporte + BuscaVlrItem(lstrItens, "0302022010")
								ldblVReversoImporte = ldblVReversoImporte + BuscaVlrItem(lstrItens, "0302022110")
								ldblVReversoImporte = ldblVReversoImporte + BuscaVlrItem(lstrItens, "0302022011")
								ldblVReversoImporte = ldblVReversoImporte + BuscaVlrItem(lstrItens, "0302022111")
							Else
								If aintSomenteMicroGeradoras = 1 Then
									ldblVReverso = BuscaVlrItem(lstrItens, "0302020994")
									ldblVReverso = ldblVReverso + BuscaVlrItem(lstrItens, "0302020993")
								End If
							End If
							If ldblVReverso = 0 Then
								If (ldblVkWhTU + ldblVkWhTE) > 0 Then
									ldblVReverso = ldblVkWhNormal - (ldblVkWhTU + ldblVkWhTE)
									If ldblVkWhNormal - (ldblVkWhTU + ldblVkWhTE) > 0 Then
										ldblVReverso = ldblVReverso + (ldblVkWhNormalBan - ldblVkWhTEBan)
									End If
								End If
							End If
							If aintSomenteMicroGeradoras = 0 Then If llngAnoMes >= "201601" Then ldblVReverso = 0
							ldblVlrAux = ldblVlrAux + ldblVkWhNormal  'consumo
						End If
						If Strings.Left(lstrGrupo, 2) = "AL" Then
							ldblVlrAux = ldblVlrAux + BuscaVlrItem(lstrItens, "0302060021")  'dif.Demanda p
							ldblVlrAux = ldblVlrAux + BuscaVlrItem(lstrItens, "0302060025")  'dif.Demanda fp
							ldblVlrAux = ldblVlrAux - BuscaVlrItem(lstrItens, "0302020051")  'Desconto Provisorio
							ldblVlrAux = ldblVlrAux - BuscaVlrItem(lstrItens, "0302020052")  'Desconto real
							ldblVlrAux = ldblVlrAux - BuscaVlrItem(lstrItens, "0302020053")  'diferença a devolver
							ldblVlrAux = ldblVlrAux + BuscaVlrItem(lstrItens, "0302020054")  'diferença a cobrar

							ldblVlrAux = ldblVlrAux - BuscaVlrItem(lstrItens, "0302020055")  'Desconto Provisorio
							ldblVlrAux = ldblVlrAux - BuscaVlrItem(lstrItens, "0302020056")  'Desconto real
							ldblVlrAux = ldblVlrAux - BuscaVlrItem(lstrItens, "0302020057")  'diferença a devolver
							ldblVlrAux = ldblVlrAux + BuscaVlrItem(lstrItens, "0302020058")  'diferença a cobrar
						End If
						If Strings.Left(lstrGrupo, 2) = "AV" Then
							ldblVlrAux = ldblVlrAux + BuscaVlrItem(lstrItens, "0302060023") 'diferença consumo fora ponta
						End If
						lstrSql = lstrSql & " " & Strings.Replace(ldblVlrAux, ",", ".") & ","
						lstrSql = lstrSql & " " & Strings.Replace(ldblVkWhFatPoBan + ldblVKwhFatfpBan + ldblVkWhNormalBan, ",", ".") & "," 'Bandeira
						'
						'Icms 1 e 2
						ldblVlrAux = 0
						ldblVlrAux = BuscaVlrItem(lstrItens, "0302030009") + BuscaVlrItem(lstrItens, "0302062009")
						ldblVlrAux = ldblVlrAux + BuscaVlrItem(lstrItens, "0302030010")
						lstrSql = lstrSql & " " & Strings.Replace(ldblVlrAux, ",", ".") & ","
						ldblVlrAux = 0
						'
						'Reativo
						If Strings.Left(lstrGrupo, 1) = "A" Then
							ldblVlrAux = BuscaVlrItem(lstrItens, "0302020012") 'Consumo
						End If
						ldblVlrAux = ldblVlrAux + BuscaVlrItem(lstrItens, "0302020031") 'Demanda
						ldblVlrAux = ldblVlrAux + BuscaVlrItem(lstrItens, "0302020013") 'Consumo ponta
						ldblVlrAux = ldblVlrAux + BuscaVlrItem(lstrItens, "0302020014") 'Consumo fora ponta
						ldblVlrAux = ldblVlrAux + BuscaVlrItem(lstrItens, "0302020027") 'Demanda ponta
						ldblVlrAux = ldblVlrAux + BuscaVlrItem(lstrItens, "0302020028") 'Demanda fora ponta
						ldblVlrAux = ldblVlrAux + BuscaVlrItem(lstrItens, "0302990044") 'Consumo Reservado
						If Strings.Left(lstrGrupo, 1) = "B" Then
							ldblVlrAux = ldblVlrAux + BuscaVlrItem(lstrItens, "0302020012") 'Consumo Reativo
						End If
						lstrSql = lstrSql & " " & Strings.Replace(ldblVlrAux, ",", ".") & ","
						'
						'Contribuição de Iluminação Pública
						ldblVlrAux = 0
						ldblVlrAux = BuscaVlrItem(lstrItens, "0301000003")
						lstrSql = lstrSql & " " & Strings.Replace(ldblVlrAux, ",", ".") & ","
						'
						'Eletrobras (sem uso)
						ldblVlrAux = 0
						ldblVlrAux = BuscaVlrItem(lstrItens, "0302990041")
						lstrSql = lstrSql & " " & Strings.Replace(ldblVlrAux, ",", ".") & ","
						'
						'ECE (sem uso)
						ldblVlrAux = 0
						ldblVlrAux = BuscaVlrItem(lstrItens, "0302070002") '0302070005
						lstrSql = lstrSql & " " & Strings.Replace(ldblVlrAux, ",", ".") & ","
						'
						'ICMS ECE (sem uso)
						ldblVlrAux = 0
						ldblVlrAux = BuscaVlrItem(lstrItens, "0302030006")
						lstrSql = lstrSql & " " & Strings.Replace(ldblVlrAux, ",", ".") & ","
						'
						'Multa ECE (sem uso)
						ldblVlrAux = 0
						ldblVlrAux = BuscaVlrItem(lstrItens, "0302050004")
						lstrSql = lstrSql & " " & Strings.Replace(ldblVlrAux, ",", ".") & ","
						'
						'Pis
						ldblVlrAux = 0
						ldblVlrAux = BuscaVlrItem(lstrItens, "0302020029") + BuscaVlrItem(lstrItens, "0302062029")
						lstrSql = lstrSql & " " & Strings.Replace(ldblVlrAux, ",", ".") & ","
						'
						'Cofins
						ldblVlrAux = 0
						ldblVlrAux = BuscaVlrItem(lstrItens, "0302020030") + BuscaVlrItem(lstrItens, "0302062030")
						lstrSql = lstrSql & " " & Strings.Replace(ldblVlrAux, ",", ".") & ","
						'
						'Icms Sob Pis e Cofins
						ldblVlrAux = 0
						ldblVlrAux = BuscaVlrItem(lstrItens, "0302030012")
						lstrSql = lstrSql & " " & Strings.Replace(ldblVlrAux, ",", ".") & ","
						'
						'Convenios, Diversos e Taxados
						ldblVlrDiv = 0
						ldblVlrTax = 0
						ldblVlrCov = 0
						ldblVlrDes = 0
						ldblVlrRet = 0
						ldblVlrOut = 0
						ldblIcmsSt = 0
						ldblPisSt = 0
						ldblCofinsSt = 0

						'coperativas
						ldblVConsCoperativaP = 0
						ldblVConsCoperativaFP = 0
						ldblVDemP = 0
						ldblVDemFP = 0
						ldblVPis = 0
						ldblVCofins = 0
						'
						For IndCodServ = 1 To CLng(Strings.Len(Strings.Trim(lstrItens)))
							lblnInclui = False
							Call BuscaCodItem(IndCodServ, lstrItens)
							ldlbCodSrv = CDbl(Strings.Replace(IIf(IsNumeric(VlrCodServ), VlrCodServ, 0), ".", ","))
							If (ldlbCodSrv < 0) And (Strings.Mid(CodServ, 1, 4) <> "9080") And lstrGrupo <> "AX" Then
								ldlbCodSrv = ldlbCodSrv * -1
							End If
							'
							'Taxas
							If (Strings.Mid(CodServ, 1, 4) = "9040") Or (Strings.Mid(CodServ, 1, 4) = "9050") Then
								ldblVlrTax = ldblVlrTax + ldlbCodSrv
								lblnInclui = True
							End If
							'
							'Outros (EUSD - MUST
							If CodServ = "0302020032" Then
								ldblVlrOut = ldblVlrOut + ldlbCodSrv
								lblnInclui = True
							End If
							'
							'Diversos
							If Strings.Mid(CodServ, 1, 4) = "9080" Then
								ldblVlrDiv = ldblVlrDiv + ldlbCodSrv
								lblnInclui = True
							End If
							'
							'Convenios
							If Strings.Mid(CodServ, 1, 4) = "9030" Then
								ldblVlrCov = ldblVlrCov + ldlbCodSrv
								lblnInclui = True
							End If
							'
							'Descontos
							If (Strings.Mid(CodServ, 1, 4) = "9070") And (CodServ <> "9070000088") Then
								ldblVlrDes = ldblVlrDes + ldlbCodSrv
								lblnInclui = True
							End If
							'
							'Retencoes
							If (CodServ = "9070000088") Or (Mid(CodServ, 1, 4) = "9090") Then
								ldblVlrRet = ldblVlrRet + ldlbCodSrv
								lblnInclui = True
							End If
							If (CodServ = "0302020051") Or (CodServ = "0302020052") Or (CodServ = "0302020053") Or (CodServ = "0302020054") Or (CodServ = "0302020055") Or (CodServ = "0302020056") Or (CodServ = "0302020057") Or (CodServ = "0302020058") Then
								If Strings.Right(CodServ, 1) <> 4 And Strings.Right(CodServ, 1) <> 8 Then
									If ldlbCodSrv > 0 Then
										ldlbCodSrv = ldlbCodSrv * (-1)
									End If
								End If
								lblnInclui = True
							End If
							'
							'Substituição Tributária
							If (CodServ = "0602020001" Or CodServ = "0602020002" Or CodServ = "0602020003") Then
								If CodServ = "0602020001" Then
									ldblIcmsSt = ldblIcmsSt + BuscaVlrItem(lstrItens, "0602020001") + BuscaVlrItem(lstrItens, "0604020001")
								ElseIf CodServ = "0602020002" Then
									ldblPisSt = ldblPisSt + BuscaVlrItem(lstrItens, "0602020002") + BuscaVlrItem(lstrItens, "0604020002")
								ElseIf CodServ = "0602020003" Then
									ldblCofinsSt = ldblCofinsSt + BuscaVlrItem(lstrItens, "0602020003") + BuscaVlrItem(lstrItens, "0604020003")
								End If
								lblnInclui = True
							End If
							'COOPERATIVA
							If lstrClas = 5201 Then
								If CodServ = "0302020010" Then
									ldblVConsCoperativaP = ldblVkWhFatPo + BuscaVlrItem(lstrItens, "0302020010") 'Consumo faturado p
								ElseIf CodServ = "0302020011" Then
									ldblVConsCoperativaFP = ldblVKwhFatfp + BuscaVlrItem(lstrItens, "0302020011") + BuscaVlrItem(lstrItens, "0302020008") 'Consumo Faturado Fp
								ElseIf CodServ = "0302020021" Then
									ldblVDemP = ldblVDemP + BuscaVlrItem(lstrItens, "0302020021") ' demanda na ponta
								ElseIf CodServ = "0302020023" Then
									ldblVDemFP = ldblVDemFP + BuscaVlrItem(lstrItens, "0302020023") + BuscaVlrItem(lstrItens, "0302020015") 'Demanda Fora da Ponta
								ElseIf CodServ = "0302020029" Then
									ldblVPis = ldblVPis + BuscaVlrItem(lstrItens, "0302020029") ' pis
								ElseIf CodServ = "0302020030" Then
									ldblVCofins = ldblVCofins + BuscaVlrItem(lstrItens, "0302020030") ' cofins
								End If
								lblnInclui = True
							End If
							'Inclusão dos itens
							If lblnInclui Then
								lstrSqlIte = "INSERT INTO " & astrTabela & "_itens" & " VALUES ( "
								lstrSqlIte = lstrSqlIte & lintTpRec & ","
								If aintTipoRel = 1 Then 'Resumo Diário
									lstrSqlIte = lstrSqlIte & "'" & Strings.Format(ldtePgto, "yyyy-MM-dd") & "',"
								Else
									lstrSqlIte = lstrSqlIte & "'0000-00-00',"
								End If
								lstrSqlIte = lstrSqlIte & "'" & CodServ & "'," & Strings.Replace(ldlbCodSrv, ",", ".") & ")"
								objExecAtualizaBancoDados.QUERY_NAME = lstrSqlIte
								repositorioAtualizaBancoDados.Execute(objExecAtualizaBancoDados)
								'''Call Executar(lstrSqlIte)
							End If
						Next IndCodServ
						lstrSql = lstrSql & " " & Replace(ldblVlrTax, ",", ".") & "," 'taxados
						lstrSql = lstrSql & " " & Replace((ldblVlrDiv + ldblVlrOut) - (ldblVlrDes), ",", ".") & ","  'diversos
						lstrSql = lstrSql & " " & Replace(ldblVlrCov, ",", ".") & "," 'convenios
						lstrSql = lstrSql & " " & Replace(ldblVlrRet, ",", ".") & "," 'rentecao
						lstrSql = lstrSql & " " & Replace(ldblVkWhDevPo, ",", ".") & ","
						lstrSql = lstrSql & " " & Replace(ldblVKwhDevfp, ",", ".") & ","
						lstrSql = lstrSql & " " & Replace(ldblVkWhUtrPo, ",", ".") & ","
						lstrSql = lstrSql & " " & Replace(ldblVKwhUtrfp, ",", ".") & ","
						'
						'Substituição Tributária
						lstrSql = lstrSql & " " & Strings.Replace(ldblIcmsSt, ",", ".") & "," 'Icms St
						lstrSql = lstrSql & " " & Strings.Replace(ldblPisSt, ",", ".") & "," 'Pis St
						lstrSql = lstrSql & " " & Strings.Replace(ldblCofinsSt, ",", ".") & "," 'Cofins St
						'
						lstrSql = lstrSql & " " & Strings.Replace(ldblVReverso, ",", ".") & "," 'Reverso
						lstrSql = lstrSql & " " & Strings.Replace(ldblVReversoImporte, ",", ".") & ","  'ReversoImporte
						'
						lstrSql = lstrSql & " " & Replace(ldblVlrTot, ",", ".") & ")"
						'
						llngSql = llngSql + 1
					End If
					'Call .MoveNext
					Call BarraProgresso(aProgressBar, alblPerc, alblInfo, 1)
				Next
				If Strings.Trim(lstrSql) <> "" Then
					objExecAtualizaBancoDados.QUERY_NAME = lstrSql
					repositorioAtualizaBancoDados.Execute(objExecAtualizaBancoDados)
				End If

			Else
				Call MsgBox("Não existem faturas no mês/ano selecionado!", vbInformation, gstrTituloMensagem)
				Call LigDes(True)
				Call Me.dtpBase.Focus()
			End If

		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: RelatorioPaisagemMontaTabela" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub lPrint(ByVal vNomeRPT As String)

		Dim dt As DataTable
		Dim dt_1 As DataTable
		Dim dt_2 As DataTable
		Dim dt_3 As DataTable
		Dim dt_4 As DataTable
		Dim dt_5 As DataTable
		Dim dc As DataColumn
		Dim ds As DataSet
		Dim lstrsql As String

		Dim bytBLOBData() As Byte

		Dim objEmpresa As New entidadeEmpresa
		Dim repositorioEmpresa As New repositorioEmpresa

		Dim vlist

		Try
			Dim rpt As New ReportDocument()

			'rptConsumidorAVencer
			If vNomeRPT = "rptRelPDDSintetico" Then

				dt_2 = New DataTable()
				dt_2.Columns.Add("CLASSE", GetType(String))
				dt_2.Columns.Add("NCONS", GetType(String))
				dt_2.Columns.Add("KWHFAT", GetType(String))
				dt_2.Columns.Add("FORNLIQUIDO", GetType(String))
				dt_2.Columns.Add("BANDEIRA", GetType(String))
				dt_2.Columns.Add("ICMS", GetType(String))
				dt_2.Columns.Add("PIS", GetType(String))
				dt_2.Columns.Add("COFINS", GetType(String))
				dt_2.Columns.Add("REATIVO", GetType(String))
				dt_2.Columns.Add("DIFDEMANDA", GetType(String))
				dt_2.Columns.Add("SUBSIDIO", GetType(String))
				dt_2.Columns.Add("SUBTRIB", GetType(String))
				dt_2.Columns.Add("TOTAL1102", GetType(String))
				dt_2.Columns.Add("ILUMPUB", GetType(String))
				dt_2.Columns.Add("JELETR", GetType(String))
				dt_2.Columns.Add("TAXADOS", GetType(String))
				dt_2.Columns.Add("DIVERSOS", GetType(String))
				dt_2.Columns.Add("CONVENIOS", GetType(String))
				dt_2.Columns.Add("TOTAL", GetType(String))
				dt_2.Columns.Add("TOTALLIQUIDO", GetType(String))
				dt_2.Columns.Add("REVERSO", GetType(String))
				dt_2.Columns.Add("IMAGEM", GetType(Byte()))


				dt_3 = New DataTable()
				dt_3.Columns.Add("TIPO", GetType(String))
				dt_3.Columns.Add("DATAAUX", GetType(String))
				dt_3.Columns.Add("DIASAUX", GetType(String))
				dt_3.Columns.Add("BANCO", GetType(String))
				dt_3.Columns.Add("ZONA", GetType(String))
				dt_3.Columns.Add("NMCIDADE", GetType(String))
				dt_3.Columns.Add("CODIGO", GetType(String))
				dt_3.Columns.Add("VALOR", GetType(String))
				dt_3.Columns.Add("DESCRICAO", GetType(String))
				dt_3.Columns.Add("DETALHAMENTO", GetType(String))

				ds = New DataSet

				lstrsql = ""
				lstrsql = "SELECT * FROM AUX_PDD_SINTETICO " 'WHERE nm_usuario = '" & My.Computer.Name & "'"
				objAtualizaBancoDados.QUERY_NAME = lstrsql
				dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

				If dt.Rows.Count > 0 Then
					For Each dr_1 As DataRow In dt.Rows

						dt_2.Rows.Add(dr_1("CLASSE"),
										  dr_1("NCONS"),
										  dr_1("KWHFAT"),
										  dr_1("FORNLIQUIDO"),
										  dr_1("BANDEIRA"),
										  dr_1("ICMS"),
										  dr_1("PIS"),
										  dr_1("COFINS"),
										  dr_1("REATIVO"),
										  dr_1("DIFDEMANDA"),
										  dr_1("SUBSIDIO"),
										  dr_1("SUBTRIB"),
										  dr_1("TOTAL1102"),
										  dr_1("ILUMPUB"),
										  dr_1("JELETR"),
										  dr_1("TAXADOS"),
										  dr_1("DIVERSOS"),
										  dr_1("CONVENIOS"),
										  dr_1("TOTAL"),
										  dr_1("TOTALLIQUIDO"),
										  dr_1("REVERSO"),
										  bytBLOBData)
					Next dr_1
				End If


				lstrsql = ""
				lstrsql = "SELECT * FROM AUX_PDD_SINTETICO_ITENS " 'WHERE nm_usuario = '" & My.Computer.Name & "'"
				objAtualizaBancoDados.QUERY_NAME = lstrsql
				dt1 = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

				If dt1.Rows.Count > 0 Then
					For Each dr_1 As DataRow In dt1.Rows

						dt_3.Rows.Add(dr_1("TIPO"),
										  dr_1("DATAAUX"),
										  dr_1("DIASAUX"),
										  dr_1("BANCO"),
										  dr_1("ZONA"),
										  dr_1("NMCIDADE"),
										  dr_1("CODIGO"),
										  dr_1("VALOR"),
										  dr_1("DESCRICAO"),
										  dr_1("DETALHAMENTO"))
					Next dr_1
				End If


				ds.Tables.Add(dt)
				ds.Tables(0).TableName = "REL_PDD_SINTETICO"

				ds.Tables.Add(dt1)
				ds.Tables(1).TableName = "REL_PDD_SINTETICO_ITENS"


				If ds.Tables(0).Rows.Count = 0 Then
					MessageBox.Show("Não há registros para o relatório escolhido! ", "Informação", MessageBoxButtons.OK, MessageBoxIcon.Information)
					Exit Sub
				Else

					rpt = New rptRelPDDSintetico


					rpt.SetDataSource(ds)
					rpt.SetParameterValue("nomeempresa", sNomeEmpresa)
					rpt.SetParameterValue("enderecoempresa", sEnderecoEmpresa)
					rpt.SetParameterValue("cepempresa", sCepEmpresa)
					rpt.SetParameterValue("ufempresa", sUFempresa)
					rpt.SetParameterValue("cidadeempresa", sCidadeEmpresa)
					rpt.SetParameterValue("bairroempresa", sBairroEmpresa)
					rpt.SetParameterValue("foneempresa", sFoneEmpresa)
					rpt.SetParameterValue("websiteempresa", sWebEmpresa)
					'rpt.SetParameterValue("database", "Data Base: " & dtpBase.Value)


					frmViewRelatorios.rpt = rpt

					frmViewRelatorios.CRViewer.Zoom((100))
					frmViewRelatorios.Text = "Relatório"
					frmViewRelatorios.ShowDialog()

				End If


			End If
			Me.Cursor = System.Windows.Forms.Cursors.Default

		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: lPrint" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try

	End Sub

	Private Sub frmRelNovoPDD_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
		Try
			Dim lstrsql As String

			objExecAtualizaBancoDados.QUERY_NAME = "drop table if exists " & istrTabela
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)


			objExecAtualizaBancoDados.QUERY_NAME = "drop table if exists AUX_PDD_SINTETICO"
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)


			objExecAtualizaBancoDados.QUERY_NAME = "drop table if exists " & istrTabela & "_itens"
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)


			objExecAtualizaBancoDados.QUERY_NAME = "drop table if exists AUX_PDD_SINTETICO_ITENS"
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: sCriaTabelaAuxiliar" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub sCriaTabelaAuxiliar()

		Try
			Dim lstrsql As String

			objExecAtualizaBancoDados.QUERY_NAME = "drop table if exists " & istrTabela
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

			lstrsql = ""
			lstrsql = "create table " & istrTabela & "("
			lstrsql = lstrsql & "tipo VARCHAR(10),"
			lstrsql = lstrsql & "datapag VARCHAR(10),"
			'lstrsql = lstrsql & "dataaux VARCHAR(10),"
			'lstrsql = lstrsql & "diasaux  VARCHAR(10),"
			lstrsql = lstrsql & "classe VARCHAR(20),"
			lstrsql = lstrsql & "ta VARCHAR(20),"
			lstrsql = lstrsql & "banco VARCHAR(10),"
			lstrsql = lstrsql & "nmbanco VARCHAR(50),"
			'lstrsql = lstrsql & "zona VARCHAR(10),"
			'lstrsql = lstrsql & "nmcidade VARCHAR(50),"
			lstrsql = lstrsql & "kwh_fat VARCHAR(20),"
			lstrsql = lstrsql & "consumo VARCHAR(20),"
			lstrsql = lstrsql & "bandeira VARCHAR(20),"
			lstrsql = lstrsql & "icms VARCHAR(20),"
			lstrsql = lstrsql & "reativo VARCHAR(20),"
			lstrsql = lstrsql & "tip VARCHAR(20),"
			lstrsql = lstrsql & "dif_eltrbr VARCHAR(20),"
			lstrsql = lstrsql & "ece VARCHAR(20),"
			lstrsql = lstrsql & "icms_ece VARCHAR(20),"
			lstrsql = lstrsql & "multa_ece VARCHAR(20),"
			lstrsql = lstrsql & "pis VARCHAR(20),"
			lstrsql = lstrsql & "cofins VARCHAR(20),"
			lstrsql = lstrsql & "icmspiscof VARCHAR(20),"
			lstrsql = lstrsql & "taxados VARCHAR(20),"
			lstrsql = lstrsql & "diversos VARCHAR(20),"
			lstrsql = lstrsql & "convenios VARCHAR(20),"
			lstrsql = lstrsql & "retencao VARCHAR(20),"
			lstrsql = lstrsql & "vkwh_dev_p VARCHAR(20),"
			lstrsql = lstrsql & "vkwh_dev_fp VARCHAR(20),"
			lstrsql = lstrsql & "vkwh_utr_p VARCHAR(20),"
			lstrsql = lstrsql & "vkwh_utr_fp VARCHAR(20),"
			lstrsql = lstrsql & "icms_st VARCHAR(20),"
			lstrsql = lstrsql & "pis_st VARCHAR(20),"
			lstrsql = lstrsql & "cofins_st VARCHAR(20),"
			lstrsql = lstrsql & "reverso VARCHAR(20),"
			lstrsql = lstrsql & "reversoimporte VARCHAR(20),"
			lstrsql = lstrsql & "total VARCHAR(20))"
			objExecAtualizaBancoDados.QUERY_NAME = lstrsql
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)


			objExecAtualizaBancoDados.QUERY_NAME = "drop table if exists AUX_PDD_SINTETICO"
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

			lstrsql = ""
			lstrsql = "create table AUX_PDD_SINTETICO ("
			lstrsql = lstrsql & "CLASSE VARCHAR(20),"
			lstrsql = lstrsql & "NCONS VARCHAR(30),"
			lstrsql = lstrsql & "KWHFAT VARCHAR(20),"
			lstrsql = lstrsql & "FORNLIQUIDO VARCHAR(20),"
			lstrsql = lstrsql & "BANDEIRA  VARCHAR(30),"
			lstrsql = lstrsql & "ICMS VARCHAR(20),"
			lstrsql = lstrsql & "PIS VARCHAR(20),"
			lstrsql = lstrsql & "COFINS VARCHAR(50),"
			lstrsql = lstrsql & "REATIVO VARCHAR(20),"
			lstrsql = lstrsql & "DIFDEMANDA VARCHAR(50),"
			lstrsql = lstrsql & "SUBSIDIO VARCHAR(20),"
			lstrsql = lstrsql & "SUBTRIB VARCHAR(20),"
			lstrsql = lstrsql & "TOTAL1102 VARCHAR(20),"
			lstrsql = lstrsql & "ILUMPUB VARCHAR(20),"
			lstrsql = lstrsql & "JELETR VARCHAR(20),"
			lstrsql = lstrsql & "TAXADOS VARCHAR(20),"
			lstrsql = lstrsql & "DIVERSOS VARCHAR(20),"
			lstrsql = lstrsql & "CONVENIOS VARCHAR(20),"
			lstrsql = lstrsql & "TOTAL VARCHAR(20),"
			lstrsql = lstrsql & "TOTALLIQUIDO VARCHAR(20),"
			lstrsql = lstrsql & "REVERSO VARCHAR(20))"
			objExecAtualizaBancoDados.QUERY_NAME = lstrsql
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)


			objExecAtualizaBancoDados.QUERY_NAME = "drop table if exists " & istrTabela & "_itens"
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

			lstrsql = ""
			lstrsql = "create table " & istrTabela & "_itens ("
			lstrsql = lstrsql & "tipo VARCHAR(10),"
			lstrsql = lstrsql & "dataaux VARCHAR(10),"
			'lstrsql = lstrsql & "diasaux VARCHAR(10),"
			'lstrsql = lstrsql & "banco  VARCHAR(50),"
			'lstrsql = lstrsql & "zona VARCHAR(10),"
			lstrsql = lstrsql & "codigo VARCHAR(20),"
			lstrsql = lstrsql & "valor  VARCHAR(20))"
			objExecAtualizaBancoDados.QUERY_NAME = lstrsql
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)


			objExecAtualizaBancoDados.QUERY_NAME = "drop table if exists AUX_PDD_SINTETICO_ITENS"
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

			lstrsql = ""
			lstrsql = "create table AUX_PDD_SINTETICO_ITENS ("
			lstrsql = lstrsql & "tipo VARCHAR(50),"
			lstrsql = lstrsql & "detalhamento VARCHAR(50),"
			lstrsql = lstrsql & "dataaux VARCHAR(10),"
			lstrsql = lstrsql & "diasaux VARCHAR(10),"
			lstrsql = lstrsql & "banco  VARCHAR(50),"
			lstrsql = lstrsql & "zona VARCHAR(10),"
			lstrsql = lstrsql & "nmcidade VARCHAR(50),"
			lstrsql = lstrsql & "codigo VARCHAR(20),"
			lstrsql = lstrsql & "valor  VARCHAR(20),"
			lstrsql = lstrsql & "descricao  VARCHAR(50))"
			objExecAtualizaBancoDados.QUERY_NAME = lstrsql
			repositorioExecAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: sCriaTabelaAuxiliar" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try

	End Sub

	Public Sub ImprimeDetalhamentosPaisagem2(ByVal astrTabelaItens As String, ByVal aintTpRel As Integer, Optional ByVal aintTipo As Integer = 3, Optional ByVal aintRelatorio As Integer = 0, Optional ByVal adteFxIni As String = "", Optional ByVal adteFxFim As String = "", Optional ByVal alngBanco As Long = 0, Optional ByVal astrZona As String = "", Optional ByVal alngDiasIni As Long = 0, Optional ByVal alngDiasFim As Long = 999999999, Optional ByVal sTipo As String = "", Optional ByVal sDescricao As String = "")
		'aintTipoRel
		'0 = Total Geral
		'1 = Resumo diário
		'2 = Zona e nome da cidade
		'3 = Banco e nome do banco
		'5 = Recebimentos por dia/banc/classe
		'aintRelatorio
		'0 = Arrecadacao
		'1 = Em Abertos
		'2 = Vencidos e Vencer
		'aintTipo
		'1 = Normal
		'2 = Voltou da Reserva
		'3 = Todos
		Dim lstrMrgOri As String
		Dim llngPosicaoY As Long
		Dim lstrTab As String
		Dim lstrTamCol As String
		Dim lstrCabDet As String

		Dim lintAux As Long
		Dim lstrTabela(12)
		Dim lstrTabDes(12)
		Dim lstrMargem(12)

		Dim lstrCod As String
		Dim lstrDes As String
		Dim ldblVlr As Double
		Dim ldblTotal As Double

		Dim lstrSql As String

		Try

			lstrTamCol = "<13mm|<40mm|>15mm;"
			lstrCabDet = "Código|Descrição|Valor"

			'Parametrização
			'Coluna 1
			lstrTabela(1) = " WHERE ((MID(codigo, 1, 4)='9080' AND codigo NOT IN('9080000092','9080000098')) OR codigo IN('9070000061','9070000066','9070000067')) "
			lstrTabela(2) = " WHERE codigo = '9070000082' "
			lstrTabela(3) = " WHERE codigo = '9070000079' "
			lstrTabela(4) = " WHERE LEFT(codigo,9) = '907000003' "
			lstrTabela(5) = " WHERE MID(codigo,1,4)='9070' AND LEFT(codigo,9) <> '907000003' AND codigo NOT IN('9070000004','9070000051','9070000082','9070000087','9070000088','9070000090','9070000091','9070000092','9070000093','9070000079','9070000061','9070000066','9070000067') "
			'Coluna 2
			lstrTabela(6) = " WHERE (MID(codigo,1,4) IN('9040','9050') OR codigo IN('9070000051'))"
			'Coluna 3
			lstrTabela(7) = " WHERE MID(codigo,1,4)='9030' "
			lstrTabela(8) = " WHERE (codigo='9070000088' OR MID(codigo,1,4)='9090') "
			'Coluna 4
			lstrTabela(9) = " WHERE codigo IN('0302020032','9080000098','9070000087','9070000091', '9080000092','9070000004','9070000090','9070000092','9070000093') "
			lstrTabela(10) = " WHERE codigo IN('0302020051','0302020052','0302020053','0302020054') "
			lstrTabela(11) = " WHERE codigo IN('0602020001','0602020002','0602020003') "
			lstrTabela(12) = " WHERE codigo IN('0302020008','0302020015','0302020011','0302020010','0302020023','0302020072','0302020031','0302020029','0302020030','0302020021') "

			'Coluna 1
			lstrTabDes(1) = "Diversos"
			lstrTabDes(2) = "Dev.Dup.Pgto"
			lstrTabDes(3) = "Bonus Itaipu"
			lstrTabDes(4) = "Ressarc.IDQUAL"
			lstrTabDes(5) = "Outras Devoluções"
			'Coluna 2
			lstrTabDes(6) = "Taxados"
			'Coluna 3
			lstrTabDes(7) = "Convênios"
			lstrTabDes(8) = "Retenções"
			'Coluna 4
			lstrTabDes(9) = "Outros"
			lstrTabDes(10) = "Livres"
			lstrTabDes(11) = "Livres - Substituição Tributária"
			lstrTabDes(12) = "COOPERATIVAS"

			'Margens
			'Coluna 1
			lstrMargem(1) = lstrMrgOri
			lstrMargem(2) = lstrMrgOri
			lstrMargem(3) = lstrMrgOri
			lstrMargem(4) = lstrMrgOri
			lstrMargem(5) = lstrMrgOri
			'Coluna 2
			lstrMargem(6) = "76mm"
			'Coluna 3
			lstrMargem(7) = "145mm"
			lstrMargem(8) = "145mm"
			'Coluna 4
			lstrMargem(9) = "214mm"
			lstrMargem(10) = "214mm"
			lstrMargem(11) = "214mm"
			lstrMargem(12) = "214mm"
			'
			Dim lstrSqlPrincipal As String
			Dim lstrsqlfiltro As String
			lstrSqlPrincipal = "SELECT `codigo`, SUM(`valor`) AS `valor` FROM " & astrTabelaItens
			For lintAux = 1 To UBound(lstrTabela)

				'Muda a margem conforme tabela
				'afrmRelatorio.VS.MarginLeft = lstrMargem(lintAux)
				'If lintAux = 1 Or lintAux = 6 Or lintAux = 7 Or lintAux = 9 Then
				'    'Posição Y de impressão
				'    afrmRelatorio.VS.CurrentY = llngPosicaoY
				'End If

				ldblTotal = 0
				lstrsqlfiltro = lstrTabela(lintAux) & " group by codigo asc"
				'If aintTpRel = 0 Then 'Tota geral
				'	If aintRelatorio = 0 Then
				'		lstrSql = lstrTabela(lintAux) & IIf(aintTipo < 3, " AND `tipo` = " & aintTipo & " ", "") & " GROUP BY `codigo` ASC "
				'	ElseIf aintRelatorio = 1 Then
				'		lstrSql = lstrTabela(lintAux) & IIf(aintTipo < 3, " AND `tipo` = " & aintTipo & " ", "") & " GROUP BY `codigo` ASC "
				'	ElseIf aintRelatorio = 2 Then
				'		lstrSql = lstrTabela(lintAux) & " AND (`diasaux` BETWEEN " & alngDiasIni & " AND " & alngDiasFim & ") GROUP BY `codigo` ASC "
				'	End If
				'ElseIf aintTpRel = 1 Then 'Diário
				'	If aintRelatorio = 0 Then
				'		lstrSql = lstrTabela(lintAux) & " AND `dataaux` = '" & Format(adteFxIni, "yyyy-MM-dd") & "'" & IIf(aintTipo < 3, " AND `tipo` = " & aintTipo & " ", "") & " GROUP BY `dataaux` ASC, `codigo` ASC "
				'	ElseIf aintRelatorio = 1 Then
				'		lstrSql = lstrTabela(lintAux) & " AND `dataaux` = '" & Format(adteFxIni, "yyyy-MM-dd") & "' GROUP BY `dataaux` ASC, `codigo` ASC "
				'	ElseIf aintRelatorio = 2 Then
				'		lstrSql = lstrTabela(lintAux) & " AND (`diasaux` BETWEEN " & alngDiasIni & " AND " & alngDiasFim & ") GROUP BY `codigo` ASC "
				'	End If
				'ElseIf aintTpRel = 2 Then 'Municipio
				'	If aintRelatorio = 2 Then
				'		lstrSql = lstrTabela(lintAux) & " AND `zona` = '" & astrZona & "' AND (`diasaux` BETWEEN " & alngDiasIni & " AND " & alngDiasFim & ") GROUP BY `zona` ASC, `codigo` ASC "
				'	Else
				'		lstrSql = lstrTabela(lintAux) & " AND `zona` = '" & astrZona & "'" & IIf(aintTipo < 3, " AND `tipo` = " & aintTipo & " ", "") & " GROUP BY `zona` ASC, `codigo` ASC "
				'	End If
				'ElseIf aintTpRel = 3 Then 'Banco
				'	lstrSql = lstrTabela(lintAux) & " AND `banco` = " & alngBanco & " " & IIf(aintTipo < 3, " AND `tipo` = " & aintTipo & " ", "") & " GROUP BY `banco` ASC, `codigo` ASC "
				'End If
				objAtualizaBancoDados.QUERY_NAME = lstrSqlPrincipal & lstrsqlfiltro
				dt = repositorioAtualizaBancoDados.Consultar(objAtualizaBancoDados)

				If dt.Rows.Count > 0 Then
					For Each row As DataRow In dt.Rows

						lstrCod = IIf(IsDBNull(row.Item("codigo")), "", row.Item("codigo"))
						lstrDes = Strings.Replace(Strings.Replace(codTodescri(lstrCod), "DESCONTO", "DESC."), "CONFORME", "CONF.")
						If Strings.Left(lstrCod, 4) = 9040 Then
							lstrDes = lstrDes & IIf(Strings.Right(lstrCod, 1) = 1, " (B - Monofásico)", IIf(Strings.Right(lstrCod, 1) = 2, " (B - Bifásico)", IIf(Strings.Right(lstrCod, 1) = 3, " (B - Trifásico)", IIf(Strings.Right(lstrCod, 1) = 4, " (A)", ""))))
						End If
						ldblVlr = CDbl(IIf(IsDBNull(row.Item("valor")), 0, row.Item("valor")))
						If ldblVlr < 0 And (vb.Left(lstrCod, 4) = "9070" Or vb.Left(lstrCod, 4) = "9090") Then ldblVlr = ldblVlr * -1

						If Mid(lstrCod, 1, 4) = "9070" Or Mid(lstrCod, 1, 4) = "9090" Then ldblVlr = ldblVlr * -1

						lstrSql = "INSERT INTO AUX_PDD_SINTETICO_ITENS SET "
						lstrSql = lstrSql & "DETALHAMENTO = '" & lstrTabDes(lintAux) & "' ,"
						lstrSql = lstrSql & "TIPO = '" & sTipo & "' ,"
						lstrSql = lstrSql & "DATAAUX = 'NULO',"
						lstrSql = lstrSql & "DIASAUX = 'NULO',"
						lstrSql = lstrSql & "BANCO = 'NULO' ,"
						lstrSql = lstrSql & "ZONA = '" & astrZona & "',"
						lstrSql = lstrSql & "NMCIDADE = '" & sDescricao & "',"
						lstrSql = lstrSql & "CODIGO = '" & lstrCod & "',"
						lstrSql = lstrSql & "VALOR = '" & Strings.Format(ldblVlr, "#,##0.00") & "',"
						lstrSql = lstrSql & "DESCRICAO = '" & lstrDes & "'"
						objExecAtualizaBancoDados.QUERY_NAME = lstrSql
						repositorioAtualizaBancoDados.Execute(objExecAtualizaBancoDados)

					Next

				End If


			Next lintAux

		Catch ex As Exception
			MessageBox.Show("ocorreu o erro: " & Err.Description & " - rotina: ImprimeDetalhamentosPaisagem2" & "", "aviso de erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try

	End Sub
End Class