LevelOS-Core/Dashboards/Cadastros/AgendaCadastroPanel.cs
2026-04-17 21:09:19 -03:00

887 lines
36 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BLL;
using CustomMessageBox;
using DAL;
using MLL;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace UI
{
public class AgendaCadastroPanel : UserControl
{
string _cx = DadosDaConexao.ObterConexao();
// ── CORES ─────────────────────────────────────────────────────────────
private readonly Color AccentBlue = Color.FromArgb(37, 99, 235);
private readonly Color TextDark = Color.FromArgb(30, 41, 59);
private readonly Color BorderColor = Color.FromArgb(226, 232, 240);
private readonly Color GreenColor = Color.FromArgb(34, 197, 94);
private readonly Color AmberColor = Color.FromArgb(245, 158, 11);
private readonly Color RedColor = Color.FromArgb(239, 68, 68);
private readonly Color MutedGray = Color.FromArgb(148, 163, 184);
private readonly Color SurfaceColor = Color.FromArgb(248, 250, 252);
private readonly Color DisabledBack = Color.FromArgb(241, 245, 249);
// ── LAYOUT ────────────────────────────────────────────────────────────
private Panel pnlToolbar = null!;
private Panel pnlLeft = null!;
private Panel pnlRight = null!;
private Panel pnlEventList = null!;
private Panel pnlSplit = null!;
private Panel pnlDias = null!;
// ── TOOLBAR ───────────────────────────────────────────────────────────
private RoundButton btnNovo = null!;
private RoundButton btnAlterar = null!;
private RoundButton btnExcluir = null!;
private RoundButton btnLocalizar = null!;
private RoundButton btnSalvar = null!;
private RoundButton btnCancelar = null!;
// ── CAMPOS DO FORMULÁRIO ──────────────────────────────────────────────
private RoundTextBox txtId = null!;
private RoundTextBox txtCodigo = null!;
private RoundTextBox txtCompromisso = null!;
private RoundTextBox txtData = null!;
private RoundTextBox txtDia = null!;
private RoundTextBox txtHora = null!;
private RoundTextBox txtFunc = null!;
private RoundTextBox txtAvisar = null!;
private RoundTextBox txtOsVinc = null!;
private CheckBox chkRealizado = null!;
// ── INFO (readonly) ───────────────────────────────────────────────────
private RoundTextBox txtCriadoEm = null!;
private RoundTextBox txtAtualizadoEm = null!;
// ── CALENDÁRIO ────────────────────────────────────────────────────────
private Label lblMesAno = null!;
private Button btnPrev = null!;
private Button btnNext = null!;
// ── ESTADO ────────────────────────────────────────────────────────────
private DateTime _currentMonth = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
private DateTime? _selectedDate = null;
private List<MLL.ModeloAgenda> _eventos = new();
private int _nextId = 1;
// ── CONSTRUTOR ────────────────────────────────────────────────────────
public AgendaCadastroPanel()
{
Dock = DockStyle.Fill;
BackColor = Color.White;
DoubleBuffered = true;
InitializeLayout();
SetCampos(false);
//CarregarDadosFake();
CarregarDadosDoBanco();
RenderCalendario();
RenderListaEventos();
}
// ══════════════════════════════════════════════════════════════════════
// LAYOUT
// ══════════════════════════════════════════════════════════════════════
private void InitializeLayout()
{
Controls.Clear();
// ── TOOLBAR ───────────────────────────────────────────────────────
pnlToolbar = new Panel
{
Dock = DockStyle.Top,
Height = 55,
BackColor = SurfaceColor
};
var flow = new FlowLayoutPanel
{
Dock = DockStyle.Fill,
Padding = new Padding(12, 10, 0, 0),
BackColor = Color.Transparent
};
btnNovo = CreateToolbarButton("Novo", GreenColor);
btnAlterar = CreateToolbarButton("Alterar", AmberColor);
btnExcluir = CreateToolbarButton("Excluir", RedColor);
btnLocalizar = CreateToolbarButton("Localizar", AccentBlue);
btnSalvar = CreateToolbarButton("Salvar", AccentBlue);
btnCancelar = CreateToolbarButton("Cancelar", MutedGray);
btnNovo.Click += (_, _) => BtnNovo_Click();
btnAlterar.Click += (_, _) => BtnAlterar_Click();
btnExcluir.Click += (_, _) => BtnExcluir_Click();
btnLocalizar.Click += (_, _) => BtnLocalizar_Click();
btnSalvar.Click += (_, _) => BtnSalvar_Click();
btnCancelar.Click += (_, _) => BtnCancelar_Click();
flow.Controls.AddRange(new Control[]
{ btnNovo, btnAlterar, btnExcluir, btnLocalizar, btnSalvar, btnCancelar });
pnlToolbar.Controls.Add(flow);
Controls.Add(pnlToolbar);
// ── SPLIT ─────────────────────────────────────────────────────────
pnlSplit = new Panel { Dock = DockStyle.Fill, BackColor = Color.White };
Controls.Add(pnlSplit);
pnlSplit.BringToFront();
// RIGHT ─ calendário + lista
pnlRight = new Panel
{
Dock = DockStyle.Right,
Width = 340,
BackColor = Color.White,
Padding = new Padding(10, 10, 10, 10)
};
pnlSplit.Controls.Add(pnlRight);
BuildCalendario(); // preenche pnlRight
// Divider
var divider = new Panel
{
Dock = DockStyle.Right,
Width = 1,
BackColor = BorderColor
};
pnlSplit.Controls.Add(divider);
// LEFT ─ formulário
pnlLeft = new Panel
{
Dock = DockStyle.Fill,
AutoScroll = true,
BackColor = Color.White
};
pnlSplit.Controls.Add(pnlLeft);
BuildFormulario();
}
// ── FORMULÁRIO ────────────────────────────────────────────────────────
private void BuildFormulario()
{
var content = new Panel { Width = 800, BackColor = Color.White };
pnlLeft.Controls.Add(content);
const int rowH = 52;
const int secH = 28;
const int secGap = 10;
const int inputH = 28;
int y = 10;
// IDENTIFICAÇÃO
content.Controls.Add(CreateSectionHeader("IDENTIFICAÇÃO", y));
y += secH + 4;
txtId = AddInput(content, "ID", 20, y, 60, inputH, readOnly: true);
txtCodigo = AddInput(content, "Código", 90, y, 120, inputH);
txtCompromisso = AddInput(content, "Compromisso", 220, y, 520, inputH);
y += rowH;
// DATA E HORA
y += secGap;
content.Controls.Add(CreateSectionHeader("DATA E HORA", y));
y += secH + 4;
txtData = AddInput(content, "Data", 20, y, 130, inputH, readOnly: true);
txtDia = AddInput(content, "Dia", 160, y, 150, inputH, readOnly: true);
txtHora = AddInput(content, "Hora", 320, y, 100, inputH);
y += rowH;
// RESPONSÁVEL E AVISO
y += secGap;
content.Controls.Add(CreateSectionHeader("RESPONSÁVEL E AVISO", y));
y += secH + 4;
txtFunc = AddInput(content, "Funcionário", 20, y, 280, inputH);
txtAvisar = AddInput(content, "Avisar", 310, y, 180, inputH);
txtOsVinc = AddInput(content, "OS Vinculada", 500, y, 140, inputH);
y += rowH;
// SITUAÇÃO
y += secGap;
content.Controls.Add(CreateSectionHeader("SITUAÇÃO", y));
y += secH + 4;
chkRealizado = new CheckBox
{
Text = "Realizado",
Location = new Point(20, y + 4),
Font = new Font("Segoe UI", 8.5f, FontStyle.Bold),
ForeColor = TextDark,
AutoSize = true
};
content.Controls.Add(chkRealizado);
y += rowH;
// INFORMAÇÕES DO REGISTRO
y += secGap;
content.Controls.Add(CreateSectionHeader("INFORMAÇÕES DO REGISTRO", y));
y += secH + 4;
txtCriadoEm = AddInput(content, "Criado Em", 20, y, 175, inputH, readOnly: true);
txtAtualizadoEm = AddInput(content, "Atualizado Em", 205, y, 175, inputH, readOnly: true);
y += rowH;
content.Height = y + 10;
}
// ── CALENDÁRIO ────────────────────────────────────────────────────────
// ATENÇÃO: No WinForms, DockStyle.Fill deve ser adicionado ANTES dos
// DockStyle.Top — a ordem de inserção em Controls é invertida visualmente.
private void BuildCalendario()
{
// 1º — Lista de eventos (Fill) → adicionada PRIMEIRO
pnlEventList = new Panel
{
Dock = DockStyle.Fill,
AutoScroll = true,
BackColor = Color.White,
Padding = new Padding(0, 4, 0, 0)
};
pnlRight.Controls.Add(pnlEventList); // ← PRIMEIRO
// 2º — Grid dos dias (Top) → adicionado DEPOIS do Fill
pnlDias = new Panel
{
Dock = DockStyle.Top,
Height = 215,
BackColor = Color.White
};
pnlRight.Controls.Add(pnlDias); // ← SEGUNDO
// 3º — Cabeçalho mês/ano (Top) → adicionado POR ÚLTIMO (aparece no topo)
var pnlCalHeader = new Panel
{
Dock = DockStyle.Top,
Height = 38,
BackColor = Color.White
};
btnPrev = new Button
{
Text = "",
Size = new Size(28, 26),
Location = new Point(0, 6),
FlatStyle = FlatStyle.Flat,
Font = new Font("Segoe UI", 13f),
ForeColor = AccentBlue,
BackColor = Color.White,
Cursor = Cursors.Hand
};
btnPrev.FlatAppearance.BorderColor = BorderColor;
btnPrev.Click += (_, _) =>
{
_currentMonth = _currentMonth.AddMonths(-1);
RenderCalendario();
RenderListaEventos();
};
btnNext = new Button
{
Text = "",
Size = new Size(28, 26),
Location = new Point(290, 6),
FlatStyle = FlatStyle.Flat,
Font = new Font("Segoe UI", 13f),
ForeColor = AccentBlue,
BackColor = Color.White,
Cursor = Cursors.Hand
};
btnNext.FlatAppearance.BorderColor = BorderColor;
btnNext.Click += (_, _) =>
{
_currentMonth = _currentMonth.AddMonths(1);
RenderCalendario();
RenderListaEventos();
};
lblMesAno = new Label
{
AutoSize = false,
TextAlign = ContentAlignment.MiddleCenter,
Font = new Font("Segoe UI", 10f, FontStyle.Bold),
ForeColor = TextDark,
Size = new Size(256, 26),
Location = new Point(32, 6)
};
pnlCalHeader.Controls.AddRange(new Control[] { btnPrev, lblMesAno, btnNext });
pnlRight.Controls.Add(pnlCalHeader); // ← ÚLTIMO (fica no topo visualmente)
}
// ══════════════════════════════════════════════════════════════════════
// RENDER CALENDÁRIO
// ══════════════════════════════════════════════════════════════════════
private void RenderCalendario()
{
pnlDias.Controls.Clear();
lblMesAno.Text = _currentMonth.ToString("MMMM yyyy",
new System.Globalization.CultureInfo("pt-BR")).ToUpper();
string[] dowLabels = { "Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb" };
int cellW = 44;
int cellH = 26;
int startX = 2;
// Cabeçalho dias da semana
for (int i = 0; i < 7; i++)
{
pnlDias.Controls.Add(new Label
{
Text = dowLabels[i],
Size = new Size(cellW, 18),
Location = new Point(startX + i * cellW, 0),
TextAlign = ContentAlignment.MiddleCenter,
Font = new Font("Segoe UI", 7.5f, FontStyle.Bold),
ForeColor = MutedGray
});
}
int firstDow = (int)new DateTime(_currentMonth.Year, _currentMonth.Month, 1).DayOfWeek;
int daysInMonth = DateTime.DaysInMonth(_currentMonth.Year, _currentMonth.Month);
var datesWithEvts = GetDatesWithEvents();
DateTime today = DateTime.Today;
int col = firstDow, row = 0;
for (int d = 1; d <= daysInMonth; d++)
{
var date = new DateTime(_currentMonth.Year, _currentMonth.Month, d);
bool isToday = date == today;
bool isSelected = _selectedDate.HasValue && date == _selectedDate.Value;
bool hasEvent = datesWithEvts.Contains(date.Date);
var btn = new Button
{
Text = hasEvent ? $"{d} •" : d.ToString(),
Size = new Size(cellW - 2, cellH),
Location = new Point(startX + col * cellW, 22 + row * (cellH + 2)),
FlatStyle = FlatStyle.Flat,
Font = new Font("Segoe UI", 8f,
isToday || isSelected ? FontStyle.Bold : FontStyle.Regular),
Cursor = Cursors.Hand,
Tag = date
};
if (isSelected)
{
btn.BackColor = AccentBlue;
btn.ForeColor = Color.White;
btn.FlatAppearance.BorderColor = AccentBlue;
}
else if (isToday)
{
btn.BackColor = Color.White;
btn.ForeColor = AccentBlue;
btn.FlatAppearance.BorderColor = AccentBlue;
}
else
{
btn.BackColor = Color.White;
btn.ForeColor = TextDark;
btn.FlatAppearance.BorderColor = BorderColor;
}
btn.Click += (s, _) =>
{
if (s is Button b && b.Tag is DateTime dt)
{
_selectedDate = dt;
if (txtData.Enabled)
{
txtData.Text = dt.ToString("dd/MM/yyyy");
txtDia.Text = new System.Globalization.CultureInfo("pt-BR")
.DateTimeFormat.GetDayName(dt.DayOfWeek);
}
RenderCalendario();
RenderListaEventos();
}
};
pnlDias.Controls.Add(btn);
col++;
if (col == 7) { col = 0; row++; }
}
}
// ══════════════════════════════════════════════════════════════════════
// RENDER LISTA DE EVENTOS
// ══════════════════════════════════════════════════════════════════════
private void RenderListaEventos()
{
pnlEventList.Controls.Clear();
var filtrados = _selectedDate.HasValue
? _eventos.Where(e => ParseData(e.dDATA).Date == _selectedDate.Value.Date).ToList()
: _eventos.Where(e => ParseData(e.dDATA).Month == _currentMonth.Month
&& ParseData(e.dDATA).Year == _currentMonth.Year).ToList();
filtrados = filtrados.OrderBy(e => e.HORA).ToList();
// Largura real do painel (com fallback para evitar 0)
int listW = pnlEventList.ClientSize.Width > 0
? pnlEventList.ClientSize.Width
: pnlRight.Width - pnlRight.Padding.Horizontal - 20;
int y = 0;
// ── Título ────────────────────────────────────────────────────────
string titulo = _selectedDate.HasValue
? $"COMPROMISSOS — {_selectedDate.Value:dd/MM/yyyy}"
: $"COMPROMISSOS — {_currentMonth.ToString("MMMM/yyyy", new System.Globalization.CultureInfo("pt-BR")).ToUpper()}";
pnlEventList.Controls.Add(new Label
{
Text = titulo,
AutoSize = false,
Width = listW,
Height = 18,
Location = new Point(0, y),
Font = new Font("Segoe UI", 7.5f, FontStyle.Bold),
ForeColor = MutedGray
});
y += 6;
// Linha separadora
pnlEventList.Controls.Add(new Panel
{
Location = new Point(0, y + 14),
Size = new Size(listW, 1),
BackColor = BorderColor
});
y += 22;
// ── Vazio ─────────────────────────────────────────────────────────
if (!filtrados.Any())
{
pnlEventList.Controls.Add(new Label
{
Text = "Nenhum compromisso encontrado.",
Location = new Point(0, y + 8),
AutoSize = true,
Font = new Font("Segoe UI", 8.5f),
ForeColor = MutedGray
});
return;
}
// ── Cards ─────────────────────────────────────────────────────────
foreach (var ev in filtrados)
{
bool realizado = ev.REALIZADO?.ToUpper() == "S";
var card = new Panel
{
Location = new Point(0, y),
Width = listW,
Height = 72,
BackColor = Color.White,
BorderStyle = BorderStyle.None,
Cursor = Cursors.Hand,
Tag = ev
};
// Borda esquerda colorida
card.Controls.Add(new Panel
{
Location = new Point(0, 0),
Size = new Size(3, 72),
BackColor = realizado ? GreenColor : AmberColor
});
card.Controls.Add(new Label
{
Text = $"{ev.HORA} — {ev.dDATA}",
Location = new Point(10, 5),
AutoSize = true,
Font = new Font("Segoe UI", 7.5f, FontStyle.Bold),
ForeColor = AccentBlue
});
card.Controls.Add(new Label
{
Text = ev.COMPROMISSO,
Location = new Point(10, 21),
AutoSize = true,
Font = new Font("Segoe UI", 8.5f, FontStyle.Bold),
ForeColor = TextDark
});
card.Controls.Add(new Label
{
Text = string.IsNullOrWhiteSpace(ev.FUNC) ? "—" : ev.FUNC,
Location = new Point(10, 39),
AutoSize = true,
Font = new Font("Segoe UI", 8f),
ForeColor = MutedGray
});
card.Controls.Add(new Label
{
Text = realizado ? "✔ Realizado" : "⏳ Pendente",
Location = new Point(10, 55),
AutoSize = true,
Font = new Font("Segoe UI", 7.5f, FontStyle.Bold),
ForeColor = realizado
? Color.FromArgb(22, 101, 52)
: Color.FromArgb(146, 64, 14)
});
// Borda do card via Paint
card.Paint += (_, pe) =>
{
using var pen = new Pen(BorderColor);
pe.Graphics.DrawRectangle(pen, 0, 0, card.Width - 1, card.Height - 1);
};
// Clique em qualquer parte do card (inclusive labels filhos)
var evLocal = ev;
EventHandler clickHandler = (_, _) => CarregarEvento(evLocal);
card.Click += clickHandler;
foreach (Control child in card.Controls)
child.Click += clickHandler;
pnlEventList.Controls.Add(card);
y += 78;
}
}
// ══════════════════════════════════════════════════════════════════════
// EVENTOS DOS BOTÕES
// ══════════════════════════════════════════════════════════════════════
private void BtnNovo_Click()
{
LimparCampos();
SetCampos(true);
txtCriadoEm.Text = DateTime.Now.ToString("dd/MM/yyyy");
}
private void BtnAlterar_Click()
{
if (string.IsNullOrWhiteSpace(txtId.Text))
{
MessageBox.Show("Nenhum registro selecionado para alterar.",
"Atenção", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
SetCampos(true);
}
private void BtnExcluir_Click()
{
BLLAgenda _agendaBLL = new BLLAgenda(this._cx);
if (string.IsNullOrWhiteSpace(txtId.Text))
{
NT_MessageBox.Show("Nenhum registro selecionado para excluir.",
"Atenção", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
var confirm = NT_MessageBox.Show("Confirma a exclusão deste registro?",
"Confirmar Exclusão", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (confirm == DialogResult.Yes)
{
int id = int.Parse(txtId.Text);
bool sucesso = _agendaBLL.Excluir(id);
if (!sucesso)
{
NT_MessageBox.Show("Erro ao excluir o registro.",
"Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
// 🔹 Atualiza lista do banco
_eventos.Clear();
_eventos.AddRange(_agendaBLL.Listar());
LimparCampos();
SetCampos(false);
RenderCalendario();
RenderListaEventos();
NT_MessageBox.Show("Registro excluído com sucesso!",
"Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}//Excluir registro selecionado
private void BtnLocalizar_Click()
{
FormHelper.Show<AgendaConsultaPanel>("Agenda de Compromissos");
}
private void BtnSalvar_Click()
{
//if (string.IsNullOrWhiteSpace(txtData.Text) ||
// string.IsNullOrWhiteSpace(txtCompromisso.Text))
//{
// MessageBox.Show("Preencha ao menos Data e Compromisso.",
// "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Warning);
// return;
//}
//bool isNew = string.IsNullOrWhiteSpace(txtId.Text);
//int id = isNew ? _nextId++ : int.Parse(txtId.Text);
//var agenda = new MLL.ModeloAgenda(
// iD_AGENDA: id,
// cODIGO: txtCodigo.Text,
// cOMPROMISSO: txtCompromisso.Text,
// dDATA: txtData.Text,
// aVISAR: txtAvisar.Text,
// fUNC: txtFunc.Text,
// dIA: txtDia.Text,
// hORA: txtHora.Text,
// rEALIZADO: chkRealizado.Checked ? "S" : "N",
// oS_VINC: txtOsVinc.Text
//);
//if (isNew)
//{
// _eventos.Add(agenda);
// txtId.Text = id.ToString();
//}
//else
//{
// int idx = _eventos.FindIndex(e => e.ID_AGENDA == id);
// if (idx >= 0) _eventos[idx] = agenda;
//}
//txtAtualizadoEm.Text = DateTime.Now.ToString("dd/MM/yyyy");
//SetCampos(false);
//RenderCalendario();
//RenderListaEventos();
//MessageBox.Show("Registro salvo com sucesso!", "Sucesso",
// MessageBoxButtons.OK, MessageBoxIcon.Information);
BLLAgenda _agendaBLL = new BLLAgenda(_cx);
if (string.IsNullOrWhiteSpace(txtData.Text) ||
string.IsNullOrWhiteSpace(txtCompromisso.Text))
{
MessageBox.Show("Preencha ao menos Data e Compromisso.",
"Atenção", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
bool isNew = string.IsNullOrWhiteSpace(txtId.Text);
var agenda = new MLL.ModeloAgenda(
iD_AGENDA: isNew ? 0 : int.Parse(txtId.Text),
cODIGO: txtCodigo.Text,
cOMPROMISSO: txtCompromisso.Text,
dDATA: txtData.Text,
aVISAR: txtAvisar.Text,
fUNC: txtFunc.Text,
dIA: txtDia.Text,
hORA: txtHora.Text,
rEALIZADO: chkRealizado.Checked ? "S" : "N",
oS_VINC: txtOsVinc.Text
);
bool sucesso;
if (isNew)
{
sucesso = _agendaBLL.Inserir(agenda);
}
else
{
sucesso = _agendaBLL.Alterar(agenda);
}
if (!sucesso)
{
MessageBox.Show("Erro ao salvar no banco de dados.",
"Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
// 🔹 Recarrega dados do banco
_eventos = _agendaBLL.Listar();
// 🔹 Atualiza UI
txtAtualizadoEm.Text = DateTime.Now.ToString("dd/MM/yyyy");
SetCampos(false);
RenderCalendario();
RenderListaEventos();
MessageBox.Show("Registro salvo com sucesso!", "Sucesso",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void BtnCancelar_Click()
{
LimparCampos();
SetCampos(false);
}
// ══════════════════════════════════════════════════════════════════════
// HELPERS
// ══════════════════════════════════════════════════════════════════════
private void SetCampos(bool enabled)
{
var campos = new[] { txtCodigo, txtCompromisso, txtHora, txtFunc, txtAvisar, txtOsVinc };
foreach (var c in campos)
{
c.Enabled = enabled;
c.BackColor = enabled ? Color.White : DisabledBack;
}
chkRealizado.Enabled = enabled;
txtData.BackColor = enabled ? Color.FromArgb(239, 246, 255) : DisabledBack;
}
private void LimparCampos()
{
txtId.Text = txtCodigo.Text = txtCompromisso.Text = string.Empty;
txtData.Text = txtDia.Text = txtHora.Text = string.Empty;
txtFunc.Text = txtAvisar.Text = txtOsVinc.Text = string.Empty;
txtCriadoEm.Text = txtAtualizadoEm.Text = string.Empty;
chkRealizado.Checked = false;
_selectedDate = null;
}
private void CarregarEvento(MLL.ModeloAgenda ev)
{
txtId.Text = ev.ID_AGENDA.ToString();
txtCodigo.Text = ev.CODIGO;
txtCompromisso.Text = ev.COMPROMISSO;
txtData.Text = ev.dDATA;
txtDia.Text = ev.DIA;
txtHora.Text = ev.HORA;
txtFunc.Text = ev.FUNC;
txtAvisar.Text = ev.AVISAR;
txtOsVinc.Text = ev.OS_VINC;
txtCriadoEm.Text = ev.dDATA;
txtAtualizadoEm.Text = DateTime.Now.ToString("dd/MM/yyyy");
chkRealizado.Checked = ev.REALIZADO?.ToUpper() == "S";
var dt = ParseData(ev.dDATA);
if (dt != DateTime.MinValue)
{
_selectedDate = dt;
_currentMonth = new DateTime(dt.Year, dt.Month, 1);
}
SetCampos(false);
RenderCalendario();
RenderListaEventos();
}
private HashSet<DateTime> GetDatesWithEvents()
{
var set = new HashSet<DateTime>();
foreach (var ev in _eventos)
{
var dt = ParseData(ev.dDATA);
if (dt != DateTime.MinValue) set.Add(dt.Date);
}
return set;
}
private static DateTime ParseData(string? value)
{
if (string.IsNullOrWhiteSpace(value)) return DateTime.MinValue;
if (DateTime.TryParseExact(value, "dd/MM/yyyy",
System.Globalization.CultureInfo.InvariantCulture,
System.Globalization.DateTimeStyles.None, out var dt))
return dt;
if (DateTime.TryParse(value, out dt)) return dt;
return DateTime.MinValue;
}
private void CarregarDadosFake()
{
var hoje = DateTime.Today;
_eventos.AddRange(new[]
{
new MLL.ModeloAgenda(1, "AG001", "Reunião com cliente",
hoje.ToString("dd/MM/yyyy"), "30 minutos antes",
"Carlos Silva", DiaSemana(hoje), "09:00", "S", "OS-1042"),
new MLL.ModeloAgenda(2, "AG002", "Visita técnica",
hoje.ToString("dd/MM/yyyy"), "1 hora antes",
"Ana Souza", DiaSemana(hoje), "14:00", "N", "OS-1055"),
new MLL.ModeloAgenda(3, "AG003", "Entrega de equipamento",
hoje.AddDays(4).ToString("dd/MM/yyyy"), "1 dia antes",
"Pedro Lima", DiaSemana(hoje.AddDays(4)), "10:30", "N", ""),
});
_nextId = 4;
}//Carregar dados fake (Não usa mais)
private void CarregarDadosDoBanco()
{
BLLAgenda _agendaBLL = new BLLAgenda(_cx);
_eventos.Clear();
_eventos.AddRange(_agendaBLL.Listar());
}// Método auxiliar para obter os dados da agenda no banco de dados e preencher a lista de eventos.
private static string DiaSemana(DateTime d) =>
new System.Globalization.CultureInfo("pt-BR").DateTimeFormat.GetDayName(d.DayOfWeek);
// ── UI HELPERS ────────────────────────────────────────────────────────
private Panel CreateSectionHeader(string title, int y)
{
var pnl = new Panel { Location = new Point(20, y), Width = 760, Height = 26 };
pnl.Controls.Add(new Label
{
Text = title,
Font = new Font("Segoe UI", 8.5f, FontStyle.Bold),
ForeColor = AccentBlue,
AutoSize = true,
Location = new Point(0, 0)
});
pnl.Controls.Add(new Panel
{
BackColor = BorderColor,
Height = 1,
Width = 740,
Location = new Point(0, 20)
});
return pnl;
}
private RoundTextBox AddInput(Control parent, string label,
int x, int y, int width, int height,
bool readOnly = false)
{
parent.Controls.Add(new Label
{
Text = label,
Location = new Point(x, y),
Font = new Font("Segoe UI", 7.5f, FontStyle.Bold),
ForeColor = readOnly ? Color.Gray : TextDark,
AutoSize = true
});
var txt = new RoundTextBox
{
Location = new Point(x, y + 16),
Size = new Size(width, height),
Radius = 4,
BorderColor = readOnly ? Color.FromArgb(203, 213, 225) : BorderColor,
FocusColor = AccentBlue,
ReadOnly = readOnly,
BackColor = readOnly ? DisabledBack : Color.White
};
parent.Controls.Add(txt);
return txt;
}
private RoundButton CreateToolbarButton(string text, Color color) => new RoundButton
{
Text = text,
Size = new Size(95, 32),
BackColor = color,
ForeColor = Color.White,
Font = new Font("Segoe UI Semibold", 8.5f),
Margin = new Padding(0, 0, 6, 0),
Cursor = Cursors.Hand
};
}
}