using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;
using System.Reflection;

namespace NewPosInstaller
{
    /// <summary>
    /// POS 기본정보 및 설치일정 확인
    /// </summary>
    public class BasicInfoCheck : Echo, IProcess
    {
        public bool Execute()
        {
            bool retValue = false; 
            try
            {
                ComLog.WriteLog(ComLog.Level.trace
                              , System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."
                              + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                              , "Start [CurrentDirectory=" + Environment.CurrentDirectory + "]");
                

                // POS 기본정보 가져오기 
                retValue = GetPosBasicInfo();
                if (retValue == false) return false;

                // 각사별 설치정보 서버정보(FTP/통신) 가져오기
                retValue = GetInstallInfo();
                if (retValue == false) return false;

                // POS 설치일정 가져오기
                //  Mod, 2017.03.01, 설치일정 무조건 조회 처리 
                //if (string.IsNullOrWhiteSpace(BasicInfo.InstallDate) || string.IsNullOrWhiteSpace(BasicInfo.InstallTime))
                //{
                //    retValue = GetScheduleInfo();
                //    if (retValue == false) return false; 
                //}
                //  Mod, 2017.03.01, 설치일정 무조건 조회 처리 
                retValue = GetScheduleInfo();
                if (retValue == false) return false; 

                return true;
            }
            catch (Exception ex)
            {
                ComLog.WriteLog(ComLog.Level.Exception
                              , System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."
                              + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                              , "  => Exception : " + ex.Message);
                return false;
            }
            finally
            {
                ComLog.WriteLog(ComLog.Level.trace
                              , System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."
                              + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                              , string.Format("End, Result={0}", retValue ? "Success" : "Failed"));
            }
        }

