using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using Microsoft.Win32;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace LLNet.GUI
{
    public partial class frmLicence : LLNet.GUI.FormBases.frmBase
    {
        public frmLicence()
        {
            InitializeComponent();
        }

        bool result = false;
        private string procId = null;
        public override void Init(object[] pArgs)
        {
            base.Init(pArgs);
            procId = Utils.Helpers.ObjToStr(pArgs[0]);
            textEdit1.EditValue = procId;
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            string licence = Utils.Helpers.ObjToStr(textEdit2.EditValue);
            try
            {
                result = LLNet.GenAdv.GenAdv.CompareLicence(licence, procId, "TDA800");
            }
            catch (Exception ex)
            {
                GUI.CApp.ShowMessage(ex.Message, "Verificación de Licencia", true);
            }

            if (!result)
            {
                GUI.CApp.ShowMessage("Licencia no válida", "Licencia no válida", true);
                Application.Exit();
            }
            else
            {
                RegistryKey key = Registry.CurrentUser;
                key = key.OpenSubKey(@"Software\Logistika\POS Retail 8.0.0", true);
                key.SetValue("Licence", licence);
            }
            DialogResult = DialogResult.OK;
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void frmLicence_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!result) Application.Exit();
        }
    }
}