164 lines
5.8 KiB
C#
164 lines
5.8 KiB
C#
using CPM;
|
|
using MLL;
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace UI.Dashboards.Cadastro
|
|
{
|
|
public class UsuarioPerfisPanel : FormularioModelo
|
|
{
|
|
// Controles marcados como anuláveis para sanar avisos do compilador modernos (NRT)
|
|
private LV_TEXTBOX1? txtId;
|
|
private ComboBox? cbUsuario;
|
|
private CheckedListBox? clbPerfis;
|
|
|
|
public UsuarioPerfisPanel()
|
|
{
|
|
this.Titulo = "VÍNCULO DE PERFIS DE ACESSO POR USUÁRIO";
|
|
MontarInterfaceCompleta();
|
|
}
|
|
|
|
private void MontarInterfaceCompleta()
|
|
{
|
|
// --- SEÇÃO 1: IDENTIFICAÇÃO E SELEÇÃO DO USUÁRIO ---
|
|
content.Controls.Add(CreateSectionHeader("Seleção do Operador / Usuário", 20));
|
|
|
|
txtId = AddInput(content, "ID VÍNCULO", 20, 55, 100, 28, true);
|
|
|
|
// Label para o ComboBox de Usuário
|
|
var lblUsuario = new Label
|
|
{
|
|
Text = "SELECIONE O USUÁRIO DO SISTEMA",
|
|
Location = new Point(135, 40),
|
|
AutoSize = true,
|
|
Font = new Font("Segoe UI", 8.25f, FontStyle.Bold),
|
|
ForeColor = Color.FromArgb(90, 90, 90)
|
|
};
|
|
|
|
cbUsuario = new ComboBox
|
|
{
|
|
Location = new Point(135, 57),
|
|
Size = new Size(500, 28),
|
|
DropDownStyle = ComboBoxStyle.DropDownList,
|
|
Font = new Font("Segoe UI", 10f)
|
|
};
|
|
|
|
content.Controls.AddRange(new Control[] { lblUsuario, cbUsuario });
|
|
|
|
// --- SEÇÃO 2: ATRIBUIÇÃO DOS PERFIS ---
|
|
content.Controls.Add(CreateSectionHeader("Perfis de Segurança e Permissões Disponíveis", 115));
|
|
|
|
// CheckedListBox para o operador marcar múltiplos perfis de forma nativa e intuitiva
|
|
clbPerfis = new CheckedListBox
|
|
{
|
|
Location = new Point(20, 150),
|
|
Size = new Size(615, 250),
|
|
Font = new Font("Segoe UI", 10f),
|
|
CheckOnClick = true,
|
|
BorderStyle = BorderStyle.FixedSingle
|
|
};
|
|
content.Controls.Add(clbPerfis);
|
|
|
|
CarregarDadosIniciais();
|
|
}
|
|
|
|
private void CarregarDadosIniciais()
|
|
{
|
|
// Simulação de preenchimento dos combos (Aqui você chamará suas BLLs correspondentes)
|
|
if (cbUsuario != null)
|
|
{
|
|
cbUsuario.Items.Add("Selecione um operador...");
|
|
cbUsuario.Items.Add("Nicolas - Administrador do Sistema");
|
|
cbUsuario.Items.Add("Davi - Operador de Caixa");
|
|
cbUsuario.SelectedIndex = 0;
|
|
}
|
|
|
|
if (clbPerfis != null)
|
|
{
|
|
clbPerfis.Items.Add("ADMINISTRADOR GLOBAL");
|
|
clbPerfis.Items.Add("FANCEIRO / CONTÁBIL");
|
|
clbPerfis.Items.Add("VENDEDOR / EMISSOR NFC-E");
|
|
clbPerfis.Items.Add("SUPORTE TÉCNICO (ORDEM DE SERVIÇO)");
|
|
}
|
|
}
|
|
|
|
// --- MÉTODOS OBRIGATÓRIOS DO FORMULÁRIO MODELO ---
|
|
|
|
protected override void OnNovo()
|
|
{
|
|
if (txtId != null) txtId.Text = "0";
|
|
|
|
if (cbUsuario != null && cbUsuario.Items.Count > 0)
|
|
cbUsuario.SelectedIndex = 0;
|
|
|
|
if (clbPerfis != null)
|
|
{
|
|
for (int i = 0; i < clbPerfis.Items.Count; i++)
|
|
{
|
|
clbPerfis.SetItemChecked(i, false);
|
|
}
|
|
}
|
|
|
|
cbUsuario?.Focus();
|
|
}
|
|
|
|
protected override void OnSalvar()
|
|
{
|
|
if (cbUsuario == null || cbUsuario.SelectedIndex <= 0)
|
|
{
|
|
MessageBox.Show("Por favor, selecione um usuário válido para aplicar as permissões.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
cbUsuario?.Focus();
|
|
return;
|
|
}
|
|
|
|
if (clbPerfis == null || clbPerfis.CheckedItems.Count == 0)
|
|
{
|
|
MessageBox.Show("Selecione ao menos um perfil de acesso para este usuário.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
clbPerfis?.Focus();
|
|
return;
|
|
}
|
|
|
|
int idVinculo = string.IsNullOrEmpty(txtId?.Text) ? 0 : Convert.ToInt32(txtId.Text);
|
|
|
|
// Loop para ler os perfis checados e montar os objetos associativos
|
|
// Como é uma tabela NxN, você gerará um registro para cada Perfil Id associado àquele UsuarioId
|
|
foreach (var itemMarcado in clbPerfis.CheckedItems)
|
|
{
|
|
var usuarioPerfil = new ModeloUsuarioPerfis
|
|
{
|
|
Id = idVinculo,
|
|
UsuarioId = cbUsuario.SelectedIndex, // Mock simulando o ID recuperado do ValueMember
|
|
PerfilId = clbPerfis.Items.IndexOf(itemMarcado) + 1 // Mock simulando o ID do Perfil
|
|
};
|
|
|
|
// Aqui sua BLL/DAL processará cada vínculo (Inserindo ou deletando os antigos antes)
|
|
}
|
|
|
|
MessageBox.Show("Políticas e perfis de acesso atualizados com sucesso!", "LevelOS - Segurança", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
protected override void OnAlterar()
|
|
{
|
|
cbUsuario?.Focus();
|
|
}
|
|
|
|
protected override void OnExcluir()
|
|
{
|
|
if (MessageBox.Show("Deseja revogar TODOS os perfis de acesso deste usuário? O operador perderá acesso às telas do sistema.", "LevelOS - Segurança", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
|
|
{
|
|
OnNovo();
|
|
}
|
|
}
|
|
|
|
protected override void OnLocalizar()
|
|
{
|
|
// Vinculado à busca global de associações de segurança
|
|
}
|
|
|
|
protected override void OnCancelar()
|
|
{
|
|
OnNovo();
|
|
}
|
|
}
|
|
} |