        public void Stop()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// POS 기본정보 가져오기 
        /// </summary>
        /// <returns></returns>
        private bool GetPosBasicInfo()
        {
            bool retValue = false;
            try
            {
                // POS 기본정보 확인 중 입니다.
                base.OnEcho("Checking POS basic information.");


                // 점포정보 INI
                // 1. PCKR     : C:\\SPCPOS\\DATA\\DBPOS\\SHOPINFO.INI
                //               C:\\SPCPOS\\DATA\\DBPOS\\DEVICEINFO.INI
                //               C:\\SPCPOS\\DATA\\DBPOS\\SALEINFO.INI
                // 2. BRKR(BR) : C:\\BRKPOS\\DB\\BRINI\\STORE.pos
                //               C:\\BRKPOS\\DB\\BRINI\\DEVICE.pos
                //
                // 3. BRKR(DD) : C:\\BRKPOS\\DB\\DDINI\\STORE.pos
                //               C:\\BRKPOS\\DB\\DDINI\\DEVICE.pos
                //               ※ BRKR의 경우 HKEY_CURRENT_USER\Software\POSBRKOREA 이 곳의 BRAND 가 "BR" 이면 BR "DD" 이면 DD
                // 4. SL       : C:\\SLPOS\\DATA\\DBPOS\\SHOPINFO.INI
                //               C:\\SLPOS\\DATA\\DBPOS\\DEVICEINFO.INI
                //               C:\\SLPOS\\DATA\\DBPOS\\SALEINFO.INI

                // ★★★ 해외 점포는 경로가 다르다
                // 해외 -> C:\SPCINT
                // 프랑스 -> C:\SPCFRA

                var dbRegKey = string.Empty;                                                                            // 데이터베이스 정보 (레지스트리)
                var targetDir = new string[] { @"C:\SPCPOS", @"C:\BRKPOS", @"C:\SLPOS", @"C:\SPCINT", @"C:\SPCFRA" };
                BasicInfo.OldPosRootDir = string.Empty; 
                BasicInfo.OldPosIniDir = string.Empty;
                BasicInfo.OldStoreINI = string.Empty;
                BasicInfo.OldDeviceINI = string.Empty;
                BasicInfo.OldSaleINI = string.Empty;
                
                DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory);
                string workDir = di.Parent.FullName;

                BasicInfo.OldPosRootDir = workDir; 
                if (targetDir.Contains(workDir) == false)
                {
                    workDir = string.Empty;
                    for (var i = 0; i < targetDir.Length; i++)
                    {
                        if (ComLib.ExistDirectory(targetDir[i]))
                        {
                            workDir = targetDir[i].ToUpper();
                            break;
                        }
                    }
                }

                if (workDir.Equals(@"C:\SPCPOS"))
                {
                    dbRegKey = @"Software\SPCPOS";
                    BasicInfo.OldPosIniDir = @"C:\SPCPOS\DATA\DBPOS";
                    BasicInfo.OldStoreINI = Path.Combine(BasicInfo.OldPosIniDir, "SHOPINFO.INI");
                    BasicInfo.OldDeviceINI = Path.Combine(BasicInfo.OldPosIniDir, "DEVICEINFO.INI");
                    BasicInfo.OldSaleINI = Path.Combine(BasicInfo.OldPosIniDir, "SALEINFO.INI");
                    BasicInfo.OldFtpINI = Path.Combine(BasicInfo.OldPosIniDir, "FTPINFO.INI");
                    BasicInfo.OldStoreOptINI = string.Empty;
                }
                else if (workDir.Equals(@"C:\BRKPOS"))
                {
                    var key = Registry.GetValue(Microsoft.Win32.Registry.CurrentUser, @"Software\POSBRKOREA", "BRAND");
                    if (key.ToUpper().Trim() == "BR")
                    {
                        BasicInfo.OldPosIniDir = @"C:\BRKPOS\DB\BRINI";
                    }
                    else if (key.ToUpper().Trim() == "DD")
                    {
                        BasicInfo.OldPosIniDir = @"C:\BRKPOS\DB\DDINI";
                    }
                    if (string.IsNullOrWhiteSpace(BasicInfo.OldPosIniDir) == false)
                    {
                        BasicInfo.OldStoreINI = Path.Combine(BasicInfo.OldPosIniDir, "STORE.pos");
                        BasicInfo.OldDeviceINI = Path.Combine(BasicInfo.OldPosIniDir, "DEVICE.pos");
                        BasicInfo.OldSaleINI = "";
                        BasicInfo.OldFtpINI = Path.Combine(BasicInfo.OldPosIniDir, "FTPINFO.pos");
                        BasicInfo.OldStoreOptINI = Path.Combine(BasicInfo.OldPosIniDir, "STOREOPT.pos");
                    }
                }
                else if (workDir.Equals(@"C:\SLPOS"))
                {
                    dbRegKey = @"Software\SLPOS";
                    BasicInfo.OldPosIniDir = @"C:\SLPOS\DATA\DBPOS";
                    BasicInfo.OldStoreINI = Path.Combine(BasicInfo.OldPosIniDir, "SHOPINFO.INI");
                    BasicInfo.OldDeviceINI = Path.Combine(BasicInfo.OldPosIniDir, "DEVICEINFO.INI");
                    BasicInfo.OldSaleINI = Path.Combine(BasicInfo.OldPosIniDir, "SALEINFO.INI");
                    BasicInfo.OldFtpINI = Path.Combine(BasicInfo.OldPosIniDir, "FTPINFO.INI");
                    BasicInfo.OldStoreOptINI = string.Empty;
                }
                else if (workDir.Equals(@"C:\SPCINT"))
                {
                    // PC 해외 ==> 추정, 정확하지는 않다. 
                    dbRegKey = @"Software\SPCINT";
                    BasicInfo.OldPosIniDir = @"C:\SPCPOS\DATA\DBPOS";
                    BasicInfo.OldStoreINI = Path.Combine(BasicInfo.OldPosIniDir, "SHOPINFO.INI");
                    BasicInfo.OldDeviceINI = Path.Combine(BasicInfo.OldPosIniDir, "DEVICEINFO.INI");
                    BasicInfo.OldSaleINI = Path.Combine(BasicInfo.OldPosIniDir, "SALEINFO.INI");
                    BasicInfo.OldFtpINI = Path.Combine(BasicInfo.OldPosIniDir, "FTPINFO.INI");
                    BasicInfo.OldStoreOptINI = string.Empty;
                }
                else if (workDir.Equals(@"C:\SPCFRA"))
                { 
                    // PC 프랑스 ==> 추정, 정확하지는 않다. 
                    dbRegKey = @"Software\SPCFRA";
                    BasicInfo.OldPosIniDir = @"C:\SPCFRA\DATA\DBPOS";
                    BasicInfo.OldStoreINI = Path.Combine(BasicInfo.OldPosIniDir, "SHOPINFO.INI");
                    BasicInfo.OldDeviceINI = Path.Combine(BasicInfo.OldPosIniDir, "DEVICEINFO.INI");
                    BasicInfo.OldSaleINI = Path.Combine(BasicInfo.OldPosIniDir, "SALEINFO.INI");
                    BasicInfo.OldFtpINI = Path.Combine(BasicInfo.OldPosIniDir, "FTPINFO.INI");
                    BasicInfo.OldStoreOptINI = string.Empty;
                }


                if (string.IsNullOrWhiteSpace(BasicInfo.OldPosIniDir))
                {
                    ComLog.WriteLog(ComLog.Level.Error
                                  , System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."
                                  + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                                  , "  => As-is pos ini File Directory not found");
                    return retValue = false;
                }
                else
                {
                    ComLog.WriteLog(ComLog.Level.trace
                                  , System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."
                                  + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                                  , "  => As-is pos ini File Directory = " + BasicInfo.OldPosIniDir);
                }

                // ini 파일에서 점포정보 획득 
                const string SECTION = "SHOPINFO";

                BasicInfo.BrandCd = IniFile.GetValue(BasicInfo.OldStoreINI, SECTION, "BRANDCD");
                BasicInfo.BrandGb = IniFile.GetValue(BasicInfo.OldStoreINI, SECTION, "BRANDGB");
                
                BasicInfo.StoreNm = IniFile.GetValue(BasicInfo.OldStoreINI, SECTION, "STORESNM");

                var addr = IniFile.GetValue(BasicInfo.OldStoreINI, SECTION, "STORE_ADDR1").Trim() + " "
                         + IniFile.GetValue(BasicInfo.OldStoreINI, SECTION, "STORE_ADDR2").Trim();
                BasicInfo.StoreAddr = addr.Trim();                                                                      // Add, 2017.03.03
                BasicInfo.StoreTel = IniFile.GetValue(BasicInfo.OldStoreINI, SECTION, "STORETELL");                     // Add, 2017.03.03

                BasicInfo.PosNo = IniFile.GetValue(BasicInfo.OldStoreINI, SECTION, "POSNO");
                BasicInfo.StoreType = IniFile.GetValue(BasicInfo.OldStoreINI, SECTION, "STORE_GB");
                if (string.IsNullOrWhiteSpace(BasicInfo.StoreType)) BasicInfo.StoreType = "0";

                // 주문구분 (메인/서브)
                BasicInfo.OrderType = IniFile.GetValue(BasicInfo.OldStoreINI, SECTION, "ORDER_GB");

                // 데이터베이스 경로 
                var dbip = Registry.GetValue(Microsoft.Win32.Registry.CurrentUser, dbRegKey, "DBIP");
                ComLog.WriteLog(ComLog.Level.trace
                              , System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."
                              + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                              , string.Format("Database Source => [{0}]", dbip));
                if (BasicInfo.StoreType == "1")
                {
                    var localhosts = new string[] { @".", @".\", @"LOCALHOST" };
                    if (string.IsNullOrWhiteSpace(dbip) == false)
                    {
                        BasicInfo.OrderType = localhosts.Contains(dbip.ToUpper()) ? "0" : "1";
                    }
                }

                BasicInfo.Nation = IniFile.GetValue(BasicInfo.OldStoreINI, SECTION, "NATION", "KOR");                   // 해외만 존재하는것 같음, 국내는 없음
                BasicInfo.Language = IniFile.GetValue(BasicInfo.OldStoreINI, SECTION, "LANGUAGE", "KR");                // 해되는 존재하는것 같은, 국내는 BR은 있고 나머지는 없음.

                BasicInfo._country = string.Empty;
                BasicInfo._cultureid = string.Empty;
                BasicInfo._font = string.Empty;
                BasicInfo._fontFix = string.Empty;

                // AS-IS 회사코드 
                BasicInfo.OldCompCd = IniFile.GetValue(BasicInfo.OldStoreINI, SECTION, "COMP_CD");
                // AS-IS 점포코드 
                BasicInfo.OldStoreNo = IniFile.GetValue(BasicInfo.OldStoreINI, SECTION, "STORECD");

                // TO-BE 회사코드 
                string _cmp = string.Empty;
                string _con = string.Empty;

                if (BasicInfo.OldCompCd.StartsWith("BR")) _cmp = "BR";
                else if (BasicInfo.OldCompCd.StartsWith("PC")) _cmp = "PC";
                else if (BasicInfo.OldCompCd.StartsWith("SL")) _cmp = "SL";
                else
                {
                    return false;
                }

                if (string.IsNullOrWhiteSpace(BasicInfo.Nation)) BasicInfo.Nation = "KOR";
                switch (BasicInfo.Nation.ToUpper())
                {
                    case "KOR": _con = "KR"; break;     // 한국
                    case "USA": _con = "US"; break;     // 미국
                    case "VNM": _con = "VN"; break;     // 베트남
                    case "CHN": _con = "CN"; break;     // 중국
                    case "FRA": _con = "FR"; break;     // 프랑스
                    case "SGP": _con = "SG"; break;     // 싱가포르 
                    default: return false;
                }

                // TO-BE 회사코드 
                BasicInfo.CompCd = _cmp + _con;
                // TO-BE 점포코드 
                BasicInfo.StoreNo = ConvertStoreCode(BasicInfo.CompCd, BasicInfo.OldStoreNo);

                return retValue = true;
            }
            catch (Exception ex)
            {
                ComLog.WriteLog(ComLog.Level.Exception
                              , System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."
                              + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                              , "  => Exception : " + ex.Message);
                return retValue = false;
            }
            finally
            {
                ComLog.WriteLog(ComLog.Level.trace
                              , System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."
                              + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                              , string.Format("  => Result={0} BasicInfo = [{1}]", retValue ? "Success" : "Failed", BasicInfo.ToString()));
            }
        }

