#region using
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using LLNet.Utils;
using System.Collections.Generic;
using System.Text;
using DevExpress.XtraEditors;
#endregion

namespace LLNet.Controls
{
	#region Delegates

	public delegate void BeforeActionEventHandler(ref bool cancel);
	public delegate void AfterGetDataEventHandler();
	public delegate void AfterActionEventHandler(DevExpress.XtraBars.BarItem buttonClicked);

	#endregion

	/// <summary>
	/// Summary description for LLToolbar.
	/// </summary>
	public class LLToolbar : DevExpress.XtraBars.BarManager	
	{

		#region Constructor

		public LLToolbar()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			// TODO: Add any initialization after the InitializeComponent call
			InitializeToolBar();

			this.btnDelete.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(btnDelete_ItemClick);
			this.btnPreviousRecord.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.btnPreviousRecord_ItemClick);
			this.btnFirstPage.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.btnFirstPage_ItemClick);
			this.btnPreviousPage.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.btnPreviousPage_ItemClick);
			this.btnNextRecord.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.btnNextRecord_ItemClick);
			this.btnNextPage.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.btnNextPage_ItemClick);
			this.btnLastPage.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.btnLastPage_ItemClick);
			this.btnPagingSize.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(btnPagingSize_ItemClick);
			this.btnSave.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.btnSave_ItemClick);
			this.btnAdd.ItemClick +=new DevExpress.XtraBars.ItemClickEventHandler(this.btnAdd_ItemClick);
			this.btnRunQuery.ItemClick +=new DevExpress.XtraBars.ItemClickEventHandler(this.btnRunQuery_ItemClick);
			this.btnClearQuery.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.btnClearQuery_ItemClick);
			this.btnAdvancedQuery.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.btnAdvancedQuery_ItemClick);	
			this.btnSaveQuery.ItemClick +=new DevExpress.XtraBars.ItemClickEventHandler(btnSaveQuery_ItemClick);
			this.btnFEjecutar.Click +=new EventHandler(btnEjecutar_Click);
			this.btnOEjecutar.Click +=new EventHandler(btnEjecutar_Click);
			this.btnCEjecutar.Click +=new EventHandler(btnEjecutar_Click);
			this.btnFAgregar.Click +=new EventHandler(btnFAgregar_Click);
			this.btnOAgregar.Click +=new EventHandler(btnOAgregar_Click);
			this.btnFLimpiar.Click +=new EventHandler(btnFLimpiar_Click);
			this.btnOLimpiar.Click +=new EventHandler(btnOLimpiar_Click);
			this.cbMyFilters.EditValueChanged +=new EventHandler(cbMyFilters_EditValueChanged);
			

			HOpers = new Hashtable();

			HOpers["igual a"] = " = && ";
			HOpers["mayor que"] = " > && ";
			HOpers["menor que"] = " < && ";
			HOpers["mayor o igual que"] = " >= && ";
			HOpers["menor o igual que"] = " <= && ";
			HOpers["contiene"] = " like '%&&%' ";
			HOpers["empieza con"] = " like '&&%' ";
			HOpers["termina con"] = " like '%&&' ";
			HOpers["es nulo"] = " is null ";
			HOpers["no es nulo"] = " is not null ";
		}

		#endregion

		#region Destructor

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				try
				{
					if (dsFilters != null && dsFilters.HasChanges())
					{
						bllInstance.updateDataSet(dsFilters.GetChanges());
					}
				}
				catch(Exception e)
				{
					MessageBox.Show("Error guardando último filtro usado: " + e.Message,"Error en Filtros",MessageBoxButtons.OK,MessageBoxIcon.Error);
				}
				
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#endregion

		#region copied from visual designed generated code

		private System.ComponentModel.IContainer components;
		private DevExpress.XtraBars.BarDockControl barDockControlTop;
		private DevExpress.XtraBars.BarDockControl barDockControlBottom;
		private DevExpress.XtraBars.BarDockControl barDockControlLeft;
		private DevExpress.XtraBars.BarDockControl barDockControlRight;
		public DevExpress.XtraBars.BarManager tbNavegacion;
		public DevExpress.XtraBars.BarButtonItem btnFirstPage;
		public DevExpress.XtraBars.BarButtonItem btnPreviousPage;
		public DevExpress.XtraBars.BarButtonItem btnPreviousRecord;
		public DevExpress.XtraEditors.Repository.RepositoryItemTextEdit repositoryItemTextEdit1;
		public DevExpress.XtraBars.BarStaticItem txtCount;
		public DevExpress.XtraBars.BarButtonItem btnNextRecord;
		public DevExpress.XtraBars.BarButtonItem btnNextPage;
		public DevExpress.XtraBars.BarButtonItem btnLastPage;
		public DevExpress.XtraBars.BarButtonItem btnPagingSize;
		public DevExpress.XtraBars.BarEditItem cmbColumns;
		public DevExpress.XtraBars.BarEditItem txtFilter;
		public DevExpress.XtraBars.BarButtonItem btnRunQuery;
		public DevExpress.XtraBars.BarButtonItem btnSave;
		public DevExpress.XtraBars.BarButtonItem btnDelete;
		public DevExpress.XtraBars.BarButtonItem btnAdd;
		public DevExpress.XtraBars.Bar tblNavigator;
		public DevExpress.XtraEditors.Repository.RepositoryItemComboBox repCmbColumns;
		public DevExpress.XtraEditors.Repository.RepositoryItemTextEdit repTxtFilter;
		public DevExpress.XtraBars.Bar tblFilter;
		public DevExpress.XtraBars.Bar tblChanges;
		public DevExpress.XtraBars.BarEditItem cbMyFilters;
		public DevExpress.XtraEditors.Repository.RepositoryItemComboBox repcbMyFilters;
		public DevExpress.XtraBars.BarDockWindow tabFiltarCls;
		public DevExpress.XtraBars.BarDockWindow tabFiltrar;
		public DevExpress.XtraBars.BarDockWindow tabOrdenar;
		public DevExpress.XtraEditors.ComboBoxEdit cbFColumns;
		public DevExpress.XtraEditors.ComboBoxEdit cbFOper;
		public DevExpress.XtraEditors.TextEdit txtFValue;
		public DevExpress.XtraEditors.MemoEdit mmFCondition;
		public DevExpress.XtraEditors.SimpleButton btnFAgregar;
		public DevExpress.XtraEditors.SimpleButton btnFLimpiar;
		public DevExpress.XtraEditors.SimpleButton btnOLimpiar;
		public DevExpress.XtraEditors.SimpleButton btnOAgregar;
		public DevExpress.XtraEditors.MemoEdit mmOCondition;
		public DevExpress.XtraEditors.ComboBoxEdit cbOOper;
		public DevExpress.XtraEditors.ComboBoxEdit cbOColumns;
		public DevExpress.XtraEditors.SimpleButton btnCLimpiar;
		public DevExpress.XtraEditors.SimpleButton btnCAgregar;
		public DevExpress.XtraEditors.MemoEdit mmCCondition;
		public DevExpress.XtraTreeList.TreeList trlCls;
		public DevExpress.XtraBars.BarButtonItem btnClearQuery;
		public DevExpress.XtraBars.BarButtonItem btnAdvancedQuery;
		public DevExpress.XtraBars.BarButtonItem btnSaveQuery;
		public DevExpress.XtraEditors.SimpleButton btnFEjecutar;
		public DevExpress.XtraEditors.SimpleButton btnOEjecutar;
		public DevExpress.XtraEditors.SimpleButton btnCEjecutar;
		private LLNet.Model.General.Filters dsFilters;
		public System.Windows.Forms.ImageList ilsSmall;
		public System.Windows.Forms.ImageList ilsLarge;
		public DevExpress.XtraBars.BarButtonItem btnRefresh;
		
		


		#endregion

		#region InitilizeToolbar()

		public void InitializeToolBar()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(this.GetType());
			
			#region copied from visual designed generated code

			this.tblNavigator = new DevExpress.XtraBars.Bar();
			this.btnFirstPage = new DevExpress.XtraBars.BarButtonItem();
			this.btnPreviousPage = new DevExpress.XtraBars.BarButtonItem();
			this.btnPreviousRecord = new DevExpress.XtraBars.BarButtonItem();
			this.txtCount = new DevExpress.XtraBars.BarStaticItem();
			this.btnNextRecord = new DevExpress.XtraBars.BarButtonItem();
			this.btnNextPage = new DevExpress.XtraBars.BarButtonItem();
			this.btnLastPage = new DevExpress.XtraBars.BarButtonItem();
			this.btnPagingSize = new DevExpress.XtraBars.BarButtonItem();
			this.tblFilter = new DevExpress.XtraBars.Bar();
			this.cmbColumns = new DevExpress.XtraBars.BarEditItem();
			this.repCmbColumns = new DevExpress.XtraEditors.Repository.RepositoryItemComboBox();
			this.txtFilter = new DevExpress.XtraBars.BarEditItem();
			this.repTxtFilter = new DevExpress.XtraEditors.Repository.RepositoryItemTextEdit();
			this.btnRunQuery = new DevExpress.XtraBars.BarButtonItem();
			this.btnClearQuery = new DevExpress.XtraBars.BarButtonItem();
			this.btnAdvancedQuery = new DevExpress.XtraBars.BarButtonItem();
			this.cbMyFilters = new DevExpress.XtraBars.BarEditItem();
			this.repcbMyFilters = new DevExpress.XtraEditors.Repository.RepositoryItemComboBox();
			this.btnSaveQuery = new DevExpress.XtraBars.BarButtonItem();
			this.tblChanges = new DevExpress.XtraBars.Bar();
			this.btnSave = new DevExpress.XtraBars.BarButtonItem();
			this.btnDelete = new DevExpress.XtraBars.BarButtonItem();
			this.btnAdd = new DevExpress.XtraBars.BarButtonItem();
			this.barDockControlTop = new DevExpress.XtraBars.BarDockControl();
			this.barDockControlBottom = new DevExpress.XtraBars.BarDockControl();
			this.barDockControlLeft = new DevExpress.XtraBars.BarDockControl();
			this.barDockControlRight = new DevExpress.XtraBars.BarDockControl();
			this.ilsSmall = new System.Windows.Forms.ImageList(this.components);
			this.ilsLarge = new System.Windows.Forms.ImageList(this.components);
			this.repositoryItemTextEdit1 = new DevExpress.XtraEditors.Repository.RepositoryItemTextEdit();
			this.tabFiltarCls = new DevExpress.XtraBars.BarDockWindow();
			this.trlCls = new DevExpress.XtraTreeList.TreeList();
			this.btnCLimpiar = new DevExpress.XtraEditors.SimpleButton();
			this.btnCAgregar = new DevExpress.XtraEditors.SimpleButton();
			this.mmCCondition = new DevExpress.XtraEditors.MemoEdit();
			this.tabFiltrar = new DevExpress.XtraBars.BarDockWindow();
			this.btnFLimpiar = new DevExpress.XtraEditors.SimpleButton();
			this.btnFAgregar = new DevExpress.XtraEditors.SimpleButton();
			this.mmFCondition = new DevExpress.XtraEditors.MemoEdit();
			this.txtFValue = new DevExpress.XtraEditors.TextEdit();
			this.cbFOper = new DevExpress.XtraEditors.ComboBoxEdit();
			this.cbFColumns = new DevExpress.XtraEditors.ComboBoxEdit();
			this.tabOrdenar = new DevExpress.XtraBars.BarDockWindow();
			this.btnOLimpiar = new DevExpress.XtraEditors.SimpleButton();
			this.btnOAgregar = new DevExpress.XtraEditors.SimpleButton();
			this.mmOCondition = new DevExpress.XtraEditors.MemoEdit();
			this.cbOOper = new DevExpress.XtraEditors.ComboBoxEdit();
			this.cbOColumns = new DevExpress.XtraEditors.ComboBoxEdit();
			this.btnFEjecutar = new DevExpress.XtraEditors.SimpleButton();
			this.btnOEjecutar = new DevExpress.XtraEditors.SimpleButton();
			this.btnCEjecutar = new DevExpress.XtraEditors.SimpleButton();
			this.btnRefresh = new DevExpress.XtraBars.BarButtonItem();
			((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.repCmbColumns)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.repTxtFilter)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.repcbMyFilters)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.repositoryItemTextEdit1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.tabFiltarCls)).BeginInit();
			this.tabFiltarCls.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.trlCls)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.mmCCondition.Properties)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.tabFiltrar)).BeginInit();
			this.tabFiltrar.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.mmFCondition.Properties)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.txtFValue.Properties)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.cbFOper.Properties)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.cbFColumns.Properties)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.tabOrdenar)).BeginInit();
			this.tabOrdenar.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.mmOCondition.Properties)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.cbOOper.Properties)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.cbOColumns.Properties)).BeginInit();
			// 
			// tbNavegacion
			// 
			this.Bars.AddRange(new DevExpress.XtraBars.Bar[] {
																			  this.tblNavigator,
																			  this.tblFilter,
																			  this.tblChanges});
			this.DockControls.Add(this.barDockControlTop);
			this.DockControls.Add(this.barDockControlBottom);
			this.DockControls.Add(this.barDockControlLeft);
			this.DockControls.Add(this.barDockControlRight);
			this.Images = this.ilsSmall;
			this.Items.AddRange(new DevExpress.XtraBars.BarItem[] {
																				   this.btnFirstPage,
																				   this.btnPreviousPage,
																				   this.btnPreviousRecord,
																				   this.txtCount,
																				   this.btnNextRecord,
																				   this.btnNextPage,
																				   this.btnLastPage,
																				   this.btnPagingSize,
																				   this.cmbColumns,
																				   this.txtFilter,
																				   this.btnRunQuery,
																				   this.btnSave,
																				   this.btnDelete,
																				   this.btnAdd,
																				   this.btnClearQuery,
																				   this.btnAdvancedQuery,
																				   this.btnSaveQuery,
																				   this.cbMyFilters,
																				   this.btnRefresh});
			this.LargeImages = this.ilsLarge;
			this.MaxItemId = 21;
			this.RepositoryItems.AddRange(new DevExpress.XtraEditors.Repository.RepositoryItem[] {
																												  this.repositoryItemTextEdit1,
																												  this.repCmbColumns,
																												  this.repTxtFilter,
																												  this.repcbMyFilters});
			// 
			// tblNavigator
			// 
			this.tblNavigator.BarName = "tblNavigator";
			this.tblNavigator.DockCol = 0;
			this.tblNavigator.DockRow = 0;
			this.tblNavigator.DockStyle = DevExpress.XtraBars.BarDockStyle.Top;
			this.tblNavigator.LinksPersistInfo.AddRange(new DevExpress.XtraBars.LinkPersistInfo[] {
																									  new DevExpress.XtraBars.LinkPersistInfo(this.btnFirstPage),
																									  new DevExpress.XtraBars.LinkPersistInfo(this.btnPreviousPage),
																									  new DevExpress.XtraBars.LinkPersistInfo(this.btnPreviousRecord),
																									  new DevExpress.XtraBars.LinkPersistInfo(this.txtCount),
																									  new DevExpress.XtraBars.LinkPersistInfo(this.btnNextRecord),
																									  new DevExpress.XtraBars.LinkPersistInfo(this.btnNextPage),
																									  new DevExpress.XtraBars.LinkPersistInfo(this.btnLastPage),
																									  new DevExpress.XtraBars.LinkPersistInfo(this.btnPagingSize),
																									  new DevExpress.XtraBars.LinkPersistInfo(this.btnRefresh)});
			this.tblNavigator.Offset = 1;
			this.tblNavigator.Text = "Navegación";
			// 
			// btnFirstPage
			// 
			this.btnFirstPage.Caption = "btnFirstPage";
			this.btnFirstPage.Hint = "Primera Página";
			this.btnFirstPage.Id = 1;
			this.btnFirstPage.ImageIndex = 1;
			this.btnFirstPage.ImageIndexDisabled = 1;
			this.btnFirstPage.Name = "btnFirstPage";
			// 
			// btnPreviousPage
			// 
			this.btnPreviousPage.Caption = "btnPreviousPage";
			this.btnPreviousPage.Hint = "Pagina Anterior";
			this.btnPreviousPage.Id = 2;
			this.btnPreviousPage.ImageIndex = 0;
			this.btnPreviousPage.ImageIndexDisabled = 0;
			this.btnPreviousPage.Name = "btnPreviousPage";
			// 
			// btnPreviousRecord
			// 
			this.btnPreviousRecord.Caption = "btnPreviousRecord";
			this.btnPreviousRecord.Hint = "Registro Anterior";
			this.btnPreviousRecord.Id = 3;
			this.btnPreviousRecord.ImageIndex = 2;
			this.btnPreviousRecord.ImageIndexDisabled = 2;
			this.btnPreviousRecord.Name = "btnPreviousRecord";
			// 
			// txtCount
			// 
			this.txtCount.Border = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
			this.txtCount.Caption = "txtCount";
			this.txtCount.Id = 5;
			this.txtCount.Name = "txtCount";
			this.txtCount.TextAlignment = System.Drawing.StringAlignment.Near;
			// 
			// btnNextRecord
			// 
			this.btnNextRecord.Caption = "btnNextRecord";
			this.btnNextRecord.Hint = "Registro Siguiente";
			this.btnNextRecord.Id = 6;
			this.btnNextRecord.ImageIndex = 3;
			this.btnNextRecord.ImageIndexDisabled = 3;
			this.btnNextRecord.Name = "btnNextRecord";
			// 
			// btnNextPage
			// 
			this.btnNextPage.Caption = "btnNextPage";
			this.btnNextPage.Hint = "Página Siguiente";
			this.btnNextPage.Id = 7;
			this.btnNextPage.ImageIndex = 5;
			this.btnNextPage.ImageIndexDisabled = 5;
			this.btnNextPage.Name = "btnNextPage";
			// 
			// btnLastPage
			// 
			this.btnLastPage.Caption = "btnLastPage";
			this.btnLastPage.Hint = "Última Página";
			this.btnLastPage.Id = 8;
			this.btnLastPage.ImageIndex = 4;
			this.btnLastPage.ImageIndexDisabled = 4;
			this.btnLastPage.Name = "btnLastPage";
			// 
			// btnLastPage
			// 
			this.btnPagingSize.Caption = "btnPagingSize";
			this.btnPagingSize.Hint = "Tamaño de Página";
			this.btnPagingSize.Id = 8;
			this.btnPagingSize.ImageIndex = 36;
			this.btnPagingSize.ImageIndexDisabled = 36;
			this.btnPagingSize.Name = "btnPagingSize";
			// 
			// btnRefresh
			// 
			this.btnRefresh.Caption = "btnRefresh";
			this.btnRefresh.Hint = "Actualizar consulta";
			this.btnRefresh.Id = 22;
			this.btnRefresh.ImageIndex = 23;
			this.btnRefresh.ImageIndexDisabled = 23;
			this.btnRefresh.Name = "btnRefresh";
			this.btnRefresh.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(this.btnRefresh_ItemClick);
			// 
			// tblFilter
			// 
			this.tblFilter.BarName = "tblFilter";
			this.tblFilter.DockCol = 1;
			this.tblFilter.DockRow = 0;
			this.tblFilter.DockStyle = DevExpress.XtraBars.BarDockStyle.Top;
			this.tblFilter.LinksPersistInfo.AddRange(new DevExpress.XtraBars.LinkPersistInfo[] {
																								   new DevExpress.XtraBars.LinkPersistInfo(DevExpress.XtraBars.BarLinkUserDefines.Width, this.cmbColumns, "", false, true, true, 157),
																								   new DevExpress.XtraBars.LinkPersistInfo(DevExpress.XtraBars.BarLinkUserDefines.Width, this.txtFilter, "", false, true, true, 150),
																								   new DevExpress.XtraBars.LinkPersistInfo(this.btnRunQuery),
																								   new DevExpress.XtraBars.LinkPersistInfo(this.btnClearQuery),																								   
																								   new DevExpress.XtraBars.LinkPersistInfo(this.cbMyFilters),
																								   new DevExpress.XtraBars.LinkPersistInfo(this.btnAdvancedQuery),
																								   new DevExpress.XtraBars.LinkPersistInfo(this.btnSaveQuery)});
			this.tblFilter.Offset = 214;
			this.tblFilter.OptionsBar.AllowRename = true;
			this.tblFilter.Text = "Filtros";

			// 
			// cmbColumns
			// 
			this.cmbColumns.Caption = "cmbColumns";
			this.cmbColumns.Hint = "Columna con la que se desea filtrar la consulta";
			this.cmbColumns.Edit = this.repCmbColumns;
			this.cmbColumns.Id = 9;
			this.cmbColumns.Name = "cmbColumns";
			this.cmbColumns.Width = 150;
