Option Strict Off
Option Explicit On
Friend Class frmCadCodigosMovtoMedidor
	Inherits System.Windows.Forms.Form
	
	Private Sub cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click
		Call Me.Close()
	End Sub
	
	Private Sub cmdSalvar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSalvar.Click
		Dim lintAux As Short
		Dim lstrSql As String
		With Me.lsvCodigos
			For lintAux = 2 To .Items.Count
				lstrSql = ""
				lstrSql = lstrSql & "UPDATE `codigos` "
				'UPGRADE_WARNING: Lower bound of collection Me.lsvCodigos.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"'
				'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"'
				lstrSql = lstrSql & "   SET `flgmedidor` = '" & IIf(.Items.Item(lintAux).Checked, "S", "N") & "' "
				'UPGRADE_WARNING: Lower bound of collection Me.lsvCodigos.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"'
				lstrSql = lstrSql & " WHERE `num` = '" & .Items.Item(lintAux).Text & "' "
				Call Executar(lstrSql)
			Next lintAux
		End With
	End Sub
	
	Private Sub frmCadCodigosMovtoMedidor_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Call CenterForm(Me)
		Call MontaLista()
	End Sub
	
	Private Sub MontaLista()
		Dim lstrCod As String
		Dim lstrDes As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		With Me.lsvCodigos
			Call .Items.Clear()
			Call .Columns.Clear()
			If .Columns.Count <= 1 Then
				Call .Columns.Add("Código", CInt(VB6.TwipsToPixelsX(1300)), System.Windows.Forms.HorizontalAlignment.Left)
				Call .Columns.Add("Descrição", CInt(VB6.TwipsToPixelsX(4000)), System.Windows.Forms.HorizontalAlignment.Left)
			End If
			Call .Items.Add("")
			'UPGRADE_WARNING: Lower bound of collection Me.lsvCodigos.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("Marcar/Desmarcar todos")
		End With
		lstrSql = ""
		lstrSql = lstrSql & "SELECT `num`, `descri` "
		lstrSql = lstrSql & "  FROM `codigos` "
		lstrSql = lstrSql & " WHERE (`num` BETWEEN '9040000000' AND '9040999999' OR "
		lstrSql = lstrSql & "        `num` BETWEEN '9050000000' AND '9050999999') "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					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"'
						lstrCod = Trim(IIf(IsDbNull(.Fields("num").value), "", .Fields("num").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"'
						lstrDes = Trim(IIf(IsDbNull(.Fields("descri").value), "", .Fields("descri").value))
						With Me.lsvCodigos
							Call .Items.Add(lstrCod)
							'UPGRADE_WARNING: Lower bound of collection Me.lsvCodigos.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(lstrDes)
						End With
						Call .MoveNext()
					End While
				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
	End Sub
	
	Private Sub lsvCodigos_ItemCheck(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.ItemCheckEventArgs) Handles lsvCodigos.ItemCheck
		Dim aListItem As System.Windows.Forms.ListViewItem = lsvCodigos.Items(eventArgs.Index)
		Dim lintLinhas As Short
		With Me.lsvCodigos
			If aListItem.Text = "" Then
				'UPGRADE_WARNING: Lower bound of collection Me.lsvCodigos.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(1).Checked = True Then
					For lintLinhas = 2 To .Items.Count
						'UPGRADE_WARNING: Lower bound of collection Me.lsvCodigos.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(lintLinhas).Checked = True
					Next lintLinhas
					'UPGRADE_WARNING: Lower bound of collection Me.lsvCodigos.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"'
				ElseIf .Items.Item(1).Checked = False Then 
					For lintLinhas = 1 To .Items.Count
						'UPGRADE_WARNING: Lower bound of collection Me.lsvCodigos.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(lintLinhas).Checked = False
					Next lintLinhas
				End If
			Else
				If aListItem.Checked = False Then
					'UPGRADE_WARNING: Lower bound of collection Me.lsvCodigos.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(1).Checked = False
				End If
			End If
		End With
	End Sub
End Class