using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data;

namespace LLNet.Tienda.MainForms.Forms.CreditEko
{
    public partial class FrmBuscarCliente : GUI.FormBases.frmBase
    {
        public string Nombre
        {
            get
            {
                if (gridView1.RowCount > 0)
                {
                    return gridView1.GetFocusedRowCellValue(colNOMBRE).ToString();
                }
                else
                {
                    return null;
                }
            }
        }

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

        private int vtipo;

        public FrmBuscarCliente(int tipo)
        {
            vtipo = tipo;
            InitializeComponent();
            txtSearch.Focus();
        }

        private void txtSearch_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Utils.QueryParams qp = new LLNet.Utils.QueryParams();
                qp.AddReplaceParam("BUSQUEDA", "%"+ txtSearch.Text+ "%");
                //Consulta los clientes de la BD
                DataSet dsB ;
                if (vtipo == 1)
                {
                    dsB = GUI.CApp.bll.getDataSet("PDV", "WMS_ClICREDITOEK", qp);
                }
                else
                {
                    if (vtipo == 2)
                    {
                        dsB = GUI.CApp.bll.getDataSet("PDV", "WMS_ClIINSTACREDIT", qp);
                    }
                    else
                    {
                        dsB = GUI.CApp.bll.getDataSet("PDV", "WMS_ClIMULTICRED", qp);
                    }
                }
                if (dsB.Tables.Count > 0)
                {
                    gCtrlCli.DataSource = dsB.Tables[0];
                    gCtrlCli.Refresh();
                }
                else
                {
                    gCtrlCli.DataSource = null;
                    gCtrlCli.Refresh();
                }
            }
        }

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

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

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

        private void gCtrlCli_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Tab)
                txtSearch.Focus();
        }
    }
}