508 lines
20 KiB
C#
508 lines
20 KiB
C#
using CPM;
|
|
using DAL;
|
|
using MLL;
|
|
using BLL;
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace UI
|
|
{
|
|
public class ChamadoCadastroPanel : FormularioModelo
|
|
{
|
|
// ── CAMPOS DO FORMULÁRIO ──────────────────────────────────────────────
|
|
private LV_TEXTBOX1 txtId = null!;
|
|
private LV_TEXTBOX1 txtCodigo = null!;
|
|
private LV_COMBOBOXCUSTOM cmbTipo = null!;
|
|
private LV_COMBOBOXCUSTOM cmbPrioridade = null!;
|
|
|
|
// Cliente — busca + campos auto-preenchidos
|
|
private LV_TEXTBOX1 txtCodCliente = null!;
|
|
private Button btnBuscarCliente = null!;
|
|
private LV_TEXTBOX1 txtNomeAvulso = null!;
|
|
private LV_TEXTBOX1 txtFones = null!;
|
|
private LV_TEXTBOX1 txtEmail = null!;
|
|
private LV_TEXTBOX1 txtEnderCli = null!;
|
|
|
|
private LV_TEXTBOX1 txtPara = null!;
|
|
private LV_TEXTBOX1 txtRealizado = null!;
|
|
private LV_TEXTBOX1 txtDiaChamado = null!;
|
|
private LV_TEXTBOX1 txtObs = null!;
|
|
|
|
// ── ESTADO ────────────────────────────────────────────────────────────
|
|
private enum ModoFormulario { Visualizacao, Novo, Edicao }
|
|
private ModoFormulario _modo = ModoFormulario.Visualizacao;
|
|
private int _idAtual = 0;
|
|
|
|
// ── BLL ───────────────────────────────────────────────────────────────
|
|
// private ChamadoBLL _bll = null!;
|
|
|
|
// ── CONSTRUTOR ────────────────────────────────────────────────────────
|
|
public ChamadoCadastroPanel()
|
|
{
|
|
Titulo = "Cadastro de Chamados";
|
|
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);
|
|
txtCodigo = AddInput(content, "Código", 120, 58, 160, 32);
|
|
txtCodigo.MaxLength = 50;
|
|
|
|
// Tipo
|
|
var lblTipo = new Label
|
|
{
|
|
Text = "Tipo",
|
|
Location = new Point(300, 58),
|
|
Font = new Font("Segoe UI", 7.5f, FontStyle.Bold),
|
|
ForeColor = TextDark,
|
|
AutoSize = true
|
|
};
|
|
cmbTipo = new LV_COMBOBOXCUSTOM
|
|
{
|
|
Location = new Point(300, 74),
|
|
Size = new Size(180, 32),
|
|
DropDownStyle = ComboBoxStyle.DropDownList,
|
|
BorderColor = BorderColor,
|
|
BackColor = Color.White,
|
|
ListBackColor = Color.White,
|
|
ListTextColor = TextDark,
|
|
IconColor = AccentBlue,
|
|
Font = new Font("Segoe UI", 9f)
|
|
};
|
|
cmbTipo.Items.Add("Suporte Técnico");
|
|
cmbTipo.Items.Add("Manutenção");
|
|
cmbTipo.Items.Add("Instalação");
|
|
cmbTipo.Items.Add("Consultoria");
|
|
cmbTipo.Items.Add("Reclamação");
|
|
cmbTipo.Items.Add("Outro");
|
|
cmbTipo.SelectedIndex = 0;
|
|
content.Controls.Add(lblTipo);
|
|
content.Controls.Add(cmbTipo);
|
|
|
|
// Prioridade
|
|
var lblPrioridade = new Label
|
|
{
|
|
Text = "Prioridade",
|
|
Location = new Point(500, 58),
|
|
Font = new Font("Segoe UI", 7.5f, FontStyle.Bold),
|
|
ForeColor = TextDark,
|
|
AutoSize = true
|
|
};
|
|
cmbPrioridade = new LV_COMBOBOXCUSTOM
|
|
{
|
|
Location = new Point(500, 74),
|
|
Size = new Size(160, 32),
|
|
DropDownStyle = ComboBoxStyle.DropDownList,
|
|
BorderColor = BorderColor,
|
|
BackColor = Color.White,
|
|
ListBackColor = Color.White,
|
|
ListTextColor = TextDark,
|
|
IconColor = AccentBlue,
|
|
Font = new Font("Segoe UI", 9f)
|
|
};
|
|
cmbPrioridade.Items.Add("Baixa");
|
|
cmbPrioridade.Items.Add("Normal");
|
|
cmbPrioridade.Items.Add("Alta");
|
|
cmbPrioridade.Items.Add("Urgente");
|
|
cmbPrioridade.SelectedIndex = 1; // Normal como padrão
|
|
content.Controls.Add(lblPrioridade);
|
|
content.Controls.Add(cmbPrioridade);
|
|
|
|
// ── SEÇÃO: CLIENTE ────────────────────────────────────────────────
|
|
content.Controls.Add(CreateSectionHeader("Cliente", 128));
|
|
|
|
// Cód. Cliente + botão buscar
|
|
var lblCodCliente = new Label
|
|
{
|
|
Text = "Cód. Cliente",
|
|
Location = new Point(20, 166),
|
|
Font = new Font("Segoe UI", 7.5f, FontStyle.Bold),
|
|
ForeColor = TextDark,
|
|
AutoSize = true
|
|
};
|
|
txtCodCliente = new LV_TEXTBOX1
|
|
{
|
|
Location = new Point(20, 182),
|
|
Size = new Size(160, 32),
|
|
BorderColor = BorderColor,
|
|
BorderFocusColor = AccentBlue,
|
|
ReadOnly = true,
|
|
BackColor = ReadOnlyBg
|
|
};
|
|
btnBuscarCliente = new Button
|
|
{
|
|
Text = "🔍 Buscar",
|
|
Location = new Point(188, 182),
|
|
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
|
|
};
|
|
btnBuscarCliente.FlatAppearance.BorderSize = 0;
|
|
btnBuscarCliente.Click += BtnBuscarCliente_Click;
|
|
|
|
content.Controls.Add(lblCodCliente);
|
|
content.Controls.Add(txtCodCliente);
|
|
content.Controls.Add(btnBuscarCliente);
|
|
|
|
txtNomeAvulso = AddInput(content, "Nome Avulso", 298, 166, 280, 32);
|
|
txtNomeAvulso.MaxLength = 150;
|
|
|
|
// Fones — readonly, preenchido via busca
|
|
var lblFones = new Label
|
|
{
|
|
Text = "Fones",
|
|
Location = new Point(20, 234),
|
|
Font = new Font("Segoe UI", 7.5f, FontStyle.Bold),
|
|
ForeColor = Color.Gray,
|
|
AutoSize = true
|
|
};
|
|
txtFones = new LV_TEXTBOX1
|
|
{
|
|
Location = new Point(20, 250),
|
|
Size = new Size(200, 32),
|
|
BorderColor = ReadOnlyBorder,
|
|
BorderFocusColor = AccentBlue,
|
|
ReadOnly = true,
|
|
BackColor = ReadOnlyBg
|
|
};
|
|
content.Controls.Add(lblFones);
|
|
content.Controls.Add(txtFones);
|
|
|
|
txtEmail = AddInput(content, "E-mail", 240, 234, 240, 32);
|
|
txtEmail.MaxLength = 150;
|
|
|
|
// Endereço — readonly, preenchido via busca
|
|
var lblEnderCli = new Label
|
|
{
|
|
Text = "Endereço",
|
|
Location = new Point(20, 302),
|
|
Font = new Font("Segoe UI", 7.5f, FontStyle.Bold),
|
|
ForeColor = Color.Gray,
|
|
AutoSize = true
|
|
};
|
|
txtEnderCli = new LV_TEXTBOX1
|
|
{
|
|
Location = new Point(20, 318),
|
|
Size = new Size(680, 32),
|
|
BorderColor = ReadOnlyBorder,
|
|
BorderFocusColor = AccentBlue,
|
|
ReadOnly = true,
|
|
BackColor = ReadOnlyBg
|
|
};
|
|
content.Controls.Add(lblEnderCli);
|
|
content.Controls.Add(txtEnderCli);
|
|
|
|
// ── SEÇÃO: CHAMADO ────────────────────────────────────────────────
|
|
content.Controls.Add(CreateSectionHeader("Chamado", 370));
|
|
|
|
txtPara = AddInput(content, "Para", 20, 408, 260, 32);
|
|
txtPara.MaxLength = 100;
|
|
|
|
txtDiaChamado = AddInput(content, "Data", 300, 408, 160, 32);
|
|
txtDiaChamado.MaxLength = 20;
|
|
|
|
txtRealizado = AddInput(content, "Realizado", 480, 408, 220, 32);
|
|
txtRealizado.MaxLength = 50;
|
|
|
|
// Observações — multiline
|
|
var lblObs = new Label
|
|
{
|
|
Text = "Observações",
|
|
Location = new Point(20, 460),
|
|
Font = new Font("Segoe UI", 7.5f, FontStyle.Bold),
|
|
ForeColor = TextDark,
|
|
AutoSize = true
|
|
};
|
|
txtObs = new LV_TEXTBOX1
|
|
{
|
|
Location = new Point(20, 476),
|
|
Size = new Size(680, 70),
|
|
BorderColor = BorderColor,
|
|
BorderFocusColor = AccentBlue,
|
|
Multiline = true,
|
|
MaxLength = 500
|
|
};
|
|
content.Controls.Add(lblObs);
|
|
content.Controls.Add(txtObs);
|
|
|
|
content.Height = 580;
|
|
}
|
|
|
|
// ── CAMPOS EDITÁVEIS ──────────────────────────────────────────────────
|
|
private LV_TEXTBOX1[] CamposEditaveis() => new[]
|
|
{
|
|
txtCodigo, txtNomeAvulso, txtEmail,
|
|
txtPara, txtDiaChamado, txtRealizado, txtObs
|
|
};
|
|
|
|
// ── MODOS DO FORMULÁRIO ───────────────────────────────────────────────
|
|
private void AplicarModo(ModoFormulario modo)
|
|
{
|
|
_modo = modo;
|
|
|
|
bool editando = modo == ModoFormulario.Novo || modo == ModoFormulario.Edicao;
|
|
|
|
// Campos editáveis normais
|
|
foreach (var txt in CamposEditaveis())
|
|
{
|
|
txt.ReadOnly = !editando;
|
|
txt.BackColor = editando ? Color.White : ReadOnlyBg;
|
|
txt.BorderColor = editando ? BorderColor : ReadOnlyBorder;
|
|
}
|
|
|
|
// Botão buscar cliente — só em modo edição
|
|
btnBuscarCliente.Enabled = editando;
|
|
|
|
// ComboBoxes
|
|
cmbTipo.Enabled = editando;
|
|
cmbTipo.BorderColor = editando ? BorderColor : ReadOnlyBorder;
|
|
cmbTipo.BackColor = editando ? Color.White : ReadOnlyBg;
|
|
|
|
cmbPrioridade.Enabled = editando;
|
|
cmbPrioridade.BorderColor = editando ? BorderColor : ReadOnlyBorder;
|
|
cmbPrioridade.BackColor = editando ? Color.White : ReadOnlyBg;
|
|
|
|
// Fones e Endereço: sempre readonly — só mudam via busca de cliente
|
|
txtFones.BorderColor = ReadOnlyBorder;
|
|
txtFones.BackColor = ReadOnlyBg;
|
|
txtEnderCli.BorderColor = ReadOnlyBorder;
|
|
txtEnderCli.BackColor = ReadOnlyBg;
|
|
|
|
// 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();
|
|
}
|
|
|
|
// ── BUSCA DE CLIENTE ──────────────────────────────────────────────────
|
|
private void BtnBuscarCliente_Click(object? sender, EventArgs e)
|
|
{
|
|
// TODO: abrir formulário de busca de clientes e retornar dados
|
|
// var frm = new FormularioBuscarCliente();
|
|
// if (frm.ShowDialog() == DialogResult.OK)
|
|
// {
|
|
// var cli = frm.ClienteSelecionado;
|
|
// txtCodCliente.Text = cli.CODIGO;
|
|
// txtFones.Text = cli.FONE;
|
|
// txtEnderCli.Text = cli.ENDERECO;
|
|
// }
|
|
|
|
MessageBox.Show("Implemente o formulário de busca de clientes.",
|
|
"Buscar Cliente", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
// ── POPULAR / LIMPAR ──────────────────────────────────────────────────
|
|
private void PopularCampos(ModeloChamado m)
|
|
{
|
|
_idAtual = m.ID_CHAMADO;
|
|
|
|
txtId.Text = m.ID_CHAMADO.ToString();
|
|
txtCodigo.Text = m.CODIGO;
|
|
txtCodCliente.Text = m.COD_CLIENTE;
|
|
txtNomeAvulso.Text = m.NOME_AVULSO;
|
|
txtFones.Text = m.FONES;
|
|
txtEmail.Text = m.EMAIL;
|
|
txtEnderCli.Text = m.ENDER_CLI;
|
|
txtPara.Text = m.PARA;
|
|
txtRealizado.Text = m.REALIZADO;
|
|
txtDiaChamado.Text = m.DIA_CHAMADO;
|
|
txtObs.Text = m.OBS;
|
|
|
|
SelecionarCombo(cmbTipo, m.TIPO);
|
|
SelecionarCombo(cmbPrioridade, m.PRIORIDADE);
|
|
}
|
|
|
|
private void LimparCampos()
|
|
{
|
|
_idAtual = 0;
|
|
|
|
txtId.Text = string.Empty;
|
|
txtCodigo.Text = string.Empty;
|
|
txtCodCliente.Text = string.Empty;
|
|
txtNomeAvulso.Text = string.Empty;
|
|
txtFones.Text = string.Empty;
|
|
txtEmail.Text = string.Empty;
|
|
txtEnderCli.Text = string.Empty;
|
|
txtPara.Text = string.Empty;
|
|
txtRealizado.Text = string.Empty;
|
|
txtDiaChamado.Text = string.Empty;
|
|
txtObs.Text = string.Empty;
|
|
|
|
cmbTipo.SelectedIndex = 0;
|
|
cmbPrioridade.SelectedIndex = 1; // Normal
|
|
}
|
|
|
|
// ── HELPER: SELECIONAR ITEM NO COMBOBOX ───────────────────────────────
|
|
private static void SelecionarCombo(LV_COMBOBOXCUSTOM cmb, string valor)
|
|
{
|
|
for (int i = 0; i < cmb.Items.Count; i++)
|
|
{
|
|
if (cmb.Items[i]?.ToString() == valor)
|
|
{
|
|
cmb.SelectedIndex = i;
|
|
return;
|
|
}
|
|
}
|
|
cmb.SelectedIndex = 0;
|
|
}
|
|
|
|
// ── VALIDAÇÃO ─────────────────────────────────────────────────────────
|
|
private bool Validar()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(txtCodigo.Text))
|
|
{
|
|
MessageBox.Show("Informe o código do chamado.", "Validação",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
txtCodigo.Focus();
|
|
return false;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(txtCodCliente.Text) &&
|
|
string.IsNullOrWhiteSpace(txtNomeAvulso.Text))
|
|
{
|
|
MessageBox.Show("Informe o cliente ou o nome avulso.", "Validação",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
btnBuscarCliente.Focus();
|
|
return false;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(txtDiaChamado.Text))
|
|
{
|
|
MessageBox.Show("Informe a data do chamado.", "Validação",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
txtDiaChamado.Focus();
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// ── MONTAR MODELO ─────────────────────────────────────────────────────
|
|
private ModeloChamado MontarModelo() => new ModeloChamado(
|
|
_idAtual,
|
|
txtCodigo.Text.Trim(),
|
|
cmbTipo.SelectedItem?.ToString() ?? string.Empty,
|
|
txtCodCliente.Text.Trim(),
|
|
txtNomeAvulso.Text.Trim(),
|
|
txtFones.Text.Trim(),
|
|
txtEmail.Text.Trim(),
|
|
txtPara.Text.Trim(),
|
|
cmbPrioridade.SelectedItem?.ToString() ?? string.Empty,
|
|
txtRealizado.Text.Trim(),
|
|
txtDiaChamado.Text.Trim(),
|
|
txtObs.Text.Trim(),
|
|
txtEnderCli.Text.Trim()
|
|
);
|
|
|
|
// ── EVENTOS ABSTRATOS ─────────────────────────────────────────────────
|
|
protected override void OnNovo()
|
|
{
|
|
AplicarModo(ModoFormulario.Novo);
|
|
txtCodigo.Focus();
|
|
}
|
|
|
|
protected override void OnAlterar()
|
|
{
|
|
if (_idAtual == 0) return;
|
|
AplicarModo(ModoFormulario.Edicao);
|
|
txtCodigo.Focus();
|
|
}
|
|
|
|
protected override void OnExcluir()
|
|
{
|
|
if (_idAtual == 0) return;
|
|
|
|
var confirm = MessageBox.Show(
|
|
$"Deseja realmente excluir o chamado \"{txtCodigo.Text}\"?",
|
|
"Confirmar exclusão",
|
|
MessageBoxButtons.YesNo,
|
|
MessageBoxIcon.Warning);
|
|
|
|
if (confirm != DialogResult.Yes) return;
|
|
|
|
try
|
|
{
|
|
// TODO: _bll.Excluir(_idAtual);
|
|
MessageBox.Show("Chamado 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 chamados
|
|
// var frm = new FormularioBuscarChamado();
|
|
// if (frm.ShowDialog() == DialogResult.OK)
|
|
// {
|
|
// PopularCampos(frm.ChamadoSelecionado);
|
|
// AplicarModo(ModoFormulario.Visualizacao);
|
|
// }
|
|
|
|
MessageBox.Show("Implemente o formulário de busca de chamados.",
|
|
"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("Chamado cadastrado com sucesso!", "Sucesso",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
else
|
|
{
|
|
// TODO: _bll.Atualizar(modelo);
|
|
MessageBox.Show("Chamado 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);
|
|
}
|
|
}
|
|
} |