LevelOS-Core/UI/Dashboards/Cadastros/ItensFotosGaleriaPanel.cs

150 lines
5.0 KiB
C#

using CPM;
using MLL;
using System;
using System.Drawing;
using System.Windows.Forms;
using UI;
namespace UI
{
public partial class ItensFotosGaleriaPanel : FormularioModelo
{
private ModeloItensFotosML _fotoItem = new ModeloItensFotosML();
// Controles - Identificação
private LV_TEXTBOX1 txtId, txtCodigo, txtCodItem, txtNomeItem;
private Button btnBuscaItem;
// Controles - Galeria e Links
private LV_TEXTBOX1 txtLinkFoto;
private PictureBox picPreview;
private Button btnTestarLink;
public ItensFotosGaleriaPanel()
{
this.Titulo = "Galeria de Fotos (Integração E-commerce)";
MontarInterface();
}
private void MontarInterface()
{
// --- SEÇÃO 1: Vínculo do Produto ---
content.Controls.Add(CreateSectionHeader("PRODUTO VINCULADO", 20));
txtId = AddInput(content, "ID", 20, 50, 70, 30, true);
txtCodigo = AddInput(content, "CÓD. VÍNCULO", 100, 50, 120, 30);
txtCodItem = AddInput(content, "CÓD. ITEM", 230, 50, 100, 30);
btnBuscaItem = CriarBotaoLupa(335, 66, OnBuscaItem);
txtNomeItem = AddInput(content, "DESCRIÇÃO DO PRODUTO", 375, 50, 460, 30, true);
// --- SEÇÃO 2: Gerenciamento da Imagem ---
content.Controls.Add(CreateSectionHeader("LINK DA IMAGEM E PREVIEW", 115));
// Link da Foto (URL do Mercado Livre ou Servidor)
txtLinkFoto = AddInput(content, "URL DA FOTO (LINK_FOTO)", 20, 145, 650, 30);
btnTestarLink = new Button
{
Text = "VISUALIZAR",
Location = new Point(680, 161),
Size = new Size(155, 30),
BackColor = Color.FromArgb(0, 120, 215),
ForeColor = Color.White,
FlatStyle = FlatStyle.Flat,
Cursor = Cursors.Hand
};
btnTestarLink.Click += OnTestarLink;
content.Controls.Add(btnTestarLink);
// Preview Box
picPreview = new PictureBox
{
Location = new Point(20, 200),
Size = new Size(815, 200),
BorderStyle = BorderStyle.FixedSingle,
SizeMode = PictureBoxSizeMode.Zoom,
BackColor = Color.WhiteSmoke
};
content.Controls.Add(picPreview);
Label lblDica = new Label
{
Text = "* Cole o link da imagem acima para validar a visualização antes de salvar.",
Location = new Point(20, 410),
AutoSize = true,
ForeColor = Color.Gray,
Font = new Font("Segoe UI", 8, FontStyle.Italic)
};
content.Controls.Add(lblDica);
content.Height = 460;
}
private Button CriarBotaoLupa(int x, int y, EventHandler clickEvent)
{
var btn = new Button
{
Text = "🔍",
Location = new Point(x, y),
Size = new Size(32, 30),
BackColor = AccentBlue,
ForeColor = Color.White,
FlatStyle = FlatStyle.Flat,
Cursor = Cursors.Hand
};
btn.FlatAppearance.BorderSize = 0;
btn.Click += clickEvent;
content.Controls.Add(btn);
return btn;
}
private void OnBuscaItem(object sender, EventArgs e) => MessageBox.Show("Selecionar Produto");
private void OnTestarLink(object sender, EventArgs e)
{
try
{
if (!string.IsNullOrEmpty(txtLinkFoto.Text))
picPreview.Load(txtLinkFoto.Text);
}
catch
{
MessageBox.Show("Não foi possível carregar a imagem do link informado.", "Erro de Link", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void PreencherModel()
{
_fotoItem.CODIGO = txtCodigo.Text;
_fotoItem.COD_ITEM = txtCodItem.Text;
_fotoItem.LINK_FOTO = txtLinkFoto.Text;
}
protected override void OnNovo()
{
_fotoItem = new ModeloItensFotosML();
txtLinkFoto.Text = string.Empty;
picPreview.Image = null;
txtCodItem.Focus();
}
protected override void OnSalvar()
{
try
{
PreencherModel();
MessageBox.Show("Link de imagem salvo com sucesso!", "Galeria ML", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show("Erro: " + ex.Message);
}
}
protected override void OnAlterar() { }
protected override void OnExcluir() { }
protected override void OnLocalizar() { }
protected override void OnCancelar() { OnNovo(); }
}
}