Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Friend Class frmRelDiversos
	Inherits System.Windows.Forms.Form
	Private istrFatura As String
	
	'UPGRADE_WARNING: Event chkTrans.CheckStateChanged 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 chkTrans_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkTrans.CheckStateChanged
		istrFatura = IIf(Me.chkTrans.CheckState = 0, "nf", "nftransicao")
	End Sub
	
	Private Sub cmdExporta_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExporta.Click
		Dim lstrLin As String
		Dim lintARQ As Short
		Dim llngRow As Integer
		Dim llngCol As Integer
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		If Trim(Me.txtArq.Text) = "" Then
			Call MsgBox("Você precisa selecionar o caminho e o arquivo para exportação!", MsgBoxStyle.Information, gstrTituloMensagem)
		Else
			lstrSql = ""
			lstrSql = lstrSql & "SELECT `zona`, "
			lstrSql = lstrSql & "       `livro`, "
			lstrSql = lstrSql & "       `conta`, "
			lstrSql = lstrSql & "       `nome`, "
			lstrSql = lstrSql & "       `mesano`, "
			lstrSql = lstrSql & "       `valor` "
			lstrSql = lstrSql & "  FROM `temp_diversos` "
			lstrSql = lstrSql & " WHERE `nomemaquina` = """ & gstrNmEstacao & """; "
			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)
						lintARQ = FreeFile
						FileOpen(lintARQ, Me.txtArq.Text, OpenMode.Output)
						While Not .EOF
							lstrLin = ""
							'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"'
							lstrLin = lstrLin & Trim(IIf(IsDbNull(.Fields("zona").value), "", .Fields("zona").value)) & "." & Trim(IIf(IsDbNull(.Fields("livro").value), "", .Fields("livro").value)) & "." & 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"'
							'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"'
							lstrLin = lstrLin & Trim(IIf(IsDbNull(.Fields("nome").value), "", .Fields("nome").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"'
							lstrLin = lstrLin & Trim(IIf(IsDbNull(.Fields("mesano").value), "", .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"'
							lstrLin = lstrLin & VB6.Format(CDbl(IIf(IsDbNull(.Fields("valor").value), "", .Fields("valor").value)), "Standard") & ";"
							PrintLine(lintARQ, lstrLin)
							Call .MoveNext()
							Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
						End While
						FileClose(lintARQ)
						Call MsgBox("Arquivo gerado com sucesso!", MsgBoxStyle.Information, gstrTituloMensagem)
					End If
					Call .Close()
				End If
			End With
		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 cmdProcessar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdProcessar.Click
		Dim lstrCodigos As String
		Dim lstrDescricao As String
		Dim lstrCabecB As String
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim ldblNumNF As Double
		Dim lstrMesAno As String
		Dim llngMesano As Integer
		Dim ldtePagto As Date
		Dim lstrItens As String
		Dim lstrGruTar As String
		Dim lstrGrupo As String
		Dim lstrCodClas As String
		Dim lstrNomClas As String
		Dim llngConsId As Integer
		Dim llngUnidId As Integer
		Dim lstrFlgSt As String
		Dim lstrNome As String
		Dim lstrNomeA As String
		Dim lstrNomeB As String
		Dim lstrNomeC As String
		Dim lstrCpfCnpj As String
		Dim lstrCpfCnpjA As String
		Dim lstrCpfCnpjB As String
		Dim lstrCpfCnpjC As String
		Dim lstrCpfCnpjF As String
		Dim ldblValor As Double
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
		Call LigDes(False)
		lstrSql = ""
		lstrSql = lstrSql & "DELETE FROM `temp_diversos` WHERE `nomemaquina` = """ & gstrNmEstacao & """; "
		Call Executar(lstrSql)
		lstrCodigos = Mid(VB6.GetItemString(Me.cmbDiversos, Me.cmbDiversos.SelectedIndex), 1, 10)
		lstrDescricao = Mid(VB6.GetItemString(Me.cmbDiversos, Me.cmbDiversos.SelectedIndex), 14)
		lstrSql = ""
		lstrSql = lstrSql & "SELECT `faturas`.`zona`, "
		lstrSql = lstrSql & "       `faturas`.`livro`, "
		lstrSql = lstrSql & "       `faturas`.`conta`, "
		lstrSql = lstrSql & "       `faturas`.`numnf`, "
		lstrSql = lstrSql & "       `faturas`.`mesano`, "
		lstrSql = lstrSql & "       `faturas`.`mesano_ref`, "
		lstrSql = lstrSql & "       `faturas`.`datapag`, "
		lstrSql = lstrSql & "       `faturas`.`itensserv`, "
		lstrSql = lstrSql & "       `faturas`.`ta`, "
		lstrSql = lstrSql & "       `faturas`.`grupo`, "
		lstrSql = lstrSql & "       `faturas`.`codclas`, "
		lstrSql = lstrSql & "       `faturas`.`cons_id`, "
		lstrSql = lstrSql & "       `faturas`.`unid_id`, "
		lstrSql = lstrSql & "       `faturas`.`flgst`, "
		lstrSql = lstrSql & "       `unida`.`nome` As `nomea`, "
		lstrSql = lstrSql & "       `unidb`.`nome` AS `nomeb`, "
		lstrSql = lstrSql & "       `consum`.`nome` AS `nomec`, "
		lstrSql = lstrSql & "       `faturas`.`cpf_cnpj` AS `cpfcnpjf`, "
		lstrSql = lstrSql & "       `unida`.`cpf_cnpj` AS `cpfcnpja`, "
		lstrSql = lstrSql & "       `unidb`.`cpf_cnpj` AS `cpfcnpjb`,"
		lstrSql = lstrSql & "       `consum`.`cgc` AS `cpfcnpjc`"
		lstrSql = lstrSql & "  FROM `" & istrFatura & "` AS `faturas` "
		lstrSql = lstrSql & " LEFT JOIN `unida` ON(`unida`.`unid_id` = `faturas`.`unid_id` AND `unida`.`cons_id` = `faturas`.`cons_id` AND `faturas`.`grupo` = 'A' ) "
		lstrSql = lstrSql & " LEFT JOIN `unidb` ON(`unidb`.`unid_id` = `faturas`.`unid_id` AND `unidb`.`cons_id` = `faturas`.`cons_id` AND `faturas`.`grupo` = 'B' ) "
		lstrSql = lstrSql & " LEFT JOIN `consum` ON(`consum`.`consreg` = `faturas`.`cons_id` ) "
		lstrSql = lstrSql & " WHERE `faturas`.`itensserv` LIKE '%" & lstrCodigos & "%' "
		If Me.opbFaturado.Checked Then
			lstrSql = lstrSql & " AND `faturas`.`mesano_ref` BETWEEN "
			lstrSql = lstrSql & VB6.Format(Me.dtpInicial.value, "yyyymm") & " AND "
			lstrSql = lstrSql & VB6.Format(Me.dtpFinal.value, "yyyymm") & " "
			lstrCabecB = "Faturado "
		ElseIf Me.opbAberto.Checked Then 
			lstrSql = lstrSql & " AND `faturas`.`mesano_ref` BETWEEN "
			lstrSql = lstrSql & VB6.Format(Me.dtpInicial.value, "yyyymm") & " AND "
			lstrSql = lstrSql & VB6.Format(Me.dtpFinal.value, "yyyymm") & " "
			lstrSql = lstrSql & "   AND (`faturas`.`flgst` <> 'C' OR (`faturas`.`flgst` = 'C' AND `faturas`.`datast` > '" & VB6.Format(Me.dtpFinal.value, "yyyy-MM-dd") & "')) "
			If Me.chkPagasApos.CheckState Then
				lstrSql = lstrSql & "   AND `faturas`.`flgst` <> 'P' "
			Else
				lstrSql = lstrSql & "   AND (`faturas`.`datapag` > '" & VB6.Format(Me.dtpFinal.value, "yyyy-MM-dd") & "' OR `faturas`.`datapag` = '0000-00-00' ) "
			End If
			lstrCabecB = "Aberto "
		ElseIf Me.opbArrecadado.Checked Then 
			lstrSql = lstrSql & "   AND `faturas`.`datapag` BETWEEN "
			lstrSql = lstrSql & "'" & VB6.Format(Me.dtpInicial.value, "yyyy-MM-dd") & "' AND "
			lstrSql = lstrSql & "'" & VB6.Format(Me.dtpFinal.value, "yyyy-MM-dd") & "' "
			lstrSql = lstrSql & "   AND (`faturas`.`flgst` <> 'C' OR (`faturas`.`flgst` = 'C' AND `faturas`.`datast` > '" & VB6.Format(Me.dtpFinal.value, "yyyy-MM-dd") & "')) "
			lstrCabecB = "Arrecadado "
		End If
		lstrCabecB = lstrCabecB & "no período de " & VB6.Format(Me.dtpInicial.value, "dd/mm/yyyy") & " até " & VB6.Format(Me.dtpFinal.value, "dd/mm/yyyy")
		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"'
						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"'
						'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"'
						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"'
						'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"'
						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"'
						'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"'
						lstrMesAno = Trim(IIf(IsDbNull(.Fields("mesano").value), "", .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"'
						llngMesano = 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"'
						ldtePagto = CDate(IIf(IsDbNull(.Fields("datapag").value), "1900-01-01", .Fields("datapag").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))
						'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"'
						lstrGruTar = Trim(IIf(IsDbNull(.Fields("ta").value), "", .Fields("ta").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), "", .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"'
						lstrCodClas = Trim(IIf(IsDbNull(.Fields("codclas").value), "", .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"'
						llngConsId = CInt(IIf(IsDbNull(.Fields("cons_id").value), 0, .Fields("cons_id").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"'
						llngUnidId = CInt(IIf(IsDbNull(.Fields("unid_id").value), 0, .Fields("unid_id").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"'
						lstrFlgSt = Trim(IIf(IsDbNull(.Fields("flgst").value), "", .Fields("flgst").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"'
						lstrNomeA = Trim(IIf(IsDbNull(.Fields("nomea").value), "", .Fields("nomea").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"'
						lstrNomeB = Trim(IIf(IsDbNull(.Fields("nomeb").value), "", .Fields("nomeb").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("nomec").value), "", .Fields("nomec").value))
						'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"'
						lstrNome = IIf(lstrNomeA <> "", lstrNomeA, IIf(lstrNomeB <> "", lstrNomeB, lstrNomeC))
						'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"'
						lstrCpfCnpjA = Trim(IIf(IsDbNull(.Fields("cpfcnpja").value), "", .Fields("cpfcnpja").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"'
						lstrCpfCnpjB = Trim(IIf(IsDbNull(.Fields("cpfcnpjb").value), "", .Fields("cpfcnpjb").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"'
						lstrCpfCnpjC = Trim(IIf(IsDbNull(.Fields("cpfcnpjc").value), "", .Fields("cpfcnpjc").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"'
						lstrCpfCnpjF = Trim(IIf(IsDbNull(.Fields("cpfcnpjf").value), "", .Fields("cpfcnpjf").value))
						'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"'
						lstrCpfCnpj = IIf(lstrCpfCnpjF <> "", lstrCpfCnpjF, IIf(lstrCpfCnpjA <> "", lstrCpfCnpjA, IIf(lstrCpfCnpjB <> "", lstrCpfCnpjB, lstrCpfCnpjC)))
						If Len(lstrCpfCnpj) <= 11 Then
							lstrCpfCnpj = FormataCPF(lstrCpfCnpj)
						Else
							lstrCpfCnpj = FormataCNPJ(lstrCpfCnpj)
						End If
						ldblValor = BuscaVlrItem(lstrItens, lstrCodigos)
						Select Case VB.Left(lstrCodClas, 1)
							Case Is < CStr(4)
								lstrCodClas = "04"
								lstrNomClas = "Industrial"
							Case Is = CStr(4)
								lstrCodClas = "03"
								lstrNomClas = "Comercial"
							Case Is = CStr(5)
								lstrCodClas = "05"
								lstrNomClas = "Rural"
							Case Is = CStr(6)
								If CDbl(VB.Left(lstrCodClas, 2)) = 64 Then
									lstrCodClas = "07"
									lstrNomClas = "Ilum. Pública"
								Else
									lstrCodClas = "06"
									lstrNomClas = "Poder Público"
								End If
							Case Is = CStr(7)
								lstrCodClas = "08"
								lstrNomClas = "Serviço Público"
							Case Is = CStr(8)
								lstrCodClas = "09"
								lstrNomClas = "Consumo Próprio"
							Case Is = CStr(9)
								If CDbl(VB.Right(lstrCodClas, 1)) = 2 Or CDbl(VB.Right(lstrCodClas, 1)) = 4 Or CDbl(VB.Right(lstrCodClas, 1)) = 5 Or CDbl(VB.Right(lstrCodClas, 1)) = 2 = 6 Then
									lstrCodClas = "01"
									lstrNomClas = "Residencial Baixa Renda"
								Else
									lstrCodClas = "02"
									lstrNomClas = "Residencial Normal"
								End If
						End Select
						lstrSql = ""
						lstrSql = lstrSql & "INSERT INTO `temp_diversos` SET "
						lstrSql = lstrSql & "            `nomemaquina` = """ & gstrNmEstacao & """, "
						lstrSql = lstrSql & "            `zona`        = '" & lstrZona & "', "
						lstrSql = lstrSql & "            `livro`       = '" & lstrLivro & "', "
						lstrSql = lstrSql & "            `conta`       = '" & lstrConta & "', "
						lstrSql = lstrSql & "            `nome`        = """ & lstrNome & """, "
						lstrSql = lstrSql & "            `numnf`       = " & ldblNumNF & ", "
						lstrSql = lstrSql & "            `mesano`      = '" & lstrMesAno & "', "
						lstrSql = lstrSql & "            `mesano_ref`  = " & llngMesano & ", "
						'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 & "            `datapag`     = '" & VB6.Format(IIf(ldtePagto = CDate("01/01/1900"), "00/00/0000", ldtePagto), "yyyy-MM-dd") & "', "
						lstrSql = lstrSql & "            `cpf_cnpj`    = '" & lstrCpfCnpj & "', "
						lstrSql = lstrSql & "            `grupo`       = '" & lstrGrupo & "', "
						lstrSql = lstrSql & "            `ta`          = '" & lstrGruTar & "', "
						lstrSql = lstrSql & "            `codclas`     = '" & lstrCodClas & "', "
						lstrSql = lstrSql & "            `nomclas`     = '" & lstrNomClas & "', "
						lstrSql = lstrSql & "            `valor`       = " & Replace(CStr(ldblValor), ",", ".") & ", "
						lstrSql = lstrSql & "            `cabec_a`     = '(" & lstrDescricao & ")', "
						lstrSql = lstrSql & "            `cabec_b`     = '" & lstrCabecB & "' "
						Call Executar(lstrSql)
						Call .MoveNext()
						Call BarraProgresso((Me.ProgressBar), (Me.lblPerc), (Me.lblInfo), 1)
					End While
				End If
				Call .Close()
			End If
		End With
		Me.lblInfo.Text = " Finalizado...."
		Call Me.lblInfo.Refresh()
		'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
		Me.Cursor = System.Windows.Forms.Cursors.Default
		Call LigDes(True)
	End Sub
	
	Private Sub cmdImprime_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdImprime.Click
		Dim lstrCriterio As String
		lstrCriterio = "{temp_diversos.nomemaquina} = """ & gstrNmEstacao & """ "
		With Me.crpAux
			.ReportFileName = My.Application.Info.DirectoryPath & "\" & LeConfig("DIR_RPT") & "RelDiversos.rpt"
			.DiscardSavedData = True
			.WindowState = Crystal.WindowStateConstants.crptMaximized
			.WindowControlBox = True
			.WindowControls = True
			.WindowShowPrintSetupBtn = True
			.WindowShowCloseBtn = True
			.WindowShowSearchBtn = True
			.SelectionFormula = lstrCriterio
			.WindowTitle = "Relatório dos diversos"
			.Destination = Crystal.DestinationConstants.crptToWindow
			.set_Formulas(1, "porclasse = " & Me.chkClasse.CheckState)
			.set_Formulas(2, "totalizado = " & Me.chkTotal.CheckState)
			If Me.chkClasse.CheckState = 1 Then
				.set_SortFields(0, "+{temp_diversos.codclas}")
				If Me.cmbOrdem.SelectedIndex = 0 Then
					.set_SortFields(1, "+{temp_diversos.nome}")
					If Me.opbArrecadado.Checked Then
						.set_SortFields(2, "+{temp_diversos.datapag}")
					Else
						.set_SortFields(2, "+{temp_diversos.mesano_ref}")
					End If
					.set_SortFields(3, "")
					.set_SortFields(4, "")
				ElseIf Me.cmbOrdem.SelectedIndex = 1 Then 
					.set_SortFields(1, "+{temp_diversos.zona}")
					.set_SortFields(2, "+{temp_diversos.livro}")
					.set_SortFields(3, "+{temp_diversos.conta}")
					If Me.opbArrecadado.Checked Then
						.set_SortFields(4, "+{temp_diversos.datapag}")
					Else
						.set_SortFields(4, "+{temp_diversos.mesano_ref}")
					End If
				End If
			Else
				If Me.cmbOrdem.SelectedIndex = 0 Then
					.set_SortFields(0, "+{temp_diversos.nome}")
					If Me.opbArrecadado.Checked Then
						.set_SortFields(1, "+{temp_diversos.datapag}")
					Else
						.set_SortFields(1, "+{temp_diversos.mesano_ref}")
					End If
					.set_SortFields(2, "")
					.set_SortFields(3, "")
					.set_SortFields(4, "")
				ElseIf Me.cmbOrdem.SelectedIndex = 1 Then 
					.set_SortFields(0, "+{temp_diversos.zona}")
					.set_SortFields(1, "+{temp_diversos.livro}")
					.set_SortFields(2, "+{temp_diversos.conta}")
					If Me.opbArrecadado.Checked Then
						.set_SortFields(3, "+{temp_diversos.datapag}")
					Else
						.set_SortFields(3, "+{temp_diversos.mesano_ref}")
					End If
					.set_SortFields(4, "")
				End If
			End If
			.Action = 0
		End With
	End Sub
	
	Private Sub cmdProcura_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdProcura.Click
		Me.dialArqOpen.ShowDialog()
		Me.txtArq.Text = Me.dialArqOpen.FileName
	End Sub
	
	Private Sub frmRelDiversos_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Dim lstrSql As String
		Call CenterForm(Me)
		Me.dtpInicial.value = BuscaDataBD
		Me.dtpInicial.value = CDate("01/" & VB6.Format(Me.dtpInicial.value, "mm/yyyy"))
		Me.dtpFinal.value = CDate(UltimoDiaMes((Me.dtpInicial.Month), (Me.dtpInicial.Year)) & "/" & VB6.Format(Me.dtpInicial.value, "mm/yyyy"))
		Call EncheComboBox()
		istrFatura = IIf(Me.chkTrans.CheckState = 0, "nf", "nftransicao")
		Me.cmbOrdem.SelectedIndex = 0
		Me.dialArqOpen.DefaultExt = "CSV"
		Me.dialArqOpen.InitialDirectory = My.Application.Info.DirectoryPath
		Me.txtArq.Text = My.Application.Info.DirectoryPath & "\diversos_" & VB6.Format(BuscaDataBD, "yyyymmddHHMM") & "." & Me.dialArqOpen.DefaultExt
		'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 = Me.txtArq.Text
		Me.dialArqOpen.Title = "Arquivo de exportação de convênios, taxas e diversos"
		Me.chkPagasApos.Enabled = False
		lstrSql = ""
		lstrSql = lstrSql & "CREATE TABLE IF NOT EXISTS `temp_diversos`    (" & 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 & "   `numnf`       double NOT NULL default '0',       " & vbCrLf
		lstrSql = lstrSql & "   `mesano`      varchar(7) NOT NULL default '',    " & vbCrLf
		lstrSql = lstrSql & "   `mesano_ref`  int(11) NOT NULL default '0',      " & vbCrLf
		lstrSql = lstrSql & "   `datapag`     date default '0000-00-00',         " & vbCrLf
		lstrSql = lstrSql & "   `cpf_cnpj`    varchar(19) default NULL,          " & vbCrLf
		lstrSql = lstrSql & "   `grupo`       char(1) NOT NULL default '',       " & vbCrLf
		lstrSql = lstrSql & "   `ta`          varchar(6) default NULL,           " & vbCrLf
		lstrSql = lstrSql & "   `valor`       decimal(14,2) default NULL,        " & vbCrLf
		lstrSql = lstrSql & "   `codclas`     varchar(2) default NULL,           " & vbCrLf
		lstrSql = lstrSql & "   `nomclas`     varchar(30) default NULL,          " & vbCrLf
		lstrSql = lstrSql & "   `cabec_a`     varchar(255) default NULL,         " & vbCrLf
		lstrSql = lstrSql & "   `cabec_b`     varchar(255) default NULL          " & vbCrLf
		lstrSql = lstrSql & " )"
		Call Executar(lstrSql)
	End Sub
	
	Private Sub EncheComboBox()
		Dim lstrCodigos As String
		Dim lstrDescricao As String
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		Call Me.cmbDiversos.Items.Clear()
		lstrSql = ""
		lstrSql = lstrSql & "SELECT * "
		lstrSql = lstrSql & "  FROM codigos "
		lstrSql = lstrSql & " WHERE num BETWEEN '9000000000' AND '9999999999' "
		lstrSql = lstrSql & "ORDER BY num ASC "
		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"'
						lstrCodigos = VB6.Format(IIf(IsDbNull(.Fields("num").value), "0", .Fields("num").value), "0000000000")
						'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"'
						lstrDescricao = IIf(IsDbNull(.Fields("descri").value), "(indefinido)", .Fields("descri").value)
						Call Me.cmbDiversos.Items.Add(lstrCodigos & " - " & lstrDescricao)
						Call .MoveNext()
					End While
				Else
					Call Me.cmbDiversos.Items.Add("0000000000 - (nenhum)")
				End If
				Call .Close()
				Me.cmbDiversos.SelectedIndex = 0
			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 cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click
		Call Me.Close()
	End Sub
	
	Private Sub LigDes(ByVal ablnModo As Boolean)
		Dim lintAux As Short
		For lintAux = Me.fmeAux.LBound To Me.fmeAux.UBound
			Me.fmeAux(lintAux).Enabled = ablnModo
		Next lintAux
		Me.cmbDiversos.Enabled = ablnModo
		Me.cmbOrdem.Enabled = ablnModo
		Me.cmdProcessar.Enabled = ablnModo
		Me.cmdImprime.Enabled = ablnModo
		Me.cmdExporta.Enabled = ablnModo
		Me.cmdFechar.Enabled = ablnModo
		System.Windows.Forms.Application.DoEvents()
	End Sub
	
	'UPGRADE_WARNING: Event opbAberto.CheckedChanged 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 opbAberto_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbAberto.CheckedChanged
		If eventSender.Checked Then
			Me.chkPagasApos.Enabled = True
		End If
	End Sub
	
	'UPGRADE_WARNING: Event opbArrecadado.CheckedChanged 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 opbArrecadado_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbArrecadado.CheckedChanged
		If eventSender.Checked Then
			Me.chkPagasApos.Enabled = False
		End If
	End Sub
	
	'UPGRADE_WARNING: Event opbFaturado.CheckedChanged 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 opbFaturado_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles opbFaturado.CheckedChanged
		If eventSender.Checked Then
			Me.chkPagasApos.Enabled = False
		End If
	End Sub
End Class