Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmRelInadimplencia_Covid
	Inherits System.Windows.Forms.Form
	Private istrNmArq As String
	'UPGRADE_WARNING: Lower bound of array ilngPerAno 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"'
	Private ilngPerAno(100) As Integer
	Private idteBase As Date
	Private istrCaminho As String
	
	Private Sub cmdArquivo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdArquivo.Click
		With Me.cmdArquivo
			Me.Enabled = False
			frmDir.frmQuemChama = Me
			frmDir.intTipo = 0
			Call frmDir.SetBounds(VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(Me.Left) + VB6.PixelsToTwipsX(.Left) + 400), VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(Me.Top) + VB6.PixelsToTwipsY(.Top) + 400), 0, 0, Windows.Forms.BoundsSpecified.X Or Windows.Forms.BoundsSpecified.Y)
			Call frmDir.Show()
		End With
	End Sub
	
	Private Sub cmdExporta_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExporta.Click
		If Me.opbCSV.Checked Then
			Call ExportaCSV()
		ElseIf Me.opbXML.Checked Then 
			Call ExportaXML()
		End If
	End Sub
	
	Private Sub ExportaXML()
		Dim lstrSigla As String
		Dim lstrLinha As String
		Dim lstrColuna As String
		'
		Dim ldblValor As Double
		'
		Dim lintARQ As Short
		Dim lstrNMArq As String
		'
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		
		lstrSql = "SELECT * FROM `inadimplentes_fatur`"
		lstrNMArq = Me.txtDir.Text & IIf(VB.Right(Trim(Me.txtDir.Text), 1) <> "\", "\", "") & Me.txtArquivo.Text
		
		If Trim(Me.txtDir.Text) <> "" And Trim(Me.txtArquivo.Text) <> "" Then
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						Call BarraProgresso(Me.ProgressBar(1), Me.lblPerc(1), (Me.lblInfo), 0, .RecordCount, " Inadimplência ")
						lintARQ = FreeFile
						FileOpen(lintARQ, lstrNMArq, OpenMode.Output)
						PrintLine(lintARQ, "<?xml version=""1.0"" encoding=""ISO8859-1""?>")
						PrintLine(lintARQ, "<TIQ Tipo=""indicadores"" " & "CodigoConcessionario=""" & gstrEmpresa_CodRes89 & """ " & "Sigla=""" & gstrEmpresa_Sigla & """ " & "DataGeracaoArquivo=""" & VB6.Format(idteBase, "dd/MM/yyyy") & """ " & "Sequencial=""S" & Me.txtVersao.Text & """>")
						
						While Not .EOF
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							lstrSigla = IIf(IsDbNull(.Fields("sigla").value), "", .Fields("sigla").value)
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							lstrLinha = IIf(IsDbNull(.Fields("linha").value), "", .Fields("linha").value)
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							lstrColuna = IIf(IsDbNull(.Fields("coluna").value), "", .Fields("coluna").value)
							ldblValor = GetValorLinhaColunaDataFlex(lstrLinha, lstrColuna)
							
							PrintLine(lintARQ, vbTab & "<indicador>")
							PrintLine(lintARQ, vbTab & vbTab & "<codigo_conjunto/>")
							PrintLine(lintARQ, vbTab & vbTab & "<codigo_UC/>")
							PrintLine(lintARQ, vbTab & vbTab & "<sigla_indice>" & lstrSigla & "</sigla_indice>")
							PrintLine(lintARQ, vbTab & vbTab & "<valor_indicador>" & Replace(CStr(ldblValor), ",", ".") & "</valor_indicador>")
							'Print #lintARQ, vbTab & vbTab & "<periodo_competencia>" & (Format(Me.dtpMesAno.Month, "00")) & "</periodo_competencia>"
							'Print #lintARQ, vbTab & vbTab & "<ano_competencia>" & (Format(Me.dtpMesAno.Year, "0000")) & "</ano_competencia>"
							PrintLine(lintARQ, vbTab & "</indicador>")
							
							Call .MoveNext()
							Call BarraProgresso(Me.ProgressBar(1), Me.lblPerc(1), (Me.lblInfo), 1,  , " Inadimplência ")
						End While
						PrintLine(lintARQ, "</TIQ>")
						FileClose(lintARQ)
						Call MsgBox("Arquivo gerado com sucesso!", MsgBoxStyle.Information, gstrTituloMensagem)
					End If
				End If
			End With
		Else
			Call MsgBox("Você deve selecionar o caminho para gerar o XML", MsgBoxStyle.Information, gstrTituloMensagem)
		End If
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Sub
	
	Private Function GetValorLinhaColunaDataFlex(ByVal astrLinha As String, ByVal astrColuna As String) As Double
		Dim ldblRet As Double
		Dim lintLin As Short
		Dim lintCol As Short
		With Me.mfgDados
			For lintLin = 1 To .Rows - 1
				If .get_TextMatrix(lintLin, 0) = astrLinha Then
					For lintCol = 1 To .Cols - 1
						If .get_TextMatrix(0, lintCol) = astrColuna Then
							ldblRet = IIf(IsNumeric(.get_TextMatrix(lintLin, lintCol)), .get_TextMatrix(lintLin, lintCol), 0)
						End If
					Next lintCol
				End If
			Next lintLin
		End With
		GetValorLinhaColunaDataFlex = ldblRet
	End Function
	
	Private Sub ExportaCSV()
		'Controle Arquivo
		Dim lstrCla As String
		Dim lstrMes As String
		Dim llngSus As Integer
		Dim ldblPer As Double
		Dim ldblFat As Double
		Dim ldblAbe As Double
		Dim lintAux As Short
		Dim lstrLin As String
		Dim lintARQ As Short
		Dim lstrNMArq As String
		
		Dim MData As String
		Dim MResidencial_fatu As Double
		Dim MResidencial_Outros_fatu As Double
		Dim MIndustrial_fatu As Double
		Dim MComercial_fatu As Double
		Dim MRural_fatu As Double
		Dim MPoder_Publico_fatu As Double
		Dim MIluminacao_Publica_fatu As Double
		Dim MServico_Publico_fatu As Double
		Dim MOutros_fatu As Double
		Dim MTotal_fatu As Double
		
		Dim MResidencial_arre As Double
		Dim MResidencial_Outros_arre As Double
		Dim MIndustrial_arre As Double
		Dim MComercial_arre As Double
		Dim MRural_arre As Double
		Dim MPoder_Publico_arre As Double
		Dim MIluminacao_Publica_arre As Double
		Dim MServico_Publico_arre As Double
		Dim MOutros_arre As Double
		Dim MTotal_arre As Double
		
		
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		
		lstrNMArq = Me.txtDir.Text & IIf(VB.Right(Trim(Me.txtDir.Text), 1) <> "\", "\", "") & Me.txtArquivo.Text
		
		If Trim(Me.txtDir.Text) <> "" And Trim(Me.txtArquivo.Text) <> "" Then
			lstrSql = ""
			lstrSql = lstrSql & "SELECT * "
			lstrSql = lstrSql & "  FROM inadimplentes_fatur"
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						Call BarraProgresso(Me.ProgressBar(1), Me.lblPerc(1), (Me.lblInfo), 0, .RecordCount, " Gerando Arquivo CSV ")
						lintARQ = FreeFile
						FileOpen(lintARQ, lstrNMArq, OpenMode.Output)
						
						lstrLin = "Data" & ";" & "Residencial_fatur" & ";" & "Residencial_Outros_fatur" & ";" & "Industrial_fatur" & ";" & "Comercial_fatur" & ";" & "Rural_fatur" & ";" & "Poder_Publico_fatur" & ";" & "Iluminacao_Publica_fatur" & ";" & "Servico_Publico_fatur" & ";" & "Outros_fatur" & ";" & "Total_fatur" & ";"
						lstrLin = lstrLin & "Residencial_arrec" & ";" & "Residencial_Outros_arrec" & ";" & "Industrial_arrec" & ";" & "Comercial_arrec" & ";" & "Rural_arrec" & ";" & "Poder_Publico_arrec" & ";" & "Iluminacao_Publica_arrec" & ";" & "Servico_Publico_arrec" & ";" & "Outros_arrec" & ";" & "Total_arrec"
						
						'Next lintAux
						If CInt(Len(lstrLin)) > 0 Then
							PrintLine(lintARQ, lstrLin)
						End If
						
						While Not .EOF
							
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							MData = Trim(IIf(IsDbNull(.Fields("Data").value), "", .Fields("Data").value))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							MResidencial_fatu = CDbl(Trim(IIf(IsDbNull(.Fields("Residencial_fatu").value), 0, .Fields("Residencial_fatu").value)))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							MResidencial_Outros_fatu = CDbl(Trim(IIf(IsDbNull(.Fields("Residencial_Outros_fatu").value), 0, .Fields("Residencial_Outros_fatu").value)))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							MIndustrial_fatu = CDbl(Trim(IIf(IsDbNull(.Fields("Industrial_fatu").value), 0, .Fields("Industrial_fatu").value)))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							MComercial_fatu = CDbl(Trim(IIf(IsDbNull(.Fields("Comercial_fatu").value), 0, .Fields("Comercial_fatu").value)))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							MRural_fatu = CDbl(Trim(IIf(IsDbNull(.Fields("Rural_fatu").value), 0, .Fields("Rural_fatu").value)))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							MPoder_Publico_fatu = CDbl(Trim(IIf(IsDbNull(.Fields("Poder_Publico_fatu").value), 0, .Fields("Poder_Publico_fatu").value)))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							MIluminacao_Publica_fatu = CDbl(Trim(IIf(IsDbNull(.Fields("Iluminacao_Publica_fatu").value), 0, .Fields("Iluminacao_Publica_fatu").value)))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							MServico_Publico_fatu = CDbl(Trim(IIf(IsDbNull(.Fields("Servico_Publico_fatu").value), 0, .Fields("Servico_Publico_fatu").value)))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							MOutros_fatu = CDbl(Trim(IIf(IsDbNull(.Fields("Outros_fatu").value), 0, .Fields("Outros_fatu").value)))
							
							MTotal_fatu = 0
							MTotal_fatu = MResidencial_fatu + MIndustrial_fatu + MComercial_fatu + MRural_fatu + MPoder_Publico_fatu + MIluminacao_Publica_fatu + MServico_Publico_fatu + MOutros_fatu
							
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							MResidencial_arre = CDbl(Trim(IIf(IsDbNull(.Fields("Residencial_arre").value), 0, .Fields("Residencial_arre").value)))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							MResidencial_Outros_arre = CDbl(Trim(IIf(IsDbNull(.Fields("Residencial_Outros_arre").value), 0, .Fields("Residencial_Outros_arre").value)))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							MIndustrial_arre = CDbl(Trim(IIf(IsDbNull(.Fields("Industrial_arre").value), 0, .Fields("Industrial_arre").value)))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							MComercial_arre = CDbl(Trim(IIf(IsDbNull(.Fields("Comercial_arre").value), 0, .Fields("Comercial_arre").value)))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							MRural_arre = CDbl(Trim(IIf(IsDbNull(.Fields("Rural_arre").value), 0, .Fields("Rural_arre").value)))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							MPoder_Publico_arre = CDbl(Trim(IIf(IsDbNull(.Fields("Poder_Publico_arre").value), 0, .Fields("Poder_Publico_arre").value)))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							MIluminacao_Publica_arre = CDbl(Trim(IIf(IsDbNull(.Fields("Iluminacao_Publica_arre").value), 0, .Fields("Iluminacao_Publica_arre").value)))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							MServico_Publico_arre = CDbl(Trim(IIf(IsDbNull(.Fields("Servico_Publico_arre").value), 0, .Fields("Servico_Publico_arre").value)))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							MOutros_arre = CDbl(Trim(IIf(IsDbNull(.Fields("Outros_arre").value), 0, .Fields("Outros_arre").value)))
							
							MTotal_arre = 0
							MTotal_arre = MResidencial_arre + MIndustrial_arre + MComercial_arre + MRural_arre + MPoder_Publico_arre + MIluminacao_Publica_arre + MServico_Publico_arre + MOutros_arre
							
							lstrLin = ""
							lstrLin = MData & ";" & MResidencial_fatu & ";" & MResidencial_Outros_fatu & ";" & MIndustrial_fatu & ";" & MComercial_fatu & ";" & MRural_fatu & ";" & MPoder_Publico_fatu & ";" & MIluminacao_Publica_fatu & ";" & MServico_Publico_fatu & ";" & MOutros_fatu & ";" & MTotal_fatu & ";"
							lstrLin = lstrLin & MResidencial_arre & ";" & MResidencial_Outros_arre & ";" & MIndustrial_arre & ";" & MComercial_arre & ";" & MRural_arre & ";" & MPoder_Publico_arre & ";" & MIluminacao_Publica_arre & ";" & MServico_Publico_arre & ";" & MOutros_arre & ";" & MTotal_arre
							
							If CInt(Len(lstrLin)) > 0 Then
								PrintLine(lintARQ, lstrLin)
							End If
							Call .MoveNext()
							Call BarraProgresso(Me.ProgressBar(1), Me.lblPerc(1), (Me.lblInfo), 1,  , " Gerando Arquivo CSV ")
						End While
						FileClose(lintARQ)
						Call MsgBox("Arquivo gerado com sucesso!", MsgBoxStyle.Information, gstrTituloMensagem)
					End If
					Call .Close()
				End If
			End With
		End If
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Sub
	
	Private Sub cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click
		Call Me.Close()
	End Sub
	
	Private Sub dtpMesAno_Change(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles dtpMesAno.Change
		If Me.opbCSV.Checked Then
			Call NomeArquivoCsv()
		ElseIf Me.opbXML.Checked Then 
			Call NomeArquivoXML()
		End If
	End Sub
	
	Private Sub dtpMesAno_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles dtpMesAno.ClickEvent
		Call dtpMesAno_Change(dtpMesAno, New System.EventArgs())
	End Sub
	
	Private Sub frmRelInadimplencia_Covid_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Dim lintAux As Short
		Dim lstrSql As String
		idteBase = BuscaDataBD
		
		istrCaminho = LeConfig("CAMINHO_XML_TIQ")
		If istrCaminho = "-1" Then
			istrCaminho = My.Application.Info.DirectoryPath
			Call CriaParConfig("CAMINHO_XML_TIQ", Replace(istrCaminho, "\", "\\"), False, "Caminho de gravação para o arquivo XML INDQUAL.")
		ElseIf istrCaminho = "" Then 
			istrCaminho = My.Application.Info.DirectoryPath
			Call GravaConfig("CAMINHO_XML_TIQ", Replace(istrCaminho, "\", "\\"))
		End If
		
		If VB.Right(Trim(istrCaminho), 1) <> "\" Then
			istrCaminho = istrCaminho & "\"
		End If
		Me.txtVersao.Text = "01"
		
		With Me.lsvMeses
			Call .Items.Clear()
			Call .Columns.Clear()
			If .Columns.Count <= 1 Then
				Call .Columns.Add("", "Mês", CInt(VB6.TwipsToPixelsX(650)))
			End If
			For lintAux = 1 To 72
				Call .Items.Add(CStr(lintAux))
				If InStr(1, "24,21,18,12,06,03,01", VB6.Format(lintAux, "00")) > 0 Then
					'UPGRADE_WARNING: Lower bound of collection Me.lsvMeses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
					.Items.Item(lintAux).Checked = True
				Else
					'UPGRADE_WARNING: Lower bound of collection Me.lsvMeses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
					.Items.Item(lintAux).Checked = False
				End If
			Next lintAux
		End With
		Call MontaGrade()
		Me.dtpDiaMesAno.value = idteBase
		Me.dtpDiaMesAnoInicial.value = idteBase
		Me.dtpMesAno.value = idteBase
		Me.dtpMesAnoInicial.value = idteBase
		Call NomeArquivoCsv()
		Call CriaTabelaAuxiliar()
	End Sub
	
	Private Sub cmdImprimir_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdImprimir.Click
		'imprime
		Dim lstrCriterio As String
		lstrCriterio = "{temp_inadimplentes.nomemaquina} = '" & gstrNmEstacao & "' "
		With Me.crpAux
			.ReportFileName = My.Application.Info.DirectoryPath & "\" & LeConfig("DIR_RPT") & "Relinadimplencia.rpt"
			.DiscardSavedData = True
			.WindowState = Crystal.WindowStateConstants.crptMaximized
			.WindowControlBox = True
			.WindowControls = True
			.WindowShowPrintSetupBtn = True
			.WindowShowCloseBtn = True
			.WindowShowSearchBtn = True
			.SelectionFormula = lstrCriterio
			.WindowTitle = "Relatório Inadimplência"
			.Destination = Crystal.DestinationConstants.crptToWindow
			.Action = 0
		End With
	End Sub
	
	Private Sub cmdProcessar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdProcessar.Click
		Call LigDes(False)
		Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
		Call MontaGrade()
		Call Fatur()
		Call Arrec()
		Call FaturMes()
		Call ArrecMes()
		
		
		Me.lblInfo1.Text = " Finalizado."
		Call MsgBox("Finalizado", MsgBoxStyle.Information, gstrTituloMensagem)
		'Call Me.lblInfo.Refresh
		Me.Cursor = System.Windows.Forms.Cursors.Default
		Call LigDes(True)
	End Sub
	
	Private Sub MontaGrade()
		Dim lintAux As Short
		Dim lintTam As Short
		With Me.mfgDados
			Call .Clear()
			.Redraw = False
			.Rows = 12
			For lintAux = 0 To 72
				.set_TextMatrix(0, lintAux, VB6.Format(lintAux, "00") & "(%)")
				.set_ColWidth(lintAux, 1200)
				If lintAux <> 0 Then
					'UPGRADE_WARNING: Lower bound of collection Me.lsvMeses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
					If Me.lsvMeses.Items.Item(lintAux).Checked = False Then
						.set_ColWidth(lintAux, 0)
					End If
				End If
			Next lintAux
			.set_TextMatrix(0, lintAux, "Suspensão")
			.set_ColWidth(lintAux, 1200)
			.set_TextMatrix(1, 0, "RESIDENCIAL TOTAL")
			.set_TextMatrix(2, 0, "RESIDENCIAL BAIXA RENDA")
			.set_TextMatrix(3, 0, "RESIDENCIAL NORMAL")
			.set_TextMatrix(4, 0, "INDUSTRIAL")
			.set_TextMatrix(5, 0, "COMERCIAL")
			.set_TextMatrix(6, 0, "RURAL")
			.set_TextMatrix(7, 0, "PODER PÚBLICO")
			.set_TextMatrix(8, 0, "ILUMINAÇÃO PÚBLICA")
			.set_TextMatrix(9, 0, "SERVIÇO PÚBLICO")
			.set_TextMatrix(10, 0, "CONSUMO PRÓPRIO")
			.set_TextMatrix(11, 0, "TOTAL")
			.Redraw = True
		End With
		With Me.mfgFaturado
			Call .Clear()
			.Redraw = False
			.Rows = Me.mfgDados.Rows
			For lintAux = 0 To 72
				.set_TextMatrix(0, lintAux, VB6.Format(lintAux, "00"))
				.set_ColWidth(lintAux, Me.mfgDados.get_ColWidth(lintAux))
			Next lintAux
			.Redraw = True
		End With
		With Me.mfgAberto
			Call .Clear()
			.Redraw = False
			.Rows = Me.mfgDados.Rows
			For lintAux = 0 To 72
				.set_TextMatrix(0, lintAux, VB6.Format(lintAux, "00"))
				.set_ColWidth(lintAux, Me.mfgDados.get_ColWidth(lintAux))
			Next lintAux
			.Redraw = True
		End With
		Me.mfgDados.set_ColWidth(0, 2200)
		Me.mfgDados.set_TextMatrix(0, 0, "Classe")
		Call ConfigTipo()
	End Sub
	
	
	
	Private Sub AdicionaGrade(ByVal aintTipo As Short, ByVal astrMesAno As String, ByVal alngCodClas As Integer, ByVal adblValor As Double, ByVal aintSuspendido As Short)
		'aintTipo=0 faturado
		'aintTipo=1 aberto
		Dim llngRow As Integer
		Dim llngCol As Integer
		Dim llngAux As Integer
		If CDbl(VB.Left(CStr(alngCodClas), 1)) < 4 Then
			llngRow = 4
		ElseIf CDbl(VB.Left(CStr(alngCodClas), 1)) = 4 Then 
			llngRow = 5
		ElseIf CDbl(VB.Left(CStr(alngCodClas), 1)) = 5 Then 
			llngRow = 6
		ElseIf CDbl(VB.Left(CStr(alngCodClas), 1)) = 6 Then 
			If CDbl(VB.Left(CStr(alngCodClas), 2)) = 64 Then
				llngRow = 8
			Else
				llngRow = 7
			End If
		ElseIf CDbl(VB.Left(CStr(alngCodClas), 1)) = 7 Then 
			llngRow = 9
		ElseIf CDbl(VB.Left(CStr(alngCodClas), 1)) = 8 Then 
			llngRow = 10
		ElseIf CDbl(VB.Left(CStr(alngCodClas), 1)) = 9 Then 
			If CDbl(VB.Right(CStr(alngCodClas), 1)) = 2 Or CDbl(VB.Right(CStr(alngCodClas), 1)) = 4 Or CDbl(VB.Right(CStr(alngCodClas), 1)) = 5 Or CDbl(VB.Right(CStr(alngCodClas), 1)) = 6 Then
				llngRow = 2
			Else
				llngRow = 3
			End If
		End If
		llngCol = 0
		If aintTipo = 0 Then
			With Me.mfgFaturado
				For llngAux = 0 To 72
					If .get_TextMatrix(0, llngAux) = astrMesAno Then
						llngCol = llngAux
						llngAux = 72
					End If
				Next llngAux
				'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"'
				.set_TextMatrix(llngRow, llngCol, VB6.Format(IIf(IsNumeric(.get_TextMatrix(llngRow, llngCol)), .get_TextMatrix(llngRow, llngCol), 0) + adblValor, "#,##0.00"))
			End With
		ElseIf aintTipo = 1 Then 
			With Me.mfgAberto
				For llngAux = 0 To 72
					If .get_TextMatrix(0, llngAux) = astrMesAno Then
						llngCol = llngAux
						llngAux = 72
					End If
				Next llngAux
				'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"'
				.set_TextMatrix(llngRow, llngCol, VB6.Format(IIf(IsNumeric(.get_TextMatrix(llngRow, llngCol)), .get_TextMatrix(llngRow, llngCol), 0) + adblValor, "#,##0.00"))
			End With
		End If
		If llngCol > 0 Then
			With Me.mfgDados
				'UPGRADE_WARNING: Lower bound of collection Me.lsvMeses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
				If Me.lsvMeses.Items.Item(llngCol).Checked = True Then 'InStr(1, istrAneel, Strings.Format(llngCol, "00")) > 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"'
					.set_TextMatrix(llngRow, 73, VB6.Format(IIf(IsNumeric(.get_TextMatrix(llngRow, 73)), .get_TextMatrix(llngRow, 73), 0) + aintSuspendido, "#,##0")) 'ANEEL
				End If
			End With
		End If
	End Sub
	
	Private Sub TotalizaGrade()
		Dim llngCol As Integer
		Dim llngRow As Integer
		Dim llngAux As Integer
		Dim ldblPer As Double
		Dim ldblTot As Double
		Dim ldblAbe As Double
		For llngCol = 0 To 72
			Me.mfgFaturado.set_TextMatrix(1, llngCol, "")
			Me.mfgFaturado.set_TextMatrix(11, llngCol, "")
			Me.mfgAberto.set_TextMatrix(1, llngCol, "")
			Me.mfgAberto.set_TextMatrix(11, llngCol, "")
		Next llngCol
		'Totaliza fatura e em aberto
		For llngCol = 0 To 72
			For llngRow = 2 To 10
				If llngRow <= 3 Then
					With Me.mfgFaturado
						'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"'
						.set_TextMatrix(1, llngCol, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(1, llngCol)), .get_TextMatrix(1, llngCol), 0)) + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, llngCol)), .get_TextMatrix(llngRow, llngCol), 0)), "#,##0.00"))
					End With
					With Me.mfgAberto
						'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"'
						.set_TextMatrix(1, llngCol, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(1, llngCol)), .get_TextMatrix(1, llngCol), 0)) + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, llngCol)), .get_TextMatrix(llngRow, llngCol), 0)), "#,##0.00"))
					End With
				End If
				With Me.mfgFaturado
					'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"'
					.set_TextMatrix(11, llngCol, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(11, llngCol)), .get_TextMatrix(11, llngCol), 0)) + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, llngCol)), .get_TextMatrix(llngRow, llngCol), 0)), "#,##0.00"))
				End With
				With Me.mfgAberto
					'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"'
					.set_TextMatrix(11, llngCol, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(11, llngCol)), .get_TextMatrix(11, llngCol), 0)) + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, llngCol)), .get_TextMatrix(llngRow, llngCol), 0)), "#,##0.00"))
				End With
			Next llngRow
		Next llngCol
		'Calcula percentual de inadimplência
		For llngCol = 1 To 72
			With Me.mfgFaturado
				'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"'
				ldblTot = CDbl(IIf(IsNumeric(.get_TextMatrix(11, llngCol)), .get_TextMatrix(11, llngCol), 0))
			End With
			For llngRow = 2 To 10
				With Me.mfgAberto
					'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"'
					ldblAbe = CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, llngCol)), .get_TextMatrix(llngRow, llngCol), 0))
				End With
				If ldblTot <> 0 Then
					ldblPer = Arredondar((ldblAbe / ldblTot) * 100, 2)
				Else
					ldblPer = 0
				End If
				With Me.mfgDados
					.set_TextMatrix(llngRow, llngCol, VB6.Format(ldblPer, "#,##0.00"))
				End With
			Next llngRow
		Next llngCol
		For llngCol = 1 To 73
			For llngRow = 2 To 10
				If llngRow <= 3 Then
					With Me.mfgDados
						'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"'
						.set_TextMatrix(1, llngCol, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(1, llngCol)), .get_TextMatrix(1, llngCol), 0)) + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, llngCol)), .get_TextMatrix(llngRow, llngCol), 0)), IIf(llngCol < 25, "#,##0.00", "#,##0")))
					End With
				End If
				With Me.mfgDados
					'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"'
					.set_TextMatrix(11, llngCol, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(11, llngCol)), .get_TextMatrix(11, llngCol), 0)) + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRow, llngCol)), .get_TextMatrix(llngRow, llngCol), 0)), IIf(llngCol < 25, "#,##0.00", "#,##0")))
				End With
			Next llngRow
		Next llngCol
	End Sub
	
	Private Function MontaTabela() As Boolean
		Dim lblnErro As Boolean
		Dim lstrSql As String
		Dim llngCol As Integer
		Dim llngRow As Integer
		Dim lintAux As Short
		On Error GoTo ErroMontaTabela
		Call Executar("DELETE FROM `temp_inadimplentes` WHERE `nomemaquina` = '" & gstrNmEstacao & "'")
		lstrSql = ""
		lstrSql = lstrSql & "INSERT INTO `temp_inadimplentes` (`nomemaquina`, `classe`, `suspendido`, " & vbCrLf
		For lintAux = 0 To 72
			lstrSql = lstrSql & "`mes_" & VB6.Format(lintAux, "00") & "`, "
		Next lintAux
		lstrSql = lstrSql & vbCrLf
		For lintAux = 0 To 72
			lstrSql = lstrSql & "`per_" & VB6.Format(lintAux, "00") & "`, "
		Next lintAux
		lstrSql = lstrSql & vbCrLf
		For lintAux = 0 To 72
			lstrSql = lstrSql & "`fat_" & VB6.Format(lintAux, "00") & "`, "
		Next lintAux
		lstrSql = lstrSql & vbCrLf
		For lintAux = 0 To 72
			lstrSql = lstrSql & "`abe_" & VB6.Format(lintAux, "00") & "`, "
		Next lintAux
		lstrSql = VB.Left(lstrSql, Len(lstrSql) - 2)
		lstrSql = lstrSql & ") VALUES "
		For llngRow = 1 To Me.mfgDados.Rows - 1
			lstrSql = lstrSql & vbCrLf & "('" & gstrNmEstacao & "', "
			lstrSql = lstrSql & "'" & Me.mfgDados.get_TextMatrix(llngRow, 0) & "',"
			lstrSql = lstrSql & " " & Replace(CStr(CDbl(IIf(IsNumeric(Me.mfgDados.get_TextMatrix(llngRow, 73)), Me.mfgDados.get_TextMatrix(llngRow, 73), 0))), ",", ".") & ", " & vbCrLf
			'Meses
			For llngCol = 0 To 72
				If llngCol = 0 Then
					lstrSql = lstrSql & "'" & Me.mfgFaturado.get_TextMatrix(0, llngCol) & "', "
					'UPGRADE_WARNING: Lower bound of collection Me.lsvMeses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
				ElseIf Me.lsvMeses.Items.Item(llngCol).Checked Then 
					lstrSql = lstrSql & "'" & Me.mfgFaturado.get_TextMatrix(0, llngCol) & "', "
				Else
					lstrSql = lstrSql & "'00/0000', "
				End If
			Next llngCol
			lstrSql = lstrSql & vbCrLf
			'Percentuais
			For llngCol = 0 To 72
				If IsNumeric(Me.mfgDados.get_TextMatrix(llngRow, llngCol)) Then
					lstrSql = lstrSql & " " & Replace(IIf(llngCol = 0, 0, CDbl(Me.mfgDados.get_TextMatrix(llngRow, llngCol))), ",", ".") & ", "
				Else
					lstrSql = lstrSql & " " & Replace(IIf(llngCol = 0, 0, Me.mfgDados.get_TextMatrix(llngRow, llngCol)), ",", ".") & ", "
				End If
			Next llngCol
			lstrSql = lstrSql & vbCrLf
			'Faturado
			For llngCol = 0 To 72
				'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"'
				lstrSql = lstrSql & " " & Replace(CStr(CDbl(IIf(IsNumeric(Me.mfgFaturado.get_TextMatrix(llngRow, llngCol)), Me.mfgFaturado.get_TextMatrix(llngRow, llngCol), 0))), ",", ".") & ", "
			Next llngCol
			lstrSql = lstrSql & vbCrLf
			'Aberto
			For llngCol = 0 To 72
				'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"'
				lstrSql = lstrSql & " " & Replace(CStr(CDbl(IIf(IsNumeric(Me.mfgAberto.get_TextMatrix(llngRow, llngCol)), Me.mfgAberto.get_TextMatrix(llngRow, llngCol), 0))), ",", ".") & ", "
			Next llngCol
			lstrSql = VB.Left(lstrSql, Len(lstrSql) - 2) & "),"
		Next llngRow
		lstrSql = VB.Left(lstrSql, Len(lstrSql) - 1) & ";"
		lblnErro = (Not Executar(lstrSql))
