166 lines
6.8 KiB
C#
166 lines
6.8 KiB
C#
using CPM;
|
|
using MLL;
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace UI.Dashboards.Cadastro
|
|
{
|
|
public class ServicosPanel : FormularioModelo
|
|
{
|
|
// Controles marcados como anuláveis para sanar avisos do compilador modernos (NRT)
|
|
private LV_TEXTBOX1? txtId;
|
|
private LV_TEXTBOX1? txtEmpresaId;
|
|
private LV_TEXTBOX1? txtNome;
|
|
private LV_TEXTBOX1? txtDescricao;
|
|
private LV_TEXTBOX1? txtValorPadrao;
|
|
private LV_TEXTBOX1? txtCusto;
|
|
private LV_TEXTBOX1? txtTipoComissao;
|
|
private LV_TEXTBOX1? txtValorComissao;
|
|
private LV_TEXTBOX1? txtTempoEstimado;
|
|
private LV_TEXTBOX1? txtCriadoEm;
|
|
private LV_TEXTBOX1? txtAtualizadoEm;
|
|
private CheckBox? chkAtivo;
|
|
|
|
public ServicosPanel()
|
|
{
|
|
this.Titulo = "CADASTRO E CONFIGURAÇÃO DE SERVIÇOS";
|
|
MontarInterfaceCompleta();
|
|
}
|
|
|
|
private void MontarInterfaceCompleta()
|
|
{
|
|
// --- SEÇÃO 1: IDENTIFICAÇÃO E DADOS GERAIS ---
|
|
content.Controls.Add(CreateSectionHeader("Identificação do Serviço", 20));
|
|
|
|
txtId = AddInput(content, "ID SERVIÇO", 20, 55, 100, 28, true);
|
|
txtEmpresaId = AddInput(content, "ID EMPRESA", 135, 55, 100, 28);
|
|
txtNome = AddInput(content, "NOME DO SERVIÇO", 250, 55, 400, 28);
|
|
|
|
// CheckBox customizado ou nativo alinhado ao grid visual
|
|
chkAtivo = new CheckBox
|
|
{
|
|
Text = "Serviço Ativo",
|
|
Location = new Point(670, 58),
|
|
Size = new Size(120, 24),
|
|
Font = new Font("Segoe UI", 10f, FontStyle.Bold),
|
|
ForeColor = Color.FromArgb(45, 45, 45),
|
|
Checked = true
|
|
};
|
|
content.Controls.Add(chkAtivo);
|
|
|
|
txtDescricao = AddInput(content, "DESCRIÇÃO DETALHADA DO SERVIÇO", 20, 115, 630, 28);
|
|
|
|
// --- SEÇÃO 2: VALORES E PRECIFICAÇÃO ---
|
|
content.Controls.Add(CreateSectionHeader("Precificação, Custos e Regras de Comissão", 185));
|
|
|
|
txtValorPadrao = AddInput(content, "VALOR PADRÃO VENDA (R$)", 20, 220, 180, 28);
|
|
txtCusto = AddInput(content, "CUSTO DO SERVIÇO (R$)", 215, 220, 180, 28);
|
|
txtTipoComissao = AddInput(content, "TIPO COMISSÃO (EX: % OU FIXO)", 410, 220, 220, 28);
|
|
txtValorComissao = AddInput(content, "VALOR COMISSÃO", 645, 220, 145, 28);
|
|
|
|
// --- SEÇÃO 3: OPERAÇÃO E LOG DE AUDITORIA ---
|
|
content.Controls.Add(CreateSectionHeader("Tempo de Execução e Auditoria", 290));
|
|
|
|
txtTempoEstimado = AddInput(content, "TEMPO ESTIMADO (EM MINUTOS)", 20, 325, 220, 28); // Grafia corrigida aqui
|
|
txtCriadoEm = AddInput(content, "DATA DE CRIAÇÃO", 255, 325, 180, 28, true);
|
|
txtAtualizadoEm = AddInput(content, "ÚLTIMA ATUALIZAÇÃO", 445, 325, 180, 28, true);
|
|
}
|
|
|
|
// --- MÉTODOS OBRIGATÓRIOS DO FORMULÁRIO MODELO ---
|
|
|
|
protected override void OnNovo()
|
|
{
|
|
// Varre e limpa os inputs do painel
|
|
foreach (Control c in content.Controls)
|
|
{
|
|
if (c is LV_TEXTBOX1 txt && !txt.ReadOnly)
|
|
{
|
|
txt.Text = string.Empty;
|
|
}
|
|
}
|
|
|
|
if (txtId != null) txtId.Text = "0";
|
|
if (txtEmpresaId != null) txtEmpresaId.Text = "1"; // Default para a empresa ativa principal
|
|
if (txtValorPadrao != null) txtValorPadrao.Text = "0,00";
|
|
if (txtCusto != null) txtCusto.Text = "0,00";
|
|
if (txtValorComissao != null) txtValorComissao.Text = "0,00";
|
|
if (txtTempoEstimado != null) txtTempoEstimado.Text = "0";
|
|
|
|
if (txtCriadoEm != null) txtCriadoEm.Text = DateTime.Now.ToString("g");
|
|
if (txtAtualizadoEm != null) txtAtualizadoEm.Text = DateTime.Now.ToString("g");
|
|
|
|
if (chkAtivo != null) chkAtivo.Checked = true;
|
|
|
|
txtNome?.Focus();
|
|
}
|
|
|
|
protected override void OnSalvar()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(txtNome?.Text))
|
|
{
|
|
MessageBox.Show("O nome do serviço é obrigatório.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
txtNome?.Focus();
|
|
return;
|
|
}
|
|
|
|
// Conversões seguras extraídas dos componentes de texto de forma resiliente
|
|
int idServico = string.IsNullOrEmpty(txtId?.Text) ? 0 : Convert.ToInt32(txtId.Text);
|
|
int idEmpresa = string.IsNullOrEmpty(txtEmpresaId?.Text) ? 0 : Convert.ToInt32(txtEmpresaId.Text);
|
|
|
|
decimal.TryParse(txtValorPadrao?.Text, out decimal vPadrao);
|
|
decimal.TryParse(txtValorComissao?.Text, out decimal vComissao);
|
|
|
|
decimal? vCusto = null;
|
|
if (!string.IsNullOrWhiteSpace(txtCusto?.Text) && decimal.TryParse(txtCusto.Text, out decimal cParsed))
|
|
vCusto = cParsed;
|
|
|
|
int? tEstimado = null;
|
|
if (!string.IsNullOrWhiteSpace(txtTempoEstimado?.Text) && int.TryParse(txtTempoEstimado.Text, out int tParsed))
|
|
tEstimado = tParsed;
|
|
|
|
// Mapeamento cirúrgico de todas as 12 propriedades da classe ModeloServicos
|
|
var servico = new ModeloServicos
|
|
{
|
|
Id = idServico,
|
|
EmpresaId = idEmpresa,
|
|
Nome = txtNome.Text,
|
|
Descricao = txtDescricao?.Text ?? string.Empty,
|
|
ValorPadrao = vPadrao,
|
|
Custo = vCusto,
|
|
TipoComissao = txtTipoComissao?.Text ?? string.Empty,
|
|
ValorComissao = vComissao,
|
|
TempoEstimado = tEstimado,
|
|
Ativo = chkAtivo?.Checked ?? false,
|
|
CriadoEm = string.IsNullOrEmpty(txtCriadoEm?.Text) ? DateTime.Now : Convert.ToDateTime(txtCriadoEm.Text),
|
|
AtualizadoEm = DateTime.Now // Sempre carimba a hora do salvamento atual
|
|
};
|
|
|
|
// Aqui o objeto 'servico' está pronto para ser enviado para sua camada de persistência (BLL / DAL)
|
|
MessageBox.Show($"Serviço '{servico.Nome}' salvo com sucesso!", "LevelOS", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
protected override void OnAlterar()
|
|
{
|
|
txtNome?.Focus();
|
|
}
|
|
|
|
protected override void OnExcluir()
|
|
{
|
|
if (MessageBox.Show("Deseja realmente remover este serviço do catálogo?", "LevelOS", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
|
|
{
|
|
OnNovo();
|
|
}
|
|
}
|
|
|
|
protected override void OnLocalizar()
|
|
{
|
|
// Vinculado à Grid de busca global de serviços
|
|
}
|
|
|
|
protected override void OnCancelar()
|
|
{
|
|
OnNovo();
|
|
}
|
|
}
|
|
} |