Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Imports fatd_faturamento.BLL.Repositorio
Imports fatd_faturamento.ENTIDADE
Imports CrystalDecisions.CrystalReports.Engine
Friend Class FrmPDD
	Inherits System.Windows.Forms.Form
	'Private ifrAuxiliar As FrmRelatorio
	Private istrClasseCabec As String
	Private objAtualizaBancosDados As New entidadeAtualizaBancoDados
	Private repositorioAtualizaBancosDados As New repositorioAtualizaBancoDados

	Private objExecAtualizaBancosDados As New entidadeAtualizaBancoDados
	Private repositorioExecAtualizaBancosDados As New repositorioAtualizaBancoDados
	Private dt, dt1, dt2, dt3, dt4, dt5 As DataTable
	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


	'UPGRADE_WARNING: Event chkComercial.CheckStateChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	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

	'UPGRADE_WARNING: Event chkConsumoProprio.CheckStateChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	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

	'UPGRADE_WARNING: Event chkIluminacaoPublica.CheckStateChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	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

	'UPGRADE_WARNING: Event chkIndustrial.CheckStateChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	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

	'UPGRADE_WARNING: Event chkPoderPublico.CheckStateChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	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

	'UPGRADE_WARNING: Event chkResidencial.CheckStateChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	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

	'UPGRADE_WARNING: Event chkResidencialBxRenda.CheckStateChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	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

	'UPGRADE_WARNING: Event chkRural.CheckStateChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	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

	'UPGRADE_WARNING: Event chkServicoPublico.CheckStateChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	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

	'UPGRADE_WARNING: Event cmbOpcao.TextChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	'UPGRADE_WARNING: ComboBox event cmbOpcao.Change was upgraded to cmbOpcao.TextChanged which has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="DFCDE711-9694-47D7-9C50-45A99CD8E91E"'
	Private Sub cmbOpcao_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmbOpcao.TextChanged
		Try
			With Me.txtResTol
				.Enabled = (Me.cmbOpcao.SelectedIndex = 0)
				.Text = IIf(.Enabled, "000", "000")
				.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 And .Visible Then Call .Focus()
			End With
			Call MontaGrade()
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmbOpcao_TextChanged" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	'UPGRADE_WARNING: Event cmbOpcao.SelectedIndexChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub cmbOpcao_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmbOpcao.SelectedIndexChanged
		Call DesLigBotoes(True)
		Call cmbOpcao_TextChanged(cmbOpcao, New System.EventArgs())
	End Sub
	
	Private Sub cmdAnalisar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdAnalisar.Click
		Dim ldblTolerancia As Double
		Dim lstrOrdImp As String
		Dim lstrCodClas As String
		Dim lstrNomClas As String
		Dim ldblDias As Double
		Dim ldblNumNF As Double
		Dim lstrMesAno As String
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim lstrNome As String
		Dim ldteVenc As Date
		Dim ldblValorTot As Double
		Dim llngUnidId As Integer
		Dim llngConsId As Integer
		Dim lstrFlgSt As String
		Dim lstrTa As String
		Dim lstrGrupo As String
		Dim lstrSituacao As String
		Dim lblnReserva As Boolean
		Dim lblnContinua As Boolean
		Dim lstrSql As String
		Dim lngConta As Integer
		'Dim lrstAuxNf As ADODB.Recordset
		'Dim lrstAuxRe As ADODB.Recordset

		Try '

			Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
			Call DesLigBotoes(False)
			'
			'lrstAuxNf = New ADODB.Recordset
			'lrstAuxRe = New ADODB.Recordset
			'
			lblnReserva = False
			lblnContinua = True
			'
			Me.lblInfo.Text = " Lendo Faturas, aguarde..."
			Call Me.lblInfo.Refresh()
			Call MontaGrade()
			lstrSql = ""
			lstrSql = lstrSql & "SELECT" & vbCrLf
			lstrSql = lstrSql & "       `numnf`, " & vbCrLf
			lstrSql = lstrSql & "       `mesano`, " & vbCrLf
			lstrSql = lstrSql & "       `mesano_ref`, " & vbCrLf
			lstrSql = lstrSql & "       `cons_id`, " & vbCrLf
			lstrSql = lstrSql & "       `unid_id`, " & vbCrLf
			lstrSql = lstrSql & "       `zona`, " & vbCrLf
			lstrSql = lstrSql & "       `livro`, " & vbCrLf
			lstrSql = lstrSql & "       `conta`, " & vbCrLf
			lstrSql = lstrSql & "       `codclas`, " & vbCrLf
			lstrSql = lstrSql & "       `datavenc`, " & vbCrLf
			lstrSql = lstrSql & "       `datapag`, " & vbCrLf
			lstrSql = lstrSql & "       `valortot`, " & vbCrLf
			lstrSql = lstrSql & "       `grupo`, " & vbCrLf
			lstrSql = lstrSql & "       `flgst`, " & vbCrLf
			lstrSql = lstrSql & "       `ta` " & 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` > '" & VB6.Format(Me.dtpBase.value, "yyyy-MM-dd") & "') " & vbCrLf
			If Me.cmbOpcao.SelectedIndex = 0 Then
				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
			ElseIf Me.cmbOpcao.SelectedIndex = 1 Then
				lstrSql = lstrSql & " AND `nf`.`flgst` = 'R' " & vbCrLf
			End If
			objAtualizaBancosDados.QUERY_NAME = lstrSql
			dt = repositorioAtualizaBancosDados.Consultar(objAtualizaBancosDados)


			If dt.Rows.Count > 0 Then
				Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, dt.Rows.Count)
				Me.mfgDados.Redraw = False
				For Each row As DataRow In dt.Rows
					lstrCodClas = VB6.Format(Trim(IIf(IsDBNull(row.Item("codclas")), "0", row.Item("codclas"))), "0000")
					ldblNumNF = CDbl(IIf(IsDBNull(row.Item("numnf")), 0, row.Item("numnf")))
					lstrMesAno = Trim(IIf(IsDBNull(row.Item("mesano")), "00/0000", row.Item("mesano")))
					lstrZona = VB6.Format(Trim(IIf(IsDBNull(row.Item("zona")), "0", row.Item("zona"))), "000")
					lstrLivro = VB6.Format(Trim(IIf(IsDBNull(row.Item("livro")), "0", row.Item("livro"))), "00")
					lstrConta = VB6.Format(Trim(IIf(IsDBNull(row.Item("conta")), "0", row.Item("conta"))), "000000")
					ldteVenc = CDate(IIf(IsDBNull(row.Item("datavenc")), "1951-01-01", row.Item("datavenc")))
					ldblDias = DateDiff(Microsoft.VisualBasic.DateInterval.Day, ldteVenc, CDate(VB6.Format(Me.dtpBase.Value, "yyyy-MM-dd")))
					ldblValorTot = CDbl(IIf(IsDBNull(row.Item("valortot")), 0, row.Item("valortot")))
					llngUnidId = CInt(IIf(IsDBNull(row.Item("unid_id")), 0, row.Item("unid_id")))
					llngConsId = CInt(IIf(IsDBNull(row.Item("cons_id")), 0, row.Item("cons_id")))
					lstrFlgSt = Trim(IIf(IsDBNull(row.Item("flgst")), "", row.Item("flgst")))
					lstrTa = Mid(Trim(IIf(IsDBNull(row.Item("ta")), "00B1", row.Item("ta"))), 3, 2)
					lstrGrupo = Trim(IIf(IsDBNull(row.Item("grupo")), "B", row.Item("grupo")))

					lstrSql = ""
					lstrSql = lstrSql & "SELECT `numnf`,`mesano`,`zona`,`livro`,`conta`,`datares` " & vbCrLf
					lstrSql = lstrSql & "  FROM `reserva` " & vbCrLf
					lstrSql = lstrSql & " WHERE `numnf`    =  " & ldblNumNF & " " & vbCrLf
					lstrSql = lstrSql & "   AND `mesano`   = '" & lstrMesAno & "' " & vbCrLf
					lstrSql = lstrSql & "   AND `zona`     = '" & lstrZona & "' " & vbCrLf
					lstrSql = lstrSql & "   AND `livro`    = '" & lstrLivro & "' " & vbCrLf
					lstrSql = lstrSql & "   AND `conta`    = '" & lstrConta & "' " & vbCrLf
					lstrSql = lstrSql & "   AND `datares` <= '" & VB6.Format(Me.dtpBase.Value, "yyyy-MM-dd") & "' "
					'Call Conectar(lstrSql, lrstAuxRe)
					objAtualizaBancosDados.QUERY_NAME = lstrSql
					dt1 = repositorioAtualizaBancosDados.Consultar(objAtualizaBancosDados)


					lblnReserva = (dt1.Rows.Count > 0)


					Select Case VB.Left(lstrCodClas, 1)
						Case Is = "9"
							If VB.Right(lstrCodClas, 2) = "02" Or VB.Right(lstrCodClas, 2) = "04" Or VB.Right(lstrCodClas, 2) = "05" Or VB.Right(lstrCodClas, 2) = "06" Then
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								ldblTolerancia = CDbl(IIf(IsNumeric(Me.txtLimiteResidencialBxRenda.Text), Me.txtLimiteResidencialBxRenda.Text, 0))
								lstrOrdImp = "01"
								lstrNomClas = "Resid. Bx.Renda"
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								If CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0)) <> 0 Then
									'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
									ldblTolerancia = ldblTolerancia + CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0))
								End If
								lblnContinua = (Me.chkResidencialBxRenda.CheckState = 1 And ldblDias > ldblTolerancia)
							Else
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								ldblTolerancia = CDbl(IIf(IsNumeric(Me.txtLimiteResidencial.Text), Me.txtLimiteResidencial.Text, 0))
								lstrOrdImp = "02"
								lstrNomClas = "Residencial"
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								If CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0)) <> 0 Then
									'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
									ldblTolerancia = ldblTolerancia + CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0))
								End If
								lblnContinua = (Me.chkResidencial.CheckState = 1 And ldblDias > ldblTolerancia)
							End If
						Case Is = "0"
							'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							ldblTolerancia = CDbl(IIf(IsNumeric(Me.txtLimiteIndustrial.Text), Me.txtLimiteIndustrial.Text, 0))
							lstrOrdImp = "03"
							lstrNomClas = "Industrial"
							'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							If CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0)) <> 0 Then
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								ldblTolerancia = ldblTolerancia + CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0))
							End If
							lblnContinua = (Me.chkIndustrial.CheckState = 1 And ldblDias > ldblTolerancia)
						Case Is = "1"
							'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							ldblTolerancia = CDbl(IIf(IsNumeric(Me.txtLimiteIndustrial.Text), Me.txtLimiteIndustrial.Text, 0))
							lstrOrdImp = "03"
							lstrNomClas = "Industrial"
							'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							If CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0)) <> 0 Then
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								ldblTolerancia = ldblTolerancia + CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0))
							End If
							lblnContinua = (Me.chkIndustrial.CheckState = 1 And ldblDias > ldblTolerancia)
						Case Is = "2"
							'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							ldblTolerancia = CDbl(IIf(IsNumeric(Me.txtLimiteIndustrial.Text), Me.txtLimiteIndustrial.Text, 0))
							lstrOrdImp = "03"
							lstrNomClas = "Industrial"
							'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							If CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0)) <> 0 Then
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								ldblTolerancia = ldblTolerancia + CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0))
							End If
							lblnContinua = (Me.chkIndustrial.CheckState = 1 And ldblDias > ldblTolerancia)
						Case Is = "3"
							'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							ldblTolerancia = CDbl(IIf(IsNumeric(Me.txtLimiteIndustrial.Text), Me.txtLimiteIndustrial.Text, 0))
							lstrOrdImp = "03"
							lstrNomClas = "Industrial"
							'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							If CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0)) <> 0 Then
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								ldblTolerancia = ldblTolerancia + CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0))
							End If
							lblnContinua = (Me.chkIndustrial.CheckState = 1 And ldblDias > ldblTolerancia)
						Case Is = "4"
							'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							ldblTolerancia = CDbl(IIf(IsNumeric(Me.txtLimiteComercial.Text), Me.txtLimiteComercial.Text, 0))
							lstrOrdImp = "04"
							lstrNomClas = "Comercial"
							'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							If CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0)) <> 0 Then
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								ldblTolerancia = ldblTolerancia + CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0))
							End If
							lblnContinua = (Me.chkComercial.CheckState = 1 And ldblDias > ldblTolerancia)
						Case Is = "5"
							'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							ldblTolerancia = CDbl(IIf(IsNumeric(Me.txtLimiteRural.Text), Me.txtLimiteRural.Text, 0))
							lstrOrdImp = "05"
							lstrNomClas = "Rural"
							'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							If CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0)) <> 0 Then
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								ldblTolerancia = ldblTolerancia + CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0))
							End If
							lblnContinua = (Me.chkRural.CheckState = 1 And ldblDias > ldblTolerancia)
						Case Is = "6"
							If VB.Left(lstrCodClas, 2) = "61" Then
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								ldblTolerancia = CDbl(IIf(IsNumeric(Me.txtLimitePoderPublico.Text), Me.txtLimitePoderPublico.Text, 0))
								lstrOrdImp = "06"
								lstrNomClas = "P. Púb. Municipal"
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								If CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0)) <> 0 Then
									'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
									ldblTolerancia = ldblTolerancia + CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0))
								End If
								lblnContinua = (Me.chkPoderPublico.CheckState = 1 And ldblDias > ldblTolerancia)
							ElseIf VB.Left(lstrCodClas, 2) = "62" Then
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								ldblTolerancia = CDbl(IIf(IsNumeric(Me.txtLimitePoderPublico.Text), Me.txtLimitePoderPublico.Text, 0))
								lstrOrdImp = "07"
								lstrNomClas = "P. Púb. Estadual"
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								If CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0)) <> 0 Then
									'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
									ldblTolerancia = ldblTolerancia + CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0))
								End If
								lblnContinua = (Me.chkPoderPublico.CheckState = 1 And ldblDias > ldblTolerancia)
							ElseIf VB.Left(lstrCodClas, 2) = "63" Then
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								ldblTolerancia = CDbl(IIf(IsNumeric(Me.txtLimitePoderPublico.Text), Me.txtLimitePoderPublico.Text, 0))
								lstrOrdImp = "08"
								lstrNomClas = "P. Púb. Federal"
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								If CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0)) <> 0 Then
									'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
									ldblTolerancia = ldblTolerancia + CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0))
								End If
								lblnContinua = (Me.chkPoderPublico.CheckState = 1 And ldblDias > ldblTolerancia)
							ElseIf VB.Left(lstrCodClas, 2) = "64" Then
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								ldblTolerancia = CDbl(IIf(IsNumeric(Me.txtLimiteIluminacaoPublica.Text), Me.txtLimiteIluminacaoPublica.Text, 0))
								lstrOrdImp = "09"
								lstrNomClas = "Iluminação Púb."
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								If CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0)) <> 0 Then
									'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
									ldblTolerancia = ldblTolerancia + CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0))
								End If
								lblnContinua = (Me.chkIluminacaoPublica.CheckState = 1 And ldblDias > ldblTolerancia)
							End If
						Case Is = "7"
							'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							ldblTolerancia = CDbl(IIf(IsNumeric(Me.txtLimiteServicoPublico.Text), Me.txtLimiteServicoPublico.Text, 0))
							lstrOrdImp = "10"
							lstrNomClas = "Serviço Público"
							'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							If CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0)) <> 0 Then
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								ldblTolerancia = ldblTolerancia + CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0))
							End If
							lblnContinua = (Me.chkServicoPublico.CheckState = 1 And ldblDias > ldblTolerancia)
						Case Is = "8"
							'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							ldblTolerancia = CDbl(IIf(IsNumeric(Me.txtLimiteConsumoProprio.Text), Me.txtLimiteConsumoProprio.Text, 0))
							lstrOrdImp = "12"
							lstrNomClas = "Consumo Próprio"
							'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							If CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0)) <> 0 Then
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								ldblTolerancia = ldblTolerancia + CDbl(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0))
							End If
							lblnContinua = (Me.chkConsumoProprio.CheckState = 1 And ldblDias > ldblTolerancia)
						Case Else
							ldblTolerancia = 0
							lstrOrdImp = "13"
							lstrNomClas = "Indefinido"
							lblnContinua = False
					End Select
					If lstrTa = "AL" Then
						lstrOrdImp = "11"
						lstrNomClas = "Consumidor Livre"
					End If
					If Not lblnReserva Then
						If lblnContinua Then
							lstrNome = RetornaNomeConsumidor(lstrZona, lstrLivro, lstrConta, llngUnidId, llngConsId, lstrGrupo, lstrSituacao)
							If lstrSituacao = "L" Then
								lblnContinua = (Me.chkLigados.CheckState = System.Windows.Forms.CheckState.Checked)
							ElseIf lstrSituacao = "D" Then
								lblnContinua = (Me.chkDesligados.CheckState = System.Windows.Forms.CheckState.Checked)
							ElseIf lstrSituacao = "C" Then
								lblnContinua = (Me.chkCortados.CheckState = System.Windows.Forms.CheckState.Checked)
							ElseIf lstrSituacao = "I" Then
								lblnContinua = (Me.chkDesativados.CheckState = System.Windows.Forms.CheckState.Checked)
							Else
								lblnContinua = True
							End If
							If lblnContinua Then
								With Me.mfgDados
									.Rows = .Rows + 1
									'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
									.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillRepeat
									If lstrFlgSt = "R" Then
										.Row = .Rows - 1
										.Col = 0
										.ColSel = .Cols - 1
										.CellForeColor = System.Drawing.ColorTranslator.FromOle(&HFF) 'Vermelho
									ElseIf lstrFlgSt = "J" Then
										.Row = .Rows - 1
										.Col = 0
										.ColSel = .Cols - 1
										.CellForeColor = System.Drawing.ColorTranslator.FromOle(&H808080) 'Cinza
									ElseIf ((lstrNome = "NOME NÃO ENCONTRADO") Or (lstrNome = "EM BRANCO")) Then
										.Row = .Rows - 1
										.Col = 0
										.ColSel = .Cols - 1
										.CellForeColor = System.Drawing.ColorTranslator.FromOle(&HFF0000) 'Azul
									Else
										.Row = .Rows - 1
										.Col = 0
										.ColSel = .Cols - 1
										.CellForeColor = System.Drawing.ColorTranslator.FromOle(&H80000008) 'Normal
									End If
									'UPGRADE_ISSUE: VBControlExtender method mfgDados.FillStyle was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
									.FillStyle = MSFlexGridLib.FillStyleSettings.flexFillSingle
									.set_TextMatrix(.Rows - 1, 0, ldblTolerancia)
									.set_TextMatrix(.Rows - 1, 1, lstrOrdImp)
									.set_TextMatrix(.Rows - 1, 2, lstrNomClas)
									.set_TextMatrix(.Rows - 1, 3, ldblNumNF)
									.set_TextMatrix(.Rows - 1, 4, lstrMesAno)
									.set_TextMatrix(.Rows - 1, 5, lstrZona)
									.set_TextMatrix(.Rows - 1, 6, lstrLivro)
									.set_TextMatrix(.Rows - 1, 7, lstrConta)
									.set_TextMatrix(.Rows - 1, 8, lstrNome)
									.set_TextMatrix(.Rows - 1, 9, VB6.Format(ldteVenc, "dd/mm/yyyy"))
									.set_TextMatrix(.Rows - 1, 10, ldblDias)
									.set_TextMatrix(.Rows - 1, 11, VB6.Format(ldblValorTot, "#,##0.00"))
									.set_TextMatrix(.Rows - 1, 12, lstrFlgSt)
									If lstrFlgSt = "J" Then
										'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
										Me.lblQtdeFaturasJudice.Text = CStr(CInt(IIf(IsNumeric(Me.lblQtdeFaturasJudice.Text), Me.lblQtdeFaturasJudice.Text, 0)) + 1)
									Else
										'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
										Me.lblQtdeFaturas.Text = CStr(CInt(IIf(IsNumeric(Me.lblQtdeFaturas.Text), Me.lblQtdeFaturas.Text, 0)) + 1)
									End If
								End With
							End If
						End If
					End If

					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
				Next
				With Me.mfgDados
					.Col = 1
					.Sort = MSFlexGridLib.SortSettings.flexSortGenericAscending
					.Redraw = True
					Me.lblQtdeFaturasTotal.Text = CStr(.Rows - 1)
				End With
			End If


			Me.Cursor = System.Windows.Forms.Cursors.Default
			Call DesLigBotoes(True)
			Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 2)

		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdAnalisar_Click" & "", "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
		Dim lstrTable As String
		Dim llngConta As Integer
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim lstrNome As String
		Dim lstrClasseRel As String
		Dim ldteVencto As Date
		Dim ldblValor As Double
		Dim ldblVlrTotal As Double
		Dim llngQtdTotal As Integer
		Dim llngDias As Integer
		Dim lstrClasse As String
		'UPGRADE_WARNING: Lower bound of array lstrClas 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 lstrClas(20) As String
		'UPGRADE_WARNING: Lower bound of array ldblTotal 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 ldblTotal(20) As Double
		'UPGRADE_WARNING: Lower bound of array lngTotal 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 lngTotal(20) As Integer
		Dim lstrMesAno As String
		Dim llngPagina As Integer
		Dim lstrsql As String
		Dim iTolerancia As Integer
		'
		Try


			lstrsql = ""
			lstrsql = "DELETE FROM AUX_RESERVA_PDD"
			objExecAtualizaBancosDados.QUERY_NAME = lstrsql
			repositorioExecAtualizaBancosDados.Execute(objExecAtualizaBancosDados)

			lstrsql = ""
			lstrsql = "DELETE FROM AUX_RESERVA_PDDTOT"
			objExecAtualizaBancosDados.QUERY_NAME = lstrsql
			repositorioExecAtualizaBancosDados.Execute(objExecAtualizaBancosDados)

			If Me.mfgDados.Rows > 1 Then
				istrClasseCabec = "Cons. da classe " & mfgDados.get_TextMatrix(1, 2) & " venc. a mais de " & mfgDados.get_TextMatrix(1, 0) & " dias"
				lstrClasse = istrClasseCabec
				Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, Me.mfgDados.Rows - 1, "Impressão dos dados contidos na Grid")
				For llngConta = 1 To Me.mfgDados.Rows - 1

					With mfgDados
						iTolerancia = .get_TextMatrix(llngConta, 0)
						lstrClasseRel = .get_TextMatrix(llngConta, 2)
						lstrMesAno = .get_TextMatrix(llngConta, 4)
						lstrZona = .get_TextMatrix(llngConta, 5)
						lstrLivro = .get_TextMatrix(llngConta, 6)
						lstrConta = .get_TextMatrix(llngConta, 7)
						lstrNome = VB.Left(.get_TextMatrix(llngConta, 8), 40)
						ldteVencto = CDate(.get_TextMatrix(llngConta, 9))
						llngDias = CInt(.get_TextMatrix(llngConta, 10))
						ldblValor = CDbl(.get_TextMatrix(llngConta, 11))
					End With

					lstrsql = "INSERT INTO AUX_RESERVA_PDD SET "
					lstrsql = lstrsql & "CLASSE = '" & lstrClasseRel & "' ,"
					lstrsql = lstrsql & "ZONA = '" & lstrZona & "',"
					lstrsql = lstrsql & "LIVRO = '" & lstrLivro & "',"
					lstrsql = lstrsql & "CONTA = '" & lstrConta & "',"
					lstrsql = lstrsql & "NOME = '" & lstrNome & "',"
					lstrsql = lstrsql & "VENCIMENTO = '" & ldteVencto & "',"
					lstrsql = lstrsql & "DIAS = '" & llngDias & "',"
					lstrsql = lstrsql & "TOLERANCIA = '" & iTolerancia & "',"
					'lstrsql = lstrsql & "VALOR = '" & ldblValor & "'"
					lstrsql = lstrsql & "VALOR = " & Replace(Replace(ldblValor, ".", ""), ",", ".") & ""
					objExecAtualizaBancosDados.QUERY_NAME = lstrsql
					repositorioExecAtualizaBancosDados.Execute(objExecAtualizaBancosDados)


					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
				Next llngConta


				lstrsql = "SELECT classe, SUM(valor) AS valor , COUNT(*) AS qtde FROM AUX_RESERVA_PDD group by classe"
				objAtualizaBancosDados.QUERY_NAME = lstrsql
				dt = repositorioAtualizaBancosDados.Consultar(objAtualizaBancosDados)

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

						lstrsql = "INSERT INTO AUX_RESERVA_PDDTOT SET "
						lstrsql = lstrsql & "CLASSE = '" & row.Item("classe") & "' ,"
						lstrsql = lstrsql & "QTDE = '" & row.Item("qtde") & "',"
						lstrsql = lstrsql & "VALOR = " & Replace(Replace(row.Item("valor"), ".", ""), ",", ".") & ""
						objExecAtualizaBancosDados.QUERY_NAME = lstrsql
						repositorioExecAtualizaBancosDados.Execute(objExecAtualizaBancosDados)

					Next
				End If

			End If

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

		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 cmdRegistrar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdRegistrar.Click
		Try
			Dim lblnContinua As Boolean
			lblnContinua = True
			Call DesLigBotoes(False)
			'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			If CInt(IIf(IsNumeric(Me.lblQtdeFaturas.Text), Me.lblQtdeFaturas.Text, 0)) > 0 Or Me.chkBaixaJudice.CheckState = System.Windows.Forms.CheckState.Checked Then
				If Me.cmbOpcao.SelectedIndex = 0 Then
					If MsgBox("Deseja realmente transportar os " & IIf(Me.chkBaixaJudice.CheckState = System.Windows.Forms.CheckState.Checked, VB6.Format(CInt(IIf(IsNumeric(Me.lblQtdeFaturasJudice.Text), Me.lblQtdeFaturasJudice.Text, 0)) + CInt(IIf(IsNumeric(Me.lblQtdeFaturas.Text), Me.lblQtdeFaturas.Text, 0)), "#,##0"), VB6.Format(Me.lblQtdeFaturas.Text, "#,##0")) & " registros de nota fiscal para reserva, com data da baixa em " & VB6.Format(Me.dtpBase.Value, "dd/mm/yyyy") & "?", MsgBoxStyle.Question + MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2, gstrTituloMensagem) = MsgBoxResult.Yes Then
						'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						If CInt(IIf(IsNumeric(Me.txtResTol.Text), Me.txtResTol.Text, 0)) = 0 Then
							lblnContinua = (MsgBox("Você não informou a quantidade de dias a mais de tolerância!" & vbCrLf & "Deseja continuar mesmo assim?", MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2, gstrTituloMensagem) = MsgBoxResult.Yes)
						End If
						If lblnContinua Then
							Me.lblInfo.Text = " Transportando Faturas para Reserva.."
							Call Me.lblInfo.Refresh()
							Call LancaPDD()
							Me.lblInfo.Text = " Pronto...!"
							Call Me.lblInfo.Refresh()
						End If
					End If
				ElseIf Me.cmbOpcao.SelectedIndex = 1 Then
					If MsgBox("Deseja realmente Retornar todos estes registros da Reserva?", MsgBoxStyle.Question + MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2, gstrTituloMensagem) = MsgBoxResult.Yes Then
						Me.lblInfo.Text = " Retornando Faturas da Reserva.."
						Call Me.lblInfo.Refresh()
						Call RetornaPDD()
						Me.lblInfo.Text = " Pronto...!"
						Call Me.lblInfo.Refresh()
					End If
				End If
			Else
				Call MsgBox("Não existe nostas fiscais para " & VB6.GetItemString(Me.cmbOpcao, Me.cmbOpcao.SelectedIndex) & "!", MsgBoxStyle.Information, gstrTituloMensagem)
			End If
			Call DesLigBotoes(True)
			If Not lblnContinua Then Call Me.txtResTol.Focus()

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

	Private Sub cmdRetirar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdRetirar.Click
		Try
			With Me.mfgDados
				If .RowSel > 0 Then
					If .get_TextMatrix(.RowSel, 12) = "J" Then
						'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						If CInt(IIf(IsNumeric(Me.lblQtdeFaturasJudice.Text), Me.lblQtdeFaturasJudice.Text, 0)) > 0 Then
							'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							Me.lblQtdeFaturasJudice.Text = CStr(CInt(IIf(IsNumeric(Me.lblQtdeFaturasJudice.Text), Me.lblQtdeFaturasJudice.Text, 0)) - 1)
						End If
					Else
						'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
						If CInt(IIf(IsNumeric(Me.lblQtdeFaturas.Text), Me.lblQtdeFaturas.Text, 0)) > 0 Then
							'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
							Me.lblQtdeFaturas.Text = CStr(CInt(IIf(IsNumeric(Me.lblQtdeFaturas.Text), Me.lblQtdeFaturas.Text, 0)) - 1)
						End If
					End If
					If .Rows > 2 Then
						Call .RemoveItem(.RowSel)
					Else
						.Rows = 1
					End If
				End If
				Me.lblQtdeFaturasTotal.Text = CStr(.Rows - 1)
			End With
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdRetirar_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub FrmPDD_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)
			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: FrmPDD_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

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

			sCriaTabelaAuxiliar()

			Me.txtResTol.Text = "000"
			With Me.cmbOpcao
				Call .Items.Add("Transportar Consumidores p/ Reserva")
				Call .Items.Add("Retornar Consumidores da Reserva")
				.SelectedIndex = 0
			End With
			'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
			Me.dtpBaixa.Value = Me.dtpBase.Value
			Call DesLigBotoes(True)
			'ifrAuxiliar = New FrmRelatorio
			Call MontaGrade()

			lstrSql = ""
			lstrSql = lstrSql & "SELECT * "
			lstrSql = lstrSql & "  FROM bancos "
			lstrSql = lstrSql & " WHERE nmbco LIKE '%RESERVA%' "
			lstrSql = lstrSql & " LIMIT 0, 1"
			objAtualizaBancosDados.QUERY_NAME = lstrSql
			dt = repositorioAtualizaBancosDados.Consultar(objAtualizaBancosDados)
			'Call Conectar(lstrSql, lrstAux)

			If dt.Rows.Count > 0 Then
				For Each row As DataRow In dt.Rows
					Me.lblCodigoBanco.Text = CStr(CInt(IIf(IsDBNull(row.Item("ban_id")), 0, row.Item("ban_id"))))
					Me.lblDescricaoBanco.Text = " " & Trim(IIf(IsDBNull(row.Item("nmbco")), "", row.Item("nmbco")))
				Next
			End If

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

	End Sub

	Private Sub FrmPDD_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		Try

			Dim lstrsql As String

			objExecAtualizaBancosDados.QUERY_NAME = "drop table if exists AUX_RESERVA_PDD"
			repositorioExecAtualizaBancosDados.Execute(objExecAtualizaBancosDados)

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


	End Sub
	
	Private Sub txtLimiteComercial_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteComercial.Enter
		With Me.txtLimiteComercial
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtLimiteComercial_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtLimiteComercial.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii = System.Windows.Forms.Keys.Return Then
			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
	End Sub
	
	Private Sub txtLimiteComercial_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteComercial.Leave
		With Me.txtLimiteComercial
			.Text = VB6.Format(.Text, "000")
		End With
	End Sub
	
	Private Sub txtLimiteConsumoProprio_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteConsumoProprio.Enter
		With Me.txtLimiteConsumoProprio
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtLimiteConsumoProprio_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtLimiteConsumoProprio.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii = System.Windows.Forms.Keys.Return Then
			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
	End Sub
	
	Private Sub txtLimiteConsumoProprio_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteConsumoProprio.Leave
		With Me.txtLimiteConsumoProprio
			.Text = VB6.Format(.Text, "000")
		End With
	End Sub
	
	Private Sub txtLimiteIluminacaoPublica_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteIluminacaoPublica.Enter
		With Me.txtLimiteIluminacaoPublica
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtLimiteIluminacaoPublica_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtLimiteIluminacaoPublica.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii = System.Windows.Forms.Keys.Return Then
			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
	End Sub
	
	Private Sub txtLimiteIluminacaoPublica_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteIluminacaoPublica.Leave
		With Me.txtLimiteIluminacaoPublica
			.Text = VB6.Format(.Text, "000")
		End With
	End Sub
	
	Private Sub txtLimiteIndustrial_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteIndustrial.Enter
		With Me.txtLimiteIndustrial
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtLimiteIndustrial_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtLimiteIndustrial.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii = System.Windows.Forms.Keys.Return Then
			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
	End Sub
	
	Private Sub txtLimiteIndustrial_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteIndustrial.Leave
		With Me.txtLimiteIndustrial
			.Text = VB6.Format(.Text, "000")
		End With
	End Sub
	
	Private Sub txtLimitePoderPublico_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimitePoderPublico.Enter
		With Me.txtLimitePoderPublico
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtLimitePoderPublico_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtLimitePoderPublico.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii = System.Windows.Forms.Keys.Return Then
			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
	End Sub
	
	Private Sub txtLimitePoderPublico_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimitePoderPublico.Leave
		With Me.txtLimitePoderPublico
			.Text = VB6.Format(.Text, "000")
		End With
	End Sub
	
	Private Sub txtLimiteResidencial_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteResidencial.Enter
		With Me.txtLimiteResidencial
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtLimiteResidencial_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtLimiteResidencial.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii = System.Windows.Forms.Keys.Return Then
			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
	End Sub
	
	Private Sub txtLimiteResidencial_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteResidencial.Leave
		With Me.txtLimiteResidencial
			.Text = VB6.Format(.Text, "000")
		End With
	End Sub
	
	Private Sub txtLimiteResidencialBxRenda_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteResidencialBxRenda.Enter
		With Me.txtLimiteResidencialBxRenda
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtLimiteResidencialBxRenda_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtLimiteResidencialBxRenda.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii = System.Windows.Forms.Keys.Return Then
			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
	End Sub
	
	Private Sub txtLimiteResidencialBxRenda_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteResidencialBxRenda.Leave
		With Me.txtLimiteResidencialBxRenda
			.Text = VB6.Format(.Text, "000")
		End With
	End Sub
	
	Private Sub txtLimiteRural_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteRural.Enter
		With Me.txtLimiteRural
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtLimiteRural_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtLimiteRural.KeyPress
		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
	End Sub
	
	Private Sub txtLimiteRural_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteRural.Leave
		With Me.txtLimiteRural
			.Text = VB6.Format(.Text, "000")
		End With
	End Sub
	
	Private Sub txtLimiteServicoPublico_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteServicoPublico.Enter
		With Me.txtLimiteServicoPublico
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtLimiteServicoPublico_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtLimiteServicoPublico.KeyPress
		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
	End Sub
	
	Private Sub txtLimiteServicoPublico_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtLimiteServicoPublico.Leave
		With Me.txtLimiteServicoPublico
			.Text = VB6.Format(.Text, "000")
		End With
	End Sub
	
	Private Sub txtResTol_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtResTol.Enter
		With Me.txtResTol
			.SelectionStart = 0
			.SelectionLength = CInt(Len(.Text))
		End With
	End Sub
	
	Private Sub txtResTol_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtResTol.KeyPress
		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
	End Sub
	
	Private Sub txtResTol_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtResTol.Leave
		With Me.txtResTol
			If CInt(Len(Trim(.Text))) = 0 Then
				.Text = "0"
			End If
			.Text = VB6.Format(.Text, "000")
		End With
	End Sub

	'Public Function CabecaRel() As Object
	'	Dim lstrSituacao As String
	'	lstrSituacao = ""
	'	If Me.chkLigados.CheckState = System.Windows.Forms.CheckState.Checked Then
	'		lstrSituacao = lstrSituacao & "Ligados"
	'	ElseIf Me.chkDesligados.CheckState = System.Windows.Forms.CheckState.Checked Then 
	'		lstrSituacao = lstrSituacao & IIf(Trim(lstrSituacao) <> "", ",", "") & "Desligados"
	'	ElseIf Me.chkDesativados.CheckState = System.Windows.Forms.CheckState.Checked Then 
	'		lstrSituacao = lstrSituacao & IIf(Trim(lstrSituacao) <> "", ",", "") & "Desativados"
	'	ElseIf Me.chkCortados.CheckState = System.Windows.Forms.CheckState.Checked Then 
	'		lstrSituacao = lstrSituacao & IIf(Trim(lstrSituacao) <> "", ",", "") & "Cortados"
	'	End If
	'	If Trim(lstrSituacao) <> "" Then
	'		lstrSituacao = "(" & lstrSituacao & ")"
	'	End If
	'	'With ifrAuxiliar
	'	'	Call Cabecalho_Relatorio(.VS, "Relatório de Provisão de Devedores Duvidosos - PDD", "em " & Me.dtpBase.value & " - " & lstrSituacao, "4", True, istrClasseCabec)
	'	'	Call LineFeed(.VS, 3)
	'	'	If istrClasseCabec <> "Resumo dos Totais Apurados" Then
	'	'		.VS.Table = "<25mm|<90mm|^20mm|>15mm|>15mm|>30mm;Identificação|Nome|Vencimento|Mês Ref|Dias|Valor"
	'	'		'UPGRADE_ISSUE: VBControlExtender method ifrAuxiliar.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
	'	'		Call .VS.DrawLine("8mm", .VS.CurrentY + 100, "202mm", .VS.CurrentY + 100)
	'	'		Call LineFeed(.VS, 1)
	'	'	End If
	'	'End With
	'End Function

	Private Sub MontaGrade()
		Try
			Me.lblQtdeFaturas.Text = CStr(0)
			Me.lblQtdeFaturasJudice.Text = CStr(0)
			Me.lblQtdeFaturasTotal.Text = CStr(0)
			With Me.mfgDados
				.Rows = 1
				.Clear()
				.Redraw = False
				.set_TextMatrix(0, 0, "Tolerância")
				.set_TextMatrix(0, 1, "Ordem")
				.set_TextMatrix(0, 2, "Classe")
				.set_TextMatrix(0, 3, "NF Num")
				.set_TextMatrix(0, 4, "Mes/Ano")
				.set_TextMatrix(0, 5, "Z")
				.set_TextMatrix(0, 6, "L")
				.set_TextMatrix(0, 7, "C")
				.set_TextMatrix(0, 8, "Consumidor")
				.set_TextMatrix(0, 9, "Vencimento")
				.set_TextMatrix(0, 10, "Dias")
				.set_TextMatrix(0, 11, "Valor")
				.set_TextMatrix(0, 12, "Flag Situação NF")
				.set_ColWidth(0, 0)
				.set_ColWidth(1, 0)
				.set_ColWidth(2, 1600)
				.set_ColWidth(3, 750)
				.set_ColWidth(4, 700)
				.set_ColWidth(5, 370)
				.set_ColWidth(6, 270)
				.set_ColWidth(7, 650)
				.set_ColWidth(8, 4500)
				.set_ColWidth(9, 1000)
				.set_ColWidth(10, 500)
				.set_ColWidth(11, 1000)
				.set_ColWidth(12, 0)
				.set_ColAlignment(2, 1)
				.set_ColAlignment(5, 3)
				.set_ColAlignment(6, 3)
				.set_ColAlignment(7, 3)
				.set_ColAlignment(9, 3)
				.set_ColAlignment(11, 7)
				.Redraw = True
			End With
			System.Windows.Forms.Application.DoEvents()
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: MontaGrade" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Function RetornaNomeConsumidor(ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByVal alngUnidId As Integer, ByVal alngConsId As Integer, ByVal astrGrupo As String, Optional ByRef astrSituacao As String = "") As String
		Try
			Dim lstrNome As String
			Dim lstrSql As String
			'Dim lrstAux As ADODB.Recordset
			'lrstAux = New ADODB.Recordset
			astrSituacao = "L"
			lstrNome = ""
			lstrSql = ""
			lstrSql = lstrSql & "SELECT `unid_id`, `zona`, `livro`, `conta`, `nome`, `situacao` " & vbCrLf
			lstrSql = lstrSql & "  FROM `uc_faturamento` " & vbCrLf
			'lstrSql = lstrSql & " WHERE `unid_id` = " & alngUnidId & vbCrLf
			lstrSql = lstrSql & " WHERE `id` = " & alngUnidId & vbCrLf
			lstrSql = lstrSql & "   AND `cons_id` = " & alngConsId
			lstrSql = lstrSql & "   AND `zona`    = " & astrZona
			lstrSql = lstrSql & "   AND `livro`   = " & astrLivro
			lstrSql = lstrSql & "   AND `conta`   = " & astrConta
			'Call Conectar(lstrSql, lrstAux)
			objAtualizaBancosDados.QUERY_NAME = lstrSql
			dt = repositorioAtualizaBancosDados.Consultar(objAtualizaBancosDados)

			If dt.Rows.Count > 0 Then
				For Each row As DataRow In dt.Rows
					lstrNome = Trim(IIf(IsDBNull(row.Item("nome")), "EM BRANCO", row.Item("nome")))
					astrSituacao = Trim(IIf(IsDBNull(row.Item("situacao")), "L", row.Item("situacao")))
				Next
			End If


			If CInt(Len(lstrNome)) = 0 Then
				lstrSql = ""
				lstrSql = lstrSql & "SELECT `consreg`, `nome` " & vbCrLf
				lstrSql = lstrSql & "  FROM `consum` " & vbCrLf
				lstrSql = lstrSql & " WHERE `consreg` = " & alngConsId
				'Call Conectar(lstrSql, lrstAux)
				objAtualizaBancosDados.QUERY_NAME = lstrSql
				dt1 = repositorioAtualizaBancosDados.Consultar(objAtualizaBancosDados)

				If dt1.Rows.Count > 0 Then
					For Each row1 As DataRow In dt1.Rows
						lstrNome = Trim(IIf(IsDBNull(row1.Item("nome")), "EM BRANCO", row1.Item("nome")))
					Next
				Else
					lstrNome = "NOME NÃO ENCONTRADO"
				End If
			End If

			RetornaNomeConsumidor = lstrNome

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

	Private Sub LancaPDD()
		Dim ldblNumNF As Double
		Dim lstrMesAno As String
		Dim llngConta As Integer
		Dim lstrFlgSt As String
		Dim lstrSql As String
		Dim llngAux As Integer
		Try
			Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
			llngAux = 0
			With Me.mfgDados
				Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .Rows - 1)
				For llngConta = 1 To .Rows - 1
					'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					ldblNumNF = CDbl(IIf(IsNumeric(.get_TextMatrix(llngConta, 3)), .get_TextMatrix(llngConta, 3), 0))
					lstrMesAno = Trim(.get_TextMatrix(llngConta, 4))
					lstrFlgSt = .get_TextMatrix(llngConta, 12)
					lstrSql = ""
					lstrSql = lstrSql & "UPDATE `nf` " & vbCrLf
					lstrSql = lstrSql & "   SET `flgst`    = 'R', " & vbCrLf
					lstrSql = lstrSql & "       `datapag`  = '" & VB6.Format(Me.dtpBaixa.Value, "yyyy-MM-dd") & "', " & vbCrLf
					lstrSql = lstrSql & "       `banarrec` =  " & CInt(IIf(IsNumeric(Me.lblCodigoBanco.Text), Me.lblCodigoBanco.Text, 0)) & ", " & vbCrLf
					lstrSql = lstrSql & "       `banident` = '" & Trim(Me.lblDescricaoBanco.Text) & "' " & vbCrLf
					lstrSql = lstrSql & " WHERE `numnf` =  " & ldblNumNF & " " & vbCrLf
					lstrSql = lstrSql & "   AND `mesano`= '" & lstrMesAno & "' " & vbCrLf
					lstrSql = lstrSql & "   AND `flgst` NOT IN('R','C','P'"
					If Me.chkBaixaJudice.CheckState = System.Windows.Forms.CheckState.Unchecked Then
						lstrSql = lstrSql & ",'J') "
					Else
						lstrSql = lstrSql & ") "
					End If
					objExecAtualizaBancosDados.QUERY_NAME = lstrSql
					repositorioExecAtualizaBancosDados.Execute(objAtualizaBancosDados)

					If lstrFlgSt <> "J" Or Me.chkBaixaJudice.CheckState = System.Windows.Forms.CheckState.Checked Then
						llngAux = llngAux + 1
					End If

					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
				Next llngConta
				Call MsgBox(llngAux & " notas fiscais transportadas para reserva com sucesso!", MsgBoxStyle.Information, gstrTituloMensagem)
				Call .Clear()
				.Rows = 1
			End With
			Me.Cursor = System.Windows.Forms.Cursors.Default
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: LancaPDD" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	
	Private Sub RetornaPDD()
		Dim ldblNumNF As Double
		Dim lstrMesAno As String
		Dim llngConta As Integer
		Dim lstrSql As String
		Dim llngAux As Integer
		Try
			'
			Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
			llngAux = 0
			With Me.mfgDados
				Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .Rows - 1)
				For llngConta = 1 To .Rows - 1
					'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					ldblNumNF = CDbl(IIf(IsNumeric(.get_TextMatrix(llngConta, 3)), .get_TextMatrix(llngConta, 3), 0))
					lstrMesAno = Trim(.get_TextMatrix(llngConta, 4))
					If ldblNumNF > 0 Then
						lstrSql = ""
						lstrSql = lstrSql & "UPDATE `nf` " & vbCrLf
						lstrSql = lstrSql & "   SET `flgst`    = '', " & vbCrLf
						lstrSql = lstrSql & "       `datapag`  = '0000-00-00', " & vbCrLf
						lstrSql = lstrSql & "       `banarrec` = (banco_fatur + 0) " & vbCrLf
						lstrSql = lstrSql & " WHERE `numnf`  = " & ldblNumNF & " " & vbCrLf
						lstrSql = lstrSql & "   AND `mesano` = '" & lstrMesAno & "' " & vbCrLf
						lstrSql = lstrSql & "   AND `flgst`  = 'R' "
						objExecAtualizaBancosDados.QUERY_NAME = lstrSql
						repositorioExecAtualizaBancosDados.Execute(objExecAtualizaBancosDados)

						llngAux = llngAux + 1

					End If
					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
				Next llngConta
				Call MsgBox(llngAux & " notas fiscais retornadas da reserva com sucesso!", MsgBoxStyle.Information, gstrTituloMensagem)
				Call .Clear()
				.Rows = 1
			End With
			Me.Cursor = System.Windows.Forms.Cursors.Default
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: RetornaPDD" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub DesLigBotoes(ByVal ablnModo As Boolean)
		Try
			Me.cmdAnalisar.Enabled = ablnModo
			Me.cmdFechar.Enabled = ablnModo
			'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			Me.cmdImprimir.Enabled = IIf(Me.mfgDados.Rows > 1, ablnModo, False)
			'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			Me.cmdRegistrar.Enabled = IIf(Me.mfgDados.Rows > 1, ablnModo, False)
			'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			Me.cmdRetirar.Enabled = IIf(Me.mfgDados.Rows > 1, ablnModo, False)
			Me.dtpBase.Enabled = ablnModo
			Me.cmbOpcao.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: DesLigBotoes" & "", "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 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 = "rptRelReservaPDD" Then

				dt_3 = New DataTable()
				dt_3.Columns.Add("CLASSE", GetType(String))
				dt_3.Columns.Add("ZONA", GetType(String))
				dt_3.Columns.Add("LIVRO", GetType(String))
				dt_3.Columns.Add("CONTA", GetType(String))
				dt_3.Columns.Add("NOME", GetType(String))
				dt_3.Columns.Add("VENCIMENTO", GetType(String))
				dt_3.Columns.Add("DIAS", GetType(String))
				dt_3.Columns.Add("TOLERANCIA", GetType(String))
				dt_3.Columns.Add("VALOR", GetType(String))

				dt_2 = New DataTable()
				dt_2.Columns.Add("CLASSE", GetType(String))
				dt_2.Columns.Add("TOTAL", GetType(String))
				dt_2.Columns.Add("QTDE", GetType(String))

				ds = New DataSet

				lstrsql = ""
				lstrsql = "SELECT * FROM AUX_RESERVA_PDD"
				objAtualizaBancosDados.QUERY_NAME = lstrsql
				dt = repositorioAtualizaBancosDados.Consultar(objAtualizaBancosDados)


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

						dt_3.Rows.Add(dr_1("CLASSE"),
										  dr_1("ZONA"),
										  dr_1("LIVRO"),
										  dr_1("CONTA"),
										  dr_1("NOME"),
										  dr_1("VENCIMENTO"),
										  dr_1("DIAS"),
										  dr_1("TOLERANCIA"),
										  dr_1("VALOR"))

					Next dr_1
				End If


				lstrsql = ""
				lstrsql = "SELECT * FROM AUX_RESERVA_PDDTOT"
				objAtualizaBancosDados.QUERY_NAME = lstrsql
				dt1 = repositorioAtualizaBancosDados.Consultar(objAtualizaBancosDados)

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

						dt_2.Rows.Add(dr_1("CLASSE"),
									  dr_1("VALOR"),
									  dr_1("QTDE"))

					Next dr_1
				End If


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

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


				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 rptRelReservaPDD


					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)


					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 sCriaTabelaAuxiliar()
		Try
			Dim lstrsql As String

			objExecAtualizaBancosDados.QUERY_NAME = "drop table if exists AUX_RESERVA_PDD"
			repositorioExecAtualizaBancosDados.Execute(objExecAtualizaBancosDados)

			lstrsql = ""
			lstrsql = "create table AUX_RESERVA_PDD("
			lstrsql = lstrsql & "CLASSE VARCHAR(50),"
			lstrsql = lstrsql & "ZONA VARCHAR(10),"
			lstrsql = lstrsql & "LIVRO  VARCHAR(10),"
			lstrsql = lstrsql & "CONTA VARCHAR(15),"
			lstrsql = lstrsql & "NOME VARCHAR(50),"
			lstrsql = lstrsql & "VENCIMENTO VARCHAR(10),"
			lstrsql = lstrsql & "DIAS VARCHAR(10),"
			lstrsql = lstrsql & "TOLERANCIA VARCHAR(10),"
			lstrsql = lstrsql & "VALOR decimal(14,2))"
			objExecAtualizaBancosDados.QUERY_NAME = lstrsql
			repositorioExecAtualizaBancosDados.Execute(objExecAtualizaBancosDados)


			objExecAtualizaBancosDados.QUERY_NAME = "drop table if exists AUX_RESERVA_PDDTOT"
			repositorioExecAtualizaBancosDados.Execute(objExecAtualizaBancosDados)

			lstrsql = ""
			lstrsql = "create table AUX_RESERVA_PDDTOT("
			lstrsql = lstrsql & "CLASSE VARCHAR(50),"
			lstrsql = lstrsql & "VALOR decimal(14,2),"
			lstrsql = lstrsql & "QTDE VARCHAR(20))"
			objExecAtualizaBancosDados.QUERY_NAME = lstrsql
			repositorioExecAtualizaBancosDados.Execute(objExecAtualizaBancosDados)

		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 cmdImprimir_Click_old()
	'	Dim lstrTable As String
	'	Dim llngConta As Long
	'	Dim lstrZona As String
	'	Dim lstrLivro As String
	'	Dim lstrConta As String
	'	Dim lstrNome As String
	'	Dim ldteVencto As Date
	'	Dim ldblValor As Double
	'	Dim ldblVlrTotal As Double
	'	Dim llngQtdTotal As Long
	'	Dim llngDias As Long
	'	Dim lstrClasse As String
	'	Dim lstrClas(1 To 20) As String
	'	Dim ldblTotal(1 To 20) As Double
	'	Dim lngTotal(1 To 20) As Long
	'	Dim lstrMesAno As String
	'	Dim llngPagina As Long
	'	'
	'	If Me.mfgDados.Rows > 1 Then
	'		istrClasseCabec = "Cons. da classe " & mfgDados.TextMatrix(1, 2) & " venc. a mais de " & mfgDados.TextMatrix(1, 0) & " dias"
	'		lstrClasse = istrClasseCabec
	'		With ifrAuxiliar
	'     Set .quem_chama = FrmPDD
	'     .VS.FontName = "Arial"
	'			.VS.FontSize = 9
	'			.VS.TableBorder = tbNone
	'			.VS.PageBorder = tbNone
	'			.VS.ShowGuides = gdShow
	'			.VS.Orientation = orPortrait
	'			.VS.PhysicalPage = True
	'			.VS.PaperSize = pprA4
	'			.VS.MarginTop = "7mm"
	'			.VS.MarginRight = "7mm"
	'			.VS.MarginLeft = "7mm"
	'			.VS.MarginBottom = "5mm"
	'			.VS.MarginFooter = "0mm"
	'			.VS.MarginHeader = "0mm"
	'			.VS.TextColor = vbBlack
	'			.VS.BrushStyle = bsSolid
	'			.VS.FontBold = False
	'			.VS.StartDoc
	'			Call BarraProgresso(Me.ProgressBar, Me.lblPerc, Me.lblInfo, 0, Me.mfgDados.Rows - 1)
	'			For llngConta = 1 To Me.mfgDados.Rows - 1
	'				istrClasseCabec = "Cons. da classe " & mfgDados.TextMatrix(llngConta, 2) & " venc. a mais de " & mfgDados.TextMatrix(llngConta, 0) & " dias"
	'				If istrClasseCabec <> lstrClasse Then
	'					Call .VS.DrawLine("8mm", .VS.CurrentY + 100, "202mm", .VS.CurrentY + 100)
	'					Call LineFeed(.VS, 1)
	'					lstrTable = ""
	'					lstrTable = lstrTable & "<40mm|>20mm<|75mm|<40mm|>20mm;Total de Débitos: |"
	'					lstrTable = lstrTable & llngQtdTotal
	'					lstrTable = lstrTable & "||Valor Total: |"
	'					lstrTable = lstrTable & Format(ldblVlrTotal, "Standard")
	'					.VS.Table = lstrTable
	'					ldblVlrTotal = 0
	'					llngQtdTotal = 0
	'					lstrClasse = istrClasseCabec
	'					If llngPagina = .VS.CurrentPage Then
	'						.VS.NewPage
	'					End If
	'				End If
	'				With mfgDados
	'					lstrMesAno = .TextMatrix(llngConta, 4)
	'					lstrZona = .TextMatrix(llngConta, 5)
	'					lstrLivro = .TextMatrix(llngConta, 6)
	'					lstrConta = .TextMatrix(llngConta, 7)
	'					lstrNome = Left(.TextMatrix(llngConta, 8), 40)
	'					ldteVencto = CDate(.TextMatrix(llngConta, 9))
	'					llngDias = .TextMatrix(llngConta, 10)
	'					ldblValor = .TextMatrix(llngConta, 11)
	'				End With
	'				llngPagina = .VS.CurrentPage
	'				lstrTable = ""
	'				lstrTable = lstrTable & "<25mm|<90mm|^20mm|>15mm|>15mm|>30mm;"
	'				lstrTable = lstrTable & lstrZona & "." & lstrLivro & "." & lstrConta
	'				lstrTable = lstrTable & "|" & lstrNome
	'				lstrTable = lstrTable & "|" & Format(ldteVencto, "dd/mm/yyyy")
	'				lstrTable = lstrTable & "|" & lstrMesAno
	'				lstrTable = lstrTable & "|" & llngDias
	'				lstrTable = lstrTable & "|" & Format(ldblValor, "Standard")
	'				.VS.Table = lstrTable
	'				ldblVlrTotal = ldblVlrTotal + ldblValor
	'				llngQtdTotal = llngQtdTotal + 1
	'				With Me.mfgDados
	'					lstrClas(.TextMatrix(llngConta, 1)) = .TextMatrix(llngConta, 2)
	'					ldblTotal(.TextMatrix(llngConta, 1)) = ldblTotal(.TextMatrix(llngConta, 1)) + ldblValor
	'					lngTotal(.TextMatrix(llngConta, 1)) = lngTotal(.TextMatrix(llngConta, 1)) + 1
	'				End With
	'				Call BarraProgresso(Me.ProgressBar, Me.lblPerc, Me.lblInfo, 1)
	'			Next llngConta
	'			Call .VS.DrawLine("8mm", .VS.CurrentY + 100, "202mm", .VS.CurrentY + 100)
	'			Call LineFeed(.VS, 1)
	'			lstrTable = ""
	'			lstrTable = lstrTable & "<40mm|>20mm<|75mm|<40mm|>20mm;"
	'			lstrTable = lstrTable & "Total de Débitos: |" & llngQtdTotal
	'			lstrTable = lstrTable & "||Valor Total: |" & Format(ldblVlrTotal, "Standard")
	'			.VS.Table = lstrTable
	'			istrClasseCabec = "Resumo dos Totais Apurados"
	'			.VS.NewPage
	'			ifrAuxiliar.VS.Table = "<30mm|<70mm|>30mm|>30mm;|Classe|Qtde|Valor"
	'			Call ifrAuxiliar.VS.DrawLine("8mm", ifrAuxiliar.VS.CurrentY + 100, "202mm", ifrAuxiliar.VS.CurrentY + 100)
	'			Call LineFeed(ifrAuxiliar.VS, 1)
	'			ldblVlrTotal = 0
	'			llngQtdTotal = 0
	'			For llngConta = 1 To 20
	'				If Len(Trim(lstrClas(llngConta))) > 0 Then
	'					lstrTable = ""
	'					lstrTable = lstrTable & "<30mm|<70mm|>30mm|>30mm;"
	'					lstrTable = lstrTable & "|" & lstrClas(llngConta)
	'					lstrTable = lstrTable & "|" & lngTotal(llngConta)
	'					lstrTable = lstrTable & "|" & Format(ldblTotal(llngConta), "Standard")
	'					.VS.Table = lstrTable
	'					.VS.PenStyle = psDot
	'					Call .VS.DrawLine("38mm", .VS.CurrentY + 10, "166mm", .VS.CurrentY + 10)
	'					.VS.PenStyle = psSolid
	'					ldblVlrTotal = ldblVlrTotal + ldblTotal(llngConta)
	'					llngQtdTotal = llngQtdTotal + lngTotal(llngConta)
	'				End If
	'			Next llngConta
	'			Call .VS.DrawLine("38mm", .VS.CurrentY + 10, "166mm", .VS.CurrentY + 10)
	'			lstrTable = ""
	'			lstrTable = lstrTable & "<30mm|<70mm|>30mm|>30mm;"
	'			lstrTable = lstrTable & "|Total"
	'			lstrTable = lstrTable & "|" & llngQtdTotal
	'			lstrTable = lstrTable & "|" & Format(ldblVlrTotal, "Standard")
	'			.VS.Table = lstrTable
	'			.VS.PenStyle = psDot
	'			Call .VS.DrawLine("38mm", .VS.CurrentY + 10, "166mm", .VS.CurrentY + 10)
	'			.VS.PenStyle = psSolid
	'			Call .VS.EndDoc
	'			Call .Show
	'		End With
	'	End If
	'End Sub



End Class