LevelOS-Core/UI/ArquivosAuxiliares/Txt/SidebarControllBKP.txt

424 lines
24 KiB
Plaintext
Raw Permalink 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 CustomMessageBox;
using DAL;
using DALL;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace UI
{
public class SidebarControl : UserControl
{
//Recebendo a conexao
string _cx = DadosDaConexao.ObterConexao();
// ── Cores do Tema LevelOS ──────────────────────────────────────────
private static readonly Color NavyDark = Color.FromArgb(15, 30, 60);
private static readonly Color NavyMid = Color.FromArgb(26, 45, 80);
private static readonly Color AccentBlue = Color.FromArgb(37, 99, 235);
private static readonly Color TextLight = Color.FromArgb(255, 255, 255);
private static readonly Color TextMuted = Color.FromArgb(148, 163, 184);
private static readonly Color Divider = Color.FromArgb(40, 255, 255, 255);
// ── Estado e Escalonamento (DPI) ───────────────────────────────────
private float _scale = 1.0f;
private int _activeIndex = 0;
private int _hoverIndex = -1;
// Propriedades Scaled (Ajustam-se ao monitor)
private int ScaledWidth => (int)(220 * _scale);
private int ScaledLogoH => (int)(55 * _scale);
private int ScaledSectionH => (int)(32 * _scale);
private int ScaledItemH => (int)(40 * _scale);
private int ScaledItemPadX => (int)(12 * _scale);
private int ScaledFooterH => (int)(50 * _scale);
private int ScaledIconSize => (int)(16 * _scale);
// ── Submenus ───────────────────────────────────────────────────────
private ContextMenuStrip _subMenuBanco, _subMenuConfiguracao,
_subMenuAjuda, _subMenuOrdemServico, _subMenuFinanceiro,_subMenuCadastro, _subMenuAgenda;
public string UserName = "Levelcode", UserFunction = "Administrador";
public event EventHandler<int>? NavItemClicked;
private readonly List<NavItem> _items = new()
{
new NavItem("Dashboard", SvgIcon.Grid, "Principal", null),
new NavItem("Cadastro", SvgIcon.UserPlus, null, "3"),
new NavItem("Ordens de Serviço", SvgIcon.FileText, null, "12"),
new NavItem("Agenda", SvgIcon.Calendar, null, null),
new NavItem("Produtos", SvgIcon.Package, "Gestão", null),
new NavItem("Estoque", SvgIcon.Inventory, null, null),
//new NavItem("Serviços", SvgIcon.Briefcase, null, null),
//new NavItem("Transportadoras", SvgIcon.Truck, null, null),
new NavItem("Financeiro", SvgIcon.DollarSign, null, null),
new NavItem("Banco de Dados", SvgIcon.Database, "Sistema", null),
new NavItem("Configurações", SvgIcon.Settings, null, null),
new NavItem("Suporte Técnico", SvgIcon.Support, "Ajuda", null),
};
public void backupFull(string conexao)
{
var backupService = new DALLBackupService(conexao);
var resultadoFull = backupService.ExecutarBackupFull();
if (resultadoFull.Sucesso)
NT_MessageBox.Show($"✅ Backup FULL concluído em {resultadoFull.Duracao.TotalSeconds:F1}s","Backup do banco de dados",MessageBoxButtons.OK, MessageBoxIcon.Information);
else
NT_MessageBox.Show($"❌ Erro no Backup FULL: {resultadoFull.Erro}","Erro ao tentar executar backup do sistema.",MessageBoxButtons.OK,MessageBoxIcon.Error);
}//Criar backup full
public void backupDifrencial(string conexao)
{
var backupService = new DALLBackupService(conexao);
var resultadoDiff = backupService.ExecutarBackupDiferencial();
if (resultadoDiff.Sucesso)
NT_MessageBox.Show($"✅ Backup DIFERENCIAL concluído em {resultadoDiff.Duracao.TotalSeconds:F1}s","Backup diferencial concluido", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
NT_MessageBox.Show($"❌ Erro no Backup DIFERENCIAL: {resultadoDiff.Erro}","Erro ao tentar executar backup diferencial no sistema", MessageBoxButtons.OK, MessageBoxIcon.Error);
}//Criar backup diferencial
public SidebarControl()
{
BackColor = NavyDark;
DoubleBuffered = true;
this.SetStyle(ControlStyles.ResizeRedraw, true);
}
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
using (Graphics g = this.CreateGraphics()) { _scale = g.DpiX / 96f; }
this.Width = ScaledWidth;
SetupSubMenus();
}
private void SetupSubMenus()
{
//Submenu Cadastro
_subMenuCadastro = CreateStyledMenu();
_subMenuCadastro.Items.Add("👤 Clientes", null, (s, e) => {NavItemClicked?.Invoke(this, 99);});
_subMenuCadastro.Items.Add("💻 Equipamentos", null, (s, e) => { NavItemClicked?.Invoke(this, 100); });
_subMenuCadastro.Items.Add("📜 Contratos", null, (s, e) => { NavItemClicked?.Invoke(this, 101); });
_subMenuCadastro.Items.Add("🏭 Fornecedores", null, (s, e) => { NavItemClicked?.Invoke(this, 102); });
_subMenuCadastro.Items.Add("👔 Funcionários", null, (s, e) => { NavItemClicked?.Invoke(this, 103); });
_subMenuCadastro.Items.Add("🚚 Transportadoras", null, (s, e) => { NavItemClicked?.Invoke(this, 104); });
_subMenuCadastro.Items.Add("🛠️ Serviços", null, (s, e) => { NavItemClicked?.Invoke(this, 105); });
_subMenuCadastro.Items.Add("🏢 Empresa", null, (s, e) => { NavItemClicked?.Invoke(this, 106); });
_subMenuCadastro.Items.Add("🔑 Usuários do Sistema", null, (s, e) => { NavItemClicked?.Invoke(this, 107); });
_subMenuBanco = CreateStyledMenu();
_subMenuBanco.Items.Add("⚙️ Configuração Database", null, (s, e) => showForms<Form>()); // Substitua pelo seu Form
_subMenuBanco.Items.Add("💾 Backup de Dados (FULL)", null, (s, e) => backupFull(this._cx));
_subMenuBanco.Items.Add("⚡ Backup de Dados (DIFF)", null, (s, e) => backupDifrencial(this._cx));
_subMenuBanco.Items.Add("🔄 Restaurar Banco");
//submenu Configurações
_subMenuConfiguracao = CreateStyledMenu();
_subMenuConfiguracao.Items.Add("🖼️ Personalização de OS");
_subMenuConfiguracao.Items.Add("🖥️ Personalização de Sistema");
_subMenuConfiguracao.Items.Add(" Configuração Empresa", null, (s, e) => { NavItemClicked?.Invoke(this, 202); });
_subMenuConfiguracao.Items.Add(new ToolStripSeparator());
_subMenuConfiguracao.Items.Add("📂 FTP-Cliente"); // Pasta para arquivos
_subMenuConfiguracao.Items.Add("💬 Telegram-Cliente"); // Balão de conversa
_subMenuConfiguracao.Items.Add("📩 SMTP-Cliente"); // Envelope de saída
_subMenuConfiguracao.Items.Add(new ToolStripSeparator());
// Automação
_subMenuConfiguracao.Items.Add("⏰ Backups Automáticos"); // Relógio para agendamento
_subMenuConfiguracao.Items.Add("☁️ Backup em Nuvem");
_subMenuAjuda = CreateStyledMenu();
_subMenuAjuda.Items.Add("💬 Atendimento Online");
_subMenuAjuda.Items.Add("📖 Manual do Sistema");
_subMenuOrdemServico = CreateStyledMenu();
_subMenuOrdemServico.Items.Add("✚ Abrir nova O.S", null, (s, e) => { /* Lógica */ });
_subMenuOrdemServico.Items.Add("✎ Alterar O.S", null, (s, e) => { /* Lógica */ });
_subMenuOrdemServico.Items.Add("🔒 Encerrar O.S", null, (s, e) => { /* Lógica */ });
_subMenuOrdemServico.Items.Add("🔍 Localizar O.S", null, (s, e) => { /* Lógica */ });
_subMenuOrdemServico.Items.Add("📋 Orçamento de O.S", null, (s, e) => { /* Lógica */ });
_subMenuOrdemServico.Items.Add("📜 Histórico de O.S", null, (s, e) => { /* Lógica */ });
_subMenuOrdemServico.Items.Add("📊 Relatório de O.S", null, (s, e) => { /* Lógica */ });
_subMenuOrdemServico.Items.Add("🖨 Imprimir", null, (s, e) => { /* Lógica */ });
_subMenuOrdemServico.Items.Add("⚠️ Chamado Técnico", null, (s, e) => { /* Lógica */ });
_subMenuOrdemServico.Items.Add("🌐 OS WEB", null, (s, e) => { /* Lógica */ });
_subMenuOrdemServico.Items.Add("🔓 Reabrir OS", null, (s, e) => { /* Lógica */ });
_subMenuFinanceiro = CreateStyledMenu();
_subMenuFinanceiro.Items.Add("💳 Contas", null, (s, e) => { /* Lógica */ });
_subMenuFinanceiro.Items.Add("📈 Contas a receber", null, (s, e) => { /* Lógica */ });
_subMenuFinanceiro.Items.Add("📉 Contas a pagar", null, (s, e) => { /* Lógica */ });
_subMenuFinanceiro.Items.Add("📉 Boletos/Duplicatas", null, (s, e) => { NavItemClicked?.Invoke(this, 500); });
_subMenuFinanceiro.Items.Add(new ToolStripSeparator()); // Linha divisória
_subMenuFinanceiro.Items.Add("🛒 Compras", null, (s, e) => { /* Lógica */ });
_subMenuFinanceiro.Items.Add("💰 Vendas", null, (s, e) => { /* Lógica */ });
_subMenuFinanceiro.Items.Add("🧾 Notas Fiscais", null, (s, e) => { /* Lógica */ });
_subMenuFinanceiro.Items.Add(new ToolStripSeparator()); // Linha divisória
_subMenuFinanceiro.Items.Add("📂 Arquivo Contador", null, (s, e) => { /* Lógica */ });
_subMenuFinanceiro.Items.Add("🏦 Dados Bancários", null, (s, e) => { /* Lógica */ });
_subMenuFinanceiro.Items.Add("🕒 Histórico Financeiro", null, (s, e) => { /* Lógica */ });
// private ContextMenuStrip _subMenuAgenda;
_subMenuAgenda = CreateStyledMenu();
//_subMenuAgenda.Items.Add(" Novo compromisso", null, (s, e) => {showForms<AgendaForm>();});
_subMenuAgenda.Items.Add(" Novo compromisso", null, (s, e) => { NavItemClicked?.Invoke(this, 300); });
_subMenuAgenda.Items.Add("🔍 Consultar compromissos", null, (s, e) => { NavItemClicked?.Invoke(this, 301); });
_subMenuAgenda.Items.Add("✏️ Alterar compromisso", null, (s, e) => { /* Lógica de edição */ });
_subMenuAgenda.Items.Add("🖨️ Imprimir", null, (s, e) => { /* Lógica de relatório */ });
}
private ContextMenuStrip CreateStyledMenu()
{
return new ContextMenuStrip
{
BackColor = NavyMid,
ForeColor = TextLight,
ShowImageMargin = false,
Font = new Font("Segoe UI", 10f * _scale),
Renderer = new ToolStripProfessionalRenderer(new SubMenuColorTable())
};
}
private void showForms<T>() where T : Form, new()
{
using (T form = new T())
{
form.StartPosition = FormStartPosition.CenterScreen;
form.ShowDialog();
}
}
//Abrir agenda
// AgendaForm.cs
public class AgendaForm : Form
{
public AgendaForm()
{
Text = "Agenda de Compromissos";
Size = new Size(1150, 780);
StartPosition = FormStartPosition.CenterScreen;
BackColor = Color.White;
var panel = new AgendaCadastroPanel();
Controls.Add(panel);
}
}//abrir agenda de compromissos
protected override void OnPaint(PaintEventArgs e)
{
var g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
DrawLogo(g);
DrawNavItems(g, ScaledLogoH + (int)(8 * _scale));
DrawFooter(g);
}
private void DrawNavItems(Graphics g, int startY)
{
int y = startY;
using var fSection = new Font("Segoe UI", 8f * _scale, FontStyle.Bold);
using var fItem = new Font("Segoe UI", 10f * _scale);
using var fItemSel = new Font("Segoe UI Semibold", 10f * _scale);
for (int i = 0; i < _items.Count; i++)
{
var item = _items[i];
if (item.Section != null)
{
y += (int)(10 * _scale);
g.DrawString(item.Section.ToUpper(), fSection, new SolidBrush(Color.FromArgb(120, TextMuted)), ScaledItemPadX + (int)(8 * _scale), y);
y += ScaledSectionH;
}
bool isActive = (i == _activeIndex);
bool isHover = (i == _hoverIndex && !isActive);
var itemRect = new Rectangle(ScaledItemPadX, y, Width - ScaledItemPadX * 2, ScaledItemH);
if (isActive) FillRoundRect(g, new SolidBrush(AccentBlue), itemRect, (int)(6 * _scale));
else if (isHover) FillRoundRect(g, new SolidBrush(Color.FromArgb(20, 255, 255, 255)), itemRect, (int)(6 * _scale));
var color = isActive ? TextLight : Color.FromArgb(200, TextLight);
DrawIcon(g, item.Icon, ScaledItemPadX + (int)(10 * _scale), y + (ScaledItemH - ScaledIconSize) / 2, ScaledIconSize, color);
g.DrawString(item.Label, isActive ? fItemSel : fItem, new SolidBrush(color), ScaledItemPadX + (int)(36 * _scale), y + (ScaledItemH - (int)(16 * _scale)) / 2);
if (HasSubMenu(item.Label))
g.DrawString("", fItem, new SolidBrush(Color.FromArgb(100, TextLight)), Width - (int)(30 * _scale), y + (ScaledItemH - (int)(18 * _scale)) / 2);
y += ScaledItemH + (int)(2 * _scale);
}
}
// Adicione "Cadastro" na verificação
private bool HasSubMenu(string label) =>
label == "Cadastro" || // <-- Adicionado aqui
label == "Banco de Dados" ||
label == "Financeiro" ||
label == "Ordens de Serviço" ||
label == "Configurações" ||
label == "Suporte Técnico" ||
label == "Agenda"
;
protected override void OnMouseClick(MouseEventArgs e)
{
int hit = HitTest(e.Y);
if (hit >= 0)
{
_activeIndex = hit; Invalidate();
string label = _items[hit].Label;
Point menuPos = new Point(Width + 2, e.Y - (int)(15 * _scale));
if (label == "Banco de Dados") _subMenuBanco.Show(this, menuPos);
else if (label == "Financeiro") _subMenuFinanceiro.Show(this, menuPos);
else if(label == "Agenda") _subMenuAgenda.Show(this, menuPos);
else if (label == "Ordens de Serviço") _subMenuOrdemServico.Show(this, menuPos);
else if (label == "Configurações") _subMenuConfiguracao.Show(this, menuPos);
else if (label == "Suporte Técnico") _subMenuAjuda.Show(this, menuPos);
else if (label == "Cadastro") _subMenuCadastro.Show(this, menuPos);
else NavItemClicked?.Invoke(this, hit);
}
}
private int HitTest(int mouseY)
{
int y = ScaledLogoH + (int)(8 * _scale);
for (int i = 0; i < _items.Count; i++)
{
if (_items[i].Section != null) y += (int)(10 * _scale) + ScaledSectionH;
if (mouseY >= y && mouseY < y + ScaledItemH) return i;
y += ScaledItemH + (int)(2 * _scale);
}
return -1;
}
protected override void OnMouseMove(MouseEventArgs e) { int hit = HitTest(e.Y); if (hit != _hoverIndex) { _hoverIndex = hit; Invalidate(); } }
protected override void OnMouseLeave(EventArgs e) { _hoverIndex = -1; Invalidate(); }
private void DrawLogo(Graphics g)
{
var iconRect = new Rectangle((int)(16 * _scale), (int)(18 * _scale), (int)(34 * _scale), (int)(34 * _scale));
FillRoundRect(g, new SolidBrush(AccentBlue), iconRect, (int)(8 * _scale));
using var fIcon = new Font("Segoe UI", 14f * _scale, FontStyle.Bold);
DrawCenteredString(g, "S", fIcon, TextLight, iconRect);
g.DrawString("LevelOS", new Font("Segoe UI Semibold", 13f * _scale), new SolidBrush(TextLight), 58 * _scale, 20 * _scale);
g.DrawString("SISTEMA ERP", new Font("Segoe UI", 8f * _scale), new SolidBrush(TextMuted), 59 * _scale, 38 * _scale);
g.DrawLine(new Pen(Divider), 0, ScaledLogoH, Width, ScaledLogoH);
}
private void DrawFooter(Graphics g)
{
int fy = Height - ScaledFooterH;
g.DrawLine(new Pen(Divider), 0, fy, Width, fy);
var avRect = new Rectangle((int)(16 * _scale), fy + (int)(14 * _scale), (int)(32 * _scale), (int)(32 * _scale));
g.FillEllipse(new SolidBrush(AccentBlue), avRect);
DrawCenteredString(g, "AD", new Font("Segoe UI Semibold", 10f * _scale), TextLight, avRect);
g.DrawString(UserName, new Font("Segoe UI Semibold", 11f * _scale), new SolidBrush(TextLight), 56 * _scale, fy + (14 * _scale));
g.DrawString(UserFunction, new Font("Segoe UI", 9f * _scale), new SolidBrush(TextMuted), 57 * _scale, fy + (30 * _scale));
}
// ── MOTOR DE ÍCONES COMPLETO (GDI+) ────────────────────────────────
private void DrawIcon(Graphics g, SvgIcon icon, int x, int y, int size, Color color)
{
using var p = new Pen(color, 1.6f * _scale) { StartCap = LineCap.Round, EndCap = LineCap.Round, LineJoin = LineJoin.Round };
float s = size / 24f;
g.TranslateTransform(x, y); g.ScaleTransform(s, s);
switch (icon)
{
case SvgIcon.Grid:
g.DrawRectangle(p, 3, 3, 7, 7); g.DrawRectangle(p, 14, 3, 7, 7); g.DrawRectangle(p, 3, 14, 7, 7); g.DrawRectangle(p, 14, 14, 7, 7); break;
case SvgIcon.Users:
g.DrawEllipse(p, 5, 3, 8, 8); g.DrawArc(p, 2, 13, 14, 8, 180, 180); g.DrawArc(p, 15, 8, 6, 6, 270, 180); break;
case SvgIcon.FileText:
g.DrawLines(p, new PointF[] { new(6, 2), new(6, 22), new(18, 22), new(18, 8), new(14, 2), new(6, 2) }); g.DrawLine(p, 14, 2, 14, 8); g.DrawLine(p, 14, 8, 18, 8); break;
case SvgIcon.Package:
g.DrawLines(p, new PointF[] { new(12, 2), new(2, 7), new(12, 12), new(22, 7), new(12, 2) }); g.DrawLine(p, 2, 7, 2, 17); g.DrawLine(p, 22, 7, 22, 17); g.DrawLine(p, 12, 12, 12, 22); break;
case SvgIcon.DollarSign:
g.DrawLine(p, 12, 2, 12, 22); g.DrawArc(p, 7, 5, 10, 7, 110, 250); g.DrawArc(p, 7, 12, 10, 7, 270, 250); break;
case SvgIcon.Database:
g.DrawEllipse(p, 4, 3, 16, 6); g.DrawLine(p, 4, 6, 4, 18); g.DrawLine(p, 20, 6, 20, 18); g.DrawArc(p, 4, 15, 16, 6, 0, 180); break;
case SvgIcon.Calendar:
g.DrawRectangle(p, 3, 4, 18, 17); g.DrawLine(p, 3, 9, 21, 9); g.DrawLine(p, 8, 2, 8, 6); g.DrawLine(p, 16, 2, 16, 6); break;
case SvgIcon.Truck:
g.DrawRectangle(p, 1, 5, 13, 11); g.DrawLines(p, new PointF[] { new(14, 16), new(14, 8), new(19, 8), new(23, 12), new(23, 16) });
g.DrawEllipse(p, 3, 15, 4, 4); g.DrawEllipse(p, 17, 15, 4, 4); break;
case SvgIcon.Factory:
g.DrawRectangle(p, 2, 10, 20, 11); g.DrawLines(p, new PointF[] { new(2, 10), new(2, 5), new(8, 10), new(8, 5), new(14, 10) }); break;
case SvgIcon.Briefcase:
g.DrawRectangle(p, 3, 7, 18, 13); g.DrawArc(p, 9, 3, 6, 8, 180, 180); break;
case SvgIcon.Support:
g.DrawArc(p, 4, 4, 16, 16, 180, 180); g.DrawRectangle(p, 3, 13, 3, 5); g.DrawRectangle(p, 18, 13, 3, 5); break;
case SvgIcon.Inventory:
g.DrawRectangle(p, 3, 3, 18, 8); g.DrawRectangle(p, 3, 13, 18, 8); break;
case SvgIcon.Settings:
g.DrawEllipse(p, 9, 9, 6, 6);
for (int a = 0; a < 360; a += 45)
{
float r = a * (float)Math.PI / 180f;
g.DrawLine(p, 12 + (float)Math.Cos(r) * 8, 12 + (float)Math.Sin(r) * 8, 12 + (float)Math.Cos(r) * 11, 12 + (float)Math.Sin(r) * 11);
}
break;
case SvgIcon.User: g.DrawEllipse(p, 8, 2, 8, 8); g.DrawArc(p, 3, 14, 18, 8, 180, 180); break;
case SvgIcon.UserCheck: g.DrawEllipse(p, 8, 3, 8, 8); g.DrawArc(p, 3, 14, 18, 8, 180, 180); g.DrawRectangle(p, 10, 15, 4, 3); break;
case SvgIcon.UserPlus:
// Desenha o corpo do usuário (círculo e arco)
g.DrawEllipse(p, 4, 4, 8, 8); // Cabeça
g.DrawArc(p, 1, 14, 14, 8, 180, 180); // Ombros
// Desenha o sinal de "+" ao lado
// Vertical
g.DrawLine(p, 19, 7, 19, 15);
// Horizontal
g.DrawLine(p, 15, 11, 23, 11);
break;
}
g.ResetTransform();
}
// ── Helpers ──
private static void FillRoundRect(Graphics g, Brush b, Rectangle r, int rad) { using var path = RoundRectPath(r, rad); g.FillPath(b, path); }
private static GraphicsPath RoundRectPath(Rectangle r, int rad)
{
var path = new GraphicsPath(); int d = Math.Max(rad * 2, 1);
path.AddArc(r.X, r.Y, d, d, 180, 90); path.AddArc(r.Right - d, r.Y, d, d, 270, 90);
path.AddArc(r.Right - d, r.Bottom - d, d, d, 0, 90); path.AddArc(r.X, r.Bottom - d, d, d, 90, 90);
path.CloseFigure(); return path;
}
private static void DrawCenteredString(Graphics g, string t, Font f, Color c, Rectangle r)
{
var sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
g.DrawString(t, f, new SolidBrush(c), r, sf);
}
private class NavItem
{
public string Label { get; }
public SvgIcon Icon { get; }
public string? Section { get; }
public string? Badge { get; }
public NavItem(string l, SvgIcon i, string? s, string? b) { Label = l; Icon = i; Section = s; Badge = b; }
}
private class SubMenuColorTable : ProfessionalColorTable
{
public override Color ToolStripDropDownBackground => NavyMid;
public override Color MenuItemSelected => AccentBlue;
public override Color MenuItemBorder => Color.Transparent;
public override Color MenuItemSelectedGradientBegin => AccentBlue;
public override Color MenuItemSelectedGradientEnd => AccentBlue;
}
}
public enum SvgIcon { Grid, Users, FileText, Package, DollarSign, User, Settings, Database, Truck, Factory, UserCheck, Briefcase, Support, Inventory, Wallet, ShoppingCart, ShoppingBag, Calendar , UserPlus}
}