//			// 
//			// repCmbColumns
//			// 
			this.repCmbColumns.AllowFocused = false;
			this.repCmbColumns.AutoHeight = false;
			this.repCmbColumns.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
																									   new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
			this.repCmbColumns.Name = "repCmbColumns";
			this.repCmbColumns.PopupSizeable = true;
//			// 
			// txtFilter
			// 
			this.txtFilter.Caption = "txtFilter";
			this.txtFilter.Hint = " Condición que debe cumplir la columna seleccionada";
			this.txtFilter.Edit = this.repTxtFilter;
			this.txtFilter.Id = 10;
			this.txtFilter.Name = "txtFilter";
			this.txtFilter.Width = 150;
			// 
			// repTxtFilter
			// 
			this.repTxtFilter.AutoHeight = false;
			this.repTxtFilter.Name = "repTxtFilter";
			// 
			// btnRunQuery
			// 
			this.btnRunQuery.Caption = "btnRunQuery";
			this.btnRunQuery.Hint = "Ejecutar Filtro";
			this.btnRunQuery.Id = 11;
			this.btnRunQuery.ImageIndex = 9;
			this.btnRunQuery.ImageIndexDisabled = 9;
			this.btnRunQuery.Name = "btnRunQuery";
			// 
			// btnClearQuery
			// 
			this.btnClearQuery.Caption = "Clear";
			this.btnClearQuery.Hint = "Limpiar Filtro";
			this.btnClearQuery.Id = 17;
			this.btnClearQuery.ImageIndex = 10;
			this.btnClearQuery.Name = "btnClearQuery";
			// 
			// btnAdvancedQuery
			// 
			this.btnAdvancedQuery.Caption = "Advanced";
			this.btnAdvancedQuery.Hint = "Filtros Avanzados";
			this.btnAdvancedQuery.Id = 18;
			this.btnAdvancedQuery.ImageIndex = 11;
			this.btnAdvancedQuery.Name = "btnAdvancedQuery";
			// 
			// cbMyFilters
			// 
			this.cbMyFilters.Caption = "cbMyFilters";
			this.cbMyFilters.Hint = "Listado de filtros predeterminados disponibles para esta consulta";
			this.cbMyFilters.Edit = this.repcbMyFilters;
			this.cbMyFilters.Id = 20;
			this.cbMyFilters.Name = "cbMyFilters";
			this.cbMyFilters.AutoFillWidth = true;
