Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmRelMediaTusd
	Inherits System.Windows.Forms.Form
	Private iintMesIniPerSeco As Short
	Private iintMesFimPerSeco As Short
	Private ifrmMediaTusd As FrmRelatorio
	Private istrTamCol As String
	Private istrCabCol As String
	Private istrGruMes As String
	
	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 LigDes(False)
		Call ImprimeRel()
		Call LigDes(True)
	End Sub
	
	Private Sub cmdProcessar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdProcessar.Click
		Dim lintIdx As Short
		Dim lblnAux As Boolean
		With Me.cmbMesIni
			For lintIdx = 0 To .Items.Count - 1
				If CInt(VB6.GetItemString(Me.cmbMesIni, .SelectedIndex)) > CDbl(VB6.GetItemString(Me.cmbMesFim, Me.cmbMesFim.SelectedIndex)) Then
					lblnAux = True
				End If
			Next lintIdx
		End With
		If lblnAux Then
			Call MsgBox("Período inicial maior que período final!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
			Call Me.cmbMesIni.Focus()
		Else
			Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
			Call LigDes(False)
			Call MontaGrade()
			Call MontaRel()
			Call LigDes(True)
			Me.Cursor = System.Windows.Forms.Cursors.Default
		End If
	End Sub
	
	Private Sub frmRelMediaTusd_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Me.txtAno.Text = CStr(Year(BuscaDataBD))
		Me.cmbMesIni.SelectedIndex = 0
		Me.cmbMesFim.SelectedIndex = Me.cmbMesFim.Items.Count - 1
		iintMesIniPerSeco = Val(LeConfig("MES_INI_PERIODO_SECO"))
		iintMesFimPerSeco = iintMesIniPerSeco + 6
		Call MontaGrade()
		ifrmMediaTusd = New FrmRelatorio
	End Sub
	
	Private Sub MontaGrade()
		With Me.mfgDados
			Call .Clear()
			.Rows = 1
			.set_ColWidth(0, 1000)
			.set_ColWidth(1, 1900)
			.set_ColWidth(2, 1020)
			.set_ColWidth(3, 1020)
			.set_ColWidth(4, 1020)
			.set_ColWidth(5, 1020)
			.set_ColWidth(6, 1020)
			.set_ColWidth(7, 1020)
			.set_ColWidth(8, 1020)
			.set_ColWidth(9, 1020)
			.set_ColWidth(10, 1020)
			.set_ColWidth(11, 750)
			.set_ColWidth(12, 1020)
			.set_ColWidth(13, 1020)
			.set_ColWidth(14, 1020)
			.set_ColWidth(15, 1020)
			.set_ColWidth(16, 1020)
			.set_TextMatrix(0, 0, "Ordem")
			.set_TextMatrix(0, 1, "Classe")
			.set_TextMatrix(0, 2, "kWh")
			.set_TextMatrix(0, 3, "Vlr kWh")
			.set_TextMatrix(0, 4, "Tarifa")
			.set_TextMatrix(0, 5, "Tusd")
			.set_TextMatrix(0, 6, "%")
			.set_TextMatrix(0, 7, "Valor")
			.set_TextMatrix(0, 8, "Te")
			.set_TextMatrix(0, 9, "%")
			.set_TextMatrix(0, 10, "Valor")
			.set_TextMatrix(0, 11, "Mês/Ano")
			.set_TextMatrix(0, 12, "Reativo")
			.set_TextMatrix(0, 13, "Demanda")
			.set_TextMatrix(0, 14, "Icms")
			.set_TextMatrix(0, 15, "Pis")
			.set_TextMatrix(0, 16, "Cofins")
		End With
		System.Windows.Forms.Application.DoEvents()
	End Sub
	
	Private Sub MontaRel()
		Dim llngMesIni As Integer
		Dim llngMesFim As Integer
		Dim lstrGrTar As String
		Dim lintAux As Short
		Dim ldblAux As Double
		Dim ldblTusd As Double
		Dim ldblTe As Double
		Dim ldblTar As Double
		Dim ldblkWhFxa As Double
		Dim ldblkWhVlr As Double
		Dim ldblReativo As Double
		Dim ldblDemanda As Double
		Dim ldblIcms As Double
		Dim ldblPis As Double
		Dim ldblCofins As Double
		Dim lstrMesAno As String
		Dim llngAnoMes As Integer
		Dim lstrTarGr As String
		Dim lstrClasse As String
		Dim lstrDsClas As String
		Dim lstrCdClas As String
		Dim lstrFItens As String
		Dim ldteLeiAnt As Date
		Dim ldteLeiAtu As Date
		Dim lintMesLeitAtual As Short
		Dim lblnPSecoUmido As Boolean
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Me.mfgDados.Redraw = False
		Me.lblInfo.Text = " Carregando as faturas, aguarde... "
		Call Me.lblInfo.Refresh()
		llngMesIni = CInt(Me.txtAno.Text & VB6.GetItemString(Me.cmbMesIni, Me.cmbMesIni.SelectedIndex))
		llngMesFim = CInt(Me.txtAno.Text & VB6.GetItemString(Me.cmbMesFim, Me.cmbMesFim.SelectedIndex))
		Me.txtTotalkWh.Text = "0"
		Me.txtTotalVlrkWh.Text = "0,00"
		Me.txtTotalTUSD.Text = "0,00"
		Me.txtTotalTE.Text = "0,00"
		Me.txtTotalVlrkW.Text = "0,00"
		Me.txtTotalVlrkVArh.Text = "0,00"
		Me.txtTotalIcms.Text = "0,00"
		Me.txtTotalPis.Text = "0,00"
		Me.txtTotalCofins.Text = "0,00"
		Me.txtMediaTUSD.Text = "0,0000000000"
		Me.txtMediaTE.Text = "0,0000000000"
		System.Windows.Forms.Application.DoEvents()
		lstrSql = ""
		lstrSql = lstrSql & "SELECT "
		lstrSql = lstrSql & "       `nf`.`mesano`, "
		lstrSql = lstrSql & "       `nf`.`ta`, "
		lstrSql = lstrSql & "       `nf`.`codclas`, "
		lstrSql = lstrSql & "       `nf`.`itensserv`, "
		lstrSql = lstrSql & "       `nf`.`dataleitant`, "
		lstrSql = lstrSql & "       `nf`.`dataleit` "
		lstrSql = lstrSql & "  FROM `nf` "
		lstrSql = lstrSql & " WHERE (CONCAT(RIGHT(`nf`.`mesano`,4),LEFT(`nf`.`mesano`,2))+0 >= " & llngMesIni & " AND "
		lstrSql = lstrSql & "        CONCAT(RIGHT(`nf`.`mesano`,4),LEFT(`nf`.`mesano`,2))+0 <= " & llngMesFim & ") "
		lstrSql = lstrSql & "   AND (`nf`.`flgst` <> 'C' OR (`nf`.`flgst` = 'C' AND `nf`.`datast` > CONCAT(right(`nf`.`mesano`,4),'-',left(`nf`.`mesano`,2),'-',DAY(LAST_DAY(CONCAT(right(`nf`.`mesano`,4),'-',left(`nf`.`mesano`,2),'-01')))))) "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State > 0 Then
				If .RecordCount > 0 Then
					Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount)
					While Not .EOF
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrMesAno = Trim(IIf(IsDbNull(.Fields("mesano").value), "", .Fields("mesano").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrTarGr = Trim(IIf(IsDbNull(.Fields("ta").value), "01B100", .Fields("ta").value))
						'UPGRADE_WARNING: 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 = Trim(IIf(IsDbNull(.Fields("codclas").value), "0", .Fields("codclas").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						lstrFItens = Trim(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"'
						ldteLeiAnt = CDate(IIf(IsDbNull(.Fields("dataleitant").value), "1900-01-01", .Fields("dataleitant").value))
						'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
						ldteLeiAtu = CDate(IIf(IsDbNull(.Fields("dataleit").value), "1900-01-01", .Fields("dataleit").value))
						lintMesLeitAtual = Month(ldteLeiAtu)
						lblnPSecoUmido = (lintMesLeitAtual >= iintMesIniPerSeco And lintMesLeitAtual <= iintMesFimPerSeco)
						If Mid(lstrTarGr, 3, 1) = "B" Then
							ldblReativo = BuscaVlrItem(lstrFItens, "0302020012")
							If CDbl(VB.Left(lstrClasse, 1)) = 9 Then
								If CDbl(VB.Right(lstrClasse, 1)) = 4 Or CDbl(VB.Right(lstrClasse, 1)) = 5 Or CDbl(VB.Right(lstrClasse, 1)) = 6 Then
									ldblIcms = 0
									ldblAux = BuscaVlrItem(lstrFItens, "0302030009")
									If ldblAux > 0 Then ldblIcms = ldblAux
									ldblAux = BuscaVlrItem(lstrFItens, "0302030010")
									If ldblAux > 0 Then ldblIcms = ldblIcms + ldblAux
									ldblPis = BuscaVlrItem(lstrFItens, "0302020029")
									ldblCofins = BuscaVlrItem(lstrFItens, "0302020030")
									For lintAux = 0 To 5
										lstrDsClas = "Residencial Bx.Renda" & " Fx. " & (lintAux + 1)
										lstrCdClas = CStr(VB.Left(lstrMesAno, 2) & 900 + (lintAux + 1))
										ldblkWhFxa = BuscaVlrItem(lstrFItens, "030201009" & lintAux)
										ldblkWhVlr = BuscaVlrItem(lstrFItens, "030202009" & lintAux)
										ldblTar = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, "01B102110" & (lintAux + 1), 3)
										ldblTusd = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, "01B102120" & (lintAux + 1), 3)
										ldblTe = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, "01B102130" & (lintAux + 1), 3)
										Call AdicionaGrade(lstrCdClas, lstrDsClas, ldblkWhFxa, ldblkWhVlr, ldblTar, ldblTusd, ldblTe, lstrMesAno, ldblReativo, 0, ldblIcms, ldblPis, ldblCofins)
										ldblIcms = 0
										ldblPis = 0
										ldblCofins = 0
										ldblReativo = 0
									Next lintAux
								Else
									lstrDsClas = "Residencial Normal"
									lstrCdClas = CStr(VB.Left(lstrMesAno, 2) & 900)
									ldblkWhFxa = BuscaVlrItem(lstrFItens, "030201009")
									ldblkWhVlr = BuscaVlrItem(lstrFItens, "030202009")
									ldblTar = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, "01B1011101", 3)
									ldblTusd = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, "01B1011201", 3)
									ldblTe = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, "01B1011301", 3)
									ldblIcms = 0
									ldblAux = BuscaVlrItem(lstrFItens, "0302030009")
									If ldblAux > 0 Then ldblIcms = ldblAux
									ldblAux = BuscaVlrItem(lstrFItens, "0302030010")
									If ldblAux > 0 Then ldblIcms = ldblIcms + ldblAux
									ldblPis = BuscaVlrItem(lstrFItens, "0302020029")
									ldblCofins = BuscaVlrItem(lstrFItens, "0302020030")
									Call AdicionaGrade(lstrCdClas, lstrDsClas, ldblkWhFxa, ldblkWhVlr, ldblTar, ldblTusd, ldblTe, lstrMesAno, ldblReativo, 0, ldblIcms, ldblPis, ldblCofins)
								End If
							Else
								If CDbl(VB.Left(lstrClasse, 1)) < 4 Then
									lstrDsClas = "Industrial"
									lstrCdClas = CStr(VB.Left(lstrMesAno, 2) & 300)
									lstrGrTar = "01B310"
								ElseIf CDbl(VB.Left(lstrClasse, 1)) = 4 Then 
									lstrDsClas = "Comercial"
									lstrCdClas = CStr(VB.Left(lstrMesAno, 2) & 400)
									lstrGrTar = "01B330"
								ElseIf CDbl(VB.Left(lstrClasse, 1)) = 5 Then 
									lstrDsClas = "Rural"
									lstrCdClas = CStr(VB.Left(lstrMesAno, 2) & 500)
									lstrGrTar = "01B201"
								ElseIf CDbl(VB.Left(lstrClasse, 1)) = 6 Then 
									If CDbl(VB.Left(lstrClasse, 2)) = 64 Then
										lstrDsClas = "Iluminação Pública"
										lstrCdClas = CStr(VB.Left(lstrMesAno, 2) & 640)
										If CDbl(VB.Right(lstrClasse, 1)) = 2 Then
											lstrGrTar = "01B402"
										Else
											lstrGrTar = "01B401"
										End If
									Else
										lstrDsClas = "Poder Público"
										lstrCdClas = CStr(VB.Left(lstrMesAno, 2) & 600)
										lstrGrTar = "01B350"
									End If
								ElseIf CDbl(VB.Left(lstrClasse, 1)) = 7 Then 
									lstrDsClas = "Serviço Público"
									lstrCdClas = CStr(VB.Left(lstrMesAno, 2) & 700)
									lstrGrTar = "01B320"
								ElseIf CDbl(VB.Left(lstrClasse, 1)) = 8 Then 
									lstrDsClas = "Consumo Próprio"
									lstrCdClas = CStr(VB.Left(lstrMesAno, 2) & 800)
									lstrGrTar = "01B340"
								End If
								ldblkWhFxa = BuscaVlrItem(lstrFItens, "030201009")
								ldblkWhVlr = BuscaVlrItem(lstrFItens, "030202009")
								ldblTar = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, lstrGrTar & "1101", 3)
								ldblTusd = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, lstrGrTar & "1201", 3)
								ldblTe = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, lstrGrTar & "1301", 3)
								ldblIcms = 0
								ldblAux = BuscaVlrItem(lstrFItens, "0302030009")
								If ldblAux > 0 Then ldblIcms = ldblAux
								ldblAux = BuscaVlrItem(lstrFItens, "0302030010")
								If ldblAux > 0 Then ldblIcms = ldblIcms + ldblAux
								ldblPis = BuscaVlrItem(lstrFItens, "0302020029")
								ldblCofins = BuscaVlrItem(lstrFItens, "0302020030")
								Call AdicionaGrade(lstrCdClas, lstrDsClas, ldblkWhFxa, ldblkWhVlr, ldblTar, ldblTusd, ldblTe, lstrMesAno, ldblReativo, 0, ldblIcms, ldblPis, ldblCofins)
							End If
						Else
							If Mid(lstrTarGr, 3, 2) = "AA" Or Mid(lstrTarGr, 3, 2) = "AV" Or Mid(lstrTarGr, 3, 2) = "AL" Or Mid(lstrTarGr, 3, 2) = "AP" Then
								lstrCdClas = CStr(VB.Left(lstrMesAno, 2) & IIf(Mid(lstrTarGr, 3, 2) = "AA", 210, IIf(Mid(lstrTarGr, 3, 2) = "AV", 220, IIf(Mid(lstrTarGr, 3, 2) = "AL", 230, IIf(Mid(lstrTarGr, 3, 2) = "AP", 240, 250)))))
								lstrDsClas = IIf(Mid(lstrTarGr, 3, 2) = "AA", "Horo Sazonal Azul Ponta", IIf(Mid(lstrTarGr, 3, 2) = "AV", "Horo Sazonal Verde Ponta", IIf(Mid(lstrTarGr, 3, 2) = "AL", "Consumidor Livre Ponta", IIf(Mid(lstrTarGr, 3, 2) = "AP", "Produtor Ponta", ""))))
								lstrGrTar = "01" & Mid(lstrTarGr, 3, 2) & "01"
								If lblnPSecoUmido Then
									ldblTar = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, lstrGrTar & "1101", 3)
									ldblTusd = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, lstrGrTar & "1201", 3)
									ldblTe = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, lstrGrTar & "1301", 3)
								Else
									ldblTar = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, lstrGrTar & "1105", 3)
									ldblTusd = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, lstrGrTar & "1205", 3)
									ldblTe = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, lstrGrTar & "1305", 3)
								End If
								ldblkWhFxa = BuscaVlrItem(lstrFItens, "0302010010") + BuscaVlrItem(lstrFItens, "0302010041") + BuscaVlrItem(lstrFItens, "0302010043")
								ldblkWhVlr = BuscaVlrItem(lstrFItens, "0302020010") + BuscaVlrItem(lstrFItens, "0302020041") + BuscaVlrItem(lstrFItens, "0302020043")
								ldblReativo = BuscaVlrItem(lstrFItens, "0302020013") + BuscaVlrItem(lstrFItens, "0302020027")
								ldblDemanda = BuscaVlrItem(lstrFItens, "0302020021") + BuscaVlrItem(lstrFItens, "0302020022")
								ldblIcms = 0
								ldblAux = BuscaVlrItem(lstrFItens, "0302030009")
								If ldblAux <> 0 Then ldblIcms = ldblAux
								ldblAux = BuscaVlrItem(lstrFItens, "0302030010")
								If ldblAux <> 0 Then
									ldblIcms = ldblIcms + ldblAux
								End If
								ldblPis = BuscaVlrItem(lstrFItens, "0302020029")
								ldblCofins = BuscaVlrItem(lstrFItens, "0302020030")
								Call AdicionaGrade(lstrCdClas, lstrDsClas, ldblkWhFxa, ldblkWhVlr, ldblTar, ldblTusd, ldblTe, lstrMesAno, ldblReativo, ldblDemanda, ldblIcms, ldblPis, ldblCofins)
								ldblIcms = 0
								ldblPis = 0
								ldblCofins = 0
								lstrCdClas = CStr(VB.Left(lstrMesAno, 2) & IIf(Mid(lstrTarGr, 3, 2) = "AA", 211, IIf(Mid(lstrTarGr, 3, 2) = "AV", 221, IIf(Mid(lstrTarGr, 3, 2) = "AL", 231, IIf(Mid(lstrTarGr, 3, 2) = "AP", 241, 251)))))
								lstrDsClas = IIf(Mid(lstrTarGr, 3, 2) = "AA", "Horo Sazonal Azul Fora Ponta", IIf(Mid(lstrTarGr, 3, 2) = "AV", "Horo Sazonal Verde Fora Ponta", IIf(Mid(lstrTarGr, 3, 2) = "AL", "Consumidor Livre Fora Ponta", IIf(Mid(lstrTarGr, 3, 2) = "AP", "Produtor Fora Ponta", ""))))
								If lblnPSecoUmido Then
									ldblTar = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, lstrGrTar & "1102", 3)
									ldblTusd = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, lstrGrTar & "1202", 3)
									ldblTe = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, lstrGrTar & "1302", 3)
								Else
									ldblTar = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, lstrGrTar & "1106", 3)
									ldblTusd = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, lstrGrTar & "1206", 3)
									ldblTe = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, lstrGrTar & "1306", 3)
								End If
								ldblkWhFxa = BuscaVlrItem(lstrFItens, "0302010011") + BuscaVlrItem(lstrFItens, "0302010042") + BuscaVlrItem(lstrFItens, "0302010044")
								ldblkWhVlr = BuscaVlrItem(lstrFItens, "0302020011") + BuscaVlrItem(lstrFItens, "0302020042") + BuscaVlrItem(lstrFItens, "0302020044")
								ldblReativo = BuscaVlrItem(lstrFItens, "0302020014") + BuscaVlrItem(lstrFItens, "0302020028")
								ldblDemanda = BuscaVlrItem(lstrFItens, "0302020023") + BuscaVlrItem(lstrFItens, "0302020026") '+ BuscaVlrItem(lstrFItens, "0302020072")
								Call AdicionaGrade(lstrCdClas, lstrDsClas, ldblkWhFxa, ldblkWhVlr, ldblTar, ldblTusd, ldblTe, lstrMesAno, ldblReativo, ldblDemanda, ldblIcms, ldblPis, ldblCofins)
							Else
								lstrCdClas = CStr(VB.Left(lstrMesAno, 2) & IIf(Mid(lstrTarGr, 3, 2) = "A4", 110, IIf(Mid(lstrTarGr, 3, 2) = "AS", 120, 130)))
								lstrDsClas = IIf(Mid(lstrTarGr, 3, 2) = "A4", "Convencional", IIf(Mid(lstrTarGr, 3, 2) = "AS", "Suprimento", ""))
								lstrGrTar = "01" & Mid(lstrTarGr, 3, 2) & "01"
								ldblkWhFxa = BuscaVlrItem(lstrFItens, "0302010009")
								ldblkWhVlr = BuscaVlrItem(lstrFItens, "0302020009")
								ldblTar = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, lstrGrTar & "1101", 3)
								ldblTusd = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, lstrGrTar & "1201", 3)
								ldblTe = TarifaProporcional(ldteLeiAnt, ldteLeiAtu, lstrGrTar & "1301", 3)
								ldblReativo = BuscaVlrItem(lstrFItens, "0302020012") + BuscaVlrItem(lstrFItens, "0302020031")
								ldblDemanda = BuscaVlrItem(lstrFItens, "0302020015") + BuscaVlrItem(lstrFItens, "0302020018")
								ldblIcms = 0
								ldblAux = BuscaVlrItem(lstrFItens, "0302030009")
								If ldblAux > 0 Then ldblIcms = ldblAux
								ldblAux = BuscaVlrItem(lstrFItens, "0302030010")
								If ldblAux > 0 Then ldblIcms = ldblIcms + ldblAux
								ldblPis = BuscaVlrItem(lstrFItens, "0302020029")
								ldblCofins = BuscaVlrItem(lstrFItens, "0302020030")
								Call AdicionaGrade(lstrCdClas, lstrDsClas, ldblkWhFxa, ldblkWhVlr, ldblTar, ldblTusd, ldblTe, lstrMesAno, ldblReativo, ldblDemanda, ldblIcms, ldblPis, ldblCofins)
							End If
						End If
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
					End While
				End If
				Call .Close()
			End If
		End With
		With Me.mfgDados
			For lintAux = 1 To .Rows - 1
				If IsNumeric(.get_TextMatrix(lintAux, 6)) Then
					.set_TextMatrix(lintAux, 7, FormatNumber(Arredondar(CDbl(.get_TextMatrix(lintAux, 3)) * (CDbl(.get_TextMatrix(lintAux, 6)) / 100), 2), 2))
					.set_TextMatrix(lintAux, 10, FormatNumber(Arredondar(CDbl(.get_TextMatrix(lintAux, 3)) * (CDbl(.get_TextMatrix(lintAux, 9)) / 100), 2), 2))
				End If
				System.Windows.Forms.Application.DoEvents()
			Next lintAux
			For lintAux = 1 To .Rows - 1
				If IsNumeric(.get_TextMatrix(lintAux, 2)) Then
					Me.txtTotalkWh.Text = FormatNumber(IIf(IsNumeric(Me.txtTotalkWh.Text), Me.txtTotalkWh.Text, 0) + CDbl(.get_TextMatrix(lintAux, 2)), 0)
				End If
				If IsNumeric(.get_TextMatrix(lintAux, 3)) Then
					Me.txtTotalVlrkWh.Text = FormatNumber(IIf(IsNumeric(Me.txtTotalVlrkWh.Text), Me.txtTotalVlrkWh.Text, 0) + CDbl(.get_TextMatrix(lintAux, 3)), 2)
				End If
				If IsNumeric(.get_TextMatrix(lintAux, 7)) Then
					Me.txtTotalTUSD.Text = FormatNumber(IIf(IsNumeric(Me.txtTotalTUSD.Text), Me.txtTotalTUSD.Text, 0) + CDbl(.get_TextMatrix(lintAux, 7)), 2)
				End If
				If IsNumeric(.get_TextMatrix(lintAux, 10)) Then
					Me.txtTotalTE.Text = FormatNumber(IIf(IsNumeric(Me.txtTotalTE.Text), Me.txtTotalTE.Text, 0) + CDbl(.get_TextMatrix(lintAux, 10)), 2)
				End If
				If IsNumeric(.get_TextMatrix(lintAux, 12)) Then
					Me.txtTotalVlrkVArh.Text = FormatNumber(IIf(IsNumeric(Me.txtTotalVlrkVArh.Text), Me.txtTotalVlrkVArh.Text, 0) + CDbl(.get_TextMatrix(lintAux, 12)), 2)
				End If
				If IsNumeric(.get_TextMatrix(lintAux, 13)) Then
					Me.txtTotalVlrkW.Text = FormatNumber(IIf(IsNumeric(Me.txtTotalVlrkW.Text), Me.txtTotalVlrkW.Text, 0) + CDbl(.get_TextMatrix(lintAux, 13)), 2)
				End If
				If IsNumeric(.get_TextMatrix(lintAux, 14)) Then
					Me.txtTotalIcms.Text = FormatNumber(IIf(IsNumeric(Me.txtTotalIcms.Text), Me.txtTotalIcms.Text, 0) + CDbl(.get_TextMatrix(lintAux, 14)), 2)
				End If
				If IsNumeric(.get_TextMatrix(lintAux, 15)) Then
					Me.txtTotalPis.Text = FormatNumber(IIf(IsNumeric(Me.txtTotalPis.Text), Me.txtTotalPis.Text, 0) + CDbl(.get_TextMatrix(lintAux, 15)), 2)
				End If
				If IsNumeric(.get_TextMatrix(lintAux, 16)) Then
					Me.txtTotalCofins.Text = FormatNumber(IIf(IsNumeric(Me.txtTotalCofins.Text), Me.txtTotalCofins.Text, 0) + CDbl(.get_TextMatrix(lintAux, 16)), 2)
				End If
				System.Windows.Forms.Application.DoEvents()
			Next lintAux
			.Redraw = True
			.Col = 0
			.Sort = MSFlexGridLib.SortSettings.flexSortGenericAscending
		End With
		Me.txtMediaTUSD.Text = CStr(Arredondar(CDbl(Me.txtTotalTUSD.Text) / CDbl(Me.txtTotalkWh.Text), 10))
		Me.txtMediaTE.Text = CStr(Arredondar(CDbl(Me.txtTotalTE.Text) / CDbl(Me.txtTotalkWh.Text), 10))
		'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 ImprimeRel()
		Dim llngRow As Integer
		Dim lstrGruMes As String
		Dim lstrClasse As String
		Dim ldblQtdkWh As Double
		Dim ldblVlrkWh As Double
		Dim ldblVlrTar As Double
		Dim ldblTusd As Double
		Dim ldblTusdP As Double
		Dim ldblTusdV As Double
		Dim ldblTe As Double
		Dim ldblTeP As Double
		Dim ldblTeV As Double
		Dim ldblVlrkW As Double
		Dim ldblVlrkVArh As Double
		Dim ldblIcms As Double
		Dim ldblPis As Double
		Dim ldblCofins As Double
		Dim lstrTab As String
		Dim lintCtrl As Short
		'Totais
		Dim ldblSubTQtdkWh As Double
		Dim ldblSubTVlrkWh As Double
		Dim ldblSubTTusdV As Double
		Dim ldblSubTTeV As Double
		Dim ldblSubTVlrkW As Double
		Dim ldblSubTVlrkVArh As Double
		Dim ldblSubTIcms As Double
		Dim ldblSubTPis As Double
		Dim ldblSubTCofins As Double
		
		Dim ldblTotGQtdkWh As Double
		Dim ldblTotGVlrkWh As Double
		Dim ldblTotGTusdV As Double
		Dim ldblTotGTeV As Double
		Dim ldblTotGVlrkW As Double
		Dim ldblTotGVlrkVArh As Double
		Dim ldblTotGIcms As Double
		Dim ldblTotGPis As Double
		Dim ldblTotGCofins As Double
		
		istrTamCol = "<45mm |>26mm|>27mm|>26mm|>26mm|>25mm|>27mm|>26mm|>25mm|>27mm;"
		istrCabCol = "CLASSE|kWh|Valor|Tarifa|Tar.TUSD|% TUSD|Valor TUSD|Tar.TE|% TE|Valor TE"
		With ifrmMediaTusd
			.quem_chama = Me
			.VS.Font = VB6.FontChangeName(.VS.Font, "Arial")
			.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
			.VS.PageBorder = VSVIEW6.TableBorderSettings.tbNone
			.VS.ShowGuides = VSVIEW6.ShowGuideSettings.gdShow
			.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.MarginFooter = "0mm"
			.VS.MarginHeader = "0mm"
			.VS.TextColor = System.Drawing.Color.Black
			.VS.BrushStyle = VSVIEW6.BrushStyleSettings.bsSolid
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
			.VS.StartDoc()
		End With
		lintCtrl = 0
		With Me.mfgDados
			ldblSubTQtdkWh = 0
			ldblSubTVlrkWh = 0
			ldblSubTTusdV = 0
			ldblSubTTeV = 0
			ldblSubTVlrkW = 0
			ldblSubTVlrkVArh = 0
			ldblSubTIcms = 0
			ldblSubTPis = 0
			ldblSubTCofins = 0
			ldblTotGQtdkWh = 0
			ldblTotGVlrkWh = 0
			ldblTotGTusdV = 0
			ldblTotGTeV = 0
			ldblTotGVlrkW = 0
			ldblTotGVlrkVArh = 0
			ldblTotGIcms = 0
			ldblTotGPis = 0
			ldblTotGCofins = 0
			lstrGruMes = ""
			For llngRow = 1 To .Rows - 1
				istrGruMes = .get_TextMatrix(llngRow, 11)
				lstrClasse = .get_TextMatrix(llngRow, 1)
				ldblQtdkWh = CDbl(.get_TextMatrix(llngRow, 2))
				ldblVlrkWh = CDbl(.get_TextMatrix(llngRow, 3))
				ldblVlrTar = CDbl(.get_TextMatrix(llngRow, 4))
				ldblTusd = CDbl(.get_TextMatrix(llngRow, 5))
				ldblTusdP = CDbl(.get_TextMatrix(llngRow, 6))
				ldblTusdV = CDbl(.get_TextMatrix(llngRow, 7))
				ldblTe = CDbl(.get_TextMatrix(llngRow, 8))
				ldblTeP = CDbl(.get_TextMatrix(llngRow, 9))
				ldblTeV = CDbl(.get_TextMatrix(llngRow, 10))
				ldblVlrkVArh = CDbl(.get_TextMatrix(llngRow, 12))
				ldblVlrkW = CDbl(.get_TextMatrix(llngRow, 13))
				ldblIcms = CDbl(.get_TextMatrix(llngRow, 14))
				ldblPis = CDbl(.get_TextMatrix(llngRow, 15))
				ldblCofins = CDbl(.get_TextMatrix(llngRow, 16))
				If lstrGruMes <> istrGruMes Then
					If (ldblSubTQtdkWh + ldblSubTVlrkWh + ldblSubTTusdV + ldblSubTTeV) <> 0 Then
						Call ImpRelTot(ldblSubTQtdkWh, ldblSubTVlrkWh, ldblSubTTusdV, ldblSubTTeV, ldblSubTVlrkW, ldblSubTVlrkVArh, ldblSubTIcms, ldblSubTPis, ldblSubTCofins, lstrGruMes, CStr(0))
						ldblSubTQtdkWh = 0
						ldblSubTVlrkWh = 0
						ldblSubTTusdV = 0
						ldblSubTTeV = 0
						ldblSubTVlrkW = 0
						ldblSubTVlrkVArh = 0
						ldblSubTIcms = 0
						ldblSubTPis = 0
						ldblSubTCofins = 0
					End If
					If lstrGruMes <> "" Then
						Call ifrmMediaTusd.VS.NewPage()
					End If
					Call CabecTipo()
					lstrGruMes = istrGruMes
				End If
				lstrTab = ""
				lstrTab = lstrTab & lstrClasse & "|"
				lstrTab = lstrTab & FormatNumber(ldblQtdkWh, 0) & "|"
				lstrTab = lstrTab & FormatNumber(ldblVlrkWh, 2) & "|"
				lstrTab = lstrTab & FormatNumber(ldblVlrTar, 2) & "|"
				lstrTab = lstrTab & FormatNumber(ldblTusd, 2) & "|"
				lstrTab = lstrTab & FormatNumber(ldblTusdP, 2) & "|"
				lstrTab = lstrTab & FormatNumber(ldblTusdV, 2) & "|"
				lstrTab = lstrTab & FormatNumber(ldblTe, 2) & "|"
				lstrTab = lstrTab & FormatNumber(ldblTeP, 2) & "|"
				lstrTab = lstrTab & FormatNumber(ldblTeV, 2)
				'Subtotal
				ldblSubTQtdkWh = ldblSubTQtdkWh + ldblQtdkWh
				ldblSubTVlrkWh = ldblSubTVlrkWh + ldblVlrkWh
				ldblSubTTusdV = ldblSubTTusdV + ldblTusdV
				ldblSubTTeV = ldblSubTTeV + ldblTeV
				ldblSubTVlrkW = ldblSubTVlrkW + ldblVlrkW
				ldblSubTVlrkVArh = ldblSubTVlrkVArh + ldblVlrkVArh
				ldblSubTIcms = ldblSubTIcms + ldblIcms
				ldblSubTPis = ldblSubTPis + ldblPis
				ldblSubTCofins = ldblSubTCofins + ldblCofins
				
				'Total Geral
				ldblTotGQtdkWh = ldblTotGQtdkWh + ldblQtdkWh
				ldblTotGVlrkWh = ldblTotGVlrkWh + ldblVlrkWh
				ldblTotGTusdV = ldblTotGTusdV + ldblTusdV
				ldblTotGTeV = ldblTotGTeV + ldblTeV
				ldblTotGVlrkW = ldblTotGVlrkW + ldblVlrkW
				ldblTotGVlrkVArh = ldblTotGVlrkVArh + ldblVlrkVArh
				ldblTotGIcms = ldblTotGIcms + ldblIcms
				ldblTotGPis = ldblTotGPis + ldblPis
				ldblTotGCofins = ldblTotGCofins + ldblCofins
				
				With ifrmMediaTusd
					If lintCtrl = 1 Then
						.VS.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
						.VS.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
						'UPGRADE_ISSUE: VBControlExtender method ifrmMediaTusd.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
						Call .VS.DrawRectangle("8mm", .VS.CurrentY, "288mm", .VS.CurrentY + 165)
						.VS.BrushColor = System.Drawing.Color.White
						.VS.PenStyle = VSVIEW6.PenStyleSettings.psSolid
						lintCtrl = 0
					Else
						lintCtrl = 1
					End If
					.VS.Table = istrTamCol & lstrTab
				End With
			Next llngRow
			Call ImpRelTot(ldblSubTQtdkWh, ldblSubTVlrkWh, ldblSubTTusdV, ldblSubTTeV, ldblSubTVlrkW, ldblSubTVlrkVArh, ldblSubTIcms, ldblSubTPis, ldblSubTCofins, istrGruMes, CStr(0))
			Call LineFeed((ifrmMediaTusd.VS), 1)
			Call ImpRelTot(ldblTotGQtdkWh, ldblTotGVlrkWh, ldblTotGTusdV, ldblTotGTeV, ldblTotGVlrkW, ldblTotGVlrkVArh, ldblTotGIcms, ldblTotGPis, ldblTotGCofins, "", CStr(1))
		End With
		With ifrmMediaTusd
			Call .VS.EndDoc()
			Call .Show()
		End With
	End Sub
	
	Public Sub CabecaRel()
		With ifrmMediaTusd
			Call Cabecalho_Relatorio(.VS, gstrEmpresa_Nome, "Relatório de Média TUSD e TE ", "3", True, "")
			.VS.Font = VB6.FontChangeSize(.VS.Font, 8)
			Call LineFeed(.VS, 3)
			.VS.Table = istrTamCol & istrCabCol
			'UPGRADE_ISSUE: VBControlExtender method ifrmMediaTusd.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
			.VS.CurrentY = .VS.CurrentY + 200
		End With
	End Sub
	
	Private Sub CabecTipo()
		Dim lstrTab As String
		If istrGruMes <> "" Then
			lstrTab = ""
			lstrTab = lstrTab & istrGruMes & "|"
			lstrTab = lstrTab & "|" 'kwh
			lstrTab = lstrTab & "|" 'valor
			lstrTab = lstrTab & "|" 'tarifa
			lstrTab = lstrTab & "|" 'tusd
			lstrTab = lstrTab & "|" '%
			lstrTab = lstrTab & "|" 'valor
			lstrTab = lstrTab & "|" 'te
			lstrTab = lstrTab & "|" '%
			lstrTab = lstrTab & "" 'valor
			With ifrmMediaTusd
				.VS.Font = VB6.FontChangeBold(.VS.Font, True)
				.VS.Table = istrTamCol & lstrTab
				.VS.Font = VB6.FontChangeBold(.VS.Font, False)
			End With
		End If
	End Sub
	
	Private Sub ImpRelTot(ByVal adblQtdKwh As Double, ByVal adblVlrkWh As Double, ByVal adblTusdV As Double, ByVal adblTeV As Double, ByVal adblVlrkW As Double, ByVal adblVlrkVArh As Double, ByVal adblIcms As Double, ByVal adblPis As Double, ByVal adblCofins As Double, ByVal astrMesAno As String, ByVal astrTipo As String)
		Dim lstrTab As String
		Dim ldblAux As Double
		Dim ldblPIc As Double
		Dim ldblPPi As Double
		Dim ldblPCo As Double
		Dim ldblVIc As Double
		Dim ldblVPi As Double
		Dim ldblVCo As Double
		
		ldblAux = adblVlrkWh + adblVlrkW + adblVlrkVArh
		ldblPIc = Arredondar(adblIcms / ldblAux, 4)
		ldblVIc = Arredondar(adblTusdV * ldblPIc, 2)
		ldblPPi = Arredondar(adblPis / ldblAux, 4)
		ldblVPi = Arredondar(adblTusdV * ldblPPi, 2)
		ldblPCo = Arredondar(adblCofins / ldblAux, 4)
		ldblVCo = Arredondar(adblTusdV * ldblPCo, 2)
		
		lstrTab = ""
		lstrTab = lstrTab & IIf(CDbl(astrTipo) = 0, "SUB-TOTAL (" & astrMesAno & ")", "TOTAL GERAL") & "|"
		lstrTab = lstrTab & FormatNumber(adblQtdKwh, 0) & "|"
		lstrTab = lstrTab & FormatNumber(adblVlrkWh, 2) & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & FormatNumber(adblTusdV, 2) & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & FormatNumber(adblTeV, 2)
		With ifrmMediaTusd
			Call LineFeed(.VS, 1)
			.VS.Font = VB6.FontChangeBold(.VS.Font, True)
			.VS.Table = istrTamCol & lstrTab
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
		End With
		lstrTab = ""
		lstrTab = lstrTab & "DEMANDA|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & FormatNumber(adblVlrkW, 2) & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		With ifrmMediaTusd
			.VS.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
			.VS.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
			'UPGRADE_ISSUE: VBControlExtender method ifrmMediaTusd.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
			Call .VS.DrawRectangle("8mm", .VS.CurrentY, "288mm", .VS.CurrentY + 165)
			.VS.BrushColor = System.Drawing.Color.White
			.VS.PenStyle = VSVIEW6.PenStyleSettings.psSolid
			.VS.Font = VB6.FontChangeBold(.VS.Font, True)
			.VS.Table = istrTamCol & lstrTab
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
		End With
		lstrTab = ""
		lstrTab = lstrTab & "REATIVO|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & FormatNumber(adblVlrkVArh, 2) & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		With ifrmMediaTusd
			.VS.Font = VB6.FontChangeBold(.VS.Font, True)
			.VS.Table = istrTamCol & lstrTab
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
		End With
		lstrTab = ""
		lstrTab = lstrTab & "TOTAL|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & FormatNumber(adblVlrkWh + adblVlrkW + adblVlrkVArh, 2) & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		With ifrmMediaTusd
			.VS.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
			.VS.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
			'UPGRADE_ISSUE: VBControlExtender method ifrmMediaTusd.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
			Call .VS.DrawRectangle("8mm", .VS.CurrentY, "288mm", .VS.CurrentY + 165)
			.VS.BrushColor = System.Drawing.Color.White
			.VS.PenStyle = VSVIEW6.PenStyleSettings.psSolid
			.VS.Font = VB6.FontChangeBold(.VS.Font, True)
			.VS.Table = istrTamCol & lstrTab
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
		End With
		lstrTab = ""
		lstrTab = lstrTab & "TRANSFERÊNCIAS|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		With ifrmMediaTusd
			.VS.Font = VB6.FontChangeBold(.VS.Font, True)
			.VS.Table = istrTamCol & lstrTab
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
		End With
		lstrTab = ""
		lstrTab = lstrTab & "ICMS|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & FormatNumber(adblIcms, 2) & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & FormatNumber(ldblPIc * 100, 2) & "(%)|"
		lstrTab = lstrTab & FormatNumber(ldblVIc, 2) & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		With ifrmMediaTusd
			.VS.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
			.VS.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
			'UPGRADE_ISSUE: VBControlExtender method ifrmMediaTusd.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
			Call .VS.DrawRectangle("8mm", .VS.CurrentY, "288mm", .VS.CurrentY + 165)
			.VS.BrushColor = System.Drawing.Color.White
			.VS.PenStyle = VSVIEW6.PenStyleSettings.psSolid
			.VS.Font = VB6.FontChangeBold(.VS.Font, True)
			.VS.Table = istrTamCol & lstrTab
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
		End With
		lstrTab = ""
		lstrTab = lstrTab & "PIS|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & FormatNumber(adblPis, 2) & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & FormatNumber(ldblPPi * 100, 2) & "(%)|"
		lstrTab = lstrTab & FormatNumber(ldblVPi, 2) & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		With ifrmMediaTusd
			.VS.Font = VB6.FontChangeBold(.VS.Font, True)
			.VS.Table = istrTamCol & lstrTab
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
		End With
		lstrTab = ""
		lstrTab = lstrTab & "COFINS|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & FormatNumber(adblCofins, 2) & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & FormatNumber(ldblPCo * 100, 2) & "(%)|"
		lstrTab = lstrTab & FormatNumber(ldblVCo, 2) & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		With ifrmMediaTusd
			.VS.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
			.VS.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
			'UPGRADE_ISSUE: VBControlExtender method ifrmMediaTusd.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
			Call .VS.DrawRectangle("8mm", .VS.CurrentY, "288mm", .VS.CurrentY + 165)
			.VS.BrushColor = System.Drawing.Color.White
			.VS.PenStyle = VSVIEW6.PenStyleSettings.psSolid
			.VS.Font = VB6.FontChangeBold(.VS.Font, True)
			.VS.Table = istrTamCol & lstrTab
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
		End With
		lstrTab = ""
		lstrTab = lstrTab & "RECEITA|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & FormatNumber(adblTusdV + ldblVIc + ldblVPi + ldblVCo, 2) & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		With ifrmMediaTusd
			.VS.Font = VB6.FontChangeBold(.VS.Font, True)
			.VS.Table = istrTamCol & lstrTab
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
		End With
		
		lstrTab = ""
		lstrTab = lstrTab & "MÉDIAS|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & FormatNumber(Arredondar(adblTusdV / adblQtdKwh, 10), 10) & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & "|"
		lstrTab = lstrTab & FormatNumber(Arredondar(adblTeV / adblQtdKwh, 10), 10)
		With ifrmMediaTusd
			Call LineFeed(.VS, 1)
			.VS.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
			.VS.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
			'UPGRADE_ISSUE: VBControlExtender method ifrmMediaTusd.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
			Call .VS.DrawRectangle("8mm", .VS.CurrentY, "288mm", .VS.CurrentY + 165)
			.VS.BrushColor = System.Drawing.Color.White
			.VS.PenStyle = VSVIEW6.PenStyleSettings.psSolid
			.VS.Font = VB6.FontChangeBold(.VS.Font, True)
			.VS.Table = istrTamCol & lstrTab
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
		End With
		
	End Sub
	
	Private Sub AdicionaGrade(ByVal astrCdClasse As String, ByVal astrDsClasse As String, ByVal adblkWh As Double, ByVal adblValor As Double, ByVal adblTarifa As Double, ByVal adblTusd As Double, ByVal adblTe As Double, ByVal astrMesAno As String, ByVal adblkVArh As Double, ByVal adblkW As Double, ByVal adblIcms As Double, ByVal adblPis As Double, ByVal adblCofins As Double)
		Dim llngRow As Integer
		Dim llngPos As Integer
		llngPos = 0
		
		If adblkWh > 0 Or adblIcms > 0 Then
			With Me.mfgDados
				'Busca a linha da grid que tem a informacao
				For llngRow = 1 To .Rows - 1
					If .get_TextMatrix(llngRow, 0) = astrCdClasse Then
						llngPos = llngRow
						llngRow = .Rows - 1
					End If
				Next llngRow
				If llngPos = 0 Then
					.Rows = .Rows + 1
					llngPos = (.Rows - 1)
					.set_TextMatrix(llngPos, 0, astrCdClasse)
					.set_TextMatrix(llngPos, 1, astrDsClasse)
					.set_TextMatrix(llngPos, 4, FormatNumber(adblTarifa, 2))
					.set_TextMatrix(llngPos, 5, FormatNumber(adblTusd, 2))
					If adblTusd > 0 Then
						.set_TextMatrix(llngPos, 6, FormatNumber(Arredondar((adblTusd / adblTarifa) * 100, 2), 2))
					Else
						.set_TextMatrix(llngPos, 6, "0,00")
					End If
					
					.set_TextMatrix(llngPos, 8, FormatNumber(adblTe, 2))
					
					If adblTe > 0 Then
						.set_TextMatrix(llngPos, 9, FormatNumber(Arredondar((adblTe / adblTarifa) * 100, 2), 2))
					Else
						.set_TextMatrix(llngPos, 9, "0,00")
					End If
					
					.set_TextMatrix(llngPos, 11, astrMesAno)
					
				End If
				.set_TextMatrix(llngPos, 2, FormatNumber(CDbl(IIf(IsNumeric(.get_TextMatrix(llngPos, 2)), .get_TextMatrix(llngPos, 2), 0)) + adblkWh, 0))
				.set_TextMatrix(llngPos, 3, FormatNumber(CDbl(IIf(IsNumeric(.get_TextMatrix(llngPos, 3)), .get_TextMatrix(llngPos, 3), 0)) + adblValor, 2))
				.set_TextMatrix(llngPos, 12, FormatNumber(CDbl(IIf(IsNumeric(.get_TextMatrix(llngPos, 12)), .get_TextMatrix(llngPos, 12), 0)) + adblkVArh, 2))
				.set_TextMatrix(llngPos, 13, FormatNumber(CDbl(IIf(IsNumeric(.get_TextMatrix(llngPos, 13)), .get_TextMatrix(llngPos, 13), 0)) + adblkW, 2))
				
				.set_TextMatrix(llngPos, 14, FormatNumber(CDbl(IIf(IsNumeric(.get_TextMatrix(llngPos, 14)), .get_TextMatrix(llngPos, 14), 0)) + adblIcms, 2))
				.set_TextMatrix(llngPos, 15, FormatNumber(CDbl(IIf(IsNumeric(.get_TextMatrix(llngPos, 15)), .get_TextMatrix(llngPos, 15), 0)) + adblPis, 2))
				.set_TextMatrix(llngPos, 16, FormatNumber(CDbl(IIf(IsNumeric(.get_TextMatrix(llngPos, 16)), .get_TextMatrix(llngPos, 16), 0)) + adblCofins, 2))
			End With
		End If
	End Sub
	
	Private Sub txtAno_Enter(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtAno.Enter
		With Me.txtAno
			.SelectionStart = 0
			.SelectionLength = Len(.Text)
		End With
	End Sub
	
	Private Sub txtAno_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtAno.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii = System.Windows.Forms.Keys.Return Then
			Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
		ElseIf KeyAscii <> 8 And (KeyAscii < 48 Or KeyAscii > 57) Then 
			KeyAscii = 0
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub LigDes(ByVal ablnAux As Boolean)
		Me.txtAno.Enabled = ablnAux
		Me.cmbMesFim.Enabled = ablnAux
		Me.cmbMesIni.Enabled = ablnAux
		Me.cmdProcessar.Enabled = ablnAux
		Me.cmdImprimir.Enabled = ablnAux
		Me.cmdFechar.Enabled = ablnAux
	End Sub
End Class