﻿using System;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;


namespace ICaiBan.Framework.DB
{
    /// <summary>
    /// 只读数据库集合
    /// </summary>
    public class ReadOnlyItemCollection : ConfigurationElementCollection
    {
        public ReadOnlyItemCollection()
        {

        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return ConfigurationElementCollectionType.AddRemoveClearMap;
            }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new ReadOnlyItemElement();
        }


        protected override ConfigurationElement CreateNewElement(string elementName)
        {
            return new ReadOnlyItemElement(elementName);
        }


        protected override Object GetElementKey(ConfigurationElement element)
        {
            return ((ReadOnlyItemElement)element).Name;
        }


        public new string AddElementName
        {
            get
            { return base.AddElementName; }

            set
            { base.AddElementName = value; }

        }

        public new string ClearElementName
        {
            get
            { return base.ClearElementName; }

            set
            { base.AddElementName = value; }

        }

        public new string RemoveElementName
        {
            get
            { return base.RemoveElementName; }
        }

        public new int Count
        {
            get { return base.Count; }
        }


        public ReadOnlyItemElement this[int index]
        {
            get
            {
                return (ReadOnlyItemElement)BaseGet(index);
            }
            set
            {
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }

        new public ReadOnlyItemElement this[string Name]
        {
            get
            {
                return (ReadOnlyItemElement)BaseGet(Name);
            }
        }

        public int IndexOf(ReadOnlyItemElement url)
        {
            return BaseIndexOf(url);
        }

        public void Add(ReadOnlyItemElement url)
        {
            BaseAdd(url);
        }

        protected override void BaseAdd(ConfigurationElement element)
        {
            BaseAdd(element, false);
        }

        public void Remove(ReadOnlyItemElement url)
        {
            if (BaseIndexOf(url) >= 0)
                BaseRemove(url.Name);
        }

        public void RemoveAt(int index)
        {
            BaseRemoveAt(index);
        }

        public void Remove(string name)
        {
            BaseRemove(name);
        }

        public void Clear()
        {
            BaseClear();
        }
    }
}
