Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmIndContinuidadeNovo
	Inherits System.Windows.Forms.Form
	Private istrNmArq As String
	Private istrGrupo As String
	Private iintMesIniPerSeco As Short
	Private iintMesFimPerSeco As Short
	Private ifrmRelIndContinuidade As FrmRelatorio
	Private istrTamCol As String
	Private iblnCor As Boolean
	Private idteBase As Date
	
	Private Sub cmdArqCsv_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdArqCsv.Click
		Dim lstrAux As String
		Call NomeArquivoCsv()
		'UPGRADE_WARNING: CommonDialog variable was not upgraded Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="671167DC-EA81-475D-B690-7A40C7BF4A23"'
		With Me.dialArq
			.DefaultExt = "TXT"
			'UPGRADE_WARNING: Filter has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
			.Filter = "*." & .DefaultExt
			If Trim(Me.txtArqCsv.Text) <> "" Then
				.FileName = StrReverse(Mid(StrReverse(Me.txtArqCsv.Text), CInt(InStr(StrReverse(Me.txtArqCsv.Text), "\")))) & istrNmArq & "." & .DefaultExt
			Else
				.FileName = My.Application.Info.DirectoryPath & "\" & istrNmArq & "." & .DefaultExt
			End If
			.Title = "Exportar resultado de indicadores de continuidade"
			Call .ShowDialog()
			lstrAux = StrReverse(.FileName)
			Me.txtArqCsv.Text = StrReverse(Mid(lstrAux, CInt(InStr(lstrAux, "\")))) & istrNmArq & "." & .DefaultExt
		End With
	End Sub
	
	Private Sub cmdExporta_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExporta.Click
		'Controle Arquivo
		Dim lstrLin As String
		Dim lintARQ As Short
		Dim lstrZon As String
		Dim lstrLiv As String
		Dim lstrCon As String
		Dim llngMes As Integer
		Dim ldblDic_I As Double
		Dim ldblDic_E As Double
		Dim ldblFic_I As Double
		Dim ldblFic_E As Double
		Dim ldblMic_I As Double
		Dim ldblMic_E As Double
		
		Dim ldblDicri As Double
		Dim llngDicri As Double
		
		Dim ldblEusd As Double
		Dim ldblFioB As Double
		Dim lstrSub As String
		Dim lstrAli As String
		Dim lstrTar As String
		Dim lstrReg As String
		Dim lstrCid As String
		Dim lstrCoj As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		If Trim(Me.txtArqCsv.Text) = "" Then
			Call MsgBox("Você deve selecionar um local para gravar o arquivo!" & vbCrLf & "Ex: C:\DADOS_DIC_FIC_DMIC.txt", MsgBoxStyle.Critical, gstrTituloMensagem)
		Else
			Call LigDes(False)
			lstrSql = ""
			lstrSql = lstrSql & "SELECT * "
			If Me.chkDicri.CheckState = System.Windows.Forms.CheckState.Unchecked Then
				lstrSql = lstrSql & "  FROM `indicadores_dicficdmic` "
			Else
				lstrSql = lstrSql & "  FROM `indicadores_dicri` "
			End If
			lstrSql = lstrSql & " WHERE `ano` = '" & Me.txtMesAnoInd.Text & "' "
			If Me.chkDicri.CheckState = System.Windows.Forms.CheckState.Unchecked Then
				lstrSql = lstrSql & " ORDER BY `zona` ASC,`livro` ASC,`conta` ASC,`mes` ASC "
			Else
				lstrSql = lstrSql & " ORDER BY `zona` ASC,`livro` ASC,`conta` ASC,`mes` ASC, `id_dicri` ASC "
			End If
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount)
						'Export para CSV
						If Trim(Me.txtArqCsv.Text) <> "" Then
							lintARQ = FreeFile
							FileOpen(lintARQ, Me.txtArqCsv.Text, OpenMode.Output)
							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"'
								lstrZon = Trim(IIf(IsDbNull(.Fields("zona").value), "", .Fields("zona").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								lstrLiv = Trim(IIf(IsDbNull(.Fields("livro").value), "", .Fields("livro").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								lstrCon = Trim(IIf(IsDbNull(.Fields("conta").value), "", .Fields("conta").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								llngMes = IIf(IsDbNull(.Fields("mes").value), 0, .Fields("mes").value)
								If Me.chkDicri.CheckState = System.Windows.Forms.CheckState.Unchecked 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"'
									ldblDic_I = IIf(IsDbNull(.Fields("rdic_i").value), 0, .Fields("rdic_i").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"'
									ldblDic_E = IIf(IsDbNull(.Fields("rdic_e").value), 0, .Fields("rdic_e").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"'
									ldblFic_I = Arredondar(IIf(IsDbNull(.Fields("rfic_i").value), 0, .Fields("rfic_i").value), 0) 'inteiro
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									ldblFic_E = Arredondar(IIf(IsDbNull(.Fields("rfic_e").value), 0, .Fields("rfic_e").value), 0)
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									ldblMic_I = IIf(IsDbNull(.Fields("rdmic_i").value), 0, .Fields("rdmic_i").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"'
									ldblMic_E = IIf(IsDbNull(.Fields("rdmic_e").value), 0, .Fields("rdmic_e").value)
								Else
									'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
									ldblDicri = IIf(IsDbNull(.Fields("rdicri").value), 0, .Fields("rdicri").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"'
									llngDicri = IIf(IsDbNull(.Fields("id_dicri").value), 0, .Fields("id_dicri").value)
								End If
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								ldblEusd = IIf(IsDbNull(.Fields("veusd").value), 0, .Fields("veusd").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"'
								ldblFioB = IIf(IsDbNull(.Fields("veusd_fio_b").value), 0, .Fields("veusd_fio_b").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"'
								lstrSub = Trim(IIf(IsDbNull(.Fields("subestacao").value), "", .Fields("subestacao").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"'
								lstrAli = Trim(IIf(IsDbNull(.Fields("alimentador").value), "", .Fields("alimentador").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								lstrTar = Trim(IIf(IsDbNull(.Fields("grupo_tarifario").value), "B3-DC", .Fields("grupo_tarifario").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"'
								lstrReg = Trim(IIf(IsDbNull(.Fields("regiao").value), "NURB", .Fields("regiao").value))
								'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
								lstrCid = IIf(IsDbNull(.Fields("cod_mun_ibge").value), "0", .Fields("cod_mun_ibge").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"'
								lstrCoj = IIf(IsDbNull(.Fields("conjunto").value), "0", .Fields("conjunto").value)
								'
								lstrLin = ""
								If gstrEmpresa_Sigla = "CERGAL" Then
									lstrLin = lstrLin & lstrZon & lstrLiv & VB.Right(lstrCon, 5)
								ElseIf gstrEmpresa_Sigla = "EFLUL" Then 
									lstrLin = lstrLin & lstrLiv & VB.Right(lstrCon, 4)
								Else
									lstrLin = lstrLin & lstrZon & lstrLiv & lstrCon
								End If
								lstrLin = lstrLin & ";" & llngMes & ";"
								If Me.chkDicri.CheckState = System.Windows.Forms.CheckState.Unchecked Then
									lstrLin = lstrLin & Replace(CStr(ldblDic_I), ".", ",") & ";"
									lstrLin = lstrLin & Replace(CStr(ldblDic_E), ".", ",") & ";"
									lstrLin = lstrLin & Replace(CStr(ldblFic_I), ".", "") & ";"
									lstrLin = lstrLin & Replace(CStr(ldblFic_E), ".", "") & ";"
									lstrLin = lstrLin & Replace(CStr(ldblMic_I), ".", ",") & ";"
									lstrLin = lstrLin & Replace(CStr(ldblMic_E), ".", ",") & ";"
								Else
									lstrLin = lstrLin & Replace(CStr(ldblDicri), ".", ",") & ";"
									lstrLin = lstrLin & llngDicri & ";"
								End If
								lstrLin = lstrLin & Replace(CStr(ldblEusd), ".", ",") & ";"
								lstrLin = lstrLin & Replace(CStr(ldblFioB), ".", ",") & ";"
								lstrLin = lstrLin & lstrSub & ";"
								lstrLin = lstrLin & lstrAli & ";"
								lstrLin = lstrLin & lstrTar & ";"
								lstrLin = lstrLin & lstrReg & ";"
								lstrLin = lstrLin & lstrCid & ";"
								lstrLin = lstrLin & lstrCoj & ";"
								lstrLin = lstrLin & gstrEmpresa_CodRes89
								PrintLine(lintARQ, lstrLin)
								Call .MoveNext()
								Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
							End While
							FileClose(lintARQ)
							Call MsgBox("Arquivo gerado com sucesso!", MsgBoxStyle.Information, gstrTituloMensagem)
						End If
					End If
					Call .Close()
				End If
			End With
			'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
			lrstAux = Nothing
			Call LigDes(True)
		End If
	End Sub
	
	Private Sub cmdImprimir_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdImprimir.Click
		Dim lstrTab As String
		Dim lstrZon As String
		Dim lstrLiv As String
		Dim lstrCon As String
		Dim lstrCod As String
		Dim lstrAux As String
		Dim ldblVlr As Double
		Dim ldblTot As Double
		Dim ldblSub As Double
		Dim ldblQtd As Double
		Dim lblnCor As Boolean
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Call LigDes(False)
		iblnCor = True
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM `sobretaxa` "
		lstrSql = lstrSql & " WHERE `codigo` BETWEEN 9070000030 AND 9070000039 "
		lstrSql = lstrSql & "   AND `referencia` = '" & Me.txtMesAnoInd.Text & "' "
		lstrSql = lstrSql & " ORDER BY `codigo` ASC "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					istrTamCol = "<20mm|<50mm|<78mm|>38mm|>20mm;|"
					With ifrmRelIndContinuidade
						.quem_chama = Me
						.VS.Font = VB6.FontChangeName(.VS.Font, "Arial")
						.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
						.VS.PageBorder = VSVIEW6.TableBorderSettings.tbNone
						.VS.Orientation = VSVIEW6.OrientationSettings.orPortrait
						.VS.PhysicalPage = True
						.VS.PaperSize = VSVIEW6.PaperSizeSettings.pprA4
						.VS.MarginTop = "7mm"
						.VS.MarginRight = "7mm"
						.VS.MarginLeft = "7mm"
						.VS.MarginBottom = "5mm"
						.VS.TextColor = System.Drawing.Color.Black
						.VS.BrushStyle = VSVIEW6.BrushStyleSettings.bsSolid
						.VS.Font = VB6.FontChangeBold(.VS.Font, False)
						.VS.StartDoc()
					End With
					ldblTot = 0
					ldblSub = 0
					ldblQtd = 0
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					lstrAux = Trim(IIf(IsDbNull(.Fields("codigo").value), "", .Fields("codigo").value))
					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"'
						lstrZon = Trim(IIf(IsDbNull(.Fields("zona").value), "", .Fields("zona").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrLiv = Trim(IIf(IsDbNull(.Fields("livro").value), "", .Fields("livro").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrCon = Trim(IIf(IsDbNull(.Fields("conta").value), "", .Fields("conta").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblVlr = CDbl(IIf(IsDbNull(.Fields("valor").value), 0, .Fields("valor").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"'
						lstrCod = Trim(IIf(IsDbNull(.Fields("codigo").value), "", .Fields("codigo").value))
						If lstrAux <> lstrCod Then
							lstrTab = ""
							lstrTab = lstrTab & istrTamCol & "Sub-Total|" & ldblQtd & "|" & VB6.Format(ldblSub, "#,##0.00") & "|"
							With ifrmRelIndContinuidade
								.VS.Font = VB6.FontChangeSize(.VS.Font, 8)
								.VS.Font = VB6.FontChangeBold(.VS.Font, True)
								.VS.Table = lstrTab
								.VS.Font = VB6.FontChangeBold(.VS.Font, False)
								If iblnCor Then
									.VS.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
									.VS.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
									'UPGRADE_ISSUE: VBControlExtender method ifrmRelIndContinuidade.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
									Call .VS.DrawRectangle("15mm", .VS.CurrentY, "195mm", .VS.CurrentY + 200) '510
									.VS.BrushColor = System.Drawing.Color.White
									.VS.PenStyle = VSVIEW6.PenStyleSettings.psSolid
									iblnCor = False
								Else
									iblnCor = True
								End If
							End With
							lstrAux = lstrCod
							ldblSub = 0
							ldblQtd = 0
						End If
						ldblQtd = ldblQtd + 1
						ldblTot = ldblTot + ldblVlr
						ldblSub = ldblSub + ldblVlr
						lstrTab = ""
						lstrTab = lstrTab & istrTamCol & lstrZon & "." & lstrLiv & "." & lstrCon & "|" & BuscaDescricaoCodido(lstrCod) & "|" & VB6.Format(ldblVlr, "#,##0.00") & "|"
						With ifrmRelIndContinuidade
							.VS.Font = VB6.FontChangeSize(.VS.Font, 8)
							.VS.Table = lstrTab
							If iblnCor Then
								.VS.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
								.VS.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
								'UPGRADE_ISSUE: VBControlExtender method ifrmRelIndContinuidade.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
								Call .VS.DrawRectangle("15mm", .VS.CurrentY, "195mm", .VS.CurrentY + 200) '510
								.VS.BrushColor = System.Drawing.Color.White
								.VS.PenStyle = VSVIEW6.PenStyleSettings.psSolid
								iblnCor = False
							Else
								iblnCor = True
							End If
						End With
						Call .MoveNext()
					End While
					If ldblQtd > 0 And ldblQtd <> .RecordCount Then
						lstrTab = ""
						lstrTab = lstrTab & istrTamCol & "Sub-Total|" & ldblQtd & "|" & VB6.Format(ldblSub, "#,##0.00") & "|"
						With ifrmRelIndContinuidade
							.VS.Font = VB6.FontChangeSize(.VS.Font, 8)
							.VS.Font = VB6.FontChangeBold(.VS.Font, True)
							.VS.Table = lstrTab
							.VS.Font = VB6.FontChangeBold(.VS.Font, False)
							If iblnCor Then
								.VS.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
								.VS.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
								'UPGRADE_ISSUE: VBControlExtender method ifrmRelIndContinuidade.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
								Call .VS.DrawRectangle("15mm", .VS.CurrentY, "195mm", .VS.CurrentY + 200) '510
								.VS.BrushColor = System.Drawing.Color.White
								.VS.PenStyle = VSVIEW6.PenStyleSettings.psSolid
								iblnCor = False
							Else
								iblnCor = True
							End If
						End With
						lstrAux = lstrCod
						ldblSub = 0
						ldblQtd = 0
					End If
					lstrTab = ""
					lstrTab = lstrTab & istrTamCol & "Total|" & .RecordCount & "|" & VB6.Format(ldblTot, "#,##0.00") & "|"
					With ifrmRelIndContinuidade
						.VS.Font = VB6.FontChangeBold(.VS.Font, True)
						.VS.Table = lstrTab
						.VS.Font = VB6.FontChangeBold(.VS.Font, False)
						Call .VS.EndDoc()
						Call VB6.ShowForm(ifrmRelIndContinuidade, False)
					End With
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
		Call LigDes(True)
	End Sub
	
	Public Sub CabecaRel()
		Dim lstrTab As String
		With ifrmRelIndContinuidade
			Call Cabecalho_Relatorio(.VS, "Listagem do Ressarcimento de Indicadores", "", "4",  , "Referência: " & Me.txtMesAnoInd.Text)
			.VS.CurrentLine = 0
			'UPGRADE_ISSUE: VBControlExtender method ifrmRelIndContinuidade.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
			.VS.CurrentY = .VS.CurrentY + 400
			.VS.Font = VB6.FontChangeBold(.VS.Font, True)
			.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
			.VS.Font = VB6.FontChangeSize(.VS.Font, 8)
			lstrTab = ""
			lstrTab = lstrTab & istrTamCol
			lstrTab = lstrTab & "Zona.Livro.Conta|Descrição|"
			lstrTab = lstrTab & "Valor (R$)|"
			.VS.Table = lstrTab
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
			.VS.Font = VB6.FontChangeSize(.VS.Font, 8)
		End With
		iblnCor = True
	End Sub
	
	Private Sub cmdProcessar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdProcessar.Click
		Dim lstrErro As String
		lstrErro = ""
		With Me
			If Len(Trim(.txtArq.Text)) = 0 And .txtArq.Enabled Then
				lstrErro = lstrErro & vbNewLine & "- Arquivo"
			End If
			If Len(Trim(.txtMesAnoInd.Text)) = 0 And .txtMesAnoInd.Enabled Then
				lstrErro = lstrErro & vbNewLine & "- Mês/Ano referente ao Indicador"
			End If
			If (Len(lstrErro) > 0) Then
				Call MsgBox("Os seguintes campos são obrigatórios:" & lstrErro, MsgBoxStyle.Information, gstrTituloMensagem)
				Exit Sub
			End If
			If GravaViaArquivo Then
				Call AtualizaEusdClasse()
			End If
		End With
	End Sub
	
	Private Function GravaViaArquivo() As Boolean
		Dim lblnRet As Boolean
		Dim lblnExi As Boolean
		'Controle de Arquivo
		Dim lintARQ As Short
		Dim lstrLinha As String
		Dim llngNRows As Integer
		Dim larrItens() As String
		Dim llngRow As Integer
		'Dados do Consumidor
		Dim lstrClasse As String
		Dim lstrZonaAux As String
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		'Dim llngConsId As Long
		'Dim llngUnidId As Long
		Dim lstrRegiao As String
		Dim lstrGrupo As String
		'Dim lstrGruTar As String
		Dim ldblVlrCM As Double
		Dim ldblEusdFb As Double
		'
		Dim lstrSubestacao As String
		Dim lstrAlimentador As String
		Dim lstrMunicipio As String
		Dim lstrConjunto As String
		Dim lstrIBGE As String
		Dim lstrMesAno As String
		'Realizados
		Dim ldblRealDic_I As Double
		Dim ldblRealDic_E As Double
		Dim ldblRealFic_I As Double
		Dim ldblRealFic_E As Double
		Dim ldblRealMic_I As Double
		Dim ldblRealMic_E As Double
		Dim ldblRealDicri As Double
		Dim llngIdDicri As Integer
		'Controle dos indices das colunas do arquivo externo
		Dim lintAux As Short
		Dim lintAuxEntidade As Short
		Dim lintAuxSub As Short
		Dim lintAuxAli As Short
		Dim lintAuxMun As Short
		Dim lintAuxCoj As Short
		Dim lintAuxReg As Short
		Dim lintAuxGrupo As Short
		Dim lintAuxMesRef As Short
		'
		Dim lintAuxDIC_I As Short
		Dim lintAuxFIC_I As Short
		Dim lintAuxMIC_I As Short
		Dim lintAuxDIC_E As Short
		Dim lintAuxFIC_E As Short
		Dim lintAuxMIC_E As Short
		'
		Dim lintAuxDICRI As Short
		'Controle de consulta
		Dim lstrTabVlr As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		'Busca o número de linhas que o arquivo em forma ASCII possue
		llngNRows = getNumRows(Me.txtArq.Text)
		'On Error GoTo ErroArquivo
		llngRow = 0
		If (llngNRows > 1) Then
			If Me.chkInterno.CheckState = System.Windows.Forms.CheckState.Checked Then
				If Me.chkDicri.CheckState = System.Windows.Forms.CheckState.Unchecked Then
					Call Executar("DELETE FROM indicadores_dicficdmic WHERE ano = " & Me.txtMesAnoInd.Text)
					Call Executar("ALTER TABLE indicadores_dicficdmic AUTO_INCREMENT = 1")
				End If
			End If
			If Me.chkDicri.CheckState = System.Windows.Forms.CheckState.Checked Then
				Call Executar("DELETE FROM indicadores_dicri WHERE ano = " & Me.txtMesAnoInd.Text)
				Call Executar("ALTER TABLE indicadores_dicri AUTO_INCREMENT = 1")
			End If
			Call LigDes(False)
			Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
			Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, llngNRows)
			'Abre arquivo externo
			lintARQ = FreeFile
			FileOpen(lintARQ, Me.txtArq.Text, OpenMode.Input)
			lstrZonaAux = ""
			While Not EOF(lintARQ)
				'Passa os dados da linha atual para variável lstrLinha
				lstrLinha = LineInput(lintARQ)
				'Retira os espaços desnecessários
				lstrLinha = Trim(lstrLinha)
				llngRow = llngRow + 1
				'Pega os indices dos campos necessários
				If llngRow = 1 Then
					larrItens = TrataCSV(lstrLinha)
					For lintAux = LBound(larrItens) To UBound(larrItens)
						If larrItens(lintAux) = "ENTIDADE" Then
							lintAuxEntidade = lintAux
						ElseIf larrItens(lintAux) = "MES" Then 
							lintAuxMesRef = lintAux
						ElseIf larrItens(lintAux) = "SUBESTACAO" Then 
							lintAuxSub = lintAux
						ElseIf larrItens(lintAux) = "ALIMENTADOR" Then 
							lintAuxAli = lintAux
						ElseIf larrItens(lintAux) = "TIPO_LOCALIZACAO" Then 
							lintAuxReg = lintAux
						ElseIf larrItens(lintAux) = "COD_MUNICIPIO" Then 
							lintAuxMun = lintAux
						ElseIf larrItens(lintAux) = "CONJUNTO" Then 
							lintAuxCoj = lintAux
						ElseIf larrItens(lintAux) = "GRUPO_TARIF" Then 
							lintAuxGrupo = lintAux
						End If
						If Me.chkDicri.CheckState = System.Windows.Forms.CheckState.Unchecked Then
							If larrItens(lintAux) = "DIC_INTERNO" Then
								lintAuxDIC_I = lintAux
							ElseIf larrItens(lintAux) = "DIC_EXTERNO" Then 
								lintAuxDIC_E = lintAux
							ElseIf larrItens(lintAux) = "FIC_INTERNO" Then 
								lintAuxFIC_I = lintAux
							ElseIf larrItens(lintAux) = "FIC_EXTERNO" Then 
								lintAuxFIC_E = lintAux
							ElseIf larrItens(lintAux) = "DMIC_INTERNO" Then 
								lintAuxMIC_I = lintAux
							ElseIf larrItens(lintAux) = "DMIC_EXTERNO" Then 
								lintAuxMIC_E = lintAux
							End If
						Else
							If larrItens(lintAux) = "DICRI" Then
								lintAuxDICRI = lintAux
							End If
						End If
					Next lintAux
				End If
				'Contrle de linhas para a barra de progresso
				If llngRow > 1 And Len(lstrLinha) > 0 Then
					'Carrega a variável array
					larrItens = TrataCSV(lstrLinha)
					'--- Preparando os dados
					'----- Dados do consumidor
					If gstrEmpresa_Sigla = "EFLUL" Then 'LLCCCC
						larrItens(lintAuxEntidade) = VB6.Format(larrItens(lintAuxEntidade), "000000")
						lstrZona = "001"
						lstrLivro = VB.Right("00" & VB.Left(IIf(Trim(larrItens(lintAuxEntidade)) = "", "00", larrItens(lintAuxEntidade)), 2), 2)
						lstrConta = VB.Right("000000" & VB.Right(IIf(Trim(larrItens(lintAuxEntidade)) = "", "000000", larrItens(lintAuxEntidade)), 4), 6)
					Else
						If gstrEmpresa_Sigla = "EFLJCL" Then 'ZZZLLCCCCCC
							larrItens(lintAuxEntidade) = VB6.Format(larrItens(lintAuxEntidade), "00000000000") '11 digitos
							lstrZona = VB.Left(larrItens(lintAuxEntidade), 3)
							lstrLivro = Mid(larrItens(lintAuxEntidade), 4, 2)
							lstrConta = VB.Right(larrItens(lintAuxEntidade), 6)
						Else 'ZZZLLCCCCC
							lstrZona = VB.Left(larrItens(lintAuxEntidade), 3)
							lstrLivro = Mid(larrItens(lintAuxEntidade), 4, 2)
							lstrConta = VB6.Format(VB.Right(larrItens(lintAuxEntidade), 5), "000000")
						End If
					End If
					lstrRegiao = Trim(VB.Left(IIf(Trim(larrItens(lintAuxReg)) = "", " ", larrItens(lintAuxReg)), 1))
					lstrGrupo = Trim(VB.Left(IIf(Trim(larrItens(lintAuxGrupo)) = "", " ", larrItens(lintAuxGrupo)), 1))
					
					If lstrGrupo = "" Then
						If VerificaExisteRegistro("unidb", "zona = '" & lstrZona & "' AND livro = '" & lstrLivro & "' AND conta = '" & lstrConta & "' ") Then
							lstrGrupo = "B"
						Else
							lstrGrupo = "A"
						End If
					End If
					If lstrRegiao = "" Then
						lstrRegiao = Trim(GetValorTabela(IIf(lstrGrupo = "B", "unidb", "unida"), "regiao", "zona = '" & lstrZona & "' AND livro = '" & lstrLivro & "' AND conta = '" & lstrConta & "' "))
						If lstrRegiao = "" Then lstrRegiao = "U"
					End If
					
					
					lstrSubestacao = IIf(Trim(larrItens(lintAuxSub)) = "", "", larrItens(lintAuxSub))
					lstrAlimentador = IIf(Trim(larrItens(lintAuxAli)) = "", "", larrItens(lintAuxAli))
					lstrMunicipio = IIf(Trim(larrItens(lintAuxMun)) = "", "", larrItens(lintAuxMun))
					lstrConjunto = IIf(Trim(larrItens(lintAuxCoj)) = "", "", larrItens(lintAuxCoj))
					lstrConjunto = gstrEmpresa_Conjunto
					If lstrZonaAux <> lstrZona Then
						If lstrMunicipio <> lstrIBGE Then
							lstrIBGE = GetValorTabela("munic", "ibge", "zona = '" & lstrZona & "' ")
						End If
						lstrZonaAux = lstrZona
					End If
					If Trim(lstrZona & lstrLivro & lstrConta) <> "" Then
						lstrMesAno = VB6.Format(IIf(Trim(larrItens(lintAuxMesRef)) = "", "01", larrItens(lintAuxMesRef)), "00") & "/" & Me.txtMesAnoInd.Text
						If Me.chkDicri.CheckState = System.Windows.Forms.CheckState.Unchecked Then
							ldblRealDic_I = CDbl(IIf(Trim(larrItens(lintAuxDIC_I)) = "", "0", larrItens(lintAuxDIC_I)))
							ldblRealDic_E = CDbl(IIf(Trim(larrItens(lintAuxDIC_E)) = "", "0", larrItens(lintAuxDIC_E)))
							ldblRealFic_I = CDbl(IIf(Trim(larrItens(lintAuxFIC_I)) = "", "0", larrItens(lintAuxFIC_I)))
							ldblRealFic_E = CDbl(IIf(Trim(larrItens(lintAuxFIC_E)) = "", "0", larrItens(lintAuxFIC_E)))
							ldblRealMic_I = CDbl(IIf(Trim(larrItens(lintAuxMIC_I)) = "", "0", larrItens(lintAuxMIC_I)))
							ldblRealMic_E = CDbl(IIf(Trim(larrItens(lintAuxMIC_E)) = "", "0", larrItens(lintAuxMIC_E)))
						Else
							If Trim(larrItens(lintAuxDICRI)) <> "DIC" Then
								ldblRealDicri = CDbl(IIf(Trim(larrItens(lintAuxDICRI)) = "", "0", larrItens(lintAuxDICRI)))
							End If
							lstrTabVlr = GetValorTabela("indicadores_dicri", "MAX(IFNULL(id_dicri,0)) id_dicri", "ano = " & VB.Right(lstrMesAno, 4) & " AND mes = '" & VB.Left(lstrMesAno, 2) & "' AND zona = '" & lstrZona & "' AND livro = '" & lstrLivro & "' AND conta = '" & lstrConta & "' AND grupo = '" & lstrGrupo & "' ")
							If IsNumeric(lstrTabVlr) Then
								llngIdDicri = CInt(lstrTabVlr)
							Else
								llngIdDicri = 0
							End If
							llngIdDicri = llngIdDicri + 1
						End If
						'myConC.Close
						'Call Carrega_Banco
						'Gravação
						'--- Insere os dados
						lblnExi = False
						If Me.chkDicri.CheckState = System.Windows.Forms.CheckState.Unchecked Then
							lblnExi = VerificaExisteRegistro("indicadores_dicficdmic", "`mes`='" & VB.Left(lstrMesAno, 2) & "' AND `ano`   = '" & VB.Right(lstrMesAno, 4) & "' AND `grupo` = '" & UCase(lstrGrupo) & "' AND `zona`  = '" & lstrZona & "' AND `livro` = '" & lstrLivro & "' AND `conta` = '" & lstrConta & "' ")
						End If
						lstrSql = ""
						If Not lblnExi Then
							lstrSql = lstrSql & "INSERT INTO "
						Else
							lstrSql = lstrSql & "UPDATE "
						End If
						If Me.chkDicri.CheckState = System.Windows.Forms.CheckState.Unchecked Then
							lstrSql = lstrSql & "`indicadores_dicficdmic` SET "
						Else
							lstrSql = lstrSql & "`indicadores_dicri` SET "
						End If
						If Not lblnExi Then
							lstrSql = lstrSql & " `mes`   = '" & VB.Left(lstrMesAno, 2) & "',"
							lstrSql = lstrSql & " `ano`   = '" & VB.Right(lstrMesAno, 4) & "',"
							lstrSql = lstrSql & " `grupo` = '" & UCase(lstrGrupo) & "',"
							lstrSql = lstrSql & " `zona`  = '" & lstrZona & "',"
							lstrSql = lstrSql & " `livro` = '" & lstrLivro & "',"
							lstrSql = lstrSql & " `conta` = '" & lstrConta & "',"
							lstrSql = lstrSql & " `subestacao`  = '" & lstrSubestacao & "',"
							lstrSql = lstrSql & " `alimentador` = '" & lstrAlimentador & "',"
							lstrSql = lstrSql & " `conjunto`    = '" & lstrConjunto & "',"
							lstrSql = lstrSql & " `cod_mun_ibge`    = '" & lstrIBGE & "',"
						End If
						'
						If Me.chkDicri.CheckState = System.Windows.Forms.CheckState.Unchecked Then
							If Me.chkInterno.CheckState = System.Windows.Forms.CheckState.Checked Then
								lstrSql = lstrSql & " `rdic_i`       = '" & Replace(CStr(ldblRealDic_I), ",", ".") & "', "
								lstrSql = lstrSql & " `rfic_i`       = '" & Replace(CStr(ldblRealFic_I), ",", ".") & "', "
								lstrSql = lstrSql & " `rdmic_i`      = '" & Replace(CStr(ldblRealMic_I), ",", ".") & "', "
							Else
								lstrSql = lstrSql & " `rdic_e`       = '" & Replace(CStr(ldblRealDic_E), ",", ".") & "', "
								lstrSql = lstrSql & " `rfic_e`       = '" & Replace(CStr(ldblRealFic_E), ",", ".") & "', "
								lstrSql = lstrSql & " `rdmic_e`      = '" & Replace(CStr(ldblRealMic_E), ",", ".") & "', "
							End If
						Else
							lstrSql = lstrSql & " `rdicri`       = '" & Replace(CStr(ldblRealDic_I), ",", ".") & "', "
							lstrSql = lstrSql & " `id_dicri`     = '" & llngIdDicri & "', "
						End If
						lstrSql = lstrSql & " `regiao`     = '" & IIf(lstrRegiao = "U", "URB", "NURB") & "' "
						If lblnExi Then
							lstrSql = lstrSql & " WHERE "
							lstrSql = lstrSql & " `mes`   = '" & VB.Left(lstrMesAno, 2) & "' AND"
							lstrSql = lstrSql & " `ano`   = '" & VB.Right(lstrMesAno, 4) & "' AND"
							lstrSql = lstrSql & " `grupo` = '" & UCase(lstrGrupo) & "' AND"
							lstrSql = lstrSql & " `zona`  = '" & lstrZona & "' AND"
							lstrSql = lstrSql & " `livro` = '" & lstrLivro & "' AND"
							lstrSql = lstrSql & " `conta` = '" & lstrConta & "' "
						End If
						'myConC.Close
						'Call Carrega_Banco
						If Trim(larrItens(lintAuxDICRI)) <> "DIC" Then
							Call Executar(lstrSql)
						End If
					End If
					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
					System.Windows.Forms.Application.DoEvents()
				End If
			End While
			'Call MsgBox("Arquivo processado com sucesso!", vbInformation, gstrTituloMensagem)
		Else
			'Me.MousePointer = vbDefault
			'Call MsgBox("O arquivo está vazio!", vbExclamation, gstrTituloMensagem)
		End If
ErroArquivo: 
		If Err.Number > 0 Then
			Me.Cursor = System.Windows.Forms.Cursors.Default
			FileClose(lintARQ)
			Call MsgBox(Err.Number & " - " & GetErrosVB(Err.Number, Err.Description), MsgBoxStyle.Critical, gstrTituloMensagem)
			Call LigDes(True)
			lblnRet = False
		Else
			FileClose(lintARQ)
			Call LigDes(True)
			Me.Cursor = System.Windows.Forms.Cursors.Default
			lblnRet = True
		End If
		GravaViaArquivo = lblnRet
	End Function
	
	Private Sub AtualizaEusdClasse()
		Dim ldblId As Double
		Dim lstrMesAno As String
		Dim lstrClasse As String
		Dim lstrGruTar As String
		Dim lstrGrupo As String
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim lstrMes As String
		Dim ldblEusd As Double
		Dim ldblFioB As Double
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		If Me.chkDicri.CheckState = System.Windows.Forms.CheckState.Unchecked Then
			lstrSql = "SELECT * FROM indicadores_dicficdmic WHERE veusd is null and ano = " & Me.txtMesAnoInd.Text
		Else
			lstrSql = "SELECT * FROM indicadores_dicri WHERE ano = " & Me.txtMesAnoInd.Text
		End If
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount)
					While Not .EOF
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldblId = IIf(IsDbNull(.Fields("id").value), "", .Fields("id").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrMes = IIf(IsDbNull(.Fields("mes").value), "", .Fields("mes").value)
						lstrMesAno = lstrMes & "/" & Me.txtMesAnoInd.Text
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrZona = IIf(IsDbNull(.Fields("zona").value), "", .Fields("zona").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrLivro = IIf(IsDbNull(.Fields("livro").value), "", .Fields("livro").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrConta = IIf(IsDbNull(.Fields("conta").value), "", .Fields("conta").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrGrupo = IIf(IsDbNull(.Fields("grupo").value), "", .Fields("grupo").value)
						'
						'myConC.Close
						'Call Carrega_Banco
						ldblEusd = CalcEUSD(lstrMesAno, lstrZona, lstrLivro, lstrConta, lstrGrupo, iintMesIniPerSeco, iintMesFimPerSeco, False, lstrClasse)
						ldblFioB = CalcEUSD(lstrMesAno, lstrZona, lstrLivro, lstrConta, lstrGrupo, iintMesIniPerSeco, iintMesFimPerSeco, True)
						'
						If lstrClasse <> "" Then
							If lstrGrupo = "B" Then
								Select Case CShort(VB.Left(lstrClasse, 1))
									Case Is < 4 'Industrial
										lstrGruTar = "B3-DC"
									Case Is = 4 'comercial
										lstrGruTar = "B3-DC"
									Case Is = 5 'Rural
										lstrGruTar = "B2-R"
									Case Is = 6 'Poderes Públicos
										lstrGruTar = "B3-DC"
										If VB.Left(lstrClasse, 2) = "64" Then
											lstrGruTar = "B4-IP"
										End If
									Case Is = 7 'Serviço Público
										lstrGruTar = "B3-DC"
									Case Is = 8 'Consumo próprio
										lstrGruTar = "B3-DC"
									Case Is = 9 'Residencial
										If VB.Right(lstrClasse, 1) <> "1" Then
											lstrGruTar = "B1-RBR"
										Else
											lstrGruTar = "B1-R"
										End If
								End Select
							Else
								lstrGruTar = "A4"
							End If
						End If
						If Me.chkDicri.CheckState = System.Windows.Forms.CheckState.Unchecked Then
							lstrSql = "UPDATE indicadores_dicficdmic SET "
						Else
							lstrSql = "UPDATE indicadores_dicri SET "
						End If
						lstrSql = lstrSql & " `grupo_tarifario`    = '" & lstrGruTar & "',"
						lstrSql = lstrSql & " `veusd`        = '" & Replace(CStr(ldblEusd), ",", ".") & "', "
						lstrSql = lstrSql & " `veusd_fio_b`  = '" & Replace(CStr(ldblFioB), ",", ".") & "' "
						lstrSql = lstrSql & " WHERE "
						lstrSql = lstrSql & " `mes`   = '" & VB.Left(lstrMesAno, 2) & "' AND"
						lstrSql = lstrSql & " `ano`   = '" & VB.Right(lstrMesAno, 4) & "' AND"
						lstrSql = lstrSql & " `grupo` = '" & UCase(lstrGrupo) & "' AND"
						lstrSql = lstrSql & " `zona`  = '" & lstrZona & "' AND"
						lstrSql = lstrSql & " `livro` = '" & lstrLivro & "' AND"
						lstrSql = lstrSql & " `conta` = '" & lstrConta & "' AND "
						lstrSql = lstrSql & " `id` = " & ldblId & " "
						'parei no 59729
						'myConC.Close
						'Call Carrega_Banco
						
						
						Call Executar(lstrSql)
						
						'lstrSql = "SELECT * FROM indicadores_dicficdmic WHERE id >=45505 and ano = " & Me.txtMesAnoInd.Text
						'Call Conectar(lstrSql, lrstAux)
						'Call BarraProgresso(Me.ProgressBar, Me.lblPerc, Me.lblInfo, 0, .RecordCount)
						'
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
					End While
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Sub
	
	Private Sub BuscaConsIdUnidId(ByVal astrGrupo As String, ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByRef alngConsId As Integer, ByRef alngUnidId As Integer, ByRef astrGruTar As String)
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		'
		'--- Busca a Tensao da Unidade Consumidora
		lstrSql = ""
		lstrSql = lstrSql & "SELECT zona,livro,conta,cons_id,unid_id,grupo,ta "
		lstrSql = lstrSql & "  FROM unid" & LCase(astrGrupo)
		lstrSql = lstrSql & " WHERE zona  = '" & astrZona & "' "
		lstrSql = lstrSql & "   AND livro = '" & astrLivro & "' "
		lstrSql = lstrSql & "   AND conta = '" & astrConta & "'"
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			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"'
					alngConsId = CInt(IIf(IsDbNull(.Fields("cons_id").value), 0, .Fields("cons_id").value))
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					alngUnidId = CInt(IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value))
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					astrGruTar = Trim(IIf(IsDbNull(.Fields("ta").value), "01B100", .Fields("ta").value))
					astrGruTar = IIf(astrGruTar <> "", astrGruTar, "01B100") 'caso não for nulo e tiver em branco então joga valor padrão
					astrGruTar = Mid(astrGruTar, 3, 2)
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
	End Sub
	
	Private Function getNumRows(ByVal astrFile As String) As Integer
		Dim lintARQ As Short
		Dim llngRows As Integer
		Dim lstrTemp As String
		'On Error GoTo ErroNumRows
		llngRows = 0
		lintARQ = FreeFile
		FileOpen(lintARQ, astrFile, OpenMode.Input)
		While Not EOF(lintARQ)
			lstrTemp = LineInput(lintARQ)
			llngRows = llngRows + 1
			System.Windows.Forms.Application.DoEvents()
		End While
ErroNumRows: 
		If Err.Number > 0 Then
			Call MsgBox(Err.Number & " - " & GetErrosVB(Err.Number, Err.Description), MsgBoxStyle.Information, gstrTituloMensagem)
		End If
		FileClose(lintARQ)
		getNumRows = llngRows
	End Function
	
	Private Function TrataCSV(ByRef strLinha As String) As String()
		Dim arrItens() As String
		Dim strTemp As String
		Dim I As Short
		Dim chkAspa As Boolean
		Dim teste As String
		
		chkAspa = False
		strTemp = ""
		arrItens = Split(strLinha, ";")
		
		For I = 0 To UBound(arrItens)
			If Not chkAspa Then
				If (VB.Left(arrItens(I), 1) = """" And VB.Right(arrItens(I), 1) = """") Or (VB.Left(arrItens(I), 1) <> """" And VB.Right(arrItens(I), 1) <> """") Then
					strTemp = strTemp & "$$$" & Replace(arrItens(I), """", "")
				ElseIf VB.Left(arrItens(I), 1) = """" Then 
					chkAspa = True
					strTemp = strTemp & "$$$" & Replace(arrItens(I), """", "")
				End If
			Else
				strTemp = strTemp & "," & Replace(arrItens(I), """", "")
				If VB.Right(arrItens(I), 1) = """" Then chkAspa = False
			End If
		Next 
		TrataCSV = Split(IIf(VB.Left(strTemp, 3) = "$$$", VB.Right(strTemp, Len(strTemp) - 3), ""), "$$$")
	End Function
	
	Private Sub frmIndContinuidadeNovo_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		Call CenterForm(Me)
		lrstAux = New ADODB.Recordset
		'Seta Mês e Ano atual no filtro
		idteBase = BuscaHoraBD
		Me.txtMesAnoInd.Text = VB6.Format(DateSerial(Year(idteBase), Month(idteBase) - 2, VB.Day(idteBase)), "yyyy")
		Call statusCampo(Me.txtMesAnoInd, True)
		Call statusCampo(Me.txtArq, True)
		iintMesIniPerSeco = Val(LeConfig("MES_INI_PERIODO_SECO"))
		iintMesFimPerSeco = iintMesIniPerSeco + 6
		'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
		ifrmRelIndContinuidade = New FrmRelatorio
		Call NomeArquivoCsv()
	End Sub
	
	Private Sub frmIndContinuidadeNovo_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		'UPGRADE_NOTE: Object ifrmRelIndContinuidade 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"'
		ifrmRelIndContinuidade = Nothing
	End Sub
	
	Private Sub txtMesAnoInd_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtMesAnoInd.Enter
		With Me.txtMesAnoInd
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtMesAnoInd_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtMesAnoInd.Leave
		With Me.txtMesAnoInd
			'.Text = FormataData(Me.txtMesAnoInd, 1)
			If Len(Trim(.Text)) = 0 Then
				.Text = VB6.Format(DateSerial(Year(Now), Month(Now) - 2, VB.Day(Now)), "yyyy")
			End If
		End With
	End Sub
	
	Private Sub frmIndContinuidadeNovo_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii = System.Windows.Forms.Keys.Return Or KeyAscii = System.Windows.Forms.Keys.Tab Then 'Identifica o Enter
			Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
			KeyAscii = 0 'Zera KeyAscii para eliminar o Enter
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	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 statusCampo(ByVal actlCampo As System.Windows.Forms.Control, ByVal ablnStatus As Boolean)
		With actlCampo
			.Enabled = ablnStatus
			.BackColor = System.Drawing.ColorTranslator.FromOle(IIf(ablnStatus, System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.Window), System.Drawing.ColorTranslator.ToOle(System.Drawing.SystemColors.InactiveBorder)))
			.Text = IIf(ablnStatus, .Text, "")
		End With
	End Sub
	
	Private Sub cmdArquivo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdArquivo.Click
		'UPGRADE_WARNING: CommonDialog variable was not upgraded Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="671167DC-EA81-475D-B690-7A40C7BF4A23"'
		With Me.dialArq
			.DefaultExt = "TXT"
			'UPGRADE_WARNING: Filter has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
			.Filter = "*." & .DefaultExt
			.FileName = Me.txtArq.Text
			.Title = "Importar arquivos de indicadores de continuidade"
			Call .ShowDialog()
			Me.txtArq.Text = .FileName
		End With
	End Sub
	
	Private Sub LigDes(ByVal ablnModo As Boolean)
		Me.cmdFechar.Enabled = ablnModo
		Me.cmdArquivo.Enabled = ablnModo
		Me.cmdProcessar.Enabled = ablnModo
		Me.cmdImprimir.Enabled = ablnModo
		Me.txtMesAnoInd.Enabled = ablnModo
		Me.chkDicri.Enabled = ablnModo
		Me.txtArq.Enabled = ablnModo
		Me.cmdArqCsv.Enabled = ablnModo
		Me.cmdExporta.Enabled = ablnModo
	End Sub
	
	Private Sub NomeArquivoCsv()
		Dim lstrAux As String
		idteBase = BuscaHoraBD
		If Me.chkDicri.CheckState = System.Windows.Forms.CheckState.Unchecked Then
			istrNmArq = "Dados_DIC_FIC_DMIC"
		Else
			istrNmArq = "Dados_DICRI"
		End If
		lstrAux = StrReverse(Me.txtArqCsv.Text)
		If Trim(lstrAux) <> "" Then
			Me.txtArqCsv.Text = StrReverse(Mid(lstrAux, CInt(InStr(lstrAux, "\")))) & istrNmArq & ".TXT"
		End If
		System.Windows.Forms.Application.DoEvents()
	End Sub
End Class