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

97 lines
3.5 KiB
C#

using CPM;
using MLL;
using System;
using System.Drawing;
using System.Globalization;
using System.Windows.Forms;
namespace UI
{
public class OrdensInsumosPanel : FormularioModelo
{
private LV_TEXTBOX1 txtId, txtCodOs, txtCodItem, txtQtd, txtCustoUnit, txtCustoTotal, txtObs;
public OrdensInsumosPanel()
{
this.Titulo = "LANÇAMENTO DE INSUMOS E MATERIAIS";
MontarInterface();
VincularEventosCalculo();
}
private void MontarInterface()
{
// --- SEÇÃO 1: IDENTIFICAÇÃO DO ITEM ---
content.Controls.Add(CreateSectionHeader("Identificação do Insumo", 20));
txtId = AddInput(content, "ID INSUMO", 20, 55, 100, 28, true);
txtCodOs = AddInput(content, "Nº DA O.S.", 130, 55, 120, 28, true);
txtCodItem = AddInput(content, "CÓD. PRODUTO", 260, 55, 150, 28);
// Botão auxiliar para buscar produto (opcional, aproveitando seu estilo)
var btnBuscar = CreateToolbarButton("Buscar Item", AccentBlue);
btnBuscar.Location = new Point(420, 71);
btnBuscar.Size = new Size(100, 28);
content.Controls.Add(btnBuscar);
// --- SEÇÃO 2: VALORES E QUANTIDADES ---
content.Controls.Add(CreateSectionHeader("Quantidades e Custos", 115));
txtQtd = AddInput(content, "QUANTIDADE", 20, 150, 100, 28);
txtCustoUnit = AddInput(content, "CUSTO UNITÁRIO (R$)", 130, 150, 150, 28);
txtCustoTotal = AddInput(content, "CUSTO TOTAL (R$)", 290, 150, 150, 28, true); // Total é calculado
// --- SEÇÃO 3: OBSERVAÇÕES ---
content.Controls.Add(CreateSectionHeader("Observações Adicionais", 210));
txtObs = AddInput(content, "DETALHES DO MATERIAL", 20, 245, 550, 60);
}
private void VincularEventosCalculo()
{
// Eventos para calcular o custo total automaticamente ao digitar
txtQtd.TextChanged += (s, e) => CalcularTotal();
txtCustoUnit.TextChanged += (s, e) => CalcularTotal();
}
private void CalcularTotal()
{
decimal.TryParse(txtQtd.Text, out decimal qtd);
decimal.TryParse(txtCustoUnit.Text, out decimal unit);
decimal total = qtd * unit;
txtCustoTotal.Text = total.ToString("N2");
}
// --- MÉTODOS DO MODELO ---
protected override void OnNovo()
{
txtCodItem.Text = "";
txtQtd.Text = "1";
txtCustoUnit.Text = "0,00";
txtCustoTotal.Text = "0,00";
txtObs.Text = "";
txtCodItem.Focus();
}
protected override void OnSalvar()
{
var insumo = new ModeloOrdensInsumos
{
COD_OS = txtCodOs.Text,
COD_ITEM = txtCodItem.Text,
QTD = txtQtd.Text,
CUSTO_UNIT = txtCustoUnit.Text,
CUSTO = txtCustoTotal.Text,
OBSERVACOES = txtObs.Text
};
// Chamada para a BLL...
MessageBox.Show("Insumo registrado com sucesso!", "LevelOS", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
protected override void OnAlterar() { /* Implementar busca e edição */ }
protected override void OnExcluir() { /* Implementar exclusão */ }
protected override void OnLocalizar() { /* Implementar busca */ }
protected override void OnCancelar() { OnNovo(); }
}
}