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.MainForms.Forms
{
    public partial class frmComplementarios : LLNet.GUI.FormBases.frmBase
    {
        public frmComplementarios()
        {
            InitializeComponent();

            GUI.CApp.TraducirForm(this);
        }

        public override void Init(object[] pArgs)
        {
            dsPDV1 = Program.FrmMainPos.DsPedido;
            gridControl1.DataSource = dsPDV1;

            base.Init(pArgs);
        }

        private void frmComplementarios_Load(object sender, EventArgs e)
        {

        }

        private void vGridControl1_Click(object sender, EventArgs e)
        {

        }

        private void frmComplementarios_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 btnAceptar_Click(object sender, EventArgs e)
        {
            gridView1.PostEditor();
            gridView1.UpdateCurrentRow();
            for (int i = 0; i < gridView1.RowCount; i++)
            {
                int rowHandle = gridView1.GetRowHandle(i);
                object cant = gridView1.GetRowCellValue(rowHandle, colCantidad);
                if (cant != null && cant != DBNull.Value)
                {
                    decimal dCant = Convert.ToDecimal(cant);
                    if (dCant > 0)
                    {
                        Program.FrmMainPos.pos.ctlAddSkus1.InsertOrderLine(
                            gridView1.GetRowCellValue(rowHandle, colSKU_ALTERNO).ToString(), dCant, GUI.CApp.usuario, null, null);
                    }
                }
            }
            Program.FrmMainPos.RefreshData();
            DialogResult = DialogResult.OK;

        }

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

