using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using LLNet.GUI;
using LLNet.Utils;

namespace LLNet.Tienda.MainForms.Forms.GiftCard
{
    public partial class FrmReemplazar : Form
    {
        public FrmReemplazar()
        {
            InitializeComponent();

            this.txtTarjetaV.Focus();
        }

        #region Reemplazar
        /// <summary>
        /// Reemplaza una gift card
        /// </summary>
        private void Reemplazar()
        {
            Utils.QueryParams qp = new QueryParams();
            qp.AddReplaceParam("TARJETAV", this.txtTarjetaV.Text);
            qp.AddReplaceParam("TARJETAN", this.txtTarjetaN.Text);
            qp.AddReplaceParam("USUARIO", GUI.CApp.usuario);

            GUI.CApp.bll.ExecuteSql("WMS_P_REEMPLAZARGC", qp, "PDV");
        }
        #endregion

        #region sbtnSalir_Click
        private void sbtnSalir_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
        #endregion

        #region btnAceptar_Click
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            try
            {
                //Longitud gift card
                int longGC = int.Parse(Helpers.Nvl(CApp.GetParam("LGC"), "").ToString());

                if (this.txtTarjetaV.Text == String.Empty)
                {
                    CApp.ShowMessage("Ingrese la tarjeta anterior", "Gift Card", true);
                    this.txtTarjetaV.Focus();
                }
                else if (this.txtTarjetaV.Text.Length != longGC)
                {
                    CApp.ShowMessage("El número de la gift card anterior deber ser de " + longGC + " caracteres", "Gift Card", true);
                    this.txtTarjetaV.Focus();
                }
                else if (this.txtTarjetaN.Text == String.Empty)
                {
                    CApp.ShowMessage("Ingrese la tarjeta nueva", "Gift Card", true);
                    this.txtTarjetaN.Focus();
                }
                else if (this.txtTarjetaN.Text.Length != longGC)
                {
                    CApp.ShowMessage("El número de la gift card nueva deber ser de " + longGC + " caracteres", "Gift Card", true);
                    this.txtTarjetaN.Focus();
                }
                else
                {
                    Reemplazar();
                }
            }
            catch (FormatException)
            {
                CApp.ShowMessage("Digite un monto válido", "Gift Card", true);
            }
            catch (Exception ex)
            {
                CApp.ShowMessage(ex.Message, "Gift Card", true);
            }
        }
        #endregion
    }
}