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

namespace LLNet.Tienda.Dialogs.Discounts
{
    public partial class dlgEfectivoEmpresa : GUI.FormBases.frmBase
    {
        private string efectivoEmpresaCaption;
        private Utils.QueryParams qp = new LLNet.Utils.QueryParams();
        private decimal maxEfectivo;

        public dlgEfectivoEmpresa()
        {
            InitializeComponent();
            efectivoEmpresaCaption = GUI.CApp.GetParam("TPEE").ToString();

            qp.AddReplaceParam("DOCUMENTO", Program.FrmMainPos.Order.ToString());
            maxEfectivo = Convert.ToDecimal(GUI.CApp.bll.GetSingleValue("MaximoEfectivoEmpresa", qp, "PDV"));
            txtEfectivoEmp.EditValue = maxEfectivo;

            GUI.CApp.TraducirForm(this);
        }

        private void panelControl2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void btnAceptar_Click(object sender, EventArgs e)
        {
            if (Convert.ToDecimal(txtEfectivoEmp.EditValue) > maxEfectivo)
            {
                GUI.CApp.ShowMessage(GUI.CApp.TraducirPalabra("El monto de ") + efectivoEmpresaCaption + GUI.CApp.TraducirPalabra(" no puede ser mayor al monto sugerido"), efectivoEmpresaCaption,false);
            }
            else
            {
                qp.AddReplaceParam("DESCUENTO", txtEfectivoEmp.EditValue.ToString());
                qp.AddReplaceParam("TIPO","M");
                qp.AddReplaceParam("USUARIO",GUI.CApp.usuario);
                qp.AddReplaceParam("ACUMULA","1");
                qp.AddReplaceParam("LINEA","NULL");
                qp.AddReplaceParam("CLASIFICACION", GUI.CApp.GetParam("CPEE").ToString()); 

                GUI.CApp.bll.ExecuteSql("CreateDiscountEE", qp, "PDV");
                Program.FrmMainPos.RefreshData();
                DialogResult = DialogResult.OK;
            }
        }

        private void btnCancelar_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void dlgEfectivoEmpresa_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            { 
                case Keys.F12:
                    btnAceptar_Click(null, null);
                    break;
                case Keys.Escape:
                    btnCancelar_Click(null, null);
                    break;
            }
        }

        private void dlgEfectivoEmpresa_Load(object sender, EventArgs e)
        {
            txtEfectivoEmp.Focus();
        }
    }
}