331 lines
13 KiB
C#
331 lines
13 KiB
C#
using CPM;
|
|
using DAL;
|
|
using MLL;
|
|
using BLL;
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace UI
|
|
{
|
|
public class CalibracaoEnsaioCadastroPanel : FormularioModelo
|
|
{
|
|
// ── CAMPOS DO FORMULÁRIO ──────────────────────────────────────────────
|
|
private LV_TEXTBOX1 txtId = null!;
|
|
private LV_TEXTBOX1 txtCodCalibracao = null!;
|
|
private Button btnBuscarCod = null!;
|
|
private LV_TEXTBOX1 txtDescricao = null!;
|
|
private LV_TEXTBOX1 txtMinimo = null!;
|
|
private LV_TEXTBOX1 txtMaximo = null!;
|
|
private LV_TEXTBOX1 txtObtido = null!;
|
|
private LV_TEXTBOX1 txtUnidade = null!;
|
|
|
|
// ── ESTADO ────────────────────────────────────────────────────────────
|
|
private enum ModoFormulario { Visualizacao, Novo, Edicao }
|
|
private ModoFormulario _modo = ModoFormulario.Visualizacao;
|
|
private int _idAtual = 0;
|
|
|
|
// ── BLL ───────────────────────────────────────────────────────────────
|
|
// private CalibracaoEnsaioBLL _bll = null!;
|
|
|
|
// ── CONSTRUTOR ────────────────────────────────────────────────────────
|
|
public CalibracaoEnsaioCadastroPanel()
|
|
{
|
|
Titulo = "Cadastro de Ensaios de Calibração";
|
|
BuildForm();
|
|
AplicarModo(ModoFormulario.Visualizacao);
|
|
}
|
|
|
|
// ── CONSTRUÇÃO DOS CAMPOS ─────────────────────────────────────────────
|
|
private void BuildForm()
|
|
{
|
|
// ── SEÇÃO: IDENTIFICAÇÃO ──────────────────────────────────────────
|
|
content.Controls.Add(CreateSectionHeader("Identificação", 20));
|
|
|
|
txtId = AddInput(content, "ID", 20, 58, 80, 32, readOnly: true);
|
|
|
|
// Código da Calibração + botão buscar
|
|
var lblCod = new Label
|
|
{
|
|
Text = "Código da Calibração",
|
|
Location = new Point(120, 58),
|
|
Font = new Font("Segoe UI", 7.5f, FontStyle.Bold),
|
|
ForeColor = TextDark,
|
|
AutoSize = true
|
|
};
|
|
|
|
txtCodCalibracao = new LV_TEXTBOX1
|
|
{
|
|
Location = new Point(120, 74),
|
|
Size = new Size(220, 32),
|
|
BorderColor = BorderColor,
|
|
BorderFocusColor = AccentBlue,
|
|
ReadOnly = true, // sempre preenchido via busca
|
|
BackColor = ReadOnlyBg
|
|
};
|
|
|
|
btnBuscarCod = new Button
|
|
{
|
|
Text = "🔍 Buscar",
|
|
Location = new Point(348, 74),
|
|
Size = new Size(90, 32),
|
|
BackColor = AccentBlue,
|
|
ForeColor = Color.White,
|
|
Font = new Font("Segoe UI Semibold", 8.5f),
|
|
Cursor = Cursors.Hand,
|
|
FlatStyle = FlatStyle.Flat,
|
|
Enabled = false // habilitado apenas em modo edição
|
|
};
|
|
btnBuscarCod.FlatAppearance.BorderSize = 0;
|
|
btnBuscarCod.Click += BtnBuscarCod_Click;
|
|
|
|
content.Controls.Add(lblCod);
|
|
content.Controls.Add(txtCodCalibracao);
|
|
content.Controls.Add(btnBuscarCod);
|
|
|
|
// ── SEÇÃO: ENSAIO ─────────────────────────────────────────────────
|
|
content.Controls.Add(CreateSectionHeader("Dados do Ensaio", 130));
|
|
|
|
txtDescricao = AddInput(content, "Descrição", 20, 168, 500, 32);
|
|
txtDescricao.MaxLength = 255;
|
|
|
|
txtUnidade = AddInput(content, "Unidade", 540, 168, 160, 32);
|
|
txtUnidade.MaxLength = 50;
|
|
|
|
// ── SEÇÃO: VALORES ────────────────────────────────────────────────
|
|
content.Controls.Add(CreateSectionHeader("Valores", 230));
|
|
|
|
txtMinimo = AddInput(content, "Mínimo", 20, 268, 180, 32);
|
|
txtMinimo.MaxLength = 50;
|
|
|
|
txtMaximo = AddInput(content, "Máximo", 220, 268, 180, 32);
|
|
txtMaximo.MaxLength = 50;
|
|
|
|
txtObtido = AddInput(content, "Obtido", 420, 268, 180, 32);
|
|
txtObtido.MaxLength = 50;
|
|
|
|
content.Height = 340;
|
|
}
|
|
|
|
// ── MODOS DO FORMULÁRIO ───────────────────────────────────────────────
|
|
private void AplicarModo(ModoFormulario modo)
|
|
{
|
|
_modo = modo;
|
|
|
|
bool editando = modo == ModoFormulario.Novo || modo == ModoFormulario.Edicao;
|
|
|
|
// Botão buscar só disponível ao editar
|
|
btnBuscarCod.Enabled = editando;
|
|
|
|
// Campos editáveis
|
|
txtDescricao.ReadOnly = !editando;
|
|
txtMinimo.ReadOnly = !editando;
|
|
txtMaximo.ReadOnly = !editando;
|
|
txtObtido.ReadOnly = !editando;
|
|
txtUnidade.ReadOnly = !editando;
|
|
|
|
// Cores
|
|
Color bgAtivo = Color.White;
|
|
Color bgInativo = ReadOnlyBg;
|
|
|
|
txtDescricao.BackColor = editando ? bgAtivo : bgInativo;
|
|
txtMinimo.BackColor = editando ? bgAtivo : bgInativo;
|
|
txtMaximo.BackColor = editando ? bgAtivo : bgInativo;
|
|
txtObtido.BackColor = editando ? bgAtivo : bgInativo;
|
|
txtUnidade.BackColor = editando ? bgAtivo : bgInativo;
|
|
|
|
// Bordas
|
|
txtDescricao.BorderColor = editando ? BorderColor : ReadOnlyBorder;
|
|
txtMinimo.BorderColor = editando ? BorderColor : ReadOnlyBorder;
|
|
txtMaximo.BorderColor = editando ? BorderColor : ReadOnlyBorder;
|
|
txtObtido.BorderColor = editando ? BorderColor : ReadOnlyBorder;
|
|
txtUnidade.BorderColor = editando ? BorderColor : ReadOnlyBorder;
|
|
|
|
// Botões toolbar
|
|
btnNovo.Enabled = !editando;
|
|
btnAlterar.Enabled = !editando && _idAtual > 0;
|
|
btnExcluir.Enabled = !editando && _idAtual > 0;
|
|
btnLocalizar.Enabled = !editando;
|
|
btnSalvar.Enabled = editando;
|
|
btnCancelar.Enabled = editando;
|
|
|
|
if (modo == ModoFormulario.Novo) LimparCampos();
|
|
}
|
|
|
|
// ── POPULAR / LIMPAR ──────────────────────────────────────────────────
|
|
private void PopularCampos(ModeloCalibracaoEnsaio m)
|
|
{
|
|
_idAtual = m.ID_CALIBRACAO_ENSAIO;
|
|
|
|
txtId.Text = m.ID_CALIBRACAO_ENSAIO.ToString();
|
|
txtCodCalibracao.Text = m.COD_CALIBRACAO;
|
|
txtDescricao.Text = m.DESCRICAO;
|
|
txtMinimo.Text = m.MINIMO;
|
|
txtMaximo.Text = m.MAXIMO;
|
|
txtObtido.Text = m.OBTIDO;
|
|
txtUnidade.Text = m.UNIDADE;
|
|
}
|
|
|
|
private void LimparCampos()
|
|
{
|
|
_idAtual = 0;
|
|
|
|
txtId.Text = string.Empty;
|
|
txtCodCalibracao.Text = string.Empty;
|
|
txtDescricao.Text = string.Empty;
|
|
txtMinimo.Text = string.Empty;
|
|
txtMaximo.Text = string.Empty;
|
|
txtObtido.Text = string.Empty;
|
|
txtUnidade.Text = string.Empty;
|
|
}
|
|
|
|
// ── BUSCA DE CALIBRAÇÃO ───────────────────────────────────────────────
|
|
private void BtnBuscarCod_Click(object? sender, EventArgs e)
|
|
{
|
|
// TODO: abrir formulário de busca de calibrações e retornar o código
|
|
// Exemplo:
|
|
// var frm = new FormularioBuscarCalibracao();
|
|
// if (frm.ShowDialog() == DialogResult.OK)
|
|
// txtCodCalibracao.Text = frm.CodigoSelecionado;
|
|
|
|
MessageBox.Show("Implemente o formulário de busca de calibrações.",
|
|
"Buscar Calibração", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
// ── VALIDAÇÃO ─────────────────────────────────────────────────────────
|
|
private bool Validar()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(txtCodCalibracao.Text))
|
|
{
|
|
MessageBox.Show("Selecione uma calibração.", "Validação",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
btnBuscarCod.Focus();
|
|
return false;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(txtDescricao.Text))
|
|
{
|
|
MessageBox.Show("Informe a descrição do ensaio.", "Validação",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
txtDescricao.Focus();
|
|
return false;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(txtUnidade.Text))
|
|
{
|
|
MessageBox.Show("Informe a unidade de medida.", "Validação",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
txtUnidade.Focus();
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// ── MONTAR MODELO ─────────────────────────────────────────────────────
|
|
private ModeloCalibracaoEnsaio MontarModelo() => new ModeloCalibracaoEnsaio(
|
|
_idAtual,
|
|
txtCodCalibracao.Text.Trim(),
|
|
txtDescricao.Text.Trim(),
|
|
txtMinimo.Text.Trim(),
|
|
txtMaximo.Text.Trim(),
|
|
txtObtido.Text.Trim(),
|
|
txtUnidade.Text.Trim()
|
|
);
|
|
|
|
// ── EVENTOS ABSTRATOS ─────────────────────────────────────────────────
|
|
protected override void OnNovo()
|
|
{
|
|
AplicarModo(ModoFormulario.Novo);
|
|
btnBuscarCod.Focus();
|
|
}
|
|
|
|
protected override void OnAlterar()
|
|
{
|
|
if (_idAtual == 0) return;
|
|
AplicarModo(ModoFormulario.Edicao);
|
|
txtDescricao.Focus();
|
|
}
|
|
|
|
protected override void OnExcluir()
|
|
{
|
|
if (_idAtual == 0) return;
|
|
|
|
var confirm = MessageBox.Show(
|
|
$"Deseja realmente excluir o ensaio \"{txtDescricao.Text}\"?",
|
|
"Confirmar exclusão",
|
|
MessageBoxButtons.YesNo,
|
|
MessageBoxIcon.Warning);
|
|
|
|
if (confirm != DialogResult.Yes) return;
|
|
|
|
try
|
|
{
|
|
// TODO: _bll.Excluir(_idAtual);
|
|
MessageBox.Show("Ensaio excluído com sucesso.", "Sucesso",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
LimparCampos();
|
|
AplicarModo(ModoFormulario.Visualizacao);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"Erro ao excluir:\n{ex.Message}", "Erro",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
protected override void OnLocalizar()
|
|
{
|
|
// TODO: abrir formulário de busca de ensaios
|
|
// var frm = new FormularioBuscarCalibracaoEnsaio();
|
|
// if (frm.ShowDialog() == DialogResult.OK)
|
|
// {
|
|
// PopularCampos(frm.EnsaioSelecionado);
|
|
// AplicarModo(ModoFormulario.Visualizacao);
|
|
// }
|
|
|
|
MessageBox.Show("Implemente o formulário de busca de ensaios.",
|
|
"Localizar", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
protected override void OnSalvar()
|
|
{
|
|
if (!Validar()) return;
|
|
|
|
var modelo = MontarModelo();
|
|
|
|
try
|
|
{
|
|
if (_modo == ModoFormulario.Novo)
|
|
{
|
|
// TODO: _bll.Criar(modelo);
|
|
MessageBox.Show("Ensaio cadastrado com sucesso!", "Sucesso",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
else
|
|
{
|
|
// TODO: _bll.Atualizar(modelo);
|
|
MessageBox.Show("Ensaio atualizado com sucesso!", "Sucesso",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
AplicarModo(ModoFormulario.Visualizacao);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"Erro ao salvar:\n{ex.Message}", "Erro",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
protected override void OnCancelar()
|
|
{
|
|
if (_idAtual > 0)
|
|
{
|
|
// TODO: recarregar do banco se necessário
|
|
}
|
|
LimparCampos();
|
|
AplicarModo(ModoFormulario.Visualizacao);
|
|
}
|
|
}
|
|
} |