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

namespace LLNet.GUI.FormBases
{
    public partial class frmDataViewToolbarBase : LLNet.GUI.FormBases.frmToolbarBase 
	{
		public System.Data.DataView dataViewToolbar;
		

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

			// TODO: Add any initialization after the InitializeComponent call
		}

		public override void Init(object[] pArgs)
		{
			base.Init (pArgs);
			
			dbToolbar.SetDataBinding(dataViewToolbar);
			dbToolbar.Open(GUI.CApp.bll,GUI.CApp.bll.DefaultConnName,QueryParams);


		}


		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		


		protected virtual void frmDataViewToolbarBase_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			foreach(FieldInfo field in this.GetType().GetFields(BindingFlags.NonPublic|BindingFlags.Instance))
			{
				if (field.FieldType == typeof(DevExpress.XtraGrid.Views.Grid.GridView ))
				{				
					((DevExpress.XtraGrid.Views.Grid.GridView )field.GetValue(this)).PostEditor();
					((DevExpress.XtraGrid.Views.Grid.GridView )field.GetValue(this)).UpdateCurrentRow();

				}
				else if (field.FieldType == typeof(DevExpress.XtraVerticalGrid.VGridControl))
				{				
					((DevExpress.XtraVerticalGrid.VGridControl )field.GetValue(this)).FocusFirst();
					((DevExpress.XtraVerticalGrid.VGridControl )field.GetValue(this)).UpdateFocusedRecord();
				}

			}
			
			if (dataViewToolbar.Table.DataSet.HasChanges())
			{
				DialogResult dlg = XtraMessageBox.Show("Desea guardar sus cambios?","Advertencia",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question);

				switch (dlg)
				{
					case DialogResult.Yes :
						dbToolbar.SaveData();
						break;
					case DialogResult.Cancel:
						e.Cancel = true;
						break;
					default :
						e.Cancel = false;
						break;
				
				}
			}		
		}

		/*private void dbToolbar_OnUpdating(ref bool cancel)
		{
			foreach(FieldInfo field in this.GetType().GetFields(BindingFlags.NonPublic|BindingFlags.Instance))
			{
				if (field.FieldType == typeof(DevExpress.XtraGrid.Views.Grid.GridView ))
				{				
					((DevExpress.XtraGrid.Views.Grid.GridView )field.GetValue(this)).PostEditor();
					((DevExpress.XtraGrid.Views.Grid.GridView )field.GetValue(this)).UpdateCurrentRow();

				}
				else if (field.FieldType == typeof(DevExpress.XtraVerticalGrid.VGridControl))
				{				
					((DevExpress.XtraVerticalGrid.VGridControl )field.GetValue(this)).FocusFirst();
					((DevExpress.XtraVerticalGrid.VGridControl )field.GetValue(this)).UpdateFocusedRecord();
				}

			}
		
		}*/
	}
}

