using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using VEPROMS.CSLA.Library;

namespace VEPROMS
{
	public partial class frmPropGrid : DevComponents.DotNetBar.Office2007Form
	{
		private object _PGobject;

		public frmPropGrid(object pgobject)
		{
			InitializeComponent();
			_PGobject = pgobject;
		}

		public frmPropGrid(object pgobject, string title)
		{
			InitializeComponent();
			_PGobject = pgobject;
			this.Text = title;
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			DialogResult = DialogResult.OK;
			DocVersionConfig dvcfg = this._PGobject as DocVersionConfig;
			if (dvcfg != null && dvcfg.IsDirty)
			{
				dvcfg.MyDocVersion.Save();
			}
			this.Close();
		}

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

		private void frmPropGrid_Load(object sender, EventArgs e)
		{
			Show();
			pg.SelectedObject = _PGobject;
		}

		private void pg_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
		{
			DocVersionConfig dvcfg = this._PGobject as DocVersionConfig;
			if (dvcfg != null)
				dvcfg.IsDirty = true;
			// check if folder config & if so, check for name change
			FolderConfig tstfoldercfg = this._PGobject as FolderConfig;
			if (tstfoldercfg != null)
			{
				if ((string)e.OldValue != tstfoldercfg.Name)
				{
					bool isunique = tstfoldercfg.CheckUniqueName(tstfoldercfg.Name);
					if (!isunique)
					{
						MessageBox.Show(string.Format("The Name '{0}' that was entered is not a unique folder name", tstfoldercfg.Name));
						tstfoldercfg.Name = (string)e.OldValue;
					}
				}
			}
			this.Refresh();

		}
	}
	//public partial class SystemConfig
	//{
	//   FolderConfig _FolderConfig;
	//   public SystemConfig(FolderConfig folderConfig)
	//   {
	//      _FolderConfig = folderConfig;
	//      //_FolderConfig.Default_SPPrefix;
	//   }
	//   public string Default_SPPrefix
	//   {
	//      get { return _FolderConfig.Default_SPPrefix; }
	//      set { _FolderConfig.Default_SPPrefix = value; }
	//   }
	//}
}