Option Strict Off
Option Explicit On
Friend Class frmRelExtratoConsumidor
	Inherits System.Windows.Forms.Form
	Private ifrmLocalizaUnidade As frmLocalizaUnidade
	
	Private Sub cmdBuscar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdBuscar.Click
		Dim lstrGrupo As String
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim llngUnidId As Integer
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
		Call LigDes(False)
		With Me.lsvFiltros
			Call .Items.Clear()
			Call .Columns.Clear()
			If .Columns.Count <= 1 Then
				Call .Columns.Add("", "Grupo", CInt(VB6.TwipsToPixelsX(650)))
				Call .Columns.Add("", "Identificador", CInt(VB6.TwipsToPixelsX(1300)))
				Call .Columns.Add("", "Código", CInt(VB6.TwipsToPixelsX(0)))
			End If
		End With
		lstrSql = ""
		lstrSql = lstrSql & "SELECT DISTINCT `grupo`, `zona`, `livro`, `conta`, `unid_id` "
		lstrSql = lstrSql & "  FROM " & gstrDataBase & ".`nf` "
		lstrSql = lstrSql & " WHERE `cons_id` = " & CInt(IIf(IsNumeric(Me.txtConsId.Text), Me.txtConsId.Text, 0)) & " "
		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"'
						lstrGrupo = 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"'
						lstrZona = IIf(IsDbNull(.Fields("zona").value), "", .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"'
						lstrLivro = IIf(IsDbNull(.Fields("livro").value), "", .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"'
						lstrConta = IIf(IsDbNull(.Fields("conta").value), "", .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"'
						llngUnidId = IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").value)
						With Me.lsvFiltros
							Call .Items.Add(lstrGrupo)
							'UPGRADE_WARNING: Lower bound of collection Me.lsvFiltros.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
							Call .Items.Item(.Items.Count).SubItems.Add(lstrZona & "." & lstrLivro & "." & lstrConta)
							'UPGRADE_WARNING: Lower bound of collection Me.lsvFiltros.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
							Call .Items.Item(.Items.Count).SubItems.Add(CStr(llngUnidId))
						End With
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
					End While
				End If
				Call .Close()
			End If
		End With
		Call LigDes(True)
		Me.Cursor = System.Windows.Forms.Cursors.Default
		'UPGRADE_WARNING: Lower bound of collection Me.lsvFiltros.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
		If Me.lsvFiltros.Items.Count > 0 Then Me.lsvFiltros.Items.Item(1).Checked = True
		'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 cmdLocalizar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLocalizar.Click
		Call LigDes(False)
		Call ifrmLocalizaUnidade.Show()
		Call ifrmLocalizaUnidade.SetaLocalizaUnidade("C", Me)
		Call LigDes(True)
	End Sub
	
	Private Sub frmRelExtratoConsumidor_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		ifrmLocalizaUnidade = New frmLocalizaUnidade
	End Sub
	
	Private Sub frmRelExtratoConsumidor_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		'UPGRADE_NOTE: Object ifrmLocalizaUnidade 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"'
		ifrmLocalizaUnidade = Nothing
	End Sub
	
	Private Sub lsvFiltros_ItemCheck(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.ItemCheckEventArgs) Handles lsvFiltros.ItemCheck
		Dim aItem As System.Windows.Forms.ListViewItem = lsvFiltros.Items(eventArgs.Index)
		Dim lintIdx As Short
		With Me.lsvFiltros
			For lintIdx = 1 To .Items.Count
				If aItem.Checked Then
					If aItem.Index <> lintIdx Then
						'UPGRADE_WARNING: Lower bound of collection Me.lsvFiltros.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
						If .Items.Item(lintIdx).Checked Then
							'UPGRADE_WARNING: Lower bound of collection Me.lsvFiltros.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
							.Items.Item(lintIdx).Checked = False
						End If
						'UPGRADE_WARNING: Lower bound of collection Me.lsvFiltros.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
						If .Items.Item(lintIdx).Selected Then
							'UPGRADE_WARNING: Lower bound of collection Me.lsvFiltros.ListItems has changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A3B628A0-A810-4AE2-BFA2-9E7A29EB9AD0"'
							.Items.Item(lintIdx).Selected = False
						End If
					End If
				End If
			Next lintIdx
		End With
		aItem.Selected = True
	End Sub
	
	Public Sub SetaCodigo(ByVal alngCodigo As Integer, ByVal astrZona As String, ByVal astrLivro As String, ByVal astrConta As String, ByVal astrGrupo As String)
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM " & gstrDataBase & ".`consum` "
		lstrSql = lstrSql & " WHERE `consreg` = " & alngCodigo
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					'UPGRADE_WARNING: Use of Null/IsNull() detected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="2EED02CB-5C0E-4DC1-AE94-4FAA3A30F51A"'
					Me.txtNome.Text = IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").value)
					Me.txtConsId.Text = CStr(alngCodigo)
				Else
					Me.txtNome.Text = ""
					Me.txtConsId.Text = ""
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstAux may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
		lrstAux = Nothing
		Call Me.lsvFiltros.Items.Clear()
	End Sub
	
	Private Sub LigDes(ByVal ablnModo As Boolean)
		Me.cmdLocalizar.Enabled = ablnModo
		Me.cmdImprimir.Enabled = ablnModo
		Me.cmdFechar.Enabled = ablnModo
		Me.cmdBuscar.Enabled = ablnModo
		Me.lsvFiltros.Enabled = ablnModo
	End Sub
End Class