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

namespace LLNet.Tienda.MainForms.Forms.MisPuntos
{
    public partial class FrmReemplazoMemb : Form
    {
        private static string _cedula;
        private static FrmEkonoPlus _frmPlus;

        public FrmReemplazoMemb(string tarjetaActual,string cedula, FrmEkonoPlus frmPlus)
        {
            InitializeComponent();
            txtTarjetaActual.Text = tarjetaActual;
            _cedula = cedula;
            _frmPlus = frmPlus;
        }

        private void FrmReemplazoMemb_Load(object sender, EventArgs e)
        {

        }

        private void btnAceptarReemplazarTargera_Click(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(txtTarjetaNueva.Text))
                {
                    Utils.QueryParams qp = new LLNet.Utils.QueryParams();
                    qp.AddReplaceParam("P_C_CEDULA", _cedula);
                    qp.AddReplaceParam("P_C_TARJETA", txtTarjetaNueva.Text);
                    qp.AddReplaceParam("P_C_MODIFICADO_POR", GUI.CApp.usuario);
                    GUI.CApp.bll.ExecuteSql("PLUS_A_ACTUALI_TARJETA_MEMB", qp, "PDV");
                    LLNet.GUI.CApp.ShowMessage("Cliente asociado exitosamente", "Afiliación - Club ekono Plus", true);
                    _frmPlus.GET_ConsDatosCed_CPLUS();
                    this.Dispose();
                    this.Close();
                }
                else
                {
                    LLNet.GUI.CApp.ShowMessage("Ingrese la nueva tarjeta plus", "Afiliación - Club ekono Plus", true);
                }
            }
            catch (Exception ex)
            {

                LLNet.GUI.CApp.ShowMessage(ex.Message,"Ocurrio un problema al actualizar la tarjeta", true);
                this.Dispose();
                this.Close();
            }
            
        }

        private void txtTarjetaNueva_KeyPress(object sender, KeyPressEventArgs e)
        {
            const char Delete = (char)8;
            e.Handled = !Char.IsDigit(e.KeyChar) && e.KeyChar != Delete;
            if (txtTarjetaNueva.Text.Length >= 15)
            {
                btnAceptarReemplazarTargera.Enabled = true;
            }
            else
            {
                btnAceptarReemplazarTargera.Enabled = false;
            }
        }

        //private void FrmReemplazoMemb_FormClosing(object sender, FormClosingEventArgs e)
        //{
        //    if(e.CloseReason == CloseReason.UserClosing)
        //    {
        //    }
        //// Prompt user to save his data

        //    if(e.CloseReason == CloseReason.WindowsShutDown)
        //    {
        //    }
        //}
    }
}
