Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmRelGtf
	Inherits System.Windows.Forms.Form
	Private ifrmRelGtf As FrmRelatorio
	Private istrTamColB As String
	Private istrTamColC As String
	Private istrTamColV As String
	Private istrTamColA As String
	Private istrCabColB As String
	Private istrCabColC As String
	Private istrCabColV As String
	Private istrCabColA As String
	Private iintMesSeco As Short
	
	Private Sub cmdExportar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExportar.Click
		Dim lstrLin As String
		Dim lintARQ As Short
		Dim llngRow As Integer
		Dim llngCol As Integer
		Dim lstrCam As String
		
		lstrCam = Trim(Me.txtDir.Text)
		If lstrCam = "" Then
			lstrCam = My.Application.Info.DirectoryPath
		Else
			If VB.Right(lstrCam, 1) <> "\" Then
				lstrCam = lstrCam & "\"
			End If
		End If
		lintARQ = FreeFile
		FileOpen(lintARQ, lstrCam & "GTF.B.csv", OpenMode.Output)
		With Me.mfgDadosB
			For llngRow = 0 To .Rows - 1
				lstrLin = ""
				For llngCol = 0 To .Cols - 1
					lstrLin = lstrLin & .get_TextMatrix(llngRow, llngCol) & ";"
				Next llngCol
				PrintLine(lintARQ, lstrLin)
			Next llngRow
		End With
		FileClose(lintARQ)
		
		lintARQ = FreeFile
		FileOpen(lintARQ, lstrCam & "GTF.AV.csv", OpenMode.Output)
		With Me.mfgDadosAV
			For llngRow = 0 To .Rows - 1
				lstrLin = ""
				For llngCol = 0 To .Cols - 1
					lstrLin = lstrLin & .get_TextMatrix(llngRow, llngCol) & ";"
				Next llngCol
				PrintLine(lintARQ, lstrLin)
			Next llngRow
		End With
		FileClose(lintARQ)
		
		lintARQ = FreeFile
		FileOpen(lintARQ, lstrCam & "GTF.AA.csv", OpenMode.Output)
		With Me.mfgDadosAA
			For llngRow = 0 To .Rows - 1
				lstrLin = ""
				For llngCol = 0 To .Cols - 1
					lstrLin = lstrLin & .get_TextMatrix(llngRow, llngCol) & ";"
				Next llngCol
				PrintLine(lintARQ, lstrLin)
			Next llngRow
		End With
		FileClose(lintARQ)
		
		lintARQ = FreeFile
		FileOpen(lintARQ, lstrCam & "GTF.AC.csv", OpenMode.Output)
		With Me.mfgDadosAC
			For llngRow = 0 To .Rows - 1
				lstrLin = ""
				For llngCol = 0 To .Cols - 1
					lstrLin = lstrLin & .get_TextMatrix(llngRow, llngCol) & ";"
				Next llngCol
				PrintLine(lintARQ, lstrLin)
			Next llngRow
		End With
		FileClose(lintARQ)
		
		Call MsgBox("Foram gerados os arquivos:" & vbCrLf & lstrCam & "GTF.B.csv" & vbCrLf & lstrCam & "GTF.AC.csv" & vbCrLf & lstrCam & "GTF.AA.csv" & vbCrLf & lstrCam & "GTF.AV.csv", MsgBoxStyle.OKOnly, "Mensagem do sistema")
	End Sub
	
	Private Sub cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click
		Call Me.Close()
	End Sub
	
	Public Sub CabecaRel()
		With ifrmRelGtf
			Call Cabecalho_Relatorio(.VS, LeConfig("EMPRESA_NOME"), "Relatório G.T.F. ", "4", True, "De " & Me.dtpInicio.value & " até " & Me.dtpFim.value)
			.VS.Font = VB6.FontChangeSize(.VS.Font, 7)
			Call LineFeed(.VS, 3)
			'UPGRADE_ISSUE: VBControlExtender method ifrmRelGtf.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(ByVal astrTipGrup As String)
		With ifrmRelGtf
			If astrTipGrup = "B" Then
				.VS.Table = istrTamColB & istrCabColB
			ElseIf astrTipGrup = "C" Then 
				.VS.Table = istrTamColC & istrCabColC
			ElseIf astrTipGrup = "V" Then 
				.VS.Table = istrTamColV & istrCabColV
			ElseIf astrTipGrup = "A" Then 
				.VS.Table = istrTamColA & istrCabColA
			End If
		End With
	End Sub
	
	Private Sub cmdImprimir_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdImprimir.Click
		Dim lstrTab As String
		Dim llngRow As Integer
		Dim lstrNewCla As String
		Dim lstrNewSub As String
		Dim lstrOldCla As String
		Dim lstrOldSub As String
		Dim lintCtrZeb As Short
		istrTamColB = "<60mm|>10mm|>15mm|>20mm|>30mm;|"
		istrTamColC = "<40mm|>10mm|>15mm|>20mm|>30mm|>30mm;|"
		istrTamColV = "<20mm|>10mm|>15mm|>20mm|>30mm|>30mm|>30mm|<30mm;|"
		istrTamColA = "<10mm|>10mm|>15mm|>20mm|>30mm|>30mm|>30mm|>30mm|<30mm;|"
		istrCabColB = "Męs|Ref|Qtde|MWh"
		istrCabColC = "Męs|Ref|Qtde|MWh|kW"
		istrCabColV = "Męs|Ref|Qtde|MWhP|MWhF|kW|Tipo"
		istrCabColA = "Męs|Ref|Qtde|MWhP|MWhF|kWP|kWF|Tipo"
		'
		With ifrmRelGtf
			.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.orPortrait
			.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
		lstrOldCla = ""
		lintCtrZeb = 0
		Call CabecTipo("B")
		With Me.mfgDadosB
			For llngRow = 1 To .Rows - 1
				lstrNewCla = .get_TextMatrix(llngRow, 2)
				lstrNewSub = .get_TextMatrix(llngRow, 3)
				If lstrNewCla <> lstrOldCla Then
					If lstrOldCla <> "" Then
						ifrmRelGtf.VS.NewPage()
						Call CabecTipo("B")
					End If
					ifrmRelGtf.VS.Table = "<190mm;" & lstrNewCla
					lstrOldCla = lstrNewCla
				End If
				If lstrNewSub <> lstrOldSub Then
					ifrmRelGtf.VS.Table = "<5mm|<185mm;|" & lstrNewSub
					lstrOldSub = lstrNewSub
				End If
				lstrTab = ""
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 0) & "|"
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 1) & "|"
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 4) & "|"
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 5)
				With ifrmRelGtf
					If lintCtrZeb = 0 Then
						.VS.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
						.VS.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
						'UPGRADE_ISSUE: VBControlExtender method ifrmRelGtf.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("60mm", .VS.CurrentY, "150mm", .VS.CurrentY + 165)
						.VS.BrushColor = System.Drawing.Color.White
						.VS.PenStyle = VSVIEW6.PenStyleSettings.psSolid
						lintCtrZeb = 1
					Else
						lintCtrZeb = 0
					End If
					.VS.Table = istrTamColB & lstrTab
				End With
			Next llngRow
		End With
		ifrmRelGtf.VS.NewPage()
		Call CabecTipo("C")
		lintCtrZeb = 0
		lstrOldCla = ""
		With Me.mfgDadosAC
			For llngRow = 1 To .Rows - 1
				lstrNewCla = .get_TextMatrix(llngRow, 2)
				lstrNewSub = .get_TextMatrix(llngRow, 3)
				If lstrNewCla <> lstrOldCla Then
					If lstrOldCla <> "" Then
						ifrmRelGtf.VS.NewPage()
						Call CabecTipo("C")
					End If
					ifrmRelGtf.VS.Table = "<190mm;" & lstrNewCla
					lstrOldCla = lstrNewCla
				End If
				If lstrNewSub <> lstrOldSub Then
					ifrmRelGtf.VS.Table = "<5mm|<185mm;|" & lstrNewSub
					lstrOldSub = lstrNewSub
				End If
				lstrTab = ""
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 0) & "|"
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 1) & "|"
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 4) & "|"
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 5) & "|"
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 6)
				With ifrmRelGtf
					If lintCtrZeb = 0 Then
						.VS.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
						.VS.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
						'UPGRADE_ISSUE: VBControlExtender method ifrmRelGtf.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("40mm", .VS.CurrentY, "170mm", .VS.CurrentY + 165)
						.VS.BrushColor = System.Drawing.Color.White
						.VS.PenStyle = VSVIEW6.PenStyleSettings.psSolid
						lintCtrZeb = 1
					Else
						lintCtrZeb = 0
					End If
					.VS.Table = istrTamColC & lstrTab
				End With
			Next llngRow
		End With
		ifrmRelGtf.VS.NewPage()
		Call CabecTipo("V")
		lintCtrZeb = 0
		lstrOldCla = ""
		With Me.mfgDadosAV
			For llngRow = 1 To .Rows - 1
				lstrNewCla = .get_TextMatrix(llngRow, 2)
				lstrNewSub = .get_TextMatrix(llngRow, 3)
				If lstrNewCla <> lstrOldCla Then
					If lstrOldCla <> "" Then
						ifrmRelGtf.VS.NewPage()
						Call CabecTipo("V")
					End If
					ifrmRelGtf.VS.Table = "<190mm;" & lstrNewCla
					lstrOldCla = lstrNewCla
				End If
				If lstrNewSub <> lstrOldSub Then
					ifrmRelGtf.VS.Table = "<5mm|<185mm;|" & lstrNewSub
					lstrOldSub = lstrNewSub
				End If
				lstrTab = ""
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 0) & "|"
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 1) & "|"
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 4) & "|"
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 5) & "|"
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 6) & "|"
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 7) & "|"
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 8)
				With ifrmRelGtf
					If lintCtrZeb = 0 Then
						.VS.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
						.VS.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
						'UPGRADE_ISSUE: VBControlExtender method ifrmRelGtf.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("20mm", .VS.CurrentY, "190mm", .VS.CurrentY + 165)
						.VS.BrushColor = System.Drawing.Color.White
						.VS.PenStyle = VSVIEW6.PenStyleSettings.psSolid
						lintCtrZeb = 1
					Else
						lintCtrZeb = 0
					End If
					.VS.Table = istrTamColV & lstrTab
				End With
			Next llngRow
		End With
		ifrmRelGtf.VS.NewPage()
		Call CabecTipo("A")
		lstrOldCla = ""
		With Me.mfgDadosAA
			For llngRow = 1 To .Rows - 1
				lstrNewCla = .get_TextMatrix(llngRow, 2)
				lstrNewSub = .get_TextMatrix(llngRow, 3)
				If lstrNewCla <> lstrOldCla Then
					If lstrOldCla <> "" Then
						ifrmRelGtf.VS.NewPage()
						Call CabecTipo("A")
					End If
					ifrmRelGtf.VS.Table = "<190mm;" & lstrNewCla
					lstrOldCla = lstrNewCla
				End If
				If lstrNewSub <> lstrOldSub Then
					ifrmRelGtf.VS.Table = "<5mm|<185mm;|" & lstrNewSub
					lstrOldSub = lstrNewSub
				End If
				lstrTab = ""
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 0) & "|"
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 1) & "|"
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 4) & "|"
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 5) & "|"
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 6) & "|"
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 7) & "|"
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 8) & "|"
				lstrTab = lstrTab & .get_TextMatrix(llngRow, 9)
				With ifrmRelGtf
					If lintCtrZeb = 0 Then
						.VS.PenStyle = VSVIEW6.PenStyleSettings.psTransparent
						.VS.BrushColor = System.Drawing.ColorTranslator.FromOle(&HE0E0E0)
						'UPGRADE_ISSUE: VBControlExtender method ifrmRelGtf.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("10mm", .VS.CurrentY, "200mm", .VS.CurrentY + 165)
						.VS.BrushColor = System.Drawing.Color.White
						.VS.PenStyle = VSVIEW6.PenStyleSettings.psSolid
						lintCtrZeb = 1
					Else
						lintCtrZeb = 0
					End If
					.VS.Table = istrTamColA & lstrTab
				End With
			Next llngRow
		End With
		With ifrmRelGtf
			Call .VS.EndDoc()
			Call .Show()
		End With
	End Sub
	
	Private Sub cmdProcessar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdProcessar.Click
		Dim lstrMes As String
		Dim lstrOrd As String
		Dim lstrCla As String
		Dim lstrGru As String
		Dim lstrDsC As String
		Dim lstrIte As String
		Dim ldblBkWh As Double
		Dim ldblCkWh As Double
		Dim ldblCkW As Double
		Dim ldblAkWhp As Double
		Dim ldblAkWhf As Double
		Dim ldblAkWp As Double
		Dim ldblAkWf As Double
		Dim ldblVkWhp As Double
		Dim ldblVkWhf As Double
		Dim ldblVkWf As Double
		Dim lblnSeca As Boolean
		Dim ldblTar As Double
		Dim llngRow As Integer
		Dim llngIni As Integer
		Dim llngFim As Integer
		Dim ldteLei As Date
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
		Call GravaConfig("DIR_GTF", Replace(Me.txtDir.Text, "\", "\\"))
		Call MontaGrades()
		Me.cmdProcessar.Enabled = False
		Me.cmdImprimir.Enabled = False
		Me.cmdFechar.Enabled = False
		Me.cmdExportar.Enabled = False
		Me.dtpInicio.value = CDate("01/" & VB6.Format(Me.dtpInicio.value, "mm/yyyy"))
		Me.dtpFim.value = CDate("01/" & VB6.Format(Me.dtpFim.value, "mm/yyyy"))
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM nf "
		lstrSql = lstrSql & " WHERE mesano_ref >= " & VB6.Format(Me.dtpInicio.value, "YYYYMM") & " AND "
		lstrSql = lstrSql & "       mesano_ref <= " & VB6.Format(Me.dtpFim.value, "YYYYMM")
		lstrSql = lstrSql & "   AND (flgst<>'C' OR (flgst = 'C' AND datast > CONCAT(right(mesano,4),'-',left(mesano,2),'-',DAY(LAST_DAY(CONCAT(right(mesano,4),'-',left(mesano,2),'-01')))))) "
		lstrSql = lstrSql & " ORDER BY grupo ASC, mesano_ref ASC, if(grupo='A', codclas, MID(ta,3,2)) ASC "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State > 0 Then
				If .RecordCount > 0 Then
					Me.lblInfo.Text = " Buscando os dados...."
					Call Me.lblInfo.Refresh()
					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"'
						lstrMes = 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"'
						lstrCla = Trim(IIf(IsDbNull(.Fields("codclas").value), "", .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"'
						lstrGru = Mid(Trim(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"'
						lstrIte = 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"'
						ldteLei = CDate(IIf(IsDbNull(.Fields("dataleit").value), "1900-01-01", .Fields("dataleit").value))
						lstrOrd = ""
						If VB.Left(lstrGru, 1) = "A" Then
							lstrDsC = BuscaClasse(lstrCla)
							If lstrGru = "A4" Then
								lstrCla = "Convencional"
								ldblCkWh = (BuscaVlrItem(lstrIte, "0302010009") / 1000) 'Em MegaWatt
								ldblCkW = Truncate(BuscaVlrItem(lstrIte, "0302010017"), 5)
								Call AdicionaGradeAC(lstrMes, lstrCla, lstrDsC, ldblCkWh, ldblCkW)
							ElseIf lstrGru = "AA" Then 
								lstrCla = "Azul"
								ldblAkWhp = (BuscaVlrItem(lstrIte, "0302010010") / 1000) 'Em MegaWatt
								ldblAkWhf = (BuscaVlrItem(lstrIte, "0302010011") / 1000) 'Em MegaWatt
								ldblAkWp = Truncate(BuscaVlrItem(lstrIte, "0302010021"), 5)
								ldblAkWf = Truncate(BuscaVlrItem(lstrIte, "0302010025"), 5)
								lblnSeca = (Month(ldteLei) >= iintMesSeco And Month(ldteLei) <= iintMesSeco + 6)
								Call AdicionaGradeAA(lstrMes, lstrCla, lstrDsC, ldblAkWhp, ldblAkWhf, ldblAkWp, ldblAkWf, lblnSeca)
							ElseIf lstrGru = "AV" Then 
								lstrCla = "Verde"
								ldblVkWhp = (BuscaVlrItem(lstrIte, "0302010010") / 1000) 'Em MegaWatt
								ldblVkWhf = (BuscaVlrItem(lstrIte, "0302010011") / 1000) 'Em MegaWatt
								ldblVkWf = Truncate(BuscaVlrItem(lstrIte, "0302010025"), 5)
								lblnSeca = (Month(ldteLei) >= iintMesSeco And Month(ldteLei) <= iintMesSeco + 6)
								Call AdicionaGradeAV(lstrMes, lstrCla, lstrDsC, ldblVkWhp, ldblVkWhf, ldblVkWf, lblnSeca)
							End If
						ElseIf VB.Left(lstrGru, 1) = "B" Then 
							If chkPeloLido.CheckState = System.Windows.Forms.CheckState.Checked Then
								ldblBkWh = BuscaVlrItem(lstrIte, "030201008")
							Else
								ldblBkWh = BuscaVlrItem(lstrIte, "030201009")
							End If
							If lstrGru = "B1" Then
								If lstrCla = "9101" Or lstrCla = "9107" Then
									lstrDsC = "Residencial Normal"
									lstrOrd = "0100"
								Else
									lstrDsC = "Residencial Baixa Renda"
									lstrOrd = "0200"
								End If
								lstrCla = "Residencial"
							ElseIf lstrGru = "B2" Then 
								lstrCla = "Rural"
								lstrDsC = "Rural"
								lstrOrd = "0300"
							ElseIf lstrGru = "B3" Then 
								If CDbl(VB.Left(lstrCla, 1)) < 4 Then
									lstrDsC = "Industrial"
									lstrOrd = "0400"
								ElseIf CDbl(VB.Left(lstrCla, 1)) = 4 Then 
									lstrDsC = "Comercial"
									lstrOrd = "0500"
								ElseIf CDbl(VB.Left(lstrCla, 2)) = 61 Or CDbl(VB.Left(lstrCla, 2)) = 62 Or CDbl(VB.Left(lstrCla, 2)) = 63 Then 
									lstrDsC = "Poder Publico"
									lstrOrd = "0600"
								ElseIf CDbl(VB.Left(lstrCla, 1)) = 7 Then 
									lstrDsC = "Servico Publico"
									lstrOrd = "0700"
								ElseIf CDbl(VB.Left(lstrCla, 1)) = 8 Then 
									lstrDsC = "Consumo Proprio"
									lstrOrd = "0800"
								End If
								lstrCla = "Demais Classes"
							ElseIf lstrGru = "B4" Then 
								If CDbl(lstrCla) = 6401 Then
									lstrDsC = "Rede"
									lstrOrd = "0900"
								ElseIf CDbl(lstrCla) = 6402 Then 
									lstrDsC = "Bubo"
									lstrOrd = "1000"
								End If
								lstrCla = "Iluminaçăo Pública"
							End If
							If lstrDsC = "Residencial Baixa Renda" Then
								With Me.mfgFxBxRenda
									For llngRow = 0 To .Rows - 1
										llngIni = CInt(.get_TextMatrix(llngRow, 0))
										llngFim = CInt(.get_TextMatrix(llngRow, 1))
										If ldblBkWh >= llngIni And ldblBkWh <= llngFim Then
											lstrOrd = VB6.Format(CInt(lstrOrd) + llngRow, "0000")
											If llngFim = 999999 Then
												lstrDsC = lstrDsC & "(Acima " & .get_TextMatrix(llngRow - 1, 1) & ")"
											Else
												lstrDsC = lstrDsC & "(" & llngFim & ")"
											End If
										End If
									Next llngRow
								End With
							End If
							If lstrDsC = "Residencial Normal" Then
								With Me.mfgFxResidencial
									For llngRow = 0 To .Rows - 1
										llngIni = CInt(.get_TextMatrix(llngRow, 0))
										llngFim = CInt(.get_TextMatrix(llngRow, 1))
										If ldblBkWh >= llngIni And ldblBkWh <= llngFim Then
											lstrOrd = VB6.Format(CInt(lstrOrd) + llngRow, "0000")
											If llngFim = 999999 Then
												lstrDsC = lstrDsC & "(Acima " & .get_TextMatrix(llngRow - 1, 1) & ")"
											Else
												lstrDsC = lstrDsC & "(" & llngFim & ")"
											End If
										End If
									Next llngRow
								End With
							End If
							Call AdicionaGradeB(lstrMes, lstrCla, lstrDsC, (ldblBkWh / 1000), lstrOrd)
						End If
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
					End While
				End If
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
		Call CalculaUltimoMes()
		With Me.mfgDadosB
			.Col = 6
			.Sort = MSFlexGridLib.SortSettings.flexSortGenericAscending
		End With
		Me.cmdProcessar.Enabled = True
		Me.cmdImprimir.Enabled = True
		Me.cmdFechar.Enabled = True
		Me.cmdExportar.Enabled = True
		Me.Cursor = System.Windows.Forms.Cursors.Default
	End Sub
	
	Private Sub CalculaUltimoMes()
		Dim llngRow As Integer
		Dim lintQtd As Short
		Dim ldblVlrP As Double
		Dim ldblVlr1 As Double
		Dim ldblVlr2 As Double
		Dim ldblVlr3 As Double
		Dim lintAux As Short
		With Me.mfgDadosB
			For llngRow = 1 To .Rows - 1
				If CDbl(.get_TextMatrix(llngRow, 0)) = 12 And Len(Trim(.get_TextMatrix(llngRow, 5))) = 0 Then
					ldblVlrP = 0
					lintQtd = 0
					ldblVlr1 = CDbl(IIf(.get_TextMatrix(llngRow - 1, 5) = "", 0, .get_TextMatrix(llngRow - 1, 5)))
					If ldblVlr1 <> 0 Then lintQtd = lintQtd + 1
					ldblVlr2 = CDbl(IIf(.get_TextMatrix(llngRow - 2, 5) = "", 0, .get_TextMatrix(llngRow - 2, 5)))
					If ldblVlr2 <> 0 Then lintQtd = lintQtd + 1
					ldblVlr3 = CDbl(IIf(.get_TextMatrix(llngRow - 3, 5) = "", 0, .get_TextMatrix(llngRow - 3, 5)))
					If ldblVlr3 <> 0 Then lintQtd = lintQtd + 1
					If lintQtd <> 0 Then
						ldblVlrP = (ldblVlr1 + ldblVlr2 + ldblVlr3) / lintQtd
						.set_TextMatrix(llngRow, 5, FormatNumber(ldblVlrP, 3))
						.set_TextMatrix(llngRow, 4, .get_TextMatrix(llngRow - 1, 4))
					Else
						.set_TextMatrix(llngRow, 4, "")
						.set_TextMatrix(llngRow, 5, "")
					End If
				End If
			Next llngRow
		End With
		With Me.mfgDadosAC
			For llngRow = 1 To .Rows - 1
				If CDbl(.get_TextMatrix(llngRow, 0)) = 12 And Len(Trim(.get_TextMatrix(llngRow, 5))) = 0 Then
					For lintAux = 5 To 6
						ldblVlrP = 0
						lintQtd = 0
						ldblVlr1 = CDbl(IIf(.get_TextMatrix(llngRow - 1, lintAux) = "", 0, .get_TextMatrix(llngRow - 1, lintAux)))
						If ldblVlr1 <> 0 Then lintQtd = lintQtd + 1
						ldblVlr2 = CDbl(IIf(.get_TextMatrix(llngRow - 2, lintAux) = "", 0, .get_TextMatrix(llngRow - 2, lintAux)))
						If ldblVlr2 <> 0 Then lintQtd = lintQtd + 1
						ldblVlr3 = CDbl(IIf(.get_TextMatrix(llngRow - 3, lintAux) = "", 0, .get_TextMatrix(llngRow - 3, lintAux)))
						If ldblVlr3 <> 0 Then lintQtd = lintQtd + 1
						If lintQtd <> 0 Then
							ldblVlrP = (ldblVlr1 + ldblVlr2 + ldblVlr3) / lintQtd
							.set_TextMatrix(llngRow, lintAux, FormatNumber(ldblVlrP, IIf(lintAux = 5, 3, 0)))
							.set_TextMatrix(llngRow, 4, .get_TextMatrix(llngRow - 1, 4))
						Else
							.set_TextMatrix(llngRow, lintAux, "")
							.set_TextMatrix(llngRow, 4, "")
						End If
						
					Next lintAux
				End If
			Next llngRow
		End With
		With Me.mfgDadosAV
			For llngRow = 1 To .Rows - 1
				If CDbl(.get_TextMatrix(llngRow, 0)) = 12 And Len(Trim(.get_TextMatrix(llngRow, 5))) = 0 Then
					For lintAux = 5 To 7
						ldblVlrP = 0
						lintQtd = 0
						ldblVlr1 = CDbl(IIf(.get_TextMatrix(llngRow - 1, lintAux) = "", 0, .get_TextMatrix(llngRow - 1, lintAux)))
						If ldblVlr1 <> 0 Then lintQtd = lintQtd + 1
						ldblVlr2 = CDbl(IIf(.get_TextMatrix(llngRow - 2, lintAux) = "", 0, .get_TextMatrix(llngRow - 2, lintAux)))
						If ldblVlr2 <> 0 Then lintQtd = lintQtd + 1
						ldblVlr3 = CDbl(IIf(.get_TextMatrix(llngRow - 3, lintAux) = "", 0, .get_TextMatrix(llngRow - 3, lintAux)))
						If ldblVlr3 <> 0 Then lintQtd = lintQtd + 1
						If lintQtd <> 0 Then
							ldblVlrP = (ldblVlr1 + ldblVlr2 + ldblVlr3) / lintQtd
							.set_TextMatrix(llngRow, lintAux, FormatNumber(ldblVlrP, IIf(lintAux = 5 Or lintAux = 6, 3, 0)))
							.set_TextMatrix(llngRow, 4, .get_TextMatrix(llngRow - 1, 4))
							.set_TextMatrix(llngRow, 8, .get_TextMatrix(llngRow - 1, 8))
						Else
							.set_TextMatrix(llngRow, lintAux, "")
							.set_TextMatrix(llngRow, 4, "")
							.set_TextMatrix(llngRow, 8, "")
						End If
					Next lintAux
				End If
			Next llngRow
		End With
		With Me.mfgDadosAA
			For llngRow = 1 To .Rows - 1
				If CDbl(.get_TextMatrix(llngRow, 0)) = 12 And Len(Trim(.get_TextMatrix(llngRow, 5))) = 0 Then
					For lintAux = 5 To 8
						ldblVlrP = 0
						lintQtd = 0
						ldblVlr1 = CDbl(IIf(.get_TextMatrix(llngRow - 1, lintAux) = "", 0, .get_TextMatrix(llngRow - 1, lintAux)))
						If ldblVlr1 <> 0 Then lintQtd = lintQtd + 1
						ldblVlr2 = CDbl(IIf(.get_TextMatrix(llngRow - 2, lintAux) = "", 0, .get_TextMatrix(llngRow - 2, lintAux)))
						If ldblVlr2 <> 0 Then lintQtd = lintQtd + 1
						ldblVlr3 = CDbl(IIf(.get_TextMatrix(llngRow - 3, lintAux) = "", 0, .get_TextMatrix(llngRow - 3, lintAux)))
						If ldblVlr3 <> 0 Then lintQtd = lintQtd + 1
						If lintQtd <> 0 Then
							ldblVlrP = (ldblVlr1 + ldblVlr2 + ldblVlr3) / lintQtd
							.set_TextMatrix(llngRow, lintAux, FormatNumber(ldblVlrP, IIf(lintAux = 5 Or lintAux = 6, 3, 0)))
							.set_TextMatrix(llngRow, 4, .get_TextMatrix(llngRow - 1, 4))
							.set_TextMatrix(llngRow, 9, .get_TextMatrix(llngRow - 1, 9))
						Else
							.set_TextMatrix(llngRow, lintAux, "")
							.set_TextMatrix(llngRow, 4, "")
							.set_TextMatrix(llngRow, 9, "")
						End If
					Next lintAux
				End If
			Next llngRow
		End With
	End Sub
	
	Private Function PegaPosGrade(ByRef amfgAux As AxMSFlexGridLib.AxMSFlexGrid, ByVal astrMes As String, ByVal astrCla As String, ByVal astrDsC As String) As Integer
		Dim llngPos As Integer
		Dim llngRow As Integer
		llngPos = 0
		With amfgAux
			'Busca a linha da grid que tem a informacao
			For llngRow = 1 To .Rows - 1
				If .get_TextMatrix(llngRow, 1) = astrMes And .get_TextMatrix(llngRow, 2) = astrCla And .get_TextMatrix(llngRow, 3) = astrDsC Then
					llngPos = llngRow
					llngRow = .Rows - 1
				End If
			Next llngRow
		End With
		PegaPosGrade = llngPos
	End Function
	
	
	Private Sub AdicionaGradeB(ByVal astrMes As String, ByVal astrCla As String, ByVal astrDsC As String, ByVal adblkWh As Double, ByVal astrOrd As String)
		Dim llngMes As Integer
		Dim llngRow As Integer
		Dim llngPos As Integer
		Dim ldteAux As Date
		llngPos = 0
		With Me.mfgDadosB
			'Busca a linha da grid que tem a informacao
			llngPos = PegaPosGrade((Me.mfgDadosB), astrMes, astrCla, astrDsC)
			If llngPos = 0 Then
				llngMes = 1
				'UPGRADE_WARNING: Couldn't resolve default property of object Me.dtpInicio.value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				ldteAux = Me.dtpInicio.value
				While ldteAux <= Me.dtpFim.value
					.Rows = .Rows + 1
					llngPos = (.Rows - 1)
					.set_TextMatrix(llngPos, 0, llngMes)
					.set_TextMatrix(llngPos, 1, VB6.Format(ldteAux, "mm/yyyy"))
					.set_TextMatrix(llngPos, 2, astrCla)
					.set_TextMatrix(llngPos, 3, astrDsC)
					.set_TextMatrix(llngPos, 6, astrOrd & VB6.Format(llngMes, "00"))
					llngMes = llngMes + 1
					ldteAux = System.Date.FromOADate(CDate(VB6.Format(ldteAux, "yyyy-mm") & "-" & UltimoDiaMes(Month(ldteAux), Year(ldteAux))).ToOADate + 1)
				End While
				llngPos = PegaPosGrade((Me.mfgDadosB), astrMes, astrCla, astrDsC)
			End If
			.set_TextMatrix(llngPos, 4, FormatNumber(CInt(IIf(.get_TextMatrix(llngPos, 4) = "", 0, .get_TextMatrix(llngPos, 4))) + 1, 0))
			.set_TextMatrix(llngPos, 5, FormatNumber(CDbl(IIf(.get_TextMatrix(llngPos, 5) = "", 0, .get_TextMatrix(llngPos, 5))) + adblkWh, 3))
		End With
		System.Windows.Forms.Application.DoEvents()
	End Sub
	
	Private Sub AdicionaGradeAC(ByVal astrMes As String, ByVal astrCla As String, ByVal astrDsC As String, ByVal adblkWh As Double, ByVal adblkW As Double)
		Dim llngMes As Integer
		Dim llngRow As Integer
		Dim llngPos As Integer
		Dim ldteAux As Date
		llngPos = 0
		With Me.mfgDadosAC
			'Busca a linha da grid que tem a informacao
			llngPos = PegaPosGrade((Me.mfgDadosAC), astrMes, astrCla, astrDsC)
			If llngPos = 0 Then
				llngMes = 1
				'UPGRADE_WARNING: Couldn't resolve default property of object Me.dtpInicio.value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				ldteAux = Me.dtpInicio.value
				While ldteAux <= Me.dtpFim.value
					.Rows = .Rows + 1
					llngPos = (.Rows - 1)
					.set_TextMatrix(llngPos, 0, llngMes)
					.set_TextMatrix(llngPos, 1, VB6.Format(ldteAux, "mm/yyyy"))
					.set_TextMatrix(llngPos, 2, astrCla)
					.set_TextMatrix(llngPos, 3, astrDsC)
					llngMes = llngMes + 1
					ldteAux = System.Date.FromOADate(CDate(VB6.Format(ldteAux, "yyyy-mm") & "-" & UltimoDiaMes(Month(ldteAux), Year(ldteAux))).ToOADate + 1)
				End While
				llngPos = PegaPosGrade((Me.mfgDadosAC), astrMes, astrCla, astrDsC)
			End If
			.set_TextMatrix(llngPos, 4, FormatNumber(CInt(IIf(.get_TextMatrix(llngPos, 4) = "", 0, .get_TextMatrix(llngPos, 4))) + 1, 0))
			.set_TextMatrix(llngPos, 5, FormatNumber(CDbl(IIf(.get_TextMatrix(llngPos, 5) = "", 0, .get_TextMatrix(llngPos, 5))) + adblkWh, 3))
			.set_TextMatrix(llngPos, 6, FormatNumber(CDbl(IIf(.get_TextMatrix(llngPos, 6) = "", 0, .get_TextMatrix(llngPos, 6))) + adblkW, 5))
		End With
	End Sub
	
	Private Sub AdicionaGradeAV(ByVal astrMes As String, ByVal astrCla As String, ByVal astrDsC As String, ByVal adblkWhp As Double, ByVal adblkWhf As Double, ByVal adblkWf As Double, ByVal ablnSec As Boolean)
		Dim llngMes As Integer
		Dim llngRow As Integer
		Dim llngPos As Integer
		Dim ldteAux As Date
		llngPos = 0
		With Me.mfgDadosAV
			'Busca a linha da grid que tem a informacao
			llngPos = PegaPosGrade((Me.mfgDadosAV), astrMes, astrCla, astrDsC)
			If llngPos = 0 Then
				llngMes = 1
				'UPGRADE_WARNING: Couldn't resolve default property of object Me.dtpInicio.value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				ldteAux = Me.dtpInicio.value
				While ldteAux <= Me.dtpFim.value
					.Rows = .Rows + 1
					llngPos = (.Rows - 1)
					.set_TextMatrix(llngPos, 0, llngMes)
					.set_TextMatrix(llngPos, 1, VB6.Format(ldteAux, "mm/yyyy"))
					.set_TextMatrix(llngPos, 2, astrCla)
					.set_TextMatrix(llngPos, 3, astrDsC)
					llngMes = llngMes + 1
					ldteAux = System.Date.FromOADate(CDate(VB6.Format(ldteAux, "yyyy-mm") & "-" & UltimoDiaMes(Month(ldteAux), Year(ldteAux))).ToOADate + 1)
				End While
				llngPos = PegaPosGrade((Me.mfgDadosAV), astrMes, astrCla, astrDsC)
			End If
			.set_TextMatrix(llngPos, 4, FormatNumber(CInt(IIf(.get_TextMatrix(llngPos, 4) = "", 0, .get_TextMatrix(llngPos, 4))) + 1, 0))
			.set_TextMatrix(llngPos, 5, FormatNumber(CDbl(IIf(.get_TextMatrix(llngPos, 5) = "", 0, .get_TextMatrix(llngPos, 5))) + adblkWhp, 3))
			.set_TextMatrix(llngPos, 6, FormatNumber(CDbl(IIf(.get_TextMatrix(llngPos, 6) = "", 0, .get_TextMatrix(llngPos, 6))) + adblkWhf, 3))
			.set_TextMatrix(llngPos, 7, FormatNumber(CDbl(IIf(.get_TextMatrix(llngPos, 7) = "", 0, .get_TextMatrix(llngPos, 7))) + adblkWf, 5))
			.set_TextMatrix(llngPos, 8, IIf(ablnSec, "SECA", "ÚMIDA"))
		End With
	End Sub
	
	Private Sub AdicionaGradeAA(ByVal astrMes As String, ByVal astrCla As String, ByVal astrDsC As String, ByVal adblkWhp As Double, ByVal adblkWhf As Double, ByVal adblkWp As Double, ByVal adblkWf As Double, ByVal ablnSec As Boolean)
		Dim llngMes As Integer
		Dim llngRow As Integer
		Dim llngPos As Integer
		Dim ldteAux As Date
		llngPos = 0
		With Me.mfgDadosAA
			'Busca a linha da grid que tem a informacao
			llngPos = PegaPosGrade((Me.mfgDadosAA), astrMes, astrCla, astrDsC)
			If llngPos = 0 Then
				llngMes = 1
				'UPGRADE_WARNING: Couldn't resolve default property of object Me.dtpInicio.value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				ldteAux = Me.dtpInicio.value
				While ldteAux <= Me.dtpFim.value
					.Rows = .Rows + 1
					llngPos = (.Rows - 1)
					.set_TextMatrix(llngPos, 0, llngMes)
					.set_TextMatrix(llngPos, 1, VB6.Format(ldteAux, "mm/yyyy"))
					.set_TextMatrix(llngPos, 2, astrCla)
					.set_TextMatrix(llngPos, 3, astrDsC)
					llngMes = llngMes + 1
					ldteAux = System.Date.FromOADate(CDate(VB6.Format(ldteAux, "yyyy-mm") & "-" & UltimoDiaMes(Month(ldteAux), Year(ldteAux))).ToOADate + 1)
				End While
				llngPos = PegaPosGrade((Me.mfgDadosAA), astrMes, astrCla, astrDsC)
			End If
			.set_TextMatrix(llngPos, 4, FormatNumber(CInt(IIf(.get_TextMatrix(llngPos, 4) = "", 0, .get_TextMatrix(llngPos, 4))) + 1, 0))
			.set_TextMatrix(llngPos, 5, FormatNumber(CDbl(IIf(.get_TextMatrix(llngPos, 5) = "", 0, .get_TextMatrix(llngPos, 5))) + adblkWhp, 3))
			.set_TextMatrix(llngPos, 6, FormatNumber(CDbl(IIf(.get_TextMatrix(llngPos, 6) = "", 0, .get_TextMatrix(llngPos, 6))) + adblkWhf, 3))
			.set_TextMatrix(llngPos, 7, FormatNumber(CDbl(IIf(.get_TextMatrix(llngPos, 7) = "", 0, .get_TextMatrix(llngPos, 7))) + adblkWp, 5))
			.set_TextMatrix(llngPos, 8, FormatNumber(CDbl(IIf(.get_TextMatrix(llngPos, 8) = "", 0, .get_TextMatrix(llngPos, 8))) + adblkWf, 5))
			.set_TextMatrix(llngPos, 9, IIf(ablnSec, "SECA", "ÚMIDA"))
		End With
	End Sub
	
	Private Function BuscaClasse(ByVal astrCod As String) As String
		Dim lstrAux As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrAux = ""
		lstrSql = ""
		lstrSql = lstrSql & "SELECT descricao FROM classe WHERE codigo = '" & astrCod & "' "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State > 0 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"'
					lstrAux = IIf(IsDbNull(.Fields("descricao").value), "", .Fields("descricao").value)
				End If
			End If
		End With
		BuscaClasse = lstrAux
	End Function
	
	Private Sub cmdSalvarArq_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSalvarArq.Click
		With Me.cmdSalvarArq
			Me.Enabled = False
			frmDir.frmQuemChama = Me
			frmDir.intTipo = 0
			Call frmDir.SetBounds(VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(Me.Left) + VB6.PixelsToTwipsX(.Left) + 400), VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(Me.Top) + VB6.PixelsToTwipsY(.Top) + 400), 0, 0, Windows.Forms.BoundsSpecified.X Or Windows.Forms.BoundsSpecified.Y)
			Call frmDir.Show()
		End With
	End Sub
	
	Private Sub dtpFim_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles dtpFim.ClickEvent
		Me.dtpFim.value = CDate("01/" & VB6.Format(Me.dtpFim.value, "mm/yyyy"))
	End Sub
	
	Private Sub dtpInicio_ClickEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles dtpInicio.ClickEvent
		Me.dtpInicio.value = CDate("01/" & VB6.Format(Me.dtpInicio.value, "mm/yyyy"))
	End Sub
	
	Private Sub frmRelGtf_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		If KeyAscii = System.Windows.Forms.Keys.Escape Then
			Call Me.Close()
		ElseIf KeyAscii = System.Windows.Forms.Keys.Return Then 
			Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub frmRelGtf_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Dim lstrFaixa As String
		Dim lintTamLs As Short
		Dim lstrDir As String
		Call CenterForm(Me)
		'Resindencial Baixa Renda
		lstrFaixa = Trim(LeConfig("DIVISAO_BAIXARENDA_GTF"))
		If lstrFaixa = "-1" Then
			lstrFaixa = "30;100;220;999999;"
			Call CriaParConfig("DIVISAO_BAIXARENDA_GTF", lstrFaixa, True, "Limites de consumo residencial baixa renda para montagem listagem do GTF")
		End If
		If My.Application.Info.Version.Major & My.Application.Info.Version.Minor & My.Application.Info.Version.Revision = "09862" Then
			lstrFaixa = "30;100;200;999999;"
			Call GravaConfig("DIVISAO_BAIXARENDA_GTF", lstrFaixa)
		End If
		lintTamLs = Len(lstrFaixa)
		If lintTamLs <> 0 Then
			Call MontaFaixas(lstrFaixa, Me.mfgFxBxRenda)
		End If
		'Resindencial Normal
		lstrFaixa = Trim(LeConfig("DIVISAO_RESIDENCIALNORMAL_GTF"))
		If lstrFaixa = "-1" Then
			lstrFaixa = "30;100;200;300;400;500;1000;999999;"
			Call CriaParConfig("DIVISAO_RESIDENCIALNORMAL_GTF", lstrFaixa, True, "Limites de consumo residencial normal para montagem listagem do GTF")
		End If
		lintTamLs = Len(lstrFaixa)
		If lintTamLs <> 0 Then
			Call MontaFaixas(lstrFaixa, Me.mfgFxResidencial)
		End If
		Me.dtpFim.value = BuscaDataBD
		'UPGRADE_WARNING: Couldn't resolve default property of object Me.dtpFim.value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
		Me.dtpInicio.value = Me.dtpFim.value
		iintMesSeco = Val(LeConfig("MES_INI_PERIODO_SECO"))
		ifrmRelGtf = New FrmRelatorio
		Call MontaGrades()
		
		lstrDir = Trim(LeConfig("DIR_GTF"))
		If lstrDir = "-1" Then
			lstrDir = My.Application.Info.DirectoryPath
			Call CriaParConfig("DIR_GTF", Replace(lstrDir, "\", "\\"), True, "Local do arquivo para montagem listagem da GTF")
		End If
		Me.txtDir.Text = lstrDir
	End Sub
	
	Private Sub MontaFaixas(ByVal astrFaixa As String, ByVal amfgAux As AxMSFlexGridLib.AxMSFlexGrid)
		Dim intPos1 As Short
		Dim intPos2 As Short
		Dim lngIni As Integer
		Dim lngFim As Integer
		
		With amfgAux
			.Redraw = False
			Call .Clear()
			Call .AddItem("")
			.Rows = 0
			lngIni = 0
			lngFim = 0
			intPos1 = 1
			intPos2 = 0
			While intPos1 <= Len(astrFaixa)
				intPos2 = InStr(intPos1, astrFaixa, ";")
				lngFim = Val(Mid(astrFaixa, intPos1, intPos2 - intPos1))
				.Rows = .Rows + 1
				.set_TextMatrix(.Rows - 1, 0, lngIni)
				.set_TextMatrix(.Rows - 1, 1, lngFim)
				If lngIni < lngFim Then
					lngIni = lngFim + 1
				End If
				intPos1 = intPos2 + 1
			End While
			.Redraw = True
		End With
	End Sub
	
	Private Sub MontaGrades()
		With Me.mfgDadosB
			Call .Clear()
			.Rows = 1
			.set_TextMatrix(0, 0, "Męs")
			.set_TextMatrix(0, 1, "Ref")
			.set_TextMatrix(0, 2, "Classe")
			.set_TextMatrix(0, 3, "Sub-Classe")
			.set_TextMatrix(0, 4, "Qtde")
			.set_TextMatrix(0, 5, "MWh")
			.set_TextMatrix(0, 6, "Ord")
			.set_ColWidth(0, 375)
			.set_ColWidth(1, 735)
			.set_ColWidth(2, 1455)
			.set_ColWidth(3, 4100)
			.set_ColWidth(4, 720)
			.set_ColWidth(5, 1300)
			.set_ColWidth(6, 0)
		End With
		With Me.mfgDadosAC
			Call .Clear()
			.Rows = 1
			.set_TextMatrix(0, 0, "Męs")
			.set_TextMatrix(0, 1, "Ref")
			.set_TextMatrix(0, 2, "Classe")
			.set_TextMatrix(0, 3, "Sub-Classe")
			.set_TextMatrix(0, 4, "Qtde")
			.set_TextMatrix(0, 5, "MWh")
			.set_TextMatrix(0, 6, "kW")
			.set_ColWidth(0, 375)
			.set_ColWidth(1, 735)
			.set_ColWidth(2, 1455)
			.set_ColWidth(3, 4100)
			.set_ColWidth(4, 720)
			.set_ColWidth(5, 1300)
			.set_ColWidth(6, 1300)
		End With
		With Me.mfgDadosAV
			Call .Clear()
			.Rows = 1
			.set_TextMatrix(0, 0, "Męs")
			.set_TextMatrix(0, 1, "Ref")
			.set_TextMatrix(0, 2, "Classe")
			.set_TextMatrix(0, 3, "Sub-Classe")
			.set_TextMatrix(0, 4, "Qtde")
			.set_TextMatrix(0, 5, "MWh P")
			.set_TextMatrix(0, 6, "MWh Fp")
			.set_TextMatrix(0, 7, "kW")
			.set_TextMatrix(0, 8, "Tipo")
			.set_ColWidth(0, 375)
			.set_ColWidth(1, 735)
			.set_ColWidth(2, 1455)
			.set_ColWidth(3, 4100)
			.set_ColWidth(4, 720)
			.set_ColWidth(5, 1300)
			.set_ColWidth(6, 1300)
			.set_ColWidth(7, 1300)
			.set_ColWidth(8, 1000)
		End With
		With Me.mfgDadosAA
			Call .Clear()
			.Rows = 1
			.set_TextMatrix(0, 0, "Męs")
			.set_TextMatrix(0, 1, "Ref")
			.set_TextMatrix(0, 2, "Classe")
			.set_TextMatrix(0, 3, "Sub-Classe")
			.set_TextMatrix(0, 4, "Qtde")
			.set_TextMatrix(0, 5, "MWh P")
			.set_TextMatrix(0, 6, "MWh Fp")
			.set_TextMatrix(0, 7, "kW P")
			.set_TextMatrix(0, 8, "kW Fp")
			.set_TextMatrix(0, 9, "Tipo")
			.set_ColWidth(0, 375)
			.set_ColWidth(1, 735)
			.set_ColWidth(2, 1455)
			.set_ColWidth(3, 4100)
			.set_ColWidth(4, 720)
			.set_ColWidth(5, 1300)
			.set_ColWidth(6, 1300)
			.set_ColWidth(7, 1300)
			.set_ColWidth(8, 1300)
			.set_ColWidth(9, 1000)
		End With
	End Sub
End Class