Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmRelLactoCvTxDv
	Inherits System.Windows.Forms.Form
	
	'UPGRADE_WARNING: Event cmbTipos.SelectedIndexChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub cmbTipos_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmbTipos.SelectedIndexChanged
		If VB6.GetItemString(Me.cmbTipos, Me.cmbTipos.SelectedIndex) <> "(nenhum)" Then
			Me.txtNomeSelecao.Text = VB6.GetItemString(Me.cmbTipos, Me.cmbTipos.SelectedIndex)
		End If
	End Sub
	
	Private Sub cmdAdiciona_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdAdiciona.Click
		Dim llngConta As Integer
		Dim lstrCodigo As String
		Dim lstrDescri As String
		Dim lblnAdiciona As Boolean
		
		lblnAdiciona = True
		lstrCodigo = Me.lvwTipos.FocusedItem.Text
		'UPGRADE_WARNING: Lower bound of collection Me.lvwTipos.SelectedItem.ListSubItems 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"'
		lstrDescri = Me.lvwTipos.FocusedItem.SubItems.Item(1).Text
		With Me.lvwSelecao
			If .Items.Count > 0 Then
				For llngConta = 1 To .Items.Count
					'UPGRADE_WARNING: Lower bound of collection Me.lvwSelecao.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(llngConta).Text = lstrCodigo Then
						lblnAdiciona = False
					End If
				Next llngConta
			End If
			If lblnAdiciona Then
				Call .Items.Add(lstrCodigo)
				'UPGRADE_WARNING: Lower bound of collection Me.lvwSelecao.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(lstrDescri)
			End If
		End With
	End Sub
	
	Private Sub cmdAdTodos_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdAdTodos.Click
		Dim llngConta As Integer
		Dim lstrCodigo As String
		Dim lstrDescri As String
		With Me.lvwTipos
			If .Items.Count > 0 Then
				For llngConta = 1 To .Items.Count
					'UPGRADE_WARNING: Lower bound of collection Me.lvwTipos.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"'
					lstrCodigo = .Items.Item(llngConta).Text
					'UPGRADE_WARNING: Lower bound of collection Me.lvwTipos.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: Lower bound of collection Me.lvwTipos.ListItems.Item() 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"'
					lstrDescri = .Items.Item(llngConta).SubItems(1).Text
					With Me.lvwSelecao
						Call .Items.Add(lstrCodigo)
						'UPGRADE_WARNING: Lower bound of collection Me.lvwSelecao.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(lstrDescri)
					End With
				Next llngConta
			End If
		End With
	End Sub
	
	Private Sub cmdCarregar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCarregar.Click
		Dim lstrSql As String
		Dim lrstConsulta As ADODB.Recordset
		Dim lstrCodigo As String
		Dim lstrDescri As String
		
		lrstConsulta = New ADODB.Recordset
		With Me.lvwSelecao
			Call .Items.Clear()
			If .Columns.Count <= 1 Then
				Call .Columns.Add("", "Código", CInt(VB6.TwipsToPixelsX(1000)))
				Call .Columns.Add("", "Descrição", CInt(VB6.TwipsToPixelsX(3500)))
			End If
		End With
		If VB6.GetItemString(Me.cmbTipos, Me.cmbTipos.SelectedIndex) <> "(nenhum)" Then
			lstrSql = ""
			lstrSql = lstrSql & "SELECT `sel_lanctoscvdvtx`.`codigo`, " & vbCrLf
			lstrSql = lstrSql & "       `codigos`.`descri` " & vbCrLf
			lstrSql = lstrSql & "  FROM `sel_lanctoscvdvtx`  " & vbCrLf
			lstrSql = lstrSql & "  LEFT JOIN `codigos` ON(`codigos`.`num` = `sel_lanctoscvdvtx`.`codigo`) " & vbCrLf
			lstrSql = lstrSql & " WHERE `sel_lanctoscvdvtx`.`descricao` = '" & VB6.GetItemString(Me.cmbTipos, Me.cmbTipos.SelectedIndex) & "' " & vbCrLf
			lstrSql = lstrSql & " ORDER BY `codigo` ASC "
			Call Conectar(lstrSql, lrstConsulta)
			With lrstConsulta
				If .State > 0 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"'
							lstrCodigo = IIf(IsDbNull(.Fields("codigo").value), "0", .Fields("codigo").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"'
							lstrDescri = IIf(IsDbNull(.Fields("descri").value), "", .Fields("descri").value)
							With Me.lvwSelecao
								Call .Items.Add(lstrCodigo)
								'UPGRADE_WARNING: Lower bound of collection Me.lvwSelecao.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(lstrDescri)
							End With
							Call .MoveNext()
						End While
					End If
					Call .Close()
				End If
			End With
			Me.txtNomeSelecao.Text = VB6.GetItemString(Me.cmbTipos, Me.cmbTipos.SelectedIndex)
		Else
			Me.txtNomeSelecao.Text = ""
		End If
		'UPGRADE_NOTE: Object lrstConsulta 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"'
		lrstConsulta = Nothing
	End Sub
	
	Private Sub cmdEmitir_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdEmitir.Click
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim lstrNomeA As String
		Dim lstrNomeB As String
		Dim lstrCodigo As String
		Dim lstrDescri As String
		Dim ldblValor As Double
		Dim llngConta As Integer
		Dim ldteIni As Date
		Dim ldteFim As Date
		Dim lstrRef As String
		Dim lstrCriterio As String
		Dim lblnConvenios As Boolean
		Dim lblnTaxas As Boolean
		Dim lstrAux As String
		Dim lstrSql As String
		Dim lrstConsulta As ADODB.Recordset
		lrstConsulta = New ADODB.Recordset
		lblnConvenios = False
		lblnTaxas = False
		'Cria a tabela temp caso ainda nao exista no banco de dados
		Me.lblInfo.Text = " Aguarde criando tabela auxiliar... "
		Call Me.lblInfo.Refresh()
		lstrSql = ""
		lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS `temp_lanctoscvdvtx`    (" & vbCrLf
		lstrSql = lstrSql & "   `nomemaquina` varchar(255) default '000',        " & vbCrLf
		lstrSql = lstrSql & "   `zona`        varchar(3)   default '000',        " & vbCrLf
		lstrSql = lstrSql & "   `livro`       varchar(2)   default '00',         " & vbCrLf
		lstrSql = lstrSql & "   `conta`       varchar(6)   default '000000',     " & vbCrLf
		lstrSql = lstrSql & "   `nome`        varchar(85)  default '',           " & vbCrLf
		lstrSql = lstrSql & "   `endcompleto` varchar(85)  default '',           " & vbCrLf
		lstrSql = lstrSql & "   `codigo`      varchar(10)  default '000000000',  " & vbCrLf
		lstrSql = lstrSql & "   `descri`      varchar(180) default '',           " & vbCrLf
		lstrSql = lstrSql & "   `ref`         varchar(200) default '',           " & vbCrLf
		lstrSql = lstrSql & "   `valor`       double(12,2) default '0.00',       " & vbCrLf
		lstrSql = lstrSql & "   `dt_ini`      date         default '0000-00-00', " & vbCrLf
		lstrSql = lstrSql & "   `dt_fim`      date         default '0000-00-00'  " & vbCrLf
		lstrSql = lstrSql & " )"
		Call Executar(lstrSql)
		'Limpa a tabela temp conforme o nome da maquina conectada
		Me.lblInfo.Text = " Aguarde limpando tabela auxiliar... "
		Call Me.lblInfo.Refresh()
		lstrSql = "DELETE FROM temp_lanctoscvdvtx WHERE nomemaquina = """ & gstrNmEstacao & """ "
		Call Executar(lstrSql)
		'Seleciona os convenios e diversos
		Me.lblInfo.Text = " Aguarde selecionado convênios e diversos... "
		Call Me.lblInfo.Refresh()
		lstrSql = ""
		lstrSql = lstrSql & "SELECT " & vbCrLf
		lstrSql = lstrSql & "       `convenios`.`zona`,     " & vbCrLf
		lstrSql = lstrSql & "       `convenios`.`livro`,    " & vbCrLf
		lstrSql = lstrSql & "       `convenios`.`conta`,    " & vbCrLf
		lstrSql = lstrSql & "       `unida`.`nome` AS `nma`," & vbCrLf
		lstrSql = lstrSql & "       `unidb`.`nome` AS `nmb`," & vbCrLf
		lstrSql = lstrSql & "       `convenios`.`convenio`, " & vbCrLf
		lstrSql = lstrSql & "       `codigos`.`descri`,     " & vbCrLf
		lstrSql = lstrSql & "       `convenios`.`valor`,    " & vbCrLf
		lstrSql = lstrSql & "       `convenios`.`dt_ini`,   " & vbCrLf
		lstrSql = lstrSql & "       `convenios`.`dt_fim`,   " & vbCrLf
		lstrSql = lstrSql & "       `convenios`.`ref`       " & vbCrLf
		lstrSql = lstrSql & "  FROM `convenios` " & vbCrLf
		lstrSql = lstrSql & "        LEFT JOIN `unida` ON(`unida`.`zona` = `convenios`.`zona` AND `unida`.`livro` = `convenios`.`livro` AND `unida`.`conta` = `convenios`.`conta`) " & vbCrLf
		lstrSql = lstrSql & "        LEFT JOIN `unidb` ON(`unidb`.`zona` = `convenios`.`zona` AND `unidb`.`livro` = `convenios`.`livro` AND `unidb`.`conta` = `convenios`.`conta`) " & vbCrLf
		lstrSql = lstrSql & "        LEFT JOIN `codigos` ON(`codigos`.`num` = `convenios`.`convenio`) " & vbCrLf
		lstrSql = lstrSql & " WHERE ((`convenios`.`dt_ini` >= '" & VB6.Format(Me.dtpInicial.value, "yyyy-MM-dd") & "' AND " & vbCrLf
		lstrSql = lstrSql & "         `convenios`.`dt_ini` <= '" & VB6.Format(Me.dtpFinal.value, "yyyy-MM-dd") & "') OR " & vbCrLf
		lstrSql = lstrSql & "        (`convenios`.`dt_fim` >= '" & VB6.Format(Me.dtpInicial.value, "yyyy-MM-dd") & "' AND " & vbCrLf
		lstrSql = lstrSql & "         `convenios`.`dt_fim` <= '" & VB6.Format(Me.dtpFinal.value, "yyyy-MM-dd") & "') OR " & vbCrLf
		lstrSql = lstrSql & "        (`convenios`.`dt_ini` <= '" & VB6.Format(Me.dtpInicial.value, "yyyy-MM-dd") & "' AND " & vbCrLf
		lstrSql = lstrSql & "         `convenios`.`dt_fim` >= '" & VB6.Format(Me.dtpFinal.value, "yyyy-MM-dd") & "')) " & vbCrLf
		
		lstrAux = ""
		With Me.lvwSelecao
			If .Items.Count > 0 Then
				For llngConta = 1 To .Items.Count
					'UPGRADE_WARNING: Lower bound of collection Me.lvwSelecao.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 VB.Left(.Items.Item(llngConta).Text, 4) <> "9040" Then
						'UPGRADE_WARNING: Lower bound of collection Me.lvwSelecao.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"'
						lstrAux = lstrAux & "'" & .Items.Item(llngConta).Text & "',"
						lblnConvenios = True
					End If
				Next llngConta
			End If
		End With
		If Len(Trim(lstrAux)) > 0 Then
			lstrSql = lstrSql & "   AND `convenios`.`convenio` IN(" & VB.Left(lstrAux, Len(lstrAux) - 1) & ") "
		End If
		If lblnConvenios Then
			Call Conectar(lstrSql, lrstConsulta)
			With lrstConsulta
				If .State > 0 Then
					If .RecordCount > 0 Then
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount, "Convênios")
						lstrSql = "INSERT INTO temp_lanctoscvdvtx(`nomemaquina`, `zona`, `livro`, `conta`, `nome`, `codigo`, `descri`, `ref`, `valor`, `dt_ini`, `dt_fim`) VALUES " & vbCrLf
						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"'
							lstrZona = Trim(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 = Trim(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 = Trim(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"'
							lstrNomeA = Trim(IIf(IsDbNull(.Fields("nma").value), "", .Fields("nma").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"'
							lstrNomeB = Trim(IIf(IsDbNull(.Fields("nmb").value), "", .Fields("nmb").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"'
							lstrCodigo = Trim(IIf(IsDbNull(.Fields("convenio").value), "", .Fields("convenio").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"'
							lstrDescri = Trim(IIf(IsDbNull(.Fields("descri").value), "", .Fields("descri").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"'
							ldblValor = CDbl(IIf(IsDbNull(.Fields("valor").value), "0", .Fields("valor").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"'
							ldteIni = CDate(IIf(IsDbNull(.Fields("dt_ini").value), "1900-01-01", .Fields("dt_ini").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"'
							ldteFim = CDate(IIf(IsDbNull(.Fields("dt_fim").value), "1900-01-01", .Fields("dt_fim").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"'
							lstrRef = Trim(IIf(IsDbNull(.Fields("ref").value), "", .Fields("ref").value))
							lstrSql = lstrSql & " (""" & gstrNmEstacao & """, "
							lstrSql = lstrSql & " """ & lstrZona & """, "
							lstrSql = lstrSql & " """ & lstrLivro & """, "
							lstrSql = lstrSql & " """ & lstrConta & """, "
							lstrSql = lstrSql & " """ & IIf(lstrNomeB = "", lstrNomeA, lstrNomeB) & """, "
							lstrSql = lstrSql & " """ & lstrCodigo & """, "
							lstrSql = lstrSql & " """ & lstrDescri & """, "
							lstrSql = lstrSql & " """ & lstrRef & """, "
							lstrSql = lstrSql & " """ & Replace(CStr(ldblValor), ",", ".") & """, "
							lstrSql = lstrSql & " """ & VB6.Format(ldteIni, "yyyy-MM-dd") & """, "
							lstrSql = lstrSql & " """ & VB6.Format(ldteFim, "yyyy-MM-dd") & """), " & vbCrLf
							Call .MoveNext()
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , "Convênios")
						End While
						Call Executar(VB.Left(lstrSql, Len(lstrSql) - 4))
					Else
						lblnConvenios = False
					End If
					Call .Close()
				End If
			End With
		End If
		'Seleciona as taxas
		Me.lblInfo.Text = " Aguarde selecionado taxas... "
		Call Me.lblInfo.Refresh()
		lstrSql = ""
		lstrSql = lstrSql & "SELECT "
		lstrSql = lstrSql & "       `taxas`.`zona`,     " & vbCrLf
		lstrSql = lstrSql & "       `taxas`.`livro`,    " & vbCrLf
		lstrSql = lstrSql & "       `taxas`.`conta`,    " & vbCrLf
		lstrSql = lstrSql & "       `unida`.`nome` AS `nma`," & vbCrLf
		lstrSql = lstrSql & "       `unidb`.`nome` AS `nmb`," & vbCrLf
		lstrSql = lstrSql & "       `taxas`.`codigo`,   " & vbCrLf
		lstrSql = lstrSql & "       `codigos`.`descri`, " & vbCrLf
		lstrSql = lstrSql & "       `taxas`.`valor`,    " & vbCrLf
		lstrSql = lstrSql & "       `taxas`.`dt_ini`,   " & vbCrLf
		lstrSql = lstrSql & "       `taxas`.`dt_fim`,   " & vbCrLf
		lstrSql = lstrSql & "       `taxas`.`ref`       " & vbCrLf
		lstrSql = lstrSql & "  FROM `taxas` "
		lstrSql = lstrSql & "        LEFT JOIN `unida` ON(`unida`.`zona` = `taxas`.`zona` AND `unida`.`livro` = `taxas`.`livro` AND `unida`.`conta` = `taxas`.`conta`) "
		lstrSql = lstrSql & "        LEFT JOIN `unidb` ON(`unidb`.`zona` = `taxas`.`zona` AND `unidb`.`livro` = `taxas`.`livro` AND `unidb`.`conta` = `taxas`.`conta`) "
		lstrSql = lstrSql & "        LEFT JOIN `codigos` ON(`codigos`.`num` = `taxas`.`codigo`) "
		lstrSql = lstrSql & " WHERE ((`taxas`.`dt_ini` >= '" & VB6.Format(Me.dtpInicial.value, "yyyy-MM-dd") & "' AND " & vbCrLf
		lstrSql = lstrSql & "         `taxas`.`dt_ini` <= '" & VB6.Format(Me.dtpFinal.value, "yyyy-MM-dd") & "') OR " & vbCrLf
		lstrSql = lstrSql & "        (`taxas`.`dt_fim` >= '" & VB6.Format(Me.dtpInicial.value, "yyyy-MM-dd") & "' AND " & vbCrLf
		lstrSql = lstrSql & "         `taxas`.`dt_fim` <= '" & VB6.Format(Me.dtpFinal.value, "yyyy-MM-dd") & "') OR " & vbCrLf
		lstrSql = lstrSql & "        (`taxas`.`dt_ini` <= '" & VB6.Format(Me.dtpInicial.value, "yyyy-MM-dd") & "' AND " & vbCrLf
		lstrSql = lstrSql & "         `taxas`.`dt_fim` >= '" & VB6.Format(Me.dtpFinal.value, "yyyy-MM-dd") & "')) " & vbCrLf
		
		lstrAux = ""
		With Me.lvwSelecao
			If .Items.Count > 0 Then
				For llngConta = 1 To .Items.Count
					'UPGRADE_WARNING: Lower bound of collection Me.lvwSelecao.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 VB.Left(.Items.Item(llngConta).Text, 4) = "9040" Then
						'UPGRADE_WARNING: Lower bound of collection Me.lvwSelecao.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"'
						lstrAux = lstrAux & "'" & .Items.Item(llngConta).Text & "',"
						lblnTaxas = True
					End If
				Next llngConta
			End If
		End With
		If Len(Trim(lstrAux)) > 0 Then
			lstrSql = lstrSql & " AND `taxas`.`codigo` IN(" & VB.Left(lstrAux, Len(lstrAux) - 1) & ") "
		End If
		If lblnTaxas Then
			Call Conectar(lstrSql, lrstConsulta)
			With lrstConsulta
				If .State > 0 Then
					If .RecordCount > 0 Then
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 0, .RecordCount, "Taxas")
						lstrSql = "INSERT INTO temp_lanctoscvdvtx(`nomemaquina`, `zona`, `livro`, `conta`, `nome`, `codigo`, `descri`, `ref`, `valor`, `dt_ini`, `dt_fim`) VALUES " & vbCrLf
						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"'
							lstrZona = Trim(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 = Trim(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 = Trim(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"'
							lstrNomeA = Trim(IIf(IsDbNull(.Fields("nma").value), "", .Fields("nma").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"'
							lstrNomeB = Trim(IIf(IsDbNull(.Fields("nmb").value), "", .Fields("nmb").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"'
							lstrCodigo = Trim(IIf(IsDbNull(.Fields("codigo").value), "", .Fields("codigo").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"'
							lstrDescri = Trim(IIf(IsDbNull(.Fields("descri").value), "", .Fields("descri").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"'
							ldblValor = CDbl(IIf(IsDbNull(.Fields("valor").value), "0", .Fields("valor").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"'
							ldteIni = CDate(IIf(IsDbNull(.Fields("dt_ini").value), "1900-01-01", .Fields("dt_ini").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"'
							ldteFim = CDate(IIf(IsDbNull(.Fields("dt_fim").value), "1900-01-01", .Fields("dt_fim").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"'
							lstrRef = Trim(IIf(IsDbNull(.Fields("ref").value), "", .Fields("ref").value))
							lstrSql = lstrSql & " (""" & gstrNmEstacao & """, "
							lstrSql = lstrSql & " """ & lstrZona & """, "
							lstrSql = lstrSql & " """ & lstrLivro & """, "
							lstrSql = lstrSql & " """ & lstrConta & """, "
							lstrSql = lstrSql & " """ & IIf(lstrNomeB = "", lstrNomeA, lstrNomeB) & """, "
							lstrSql = lstrSql & " """ & lstrCodigo & """, "
							lstrSql = lstrSql & " """ & lstrDescri & """, "
							lstrSql = lstrSql & " """ & lstrRef & """, "
							lstrSql = lstrSql & " """ & Replace(CStr(ldblValor), ",", ".") & """, "
							lstrSql = lstrSql & " """ & VB6.Format(ldteIni, "yyyy-MM-dd") & """, "
							lstrSql = lstrSql & " """ & VB6.Format(ldteFim, "yyyy-MM-dd") & """), " & vbCrLf
							Call .MoveNext()
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1,  , "Taxas")
						End While
						Call Executar(VB.Left(lstrSql, Len(lstrSql) - 4))
					Else
						lblnTaxas = False
					End If
					Call .Close()
				End If
			End With
		End If
		If lblnConvenios = True Or lblnTaxas = True Then
			lstrCriterio = "{temp_lanctoscvdvtx.nomemaquina} = """ & gstrNmEstacao & """ "
			With cryRelLactos
				.ReportFileName = My.Application.Info.DirectoryPath & "\" & LeConfig("DIR_RPT") & "Lancamentos.rpt"
				.DiscardSavedData = True
				.WindowState = Crystal.WindowStateConstants.crptMaximized
				.WindowControlBox = True
				.WindowControls = True
				.WindowShowPrintSetupBtn = True
				.WindowShowCloseBtn = True
				.WindowShowSearchBtn = True
				.WindowTitle = "Impressão dos Lançamentos de Convênios, Diversos e Taxas"
				.Destination = Crystal.DestinationConstants.crptToWindow
				.SelectionFormula = lstrCriterio
				.set_Formulas(1, "TituloA = ""Listagem dos lançamentos do período de " & VB6.Format(Me.dtpInicial.value, "dd/mm/yyyy") & " até " & VB6.Format(Me.dtpFinal.value, "dd/mm/yyyy") & """ ")
				.set_SortFields(0, "+{temp_lanctoscvdvtx.codigo}")
				If Me.opbNome.Checked Then
					.set_SortFields(1, "+{temp_lanctoscvdvtx.nome}")
				ElseIf Me.opbZlc.Checked Then 
					.set_SortFields(1, "+{temp_lanctoscvdvtx.zona}")
					.set_SortFields(2, "+{temp_lanctoscvdvtx.livro}")
					.set_SortFields(3, "+{temp_lanctoscvdvtx.conta}")
				Else
					.set_SortFields(1, "+{temp_lanctoscvdvtx.zona}")
					.set_SortFields(2, "+{temp_lanctoscvdvtx.livro}")
					.set_SortFields(3, "+{temp_lanctoscvdvtx.conta}")
					.set_SortFields(4, "+{temp_lanctoscvdvtx.dt_ini}")
					.set_SortFields(5, "+{temp_lanctoscvdvtx.dt_fim}")
				End If
				.Action = 0
			End With
		Else
			Call MsgBox("Não foi encontrado nenhum registro, favor verifique seus filtros e emita novamente!", MsgBoxStyle.Information, gstrTituloMensagem)
		End If
		'UPGRADE_NOTE: Object lrstConsulta 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"'
		lrstConsulta = Nothing
	End Sub
	
	Private Sub cmdExcluir_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExcluir.Click
		Dim lstrSql As String
		lstrSql = ""
		lstrSql = lstrSql & "DELETE FROM `sel_lanctoscvdvtx` " & vbCrLf
		lstrSql = lstrSql & "      WHERE `sel_lanctoscvdvtx`.`descricao` = '" & VB6.GetItemString(Me.cmbTipos, Me.cmbTipos.SelectedIndex) & "' "
		Call Executar(lstrSql)
		Call EnchePreDefinidos()
		Call cmdCarregar_Click(cmdCarregar, New System.EventArgs())
	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 cmdGravar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdGravar.Click
		Dim lstrSql As String
		Dim llngConta As Integer
		Dim lstrCodigo As String
		Dim lrstConsulta As ADODB.Recordset
		lrstConsulta = New ADODB.Recordset
		
		If Len(Trim(Me.txtNomeSelecao.Text)) = 0 Then
			Call MsgBox("É necessário informar um nome para gravar esta seleção!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
			Call Me.txtNomeSelecao.Focus()
		Else
			Me.txtNomeSelecao.Text = Replace(Me.txtNomeSelecao.Text, """", "'")
			lstrSql = lstrSql & "SELECT * " & vbCrLf
			lstrSql = lstrSql & "  FROM `sel_lanctoscvdvtx` " & vbCrLf
			lstrSql = lstrSql & " WHERE `sel_lanctoscvdvtx`.`descricao` = '" & Trim(Me.txtNomeSelecao.Text) & "' "
			Call Conectar(lstrSql, lrstConsulta)
			With lrstConsulta
				If .State > 0 Then
					If .RecordCount > 0 Then
						lstrSql = ""
						lstrSql = lstrSql & "DELETE FROM `sel_lanctoscvdvtx` " & vbCrLf
						lstrSql = lstrSql & "      WHERE `sel_lanctoscvdvtx`.`descricao` = '" & Trim(Me.txtNomeSelecao.Text) & "' "
						Call Executar(lstrSql)
					End If
					Call .Close()
				End If
			End With
			With Me.lvwSelecao
				If .Items.Count > 0 Then
					lstrSql = ""
					lstrSql = lstrSql & "INSERT INTO `sel_lanctoscvdvtx` (`descricao`,`codigo`) VALUES"
					For llngConta = 1 To .Items.Count
						'UPGRADE_WARNING: Lower bound of collection Me.lvwSelecao.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"'
						lstrCodigo = .Items.Item(llngConta).Text
						lstrSql = lstrSql & " (""" & Trim(Me.txtNomeSelecao.Text) & """, "
						lstrSql = lstrSql & "'" & lstrCodigo & "'), "
					Next llngConta
					Call Executar(VB.Left(lstrSql, Len(lstrSql) - 2))
				End If
			End With
			Call EnchePreDefinidos()
			Call cmdCarregar_Click(cmdCarregar, New System.EventArgs())
		End If
		'UPGRADE_NOTE: Object lrstConsulta 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"'
		lrstConsulta = Nothing
	End Sub
	
	Private Sub cmdLimpar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLimpar.Click
		With Me.lvwSelecao
			Call .Items.Clear()
			If .Columns.Count <= 1 Then
				Call .Columns.Add("", "Código", CInt(VB6.TwipsToPixelsX(1000)))
				Call .Columns.Add("", "Descrição", CInt(VB6.TwipsToPixelsX(3500)))
			End If
		End With
		Me.txtNomeSelecao.Text = ""
	End Sub
	
	Private Sub cmdRetira_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdRetira.Click
		With Me.lvwSelecao
			If .Items.Count > 0 Then
				.Items.RemoveAt((.FocusedItem.Index))
			End If
		End With
	End Sub
	
	Private Sub cmdReTodos_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdReTodos.Click
		With Me.lvwSelecao
			Call .Items.Clear()
			If .Columns.Count <= 1 Then
				Call .Columns.Add("", "Código", CInt(VB6.TwipsToPixelsX(1000)))
				Call .Columns.Add("", "Descrição", CInt(VB6.TwipsToPixelsX(3500)))
			End If
		End With
	End Sub
	
	Private Sub frmRelLactoCvTxDv_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Me.Icon = FrmAtPrincipal.Icon
		Call CenterForm(Me)
		Me.dtpInicial.value = CDate("01/" & VB6.Format(BuscaDataBD, "mm/yyyy"))
		Me.dtpFinal.value = CDate(VB6.Format(UltimoDiaMes((Me.dtpInicial.Month), (Me.dtpInicial.Year)), "00") & "/" & VB6.Format(Me.dtpInicial.value, "mm/yyyy"))
		Call EncheTipos()
		Call EnchePreDefinidos()
		If VB6.GetItemString(Me.cmbTipos, Me.cmbTipos.SelectedIndex) <> "(nenhum)" Then
			Call cmdCarregar_Click(cmdCarregar, New System.EventArgs())
		End If
	End Sub
	
	Private Sub frmRelLactoCvTxDv_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.Return Then
			Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
		ElseIf KeyAscii = System.Windows.Forms.Keys.Escape Then 
			Call cmdFechar_Click(cmdFechar, New System.EventArgs())
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub EncheTipos()
		Dim lstrCodigo As String
		Dim lstrDescri As String
		Dim lstrSql As String
		Dim lrstConsulta As ADODB.Recordset
		lrstConsulta = New ADODB.Recordset
		With Me.lvwTipos
			Call .Items.Clear()
			If .Columns.Count <= 1 Then
				Call .Columns.Add("", "Código", CInt(VB6.TwipsToPixelsX(1000)))
				Call .Columns.Add("", "Descrição", CInt(VB6.TwipsToPixelsX(3500)))
			End If
		End With
		With Me.lvwSelecao
			Call .Items.Clear()
			If .Columns.Count <= 1 Then
				Call .Columns.Add("", "Código", CInt(VB6.TwipsToPixelsX(1000)))
				Call .Columns.Add("", "Descrição", CInt(VB6.TwipsToPixelsX(3500)))
			End If
		End With
		lstrSql = ""
		lstrSql = lstrSql & "SELECT `codigos`.`num`, " & vbCrLf
		lstrSql = lstrSql & "       `codigos`.`descri` " & vbCrLf
		lstrSql = lstrSql & "  FROM `codigos` " & vbCrLf
		lstrSql = lstrSql & " WHERE `codigos`.`num` LIKE '9030%' " & vbCrLf
		lstrSql = lstrSql & "    OR `codigos`.`num` LIKE '9040%' " & vbCrLf
		lstrSql = lstrSql & "    OR `codigos`.`num` LIKE '9070%' " & vbCrLf
		lstrSql = lstrSql & "    OR `codigos`.`num` LIKE '9080%' " & vbCrLf
		lstrSql = lstrSql & "ORDER BY `codigos`.`num` ASC, descri ASC "
		Call Conectar(lstrSql, lrstConsulta)
		With lrstConsulta
			If .State > 0 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"'
						lstrCodigo = IIf(IsDbNull(.Fields("num").value), "0", .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"'
						lstrDescri = IIf(IsDbNull(.Fields("descri").value), "", .Fields("descri").value)
						With Me.lvwTipos
							Call .Items.Add(lstrCodigo)
							'UPGRADE_WARNING: Lower bound of collection Me.lvwTipos.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(lstrDescri)
						End With
						Call .MoveNext()
					End While
				End If
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstConsulta 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"'
		lrstConsulta = Nothing
	End Sub
	
	Private Sub EnchePreDefinidos()
		Dim lintConta As Short
		Dim lintIndex As Short
		Dim lstrSql As String
		Dim lrstConsulta As ADODB.Recordset
		Dim lstrCodigo As String
		Dim lstrDescri As String
		lrstConsulta = New ADODB.Recordset
		Call Me.cmbTipos.Items.Clear()
		lintIndex = 0
		lstrSql = ""
		lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS `sel_lanctoscvdvtx`    (" & vbCrLf
		lstrSql = lstrSql & "   `descricao` varchar(100) default '',          " & vbCrLf
		lstrSql = lstrSql & "   `codigo`    varchar(10)  default '0000000000' " & vbCrLf
		lstrSql = lstrSql & " )"
		Call Executar(lstrSql)
		lstrSql = ""
		lstrSql = lstrSql & "SELECT DISTINCT `sel_lanctoscvdvtx`.`descricao` " & vbCrLf
		lstrSql = lstrSql & "  FROM `sel_lanctoscvdvtx` " & vbCrLf
		lstrSql = lstrSql & " ORDER BY `descricao` ASC "
		Call Conectar(lstrSql, lrstConsulta)
		With lrstConsulta
			If .State > 0 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"'
						lstrDescri = IIf(IsDbNull(.Fields("descricao").value), "(nenhum)", .Fields("descricao").value)
						Call Me.cmbTipos.Items.Add(lstrDescri)
						Call .MoveNext()
					End While
				Else
					Call Me.cmbTipos.Items.Add("(nenhum)")
				End If
				With Me.cmbTipos
					If Len(Trim(Me.txtNomeSelecao.Text)) > 0 Then
						For lintConta = 0 To .Items.Count - 1
							If VB6.GetItemString(Me.cmbTipos, lintConta) = Me.txtNomeSelecao.Text Then
								lintIndex = lintConta
							End If
						Next lintConta
					End If
					.SelectedIndex = lintIndex
				End With
				Call .Close()
			End If
		End With
		'UPGRADE_NOTE: Object lrstConsulta 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"'
		lrstConsulta = Nothing
	End Sub
	
	Private Sub lvwSelecao_DoubleClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles lvwSelecao.DoubleClick
		Call cmdRetira_Click(cmdRetira, New System.EventArgs())
	End Sub
	
	Private Sub lvwTipos_DoubleClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles lvwTipos.DoubleClick
		Call cmdAdiciona_Click(cmdAdiciona, New System.EventArgs())
	End Sub
End Class