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
{
    public partial class FrmHijosEcom : Form
    {
        private string pSkuAlt;
        private decimal pcantidad, plinea;

        public FrmHijosEcom(string pSKU, decimal cantidad, decimal linea)
        {
            InitializeComponent();
            this.pSkuAlt = pSKU;
            this.plinea = linea;
            this.pcantidad = cantidad * -1;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FrmHijosEcom_Load(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            Utils.QueryParams param = new LLNet.Utils.QueryParams();
            param.AddReplaceParam("pSKU", this.pSkuAlt);

            ds = GUI.CApp.bll.getDataSet("PDV", "ListaSkuHijos", param);
            dgvHijosEcom.DataSource = ds.Tables[0];

        }

        private void dgvHijosEcom_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            string skuhijo = dgvHijosEcom.Rows[dgvHijosEcom.CurrentRow.Index].Cells[0].Value.ToString();

            Utils.QueryParams param = new LLNet.Utils.QueryParams();
            param.AddReplaceParam("pSKUALT", skuhijo);
        
            int skuecom = Convert.ToInt32(GUI.CApp.bll.GetSingleValue("CodigoSku", param, "PDV"));

            param.Clear();

            param.AddReplaceParam("pDOCUMENTO", GUI.CApp.Document.ToString());
            param.AddReplaceParam("pLINEA", plinea.ToString());
            param.AddReplaceParam("pCANTIDAD", pcantidad.ToString());
            param.AddReplaceParam("pSKU", skuecom.ToString());
            param.AddReplaceParam("pSKUALT", skuhijo);
            param.AddReplaceParam("pUSUARIO", GUI.CApp.usuario);
            GUI.CApp.bll.ExecuteSql("GuardarHijosEcom", param, "PDV");

            GUI.CApp.ShowMessage("El codigo seleccionado es: " + skuhijo, "Codigo Hijo Ecommerce", true);

            this.Close();
        }

    }
}
