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

            GUI.CApp.TraducirForm(this);
        }

        public string Serie
        {
            get
            {
                if (gridView1.RowCount > 0)
                {
                    return gridView1.GetFocusedRowCellValue(colSERIE).ToString();
                }
                else
                {
                    return null;
                }
            }
        }

        public string Factura
        {
            get 
            {
                if (gridView1.RowCount > 0)
                {
                    return gridView1.GetFocusedRowCellValue(colNO_DOCUMENTO).ToString();
                }
                else
                {
                    return null;
                }
            }
        }

        private void frmFindSku_Load(object sender, EventArgs e)
        {
            gridView1.BestFitColumns();
        }

        private void txtSearch_KeyDown(object sender, KeyEventArgs e)
        {
            
            if (e.KeyCode == Keys.Enter)
            {
                Cursor oldCursor = Cursor.Current;
                Cursor.Current = Cursors.WaitCursor;
                Utils.QueryParams qp = new LLNet.Utils.QueryParams();
                if (GUI.CApp.GetParam("HBMM").ToString() == "X")
                {
                    qp.AddReplaceParam("BUSQUEDA", "%" + txtSearch.EditValue.ToString().ToUpper() + "%");
                }
                else
                {
                    qp.AddReplaceParam("BUSQUEDA", "%" + txtSearch.EditValue.ToString() + "%");
                }
                Utils.Helpers.Merge(GUI.CApp.bll.getTypedDataSet(dsPDV1.GetType(), dsPDV1.TDA_V_FACTURAS.TableName, qp,"BusquedaFacturas"), dsPDV1);

                gridView1.BestFitColumns();
                gridControl1.Focus();
                Cursor.Current = oldCursor;
            }

        }

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

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
        }

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

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
        }

        private void frmFindInvoice_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.F12:
                    DialogResult = DialogResult.OK;
                    break;
                case Keys.Escape:
                    DialogResult = DialogResult.Cancel;
                    break;
                case Keys.F2:
                    txtSearch.Focus();
                    txtSearch.SelectAll();
                    break;
            }

        }
    }
}