using System.Collections;
using System.ComponentModel;
using System.Diagnostics;

namespace ZANZILib.Protocols.QueryCriteria
{
    ///	<summary>
    ///	Generic help classes for protocols
    ///	provides type converters for protocol property grids
    ///	provides dropdown resource values extracted from resource dll
    ///	At present retrieves country and catagory dropdown values
    ///	</summary>
    public class clsPropertyConverters
    {
        #region Variable declaration

        //	static  ArrayList aCatIDs;
        //	static  ArrayList aCatNames;

        #endregion

        #region	Functions

        #region Nested type: CategoryConverter

        public class CategoryConverter : CountryConverter
        {
            private readonly ArrayList aCatNames;
            private ArrayList aCatIDs;


            public CategoryConverter()
            {
                Debug.WriteLine("CategoryConverter init");
                //Get the catagory values
                //Get the catagories into local variable

                ZANZIRes.clsMain cls = new ZANZIRes.clsMain();
                aCatNames = cls.GetCatagory(ZANZIRes.clsMain.TypeArray.Category, ZANZIRes.clsMain.TypeField.Name);
                aCatIDs = cls.GetCatagory(ZANZIRes.clsMain.TypeArray.Category, ZANZIRes.clsMain.TypeField.ID);
            }

            public override TypeConverter.StandardValuesCollection
                GetStandardValues(ITypeDescriptorContext context)
            {
                //Enum and get a list of all countries in the framework
                //return new StandardValuesCollection(new string[]{"New	File", "File1",	"Document1"});

                //return new StandardValuesCollection(CategoryList());
                //ZANZIRes.clsMain cls = new ZANZIRes.clsMain();
                //return new StandardValuesCollection(cls.GetDataTable());
                return new StandardValuesCollection(aCatNames);
            }

//
//			public int GetIDFromName(string name)
//			{
//			
//				return new int;
//			}
        }

        #endregion

        #region Nested type: CountryConverter

        /// <summary>
        /// Gets a ArryList of Category from this assebly
        /// for use as dropdown values in a dropdown listbox
        /// </summary>
        /// <returns>ArryList of strings</returns>
        //			private	ArrayList CategoryList()
        //			{
        //				ArrayList aStr=	new	ArrayList();
        //				
        //				return aStr	;
        //
        //			}
        //		}
        /// <summary>
        /// Class that is used to enable read/write operations
        /// for properties listed in a propertygrid
        /// where properties are of type string
        /// </summary>
        public class CountryConverter : StringConverter
        {
            private readonly ArrayList aCountryNames;
            private ArrayList aCountryIDs;

            public CountryConverter()
            {
                Debug.WriteLine("CountryConverter init");

                ZANZIRes.clsMain cls = new ZANZIRes.clsMain();
                aCountryNames = cls.GetCatagory(ZANZIRes.clsMain.TypeArray.Country, ZANZIRes.clsMain.TypeField.Name);
                aCountryIDs = cls.GetCatagory(ZANZIRes.clsMain.TypeArray.Country, ZANZIRes.clsMain.TypeField.ID);
            }

            public override bool GetStandardValuesSupported(
                ITypeDescriptorContext context)
            {
                return true;
            }

            public override StandardValuesCollection
                GetStandardValues(ITypeDescriptorContext context)
            {
                //Enum and get a list of all countries in the framework
                //return new StandardValuesCollection(new string[]{"New	File", "File1",	"Document1"});

                //return new StandardValuesCollection(CountryList());
                return new StandardValuesCollection(aCountryNames);
            }

            public override bool GetStandardValuesExclusive(
                ITypeDescriptorContext context)
            {
                return true;
            }

//			public int GetIDFromName(string name)
//			{
//				return int;
//			
//			}


            /// <summary>
            /// Gets a ArryList of countries from the framework
            /// for use as dropdown values in a dropdown listbox
            /// </summary>
            /// <returns>ArryList of strings</returns>
            //			private	ArrayList CountryList()
            //			{
            //				ArrayList aStr=	new	ArrayList();
            //				CultureInfo[] ci = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
            //
            //				for(int	i=0;i<=(int)ci.Length-1	;i++) 
            //				{
            //				
            //					string str =  new RegionInfo(ci[i].LCID).EnglishName;
            //				
            //					try
            //					{
            //						if (!aStr.Contains(str))
            //						 aStr.Add(str);
            //				
            //							
            //					}
            //					catch (Exception ex)
            //					{
            //						//Console.WriteLine("{0} Exception caught.", ex);
            //					}
            //				}
            //				aStr.Sort();
            //
            //				foreach (string i in aStr) 
            //				{
            //					
            //
            //								Debug.WriteLine (i.ToString() );
            //				}
            //
            //				return aStr	;
            //
            //			}
        }

        #endregion

        #endregion

//		#region the converter class for rw property convertion
//
//		public class FilterCritConverter:ExpandableObjectConverter
//		{
//
//			public override bool CanConvertTo(ITypeDescriptorContext context,
//				System.Type destinationType) 
//			{
//				if (destinationType == typeof( ZANZILib.Protocols.QueryCriteria.clsZanziProt.FilterCrit))
//					return true;
//
//				return base.CanConvertTo(context, destinationType);
//			}
//
//			public override object ConvertTo(ITypeDescriptorContext context,
//				CultureInfo culture, 
//				object value, 
//				System.Type destinationType) 
//			{
//				if (destinationType == typeof(System.String) && 
//					value is ZANZILib.Protocols.QueryCriteria.clsZanziProt.FilterCrit)
//				{
//
//					ZANZILib.Protocols.QueryCriteria.clsZanziProt.FilterCrit so = (clsZanziProt.FilterCrit)value;
//
//					return so.Name;
//				}
//				return base.ConvertTo(context, culture, value, destinationType);
//			}
//
//			public override bool CanConvertFrom(ITypeDescriptorContext context,
//				System.Type sourceType) 
//			{
//				if (sourceType == typeof(string))
//					return true;
//
//				return base.CanConvertFrom(context, sourceType);
//			}
//
//			public override object ConvertFrom(ITypeDescriptorContext context,
//				CultureInfo culture, object value) 
//			{
//				if (value is string) 
//				{
//					try 
//					{
//						string s = (string) value;
//						int colon = s.IndexOf(':');
//						int comma = s.IndexOf(',');
//
//						if (colon != -1 && comma != -1) 
//						{
//							string checkWhileTyping = s.Substring(colon + 1 ,
//								(comma - colon - 1));
//
//							colon = s.IndexOf(':', comma + 1);
//							comma = s.IndexOf(',', comma + 1);
//
//							string checkCaps = s.Substring(colon + 1 , 
//								(comma - colon -1));
//
//							colon = s.IndexOf(':', comma + 1);
//
//							string suggCorr = s.Substring(colon + 1);
//
//							clsZanziProt.FilterCrit so = new clsZanziProt.FilterCrit();
//
//							//so.Name =string.Parse(so.Name);
//							//so.SpellCheckCAPS = Boolean.Parse(checkCaps);
//							//so.SuggestCorrections = Boolean.Parse(suggCorr);
//	                    
//							return so;
//						}
//					}
//					catch 
//					{
//						throw new ArgumentException(
//							"Can not convert '" + (string)value + 
//							"' to type FilterCrit");
//					}
//				}  
//				return base.ConvertFrom(context, culture, value);
//			}
//		}
//		#endregion
//		
    }
}