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.Offers
{
    public partial class dlgOfferOptions : GUI.FormBases.frmBase
    {
        public dlgOfferOptions()
        {
            InitializeComponent();

            GUI.CApp.TraducirForm(this);
        }

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

        private void btnLinea_Click(object sender, EventArgs e)
        {
            if (Program.FrmMainPos.DsPedido.TDA_DETALLE_PEDIDO.Count > 0)
            {
                Utils.QueryParams qp = new LLNet.Utils.QueryParams();
                qp.AddReplaceParam("DOCUMENTO", Program.FrmMainPos.Order.ToString());
                qp.AddReplaceParam("LINEA", Program.FrmMainPos.pos.ctlDetail1.bgvDetail.GetFocusedRowCellValue("LINEA").ToString());
                GUI.CApp.bll.ExecuteSql("ApplyOfferToDocLine", qp, "PDV");
                Program.FrmMainPos.RefreshData();

                Close();
                Dispose();
            }
            else
                GUI.CApp.ShowMessage("No ha ingresado ningún producto al pedido", "Ofertas", true);
            
        }

        private void btnPedido_Click(object sender, EventArgs e)
        {
            if (Program.FrmMainPos.DsPedido.TDA_DETALLE_PEDIDO.Count > 0)
            {
                Utils.QueryParams qp = new LLNet.Utils.QueryParams();
                qp.AddReplaceParam("DOCUMENTO", Program.FrmMainPos.Order.ToString());
                GUI.CApp.bll.ExecuteSql("ApplyOfferToDocument", qp, "PDV");
                Program.FrmMainPos.RefreshData();

                Close();
                Dispose();
            }
            else
                GUI.CApp.ShowMessage("No ha ingresado ningún producto al pedido", "Ofertas", true);
        }

        private void dlgOfferOptions_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Escape :
                    simpleButton5_Click(null, null);
                    break;
                case Keys.F12 :
                    btnPedido_Click(null, null);
                    break;
            }
        }
    }
}