using System;
using System.IO;

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

/*-----------------------------------------------------------------------------------------------*/
// 설      명 : Pos 판매정보파일 읽기
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Service
{
    class ReadConfigInfo : IServiceUs
    {
        private SManager sManager = new SManager();                                 //이 객체를 통해 업무 Service 호출
        private StateServer StateObject = (StateServer)StateServer.GetInstance();   //StateObject : StateServer Object(객체)
        private PosStatus m_cPosStatus;                                             //기본정보 참조
        private TranStatus m_cTrnStatus;                                            //거래정보 참조
        private DeviceStatus m_cDevStatus;                                          //기기정보 참조

        public ReadConfigInfo()
        {
            m_cPosStatus = (PosStatus)StateObject.POS;                              //POS 기본정보
            m_cTrnStatus = (TranStatus)StateObject.TRAN;                            //POS 거래정보
            m_cDevStatus = (DeviceStatus)StateObject.DEVICE;                        //POS 주변기기정보
        }

        /// <summary>
        /// 설정파일 읽기
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string Execute(string[] aParam)
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                ReadPosConfig();

                sRet = UserCom.RST_OK;
            }
            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 sRet;
        }

        /// <summary>
        /// POS 환경 설정 파일 읽기
        /// </summary>
        public void ReadPosConfig()
        {
            CmMessage m_PosConfig = CmMessage.MakeMessageFromFile(BaseCom.NxIniPath + PosConst.INI_FILE_NAME.PosConfig);
            CmMessage m_PosSaleInfo = CmMessage.MakeMessageFromFile(BaseCom.NxIniPath + PosConst.INI_FILE_NAME.PosSaleInfo);
            CmMessage m_PosDevice = CmMessage.MakeMessageFromFile(BaseCom.NxIniPath + PosConst.INI_FILE_NAME.PosDevice);
            CmMessage m_PosCommPort = CmMessage.MakeMessageFromFile(BaseCom.NxIniPath + PosConst.INI_FILE_NAME.CommPort);
            //#20171227 인천공항 포스연동 start, phj
            CmMessage m_IncheonAirPort = CmMessage.MakeMessageFromFile(BaseCom.NxIniPath + PosConst.INI_FILE_NAME.IncheonAirPort);
            //#20171227 인천공항 포스연동 end, phj
            
            //#20180322 휴게소pos매출연동 start,phj
            CmMessage m_RestAreaPos = CmMessage.MakeMessageFromFile(BaseCom.NxIniPath + PosConst.INI_FILE_NAME.RestAreaPos);
            //#20180322 휴게소pos매출연동 end,phj

            bool bModifyFlag = false;

            try
            {
                //#20171227 인천공항 포스연동 start, phj 
                m_cPosStatus.IncheonAirport.AirportIP = CmUtil.StringNullEmpty(GetConfigInfo(m_IncheonAirPort, "INCHEONAIRPORT", "AirportIP"));
                m_cPosStatus.IncheonAirport.AirportUser = CmUtil.StringNullEmpty(GetConfigInfo(m_IncheonAirPort, "INCHEONAIRPORT", "AirportUser"));
                m_cPosStatus.IncheonAirport.AirportPass = CmUtil.StringNullEmpty(GetConfigInfo(m_IncheonAirPort, "INCHEONAIRPORT", "AirportPass"));
                m_cPosStatus.IncheonAirport.AirportComp = CmUtil.StringNullEmpty(GetConfigInfo(m_IncheonAirPort, "INCHEONAIRPORT", "AirportComp"));
                m_cPosStatus.IncheonAirport.AirportStore = CmUtil.StringNullEmpty(GetConfigInfo(m_IncheonAirPort, "INCHEONAIRPORT", "AirportStore"));
                m_cPosStatus.IncheonAirport.AirportPosNo = CmUtil.StringNullEmpty(GetConfigInfo(m_IncheonAirPort, "INCHEONAIRPORT", "AirportPosNo"));
                //#20171227 인천공항 포스연동 end, phj

                //#20180322 휴게소pos매출연동 start,phj
                m_cPosStatus.RestAreaPos.RestAreaPosDir = CmUtil.StringNullEmpty(GetConfigInfo(m_RestAreaPos, "RESTAREAPOS", "RestAreaPosDir"));
                m_cPosStatus.RestAreaPos.RestAreaPosGroupCd = CmUtil.StringNullEmpty(GetConfigInfo(m_RestAreaPos, "RESTAREAPOS", "RestAreaPosGroupCd"));
                m_cPosStatus.RestAreaPos.RestAreaPosPosGroupCd = CmUtil.StringNullEmpty(GetConfigInfo(m_RestAreaPos, "RESTAREAPOS", "RestAreaPosPosGroupCd"));
                m_cPosStatus.RestAreaPos.RestAreaPosCd = CmUtil.StringNullEmpty(GetConfigInfo(m_RestAreaPos, "RESTAREAPOS", "RestAreaPosCd"));
                m_cPosStatus.RestAreaPos.RestAreaPosPosNo = CmUtil.StringNullEmpty(GetConfigInfo(m_RestAreaPos, "RESTAREAPOS", "RestAreaPosPosNo"));
                //#20180322 휴게소pos매출연동 end,phj

                // PosConfig.INI
                m_cPosStatus.Base.CmpCd = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "POS", "CmpCd"));
                m_cPosStatus.Base.BrandDiv = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "POS", "BrandDiv"));
                m_cPosStatus.Base.BrandCd = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "POS", "BrandCd"));
                m_cPosStatus.Base.StoreNo = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "POS", "StoreNo"));
                m_cPosStatus.Base.PosNo = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "POS", "PosNo"));

                //m_cPosStatus.Base.PosType = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "POS", "PosType"));
                //m_cPosStatus.Base.PosCommunicationType = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "POS", "PosCommunicationType"));

                //m_cPosStatus.Base.KacPos = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "POS", "KacPos"));
                //m_cPosStatus.Base.KacConNo = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "POS", "KacConNo"));
                //m_cPosStatus.Base.ExPos = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "POS", "ExPos"));
                //m_cPosStatus.Base.ExStoreCd = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "POS", "ExStoreCd"));
                //m_cPosStatus.Base.ExCornerCd = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "POS", "ExCornerCd"));
                
                // 고속도로 입점 관련 정보 기본값 설정
                //if (m_cPosStatus.Base.ExPos == "1")
                //{
                //    if (string.IsNullOrWhiteSpace(m_cPosStatus.Base.ExStoreCd)) m_cPosStatus.Base.ExStoreCd = "S00000104";
                //    if (string.IsNullOrWhiteSpace(m_cPosStatus.Base.ExCornerCd)) m_cPosStatus.Base.ExCornerCd = "0008"; 
                //}
                
                //m_cPosStatus.Base.DesignType = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "POS", "DesignType"));
                //m_cPosStatus.Base.ThemeType = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "POS", "ThemeType"));
                m_cPosStatus.Base.LogLevel = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "POS", "LogLevel")));
                m_cPosStatus.Base.DmbIf = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "POS", "DmbIf"));
                m_cPosStatus.Base.MasterDown = CmUtil.IsNull(GetConfigInfo(m_PosConfig, "POS", "MasterDown"), "1");
                
                m_cPosStatus.Base.LocalDbSource = UserLog.UserAES.StaticKeyDecrypt(CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "DATABASE", "LocalSource")));
                m_cPosStatus.Base.LocalDbCatalog = UserLog.UserAES.StaticKeyDecrypt(CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "DATABASE", "LocalCatalog")));
                m_cPosStatus.Base.LocalDbUserID = UserLog.UserAES.StaticKeyDecrypt(CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "DATABASE", "LocalUserID")));
                m_cPosStatus.Base.LocalDbPassword = UserLog.UserAES.StaticKeyDecrypt(CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "DATABASE", "LocalPassword")));

                m_cPosStatus.Base.CultureID = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "GLOBAL", "CultureID"));
                m_cPosStatus.Base.Country = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "GLOBAL", "Country"));
                m_cPosStatus.Base.FONT = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "GLOBAL", "Font"));
                m_cPosStatus.Base.FONT_FIX = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "GLOBAL", "FontFix", "굴림체"));

                if (m_cPosStatus.Sale.ScreenSizeUser == 0)
                {
                    m_cPosStatus.Sale.ScreenSizeUser = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "GLOBAL", "ScreenSizeUser", "0")));
                    m_cPosStatus.Sale.ScreenSizeCust = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "GLOBAL", "ScreenSizeCust", "0")));
                }
                
                m_cPosStatus.Base.CommSvrIp = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "SERVER", "CommSvrIp"));
                m_cPosStatus.Base.DmbSvrIp = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "SERVER", "DmbSvrIp"));
                m_cPosStatus.Base.CmsSvrIp = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "SERVER", "CmsSvrIp"));  /// 2019-02-25 - 1997fx11
                m_cPosStatus.Base.FtpConnType = CmUtil.IsNull(GetConfigInfo(m_PosConfig, "SERVER", "FtpConnType"), "1");

                m_cPosStatus.Base.TextLogoMsg1 = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "PRINT", "TextLogoMsg1"));
                m_cPosStatus.Base.TextLogoMsg2 = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "PRINT", "TextLogoMsg2"));
                // 영수증 상단 텍스트로고 출력 여부 설정
                if(m_cPosStatus.Base.TextLogoMsg1.Length > 0 || m_cPosStatus.Base.TextLogoMsg2.Length > 0)
                {
                    m_cPosStatus.Base.TextLogoMsgUseYn = "1";
                }
                else
                {
                    m_cPosStatus.Base.TextLogoMsgUseYn = "0";
                }
                m_cPosStatus.Ver.ProgramVer = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "PGMVER", "ProgramVer10"));
                m_cPosStatus.Ver.ProgramVerSeq = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "PGMVER", "ProgramVerSeq10"));

                m_cPosStatus.Base.LogoUpload = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "POS", "LogoUpload"));

                // CommPort.ini
                m_cPosStatus.Base.TranPort = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosCommPort, "SERVER", "TranPort")));
                m_cPosStatus.Base.JrnlPort = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosCommPort, "SERVER", "JrnlPort")));
                m_cPosStatus.Base.SysInfoPort = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosCommPort, "SERVER", "SysInfoPort")));
                m_cPosStatus.Base.TranInqPort = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosCommPort, "SERVER", "TranInqPort")));
                m_cPosStatus.Base.MissChkPort = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosCommPort, "SERVER", "MissChkPort")));
                m_cPosStatus.Base.PayInqPort = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosCommPort, "SERVER", "PayInqPort")));
                m_cPosStatus.Base.BizInqPort = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosCommPort, "SERVER", "BizInqPort")));
                m_cPosStatus.Base.MstPort = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosCommPort, "SERVER", "MstPort")));
                m_cPosStatus.Base.CmsPort = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosCommPort, "SERVER", "CmsPort")));    //  2019-02-22 - 1997fx11
                m_cPosStatus.Base.SignLogPort = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosCommPort, "SERVER", "SignLogPort")));
                m_cPosStatus.Base.PayLogPort = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosCommPort, "SERVER", "PayLogPort")));
                m_cPosStatus.Base.AppLogPort = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosCommPort, "SERVER", "AppLogPort")));
                m_cPosStatus.Base.EtcTranPort = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosCommPort, "SERVER", "EtcTranPort")));
                m_cPosStatus.Base.KDSSvrPort = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosCommPort, "SERVER", "KDSSvrPort")));
                m_cPosStatus.Base.DmbIfPort = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosCommPort, "SERVER", "DmbIfPort")));
                m_cPosStatus.Base.ScaleLogPort = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosCommPort, "SERVER", "ScaleLogPort")));
                m_cPosStatus.Base.KioskPort = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosCommPort, "SERVER", "KioskPort")));    //  2019-03-20 - 1997fx11

                if (m_cPosStatus.Base.ScaleLogPort == 0)
                {
                    m_cPosStatus.Base.ScaleLogPort = 9015;
                    // PosSaleInfo.ini 저장
                    IServiceUs cSaveConfigInfo = (IServiceUs)sManager.InitServiceInstance(ServiceLists.BSV_OPEN_CLOSE.DLL, ServiceLists.BSV_OPEN_CLOSE.SAVE_CONFIGINFO);
                    string sRet = cSaveConfigInfo.Execute(new string[] { PosConst.INI_FILE_NAME.CommPort });
                }
                
                // PosSaleInfo.ini
                m_cPosStatus.Base.OpenClose = CmUtil.StringNullEmpty(GetConfigInfo(m_PosSaleInfo, "POSOPEN", "OpenClose", "0"));
                m_cPosStatus.Base.SaleDate = CmUtil.StringNullEmpty(GetConfigInfo(m_PosSaleInfo, "POSOPEN", "SaleDate", PosConst.BEGINNING_MST_DOWN_DATE.Substring(0, 8)));
                m_cPosStatus.Base.MstDownDate = CmUtil.StringNullEmpty(GetConfigInfo(m_PosSaleInfo, "POSOPEN", "MstDownDate", m_cPosStatus.Mst.ComplexShopType == "0" ? PosConst.BEGINNING_MST_DOWN_DATE : PosConst.BEGINNING_COMPLEX_SHOP_MST_DOWN_DATE));
                m_cPosStatus.Base.KSN_IC_Download = CmUtil.StringNullEmpty(GetConfigInfo(m_PosSaleInfo, "POSOPEN", "KSN_IC_Download"));
                m_cPosStatus.Base.KSN_SignPad_Download = CmUtil.StringNullEmpty(GetConfigInfo(m_PosSaleInfo, "POSOPEN", "KSN_SignPad_Download"));

                // 시스템 오픈일자 
                m_cPosStatus.Base.SysOpenDate = CmUtil.StringNullEmpty(GetConfigInfo(m_PosSaleInfo, "POSOPEN", "SysOpenDate"));

                m_cPosStatus.Base.MsgSeqNo = CmUtil.StringNullEmpty(GetConfigInfo(m_PosSaleInfo, "MSGNO", "MsgSeqNo"));
                m_cPosStatus.Base.RegNo = CmUtil.StringNullEmpty(GetConfigInfo(m_PosSaleInfo, "MSGNO", "RegNo"));
                m_cPosStatus.Base.TradeNo = CmUtil.StringNullEmpty(GetConfigInfo(m_PosSaleInfo, "MSGNO", "TradeNo"));
                m_cPosStatus.Base.StartTradeNo = CmUtil.StringNullEmpty(GetConfigInfo(m_PosSaleInfo, "MSGNO", "StartTradeNo"));
                m_cPosStatus.Base.MidCloseSeq = CmUtil.StringNullEmpty(GetConfigInfo(m_PosSaleInfo, "MSGNO", "MidCloseSeq"));
                if (m_cPosStatus.Base.MidCloseSeq.Trim() == "") m_cPosStatus.Base.MidCloseSeq = "01";
                
                //m_cPosStatus.Base.CashierNo = CmUtil.StringNullEmpty(GetConfigInfo(m_PosSaleInfo, "CASHIER", "CashierNo"));
                //m_cPosStatus.Base.CashierName = CmUtil.StringNullEmpty(GetConfigInfo(m_PosSaleInfo, "CASHIER", "CashierName"));
                //m_cPosStatus.Base.CashierAuth = CmUtil.StringNullEmpty(GetConfigInfo(m_PosSaleInfo, "CASHIER", "CashierAuth"));

                m_cPosStatus.Base.MstBatchDownDate = CmUtil.StringNullEmpty(GetConfigInfo(m_PosSaleInfo, "CHECKOVER", "MstBatchDownDate", m_cPosStatus.Mst.ComplexShopType == "0" ? PosConst.BEGINNING_MST_DOWN_DATE : PosConst.BEGINNING_COMPLEX_SHOP_MST_DOWN_DATE));
                m_cPosStatus.Base.RegularNoticeUpdateDT = CmUtil.StringNullEmpty(GetConfigInfo(m_PosSaleInfo, "CHECKOVER", "RegularNoticeUpdDate"));
                m_cPosStatus.Base.EmergencyNoticeUpdateDT = CmUtil.StringNullEmpty(GetConfigInfo(m_PosSaleInfo, "CHECKOVER", "EmergencyNoticeUpdDate"));
                m_cPosStatus.Base.SaleNoticeUpdateDT1 = CmUtil.StringNullEmpty(GetConfigInfo(m_PosSaleInfo, "CHECKOVER", "SaleNoticeUpdDate1"));
                m_cPosStatus.Base.SaleNoticeUpdateDT2 = CmUtil.StringNullEmpty(GetConfigInfo(m_PosSaleInfo, "CHECKOVER", "SaleNoticeUpdDate2"));
                //  2019-03-21 - 1997fx11 : Kiosk 관련 신상품 마지막업데이트일자 추가
                m_cPosStatus.Base.NewProductUpdateDT = CmUtil.StringNullEmpty(GetConfigInfo(m_PosSaleInfo, "CHECKOVER", "NewProductUpdDate"));

                string sInitValue = DateTime.Now.ToString("yyyyMMdd") + "000000";
                m_cPosStatus.Base.RegularNoticeUpdateDT = m_cPosStatus.Base.RegularNoticeUpdateDT == "" ? sInitValue : m_cPosStatus.Base.RegularNoticeUpdateDT;
                m_cPosStatus.Base.EmergencyNoticeUpdateDT = m_cPosStatus.Base.EmergencyNoticeUpdateDT == "" ? sInitValue : m_cPosStatus.Base.EmergencyNoticeUpdateDT;
                m_cPosStatus.Base.SaleNoticeUpdateDT1 = m_cPosStatus.Base.SaleNoticeUpdateDT1 == "" ? sInitValue : m_cPosStatus.Base.SaleNoticeUpdateDT1;
                m_cPosStatus.Base.SaleNoticeUpdateDT2 = m_cPosStatus.Base.SaleNoticeUpdateDT2 == "" ? sInitValue : m_cPosStatus.Base.SaleNoticeUpdateDT2;
                m_cPosStatus.Base.NewProductUpdateDT = m_cPosStatus.Base.NewProductUpdateDT == "" ? sInitValue : m_cPosStatus.Base.NewProductUpdateDT;

                // PosDevice.ini
                // Printer
                m_cPosStatus.Base.OlePosPrinterController = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "POSPRINTER", "Controller"));
                m_cPosStatus.Base.OlePosPrinterSerialPortNumber = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "POSPRINTER", "SerialPortNumber"));
                m_cPosStatus.Base.OlePosPrinterSerialBaudRate = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "POSPRINTER", "SerialBaudRate")));
                m_cPosStatus.Base.OlePosPrinterModel = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "POSPRINTER", "Model"));
                m_cDevStatus.Printer.UseYn = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "POSPRINTER", "UseFlag")) == "1" ? true : false;
                if (m_cDevStatus.Printer.UseYn == false)
                {
                    bModifyFlag = true;
                    m_PosDevice.GetMessage("POSPRINTER".Trim()).MakeMessageOverWrite("UseFlag".Trim(), "0");
                }

                //#20171212 프린터 상태 체크 여부 추가 start
                //0: 체크, 1: 체크안함
                m_cPosStatus.Base.OlePosPrinterCheckYn = CmUtil.IsNull(GetConfigInfo(m_PosDevice, "POSPRINTER", "CheckPrinter"), "0");
                //#20171212 프린터 상태 체크 여부 추가 end

                // IcReader
                m_cPosStatus.Base.OlePosICReaderSerialPortNumber = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "ICREADER", "SerialPortNumber"));
                m_cPosStatus.Base.OlePosICReaderSerialBaudRate = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "ICREADER", "SerialBaudRate")));
                //m_cPosStatus.Base.OlePosICReaderSerialNumber = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "ICREADER", "SerialNumber"));
                m_cPosStatus.Base.OlePosICReaderModel = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "ICREADER", "Model"));
                m_cDevStatus.ICReader.UseYn = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "ICREADER", "UseFlag")) == "1" ? true : false;
                if (m_cDevStatus.ICReader.UseYn == false)
                {
                    bModifyFlag = true;
                    m_PosDevice.GetMessage("ICREADER".Trim()).MakeMessageOverWrite("UseFlag".Trim(), "0");
                }

                // CAT Terminal
                m_cPosStatus.Base.OlePosCATSerialPortNumber = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "CATTERMINAL", "SerialPortNumber"));
                m_cPosStatus.Base.OlePosCATSerialBaudRate = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "CATTERMINAL", "SerialBaudRate")));
                m_cPosStatus.Base.OlePosCATTimeout = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "CATTERMINAL", "TimeOut")));
                m_cPosStatus.Base.OlePosCATModel = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "CATTERMINAL", "Model"));
                m_cDevStatus.CatTerminal.UseYn = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "CATTERMINAL", "UseFlag")) == "1" ? true : false;
                if (m_cDevStatus.CatTerminal.UseYn == false)
                {
                    bModifyFlag = true;
                    m_PosDevice.GetMessage("CATTERMINAL".Trim()).MakeMessageOverWrite("UseFlag".Trim(), "0");

                    m_cPosStatus.Base.OlePosCATModel = "";
                }
                else if (m_cPosStatus.Base.OlePosCATModel == PosConst.CAT_MODEL_DIV._CHN_SAND)
                {
                    // 샨더인 경우 sand.ini port 설정
                    WinAPI.WritePrivateProfileString("COMDEF", "com", m_cPosStatus.Base.OlePosCATSerialPortNumber.Substring(3, m_cPosStatus.Base.OlePosCATSerialPortNumber.Length - 3), BaseCom.NxBinPath + "sand.ini"); 
                }

                // CashDrawer
                m_cPosStatus.Base.OlePosCashDrawerType = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "CASHDRAWER", "CashDrawerType"));
                m_cDevStatus.Cashdrawer.UseYn = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "CASHDRAWER", "UseFlag")) == "1" ? true : false;
                if (m_cDevStatus.Cashdrawer.UseYn == false)
                {
                    bModifyFlag = true;
                    m_PosDevice.GetMessage("CASHDRAWER".Trim()).MakeMessageOverWrite("UseFlag".Trim(), "0");
                }
                m_cPosStatus.Base.OlePosCashDrawerSerialPortNumber = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "CASHDRAWER", "SerialPortNumber"));
                m_cPosStatus.Base.OlePosCashDrawerBaudRate = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "CASHDRAWER", "SerialBaudRate")));

                // Scale
                m_cPosStatus.Base.OlePosScaleSerialPortNumber = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "SCALE", "SerialPortNumber"));
                m_cPosStatus.Base.OlePosScaleSerialBaudRate = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "SCALE", "SerialBaudRate")));
                m_cDevStatus.Scale.UseYn = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "SCALE", "UseFlag")) == "1" ? true : false;
                if (m_cDevStatus.Scale.UseYn == false)
                {
                    bModifyFlag = true;
                    m_PosDevice.GetMessage("SCALE".Trim()).MakeMessageOverWrite("UseFlag".Trim(), "0");
                }

                // ScalePoleDisplay
                m_cPosStatus.Base.OleScalePoleDisplayPortNumber = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "SCALEPOLEDISP", "SerialPortNumber"));
                m_cPosStatus.Base.OleScalePoleDisplayBaudRate = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "SCALEPOLEDISP", "SerialBaudRate")));
                m_cDevStatus.ScalePoleDisplay.UseYn = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "SCALEPOLEDISP", "UseFlag")) == "1" ? true : false;
                if(m_cDevStatus.ScalePoleDisplay.UseYn == false)
                {
                    bModifyFlag = true;
                    m_PosDevice.GetMessage("SCALEPOLEDISP".Trim()).MakeMessageOverWrite("UseFlag".Trim(), "0");
                }

                // SignPad
                m_cPosStatus.Base.OlePosSignPadSerialPortNumber = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "SIGNPAD", "SerialPortNumber"));
                m_cPosStatus.Base.OlePosSignPadSerialBaudRate = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "SIGNPAD", "SerialBaudRate")));
                m_cPosStatus.Base.OlePosSignPadModel = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "SIGNPAD", "Model"));
                m_cPosStatus.Base.OlePosSignPadFileDate = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "SIGNPAD", "FileDate")));
                m_cPosStatus.Base.OlePosSignPadAutoFlag = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "SIGNPAD", "AutoFlag"));
                m_cPosStatus.Base.OlePosSignPadMinCnt = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "SIGNPAD", "MinCnt")));
                m_cPosStatus.Base.OlePosSignPadTimeOut = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "SIGNPAD", "TimeOut")));
                m_cDevStatus.SignPad.UseYn = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "SIGNPAD", "UseFlag")) == "1" ? true : false;
                if (m_cDevStatus.SignPad.UseYn == false)
                {
                    bModifyFlag = true;
                    m_PosDevice.GetMessage("SIGNPAD".Trim()).MakeMessageOverWrite("UseFlag".Trim(), "0");
                }

                // Label Printer
                m_cPosStatus.Base.OlePosLabelPrinterSerialPortNumber = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "LABELPRINTER", "SerialPortNumber"));
                m_cPosStatus.Base.OlePosLabelPrinterSerialBaudRate = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "LABELPRINTER", "SerialBaudRate")));
                m_cPosStatus.Base.OlePosLabelPrinterModel = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "LABELPRINTER", "Model"));
                m_cDevStatus.LabelPrinter.UseYn = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "LABELPRINTER", "UseFlag")) == "1" ? true : false;
                if (m_cDevStatus.LabelPrinter.UseYn == false)
                {
                    bModifyFlag = true;
                    m_PosDevice.GetMessage("LABELPRINTER".Trim()).MakeMessageOverWrite("UseFlag".Trim(), "0");
                }

                // Scanner
                m_cDevStatus.Scanner.UseYn = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "SCANNER", "UseFlag")) == "1" ? true : false;
                if (m_cDevStatus.Scanner.UseYn == false)
                {
                    bModifyFlag = true;
                    m_PosDevice.GetMessage("SCANNER".Trim()).MakeMessageOverWrite("UseFlag".Trim(), "0");
                }

                // MSR
                m_cPosStatus.Base.OlePosMsrController = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "MSR", "Controller"));
                m_cPosStatus.Base.OlePosMsrSerialPortNumber = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "MSR", "SerialPortNumber"));
                m_cPosStatus.Base.OlePosMsrSerialBaudRate = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "MSR", "SerialBaudRate")));
                m_cPosStatus.Base.OlePosMsrModel = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "MSR", "Model"));
                m_cDevStatus.Msr.UseYn = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "MSR", "UseFlag")) == "1" ? true : false;
                if (m_cDevStatus.Msr.UseYn == false)
                {
                    bModifyFlag = true;
                    m_PosDevice.GetMessage("MSR".Trim()).MakeMessageOverWrite("UseFlag".Trim(), "0");
                }
                m_cDevStatus.Msr.STX = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "MSR", "STX"));
                m_cDevStatus.Msr.ETX = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "MSR", "ETX"));

                // CDP
                m_cPosStatus.Base.OleCdpController = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "CDP", "Controller"));
                m_cPosStatus.Base.OleCdpSerialPortNumber = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "CDP", "SerialPortNumber"));
                m_cPosStatus.Base.OleCdpSerialBaudRate = CmUtil.LongParse(CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "CDP", "SerialBaudRate")));
                m_cPosStatus.Base.OleCdpModel = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "CDP", "Model"));
                m_cDevStatus.Cdp.UseYn = CmUtil.StringNullEmpty(GetConfigInfo(m_PosDevice, "CDP", "UseFlag")) == "1" ? true : false;
                if(m_cDevStatus.Cdp.UseYn == false)
                {
                    bModifyFlag = true;
                    m_PosDevice.GetMessage("CDP").MakeMessageOverWrite("UseFlag", "0");
                }

                //#16232 환경부 1회용컵 사용줄이기 관련 테이크인아웃 설정 start
                m_cPosStatus.Base.ProdTakeInOutUse = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "PRODTAKEINOUT", "ProdTakeInOutUse"));
                m_cPosStatus.Base.ProdTakeInOutDiv = CmUtil.StringNullEmpty(GetConfigInfo(m_PosConfig, "PRODTAKEINOUT", "ProdTakeInOutDiv"));
                //#16232 환경부 1회용컵 사용줄이기 관련 테이크인아웃 설정 end

                // 초기화
                m_cPosStatus.Base.TrainingFlag = "0";
                m_cPosStatus.Base.OwnPartDiv = "0";
            }
            catch(Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            finally
            {
                if (bModifyFlag == true) m_PosDevice.MakeFileFromMessage(BaseCom.NxIniPath + PosConst.INI_FILE_NAME.PosDevice);
            }
        }

        /// <summary>
        /// 설정 파일 읽기
        /// </summary>
        /// <param name="cCfgInfo"></param>
        /// <param name="sGroup"></param>
        /// <param name="sValueName"></param>
        /// <param name="sDefault"></param>
        /// <returns></returns>
        private string GetConfigInfo(CmMessage cCfgInfo, string sGroup, string sValueName, string sDefault = "")
        {
            try
            {
                string sValue = cCfgInfo.GetMessage(sGroup).GetMessageValue(sValueName);
                //if (sValue == null)
                if (string.IsNullOrWhiteSpace(sValue))
                    return sDefault;
                else
                    return sValue;
            }
            catch { }

            return sDefault;
        }
    }
}
