Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmRelSampNovo
	Inherits System.Windows.Forms.Form
	Private ifrmRelSamp As FrmRelatorio
	Private ifrmDir As frmDir
	Private istrCaminho As String
	Private istrTabela As String
	Private istrTab945 As String
	Private ilngLimRes As Integer
	Private ilngLimRur As Integer
	Private iblnExporta As Boolean
	
	Private Sub cmdExporta_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExporta.Click
		Dim lintRef As Short
		Dim lintCla As Short
		Dim lintMod As Short
		Dim lintSub As Short
		Dim lintDet As Short
		Dim lintPos As Short
		Dim ldblVlr As Double
		Dim lstrVlr As String
		'Controle de arquivos
		Dim lstrArq As String
		Dim lintArqReg As Short
		Dim lintArqRef As Short
		Dim lintMestre As Short
		Dim lintCadastro As Short
		Dim lstrLin As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		On Error GoTo ErroGeraArquivos
		Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
		Call LigDes(False)
		lrstAux = New ADODB.Recordset
		Me.lblInfoArq.Text = " Buscando os dados para exportação do samp referente ao mês/ano " & VB6.Format(Me.dtpMesAno.value, "MM/yyyy") & ", aguarde... "
		Call Me.lblInfoArq.Refresh()
		lstrSql = ""
		lstrSql = "SELECT * FROM " & gstrDataBase & ".`samp_exportacao` WHERE `ano_mes` = " & VB6.Format(Me.dtpMesAno.value, "yyyyMM") & " ORDER BY `sequencia` ASC "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					Call BarraProgresso((Me.ProgressBarArq), (Me.lblPercArq), (Me.lblInfoArq), 0, .RecordCount, " Exportando ")
					lintArqReg = FreeFile
					FileOpen(lintArqReg, Me.txtDir.Text & "\" & Me.txtArquivoRegular.Text, OpenMode.Output)
					lintArqRef = FreeFile
					FileOpen(lintArqRef, Me.txtDir.Text & "\" & Me.txtArquivoRefaturado.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"'
						lintRef = IIf(IsDbNull(.Fields("refaturado").value), 0, .Fields("refaturado").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"'
						lintCla = IIf(IsDbNull(.Fields("classe").value), 0, .Fields("classe").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"'
						lintMod = IIf(IsDbNull(.Fields("modalidade").value), 0, .Fields("modalidade").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"'
						lintSub = IIf(IsDbNull(.Fields("sub_grupo").value), 0, .Fields("sub_grupo").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lintDet = IIf(IsDbNull(.Fields("detalhe").value), 0, .Fields("detalhe").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"'
						lintPos = IIf(IsDbNull(.Fields("posto").value), 0, .Fields("posto").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 = IIf(IsDbNull(.Fields("valor").value), 0, .Fields("valor").value)
						If lintDet = 1 Or lintDet = 2 Or lintDet = 3 Or lintDet = 4 Or lintDet = 7 Or lintDet = 10 Or lintDet = 15 Or lintDet = 21 Or lintDet = 22 Or lintDet = 23 Or lintDet = 24 Then
							lstrVlr = Replace(Replace(VB6.Format(ldblVlr, "#,##0"), ".", ""), ",", VB6.GetItemString(Me.cmbCaracter, Me.cmbCaracter.SelectedIndex))
						Else
							If Me.chkCasaDecimal.CheckState = System.Windows.Forms.CheckState.Unchecked Then
								If lintDet = 5 Or lintDet = 6 Or lintDet = 8 Or lintDet = 9 Or lintDet = 11 Or lintDet = 12 Or lintDet = 13 Or lintDet = 14 Or lintDet = 16 Or lintDet = 17 Or lintDet = 18 Or lintDet = 19 Or lintDet = 25 Then
									lstrVlr = Replace(VB6.Format(ldblVlr, "#,##0.00"), ".", "")
								Else
									lstrVlr = Replace(Replace(VB6.Format(ldblVlr * 100, "###,###0"), ".", ""), ",", "")
								End If
							Else
								lstrVlr = Replace(Replace(VB6.Format(ldblVlr, "#,##0.00"), ".", ""), ",", VB6.GetItemString(Me.cmbCaracter, Me.cmbCaracter.SelectedIndex))
							End If
						End If
						If Me.chkExportaDescritivo.CheckState = System.Windows.Forms.CheckState.Unchecked Then
							lstrLin = lintCla & ";" & lintMod & ";" & lintSub & ";" & lintDet & ";" & lintPos & ";" & lstrVlr
						Else
							lstrLin = ""
							lstrLin = lstrLin & lintCla & ";" & GetExpSampClasses(lintCla) & ";"
							lstrLin = lstrLin & lintMod & ";" & GetExpModalidade(lintMod) & ";"
							lstrLin = lstrLin & lintSub & ";" & GetExpSubGrupo(lintSub) & ";"
							lstrLin = lstrLin & lintDet & ";" & GetExpDetalheFornecimento(lintDet) & ";"
							lstrLin = lstrLin & lintPos & ";" & GetExpPostoTarifario(lintPos) & ";" & lstrVlr
						End If
						If lintRef = 0 Then
							PrintLine(lintArqReg, lstrLin)
						ElseIf lintRef = 1 Then 
							PrintLine(lintArqRef, lstrLin)
						End If
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBarArq), (Me.lblPercArq), (Me.lblInfoArq), 1,  , " Exportando ")
					End While
					FileClose(lintArqReg)
					FileClose(lintArqRef)
					Me.lblInfoArq.Text = Me.lblInfoArq.Text & " *** Finalizado **** "
					Call MsgBox("Arquivos gerados com sucesso!", MsgBoxStyle.Information, gstrTituloMensagem)
				Else
					Me.Cursor = System.Windows.Forms.Cursors.Default
					Call MsgBox("Não foi encotrado dados para serem exportados!", MsgBoxStyle.Information, gstrTituloMensagem)
				End If
				Call .Close()
			End If
		End With
ErroGeraArquivos: 
		Me.Cursor = System.Windows.Forms.Cursors.Default
		Call LigDes(True)
		If myConC.Errors.Count > 0 Then
			Call MsgBox("Código: " & myConC.Errors.Item(myConC.Errors.Count - 1).NativeError & vbCrLf & "Descrição:" & myConC.Errors.Item(myConC.Errors.Count - 1).Description, MsgBoxStyle.Critical, gstrTituloMensagem)
		ElseIf Err.Number > 0 Then 
			Call MsgBox(Err.Number & " - " & GetErrosVB(Err.Number, Err.Description), MsgBoxStyle.Critical, 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 Sub cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click
		Call Me.Close()
	End Sub
	
	Private Sub cmdImprimir_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdImprimir.Click
		Call CriaTabelaTemporaria()
		If MontaTabela Then
			Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
			Call LigDes(False)
			ifrmRelSamp.quem_chama = Me
			With ifrmRelSamp
				.VS.Font = VB6.FontChangeName(.VS.Font, "Arial")
				.VS.TableBorder = VSVIEW6.TableBorderSettings.tbAll
				.VS.PageBorder = VSVIEW6.TableBorderSettings.tbNone
				.VS.Orientation = VSVIEW6.OrientationSettings.orLandscape
				.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)
				Call .VS.StartDoc()
				.VS.Font = VB6.FontChangeSize(.VS.Font, 8)
				If Me.chkGrupoBx.CheckState = System.Windows.Forms.CheckState.Checked Then
					Call Cabecalho_Relatorio(.VS, "Informações para Preenchimento da Planilha do SAMP", "Mês/Ano Referência: " & VB6.Format(Me.dtpMesAno.value, "MM/yyyy"), "3", False, "Grupo B - Baixa Renda REN 945")
					Call LineFeed(.VS, 2)
					.VS.MarginLeft = "15mm"
					Call GeraImpressaoBaixaRenda()
					Call .VS.NewPage()
				End If
				If Me.chkGrupoB.CheckState = System.Windows.Forms.CheckState.Checked Then
					Call Cabecalho_Relatorio(.VS, "Informações para Preenchimento da Planilha do SAMP", "Mês/Ano Referência: " & VB6.Format(Me.dtpMesAno.value, "MM/yyyy"), "3", False, "Grupo B")
					Call LineFeed(.VS, 2)
					.VS.MarginLeft = "15mm"
					Call GeraImpressaoGrupoB()
					Call .VS.NewPage()
				End If
				If Me.chkMicroGeracao.CheckState = System.Windows.Forms.CheckState.Checked Then
					Call Cabecalho_Relatorio(.VS, "Informações para Preenchimento da Planilha do SAMP", "Mês/Ano Referência: " & VB6.Format(Me.dtpMesAno.value, "MM/yyyy"), "3", False, "Grupo B - Micro Geração")
					Call LineFeed(.VS, 2)
					.VS.MarginLeft = "10mm"
					Call GeraImpressaoGrupoBMicroGeracao()
					Call .VS.NewPage()
				End If
				If Me.chkIrrigante.CheckState = System.Windows.Forms.CheckState.Checked Then
					Call Cabecalho_Relatorio(.VS, "Informações para Preenchimento da Planilha do SAMP", "Mês/Ano Referência: " & VB6.Format(Me.dtpMesAno.value, "MM/yyyy"), "3", False, "Grupo B - Irrg.Aquic.")
					Call LineFeed(.VS, 2)
					.VS.MarginLeft = "10mm"
					Call GeraImpressaoGrupoBIrrigacaoAquicultura()
					Call .VS.NewPage()
				End If
				If Me.chkTarifaBranca.CheckState = System.Windows.Forms.CheckState.Checked Then
					Call Cabecalho_Relatorio(.VS, "Informações para Preenchimento da Planilha do SAMP", "Mês/Ano Referência: " & VB6.Format(Me.dtpMesAno.value, "MM/yyyy"), "3", False, "Grupo B - Tarifa Branca")
					Call LineFeed(.VS, 2)
					.VS.MarginLeft = "10mm"
					Call GeraImpressaoGrupoBTarifaBranca()
					Call .VS.NewPage()
				End If
				
				If Me.chkUsina.CheckState = System.Windows.Forms.CheckState.Checked Then
					Call Cabecalho_Relatorio(.VS, "Informações para Preenchimento da Planilha do SAMP", "Mês/Ano Referência: " & VB6.Format(Me.dtpMesAno.value, "MM/yyyy"), "3", False, "Usinas")
					Call LineFeed(.VS, 2)
					.VS.MarginLeft = "30mm"
					Call GeraImpressaoUsinas()
					Call .VS.NewPage()
				End If
				If Me.chkGrupoAConvencional.CheckState = System.Windows.Forms.CheckState.Checked Then
					Call Cabecalho_Relatorio(.VS, "Informações para Preenchimento da Planilha do SAMP", "Mês/Ano Referência: " & VB6.Format(Me.dtpMesAno.value, "MM/yyyy"), "3", False, "Grupo A - Convencional")
					Call LineFeed(.VS, 2)
					.VS.MarginLeft = "7mm"
					Call GeraImpressaoGrupoAConvencional()
					Call .VS.NewPage()
				End If
				If Me.chkGrupoAHorosazonal.CheckState = System.Windows.Forms.CheckState.Checked Then
					Call Cabecalho_Relatorio(.VS, "Informações para Preenchimento da Planilha do SAMP", "Mês/Ano Referência: " & VB6.Format(Me.dtpMesAno.value, "MM/yyyy"), "3", False, "Grupo A - Horo sazonal")
					Call LineFeed(.VS, 2)
					.VS.MarginLeft = "7mm"
					Call GeraImpressaoGrupoAHorossazonal()
					Call .VS.NewPage()
				End If
				If Me.chkGrupoALivre.CheckState = System.Windows.Forms.CheckState.Checked Then
					Call Cabecalho_Relatorio(.VS, "Informações para Preenchimento da Planilha do SAMP", "Mês/Ano Referência: " & VB6.Format(Me.dtpMesAno.value, "MM/yyyy"), "3", False, "Grupo A - Livre/Parc.Cativo")
					Call LineFeed(.VS, 2)
					.VS.MarginLeft = "10mm"
					Call GeraImpressaoGrupoALivre()
				End If
				'
				Call GravaExportacao()
				Call .VS.EndDoc()
				Call .Show()
			End With
			Call LigDes(True)
			Me.Cursor = System.Windows.Forms.Cursors.Default
		End If
	End Sub
	
	Private Sub GeraImpressaoBaixaRenda()
		Dim lstrTabAux As String
		Dim lstrTabTit As String
		Dim lstrTamCol As String
		Dim lintRefatu As Short
		Dim lintOrdCla As Short
		Dim lstrDesCla As String
		'
		Dim ldblQtdCon As Double
		'Consumos
		Dim ldblQtdkWh As Double
		Dim ldblVlrkWh As Double
		Dim ldblVlrBan As Double
		Dim ldblVlrRec As Double
		'Reativos
		Dim ldblQtdRev As Double
		Dim ldblVlrRev As Double
		'Tributos
		Dim ldblVlrIcm As Double
		Dim ldblVlrPis As Double
		Dim ldblVlrCof As Double
		'Totais
		Dim ldblTotQtdCon As Double
		'Consumos
		Dim ldblTotQtdkWh As Double
		Dim ldblTotVlrkWh As Double
		Dim ldblTotVlrBan As Double
		Dim ldblTotVlrRec As Double
		'Reativos
		Dim ldblTotQtdRev As Double
		Dim ldblTotVlrRev As Double
		'Tributos
		Dim ldblTotVlrIcm As Double
		Dim ldblTotVlrPis As Double
		Dim ldblTotVlrCof As Double
		'Auxiliares
		Dim lintAux As Short
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrTamCol = "<35mm |>15mm  |>25mm|>25mm   |>25mm        |>25mm  |>20mm  |>20mm    |>25mm|>25mm|>25mm;"
		lstrTabTit = "Classe|Nº Cons|kWh  |kWh (R$)|Bandeira (R$)|Receita|Reverso|Rev. (R$)|ICMS |PIS  |COFINS"
		For lintRefatu = 0 To 1
			If lintRefatu = 1 Then
				For lintAux = 1 To 3
					ifrmRelSamp.VS.Paragraph = ""
				Next 
			End If
			'
			lstrSql = ""
			lstrSql = lstrSql & "  SELECT `ord_classe`, `ds_classe`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`faixa`) `ncons`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`consumo`) `qkwh_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`valor`) `vkwh_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`bandeira`) `vkwh_fat_ban`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`receita`) `vreceita`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`icms`) `icms`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`pis`) `pis`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`cofins`) `cofins` " & vbCrLf
			lstrSql = lstrSql & "    FROM " & gstrDataBase & "." & istrTab945 & " " & vbCrLf
			lstrSql = lstrSql & "   WHERE `refaturado` = " & lintRefatu & " " & vbCrLf
			lstrSql = lstrSql & "GROUP BY `ord_classe`, `ds_classe` " & vbCrLf
			lstrSql = lstrSql & "ORDER BY `ord_classe` ASC, `ds_classe` ASC "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeBold(.Font, True)
							.Font = VB6.FontChangeSize(.Font, 10)
							.Paragraph = IIf(lintRefatu = 1, "REFATURAMENTO", "REGULAR")
							.Font = VB6.FontChangeSize(.Font, 8)
							.TableBorder = VSVIEW6.TableBorderSettings.tbAll
							.Table = lstrTamCol & lstrTabTit
							.Font = VB6.FontChangeBold(.Font, False)
						End With
						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"'
							lintOrdCla = CShort(IIf(IsDbNull(.Fields("ord_classe").value), 0, .Fields("ord_classe").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"'
							lstrDesCla = CStr(IIf(IsDbNull(.Fields("ds_classe").value), "", .Fields("ds_classe").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"'
							ldblQtdCon = CDbl(IIf(IsDbNull(.Fields("ncons").value), 0, .Fields("ncons").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"'
							ldblQtdkWh = CDbl(IIf(IsDbNull(.Fields("qkwh_fat").value), 0, .Fields("qkwh_fat").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"'
							ldblVlrkWh = CDbl(IIf(IsDbNull(.Fields("vkwh_fat").value), 0, .Fields("vkwh_fat").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"'
							ldblVlrBan = CDbl(IIf(IsDbNull(.Fields("vkwh_fat_ban").value), 0, .Fields("vkwh_fat_ban").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"'
							ldblVlrRec = CDbl(IIf(IsDbNull(.Fields("vreceita").value), 0, .Fields("vreceita").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"'
							ldblVlrIcm = CDbl(IIf(IsDbNull(.Fields("icms").value), 0, .Fields("icms").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"'
							ldblVlrPis = CDbl(IIf(IsDbNull(.Fields("pis").value), 0, .Fields("pis").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"'
							ldblVlrCof = CDbl(IIf(IsDbNull(.Fields("cofins").value), 0, .Fields("cofins").value))
							
							ldblTotQtdCon = ldblTotQtdCon + ldblQtdCon
							ldblTotQtdkWh = ldblTotQtdkWh + ldblQtdkWh
							ldblTotVlrkWh = ldblTotVlrkWh + ldblVlrkWh
							ldblTotVlrBan = ldblTotVlrBan + ldblVlrBan
							ldblTotVlrRec = ldblTotVlrRec + ldblVlrRec
							ldblTotQtdRev = ldblTotQtdRev + ldblQtdRev
							ldblTotVlrRev = ldblTotVlrRev + ldblVlrRev
							ldblTotVlrIcm = ldblTotVlrIcm + ldblVlrIcm
							ldblTotVlrPis = ldblTotVlrPis + ldblVlrPis
							ldblTotVlrCof = ldblTotVlrCof + ldblVlrCof
							'Detalhe
							lstrTabAux = ""
							lstrTabAux = lstrTabAux & lstrDesCla & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdCon, "###,###,###,##0") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWh, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWh, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrBan, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrRec, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdRev, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrRev, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrIcm, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrPis, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrCof, "#,##0.00")
							ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
							Call .MoveNext()
						End While
						lstrTabAux = ""
						lstrTabAux = lstrTabAux & "Total Geral|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdCon, "###,###,###,##0") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWh, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWh, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrBan, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrRec, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdRev, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrRev, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrIcm, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrPis, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrCof, "#,##0.00")
						ifrmRelSamp.VS.Font = VB6.FontChangeBold(ifrmRelSamp.VS.Font, True)
						ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
						ifrmRelSamp.VS.Font = VB6.FontChangeBold(ifrmRelSamp.VS.Font, False)
					Else
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeBold(.Font, True)
							.Font = VB6.FontChangeSize(.Font, 10)
							.Paragraph = IIf(lintRefatu = 1, "REFATURAMENTO", "REGULAR")
							.Font = VB6.FontChangeSize(.Font, 8)
							.TableBorder = VSVIEW6.TableBorderSettings.tbAll
							.Table = lstrTamCol & lstrTabTit
							.Font = VB6.FontChangeBold(.Font, False)
						End With
						lstrTabAux = ""
						lstrTabAux = lstrTabAux & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "###,###,###,##0") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00")
						ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
					End If
					Call .Close()
				End If
			End With
		Next lintRefatu
		'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 GeraImpressaoGrupoB()
		Dim lstrTabAux As String
		Dim lstrTabTit As String
		Dim lstrTamCol As String
		Dim lintRefatu As Short
		Dim lintOrdCla As Short
		Dim lstrDesCla As String
		'
		Dim ldblQtdCon As Double
		'Consumos
		Dim ldblQtdkWh As Double
		Dim ldblVlrkWh As Double
		Dim ldblVlrBan As Double
		Dim ldblVlrRec As Double
		'Reativos
		Dim ldblQtdRev As Double
		Dim ldblVlrRev As Double
		'Tributos
		Dim ldblVlrIcm As Double
		Dim ldblVlrPis As Double
		Dim ldblVlrCof As Double
		'Totais
		Dim ldblTotQtdCon(2) As Double
		'Consumos
		Dim ldblTotQtdkWh(2) As Double
		Dim ldblTotVlrkWh(2) As Double
		Dim ldblTotVlrBan(2) As Double
		Dim ldblTotVlrRec(2) As Double
		'Reativos
		Dim ldblTotQtdRev(2) As Double
		Dim ldblTotVlrRev(2) As Double
		'Tributos
		Dim ldblTotVlrIcm(2) As Double
		Dim ldblTotVlrPis(2) As Double
		Dim ldblTotVlrCof(2) As Double
		'Auxiliares
		Dim lblnSubTot As Boolean
		Dim lintTotAux As Short
		Dim lintAux As Short
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrTamCol = "<35mm |>15mm  |>25mm|>25mm   |>25mm        |>25mm  |>20mm  |>20mm    |>25mm|>25mm|>25mm;"
		lstrTabTit = "Classe|Nº Cons|kWh  |kWh (R$)|Bandeira (R$)|Receita|Reverso|Rev. (R$)|ICMS |PIS  |COFINS"
		For lintRefatu = 0 To 1
			lblnSubTot = True
			If lintRefatu = 1 Then
				For lintAux = 1 To 3
					ifrmRelSamp.VS.Paragraph = ""
				Next 
			End If
			For lintTotAux = 0 To 2
				ldblTotQtdCon(lintTotAux) = 0
				ldblTotQtdkWh(lintTotAux) = 0
				ldblTotVlrkWh(lintTotAux) = 0
				ldblTotVlrBan(lintTotAux) = 0
				ldblTotVlrRec(lintTotAux) = 0
				ldblTotQtdRev(lintTotAux) = 0
				ldblTotVlrRev(lintTotAux) = 0
				ldblTotVlrIcm(lintTotAux) = 0
				ldblTotVlrPis(lintTotAux) = 0
				ldblTotVlrCof(lintTotAux) = 0
			Next lintTotAux
			'
			lstrSql = ""
			lstrSql = lstrSql & "  SELECT " & vbCrLf
			lstrSql = lstrSql & "        `ord_classe`, " & vbCrLf
			lstrSql = lstrSql & "        `ds_classe`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(if(`qkwh_fat` < 0, 0, 1)) `ncons`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`qkwh_fat`) `qkwh_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkwh_fat`) `vkwh_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkwh_fat_ban`) `vkwh_fat_ban`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`receita_fp`) `vreceita`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`qkwh_reverso`) `qkwh_reverso`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkwh_reverso`) `vkwh_reverso`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`icms`) `icms`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`pis`) `pis`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`cofins`) `cofins` " & vbCrLf
			lstrSql = lstrSql & "    FROM " & gstrDataBase & "." & istrTabela & " " & vbCrLf
			lstrSql = lstrSql & "   WHERE `grupo` = 'B' " & vbCrLf
			lstrSql = lstrSql & "     AND `refaturado` = " & lintRefatu & " " & vbCrLf
			lstrSql = lstrSql & "     AND `usinas` <> 1 " & vbCrLf
			lstrSql = lstrSql & "     AND `irrigacao_aquicultura` <> 1 " & vbCrLf
			lstrSql = lstrSql & "     AND `tarifa_branca` <> 1 " & vbCrLf
			lstrSql = lstrSql & "GROUP BY `ord_classe`, `ds_classe` " & vbCrLf
			lstrSql = lstrSql & "ORDER BY `ord_classe` ASC, `ds_classe` ASC "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeBold(.Font, True)
							.Font = VB6.FontChangeSize(.Font, 10)
							.Paragraph = IIf(lintRefatu = 1, "REFATURAMENTO", "REGULAR")
							.Font = VB6.FontChangeSize(.Font, 8)
							.TableBorder = VSVIEW6.TableBorderSettings.tbAll
							.Table = lstrTamCol & lstrTabTit
							.Font = VB6.FontChangeBold(.Font, False)
						End With
						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"'
							lintOrdCla = CShort(IIf(IsDbNull(.Fields("ord_classe").value), 0, .Fields("ord_classe").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"'
							lstrDesCla = CStr(IIf(IsDbNull(.Fields("ds_classe").value), "", .Fields("ds_classe").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"'
							ldblQtdCon = CDbl(IIf(IsDbNull(.Fields("ncons").value), 0, .Fields("ncons").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"'
							ldblQtdkWh = CDbl(IIf(IsDbNull(.Fields("qkwh_fat").value), 0, .Fields("qkwh_fat").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"'
							ldblVlrkWh = CDbl(IIf(IsDbNull(.Fields("vkwh_fat").value), 0, .Fields("vkwh_fat").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"'
							ldblVlrBan = CDbl(IIf(IsDbNull(.Fields("vkwh_fat_ban").value), 0, .Fields("vkwh_fat_ban").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"'
							ldblVlrRec = CDbl(IIf(IsDbNull(.Fields("vreceita").value), 0, .Fields("vreceita").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"'
							ldblQtdRev = CDbl(IIf(IsDbNull(.Fields("qkwh_reverso").value), 0, .Fields("qkwh_reverso").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"'
							ldblVlrRev = CDbl(IIf(IsDbNull(.Fields("vkwh_reverso").value), 0, .Fields("vkwh_reverso").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"'
							ldblVlrIcm = CDbl(IIf(IsDbNull(.Fields("icms").value), 0, .Fields("icms").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"'
							ldblVlrPis = CDbl(IIf(IsDbNull(.Fields("pis").value), 0, .Fields("pis").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"'
							ldblVlrCof = CDbl(IIf(IsDbNull(.Fields("cofins").value), 0, .Fields("cofins").value))
							If lintOrdCla = 10 Then
								lintTotAux = 1
							ElseIf lintOrdCla >= 11 And lintOrdCla < 30 Then 
								lintTotAux = 0
							Else
								lintTotAux = 2
							End If
							ldblTotQtdCon(lintTotAux) = ldblTotQtdCon(lintTotAux) + ldblQtdCon
							ldblTotQtdkWh(lintTotAux) = ldblTotQtdkWh(lintTotAux) + ldblQtdkWh
							ldblTotVlrkWh(lintTotAux) = ldblTotVlrkWh(lintTotAux) + ldblVlrkWh
							ldblTotVlrBan(lintTotAux) = ldblTotVlrBan(lintTotAux) + ldblVlrBan
							ldblTotVlrRec(lintTotAux) = ldblTotVlrRec(lintTotAux) + ldblVlrRec
							ldblTotQtdRev(lintTotAux) = ldblTotQtdRev(lintTotAux) + ldblQtdRev
							ldblTotVlrRev(lintTotAux) = ldblTotVlrRev(lintTotAux) + ldblVlrRev
							ldblTotVlrIcm(lintTotAux) = ldblTotVlrIcm(lintTotAux) + ldblVlrIcm
							ldblTotVlrPis(lintTotAux) = ldblTotVlrPis(lintTotAux) + ldblVlrPis
							ldblTotVlrCof(lintTotAux) = ldblTotVlrCof(lintTotAux) + ldblVlrCof
							'Subtotais
							If lintOrdCla >= 30 And lblnSubTot Then
								lstrTabAux = ""
								lstrTabAux = lstrTabAux & "Total Bx.Renda|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdCon(0), "###,###,###,##0") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWh(0), "#,###0.000") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWh(0), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrBan(0), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrRec(0), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdRev(0), "#,###0.000") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrRev(0), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrIcm(0), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrPis(0), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrCof(0), "#,##0.00")
								ifrmRelSamp.VS.Font = VB6.FontChangeBold(ifrmRelSamp.VS.Font, True)
								ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
								lstrTabAux = ""
								lstrTabAux = lstrTabAux & "Total Residencial|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdCon(0) + ldblTotQtdCon(1), "###,###,###,##0") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWh(0) + ldblTotQtdkWh(1), "#,###0.000") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWh(0) + ldblTotVlrkWh(1), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrBan(0) + ldblTotVlrBan(1), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrRec(0) + ldblTotVlrRec(1), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdRev(0) + ldblTotQtdRev(1), "#,###0.000") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrRev(0) + ldblTotVlrRev(1), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrIcm(0) + ldblTotVlrIcm(1), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrPis(0) + ldblTotVlrPis(1), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrCof(0) + ldblTotVlrCof(1), "#,##0.00")
								ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
								ifrmRelSamp.VS.Font = VB6.FontChangeBold(ifrmRelSamp.VS.Font, False)
								lblnSubTot = False
							End If
							'Detalhe
							lstrTabAux = ""
							lstrTabAux = lstrTabAux & lstrDesCla & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdCon, "###,###,###,##0") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWh, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWh, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrBan, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrRec, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdRev, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrRev, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrIcm, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrPis, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrCof, "#,##0.00")
							ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
							Call .MoveNext()
						End While
						lstrTabAux = ""
						lstrTabAux = lstrTabAux & "Total Geral|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdCon(0) + ldblTotQtdCon(1) + ldblTotQtdCon(2), "###,###,###,##0") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWh(0) + ldblTotQtdkWh(1) + ldblTotQtdkWh(2), "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWh(0) + ldblTotVlrkWh(1) + ldblTotVlrkWh(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrBan(0) + ldblTotVlrBan(1) + ldblTotVlrBan(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrRec(0) + ldblTotVlrRec(1) + ldblTotVlrRec(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdRev(0) + ldblTotQtdRev(1) + ldblTotQtdRev(2), "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrRev(0) + ldblTotVlrRev(1) + ldblTotVlrRev(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrIcm(0) + ldblTotVlrIcm(1) + ldblTotVlrIcm(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrPis(0) + ldblTotVlrPis(1) + ldblTotVlrPis(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrCof(0) + ldblTotVlrCof(1) + ldblTotVlrCof(2), "#,##0.00")
						ifrmRelSamp.VS.Font = VB6.FontChangeBold(ifrmRelSamp.VS.Font, True)
						ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
						ifrmRelSamp.VS.Font = VB6.FontChangeBold(ifrmRelSamp.VS.Font, False)
					Else
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeBold(.Font, True)
							.Font = VB6.FontChangeSize(.Font, 10)
							.Paragraph = IIf(lintRefatu = 1, "REFATURAMENTO", "REGULAR")
							.Font = VB6.FontChangeSize(.Font, 8)
							.TableBorder = VSVIEW6.TableBorderSettings.tbAll
							.Table = lstrTamCol & lstrTabTit
							.Font = VB6.FontChangeBold(.Font, False)
						End With
						lstrTabAux = ""
						lstrTabAux = lstrTabAux & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "###,###,###,##0") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00")
						ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
					End If
					Call .Close()
				End If
			End With
		Next lintRefatu
		'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 GeraImpressaoGrupoBMicroGeracao()
		Dim lstrTabAux As String
		Dim lstrTabTit As String
		Dim lstrTamCol As String
		Dim lintRefatu As Short
		Dim lintOrdCla As Short
		Dim lstrDesCla As String
		'
		Dim ldblQtdCon As Double
		'Consumos
		Dim ldblQtdkWhLido As Double
		Dim ldblQtdkWh As Double
		Dim ldblVlrkWh As Double
		Dim ldblVlrBan As Double
		'Reativos
		Dim ldblQtdRev As Double
		Dim ldblVlrRev As Double
		'Tributos
		Dim ldblVlrIcm As Double
		Dim ldblVlrPis As Double
		Dim ldblVlrCof As Double
		'
		Dim ldblVlrRec As Double
		'Totais
		Dim ldblTotQtdCon(2) As Double
		'Consumos
		Dim ldblTotQtdkWhLido(2) As Double
		Dim ldblTotQtdkWh(2) As Double
		Dim ldblTotVlrkWh(2) As Double
		Dim ldblTotVlrBan(2) As Double
		'Reativos
		Dim ldblTotQtdRev(2) As Double
		Dim ldblTotVlrRev(2) As Double
		'Tributos
		Dim ldblTotVlrIcm(2) As Double
		Dim ldblTotVlrPis(2) As Double
		Dim ldblTotVlrCof(2) As Double
		'
		Dim ldblTotReceita(2) As Double
		'Auxiliares
		Dim lblnSubTot As Boolean
		Dim lintTotAux As Short
		Dim lintAux As Short
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrTamCol = "<30mm |>15mm  |>25mm   |>25mm   |>25mm   |>23mm        |>25mm        |>25mm      |>25mm       |>17mm|>17mm|>17mm;"
		lstrTabTit = "Classe|Nº Cons|kWh Lido|kWh Fat.|kWh (R$)|Bandeira (R$)|Receita (R$) |Reverso kWh|Receita Rev.|ICMS |PIS  |COFINS"
		For lintRefatu = 0 To 1
			lblnSubTot = True
			If lintRefatu = 1 Then
				For lintAux = 1 To 3
					ifrmRelSamp.VS.Paragraph = ""
				Next 
			End If
			'
			lstrSql = ""
			lstrSql = lstrSql & "  SELECT " & vbCrLf
			lstrSql = lstrSql & "        `ord_classe`, " & vbCrLf
			lstrSql = lstrSql & "        `ds_classe`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(if(qkwh_fat<0,0,1)) `ncons`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(qkwh_cons) `qkwh_lid`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(qkwh_fat) `qkwh_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(vkwh_fat) `vkwh_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(vkwh_fat_ban) `vkwh_fat_ban`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(receita_fp) `vreceita`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(qkwh_reverso) `qkwh_reverso`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(vkwh_reverso) `vkwh_reverso`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(icms) `icms`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(pis) `pis`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(cofins) `cofins` " & vbCrLf
			lstrSql = lstrSql & "    FROM " & istrTabela & " " & vbCrLf
			lstrSql = lstrSql & "   WHERE `grupo` = 'B' " & vbCrLf
			lstrSql = lstrSql & "     AND `refaturado` = " & lintRefatu & " " & vbCrLf
			lstrSql = lstrSql & "     AND `micro_geracao` = 1 " & vbCrLf
			lstrSql = lstrSql & "GROUP BY `ord_classe`, `ds_classe` " & vbCrLf
			lstrSql = lstrSql & "ORDER BY `ord_classe` ASC, `ds_classe` ASC "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeBold(.Font, True)
							.Font = VB6.FontChangeSize(.Font, 10)
							.Paragraph = IIf(lintRefatu = 1, "REFATURAMENTO", "REGULAR")
							.Font = VB6.FontChangeSize(.Font, 8)
							.TableBorder = VSVIEW6.TableBorderSettings.tbAll
							.Table = lstrTamCol & lstrTabTit
							.Font = VB6.FontChangeBold(.Font, False)
						End With
						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"'
							lintOrdCla = CShort(IIf(IsDbNull(.Fields("ord_classe").value), 0, .Fields("ord_classe").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"'
							lstrDesCla = CStr(IIf(IsDbNull(.Fields("ds_classe").value), "", .Fields("ds_classe").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"'
							ldblQtdCon = CDbl(IIf(IsDbNull(.Fields("ncons").value), 0, .Fields("ncons").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"'
							ldblQtdkWhLido = CDbl(IIf(IsDbNull(.Fields("qkwh_lid").value), 0, .Fields("qkwh_lid").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"'
							ldblQtdkWh = CDbl(IIf(IsDbNull(.Fields("qkwh_fat").value), 0, .Fields("qkwh_fat").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"'
							ldblVlrkWh = CDbl(IIf(IsDbNull(.Fields("vkwh_fat").value), 0, .Fields("vkwh_fat").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"'
							ldblVlrBan = CDbl(IIf(IsDbNull(.Fields("vkwh_fat_ban").value), 0, .Fields("vkwh_fat_ban").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"'
							ldblVlrRec = CDbl(IIf(IsDbNull(.Fields("vreceita").value), 0, .Fields("vreceita").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"'
							ldblQtdRev = CDbl(IIf(IsDbNull(.Fields("qkwh_reverso").value), 0, .Fields("qkwh_reverso").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"'
							ldblVlrRev = CDbl(IIf(IsDbNull(.Fields("vkwh_reverso").value), 0, .Fields("vkwh_reverso").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"'
							ldblVlrIcm = CDbl(IIf(IsDbNull(.Fields("icms").value), 0, .Fields("icms").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"'
							ldblVlrPis = CDbl(IIf(IsDbNull(.Fields("pis").value), 0, .Fields("pis").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"'
							ldblVlrCof = CDbl(IIf(IsDbNull(.Fields("cofins").value), 0, .Fields("cofins").value))
							If lintOrdCla = 10 Then
								lintTotAux = 1
							ElseIf lintOrdCla >= 20 And lintOrdCla < 30 Then 
								lintTotAux = 0
							Else
								lintTotAux = 2
							End If
							ldblTotQtdCon(lintTotAux) = ldblTotQtdCon(lintTotAux) + ldblQtdCon
							ldblTotQtdkWhLido(lintTotAux) = ldblTotQtdkWhLido(lintTotAux) + ldblQtdkWhLido
							ldblTotQtdkWh(lintTotAux) = ldblTotQtdkWh(lintTotAux) + ldblQtdkWh
							ldblTotVlrkWh(lintTotAux) = ldblTotVlrkWh(lintTotAux) + ldblVlrkWh
							ldblTotVlrBan(lintTotAux) = ldblTotVlrBan(lintTotAux) + ldblVlrBan
							ldblTotQtdRev(lintTotAux) = ldblTotQtdRev(lintTotAux) + ldblQtdRev
							ldblTotVlrRev(lintTotAux) = ldblTotVlrRev(lintTotAux) + ldblVlrRev
							ldblTotReceita(lintTotAux) = ldblTotReceita(lintTotAux) + ldblVlrRec
							ldblTotVlrIcm(lintTotAux) = ldblTotVlrIcm(lintTotAux) + ldblVlrIcm
							ldblTotVlrPis(lintTotAux) = ldblTotVlrPis(lintTotAux) + ldblVlrPis
							ldblTotVlrCof(lintTotAux) = ldblTotVlrCof(lintTotAux) + ldblVlrCof
							
							'Subtotais
							If lintOrdCla >= 30 And lblnSubTot Then
								lstrTabAux = ""
								lstrTabAux = lstrTabAux & "Total Bx.Renda|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdCon(0), "###,###,###,##0") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWhLido(0), "#,###0.000") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWh(0), "#,###0.000") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWh(0), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrBan(0), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotReceita(0), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdRev(0), "#,###0.000") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrRev(0), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrIcm(0), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrPis(0), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrCof(0), "#,##0.00")
								
								ifrmRelSamp.VS.Font = VB6.FontChangeBold(ifrmRelSamp.VS.Font, True)
								ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
								lstrTabAux = ""
								lstrTabAux = lstrTabAux & "Total Residencial|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdCon(0) + ldblTotQtdCon(1), "###,###,###,##0") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWhLido(0) + ldblTotQtdkWhLido(1), "#,###0.000") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWh(0) + ldblTotQtdkWh(1), "#,###0.000") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWh(0) + ldblTotVlrkWh(1), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrBan(0) + ldblTotVlrBan(1), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotReceita(0) + ldblTotReceita(1), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdRev(0) + ldblTotQtdRev(1), "#,###0.000") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrRev(0) + ldblTotVlrRev(1), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrIcm(0) + ldblTotVlrIcm(1), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrPis(0) + ldblTotVlrPis(1), "#,##0.00") & "|"
								lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrCof(0) + ldblTotVlrCof(1), "#,##0.00")
								
								ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
								ifrmRelSamp.VS.Font = VB6.FontChangeBold(ifrmRelSamp.VS.Font, False)
								lblnSubTot = False
							End If
							'Detalhe
							lstrTabAux = ""
							lstrTabAux = lstrTabAux & lstrDesCla & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdCon, "###,###,###,##0") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWhLido, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWh, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWh, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrBan, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrRec, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdRev, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrRev, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrIcm, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrPis, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrCof, "#,##0.00")
							
							ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
							Call .MoveNext()
						End While
						lstrTabAux = ""
						lstrTabAux = lstrTabAux & "Total Geral|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdCon(0) + ldblTotQtdCon(1) + ldblTotQtdCon(2), "###,###,###,##0") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWhLido(0) + ldblTotQtdkWhLido(1) + ldblTotQtdkWhLido(2), "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWh(0) + ldblTotQtdkWh(1) + ldblTotQtdkWh(2), "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWh(0) + ldblTotVlrkWh(1) + ldblTotVlrkWh(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrBan(0) + ldblTotVlrBan(1) + ldblTotVlrBan(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotReceita(0) + ldblTotReceita(1) + ldblTotReceita(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdRev(0) + ldblTotQtdRev(1) + ldblTotQtdRev(2), "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrRev(0) + ldblTotVlrRev(1) + ldblTotVlrRev(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrIcm(0) + ldblTotVlrIcm(1) + ldblTotVlrIcm(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrPis(0) + ldblTotVlrPis(1) + ldblTotVlrPis(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrCof(0) + ldblTotVlrCof(1) + ldblTotVlrCof(2), "#,##0.00")
						
						ifrmRelSamp.VS.Font = VB6.FontChangeBold(ifrmRelSamp.VS.Font, True)
						ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
						ifrmRelSamp.VS.Font = VB6.FontChangeBold(ifrmRelSamp.VS.Font, False)
					Else
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeBold(.Font, True)
							.Font = VB6.FontChangeSize(.Font, 10)
							.Paragraph = IIf(lintRefatu = 1, "REFATURAMENTO", "REGULAR")
							.Font = VB6.FontChangeSize(.Font, 8)
							.TableBorder = VSVIEW6.TableBorderSettings.tbAll
							.Table = lstrTamCol & lstrTabTit
							.Font = VB6.FontChangeBold(.Font, False)
						End With
						lstrTabAux = ""
						lstrTabAux = lstrTabAux & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "###,###,###,##0") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00")
						ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
					End If
					Call .Close()
				End If
			End With
		Next lintRefatu
		'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 GeraImpressaoGrupoBIrrigacaoAquicultura()
		Dim lstrTabAux As String
		Dim lstrTabTit As String
		Dim lstrTamCol As String
		Dim lintRefatu As Short
		Dim lintOrdCla As Short
		Dim lstrDesCla As String
		'
		Dim ldblQtdCon As Double
		'Consumos
		Dim ldblQtdkWh As Double
		Dim ldblVlrkWh As Double
		Dim ldblVlrBan As Double
		'
		Dim ldblQtdkWh_n As Double
		Dim ldblVlrkWh_n As Double
		Dim ldblVlrBan_n As Double
		Dim ldblQtdkWh_r As Double
		Dim ldblVlrkWh_r As Double
		Dim ldblVlrBan_r As Double
		'Tributos
		Dim ldblVlrIcm As Double
		Dim ldblVlrPis As Double
		Dim ldblVlrCof As Double
		'
		'Totais
		Dim ldblTotQtdCon(2) As Double
		'Consumos
		Dim ldblTotQtdkWh(2) As Double
		Dim ldblTotVlrkWh(2) As Double
		Dim ldblTotVlrBan(2) As Double
		'
		Dim ldblTotQtdkWh_n(2) As Double
		Dim ldblTotVlrkWh_n(2) As Double
		Dim ldblTotVlrBan_n(2) As Double
		Dim ldblTotQtdkWh_r(2) As Double
		Dim ldblTotVlrkWh_r(2) As Double
		Dim ldblTotVlrBan_r(2) As Double
		'Tributos
		Dim ldblTotVlrIcm(2) As Double
		Dim ldblTotVlrPis(2) As Double
		Dim ldblTotVlrCof(2) As Double
		'
		'Auxiliares
		Dim lblnSubTot As Boolean
		Dim lintTotAux As Short
		Dim lintAux As Short
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrTamCol = "<20mm |>15mm  |>17mm   |>17mm   |>15mm    |>17mm                    |>16mm                         |>17mm                        |>17mm                        |>20mm                     |>17mm                          |>17mm                         |>17mm                         |>17mm|>17mm|>17mm;"
		lstrTabTit = "Classe|Nº Cons|kWh Fat.|kWh (R$)|Ban. (R$)|kWh" & vbCrLf & "P.Normal|Ban.(R$)" & vbCrLf & "P.Normal|kWh(R$)" & vbCrLf & "P.Normal|Receita" & vbCrLf & "P.Normal|kWh" & vbCrLf & "P.Reserv.|Ban.(R$)" & vbCrLf & "P.Reserv.|kWh(R$)" & vbCrLf & "P.Reserv.|Receita" & vbCrLf & "P.Reserv.|ICMS |PIS  |COFINS"
		For lintRefatu = 0 To 1
			lblnSubTot = True
			If lintRefatu = 1 Then
				For lintAux = 1 To 3
					ifrmRelSamp.VS.Paragraph = ""
				Next 
			End If
			'
			lstrSql = ""
			lstrSql = lstrSql & "  SELECT " & vbCrLf
			lstrSql = lstrSql & "        `ord_classe`, " & vbCrLf
			lstrSql = lstrSql & "        `ds_classe`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(if(qkwh_fat<0,0,1)) `ncons`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(qkwh_fat) `qkwh_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(vkwh_fat) `vkwh_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(vkwh_fat_ban) `vkwh_fat_ban`, " & vbCrLf
			'
			lstrSql = lstrSql & "        SUM(qirr_nor_kwh_fat) `qkwh_n_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(qirr_res_kwh_fat) `qkwh_r_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(virr_nor_kwh_fat) `vkwh_n_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(virr_nor_kwh_fat_ban) `vkwh_n_fat_ban`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(virr_res_kwh_fat) `vkwh_r_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(virr_res_kwh_fat_ban) `vkwh_r_fat_ban`, " & vbCrLf
			'
			lstrSql = lstrSql & "        SUM(icms) `icms`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(pis) `pis`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(cofins) `cofins` " & vbCrLf
			lstrSql = lstrSql & "    FROM " & istrTabela & " " & vbCrLf
			lstrSql = lstrSql & "   WHERE `grupo` = 'B' " & vbCrLf
			lstrSql = lstrSql & "     AND `refaturado` = " & lintRefatu & " " & vbCrLf
			lstrSql = lstrSql & "     AND `irrigacao_aquicultura` = 1 " & vbCrLf
			lstrSql = lstrSql & "GROUP BY `ord_classe`, `ds_classe` " & vbCrLf
			lstrSql = lstrSql & "ORDER BY `ord_classe` ASC, `ds_classe` ASC "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeBold(.Font, True)
							.Font = VB6.FontChangeSize(.Font, 10)
							.Paragraph = IIf(lintRefatu = 1, "REFATURAMENTO", "REGULAR")
							.Font = VB6.FontChangeSize(.Font, 8)
							.TableBorder = VSVIEW6.TableBorderSettings.tbAll
							.Table = lstrTamCol & lstrTabTit
							.Font = VB6.FontChangeBold(.Font, False)
						End With
						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"'
							lintOrdCla = CShort(IIf(IsDbNull(.Fields("ord_classe").value), 0, .Fields("ord_classe").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"'
							lstrDesCla = CStr(IIf(IsDbNull(.Fields("ds_classe").value), "", .Fields("ds_classe").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"'
							ldblQtdCon = CDbl(IIf(IsDbNull(.Fields("ncons").value), 0, .Fields("ncons").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"'
							ldblQtdkWh = CDbl(IIf(IsDbNull(.Fields("qkwh_fat").value), 0, .Fields("qkwh_fat").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"'
							ldblVlrkWh = CDbl(IIf(IsDbNull(.Fields("vkwh_fat").value), 0, .Fields("vkwh_fat").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"'
							ldblVlrBan = CDbl(IIf(IsDbNull(.Fields("vkwh_fat_ban").value), 0, .Fields("vkwh_fat_ban").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"'
							ldblQtdkWh_n = CDbl(IIf(IsDbNull(.Fields("qkwh_n_fat").value), 0, .Fields("qkwh_n_fat").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"'
							ldblVlrkWh_n = CDbl(IIf(IsDbNull(.Fields("vkwh_n_fat").value), 0, .Fields("vkwh_n_fat").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"'
							ldblVlrBan_n = CDbl(IIf(IsDbNull(.Fields("vkwh_n_fat_ban").value), 0, .Fields("vkwh_n_fat_ban").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"'
							ldblQtdkWh_r = CDbl(IIf(IsDbNull(.Fields("qkwh_r_fat").value), 0, .Fields("qkwh_r_fat").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"'
							ldblVlrkWh_r = CDbl(IIf(IsDbNull(.Fields("vkwh_r_fat").value), 0, .Fields("vkwh_r_fat").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"'
							ldblVlrBan_r = CDbl(IIf(IsDbNull(.Fields("vkwh_r_fat_ban").value), 0, .Fields("vkwh_r_fat_ban").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"'
							ldblVlrIcm = CDbl(IIf(IsDbNull(.Fields("icms").value), 0, .Fields("icms").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"'
							ldblVlrPis = CDbl(IIf(IsDbNull(.Fields("pis").value), 0, .Fields("pis").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"'
							ldblVlrCof = CDbl(IIf(IsDbNull(.Fields("cofins").value), 0, .Fields("cofins").value))
							If lintOrdCla = 10 Then
								lintTotAux = 1
							ElseIf lintOrdCla >= 20 And lintOrdCla < 30 Then 
								lintTotAux = 0
							Else
								lintTotAux = 2
							End If
							ldblTotQtdCon(lintTotAux) = ldblTotQtdCon(lintTotAux) + ldblQtdCon
							ldblTotQtdkWh(lintTotAux) = ldblTotQtdkWh(lintTotAux) + ldblQtdkWh
							ldblTotVlrkWh(lintTotAux) = ldblTotVlrkWh(lintTotAux) + ldblVlrkWh
							ldblTotVlrBan(lintTotAux) = ldblTotVlrBan(lintTotAux) + ldblVlrBan
							'
							ldblTotQtdkWh_n(lintTotAux) = ldblTotQtdkWh_n(lintTotAux) + ldblQtdkWh_n
							ldblTotVlrkWh_n(lintTotAux) = ldblTotVlrkWh_n(lintTotAux) + ldblVlrkWh_n
							ldblTotVlrBan_n(lintTotAux) = ldblTotVlrBan_n(lintTotAux) + ldblVlrBan_n
							ldblTotQtdkWh_r(lintTotAux) = ldblTotQtdkWh_r(lintTotAux) + ldblQtdkWh_r
							ldblTotVlrkWh_r(lintTotAux) = ldblTotVlrkWh_r(lintTotAux) + ldblVlrkWh_r
							ldblTotVlrBan_r(lintTotAux) = ldblTotVlrBan_r(lintTotAux) + ldblVlrBan_r
							'
							ldblTotVlrIcm(lintTotAux) = ldblTotVlrIcm(lintTotAux) + ldblVlrIcm
							ldblTotVlrPis(lintTotAux) = ldblTotVlrPis(lintTotAux) + ldblVlrPis
							ldblTotVlrCof(lintTotAux) = ldblTotVlrCof(lintTotAux) + ldblVlrCof
							
							'            'Subtotais
							'            If lintOrdCla >= 30 And lblnSubTot Then
							'              lstrTabAux = ""
							'              lstrTabAux = lstrTabAux & "Total Bx.Renda|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotQtdCon(0), "###,###,###,##0") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotQtdkWh(0), "#,###0.000") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrkWh(0), "#,##0.00") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrBan(0), "#,##0.00") & "|"
							'
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotQtdkWh_n(0), "#,###0.000") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrBan_n(0), "#,##0.00") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrkWh_n(0), "#,##0.00") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrkWh_n(0) + ldblTotVlrBan_n(0), "#,##0.00") & "|"
							'
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotQtdkWh_r(0), "#,###0.000") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrBan_r(0), "#,##0.00") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrkWh_r(0), "#,##0.00") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrkWh_r(0) + ldblTotVlrBan_r(0), "#,##0.00") & "|"
							'
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrIcm(0), "#,##0.00") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrPis(0), "#,##0.00") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrCof(0), "#,##0.00")
							'
							'              ifrmRelSamp.VS.FontBold = True
							'              ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
							'              lstrTabAux = ""
							'              lstrTabAux = lstrTabAux & "Total Residencial|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotQtdCon(0) + ldblTotQtdCon(1), "###,###,###,##0") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotQtdkWh(0) + ldblTotQtdkWh(1), "#,###0.000") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrkWh(0) + ldblTotVlrkWh(1), "#,##0.00") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrBan(0) + ldblTotVlrBan(1), "#,##0.00") & "|"
							'
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotQtdkWh_n(0) + ldblTotQtdkWh_n(1), "#,###0.000") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrBan_n(0) + ldblTotVlrBan_n(1), "#,##0.00") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrkWh_n(0) + ldblTotVlrkWh_n(1), "#,##0.00") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrkWh_n(0) + ldblTotVlrkWh_n(1) + ldblTotVlrBan_n(0) + ldblTotVlrBan_n(1), "#,##0.00") & "|"
							'
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotQtdkWh_r(0) + ldblTotQtdkWh_r(1), "#,###0.000") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrBan_r(0) + ldblTotVlrBan_r(1), "#,##0.00") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrkWh_r(0) + ldblTotVlrkWh_r(1), "#,##0.00") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrkWh_r(0) + ldblTotVlrkWh_r(1) + ldblTotVlrBan_r(0) + ldblTotVlrBan_r(1), "#,##0.00") & "|"
							'
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrIcm(0) + ldblTotVlrIcm(1), "#,##0.00") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrPis(0) + ldblTotVlrPis(1), "#,##0.00") & "|"
							'              lstrTabAux = lstrTabAux & Strings.Format(ldblTotVlrCof(0) + ldblTotVlrCof(1), "#,##0.00")
							'
							'              ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
							'              ifrmRelSamp.VS.FontBold = False
							'              lblnSubTot = False
							'            End If
							'Detalhe
							lstrTabAux = ""
							lstrTabAux = lstrTabAux & lstrDesCla & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdCon, "###,###,###,##0") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWh, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWh, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrBan, "#,##0.00") & "|"
							
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWh_n, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrBan_n, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWh_n, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWh_n + ldblVlrBan_n, "#,##0.00") & "|"
							
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWh_r, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrBan_r, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWh_r, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWh_r + ldblVlrBan_r, "#,##0.00") & "|"
							
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrIcm, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrPis, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrCof, "#,##0.00")
							
							ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
							Call .MoveNext()
						End While
						lstrTabAux = ""
						lstrTabAux = lstrTabAux & "Total Geral|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdCon(0) + ldblTotQtdCon(1) + ldblTotQtdCon(2), "###,###,###,##0") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWh(0) + ldblTotQtdkWh(1) + ldblTotQtdkWh(2), "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWh(0) + ldblTotVlrkWh(1) + ldblTotVlrkWh(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrBan(0) + ldblTotVlrBan(1) + ldblTotVlrBan(2), "#,##0.00") & "|"
						
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWh_n(0) + ldblTotQtdkWh_n(1) + ldblTotQtdkWh_n(2), "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrBan_n(0) + ldblTotVlrBan_n(1) + ldblTotVlrBan_n(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWh_n(0) + ldblTotVlrkWh_n(1) + ldblTotVlrkWh_n(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWh_n(0) + ldblTotVlrkWh_n(1) + ldblTotVlrkWh_n(2) + ldblTotVlrBan_n(0) + ldblTotVlrBan_n(1) + ldblTotVlrBan_n(2), "#,##0.00") & "|"
						
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWh_r(0) + ldblTotQtdkWh_r(1) + ldblTotQtdkWh_r(2), "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrBan_r(0) + ldblTotVlrBan_r(1) + ldblTotVlrBan_r(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWh_r(0) + ldblTotVlrkWh_r(1) + ldblTotVlrkWh_r(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWh_r(0) + ldblTotVlrkWh_r(1) + ldblTotVlrkWh_r(2) + ldblTotVlrBan_r(0) + ldblTotVlrBan_r(1) + ldblTotVlrBan_r(2), "#,##0.00") & "|"
						
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrIcm(0) + ldblTotVlrIcm(1) + ldblTotVlrIcm(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrPis(0) + ldblTotVlrPis(1) + ldblTotVlrPis(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrCof(0) + ldblTotVlrCof(1) + ldblTotVlrCof(2), "#,##0.00")
						
						ifrmRelSamp.VS.Font = VB6.FontChangeBold(ifrmRelSamp.VS.Font, True)
						ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
						ifrmRelSamp.VS.Font = VB6.FontChangeBold(ifrmRelSamp.VS.Font, False)
					Else
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeBold(.Font, True)
							.Font = VB6.FontChangeSize(.Font, 10)
							.Paragraph = IIf(lintRefatu = 1, "REFATURAMENTO", "REGULAR")
							.Font = VB6.FontChangeSize(.Font, 8)
							.TableBorder = VSVIEW6.TableBorderSettings.tbAll
							.Table = lstrTamCol & lstrTabTit
							.Font = VB6.FontChangeBold(.Font, False)
						End With
						lstrTabAux = ""
						lstrTabAux = lstrTabAux & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "###,###,###,##0") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00")
						ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
					End If
					Call .Close()
				End If
			End With
		Next lintRefatu
		'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 GeraImpressaoGrupoBTarifaBranca()
		Dim lstrTabAux As String
		Dim lstrTabTit As String
		Dim lstrTamCol As String
		Dim lintRefatu As Short
		Dim lintOrdCla As Short
		Dim lstrDesCla As String
		'
		Dim ldblQtdCon As Double
		'Consumos
		Dim ldblQtdkWh As Double
		Dim ldblVlrkWh As Double
		Dim ldblVlrBan As Double
		'
		Dim ldblQtdkWh_p As Double
		Dim ldblVlrkWh_p As Double
		Dim ldblVlrBan_p As Double
		Dim ldblQtdkWh_i As Double
		Dim ldblVlrkWh_i As Double
		Dim ldblVlrBan_i As Double
		Dim ldblQtdkWh_f As Double
		Dim ldblVlrkWh_f As Double
		Dim ldblVlrBan_f As Double
		'Tributos
		Dim ldblVlrIcm As Double
		Dim ldblVlrPis As Double
		Dim ldblVlrCof As Double
		'
		'Totais
		Dim ldblTotQtdCon(2) As Double
		'Consumos
		Dim ldblTotQtdkWh(2) As Double
		Dim ldblTotVlrkWh(2) As Double
		Dim ldblTotVlrBan(2) As Double
		'
		Dim ldblTotQtdkWh_p(2) As Double
		Dim ldblTotVlrkWh_p(2) As Double
		Dim ldblTotVlrBan_p(2) As Double
		Dim ldblTotQtdkWh_i(2) As Double
		Dim ldblTotVlrkWh_i(2) As Double
		Dim ldblTotVlrBan_i(2) As Double
		Dim ldblTotQtdkWh_f(2) As Double
		Dim ldblTotVlrkWh_f(2) As Double
		Dim ldblTotVlrBan_f(2) As Double
		'Tributos
		Dim ldblTotVlrIcm(2) As Double
		Dim ldblTotVlrPis(2) As Double
		Dim ldblTotVlrCof(2) As Double
		'
		'Auxiliares
		Dim lblnSubTot As Boolean
		Dim lintTotAux As Short
		Dim lintAux As Short
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrTamCol = "<15mm|>11mm|>15mm|>14mm|>13mm|>15mm|>14mm|>14mm|>14mm|>15mm|>15mm|>15mm|>15mm|>15mm|>13mm|>13mm|>14mm|>13mm|>13mm|>14mm;"
		
		lstrTabTit = "Classe|Nº Cons|kWh Fat.|kWh (R$)|Ban. (R$)|"
		
		lstrTabTit = lstrTabTit & "kWh" & vbCrLf & "Ponta|"
		lstrTabTit = lstrTabTit & "Ban.(R$)" & vbCrLf & "Ponta|"
		lstrTabTit = lstrTabTit & "kWh(R$)" & vbCrLf & "Ponta|"
		lstrTabTit = lstrTabTit & "Receita" & vbCrLf & "Ponta|"
		
		lstrTabTit = lstrTabTit & "kWh" & vbCrLf & "Inter|"
		lstrTabTit = lstrTabTit & "Ban.(R$)" & vbCrLf & "Inter|"
		lstrTabTit = lstrTabTit & "kWh(R$)" & vbCrLf & "Inter|"
		lstrTabTit = lstrTabTit & "Receita" & vbCrLf & "Inter|"
		
		lstrTabTit = lstrTabTit & "kWh" & vbCrLf & "ForaP|"
		lstrTabTit = lstrTabTit & "Ban.(R$)" & vbCrLf & "ForaP|"
		lstrTabTit = lstrTabTit & "kWh(R$)" & vbCrLf & "ForaP|"
		lstrTabTit = lstrTabTit & "Receita" & vbCrLf & "ForaP|"
		
		lstrTabTit = lstrTabTit & "ICMS |PIS  |COFINS"
		For lintRefatu = 0 To 1
			lblnSubTot = True
			If lintRefatu = 1 Then
				For lintAux = 1 To 3
					ifrmRelSamp.VS.Paragraph = ""
				Next 
			End If
			'
			lstrSql = ""
			lstrSql = lstrSql & "  SELECT " & vbCrLf
			lstrSql = lstrSql & "        `ord_classe`, " & vbCrLf
			lstrSql = lstrSql & "        `ds_classe`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(if(qkwh_fat<0,0,1)) `ncons`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(qkwh_fat) `qkwh_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(vkwh_fat) `vkwh_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(vkwh_fat_ban) `vkwh_fat_ban`, " & vbCrLf
			'
			lstrSql = lstrSql & "        SUM(qtarbranca_kwh_ponta) `qkwh_p_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(qtarbranca_kwh_inter) `qkwh_i_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(qtarbranca_kwh_forap) `qkwh_f_fat`, " & vbCrLf
			
			lstrSql = lstrSql & "        SUM(vtarbranca_kwh_ponta) `vkwh_p_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(vtarbranca_kwh_ponta_ban) `vkwh_p_fat_ban`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(vtarbranca_kwh_inter) `vkwh_i_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(vtarbranca_kwh_inter_ban) `vkwh_i_fat_ban`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(vtarbranca_kwh_forap) `vkwh_f_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(vtarbranca_kwh_forap_ban) `vkwh_f_fat_ban`, " & vbCrLf
			'
			lstrSql = lstrSql & "        SUM(icms) `icms`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(pis) `pis`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(cofins) `cofins` " & vbCrLf
			lstrSql = lstrSql & "    FROM " & istrTabela & " " & vbCrLf
			lstrSql = lstrSql & "   WHERE `grupo` = 'B' " & vbCrLf
			lstrSql = lstrSql & "     AND `refaturado` = " & lintRefatu & " " & vbCrLf
			lstrSql = lstrSql & "     AND `tarifa_branca` = 1 " & vbCrLf
			lstrSql = lstrSql & "GROUP BY `ord_classe`, `ds_classe` " & vbCrLf
			lstrSql = lstrSql & "ORDER BY `ord_classe` ASC, `ds_classe` ASC "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeBold(.Font, True)
							.Font = VB6.FontChangeSize(.Font, 10)
							.Paragraph = IIf(lintRefatu = 1, "REFATURAMENTO", "REGULAR")
							.Font = VB6.FontChangeSize(.Font, 6)
							.TableBorder = VSVIEW6.TableBorderSettings.tbAll
							.Table = lstrTamCol & lstrTabTit
							.Font = VB6.FontChangeBold(.Font, False)
						End With
						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"'
							lintOrdCla = CShort(IIf(IsDbNull(.Fields("ord_classe").value), 0, .Fields("ord_classe").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"'
							lstrDesCla = CStr(IIf(IsDbNull(.Fields("ds_classe").value), "", .Fields("ds_classe").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"'
							ldblQtdCon = CDbl(IIf(IsDbNull(.Fields("ncons").value), 0, .Fields("ncons").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"'
							ldblQtdkWh = CDbl(IIf(IsDbNull(.Fields("qkwh_fat").value), 0, .Fields("qkwh_fat").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"'
							ldblVlrkWh = CDbl(IIf(IsDbNull(.Fields("vkwh_fat").value), 0, .Fields("vkwh_fat").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"'
							ldblVlrBan = CDbl(IIf(IsDbNull(.Fields("vkwh_fat_ban").value), 0, .Fields("vkwh_fat_ban").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"'
							ldblQtdkWh_p = CDbl(IIf(IsDbNull(.Fields("qkwh_p_fat").value), 0, .Fields("qkwh_p_fat").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"'
							ldblVlrkWh_p = CDbl(IIf(IsDbNull(.Fields("vkwh_p_fat").value), 0, .Fields("vkwh_p_fat").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"'
							ldblVlrBan_p = CDbl(IIf(IsDbNull(.Fields("vkwh_p_fat_ban").value), 0, .Fields("vkwh_p_fat_ban").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"'
							ldblQtdkWh_i = CDbl(IIf(IsDbNull(.Fields("qkwh_i_fat").value), 0, .Fields("qkwh_i_fat").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"'
							ldblVlrkWh_i = CDbl(IIf(IsDbNull(.Fields("vkwh_i_fat").value), 0, .Fields("vkwh_i_fat").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"'
							ldblVlrBan_i = CDbl(IIf(IsDbNull(.Fields("vkwh_i_fat_ban").value), 0, .Fields("vkwh_i_fat_ban").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"'
							ldblQtdkWh_f = CDbl(IIf(IsDbNull(.Fields("qkwh_f_fat").value), 0, .Fields("qkwh_f_fat").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"'
							ldblVlrkWh_f = CDbl(IIf(IsDbNull(.Fields("vkwh_f_fat").value), 0, .Fields("vkwh_f_fat").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"'
							ldblVlrBan_f = CDbl(IIf(IsDbNull(.Fields("vkwh_f_fat_ban").value), 0, .Fields("vkwh_f_fat_ban").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"'
							ldblVlrIcm = CDbl(IIf(IsDbNull(.Fields("icms").value), 0, .Fields("icms").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"'
							ldblVlrPis = CDbl(IIf(IsDbNull(.Fields("pis").value), 0, .Fields("pis").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"'
							ldblVlrCof = CDbl(IIf(IsDbNull(.Fields("cofins").value), 0, .Fields("cofins").value))
							If lintOrdCla = 10 Then
								lintTotAux = 1
							ElseIf lintOrdCla >= 20 And lintOrdCla < 30 Then 
								lintTotAux = 0
							Else
								lintTotAux = 2
							End If
							ldblTotQtdCon(lintTotAux) = ldblTotQtdCon(lintTotAux) + ldblQtdCon
							ldblTotQtdkWh(lintTotAux) = ldblTotQtdkWh(lintTotAux) + ldblQtdkWh
							ldblTotVlrkWh(lintTotAux) = ldblTotVlrkWh(lintTotAux) + ldblVlrkWh
							ldblTotVlrBan(lintTotAux) = ldblTotVlrBan(lintTotAux) + ldblVlrBan
							'
							ldblTotQtdkWh_p(lintTotAux) = ldblTotQtdkWh_p(lintTotAux) + ldblQtdkWh_p
							ldblTotVlrkWh_p(lintTotAux) = ldblTotVlrkWh_p(lintTotAux) + ldblVlrkWh_p
							ldblTotVlrBan_p(lintTotAux) = ldblTotVlrBan_p(lintTotAux) + ldblVlrBan_p
							ldblTotQtdkWh_i(lintTotAux) = ldblTotQtdkWh_i(lintTotAux) + ldblQtdkWh_i
							ldblTotVlrkWh_i(lintTotAux) = ldblTotVlrkWh_i(lintTotAux) + ldblVlrkWh_i
							ldblTotVlrBan_i(lintTotAux) = ldblTotVlrBan_i(lintTotAux) + ldblVlrBan_i
							ldblTotQtdkWh_f(lintTotAux) = ldblTotQtdkWh_f(lintTotAux) + ldblQtdkWh_f
							ldblTotVlrkWh_f(lintTotAux) = ldblTotVlrkWh_f(lintTotAux) + ldblVlrkWh_f
							ldblTotVlrBan_f(lintTotAux) = ldblTotVlrBan_f(lintTotAux) + ldblVlrBan_f
							'
							ldblTotVlrIcm(lintTotAux) = ldblTotVlrIcm(lintTotAux) + ldblVlrIcm
							ldblTotVlrPis(lintTotAux) = ldblTotVlrPis(lintTotAux) + ldblVlrPis
							ldblTotVlrCof(lintTotAux) = ldblTotVlrCof(lintTotAux) + ldblVlrCof
							
							'Detalhe
							lstrTabAux = ""
							lstrTabAux = lstrTabAux & lstrDesCla & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdCon, "###,###,###,##0") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWh, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWh, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrBan, "#,##0.00") & "|"
							
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWh_p, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrBan_p, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWh_p, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWh_p + ldblVlrBan_p, "#,##0.00") & "|"
							
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWh_i, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrBan_i, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWh_i, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWh_i + ldblVlrBan_i, "#,##0.00") & "|"
							
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWh_f, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrBan_f, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWh_f, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWh_f + ldblVlrBan_f, "#,##0.00") & "|"
							
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrIcm, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrPis, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrCof, "#,##0.00")
							
							ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
							Call .MoveNext()
						End While
						lstrTabAux = ""
						lstrTabAux = lstrTabAux & "Total Geral|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdCon(0) + ldblTotQtdCon(1) + ldblTotQtdCon(2), "###,###,###,##0") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWh(0) + ldblTotQtdkWh(1) + ldblTotQtdkWh(2), "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWh(0) + ldblTotVlrkWh(1) + ldblTotVlrkWh(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrBan(0) + ldblTotVlrBan(1) + ldblTotVlrBan(2), "#,##0.00") & "|"
						
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWh_p(0) + ldblTotQtdkWh_p(1) + ldblTotQtdkWh_p(2), "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrBan_p(0) + ldblTotVlrBan_p(1) + ldblTotVlrBan_p(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWh_p(0) + ldblTotVlrkWh_p(1) + ldblTotVlrkWh_p(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWh_p(0) + ldblTotVlrkWh_p(1) + ldblTotVlrkWh_p(2) + ldblTotVlrBan_p(0) + ldblTotVlrBan_p(1) + ldblTotVlrBan_p(2), "#,##0.00") & "|"
						
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWh_i(0) + ldblTotQtdkWh_i(1) + ldblTotQtdkWh_i(2), "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrBan_i(0) + ldblTotVlrBan_i(1) + ldblTotVlrBan_i(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWh_i(0) + ldblTotVlrkWh_i(1) + ldblTotVlrkWh_i(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWh_i(0) + ldblTotVlrkWh_i(1) + ldblTotVlrkWh_i(2) + ldblTotVlrBan_i(0) + ldblTotVlrBan_i(1) + ldblTotVlrBan_i(2), "#,##0.00") & "|"
						
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWh_f(0) + ldblTotQtdkWh_f(1) + ldblTotQtdkWh_f(2), "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrBan_f(0) + ldblTotVlrBan_f(1) + ldblTotVlrBan_f(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWh_f(0) + ldblTotVlrkWh_f(1) + ldblTotVlrkWh_f(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWh_f(0) + ldblTotVlrkWh_f(1) + ldblTotVlrkWh_f(2) + ldblTotVlrBan_f(0) + ldblTotVlrBan_f(1) + ldblTotVlrBan_f(2), "#,##0.00") & "|"
						
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrIcm(0) + ldblTotVlrIcm(1) + ldblTotVlrIcm(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrPis(0) + ldblTotVlrPis(1) + ldblTotVlrPis(2), "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrCof(0) + ldblTotVlrCof(1) + ldblTotVlrCof(2), "#,##0.00")
						
						ifrmRelSamp.VS.Font = VB6.FontChangeBold(ifrmRelSamp.VS.Font, True)
						ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
						ifrmRelSamp.VS.Font = VB6.FontChangeBold(ifrmRelSamp.VS.Font, False)
					Else
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeBold(.Font, True)
							.Font = VB6.FontChangeSize(.Font, 10)
							.Paragraph = IIf(lintRefatu = 1, "REFATURAMENTO", "REGULAR")
							.Font = VB6.FontChangeSize(.Font, 6)
							.TableBorder = VSVIEW6.TableBorderSettings.tbAll
							.Table = lstrTamCol & lstrTabTit
							.Font = VB6.FontChangeBold(.Font, False)
						End With
						lstrTabAux = ""
						lstrTabAux = lstrTabAux & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "###,###,###,##0") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00")
						ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
					End If
					Call .Close()
				End If
			End With
		Next lintRefatu
		'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 GeraImpressaoUsinas()
		Dim lstrTabAux As String
		Dim lstrTabTit As String
		Dim lstrTamCol As String
		Dim lintRefatu As Short
		Dim lstrComCla As String
		'
		Dim ldblQtdCon As Double
		'Must
		Dim ldblQtdMus As Double
		Dim ldblVlrMus As Double
		Dim ldblVlrDes As Double
		Dim ldblVlrEnc As Double
		'Totais
		Dim ldblTotQtdCon As Double
		'Must
		Dim ldblTotQtdMus As Double
		Dim ldblTotVlrMus As Double
		Dim ldblTotVlrDes As Double
		Dim ldblTotVlrEnc As Double
		'Auxiliares
		Dim lintAux As Short
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrTamCol = "<35mm |>15mm  |>30mm     |>30mm    |>30mm        |>30mm       |>30mm;"
		lstrTabTit = "Classe|Nº Cons|Contratado|Must (R$)|Desconto (R$)|Receita (R$)|Encargo (R$)"
		For lintRefatu = 0 To 1
			If lintRefatu = 1 Then
				For lintAux = 1 To 3
					ifrmRelSamp.VS.Paragraph = ""
				Next 
			End If
			lstrSql = ""
			lstrSql = lstrSql & "  SELECT " & vbCrLf
			lstrSql = lstrSql & "        `com_classe`, " & vbCrLf
			lstrSql = lstrSql & "        COUNT(*) `ncons`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`must_qtd`) `must_qtd`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`must_vlr`) `must_vlr`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`must_des`) `must_des`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`must_enc`) `must_enc` " & vbCrLf
			lstrSql = lstrSql & "    FROM " & gstrDataBase & "." & istrTabela & " " & vbCrLf
			lstrSql = lstrSql & "   WHERE `refaturado` = " & lintRefatu & " " & vbCrLf
			lstrSql = lstrSql & "     AND `usinas` = 1 " & vbCrLf
			lstrSql = lstrSql & "GROUP BY `com_classe` " & vbCrLf
			lstrSql = lstrSql & "ORDER BY `com_classe` ASC "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeBold(.Font, True)
							.Font = VB6.FontChangeSize(.Font, 10)
							.Paragraph = IIf(lintRefatu = 1, "REFATURAMENTO", "REGULAR")
							.Font = VB6.FontChangeSize(.Font, 8)
							.TableBorder = VSVIEW6.TableBorderSettings.tbAll
							.Table = lstrTamCol & lstrTabTit
							.Font = VB6.FontChangeBold(.Font, False)
						End With
						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"'
							lstrComCla = CStr(IIf(IsDbNull(.Fields("com_classe").value), "", .Fields("com_classe").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"'
							ldblQtdCon = CDbl(IIf(IsDbNull(.Fields("ncons").value), 0, .Fields("ncons").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"'
							ldblQtdMus = CDbl(IIf(IsDbNull(.Fields("must_qtd").value), 0, .Fields("must_qtd").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"'
							ldblVlrMus = CDbl(IIf(IsDbNull(.Fields("must_vlr").value), 0, .Fields("must_vlr").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"'
							ldblVlrDes = CDbl(IIf(IsDbNull(.Fields("must_des").value), 0, .Fields("must_des").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"'
							ldblVlrEnc = CDbl(IIf(IsDbNull(.Fields("must_enc").value), 0, .Fields("must_enc").value))
							'
							ldblTotQtdCon = ldblTotQtdCon + ldblQtdCon
							ldblTotQtdMus = ldblTotQtdMus + ldblQtdMus
							ldblTotVlrMus = ldblTotVlrMus + ldblVlrMus
							ldblTotVlrDes = ldblTotVlrDes + ldblVlrDes
							ldblTotVlrEnc = ldblTotVlrEnc + ldblVlrEnc
							'Detalhe
							lstrTabAux = ""
							lstrTabAux = lstrTabAux & lstrComCla & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdCon, "###,###,###,##0") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdMus, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrMus, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrDes, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrMus - ldblVlrDes, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrEnc, "#,##0.00")
							ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
							Call .MoveNext()
						End While
						lstrTabAux = ""
						lstrTabAux = lstrTabAux & "Total Geral|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdCon, "###,###,###,##0") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdMus, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrMus, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrDes, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrMus - ldblTotVlrDes, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblVlrEnc, "#,##0.00")
						ifrmRelSamp.VS.Font = VB6.FontChangeBold(ifrmRelSamp.VS.Font, True)
						ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
						ifrmRelSamp.VS.Font = VB6.FontChangeBold(ifrmRelSamp.VS.Font, False)
					Else
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeBold(.Font, True)
							.Font = VB6.FontChangeSize(.Font, 10)
							.Paragraph = IIf(lintRefatu = 1, "REFATURAMENTO", "REGULAR")
							.Font = VB6.FontChangeSize(.Font, 8)
							.TableBorder = VSVIEW6.TableBorderSettings.tbAll
							.Table = lstrTamCol & lstrTabTit
							.Font = VB6.FontChangeBold(.Font, False)
						End With
						lstrTabAux = ""
						lstrTabAux = lstrTabAux & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "###,###,###,##0") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00")
						ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
					End If
					Call .Close()
				End If
			End With
		Next lintRefatu
		'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 GeraImpressaoGrupoAConvencional()
		Dim lstrTabAux As String
		Dim lstrTabTit As String
		Dim lstrTamCol As String
		Dim lintRefatu As Short
		Dim lintOrdCla As Short
		Dim lstrDesCla As String
		'
		Dim ldblQtdCon As Double
		'Consumos
		Dim ldblQtdkWh As Double
		Dim ldblVlrkWh As Double
		Dim ldblVlrBan As Double
		'Demadas
		Dim ldblQtdkW As Double
		Dim ldblVlrkW As Double
		Dim ldblQtdkWu As Double
		Dim ldblVlrkWu As Double
		'Receita
		Dim ldblVlrRec As Double
		'Reativos
		Dim ldblVlrCRe As Double
		Dim ldblVlrDRe As Double
		'Tributos
		Dim ldblVlrIcm As Double
		Dim ldblVlrPis As Double
		Dim ldblVlrCof As Double
		'Totais
		Dim ldblTotQtdCon As Double
		'Consumos
		Dim ldblTotQtdkWh As Double
		Dim ldblTotVlrkWh As Double
		Dim ldblTotVlrBan As Double
		'Demandas
		Dim ldblTotQtdkW As Double
		Dim ldblTotVlrkW As Double
		Dim ldblTotQtdkWu As Double
		Dim ldblTotVlrkWu As Double
		'
		Dim ldblTotVlrRec As Double
		'Reativos
		Dim ldblTotVlrCRe As Double
		Dim ldblTotVlrDRe As Double
		'Tributos
		Dim ldblTotVlrIcm As Double
		Dim ldblTotVlrPis As Double
		Dim ldblTotVlrCof As Double
		'Auxliares
		Dim lintAux As Short
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrTamCol = "<30mm |>15mm  |>25mm|>20mm|>20mm |>25mm   |>25mm        |>25mm  |>20mm  |>20mm      |>18mm|>18mm|>18mm;"
		lstrTabTit = "Classe|Nº Cons|kWh  |kW   |kW Ult|kWh (R$)|Bandeira (R$)|Receita|kW (R$)|kW Ult.(R$)|ICMS |PIS  |COFINS"
		For lintRefatu = 0 To 1
			If lintRefatu = 1 Then
				For lintAux = 1 To 3
					ifrmRelSamp.VS.Paragraph = ""
				Next 
			End If
			'
			lstrSql = ""
			lstrSql = lstrSql & "  SELECT " & vbCrLf
			lstrSql = lstrSql & "        `ord_classe`, " & vbCrLf
			lstrSql = lstrSql & "        `ds_classe`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(if((`qkwh_fat` + `qkw_fat`) < 0, 0, 1)) `ncons`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`qkwh_fat`) `qkwh_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkwh_fat`) `vkwh_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkwh_fat_ban`) `vkwh_fat_ban`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`qkw_fat`) `qkw_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkw_fat`) `vkw_fat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`qkw_fatu_fp`) `qkw_fatu_fp`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkw_fatu_fp`) `vkw_fatu_fp`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`receita_fp`) `vreceita`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vconreat`) `vconreat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vdemreat`) `vdemreat`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`icms`) `icms`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`pis`) `pis`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`cofins`) `cofins` " & vbCrLf
			lstrSql = lstrSql & "    FROM " & gstrDataBase & "." & istrTabela & " " & vbCrLf
			lstrSql = lstrSql & "   WHERE `grupo` = 'A4' " & vbCrLf
			lstrSql = lstrSql & "     AND `refaturado` = " & lintRefatu & " " & vbCrLf
			lstrSql = lstrSql & "     AND `usinas` = 0 " & vbCrLf
			lstrSql = lstrSql & "GROUP BY `ord_classe`, `ds_classe` " & vbCrLf
			lstrSql = lstrSql & "ORDER BY `ord_classe` ASC, `ds_classe` ASC "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeBold(.Font, True)
							.Font = VB6.FontChangeSize(.Font, 10)
							.Paragraph = IIf(lintRefatu = 1, "REFATURAMENTO", "REGULAR")
							.Font = VB6.FontChangeSize(.Font, 8)
							.TableBorder = VSVIEW6.TableBorderSettings.tbAll
							.Table = lstrTamCol & lstrTabTit
							.Font = VB6.FontChangeBold(.Font, False)
						End With
						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"'
							lintOrdCla = CShort(IIf(IsDbNull(.Fields("ord_classe").value), 0, .Fields("ord_classe").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"'
							lstrDesCla = CStr(IIf(IsDbNull(.Fields("ds_classe").value), "", .Fields("ds_classe").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"'
							ldblQtdCon = CDbl(IIf(IsDbNull(.Fields("ncons").value), 0, .Fields("ncons").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"'
							ldblQtdkWh = CDbl(IIf(IsDbNull(.Fields("qkwh_fat").value), 0, .Fields("qkwh_fat").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"'
							ldblVlrkWh = CDbl(IIf(IsDbNull(.Fields("vkwh_fat").value), 0, .Fields("vkwh_fat").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"'
							ldblVlrBan = CDbl(IIf(IsDbNull(.Fields("vkwh_fat_ban").value), 0, .Fields("vkwh_fat_ban").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"'
							ldblQtdkW = CDbl(IIf(IsDbNull(.Fields("qkw_fat").value), 0, .Fields("qkw_fat").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"'
							ldblVlrkW = CDbl(IIf(IsDbNull(.Fields("vkw_fat").value), 0, .Fields("vkw_fat").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"'
							ldblQtdkWu = CDbl(IIf(IsDbNull(.Fields("qkw_fatu_fp").value), 0, .Fields("qkw_fatu_fp").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"'
							ldblVlrkWu = CDbl(IIf(IsDbNull(.Fields("vkw_fatu_fp").value), 0, .Fields("vkw_fatu_fp").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"'
							ldblVlrRec = CDbl(IIf(IsDbNull(.Fields("vreceita").value), 0, .Fields("vreceita").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"'
							ldblVlrCRe = CDbl(IIf(IsDbNull(.Fields("vconreat").value), 0, .Fields("vconreat").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"'
							ldblVlrDRe = CDbl(IIf(IsDbNull(.Fields("vdemreat").value), 0, .Fields("vdemreat").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"'
							ldblVlrIcm = CDbl(IIf(IsDbNull(.Fields("icms").value), 0, .Fields("icms").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"'
							ldblVlrPis = CDbl(IIf(IsDbNull(.Fields("pis").value), 0, .Fields("pis").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"'
							ldblVlrCof = CDbl(IIf(IsDbNull(.Fields("cofins").value), 0, .Fields("cofins").value))
							ldblTotQtdCon = ldblTotQtdCon + ldblQtdCon
							ldblTotQtdkWh = ldblTotQtdkWh + ldblQtdkWh
							ldblTotVlrkWh = ldblTotVlrkWh + ldblVlrkWh
							ldblTotVlrBan = ldblTotVlrBan + ldblVlrBan
							ldblTotQtdkW = ldblTotQtdkW + ldblQtdkW
							ldblTotVlrkW = ldblTotVlrkW + ldblVlrkW
							ldblTotQtdkWu = ldblTotQtdkWu + ldblQtdkWu
							ldblTotVlrkWu = ldblTotVlrkWu + ldblVlrkWu
							ldblTotVlrRec = ldblTotVlrRec + ldblVlrRec
							ldblTotVlrCRe = ldblTotVlrCRe + ldblVlrCRe
							ldblTotVlrDRe = ldblTotVlrDRe + ldblVlrDRe
							ldblTotVlrIcm = ldblTotVlrIcm + ldblVlrIcm
							ldblTotVlrPis = ldblTotVlrPis + ldblVlrPis
							ldblTotVlrCof = ldblTotVlrCof + ldblVlrCof
							'Detalhe
							lstrTabAux = ""
							lstrTabAux = lstrTabAux & lstrDesCla & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdCon, "###,###,###,##0") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWh, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkW, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWu, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWh, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrBan, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrRec, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkW, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWu, "#,##0.00") & "|"
							'lstrTabAux = lstrTabAux & Strings.Format(ldblVlrCRe, "#,###0.000") & "|"
							'lstrTabAux = lstrTabAux & Strings.Format(ldblVlrDRe, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrIcm, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrPis, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrCof, "#,##0.00")
							ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
							Call .MoveNext()
						End While
						lstrTabAux = ""
						lstrTabAux = lstrTabAux & "Total Geral|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdCon, "###,###,###,##0") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWh, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkW, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWu, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWh, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrBan, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrRec, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkW, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWu, "#,##0.00") & "|"
						'lstrTabAux = lstrTabAux & Strings.Format(ldbltotVlrCRe, "#,###0.000") & "|"
						'lstrTabAux = lstrTabAux & Strings.Format(ldbltotVlrDRe, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrIcm, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrPis, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrCof, "#,##0.00")
						ifrmRelSamp.VS.Font = VB6.FontChangeBold(ifrmRelSamp.VS.Font, True)
						ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
						ifrmRelSamp.VS.Font = VB6.FontChangeBold(ifrmRelSamp.VS.Font, False)
					Else
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeBold(.Font, True)
							.Font = VB6.FontChangeSize(.Font, 10)
							.Paragraph = IIf(lintRefatu = 1, "REFATURAMENTO", "REGULAR")
							.Font = VB6.FontChangeSize(.Font, 8)
							.TableBorder = VSVIEW6.TableBorderSettings.tbAll
							.Table = lstrTamCol & lstrTabTit
							.Font = VB6.FontChangeBold(.Font, False)
						End With
						lstrTabAux = ""
						lstrTabAux = lstrTabAux & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "###,###,###,##0") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						'lstrTabAux = lstrTabAux & Strings.Format(0, "#,###0.000") & "|"
						'lstrTabAux = lstrTabAux & Strings.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00")
						ifrmRelSamp.VS.Table = lstrTamCol & lstrTabAux
					End If
					Call .Close()
				End If
			End With
		Next lintRefatu
		'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 GeraImpressaoGrupoAHorossazonal()
		Dim lstrTabAux As String
		Dim lstrTabTit1 As String
		Dim lstrTamCol1 As String
		Dim lstrTabTit2 As String
		Dim lstrTamCol2 As String
		Dim lintRefatu As Short
		Dim lintOrdCla As Short
		Dim lstrDesCla As String
		
		Dim ldblQtdCon As Double
		'Consumos
		Dim ldblQtdkWhp As Double
		Dim ldblQtdkWhfp As Double
		Dim ldblVlrkWhp As Double
		Dim ldblVlrkWhfp As Double
		Dim ldblVlrBanp As Double
		Dim ldblVlrBanfp As Double
		'Demandas
		Dim ldblQtdkWp As Double
		Dim ldblQtdkWfp As Double
		Dim ldblVlrkWp As Double
		Dim ldblVlrkWfp As Double
		Dim ldblQtdkWup As Double
		Dim ldblQtdkWufp As Double
		Dim ldblVlrkWup As Double
		Dim ldblVlrkWufp As Double
		'Reativos
		Dim ldblVlrCRep As Double
		Dim ldblVlrCRefp As Double
		Dim ldblVlrDRep As Double
		Dim ldblVlrDRefp As Double
		'Receita
		Dim ldblVlrRecp As Double
		Dim ldblVlrRecfp As Double
		'Tributos
		Dim ldblVlrIcm As Double
		Dim ldblVlrPis As Double
		Dim ldblVlrCof As Double
		'Totais
		Dim ldblTotQtdCon As Double
		'Consumos
		Dim ldblTotQtdkWhp As Double
		Dim ldblTotQtdkWhfp As Double
		Dim ldblTotVlrkWhp As Double
		Dim ldblTotVlrkWhfp As Double
		Dim ldblTotVlrBanp As Double
		Dim ldblTotVlrBanfp As Double
		'Demandas
		Dim ldblTotQtdkWp As Double
		Dim ldblTotQtdkWfp As Double
		Dim ldblTotVlrkWp As Double
		Dim ldblTotVlrkWfp As Double
		Dim ldblTotQtdkWup As Double
		Dim ldblTotQtdkWufp As Double
		Dim ldblTotVlrkWup As Double
		Dim ldblTotVlrkWufp As Double
		'Reativos
		Dim ldblTotVlrCRep As Double
		Dim ldblTotVlrCRefp As Double
		Dim ldblTotVlrDRep As Double
		Dim ldblTotVlrDRefp As Double
		'Receita
		Dim ldblTotVlrRecp As Double
		Dim ldblTotVlrRecfp As Double
		'Tributos
		Dim ldblTotVlrIcm As Double
		Dim ldblTotVlrPis As Double
		Dim ldblTotVlrCof As Double
		'Auxiliares
		Dim lintAux As Short
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		'
		lstrTamCol1 = "<11mm  |^34mm        |^30mm        |^22mm        |^34mm        |^27mm          |^27mm          |^27mm          |^26mm        |>41mm;"
		lstrTabTit1 = "       |kWh          |kW           |kW Ult       |kWh (R$)     |Bandeira(R$)   |Receita        |kW (R$)        |kW Ult (R$)  |"
		lstrTamCol2 = ">11mm  |>17mm|>17mm  |>15mm|>15mm  |>11mm|>11mm  |>17mm|>17mm  |>13.5mm|>13.5mm|>13.5mm|>13.5mm|>13.5mm|>13.5mm|>13mm|>13mm  |>15mm|>13mm|>13mm;"
		lstrTabTit2 = "Nº Cons|Ponta|Fora P.|Ponta|Fora P.|Ponta|Fora P.|Ponta|Fora P.|Ponta  |Fora P.|Ponta  |Fora P.|Ponta  |Fora P.|Ponta|Fora P.|ICMS |PIS  |COFINS"
		'
		For lintRefatu = 0 To 1
			If lintRefatu = 1 Then
				For lintAux = 1 To 3
					ifrmRelSamp.VS.Paragraph = ""
				Next 
			End If
			'
			lstrSql = ""
			lstrSql = lstrSql & "  SELECT " & vbCrLf
			lstrSql = lstrSql & "        `ord_classe`, " & vbCrLf
			lstrSql = lstrSql & "        `ds_classe`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(if((`qkwh_fat_p` + `qkwh_fat_fp` + `qkw_fat_p` + `qkw_fat_fp`) < 0, 0, 1)) `ncons`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`qkwh_fat_p`) `qkwh_fat_p`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`qkwh_fat_fp`) `qkwh_fat_fp`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkwh_fat_p`) `vkwh_fat_p`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkwh_fat_fp`) `vkwh_fat_fp`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkwh_fat_p_ban`) `vkwh_fat_p_ban`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkwh_fat_fp_ban`) `vkwh_fat_fp_ban`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`qkw_fat_p`) `qkw_fat_p`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`qkw_fat_fp`) `qkw_fat_fp`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkw_fat_p`) `vkw_fat_p`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkw_fat_fp`) `vkw_fat_fp`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`qkw_fatu_p`) `qkw_fatu_p`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`qkw_fatu_fp`) `qkw_fatu_fp`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkw_fatu_p`) `vkw_fatu_p`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkw_fatu_fp`) `vkw_fatu_fp`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vconreat_p`) `vconreat_p`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vconreat_fp`) `vconreat_fp`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vdemreat_p`) `vdemreat_p`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vdemreat_fp`) `vdemreat_fp`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`receita_p`) `vreceita_p`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`receita_fp`) `vreceita_fp`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`icms`) `icms`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`pis`) `pis`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`cofins`) `cofins` " & vbCrLf
			lstrSql = lstrSql & "    FROM " & gstrDataBase & "." & istrTabela & " " & vbCrLf
			lstrSql = lstrSql & "   WHERE `grupo` IN( 'AA','AV','AX') " & vbCrLf
			lstrSql = lstrSql & "     AND `refaturado` = " & lintRefatu & " " & vbCrLf
			lstrSql = lstrSql & "GROUP BY `ord_classe`, `ds_classe` " & vbCrLf
			lstrSql = lstrSql & "ORDER BY `ord_classe` ASC, `ds_classe` ASC "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeBold(.Font, True)
							.Font = VB6.FontChangeSize(.Font, 10)
							.Paragraph = IIf(lintRefatu = 1, "REFATURAMENTO", "REGULAR")
							.Font = VB6.FontChangeSize(.Font, 6)
							.TableBorder = VSVIEW6.TableBorderSettings.tbAll
							.Font = VB6.FontChangeBold(.Font, False)
						End With
						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"'
							lintOrdCla = CShort(IIf(IsDbNull(.Fields("ord_classe").value), 0, .Fields("ord_classe").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"'
							lstrDesCla = CStr(IIf(IsDbNull(.Fields("ds_classe").value), "", .Fields("ds_classe").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"'
							ldblQtdCon = CDbl(IIf(IsDbNull(.Fields("ncons").value), 0, .Fields("ncons").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"'
							ldblQtdkWhp = CDbl(IIf(IsDbNull(.Fields("qkwh_fat_p").value), 0, .Fields("qkwh_fat_p").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"'
							ldblQtdkWhfp = CDbl(IIf(IsDbNull(.Fields("qkwh_fat_fp").value), 0, .Fields("qkwh_fat_fp").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"'
							ldblVlrkWhp = CDbl(IIf(IsDbNull(.Fields("vkwh_fat_p").value), 0, .Fields("vkwh_fat_p").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"'
							ldblVlrkWhfp = CDbl(IIf(IsDbNull(.Fields("vkwh_fat_fp").value), 0, .Fields("vkwh_fat_fp").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"'
							ldblVlrBanp = CDbl(IIf(IsDbNull(.Fields("vkwh_fat_p_ban").value), 0, .Fields("vkwh_fat_p_ban").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"'
							ldblVlrBanfp = CDbl(IIf(IsDbNull(.Fields("vkwh_fat_fp_ban").value), 0, .Fields("vkwh_fat_fp_ban").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"'
							ldblQtdkWp = CDbl(IIf(IsDbNull(.Fields("qkw_fat_p").value), 0, .Fields("qkw_fat_p").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"'
							ldblQtdkWfp = CDbl(IIf(IsDbNull(.Fields("qkw_fat_fp").value), 0, .Fields("qkw_fat_fp").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"'
							ldblVlrkWp = CDbl(IIf(IsDbNull(.Fields("vkw_fat_p").value), 0, .Fields("vkw_fat_p").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"'
							ldblVlrkWfp = CDbl(IIf(IsDbNull(.Fields("vkw_fat_fp").value), 0, .Fields("vkw_fat_fp").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"'
							ldblQtdkWup = CDbl(IIf(IsDbNull(.Fields("qkw_fatu_p").value), 0, .Fields("qkw_fatu_p").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"'
							ldblQtdkWufp = CDbl(IIf(IsDbNull(.Fields("qkw_fatu_fp").value), 0, .Fields("qkw_fatu_fp").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"'
							ldblVlrkWup = CDbl(IIf(IsDbNull(.Fields("vkw_fatu_p").value), 0, .Fields("vkw_fatu_p").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"'
							ldblVlrkWufp = CDbl(IIf(IsDbNull(.Fields("vkw_fatu_fp").value), 0, .Fields("vkw_fatu_fp").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"'
							ldblVlrCRep = CDbl(IIf(IsDbNull(.Fields("vconreat_p").value), 0, .Fields("vconreat_p").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"'
							ldblVlrCRefp = CDbl(IIf(IsDbNull(.Fields("vconreat_fp").value), 0, .Fields("vconreat_fp").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"'
							ldblVlrDRep = CDbl(IIf(IsDbNull(.Fields("vdemreat_p").value), 0, .Fields("vdemreat_p").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"'
							ldblVlrDRefp = CDbl(IIf(IsDbNull(.Fields("vdemreat_fp").value), 0, .Fields("vdemreat_fp").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"'
							ldblVlrRecp = CDbl(IIf(IsDbNull(.Fields("vreceita_p").value), 0, .Fields("vreceita_p").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"'
							ldblVlrRecfp = CDbl(IIf(IsDbNull(.Fields("vreceita_fp").value), 0, .Fields("vreceita_fp").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"'
							ldblVlrIcm = CDbl(IIf(IsDbNull(.Fields("icms").value), 0, .Fields("icms").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"'
							ldblVlrPis = CDbl(IIf(IsDbNull(.Fields("pis").value), 0, .Fields("pis").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"'
							ldblVlrCof = CDbl(IIf(IsDbNull(.Fields("cofins").value), 0, .Fields("cofins").value))
							ldblTotQtdCon = ldblTotQtdCon + ldblQtdCon
							ldblTotQtdkWhp = ldblTotQtdkWhp + ldblQtdkWhp
							ldblTotQtdkWhfp = ldblTotQtdkWhfp + ldblQtdkWhfp
							ldblTotVlrkWhp = ldblTotVlrkWhp + ldblVlrkWhp
							ldblTotVlrkWhfp = ldblTotVlrkWhfp + ldblVlrkWhfp
							ldblTotVlrBanp = ldblTotVlrBanp + ldblVlrBanp
							ldblTotVlrBanfp = ldblTotVlrBanfp + ldblVlrBanfp
							ldblTotQtdkWp = ldblTotQtdkWp + ldblQtdkWp
							ldblTotQtdkWfp = ldblTotQtdkWfp + ldblQtdkWfp
							ldblTotVlrkWp = ldblTotVlrkWp + ldblVlrkWp
							ldblTotVlrkWfp = ldblTotVlrkWfp + ldblVlrkWfp
							ldblTotQtdkWup = ldblTotQtdkWup + ldblQtdkWup
							ldblTotQtdkWufp = ldblTotQtdkWufp + ldblQtdkWufp
							ldblTotVlrkWup = ldblTotVlrkWup + ldblVlrkWup
							ldblTotVlrkWufp = ldblTotVlrkWufp + ldblVlrkWufp
							ldblTotVlrCRep = ldblTotVlrCRep + ldblVlrCRep
							ldblTotVlrCRefp = ldblTotVlrCRefp + ldblVlrCRefp
							ldblTotVlrDRep = ldblTotVlrDRep + ldblVlrDRep
							ldblTotVlrDRefp = ldblTotVlrDRefp + ldblVlrDRefp
							ldblTotVlrRecp = ldblTotVlrRecp + ldblVlrRecp
							ldblTotVlrRecfp = ldblTotVlrRecfp + ldblVlrRecfp
							ldblTotVlrIcm = ldblTotVlrIcm + ldblVlrIcm
							ldblTotVlrPis = ldblTotVlrPis + ldblVlrPis
							ldblTotVlrCof = ldblTotVlrCof + ldblVlrCof
							'Detalhe
							lstrTabAux = ""
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdCon, "###,###,###,##0") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWhp, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWhfp, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWp, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWfp, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWup, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWufp, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWhp, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWhfp, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrBanp, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrBanfp, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrRecp, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrRecfp, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWp, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWfp, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWup, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWufp, "#,##0.00") & "|"
							'lstrTabAux = lstrTabAux & Strings.Format(ldblVlrCRep, "#,###0.000") & "|"
							'lstrTabAux = lstrTabAux & Strings.Format(ldblVlrCRefp, "#,###0.000") & "|"
							'lstrTabAux = lstrTabAux & Strings.Format(ldblVlrDRep, "#,##0.00") & "|"
							'lstrTabAux = lstrTabAux & Strings.Format(ldblVlrDRefp, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrIcm, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrPis, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrCof, "#,##0.00")
							With ifrmRelSamp.VS
								.Font = VB6.FontChangeSize(.Font, 10)
								.Paragraph = ""
								.Paragraph = lstrDesCla
								.Font = VB6.FontChangeSize(.Font, 6)
								.Table = lstrTamCol1 & lstrTabTit1
								'Fundo Cinza
								.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
								.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
								'UPGRADE_ISSUE: VBControlExtender method ifrmRelSamp.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
								.DrawRectangle("7mm", .CurrentY, "286mm", .CurrentY + 140)
								.BrushColor = System.Drawing.Color.White
								.PenStyle = VSVIEW6.PenStyleSettings.psSolid
								.Table = lstrTamCol2 & lstrTabTit2
								.Table = lstrTamCol2 & lstrTabAux
							End With
							Call .MoveNext()
						End While
						lstrTabAux = ""
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdCon, "###,###,###,##0") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWhp, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWhfp, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWp, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWfp, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWup, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWufp, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWhp, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWhfp, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrBanp, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrBanfp, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrRecp, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrRecfp, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWp, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWfp, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWup, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWufp, "#,##0.00") & "|"
						'lstrTabAux = lstrTabAux & Strings.Format(ldbltotVlrCRep, "#,###0.000") & "|"
						'lstrTabAux = lstrTabAux & Strings.Format(ldbltotVlrCRefp, "#,###0.000") & "|"
						'lstrTabAux = lstrTabAux & Strings.Format(ldbltotVlrDRep, "#,##0.00") & "|"
						'lstrTabAux = lstrTabAux & Strings.Format(ldbltotVlrDRefp, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrIcm, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrPis, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrCof, "#,##0.00")
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeBold(.Font, True)
							.Font = VB6.FontChangeSize(.Font, 10)
							.Paragraph = ""
							.Paragraph = "Total Geral"
							.Font = VB6.FontChangeSize(.Font, 6)
							.Table = lstrTamCol1 & lstrTabTit1
							'Fundo Cinza
							.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
							.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
							'UPGRADE_ISSUE: VBControlExtender method ifrmRelSamp.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
							.DrawRectangle("7mm", .CurrentY, "286mm", .CurrentY + 140)
							.BrushColor = System.Drawing.Color.White
							.PenStyle = VSVIEW6.PenStyleSettings.psSolid
							.Table = lstrTamCol2 & lstrTabTit2
							.Table = lstrTamCol2 & lstrTabAux
							.Font = VB6.FontChangeBold(.Font, False)
						End With
					Else
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeBold(.Font, True)
							.Font = VB6.FontChangeSize(.Font, 10)
							.Paragraph = IIf(lintRefatu = 1, "REFATURAMENTO", "REGULAR")
							.Font = VB6.FontChangeSize(.Font, 6)
							.TableBorder = VSVIEW6.TableBorderSettings.tbAll
							.Font = VB6.FontChangeBold(.Font, False)
						End With
						lstrTabAux = ""
						lstrTabAux = lstrTabAux & VB6.Format(0, "###,###,###,##0") & "|" 'qtde consumidores
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|" 'qtde consumo
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|" 'qtde consumo
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|" 'qtde demanda
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|" 'qtde demanda
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|" 'qtde ultrapassagem
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|" 'qtde ultrapassagem
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						'lstrTabAux = lstrTabAux & Strings.Format(0, "#,###0.000") & "|"
						'lstrTabAux = lstrTabAux & Strings.Format(0, "#,##0.00") & "|"
						'lstrTabAux = lstrTabAux & Strings.Format(0, "#,###0.000") & "|"
						'lstrTabAux = lstrTabAux & Strings.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00")
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeBold(.Font, True)
							.Paragraph = ""
							.Paragraph = ""
							.Table = lstrTamCol1 & lstrTabTit1
							'Fundo Cinza
							.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
							.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
							'UPGRADE_ISSUE: VBControlExtender method ifrmRelSamp.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
							.DrawRectangle("7mm", .CurrentY, "286mm", .CurrentY + 140)
							.BrushColor = System.Drawing.Color.White
							.PenStyle = VSVIEW6.PenStyleSettings.psSolid
							.Table = lstrTamCol2 & lstrTabTit2
							.Table = lstrTamCol2 & lstrTabAux
							.Font = VB6.FontChangeBold(.Font, False)
						End With
					End If
					Call .Close()
				End If
			End With
		Next lintRefatu
		'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
		ifrmRelSamp.VS.Font = VB6.FontChangeSize(ifrmRelSamp.VS.Font, 8)
	End Sub
	
	Private Sub GeraImpressaoGrupoALivre()
		Dim lstrTabAux As String
		Dim lstrTabTit1 As String
		Dim lstrTamCol1 As String
		Dim lstrTabTit2 As String
		Dim lstrTamCol2 As String
		Dim lintRefatu As Short
		Dim lintOrdCla As Short
		Dim lstrDesCla As String
		'
		Dim ldblQtdCon As Double
		'Consumos
		Dim ldblQtdkWhp As Double
		Dim ldblQtdkWhfp As Double
		Dim ldblVlrkWhp As Double
		Dim ldblVlrkWhfp As Double
		Dim ldblVlrBanp As Double
		Dim ldblVlrBanfp As Double
		'Livre - Encargos
		Dim ldblQtdLivp As Double
		Dim ldblQtdLivfp As Double
		Dim ldblVlrLivp As Double
		Dim ldblVlrLivfp As Double
		'Demandas
		Dim ldblQtdkWp As Double
		Dim ldblQtdkWfp As Double
		Dim ldblVlrkWp As Double
		Dim ldblVlrkWfp As Double
		Dim ldblQtdkWup As Double
		Dim ldblQtdkWufp As Double
		Dim ldblVlrkWup As Double
		Dim ldblVlrkWufp As Double
		'CCEE
		Dim ldblVlrDscProv As Double
		Dim ldblVlrDscReal As Double
		Dim ldblVlrDevCcee As Double
		Dim ldblVlrCobCcee As Double
		Dim ldblVlrkwhDscProv As Double
		Dim ldblVlrkwhDscReal As Double
		Dim ldblVlrkwhDevCcee As Double
		Dim ldblVlrkwhCobCcee As Double
		'Receita
		Dim ldblVlrRecp As Double
		Dim ldblVlrRecfp As Double
		'Reativos
		Dim ldblVlrCRep As Double
		Dim ldblVlrCRefp As Double
		Dim ldblVlrDRep As Double
		Dim ldblVlrDRefp As Double
		'Tributos
		Dim ldblVlrIcm As Double
		Dim ldblVlrPis As Double
		Dim ldblVlrCof As Double
		'Totais
		Dim ldblTotQtdCon As Double
		'Consumo
		Dim ldblTotQtdkWhp As Double
		Dim ldblTotQtdkWhfp As Double
		Dim ldblTotVlrkWhp As Double
		Dim ldblTotVlrkWhfp As Double
		Dim ldblTotVlrBanp As Double
		Dim ldblTotVlrBanfp As Double
		'Livre - Encargos
		Dim ldblTotQtdLivp As Double
		Dim ldblTotQtdLivfp As Double
		Dim ldblTotVlrLivp As Double
		Dim ldblTotVlrLivfp As Double
		'Demandas
		Dim ldblTotQtdkWp As Double
		Dim ldblTotQtdkWfp As Double
		Dim ldblTotVlrkWp As Double
		Dim ldblTotVlrkWfp As Double
		Dim ldblTotQtdkWup As Double
		Dim ldblTotQtdkWufp As Double
		Dim ldblTotVlrkWup As Double
		Dim ldblTotVlrkWufp As Double
		'CCEE
		Dim ldblTotVlrDscProv As Double
		Dim ldblTotVlrDscReal As Double
		Dim ldblTotVlrDevCcee As Double
		Dim ldblTotVlrCobCcee As Double
		
		Dim ldblTotVlrkwhDscProv As Double
		Dim ldblTotVlrkwhDscReal As Double
		Dim ldblTotVlrkwhDevCcee As Double
		Dim ldblTotVlrkwhCobCcee As Double
		'Receita
		Dim ldblTotVlrRecp As Double
		Dim ldblTotVlrRecfp As Double
		'Reativos
		Dim ldblTotVlrCRep As Double
		Dim ldblTotVlrCRefp As Double
		Dim ldblTotVlrDRep As Double
		Dim ldblTotVlrDRefp As Double
		'Tributos
		Dim ldblTotVlrIcm As Double
		Dim ldblTotVlrPis As Double
		Dim ldblTotVlrCof As Double
		'Auxiliares
		Dim lintAux As Short
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		'
		lstrTamCol1 = "<20mm |>15mm  |>30mm    |>30mm    |>30mm   |>30mm   |>30mm|>30mm|>30mm;"
		lstrTabTit1 = "Classe|Nº Cons|Desc.Prov|Desc.Real|Dev.CCEE|Cob.CCEE|ICMS |PIS  |COFINS"
		
		lstrTamCol2 = "^35mm|>30mm|>15mm  |>15mm |>30mm  |>30mm   |>30mm       |>30mm  |>30mm      |>15mm  |>15mm;"
		lstrTabTit2 = "     |kWh  |kW     |kW Ult|Encargo|kWh (R$)|Bandeira(R$)|Receita|Encargo(R$)|kW (R$)|kW Ult.(R$)"
		'
		For lintRefatu = 0 To 1
			If lintRefatu = 1 Then
				For lintAux = 1 To 3
					ifrmRelSamp.VS.Paragraph = ""
				Next 
			End If
			'
			lstrSql = ""
			lstrSql = lstrSql & "  SELECT " & vbCrLf
			lstrSql = lstrSql & "        `parc_cativo`, " & vbCrLf
			lstrSql = lstrSql & "        `ord_classe`, " & vbCrLf
			lstrSql = lstrSql & "        `ds_classe`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(if((`qkwh_fat_p` + `qkwh_fat_fp` + `qkwh_fat_p_liv` + `qkwh_fat_fp_liv` + `qkw_fat_p` + `qkw_fat_fp`) < 0, 0, 1)) `ncons`, " & vbCrLf
			'Consumos
			lstrSql = lstrSql & "        SUM(`qkwh_fat_p`) `qkwh_fat_p`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`qkwh_fat_fp`) `qkwh_fat_fp`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkwh_fat_p`) `vkwh_fat_p`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkwh_fat_fp`) `vkwh_fat_fp`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkwh_fat_p_ban`) `vkwh_fat_p_ban`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkwh_fat_fp_ban`) `vkwh_fat_fp_ban`, " & vbCrLf
			'Livre - Encargos
			lstrSql = lstrSql & "        SUM(`qkwh_fat_p_liv`) `qkwh_fat_p_liv`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`qkwh_fat_fp_liv`) `qkwh_fat_fp_liv`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkwh_fat_p_liv`) `vkwh_fat_p_liv`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkwh_fat_fp_liv`) `vkwh_fat_fp_liv`, " & vbCrLf
			'Demandas
			lstrSql = lstrSql & "        SUM(`qkw_fat_p`) `qkw_fat_p`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`qkw_fat_fp`) `qkw_fat_fp`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkw_fat_p`) `vkw_fat_p`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkw_fat_fp`) `vkw_fat_fp`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`qkw_fatu_p`) `qkw_fatu_p`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`qkw_fatu_fp`) `qkw_fatu_fp`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkw_fatu_p`) `vkw_fatu_p`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkw_fatu_fp`) `vkw_fatu_fp`, " & vbCrLf
			'CCEE
			lstrSql = lstrSql & "        SUM(`vkw_dsc_prov`) `vkw_dsc_prov`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkw_dsc_real`) `vkw_dsc_real`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkw_dev_ccee`) `vkw_dev_ccee`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkw_cob_ccee`) `vkw_cob_ccee`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkwh_dsc_prov`) `vkwh_dsc_prov`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkwh_dsc_real`) `vkwh_dsc_real`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkwh_dev_ccee`) `vkwh_dev_ccee`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vkwh_cob_ccee`) `vkwh_cob_ccee`, " & vbCrLf
			'Receita
			lstrSql = lstrSql & "        SUM(`receita_p`) `vreceita_p`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`receita_fp`) `vreceita_fp`, " & vbCrLf
			'Reativos
			lstrSql = lstrSql & "        SUM(`vconreat_p`) `vconreat_p`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vconreat_fp`) `vconreat_fp`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vdemreat_p`) `vdemreat_p`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`vdemreat_fp`) `vdemreat_fp`, " & vbCrLf
			'Tributos
			lstrSql = lstrSql & "        SUM(`icms`) `icms`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`pis`) `pis`, " & vbCrLf
			lstrSql = lstrSql & "        SUM(`cofins`) `cofins` " & vbCrLf
			lstrSql = lstrSql & "    FROM " & gstrDataBase & "." & istrTabela & " " & vbCrLf
			lstrSql = lstrSql & "   WHERE `grupo` IN( 'AL','ALP', 'ALS','ALV') " & vbCrLf
			lstrSql = lstrSql & "     AND `refaturado` = " & lintRefatu & " " & vbCrLf
			lstrSql = lstrSql & "GROUP BY `ord_classe`, `ds_classe` " & vbCrLf
			lstrSql = lstrSql & "ORDER BY `ord_classe` ASC, `ds_classe` ASC "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeBold(.Font, True)
							.Font = VB6.FontChangeSize(.Font, 10)
							.Paragraph = IIf(lintRefatu = 1, "REFATURAMENTO", "REGULAR")
							.Font = VB6.FontChangeSize(.Font, 6)
							.TableBorder = VSVIEW6.TableBorderSettings.tbAll
							.Font = VB6.FontChangeBold(.Font, False)
						End With
						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"'
							lintOrdCla = CShort(IIf(IsDbNull(.Fields("ord_classe").value), 0, .Fields("ord_classe").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"'
							lstrDesCla = CStr(IIf(IsDbNull(.Fields("ds_classe").value), "", .Fields("ds_classe").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"'
							ldblQtdCon = CDbl(IIf(IsDbNull(.Fields("ncons").value), 0, .Fields("ncons").value))
							'Consumo
							'UPGRADE_WARNING: 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"'
							ldblQtdkWhp = CDbl(IIf(IsDbNull(.Fields("qkwh_fat_p").value), 0, .Fields("qkwh_fat_p").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"'
							ldblQtdkWhfp = CDbl(IIf(IsDbNull(.Fields("qkwh_fat_fp").value), 0, .Fields("qkwh_fat_fp").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"'
							ldblVlrkWhp = CDbl(IIf(IsDbNull(.Fields("vkwh_fat_p").value), 0, .Fields("vkwh_fat_p").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"'
							ldblVlrkWhfp = CDbl(IIf(IsDbNull(.Fields("vkwh_fat_fp").value), 0, .Fields("vkwh_fat_fp").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"'
							ldblVlrBanp = CDbl(IIf(IsDbNull(.Fields("vkwh_fat_p_ban").value), 0, .Fields("vkwh_fat_p_ban").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"'
							ldblVlrBanfp = CDbl(IIf(IsDbNull(.Fields("vkwh_fat_fp_ban").value), 0, .Fields("vkwh_fat_fp_ban").value))
							'Livre - Encargos
							'UPGRADE_WARNING: 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"'
							ldblQtdLivp = CDbl(IIf(IsDbNull(.Fields("qkwh_fat_p_liv").value), 0, .Fields("qkwh_fat_p_liv").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"'
							ldblQtdLivfp = CDbl(IIf(IsDbNull(.Fields("qkwh_fat_fp_liv").value), 0, .Fields("qkwh_fat_fp_liv").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"'
							ldblVlrLivp = CDbl(IIf(IsDbNull(.Fields("vkwh_fat_p_liv").value), 0, .Fields("vkwh_fat_p_liv").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"'
							ldblVlrLivfp = CDbl(IIf(IsDbNull(.Fields("vkwh_fat_fp_liv").value), 0, .Fields("vkwh_fat_fp_liv").value))
							'Demandas
							'UPGRADE_WARNING: 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"'
							ldblQtdkWp = CDbl(IIf(IsDbNull(.Fields("qkw_fat_p").value), 0, .Fields("qkw_fat_p").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"'
							ldblQtdkWfp = CDbl(IIf(IsDbNull(.Fields("qkw_fat_fp").value), 0, .Fields("qkw_fat_fp").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"'
							ldblVlrkWp = CDbl(IIf(IsDbNull(.Fields("vkw_fat_p").value), 0, .Fields("vkw_fat_p").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"'
							ldblVlrkWfp = CDbl(IIf(IsDbNull(.Fields("vkw_fat_fp").value), 0, .Fields("vkw_fat_fp").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"'
							ldblQtdkWup = CDbl(IIf(IsDbNull(.Fields("qkw_fatu_p").value), 0, .Fields("qkw_fatu_p").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"'
							ldblQtdkWufp = CDbl(IIf(IsDbNull(.Fields("qkw_fatu_fp").value), 0, .Fields("qkw_fatu_fp").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"'
							ldblVlrkWup = CDbl(IIf(IsDbNull(.Fields("vkw_fatu_p").value), 0, .Fields("vkw_fatu_p").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"'
							ldblVlrkWufp = CDbl(IIf(IsDbNull(.Fields("vkw_fatu_fp").value), 0, .Fields("vkw_fatu_fp").value))
							'CCEE
							'UPGRADE_WARNING: 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"'
							ldblVlrDscProv = CDbl(IIf(IsDbNull(.Fields("vkw_dsc_prov").value), 0, .Fields("vkw_dsc_prov").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"'
							ldblVlrDscReal = CDbl(IIf(IsDbNull(.Fields("vkw_dsc_real").value), 0, .Fields("vkw_dsc_real").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"'
							ldblVlrDevCcee = CDbl(IIf(IsDbNull(.Fields("vkw_dev_ccee").value), 0, .Fields("vkw_dev_ccee").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"'
							ldblVlrCobCcee = CDbl(IIf(IsDbNull(.Fields("vkw_cob_ccee").value), 0, .Fields("vkw_cob_ccee").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"'
							ldblVlrkwhDscProv = CDbl(IIf(IsDbNull(.Fields("vkwh_dsc_prov").value), 0, .Fields("vkwh_dsc_prov").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"'
							ldblVlrkwhDscReal = CDbl(IIf(IsDbNull(.Fields("vkwh_dsc_real").value), 0, .Fields("vkwh_dsc_real").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"'
							ldblVlrkwhDevCcee = CDbl(IIf(IsDbNull(.Fields("vkwh_dev_ccee").value), 0, .Fields("vkwh_dev_ccee").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"'
							ldblVlrkwhCobCcee = CDbl(IIf(IsDbNull(.Fields("vkwh_cob_ccee").value), 0, .Fields("vkwh_cob_ccee").value))
							'Receita
							'UPGRADE_WARNING: 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"'
							ldblVlrRecp = CDbl(IIf(IsDbNull(.Fields("vreceita_p").value), 0, .Fields("vreceita_p").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"'
							ldblVlrRecfp = CDbl(IIf(IsDbNull(.Fields("vreceita_fp").value), 0, .Fields("vreceita_fp").value))
							'Reativos
							'UPGRADE_WARNING: 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"'
							ldblVlrCRep = CDbl(IIf(IsDbNull(.Fields("vconreat_p").value), 0, .Fields("vconreat_p").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"'
							ldblVlrCRefp = CDbl(IIf(IsDbNull(.Fields("vconreat_fp").value), 0, .Fields("vconreat_fp").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"'
							ldblVlrDRep = CDbl(IIf(IsDbNull(.Fields("vdemreat_p").value), 0, .Fields("vdemreat_p").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"'
							ldblVlrDRefp = CDbl(IIf(IsDbNull(.Fields("vdemreat_fp").value), 0, .Fields("vdemreat_fp").value))
							'Tributos
							'UPGRADE_WARNING: 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"'
							ldblVlrIcm = CDbl(IIf(IsDbNull(.Fields("icms").value), 0, .Fields("icms").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"'
							ldblVlrPis = CDbl(IIf(IsDbNull(.Fields("pis").value), 0, .Fields("pis").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"'
							ldblVlrCof = CDbl(IIf(IsDbNull(.Fields("cofins").value), 0, .Fields("cofins").value))
							'Totais
							ldblTotQtdCon = ldblTotQtdCon + ldblQtdCon
							'Consumos
							ldblTotQtdkWhp = ldblTotQtdkWhp + ldblQtdkWhp
							ldblTotQtdkWhfp = ldblTotQtdkWhfp + ldblQtdkWhfp
							ldblTotVlrkWhp = ldblTotVlrkWhp + ldblVlrkWhp
							ldblTotVlrkWhfp = ldblTotVlrkWhfp + ldblVlrkWhfp
							ldblTotVlrBanp = ldblTotVlrBanp + ldblVlrBanp
							ldblTotVlrBanfp = ldblTotVlrBanfp + ldblVlrBanfp
							'Livre - Encargos
							ldblTotQtdLivp = ldblTotQtdLivp + ldblQtdLivp
							ldblTotQtdLivfp = ldblTotQtdLivfp + ldblQtdLivfp
							ldblTotVlrLivp = ldblTotVlrLivp + ldblVlrLivp
							ldblTotVlrLivfp = ldblTotVlrLivfp + ldblVlrLivfp
							'Demandas
							ldblTotQtdkWp = ldblTotQtdkWp + ldblQtdkWp
							ldblTotQtdkWfp = ldblTotQtdkWfp + ldblQtdkWfp
							ldblTotVlrkWp = ldblTotVlrkWp + ldblVlrkWp
							ldblTotVlrkWfp = ldblTotVlrkWfp + ldblVlrkWfp
							ldblTotQtdkWup = ldblTotQtdkWup + ldblQtdkWup
							ldblTotQtdkWufp = ldblTotQtdkWufp + ldblQtdkWufp
							ldblTotVlrkWup = ldblTotVlrkWup + ldblVlrkWup
							ldblTotVlrkWufp = ldblTotVlrkWufp + ldblVlrkWufp
							'CCEE
							ldblTotVlrDscProv = ldblTotVlrDscProv + ldblVlrDscProv
							ldblTotVlrDscReal = ldblTotVlrDscReal + ldblVlrDscReal
							ldblTotVlrDevCcee = ldblTotVlrDevCcee + ldblVlrDevCcee
							ldblTotVlrCobCcee = ldblTotVlrCobCcee + ldblVlrCobCcee
							
							ldblTotVlrkwhDscProv = ldblTotVlrkwhDscProv + ldblVlrkwhDscProv
							ldblTotVlrkwhDscReal = ldblTotVlrkwhDscReal + ldblVlrkwhDscReal
							ldblTotVlrkwhDevCcee = ldblTotVlrkwhDevCcee + ldblVlrkwhDevCcee
							ldblTotVlrkwhCobCcee = ldblTotVlrkwhCobCcee + ldblVlrkwhCobCcee
							'Receita
							ldblTotVlrRecp = ldblTotVlrRecp + ldblVlrRecp
							ldblTotVlrRecfp = ldblTotVlrRecfp + ldblVlrRecfp
							'Reativos
							ldblTotVlrCRep = ldblTotVlrCRep + ldblVlrCRep
							ldblTotVlrCRefp = ldblTotVlrCRefp + ldblVlrCRefp
							ldblTotVlrDRep = ldblTotVlrDRep + ldblVlrDRep
							ldblTotVlrDRefp = ldblTotVlrDRefp + ldblVlrDRefp
							'Tributos
							ldblTotVlrIcm = ldblTotVlrIcm + ldblVlrIcm
							ldblTotVlrPis = ldblTotVlrPis + ldblVlrPis
							ldblTotVlrCof = ldblTotVlrCof + ldblVlrCof
							'Detalhe
							lstrTabAux = lstrDesCla & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdCon, "###,###,###,##0") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrDscProv, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrDscReal, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrDevCcee, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrCobCcee, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrIcm, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrPis, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrCof, "#,##0.00")
							With ifrmRelSamp.VS
								.Paragraph = ""
								.Font = VB6.FontChangeSize(.Font, 6)
								'Fundo Cinza
								.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
								.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
								'UPGRADE_ISSUE: VBControlExtender method ifrmRelSamp.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
								.DrawRectangle("10mm", .CurrentY, "255mm", .CurrentY + 140)
								.BrushColor = System.Drawing.Color.White
								.PenStyle = VSVIEW6.PenStyleSettings.psSolid
								.Table = lstrTamCol1 & lstrTabTit1
								.Table = lstrTamCol1 & lstrTabAux
							End With
							lstrTabAux = "|"
							lstrTabAux = lstrTabAux & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkwhDscProv, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkwhDscReal, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkwhDevCcee, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkwhCobCcee, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & "|"
							lstrTabAux = lstrTabAux & "|"
							ifrmRelSamp.VS.Table = lstrTamCol1 & lstrTabAux
							
							lstrTabAux = "Ponta|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWhp, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWp, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWup, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdLivp, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWhp, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrBanp, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrRecp, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrLivp, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWp, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWup, "#,##0.00") & "|"
							'lstrTabAux = lstrTabAux & Strings.Format(ldblVlrCRep, "#,###0.000") & "|"
							'lstrTabAux = lstrTabAux & Strings.Format(ldblVlrDRep, "#,##0.00") & "|"
							With ifrmRelSamp.VS
								'.Paragraph = ""
								.Font = VB6.FontChangeSize(.Font, 6)
								'Fundo Cinza
								.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
								.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
								'UPGRADE_ISSUE: VBControlExtender method ifrmRelSamp.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
								.DrawRectangle("10mm", .CurrentY, "285mm", .CurrentY + 140)
								.BrushColor = System.Drawing.Color.White
								.PenStyle = VSVIEW6.PenStyleSettings.psSolid
								.Table = lstrTamCol2 & lstrTabTit2
								.Table = lstrTamCol2 & lstrTabAux
							End With
							lstrTabAux = "Fora Ponta|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWhfp, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWfp, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdkWufp, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblQtdLivfp, "#,###0.000") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWhfp, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrBanfp, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrRecfp, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrLivfp, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWfp, "#,##0.00") & "|"
							lstrTabAux = lstrTabAux & VB6.Format(ldblVlrkWufp, "#,##0.00") & "|"
							'lstrTabAux = lstrTabAux & Strings.Format(ldblVlrCRefp, "#,###0.000") & "|"
							'lstrTabAux = lstrTabAux & Strings.Format(ldblVlrDRefp, "#,##0.00") & "|"
							With ifrmRelSamp.VS
								.Font = VB6.FontChangeSize(.Font, 6)
								.Table = lstrTamCol2 & lstrTabAux
							End With
							Call .MoveNext()
						End While
						lstrTabAux = "Total Geral|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdCon, "###,###,###,##0") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrDscProv, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrDscReal, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrDevCcee, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrCobCcee, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrIcm, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrPis, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrCof, "#,##0.00")
						With ifrmRelSamp.VS
							.Paragraph = ""
							.Font = VB6.FontChangeSize(.Font, 6)
							.Font = VB6.FontChangeBold(.Font, True)
							'Fundo Cinza
							.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
							.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
							'UPGRADE_ISSUE: VBControlExtender method ifrmRelSamp.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
							.DrawRectangle("10mm", .CurrentY, "255mm", .CurrentY + 140)
							.BrushColor = System.Drawing.Color.White
							.PenStyle = VSVIEW6.PenStyleSettings.psSolid
							.Table = lstrTamCol1 & lstrTabTit1
							.Table = lstrTamCol1 & lstrTabAux
						End With
						lstrTabAux = "|"
						lstrTabAux = lstrTabAux & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkwhDscProv, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkwhDscReal, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkwhDevCcee, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkwhCobCcee, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & "|"
						lstrTabAux = lstrTabAux & "|"
						ifrmRelSamp.VS.Table = lstrTamCol1 & lstrTabAux
						lstrTabAux = "Ponta|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWhp, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWp, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWup, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdLivp, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWhp, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrBanp, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrRecp, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrLivp, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWp, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWup, "#,##0.00") & "|"
						'lstrTabAux = lstrTabAux & Strings.Format(ldbltotVlrCRep, "#,###0.000") & "|"
						'lstrTabAux = lstrTabAux & Strings.Format(ldbltotVlrDRep, "#,##0.00") & "|"
						With ifrmRelSamp.VS
							'.Paragraph = ""
							.Font = VB6.FontChangeSize(.Font, 6)
							'Fundo Cinza
							.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
							.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
							'UPGRADE_ISSUE: VBControlExtender method ifrmRelSamp.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
							.DrawRectangle("10mm", .CurrentY, "285mm", .CurrentY + 140)
							.BrushColor = System.Drawing.Color.White
							.PenStyle = VSVIEW6.PenStyleSettings.psSolid
							.Table = lstrTamCol2 & lstrTabTit2
							.Table = lstrTamCol2 & lstrTabAux
						End With
						lstrTabAux = "Fora Ponta|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWhfp, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWfp, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdkWufp, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotQtdLivfp, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWhfp, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrBanfp, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrRecfp, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrLivfp, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWfp, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(ldblTotVlrkWufp, "#,##0.00") & "|"
						'lstrTabAux = lstrTabAux & Strings.Format(ldbltotVlrCRefp, "#,###0.000") & "|"
						'lstrTabAux = lstrTabAux & Strings.Format(ldbltotVlrDRefp, "#,##0.00") & "|"
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeSize(.Font, 6)
							.Table = lstrTamCol2 & lstrTabAux
							.Font = VB6.FontChangeBold(.Font, False)
						End With
					Else
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeBold(.Font, True)
							.Font = VB6.FontChangeSize(.Font, 10)
							.Paragraph = IIf(lintRefatu = 1, "REFATURAMENTO", "REGULAR")
							.Font = VB6.FontChangeSize(.Font, 6)
							.TableBorder = VSVIEW6.TableBorderSettings.tbAll
							.Font = VB6.FontChangeBold(.Font, False)
						End With
						lstrTabAux = "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "###,###,###,##0") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00")
						With ifrmRelSamp.VS
							.Paragraph = ""
							.Font = VB6.FontChangeSize(.Font, 6)
							'Fundo Cinza
							.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
							.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
							'UPGRADE_ISSUE: VBControlExtender method ifrmRelSamp.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
							.DrawRectangle("10mm", .CurrentY, "255mm", .CurrentY + 140)
							.BrushColor = System.Drawing.Color.White
							.PenStyle = VSVIEW6.PenStyleSettings.psSolid
							.Table = lstrTamCol1 & lstrTabTit1
							.Table = lstrTamCol1 & lstrTabAux
						End With
						lstrTabAux = "Ponta|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						'lstrTabAux = lstrTabAux & Strings.Format(0, "#,###0.000") & "|"
						'lstrTabAux = lstrTabAux & Strings.Format(0, "#,##0.00") & "|"
						With ifrmRelSamp.VS
							.Paragraph = ""
							.Font = VB6.FontChangeSize(.Font, 6)
							'Fundo Cinza
							.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
							.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
							'UPGRADE_ISSUE: VBControlExtender method ifrmRelSamp.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
							.DrawRectangle("10mm", .CurrentY, "285mm", .CurrentY + 140)
							.BrushColor = System.Drawing.Color.White
							.PenStyle = VSVIEW6.PenStyleSettings.psSolid
							.Table = lstrTamCol2 & lstrTabTit2
							.Table = lstrTamCol2 & lstrTabAux
						End With
						lstrTabAux = "Fora Ponta|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,###0.000") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						lstrTabAux = lstrTabAux & VB6.Format(0, "#,##0.00") & "|"
						'lstrTabAux = lstrTabAux & Strings.Format(0, "#,###0.000") & "|"
						'lstrTabAux = lstrTabAux & Strings.Format(0, "#,##0.00") & "|"
						With ifrmRelSamp.VS
							.Font = VB6.FontChangeSize(.Font, 6)
							.Table = lstrTamCol2 & lstrTabAux
						End With
					End If
					Call .Close()
				End If
			End With
		Next lintRefatu
		'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
		ifrmRelSamp.VS.Font = VB6.FontChangeSize(ifrmRelSamp.VS.Font, 8)
	End Sub
	
	Private Sub cmdPasta_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdPasta.Click
		With Me.cmdPasta
			Me.Enabled = False
			ifrmDir.frmQuemChama = Me
			ifrmDir.intTipo = 1
			Call ifrmDir.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 ifrmDir.ShowDialog()
		End With
	End Sub
	
	Private Sub cmdSiase_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSiase.Click
		Call frmGerarDadosSiase.Show()
	End Sub
	
	Private Sub dtpMesAno_Change(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles dtpMesAno.Change
		Call MontaNomeArquivo()
	End Sub
	
	Private Sub DTPMesAno_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles DTPMesAno.Leave
		iblnExporta = VerificaSeExisteExportacao
		Me.cmdExporta.Enabled = iblnExporta
	End Sub
	
	Private Sub frmRelSampNovo_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		Select Case KeyAscii
			Case System.Windows.Forms.Keys.Return
				KeyAscii = 0
				Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
			Case System.Windows.Forms.Keys.Escape
				Call cmdFechar_Click(cmdFechar, New System.EventArgs())
		End Select
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub frmRelSampNovo_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Dim lstrAux As String
		Call CenterForm(Me)
		ifrmRelSamp = New FrmRelatorio
		ifrmDir = New frmDir
		istrTabela = "tmp_samp"
		istrTab945 = "tmp_samp_945"
		Call CenterForm(Me)
		lstrAux = LeConfig("MESANOFATURAMENTO")
		If Len(Trim(lstrAux)) < 1 Then
			lstrAux = "01/" & VB6.Format(Now, "MM/yyyy")
		Else
			lstrAux = "01/" & lstrAux
		End If
		Me.dtpMesAno.value = CDate(IIf(IsDate(lstrAux), lstrAux, Today))
		ilngLimRes = CInt(LeConfig("LIMITE_RESIDENCIAL"))
		ilngLimRur = CInt(LeConfig("LIMITE_RURAL"))
		istrCaminho = Trim(LeConfig("DIR_GERACAO_SAMP"))
		If istrCaminho = "-1" Then
			istrCaminho = My.Application.Info.DirectoryPath
			Call CriaParConfig("DIR_GERACAO_SAMP", Replace(istrCaminho, "\", "\\"), False, "Caminho para gerar os arquivos samp.")
		ElseIf istrCaminho = "" Then 
			istrCaminho = My.Application.Info.DirectoryPath
			Call GravaConfig("DIR_GERACAO_SAMP", Replace(istrCaminho, "\", "\\"))
		End If
		Me.txtDir.Text = istrCaminho
		Call MontaNomeArquivo()
		iblnExporta = VerificaSeExisteExportacao
		Me.cmdExporta.Enabled = iblnExporta
		Me.cmbCaracter.SelectedIndex = 0
	End Sub
	
	Private Sub frmRelSampNovo_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		Call Executar("DROP TEMPORARY TABLE IF EXISTS " & istrTabela, True)
		Call Executar("DROP TABLE IF EXISTS " & istrTabela, True)
		Call Executar("DROP TEMPORARY TABLE IF EXISTS " & istrTab945)
		Call Executar("DROP TABLE IF EXISTS " & istrTab945)
		Call GravaConfig("DIR_GERACAO_SAMP", Replace(Me.txtDir.Text, "\", "\\"))
		'UPGRADE_NOTE: Object ifrmDir 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"'
		ifrmDir = Nothing
		'UPGRADE_NOTE: Object ifrmRelSamp 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"'
		ifrmRelSamp = Nothing
	End Sub
	
	Private Sub CriaTabelaTemporaria()
		Dim lstrSql As String
		Call Executar("DROP TEMPORARY TABLE IF EXISTS " & istrTabela, True)
		Call Executar("DROP TABLE IF EXISTS " & istrTabela, True)
		lstrSql = ""
		lstrSql = lstrSql & "CREATE TEMPORARY TABLE IF NOT EXISTS " & istrTabela & "("
		'lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS " & istrTabela & "("
		lstrSql = lstrSql & "refaturado  TINYINT(1)   DEFAULT NULL, "
		lstrSql = lstrSql & "grupo       VARCHAR(3)   DEFAULT NULL, "
		lstrSql = lstrSql & "classe      VARCHAR(4)   DEFAULT NULL, "
		lstrSql = lstrSql & "ds_classe   VARCHAR(200) DEFAULT NULL, "
		lstrSql = lstrSql & "com_classe  VARCHAR(200) DEFAULT NULL, "
		lstrSql = lstrSql & "ord_classe  TINYINT(2)   DEFAULT NULL, "
		lstrSql = lstrSql & "parc_cativo TINYINT(1)   DEFAULT NULL, "
		lstrSql = lstrSql & "usinas      TINYINT(1)   DEFAULT NULL, "
		lstrSql = lstrSql & "micro_geracao TINYINT(1)   DEFAULT NULL, "
		lstrSql = lstrSql & "irrigacao_aquicultura TINYINT(1)   DEFAULT NULL, "
		lstrSql = lstrSql & "tarifa_branca TINYINT(1)   DEFAULT NULL, "
		'Convencional
		'Qtde
		lstrSql = lstrSql & "qkwh_cons    DOUBLE DEFAULT '0', " 'Kwh CONSUMIDO (ENERGIA CONSUMIDA)
		lstrSql = lstrSql & "qkwh_fat     DOUBLE DEFAULT '0', " 'Kwh FATURADO
		lstrSql = lstrSql & "qkwh_fat_ban DOUBLE DEFAULT '0', " 'Kwh FATURADO Bandeira
		lstrSql = lstrSql & "qkw_fat      DOUBLE DEFAULT '0', " 'Kw FATURADO
		'Irrigacao
		lstrSql = lstrSql & "qirr_nor_kwh_fat     DOUBLE DEFAULT '0', " 'Kwh FATURADO
		lstrSql = lstrSql & "qirr_nor_kwh_fat_ban DOUBLE DEFAULT '0', " 'Kwh FATURADO Bandeira
		lstrSql = lstrSql & "qirr_res_kwh_fat     DOUBLE DEFAULT '0', " 'Kwh FATURADO
		lstrSql = lstrSql & "qirr_res_kwh_fat_ban DOUBLE DEFAULT '0', " 'Kwh FATURADO Bandeira
		'Tarifa Branca
		lstrSql = lstrSql & "qtarbranca_kwh_ponta DOUBLE DEFAULT '0', " 'Kwh FATURADO POTA
		lstrSql = lstrSql & "qtarbranca_kwh_ponta_ban DOUBLE DEFAULT '0', " 'Kwh FATURADO PONTA Bandeira
		lstrSql = lstrSql & "qtarbranca_kwh_inter DOUBLE DEFAULT '0', " 'Kwh FATURADO INTERMEDIARIO
		lstrSql = lstrSql & "qtarbranca_kwh_inter_ban DOUBLE DEFAULT '0', " 'Kwh FATURADO INTERMEDIARIO Bandeira
		lstrSql = lstrSql & "qtarbranca_kwh_forap DOUBLE DEFAULT '0', " 'Kwh FATURADO FORA PONTA
		lstrSql = lstrSql & "qtarbranca_kwh_forap_ban DOUBLE DEFAULT '0', " 'Kwh FATURADO FORA PONTA Bandeira
		'Valor
		lstrSql = lstrSql & "vkwh_cons    DECIMAL(14,2) DEFAULT '0.00', " 'Kwh CONSUMIDO (ENERGIA CONSUMIDA)
		lstrSql = lstrSql & "vkwh_fat     DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO
		lstrSql = lstrSql & "vkwh_fat_ban DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO Bandeira
		lstrSql = lstrSql & "vkw_fat      DECIMAL(14,2) DEFAULT '0.00', " 'Kw FATURADO
		lstrSql = lstrSql & "vconreat     DECIMAL(14,2) DEFAULT '0.00', " 'REATIVO
		lstrSql = lstrSql & "vdemreat     DECIMAL(14,2) DEFAULT '0.00', " 'REATIVO
		'Irrigacao
		lstrSql = lstrSql & "virr_nor_kwh_fat     DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO
		lstrSql = lstrSql & "virr_nor_kwh_fat_ban DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO Bandeira
		lstrSql = lstrSql & "virr_res_kwh_fat     DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO
		lstrSql = lstrSql & "virr_res_kwh_fat_ban DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO Bandeira
		'Tarifa Branca
		lstrSql = lstrSql & "vtarbranca_kwh_ponta DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO POTA
		lstrSql = lstrSql & "vtarbranca_kwh_ponta_ban DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO PONTA Bandeira
		lstrSql = lstrSql & "vtarbranca_kwh_inter DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO INTERMEDIARIO
		lstrSql = lstrSql & "vtarbranca_kwh_inter_ban DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO INTERMEDIARIO Bandeira
		lstrSql = lstrSql & "vtarbranca_kwh_forap DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO FORA PONTA
		lstrSql = lstrSql & "vtarbranca_kwh_forap_ban DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO FORA PONTA Bandeira
		'Horosazonal
		'Qtde
		lstrSql = lstrSql & "qkwh_fat_p      DOUBLE DEFAULT '0', " 'Kwh FATURADO (ENERGIA FAT PONTA)
		lstrSql = lstrSql & "qkwh_fat_fp     DOUBLE DEFAULT '0', " 'Kwh FATURADO (ENERGIA FAT FORA PONTA)
		lstrSql = lstrSql & "qkwh_fat_p_ban  DOUBLE DEFAULT '0', " 'Kwh FATURADO (ENERGIA FAT PONTA) Bandeira
		lstrSql = lstrSql & "qkwh_fat_fp_ban DOUBLE DEFAULT '0', " 'Kwh FATURADO (ENERGIA FAT FORA PONTA) Bandeira
		lstrSql = lstrSql & "qkwh_fat_p_liv  DOUBLE DEFAULT '0', " 'Kwh FATURADO (ENERGIA FAT PONTA) Livre
		lstrSql = lstrSql & "qkwh_fat_fp_liv DOUBLE DEFAULT '0', " 'Kwh FATURADO (ENERGIA FAT FORA PONTA) Livre
		lstrSql = lstrSql & "qkwh_dev_p      DOUBLE DEFAULT '0', " 'Kwh Devolvido PONTA
		lstrSql = lstrSql & "qkwh_dev_fp     DOUBLE DEFAULT '0', " 'Kwh Devolvido FORA PONTA
		lstrSql = lstrSql & "qkwh_utr_p      DOUBLE DEFAULT '0', " 'Kwh Ultrapassado PONTA
		lstrSql = lstrSql & "qkwh_utr_fp     DOUBLE DEFAULT '0', " 'Kwh Ultrapassado FORA PONTA
		lstrSql = lstrSql & "qkw_fat_p       DOUBLE DEFAULT '0', " 'Kw FATURADO (DEMANDA FAT PONTA)
		lstrSql = lstrSql & "qkw_fat_fp      DOUBLE DEFAULT '0', " 'Kw FATURADO (DEMANDA FAT FORA PONTA)
		lstrSql = lstrSql & "qkw_fatu_p      DOUBLE DEFAULT '0', " 'Kw FATURADO ULTRAPASSAGEM P
		lstrSql = lstrSql & "qkw_fatu_fp     DOUBLE DEFAULT '0', " 'Kw FATURADO ULTRAPASSAGEM FP
		'Valor
		lstrSql = lstrSql & "vkwh_fat_p      DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO (ENERGIA FAT PONTA)
		lstrSql = lstrSql & "vkwh_fat_fp     DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO (ENERGIA FAT FORA PONTA)
		lstrSql = lstrSql & "vkwh_fat_p_ban  DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO (ENERGIA FAT PONTA) Bandeira
		lstrSql = lstrSql & "vkwh_fat_fp_ban DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO (ENERGIA FAT FORA PONTA) Bandeira
		lstrSql = lstrSql & "vkwh_fat_p_liv  DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO (ENERGIA FAT PONTA) Livre
		lstrSql = lstrSql & "vkwh_fat_fp_liv DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO (ENERGIA FAT FORA PONTA) Livre
		lstrSql = lstrSql & "vkwh_dev_p      DECIMAL(14,2) DEFAULT '0.00', " 'Kwh DEVOLVIDO (ENERGIA FAT PONTA)
		lstrSql = lstrSql & "vkwh_dev_fp     DECIMAL(14,2) DEFAULT '0.00', " 'Kwh DEVOLVIDO (ENERGIA FAT FORA PONTA)
		lstrSql = lstrSql & "vkwh_utr_p      DECIMAL(14,2) DEFAULT '0.00', " 'Kwh ULTRAPASSADO (ENERGIA FAT PONTA)
		lstrSql = lstrSql & "vkwh_utr_fp     DECIMAL(14,2) DEFAULT '0.00', " 'Kwh ULTRAPASSADO (ENERGIA FAT FORA PONTA)
		lstrSql = lstrSql & "vkw_fat_p       DECIMAL(14,2) DEFAULT '0.00', " 'Kw FATURADO (DEMANDA FAT PONTA)
		lstrSql = lstrSql & "vkw_fat_fp      DECIMAL(14,2) DEFAULT '0.00', " 'Kw FATURADO (DEMANDA FAT FORA PONTA)
		lstrSql = lstrSql & "vkw_fatu_p      DECIMAL(14,2) DEFAULT '0.00', " 'Kw FATURADO ULTRAPASSAGEM P
		lstrSql = lstrSql & "vkw_fatu_fp     DECIMAL(14,2) DEFAULT '0.00', " 'Kw FATURADO ULTRAPASSAGEM FP
		lstrSql = lstrSql & "vkw_dsc_prov    DECIMAL(14,2) DEFAULT '0.00', " 'Kw - Desconto Provisorio CCEE
		lstrSql = lstrSql & "vkw_dsc_real    DECIMAL(14,2) DEFAULT '0.00', " 'Kw - Desconto Real CCEE
		lstrSql = lstrSql & "vkw_dev_ccee    DECIMAL(14,2) DEFAULT '0.00', " 'Kw - Devolução da difereça entre o real e o provisório
		lstrSql = lstrSql & "vkw_cob_ccee    DECIMAL(14,2) DEFAULT '0.00', " 'Kw - Cobrança da diferença entre o real e o provisório
		lstrSql = lstrSql & "vkwh_dsc_prov   DECIMAL(14,2) DEFAULT '0.00', " 'Kwh - Desconto Provisorio CCEE
		lstrSql = lstrSql & "vkwh_dsc_real   DECIMAL(14,2) DEFAULT '0.00', " 'Kwh - Desconto Real CCEE
		lstrSql = lstrSql & "vkwh_dev_ccee   DECIMAL(14,2) DEFAULT '0.00', " 'Kwh - Devolução da difereça entre o real e o provisório
		lstrSql = lstrSql & "vkwh_cob_ccee   DECIMAL(14,2) DEFAULT '0.00', " 'Kwh - Cobrança da diferença entre o real e o provisório
		'Receita
		lstrSql = lstrSql & "receita_p       DECIMAL(14,2) DEFAULT '0.00', "
		lstrSql = lstrSql & "receita_i       DECIMAL(14,2) DEFAULT '0.00', "
		lstrSql = lstrSql & "receita_fp      DECIMAL(14,2) DEFAULT '0.00', "
		'Irrigacao
		lstrSql = lstrSql & "vrec_irr_nor     DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO
		lstrSql = lstrSql & "vrec_irr_nor_ban DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO Bandeira
		lstrSql = lstrSql & "vrec_irr_res     DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO
		'Tarifa Branca
		lstrSql = lstrSql & "vrectarbranca_kwh_ponta DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO POTA
		lstrSql = lstrSql & "vrectarbranca_kwh_ponta_ban DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO PONTA Bandeira
		lstrSql = lstrSql & "vrectarbranca_kwh_inter DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO INTERMEDIARIO
		lstrSql = lstrSql & "vrectarbranca_kwh_inter_ban DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO INTERMEDIARIO Bandeira
		lstrSql = lstrSql & "vrectarbranca_kwh_forap DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO FORA PONTA
		lstrSql = lstrSql & "vrectarbranca_kwh_forap_ban DECIMAL(14,2) DEFAULT '0.00', " 'Kwh FATURADO FORA PONTA Bandeira
		'------ Reverso
		lstrSql = lstrSql & "qkwh_reverso DOUBLE, " 'Qtde kWh Reverso
		lstrSql = lstrSql & "vkwh_reverso DECIMAL(14,2) DEFAULT '0.00', " 'Vallor kWh Reverso
		'Reativo
		lstrSql = lstrSql & "vconreat_p  DECIMAL(14,2) DEFAULT '0.00', " 'REATIVO
		lstrSql = lstrSql & "vconreat_fp DECIMAL(14,2) DEFAULT '0.00', " 'REATIVO
		lstrSql = lstrSql & "vdemreat_p  DECIMAL(14,2) DEFAULT '0.00', " 'REATIVO
		lstrSql = lstrSql & "vdemreat_fp DECIMAL(14,2) DEFAULT '0.00', " 'REATIVO
		'Tributos
		lstrSql = lstrSql & "icms         DECIMAL(14,2) DEFAULT '0.00', " 'ICMS R$
		lstrSql = lstrSql & "pis          DECIMAL(14,2) DEFAULT '0.00', " 'PIS R$
		lstrSql = lstrSql & "cofins       DECIMAL(14,2) DEFAULT '0.00', " 'COFINS R$
		'Tributacao Comercializador usado para o Livre
		lstrSql = lstrSql & "icms_st      DECIMAL(14,2) DEFAULT '0.00', " 'Icms - ST
		lstrSql = lstrSql & "pis_st       DECIMAL(14,2) DEFAULT '0.00', " 'Pis - ST
		lstrSql = lstrSql & "cofins_st    DECIMAL(14,2) DEFAULT '0.00', " 'Cofins - ST
		'*********************************************
		lstrSql = lstrSql & "baseicms     DECIMAL(14,2) DEFAULT '0.00', " 'Base ICMS R$
		lstrSql = lstrSql & "basepis      DECIMAL(14,2) DEFAULT '0.00', " 'Base PIS R$
		lstrSql = lstrSql & "basecofins   DECIMAL(14,2) DEFAULT '0.00', " 'Base Cofins R$
		lstrSql = lstrSql & "icmspiscof   DECIMAL(14,2) DEFAULT '0.00', " 'ICMS/PIS/COFINS R$
		'Usinas
		lstrSql = lstrSql & "must_qtd DOUBLE DEFAULT '0', " 'MUST
		lstrSql = lstrSql & "must_vlr DECIMAL(14,2) DEFAULT '0.00', " 'MUST
		lstrSql = lstrSql & "must_des DECIMAL(14,2) DEFAULT '0.00', " 'MUST
		lstrSql = lstrSql & "must_enc DECIMAL(14,2) DEFAULT '0.00', " 'MUST
		lstrSql = lstrSql & " KEY `keyrefat` (`refaturado`), "
		lstrSql = lstrSql & " KEY `keygrupo` (`grupo`), "
		lstrSql = lstrSql & " KEY `keyclasse` (`classe`), "
		lstrSql = lstrSql & " KEY `keydsclas` (`ds_classe`), "
		lstrSql = lstrSql & " KEY `keycomcla` (`com_classe`), "
		lstrSql = lstrSql & " KEY `keyordcla` (`ord_classe`), "
		lstrSql = lstrSql & " KEY `keyparcat` (`parc_cativo`), "
		lstrSql = lstrSql & " KEY `keyunsina` (`usinas`) "
		lstrSql = lstrSql & ") ENGINE=InnoDB DEFAULT CHARSET=latin1;"
		Call Executar(lstrSql, True)
		Call Executar("DROP TEMPORARY TABLE IF EXISTS " & istrTab945)
		Call Executar("DROP TABLE IF EXISTS " & istrTab945)
		lstrSql = ""
		lstrSql = lstrSql & "CREATE TEMPORARY TABLE IF NOT EXISTS " & istrTab945 & "("
		'lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS " & istrTab945 & "("
		lstrSql = lstrSql & " refaturado TINYINT(1)   DEFAULT 0,"
		lstrSql = lstrSql & " ds_classe  VARCHAR(200) DEFAULT '', "
		lstrSql = lstrSql & " ord_classe TINYINT(2)   DEFAULT 0, "
		lstrSql = lstrSql & " faixa      INT(11)      DEFAULT 0,"
		lstrSql = lstrSql & " consumo    DOUBLE       DEFAULT 0,"
		lstrSql = lstrSql & " valor      DOUBLE       DEFAULT 0,"
		lstrSql = lstrSql & " bandeira   DOUBLE       DEFAULT 0,"
		lstrSql = lstrSql & " receita    DOUBLE       DEFAULT 0,"
		lstrSql = lstrSql & " icms       DOUBLE       DEFAULT 0,"
		lstrSql = lstrSql & " pis        DOUBLE       DEFAULT 0,"
		lstrSql = lstrSql & " cofins     DOUBLE       DEFAULT 0,"
		lstrSql = lstrSql & " KEY `keyrefat` (`refaturado`),"
		lstrSql = lstrSql & " KEY `keydsclas` (`ds_classe`), "
		lstrSql = lstrSql & " KEY `keyordcla` (`ord_classe`) "
		lstrSql = lstrSql & ") ENGINE=InnoDB DEFAULT CHARSET=latin1;"
		Call Executar(lstrSql)
	End Sub
	
	Private Function MontaTabela() As Boolean
		Dim lblnRetorno As Boolean
		Dim ldteIni As Date
		Dim ldteFim As Date
		Dim lintContInsertPri As Short
		'
		Dim llngAnoMes As Integer
		Dim lstrFase As String
		Dim lstrItens As String 'itens faturados
		Dim lintOrdCla As Short 'Ordem de impressao
		Dim lstrClasse As String 'Código da classe
		Dim lstrDsClas As String 'Descrição classe
		Dim lstrCmClas As String 'Complemento classe
		Dim lstrGrupo As String 'Grupo
		Dim lstrTensao As String
		Dim llngUnidId As Integer
		Dim lintLivreEspecial As Short 'Se é consumidor livre especial
		Dim lintParcialmenteCativo As Short 'Se é consumidor livre mas parcialmente cativo
		Dim lintLivreVerde As Short
		Dim lintMicroGeracao As Short
		Dim lintIrrigacaoAquicultura As Short
		Dim lintTarifaBranca As Short
		Dim lstrFlgst As String 'Situação Fatura
		Dim ldteFlgSt As Date
		Dim lstrFlgRe As String 'Refaturamento
		Dim lintFlgRe As Short
		Dim lintMpr As Short 'Usado para caso tiver alguma fatura cancelada no mês de faturamento de outro mês
		'Controle Baixa Renda REH 945
		Dim lintFaixa As Short
		Dim lstrDes945(1, 3) As String
		Dim lintQtdFxa(1, 3) As Short
		
		Dim ldblQtdkWh(1, 3) As Double
		Dim ldblVlrkWh(1, 3) As Double
		Dim ldblBankWh(1, 3) As Double
		
		Dim ldblQtd945(1, 3) As Double
		Dim ldblVlr945(1, 3) As Double
		Dim ldblBan945(1, 3) As Double
		
		Dim ldblVlrIcm(1, 3) As Double
		Dim ldblVlrPis(1, 3) As Double
		Dim ldblVlrCof(1, 3) As Double
		'Convencional
		'Qiantidade
		Dim ldblQKwhCons As Double 'Qtde Consumo lido
		Dim ldblQKwhFat As Double 'Qtde Consumo faturado
		Dim ldblQKwhFatBan As Double 'Qtde Consumo faturado Bandeira
		Dim ldblQKwhFatTU As Double 'Qtde consumo faturado TUSD
		Dim ldblQkWhFatTE As Double 'Qtde consumo faturado TE
		Dim ldblQkWhFatTEBan As Double 'Qtde consumo faturado TE Bandeira
		Dim ldblQKwhReverso As Double 'Qtde consumo reverso
		Dim ldblQKwContr As Double 'Qtde Demanda Contratada
		Dim ldblQKwFat As Double 'Qtde Demanda
		'
		Dim ldblVKwhCons As Double 'Valor Consumo lido
		Dim ldblVKwhFat As Double 'Valor Consumo faturado
		Dim ldblVKwhFatBan As Double 'Valor Consumo faturado Bandeira
		Dim ldblVkWhFatTU As Double 'Valor consumo faturado TUSD
		Dim ldblVkWhFatTE As Double 'Valor consumo faturado TE
		Dim ldblVkWhFatTEBan As Double 'Valor consumo faturado TE Bandeira
		Dim ldblVKwhReverso As Double 'valor consumo reverso
		Dim ldblVKwFat As Double 'Valor Demanda
		'
		'Horosazonal
		Dim ldblQKwhFatp As Double 'Qtde Consumo Faturado p
		Dim ldblQKwhFatfp As Double 'Qtde Consumo Faturado fp
		Dim ldblQKwhFatpBan As Double 'Qtde Consumo Faturado p Bandeira
		Dim ldblQKwhFatfpBan As Double 'Qtde Consumo Faturado fp Bandeira
		Dim ldblQKwhFatpLiv As Double 'Qtde Consumo Faturado p Livre
		Dim ldblQKwhFatfpLiv As Double 'Qtde Consumo Faturado fp Livre
		'
		Dim ldblQKwhDevp As Double 'Qtde Consumo Devolvido p
		Dim ldblQKwhDevfp As Double 'Qtde Consumo Devolvido fp
		Dim ldblQKwhUtrp As Double 'Qtde Consumo Ultrapassado p
		Dim ldblQKwhUtrfp As Double 'Qtde Consumo Ultrapassado fp
		'
		Dim ldblQKwContrp As Double 'Qtde Demanda Contratada Ponta
		Dim ldblQKwContrfp As Double 'Qtde Demanda Contratada Fora Ponta
		Dim ldblQKwFatp As Double 'Qtde Demanda p
		Dim ldblQKwFatfp As Double 'Qtde Demanda fp
		Dim ldblQKwFatUp As Double 'Qtde Demanda Ultrapassagem p
		Dim ldblQKwFatUfp As Double 'Qtde Demanda Ultrapassagem fp
		'
		Dim ldblVKwhFatp As Double 'Valor Consumo faturado p
		Dim ldblVKwhFatfp As Double 'Valor Consumo faturado fp
		Dim ldblVKwhFatpBan As Double 'Valor Consumo faturado p Badeira
		Dim ldblVKwhFatfpBan As Double 'Valor Consumo faturado fp Bandeira
		Dim ldblVKwhFatpLiv As Double 'Valor Consumo faturado p Livre
		Dim ldblVKwhFatfpLiv As Double 'Valor Consumo faturado fp Livre
		'
		Dim ldblVKwhDevp As Double 'Valor Consumo devolvido p
		Dim ldblVKwhDevfp As Double 'Valor Consumo devolvido fp
		Dim ldblVKwhUtrp As Double 'Valor Consumo Ultrapassado p
		Dim ldblVKwhUtrfp As Double 'Valor Consumo Ultrapassado fp
		'
		Dim ldblVKwFatp As Double 'Valor Demanda p
		Dim ldblVKwFatfp As Double 'Valor Demanda fp
		Dim ldblVKwFatUp As Double 'Valor Demanda Ultrapassagem p
		Dim ldblVKwFatUfp As Double 'Valor Demanda Ultrapassagem fp
		'
		Dim ldblVkwDscProv As Double 'Desconto provisorio
		Dim ldblVkwDscReal As Double 'Desconto real
		Dim ldblVkwDevCcee As Double 'Diferença a devolver
		Dim ldblVkwCobCcee As Double 'Diferença a cobrar
		'
		Dim ldblVkwhDscProv As Double 'Desconto provisorio
		Dim ldblVkwhDscReal As Double 'Desconto real
		Dim ldblVkwhDevCcee As Double 'Diferença a devolver
		Dim ldblVkwhCobCcee As Double 'Diferença a cobrar
		'
		Dim ldblReceita_p As Double
		Dim ldblReceita_I As Double
		Dim ldblReceita_fp As Double
		'
		Dim ldblIcms As Double 'Valor de icms.
		Dim ldblPis As Double 'Valor de PIS.
		Dim ldblCofins As Double 'Valor de COFINS.
		'
		Dim ldblIcmsSt As Double 'Icms Sistema Transmissão
		Dim ldblPisSt As Double 'Pis Sistema Transmissão
		Dim ldblCofinsSt As Double 'Cofns Sistema Transmissão
		'
		Dim ldblBaseIcms As Double 'Valor Base icms.
		Dim ldblBasePis As Double 'Valor Base PIS.
		Dim ldblBaseCofins As Double 'Valor Base COFINS.
		'
		Dim ldblIcmsPisCof As Double 'valor de icms/pis/cofins.
		'
		Dim ldblQtdMust As Double 'qtde
		Dim ldblVlrMust As Double 'valor
		Dim ldblEncMust As Double 'encargo
		Dim ldblDesMust As Double 'desconto
		'
		Dim ldblConsumoReativo As Double 'Consumo Reativo (Convencional)
		Dim ldblDemandaReativa As Double 'Demanda Reativo (Convencional)
		Dim ldblConsumoReativop As Double 'Consumo Reativo na ponta (Horosazonal)
		Dim ldblConsumoReativofp As Double 'Consumo Reativo fora da ponta (Horosazonal)
		Dim ldblDemandaReativap As Double 'Demanda Reativo na ponta (Horosazonal)
		Dim ldblDemandaReativafp As Double 'Demanda Reativo fora da ponta (Horosazonal)
		'Irrigacao
		Dim ldblQIrr_Normal_kWh_fat As Double
		Dim ldblQIrr_Reserv_kWh_fat As Double
		Dim ldblVIrr_Normal_kWh_fat As Double
		Dim ldblVIrr_Normal_kWh_fat_ban As Double
		Dim ldblVIrr_Reserv_kWh_fat As Double
		Dim ldblVIrr_Reserv_kWh_fat_ban As Double
		Dim ldblTarifa_irrigante As Double
		Dim ldblTarifa_irrigante_ban As Double
		Dim ldblVIrr_Desconto As Double
		Dim ldblVIrr_Desconto_ban As Double
		'Tarifa Branca
		Dim ldblQTarBranca_kWh_Ponta As Double
		Dim ldblQTarBranca_kWh_Ponta_Ban As Double
		Dim ldblQTarBranca_kWh_Inter As Double
		Dim ldblQTarBranca_kWh_Inter_Ban As Double
		Dim ldblQTarBranca_kWh_ForaP As Double
		Dim ldblQTarBranca_kWh_ForaP_Ban As Double
		Dim ldblVTarBranca_kWh_Ponta As Double
		Dim ldblVTarBranca_kWh_Ponta_Ban As Double
		Dim ldblVTarBranca_kWh_Inter As Double
		Dim ldblVTarBranca_kWh_Inter_Ban As Double
		Dim ldblVTarBranca_kWh_ForaP As Double
		Dim ldblVTarBranca_kWh_ForaP_Ban As Double
		'
		Dim lintRef As Short
		Dim lintAux As Short
		Dim lstrSql As String
		Dim lstrSqlPri As String
		Dim lstrSqlPAx As String
		Dim lrstAux As ADODB.Recordset
		'
		On Error GoTo ErrMontaTabela
		'
		Call Executar("START TRANSACTION", False)
		'
		lrstAux = New ADODB.Recordset
		'
		Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
		Call LigDes(False)
		Me.lblInfo.Text = " Buscando faturas aguarde..."
		Call Me.lblInfo.Refresh()
		Me.lblPerc.Text = ""
		Call Me.lblPerc.Refresh()
		Me.lblInfoArq.Text = ""
		Call Me.lblInfoArq.Refresh()
		Me.lblPercArq.Text = ""
		Call Me.lblPercArq.Refresh()
		Me.lblInfoPre.Text = ""
		Call Me.lblInfoPre.Refresh()
		Me.lblPercPre.Text = ""
		Call Me.lblPercPre.Refresh()
		Me.ProgressBar.Value = 0
		Me.ProgressBarArq.Value = 0
		Me.ProgressBarPre.Value = 0
		System.Windows.Forms.Application.DoEvents()
		'
		ldteFim = CDate(UltimoDiaMes((Me.dtpMesAno.Month), (Me.dtpMesAno.Year)) & "/" & VB6.Format(Me.dtpMesAno.value, "MM/yyyy"))
		ldteIni = CDate("01/" & VB6.Format(ldteFim, "MM/yyyy"))
		'
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * " & vbCrLf
		lstrSql = lstrSql & "  FROM " & gstrDataBase & ".`nf` " & vbCrLf
		lstrSql = lstrSql & " WHERE ((`mesano_ref` = " & CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")) & " " & vbCrLf
		lstrSql = lstrSql & "   AND `mesano` = '" & VB6.Format(Me.dtpMesAno.value, "MM/yyyy") & "') " & vbCrLf
		'lstrSql = lstrSql & "    OR (flgst = 'C' AND mesano_ref <> REPLACE(LEFT(datast, 7),'-','') AND datast BETWEEN '" & Strings.Format(ldteIni, "yyyy-MM-dd") & "' AND '" & Strings.Format(ldteFim, "yyyy-MM-dd") & "'))" & vbCrLf
		lstrSql = lstrSql & "   AND (`flgst` <> 'C' OR " & vbCrLf
		lstrSql = lstrSql & "        ( (`flgst` = 'C' AND `datast` > '" & VB6.Format(ldteFim, "yyyy-MM-dd") & "') OR " & vbCrLf
		lstrSql = lstrSql & "          (`flgst` = 'C' AND `mesano_ref` <> REPLACE(LEFT(`datast`, 7),'-','') AND `datast` BETWEEN '" & VB6.Format(ldteIni, "yyyy-MM-dd") & "' AND '" & VB6.Format(ldteFim, "yyyy-MM-dd") & "')" & vbCrLf
		lstrSql = lstrSql & "         )" & vbCrLf
		lstrSql = lstrSql & "       ))" & vbCrLf
		''lstrSql = lstrSql & "  AND codclas in(5701,5502)"
		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, " Faturas ")
					lstrSqlPri = "INSERT INTO " & gstrDataBase & "." & istrTabela
					lstrSqlPri = lstrSqlPri & " (refaturado, grupo, classe, ds_classe, com_classe, ord_classe, parc_cativo, usinas, micro_geracao, irrigacao_aquicultura, tarifa_branca, "
					'Convencional
					'Qtde
					lstrSqlPri = lstrSqlPri & "qkwh_cons, qkwh_fat, qkwh_fat_ban, qkw_fat, "
					'Valor
					lstrSqlPri = lstrSqlPri & "vkwh_cons, vkwh_fat, vkwh_fat_ban, vkw_fat, vconreat, vdemreat, "
					'Horosazonal
					'Qtde
					lstrSqlPri = lstrSqlPri & "qkwh_fat_p, qkwh_fat_fp, qkwh_fat_p_ban, qkwh_fat_fp_ban, qkwh_fat_p_liv, qkwh_fat_fp_liv, "
					lstrSqlPri = lstrSqlPri & "qkwh_dev_p, qkwh_dev_fp, qkwh_utr_p, qkwh_utr_fp, "
					lstrSqlPri = lstrSqlPri & "qkw_fat_p, qkw_fat_fp, qkw_fatu_p, qkw_fatu_fp, "
					'Valor
					lstrSqlPri = lstrSqlPri & "vkwh_fat_p, vkwh_fat_fp, vkwh_fat_p_ban, vkwh_fat_fp_ban, vkwh_fat_p_liv, vkwh_fat_fp_liv, "
					lstrSqlPri = lstrSqlPri & "vkwh_dev_p, vkwh_dev_fp, vkwh_utr_p, vkwh_utr_fp, vkw_fat_p, vkw_fat_fp, vkw_fatu_p, vkw_fatu_fp, "
					lstrSqlPri = lstrSqlPri & "vkw_dsc_prov, vkw_dsc_real, vkw_dev_ccee, vkw_cob_ccee, vkwh_dsc_prov, vkwh_dsc_real, vkwh_dev_ccee, vkwh_cob_ccee, "
					'Reativo
					lstrSqlPri = lstrSqlPri & "vconreat_p, vconreat_fp, vdemreat_p, vdemreat_fp, "
					'Receita
					lstrSqlPri = lstrSqlPri & "receita_p, receita_i, receita_fp, "
					'Reverso
					lstrSqlPri = lstrSqlPri & "qkwh_reverso, vkwh_reverso, "
					'Irrigacao
					lstrSqlPri = lstrSqlPri & "qirr_nor_kwh_fat, qirr_nor_kwh_fat_ban, qirr_res_kwh_fat, qirr_res_kwh_fat_ban, "
					lstrSqlPri = lstrSqlPri & "virr_nor_kwh_fat, virr_nor_kwh_fat_ban, virr_res_kwh_fat, virr_res_kwh_fat_ban, "
					'Tarifa Branca
					lstrSqlPri = lstrSqlPri & "qtarbranca_kwh_ponta, qtarbranca_kwh_ponta_ban, qtarbranca_kwh_inter, qtarbranca_kwh_inter_ban, qtarbranca_kwh_forap, qtarbranca_kwh_forap_ban, "
					lstrSqlPri = lstrSqlPri & "vtarbranca_kwh_ponta, vtarbranca_kwh_ponta_ban, vtarbranca_kwh_inter, vtarbranca_kwh_inter_ban, vtarbranca_kwh_forap, vtarbranca_kwh_forap_ban, "
					'Tributos
					lstrSqlPri = lstrSqlPri & "icms, pis, cofins, "
					'Tributacao Comercializador usado para o Livre
					lstrSqlPri = lstrSqlPri & "icms_st, pis_st, cofins_st, "
					'Base de calculo
					lstrSqlPri = lstrSqlPri & "baseicms, basepis, basecofins, icmspiscof, "
					'Usinas
					lstrSqlPri = lstrSqlPri & "must_qtd, must_vlr, must_des, must_enc) VALUES "
					lstrSqlPAx = ""
					lintContInsertPri = 1
					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"'
						llngAnoMes = IIf(IsDbNull(.Fields("mesano_ref").value), 0, .Fields("mesano_ref").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrFlgRe = Trim(IIf(IsDbNull(.Fields("flgmedfat").value), "N", .Fields("flgmedfat").value))
						If lstrFlgRe = "" Then lstrFlgRe = "N"
						If lstrFlgRe = "S" Then
							lintFlgRe = 1
						Else
							lintFlgRe = 0
						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"'
						lstrItens = IIf(IsDbNull(.Fields("itensserv").Value), "", .Fields("itensserv").Value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrClasse = IIf(IsDbNull(.Fields("codclas").value), "0000", .Fields("codclas").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrGrupo = Mid(IIf(IsDbNull(.Fields("ta").value), "", .Fields("ta").value), 3, 2)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrFase = IIf(IsDbNull(.Fields("fase").value), "M", .Fields("fase").value)
						If Mid(lstrGrupo, 1) = "B" Then
							If lstrFase = "M" Then
								lstrTensao = "220"
							ElseIf lstrFase = "B" Then 
								lstrTensao = "220"
							ElseIf lstrFase = "T" Then 
								lstrTensao = "380"
							End If
						ElseIf Mid(lstrGrupo, 1) = "A" 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"'
							lstrTensao = IIf(IsDbNull(.Fields("tensao").value), "380", .Fields("tensao").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"'
						llngUnidId = IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lintLivreEspecial = IIf(IsDbNull(.Fields("livreespecial").value), 0, .Fields("livreespecial").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"'
						lintParcialmenteCativo = IIf(IsDbNull(.Fields("parcialmente_cativo").value), 0, .Fields("parcialmente_cativo").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lintLivreVerde = IIf(IsDbNull(.Fields("livre_verde").value), 0, .Fields("livre_verde").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"'
						lintMicroGeracao = IIf(IsDbNull(.Fields("micro_geracao").value), 0, .Fields("micro_geracao").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"'
						lintIrrigacaoAquicultura = IIf(IsDbNull(.Fields("irrigacao_aquicultura").value), 0, .Fields("irrigacao_aquicultura").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lintTarifaBranca = IIf(IsDbNull(.Fields("tarifa_branca").value), 0, .Fields("tarifa_branca").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrFlgst = Trim(IIf(IsDbNull(.Fields("flgst").value), "", .Fields("flgst").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"'
						ldteFlgSt = CDate(IIf(IsDbNull(.Fields("datast").value), "1900-01-01", .Fields("datast").value))
						If lstrFlgst = "C" Then
							If ldteFlgSt <= ldteFim Then
								lintMpr = -1
							Else
								lintMpr = 1
							End If
						Else
							lintMpr = 1
						End If
						'Convencional
						'Quantidade
						ldblQKwhCons = 0 'Consumo lido
						ldblQKwhFat = 0 'Consumo faturado
						ldblVKwhFatBan = 0 'Consumo faturado bandeira
						ldblQKwhFatTU = 0 'Consumo faturado TUSD
						ldblQkWhFatTE = 0 'Consumo faturado TE
						ldblQkWhFatTEBan = 0 'Consumo faturado TE bandeira
						ldblQKwhReverso = 0 'Consumo reverso
						ldblQKwFat = 0 'Demanda
						'Valor
						ldblVKwhCons = 0 'Consumo lido
						ldblVKwhFat = 0 'Consumo faturado
						ldblVKwhFatBan = 0 'Consumo faturado Bandeira
						ldblVkWhFatTU = 0 'Consumo faturado TUSD
						ldblVkWhFatTE = 0 'Consumo faturado TE
						ldblVkWhFatTEBan = 0 'Consumo faturado TE bandeira
						ldblVKwhReverso = 0 'Consumo reverso
						ldblVKwFat = 0 'Demanda
						'
						'Horosazonal
						'Quantidade
						ldblQKwhFatp = 0 'Qtde Consumo faturado p
						ldblQKwhFatfp = 0 'Qtde Consumo faturado fp
						ldblQKwhFatpBan = 0 'Qtde Consumo faturado p Bandeira
						ldblQKwhFatfpBan = 0 'Qtde Consumo faturado fp Bandeira
						ldblQKwhFatpLiv = 0 'Qtde Consumo faturado p Livre
						ldblQKwhFatfpLiv = 0 'Qtde Consumo faturado fp Livre
						'
						ldblQKwhDevp = 0 'Qtde Consumo Devolvido p
						ldblQKwhDevfp = 0 'Qtde Consumo Devolvido fp
						ldblQKwhUtrp = 0 'Qtde Consumo Ultrapassado p
						ldblQKwhUtrfp = 0 'Qtde Consumo Ultrapassado fp
						'
						ldblQKwFatp = 0 'Qtde Demanda p
						ldblQKwFatfp = 0 'Qtde Demanda fp
						ldblQKwFatUp = 0 'Qtde Demanda de ultrapassagem p
						ldblQKwFatUfp = 0 'Qtde Demanda de ultrapassagem fp
						'Valor
						ldblVKwhFatp = 0 'Valor Consumo faturado p
						ldblVKwhFatfp = 0 'Valor Consumo faturado fp
						ldblVKwhFatpBan = 0 'Valor Consumo faturado p Bandeira
						ldblVKwhFatfpBan = 0 'Valor Consumo faturado fp Bandeira
						ldblVKwhFatpLiv = 0 'Valor Consumo faturado p Livre
						ldblVKwhFatfpLiv = 0 'Valor Consumo faturado fp Livre
						'
						ldblVKwhDevp = 0 'Valor Consumo devolvido p
						ldblVKwhDevfp = 0 'Valor Consumo devolvido fp
						ldblVKwhUtrp = 0 'Valor Consumo Ultrapassado p
						ldblVKwhUtrfp = 0 'Valor Consumo Ultrapassado fp
						'
						ldblVKwFatp = 0 'Valor Demanda p
						ldblVKwFatfp = 0 'Valor Demanda fp
						ldblVKwFatUp = 0 'Valor Demanda de ultrapassagem p
						ldblVKwFatUfp = 0 'Valor Demanda de ultrapassagem fp
						'Desconto Provisorio
						ldblVkwDscProv = 0 'Desconto provisorio
						ldblVkwDscReal = 0 'Desconto real
						ldblVkwDevCcee = 0 'Diferença a devolver
						ldblVkwCobCcee = 0 'Diferença a cobrar
						ldblVkwhDscProv = 0 'Desconto provisorio
						ldblVkwhDscReal = 0 'Desconto real
						ldblVkwhDevCcee = 0 'Diferença a devolver
						ldblVkwhCobCcee = 0 'Diferença a cobrar
						'
						ldblReceita_p = 0
						ldblReceita_fp = 0
						'----
						ldblIcms = 0 'Vlr Icms.
						ldblPis = 0 'Vlr PIS.
						ldblCofins = 0 'Vlr COFINS.
						'
						ldblIcmsSt = 0
						ldblPisSt = 0
						ldblCofinsSt = 0
						'
						ldblBaseIcms = 0 'Vlr Base Icms.
						ldblBasePis = 0 'Vlr Base PIS.
						ldblBaseCofins = 0 'Vlr Base COFINS.
						'
						ldblIcmsPisCof = 0 'Vlr Icms/Pis/Cofins.
						ldblQtdMust = 0 'MUST
						ldblVlrMust = 0 'MUST
						ldblEncMust = 0 'MUST
						ldblDesMust = 0 'MUST
						'
						ldblConsumoReativo = 0 'Consumo Reativo
						ldblDemandaReativa = 0 'Demanda Reativo
						ldblConsumoReativop = 0 'Consumo Reativo p
						ldblConsumoReativofp = 0 'Consumo Reativo fp
						ldblDemandaReativap = 0 'Demanda Reativo p
						ldblDemandaReativafp = 0 'Demanda Reativo fp
						'Irrigacao
						ldblQIrr_Normal_kWh_fat = 0
						ldblQIrr_Reserv_kWh_fat = 0
						ldblVIrr_Normal_kWh_fat = 0
						ldblVIrr_Normal_kWh_fat_ban = 0
						ldblVIrr_Reserv_kWh_fat = 0
						ldblVIrr_Reserv_kWh_fat_ban = 0
						ldblTarifa_irrigante = 0
						ldblTarifa_irrigante_ban = 0
						ldblVIrr_Desconto = 0
						ldblVIrr_Desconto_ban = 0
						'Tarifa Branca
						ldblQTarBranca_kWh_Ponta = 0
						ldblQTarBranca_kWh_Ponta_Ban = 0
						ldblQTarBranca_kWh_Inter = 0
						ldblQTarBranca_kWh_Inter_Ban = 0
						ldblQTarBranca_kWh_ForaP = 0
						ldblQTarBranca_kWh_ForaP_Ban = 0
						ldblVTarBranca_kWh_Ponta = 0
						ldblVTarBranca_kWh_Ponta_Ban = 0
						ldblVTarBranca_kWh_Inter = 0
						ldblVTarBranca_kWh_Inter_Ban = 0
						ldblVTarBranca_kWh_ForaP = 0
						ldblVTarBranca_kWh_ForaP_Ban = 0
						
						'************
						ldblBaseIcms = (BuscaVlrItem(lstrItens, "0302030001") + BuscaVlrItem(lstrItens, "0302030003")) * lintMpr
						ldblBasePis = BuscaVlrItem(lstrItens, "0302020033") * lintMpr
						ldblBaseCofins = BuscaVlrItem(lstrItens, "302020034") * lintMpr
						Select Case VB.Left(lstrClasse, 1)
							Case Is = CStr(9)
								If VB.Right(lstrClasse, 1) <> "1" Then
									lstrDsClas = "Bx.Renda"
									lintOrdCla = 20
								Else
									lstrDsClas = "Residencial Normal"
									lintOrdCla = 10
								End If
							Case Is = CStr(4)
								lstrDsClas = "Comercial"
								lintOrdCla = 40
							Case Is = CStr(5)
								lstrDsClas = "Rural"
								lintOrdCla = 50
								If VB.Left(lstrClasse, 2) = "55" And lintIrrigacaoAquicultura = 1 Then
									lstrDsClas = "Rural Irrigante"
									lintOrdCla = 55
								ElseIf VB.Left(lstrClasse, 2) = "57" And lintIrrigacaoAquicultura = 1 Then 
									lstrDsClas = "Rural Aquicultor"
									lintOrdCla = 57
								ElseIf VB.Left(lstrClasse, 2) = "52" Then 
									lstrDsClas = "Rural Coop. Eletrif. Rural"
									lintOrdCla = 52
								ElseIf VB.Left(lstrClasse, 2) = "54" Then 
									lstrDsClas = "Rural Serv. Púb. Irrigação"
									lintOrdCla = 54
								End If
							Case Is = CStr(7)
								lstrDsClas = "Serviço Público"
								lintOrdCla = 70
								If VB.Left(lstrClasse, 2) = "71" Then
									lstrDsClas = "Serviço Público (tração elétrica)"
									lintOrdCla = 71
								ElseIf VB.Left(lstrClasse, 2) = "73" Then 
									lstrDsClas = "Serviço Público de Irrigação"
									lintOrdCla = 73
								End If
							Case Is = CStr(8)
								lstrDsClas = "Consumo Próprio"
								lintOrdCla = 80
							Case Is < CStr(4)
								lstrDsClas = "Industrial"
								lintOrdCla = 30
							Case Is = CStr(6)
								If VB.Left(lstrClasse, 4) = "6401" Then
									lstrDsClas = "Ilum.Púb.(Rede)"
									lintOrdCla = 61
								ElseIf VB.Left(lstrClasse, 4) = "6402" Then 
									lstrDsClas = "Ilum.Púb.(Bulbo)"
									lintOrdCla = 62
								Else
									lstrDsClas = "Poder Público"
									lintOrdCla = 60
								End If
							Case Else
								lstrDsClas = "Indefinido"
								lintOrdCla = 90
						End Select
						If lstrGrupo = "AS" Or lstrGrupo = "A4" Or VB.Left(lstrGrupo, 1) = "B" Then
							'Quantidade
							If VB.Left(lstrGrupo, 1) <> "B" Then
								ldblQKwhCons = BuscaVlrItem(lstrItens, "0302010008") * lintMpr 'Consumo lido
								ldblQKwhFat = BuscaVlrItem(lstrItens, "0302010009") * lintMpr 'Consumo faturado
								ldblQKwhFatBan = BuscaVlrItem(lstrItens, "0302110009") * lintMpr 'Consumo faturado bandeira
								ldblVKwhCons = BuscaVlrItem(lstrItens, "0302020008") * lintMpr 'Consumo lido
								ldblVKwhFat = BuscaVlrItem(lstrItens, "0302020009") * lintMpr 'Consumo faturado
								ldblVKwhFatBan = BuscaVlrItem(lstrItens, "0302120009") * lintMpr 'Consumo faturado bandeira
								ldblReceita_fp = ldblReceita_fp + ldblVKwhFat + ldblVKwhFatBan
								If lstrGrupo = "AS" Then
									lstrDsClas = "Suprimento"
								End If
							Else
								ldblQKwhCons = BuscaVlrItem(lstrItens, "030201008") * lintMpr 'Consumo lido
								ldblQKwhFat = BuscaVlrItem(lstrItens, "030201009") * lintMpr 'Consumo faturado
								ldblQKwhFatBan = BuscaVlrItem(lstrItens, "030211009") * lintMpr 'Consumo faturado bandeira
								ldblVKwhCons = BuscaVlrItem(lstrItens, "030202008") * lintMpr 'Consumo lido
								ldblVKwhFat = BuscaVlrItem(lstrItens, "030202009") * lintMpr 'Consumo faturado
								ldblVKwhFatBan = BuscaVlrItem(lstrItens, "030212009") * lintMpr 'Consumo faturado bandeira
								'
								If lintIrrigacaoAquicultura = 1 Then
									ldblTarifa_irrigante = BuscaVlrItem(lstrItens, "01B2011101")
									ldblTarifa_irrigante_ban = BuscaVlrItem(lstrItens, "10B2011101")
									If ldblTarifa_irrigante_ban = 0 Then
										ldblTarifa_irrigante_ban = BuscaVlrItem(lstrItens, "20B2011101")
									End If
									If ldblTarifa_irrigante_ban = 0 Then
										ldblTarifa_irrigante_ban = BuscaVlrItem(lstrItens, "30B2011101")
									End If
									ldblVIrr_Desconto = (BuscaVlrItem(lstrItens, "9070000009") * -1) * lintMpr
									ldblVIrr_Desconto_ban = (BuscaVlrItem(lstrItens, "9070000008") * -1) * lintMpr
									
									ldblQIrr_Reserv_kWh_fat = BuscaVlrItem(lstrItens, "0302990054") * lintMpr
									ldblQIrr_Normal_kWh_fat = ldblQKwhFat - ldblQIrr_Reserv_kWh_fat
									
									ldblVIrr_Normal_kWh_fat = Truncate(ldblQIrr_Normal_kWh_fat * ldblTarifa_irrigante, 2)
									ldblVIrr_Normal_kWh_fat_ban = Truncate(ldblQIrr_Normal_kWh_fat * ldblTarifa_irrigante_ban, 2)
									
									ldblVIrr_Reserv_kWh_fat = Truncate(ldblQIrr_Reserv_kWh_fat * ldblTarifa_irrigante, 2) '+ ldblVIrr_Desconto
									ldblVIrr_Reserv_kWh_fat_ban = Truncate(ldblQIrr_Reserv_kWh_fat * ldblTarifa_irrigante_ban, 2) '+ ldblVIrr_Desconto_ban
								End If
								If lintTarifaBranca = 1 Then
									ldblQTarBranca_kWh_Ponta = BuscaValorItem(lstrItens, "0302010190") * lintMpr
									ldblQTarBranca_kWh_Ponta_Ban = BuscaValorItem(lstrItens, "0302110190") * lintMpr
									ldblQTarBranca_kWh_Inter = BuscaValorItem(lstrItens, "0302010290") * lintMpr
									ldblQTarBranca_kWh_Inter_Ban = BuscaValorItem(lstrItens, "0302110290") * lintMpr
									ldblQTarBranca_kWh_ForaP = BuscaValorItem(lstrItens, "0302010390") * lintMpr
									ldblQTarBranca_kWh_ForaP_Ban = BuscaValorItem(lstrItens, "0302110390") * lintMpr
									
									ldblVTarBranca_kWh_Ponta = BuscaValorItem(lstrItens, "0302020190") * lintMpr
									ldblVTarBranca_kWh_Ponta_Ban = BuscaValorItem(lstrItens, "0302120190") * lintMpr
									ldblVTarBranca_kWh_Inter = BuscaValorItem(lstrItens, "0302020290") * lintMpr
									ldblVTarBranca_kWh_Inter_Ban = BuscaValorItem(lstrItens, "0302120290") * lintMpr
									ldblVTarBranca_kWh_ForaP = BuscaValorItem(lstrItens, "0302020390") * lintMpr
									ldblVTarBranca_kWh_ForaP_Ban = BuscaValorItem(lstrItens, "0302120390") * lintMpr
									
									
									ldblReceita_p = ldblReceita_p + ldblVTarBranca_kWh_Ponta + ldblVTarBranca_kWh_Ponta_Ban
									ldblReceita_I = ldblReceita_I + ldblVTarBranca_kWh_Inter + ldblVTarBranca_kWh_Inter_Ban
									ldblReceita_fp = ldblReceita_fp + ldblVTarBranca_kWh_ForaP + ldblVTarBranca_kWh_ForaP_Ban
								End If
								'
								ldblReceita_fp = ldblReceita_fp + ldblVKwhFat + ldblVKwhFatBan
								'
								ldblQKwhFatTU = BuscaVlrItem(lstrItens, "030301009") * lintMpr 'consumo faturado TUSD
								ldblQkWhFatTE = BuscaVlrItem(lstrItens, "030401009") * lintMpr 'consumo faturado TE
								ldblQkWhFatTEBan = BuscaVlrItem(lstrItens, "030411009") * lintMpr 'consumo faturado TE bandeira
								ldblVkWhFatTU = BuscaVlrItem(lstrItens, "030302009") * lintMpr 'consumo faturado TUSD
								ldblVkWhFatTE = BuscaVlrItem(lstrItens, "030402009") * lintMpr 'consumo faturado TE
								ldblVkWhFatTEBan = BuscaVlrItem(lstrItens, "030412009") * lintMpr 'consumo faturado TE bandeira
								ldblQKwhReverso = BuscaVlrItem(lstrItens, "0302020996") * lintMpr 'Qtde Reverso
								ldblVKwhReverso = BuscaVlrItem(lstrItens, "0302020994") * lintMpr 'Valor Reverso
								If ldblVKwhReverso = 0 Then
									If ldblVkWhFatTU + ldblVkWhFatTE > 0 Then
										ldblVKwhReverso = (ldblVKwhFat - (ldblVkWhFatTU + ldblVkWhFatTE)) * lintMpr 'Valor Reverso
										If ldblVKwhFat - (ldblVkWhFatTU + ldblVkWhFatTE) > 0 Then
											ldblVKwhReverso = ldblVKwhReverso + (ldblVKwhFatBan - ldblVkWhFatTEBan)
										End If
									End If
								End If
								'fator de conversao 1ah em 220 = 0.22 em 380 = .38
								'1436Ah em 220v = 315.92 kWh
								'1436Ah em 380v = 545.68 kWh
								'820Ah em 220v = 180.4 kWh
								'820Ah em 380v = 311.6 kWh
								If llngAnoMes <= 201512 And lintMicroGeracao = 1 And VB.Left(lstrGrupo, 1) = "B" Then
									ldblQKwhFat = ldblQKwhFat - ldblQKwhReverso
									If lstrFase = "M" And ldblQKwhFat < 30 Then
										ldblQKwhFat = 30
									ElseIf lstrFase = "B" And ldblQKwhFat < 50 Then 
										ldblQKwhFat = 50
									ElseIf lstrFase = "T" And ldblQKwhFat < 100 Then 
										ldblQKwhFat = 100
									End If
								End If
								If VB.Left(lstrClasse, 1) = "4" Then
									If ((lstrTensao = "220" And ldblVKwhFat <= 180.4) Or (lstrTensao = "380" And ldblVKwhFat <= 311.6)) Then
										lintOrdCla = 41
									ElseIf ((lstrTensao = "220" And ldblVKwhFat <= 315.92) Or (lstrTensao = "380" And ldblVKwhFat <= 545.68)) Then 
										lintOrdCla = 42
									End If
								End If
								If lstrFlgRe = "S" Then
									lintFlgRe = 1
								Else
									lintFlgRe = 0
								End If
								If InStr(1, lstrDsClas, "Bx.Renda") > 0 Then
									
									ldblQtdkWh(lintFlgRe, 0) = BuscaVlrItem(lstrItens, "0302010090") 'faixa1
									ldblQtdkWh(lintFlgRe, 1) = BuscaVlrItem(lstrItens, "0302010091") 'faixa2
									ldblQtdkWh(lintFlgRe, 2) = BuscaVlrItem(lstrItens, "0302010092") 'faixa3
									ldblQtdkWh(lintFlgRe, 3) = BuscaVlrItem(lstrItens, "0302010093") 'faixa4
									ldblVlrkWh(lintFlgRe, 0) = BuscaVlrItem(lstrItens, "0302020090") 'faixa1
									ldblVlrkWh(lintFlgRe, 1) = BuscaVlrItem(lstrItens, "0302020091") 'faixa2
									ldblVlrkWh(lintFlgRe, 2) = BuscaVlrItem(lstrItens, "0302020092") 'faixa3
									ldblVlrkWh(lintFlgRe, 3) = BuscaVlrItem(lstrItens, "0302020093") 'faixa4
									ldblBankWh(lintFlgRe, 0) = BuscaVlrItem(lstrItens, "0302120090") 'faixa1
									ldblBankWh(lintFlgRe, 1) = BuscaVlrItem(lstrItens, "0302120091") 'faixa2
									ldblBankWh(lintFlgRe, 2) = BuscaVlrItem(lstrItens, "0302120092") 'faixa3
									ldblBankWh(lintFlgRe, 3) = BuscaVlrItem(lstrItens, "0302120093") 'faixa4
									If ldblQKwhFat <= 30 Then
										lintOrdCla = 21
										lintFaixa = 0
										lstrDes945(lintFlgRe, lintFaixa) = lstrDsClas & " 0 até 30"
									ElseIf ldblQKwhFat > 30 And ldblQKwhFat <= 100 Then 
										lintOrdCla = 22
										lintFaixa = 1
										lstrDes945(lintFlgRe, lintFaixa) = lstrDsClas & " 31 até 100"
									ElseIf ldblQKwhFat > 100 And ldblQKwhFat <= 220 Then 
										lintOrdCla = 23
										lintFaixa = 2
										lstrDes945(lintFlgRe, lintFaixa) = lstrDsClas & " 101 até 220"
									ElseIf ldblQKwhFat > 220 Then 
										lintOrdCla = 24
										lintFaixa = 3
										lstrDes945(lintFlgRe, lintFaixa) = lstrDsClas & " acima de 220"
									End If
									lintQtdFxa(lintFlgRe, lintFaixa) = lintQtdFxa(lintFlgRe, lintFaixa) + 1
									If lintFaixa >= 0 And lintFaixa <= 3 Then
										ldblQtd945(lintFlgRe, 0) = ldblQtd945(lintFlgRe, 0) + ldblQtdkWh(lintFlgRe, 0)
										ldblVlr945(lintFlgRe, 0) = ldblVlr945(lintFlgRe, 0) + ldblVlrkWh(lintFlgRe, 0)
										ldblBan945(lintFlgRe, 0) = ldblBan945(lintFlgRe, 0) + ldblBankWh(lintFlgRe, 0)
										If lintFaixa = 0 Then
											ldblVlrIcm(lintFlgRe, 0) = ldblVlrIcm(lintFlgRe, 0) + (BuscaVlrItem(lstrItens, "0302030009") + BuscaVlrItem(lstrItens, "0302030010"))
											ldblVlrPis(lintFlgRe, 0) = ldblVlrPis(lintFlgRe, 0) + BuscaVlrItem(lstrItens, "0302020029")
											ldblVlrCof(lintFlgRe, 0) = ldblVlrCof(lintFlgRe, 0) + BuscaVlrItem(lstrItens, "0302020030")
										End If
									End If
									If lintFaixa >= 1 And lintFaixa <= 3 Then
										ldblQtd945(lintFlgRe, 1) = ldblQtd945(lintFlgRe, 1) + ldblQtdkWh(lintFlgRe, 1)
										ldblVlr945(lintFlgRe, 1) = ldblVlr945(lintFlgRe, 1) + ldblVlrkWh(lintFlgRe, 1)
										ldblBan945(lintFlgRe, 1) = ldblBan945(lintFlgRe, 1) + ldblBankWh(lintFlgRe, 1)
										If lintFaixa = 1 Then
											ldblVlrIcm(lintFlgRe, 1) = ldblVlrIcm(lintFlgRe, 1) + (BuscaVlrItem(lstrItens, "0302030009") + BuscaVlrItem(lstrItens, "0302030010"))
											ldblVlrPis(lintFlgRe, 1) = ldblVlrPis(lintFlgRe, 1) + BuscaVlrItem(lstrItens, "0302020029")
											ldblVlrCof(lintFlgRe, 1) = ldblVlrCof(lintFlgRe, 1) + BuscaVlrItem(lstrItens, "0302020030")
										End If
									End If
									If lintFaixa >= 2 And lintFaixa <= 3 Then
										ldblQtd945(lintFlgRe, 2) = ldblQtd945(lintFlgRe, 2) + ldblQtdkWh(lintFlgRe, 2)
										ldblVlr945(lintFlgRe, 2) = ldblVlr945(lintFlgRe, 2) + ldblVlrkWh(lintFlgRe, 2)
										ldblBan945(lintFlgRe, 2) = ldblBan945(lintFlgRe, 2) + ldblBankWh(lintFlgRe, 2)
										If lintFaixa = 2 Then
											ldblVlrIcm(lintFlgRe, 2) = ldblVlrIcm(lintFlgRe, 2) + (BuscaVlrItem(lstrItens, "0302030009") + BuscaVlrItem(lstrItens, "0302030010"))
											ldblVlrPis(lintFlgRe, 2) = ldblVlrPis(lintFlgRe, 2) + BuscaVlrItem(lstrItens, "0302020029")
											ldblVlrCof(lintFlgRe, 2) = ldblVlrCof(lintFlgRe, 2) + BuscaVlrItem(lstrItens, "0302020030")
										End If
									End If
									If lintFaixa = 3 Then
										ldblQtd945(lintFlgRe, 3) = ldblQtd945(lintFlgRe, 3) + ldblQtdkWh(lintFlgRe, 3)
										ldblVlr945(lintFlgRe, 3) = ldblVlr945(lintFlgRe, 3) + ldblVlrkWh(lintFlgRe, 3)
										ldblBan945(lintFlgRe, 3) = ldblBan945(lintFlgRe, 3) + ldblBankWh(lintFlgRe, 3)
										If lintFaixa = 3 Then
											ldblVlrIcm(lintFlgRe, 3) = ldblVlrIcm(lintFlgRe, 3) + (BuscaVlrItem(lstrItens, "0302030009") + BuscaVlrItem(lstrItens, "0302030010"))
											ldblVlrPis(lintFlgRe, 3) = ldblVlrPis(lintFlgRe, 3) + BuscaVlrItem(lstrItens, "0302020029")
											ldblVlrCof(lintFlgRe, 3) = ldblVlrCof(lintFlgRe, 3) + BuscaVlrItem(lstrItens, "0302020030")
										End If
									End If
									If ldblQKwhFat <= 30 Then
										lstrDsClas = lstrDsClas & " 0 até 30"
										lintOrdCla = 11
									ElseIf ldblQKwhFat > 30 And ldblQKwhFat < 80 Then 
										lstrDsClas = lstrDsClas & " 31 até 79"
										lintOrdCla = 12
									ElseIf ldblQKwhFat >= 80 And ldblQKwhFat <= 100 Then 
										lstrDsClas = lstrDsClas & " 80 até 100"
										lintOrdCla = 13
									ElseIf ldblQKwhFat >= 101 And ldblQKwhFat <= 140 Then 
										lstrDsClas = "Bx.Renda 101 até 140"
										lintOrdCla = 15
									ElseIf ldblQKwhFat >= 141 And ldblQKwhFat <= 150 Then 
										lstrDsClas = "Bx.Renda 141 até 150"
										lintOrdCla = 16
									ElseIf ldblQKwhFat >= 151 And ldblQKwhFat <= 160 Then 
										lstrDsClas = "Bx.Renda 151 até 160"
										lintOrdCla = 17
									ElseIf ldblQKwhFat > 160 Then 
										lstrDsClas = "Bx.Renda acima de 160"
										lintOrdCla = 23
									End If
								End If
							End If
							ldblQKwFat = BuscaVlrItem(lstrItens, "0302010017") * lintMpr 'Demanda
							'Valor
							ldblVKwFat = BuscaVlrItem(lstrItens, "0302020015") * lintMpr 'Demanda
							ldblQKwFatUfp = BuscaVlrItem(lstrItens, "0302010018") * lintMpr 'Demanda de ultrapassagem fp
							ldblVKwFatUfp = BuscaVlrItem(lstrItens, "0302020018") * lintMpr 'Demanda de ultrapassagem Convencional
							ldblConsumoReativo = BuscaVlrItem(lstrItens, "0302020012") * lintMpr 'Consumo Reativo
							ldblDemandaReativa = BuscaVlrItem(lstrItens, "0302020031") * lintMpr 'Demanda Reativo
						ElseIf lstrGrupo = "AA" Or lstrGrupo = "AV" Or lstrGrupo = "AL" Or lstrGrupo = "AP" Or lstrGrupo = "AX" Then 
							'Quantidade
							ldblQKwhFatp = 0
							ldblQKwhFatfp = 0
							ldblQKwhFatpLiv = 0
							ldblQKwhFatfpLiv = 0
							ldblQKwhDevp = BuscaVlrItem(lstrItens, "0302010041") * lintMpr 'Consumo devolvido na p
							ldblQKwhDevfp = BuscaVlrItem(lstrItens, "0302010042") * lintMpr 'Consumo devolvido na fp
							ldblQKwhUtrp = BuscaVlrItem(lstrItens, "0302010043") * lintMpr 'Consumo ultrapassado na p
							ldblQKwhUtrfp = BuscaVlrItem(lstrItens, "0302010044") * lintMpr 'Consumo ultrapassado na fp
							If ldblQKwhFatp = 0 Then
								ldblQKwhFatp = BuscaVlrItem(lstrItens, "0302010010") * lintMpr 'Consumo faturado p
								ldblQKwhFatpBan = BuscaVlrItem(lstrItens, "0302110010") * lintMpr 'Consumo faturado p bandeira
								If lstrGrupo = "AL" Then
									If lintParcialmenteCativo = 1 Then
										ldblQKwhFatpLiv = BuscaVlrItem(lstrItens, "0302010060") * lintMpr 'Consumo faturado p
										ldblQKwhFatp = ldblQKwhFatp - ldblQKwhFatpLiv
									Else
										ldblQKwhFatpLiv = BuscaVlrItem(lstrItens, "0302010010") * lintMpr 'Consumo faturado p
										ldblQKwhFatp = ldblQKwhFatp - ldblQKwhFatpLiv
										ldblQKwhFatpBan = 0
									End If
								End If
							End If
							If ldblQKwhFatfp = 0 Then
								ldblQKwhFatfp = BuscaVlrItem(lstrItens, "0302010011") * lintMpr 'Consumo faturado fp
								ldblQKwhFatfpBan = BuscaVlrItem(lstrItens, "0302110011") * lintMpr 'Consumo faturado fp
								If lstrGrupo = "AL" Then
									If lintParcialmenteCativo = 1 Then
										ldblQKwhFatfpLiv = BuscaVlrItem(lstrItens, "0302010061") * lintMpr 'Consumo faturado fp
										ldblQKwhFatfp = ldblQKwhFatfp - ldblQKwhFatfpLiv
									Else
										ldblQKwhFatfpLiv = BuscaVlrItem(lstrItens, "0302010011") * lintMpr 'Consumo faturado fp
										ldblQKwhFatfp = ldblQKwhFatfp - ldblQKwhFatfpLiv
										ldblQKwhFatfpBan = 0
									End If
								End If
							End If
							ldblQKwFatp = BuscaVlrItem(lstrItens, "0302010021") * lintMpr ' + BuscaVlrItem(lstrItens, "0302010022")  'Demanda p
							ldblQKwFatfp = BuscaVlrItem(lstrItens, "0302010025") * lintMpr ' + BuscaVlrItem(lstrItens, "0302010026") 'Demanda fp
							ldblQKwhCons = ldblQKwhFatp + ldblQKwhFatfp '+ ldblQKwFatp + ldblQKwFatfp
							ldblQKwFatUp = BuscaVlrItem(lstrItens, "0302010022") * lintMpr 'Demanda de ultrapassagem p
							ldblQKwFatUfp = BuscaVlrItem(lstrItens, "0302010026") * lintMpr 'Demanda de ultrapassagem fp
							'Valor
							ldblVKwhFatp = 0
							ldblVKwhFatfp = 0
							ldblVKwhFatpLiv = 0
							ldblVKwhFatfpLiv = 0
							ldblVKwhFatp = BuscaVlrItem(lstrItens, "0302020010") * lintMpr 'Consumo faturado p
							ldblVKwhFatpBan = BuscaVlrItem(lstrItens, "0302120010") * lintMpr 'Consumo faturado p
							If lstrGrupo = "AL" Then
								If lintParcialmenteCativo = 1 Then
									ldblVKwhFatpLiv = BuscaVlrItem(lstrItens, "0302020060") * lintMpr 'Consumo faturado p
									ldblReceita_p = ldblReceita_p + ldblVKwhFatp + ldblVKwhFatpBan
								Else
									ldblVKwhFatpLiv = BuscaVlrItem(lstrItens, "0302020010") * lintMpr 'Consumo faturado p
									ldblVKwhFatp = ldblVKwhFatp - ldblVKwhFatpLiv
									ldblVKwhFatpBan = 0
								End If
							Else
								ldblReceita_p = ldblReceita_p + ldblVKwhFatp + ldblVKwhFatpBan
							End If
							ldblVKwhFatfp = BuscaVlrItem(lstrItens, "0302020011") * lintMpr 'Consumo faturado fp
							ldblVKwhFatfpBan = BuscaVlrItem(lstrItens, "0302120011") * lintMpr 'Consumo faturado fp
							If lstrGrupo = "AL" Then
								If lintParcialmenteCativo = 1 Then
									ldblVKwhFatfpLiv = BuscaVlrItem(lstrItens, "0302020061") * lintMpr 'Consumo faturado fp
									ldblReceita_fp = ldblReceita_fp + ldblVKwhFatfp + ldblVKwhFatfpBan
								Else
									ldblVKwhFatfpLiv = BuscaVlrItem(lstrItens, "0302020011") * lintMpr 'Consumo faturado fp
									ldblVKwhFatfp = ldblVKwhFatfp - ldblVKwhFatfpLiv
									ldblVKwhFatfpBan = 0
								End If
							Else
								ldblReceita_fp = ldblReceita_fp + ldblVKwhFatfp + ldblVKwhFatfpBan
							End If
							ldblVKwhDevp = BuscaVlrItem(lstrItens, "0302020041") * lintMpr 'Valor Consumo devolvido na p
							ldblVKwhDevfp = BuscaVlrItem(lstrItens, "0302020042") * lintMpr 'Valor Consumo devolvido na fp
							ldblVKwhUtrp = BuscaVlrItem(lstrItens, "0302020043") * lintMpr 'Valor Consumo ultrapassado na p
							ldblVKwhUtrfp = BuscaVlrItem(lstrItens, "0302020044") * lintMpr 'Valor Consumo ultrapassado na fp
							If lstrGrupo = "AV" Then
								ldblVKwhDevfp = ldblVKwhDevfp + (BuscaVlrItem(lstrItens, "0302060023") * lintMpr)
							End If
							ldblReceita_p = ldblReceita_p + ldblVKwhDevp + ldblVKwhUtrp
							ldblReceita_fp = ldblReceita_fp + ldblVKwhDevfp + ldblVKwhUtrfp
							ldblVKwhCons = ldblVKwhFatp + ldblVKwhFatfp '+ ldblVKwFatp + ldblVKwFatfp
							ldblVKwFatp = BuscaVlrItem(lstrItens, "0302020021") * lintMpr ' + BuscaVlrItem(lstrItens, "0302020022")  'Demanda p
							ldblVKwFatfp = (BuscaVlrItem(lstrItens, "0302020023") + BuscaVlrItem(lstrItens, "0302020072")) * lintMpr '+ (BuscaVlrItem(lstrItens, "0302020072") * lintMpr) ' + BuscaVlrItem(lstrItens, "0302020026") 'Demanda fp
							If lstrGrupo = "AL" Then
								ldblVKwFatp = ldblVKwFatp + (BuscaVlrItem(lstrItens, "0302060021") * lintMpr) 'dif.Demanda p
								ldblVKwFatfp = ldblVKwFatfp + (BuscaVlrItem(lstrItens, "0302060025") * lintMpr) 'dif.Demanda fp
								ldblVkwDscProv = BuscaVlrItem(lstrItens, "0302020051") * lintMpr 'Desconto Provisorio
								ldblVkwDscReal = BuscaVlrItem(lstrItens, "0302020052") * lintMpr 'Desconto real
								ldblVkwDevCcee = BuscaVlrItem(lstrItens, "0302020053") * lintMpr 'diferença a devolver
								ldblVkwCobCcee = BuscaVlrItem(lstrItens, "0302020054") * lintMpr 'diferença a cobrar
								'
								ldblVkwhDscProv = BuscaVlrItem(lstrItens, "0302020055") * lintMpr 'Desconto Provisorio
								ldblVkwhDscReal = BuscaVlrItem(lstrItens, "0302020056") * lintMpr 'Desconto real
								ldblVkwhDevCcee = BuscaVlrItem(lstrItens, "0302020057") * lintMpr 'diferença a devolver
								ldblVkwhCobCcee = BuscaVlrItem(lstrItens, "0302020058") * lintMpr 'diferença a cobrar
							End If
							ldblVKwFatUp = BuscaVlrItem(lstrItens, "0302020022") * lintMpr 'Demanda de ultrapassagem p
							ldblVKwFatUfp = BuscaVlrItem(lstrItens, "0302020026") * lintMpr 'Demanda de ultrapassagem fp
							ldblConsumoReativop = BuscaVlrItem(lstrItens, "0302020013") * lintMpr 'Consumo Reativo p
							ldblConsumoReativofp = (BuscaVlrItem(lstrItens, "0302020014") + BuscaVlrItem(lstrItens, "0302990044")) * lintMpr 'Consumo Reativo fp + Consumo reservado
							ldblDemandaReativap = BuscaVlrItem(lstrItens, "0302020027") * lintMpr 'Demanda Reativo p
							ldblDemandaReativafp = BuscaVlrItem(lstrItens, "0302020028") * lintMpr 'Demanda Reativo fp
							If lstrGrupo = "AA" Then
								lstrDsClas = lstrDsClas & " Azul"
							ElseIf lstrGrupo = "AV" Then 
								lstrDsClas = lstrDsClas & " Verde"
							ElseIf lstrGrupo = "AL" Then 
								If lintParcialmenteCativo = 1 Then
									lstrDsClas = "Livre Parc.Cat."
								ElseIf lintLivreVerde = 1 Then 
									lstrDsClas = "Livre Verde"
								ElseIf lintLivreEspecial = 1 Then 
									lstrDsClas = "Livre Especial"
								Else
									lstrDsClas = "Livre"
								End If
							ElseIf lstrGrupo = "AX" Then 
								lstrDsClas = "Suprimento Horo"
								lintOrdCla = 99
							End If
						End If
						ldblIcms = BuscaVlrItem(lstrItens, "0302030009") * lintMpr 'Vlr Icms.
						ldblIcms = ldblIcms + (BuscaVlrItem(lstrItens, "0302030010") * lintMpr) 'Vlr Icms.
						ldblPis = BuscaVlrItem(lstrItens, "0302020029") * lintMpr 'Vlr PIS.
						ldblCofins = BuscaVlrItem(lstrItens, "0302020030") * lintMpr 'Vlr COFINS.
						'
						ldblIcmsSt = BuscaVlrItem(lstrItens, "0602020001") * lintMpr
						ldblPisSt = BuscaVlrItem(lstrItens, "0602020002") * lintMpr
						ldblCofinsSt = BuscaVlrItem(lstrItens, "0602020003") * lintMpr
						'
						ldblIcmsPisCof = BuscaVlrItem(lstrItens, "0302030012") * lintMpr 'Vlr Icms/Pis/Cofins.
						'Usinas
						ldblQtdMust = BuscaVlrItem(lstrItens, "0302010032") * lintMpr 'EUSD - Must qtde
						ldblVlrMust = BuscaVlrItem(lstrItens, "0302020032") * lintMpr 'EUSD - Must valor
						ldblEncMust = BuscaVlrItem(lstrItens, "9080000098") * lintMpr 'EUSD - Must encargo
						ldblDesMust = BuscaVlrItem(lstrItens, "9070000087") + BuscaVlrItem(lstrItens, "9070000091") * lintMpr 'EUSD - Must descontos
						If ldblVlrMust > 0 Then
							lstrCmClas = BuscaComplemento(llngUnidId)
						Else
							lstrCmClas = ""
						End If
						lstrSqlPAx = lstrSqlPAx & "("
						lstrSqlPAx = lstrSqlPAx & " " & lintFlgRe & ", " 'refaturado
						lstrSqlPAx = lstrSqlPAx & "'" & IIf(VB.Left(lstrGrupo, 1) = "A", lstrGrupo, VB.Left(lstrGrupo, 1)) & IIf(lstrGrupo = "AL", IIf(lintLivreVerde = 1, "V", IIf(lintParcialmenteCativo = 1, "P", IIf(lintLivreEspecial = 1, "S", ""))), "") & "'," 'grupo
						lstrSqlPAx = lstrSqlPAx & "'" & lstrClasse & "', " 'classe
						lstrSqlPAx = lstrSqlPAx & "'" & lstrDsClas & "', " 'ds_classe
						lstrSqlPAx = lstrSqlPAx & "'" & lstrCmClas & "', " 'com_classe
						lstrSqlPAx = lstrSqlPAx & " " & lintOrdCla & ", " 'ord_classe
						lstrSqlPAx = lstrSqlPAx & " " & lintParcialmenteCativo & ", " 'parc_cativo
						lstrSqlPAx = lstrSqlPAx & " " & IIf(ldblVlrMust > 0, 1, 0) & ", " 'usinas
						lstrSqlPAx = lstrSqlPAx & " " & lintMicroGeracao & ", " 'micro_geracao
						lstrSqlPAx = lstrSqlPAx & " " & lintIrrigacaoAquicultura & ", " 'Irrigante
						lstrSqlPAx = lstrSqlPAx & " " & lintTarifaBranca & ", " 'Tarifa Branca
						'Convencional
						'Qtde
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQKwhCons), ",", ".") & "', " 'qkwh_cons
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQKwhFat), ",", ".") & "', " 'qkwh_fat
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQKwhFatBan), ",", ".") & "', " 'qkwh_fat_ban
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQKwFat), ",", ".") & "', " 'qkw_fat
						'Valor
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVKwhCons), ",", ".") & "', " 'vkwh_cons
						If (ldblVkWhFatTU + ldblVkWhFatTE) > 0 Then
							lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVkWhFatTU + ldblVkWhFatTE), ",", ".") & "', " 'vkwh_fat
							lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVkWhFatTEBan), ",", ".") & "', " 'vkwh_fat_ban
						Else
							lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVKwhFat), ",", ".") & "', " 'vkwh_fat
							lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVKwhFatBan), ",", ".") & "', " 'vkwh_fat_ban
						End If
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVKwFat), ",", ".") & "', " 'vkw_fat
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblConsumoReativo), ",", ".") & "', " 'vconreat
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblDemandaReativa), ",", ".") & "', " 'vdemreat
						'Horosazonal
						'Qtde
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQKwhFatp), ",", ".") & "', " 'qkwh_fat_p
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQKwhFatfp), ",", ".") & "', " 'qkwh_fat_fp
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQKwhFatpBan), ",", ".") & "', " 'qkwh_fat_p_ban
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQKwhFatfpBan), ",", ".") & "', " 'qkwh_fat_fp_ban
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQKwhFatpLiv), ",", ".") & "', " 'qkwh_fat_p_liv
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQKwhFatfpLiv), ",", ".") & "', " 'qkwh_fat_fp_liv
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQKwhDevp), ",", ".") & "', " 'qkwh_dev_p
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQKwhDevfp), ",", ".") & "', " 'qkwh_dev_fp
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQKwhUtrp), ",", ".") & "', " 'qkwh_utr_p
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQKwhUtrfp), ",", ".") & "', " 'qkwh_utr_fp
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQKwFatp), ",", ".") & "', " 'qkw_fat_p
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQKwFatfp), ",", ".") & "', " 'qkw_fat_fp
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQKwFatUp), ",", ".") & "', " 'qkw_fatu_p
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQKwFatUfp), ",", ".") & "', " 'qkw_fatu_fp
						'Valor
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVKwhFatp), ",", ".") & "', " 'vkwh_fat_p
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVKwhFatfp), ",", ".") & "', " 'vkwh_fat_fp
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVKwhFatpBan), ",", ".") & "', " 'vkwh_fat_p_ban
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVKwhFatfpBan), ",", ".") & "', " 'vkwh_fat_fp_ban
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVKwhFatpLiv), ",", ".") & "', " 'vkwh_fat_p_liv
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVKwhFatfpLiv), ",", ".") & "', " 'vkwh_fat_fp_liv
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVKwhDevp), ",", ".") & "', " 'vkwh_dev_p
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVKwhDevfp), ",", ".") & "', " 'vkwh_dev_fp
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVKwhUtrp), ",", ".") & "', " 'vkwh_utr_p
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVKwhUtrfp), ",", ".") & "', " 'vkwh_utr_fp
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVKwFatp), ",", ".") & "', " 'vkw_fat_p
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVKwFatfp), ",", ".") & "', " 'vkw_fat_fp
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVKwFatUp), ",", ".") & "', " 'vkw_fatu_p
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVKwFatUfp), ",", ".") & "', " 'vkw_fatu_fp
						'
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVkwDscProv), ",", ".") & "', " 'vkw_dsc_prov
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVkwDscReal), ",", ".") & "', " 'vkw_dsc_real
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVkwDevCcee), ",", ".") & "', " 'vkw_dev_ccee
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVkwCobCcee), ",", ".") & "', " 'vkw_cob_ccee
						'
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVkwhDscProv), ",", ".") & "', " 'vkw_dsc_prov
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVkwhDscReal), ",", ".") & "', " 'vkw_dsc_real
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVkwhDevCcee), ",", ".") & "', " 'vkw_dev_ccee
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVkwhCobCcee), ",", ".") & "', " 'vkw_cob_ccee
						'Reativo
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblConsumoReativop), ",", ".") & "', " 'vconreat_p = Consumo Reativo ponta
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblConsumoReativofp), ",", ".") & "', " 'vconreat_fp = Consumo Reativo fora ponta
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblDemandaReativap), ",", ".") & "', " 'vdemreat_p = Demanda Reativo ponta
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblDemandaReativafp), ",", ".") & "', " 'vdemreat_fp = Demanda Reativo fora ponta
						'Receita
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblReceita_p), ",", ".") & "', " 'receita
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblReceita_I), ",", ".") & "', " 'receita
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblReceita_fp), ",", ".") & "', " 'receita
						'Reverso
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQKwhReverso), ",", ".") & "', " 'reverso
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVKwhReverso), ",", ".") & "', " 'valor
						'Irrigacao
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQIrr_Normal_kWh_fat), ",", ".") & "', " 'qirr_nor_kwh_fat
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQIrr_Normal_kWh_fat), ",", ".") & "', " 'qirr_nor_kwh_fat_ban
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQIrr_Reserv_kWh_fat), ",", ".") & "', " 'qirr_res_kwh_fat
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQIrr_Reserv_kWh_fat), ",", ".") & "', " 'qirr_res_kwh_fat_ban
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVIrr_Normal_kWh_fat), ",", ".") & "', " 'virr_nor_kwh_fat
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVIrr_Normal_kWh_fat_ban), ",", ".") & "', " 'virr_nor_kwh_fat_ban
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVIrr_Reserv_kWh_fat), ",", ".") & "', " 'virr_res_kwh_fat
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVIrr_Reserv_kWh_fat_ban), ",", ".") & "', " 'virr_res_kwh_fat_ban
						'Tarifa Branca
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQTarBranca_kWh_Ponta), ",", ".") & "', "
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQTarBranca_kWh_Ponta_Ban), ",", ".") & "', "
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQTarBranca_kWh_Inter), ",", ".") & "', "
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQTarBranca_kWh_Inter_Ban), ",", ".") & "', "
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQTarBranca_kWh_ForaP), ",", ".") & "', "
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQTarBranca_kWh_ForaP_Ban), ",", ".") & "', "
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVTarBranca_kWh_Ponta), ",", ".") & "', "
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVTarBranca_kWh_Ponta_Ban), ",", ".") & "', "
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVTarBranca_kWh_Inter), ",", ".") & "', "
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVTarBranca_kWh_Inter_Ban), ",", ".") & "', "
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVTarBranca_kWh_ForaP), ",", ".") & "', "
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVTarBranca_kWh_ForaP_Ban), ",", ".") & "', "
						'Tributos
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblIcms), ",", ".") & "', " 'icms
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblPis), ",", ".") & "', " 'pis
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblCofins), ",", ".") & "', " 'cofins
						'Tributacao Comercializador usado para o Livre
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblIcmsSt), ",", ".") & "', " 'icms - st
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblPisSt), ",", ".") & "', " 'pis - st
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblCofinsSt), ",", ".") & "', " 'cofins - st
						'Base de calculo
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblBaseIcms), ",", ".") & "', " 'base icms
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblBasePis), ",", ".") & "', " 'base pis
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblBaseCofins), ",", ".") & "', " 'base cofins
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblIcmsPisCof), ",", ".") & "', " 'icms/pis/cofins
						'Usinas
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblQtdMust), ",", ".") & "', " 'must_qtd
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblVlrMust), ",", ".") & "', " 'must_vlr
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblDesMust), ",", ".") & "', " 'must_des
						lstrSqlPAx = lstrSqlPAx & "'" & Replace(CStr(ldblEncMust), ",", ".") & "' " 'must_enc
						lstrSqlPAx = lstrSqlPAx & "), "
						lintContInsertPri = lintContInsertPri + 1
						If lintContInsertPri > 300 Then
							Call Executar(lstrSqlPri & VB.Left(lstrSqlPAx, Len(lstrSqlPAx) - 2), False)
							lstrSqlPAx = ""
							lintContInsertPri = 1
						End If
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " Faturas ")
						System.Windows.Forms.Application.DoEvents()
					End While
					If lintContInsertPri > 0 And Len(Trim(lstrSqlPAx)) > 0 Then
						Call Executar(lstrSqlPri & VB.Left(lstrSqlPAx, Len(lstrSqlPAx) - 2), False)
					End If
					lblnRetorno = True
				Else
					Call LigDes(True)
					Me.Cursor = System.Windows.Forms.Cursors.Default
					Call MsgBox("Não existem faturas no período selecionado!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
					lblnRetorno = False
				End If
				Call .Close()
			End If
		End With
		If lblnRetorno Then
			For lintRef = 0 To 1
				For lintAux = 0 To 3
					'Grava 945
					If lintQtdFxa(lintRef, lintAux) > 0 Then
						lstrSql = ""
						lstrSql = lstrSql & "INSERT INTO " & gstrDataBase & "." & istrTab945 & " SET " & vbCrLf
						lstrSql = lstrSql & "refaturado = " & lintRef & ", " & vbCrLf
						lstrSql = lstrSql & "ds_classe  = '" & lstrDes945(lintRef, lintAux) & "', " & vbCrLf
						lstrSql = lstrSql & "ord_classe =  " & lintAux + 20 & ", " & vbCrLf
						lstrSql = lstrSql & "faixa = " & lintQtdFxa(lintRef, lintAux) & ", " & vbCrLf
						lstrSql = lstrSql & "consumo= " & Replace(CStr(ldblQtd945(lintRef, lintAux)), ",", ".") & ", " & vbCrLf
						lstrSql = lstrSql & "valor= " & Replace(CStr(ldblVlr945(lintRef, lintAux)), ",", ".") & ", " & vbCrLf
						lstrSql = lstrSql & "bandeira= " & Replace(CStr(ldblBan945(lintRef, lintAux)), ",", ".") & ", " & vbCrLf
						lstrSql = lstrSql & "receita  = " & Replace(CStr(ldblVlr945(lintRef, lintAux) + ldblBan945(lintRef, lintAux)), ",", ".") & ", " & vbCrLf
						lstrSql = lstrSql & "icms     = " & Replace(CStr(ldblVlrIcm(lintRef, lintAux)), ",", ".") & ", " & vbCrLf
						lstrSql = lstrSql & "pis      = " & Replace(CStr(ldblVlrPis(lintRef, lintAux)), ",", ".") & ", " & vbCrLf
						lstrSql = lstrSql & "cofins   = " & Replace(CStr(ldblVlrCof(lintRef, lintAux)), ",", ".") & " " & vbCrLf
						Call Executar(lstrSql, False)
					End If
				Next lintAux
			Next lintRef
			Me.lblInfo.Text = Me.lblInfo.Text & " *** Finalizado *** "
			Call Me.lblInfo.Refresh()
		End If
		Call Executar("COMMIT", False)
ErrMontaTabela: 
		Me.Cursor = System.Windows.Forms.Cursors.Default
		Call LigDes(True)
		If myConC.Errors.Count > 0 Then
			Call MsgBox("Código: " & myConC.Errors.Item(myConC.Errors.Count - 1).NativeError & vbCrLf & "Descrição:" & myConC.Errors.Item(myConC.Errors.Count - 1).Description, MsgBoxStyle.Critical, gstrTituloMensagem)
			Call Executar("ROLLBACK", False)
		ElseIf Err.Number > 0 Then 
			Call MsgBox(Err.Number & " - " & GetErrosVB(Err.Number, Err.Description), MsgBoxStyle.Information, gstrTituloMensagem)
			Call Executar("ROLLBACK", False)
		End If
		'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
		MontaTabela = lblnRetorno
	End Function
	
	Private Function BuscaComplemento(ByVal astrUnidid As Short) As String
		Dim lstrRet As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrRet = ""
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * " & vbCrLf
		lstrSql = lstrSql & "  FROM `unidb` " & vbCrLf
		lstrSql = lstrSql & " WHERE `unid_id` = " & astrUnidid & " " & vbCrLf
		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"'
					lstrRet = IIf(IsDbNull(.Fields("complement").value), "", .Fields("complement").value)
				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
		BuscaComplemento = lstrRet
	End Function
	
	Private Sub LigDes(ByVal ablnModo As Boolean)
		Me.dtpMesAno.Enabled = ablnModo
		Me.cmdImprimir.Enabled = ablnModo
		Me.cmdExporta.Enabled = IIf(Not iblnExporta, False, ablnModo)
		Me.cmdPasta.Enabled = ablnModo
		Me.txtDir.Enabled = ablnModo
		Me.cmdFechar.Enabled = ablnModo
		Me.chkGrupoAConvencional.Enabled = ablnModo
		Me.chkGrupoAHorosazonal.Enabled = ablnModo
		Me.chkGrupoALivre.Enabled = ablnModo
		Me.chkGrupoB.Enabled = ablnModo
		Me.chkGrupoBx.Enabled = ablnModo
		Me.chkMicroGeracao.Enabled = ablnModo
		Me.chkUsina.Enabled = ablnModo
		Me.chkIrrigante.Enabled = ablnModo
		Me.chkReceitakWhBan.Enabled = ablnModo
		Me.chkExportaDescritivo.Enabled = ablnModo
		Me.chkCasaDecimal.Enabled = ablnModo
		Me.chkTarifaBranca.Enabled = ablnModo
		Me.cmbCaracter.Enabled = ablnModo
	End Sub
	
	Private Function GetSampClasses(ByVal classe As Short) As Short
		Dim lintRet As Short
		If classe >= 10 And classe < 30 Then
			lintRet = 1 'Residencial
		ElseIf classe = 30 Then 
			lintRet = 2 'Industrial
		ElseIf classe = 40 Then 
			lintRet = 3 'Comercial, Serviços e Outras
		ElseIf classe = 55 Then 
			lintRet = 9 'Rural Irrigante
		ElseIf classe = 57 Then 
			lintRet = 10 'Rural Aquicultor
		ElseIf classe = 50 Then 
			lintRet = 4 'Rural
		ElseIf classe = 61 Or classe = 62 Then 
			lintRet = 6 'Iluminação Pública
		ElseIf classe = 60 Then 
			lintRet = 5 'Poder Público
		ElseIf classe = 71 Then 
			lintRet = 13 'Serviço Público (tração elétrica)
		ElseIf classe = 70 Or classe = 73 Then 
			lintRet = 7 'Serviço Público (água, esgoto e saneamento)
		ElseIf classe = 80 Then 
			lintRet = 8 'Consumo Próprio
		Else
			lintRet = 0
		End If
		GetSampClasses = lintRet
	End Function
	
	Private Function GetExpSampClasses(ByVal classe As Short) As String
		Dim lstrRet As String
		If classe = 1 Then
			lstrRet = "Residencial"
		ElseIf classe = 2 Then 
			lstrRet = "Industrial"
		ElseIf classe = 3 Then 
			lstrRet = "Comercial, Serviços e Outras"
		ElseIf classe = 4 Then 
			lstrRet = "Rural"
		ElseIf classe = 5 Then 
			lstrRet = "Poder Público"
		ElseIf classe = 6 Then 
			lstrRet = "Iluminação Pública"
		ElseIf classe = 7 Then 
			lstrRet = "Serviço Público (água, esgoto e saneamento)"
		ElseIf classe = 8 Then 
			lstrRet = "Consumo Próprio"
		ElseIf classe = 9 Then 
			lstrRet = "Rural Irrigante"
		ElseIf classe = 10 Then 
			lstrRet = "Rural Aquicultor"
		ElseIf classe = 13 Then 
			lstrRet = "Serviço Público (tração elétrica)"
		Else
			lstrRet = "Outras"
		End If
		GetExpSampClasses = lstrRet
	End Function
	
	
	Private Function GetModalidade(ByVal astrModalidade As String) As Short
		Dim lintRet As Short
		If astrModalidade = "AA" Then
			lintRet = 4 'Horo-Sazonal Azul
		ElseIf astrModalidade = "AV" Then 
			lintRet = 5 'Horo-Sazonal Verde
		Else
			lintRet = 1 'Convencional
		End If
		'  If astrModalidade = "" Then lintRet = 15 'Horo-Sazonal Azul - ABRACE
		'  If astrModalidade = "" Then lintRet = 13 'Branca
		'  If astrModalidade = "" Then lintRet = 16 'Horo-Sazonal Verde - ABRACE
		'  If astrModalidade = "" Then lintRet = 17 'Horo-Sazonal Azul - INPA
		'  If astrModalidade = "" Then lintRet = 14 'Convencional - ABRACE
		'  If astrModalidade = "" Then lintRet = 12 'Energia Fotovoltaica (Res. 083/2004)
		'  If astrModalidade = "" Then lintRet = 2 'Tensão Secundária de Distribuição em 127 V
		'  If astrModalidade = "" Then lintRet = 8 'Com Controlador de Demanda
		'  If astrModalidade = "" Then lintRet = 9 'Tarifa Amarela
		'  If astrModalidade = "" Then lintRet = 10 'Tarifa da Madrugada
		'  If astrModalidade = "" Then lintRet = 3 'Tensão Secundária de Distribuição em 220 V
		'  If astrModalidade = "" Then lintRet = 6 'Tarifa de Emergência Horo-Sazonal Azul
		'  If astrModalidade = "" Then lintRet = 7 'Tarifa de Emergência Horo-Sazonal Verde
		'  If astrModalidade = "" Then lintRet = 11 'Não se aplica
		GetModalidade = lintRet
	End Function
	
	Private Function GetExpModalidade(ByVal aintModalidade As Short) As String
		Dim lstrRet As String
		If aintModalidade = 4 Then
			lstrRet = "Horo-Sazonal Azul"
		ElseIf aintModalidade = 5 Then 
			lstrRet = "Horo-Sazonal Verde"
		Else
			lstrRet = "Convencional"
		End If
		'  If astrModalidade = "" Then lintRet = 15 'Horo-Sazonal Azul - ABRACE
		'  If astrModalidade = "" Then lintRet = 13 'Branca
		'  If astrModalidade = "" Then lintRet = 16 'Horo-Sazonal Verde - ABRACE
		'  If astrModalidade = "" Then lintRet = 17 'Horo-Sazonal Azul - INPA
		'  If astrModalidade = "" Then lintRet = 14 'Convencional - ABRACE
		'  If astrModalidade = "" Then lintRet = 12 'Energia Fotovoltaica (Res. 083/2004)
		'  If astrModalidade = "" Then lintRet = 2 'Tensão Secundária de Distribuição em 127 V
		'  If astrModalidade = "" Then lintRet = 8 'Com Controlador de Demanda
		'  If astrModalidade = "" Then lintRet = 9 'Tarifa Amarela
		'  If astrModalidade = "" Then lintRet = 10 'Tarifa da Madrugada
		'  If astrModalidade = "" Then lintRet = 3 'Tensão Secundária de Distribuição em 220 V
		'  If astrModalidade = "" Then lintRet = 6 'Tarifa de Emergência Horo-Sazonal Azul
		'  If astrModalidade = "" Then lintRet = 7 'Tarifa de Emergência Horo-Sazonal Verde
		'  If astrModalidade = "" Then lintRet = 11 'Não se aplica
		GetExpModalidade = lstrRet
	End Function
	
	Private Function GetSubGrupo(ByVal SubGrupo As String, ByVal classe As Short, ByVal abln945 As Boolean) As Short
		Dim lintRet As Short
		If VB.Left(SubGrupo, 1) = "A" Then
			If classe = 73 Then
				lintRet = 56 'A4 - Serviço Público de Irrigação (2,3 kV a 25 kV)
			ElseIf classe = 52 Then 
				lintRet = 52 'A4 - Cooperativa de Eletrificação Rural (2,3 kV a 25 kV)
			Else
				lintRet = 25 'A4 (2,3 a 25 kV)
			End If
		ElseIf VB.Left(SubGrupo, 1) = "B" Then 
			If classe = 10 Then
				lintRet = 1 'B1 - Residencial
			ElseIf (classe > 10 And classe < 30) And Not abln945 Then 
				If classe = 11 Then
					lintRet = 2 'B1 - Residencial Baixa Renda (Consumo mensal até 30 kWh)
				ElseIf classe = 12 Then 
					lintRet = 3 'B1 - Residencial Baixa Renda (Consumo mensal superior a 30 kWh e inferior a 80kWh)
				ElseIf classe = 13 Then 
					lintRet = 41 'B1 - Residencial Baixa Renda (Consumo mensal de 80 a 100 kWh)
				ElseIf classe = 14 Then 
					lintRet = 60 'B1 - Residencial Baixa Renda (Consumo mensal superior a 100 até 200 kWh)
				ElseIf classe = 15 Then 
					lintRet = 4 'B1 - Residencial Baixa Renda (Consumo mensal de 101 a 140 kWh)
				ElseIf classe = 16 Then 
					lintRet = 5 'B1 - Residencial Baixa Renda (Consumo mensal de 141 a 150 kWh)
				ElseIf classe = 17 Then 
					lintRet = 6 'B1 - Residencial Baixa Renda (Consumo mensal de 151 a 160 kWh)
				ElseIf classe = 18 Then 
					lintRet = 7 'B1 - Residencial Baixa Renda (Consumo mensal de 161 a 180 kWh)
				ElseIf classe = 19 Then 
					lintRet = 8 'B1 - Residencial Baixa Renda (Consumo mensal de 181 a 200 kWh)
				ElseIf classe = 20 Then 
					lintRet = 9 'B1 - Residencial Baixa Renda (Consumo mensal de 201 a 220 kWh)
				ElseIf classe = 21 Then 
					lintRet = 45 'B1 - Residencial Baixa Renda(Consumo Mensal Superior ao Limite Regional de 140kWh)
				ElseIf classe = 22 Then 
					lintRet = 46 'B1 - Residencial Baixa Renda(Consumo Mensal Superior ao Limite Regional de 150kWh)
				ElseIf classe = 23 Then 
					lintRet = 47 'B1 - Residencial Baixa Renda(Consumo Mensal Superior ao Limite Regional de 160kWh)
				ElseIf classe = 24 Then 
					lintRet = 48 'B1 - Residencial Baixa Renda(Consumo Mensal Superior ao Limite Regional de 180kWh)
				ElseIf classe = 25 Then 
					lintRet = 49 'B1 - Residencial Baixa Renda(Consumo Mensal Superior ao Limite Regional de 200kWh)
				ElseIf classe = 26 Then 
					lintRet = 50 'B1 - Residencial Baixa Renda(Consumo Mensal Superior ao Limite Regional de 220kWh)
				End If
			ElseIf (classe >= 20 And classe < 30) And abln945 Then 
				lintRet = 57 'B1 - Residencial Baixa Renda
				'      If classe = 20 Then
				'        lintRet = 62 'B1- Baixa Renda - Consumo mensal inferior ou igual a 30 kWh (RES. 945/2010)
				'      ElseIf classe = 21 Then
				'        lintRet = 63 'B1- Baixa Renda - Consumo mensal superior a 30 kWh e inferior ou igual a 100 kWh (RES. 945/2010)
				'      ElseIf classe = 22 Then
				'        lintRet = 64 'B1- Baixa Renda - Consumo mensal superior a 100 kWh e inferior ou igual a 220 kWh (RES. 945/2010)
				'      ElseIf classe = 23 Then
				'        lintRet = 65 'B1- Baixa Renda - Consumo mensal superior a 220 kWh (RES. 945/2010)
				'      End If
				
				If classe = 21 Then
					lintRet = 62 'B1- Baixa Renda - Consumo mensal inferior ou igual a 30 kWh (RES. 945/2010)
				ElseIf classe = 22 Then 
					lintRet = 63 'B1- Baixa Renda - Consumo mensal superior a 30 kWh e inferior ou igual a 100 kWh (RES. 945/2010)
				ElseIf classe = 23 Then 
					lintRet = 64 'B1- Baixa Renda - Consumo mensal superior a 100 kWh e inferior ou igual a 220 kWh (RES. 945/2010)
				ElseIf classe = 24 Then 
					lintRet = 65 'B1- Baixa Renda - Consumo mensal superior a 220 kWh (RES. 945/2010)
				End If
				
				
			ElseIf classe = 52 Then 
				lintRet = 31 'B2 - Cooperativa de Eletrificação Rural
			ElseIf classe = 54 Then 
				lintRet = 32 'B2 - Serviço Público de Irrigação
			ElseIf CDbl(VB.Left(CStr(classe), 1)) = 5 Then 
				lintRet = 30 'B2 - Rural
			ElseIf classe = 41 Then 
				lintRet = 33 'B3 - Classe Comercial (Consumo mensal até 820 Ah)
			ElseIf classe = 42 Then 
				lintRet = 34 'B3 - Classe Comercial (Consumo mensal até 1.436 Ah)
			ElseIf classe = 61 Then 
				lintRet = 36 'B4a - Iluminação Pública - Rede de Distribuição
			ElseIf classe = 62 Then 
				lintRet = 37 'B4b - Iluminação Pública - Bulbo de Lâmpada
			Else
				lintRet = 35 'B3 - Demais Classes
			End If
		End If
		
		'  If SubGrupo = "" Then lintRet = 10 'B1 - Residencial Baixa Renda (Consumo mensal até 136 Ah)
		'  If SubGrupo = "" Then lintRet = 11 'B1 - Residencial Baixa Renda (Consumo mensal de 137 a 236 Ah)
		'  If SubGrupo = "" Then lintRet = 17 'B1 - Residencial Baixa Renda (Consumo mensal de 137 a 341 Ah)
		'  If SubGrupo = "" Then lintRet = 12 'B1 - Residencial Baixa Renda (Consumo mensal de 237 a 341 Ah)
		'  If SubGrupo = "" Then lintRet = 13 'B1 - Residencial Baixa Renda (Consumo mensal de 342 a 590 Ah)
		'  If SubGrupo = "" Then lintRet = 14 'B1 - Residencial Baixa Renda (Consumo mensal de 591 a 1.135 Ah)
		'  If SubGrupo = "" Then lintRet = 51 'B1 - Residencial Baixa Renda (Consumo mensal de 342 a 655 Ah)
		'  If SubGrupo = "" Then lintRet = 18 'B1 - Residencial Baixa Renda (Consumo mensal de 656 a 830 Ah)
		'  If SubGrupo = "" Then lintRet = 15 'B1 - Residencial Baixa Renda (Consumo mensal de 1.136 a 1.436 Ah)
		'  If SubGrupo = "" Then lintRet = 19 'B1 - Residencial Baixa Renda (Consumo mensal de 831 a 1.245 Ah)
		'  If SubGrupo = "" Then lintRet = 16 'B1 - Residencial Baixa Renda (Consumo mensal de 1.437 a 2.154 Ah)
		
		
		'  If SubGrupo = "B4" Then lintRet = 38 'B4c - Iluminação Pública - Nível de IP acima do Padrão
		'  If SubGrupo = "" Then lintRet = 26 'A4a - Cooperativa de Eletrificação Rural Tipo 1
		'  If SubGrupo = "" Then lintRet = 27 'A4b - Cooperativa de Eletrificação Rural Tipo 2
		'  If SubGrupo = "" Then lintRet = 28 'A4c - Cooperativa de Eletrificação Rural Tipo 3
		'  If SubGrupo = "" Then lintRet = 20 'A1 (230 kV ou mais)
		'  If SubGrupo = "" Then lintRet = 21 'A2 (88 a 138 kV)
		'  If SubGrupo = "" Then lintRet = 58 'A2 - Cooperativa de Eletrificação Rural (88 a 138 kV)
		'  If SubGrupo = "" Then lintRet = 22 'A3 ( 69 kV)
		'  If SubGrupo = "" Then lintRet = 23 'A3 - Cooperativa de Eletrificação Rural (69 kV)
		'  If SubGrupo = "" Then lintRet = 24 'A3a (30 kV a 44 kV)
		'  If SubGrupo = "" Then lintRet = 53 'A3 - Serviço Público de Irrigação (69 kV)
		'  If SubGrupo = "" Then lintRet = 54 'A3a - Cooperativa de Eletrificação Rural (30 kV a 44 kV)
		'  If SubGrupo = "" Then lintRet = 55 'A3a - Serviço Público de Irrigação (30 kV a 44 kV)
		'  If SubGrupo = "" Then lintRet = 29 'AS (Subterrâneo)
		GetSubGrupo = lintRet
	End Function
	
	Private Function GetExpSubGrupo(ByVal aintSubGrupo As Short) As String
		Dim lstrRet As String
		If aintSubGrupo = 1 Then
			lstrRet = "B1 - Residencial"
		ElseIf aintSubGrupo = 2 Then 
			lstrRet = "B1 - Residencial Baixa Renda (Consumo mensal até 30 kWh)"
		ElseIf aintSubGrupo = 3 Then 
			lstrRet = "B1 - Residencial Baixa Renda (Consumo mensal superior a 30 kWh e inferior a 80kWh)"
		ElseIf aintSubGrupo = 4 Then 
			lstrRet = "B1 - Residencial Baixa Renda (Consumo mensal de 101 a 140 kWh)"
		ElseIf aintSubGrupo = 5 Then 
			lstrRet = "B1 - Residencial Baixa Renda (Consumo mensal de 141 a 150 kWh)"
		ElseIf aintSubGrupo = 6 Then 
			lstrRet = "B1 - Residencial Baixa Renda (Consumo mensal de 151 a 160 kWh)"
		ElseIf aintSubGrupo = 7 Then 
			lstrRet = "B1 - Residencial Baixa Renda (Consumo mensal de 161 a 180 kWh)"
		ElseIf aintSubGrupo = 8 Then 
			lstrRet = "B1 - Residencial Baixa Renda (Consumo mensal de 181 a 200 kWh)"
		ElseIf aintSubGrupo = 9 Then 
			lstrRet = "B1 - Residencial Baixa Renda (Consumo mensal de 201 a 220 kWh)"
		ElseIf aintSubGrupo = 25 Then 
			lstrRet = "A4 (2,3 a 25 kV)"
		ElseIf aintSubGrupo = 30 Then 
			lstrRet = "B2 - Rural"
		ElseIf aintSubGrupo = 31 Then 
			lstrRet = "B2 - Cooperativa de Eletrificação Rural"
		ElseIf aintSubGrupo = 32 Then 
			lstrRet = "B2 - Serviço Público de Irrigação"
		ElseIf aintSubGrupo = 33 Then 
			lstrRet = "B3 - Classe Comercial (Consumo mensal até 820 Ah)"
		ElseIf aintSubGrupo = 34 Then 
			lstrRet = "B3 - Classe Comercial (Consumo mensal até 1.436 Ah)"
		ElseIf aintSubGrupo = 35 Then 
			lstrRet = "B3 - Demais Classes"
		ElseIf aintSubGrupo = 36 Then 
			lstrRet = "B4a - Iluminação Pública - Rede de Distribuição"
		ElseIf aintSubGrupo = 37 Then 
			lstrRet = "B4b - Iluminação Pública - Bulbo de Lâmpada"
		ElseIf aintSubGrupo = 41 Then 
			lstrRet = "B1 - Residencial Baixa Renda (Consumo mensal de 80 a 100 kWh)"
		ElseIf aintSubGrupo = 45 Then 
			lstrRet = "B1 - Residencial Baixa Renda(Consumo Mensal Superior ao Limite Regional de 140kWh)"
		ElseIf aintSubGrupo = 46 Then 
			lstrRet = "B1 - Residencial Baixa Renda(Consumo Mensal Superior ao Limite Regional de 150kWh)"
		ElseIf aintSubGrupo = 47 Then 
			lstrRet = "B1 - Residencial Baixa Renda(Consumo Mensal Superior ao Limite Regional de 160kWh)"
		ElseIf aintSubGrupo = 48 Then 
			lstrRet = "B1 - Residencial Baixa Renda(Consumo Mensal Superior ao Limite Regional de 180kWh)"
		ElseIf aintSubGrupo = 49 Then 
			lstrRet = "B1 - Residencial Baixa Renda(Consumo Mensal Superior ao Limite Regional de 200kWh)"
		ElseIf aintSubGrupo = 50 Then 
			lstrRet = "B1 - Residencial Baixa Renda(Consumo Mensal Superior ao Limite Regional de 220kWh)"
		ElseIf aintSubGrupo = 52 Then 
			lstrRet = "A4 - Cooperativa de Eletrificação Rural (2,3 kV a 25 kV)"
		ElseIf aintSubGrupo = 56 Then 
			lstrRet = "A4 - Serviço Público de Irrigação (2,3 kV a 25 kV)"
		ElseIf aintSubGrupo = 57 Then 
			lstrRet = "B1 - Residencial Baixa Renda"
		ElseIf aintSubGrupo = 60 Then 
			lstrRet = "B1 - Residencial Baixa Renda (Consumo mensal superior a 100 até 200 kWh)"
		ElseIf aintSubGrupo = 62 Then 
			lstrRet = "B1- Baixa Renda - Consumo mensal inferior ou igual a 30 kWh (RES. 945/2010)"
		ElseIf aintSubGrupo = 63 Then 
			lstrRet = "B1- Baixa Renda - Consumo mensal superior a 30 kWh e inferior ou igual a 100 kWh (RES. 945/2010)"
		ElseIf aintSubGrupo = 64 Then 
			lstrRet = "B1- Baixa Renda - Consumo mensal superior a 100 kWh e inferior ou igual a 220 kWh (RES. 945/2010)"
		ElseIf aintSubGrupo = 65 Then 
			lstrRet = "B1- Baixa Renda - Consumo mensal superior a 220 kWh (RES. 945/2010)"
		End If
		
		GetExpSubGrupo = lstrRet
	End Function
	
	Private Function GetDetalheFornecimento(ByVal astrTipo As String) As Short
		Dim lintRet As Short
		'
		If astrTipo = "QC" Then
			lintRet = 1 'Número de consumidores
		ElseIf astrTipo = "EG" Then 
			lintRet = 21 'Energia Gerada (kWh)
		ElseIf astrTipo = "EC" Then 
			lintRet = 24 'Energia Consumida (kWh)
		ElseIf astrTipo = "EF" Then 
			lintRet = 22 'Energia Faturada (kWh)
		ElseIf astrTipo = "CF" Then 
			lintRet = 3 'Consumo Faturado (kWh)
		ElseIf astrTipo = "DC" Then 
			lintRet = 20 'Desconto Consumo %
		ElseIf astrTipo = "RC" Then 
			lintRet = 6 'Receita Consumo (R$)
		ElseIf astrTipo = "RB" Then 
			lintRet = 25 'Receita Bandeiras (R$)
		ElseIf astrTipo = "DF" Then 
			lintRet = 2 'Demanda Faturada(kW)
		ElseIf astrTipo = "RD" Then 
			lintRet = 5 'Receita Demanda (R$)
		ElseIf astrTipo = "DD" Then 
			lintRet = 19 'Desconto Demanda %
		ElseIf astrTipo = "UD" Then 
			lintRet = 7 'Ultrapassagem Demanda (kW)
		ElseIf astrTipo = "RU" Then 
			lintRet = 8 'Receita Ultrapassagem Demanda (R$)
		ElseIf astrTipo = "I" Then 
			lintRet = 9 'ICMS (R$)
		ElseIf astrTipo = "P" Then 
			lintRet = 17 'PIS/PASEP (R$)
		ElseIf astrTipo = "C" Then 
			lintRet = 18 'COFINS (R$)
		ElseIf astrTipo = "L" Then 
			lintRet = 10 'Limite Regional (kWh)
		Else
			lintRet = 0
		End If
		
		'  If astrTipo = "" Then lintRet = 4  'Consumo Faturado (kWh Equivalentes)
		'  If astrTipo = "" Then lintRet = 23 'Energia debitada do SCEE (kWh)
		'  If astrTipo = "" Then lintRet = 15 'Energia Adicional Temporária (kWh)
		'  If astrTipo = "" Then lintRet = 16 'Receita Energia Adicional Temporária (R$)
		'  If astrTipo = "" Then lintRet = 11 'Subsídio Mês de Competência Sm(%)
		'  If astrTipo = "" Then lintRet = 12 'Subsídio Mês de Abril/2002 Sref(%)
		'  If astrTipo = "" Then lintRet = 13 'Faturamento Real Residencial Mês de Competência Zm(R$)
		'  If astrTipo = "" Then lintRet = 14 'Diferença Mensal Receita Dm(R$)
		GetDetalheFornecimento = lintRet
	End Function
	
	Private Function GetExpDetalheFornecimento(ByVal aintDetalhe As Short) As String
		Dim lstrRet As String
		'
		If aintDetalhe = 1 Then
			lstrRet = "Número de consumidores"
		ElseIf aintDetalhe = 2 Then 
			lstrRet = "Demanda Faturada(kW)"
		ElseIf aintDetalhe = 3 Then 
			lstrRet = "Consumo Faturado (kWh)"
		ElseIf aintDetalhe = 5 Then 
			lstrRet = "Receita Demanda (R$)"
		ElseIf aintDetalhe = 6 Then 
			lstrRet = "Receita Consumo (R$)"
		ElseIf aintDetalhe = 7 Then 
			lstrRet = "Ultrapassagem Demanda (kW)"
		ElseIf aintDetalhe = 8 Then 
			lstrRet = "Receita Ultrapassagem Demanda (R$)"
		ElseIf aintDetalhe = 9 Then 
			lstrRet = "ICMS (R$)"
		ElseIf aintDetalhe = 10 Then 
			lstrRet = "Limite Regional (kWh)"
		ElseIf aintDetalhe = 17 Then 
			lstrRet = "PIS/PASEP (R$)"
		ElseIf aintDetalhe = 18 Then 
			lstrRet = "COFINS (R$)"
		ElseIf aintDetalhe = 19 Then 
			lstrRet = "Desconto Demanda %"
		ElseIf aintDetalhe = 20 Then 
			lstrRet = "Desconto Consumo %"
		ElseIf aintDetalhe = 21 Then 
			lstrRet = "Energia Gerada (kWh)"
		ElseIf aintDetalhe = 22 Then 
			lstrRet = "Energia Faturada (kWh)"
		ElseIf aintDetalhe = 24 Then 
			lstrRet = "Energia Consumida (kWh)"
		ElseIf aintDetalhe = 25 Then 
			lstrRet = "Receita Bandeiras (R$)"
		Else
			lstrRet = ""
		End If
		GetExpDetalheFornecimento = lstrRet
	End Function
	
	Private Function GetPostoTarifario(ByVal astrTipo As String) As Short
		Dim lintRet As Short
		If astrTipo = "P" Then
			lintRet = 1 'Ponta
		ElseIf astrTipo = "FP" Then 
			lintRet = 2 'Fora de Ponta
		ElseIf astrTipo = "ND" Then 
			lintRet = 3 'Não se aplica
		ElseIf astrTipo = "N" Then 
			lintRet = 4 'Período Normal
		ElseIf astrTipo = "R" Then 
			lintRet = 5 'Período Reservado
		ElseIf astrTipo = "I" Then 
			lintRet = 6 'Intermediário
		Else
			lintRet = 3
		End If
		GetPostoTarifario = lintRet
	End Function
	
	Private Function GetExpPostoTarifario(ByVal aintPosto As Short) As String
		Dim lstrRet As String
		If aintPosto = 1 Then
			lstrRet = "Ponta"
		ElseIf aintPosto = 2 Then 
			lstrRet = "Fora de Ponta"
		ElseIf aintPosto = 3 Then 
			lstrRet = "Não se aplica"
		ElseIf aintPosto = 4 Then 
			lstrRet = "Período Normal"
		ElseIf aintPosto = 5 Then 
			lstrRet = "Período Reservado"
		ElseIf aintPosto = 6 Then 
			lstrRet = "Intermediário"
		End If
		GetExpPostoTarifario = lstrRet
	End Function
	
	Private Sub GravaExportacao()
		Dim lintSeq As Short
		Dim lintRef As Short
		Dim lstrCla As String
		Dim lintOrd As Short
		Dim ldblQtd As Double
		Dim ldblkWh As Double
		Dim ldblVlr As Double
		Dim ldblBan As Double
		Dim ldblRec As Double
		'
		Dim ldblkWhN As Double
		Dim ldblkWhR As Double
		Dim ldblVlrN As Double
		Dim ldblVlrR As Double
		Dim ldblBanN As Double
		Dim ldblBanR As Double
		'
		Dim ldblIcm As Double
		Dim ldblPis As Double
		Dim ldblCof As Double
		'Consumos
		Dim ldblQtdkWhp As Double
		Dim ldblQtdkWhfp As Double
		Dim ldblVlrkWhp As Double
		Dim ldblVlrkWhfp As Double
		Dim ldblVlrBanp As Double
		Dim ldblVlrBanfp As Double
		Dim ldblVlrRecp As Double
		Dim ldblVlrRecfp As Double
		'Demandas
		Dim ldblQtdkWp As Double
		Dim ldblQtdkWfp As Double
		Dim ldblVlrkWp As Double
		Dim ldblVlrkWfp As Double
		Dim ldblQtdkWup As Double
		Dim ldblQtdkWufp As Double
		Dim ldblVlrkWup As Double
		Dim ldblVlrkWufp As Double
		'Reativos
		Dim ldblVlrCRep As Double
		Dim ldblVlrCRefp As Double
		Dim ldblVlrDRep As Double
		Dim ldblVlrDRefp As Double
		'
		Dim lintSampCla As Short
		Dim lintSampMod As Short
		Dim lintSampPos As Short
		Dim lintSampSub As Short
		Dim lblnSampAux As Boolean
		'
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		On Error GoTo ErroGravaExportacao
		Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
		Call LigDes(False)
		iblnExporta = False
		lrstAux = New ADODB.Recordset
		Call Executar("DELETE FROM " & gstrDataBase & ".`samp_exportacao` WHERE `ano_mes` = " & VB6.Format(Me.dtpMesAno.value, "yyyyMM"))
		Call Executar("START TRANSACTION", False)
		Me.lblInfoPre.Text = " Buscando Baixa Renda 945, aguarde...."
		Call Me.lblInfoPre.Refresh()
		lintSeq = 1
		'Grupo B Baixa Renda 945
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * FROM " & gstrDataBase & "." & istrTab945 & " ORDER BY `ord_classe` ASC"
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					Call BarraProgresso((Me.ProgressBarPre), (Me.lblPercPre), (Me.lblInfoPre), 0, .RecordCount, " Baixa Renda 945 ")
					lintSampCla = GetSampClasses(10)
					lintSampMod = GetModalidade("B")
					lintSampPos = GetPostoTarifario("ND")
					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"'
						lintRef = IIf(IsDbNull(.Fields("refaturado").value), 0, .Fields("refaturado").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrCla = IIf(IsDbNull(.Fields("ds_classe").value), "", .Fields("ds_classe").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"'
						lintOrd = IIf(IsDbNull(.Fields("ord_classe").value), 20, .Fields("ord_classe").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"'
						ldblQtd = IIf(IsDbNull(.Fields("faixa").value), 0, .Fields("faixa").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"'
						ldblkWh = IIf(IsDbNull(.Fields("consumo").value), 0, .Fields("consumo").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 = 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"'
						ldblBan = IIf(IsDbNull(.Fields("bandeira").value), 0, .Fields("bandeira").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"'
						ldblRec = IIf(IsDbNull(.Fields("receita").value), 0, .Fields("receita").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"'
						ldblIcm = IIf(IsDbNull(.Fields("icms").value), 0, .Fields("icms").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"'
						ldblPis = IIf(IsDbNull(.Fields("pis").value), 0, .Fields("pis").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"'
						ldblCof = IIf(IsDbNull(.Fields("cofins").value), 0, .Fields("cofins").value)
						'Quantidade Consumidores
						Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 2, lintSampCla, lintSampMod, GetSubGrupo("B", lintOrd, True), GetDetalheFornecimento("QC"), lintSampPos, ldblQtd)
						'Quantidade kWh
						Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 2, lintSampCla, lintSampMod, GetSubGrupo("B", lintOrd, True), GetDetalheFornecimento("CF"), lintSampPos, ldblkWh)
						'Receita kWh R$
						Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 2, lintSampCla, lintSampMod, GetSubGrupo("B", lintOrd, True), GetDetalheFornecimento("RC"), lintSampPos, IIf(Me.chkReceitakWhBan.CheckState = System.Windows.Forms.CheckState.Checked, ldblRec, ldblVlr))
						'Receita Bandeira R$
						Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 2, lintSampCla, lintSampMod, GetSubGrupo("B", lintOrd, True), GetDetalheFornecimento("RB"), lintSampPos, ldblBan)
						If ldblIcm > 0 Then
							'ICMS R$
							Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 2, lintSampCla, lintSampMod, GetSubGrupo("B", lintOrd, True), GetDetalheFornecimento("I"), lintSampPos, ldblIcm)
						End If
						If ldblPis > 0 Then
							'PIS R$
							Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 2, lintSampCla, lintSampMod, GetSubGrupo("B", lintOrd, True), GetDetalheFornecimento("P"), lintSampPos, ldblPis)
						End If
						If ldblCof > 0 Then
							'COFINS R$
							Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 2, lintSampCla, lintSampMod, GetSubGrupo("B", lintOrd, True), GetDetalheFornecimento("C"), lintSampPos, ldblCof)
						End If
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBarPre), (Me.lblPercPre), (Me.lblInfoPre), 1,  , " Baixa Renda 945 ")
					End While
				End If
				Call .Close()
			End If
		End With
		'Grupo B normal
		lstrSql = ""
		lstrSql = lstrSql & "  SELECT "
		lstrSql = lstrSql & "         `ord_classe`,"
		lstrSql = lstrSql & "         `ds_classe`,"
		lstrSql = lstrSql & "         `refaturado`,"
		lstrSql = lstrSql & "     SUM(IF(`qkwh_fat` < 0, 0, 1)) `ncons`,"
		lstrSql = lstrSql & "     SUM(`qkwh_fat`) `qkwh_fat`,"
		lstrSql = lstrSql & "     SUM(`vkwh_fat`) `vkwh_fat`,"
		lstrSql = lstrSql & "     SUM(`vkwh_fat_ban`) `vkwh_fat_ban`,"
		lstrSql = lstrSql & "     SUM(`receita_fp`) `vreceita`, "
		lstrSql = lstrSql & "     SUM(`qkwh_reverso`) `qkwh_reverso`,"
		lstrSql = lstrSql & "     SUM(`vkwh_reverso`) `vkwh_reverso`,"
		'
		lstrSql = lstrSql & "        SUM(qirr_nor_kwh_fat) `qkwh_n_fat`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(qirr_res_kwh_fat) `qkwh_r_fat`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(virr_nor_kwh_fat) `vkwh_n_fat`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(virr_nor_kwh_fat_ban) `vkwh_n_fat_ban`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(virr_res_kwh_fat) `vkwh_r_fat`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(virr_res_kwh_fat_ban) `vkwh_r_fat_ban`, " & vbCrLf
		'
		lstrSql = lstrSql & "     SUM(`icms`) `icms`,"
		lstrSql = lstrSql & "     SUM(`pis`) `pis`,"
		lstrSql = lstrSql & "     SUM(`cofins`) `cofins`"
		lstrSql = lstrSql & "    FROM " & gstrDataBase & "." & istrTabela & " "
		lstrSql = lstrSql & "   WHERE `usinas` = 0 "
		lstrSql = lstrSql & "     AND `grupo` = 'B' "
		lstrSql = lstrSql & "GROUP BY 1, 2, 3 "
		lstrSql = lstrSql & "ORDER BY 1 ASC, 2 ASC, 3 ASC  "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					lintSampMod = GetModalidade("B")
					lintSampPos = GetPostoTarifario("ND")
					Call BarraProgresso((Me.ProgressBarPre), (Me.lblPercPre), (Me.lblInfoPre), 0, .RecordCount, " Grupo B ")
					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"'
						lintRef = IIf(IsDbNull(.Fields("refaturado").value), 0, .Fields("refaturado").value)
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrCla = IIf(IsDbNull(.Fields("ds_classe").value), "", .Fields("ds_classe").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"'
						lintOrd = IIf(IsDbNull(.Fields("ord_classe").value), 20, .Fields("ord_classe").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"'
						ldblQtd = IIf(IsDbNull(.Fields("ncons").value), 0, .Fields("ncons").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"'
						ldblkWh = IIf(IsDbNull(.Fields("qkwh_fat").value), 0, .Fields("qkwh_fat").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 = IIf(IsDbNull(.Fields("vkwh_fat").value), 0, .Fields("vkwh_fat").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"'
						ldblBan = IIf(IsDbNull(.Fields("vkwh_fat_ban").value), 0, .Fields("vkwh_fat_ban").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"'
						ldblRec = IIf(IsDbNull(.Fields("vreceita").value), 0, .Fields("vreceita").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"'
						ldblkWhN = IIf(IsDbNull(.Fields("qkwh_n_fat").value), 0, .Fields("qkwh_n_fat").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"'
						ldblkWhR = IIf(IsDbNull(.Fields("qkwh_r_fat").value), 0, .Fields("qkwh_r_fat").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"'
						ldblVlrN = IIf(IsDbNull(.Fields("vkwh_n_fat").value), 0, .Fields("vkwh_n_fat").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"'
						ldblVlrR = IIf(IsDbNull(.Fields("vkwh_r_fat").value), 0, .Fields("vkwh_r_fat").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"'
						ldblBanN = IIf(IsDbNull(.Fields("vkwh_n_fat_ban").value), 0, .Fields("vkwh_n_fat_ban").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"'
						ldblBanR = IIf(IsDbNull(.Fields("vkwh_r_fat_ban").value), 0, .Fields("vkwh_r_fat_ban").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"'
						ldblIcm = IIf(IsDbNull(.Fields("icms").value), 0, .Fields("icms").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"'
						ldblPis = IIf(IsDbNull(.Fields("pis").value), 0, .Fields("pis").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"'
						ldblCof = IIf(IsDbNull(.Fields("cofins").value), 0, .Fields("cofins").value)
						lblnSampAux = True
						lintSampCla = GetSampClasses(lintOrd)
						lintSampSub = GetSubGrupo("B", lintOrd, False)
						If lintSampCla = 1 And InStr(1, "02,03,41,04,05,06,47", VB6.Format(lintSampSub, "00")) > 0 Then
							lblnSampAux = False
						Else
							lblnSampAux = True
						End If
						If lblnSampAux Then
							'Quantidade Consumidores
							Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, lintSampCla, lintSampMod, lintSampSub, GetDetalheFornecimento("QC"), lintSampPos, ldblQtd)
							If lintSampCla = 9 Then
								'Quantidade kWh - Período Normal
								Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, lintSampCla, lintSampMod, lintSampSub, GetDetalheFornecimento("CF"), GetPostoTarifario("N"), ldblkWhN)
								'Receita kWh R$ - Período Normal
								Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, lintSampCla, lintSampMod, lintSampSub, GetDetalheFornecimento("RC"), GetPostoTarifario("N"), IIf(Me.chkReceitakWhBan.CheckState = System.Windows.Forms.CheckState.Checked, (ldblVlrN + ldblBanN), ldblVlrN))
								'Quantidade kWh - Período Reservado
								Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, lintSampCla, lintSampMod, lintSampSub, GetDetalheFornecimento("CF"), GetPostoTarifario("R"), ldblkWhR)
								'Receita kWh R$ - Período Reservado
								Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, lintSampCla, lintSampMod, lintSampSub, GetDetalheFornecimento("RC"), GetPostoTarifario("R"), IIf(Me.chkReceitakWhBan.CheckState = System.Windows.Forms.CheckState.Checked, (ldblVlrR + ldblBanR), ldblVlrR))
								'Receita Bandeira R$
								Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, lintSampCla, lintSampMod, lintSampSub, GetDetalheFornecimento("RB"), lintSampPos, ldblBanN + ldblBanR)
							Else
								'Quantidade kWh
								Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, lintSampCla, lintSampMod, lintSampSub, GetDetalheFornecimento("CF"), lintSampPos, ldblkWh)
								'Receita kWh R$
								Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, lintSampCla, lintSampMod, lintSampSub, GetDetalheFornecimento("RC"), lintSampPos, IIf(Me.chkReceitakWhBan.CheckState = System.Windows.Forms.CheckState.Checked, ldblRec, ldblVlr))
								'Receita Bandeira R$
								Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, lintSampCla, lintSampMod, lintSampSub, GetDetalheFornecimento("RB"), lintSampPos, ldblBan)
							End If
							If ldblIcm > 0 Then
								'ICMS R$
								Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, lintSampCla, lintSampMod, lintSampSub, GetDetalheFornecimento("I"), lintSampPos, ldblIcm)
							End If
							If ldblPis > 0 Then
								'PIS R$
								Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, lintSampCla, lintSampMod, lintSampSub, GetDetalheFornecimento("P"), lintSampPos, ldblPis)
							End If
							If ldblCof > 0 Then
								'COFINS R$
								Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, lintSampCla, lintSampMod, lintSampSub, GetDetalheFornecimento("C"), lintSampPos, ldblCof)
							End If
						End If
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBarPre), (Me.lblPercPre), (Me.lblInfoPre), 1,  , " Grupo B ")
					End While
				End If
				Call .Close()
			End If
		End With
		'Grupo A Horosazonal
		lstrSql = ""
		lstrSql = lstrSql & "  SELECT " & vbCrLf
		lstrSql = lstrSql & "        `ord_classe`,  " & vbCrLf
		lstrSql = lstrSql & "        `ds_classe`, " & vbCrLf
		lstrSql = lstrSql & "        `refaturado`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(if((qkwh_fat_p+qkwh_fat_fp+qkw_fat_p+qkw_fat_fp)<0,0,1)) `ncons`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(qkwh_fat_p) `qkwh_fat_p`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(qkwh_fat_fp) `qkwh_fat_fp`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(vkwh_fat_p) `vkwh_fat_p`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(vkwh_fat_fp) `vkwh_fat_fp`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(vkwh_fat_p_ban) `vkwh_fat_p_ban`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(vkwh_fat_fp_ban) `vkwh_fat_fp_ban`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(qkw_fat_p) `qkw_fat_p`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(qkw_fat_fp) `qkw_fat_fp`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(vkw_fat_p) `vkw_fat_p`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(vkw_fat_fp) `vkw_fat_fp`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(qkw_fatu_p) `qkw_fatu_p`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(qkw_fatu_fp) `qkw_fatu_fp`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(vkw_fatu_p) `vkw_fatu_p`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(vkw_fatu_fp) `vkw_fatu_fp`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(vconreat_p) `vconreat_p`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(vconreat_fp) `vconreat_fp`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(vdemreat_p) `vdemreat_p`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(vdemreat_fp) `vdemreat_fp`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(`receita_p`) `vreceita_p`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(`receita_fp`) `vreceita_fp`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(icms) `icms`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(pis) `pis`, " & vbCrLf
		lstrSql = lstrSql & "        SUM(cofins) `cofins` " & vbCrLf
		lstrSql = lstrSql & "    FROM " & gstrDataBase & "." & istrTabela & " " & vbCrLf
		lstrSql = lstrSql & "   WHERE `grupo` IN( 'AA','AV','AX') " & vbCrLf
		lstrSql = lstrSql & "GROUP BY 1, 2, 3 " & vbCrLf
		lstrSql = lstrSql & "ORDER BY 1 ASC, 2 ASC, 3 ASC "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					lintSampMod = GetModalidade("AV")
					Call BarraProgresso((Me.ProgressBarPre), (Me.lblPercPre), (Me.lblInfoPre), 0, .RecordCount, " Grupo A Horosazonal ")
					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"'
						lintRef = IIf(IsDbNull(.Fields("refaturado").value), 0, .Fields("refaturado").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"'
						lstrCla = CStr(IIf(IsDbNull(.Fields("ds_classe").value), "", .Fields("ds_classe").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"'
						lintOrd = CShort(IIf(IsDbNull(.Fields("ord_classe").value), 0, .Fields("ord_classe").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"'
						ldblQtd = CDbl(IIf(IsDbNull(.Fields("ncons").value), 0, .Fields("ncons").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"'
						ldblQtdkWhp = CDbl(IIf(IsDbNull(.Fields("qkwh_fat_p").value), 0, .Fields("qkwh_fat_p").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"'
						ldblQtdkWhfp = CDbl(IIf(IsDbNull(.Fields("qkwh_fat_fp").value), 0, .Fields("qkwh_fat_fp").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"'
						ldblVlrkWhp = CDbl(IIf(IsDbNull(.Fields("vkwh_fat_p").value), 0, .Fields("vkwh_fat_p").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"'
						ldblVlrkWhfp = CDbl(IIf(IsDbNull(.Fields("vkwh_fat_fp").value), 0, .Fields("vkwh_fat_fp").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"'
						ldblVlrBanp = CDbl(IIf(IsDbNull(.Fields("vkwh_fat_p_ban").value), 0, .Fields("vkwh_fat_p_ban").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"'
						ldblVlrBanfp = CDbl(IIf(IsDbNull(.Fields("vkwh_fat_fp_ban").value), 0, .Fields("vkwh_fat_fp_ban").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"'
						ldblQtdkWp = CDbl(IIf(IsDbNull(.Fields("qkw_fat_p").value), 0, .Fields("qkw_fat_p").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"'
						ldblQtdkWfp = CDbl(IIf(IsDbNull(.Fields("qkw_fat_fp").value), 0, .Fields("qkw_fat_fp").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"'
						ldblVlrkWp = CDbl(IIf(IsDbNull(.Fields("vkw_fat_p").value), 0, .Fields("vkw_fat_p").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"'
						ldblVlrkWfp = CDbl(IIf(IsDbNull(.Fields("vkw_fat_fp").value), 0, .Fields("vkw_fat_fp").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"'
						ldblQtdkWup = CDbl(IIf(IsDbNull(.Fields("qkw_fatu_p").value), 0, .Fields("qkw_fatu_p").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"'
						ldblQtdkWufp = CDbl(IIf(IsDbNull(.Fields("qkw_fatu_fp").value), 0, .Fields("qkw_fatu_fp").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"'
						ldblVlrkWup = CDbl(IIf(IsDbNull(.Fields("vkw_fatu_p").value), 0, .Fields("vkw_fatu_p").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"'
						ldblVlrkWufp = CDbl(IIf(IsDbNull(.Fields("vkw_fatu_fp").value), 0, .Fields("vkw_fatu_fp").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"'
						ldblVlrCRep = CDbl(IIf(IsDbNull(.Fields("vconreat_p").value), 0, .Fields("vconreat_p").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"'
						ldblVlrCRefp = CDbl(IIf(IsDbNull(.Fields("vconreat_fp").value), 0, .Fields("vconreat_fp").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"'
						ldblVlrDRep = CDbl(IIf(IsDbNull(.Fields("vdemreat_p").value), 0, .Fields("vdemreat_p").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"'
						ldblVlrDRefp = CDbl(IIf(IsDbNull(.Fields("vdemreat_fp").value), 0, .Fields("vdemreat_fp").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"'
						ldblVlrRecp = CDbl(IIf(IsDbNull(.Fields("vreceita_p").value), 0, .Fields("vreceita_p").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"'
						ldblVlrRecfp = CDbl(IIf(IsDbNull(.Fields("vreceita_fp").value), 0, .Fields("vreceita_fp").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"'
						ldblIcm = CDbl(IIf(IsDbNull(.Fields("icms").value), 0, .Fields("icms").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"'
						ldblPis = CDbl(IIf(IsDbNull(.Fields("pis").value), 0, .Fields("pis").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"'
						ldblCof = CDbl(IIf(IsDbNull(.Fields("cofins").value), 0, .Fields("cofins").value))
						'Quantidade Consumidores
						Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, GetSampClasses(lintOrd), lintSampMod, GetSubGrupo("A", lintOrd, False), GetDetalheFornecimento("QC"), GetPostoTarifario("ND"), ldblQtd)
						'Quantidade kWh ponta
						Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, GetSampClasses(lintOrd), lintSampMod, GetSubGrupo("A", lintOrd, False), GetDetalheFornecimento("CF"), GetPostoTarifario("P"), ldblQtdkWhp)
						'Quantidade kWh fora ponta
						Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, GetSampClasses(lintOrd), lintSampMod, GetSubGrupo("A", lintOrd, False), GetDetalheFornecimento("CF"), GetPostoTarifario("FP"), ldblQtdkWhfp)
						'Receita kWh R$ ponta
						Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, GetSampClasses(lintOrd), lintSampMod, GetSubGrupo("A", lintOrd, False), GetDetalheFornecimento("RC"), GetPostoTarifario("P"), IIf(Me.chkReceitakWhBan.CheckState = System.Windows.Forms.CheckState.Checked, ldblVlrRecp, ldblVlrkWhp))
						'Receita kWh R$ fora ponta
						Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, GetSampClasses(lintOrd), lintSampMod, GetSubGrupo("A", lintOrd, False), GetDetalheFornecimento("RC"), GetPostoTarifario("FP"), IIf(Me.chkReceitakWhBan.CheckState = System.Windows.Forms.CheckState.Checked, ldblVlrRecfp, ldblVlrkWhfp))
						'Receita Bandeira R$ ponta
						Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, GetSampClasses(lintOrd), lintSampMod, GetSubGrupo("A", lintOrd, False), GetDetalheFornecimento("RB"), GetPostoTarifario("P"), ldblVlrBanp)
						'Receita Bandeira R$ ponta
						Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, GetSampClasses(lintOrd), lintSampMod, GetSubGrupo("A", lintOrd, False), GetDetalheFornecimento("RB"), GetPostoTarifario("FP"), ldblVlrBanfp)
						If ldblQtdkWp > 0 Then
							'Quantidade kW ponta
							Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, GetSampClasses(lintOrd), lintSampMod, GetSubGrupo("A", lintOrd, False), GetDetalheFornecimento("DF"), GetPostoTarifario("P"), ldblQtdkWp)
						End If
						If ldblQtdkWfp > 0 Then
							'Quantidade kW fora ponta
							Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, GetSampClasses(lintOrd), lintSampMod, GetSubGrupo("A", lintOrd, False), GetDetalheFornecimento("DF"), GetPostoTarifario(IIf(lintSampMod = 5, "ND", "FP")), ldblQtdkWfp)
						End If
						If ldblVlrkWp > 0 Then
							'Receita kW R$ ponta
							Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, GetSampClasses(lintOrd), lintSampMod, GetSubGrupo("A", lintOrd, False), GetDetalheFornecimento("RD"), GetPostoTarifario("P"), ldblVlrkWp)
						End If
						If ldblVlrkWfp > 0 Then
							'Receita kW R$ fora ponta
							Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, GetSampClasses(lintOrd), lintSampMod, GetSubGrupo("A", lintOrd, False), GetDetalheFornecimento("RD"), GetPostoTarifario(IIf(lintSampMod = 5, "ND", "FP")), ldblVlrkWfp)
						End If
						If ldblQtdkWup > 0 Then
							'Quantidade kW ponta
							Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, GetSampClasses(lintOrd), lintSampMod, GetSubGrupo("A", lintOrd, False), GetDetalheFornecimento("UD"), GetPostoTarifario("P"), ldblQtdkWup)
						End If
						If ldblQtdkWufp > 0 Then
							'Quantidade kW fora ponta
							Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, GetSampClasses(lintOrd), lintSampMod, GetSubGrupo("A", lintOrd, False), GetDetalheFornecimento("UD"), GetPostoTarifario(IIf(lintSampMod = 5, "ND", "FP")), ldblQtdkWufp)
						End If
						If ldblVlrkWup > 0 Then
							'Receita kW R$ ponta
							Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, GetSampClasses(lintOrd), lintSampMod, GetSubGrupo("A", lintOrd, False), GetDetalheFornecimento("RU"), GetPostoTarifario("P"), ldblVlrkWup)
						End If
						If ldblVlrkWufp > 0 Then
							'Receita kW R$ fora ponta
							Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, GetSampClasses(lintOrd), lintSampMod, GetSubGrupo("A", lintOrd, False), GetDetalheFornecimento("RU"), GetPostoTarifario(IIf(lintSampMod = 5, "ND", "FP")), ldblVlrkWufp)
						End If
						If ldblIcm > 0 Then
							'ICMS R$
							Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, GetSampClasses(lintOrd), lintSampMod, GetSubGrupo("A", lintOrd, False), GetDetalheFornecimento("I"), lintSampPos, ldblIcm)
						End If
						If ldblPis > 0 Then
							'PIS R$
							Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, GetSampClasses(lintOrd), lintSampMod, GetSubGrupo("A", lintOrd, False), GetDetalheFornecimento("P"), lintSampPos, ldblPis)
						End If
						If ldblCof > 0 Then
							'COFINS R$
							Call InsertSampExportacao(CInt(VB6.Format(Me.dtpMesAno.value, "yyyyMM")), lintSeq, lintRef, 1, GetSampClasses(lintOrd), lintSampMod, GetSubGrupo("A", lintOrd, False), GetDetalheFornecimento("C"), lintSampPos, ldblCof)
						End If
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBarPre), (Me.lblPercPre), (Me.lblInfoPre), 1,  , " Grupo A Horosazonal")
					End While
				End If
				Call .Close()
			End If
		End With
		iblnExporta = True
		Call Executar("COMMIT", False)
		Me.lblInfoPre.Text = Me.lblInfoPre.Text & " *** Finalizado ***"
		Call Me.lblInfoPre.Refresh()
ErroGravaExportacao: 
		Me.Cursor = System.Windows.Forms.Cursors.Default
		Call LigDes(True)
		If myConC.Errors.Count > 0 Then
			Call MsgBox("Código: " & myConC.Errors.Item(myConC.Errors.Count - 1).NativeError & vbCrLf & "Descrição:" & myConC.Errors.Item(myConC.Errors.Count - 1).Description, MsgBoxStyle.Critical, gstrTituloMensagem)
			Call Executar("ROLLBACK", False)
		ElseIf Err.Number > 0 Then 
			Call MsgBox(Err.Number & " - " & GetErrosVB(Err.Number, Err.Description), MsgBoxStyle.Information, gstrTituloMensagem)
			Call Executar("ROLLBACK", False)
		End If
		'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 InsertSampExportacao(ByVal Ano_Mes As Integer, ByRef Sequencia As Short, ByVal Refaturado As Short, ByVal tipo As Short, ByVal classe As Short, ByVal Modalidade As Short, ByVal SubGrupo As Short, ByVal Detalhe As Short, ByVal Posto As Short, Optional ByVal adblValor As Double = 0)
		Dim lstrSql As String
		lstrSql = ""
		lstrSql = lstrSql & "INSERT INTO " & gstrDataBase & ".`samp_exportacao` SET "
		lstrSql = lstrSql & " `ano_mes` = " & Ano_Mes & ", "
		lstrSql = lstrSql & " `sequencia` = " & Sequencia & ", "
		lstrSql = lstrSql & " `refaturado` = " & Refaturado & ", "
		lstrSql = lstrSql & " `tipo` = " & tipo & ", "
		lstrSql = lstrSql & " `classe` = " & classe & ", "
		lstrSql = lstrSql & " `modalidade` = " & Modalidade & ", "
		lstrSql = lstrSql & " `sub_grupo` = " & SubGrupo & ", "
		lstrSql = lstrSql & " `detalhe` = " & Detalhe & ", "
		lstrSql = lstrSql & " `posto` = " & Posto & ", "
		lstrSql = lstrSql & " `valor` = " & Replace(CStr(adblValor), ",", ".") & "; "
		Call Executar(lstrSql, False)
		Sequencia = Sequencia + 1
	End Sub
	
	Private Sub MontaNomeArquivo()
		Dim lstrNomeArq As String
		lstrNomeArq = "SAMP_" & VB6.Format(Me.dtpMesAno.value, "yyyyMM") & "_Faturamento"
		Me.txtArquivoRegular.Text = lstrNomeArq & "_Regular.TXT"
		Me.txtArquivoRefaturado.Text = lstrNomeArq & "_Refaturamento.TXT"
	End Sub
	
	'UPGRADE_WARNING: Event txtDir.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 txtDir_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtDir.TextChanged
		istrCaminho = Me.txtDir.Text
	End Sub
	
	Private Function VerificaSeExisteExportacao() As Boolean
		Dim lblnRet As Boolean
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lblnRet = False
		Call Conectar("SELECT * FROM " & gstrDataBase & ".`samp_exportacao` WHERE `ano_mes` = " & VB6.Format(Me.dtpMesAno.value, "yyyyMM") & " LIMIT 0, 1", lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				lblnRet = (.RecordCount > 0)
				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
		VerificaSeExisteExportacao = lblnRet
	End Function
End Class