85 lines
2.6 KiB
C#
85 lines
2.6 KiB
C#
using Levelcode_licenseCliente.Models;
|
|
using Levelcode_licenseCliente.Services;
|
|
using System;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
|
|
namespace LevelCode.App.Cliente.Forms
|
|
{
|
|
public partial class FrmAtivacao : Form
|
|
{
|
|
private string _arquivoLicenca;
|
|
|
|
// ⚠️ Ajuste sua connection string aqui
|
|
private readonly string _connectionString =
|
|
"Server=206.42.13.180;Database=Levelcode-ModasMVP;User Id=nicolas;Password=Nike12122020*##;";
|
|
|
|
public FrmAtivacao()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void btnSelecionar_Click(object sender, EventArgs e)
|
|
{
|
|
OpenFileDialog ofd = new OpenFileDialog
|
|
{
|
|
Filter = "Arquivo de Licença (*.key)|*.key"
|
|
};
|
|
|
|
if (ofd.ShowDialog() == DialogResult.OK)
|
|
{
|
|
_arquivoLicenca = ofd.FileName;
|
|
txtCaminhoLicenca.Text = _arquivoLicenca;
|
|
txtStatus.Text = "Arquivo de licença selecionado.";
|
|
}
|
|
}
|
|
|
|
private void btnAtivar_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(_arquivoLicenca))
|
|
throw new Exception("Selecione o arquivo de licença.");
|
|
|
|
string caminhoPublicKey =
|
|
Path.Combine(
|
|
AppDomain.CurrentDomain.BaseDirectory,
|
|
"public.key");
|
|
|
|
AtivacaoService service =
|
|
new AtivacaoService(_connectionString);
|
|
|
|
ModeloLicenca licenca =
|
|
service.Ativar(_arquivoLicenca, caminhoPublicKey);
|
|
|
|
// 💾 Salvar ativação local
|
|
service.SalvarAtivacaoLocal(licenca);
|
|
|
|
txtStatus.Text =
|
|
"Sistema ativado com sucesso!\n\n" +
|
|
$"Cliente: {licenca.Cliente}\n" +
|
|
$"Expira em: {licenca.ExpiraEm?.ToShortDateString() ?? "Nunca"}";
|
|
|
|
MessageBox.Show(
|
|
"Sistema ativado com sucesso!",
|
|
"Ativação",
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Information);
|
|
|
|
this.DialogResult = DialogResult.OK;
|
|
this.Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
txtStatus.Text = "Erro: " + ex.Message;
|
|
|
|
MessageBox.Show(
|
|
ex.Message,
|
|
"Erro na ativação",
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|