        private bool GetInstallInfo()
        {
            bool retValue = false; 
            try
            {
                // 설치정보 확인 중 입니다.
                base.OnEcho("Checking installation information.");

                string SECTION = string.Empty; 
                string filePath = Environment.CurrentDirectory + @"\NewPosInstaller.ini";

                SECTION = "INSTALL";
                string temp = IniFile.GetValue(filePath, SECTION, "InstallDir", @"C:\SPC\POS\");
                if (temp.Substring(temp.Length - 1, 1) != @"\") temp += @"\";
                DirInfo.InstallDir = temp;

                SECTION = "DATABASE";
                DatabaseInfo.InstanceName = IniFile.GetValue(filePath, SECTION, "InstanceName", @"MSSQL$SPCPOS");
                DatabaseInfo.DataSource = IniFile.GetValue(filePath, SECTION, "DataSource", @".\SPCPOS");
                DatabaseInfo.Password = IniFile.GetValue(filePath, SECTION, "Password", @"@spcPOS!123");
                DatabaseInfo.UserId = IniFile.GetValue(filePath, SECTION, "UserId", @"sa");

                SECTION = BasicInfo.CompCd;
                ServerInfo.FtpName = IniFile.GetValue(filePath, SECTION, "FtpIP");
                ServerInfo.FtpIP = ComLib.GetIpAddress(ServerInfo.FtpName);
                ServerInfo.FtpUser = IniFile.GetValue(filePath, SECTION, "FtpUser");
                ServerInfo.FtpPass = IniFile.GetValue(filePath, SECTION, "FtpPass");
                ServerInfo.FtpPath = IniFile.GetValue(filePath, SECTION, "FtpPath");
                ServerInfo.DownFile = IniFile.GetValue(filePath, SECTION, "DownFile", "SPC.zip");

                ServerInfo.SvrName = IniFile.GetValue(filePath, SECTION, "SvrIP");
                ServerInfo.SvrIP = ComLib.GetIpAddress(ServerInfo.SvrName);
                ServerInfo.SvrPort = ComLib.IntParse(IniFile.GetValue(filePath, SECTION, "SvrPort"));

                if (string.IsNullOrWhiteSpace(ServerInfo.FtpIP)) return false;
                if (string.IsNullOrWhiteSpace(ServerInfo.FtpUser)) return false;
                if (string.IsNullOrWhiteSpace(ServerInfo.FtpPass)) return false;
                if (string.IsNullOrWhiteSpace(ServerInfo.FtpPath)) return false;
                if (ServerInfo.FtpPath.Substring(ServerInfo.FtpPath.Length - 1, 1) != "/") ServerInfo.FtpPath += "/";

                // 국가코드가 없으면, KOR 기본값으로 처리 
                if (string.IsNullOrWhiteSpace(BasicInfo.Nation)) BasicInfo.Nation = "KOR";

                #region ### (주석) 2017.01.13, 폰트/언어/문화 코드는 코드에서 설정하지 않고, Config.ini 파일설정을 그냥 사용한다. 

                // ****************************************************************************************************
                //  2017.01.13, 폰트/언어/문화 코드는 코드에서 설정하지 않고, Config.ini 파일설정을 그냥 사용한다. 
                //              해외법인의 경우에는 법인별 배포파일을 다운로드 받는다. 
                // ****************************************************************************************************

                // 폰트/글로버정보 기본값 설정 , 언어,문화 코드는 마스터(DB)로 관리 기본값만 설정
                //switch (BasicInfo.Nation.ToUpper())
                //{
                //    case "KOR": BasicInfo._font = "나눔스퀘어";                  BasicInfo._fontFix = "굴림체";      BasicInfo._country = "ko-KR"; BasicInfo._cultureid = "MC002"; break;     // 한국
                //    case "USA": BasicInfo._font = SystemFonts.DefaultFont.Name; BasicInfo._fontFix = "Courier New"; BasicInfo._country = "en-US"; BasicInfo._cultureid = "MC001"; break;     // 미국
                //    case "VNM": BasicInfo._font = SystemFonts.DefaultFont.Name; BasicInfo._fontFix = "Courier New"; BasicInfo._country = "vi-VN"; BasicInfo._cultureid = "MVN01"; break;     // 베트남
                //    case "CHN": BasicInfo._font = SystemFonts.DefaultFont.Name; BasicInfo._fontFix = "Courier New"; BasicInfo._country = "zh-CH"; BasicInfo._cultureid = "M0005"; break;     // 중국
                //    case "FRA": BasicInfo._font = SystemFonts.DefaultFont.Name; BasicInfo._fontFix = "Courier New"; BasicInfo._country = "fr-FR"; BasicInfo._cultureid = "M0004"; break;     // 프랑스
                //    case "SGP": BasicInfo._font = SystemFonts.DefaultFont.Name; BasicInfo._fontFix = "Courier New"; BasicInfo._country = "en-SG"; BasicInfo._cultureid = "     "; break;     // 싱가포르 
                //}

                //// 폰트/글로벌정보를 설정값이 존재하면 대체 한다.
                //temp = string.Empty; 
                //temp = IniFile.GetValue(filePath, SECTION, "FontName", "");
                //if (string.IsNullOrWhiteSpace(temp) == false) BasicInfo._font = temp; 

                //temp = IniFile.GetValue(filePath, SECTION, "FontFixName", "");
                //if (string.IsNullOrWhiteSpace(temp) == false) BasicInfo._fontFix = temp; 

                //temp= IniFile.GetValue(filePath, SECTION, "Country", "");
                //if (string.IsNullOrWhiteSpace(temp) == false) BasicInfo._country = temp;

                //temp = IniFile.GetValue(filePath, SECTION, "CultureID", "");
                //if (string.IsNullOrWhiteSpace(temp) == false) BasicInfo._cultureid = temp;  

                #endregion

                return retValue = true;
            }
            catch (Exception ex)
            {
                ServerInfo.FtpIP = string.Empty;
                ServerInfo.FtpUser = string.Empty;
                ServerInfo.FtpPass = string.Empty;
                ServerInfo.SvrIP = string.Empty;
                ServerInfo.SvrPort = 0;

                ComLog.WriteLog(ComLog.Level.Exception
                              , System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."
                              + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                              , "  => Exception : " + ex.Message);
                return retValue = false;
            }
            finally
            {
                ComLog.WriteLog(ComLog.Level.trace
                              , System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."
                              + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                              , string.Format("  => Result={0} ServerInfo = [{1}]", retValue ? "Success" : "Failed", ServerInfo.ToString()));
            }
        }

        /// <summary>
        /// 설치일자 서버조회 
        /// </summary>
        /// <returns></returns>
        private bool GetScheduleInfo()
        {
            bool retValue = false; 
            try
            {
                // 설치일정 확인 중 입니다.
                base.OnEcho("Checking installation schedule.");

                BasicInfo.InstallDate = string.Empty;
                BasicInfo.InstallTime = string.Empty;
                BasicInfo.SysOpenDate = string.Empty; 

                // 설치일정 요청 
                Hashtable htSendData = new Hashtable();
                Hashtable htRecvData = new Hashtable();

                // 통신해더 생성
                string commHead = ItemColumn.MakeCommHeader(0, "06");  

                htSendData.Add(Column.IQ_INSTALL_SCHEDULE_INQ.DATA.INQ_TYPE, Column.IQ_INSTALL_SCHEDULE_INQ.MSG_ID);
                htSendData.Add(Column.IQ_INSTALL_SCHEDULE_INQ.DATA.STOR_CD, BasicInfo.StoreNo);
                htSendData.Add(Column.IQ_INSTALL_SCHEDULE_INQ.DATA.REQ_TYPE, "1");
                htSendData.Add(Column.IQ_INSTALL_SCHEDULE_INQ.DATA.INSTALL_DATE, "");
                htSendData.Add(Column.IQ_INSTALL_SCHEDULE_INQ.DATA.INSTALL_TIME, "");
                htSendData.Add(Column.IQ_INSTALL_SCHEDULE_INQ.DATA.SYS_OPEN_DATE, "");
                htSendData.Add(Column.IQ_INSTALL_SCHEDULE_INQ.DATA.RES_CD, "");

                NetworkJSON irt = new NetworkJSON();
                int ret = irt.IRTSendReceive(ServerInfo.SvrIP, ServerInfo.SvrPort, 1000 * 20, commHead, htSendData, ref htRecvData);
                if (ret != ComLib.OK)
                {
                    ComLog.WriteLog(ComLog.Level.Error
                                  , System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."
                                  + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                                  , "  => Server communication error");
                    return retValue = false;
                }
                string res = htRecvData[Column.IQ_INSTALL_SCHEDULE_INQ.DATA.RES_CD].ToString().Trim();
                ComLog.WriteLog(ComLog.Level.Error
                              , System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."
                              + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                              , string.Format("  => Inquery install schedule RespCode={0}", res));
                if (res != "00")
                {
                    return retValue = false; 
                }

                BasicInfo.InstallDate = htRecvData[Column.IQ_INSTALL_SCHEDULE_INQ.DATA.INSTALL_DATE].ToString().Trim();
                BasicInfo.InstallTime = htRecvData[Column.IQ_INSTALL_SCHEDULE_INQ.DATA.INSTALL_TIME].ToString().Trim();
                BasicInfo.SysOpenDate = htRecvData[Column.IQ_INSTALL_SCHEDULE_INQ.DATA.SYS_OPEN_DATE].ToString().Trim();

                return retValue = true;
            }
            catch (Exception ex)
            {
                ComLog.WriteLog(ComLog.Level.Exception
                              , System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."
                              + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                              , "  => Exception : " + ex.Message);
                return retValue = false;
            }
            finally
            {
                ComLog.WriteLog(ComLog.Level.trace
                              , System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."
                              + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                              , string.Format("  => IQ_INSTALL_SCHEDULE_INQ Result={0} InstallDate={1} InstallTime={2} SysOpenDate={3}"
                              , retValue ? "Success" : "Failed", BasicInfo.InstallDate, BasicInfo.InstallTime, BasicInfo.SysOpenDate));
            }
        }

        /// <summary>
        /// 점포코드 매핑 
        /// </summary>
        /// <param name="compCode"></param>
        /// <param name="oldStoreNo"></param>
        /// <returns></returns>
        private string ConvertStoreCode(string compCode, string oldStoreNo)
        {
            bool retValue = false;
            string newStoreNo = string.Empty; 

            try
            {
                // 점포코드 확인 중 입니다.
                base.OnEcho("Checking store codes.");

                //string[] resourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
                string recName = "NewPosInstaller.StoreCodeMap.txt";
                using (StreamReader sr = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(recName )))
                {
                    while (sr.Peek() >= 0)
                    {
                        string line = sr.ReadLine();

                        if (line.StartsWith("#")) continue;
                        if (string.IsNullOrWhiteSpace(line)) continue;

                        string[] data = line.Split(',');
                        if (data.Length < 3) continue;

                        if (compCode == data[0].Trim() && oldStoreNo == data[1].Trim())
                        {
                            newStoreNo = data[2].Trim();
                            break;                  
                        }
                    }
                }

                // 없으면, 옛날코드 리턴
                if (string.IsNullOrWhiteSpace(newStoreNo)) newStoreNo = oldStoreNo;

                retValue = true;
                return newStoreNo;
            }
            catch (Exception ex)
            {
                ComLog.WriteLog(ComLog.Level.Exception
                              , System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."
                              + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                              , "  => Exception : " + ex.Message);
                retValue = false;
                return newStoreNo = oldStoreNo;
            }
            finally
            {
                ComLog.WriteLog(ComLog.Level.trace
                              , System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."
                              + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                              , string.Format("  => Result={0}, CompCode={1}, OldStoreNo={2}, NewStoreNo={3}", retValue ? "Success" : "Failed", compCode, oldStoreNo, newStoreNo));
            }
        }










        /// <summary>
        /// AS-IS 회사코드 -> TO-BE 회사코드 및 글로벌 처리  (미사용)
        /// </summary>
        /// <param name="oldCmpCd"></param>
        /// <param name="nat"></param>
        /// <param name="lang"></param>
        /// <returns></returns>
        private bool ConvertCompCode()
        {
            string _cmp = string.Empty;
            string _con = string.Empty;
            string _cul = string.Empty;
            string _lan = string.Empty;

            try
            {
                //////// 회사코드
                //////if (BasicInfo.OldCompCd.StartsWith("BR"))
                //////{
                //////    _cmp = "BR";
                //////}
                //////else if (BasicInfo.OldCompCd.StartsWith("PC"))
                //////{
                //////    _cmp = "PC";
                //////}
                //////else if (BasicInfo.OldCompCd.StartsWith("SL"))
                //////{
                //////    _cmp = "SL";
                //////}
                //////else
                //////{
                //////    return false;
                //////}

                //////// 국가/폰트 
                //////if (string.IsNullOrWhiteSpace(BasicInfo.Nation)) BasicInfo.Nation = "KOR";
                //////switch (BasicInfo.Nation.ToUpper())
                //////{
                //////    case "KOR": _con = "KR"; BasicInfo._font = "나눔스퀘어"; BasicInfo._fontFix = "굴림체"; break;     // 한국
                //////    case "USA": _con = "US"; BasicInfo._font = SystemFonts.DefaultFont.Name; BasicInfo._fontFix = "Courier New"; break;     // 미국
                //////    case "VNM": _con = "VN"; BasicInfo._font = SystemFonts.DefaultFont.Name; BasicInfo._fontFix = "Courier New"; break;     // 베트남
                //////    case "CHN": _con = "CH"; BasicInfo._font = SystemFonts.DefaultFont.Name; BasicInfo._fontFix = "Courier New"; break;     // 중국
                //////    case "FRA": _con = "FR"; BasicInfo._font = SystemFonts.DefaultFont.Name; BasicInfo._fontFix = "Courier New"; break;     // 프랑스
                //////    case "SGP": _con = "SG"; BasicInfo._font = SystemFonts.DefaultFont.Name; BasicInfo._fontFix = "Courier New"; break;     // 싱가포르 
                //////    default: return false;
                //////}

                //////// 언어,문화 코드는 마스터(DB)로 관리 기본값만 설정
                //////switch (BasicInfo.Nation.ToUpper())
                //////{
                //////    case "KOR": BasicInfo._contry = "ko-KR"; BasicInfo._cultureid = "MC002"; break;    // 한국
                //////    case "USA": BasicInfo._contry = "en-US"; BasicInfo._cultureid = "MC001"; break;    // 미국
                //////    case "VNM": BasicInfo._contry = "vi-VN"; BasicInfo._cultureid = "MVN01"; break;    // 베트남
                //////    case "CHN": BasicInfo._contry = "zh-CH"; BasicInfo._cultureid = "M0005"; break;    // 중국
                //////    case "FRA": BasicInfo._contry = "fr-FR"; BasicInfo._cultureid = "M0004"; break;    // 프랑스
                //////    case "SGP": BasicInfo._contry = "en-SG"; BasicInfo._cultureid = "     "; break;    // 싱가포르 
                //////    default:
                //////        BasicInfo._contry = ""; BasicInfo._cultureid = ""; break;
                //////}

                //////// 회사코드
                //////BasicInfo.CompCd = _cmp + _con;

                return true;
            }
            catch (Exception ex)
            {
                ComLog.WriteLog(ComLog.Level.Exception
                              , System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."
                              + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
                              , ex.Message);
                return false;
            }
        }
    }
}
