Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class FrmRelConsumBaixaRenda
	Inherits System.Windows.Forms.Form
	Dim fr As New FrmRelatorio
	
	Private Sub BtCancel_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles BtCancel.Click
		Me.Close()
	End Sub
	
	Private Sub BtEmitir_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles BtEmitir.Click
		Call RelNormal((cOpcao.SelectedIndex))
	End Sub
	
	Private Sub FrmRelConsumBaixaRenda_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		cOpcao.SelectedIndex = 0
		cOrdem.SelectedIndex = 0
		txtMesAno.Text = LeConfig("MESANOFATURAMENTO")
	End Sub
	
	Private Sub RelNormal(ByRef Filtro As Short)
		Dim strSql As String
		Dim strTemp As String
		Dim strTamCol As String
		Dim rsConsulta As New ADODB.Recordset
		
		strSql = "SELECT u.zona, u.livro, u.conta, n.codclas, u.end, u.cons_id, u.rota, u.nome " & "  FROM unidb u, nf n "
		
		If Filtro = 0 Then
			strSql = strSql & " WHERE (LEFT(n.codclas,1) = 9 AND RIGHT(n.codclas,2) <> '01') "
		ElseIf Filtro = 1 Then 
			strSql = strSql & " WHERE n.codclas = '9104' "
		ElseIf Filtro = 2 Then 
			strSql = strSql & " WHERE n.codclas = '9106' "
		ElseIf Filtro = 3 Then 
			strSql = strSql & " WHERE n.codclas = '9102' "
		ElseIf Filtro = 4 Then 
			strSql = strSql & " WHERE n.codclas = '9105' "
		End If
		
		strSql = strSql & " AND u.zona = n.zona " & " AND u.livro = n.livro " & " AND u.conta = n.conta " & " AND n.mesano = """ & txtMesAno.Text & """ "
		
		If cOrdem.SelectedIndex = 0 Then
			strSql = strSql & " ORDER BY u.zona ASC, u.livro ASC, u.conta ASC"
		ElseIf cOrdem.SelectedIndex = 1 Then 
			strSql = strSql & " ORDER BY u.nome ASC"
		Else
			strSql = strSql & " ORDER BY LEFT(u.rota,4) ASC, RIGHT(u.rota,4) ASC"
		End If
		
		Call Conectar(strSql, rsConsulta)
		
		If rsConsulta.RecordCount > 0 Then
			Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, rsConsulta.RecordCount)
			strTamCol = "<27mm|<20mm|<65mm|<65mm|<15mm;"
			fr.quem_chama = Me
			
			fr.VS.Font = VB6.FontChangeName(fr.VS.Font, "Arial")
			fr.VS.Font = VB6.FontChangeSize(fr.VS.Font, 8)
			fr.VS.TableBorder = VSVIEW6.TableBorderSettings.tbNone
			fr.VS.PageBorder = VSVIEW6.TableBorderSettings.tbNone
			fr.VS.Orientation = VSVIEW6.OrientationSettings.orPortrait
			fr.VS.PhysicalPage = True
			fr.VS.PaperSize = VSVIEW6.PaperSizeSettings.pprA4
			fr.VS.MarginTop = "7mm"
			fr.VS.MarginRight = "7mm"
			fr.VS.MarginLeft = "7mm"
			fr.VS.MarginBottom = "5mm"
			fr.VS.TextColor = System.Drawing.Color.Black
			fr.VS.BrushStyle = VSVIEW6.BrushStyleSettings.bsSolid
			fr.VS.Font = VB6.FontChangeBold(fr.VS.Font, False)
			Call fr.VS.StartDoc()
			
			While Not rsConsulta.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"'
				strTemp = VB6.Format(rsConsulta.Fields("Zona").Value, "000") & "." & VB6.Format(rsConsulta.Fields("Livro").Value, "00") & "." & VB6.Format(rsConsulta.Fields("Conta").Value, "000000") & "|" & VB6.Format(rsConsulta.Fields("Rota").Value, "00000000") & "|" & VB.Left(IIf(IsDbNull(rsConsulta.Fields("nome").Value), "", rsConsulta.Fields("nome").Value), 34) & "|" & IIf(IsDbNull(rsConsulta.Fields("End").Value), "", rsConsulta.Fields("End").Value) & "|" & IIf(IsDbNull(rsConsulta.Fields("codclas").Value), "", rsConsulta.Fields("codclas").Value)
				fr.VS.Table = strTamCol & strTemp
				
				Call rsConsulta.MoveNext()
				Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
				System.Windows.Forms.Application.DoEvents()
			End While
			
			Call LineFeed((fr.VS), 2)
			fr.VS.Font = VB6.FontChangeBold(fr.VS.Font, True)
			If rsConsulta.RecordCount > 0 Then
				fr.VS.Table = "<50mm|<75mm|<20mm;" & "|" & "Total de consumidores baixa renda:" & "|" & rsConsulta.RecordCount
			End If
			Call fr.VS.EndDoc()
			Call fr.Show()
		Else
			Call MsgBox("Não existem consumidores nesta classe!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
		End If
		If rsConsulta.State = 1 Then Call rsConsulta.Close()
	End Sub
	
	Public Function CabecaRel() As Object
		Call Cabecalho_Relatorio((fr.VS), "Relatório de Consumidores Baixa Renda", "", "2", False, "")
		Call LineFeed((fr.VS), 1)
		fr.VS.Font = VB6.FontChangeSize(fr.VS.Font, 8)
		fr.VS.Font = VB6.FontChangeBold(fr.VS.Font, True)
		fr.VS.Table = "^27mm|^20mm|^65mm|^65mm|^15mm;" & "IDENTIFICAÇÃO" & "|" & "ROTA" & "|" & "NOME" & "|" & "ENDEREÇO" & "|" & "CLASSE"
		fr.VS.Font = VB6.FontChangeBold(fr.VS.Font, False)
	End Function
End Class