using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace CNAS_DBSync
{
    public class InstrumentDataFact
    {
        public static InstrumentData CreateInstrumentDataSource(DataSourceType dataSourceType,params object[] vs)
        {
            InstrumentData instrumentData;

            switch (dataSourceType)
            {                
                case DataSourceType.Access:
                    instrumentData = new AccessInstrumentData(vs);
                    break;
                case DataSourceType.SQL:
                    instrumentData = new SQLInstrumentData(vs);
                    break;
                case DataSourceType.SQLLite:
                    instrumentData = new SQLiteInstrumentData(vs);
                    break;
                case DataSourceType.Excel:
                default:
                    instrumentData = new ExcelInstrumentData(vs);
                    break;
            }
            return instrumentData;
        }
    }

    public abstract class InstrumentData
    {
        /// <summary>
        /// 获取数据源数据
        /// </summary>
        public abstract Dictionary<string,DataTable> GetInstrumentData();
    }

    public class ExcelInstrumentData:InstrumentData
    {
        public string StrLocalPath { get; set; }

        public ExcelInstrumentData(params object[] vs)
        {
            this.StrLocalPath = vs[0].ToString();
        }

        public override Dictionary<string, DataTable> GetInstrumentData()
        {
            return ExcelHelper.ReadExcelTableNameToTable(StrLocalPath);
        }
    }

    public class AccessInstrumentData : InstrumentData
    {
        public string StrLocalPath { get; set; }

        public string StrUser { get; set; }

        public string StrPwd { get; set; }

        public AccessInstrumentData(params object[] vs)
        {
            this.StrLocalPath = vs[0].ToString();
            if(vs[1]!=null)  this.StrUser = vs[1].ToString();
            this.StrPwd = vs[2].ToString();
        }

        public override Dictionary<string, DataTable> GetInstrumentData()
        {
            return MdbHelper.ReadAccessTables(StrLocalPath,StrUser,StrPwd);
        }
    }

    public class SQLInstrumentData : InstrumentData
    {
        public string StrHost { get; set; }

        public string StrName { get; set; }

        public string StrUser { get; set; }

        public string StrPwd { get; set; }

        public SQLInstrumentData(params object[] vs)
        {
            this.StrHost = vs[0].ToString();
            this.StrName = vs[1].ToString();
            this.StrUser = vs[2].ToString();
            this.StrPwd = vs[3].ToString();
        }


        public override Dictionary<string, DataTable> GetInstrumentData()
        {
            throw new NotImplementedException();
        }

        private string CreateConnectionString()
        {
            return string.Format("");
        }
    }

    public class SQLiteInstrumentData : InstrumentData
    {
        public string StrLocalPath { get; set; }

        public string StrUser { get; set; }

        public string StrPwd { get; set; }

        public SQLiteInstrumentData(params object[] vs)
        {
            this.StrLocalPath = vs[0].ToString();
            if (vs[1] != null)  this.StrUser = vs[1].ToString();
            this.StrPwd = vs[2].ToString();
        }

        public override Dictionary<string, DataTable> GetInstrumentData()
        {
            SQLiteHelper.SetConnectionString(StrLocalPath, StrPwd);
            return SQLiteHelper.ReadSQLiteTables();
        }
    }

}
