Option Strict Off
Option Explicit On
Friend Class frmCadUniGruposMensagens
	Inherits System.Windows.Forms.Form
	Private ifrmQuemChama As System.Windows.Forms.Form
	'Private ifrmLocalizar As frmLocalizadorGeralNovo
	Private iblnNovo As Boolean
	Private istrTabela As String
	Private istrPriKey() As String
	Private istrForKey() As String
	Private irstTabela As DataTable
	'Private iTextBox() As clsCtrlEventos
	Private Sub cmdExcluir_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExcluir.Click
		Try
			Call ctrl_form_ExcluirRegistros(Me, istrTabela, istrPriKey)
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdExcluir_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	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 cmdLocalizar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLocalizar.Click
		Try
			Call frmLocalizadorGeral.Show()
			Call frmLocalizadorGeral.SetParametros(istrTabela, Me.Text, Me)
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdLocalizar_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	Private Sub cmdLocalizarProcessos_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs)
		Try
			Call frmLocalizadorGeral.Show()
			Call frmLocalizadorGeral.SetParametros("caduni_processos", "Cadastro único - processos", Me)
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdLocalizarProcessos_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub cmdNovo_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdNovo.Click
		Try
			iblnNovo = True
			Call ctrl_form_LimpaCamposPadrao(Me)
			Call Me.txtAno.Focus()
			Me.txtAno.Text = CStr(Year(Date.Now))
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdNovo_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	Private Sub cmdSalvar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSalvar.Click
		Try
			Call ctrl_form_SalvarRegistro(Me, istrTabela, istrPriKey, irstTabela, iblnNovo)
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdSalvar_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub frmCadUniGruposMensagens_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
		Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
		Try
			Call ctrl_form_FormKeyPress(Me, KeyAscii)
			eventArgs.KeyChar = Chr(KeyAscii)
			If KeyAscii = 0 Then
				eventArgs.Handled = True
			End If
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: frmCadUniGruposMensagens_KeyPress" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	
	Private Sub frmCadUniGruposMensagens_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Dim vControl As System.Windows.Forms.Control
		Dim lstrKeyPri As String
		Dim lintAux As Short
		Try
			'Call CenterFormQuemChama(Me, ifrmQuemChama)
			istrTabela = "caduni_grupos_mensagens"
			irstTabela = New DataTable
			'ifrmLocalizar = New frmLocalizadorGeralNovo
			Call ctrl_form_LimpaCamposPadrao(Me)
			istrPriKey = ctrl_form_GetChavesKeyTable(istrTabela, "PRIMARY")
			istrForKey = ctrl_form_GetChavesKeyTable(istrTabela, "FOREIGN")
			lstrKeyPri = ctrl_form_MontaPrimaryKeyTable(Me, istrPriKey)
			'Call SetaCodigo(istrTabela, lstrKeyPri)
			'Inicializa a classe de eventos dos objetos TextBox
			lintAux = 0
			'For Each vControl In Me.Controls
			'	'UPGRADE_WARNING: TypeOf has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
			'	If TypeOf vControl Is System.Windows.Forms.TextBox Then
			'		'ReDim Preserve iTextBox(lintAux)
			'		'iTextBox(lintAux) = New clsCtrlEventos
			'		'iTextBox(lintAux).TextBox = vControl
			'		'lintAux = lintAux + 1
			'	End If
			'Next vControl
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: frmCadUniGruposMensagens_Load" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub frmCadUniGruposMensagens_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		Try
			If Not ifrmQuemChama Is Nothing Then ifrmQuemChama.Enabled = True
			ifrmQuemChama = Nothing
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: frmCadUniGruposMensagens_FormClosed" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Public Sub SetaCodigo(ByVal astrTabela As String, ByRef astrPriKey As String)
		'Dim lstrKeyPri As String
		'Try
		'	iblnNovo = False
		'	txtId.Text = astrPriKey
		'	lstrKeyPri = ctrl_form_MontaPrimaryKeyTable(Me, istrPriKey)

		Dim lstrKeyPri As String
		Dim sTabDif As String
		Try

			If astrTabela = "caduni_grupos_mensagens" Then
				iblnNovo = False
				txtId.Text = astrPriKey
				lstrKeyPri = ctrl_form_MontaPrimaryKeyTable(Me, istrPriKey)
			ElseIf astrTabela = "caduni_processos" Then
				txtId_Caduni_Processos.Text = astrPriKey
				sTabDif = "caduni_processos"
				lstrKeyPri = ctrl_form_MontaPrimaryKeyTable(Me, istrPriKey, True, sTabDif)
			ElseIf astrTabela = "caduni_tipos_mensagens" Then
				txtId_Caduni_Tipos_Mensagens.Text = astrPriKey
				sTabDif = "caduni_tipos_mensagens"
				lstrKeyPri = ctrl_form_MontaPrimaryKeyTable(Me, istrPriKey, True, sTabDif)
			ElseIf astrTabela = "caduni_mensagens" Then
				txtId_Caduni_Mensagens.Text = astrPriKey
				sTabDif = "caduni_mensagens"
				lstrKeyPri = ctrl_form_MontaPrimaryKeyTable(Me, istrPriKey, True, sTabDif)
			ElseIf astrTabela = "caduni_grupos" Then
				txtId_Caduni_Grupos.Text = astrPriKey
				sTabDif = "caduni_grupos"
				lstrKeyPri = ctrl_form_MontaPrimaryKeyTable(Me, istrPriKey, True, sTabDif)
			End If

			Call ctrl_form_SetaCodigo(Me, astrTabela, istrTabela, lstrKeyPri, irstTabela)
			'Call ctrl_form_SetaCodigo(Me, astrTabela, istrTabela, astrPriKey, irstTabela)
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: SetaCodigo" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Public Sub SetaParametros(ByRef afrmQuemChama As System.Windows.Forms.Form)
		Try
			ifrmQuemChama = afrmQuemChama
			ifrmQuemChama.Enabled = False
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: SetaParametros" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub cmdLocalizarGrupos_Click_1(sender As Object, e As EventArgs) Handles cmdLocalizarGrupos.Click
		Try
			Call frmLocalizadorGeral.Show()
			Call frmLocalizadorGeral.SetParametros("caduni_grupos", "Cadastro único - grupos", Me)
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdLocalizarGrupos_Click_1" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub cmdLocalizarMensagens_Click_1(sender As Object, e As EventArgs) Handles cmdLocalizarMensagens.Click
		Try
			Call frmLocalizadorGeral.Show()
			Call frmLocalizadorGeral.SetParametros("caduni_mensagens", "Cadastro único - mensagens", Me)
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdLocalizarTiposMensagens_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub

	Private Sub cmdLocalizarTiposMensagens_Click_1(sender As Object, e As EventArgs) Handles cmdLocalizarTiposMensagens.Click
		Try
			Call frmLocalizadorGeral.Show()
			Call frmLocalizadorGeral.SetParametros("caduni_tipos_mensagens", "Cadastro único - tipos mensagens", Me)
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdLocalizarTiposMensagens_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
	Private Sub cmdLocalizarProcessos_Click_1(sender As Object, e As EventArgs) Handles cmdLocalizarProcessos.Click
		Try
			Call frmLocalizadorGeral.Show()
			Call frmLocalizadorGeral.SetParametros("caduni_processos", "Cadastro único - processos", Me)
		Catch ex As Exception
			MessageBox.Show("Ocorreu o Erro: " & Err.Description & " - Rotina: cmdLocalizarProcessos_Click" & "", "Aviso de Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
			Exit Sub
		End Try
	End Sub
End Class