Option Strict Off
Option Explicit On
Friend Class frmHistorico
	Inherits System.Windows.Forms.Form
	Private ilngUnidId As Integer
	Private ilngConsId As Integer
	Private istrGrupo As String
	Private ifrmImpHis As FrmRelatorio
	
	Public Sub SetaDados(ByVal astrGrupo As String, ByVal alngConsId As Integer, ByVal alngUnidId As Integer)
		istrGrupo = astrGrupo
		ilngUnidId = alngUnidId
		ilngConsId = alngConsId
		Me.Text = Me.Text & "Grupo " & istrGrupo
	End Sub
	
	Private Sub cmdEditSv_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdEditSv.Click
		Dim lstrSql As String
		
		If Me.cmdEditSv.Text = "Editar" Then
			Me.cmdEditSv.Text = "Salvar"
			Me.txtHistorico.ReadOnly = False
		Else
			lstrSql = ""
			lstrSql = lstrSql & "UPDATE `unid" & LCase(istrGrupo) & "` "
			lstrSql = lstrSql & "   SET historico = '" & Me.txtHistorico.Text & "' "
			lstrSql = lstrSql & " WHERE unid_id = " & ilngUnidId & " "
			Me.cmdEditSv.Text = "Editar"
			Me.txtHistorico.ReadOnly = True
			Call Executar(lstrSql)
		End If
	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 cmdImp_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdImp.Click
		Call MontaHistorico()
	End Sub
	
	Private Sub cmdProc_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdProc.Click
		Dim posA As Short
		Dim posB As Short
		
		If CDbl(Me.txtHistorico.Tag) > 0 Then posA = CShort(Me.txtHistorico.Tag)
		
		If Me.txtProc.Text <> "" Then
			posA = InStr(CShort(Me.txtHistorico.Tag), Me.txtHistorico.Text, Me.txtProc.Text)
			
			If posA > 0 Then
				posB = Len(Me.txtProc.Text)
				Me.txtHistorico.SelectionStart = posA - 1
				Me.txtHistorico.SelectionLength = posB
				If Me.txtHistorico.Enabled = True Then Me.txtHistorico.Focus()
			Else
				MsgBox("'" & txtProc.Text & "' não encontrado!", MsgBoxStyle.Exclamation, gstrTituloMensagem)
			End If
			
			txtHistorico.Tag = posA + 1
		End If
	End Sub
	
	Private Sub frmHistorico_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.Escape Then
			Call cmdFechar_Click(cmdFechar, New System.EventArgs())
		ElseIf KeyAscii = System.Windows.Forms.Keys.Return Then 
			Call SendKeysA(System.Windows.Forms.Keys.Tab, True)
		End If
		eventArgs.KeyChar = Chr(KeyAscii)
		If KeyAscii = 0 Then
			eventArgs.Handled = True
		End If
	End Sub
	
	Private Sub frmHistorico_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Dim lstrSql As String
		Dim lrstAux As ADODB.Recordset
		lrstAux = New ADODB.Recordset
		lstrSql = ""
		lstrSql = lstrSql & "SELECT `nome`, "
		lstrSql = lstrSql & "       `historico` "
		lstrSql = lstrSql & "  FROM `unid" & LCase(istrGrupo) & "` "
		lstrSql = lstrSql & " WHERE unid_id = " & ilngUnidId & " "
		Call Conectar(lstrSql, lrstAux)
		With lrstAux
			If .State > 0 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.txtNomeCons.Text = 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"'
					Me.txtHistorico.Text = Trim(IIf(IsDbNull(.Fields("historico").value), "", .Fields("historico").value))
				End If
				Call .Close()
			End If
		End With
		ifrmImpHis = New FrmRelatorio
	End Sub
	
	Private Sub MontaHistorico()
		With ifrmImpHis
			.quem_chama = Me
			Call iniDoc(.VS, True)
			'UPGRADE_ISSUE: VBControlExtender method ifrmImpHis.VS.CurrentY was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
			.VS.CurrentY = "33mm"
			.VS.MarginLeft = "20mm"
			.VS.TextAlign = VSVIEW6.TextAlignSettings.taLeftTop
			'UPGRADE_NOTE: Text was upgraded to CtlText. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
			.VS.CtlText = Me.txtHistorico.Text
			Call iniDoc(.VS, False)
			Call .VS.EndDoc()
			Call .Show()
		End With
	End Sub
	
	Public Function CabecaRel() As Object
		With ifrmImpHis
			Call Cabecalho_Relatorio(.VS, "Historico do assinante", Me.txtNomeCons.Text, CStr(4), False, "")
			Call LineFeed(.VS, 1)
		End With
	End Function
End Class