using System;
using System.Data;
using System.Collections;

using Cosmos.UserFrame;
using Cosmos.ServiceProvider;
using Cosmos.Common;
using Cosmos.CommonManager; 

/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 무결성 관리
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Service
{
    public class Integrity : IIntegrity
    {
        #region 변수 선언
        private SManager sManager = new SManager();                                 // 이 객체를 통해 업무 Service 호출
        private PosStatus m_cPosStatus = new PosStatus();                           //기본정보 참조
        private IMasterUs m_cMstService = null;                                     // 마스터 인터페이스
        private StateServer StateObject = (StateServer)StateServer.GetInstance();   // StateObject : StateServer Object (객체)
        private IDataProcessUs m_cDataService = null;
        private TranStatus m_cTrnStatus = new TranStatus();                         //거래정보 참조

        private ISaleCompleteUs m_cSaleComplete = null;                             // 거래완료처리
        private IDatabaseSQL m_cSqlDbService = null;                                // 데이터베이스 관리
        private IDataCommonUs m_cDataCommon = null;                                 // POS 공통함수 인터페이스

        public Integrity()
        {
            m_cPosStatus = (PosStatus)StateObject.POS;      // POS 기본정보
            m_cTrnStatus = (TranStatus)StateObject.TRAN;    // POS 거래정보

            m_cMstService = (IMasterUs)sManager.InitServiceInstance(ServiceLists.ASV_MASTER.DLL, ServiceLists.ASV_MASTER.POS_MASTER);
            m_cDataService = (IDataProcessUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_SERVICE);
            m_cSaleComplete = (ISaleCompleteUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.SALE_COMPLETE);
            m_cSqlDbService = (IDatabaseSQL)sManager.InitServiceInstance(ServiceLists.AGENT_DATABASE.DLL, ServiceLists.AGENT_DATABASE.DATABASE_MSSQL);
            m_cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);

        }
        #endregion

        #region 무결성 로그 조회
        /// <summary>
        /// 무결성 로그 조회
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public DataTable SelectIntegrityLog(string[] aParam)
        {
            string sSql = "";
            try
            {
                sSql = "";

                sSql += " SELECT \n";
                sSql += "       SEQ \n";
                sSql += "   ,   ISNULL(PROC_TYPE, 'M')      PROC_TYPE \n";
                sSql += "   ,   ISNULL(CHECK_DT, '')        CHECK_DT \n";
                sSql += "   ,   ISNULL(CHECK_FLAG, 'N')     CHECK_FLAG \n";
                sSql += "FROM POSLOG..ETC_INTEGRITY_LOG \n";
                sSql += "WHERE CMP_CD	= '" + m_cPosStatus.Base.CmpCd + "' \n";
                sSql += "AND SALE_DT	= '" + aParam[0] + "' \n";
                sSql += "AND STOR_CD	= '" + m_cPosStatus.Base.StoreNo + "' \n";
                sSql += "AND POS_NO		= '" + m_cPosStatus.Base.PosNo + "' \n";
                sSql += "AND DEVICE_TYPE = '" + aParam[2] + "' \n";
                sSql += "AND CHECK_TYPE	= '" + aParam[1] + "' \n";                
                sSql += "ORDER BY SEQ desc \n";

                sSql = sSql.Replace("\t", " ");

                DataTable dtDataInfo = m_cMstService.Select(new string[] { sSql });

                return dtDataInfo;
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return null;
        }
        #endregion
         
    }
}
