﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using SGLibrary.Extend;

namespace SGLibrary.Framework.GridBind.WinForm
{
    public interface IGridViewBind<T> 
    {
        /// <summary>
        /// 行数量
        /// </summary>
        Int32 Count { get; }

        /// <summary>
        /// 行数量变动
        /// </summary>
        event EventHandler<EventArgs<Int32>> CountChanged;

        /// <summary>
        /// 获取或设置列表中的位置
        /// </summary>
        Int32 Position { get; set; }

        bool TopIsSelected{ get; }

        bool EndIsSelected { get; }

        /// <summary>
        /// 当前行为顶行
        /// </summary>
        Boolean CurrentIsTop { get; }

        /// <summary>
        /// 当前行为底行
        /// </summary>
        Boolean CurrentIsEnd { get; }

        /// <summary>
        /// 当前仅选中一个行
        /// </summary>
        Boolean IsOnlyOneSelect { get; }

        /// <summary>
        /// 有选中行
        /// </summary>
        Boolean HasSelected { get; }

        /// <summary>
        /// 获取或设置列表中的当前项
        /// </summary>
        T Current { get; set; }

        /// <summary>
        /// 当前所选(Current总是存在，但不一定被选择)
        /// </summary>
        T CurrentSelect { get; }

        /// <summary>
        /// 获取或设置列表中的位置
        /// </summary>
        Int32 PositionTo(T t);

        /// <summary>
        /// 选择所有
        /// </summary>
        void SelectedAll();

        /// <summary>
        /// 取消所有的选择
        /// </summary>
        void ClearSelection();

        /// <summary>
        /// 所选择的数据
        /// </summary>
        IList<T> SelectedObjects { get; set; }

        void SelectedObjectsAdd(IList<T> Values);

        String DataSourceName { get; set; }

        IList<T> DataSource { get; set; }

        void Binding(IList<T> dataSource);

        /// <param name="dataSourceName">导出时作为默认文件名</param>
        void Binding(IList<T> dataSource, String dataSourceName);

        /// <param name="key">保存表格配制会包括此dataSourceKey</param>
        void Binding(IList<T> dataSource, String dataSourceName, String dataSourceKey);

        void Refresh();

        void Add(IEnumerable<T> Values);
        void Add(T Value);

        void Remove(IList<T> Values);
        void Remove(T Value);
        void RemoveCurrent();
        void RemoveSelected();

        void OrderBy<TKey>(SGLibrary.Extend.Func<T, TKey> keySelector);
        void OrderByDescending<TKey>(SGLibrary.Extend.Func<T, TKey> keySelector);

        /// <summary>
        /// 清除所有绑定对象
        /// </summary>
        void Clear();

        DataGridViewColumn GetColumn(String propertyName);
        Comparison<T> Comparison { get; set; }

        dlgGetComboboxColumnItems GetComboboxColumnItems { get; set; }
        dlgGetLookupColumnDataSource GetLookupColumnDataSource { get; set; }
        void RefreshLookupAnComboboxColumn();
        Boolean SaveConfig();

        /// <summary>
        /// 成功返回的Text为文件名，失败则为错误信息
        /// </summary>
        KeyText<Boolean> ExportToExcel(String fileName);

        Boolean AllowSort { get; set; }
        String DataSourceKey { get; }
    }
}
