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 frmSavedOrders : LLNet.GUI.FormBases.frmBase
    {
        public frmSavedOrders()
        {
            InitializeComponent();

            GUI.CApp.TraducirForm(this);
        }

        public override void Init(object[] pArgs)
        {
            base.Init(pArgs);
            dsPDV1.EnforceConstraints = false;
            dsPDV1.RET_V_PEDIDOS.Clear();
            Utils.Helpers.Merge(
                GUI.CApp.bll.getTypedDataSet(dsPDV1.GetType(), dsPDV1.RET_V_PEDIDOS.TableName),
                dsPDV1);

            gridView1.BestFitColumns();
            dsPDV1.EnforceConstraints = true;
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            Program.GetOrder(Convert.ToDecimal(gridView1.GetFocusedRowCellValue("INTERNO")), "P");
            Close();
        }

        private void gridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                gridView1_DoubleClick(null, null);
        }

        private void frmSavedOrders_FormClosing(object sender, FormClosingEventArgs e)
        {
/*            if (e.CloseReason == CloseReason.UserClosing)
            {
                e.Cancel = true;
                Program.CloseWindow(this);
            }

            if (e.CloseReason == CloseReason.TaskManagerClosing)
            {
                e.Cancel = true;
                Program.CloseWindow(this);
            }*/
        }

        private void btnAceptar_Click(object sender, EventArgs e)
        {
            gridView1_DoubleClick(null, null);
        }

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

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