Option Strict Off
Option Explicit On
Friend Class frmLocalizaFaturaComplementar
	Inherits System.Windows.Forms.Form
	Private ifrmQuemChama As System.Windows.Forms.Form
	
	Private Sub cmdFechar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFechar.Click
		If Not ifrmQuemChama Is Nothing Then
			ifrmQuemChama.Enabled = True
		End If
		Call Me.Close()
		'UPGRADE_WARNING: Form method ifrmQuemChama.ZOrder has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		Call ifrmQuemChama.BringToFront()
	End Sub
	
	Private Sub MontaGrade()
		With Me.mfgDados
			.set_Cols( , 9)
			.Rows = 2
			.FixedRows = 1
			.FixedCols = 0
			.Redraw = False
			.set_TextMatrix(0, 0, "Zona")
			.set_TextMatrix(0, 1, "Livro")
			.set_TextMatrix(0, 2, "Conta")
			.set_TextMatrix(0, 3, "Numero Fatura")
			.set_TextMatrix(0, 4, "Complementar")
			.set_TextMatrix(0, 5, "Valor Total")
			.set_TextMatrix(0, 6, "Situação")
			.set_TextMatrix(0, 7, "Localização")
			.set_TextMatrix(0, 8, "NSU")
			.set_ColWidth(8,  , 0)
			.set_ColWidth(0,  , 500)
			.set_ColWidth(1,  , 500)
			.set_ColWidth(2,  , 800)
			.set_ColAlignment(0, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_ColAlignment(1, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_ColAlignment(2, MSFlexGridLib.AlignmentSettings.flexAlignCenterCenter)
			.set_ColWidth(3,  , 1300)
			.set_ColWidth(4,  , 1200)
			.set_ColWidth(5,  , 1500)
			.set_ColWidth(6,  , 1200)
			.set_ColWidth(7,  , 3300)
			
			.Redraw = True
		End With
	End Sub
	
	Public Sub SetaParametros(ByRef afrmQuemChama As System.Windows.Forms.Form, ByVal astrGrupo As String, ByVal adblCons_Id As Double, ByVal adblUnid_id As Double, ByVal alngAnoMes As Integer)
		Dim lstrZona As String
		Dim lstrLivro As String
		Dim lstrConta As String
		Dim ldblNumNf As Double
		Dim ldblNsuNr As Double
		Dim llngComp As Integer
		Dim ldblValor As Double
		Dim lstrSit As String
		Dim lstrLoc As String
		Dim lstrSql As String
		Dim lblnAux As Boolean
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		ifrmQuemChama = afrmQuemChama
		If Not ifrmQuemChama Is Nothing Then
			ifrmQuemChama.Enabled = False
		End If
		lblnAux = False
		Call MontaGrade()
		lstrSql = "SELECT `zona`, `livro`, `conta`, `numnf`, `fatura_complementar`, `valortot`, `flgst`, 'Em Faturamento' `localizacao`, `nsu`" & "  FROM `nftransicao` " & " WHERE `grupo` = '" & astrGrupo & "' " & "   AND `cons_id` = " & adblCons_Id & "   AND `unid_id` = " & adblUnid_id & "   AND `mesano_ref` = " & alngAnoMes & "   AND `fatura_complementar` > 0 " & " UNION ALL " & "SELECT `zona`, `livro`, `conta`, `numnf`, `fatura_complementar`, `valortot`, `flgst`, 'Em Arrecadação' `localizacao`, `nsu`" & "  FROM `nf` " & " WHERE `grupo` = '" & astrGrupo & "' " & "   AND `cons_id` = " & adblCons_Id & "   AND `unid_id` = " & adblUnid_id & "   AND `mesano_ref` = " & alngAnoMes & "   AND `fatura_complementar` > 0 "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State = ADODB.ObjectStateEnum.adStateOpen Then
				If .RecordCount > 0 Then
					lblnAux = True
					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 = 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"'
						ldblNumNf = 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"'
						ldblNsuNr = IIf(IsDbNull(.Fields("nsu").value), 0, .Fields("nsu").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"'
						llngComp = IIf(IsDbNull(.Fields("fatura_complementar").value), 0, .Fields("fatura_complementar").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 = IIf(IsDbNull(.Fields("valortot").value), 0, .Fields("valortot").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"'
						lstrSit = 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"'
						lstrLoc = IIf(IsDbNull(.Fields("localizacao").value), "", .Fields("localizacao").value)
						With Me.mfgDados
							.set_TextMatrix(.Rows - 1, 0, lstrZona)
							.set_TextMatrix(.Rows - 1, 1, lstrLivro)
							.set_TextMatrix(.Rows - 1, 2, lstrConta)
							.set_TextMatrix(.Rows - 1, 3, ldblNumNf)
							.set_TextMatrix(.Rows - 1, 4, llngComp)
							.set_TextMatrix(.Rows - 1, 5, VB6.Format(ldblValor, "#,##0.00"))
							.set_TextMatrix(.Rows - 1, 6, IIf(lstrSit = "", "Aberta", IIf(lstrSit = "P", "Paga", IIf(lstrSit = "R", "Reserva", IIf(lstrSit = "J", "Judice", IIf(lstrSit = "C", "Cancelada", "Outros"))))))
							.set_TextMatrix(.Rows - 1, 7, lstrLoc)
							.set_TextMatrix(.Rows - 1, 8, ldblNsuNr)
							.Rows = .Rows + 1
						End With
						Call .MoveNext()
					End While
					If Me.mfgDados.Rows > 2 Then
						Me.mfgDados.Rows = Me.mfgDados.Rows - 1
					End If
				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
		If Not lblnAux Then
			Call MsgBox("Não existe faturas complentares geradas ainda para esta unidade consumidora!", MsgBoxStyle.Information, gstrTituloMensagem)
			If Not ifrmQuemChama Is Nothing Then
				ifrmQuemChama.Enabled = True
			End If
			Call Me.Close()
			'UPGRADE_WARNING: Form method ifrmQuemChama.ZOrder has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
			Call ifrmQuemChama.BringToFront()
		End If
	End Sub
	
	Private Sub frmLocalizaFaturaComplementar_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Call CenterForm(Me)
		Call MontaGrade()
	End Sub
	
	Private Sub mfgDados_DblClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mfgDados.DblClick
		With Me.mfgDados
			If .Rows > 1 Then
				If .RowSel > 0 Then
					If Not ifrmQuemChama Is Nothing Then
						ifrmQuemChama.Enabled = True
					End If
					'UPGRADE_ISSUE: Control SetaCodigoRetornoPesquisa could not be resolved because it was within the generic namespace Form. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="084D22AD-ECB1-400F-B4C7-418ECEC5E36E"'
					Call ifrmQuemChama.SetaCodigoRetornoPesquisa(CDbl(IIf(IsNumeric(.get_TextMatrix(.RowSel, 3)), .get_TextMatrix(.RowSel, 3), 0)), CDbl(IIf(IsNumeric(.get_TextMatrix(.RowSel, 8)), .get_TextMatrix(.RowSel, 8), 0)), CInt(IIf(IsNumeric(.get_TextMatrix(.RowSel, 4)), .get_TextMatrix(.RowSel, 4), 0)))
				End If
			End If
		End With
		Call Me.Close()
		'UPGRADE_WARNING: Form method ifrmQuemChama.ZOrder has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
		Call ifrmQuemChama.BringToFront()
	End Sub
End Class