206 lines
8.6 KiB
C#
206 lines
8.6 KiB
C#
using BLL;
|
|
using MLL;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
using System.Linq;
|
|
|
|
namespace UI
|
|
{
|
|
public class OrcaPadraoCadastroPanel : UserControl
|
|
{
|
|
// ── DESIGN ──────────────────────────────────────────────────────────
|
|
private readonly Color AccentBlue = Color.FromArgb(37, 99, 235);
|
|
private readonly Color BorderColor = Color.FromArgb(226, 232, 240);
|
|
private readonly Color TextDark = Color.FromArgb(30, 41, 59);
|
|
|
|
// ── CONTROLES ───────────────────────────────────────────────────────
|
|
private RoundTextBox txtCodigo = null!;
|
|
private RoundTextBox txtNome = null!;
|
|
private TextBox txtObs = null!;
|
|
private ComboBox cmbUsado = null!;
|
|
private ComboBox cmbShowObs = null!;
|
|
private DataGridView dgvItens = null!;
|
|
|
|
private ModeloOrcaPadrao _modelo = null!;
|
|
public event Action? OnVoltar;
|
|
|
|
public OrcaPadraoCadastroPanel(ModeloOrcaPadrao modelo)
|
|
{
|
|
_modelo = modelo;
|
|
Dock = DockStyle.Fill;
|
|
BackColor = Color.White;
|
|
InitializeComponent();
|
|
PreencherCampos();
|
|
CarregarItens();
|
|
}
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
var pnlHeader = new Panel { Dock = DockStyle.Top, Height = 60, BackColor = Color.FromArgb(248, 250, 252) };
|
|
|
|
var lblTitulo = new Label
|
|
{
|
|
Text = _modelo.ID_ORCA_PADRAO == 0 ? "Novo Orçamento Padrão" : "Editando Modelo",
|
|
Font = new Font("Segoe UI", 12f, FontStyle.Bold),
|
|
ForeColor = TextDark,
|
|
Location = new Point(20, 18),
|
|
AutoSize = true
|
|
};
|
|
|
|
var btnSalvar = new RoundButton
|
|
{
|
|
Text = "Salvar Modelo",
|
|
Size = new Size(130, 35),
|
|
Location = new Point(Width - 150, 12),
|
|
Anchor = AnchorStyles.Top | AnchorStyles.Right,
|
|
BackColor = AccentBlue,
|
|
ForeColor = Color.White,
|
|
Cursor = Cursors.Hand
|
|
};
|
|
btnSalvar.Click += (s, e) => Salvar();
|
|
|
|
var btnVoltar = new RoundButton
|
|
{
|
|
Text = "Voltar",
|
|
Size = new Size(80, 35),
|
|
Location = new Point(Width - 240, 12),
|
|
Anchor = AnchorStyles.Top | AnchorStyles.Right,
|
|
BackColor = Color.FromArgb(203, 213, 225),
|
|
ForeColor = TextDark,
|
|
Cursor = Cursors.Hand
|
|
};
|
|
btnVoltar.Click += (s, e) => OnVoltar?.Invoke();
|
|
|
|
pnlHeader.Controls.AddRange(new Control[] { lblTitulo, btnSalvar, btnVoltar });
|
|
Controls.Add(pnlHeader);
|
|
|
|
// Campos de Cabeçalho
|
|
txtCodigo = AddCampo("Código", 20, 80, 150);
|
|
txtNome = AddCampo("Nome do Modelo (Ex: Manutenção Básica)", 180, 80, 400);
|
|
|
|
AddLabel("Ativo?", 20, 140);
|
|
cmbUsado = new ComboBox { Location = new Point(20, 160), Size = new Size(150, 26), DropDownStyle = ComboBoxStyle.DropDownList };
|
|
cmbUsado.Items.AddRange(new[] { "S", "N" });
|
|
|
|
AddLabel("Exibir Obs no Impresso?", 180, 140);
|
|
cmbShowObs = new ComboBox { Location = new Point(180, 160), Size = new Size(150, 26), DropDownStyle = ComboBoxStyle.DropDownList };
|
|
cmbShowObs.Items.AddRange(new[] { "S", "N" });
|
|
|
|
// Campo de Observação (Ajustado para dar espaço ao Grid)
|
|
AddLabel("Texto Padrão do Orçamento / Observações", 20, 205);
|
|
txtObs = new TextBox
|
|
{
|
|
Location = new Point(20, 225),
|
|
Size = new Size(Width - 40, 120), // Altura fixa para caber o grid embaixo
|
|
Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
|
|
Multiline = true,
|
|
ScrollBars = ScrollBars.Vertical,
|
|
Font = new Font("Consolas", 10f),
|
|
BorderStyle = BorderStyle.FixedSingle
|
|
};
|
|
|
|
// Grid de Itens
|
|
AddLabel("Itens do Modelo (Peças / Serviços)", 20, 360);
|
|
dgvItens = new DataGridView
|
|
{
|
|
Location = new Point(20, 380),
|
|
Size = new Size(Width - 40, Height - 400),
|
|
Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right,
|
|
BackgroundColor = Color.White,
|
|
BorderStyle = BorderStyle.FixedSingle,
|
|
AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
|
|
AllowUserToResizeRows = false,
|
|
RowHeadersVisible = false
|
|
};
|
|
|
|
ConfigurarGridItens();
|
|
|
|
Controls.AddRange(new Control[] { cmbUsado, cmbShowObs, txtObs, dgvItens });
|
|
}
|
|
|
|
private void ConfigurarGridItens()
|
|
{
|
|
dgvItens.Columns.Clear();
|
|
dgvItens.Columns.Add(new DataGridViewTextBoxColumn { Name = "colTipo", HeaderText = "Tipo (P/S)", FillWeight = 15 });
|
|
dgvItens.Columns.Add(new DataGridViewTextBoxColumn { Name = "colCodItem", HeaderText = "Cód. Item", FillWeight = 25 });
|
|
dgvItens.Columns.Add(new DataGridViewTextBoxColumn { Name = "colQtd", HeaderText = "Quantidade", FillWeight = 20 });
|
|
dgvItens.Columns.Add(new DataGridViewTextBoxColumn { Name = "colCodigoInterno", HeaderText = "Código Barras", FillWeight = 40 });
|
|
}
|
|
|
|
private RoundTextBox AddCampo(string label, int x, int y, int w)
|
|
{
|
|
AddLabel(label, x, y - 20);
|
|
var txt = new RoundTextBox { Location = new Point(x, y), Size = new Size(w, 30), Radius = 5, BorderColor = BorderColor };
|
|
Controls.Add(txt);
|
|
return txt;
|
|
}
|
|
|
|
private void AddLabel(string texto, int x, int y)
|
|
{
|
|
Controls.Add(new Label { Text = texto, Location = new Point(x, y), AutoSize = true, Font = new Font("Segoe UI", 8.5f, FontStyle.Bold), ForeColor = TextDark });
|
|
}
|
|
|
|
private void PreencherCampos()
|
|
{
|
|
txtCodigo.Text = _modelo.CODIGO;
|
|
txtNome.Text = _modelo.NOME;
|
|
txtObs.Text = _modelo.OBS;
|
|
cmbUsado.SelectedItem = string.IsNullOrEmpty(_modelo.USADO) ? "S" : _modelo.USADO;
|
|
cmbShowObs.SelectedItem = string.IsNullOrEmpty(_modelo.SHOW_OBS) ? "S" : _modelo.SHOW_OBS;
|
|
}
|
|
|
|
private void CarregarItens()
|
|
{
|
|
if (_modelo.ID_ORCA_PADRAO == 0) return;
|
|
|
|
// BLLOrcaPadraoItens bllItens = new BLLOrcaPadraoItens(DadosDaConexao.ObterConexao());
|
|
// var itens = bllItens.ListarPorOrcamento(_modelo.CODIGO);
|
|
// foreach(var i in itens) dgvItens.Rows.Add(i.ITEM_TIPO, i.ITEM_COD, i.ITEM_QTD, i.CODIGO);
|
|
}
|
|
|
|
private void Salvar()
|
|
{
|
|
if (string.IsNullOrEmpty(txtCodigo.Text))
|
|
{
|
|
MessageBox.Show("Informe o código do modelo."); return;
|
|
}
|
|
|
|
_modelo.CODIGO = txtCodigo.Text;
|
|
_modelo.NOME = txtNome.Text;
|
|
_modelo.OBS = txtObs.Text;
|
|
_modelo.USADO = cmbUsado.SelectedItem?.ToString() ?? "S";
|
|
_modelo.SHOW_OBS = cmbShowObs.SelectedItem?.ToString() ?? "S";
|
|
|
|
// Coleta os itens do Grid
|
|
List<ModeloOrcaPadraoItens> listaItens = new List<ModeloOrcaPadraoItens>();
|
|
foreach (DataGridViewRow row in dgvItens.Rows)
|
|
{
|
|
if (row.IsNewRow) continue;
|
|
|
|
listaItens.Add(new ModeloOrcaPadraoItens
|
|
{
|
|
COD_ORCA = _modelo.CODIGO,
|
|
ITEM_TIPO = row.Cells["colTipo"].Value?.ToString() ?? "",
|
|
ITEM_COD = row.Cells["colCodItem"].Value?.ToString() ?? "",
|
|
ITEM_QTD = row.Cells["colQtd"].Value?.ToString() ?? "1",
|
|
CODIGO = row.Cells["colCodigoInterno"].Value?.ToString() ?? ""
|
|
});
|
|
}
|
|
|
|
try
|
|
{
|
|
// BLLOrcaPadrao bll = new BLLOrcaPadrao(DadosDaConexao.ObterConexao());
|
|
// bll.SalvarComItens(_modelo, listaItens);
|
|
|
|
MessageBox.Show("Modelo e Itens salvos com sucesso!", "LevelOS", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
OnVoltar?.Invoke();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show("Erro ao salvar: " + ex.Message);
|
|
}
|
|
}
|
|
}
|
|
} |