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

            GUI.CApp.TraducirForm(this);
        }

        public decimal Clasificacion
        {
            get
            {
                return Convert.ToDecimal(treeList1.FocusedNode.GetValue("CLASIFICACION"));
            }
        }

        public String DescRegion
        {
            get
            {
                return treeList1.FocusedNode.GetValue("REGION").ToString();
            }
        }

        private void frmRegionGeografica_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.F2:
                    btnBuscar_Click(null, null);
                    break;
                case Keys.F12 :
                    btnAceptar.PerformClick();
                    break;
                case Keys.Escape :
                    btnSalir.PerformClick();
                    break;
            }
        }

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

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

        private void frmRegionGeografica_Load(object sender, EventArgs e)
        {
            Utils.Helpers.Merge(GUI.CApp.bll.getTypedDataSet(dsPDV1.GetType(), dsPDV1.TDA_V_REGION_GEOGRAFICA.TableName), dsPDV1);
            treeList1.MoveFirst();
            treeList1.Focus();
        }

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

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

        private void textEdit1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Utils.QueryParams qp = new LLNet.Utils.QueryParams();
                qp.AddReplaceParam("FILTRO", Utils.Helpers.ObjToStr(((DevExpress.XtraEditors.TextEdit)sender).EditValue));
                dsPDV1.TDA_V_REGION_GEOGRAFICA.Clear();
                Utils.Helpers.Merge(GUI.CApp.bll.getTypedDataSet(dsPDV1.GetType(), dsPDV1.TDA_V_REGION_GEOGRAFICA.TableName, qp, "FiltroRegionGeografica"), dsPDV1);
                treeList1.DataSource = dsPDV1;
                treeList1.DataMember = dsPDV1.TDA_V_REGION_GEOGRAFICA.TableName;
                treeList1.RefreshDataSource();
                treeList1.MoveFirst();
                treeList1.Focus();
                
            }
        }

        private void btnBuscar_Click(object sender, EventArgs e)
        {
            textEdit1.Focus();
            textEdit1.SelectAll();

        }
    }
}