//			this.cbMyFilters.Width = 180;
			// 
			// repcbMyFilters
			// 
			this.repcbMyFilters.AutoHeight = false;
			this.repcbMyFilters.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
																												 new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
			this.repcbMyFilters.Name = "repcbMyFilters";
			this.repcbMyFilters.AllowFocused = false;
			this.repcbMyFilters.PopupSizeable = true;
			// 
			// btnSaveQuery
			// 
			this.btnSaveQuery.Caption = "btnSaveFilter";
			this.btnSaveQuery.Hint = "Guardar Filtro";
			this.btnSaveQuery.Id = 19;
			this.btnSaveQuery.ImageIndex = 27;
			this.btnSaveQuery.Name = "btnSaveQuery";
			// 
			// tblChanges
			// 
			this.tblChanges.BarName = "tblChanges";
			this.tblChanges.DockCol = 2;
			this.tblChanges.DockRow = 0;
			this.tblChanges.DockStyle = DevExpress.XtraBars.BarDockStyle.Top;
			this.tblChanges.LinksPersistInfo.AddRange(new DevExpress.XtraBars.LinkPersistInfo[] {
																									new DevExpress.XtraBars.LinkPersistInfo(this.btnSave),
																									new DevExpress.XtraBars.LinkPersistInfo(this.btnDelete),
																									new DevExpress.XtraBars.LinkPersistInfo(this.btnAdd)});
			this.tblChanges.Offset = 426;
			this.tblChanges.OptionsBar.AllowRename = true;
			this.tblChanges.Text = "Cambios";
			// 
			// btnSave
			// 
			this.btnSave.Caption = "btnSave";
			this.btnSave.Hint = "Guardar Cambios";
			this.btnSave.Id = 12;
			this.btnSave.ImageIndex = 6;
			this.btnSave.ImageIndexDisabled = 6;
			this.btnSave.Name = "btnSave";
			this.btnSave.ItemShortcut = new DevExpress.XtraBars.BarShortcut(Shortcut.CtrlS);
			// 
			// btnDelete
			// 
			this.btnDelete.Caption = "btnDelete";
			this.btnDelete.Hint = "Eliminar Registro";
			this.btnDelete.Id = 15;
			this.btnDelete.ImageIndex = 7;
			this.btnDelete.ImageIndexDisabled = 7;
			this.btnDelete.Name = "btnDelete";
			// 
			// btnAdd
			// 
			this.btnAdd.Caption = "btnAdd";
			this.btnAdd.Hint = "Nuevo Registro";
			this.btnAdd.Id = 16;
			this.btnAdd.ImageIndex = 8;
			this.btnAdd.ImageIndexDisabled = 8;
			this.btnAdd.Name = "btnAdd";
			// 
			// ilsSmall
			// 
			this.ilsSmall.ImageSize = new System.Drawing.Size(16, 16);
			this.ilsSmall.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilsSmall.ImageStream")));
			this.ilsSmall.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// ilsLarge
			// 
			this.ilsLarge.ImageSize = new System.Drawing.Size(16, 16);
			this.ilsLarge.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilsLarge.ImageStream")));
			this.ilsLarge.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// repositoryItemTextEdit1
			// 
			this.repositoryItemTextEdit1.AutoHeight = false;
			this.repositoryItemTextEdit1.Name = "repositoryItemTextEdit1";

			// 
			// trlCls
			// 
			this.trlCls.Location = new System.Drawing.Point(16, 16);
			this.trlCls.Name = "trlCls";
			this.trlCls.Size = new System.Drawing.Size(184, 144);
			this.trlCls.TabIndex = 14;
			this.trlCls.Text = "treeList1";

			// 
			// btnCLimpiar
			// 
			this.btnCLimpiar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.btnCLimpiar.Location = new System.Drawing.Point(483, 56);
			this.btnCLimpiar.Name = "btnCLimpiar";
			this.btnCLimpiar.TabIndex = 12;
			this.btnCLimpiar.Text = "Limpiar";
			// 
			// btnCAgregar
			// 
			this.btnCAgregar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.btnCAgregar.Location = new System.Drawing.Point(483, 16);
			this.btnCAgregar.Name = "btnCAgregar";
			this.btnCAgregar.TabIndex = 11;
			this.btnCAgregar.Text = "Agregar";
			// 
			// mmCCondition
			// 
			this.mmCCondition.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.mmCCondition.EditValue = "";
			this.mmCCondition.Location = new System.Drawing.Point(216, 48);
			this.mmCCondition.Name = "mmCCondition";
			this.mmCCondition.Size = new System.Drawing.Size(245, 112);
			this.mmCCondition.TabIndex = 10;
			// 
			// tabFiltrar
			// 
			this.tabFiltrar.Controls.Add(this.btnFEjecutar);
			this.tabFiltrar.Controls.Add(this.btnFLimpiar);
			this.tabFiltrar.Controls.Add(this.btnFAgregar);
			this.tabFiltrar.Controls.Add(this.mmFCondition);
			this.tabFiltrar.Controls.Add(this.txtFValue);
			this.tabFiltrar.Controls.Add(this.cbFOper);
			this.tabFiltrar.Controls.Add(this.cbFColumns);
			this.tabFiltrar.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.tabFiltrar.DockCaption = "Filtrar";
			this.tabFiltrar.DockCol = 0;
			this.tabFiltrar.DockedBorderColor = System.Drawing.SystemColors.ControlDark;
			this.tabFiltrar.DockedSize = new System.Drawing.Size(200, 219);
			this.tabFiltrar.DockRow = 1;
		
			this.tabFiltrar.FloatSize = new System.Drawing.Size(579, 214);
			this.tabFiltrar.Manager = this;
			this.tabFiltrar.Name = "tabFiltrar";
			
			this.tabFiltrar.ShowCloseButton = true;
			this.tabFiltrar.Size = new System.Drawing.Size(575, 173);
			this.tabFiltrar.TabCaption = "Filtrar";
			this.tabFiltrar.TabIndex = 0;
			// 
			// tabOrdenar
			// 
			this.tabOrdenar.Controls.Add(this.btnOEjecutar);
			this.tabOrdenar.Controls.Add(this.btnOLimpiar);
			this.tabOrdenar.Controls.Add(this.btnOAgregar);
			this.tabOrdenar.Controls.Add(this.mmOCondition);
			this.tabOrdenar.Controls.Add(this.cbOOper);
			this.tabOrdenar.Controls.Add(this.cbOColumns);
			this.tabOrdenar.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.tabOrdenar.DockCaption = "Ordenar";
			this.tabOrdenar.DockCol = 0;
			this.tabOrdenar.DockedBorderColor = System.Drawing.SystemColors.ControlDark;
			this.tabOrdenar.DockedSize = new System.Drawing.Size(200, 219);
			
			this.tabOrdenar.DockRow = 1;
			
			this.tabOrdenar.FloatSize = new System.Drawing.Size(579, 214);
			this.tabOrdenar.Manager = this;
			this.tabOrdenar.Name = "tabOrdenar";
			this.tabOrdenar.ShowCloseButton = true;
			this.tabOrdenar.Size = new System.Drawing.Size(575, 173);
			this.tabOrdenar.TabIndex = 0;
			// 
			// tabFiltarCls
			// 
			this.tabFiltarCls.Controls.Add(this.btnCEjecutar);
			this.tabFiltarCls.Controls.Add(this.trlCls);
			this.tabFiltarCls.Controls.Add(this.btnCLimpiar);
			this.tabFiltarCls.Controls.Add(this.btnCAgregar);
			this.tabFiltarCls.Controls.Add(this.mmCCondition);
			this.tabFiltarCls.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.tabFiltarCls.DockCaption = "Filtrar por Clasificación";
			this.tabFiltarCls.DockCol = 0;
			this.tabFiltarCls.DockedBorderColor = System.Drawing.SystemColors.ControlDark;
			this.tabFiltarCls.DockedSize = new System.Drawing.Size(200, 219);
			this.tabFiltarCls.DockRow = 1;
			
			this.tabFiltarCls.FloatSize = new System.Drawing.Size(579, 214);
			this.tabFiltarCls.Manager = this;
			this.tabFiltarCls.Name = "tabFiltarCls";
			this.tabFiltarCls.ShowCloseButton = true;
			this.tabFiltarCls.Size = new System.Drawing.Size(575, 173);
			this.tabFiltarCls.TabIndex = 0;


			// 
			// btnFLimpiar
			// 
			this.btnFLimpiar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.btnFLimpiar.Location = new System.Drawing.Point(483, 56);
			this.btnFLimpiar.Name = "btnFLimpiar";
			this.btnFLimpiar.TabIndex = 5;
			this.btnFLimpiar.Text = "Limpiar";
			// 
			// btnFAgregar
			// 
			this.btnFAgregar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.btnFAgregar.Location = new System.Drawing.Point(483, 16);
			this.btnFAgregar.Name = "btnFAgregar";
			this.btnFAgregar.TabIndex = 4;
			this.btnFAgregar.Text = "Agregar";
			// 
			// mmFCondition
			// 
			this.mmFCondition.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.mmFCondition.EditValue = "";
			this.mmFCondition.Location = new System.Drawing.Point(16, 48);
			this.mmFCondition.Name = "mmFCondition";
			this.mmFCondition.Size = new System.Drawing.Size(445, 112);
			this.mmFCondition.TabIndex = 3;
			// 
			// txtFValue
			// 
			this.txtFValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.txtFValue.EditValue = "";
			this.txtFValue.Location = new System.Drawing.Point(340, 16);
			this.txtFValue.Name = "txtFValue";
			this.txtFValue.Size = new System.Drawing.Size(123, 19);
			this.txtFValue.TabIndex = 2;
			// 
			// cbFOper
			// 
			this.cbFOper.EditValue = "";
			this.cbFOper.Location = new System.Drawing.Point(216, 16);
			this.cbFOper.Name = "cbFOper";
			// 
			// cbFOper.Properties
			// 
			this.cbFOper.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
																											new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
			this.cbFOper.Properties.DropDownRows = 10;
			this.cbFOper.Properties.PopupSizeable = true;
			this.cbFOper.Size = new System.Drawing.Size(104, 19);
			this.cbFOper.TabIndex = 1;
			// 
			// cbFColumns
			// 
			this.cbFColumns.EditValue = "";
			this.cbFColumns.Location = new System.Drawing.Point(16, 16);
			this.cbFColumns.Name = "cbFColumns";
			// 
			// cbFColumns.Properties
			// 
			this.cbFColumns.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
																											   new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
			this.cbFColumns.Properties.PopupSizeable = true;
			this.cbFColumns.Size = new System.Drawing.Size(184, 19);
			this.cbFColumns.TabIndex = 0;

			// 
			// btnOLimpiar
			// 
			this.btnOLimpiar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.btnOLimpiar.Location = new System.Drawing.Point(483, 56);
			this.btnOLimpiar.Name = "btnOLimpiar";
			this.btnOLimpiar.TabIndex = 12;
			this.btnOLimpiar.Text = "Limpiar";
			// 
			// btnOAgregar
			// 
			this.btnOAgregar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.btnOAgregar.Location = new System.Drawing.Point(483, 16);
			this.btnOAgregar.Name = "btnOAgregar";
			this.btnOAgregar.TabIndex = 11;
			this.btnOAgregar.Text = "Agregar";
			// 
			// mmOCondition
			// 
			this.mmOCondition.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.mmOCondition.EditValue = "";
			this.mmOCondition.Location = new System.Drawing.Point(16, 48);
			this.mmOCondition.Name = "mmOCondition";
			this.mmOCondition.Size = new System.Drawing.Size(445, 112);
			this.mmOCondition.TabIndex = 10;
			// 
			// cbOOper
			// 
			this.cbOOper.EditValue = "";
			this.cbOOper.Location = new System.Drawing.Point(216, 16);
			this.cbOOper.Name = "cbOOper";
			// 
			// cbOOper.Properties
			// 
			this.cbOOper.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
																											new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
			this.cbOOper.Properties.PopupSizeable = true;
			this.cbOOper.Size = new System.Drawing.Size(104, 19);
			this.cbOOper.TabIndex = 8;
			// 
			// cbOColumns
			// 
			this.cbOColumns.EditValue = "";
			this.cbOColumns.Location = new System.Drawing.Point(16, 16);
			this.cbOColumns.Name = "cbOColumns";
			// 
			// cbOColumns.Properties
			// 
			this.cbOColumns.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
																											   new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
			this.cbOColumns.Properties.PopupSizeable = true;
			this.cbOColumns.Size = new System.Drawing.Size(184, 19);
			this.cbOColumns.TabIndex = 7;
			// 
			// btnFEjecutar
			// 
			this.btnFEjecutar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.btnFEjecutar.Location = new System.Drawing.Point(483, 96);
			this.btnFEjecutar.Name = "btnFEjecutar";
			this.btnFEjecutar.TabIndex = 7;
			this.btnFEjecutar.Text = "Ejecutar";
			// 
			// btnOEjecutar
			// 
			this.btnOEjecutar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.btnOEjecutar.Location = new System.Drawing.Point(483, 96);
			this.btnOEjecutar.Name = "btnOEjecutar";
			this.btnOEjecutar.TabIndex = 14;
			this.btnOEjecutar.Text = "Ejecutar";
			// 
			// btnCEjecutar
			// 
			this.btnCEjecutar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
			this.btnCEjecutar.Location = new System.Drawing.Point(483, 96);
			this.btnCEjecutar.Name = "btnCEjecutar";
			this.btnCEjecutar.TabIndex = 15;
			this.btnCEjecutar.Text = "Ejecutar";

			hideFilter();

			((System.ComponentModel.ISupportInitialize)(this)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.repCmbColumns)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.repTxtFilter)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.repcbMyFilters)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.repositoryItemTextEdit1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.tabFiltarCls)).EndInit();
			this.tabFiltarCls.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.trlCls)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.mmCCondition.Properties)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.tabFiltrar)).EndInit();
			this.tabFiltrar.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.mmFCondition.Properties)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.txtFValue.Properties)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.cbFOper.Properties)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.cbFColumns.Properties)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.tabOrdenar)).EndInit();
			this.tabOrdenar.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.mmOCondition.Properties)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.cbOOper.Properties)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.cbOColumns.Properties)).EndInit();

			#endregion
		}

		#endregion

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		public void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(LLToolbar));
			this.dsFilters = new LLNet.Model.General.Filters();
			this.ilsSmall = new System.Windows.Forms.ImageList(this.components);
			this.ilsLarge = new System.Windows.Forms.ImageList(this.components);
			((System.ComponentModel.ISupportInitialize)(this.dsFilters)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
			// 
			// dsFilters
			// 
			this.dsFilters.DataSetName = "Filters";
			this.dsFilters.Locale = new System.Globalization.CultureInfo("en-US");
			// 
			// ilsSmall
			// 
			this.ilsSmall.ImageSize = new System.Drawing.Size(16, 16);
			this.ilsSmall.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilsSmall.ImageStream")));
			this.ilsSmall.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// ilsLarge
			// 
			this.ilsLarge.ImageSize = new System.Drawing.Size(16, 16);
			this.ilsLarge.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilsLarge.ImageStream")));
			this.ilsLarge.TransparentColor = System.Drawing.Color.Transparent;
			((System.ComponentModel.ISupportInitialize)(this.dsFilters)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this)).EndInit();

		}
		#endregion

		#region private variables

		private int initCount = 0;
		private EventHandler eh = null;
		private DataView dataSource = null;
		private Model.IBLL bllInstance;
		private string connectionName = "";
		private bool active;
		private Utils.QueryParams pList = null;
		private Utils.EntityClasifications entityClasifications = null;
		private Utils.QueryParams externPList = null;
		private Hashtable HOpers;
		private string modulePrefix; 
		private string moduleName; 
		private string user;
		private string queryName;
		private BindingManagerBase cManager;
		//campo en el dataset que corresponde a la columna seleccionada en el combo
			
		private long recordCount = 0;
		private int pageSize = 20;
		private bool endReached = false;
		private long startRecord = 1;
		private long endRecord;
		private long lastRecord = 0;


		#endregion

		#region private members

		private void hideFilter()
		{
			tabFiltarCls.HideDockWindow();
			tabFiltrar.HideDockWindow();
			tabOrdenar.HideDockWindow();
		}

		private void getData(long start, long end)
		{
			bool oldEnforceConstraints =dataSource.Table.DataSet.EnforceConstraints;
			dataSource.Table.DataSet.EnforceConstraints = false;
			dataSource.Table.Clear();
			Helpers.Merge(bllInstance.getConnTypedDataSet(dataSet.GetType(),dataSource.Table.TableName,connectionName,start,end,joinQueryParams(),queryName),dataSet);

			if (OnAfterGetData != null)
			{
				OnAfterGetData();
			}

			try
			{
				dataSource.Table.DataSet.EnforceConstraints = oldEnforceConstraints;
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.Message);
			}
		}

		private void showFilter()
		{
			//this.tabFiltarCls.GroupId = new System.Guid("95ad75e9-c1cc-40db-98b5-371ee0f2c128");
			//this.tabFiltarCls.InnerWindows.AddRange(new DevExpress.XtraBars.BarDockWindow[] {
			//																					this.tabFiltrar,
			//																					this.tabOrdenar,
			//																					this.tabFiltarCls});
			this.tabOrdenar.GroupId = new System.Guid("95ad75e9-c1cc-40db-98b5-371ee0f2c128");
			this.tabOrdenar.InnerWindows.AddRange(new DevExpress.XtraBars.BarDockWindow[] {
																								this.tabFiltrar,
																								this.tabOrdenar});
			//,this.tabFiltarCls});
			this.tabFiltrar.GroupId = new System.Guid("95ad75e9-c1cc-40db-98b5-371ee0f2c128");
			this.tabFiltrar.InnerWindows.AddRange(new DevExpress.XtraBars.BarDockWindow[] {
																								this.tabFiltrar,
																							  this.tabOrdenar});
			//,this.tabFiltarCls});
			
			
			
			//tabFiltarCls.ShowDockWindow();
			tabOrdenar.ShowDockWindow();
			tabFiltrar.ShowDockWindow();

			this.tabFiltrar.DockStyle = DevExpress.XtraBars.BarDockStyle.Bottom;
			this.tabOrdenar.DockStyle = DevExpress.XtraBars.BarDockStyle.Bottom;
			//this.tabFiltarCls.DockStyle = DevExpress.XtraBars.BarDockStyle.Bottom;
		}

		private void runQuery()
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 
			try 
			{
				initPagingValues(); 
                
		
				if (cmbColumns.EditValue != null && txtFilter.EditValue != null)
                {
                    
					string currentColumn = getFieldNameFromCaption(cmbColumns.EditValue.ToString());
								
					pList.AddRecursiveConditionParam(Utils.QueryParams.PredefinedTags.ToolbarTag,"AND",currentColumn,"LIKE","'%" + txtFilter.EditValue.ToString() + "%'");
				}
				else
				{
					pList.AddReplaceParam(Utils.QueryParams.PredefinedTags.ToolbarTag,"");
				}
	
				string sqlWhere = "";
				if (Utils.Helpers.ObjToStr(mmFCondition.EditValue) != "")
				{
					sqlWhere = Utils.Helpers.ObjToStr(mmFCondition.EditValue);
					if (Utils.Helpers.ObjToStr(mmCCondition.EditValue) != "")
					{
						sqlWhere += (" AND " + Utils.Helpers.ObjToStr(mmCCondition.EditValue));					
					}
				}
				else
				{
					if (Utils.Helpers.ObjToStr(mmCCondition.EditValue) != "")
					{
						sqlWhere = Utils.Helpers.ObjToStr(mmCCondition.EditValue);					
					}
				}

				pList.ReplaceConditionParam(Utils.QueryParams.PredefinedTags.AdvancedToolbarTag,sqlWhere);
		
				pList.AddOrderByParam(Utils.QueryParams.PredefinedTags.OrderByToolbarTag,Utils.Helpers.ObjToStr(mmOCondition.EditValue.ToString()));

                if (Utils.Helpers.psocio != null)
                {
                    pList.AddOrderByParam(Utils.QueryParams.PredefinedTags.PosToolbarTag, " AND SOCIO = '" + Utils.Helpers.psocio.ToString() + "'");
                }

                if (Utils.Helpers.pdocumento != null)
                {
                    pList.AddOrderByParam(Utils.QueryParams.PredefinedTags.RepToolbarTag, " AND DOCUMENTO = '" + Utils.Helpers.pdocumento.ToString() + "'");
                }
				
                btnFirstPage_ItemClick(null, null);


  


            }
			finally
			{
				Cursor.Current = oldCursor;
			}
		
		}

		private string getFieldNameFromCaption(string caption)
		{
			foreach(DataColumn col in dataSource.Table.Columns)
			{
				if (Utils.Helpers.InitCap(col.Caption) == caption)
				{
					return col.ColumnName;
				}
			}

			return "";
		}

		private DataColumn getDataColumnFromCaption(string caption)
		{
			foreach(DataColumn col in dataSource.Table.Columns)
			{
				if (Utils.Helpers.InitCap(col.Caption) == caption)
				{
					return col;
				}
			}

			return null;
		}


		private void initPagingValues()
		{
			recordCount = 0;
			endReached = false;
			startRecord = 1;
			endRecord = pageSize;
			lastRecord = 0;
			pList.Clear();
		}

		private Utils.QueryParams joinQueryParams()
		{
			Utils.QueryParams result = new Utils.QueryParams();

			if (externPList != null)
			{
				foreach(Utils.ParamBase param in externPList)
				{
					result.AddParamBase(param);		
				}
			}

			foreach(Utils.ParamBase param in pList)
			{
				result.AddParamBase(param);		
			}
		

			return result;
		}

		private void checkInitBinding()
		{
			if (dataSource == null)
			{
				throw new Exception("Debe configurar un DataSource");
			}
		}

		private void checkInitConnection()
		{
			checkInitBinding();
			if (bllInstance == null)
			{
				throw new Exception("Debe configurar una instancia de la capa de negocios");
			}

		}


		private void UpdateButtons(object sender, EventArgs e)
		{
			// TODO: Capturar resizing para ambos texts
			checkInitBinding();
			btnFirstPage.Enabled = btnPreviousPage.Enabled = (CManager.Count > 0) && (startRecord + CManager.Position) > PageSize; 
			btnPreviousRecord.Enabled =	(CManager.Count > 0) && (startRecord + CManager.Position > 1);
			btnLastPage.Enabled  = btnNextPage.Enabled  = (CManager.Count > 0) && !endReached || !( (startRecord + ( (CManager.Position == PageSize) ? (CManager.Position - 1) : CManager.Position )   ) >= (recordCount - PageSize) );
			btnNextRecord.Enabled = (CManager.Count > 0) && !( endReached && ( startRecord + CManager.Position == recordCount ) );
			btnDelete.Enabled = (CManager.Count > 0);
	
			long pos = CManager.Position;
			pos += startRecord;

			if (endReached)
			{
				txtCount.Caption  = pos.ToString() + "-" + recordCount.ToString();
			}
			else
			{
				lastRecord = Math.Max(lastRecord,(startRecord + CManager.Count - 1));
				txtCount.Caption  = pos.ToString() + "-" + lastRecord.ToString() + "...";
			}
		}


		private void BeginUCInit()
		{
			if (initCount ++ == 0 && dataSource != null && eh != null)
			{
				CManager.PositionChanged -= eh;
			}
		}

		private void EndUCInit()
		{
			if (--initCount == 0 && dataSource != null)
			{
				if (eh == null)
				{
					eh = new EventHandler(UpdateButtons);
					CManager.PositionChanged += eh;
					UpdateButtons(null, null);
				}
			}
		}

		private void fillColumnsCombo()
		{   
			foreach(System.Data.DataColumn col in dataSource.Table.Columns)
			{
				//TODO: añadir un evento que se dispare antes de colocar cada columna, que permita cambier el caption o no insertarla en la lista
				if ((col.Caption != "NoCaption") && (col.Caption != "TUPLA") && (col.Caption.Trim() != "") )
				{

					repCmbColumns.Items.Add(Utils.Helpers.InitCap(col.Caption));
					cbFColumns.Properties.Items.Add(Utils.Helpers.InitCap(col.Caption));
					cbOColumns.Properties.Items.Add(Utils.Helpers.InitCap(col.Caption));
					
				}
			}

			cbOOper.Properties.Items.Add("Ascendente");
			cbOOper.Properties.Items.Add("Descendente");

			foreach(object oper in HOpers.Keys) 
			{
				cbFOper.Properties.Items.Add((string)oper);
			}

			//lleno los filtros predefinidos.
			Utils.QueryParams filterParams = new Utils.QueryParams();
			filterParams.AddReplaceParam("MODULE_NAME",ModuleName);
			filterParams.AddReplaceParam("USER",User);
			
			dsFilters.EnforceConstraints = false;
			Helpers.Merge(bllInstance.getConnTypedDataSet(dsFilters.GetType(),dsFilters.CG_USER_FILTERS.TableName,connectionName,filterParams),dsFilters);
			
			if (dsFilters.CG_USER_FILTERS.Rows.Count > 0)
			{
				repcbMyFilters.Items.Add("");
				foreach(DataRow dr in dsFilters.CG_USER_FILTERS.Rows)
				{
					string s = dr["FILTER_NAME"].ToString();
					repcbMyFilters.Items.Add(s);	
				}

				DataRow[] finded = dsFilters.CG_USER_FILTERS.Select("LAST_USED is not null","LAST_USED DESC");
				if (finded.Length > 0)
				{
					cbMyFilters.EditValue = finded[0]["FILTER_NAME"].ToString();
				}
				else
				{
					runQuery();
				}
			}
			else
			{
				runQuery();
			}
		}

		private bool isLikeOper(string oper)
		{
			return (oper == "contiene" || oper == "empieza con" || oper == "termina con");
		}

		private void nextPage(long pStartRecord, long pEndRecord)
		{
			getData(pStartRecord, pEndRecord); 
			if (dataSet.Tables[dataSource.Table.TableName].Rows.Count<pageSize)
			{
				endReached=true;
				recordCount = pStartRecord + dataSet.Tables[dataSource.Table.TableName].Rows.Count - 1;
			}

	        startRecord=pStartRecord;
			endRecord=pEndRecord;
			UpdateButtons(null,null);
		}

		private void firstPage(long pStartRecord, long pEndRecord)
		{
			getData(pStartRecord, pEndRecord); 
			if (dataSet.Tables[dataSource.Table.TableName].Rows.Count<pageSize)
			{
				endReached=true;
				recordCount = dataSet.Tables[dataSource.Table.TableName].Rows.Count;
			}

			startRecord=pStartRecord;
			endRecord=pEndRecord;
			
			UpdateButtons(null,null);
		}

		private void lastPage(long pStartRecord, long pEndRecord)
		{
			getData(pStartRecord, pEndRecord); 

			endReached=true;

			startRecord=pStartRecord;
			endRecord=pEndRecord;
			CManager.Position = 0;
			UpdateButtons(null,null);
		}

		private void previousPage(long pStartRecord, long pEndRecord)
		{
			getData(pStartRecord, pEndRecord); 

			startRecord=pStartRecord;
			endRecord=pEndRecord;
			CManager.Position = CManager.Count - 1;
			UpdateButtons(null,null);
		}



		#endregion

		#region private properties


		private DataSet dataSet
		{
			get {return dataSource.Table.DataSet;}
		}

		#endregion

		#region private events

		private void cbMyFilters_EditValueChanged(object sender, EventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{
				bool cancel = false;
				
				//busco el filtro en mi dataset y seteo las condiciones
				if (OnFilterChanging != null)
				{
					OnFilterChanging(ref cancel);
				}

				if (cancel == true) return;


				if (repcbMyFilters.Items.Count > 0)
				{
					if (Utils.Helpers.ObjToStr(cbMyFilters.EditValue) == "") 
					{
						cmbColumns.EditValue = null;
						txtFilter.EditValue = null;	
						mmFCondition.EditValue = "";
						mmOCondition.EditValue = "";
						cbFColumns.EditValue = "";
						txtFValue.EditValue = "";
						cbFOper.EditValue = "";
						cbMyFilters.EditValue = "";

						//pongo todos los last_used en null
						foreach(System.Data.DataRow row in dsFilters.CG_USER_FILTERS.Rows)
						{
							row["LAST_USED"] = System.DBNull.Value;
						}

						runQuery();
					}
					else
					{
						DataRow[] finded = dsFilters.CG_USER_FILTERS.Select("FILTER_NAME = '" + cbMyFilters.EditValue + "'");
						if (finded.Length > 0)
						{
							mmFCondition.EditValue = finded[0]["WHERE_CLAUSE"].ToString();
							mmOCondition.EditValue = finded[0]["ORDERBY_CLAUSE"].ToString();
							finded[0]["LAST_USED"] = System.DateTime.Now;
							runQuery();
						}
					}
				}

				if (OnFilterChanged != null)
				{
					OnFilterChanged(null);
				}
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}
		}

		private void btnFLimpiar_Click(object sender, EventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{
				mmFCondition.EditValue = "";
				cbFColumns.EditValue = "";
				txtFValue.EditValue = "";
				cbFOper.EditValue = "";
				cbMyFilters.EditValue = "";
				runQuery();
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}
		}

		private void btnOLimpiar_Click(object sender, EventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{
				mmOCondition.EditValue = "";
				cbOOper.EditValue = "";
				cbOColumns.EditValue = "";
				cbMyFilters.EditValue = "";
				runQuery();
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}
		}


		private void btnFAgregar_Click(object sender, EventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{
				if ( 
					Utils.Helpers.ObjToStr(cbFColumns.EditValue.ToString()) == "" || 
					Utils.Helpers.ObjToStr(cbFOper.EditValue.ToString()) == "" 
					) 
				{
					MessageBox.Show("Debe llenar los valores requeridos");
					return;
				}
				
				if (mmFCondition.Text != "")
				{
					mmFCondition.Text += " AND ";
				}

				string cvalue = "";
				if (!isLikeOper(cbFOper.EditValue.ToString()) && Utils.Helpers.IsQuoted(getDataColumnFromCaption(cbFColumns.EditValue.ToString())))
				{
					cvalue = ( " '" + Utils.Helpers.ObjToStr(txtFValue.EditValue) + "'" );
				}
				else
				{
					cvalue = Utils.Helpers.ObjToStr(txtFValue.EditValue);
				}

				mmFCondition.Text += ( getFieldNameFromCaption(cbFColumns.EditValue.ToString()) + " " + ((string)HOpers[cbFOper.EditValue.ToString()]).Replace("&&",cvalue) );
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}
		}

		private void btnOAgregar_Click(object sender, EventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{
				if (
					Utils.Helpers.ObjToStr(cbOColumns.EditValue.ToString()) == "" || 
					Utils.Helpers.ObjToStr(cbOOper.EditValue.ToString()) == "" 
					)
				{
					MessageBox.Show("Debe llenar los valores requeridos");
					return;
				}
				
				if (Utils.Helpers.ObjToStr(mmOCondition.EditValue.ToString()) == "")
				{
					mmOCondition.EditValue = "ORDER BY " + getFieldNameFromCaption(cbOColumns.EditValue.ToString());	
				}
				else
				{
					mmOCondition.EditValue += ( ", " + getFieldNameFromCaption(cbOColumns.EditValue.ToString()) );
				}

				if (Utils.Helpers.ObjToStr(cbOOper.EditValue.ToString()) == "Ascendente")
				{
					mmOCondition.EditValue += " ASC";	
				}
				else
				{
					mmOCondition.EditValue += " DESC";
				}
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}
		}

		private void btnSaveQuery_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{
				if (Utils.Helpers.ObjToStr(mmFCondition.EditValue) == "" &&
					Utils.Helpers.ObjToStr(mmOCondition.EditValue) == "")
				{
					MessageBox.Show("Debe definir las condiciones del filtro");
					return;
				}
				
				dlgSaveFilter dlg = new dlgSaveFilter();
				dlg.txtFilterName.EditValue = Utils.Helpers.ObjToStr(cbMyFilters.EditValue);
				if (dlg.ShowDialog() == DialogResult.OK && Utils.Helpers.ObjToStr(dlg.txtFilterName.EditValue) != "")
				{
					bool newFilter = false;
					if (Utils.Helpers.ObjToStr(dlg.txtFilterName.EditValue) != Utils.Helpers.ObjToStr(cbMyFilters.EditValue)) //es nuevo
					{
						dsFilters.CG_USER_FILTERS.AddCG_USER_FILTERSRow(Utils.Helpers.ObjToStr(dlg.txtFilterName.EditValue),
																		Utils.Helpers.ObjToStr(mmFCondition.EditValue),
																		Utils.Helpers.ObjToStr(mmOCondition.EditValue),
																		User,ModuleName,"X",DateTime.Now,null);
						newFilter = true;	
					}
					else // se modifico el actual
					{ 

						//LLNet.Model.General.Filters.CG_USER_FILTERSRow currentRow = dsFilters.CG_USER_FILTERS.FindByFILTER_NAMEUSER_IDMODULE_NAME(Utils.Helpers.ObjToStr(dlg.txtFilterName.EditValue),User,ModuleName);
						LLNet.Model.General.Filters.CG_USER_FILTERSRow currentRow = (dsFilters.Tables[0].Select("FILTER_NAME = '" + Utils.Helpers.ObjToStr(dlg.txtFilterName.EditValue) + "' AND MODULE_NAME = '" + ModuleName + "' AND (USER_ID = '" + User + "' OR PRIVATE_FILTER IS NULL) " ))[0] as LLNet.Model.General.Filters.CG_USER_FILTERSRow ;
					
						

						currentRow.WHERE_CLAUSE = Utils.Helpers.ObjToStr(mmFCondition.EditValue);
						currentRow.ORDERBY_CLAUSE = Utils.Helpers.ObjToStr(mmOCondition.EditValue);
					}

					Helpers.Merge(BllInstance.updateDataSet(dsFilters.GetChanges()),dsFilters);

					if (newFilter) 
					{
						repcbMyFilters.Items.Add(Utils.Helpers.ObjToStr(dlg.txtFilterName.EditValue));
						cbMyFilters.EditValue = Utils.Helpers.ObjToStr(dlg.txtFilterName.EditValue);
						repcbMyFilters.DropDownRows++;
					}
				}
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}
		}

		private void btnFirstPage_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{
				firstPage(1,pageSize);
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}
		}

		private void btnPreviousPage_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{
				checkInitBinding();
				previousPage( Math.Max(1,startRecord-pageSize), Math.Max(pageSize,endRecord-pageSize) );
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}

		}

		private void btnPreviousRecord_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{
				checkInitBinding();
							
				if (CManager.Position == 0)
				{
					btnPreviousPage_ItemClick(sender,e);
				}
				else
				{
					CManager.Position -= 1;
				}
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}
		}

		private void btnNextRecord_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{
				checkInitBinding();
				
				if (CManager.Position == CManager.Count -1)
				{
					btnNextPage_ItemClick(sender,e);
				}
				else
				{
					CManager.Position += 1;
				}
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}
		}

		private void btnNextPage_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{
				checkInitBinding();
				nextPage(startRecord+pageSize,endRecord+pageSize);
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}
		}

		private void btnLastPage_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{
				recordCount = bllInstance.GetCount(dataSet.GetType(),dataSource.Table.TableName,joinQueryParams(),QueryName);
				lastPage(Math.Max(1,recordCount - pageSize),recordCount);
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}
		}

		private void btnPagingSize_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{
				dlgSavePagingSize sps = new dlgSavePagingSize();
				sps.spPagingSize.EditValue = pageSize;
				sps.ShowDialog();
				if (sps.DialogResult == DialogResult.OK)
				{
					Utils.QueryParams qp = new QueryParams();
					qp.AddReplaceParam("MODULE",modulePrefix + moduleName);
					qp.AddReplaceParam("PAGING_SIZE",sps.spPagingSize.EditValue.ToString());
					
					bllInstance.ExecuteSql("SavePageSize",qp,"General");
					pageSize = Int32.Parse(sps.spPagingSize.EditValue.ToString());
					recordCount = 0;
					endReached = false;
					startRecord = 1;
					endRecord = pageSize;
					lastRecord = 0;
					this.Refresh();
				}
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}
		}

		private void btnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{
				Refresh();
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}
		}
		
		private void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{

				bool cancel = false;
				if (OnUpdating != null)
				{
					OnUpdating(ref cancel);
				}

				if (!cancel)
				{
					if (dataSet.HasChanges())
					{
						try
						{
							DataSet ds = bllInstance.updateConnDataSet(dataSet.GetChanges(),connectionName);
							if (!ds.HasErrors)
							{
								//							Helpers.Merge(ds,dataSet);
								dataSet.AcceptChanges();
							}
							else
							{
								dataSet.RejectChanges();
							}
						}
						catch (Exception ex)
						{
							dataSet.RejectChanges();
							throw ex;
						}
					}
				}

				if (OnUpdated != null)
				{
					OnUpdated(btnSave);
				}
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}
		}

		
		private void btnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{
				bool cancel = false;
				if (OnDeleting != null)
				{
					OnDeleting(ref cancel);
				}
				if (!cancel)
				{
					CManager.EndCurrentEdit();
					dataSource.Delete(CManager.Position);
				}
				if (OnDeleted != null)
				{
					OnDeleted(btnDelete);
				}
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}
		}

	
		private void btnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{
				bool cancel = false;
				if (OnAdding != null)
				{
					OnAdding(ref cancel);
				}
				if (!cancel)
				{
					dataSource.AddNew();
					CManager.Position = CManager.Count - 1;

				}
				if (OnAdded != null)
				{
					OnAdded(btnAdd);
				}
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}
		}

		
		private void btnRunQuery_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{
				checkInitBinding();

				if (cmbColumns.EditValue != null && txtFilter.EditValue != null)
				{
					runQuery();			
				}
				else
				{
					MessageBox.Show("Debe seleccionar una columna e indicar un valor");
				}
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}
		}


		private void btnClearQuery_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{
				checkInitBinding();
				cmbColumns.EditValue = null;
				txtFilter.EditValue = null;
				
				runQuery();
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}
		}

		
		private void btnAdvancedQuery_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{
				showFilter();
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}
		}

		private void btnEjecutar_Click(object sender, EventArgs e)
		{
			Cursor oldCursor = Cursor.Current; 
			Cursor.Current = Cursors.WaitCursor; 

			try
			{
				runQuery();
			}
			finally
			{
				Cursor.Current = oldCursor; 
			}
		}
		
	
		#endregion

		#region public properties

		public int PageSize
		{
			get {return pageSize;}
			set {pageSize = value;}
		}

		public Model.IBLL BllInstance
		{
			get {return bllInstance;}
			set {bllInstance = value;}
		}

		public Utils.EntityClasifications EntityClasifications
		{
			get {return entityClasifications;}
			set {entityClasifications = value;}
		}

		public Utils.QueryParams QueryParams
		{
			get 
			{
				// Para que no de errores el compilador al estar en modo de diseño
				if (!DesignMode)
                    return joinQueryParams();
				else
					return null;
			}
			set {externPList = value;}
		}

		public string ConnectionName
		{
			get {return connectionName;}
			set {connectionName=value;}
		}

		public string QueryName
		{
			get {return queryName;}
			set {queryName = value;}
		}

		public bool Active
		{
			get {return active;}
			set {active = value;}
		}

		public string ModuleName
		{
			get {return moduleName;}
			set {moduleName = value;}
		}

		public string ModulePrefix
		{
			get {return modulePrefix;}
			set {modulePrefix = value;}
		}

		public string User
		{
			get {return user;}
			set {user = value;}
		}

		public long StartRecord
		{
			get {return this.startRecord;}
		}

		public object DataSource 
		{ 
			get {return dataSource;}
			set 
			{
				if (value != null && dataSource != value)
				{
					BeginUCInit();
					if (value is DataView)
					{
						dataSource = value as DataView;
						cManager = this.Form.BindingContext[value];
					}
					else if (value is DataTable)
					{
						dataSource = ((DataTable)value).DefaultView;
						cManager = this.Form.BindingContext[value];
					}
					else
						throw new Exception("El tipo de datos del DataSource es desconocido.");
					EndUCInit();
				}
			}
		}

		
		public BindingManagerBase CManager
		{
			get { return cManager; }
		}

		#endregion

		#region public members

		public void Open(Model.IBLL pBllInstance, string pConnName, Utils.QueryParams pExList)
		{
			if (!active)
			{
				active = true;
				externPList = pExList;
				bllInstance = pBllInstance;
				connectionName = (pConnName == null) ? bllInstance.DefaultConnName : pConnName;
				
				fillColumnsCombo();	
			}
		}

		public void Open(Model.IBLL pBllInstance)
		{
			if (!active)
			{
				active = true;
				bllInstance = pBllInstance;
				connectionName = bllInstance.DefaultConnName;
				runQuery();
			}
		}

		public void Open(Model.IBLL pBllInstance, string pConnName)
		{
			if (!active)
			{
				active = true;
				bllInstance = pBllInstance;
				connectionName = (pConnName == null) ? bllInstance.DefaultConnName : pConnName;
				runQuery();
			}
		}

		public void SetDataBinding(object dataSource)
		{
			BeginUCInit();
			DataSource = dataSource;
			
			if (pList == null) 
			{
				pList = new Utils.QueryParams();
			}
			else
			{
				pList.Clear();
			}

			EndUCInit();
		}

		public void Refresh()
		{
			bool cancel = false;
			if (OnRefreshing != null)
			{
				OnRefreshing(ref cancel);
			}

			if (!cancel)
			{

				if (endReached)
				{
					btnLastPage_ItemClick(null,null);
				}
				else
				{
					getData(startRecord,endRecord); 
					if (dataSet.Tables[dataSource.Table.TableName].Rows.Count < pageSize)
					{
						endReached=true;
						recordCount = dataSet.Tables[dataSource.Table.TableName].Rows.Count;
					}
	
					UpdateButtons(null,null);
				}
			}

			if (OnRefreshed != null)
			{
				OnRefreshed(btnRefresh);
			}
		}

		public void FirstPage()
		{
			btnFirstPage_ItemClick(null,null);
		}

		public void LastPage()
		{
			btnLastPage_ItemClick(null,null);
		}

		public void NextPage()
		{
			btnNextPage_ItemClick(null,null);
		}

		public void PreviousPage()
		{
			btnPreviousPage_ItemClick(null,null);
		}

		public void NextRecord()
		{
			btnNextRecord_ItemClick(null,null);
		}

		public void PreviousRecord()
		{
			btnPreviousRecord_ItemClick(null,null);
		}

		public void SaveData()
		{
			btnSave_ItemClick(null,null);
		}

		#endregion
			
		#region public events

		public event BeforeActionEventHandler OnUpdating;
		public event BeforeActionEventHandler OnDeleting;
		public event BeforeActionEventHandler OnAdding;
		public event BeforeActionEventHandler OnRefreshing;
		public event BeforeActionEventHandler OnFilterChanging;

		public event AfterActionEventHandler OnUpdated;
		public event AfterActionEventHandler OnDeleted;
		public event AfterActionEventHandler OnAdded;
		public event AfterActionEventHandler OnRefreshed;
		public event AfterActionEventHandler OnFilterChanged;

		public event AfterGetDataEventHandler OnAfterGetData;

		#endregion
	}
}