ErroMontaTabela: 
		If lblnErro Then
			'Recria tabela temp_diversos
			Call Executar("DROP TABLE IF EXISTS `temp_inadimplentes`")
			Call CriaTabelaAuxiliar()
			'Call MsgBox("Recriado a tabela auxiliar, favor tente novamente", vbInformation, gstrTituloMensagem)
		ElseIf Err.Number > 0 Then 
			Call MsgBox(Err.Number & " - " & GetErrosVB(Err.Number, Err.Description), MsgBoxStyle.Exclamation, gstrTituloMensagem)
		End If
		MontaTabela = (Not lblnErro)
	End Function
	
	Private Sub ConfigTipo()
		Dim llngAux As Short
		With Me.mfgDados
			For llngAux = 1 To 72
				.set_ColWidth(llngAux, 1200)
				Me.mfgFaturado.set_ColWidth(llngAux, 1200)
				Me.mfgAberto.set_ColWidth(llngAux, 1200)
				'UPGRADE_WARNING: Lower bound of collection Me.lsvMeses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
				If Me.lsvMeses.Items.Item(llngAux).Checked = False Then '  InStr(1, istrAneel, Left(.TextMatrix(0, llngAux), 2)) = 0 Then
					.set_ColWidth(llngAux, 0)
					Me.mfgFaturado.set_ColWidth(llngAux, 0)
					Me.mfgAberto.set_ColWidth(llngAux, 0)
				End If
			Next llngAux
			.set_ColWidth(llngAux, 1200)
		End With
		With Me.mfgDados
			'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
			.Row = 1
			.Col = 0
			.ColSel = .Cols - 1
			.CellFontBold = True
			.Row = 11
			.ColSel = .Cols - 1
			.CellFontBold = True
			'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
		End With
		With Me.mfgFaturado
			'UPGRADE_ISSUE: VBControlExtender method mfgFaturado.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
			.Row = 1
			.Col = 0
			.ColSel = .Cols - 1
			.CellFontBold = True
			.Row = 11
			.ColSel = .Cols - 1
			.CellFontBold = True
			'UPGRADE_ISSUE: VBControlExtender method mfgFaturado.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
		End With
		With Me.mfgAberto
			'UPGRADE_ISSUE: VBControlExtender method mfgAberto.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
			.Row = 1
			.Col = 0
			.ColSel = .Cols - 1
			.CellFontBold = True
			.Row = 11
			.ColSel = .Cols - 1
			.CellFontBold = True
			'UPGRADE_ISSUE: VBControlExtender method mfgAberto.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
		End With
	End Sub
	
	Private Sub LigDes(ByVal ablnModo As Boolean)
		Me.cmdFechar.Enabled = ablnModo
		Me.cmdProcessar.Enabled = ablnModo
		Me.cmdImprimir.Enabled = ablnModo
		Me.cmdExporta.Enabled = ablnModo
		Me.cmdArquivo.Enabled = ablnModo
		Me.dtpDiaMesAno.Enabled = ablnModo
		Me.fmeAux(0).Enabled = ablnModo
		Me.fmeAux(1).Enabled = ablnModo
		Me.lsvMeses.Enabled = ablnModo
		Me.dtpDiaMesAnoInicial.Enabled = ablnModo
		Me.dtpMesAnoInicial.Enabled = ablnModo
		Me.dtpMesAno.Enabled = ablnModo
		
		'Me.mfgFaturado.Enabled = ablnModo
		'Me.mfgAberto.Enabled = ablnModo
		'Me.mfgDados.Enabled = ablnModo
	End Sub
	
	Private Function VerificaCorte(ByVal adblNumNf As Double, ByVal astrMesAno As String, ByVal adteBase As Date) As Boolean
		Dim lblnRet As Boolean
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lblnRet = False
		If Me.mfgFaturado.get_TextMatrix(0, 0) <> astrMesAno Then
			lstrSql = ""
			lstrSql = lstrSql & "SELECT * "
			lstrSql = lstrSql & "  FROM `concorte` "
			lstrSql = lstrSql & " WHERE `numnf`  = " & adblNumNf & " "
			lstrSql = lstrSql & "   AND `mesano` = '" & astrMesAno & "' "
			lstrSql = lstrSql & "   AND `datacorte` IS NOT NULL "
			lstrSql = lstrSql & "   AND `datacorte` <> '0000-00-00' "
			lstrSql = lstrSql & "   AND `datacorte` <= '" & VB6.Format(adteBase, "yyyy-MM-dd") & "' "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					lblnRet = (.RecordCount > 0)
					Call .Close()
				End If
			End With
		End If
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
		VerificaCorte = lblnRet
	End Function
	
	Private Sub frmRelInadimplencia_Covid_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		Call Executar("DELETE FROM `temp_inadimplentes` WHERE `nomemaquina` = '" & gstrNmEstacao & "'")
	End Sub
	
	Private Sub lsvMeses_ItemCheck(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.ItemCheckEventArgs) Handles lsvMeses.ItemCheck
		Dim Item As System.Windows.Forms.ListViewItem = lsvMeses.Items(eventArgs.Index)
		Call MontaGrade()
	End Sub
	
	'UPGRADE_WARNING: Event opbCSV.CheckedChanged 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 opbCSV_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbCSV.CheckedChanged
		If eventSender.Checked Then
			Call NomeArquivoCsv()
		End If
	End Sub
	
	'UPGRADE_WARNING: Event opbInadimplencia.CheckedChanged 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 opbInadimplencia_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbInadimplencia.CheckedChanged
		If eventSender.Checked Then
			Dim lintAux As Short
			With Me.lsvMeses
				For lintAux = 1 To 72
					If InStr(1, "24,21,18,12,06,03,01", VB6.Format(lintAux, "00")) > 0 Then
						'UPGRADE_WARNING: Lower bound of collection Me.lsvMeses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
						.Items.Item(lintAux).Checked = True
					Else
						'UPGRADE_WARNING: Lower bound of collection Me.lsvMeses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
						.Items.Item(lintAux).Checked = False
					End If
				Next lintAux
			End With
			Call MontaGrade()
			Me.chkLivres.Enabled = True
			Me.chkConsumoProprio.Enabled = True
			Me.chkLivres.CheckState = System.Windows.Forms.CheckState.Checked
			Me.chkConsumoProprio.CheckState = System.Windows.Forms.CheckState.Checked
		End If
	End Sub
	
	'UPGRADE_WARNING: Event opbIrrecuperaveis.CheckedChanged 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 opbIrrecuperaveis_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbIrrecuperaveis.CheckedChanged
		If eventSender.Checked Then
			Dim lintAux As Short
			With Me.lsvMeses
				For lintAux = 1 To 72
					If InStr(1, "36,30,24,21,18,15,12,09,06,05,04,03,02,01", VB6.Format(lintAux, "00")) > 0 Then
						'UPGRADE_WARNING: Lower bound of collection Me.lsvMeses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
						.Items.Item(lintAux).Checked = True
					Else
						'UPGRADE_WARNING: Lower bound of collection Me.lsvMeses.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
						.Items.Item(lintAux).Checked = False
					End If
				Next lintAux
			End With
			Call MontaGrade()
			Me.chkLivres.Enabled = False
			Me.chkConsumoProprio.Enabled = False
			Me.chkLivres.CheckState = System.Windows.Forms.CheckState.Unchecked
			Me.chkConsumoProprio.CheckState = System.Windows.Forms.CheckState.Unchecked
		End If
	End Sub
	
	Private Sub NomeArquivoCsv()
		Dim lstrAux As String
		istrNmArq = "Dados COVID ANEEL - " & gstrEmpresa_Sigla & " - " & VB6.Format(Me.dtpDiaMesAno.value, "ddMMyyyy")
		Me.txtArquivo.Text = istrCaminho
		Me.txtArquivo.Text = istrNmArq & ".CSV"
		System.Windows.Forms.Application.DoEvents()
		
	End Sub
	
	Private Sub NomeArquivoXML()
		istrNmArq = "APLTIQ" & VB6.Format(VB.Left(gstrEmpresa_CodRes89, 4), "0000") & "INDICADORES_"
		Me.txtArquivo.Text = istrCaminho
		Me.txtArquivo.Text = istrNmArq & VB6.Format(idteBase, "ddMMyyyy") & "_S" & VB6.Format(Me.txtVersao.Text, "00") & ".XML"
		System.Windows.Forms.Application.DoEvents()
	End Sub
	
	Private Sub CriaTabelaAuxiliar()
		Dim lstrSql As String
		Dim lintAux As Short
		lstrSql = ""
		lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS `temp_inadimplentes` ("
		lstrSql = lstrSql & "`nomemaquina`            varchar(255) DEFAULT NULL, "
		lstrSql = lstrSql & "`classe`                 varchar(100) DEFAULT NULL, "
		lstrSql = lstrSql & "`suspendido`             int(11) NOT NULL default '0', "
		For lintAux = 0 To 72
			lstrSql = lstrSql & "`mes_" & VB6.Format(lintAux, "00") & "`                 varchar(7) NOT NULL default '', "
		Next lintAux
		For lintAux = 0 To 72
			lstrSql = lstrSql & "`per_" & VB6.Format(lintAux, "00") & "`                 decimal(14,2) default NULL, "
		Next lintAux
		For lintAux = 0 To 72
			lstrSql = lstrSql & "`fat_" & VB6.Format(lintAux, "00") & "`                 decimal(14,2) default NULL, "
		Next lintAux
		For lintAux = 0 To 72
			lstrSql = lstrSql & "`abe_" & VB6.Format(lintAux, "00") & "`                 decimal(14,2) default NULL, "
		Next lintAux
		lstrSql = VB.Left(lstrSql, Len(lstrSql) - 2) & ")"
		Call Executar(lstrSql)
	End Sub
	
	'UPGRADE_WARNING: Event opbXML.CheckedChanged 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 opbXML_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbXML.CheckedChanged
		If eventSender.Checked Then
			Call NomeArquivoXML()
		End If
	End Sub
	
	'UPGRADE_WARNING: Event txtVersao.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"'
	Private Sub txtVersao_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtVersao.TextChanged
		If Me.opbXML.Checked Then
			Call NomeArquivoXML()
		End If
	End Sub
	
	Private Sub Fatur()
		
		Dim ldblNumNf As Double
		Dim lstrMesAno As String
		Dim llngMesano As Integer
		
		Dim ldblVlrFat As Double
		Dim ldblVlrLiq As Double
		Dim llngCdClas As Integer
		Dim lstrFlgSit As String
		Dim ldteFlgSit As Date
		Dim ldtePagto As Date
		Dim lintAux As Decimal
		Dim ldteAux As Date
		Dim ldteBas As Date
		Dim ldteBasIni As Date
		Dim lstrMes As String
		Dim lblnAux As Boolean
		Dim lblnCon As Boolean
		
		Dim MResidencial As Double
		Dim MResidencial_Outros As Double
		Dim MIndustrial As Double
		Dim MComercial As Double
		Dim MRural As Double
		Dim MPoder_Publico As Double
		Dim MIluminacao_Publica As Double
		Dim MServico_Publico As Double
		Dim MOutros As Double
		Dim MTotData As Short
		
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Dim lrstAux1 As ADODB.Recordset
		lrstAux1 = New ADODB.Recordset
		Me.lblInfo.Text = " Buscando os dados por dia aguarde..."
		Call Me.lblInfo.Refresh()
		lblnAux = True
		ldteBas = CDate(VB6.Format(Me.dtpDiaMesAno.value, "dd/mm/yyyy"))
		ldteBasIni = CDate(VB6.Format(Me.dtpDiaMesAnoInicial.value, "dd/mm/yyyy"))
		MTotData = ldteBas.ToOADate - ldteBasIni.ToOADate
		
		For lintAux = 0 To MTotData
			
			ilngPerAno(lintAux + 1) = CInt(VB6.Format(DateAdd(Microsoft.VisualBasic.DateInterval.Day, IIf(lintAux = 0, 0, lintAux * -1), ldteBas), "yyyymmdd"))
			
			Me.mfgFaturado.set_TextMatrix(0, lintAux, Mid(CStr(ilngPerAno(lintAux + 1)), 1, 4) & "-" & Mid(CStr(ilngPerAno(lintAux + 1)), 5, 2) & "-" & Mid(CStr(ilngPerAno(lintAux + 1)), 7, 2))
			Me.mfgAberto.set_TextMatrix(0, lintAux, Mid(CStr(ilngPerAno(lintAux + 1)), 1, 4) & "-" & Mid(CStr(ilngPerAno(lintAux + 1)), 5, 2) & "-" & Mid(CStr(ilngPerAno(lintAux + 1)), 7, 2))
			'UPGRADE_NOTE: Refresh was upgraded to CtlRefresh. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
			Call Me.mfgFaturado.CtlRefresh()
			'UPGRADE_NOTE: Refresh was upgraded to CtlRefresh. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
			Call Me.mfgAberto.CtlRefresh()
			System.Windows.Forms.Application.DoEvents()
		Next lintAux
		System.Windows.Forms.Application.DoEvents()
		
		Call myConC.Execute("DELETE FROM `inadimplentes_Fatur`;")
		
		For lintAux = 0 To MTotData
			
			Me.lblInfo1.Text = " Buscando os dados de fatur. dia " & VB6.Format(Me.mfgFaturado.get_TextMatrix(0, lintAux), "dd/mm/yyyy")
			
			If lblnAux Then
				
				lstrSql = ""
				lstrSql = lstrSql & "SELECT numnf, mesano, mesano_ref, ta, zona, livro, conta, cons_id, unid_id, grupo, valortot, valorliq, codclas, flgst, datast, datapag " & vbCrLf
				lstrSql = lstrSql & "  FROM nf " & vbCrLf
				lstrSql = lstrSql & " WHERE datavenc = '" & Me.mfgFaturado.get_TextMatrix(0, lintAux) & "'"
				Call Conectar(lstrSql, lrstAux)
				With lrstAux
					If .State = ADODB.ObjectStateEnum.adStateOpen Then
						If .RecordCount > 0 Then
							Call BarraProgresso(Me.ProgressBar(1), Me.lblPerc(1), (Me.lblInfo), 0, .RecordCount)
							While Not .EOF
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								'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"'
								ldblVlrFat = CDbl(IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								'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"'
								llngCdClas = CInt(IIf(IsDbNull(.Fields("codclas").value), 0, .Fields("codclas").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								'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"'
								lstrFlgSit = Trim(IIf(IsDbNull(.Fields("flgst").value), "", .Fields("flgst").value))
								lblnCon = True
								
								If lblnCon Then
									'Faturado
									If lstrFlgSit <> "C" Then
										
										lstrSql = ""
										lstrSql = lstrSql & "SELECT * FROM inadimplentes_Fatur " & vbCrLf
										lstrSql = lstrSql & " WHERE Data = '" & VB6.Format(Me.mfgFaturado.get_TextMatrix(0, lintAux), "dd/mm/yyyy") & "'"
										Call Conectar(lstrSql, lrstAux1)
										With lrstAux1
											If .State = ADODB.ObjectStateEnum.adStateOpen Then
												If .RecordCount > 0 Then
													
													'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
													'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"'
													MResidencial = CDbl(IIf(IsDbNull(.Fields("Residencial_fatu").value), 0, .Fields("Residencial_fatu").value))
													'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
													'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"'
													MResidencial_Outros = CDbl(IIf(IsDbNull(.Fields("Residencial_Outros_fatu").value), 0, .Fields("Residencial_Outros_fatu").value))
													'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
													'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"'
													MIndustrial = CDbl(IIf(IsDbNull(.Fields("Industrial_fatu").value), 0, .Fields("Industrial_fatu").value))
													'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
													'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"'
													MComercial = CDbl(IIf(IsDbNull(.Fields("Comercial_fatu").value), 0, .Fields("Comercial_fatu").value))
													'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
													'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"'
													MRural = CDbl(IIf(IsDbNull(.Fields("Rural_fatu").value), 0, .Fields("Rural_fatu").value))
													'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
													'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"'
													MPoder_Publico = CDbl(IIf(IsDbNull(.Fields("Poder_Publico_fatu").value), 0, .Fields("Poder_Publico_fatu").value))
													'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
													'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"'
													MIluminacao_Publica = CDbl(IIf(IsDbNull(.Fields("Iluminacao_Publica_fatu").value), 0, .Fields("Iluminacao_Publica_fatu").value))
													'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
													'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"'
													MServico_Publico = CDbl(IIf(IsDbNull(.Fields("Servico_Publico_fatu").value), 0, .Fields("Servico_Publico_fatu").value))
													'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
													'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"'
													MOutros = CDbl(IIf(IsDbNull(.Fields("Outros_fatu").value), 0, .Fields("Outros_fatu").value))
													
													If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 Then
														MResidencial = MResidencial + ldblVlrFat
													End If
													If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 And llngCdClas <> 9101 Then
														MResidencial_Outros = MResidencial_Outros + ldblVlrFat
													ElseIf llngCdClas <= 3999 Then 
														MIndustrial = MIndustrial + ldblVlrFat
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 4 Then 
														MComercial = MComercial + ldblVlrFat
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 5 Then 
														MRural = MRural + ldblVlrFat
													ElseIf llngCdClas >= 6100 And llngCdClas <= 6399 Then 
														MPoder_Publico = MPoder_Publico + ldblVlrFat
													ElseIf llngCdClas >= 6400 And llngCdClas <= 6499 Then 
														MIluminacao_Publica = MIluminacao_Publica + ldblVlrFat
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 7 Then 
														MServico_Publico = MServico_Publico + ldblVlrFat
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 8 Then 
														MOutros = MOutros + ldblVlrFat
													End If
													
													lstrSql = ""
													lstrSql = lstrSql & "UPDATE `inadimplentes_Fatur` "
													If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 Then
														lstrSql = lstrSql & " SET `Residencial_fatu` = '" & Replace(CStr(MResidencial), ",", ".") & "'"
													End If
													If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 And llngCdClas <> 9101 Then
														lstrSql = lstrSql & " , `Residencial_Outros_fatu` = '" & Replace(CStr(MResidencial_Outros), ",", ".") & "'"
													ElseIf llngCdClas <= 3999 Then 
														lstrSql = lstrSql & " SET `Industrial_fatu` = '" & Replace(CStr(MIndustrial), ",", ".") & "'"
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 4 Then 
														lstrSql = lstrSql & " SET `Comercial_fatu` = '" & Replace(CStr(MComercial), ",", ".") & "'"
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 5 Then 
														lstrSql = lstrSql & " SET `Rural_fatu` = '" & Replace(CStr(MRural), ",", ".") & "'"
													ElseIf llngCdClas >= 6100 And llngCdClas <= 6399 Then 
														lstrSql = lstrSql & " SET `Poder_Publico_fatu` = '" & Replace(CStr(MPoder_Publico), ",", ".") & "'"
													ElseIf llngCdClas >= 6400 And llngCdClas <= 6499 Then 
														lstrSql = lstrSql & " SET `Iluminacao_Publica_fatu` = '" & Replace(CStr(MIluminacao_Publica), ",", ".") & "'"
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 7 Then 
														lstrSql = lstrSql & " SET `Servico_Publico_fatu` = '" & Replace(CStr(MServico_Publico), ",", ".") & "'"
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 8 Then 
														lstrSql = lstrSql & " SET `Outros_fatu` = '" & Replace(CStr(MOutros), ",", ".") & "'"
													End If
													lstrSql = lstrSql & " WHERE Data = '" & VB6.Format(Me.mfgFaturado.get_TextMatrix(0, lintAux), "dd/mm/yyyy") & "'"
													Call myConC.Execute(lstrSql)
													
												Else
													
													lstrSql = ""
													lstrSql = "INSERT INTO `inadimplentes_Fatur` SET "
													lstrSql = lstrSql & " `Data` = '" & VB6.Format(Me.mfgFaturado.get_TextMatrix(0, lintAux), "dd/mm/yyyy") & "'"
													
													If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 Then
														lstrSql = lstrSql & " ,`Residencial_fatu` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
													End If
													If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 And llngCdClas <> 9101 Then
														lstrSql = lstrSql & " ,`Residencial_Outros_fatu` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
													ElseIf llngCdClas <= 3999 Then 
														lstrSql = lstrSql & " ,`Industrial_fatu` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 4 Then 
														lstrSql = lstrSql & " ,`Comercial_fatu` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 5 Then 
														lstrSql = lstrSql & " ,`Rural_fatu` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
													ElseIf llngCdClas >= 6100 And llngCdClas <= 6399 Then 
														lstrSql = lstrSql & " ,`Poder_Publico_fatu` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
													ElseIf llngCdClas >= 6400 And llngCdClas <= 6499 Then 
														lstrSql = lstrSql & " ,`Iluminacao_Publica_fatu` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 7 Then 
														lstrSql = lstrSql & " ,`Servico_Publico_fatu` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 8 Then 
														lstrSql = lstrSql & " ,`Outros_fatu` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
													End If
													Call myConC.Execute(lstrSql)
												End If
											End If
											Call .Close()
										End With
										
									End If
									'Aberto
									'If (ldtePagto = Conversion.CDate("01/01/1900") Or ldtePagto > ldteBas) And (lstrFlgSit <> "C" Or (lstrFlgSit = "C" And ldteFlgSit > ldteAux)) Then
									' Call AdicionaGrade(1, lstrMesAno, llngCdClas, ldblVlrFat, 0)
									'End If
								End If
								Call .MoveNext()
								Call BarraProgresso(Me.ProgressBar(1), Me.lblPerc(1), (Me.lblInfo), 1,  , " " & lstrMesAno & " ")
							End While
						Else
							
							lstrSql = ""
							lstrSql = "INSERT INTO `inadimplentes_Fatur` SET "
							lstrSql = lstrSql & " `Data` = '" & VB6.Format(Me.mfgFaturado.get_TextMatrix(0, lintAux), "dd/mm/yyyy") & "'"
							
							lstrSql = lstrSql & " ,`Residencial_fatu` = 0"
							lstrSql = lstrSql & " ,`Residencial_Outros_fatu` = 0"
							lstrSql = lstrSql & " ,`Industrial_fatu` = 0"
							lstrSql = lstrSql & " ,`Comercial_fatu` = 0"
							lstrSql = lstrSql & " ,`Rural_fatu` = 0"
							lstrSql = lstrSql & " ,`Poder_Publico_fatu` = 0"
							lstrSql = lstrSql & " ,`Iluminacao_Publica_fatu` = 0"
							lstrSql = lstrSql & " ,`Servico_Publico_fatu` = 0"
							lstrSql = lstrSql & " ,`Outros_fatu` = 0"
							Call myConC.Execute(lstrSql)
							
						End If
						Call .Close()
					End If
				End With
			End If
		Next lintAux
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Sub
	
	Private Sub Arrec()
		
		Dim ldblNumNf As Double
		Dim lstrMesAno As String
		Dim llngMesano As Integer
		
		Dim ldblVlrFat As Double
		Dim ldblVlrLiq As Double
		Dim llngCdClas As Integer
		Dim lstrFlgSit As String
		Dim ldteFlgSit As Date
		Dim ldtePagto As Date
		Dim lintAux As Decimal
		Dim ldteAux As Date
		Dim ldteBas As Date
		Dim ldteBasIni As Date
		Dim lstrMes As String
		Dim lblnAux As Boolean
		Dim lblnCon As Boolean
		
		Dim MResidencial As Double
		Dim MResidencial_Outros As Double
		Dim MIndustrial As Double
		Dim MComercial As Double
		Dim MRural As Double
		Dim MPoder_Publico As Double
		Dim MIluminacao_Publica As Double
		Dim MServico_Publico As Double
		Dim MOutros As Double
		Dim MTotData As Short
		
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Dim lrstAux1 As ADODB.Recordset
		lrstAux1 = New ADODB.Recordset
		Me.lblInfo.Text = " Buscando os dados por dia aguarde..."
		Call Me.lblInfo.Refresh()
		lblnAux = True
		ldteBas = CDate(VB6.Format(Me.dtpDiaMesAno.value, "dd/mm/yyyy"))
		ldteBasIni = CDate(VB6.Format(Me.dtpDiaMesAnoInicial.value, "dd/mm/yyyy"))
		MTotData = ldteBas.ToOADate - ldteBasIni.ToOADate
		
		For lintAux = 0 To MTotData
			
			ilngPerAno(lintAux + 1) = CInt(VB6.Format(DateAdd(Microsoft.VisualBasic.DateInterval.Day, IIf(lintAux = 0, 0, lintAux * -1), ldteBas), "yyyymmdd"))
			
			Me.mfgFaturado.set_TextMatrix(0, lintAux, Mid(CStr(ilngPerAno(lintAux + 1)), 1, 4) & "-" & Mid(CStr(ilngPerAno(lintAux + 1)), 5, 2) & "-" & Mid(CStr(ilngPerAno(lintAux + 1)), 7, 2))
			Me.mfgAberto.set_TextMatrix(0, lintAux, Mid(CStr(ilngPerAno(lintAux + 1)), 1, 4) & "-" & Mid(CStr(ilngPerAno(lintAux + 1)), 5, 2) & "-" & Mid(CStr(ilngPerAno(lintAux + 1)), 7, 2))
			'UPGRADE_NOTE: Refresh was upgraded to CtlRefresh. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
			Call Me.mfgFaturado.CtlRefresh()
			'UPGRADE_NOTE: Refresh was upgraded to CtlRefresh. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
			Call Me.mfgAberto.CtlRefresh()
			System.Windows.Forms.Application.DoEvents()
		Next lintAux
		System.Windows.Forms.Application.DoEvents()
		
		For lintAux = 0 To MTotData
			
			Me.lblInfo1.Text = " Buscando os dados de Arrec. dia " & VB6.Format(Me.mfgFaturado.get_TextMatrix(0, lintAux), "dd/mm/yyyy")
			
			If lblnAux Then
				
				lstrSql = ""
				lstrSql = lstrSql & "SELECT numnf, mesano, mesano_ref, ta, zona, livro, conta, cons_id, unid_id, grupo, valortot, valorliq, codclas, flgst, datast, datapag " & vbCrLf
				lstrSql = lstrSql & "  FROM nf " & vbCrLf
				lstrSql = lstrSql & " WHERE datapag = '" & Me.mfgFaturado.get_TextMatrix(0, lintAux) & "'"
				Call Conectar(lstrSql, lrstAux)
				With lrstAux
					If .State = ADODB.ObjectStateEnum.adStateOpen Then
						If .RecordCount > 0 Then
							Call BarraProgresso(Me.ProgressBar(1), Me.lblPerc(1), (Me.lblInfo), 0, .RecordCount)
							While Not .EOF
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								'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"'
								ldblVlrFat = CDbl(IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								'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"'
								llngCdClas = CInt(IIf(IsDbNull(.Fields("codclas").value), 0, .Fields("codclas").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								'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"'
								lstrFlgSit = Trim(IIf(IsDbNull(.Fields("flgst").value), "", .Fields("flgst").value))
								lblnCon = True
								
								If lblnCon Then
									'Faturado
									If lstrFlgSit = "P" Then
										
										lstrSql = ""
										lstrSql = lstrSql & "SELECT * FROM inadimplentes_Fatur " & vbCrLf
										lstrSql = lstrSql & " WHERE Data = '" & VB6.Format(Me.mfgFaturado.get_TextMatrix(0, lintAux), "dd/mm/yyyy") & "'"
										Call Conectar(lstrSql, lrstAux1)
										With lrstAux1
											If .State = ADODB.ObjectStateEnum.adStateOpen Then
												If .RecordCount > 0 Then
													
													'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
													'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"'
													MResidencial = CDbl(IIf(IsDbNull(.Fields("Residencial_arre").value), 0, .Fields("Residencial_arre").value))
													'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
													'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"'
													MResidencial_Outros = CDbl(IIf(IsDbNull(.Fields("Residencial_Outros_arre").value), 0, .Fields("Residencial_Outros_arre").value))
													'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
													'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"'
													MIndustrial = CDbl(IIf(IsDbNull(.Fields("Industrial_arre").value), 0, .Fields("Industrial_arre").value))
													'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
													'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"'
													MComercial = CDbl(IIf(IsDbNull(.Fields("Comercial_arre").value), 0, .Fields("Comercial_arre").value))
													'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
													'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"'
													MRural = CDbl(IIf(IsDbNull(.Fields("Rural_arre").value), 0, .Fields("Rural_arre").value))
													'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
													'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"'
													MPoder_Publico = CDbl(IIf(IsDbNull(.Fields("Poder_Publico_arre").value), 0, .Fields("Poder_Publico_arre").value))
													'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
													'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"'
													MIluminacao_Publica = CDbl(IIf(IsDbNull(.Fields("Iluminacao_Publica_arre").value), 0, .Fields("Iluminacao_Publica_arre").value))
													'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
													'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"'
													MServico_Publico = CDbl(IIf(IsDbNull(.Fields("Servico_Publico_arre").value), 0, .Fields("Servico_Publico_arre").value))
													'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
													'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"'
													MOutros = CDbl(IIf(IsDbNull(.Fields("Outros_arre").value), 0, .Fields("Outros_arre").value))
													
													If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 Then
														MResidencial = MResidencial + ldblVlrFat
													End If
													If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 And llngCdClas <> 9101 Then
														MResidencial_Outros = MResidencial_Outros + ldblVlrFat
													ElseIf llngCdClas <= 3999 Then 
														MIndustrial = MIndustrial + ldblVlrFat
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 4 Then 
														MComercial = MComercial + ldblVlrFat
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 5 Then 
														MRural = MRural + ldblVlrFat
													ElseIf llngCdClas >= 6100 And llngCdClas <= 6399 Then 
														MPoder_Publico = MPoder_Publico + ldblVlrFat
													ElseIf llngCdClas >= 6400 And llngCdClas <= 6499 Then 
														MIluminacao_Publica = MIluminacao_Publica + ldblVlrFat
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 7 Then 
														MServico_Publico = MServico_Publico + ldblVlrFat
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 8 Then 
														MOutros = MOutros + ldblVlrFat
													End If
													
													lstrSql = ""
													lstrSql = lstrSql & "UPDATE `inadimplentes_Fatur` "
													If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 Then
														lstrSql = lstrSql & " SET `Residencial_arre` = '" & Replace(CStr(MResidencial), ",", ".") & "'"
													End If
													If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 And llngCdClas <> 9101 Then
														lstrSql = lstrSql & " ,`Residencial_Outros_arre` = '" & Replace(CStr(MResidencial_Outros), ",", ".") & "'"
													ElseIf llngCdClas <= 3999 Then 
														lstrSql = lstrSql & " SET `Industrial_arre` = '" & Replace(CStr(MIndustrial), ",", ".") & "'"
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 4 Then 
														lstrSql = lstrSql & " SET `Comercial_arre` = '" & Replace(CStr(MComercial), ",", ".") & "'"
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 5 Then 
														lstrSql = lstrSql & " SET `Rural_arre` = '" & Replace(CStr(MRural), ",", ".") & "'"
													ElseIf llngCdClas >= 6100 And llngCdClas <= 6399 Then 
														lstrSql = lstrSql & " SET `Poder_Publico_arre` = '" & Replace(CStr(MPoder_Publico), ",", ".") & "'"
													ElseIf llngCdClas >= 6400 And llngCdClas <= 6499 Then 
														lstrSql = lstrSql & " SET `Iluminacao_Publica_arre` = '" & Replace(CStr(MIluminacao_Publica), ",", ".") & "'"
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 7 Then 
														lstrSql = lstrSql & " SET `Servico_Publico_arre` = '" & Replace(CStr(MServico_Publico), ",", ".") & "'"
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 8 Then 
														lstrSql = lstrSql & " SET `Outros_arre` = '" & Replace(CStr(MOutros), ",", ".") & "'"
													End If
													lstrSql = lstrSql & " WHERE Data = '" & VB6.Format(Me.mfgFaturado.get_TextMatrix(0, lintAux), "dd/mm/yyyy") & "'"
													Call myConC.Execute(lstrSql)
													
												Else
													
													lstrSql = ""
													lstrSql = "INSERT INTO `inadimplentes_Fatur` SET "
													lstrSql = lstrSql & " `Data` = '" & VB6.Format(Me.mfgFaturado.get_TextMatrix(0, lintAux), "dd/mm/yyyy") & "'"
													
													If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 Then
														lstrSql = lstrSql & " ,`Residencial_arre` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
													End If
													If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 And llngCdClas <> 9101 Then
														lstrSql = lstrSql & " ,`Residencial_Outros_arre` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
													ElseIf llngCdClas <= 3999 Then 
														lstrSql = lstrSql & " ,`Industrial_arre` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 4 Then 
														lstrSql = lstrSql & " ,`Comercial_arre` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 5 Then 
														lstrSql = lstrSql & " ,`Rural_arre` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
													ElseIf llngCdClas >= 6100 And llngCdClas <= 6399 Then 
														lstrSql = lstrSql & " ,`Poder_Publico_arre` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
													ElseIf llngCdClas >= 6400 And llngCdClas <= 6499 Then 
														lstrSql = lstrSql & " ,`Iluminacao_Publica_arre` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 7 Then 
														lstrSql = lstrSql & " ,`Servico_Publico_arre` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
													ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 8 Then 
														lstrSql = lstrSql & " ,`Outros_arre` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
													End If
													Call myConC.Execute(lstrSql)
												End If
											End If
											Call .Close()
										End With
										
									End If
									'Aberto
									'If (ldtePagto = Conversion.CDate("01/01/1900") Or ldtePagto > ldteBas) And (lstrFlgSit <> "C" Or (lstrFlgSit = "C" And ldteFlgSit > ldteAux)) Then
									' Call AdicionaGrade(1, lstrMesAno, llngCdClas, ldblVlrFat, 0)
									'End If
								End If
								Call .MoveNext()
								Call BarraProgresso(Me.ProgressBar(1), Me.lblPerc(1), (Me.lblInfo), 1,  , " " & lstrMesAno & " ")
							End While
						Else
							
							lstrSql = ""
							lstrSql = lstrSql & "UPDATE `inadimplentes_Fatur` "
							lstrSql = lstrSql & " SET `Residencial_arre` = 0,"
							lstrSql = lstrSql & " `Residencial_Outros_arre` = 0,"
							lstrSql = lstrSql & " `Industrial_arre` = 0,"
							lstrSql = lstrSql & " `Comercial_arre` = 0,"
							lstrSql = lstrSql & " `Rural_arre` = 0,"
							lstrSql = lstrSql & " `Poder_Publico_arre` = 0,"
							lstrSql = lstrSql & " `Iluminacao_Publica_arre` = 0,"
							lstrSql = lstrSql & " `Servico_Publico_arre` = 0,"
							lstrSql = lstrSql & " `Outros_arre` = 0"
							lstrSql = lstrSql & " WHERE Data = '" & VB6.Format(Me.mfgFaturado.get_TextMatrix(0, lintAux), "dd/mm/yyyy") & "'"
							Call myConC.Execute(lstrSql)
							
						End If
						Call .Close()
					End If
				End With
			End If
		Next lintAux
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Sub
	
	Private Sub ArrecMes()
		
		Dim ldblNumNf As Double
		Dim lstrMesAno As String
		Dim llngMesano As Integer
		
		Dim ldblVlrFat As Double
		Dim ldblVlrLiq As Double
		Dim llngCdClas As Integer
		Dim lstrFlgSit As String
		Dim ldteFlgSit As Date
		Dim ldtePagto As Date
		Dim lintAux As Decimal
		Dim ldteAux As Date
		Dim ldteBas As Date
		Dim ldteBasIni As Date
		Dim lstrMes As String
		Dim lblnAux As Boolean
		Dim lblnCon As Boolean
		
		Dim MResidencial As Double
		Dim MResidencial_Outros As Double
		Dim MIndustrial As Double
		Dim MComercial As Double
		Dim MRural As Double
		Dim MPoder_Publico As Double
		Dim MIluminacao_Publica As Double
		Dim MServico_Publico As Double
		Dim MOutros As Double
		Dim MTotData As Short
		
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Dim lrstAux1 As ADODB.Recordset
		lrstAux1 = New ADODB.Recordset
		Me.lblInfo.Text = " Buscando os dados por Mês aguarde..."
		Call Me.lblInfo.Refresh()
		lblnAux = True
		ldteBas = CDate(VB6.Format(Me.dtpMesAno.value, "mm/yyyy"))
		ldteBasIni = CDate(VB6.Format(Me.dtpMesAnoInicial.value, "mm/yyyy"))
		MTotData = DateDiff(Microsoft.VisualBasic.DateInterval.Month, ldteBasIni, ldteBas) + 1
		
		For lintAux = 0 To MTotData
			
			ilngPerAno(lintAux + 1) = CInt(VB6.Format(DateAdd(Microsoft.VisualBasic.DateInterval.Month, IIf(lintAux = 0, 0, lintAux * -1), ldteBas), "yyyymm"))
			Me.mfgFaturado.set_TextMatrix(0, lintAux, VB.Right(CStr(ilngPerAno(lintAux + 1)), 2) & "/" & VB.Left(CStr(ilngPerAno(lintAux + 1)), 4))
			Me.mfgAberto.set_TextMatrix(0, lintAux, VB.Right(CStr(ilngPerAno(lintAux + 1)), 2) & "/" & VB.Left(CStr(ilngPerAno(lintAux + 1)), 4))
			'UPGRADE_NOTE: Refresh was upgraded to CtlRefresh. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
			Call Me.mfgFaturado.CtlRefresh()
			'UPGRADE_NOTE: Refresh was upgraded to CtlRefresh. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
			Call Me.mfgAberto.CtlRefresh()
			System.Windows.Forms.Application.DoEvents()
		Next lintAux
		System.Windows.Forms.Application.DoEvents()
		
		For lintAux = 0 To MTotData
			
			Me.lblInfo1.Text = " Buscando os dados de Arrec. Mês " & VB6.Format(Me.mfgFaturado.get_TextMatrix(0, lintAux), "mm/yyyy")
			
			If lblnAux Then
				
				lstrSql = ""
				lstrSql = lstrSql & "SELECT numnf, mesano, mesano_ref, ta, zona, livro, conta, cons_id, unid_id, grupo, valortot, valorliq, codclas, flgst, datast, datapag " & vbCrLf
				lstrSql = lstrSql & "  FROM nf " & vbCrLf
				lstrSql = lstrSql & " WHERE datapag between '" & Mid(Me.mfgFaturado.get_TextMatrix(0, lintAux), 4, 4) & "-" & Mid(Me.mfgFaturado.get_TextMatrix(0, lintAux), 1, 2) & "-01" & "'  and '" & Mid(Me.mfgFaturado.get_TextMatrix(0, lintAux), 4, 4) & "-" & Mid(Me.mfgFaturado.get_TextMatrix(0, lintAux), 1, 2) & "-31'"
				Call Conectar(lstrSql, lrstAux)
				With lrstAux
					If .State = ADODB.ObjectStateEnum.adStateOpen Then
						If .RecordCount > 0 Then
							Call BarraProgresso(Me.ProgressBar(1), Me.lblPerc(1), (Me.lblInfo), 0, .RecordCount)
							While Not .EOF
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								'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"'
								ldblVlrFat = CDbl(IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								'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"'
								llngCdClas = CInt(IIf(IsDbNull(.Fields("codclas").value), 0, .Fields("codclas").value))
								lblnCon = True
								
								If lblnCon Then
									'Faturado
									''If lstrFlgSit = "P" Then
									
									lstrSql = ""
									lstrSql = lstrSql & "SELECT * FROM inadimplentes_Fatur " & vbCrLf
									lstrSql = lstrSql & " WHERE Data = '" & VB6.Format(Me.mfgFaturado.get_TextMatrix(0, lintAux), "mm/yyyy") & "'"
									Call Conectar(lstrSql, lrstAux1)
									With lrstAux1
										If .State = ADODB.ObjectStateEnum.adStateOpen Then
											If .RecordCount > 0 Then
												
												'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
												'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"'
												MResidencial = CDbl(IIf(IsDbNull(.Fields("Residencial_arre").value), 0, .Fields("Residencial_arre").value))
												'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
												'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"'
												MResidencial_Outros = CDbl(IIf(IsDbNull(.Fields("Residencial_Outros_arre").value), 0, .Fields("Residencial_Outros_arre").value))
												'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
												'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"'
												MIndustrial = CDbl(IIf(IsDbNull(.Fields("Industrial_arre").value), 0, .Fields("Industrial_arre").value))
												'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
												'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"'
												MComercial = CDbl(IIf(IsDbNull(.Fields("Comercial_arre").value), 0, .Fields("Comercial_arre").value))
												'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
												'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"'
												MRural = CDbl(IIf(IsDbNull(.Fields("Rural_arre").value), 0, .Fields("Rural_arre").value))
												'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
												'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"'
												MPoder_Publico = CDbl(IIf(IsDbNull(.Fields("Poder_Publico_arre").value), 0, .Fields("Poder_Publico_arre").value))
												'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
												'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"'
												MIluminacao_Publica = CDbl(IIf(IsDbNull(.Fields("Iluminacao_Publica_arre").value), 0, .Fields("Iluminacao_Publica_arre").value))
												'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
												'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"'
												MServico_Publico = CDbl(IIf(IsDbNull(.Fields("Servico_Publico_arre").value), 0, .Fields("Servico_Publico_arre").value))
												'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
												'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"'
												MOutros = CDbl(IIf(IsDbNull(.Fields("Outros_arre").value), 0, .Fields("Outros_arre").value))
												
												If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 Then
													MResidencial = MResidencial + ldblVlrFat
												End If
												If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 And llngCdClas <> 9101 Then
													MResidencial_Outros = MResidencial_Outros + ldblVlrFat
												ElseIf llngCdClas <= 3999 Then 
													MIndustrial = MIndustrial + ldblVlrFat
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 4 Then 
													MComercial = MComercial + ldblVlrFat
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 5 Then 
													MRural = MRural + ldblVlrFat
												ElseIf llngCdClas >= 6100 And llngCdClas <= 6399 Then 
													MPoder_Publico = MPoder_Publico + ldblVlrFat
												ElseIf llngCdClas >= 6400 And llngCdClas <= 6499 Then 
													MIluminacao_Publica = MIluminacao_Publica + ldblVlrFat
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 7 Then 
													MServico_Publico = MServico_Publico + ldblVlrFat
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 8 Then 
													MOutros = MOutros + ldblVlrFat
												End If
												
												lstrSql = ""
												lstrSql = lstrSql & "UPDATE `inadimplentes_Fatur` "
												If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 Then
													lstrSql = lstrSql & " SET `Residencial_arre` = '" & Replace(CStr(MResidencial), ",", ".") & "'"
												End If
												If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 And llngCdClas <> 9101 Then
													lstrSql = lstrSql & " , `Residencial_Outros_arre` = '" & Replace(CStr(MResidencial_Outros), ",", ".") & "'"
												ElseIf llngCdClas <= 3999 Then 
													lstrSql = lstrSql & " SET `Industrial_arre` = '" & Replace(CStr(MIndustrial), ",", ".") & "'"
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 4 Then 
													lstrSql = lstrSql & " SET `Comercial_arre` = '" & Replace(CStr(MComercial), ",", ".") & "'"
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 5 Then 
													lstrSql = lstrSql & " SET `Rural_arre` = '" & Replace(CStr(MRural), ",", ".") & "'"
												ElseIf llngCdClas >= 6100 And llngCdClas <= 6399 Then 
													lstrSql = lstrSql & " SET `Poder_Publico_arre` = '" & Replace(CStr(MPoder_Publico), ",", ".") & "'"
												ElseIf llngCdClas >= 6400 And llngCdClas <= 6499 Then 
													lstrSql = lstrSql & " SET `Iluminacao_Publica_arre` = '" & Replace(CStr(MIluminacao_Publica), ",", ".") & "'"
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 7 Then 
													lstrSql = lstrSql & " SET `Servico_Publico_arre` = '" & Replace(CStr(MServico_Publico), ",", ".") & "'"
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 8 Then 
													lstrSql = lstrSql & " SET `Outros_arre` = '" & Replace(CStr(MOutros), ",", ".") & "'"
												End If
												lstrSql = lstrSql & " WHERE Data = '" & VB6.Format(Me.mfgFaturado.get_TextMatrix(0, lintAux), "mm/yyyy") & "'"
												Call myConC.Execute(lstrSql)
												
											Else
												
												lstrSql = ""
												lstrSql = "INSERT INTO `inadimplentes_Fatur` SET "
												lstrSql = lstrSql & " `Data` = '" & VB6.Format(Me.mfgFaturado.get_TextMatrix(0, lintAux), "mm/yyyy") & "'"
												
												If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 Then
													lstrSql = lstrSql & " ,`Residencial_arre` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
												End If
												If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 And llngCdClas <> 9101 Then
													lstrSql = lstrSql & " ,`Residencial_Outros_arre` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
												ElseIf llngCdClas <= 3999 Then 
													lstrSql = lstrSql & " ,`Industrial_arre` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 4 Then 
													lstrSql = lstrSql & " ,`Comercial_arre` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 5 Then 
													lstrSql = lstrSql & " ,`Rural_arre` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
												ElseIf llngCdClas >= 6100 And llngCdClas <= 6399 Then 
													lstrSql = lstrSql & " ,`Poder_Publico_arre` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
												ElseIf llngCdClas >= 6400 And llngCdClas <= 6499 Then 
													lstrSql = lstrSql & " ,`Iluminacao_Publica_arre` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 7 Then 
													lstrSql = lstrSql & " ,`Servico_Publico_arre` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 8 Then 
													lstrSql = lstrSql & " ,`Outros_arre` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
												End If
												Call myConC.Execute(lstrSql)
											End If
										End If
										Call .Close()
									End With
									
									''End If
									'Aberto
									'If (ldtePagto = Conversion.CDate("01/01/1900") Or ldtePagto > ldteBas) And (lstrFlgSit <> "C" Or (lstrFlgSit = "C" And ldteFlgSit > ldteAux)) Then
									' Call AdicionaGrade(1, lstrMesAno, llngCdClas, ldblVlrFat, 0)
									'End If
								End If
								Call .MoveNext()
								Call BarraProgresso(Me.ProgressBar(1), Me.lblPerc(1), (Me.lblInfo), 1,  , " " & lstrMesAno & " ")
							End While
						Else
							
							lstrSql = ""
							lstrSql = "INSERT INTO `inadimplentes_Fatur` SET "
							lstrSql = lstrSql & " `Data` = '" & VB6.Format(Me.mfgFaturado.get_TextMatrix(0, lintAux), "mm/yyyy") & "'"
							
							lstrSql = lstrSql & " ,`Residencial_arre` = 0"
							lstrSql = lstrSql & " ,`Residencial_Outros_arre` = 0"
							lstrSql = lstrSql & " ,`Industrial_arre` = 0"
							lstrSql = lstrSql & " ,`Comercial_arre` = 0"
							lstrSql = lstrSql & " ,`Rural_arre` = 0"
							lstrSql = lstrSql & " ,`Poder_Publico_arre` = 0"
							lstrSql = lstrSql & " ,`Iluminacao_Publica_arre` = 0"
							lstrSql = lstrSql & " ,`Servico_Publico_arre` = 0"
							lstrSql = lstrSql & " ,`Outros_arre` = 0"
							Call myConC.Execute(lstrSql)
							
						End If
						Call .Close()
					End If
				End With
			End If
		Next lintAux
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Sub
	
	Private Sub FaturMes()
		
		Dim ldblNumNf As Double
		Dim lstrMesAno As String
		Dim llngMesano As Integer
		
		Dim ldblVlrFat As Double
		Dim ldblVlrLiq As Double
		Dim llngCdClas As Integer
		Dim lstrFlgSit As String
		Dim ldteFlgSit As Date
		Dim ldtePagto As Date
		Dim lintAux As Decimal
		Dim ldteAux As Date
		Dim ldteBas As Date
		Dim ldteBas1 As Date
		Dim ldteBasIni As Date
		Dim lstrMes As String
		Dim lblnAux As Boolean
		Dim lblnCon As Boolean
		
		Dim MResidencial As Double
		Dim MResidencial_Outros As Double
		Dim MIndustrial As Double
		Dim MComercial As Double
		Dim MRural As Double
		Dim MPoder_Publico As Double
		Dim MIluminacao_Publica As Double
		Dim MServico_Publico As Double
		Dim MOutros As Double
		Dim MTotData As Short
		
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Dim lrstAux1 As ADODB.Recordset
		lrstAux1 = New ADODB.Recordset
		Me.lblInfo.Text = " Buscando os dados por Mês aguarde..."
		Call Me.lblInfo.Refresh()
		lblnAux = True
		ldteBas = CDate(VB6.Format(Me.dtpMesAno.value, "mm/yyyy"))
		ldteBasIni = CDate(VB6.Format(Me.dtpMesAnoInicial.value, "mm/yyyy"))
		MTotData = DateDiff(Microsoft.VisualBasic.DateInterval.Month, ldteBasIni, ldteBas) + 1
		
		For lintAux = 0 To MTotData
			
			ilngPerAno(lintAux + 1) = CInt(VB6.Format(DateAdd(Microsoft.VisualBasic.DateInterval.Month, IIf(lintAux = 0, 0, lintAux * -1), ldteBas), "yyyymm"))
			Me.mfgFaturado.set_TextMatrix(0, lintAux, VB.Right(CStr(ilngPerAno(lintAux + 1)), 2) & "/" & VB.Left(CStr(ilngPerAno(lintAux + 1)), 4))
			Me.mfgAberto.set_TextMatrix(0, lintAux, VB.Right(CStr(ilngPerAno(lintAux + 1)), 2) & "/" & VB.Left(CStr(ilngPerAno(lintAux + 1)), 4))
			
			'UPGRADE_NOTE: Refresh was upgraded to CtlRefresh. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
			Call Me.mfgFaturado.CtlRefresh()
			'UPGRADE_NOTE: Refresh was upgraded to CtlRefresh. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
			Call Me.mfgAberto.CtlRefresh()
			System.Windows.Forms.Application.DoEvents()
		Next lintAux
		System.Windows.Forms.Application.DoEvents()
		
		For lintAux = 0 To MTotData
			
			Me.lblInfo1.Text = " Buscando os dados de Fatur. Mês " & VB6.Format(Me.mfgFaturado.get_TextMatrix(0, lintAux), "mm/yyyy")
			
			If lblnAux Then
				
				lstrSql = ""
				lstrSql = lstrSql & "SELECT numnf, mesano, mesano_ref, ta, zona, livro, conta, cons_id, unid_id, grupo, valortot, valorliq, codclas, flgst, datast, datapag " & vbCrLf
				lstrSql = lstrSql & "  FROM nf " & vbCrLf
				lstrSql = lstrSql & " WHERE datavenc between '" & Mid(Me.mfgFaturado.get_TextMatrix(0, lintAux), 4, 4) & "-" & Mid(Me.mfgFaturado.get_TextMatrix(0, lintAux), 1, 2) & "-01" & "'  and '" & Mid(Me.mfgFaturado.get_TextMatrix(0, lintAux), 4, 4) & "-" & Mid(Me.mfgFaturado.get_TextMatrix(0, lintAux), 1, 2) & "-31'"
				Call Conectar(lstrSql, lrstAux)
				With lrstAux
					If .State = ADODB.ObjectStateEnum.adStateOpen Then
						If .RecordCount > 0 Then
							Call BarraProgresso(Me.ProgressBar(1), Me.lblPerc(1), (Me.lblInfo), 0, .RecordCount)
							While Not .EOF
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								'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"'
								ldblVlrFat = CDbl(IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								'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"'
								llngCdClas = CInt(IIf(IsDbNull(.Fields("codclas").value), 0, .Fields("codclas").value))
								lblnCon = True
								
								If lblnCon Then
									'Faturado
									''If lstrFlgSit <> "C" Then
									
									lstrSql = ""
									lstrSql = lstrSql & "SELECT * FROM inadimplentes_Fatur " & vbCrLf
									lstrSql = lstrSql & " WHERE Data = '" & VB6.Format(Me.mfgFaturado.get_TextMatrix(0, lintAux), "mm/yyyy") & "'"
									Call Conectar(lstrSql, lrstAux1)
									With lrstAux1
										If .State = ADODB.ObjectStateEnum.adStateOpen Then
											If .RecordCount > 0 Then
												
												'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
												'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"'
												MResidencial = CDbl(IIf(IsDbNull(.Fields("Residencial_fatu").value), 0, .Fields("Residencial_fatu").value))
												'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
												'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"'
												MResidencial_Outros = CDbl(IIf(IsDbNull(.Fields("Residencial_Outros_fatu").value), 0, .Fields("Residencial_Outros_fatu").value))
												'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
												'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"'
												MIndustrial = CDbl(IIf(IsDbNull(.Fields("Industrial_fatu").value), 0, .Fields("Industrial_fatu").value))
												'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
												'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"'
												MComercial = CDbl(IIf(IsDbNull(.Fields("Comercial_fatu").value), 0, .Fields("Comercial_fatu").value))
												'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
												'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"'
												MRural = CDbl(IIf(IsDbNull(.Fields("Rural_fatu").value), 0, .Fields("Rural_fatu").value))
												'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
												'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"'
												MPoder_Publico = CDbl(IIf(IsDbNull(.Fields("Poder_Publico_fatu").value), 0, .Fields("Poder_Publico_fatu").value))
												'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
												'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"'
												MIluminacao_Publica = CDbl(IIf(IsDbNull(.Fields("Iluminacao_Publica_fatu").value), 0, .Fields("Iluminacao_Publica_fatu").value))
												'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
												'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"'
												MServico_Publico = CDbl(IIf(IsDbNull(.Fields("Servico_Publico_fatu").value), 0, .Fields("Servico_Publico_fatu").value))
												'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
												'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"'
												MOutros = CDbl(IIf(IsDbNull(.Fields("Outros_fatu").value), 0, .Fields("Outros_fatu").value))
												
												If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 Then
													MResidencial = MResidencial + ldblVlrFat
												End If
												If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 And llngCdClas <> 9101 Then
													MResidencial_Outros = MResidencial_Outros + ldblVlrFat
												ElseIf llngCdClas <= 3999 Then 
													MIndustrial = MIndustrial + ldblVlrFat
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 4 Then 
													MComercial = MComercial + ldblVlrFat
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 5 Then 
													MRural = MRural + ldblVlrFat
												ElseIf llngCdClas >= 6100 And llngCdClas <= 6399 Then 
													MPoder_Publico = MPoder_Publico + ldblVlrFat
												ElseIf llngCdClas >= 6400 And llngCdClas <= 6499 Then 
													MIluminacao_Publica = MIluminacao_Publica + ldblVlrFat
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 7 Then 
													MServico_Publico = MServico_Publico + ldblVlrFat
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 8 Then 
													MOutros = MOutros + ldblVlrFat
												End If
												
												lstrSql = ""
												lstrSql = lstrSql & "UPDATE `inadimplentes_Fatur` "
												If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 Then
													lstrSql = lstrSql & " SET `Residencial_fatu` = '" & Replace(CStr(MResidencial), ",", ".") & "'"
												End If
												If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 And llngCdClas <> 9101 Then
													lstrSql = lstrSql & " , `Residencial_Outros_fatu` = '" & Replace(CStr(MResidencial_Outros), ",", ".") & "'"
												ElseIf llngCdClas <= 3999 Then 
													lstrSql = lstrSql & " SET `Industrial_fatu` = '" & Replace(CStr(MIndustrial), ",", ".") & "'"
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 4 Then 
													lstrSql = lstrSql & " SET `Comercial_fatu` = '" & Replace(CStr(MComercial), ",", ".") & "'"
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 5 Then 
													lstrSql = lstrSql & " SET `Rural_fatu` = '" & Replace(CStr(MRural), ",", ".") & "'"
												ElseIf llngCdClas >= 6100 And llngCdClas <= 6399 Then 
													lstrSql = lstrSql & " SET `Poder_Publico_fatu` = '" & Replace(CStr(MPoder_Publico), ",", ".") & "'"
												ElseIf llngCdClas >= 6400 And llngCdClas <= 6499 Then 
													lstrSql = lstrSql & " SET `Iluminacao_Publica_fatu` = '" & Replace(CStr(MIluminacao_Publica), ",", ".") & "'"
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 7 Then 
													lstrSql = lstrSql & " SET `Servico_Publico_fatu` = '" & Replace(CStr(MServico_Publico), ",", ".") & "'"
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 8 Then 
													lstrSql = lstrSql & " SET `Outros_fatu` = '" & Replace(CStr(MOutros), ",", ".") & "'"
												End If
												lstrSql = lstrSql & " WHERE Data = '" & VB6.Format(Me.mfgFaturado.get_TextMatrix(0, lintAux), "mm/yyyy") & "'"
												Call myConC.Execute(lstrSql)
												
											Else
												
												lstrSql = ""
												lstrSql = "INSERT INTO `inadimplentes_Fatur` SET "
												lstrSql = lstrSql & " `Data` = '" & VB6.Format(Me.mfgFaturado.get_TextMatrix(0, lintAux), "mm/yyyy") & "'"
												
												If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 Then
													lstrSql = lstrSql & " ,`Residencial_fatu` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
												End If
												If CDbl(Mid(CStr(llngCdClas), 1, 2)) = 91 And llngCdClas <> 9101 Then
													lstrSql = lstrSql & " ,`Residencial_Outros_fatu` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
												ElseIf llngCdClas <= 3999 Then 
													lstrSql = lstrSql & " ,`Industrial_fatu` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 4 Then 
													lstrSql = lstrSql & " ,`Comercial_fatu` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 5 Then 
													lstrSql = lstrSql & " ,`Rural_fatu` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
												ElseIf llngCdClas >= 6100 And llngCdClas <= 6399 Then 
													lstrSql = lstrSql & " ,`Poder_Publico_fatu` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
												ElseIf llngCdClas >= 6400 And llngCdClas <= 6499 Then 
													lstrSql = lstrSql & " ,`Iluminacao_Publica_fatu` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 7 Then 
													lstrSql = lstrSql & " ,`Servico_Publico_fatu` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
												ElseIf CDbl(Mid(CStr(llngCdClas), 1, 1)) = 8 Then 
													lstrSql = lstrSql & " ,`Outros_fatu` = '" & Replace(CStr(ldblVlrFat), ",", ".") & "'"
												End If
												Call myConC.Execute(lstrSql)
											End If
										End If
										Call .Close()
									End With
									
									''End If
									'Aberto
									'If (ldtePagto = Conversion.CDate("01/01/1900") Or ldtePagto > ldteBas) And (lstrFlgSit <> "C" Or (lstrFlgSit = "C" And ldteFlgSit > ldteAux)) Then
									' Call AdicionaGrade(1, lstrMesAno, llngCdClas, ldblVlrFat, 0)
									'End If
								End If
								Call .MoveNext()
								Call BarraProgresso(Me.ProgressBar(1), Me.lblPerc(1), (Me.lblInfo), 1,  , " " & lstrMesAno & " ")
							End While
						Else
							
							lstrSql = ""
							lstrSql = "INSERT INTO `inadimplentes_Fatur` SET "
							lstrSql = lstrSql & " `Data` = '" & VB6.Format(Me.mfgFaturado.get_TextMatrix(0, lintAux), "mm/yyyy") & "'"
							
							lstrSql = lstrSql & " ,`Residencial_fatu` = 0"
							lstrSql = lstrSql & " ,`Residencial_Outros_fatu` = 0"
							lstrSql = lstrSql & " ,`Industrial_fatu` = 0"
							lstrSql = lstrSql & " ,`Comercial_fatu` = 0"
							lstrSql = lstrSql & " ,`Rural_fatu` = 0"
							lstrSql = lstrSql & " ,`Poder_Publico_fatu` = 0"
							lstrSql = lstrSql & " ,`Iluminacao_Publica_fatu` = 0"
							lstrSql = lstrSql & " ,`Servico_Publico_fatu` = 0"
							lstrSql = lstrSql & " ,`Outros_fatu` = 0"
							Call myConC.Execute(lstrSql)
							
						End If
						Call .Close()
					End If
				End With
			End If
		Next lintAux
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Sub
End Class