Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmRelSubvencaoServicoPublico
	Inherits System.Windows.Forms.Form
	Private ifrmRelSubvencaoServPub As FrmRelatorio
	Private istrTamCol As String
	
	Private Sub cmdArquivo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdArquivo.Click
		Me.dialArqOpen.DefaultExt = "CSV"
		'UPGRADE_WARNING: Filter has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
		Me.dialArqOpen.Filter = "*." & Me.dialArqOpen.DefaultExt
		Me.dialArqOpen.FileName = My.Application.Info.DirectoryPath & "\SubvencaoServicoPublico_" & VB6.Format(BuscaDataBD, "YYYYMMDDHHNNSS") & "." & Me.dialArqOpen.DefaultExt
		Me.dialArqOpen.Title = "Arquivo de exportação do Subvenção Serviço Público"
		Me.dialArqOpen.ShowDialog()
		Me.txtArquivo.Text = Me.dialArqOpen.FileName
	End Sub
	
	Private Sub cmdExporta_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExporta.Click
		'Controle Arquivo
		Dim lstrLin As String
		Dim lintARQ As Short
		Dim llngRow As Integer
		Dim llngCol As Integer
		'Controle de Query
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		If Trim(Me.txtArquivo.Text) = "" Then
			Call MsgBox("Você deve selecionar um local e o nome do arquivo que deseja gravar!" & vbCrLf & "Ex: C:\SubvencaoServicoPublico_" & VB6.Format(BuscaDataBD, "YYYYMMDDHHNNSS") & ".CSV", MsgBoxStyle.Critical, gstrTituloMensagem)
		Else
			Call LigDes(False)
			'Export para CSV
			If Trim(Me.txtArquivo.Text) <> "" Then
				lintARQ = FreeFile
				FileOpen(lintARQ, Me.txtArquivo.Text, OpenMode.Output)
				With Me.mfgRural
					If .Rows > 1 Then
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .Rows - 1, " Gerando Arquivo ")
						For llngRow = 0 To .Rows - 1
							lstrLin = ""
							For llngCol = 0 To .Cols - 2
								lstrLin = lstrLin & .get_TextMatrix(llngRow, llngCol) & ";"
							Next llngCol
							PrintLine(lintARQ, lstrLin)
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , " Gerando Arquivo ")
						Next llngRow
					End If
				End With
				FileClose(lintARQ)
				Call MsgBox("Arquivo gerado com sucesso!", MsgBoxStyle.Information, gstrTituloMensagem)
			Else
				Call MsgBox("Você precisa selecionar o caminho e o arquivo para exportação!", MsgBoxStyle.Information, gstrTituloMensagem)
			End If
			Call LigDes(True)
		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
		Dim lstrTab As String
		Dim llngRow As Integer
		Dim llngCol As Integer
		istrTamCol = "<0mm|^25mm|>50mm|>50mm|>50mm|>50mm|>50mm|>0mm;|"
		With ifrmRelSubvencaoServPub
			.quem_chama = Me
			.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)
			.VS.StartDoc()
			.VS.CurrentLine = 0
			.VS.Font = VB6.FontChangeSize(.VS.Font, 9)
			Call Cabecalho_Relatorio(.VS, "Relatório de Subvenção Serviço Público", "Período: " & VB6.Format(Me.dtpMesAno(0).value, "MM/YYYY") & " até " & VB6.Format(Me.dtpMesAno(1).value, "MM/YYYY"), "3")
			.VS.Font = VB6.FontChangeBold(.VS.Font, True)
			Call LineFeed(.VS, 2)
			.VS.TableBorder = VSVIEW6.TableBorderSettings.tbAll
			With Me.mfgDados
				lstrTab = ""
				For llngCol = 0 To .Cols - 1
					lstrTab = lstrTab & .get_TextMatrix(0, llngCol) & IIf(llngCol < .Cols - 1, "|", "")
				Next llngCol
			End With
			.VS.Table = istrTamCol & lstrTab
			.VS.Font = VB6.FontChangeBold(.VS.Font, False)
		End With
		With Me.mfgDados
			For llngRow = 1 To .Rows - 1
				lstrTab = ""
				For llngCol = 0 To .Cols - 1
					lstrTab = lstrTab & .get_TextMatrix(llngRow, llngCol) & IIf(llngCol < .Cols - 1, "|", "")
				Next llngCol
				ifrmRelSubvencaoServPub.VS.Table = istrTamCol & lstrTab
			Next llngRow
		End With
		With ifrmRelSubvencaoServPub
			.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
			Call .VS.EndDoc()
			Call VB6.ShowForm(ifrmRelSubvencaoServPub, False)
		End With
	End Sub
	
	Private Sub cmdProcessar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdProcessar.Click
		Dim lstrIdent As String
		Dim lstrNomeC As String
		Dim lstrClass As String
		Dim lstrDsCla As String
		Dim ldblNumNF As Double
		Dim lstrMesAn As String
		Dim llngMARef As Integer
		Dim ldteEmiss As Date
		Dim ldteApres As Date
		Dim ldteVecto As Date
		Dim ldteLeAtu As Date
		Dim ldteLeAnt As Date
		Dim lstrGrupo As String
		Dim lstrItens As String
		Dim ldblQtkWh As Double
		Dim ldblVlkWh As Double
		Dim ldblTarif As Double
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
		Call MontaGrade()
		Call LigDes(False)
		Me.lblInfo.Text = " Buscando os dados das faturas. Aguarde..."
		Call Me.lblInfo.Refresh()
		'UPGRADE_WARNING: Couldn't resolve default property of object Me.dtpMesAno(1).value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
		'UPGRADE_WARNING: Couldn't resolve default property of object Me.dtpMesAno(0).value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
		If Me.dtpMesAno(0).value > Me.dtpMesAno(1).value Then
			Call MsgBox("O período final não pode ser menor que o período inicial!", MsgBoxStyle.Critical, gstrTituloMensagem)
		Else
			Me.mfgRural.Redraw = False
			lstrSql = ""
			lstrSql = lstrSql & "SELECT `nf`.`zona`, "
			lstrSql = lstrSql & "       `nf`.`livro`, "
			lstrSql = lstrSql & "       `nf`.`conta`, "
			lstrSql = lstrSql & "       `nf`.`cons_id`, "
			lstrSql = lstrSql & "       `nf`.`unid_id`, "
			lstrSql = lstrSql & "       IFNULL(IFNULL(`unida`.`nome`,`unidb`.`nome`),`consum`.`nome`) `nome_consumidor`, "
			lstrSql = lstrSql & "       `nf`.`codclas`, "
			lstrSql = lstrSql & "       `classe`.`descricao` `descricao_classe`, "
			lstrSql = lstrSql & "       `nf`.`numnf`, "
			lstrSql = lstrSql & "       `nf`.`mesano`, "
			lstrSql = lstrSql & "       `nf`.`mesano_ref`, "
			lstrSql = lstrSql & "       `nf`.`dataem`, "
			lstrSql = lstrSql & "       `nf`.`dataapr`, "
			lstrSql = lstrSql & "       `nf`.`datavenc`, "
			lstrSql = lstrSql & "       `nf`.`dataleit`, "
			lstrSql = lstrSql & "       `nf`.`dataleitant`, "
			lstrSql = lstrSql & "       `nf`.`grupo`, "
			lstrSql = lstrSql & "       `nf`.`itensserv` "
			lstrSql = lstrSql & "  FROM `nf` "
			lstrSql = lstrSql & " LEFT JOIN `unida` ON(`unida`.`cons_id` = `nf`.`cons_id` AND `unida`.`unid_id` = `nf`.`unid_id` AND `nf`.`grupo` = 'A') "
			lstrSql = lstrSql & " LEFT JOIN `unidb` ON(`unidb`.`cons_id` = `nf`.`cons_id` AND `unidb`.`unid_id` = `nf`.`unid_id` AND `nf`.`grupo` = 'B') "
			lstrSql = lstrSql & " LEFT JOIN `consum` ON(`consum`.`consreg` = `nf`.`cons_id`) "
			lstrSql = lstrSql & " LEFT JOIN `classe` ON(`classe`.`codigo` = `nf`.`codclas`) "
			lstrSql = lstrSql & " WHERE (`nf`.`mesano_ref` BETWEEN " & CInt(VB6.Format(Me.dtpMesAno(0).value, "YYYYMM"))
			lstrSql = lstrSql & "                              AND " & CInt(VB6.Format(Me.dtpMesAno(1).value, "YYYYMM")) & ")"
			lstrSql = lstrSql & "   AND `nf`.`grupo` = 'B' "
			lstrSql = lstrSql & "   AND (`nf`.`codclas` BETWEEN '7000' AND '7999') "
			Call Conectar(lstrSql, lrstAux)
			With lrstAux
				If .State = ADODB.ObjectStateEnum.adStateOpen Then
					If .RecordCount > 0 Then
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount)
						While Not .EOF
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							'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"'
							lstrIdent = Trim(IIf(IsDbNull(.Fields("zona").value), "000", .Fields("zona").value))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							'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"'
							lstrIdent = lstrIdent & "." & Trim(IIf(IsDbNull(.Fields("livro").value), "00", .Fields("livro").value))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							'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"'
							lstrIdent = lstrIdent & "." & Trim(IIf(IsDbNull(.Fields("conta").value), "000000", .Fields("conta").value))
							'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
							'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"'
							lstrNomeC = Trim(IIf(IsDbNull(.Fields("nome_consumidor").value), "sem nome", .Fields("nome_consumidor").value))
							'UPGRADE_WARNING: 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"'
							lstrClass = Trim(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"'
							'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"'
							lstrDsCla = Trim(IIf(IsDbNull(.Fields("descricao_classe").value), "0000", .Fields("descricao_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"'
							ldblNumNF = CDbl(IIf(IsDbNull(.Fields("numnf").value), "0", .Fields("numnf").value))
							'UPGRADE_WARNING: 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"'
							lstrMesAn = Trim(IIf(IsDbNull(.Fields("mesano").value), "00/0000", .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"'
							'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"'
							llngMARef = CInt(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"'
							'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"'
							ldteEmiss = CDate(IIf(IsDbNull(.Fields("dataem").value), "1900-01-01", .Fields("dataem").value))
							'UPGRADE_WARNING: 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"'
							ldteApres = CDate(IIf(IsDbNull(.Fields("dataapr").value), "1900-01-01", .Fields("dataapr").value))
							'UPGRADE_WARNING: 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"'
							ldteVecto = CDate(IIf(IsDbNull(.Fields("datavenc").value), "1900-01-01", .Fields("datavenc").value))
							'UPGRADE_WARNING: 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"'
							ldteLeAtu = CDate(IIf(IsDbNull(.Fields("dataleit").value), "1900-01-01", .Fields("dataleit").value))
							'UPGRADE_WARNING: 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"'
							ldteLeAnt = 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"'
							'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"'
							lstrGrupo = Trim(IIf(IsDbNull(.Fields("grupo").value), "B", .Fields("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"'
							'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"'
							lstrItens = Trim(IIf(IsDbNull(.Fields("itensserv").value), "", .Fields("itensserv").value))
							ldblQtkWh = BuscaVlrItem(lstrItens, "030201009")
							ldblVlkWh = BuscaVlrItem(lstrItens, "030202009")
							ldblTarif = TarifaProporcional(ldteLeAnt, ldteLeAtu, "01B3201101", 3) 'Tarifa Serviço Público
							With Me.mfgRural
								.Rows = .Rows + 1
								.set_TextMatrix(.Rows - 1, 0, lstrIdent)
								.set_TextMatrix(.Rows - 1, 1, lstrNomeC)
								.set_TextMatrix(.Rows - 1, 2, lstrClass)
								.set_TextMatrix(.Rows - 1, 3, lstrDsCla)
								.set_TextMatrix(.Rows - 1, 4, VB6.Format(ldblNumNF, "#,##0"))
								.set_TextMatrix(.Rows - 1, 5, lstrMesAn)
								.set_TextMatrix(.Rows - 1, 6, llngMARef)
								.set_TextMatrix(.Rows - 1, 7, VB6.Format(ldteEmiss, "DD/MM/YYYY"))
								.set_TextMatrix(.Rows - 1, 8, VB6.Format(ldteApres, "DD/MM/YYYY"))
								.set_TextMatrix(.Rows - 1, 9, VB6.Format(ldteVecto, "DD/MM/YYYY"))
								.set_TextMatrix(.Rows - 1, 10, VB6.Format(ldteLeAtu, "DD/MM/YYYY"))
								.set_TextMatrix(.Rows - 1, 11, VB6.Format(ldteLeAnt, "DD/MM/YYYY"))
								.set_TextMatrix(.Rows - 1, 12, lstrGrupo)
								.set_TextMatrix(.Rows - 1, 13, VB6.Format(ldblQtkWh, "#,##0"))
								.set_TextMatrix(.Rows - 1, 14, VB6.Format(Arredondar(ldblTarif - (ldblTarif * (15 / 100)), 5), "#,##0.00")) 'Tarifa com 15%
								.set_TextMatrix(.Rows - 1, 15, VB6.Format(ldblVlkWh, "#,##0.00"))
								.set_TextMatrix(.Rows - 1, 16, VB6.Format(ldblTarif, "#,##0.00")) 'Tarifa cheia
								.set_TextMatrix(.Rows - 1, 17, VB6.Format(Truncate(ldblQtkWh * (ldblTarif / 1000), 2), "#,##0.00"))
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(Information.IsNumeric(Me.mfgRural.TextMatrix(Me.mfgRural.Rows - 1, 17)), Me.mfgRural.TextMatrix(Me.mfgRural.Rows - 1, 17), 0). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
								.set_TextMatrix(.Rows - 1, 18, IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 15)), .get_TextMatrix(.Rows - 1, 15), 0) - IIf(IsNumeric(.get_TextMatrix(.Rows - 1, 17)), .get_TextMatrix(.Rows - 1, 17), 0))
								.set_TextMatrix(.Rows - 1, 19, llngMARef & VB6.Format(ldblNumNF, New String("0", 9)))
							End With
							Call .MoveNext()
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
						End While
					End If
					Call .Close()
				End If
			End With
			With Me.mfgRural
				.Col = 19
				.Sort = MSFlexGridLib.SortSettings.flexSortNumericAscending
				.Redraw = True
			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 TotalizaGrade()
		End If
		Call LigDes(True)
		Me.Cursor = System.Windows.Forms.Cursors.Default
	End Sub
	
	Private Sub TotalizaGrade()
		Dim llngRo1 As Integer
		Dim llngRo2 As Integer
		Dim llngAux As Integer
		Dim llngTQtdCo As Integer
		Dim lstrMesAno As String
		Dim ldblQtekWh As Double
		Dim ldblRurkWh As Double
		Dim ldblReskWh As Double
		Dim ldblDifkWh As Double
		Me.mfgDados.Redraw = False
		With Me.mfgRural
			For llngRo1 = 1 To .Rows - 1
				lstrMesAno = Trim(.get_TextMatrix(llngRo1, 5))
				'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"'
				ldblQtekWh = CDbl(IIf(IsNumeric(.get_TextMatrix(llngRo1, 13)), .get_TextMatrix(llngRo1, 13), 0))
				'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"'
				ldblRurkWh = CDbl(IIf(IsNumeric(.get_TextMatrix(llngRo1, 15)), .get_TextMatrix(llngRo1, 15), 0))
				'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"'
				ldblReskWh = CDbl(IIf(IsNumeric(.get_TextMatrix(llngRo1, 17)), .get_TextMatrix(llngRo1, 17), 0))
				'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"'
				ldblDifkWh = CDbl(IIf(IsNumeric(.get_TextMatrix(llngRo1, 18)), .get_TextMatrix(llngRo1, 18), 0))
				With Me.mfgDados
					If .Rows > 1 Then
						For llngRo2 = 1 To .Rows - 1
							If Trim(.get_TextMatrix(llngRo2, 0)) = lstrMesAno Then
								llngAux = llngRo2
								llngRo2 = .Rows - 1
							Else
								llngAux = 0
							End If
						Next llngRo2
					Else
						.Rows = .Rows + 1
						llngAux = .Rows - 1
						.set_TextMatrix(llngAux, 0, lstrMesAno)
						.set_TextMatrix(llngAux, 6, CInt(VB.Right(lstrMesAno, 4) & VB.Left(lstrMesAno, 2)))
					End If
					If llngAux = 0 Then
						.Rows = .Rows + 1
						llngAux = .Rows - 1
						.set_TextMatrix(llngAux, 0, lstrMesAno)
						.set_TextMatrix(llngAux, 6, CInt(VB.Right(lstrMesAno, 4) & VB.Left(lstrMesAno, 2)))
					End If
					'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					.set_TextMatrix(llngAux, 1, VB6.Format(CShort(IIf(IsNumeric(.get_TextMatrix(llngAux, 1)), .get_TextMatrix(llngAux, 1), 0)) + 1, "#,##0")) 'Qtde de Consumidores
					'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					.set_TextMatrix(llngAux, 2, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(llngAux, 2)), .get_TextMatrix(llngAux, 2), 0)) + ldblQtekWh, "#,##0"))
					'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					.set_TextMatrix(llngAux, 3, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(llngAux, 3)), .get_TextMatrix(llngAux, 3), 0)) + ldblRurkWh, "#,##0.00"))
					'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					.set_TextMatrix(llngAux, 4, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(llngAux, 4)), .get_TextMatrix(llngAux, 4), 0)) + ldblReskWh, "#,##0.00"))
					'UPGRADE_WARNING: Couldn't resolve default property of object Interaction.IIf(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					.set_TextMatrix(llngAux, 5, VB6.Format(CDbl(IIf(IsNumeric(.get_TextMatrix(llngAux, 5)), .get_TextMatrix(llngAux, 5), 0)) + ldblDifkWh, "#,##0.00"))
				End With
			Next llngRo1
		End With
		llngTQtdCo = 0
		ldblQtekWh = 0
		ldblRurkWh = 0
		ldblReskWh = 0
		ldblDifkWh = 0
		With Me.mfgDados
			If .Rows > 1 Then
				For llngRo1 = 1 To .Rows - 1
					'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"'
					llngTQtdCo = llngTQtdCo + CInt(IIf(IsNumeric(.get_TextMatrix(llngRo1, 1)), .get_TextMatrix(llngRo1, 1), 0))
					'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"'
					ldblQtekWh = ldblQtekWh + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRo1, 2)), .get_TextMatrix(llngRo1, 2), 0))
					'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"'
					ldblRurkWh = ldblRurkWh + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRo1, 3)), .get_TextMatrix(llngRo1, 3), 0))
					'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"'
					ldblReskWh = ldblReskWh + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRo1, 4)), .get_TextMatrix(llngRo1, 4), 0))
					'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"'
					ldblDifkWh = ldblDifkWh + CDbl(IIf(IsNumeric(.get_TextMatrix(llngRo1, 5)), .get_TextMatrix(llngRo1, 5), 0))
				Next llngRo1
				.Rows = .Rows + 1
				.set_TextMatrix(.Rows - 1, 0, "Total")
				.set_TextMatrix(.Rows - 1, 1, VB6.Format(llngTQtdCo, "#,##0"))
				.set_TextMatrix(.Rows - 1, 2, VB6.Format(ldblQtekWh, "#,##0"))
				.set_TextMatrix(.Rows - 1, 3, VB6.Format(ldblRurkWh, "#,##0.00"))
				.set_TextMatrix(.Rows - 1, 4, VB6.Format(ldblReskWh, "#,##0.00"))
				.set_TextMatrix(.Rows - 1, 5, VB6.Format(ldblDifkWh, "#,##0.00"))
				.set_TextMatrix(.Rows - 1, 6, 999999)
			End If
			.Col = 6
			.Sort = MSFlexGridLib.SortSettings.flexSortNumericAscending
		End With
		Me.mfgDados.Redraw = True
	End Sub
	
	Private Sub MontaGrade()
		With Me.mfgRural
			.Rows = 1
			Call .Clear()
			.Redraw = False
			.set_TextMatrix(0, 0, "Identificador")
			.set_ColWidth(0, 1200)
			.set_ColAlignment(0, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_TextMatrix(0, 1, "Nome")
			.set_ColWidth(1, 3000)
			.set_ColAlignment(1, MSFlexGridLib.AlignmentSettings.flexAlignLeftCenter)
			.set_TextMatrix(0, 2, "Classe")
			.set_ColWidth(2, 550)
			.set_ColAlignment(2, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_TextMatrix(0, 3, "Descrição")
			.set_ColWidth(3, 3000)
			.set_ColAlignment(3, MSFlexGridLib.AlignmentSettings.flexAlignLeftCenter)
			.set_TextMatrix(0, 4, "Fatura")
			.set_ColWidth(4, 800)
			.set_ColAlignment(4, MSFlexGridLib.AlignmentSettings.flexAlignRightCenter)
			.set_TextMatrix(0, 5, "Referência")
			.set_ColWidth(5, 900)
			.set_ColAlignment(5, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_TextMatrix(0, 6, "Mês/Ano")
			.set_ColWidth(6, 700)
			.set_ColAlignment(6, MSFlexGridLib.AlignmentSettings.flexAlignRightCenter)
			.set_TextMatrix(0, 7, "Emissão")
			.set_ColWidth(7, 1000)
			.set_ColAlignment(7, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_TextMatrix(0, 8, "Apresentação")
			.set_ColWidth(8, 1080)
			.set_ColAlignment(8, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_TextMatrix(0, 9, "Vencimento")
			.set_ColWidth(9, 1000)
			.set_ColAlignment(9, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_TextMatrix(0, 10, "Leit.Atual")
			.set_ColWidth(10, 1000)
			.set_ColAlignment(10, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_TextMatrix(0, 11, "Leit.Anter.")
			.set_ColWidth(11, 1000)
			.set_ColAlignment(11, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_TextMatrix(0, 12, "Grupo")
			.set_ColWidth(12, 550)
			.set_ColAlignment(12, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_TextMatrix(0, 13, "Qtde kWh")
			.set_ColWidth(13, 1000)
			.set_ColAlignment(13, MSFlexGridLib.AlignmentSettings.flexAlignRightCenter)
			.set_TextMatrix(0, 14, "Tarifa 15%")
			.set_ColWidth(14, 1000)
			.set_ColAlignment(14, MSFlexGridLib.AlignmentSettings.flexAlignRightCenter)
			.set_TextMatrix(0, 15, "Valor kWh")
			.set_ColWidth(15, 1000)
			.set_ColAlignment(15, MSFlexGridLib.AlignmentSettings.flexAlignRightCenter)
			.set_TextMatrix(0, 16, "Tarifa")
			.set_ColWidth(16, 1000)
			.set_ColAlignment(16, MSFlexGridLib.AlignmentSettings.flexAlignRightCenter)
			.set_TextMatrix(0, 17, "Valor kWh")
			.set_ColWidth(17, 1000)
			.set_ColAlignment(17, MSFlexGridLib.AlignmentSettings.flexAlignRightCenter)
			.set_TextMatrix(0, 18, "Diferença")
			.set_ColWidth(18, 1000)
			.set_ColAlignment(18, MSFlexGridLib.AlignmentSettings.flexAlignRightCenter)
			.set_TextMatrix(0, 19, "Ordena")
			.set_ColWidth(19, 0)
			.Redraw = True
		End With
		With Me.mfgDados
			.Rows = 1
			Call .Clear()
			.set_TextMatrix(0, 0, "Faturamento")
			.set_ColWidth(0, 1100)
			.set_ColAlignment(0, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_TextMatrix(0, 1, "Qtde. Consumidores")
			.set_ColWidth(1, 1600)
			.set_ColAlignment(1, MSFlexGridLib.AlignmentSettings.flexAlignRightCenter)
			.set_TextMatrix(0, 2, "Qtde. kWh")
			.set_ColWidth(2, 1600)
			.set_ColAlignment(2, MSFlexGridLib.AlignmentSettings.flexAlignRightCenter)
			.set_TextMatrix(0, 3, "Valor 15%")
			.set_ColWidth(3, 1600)
			.set_ColAlignment(3, MSFlexGridLib.AlignmentSettings.flexAlignRightCenter)
			.set_TextMatrix(0, 4, "Valor Cheio")
			.set_ColWidth(4, 1600)
			.set_ColAlignment(4, MSFlexGridLib.AlignmentSettings.flexAlignRightCenter)
			.set_TextMatrix(0, 5, "Diferença")
			.set_ColWidth(5, 1600)
			.set_ColAlignment(5, MSFlexGridLib.AlignmentSettings.flexAlignRightCenter)
			.set_TextMatrix(0, 6, "Ordem")
			.set_ColWidth(6, 0)
		End With
	End Sub
	
	Private Sub frmRelSubvencaoServicoPublico_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 cmdFechar_Click(cmdFechar, New System.EventArgs())
		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 frmRelSubvencaoServicoPublico_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		ifrmRelSubvencaoServPub = New FrmRelatorio
		Call CenterForm(Me)
		Call MontaGrade()
		Me.dtpMesAno(0).value = BuscaDataBD
		'UPGRADE_WARNING: Couldn't resolve default property of object Me.dtpMesAno().value. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
		Me.dtpMesAno(1).value = Me.dtpMesAno(0).value
	End Sub
	
	Private Sub LigDes(ByVal ablnModo As Boolean)
		Me.cmdExporta.Enabled = ablnModo
		Me.cmdFechar.Enabled = ablnModo
		Me.cmdImprimir.Enabled = ablnModo
		Me.cmdProcessar.Enabled = ablnModo
		Me.dtpMesAno(0).Enabled = ablnModo
		Me.dtpMesAno(1).Enabled = ablnModo
	End Sub
	
	Private Sub frmRelSubvencaoServicoPublico_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		'UPGRADE_NOTE: Object ifrmRelSubvencaoServPub 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"'
		ifrmRelSubvencaoServPub = Nothing
	End Sub
End Class