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

using System.Data.OleDb;

namespace CRVM.SIDExcuter
{
    public class LogicConnect
    {
        private IDBAccess projDB = null;
        private StringConnectItem connstrItem = null;
        public EDBItem dbItem;
        private string connstr = "";
        private string tablestr;

        public LogicConnect(EDBItem dbItem, string tablestr)
        {
            this.dbItem = dbItem;
            this.tablestr = tablestr;
            ConnectStrs(dbItem);
        }
     
        public void ConnectStrs(EDBItem dbItem)
        {
            // dbItem = connstrItem.dbItem;

            if (dbItem != null)
            {
                connstrItem = new StringConnectItem();
                connstr = StringConnectItem.InitialStrConn(dbItem);
                projDB = DBFactory.CreateAccess(dbItem.DataType);
            }
            else
            {
                throw new Exception("请配置数据库数据！");
            }
        }
       public DataTable SelTableData(string tablename)
        {
            DataTable dt = new DataTable();
            dt = projDB.SelTableData(tablename, connstr);
            return dt;
        }
        public DataTable SelTableData(string tablename,string sql)
        {
            DataTable dt = new DataTable();
            dt = projDB.SelTableData(tablename,connstr,sql );
            return dt;
        }
         public DataTable DataBase(string sql)
        {
            DataTable dt = new DataTable();
            dt = projDB.DataBase(connstr, sql);
            return dt;
        }
        /// <summary>
        /// 获取事件信息
        /// </summary>
        /// <returns></returns>
        public DataTable GetEventInfo(ShowStyle style)
        {
            string sql = "select seq, eventname, field,datavalue,status,tom from T_BPC_TRIGGER order by seq asc";
            DataTable dt = new DataTable();
            dt = projDB.GetData(connstr, sql, style);
            return dt;
        }

    }
}

