using LevelCode.License.Business; using LevelCode.License.DataAccess; using LevelCode.License.Models; using LevelCode.License.Models.Enums; using System; using System.Collections.Generic; using System.Windows.Forms; namespace LevelCode.License.Forms { public partial class FrmLicencas : Form { public FrmLicencas() { InitializeComponent(); CarregarTipos(); } private void CarregarTipos() { cmbTipoLicenca.DataSource = Enum.GetValues(typeof(TipoLicencaEnum)); } private void chkSemExpiracao_CheckedChanged(object sender, EventArgs e) { dtpExpiraEm.Enabled = !chkSemExpiracao.Checked; } private void btnSalvar_Click(object sender, EventArgs e) { try { // 🔹 1. LER OS MÓDULOS MARCADOS List modulosSelecionados = new List(); foreach (var item in chkModulos.CheckedItems) { modulosSelecionados.Add(item.ToString()); } // 🔹 2. CRIAR O MODELO COM OS MÓDULOS ModeloLicenca licenca = new ModeloLicenca { Cliente = txtCliente.Text.Trim(), CodigoTipoLicenca = (int)(TipoLicencaEnum)cmbTipoLicenca.SelectedItem, TipoLicenca = cmbTipoLicenca.SelectedItem.ToString(), LimiteMaquinas = Convert.ToInt32(txtLimiteMaquinas.Text), ExpiraEm = chkSemExpiracao.Checked ? (DateTime?)null : dtpExpiraEm.Value, // ✅ AQUI ESTAVA FALTANDO ModulosLista = modulosSelecionados }; using (DbConexao db = new DbConexao()) { LicencaDAL dal = new LicencaDAL(db); LicencaService service = new LicencaService(dal); int id = service.CriarLicenca(licenca); MessageBox.Show( "Licença criada com sucesso!\nID: " + id, "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show( ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }