/*
 
//#20180413 웰컴카드 신규기능 추가 start,phj
//#20180413 웰컴카드 신규기능 추가 end,phj
 
*/

using System;
using System.Collections;
using Cosmos.UserFrame;
using Cosmos.ServiceProvider;
using Cosmos.Common;
using Cosmos.CommonManager;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
using System.Data.OleDb;
using System.Data;
using System.Xml;
using ADODB;
using System.Reflection;
using PosDBApi;
using Cosmos.BaseFrame;
using Newtonsoft.Json;


/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 웰컴카드 발급/할인 함수모음   
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Service
{
    class WelcomCard : PaymentBase, IPaymentUs, IWelcomeCard 
    //class WelcomCard : PaymentBase, IWelcomeCard 
    {
        #region 생산자
        private IPaymentExpUs m_cHappyPoint = null;
        private IDatabaseSQL m_cSqlDbService = null;

        /// <summary>
        /// 현재 등록중인 결제 정보
        /// </summary>
        public WelcomCard()
        {
            m_cPosStatus = (PosStatus)StateObject.POS;      // POS 기본정보
            m_cTrnStatus = (TranStatus)StateObject.TRAN;    // POS 거래정보
            //m_cDevStatus = (DeviceStatus)StateObject.TRAN;  // 디바이스 관리 
            m_cHappyPoint = (IPaymentExpUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.POINTHAPPYPOINT);
            m_cSqlDbService = (IDatabaseSQL)sManager.InitServiceInstance(ServiceLists.AGENT_DATABASE.DLL, ServiceLists.AGENT_DATABASE.DATABASE_MSSQL); 
        }
        #endregion

        #region 결제 등록
        /// <summary>
        /// 결제 등록
        /// </summary>
        public string SetPayment(string[] aParam)
        {
            return "";
        }
        #endregion

        #region 결제 조회
        /// <summary>
        /// 결제 조회
        /// </summary>
        public string SearchPayment(string[] aParam, ref string[] aRet)
        {
            return "";
        }
        #endregion

        #region 결제 정보 획득
        /// <summary>
        /// 결제 정보 획득
        /// </summary>
        public object GetPayment(string[] aParam)
        {
            return "";
        }
        #endregion
 
        #region 결제 취소
        /// <summary>
        /// 결제 취소
        /// </summary>
        public string CancelPayment(string[] aParam)
        {
            string sRet = UserCom.RST_ERR;

            if (m_cTrnStatus.Head.TradeDiv != ItemConst.TRAN_DIV.NORMAL) return sRet;
            if (m_cPosStatus.Base.TrainingFlag == "1" || m_cPosStatus.Mst.TestStorYn == "1") return sRet;

            double sTarget_Amt = 0;
            string sInPutData = string.Empty;
            string sInPutType = string.Empty;
            string sTelecom = string.Empty;
            string sCard_No = string.Empty;
            string sHP_WccNo = string.Empty;
            string sHP_CustNo = string.Empty;
            string sCard_type = string.Empty;
            string sYYYYMMDD = string.Empty;
            string sHHmmss = string.Empty;
            string sApprNo = string.Empty;

            try
            {
                int nPayRow = CmUtil.IntParse(aParam[0]); // 취소할 행번호

                // 결제 내역 받아 오기
                ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
                m_cPayItem = (Column.TR_PAYMENT.DATA)alPayItem[nPayRow];
               
                sInPutData = m_cPayItem.OCCUR_ENTRY_19; // 입력 데이터 
                sInPutType = m_cPayItem.OCCUR_ENTRY_05; // 입력구분
                sTelecom = ""; //통신사구분
                sCard_No = m_cPayItem.OCCUR_ENTRY_01;  //카드번호
                sHP_WccNo = m_cPayItem.OCCUR_ENTRY_01; //HPC - 웰컴카드번호
                sTarget_Amt = m_cPayItem.AMT_ENTRY_10; //대상금액
                sHP_CustNo = m_cPayItem.OCCUR_ENTRY_22; //HPC - 회원번호
                sCard_type = m_cPayItem.OCCUR_ENTRY_23; //실물카드 또는 해피앱 구분
                sYYYYMMDD = m_cPayItem.OCCUR_ENTRY_03; //거래일자(YYYYMMDD) 
                sHHmmss = m_cPayItem.OCCUR_ENTRY_04; //거래시간(HHMMSS)
                sApprNo = m_cPayItem.OCCUR_ENTRY_02; //승인번호	

                // 전문통신!!!
                string[] saRecvdData = null;
                sRet = WelcomeCard_SendDataMake(PosConst.CANCEL_DIV.NORMAL,
                                                new string[] {PosConst.WELCOMECARD_TYPE.DC_CANCEL,      //웰컴타입                            
                                                              sInPutData,                               //카드번호
                                                              sInPutType,                               //입력구분
                                                              sHP_CustNo,                               //HPC - 회원번호
                                                              sHP_WccNo,                                //HPC - 웰컴카드번호
                                                              sCard_type,                               //웰컴카드 C:실물카드, A:해피App
                                                              sTelecom,                                 //통신사구분
                                                              sTarget_Amt.ToString(),                   //할인대상금액
                                                              sYYYYMMDD,                                //거래일자(YYYYMMDD) 
                                                              sHHmmss,                                  //거래시간(HHMMSS)
                                                              sApprNo},                                 //승인번호	
                                                ref saRecvdData);

                if (sRet != UserCom.RST_OK) return sRet;

                if (m_cPayItem.PAY_DTL_CD_05 == PosConst.PAY_DC_TYPE.DC)
                {
                    ClearPluDiscountAmount(m_cPayItem.PAY_WAY_CD + m_cPayItem.PAY_DTL_CD_01, "");        // 할인금액 삭제
                }

                m_cPayItem.CANCEL_DIV = PosConst.CANCEL_DIV.CANCEL;
                m_cDataService.UpdatePluAmount(); // 상품 합계금액 계산(거래해더)
                m_cDataService.UpdatePayAmount(); // 결제 금액 재 계산 처리

                // 여전법 대응 ///////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref m_cPayItem.CanFiller1);
                //////////////////////////////////////////////////////////////////////////////////

                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;
            }

            return sRet;
        }
        #endregion

        #region 결제 반품(자동반품)
        /// <summary>
        /// 결제 반품(자동반품)
        /// </summary>
        public string RefundPayment(string[] aParam)
        {
            string sRet = UserCom.RST_ERR;

            double sTarget_Amt = 0;
            string sInPutData = string.Empty;
            string sInPutType = string.Empty;
            string sTelecom = string.Empty;
            string sCard_No = string.Empty;
            string sHP_WccNo = string.Empty;
            string sHP_CustNo = string.Empty;
            string sCard_type = string.Empty;
            string sYYYYMMDD = string.Empty;
            string sHHmmss = string.Empty;
            string sApprNo = string.Empty;

            try
            {
                if (m_cTrnStatus.Head.TradeDiv != ItemConst.TRAN_DIV.REFUND) return sRet;

                int nPayRow = CmUtil.IntParse(aParam[0]); // 취소할 행번호

                // 결제 내역 받아 오기
                ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
                m_cPayItem = (Column.TR_PAYMENT.DATA)alPayItem[nPayRow];

                sInPutData = m_cPayItem.OCCUR_ENTRY_19;
                sInPutType = m_cPayItem.OCCUR_ENTRY_05;     // 입력구분
                sTelecom = "";  //통신사구분
                sCard_No = m_cPayItem.OCCUR_ENTRY_01;  //카드번호
                sHP_WccNo = m_cPayItem.OCCUR_ENTRY_01; //HPC - 웰컴카드번호
                sTarget_Amt = m_cPayItem.AMT_ENTRY_10; //대상금액
                sHP_CustNo = m_cPayItem.OCCUR_ENTRY_22; //HPC - 회원번호
                sCard_type = m_cPayItem.OCCUR_ENTRY_23; //실물카드 또는 해피앱 구분
                sYYYYMMDD = m_cPayItem.OCCUR_ENTRY_03; //거래일자(YYYYMMDD) 
                sHHmmss = m_cPayItem.OCCUR_ENTRY_04; //거래시간(HHMMSS)
                sApprNo = m_cPayItem.OCCUR_ENTRY_02; //승인번호	

                // 전문통신!!!
                string[] saRecvdData = null;
                sRet = WelcomeCard_SendDataMake(PosConst.CANCEL_DIV.CANCEL,
                                                new string[] {PosConst.WELCOMECARD_TYPE.DC_CANCEL,      //웰컴타입                            
                                                              sInPutData,                               //카드번호
                                                              sInPutType,                               //입력구분
                                                              sHP_CustNo,                               //HPC - 회원번호
                                                              sHP_WccNo,                                //HPC - 웰컴카드번호
                                                              sCard_type,                               //웰컴카드 C:실물카드, A:해피App
                                                              sTelecom,                                 //통신사구분
                                                              sTarget_Amt.ToString(),                   //할인대상금액
                                                              sYYYYMMDD,                                //거래일자(YYYYMMDD) 
                                                              sHHmmss,                                  //거래시간(HHMMSS)
                                                              sApprNo},                                 //승인번호	
                                                ref saRecvdData);


                if (sRet != UserCom.RST_OK) return sRet;

                //if (m_cPayItem.PAY_DTL_CD_05 == PosConst.PAY_DC_TYPE.DC)
                //{
                //    ClearPluDiscountAmount(m_cPayItem.PAY_WAY_CD + m_cPayItem.PAY_DTL_CD_01, "");        // 할인금액 삭제
                //}

                //m_cPayItem.CANCEL_DIV = PosConst.CANCEL_DIV.CANCEL;

                //m_cDataService.UpdatePluAmount(); // 상품 합계금액 계산(거래해더)
                //m_cDataService.UpdatePayAmount(); // 결제 금액 재 계산 처리

                // 여전법 대응 ///////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref m_cPayItem.CanFiller1);
                //////////////////////////////////////////////////////////////////////////////////

                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;
            }

            return sRet;
        }
        #endregion

        #region 웰컴카드 할인등록

        /// <summary>
        /// 웰컴카드 할인등록
        /// </summary>
        public string SetWccDCPayment(string[] sParam, ref string[] sRevParam)
        {
            string sRet = UserCom.RST_ERR;

            if (m_cTrnStatus.Head.TradeDiv != ItemConst.TRAN_DIV.NORMAL) return sRet;
            if (m_cPosStatus.Base.TrainingFlag == "1" || m_cPosStatus.Mst.TestStorYn == "1") return sRet;
            
            //적용 시 주석해제
            //string sVanCD = "";
            //sVanCD = GetPayDtlCdToVanCode(ItemConst.TR_ITEM_ID.MOBILE_COM_POINT, ItemConst.TR_ITEM_ID.MOBILE_COM.WELCOMECARD);
            //if (sVanCD == "")
            //{
            //    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0563);
            //    return UserCom.RST_ERR;
            //}

            string sWccType = sParam.Length >= 1 ? sParam[0] : ""; //웰컴타입
            string sInputCardNo = sParam.Length >= 2 ? sParam[1] : ""; //카드번호
            string sInputType = sParam.Length >= 3 ? sParam[2] : ""; //카드입력구분
            string sInputHPCustNo = sParam.Length >= 4 ? sParam[3] : ""; //HPC - 회원번호
            string sInputHPWccNo = sParam.Length >= 5 ? sParam[4] : ""; //HPC - 웰컴카드번호
            string sInputCardtype = sParam.Length >= 6 ? sParam[5] : ""; //웰컴카드 C:실물카드, A:해피App
            string sInputTelecom = sParam.Length >= 7 ? sParam[6] : ""; //통신사구분
            string sTargetAmt = sParam.Length >= 8 ? sParam[7] : "";  // 할인대상금액
            string sYYYYMMDD = sParam.Length >= 9 ? sParam[8] : ""; //거래일자(YYYYMMDD) 
            string sHHmmss = sParam.Length >= 10 ? sParam[9] : ""; //거래시간(HHMMSS)
            string sApprNo = sParam.Length >= 11 ? sParam[10] : ""; //승인번호
             
            try
            {
                UserLog.WriteLogFile(UserCom.LOG_IOS,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                     "[WelcomeCard_SendDataMake] " +
                                     " sInputCardNo  :" + sInputCardNo + "," +
                                     " sInputType :" + sInputType + "," +
                                     " sInputHPCustNo :" + sInputHPCustNo + "," +
                                     " sInputHPWccNo :" + sInputHPWccNo + "," +
                                     " sInputCardtype :" + sInputCardtype + "," +
                                     " sInputTelecom :" + sInputTelecom + "," +
                                     " sTargetAmt :" + sTargetAmt + "," +
                                     " sYYYYMMDD :" + sYYYYMMDD + "," +
                                     " sHHmmss :" + sHHmmss + "," +
                                     " sApprNo :" + sApprNo
                                     );


                m_cPayItem = new Column.TR_PAYMENT.DATA(); // 결과 저장 변수 생성
                m_cPayItem.PAY_WAY_CD = GetMenuKeyToPayWayCd(PosKey.MENU_KEY.WELCOMECARD_DC);
                m_cPayItem.PAY_DTL_CD_01 = GetMenuKeyToPayDtlCd(PosKey.MENU_KEY.WELCOMECARD_DC);

                // 전문통신!!! 
                sRet = WelcomeCard_SendDataMake(PosConst.CANCEL_DIV.NORMAL,
                                                new string[] { sWccType, 
                                                               sInputCardNo, 
                                                               sInputType, 
                                                               sInputHPCustNo, 
                                                               sInputHPWccNo, 
                                                               sInputCardtype, 
                                                               "", 
                                                               sTargetAmt, 
                                                               sYYYYMMDD, 
                                                               sHHmmss, 
                                                               sApprNo },
                                                ref sRevParam);

                if (sRet != UserCom.RST_OK) { return sRet; }

                // 결제 아이템 추가
                ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);     // 결제 내역 받아 오기
                m_cPayItem.SEQ = alPayItem.Count + 1;
                alPayItem.Add(m_cPayItem);

                if (m_cPayItem.PAY_DTL_CD_05 == PosConst.PAY_DC_TYPE.DC)
                {
                    // 상품아이템에 할인금액 설정
                    SetPluDiscountAmount(-1, m_cPayItem.PAY_WAY_CD + m_cPayItem.PAY_DTL_CD_01, "", m_cPayItem.PAY_AMT);
                }

                m_cPayItem.CANCEL_DIV = PosConst.CANCEL_DIV.NORMAL;

                m_cDataService.UpdatePluAmount(); // 상품 합계금액 계산(거래해더)
                m_cDataService.UpdatePayAmount(); // 결제 금액 재 계산 처리 
            }
            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 UserCom.RST_ERR;
            }

            return sRet;
        }
        #endregion

        #region 결제 수기 등록(임의등록)
        /// <summary>
        /// 결제 수기 등록(임의등록)
        /// </summary>
        public string SetMenualPayment(string[] aParam)
        {
            return "";
        }
        #endregion
         
        #region 해피앱 고객등록 대상자인지 체크
        public bool ClientRegisterCheck(string sType, string[] aParam, ref string sHP_CustNumer, ref string sHP_WelcomeCard)
        {
            // 해피포인트 고객유무
            bool bRet = false; 

            try
            {
                string HP_CustNumer = "";
                string HP_WelcomeCard = "";
                string[] saRecvdData = null;

                // 해피포인트 조회 건 체크.
                if (sType == PosConst.WELCOMECARD_MSG.HP_SEARCH_DATA)
                {
                    Column.TR_ETC.DATA cEtcItem = null;
                    cEtcItem = new Column.TR_ETC.DATA();
                    cEtcItem = (Column.TR_ETC.DATA)m_cHappyPoint.GetPayment(new string[] { });

                    if (cEtcItem == null) return false;          
                   
                    if (cEtcItem.CANCEL_DIV == ItemConst.PAY_CANCEL_DIV.CANCEL) return false;
                    if (cEtcItem.ETC_WAY_CD != ItemConst.TR_ITEM_ID.ETC_INFO_ITEM || cEtcItem.ETC_DTL_CD_01 != ItemConst.TR_ITEM_ID.ETC_INFO.SAVEPOINT) return false;
                    //if (cEtcItem.OCCUR_ENTRY_12 != "Y") return false; //해피앱여부 20180628 체크안하도록수정
                    if (cEtcItem.OCCUR_ENTRY_10 == "") return false; //HCP회원번호

                    // HCP고객번호
                    HP_CustNumer = CmUtil.MidH(cEtcItem.OCCUR_ENTRY_10, 0, 10).Trim();


                    //// 웰컴카드번호
                    //int nNowPos = 0;
                    //string[] aIrtRsp = new string[Column.POINT_ADD_INFO_SEARCH.LEN.Length];
                    //ItemColumn.ParseMessage(Column.POINT_ADD_INFO_SEARCH.LEN, Column.POINT_ADD_INFO_SEARCH.TYPE, Encoding.Default.GetBytes(cEtcItem.HP_ADD_INFO_SCH), ref nNowPos, ref aIrtRsp);
                    //HP_WelcomeCard = aIrtRsp[Column.POINT_ADD_INFO_SEARCH.SEQ.pointRESERVED]; //HPC -WELCOME CARD 추후 적립받으면 적용할 것 
                    //if (HP_WelcomeCard != "") { HP_WelcomeCard = CmUtil.MidH(HP_WelcomeCard, 0, 50).Trim(); }

                    // 웰컴카드번호
                    HP_WelcomeCard = cEtcItem.OCCUR_ENTRY_19;


                    bRet = true;
                }
                // 해피포인트 등록 건 있는지 체크.
                else if (sType == PosConst.WELCOMECARD_MSG.HP_REGISTER_DATA)
                {
                    ArrayList alEtcItem = (ArrayList)StateObject.GetItemObject(Column.TR_ETC.ITEM);
                    foreach (Column.TR_ETC.DATA cEtcItem in alEtcItem)
                    {
                        if (cEtcItem.CANCEL_DIV == ItemConst.PAY_CANCEL_DIV.CANCEL) continue;
                        if (cEtcItem.ETC_WAY_CD != ItemConst.TR_ITEM_ID.ETC_INFO_ITEM || cEtcItem.ETC_DTL_CD_01 != ItemConst.TR_ITEM_ID.ETC_INFO.SAVEPOINT) continue;
                        //if (cEtcItem.OCCUR_ENTRY_12 != "Y") continue; //해피앱여부 20180628 체크안하도록수정
                        if (cEtcItem.OCCUR_ENTRY_10 == "") continue; //HCP회원번호

                        // HCP고객번호
                        HP_CustNumer = CmUtil.MidH(cEtcItem.OCCUR_ENTRY_10, 0, 10).Trim();


                        //// 웰컴카드번호
                        //int nNowPos = 0;
                        //string[] aIrtRsp = new string[Column.POINT_ADD_INFO_SEARCH.LEN.Length];
                        //ItemColumn.ParseMessage(Column.POINT_ADD_INFO_SEARCH.LEN, Column.POINT_ADD_INFO_SEARCH.TYPE, Encoding.Default.GetBytes(cEtcItem.HP_ADD_INFO_SCH), ref nNowPos, ref aIrtRsp);
                        //HP_WelcomeCard = aIrtRsp[Column.POINT_ADD_INFO_SEARCH.SEQ.pointRESERVED]; //HPC -WELCOME CARD 추후 적립받으면 적용할 것 
                        //if (HP_WelcomeCard != "") { HP_WelcomeCard = CmUtil.MidH(HP_WelcomeCard, 0, 50).Trim(); }

                        // 웰컴카드번호
                        HP_WelcomeCard = cEtcItem.OCCUR_ENTRY_19;


                        bRet = true;
                        break;
                    }
                }
                // 현재 해피포인트 조회 건 있는지 체크.
                else if (sType == PosConst.WELCOMECARD_MSG.HP_SEARCH)
                {
                    // 해피포인트 자동 조회 
                    if (aParam == null) return false;
                    if (aParam.Length <= 0) return false;

                    string sPutType = aParam.Length >= 1 ? aParam[0] : "";
                    string sMaskData = aParam.Length >= 2 ? aParam[1] : "";
                    string sEncData = aParam.Length >= 3 ? aParam[2] : "";
                    string sMsgYN = aParam.Length >= 4 ? aParam[3] : "";
                    string sServiceCode = aParam.Length >= 5 ? aParam[4] : "";
                    string sInPutData = aParam.Length >= 6 ? aParam[5] : "";

                    //-------------------------------------------------------------------------------------------------------------------------
                    // 해피포인트 조회전문 날림
                    //-------------------------------------------------------------------------------------------------------------------------
                    string sRet = "";
                    sRet = m_cHappyPoint.SearchPayment(new string[] { sPutType, sMaskData, sEncData, sMsgYN, "", sInPutData }, ref saRecvdData);
                    if (sRet != UserCom.RST_OK) return false;

                    //-------------------------------------------------------------------------------------------------------------------------
                    // 조회 데이터 획득
                    //-------------------------------------------------------------------------------------------------------------------------
                    Column.TR_ETC.DATA cEtcItem = null;
                    cEtcItem = new Column.TR_ETC.DATA();
                    cEtcItem = (Column.TR_ETC.DATA)m_cHappyPoint.GetPayment(new string[] { });                   

                    if (cEtcItem == null) return false;
                    if (cEtcItem.CANCEL_DIV == ItemConst.PAY_CANCEL_DIV.CANCEL) return false;
                    if (cEtcItem.ETC_WAY_CD != ItemConst.TR_ITEM_ID.ETC_INFO_ITEM || cEtcItem.ETC_DTL_CD_01 != ItemConst.TR_ITEM_ID.ETC_INFO.SAVEPOINT) return false;
                    //if (cEtcItem.OCCUR_ENTRY_12 != "Y") return false; //해피앱여부
                    //if (cEtcItem.OCCUR_ENTRY_10 == "") return false; //HCP회원번호

                    // HCP고객번호
                    HP_CustNumer = CmUtil.MidH(cEtcItem.OCCUR_ENTRY_10, 0, 10).Trim();

                    //// 웰컴카드번호
                    //int nNowPos = 0;
                    //string[] aIrtRsp = new string[Column.POINT_ADD_INFO_SEARCH.LEN.Length];
                    //ItemColumn.ParseMessage(Column.POINT_ADD_INFO_SEARCH.LEN, Column.POINT_ADD_INFO_SEARCH.TYPE, Encoding.Default.GetBytes(cEtcItem.HP_ADD_INFO_SCH), ref nNowPos, ref aIrtRsp);
                    //HP_WelcomeCard = aIrtRsp[Column.POINT_ADD_INFO_SEARCH.SEQ.pointRESERVED]; //HPC -WELCOME CARD 추후 적립받으면 적용할 것 
                    //if (HP_WelcomeCard != "") { HP_WelcomeCard = CmUtil.MidH(HP_WelcomeCard, 0, 50).Trim(); }

                    // 웰컴카드번호
                    HP_WelcomeCard = cEtcItem.OCCUR_ENTRY_19;


                    bRet = true;
                }

                sHP_CustNumer = HP_CustNumer; //HPC 조회응답 - 회원번호
                sHP_WelcomeCard = HP_WelcomeCard; //HPC 조회응답 - 컴카드번호
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                            System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + 
                                            System.Reflection.MethodBase.GetCurrentMethod().Name + "()", 
                                            ex.Message);

                bRet = false;
            }

            return bRet;
        }
        #endregion

        #region 웰컴카드 빈체크
        public string WelcomeCard_PrefixCheck(string pCardNo)
        {
            string sRet = "";
            string sQuery = "";
            string sCardNo = "";
            string sCardKind = "";

            try
            {
                //#17515 PB 중산마을 - 유플러스 결합카드 통신사 자동선택안되는 현상 start
                if (PosMstManager.GetPosOption(POS_OPTION.OPT516) != "1") return sRet;
                //#17515 PB 중산마을 - 유플러스 결합카드 통신사 자동선택안되는 현상 end
                

                sCardNo = pCardNo;
                if (sCardNo == "") return sRet;

                sQuery = " SELECT * ";
                sQuery += "   FROM POSMST.dbo.MST_CARD_PREFIX WITH(NOLOCK) ";
                sQuery += "  WHERE CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                sQuery += "    AND '" + sCardNo.Substring(0, 6) + "' LIKE REPLACE(PRFX_CD, 'X', '') + '%'";
                sQuery += "    AND USE_YN = '" + PosConst.MST_USE_YN.YES + "'";

                IMasterUs cMstService = (IMasterUs)sManager.InitServiceInstance(ServiceLists.ASV_MASTER.DLL, ServiceLists.ASV_MASTER.POS_MASTER);
                DataTable dtCardInfo = cMstService.Select(new string[] { sQuery });

                if (dtCardInfo != null && dtCardInfo.Rows.Count > 0)
                {
                    foreach (DataRow dr in dtCardInfo.Rows)
                    {
                        if (CmUtil.GetDataRowStr(dr, PosMst.MST_CARD_PREFIX.DATA.CARD_DIV) == "C") continue;
                        sCardKind = CmUtil.GetDataRowStr(dr, PosMst.MST_CARD_PREFIX.DATA.CARD_DIV);
                        break;
                    }
                }
                
                if (sCardKind == "H") sCardKind = "A";
                if (sCardKind == "W") sCardKind = "C";
                
                sRet = sCardKind;

                return sRet;
            }
            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;
            }
        }
        #endregion

        #region 웰컴카드 전문조립

        public string WelcomeCard_SendDataMake(string sTradeDiv, string[] sParam, ref string[] sRevParam)
        {
            string sRet = UserCom.RST_ERR;

            string sWccType = sParam.Length >= 1 ? sParam[0] : ""; //웰컴타입
            string sInputCardNo = sParam.Length >= 2 ? sParam[1] : ""; //카드번호
            string sInputType = sParam.Length >= 3 ? sParam[2] : ""; //카드입력구분
            string sInputHPCustNo = sParam.Length >= 4 ? sParam[3] : ""; //HPC - 회원번호
            string sInputHPWccNo = sParam.Length >= 5 ? sParam[4] : ""; //HPC - 웰컴카드번호
            string sInputCardtype = sParam.Length >= 6 ? sParam[5] : ""; //웰컴카드 C:실물카드, A:해피App
            string sInputTelecom = sParam.Length >= 7 ? sParam[6] : ""; //통신사구분
            string sTargetAmt = sParam.Length >= 8 ? sParam[7] : "";  // 할인대상금액
            string sYYYYMMDD = sParam.Length >= 9 ? sParam[8] : ""; //거래일자(YYYYMMDD) 
            string sHHmmss = sParam.Length >= 10 ? sParam[9] : ""; //거래시간(HHMMSS)
            string sApprNo = sParam.Length >= 11 ? sParam[10] : ""; //승인번호
            string sReadingHPData = sParam.Length >= 12 ? sParam[11] : ""; //

            string[] saSendData = null;//보내는
            string[] saRecvdData = null;//받은

            try
            {
                UserLog.WriteLogFile(UserCom.LOG_IOS,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                     "[WelcomeCard_SendDataMake] " + 
                                     " sTradeDiv :" + sTradeDiv + "," +
                                     " sWccType  :" + sWccType + "," +
                                     " sInputHPCustNo :" + sInputHPCustNo + "," +
                                     " sInputHPWccNo :" + sInputHPWccNo + "," +
                                     " sInputCardtype :" + sInputCardtype + "," +
                                     " sInputTelecom :" + sInputTelecom + "," +
                                     " sTargetAmt :" + sTargetAmt + "," +
                                     " sYYYYMMDD :" + sYYYYMMDD + "," +
                                     " sHHmmss :" + sHHmmss + "," +
                                     " sApprNo :" + sApprNo + "," +
                                     " sReadingHPData :" + sReadingHPData 
                                     );

                if (sWccType == PosConst.WELCOMECARD_TYPE.ISSUE_SEARCH || sWccType == PosConst.WELCOMECARD_TYPE.POS_CLIENT_REGISTER || sWccType == PosConst.WELCOMECARD_TYPE.POS_CLIENT_REGISTER_CANCEL)
                {
                    #region 웰컴카드 조회/ 웰컴고객등록

                    if (sWccType == PosConst.WELCOMECARD_TYPE.ISSUE_SEARCH)
                    {
                        saRecvdData = new string[Column.WELCOMECARD_SEARCH_RECV.LEN.Length];
                        saSendData = new string[Column.WELCOMECARD_SEARCH.LEN.Length];
                        for (int i = 0; i < saRecvdData.Length; i++) { saRecvdData[i] = ""; }
                        for (int i = 0; i < saSendData.Length; i++) { saSendData[i] = ""; }
                        saSendData[0] = "0"; //전체 전문길이
                        saSendData[1] = "MC"; //구분
                        saSendData[2] = "0100"; //전문유형
                        saSendData[3] = "10"; //업무구분
                        saSendData[4] = "V100"; //전문버전
                    }
                    else if (sWccType == PosConst.WELCOMECARD_TYPE.POS_CLIENT_REGISTER)
                    {
                        saRecvdData = new string[Column.WELCOMECARD_SERVER_REGISTER_RECV.LEN.Length];
                        saSendData = new string[Column.WELCOMECARD_SERVER_REGISTER.LEN.Length];
                        for (int i = 0; i < saRecvdData.Length; i++) { saRecvdData[i] = ""; }
                        for (int i = 0; i < saSendData.Length; i++) { saSendData[i] = ""; }
                        saSendData[0] = "0"; //전체 전문길이
                        saSendData[1] = "MC"; //구분
                        saSendData[2] = "2300"; //전문유형
                        saSendData[3] = "40"; //업무구분
                        saSendData[4] = "V100"; //전문버전
                    }
                    else if (sWccType == PosConst.WELCOMECARD_TYPE.POS_CLIENT_REGISTER_CANCEL)
                    {
                        saRecvdData = new string[Column.WELCOMECARD_SERVER_REGISTER_RECV.LEN.Length];
                        saSendData = new string[Column.WELCOMECARD_SERVER_REGISTER.LEN.Length];
                        for (int i = 0; i < saRecvdData.Length; i++) { saRecvdData[i] = ""; }
                        for (int i = 0; i < saSendData.Length; i++) { saSendData[i] = ""; }
                        saSendData[0] = "0"; //전체 전문길이
                        saSendData[1] = "MC"; //구분
                        saSendData[2] = "2400"; //전문유형
                        saSendData[3] = "40"; //업무구분
                        saSendData[4] = "V100"; //전문버전
                    }

                    saSendData[5] = sYYYYMMDD; //거래일자
                    saSendData[6] = sHHmmss; //거래시간
                    saSendData[7] = sApprNo; //승인번호 
                    saSendData[8] = ""; //응답코드
                    saSendData[9] = sInputCardNo; //welcome카드번호
                    saSendData[10] = sInputHPCustNo; //HPC고객번호
                    saSendData[11] = m_cPosStatus.Base.SaleDate; //영업일자
                    saSendData[12] = m_cPosStatus.Base.StoreNo; //점포코드
                    saSendData[13] = m_cPosStatus.Base.PosNo; //POS번호
                    saSendData[14] = m_cPosStatus.Base.TradeNo; //BILL번호
                    saSendData[15] = ""; //Filler

                    #endregion

                    // 전문통신!!!
                    sRet = WelcomeCard_Approval(sTradeDiv, sWccType, sInputType, saSendData, ref saRecvdData);
                } 
                else if (sWccType == PosConst.WELCOMECARD_TYPE.ISSUE_REGISTER || sWccType == PosConst.WELCOMECARD_TYPE.ISSUE_CANCEL)
                {
                    #region 발급/ 발급취소

                    saRecvdData = new string[Column.WELCOMECARD_ISSUE_RECV.LEN.Length];
                    saSendData = new string[Column.WELCOMECARD_ISSUE.LEN.Length];
                    for (int i = 0; i < saRecvdData.Length; i++) { saRecvdData[i] = ""; }
                    for (int i = 0; i < saSendData.Length; i++) { saSendData[i] = ""; }

                    // 웰컴카드 발급
                    if (sWccType == PosConst.WELCOMECARD_TYPE.ISSUE_REGISTER)
                    {
                        saSendData[0] = "0";    //전체 전문길이
                        saSendData[1] = "MC";   //구분
                        saSendData[2] = "2100"; //전문유형
                        saSendData[3] = "50";   //업무구분
                        saSendData[4] = "V100"; //전문버전 
                    }
                    // 웰컴카드 발급취소 
                    else if (sWccType == PosConst.WELCOMECARD_TYPE.ISSUE_CANCEL)
                    {
                        saSendData[0] = "0";    //전체 전문길이
                        saSendData[1] = "MC";   //구분
                        saSendData[2] = "2200"; //전문유형
                        saSendData[3] = "50";   //업무구분
                        saSendData[4] = "V100"; //전문버전 
                    }

                    saSendData[5] = sYYYYMMDD; //거래일자
                    saSendData[6] = sHHmmss; //거래시간
                    saSendData[7] = sApprNo; //승인번호
                    saSendData[8] = ""; //응답코드
                    saSendData[9] = sInputCardNo; //카드번호
                    saSendData[10] = sInputHPCustNo; //HPC고객번호
                    saSendData[11] = m_cPosStatus.Base.SaleDate; //영업일자
                    saSendData[12] = m_cPosStatus.Base.StoreNo; //점포코드
                    saSendData[13] = m_cPosStatus.Base.PosNo; //POS번호
                    saSendData[14] = m_cPosStatus.Base.TradeNo; //BILL번호
                    saSendData[15] = sInputTelecom; //통신사 구분
                    saSendData[16] = ""; //Filler

                    #endregion

                    // 전문통신!!!
                    sRet = WelcomeCard_Approval(sTradeDiv, sWccType, sInputType, saSendData, ref saRecvdData);
                }
                else if (sWccType == PosConst.WELCOMECARD_TYPE.DC_AGREE || 
                         sWccType == PosConst.WELCOMECARD_TYPE.DC_CANCEL ||
                         sWccType == PosConst.WELCOMECARD_TYPE.DC_NETAGREE || 
                         sWccType == PosConst.WELCOMECARD_TYPE.DC_NETCANCEL)
                { 
                    #region 할인관련

                    saRecvdData = new string[Column.WELCOMECARD_DC_RECV.LEN.Length];
                    saSendData = new string[Column.WELCOMECARD_DC.LEN.Length];
                    for (int i = 0; i < saRecvdData.Length; i++) { saRecvdData[i] = ""; }
                    for (int i = 0; i < saSendData.Length; i++) { saSendData[i] = ""; }

                    //할인
                    if (sWccType == PosConst.WELCOMECARD_TYPE.DC_AGREE)
                    {
                        saSendData[0] = "0"; //전체 전문길이
                        saSendData[1] = "MC"; //구분
                        saSendData[2] = "0200"; //전문유형
                        saSendData[3] = "20"; //업무구분
                        saSendData[4] = "V100"; //전문버전  
                    }
                    //할인취소
                    else if (sWccType == PosConst.WELCOMECARD_TYPE.DC_CANCEL)
                    {
                        saSendData[0] = "0"; //전체 전문길이
                        saSendData[1] = "MC"; //구분
                        saSendData[2] = "0300"; //전문유형
                        saSendData[3] = "20"; //업무구분
                        saSendData[4] = "V100"; //전문버전
                    }
                    //망상할인취소
                    else if (sWccType == PosConst.WELCOMECARD_TYPE.DC_NETAGREE)
                    {
                        saSendData[0] = "0"; //전체 전문길이
                        saSendData[1] = "MC"; //구분
                        saSendData[2] = "0400"; //전문유형
                        saSendData[3] = "20"; //업무구분
                        saSendData[4] = "V100"; //전문버전
                    }
                    //망상할인
                    else if (sWccType == PosConst.WELCOMECARD_TYPE.DC_NETCANCEL)
                    {
                        saSendData[0] = "0"; //전체 전문길이
                        saSendData[1] = "MC"; //구분
                        saSendData[2] = "0500"; //전문유형
                        saSendData[3] = "20"; //업무구분
                        saSendData[4] = "V100"; //전문버전
                    }

                    saSendData[5] = sYYYYMMDD; //거래일자
                    saSendData[6] = sHHmmss; //거래시간
                    saSendData[7] = sApprNo; //승인번호
                    saSendData[8] = ""; //응답코드
                    saSendData[9] = sInputCardNo; //카드번호
                    saSendData[10] = sInputHPCustNo; //HPC고객번호
                    saSendData[11] = m_cPosStatus.Base.SaleDate; //영업일자
                    saSendData[12] = m_cPosStatus.Base.StoreNo; //점포코드
                    saSendData[13] = m_cPosStatus.Base.PosNo; //POS번호
                    saSendData[14] = m_cPosStatus.Base.TradeNo; //BILL번호
                    saSendData[15] = sInputCardtype; //입력구분 C:실물카드, A:해피App
                    saSendData[16] = sTargetAmt; //대상금액 
                    saSendData[17] = ""; //Filler

                    #endregion

                    // 전문통신!!!
                    sRet = WelcomeCard_Approval(sTradeDiv, sWccType, sInputType, saSendData, ref saRecvdData);
                }
                else if (sWccType == PosConst.WELCOMECARD_TYPE.HPC_CLIENT_REGISTER)
                {
                    #region HPC고객등록
                    string sReqDivCd = string.Empty;
                    if (sTradeDiv == PosConst.CANCEL_DIV.NORMAL)
                    {
                        sReqDivCd = "40";//등록
                    }
                    else
                    {
                        sReqDivCd = "41";//해지
                    }

                    //sRet = HPAppClientRegister(new string[] { sWccType, sInputType, sReqDivCd, sInputCardNo, sTradeDiv, sReadingHPData });
                    sRet = HPAppClientRegister(new string[] { sTradeDiv, sWccType, sInputCardNo, sInputType, sReqDivCd, sInputHPWccNo, sReadingHPData });
                    #endregion
                }

                sRevParam = saRecvdData;

                //#20180605 응답값이 비어있을 경우 에러로 판단. start
                if (sWccType != PosConst.WELCOMECARD_TYPE.HPC_CLIENT_REGISTER && saRecvdData == null)
                {
                    sRet = UserCom.RST_ERR;

                    UserLog.WriteLogFile(UserCom.LOG_IOS,
                                         System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                         System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                         System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                         "[WelcomeCard_SendDataMake] saRecvdData is null");
                }
                //#20180605 응답값이 비어있을 경우 에러로 판단. end

                UserLog.WriteLogFile(UserCom.LOG_IOS,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                     "[WelcomeCard_SendDataMake] sRet :" + sRet.ToString());
            }
            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 UserCom.RST_ERR;
            }

            return sRet;
        }
        #endregion

        #region 웰컴카드 바디생성
        /// <summary>
        /// 월컴카드 발급-조회
        /// </summary>
        private string MakeBodyData(string aType, string[] aParam)
        {
            string sSendData = string.Empty;

            try
            {
                int iLen = 0;
                string sBody = string.Empty;
                string sBodyLen = string.Empty;
                string sBodyData = string.Empty;

                string[] aIrtBody = null;

                if (aType == PosConst.WELCOMECARD_TYPE.ISSUE_SEARCH)
                {
                    #region 발급조회

                    aIrtBody = new string[Column.WELCOMECARD_SEARCH.LEN.Length];

                    aIrtBody[Column.WELCOMECARD_SEARCH.SEQ.sLen] = aParam[0]; //전체 전문길이
                    aIrtBody[Column.WELCOMECARD_SEARCH.SEQ.sMsgDiv] = aParam[1]; //구분
                    aIrtBody[Column.WELCOMECARD_SEARCH.SEQ.sMsgType] = aParam[2]; //전문유형
                    aIrtBody[Column.WELCOMECARD_SEARCH.SEQ.sMsgGubun] = aParam[3]; //업무구분
                    aIrtBody[Column.WELCOMECARD_SEARCH.SEQ.sMsgVersion] = aParam[4]; //전문버전
                    aIrtBody[Column.WELCOMECARD_SEARCH.SEQ.sYYYYMMDD] = aParam[5]; //거래일자
                    aIrtBody[Column.WELCOMECARD_SEARCH.SEQ.shhmmss] = aParam[6]; //거래시간
                    aIrtBody[Column.WELCOMECARD_SEARCH.SEQ.sApprNo] = aParam[7]; //승인번호
                    aIrtBody[Column.WELCOMECARD_SEARCH.SEQ.sReqCode] = aParam[8]; //응답코드
                    aIrtBody[Column.WELCOMECARD_SEARCH.SEQ.sCardNo] = aParam[9]; //카드번호
                    aIrtBody[Column.WELCOMECARD_SEARCH.SEQ.sHPCustNo] = aParam[10];//HPC고객번호
                    aIrtBody[Column.WELCOMECARD_SEARCH.SEQ.sSaleDate] = aParam[11];//영업일자
                    aIrtBody[Column.WELCOMECARD_SEARCH.SEQ.sStoreCode] = aParam[12];//점포코드
                    aIrtBody[Column.WELCOMECARD_SEARCH.SEQ.sPosNo] = aParam[13];//POS번호
                    aIrtBody[Column.WELCOMECARD_SEARCH.SEQ.sBillNo] = aParam[14];//BILL번호
                    aIrtBody[Column.WELCOMECARD_SEARCH.SEQ.sFiller] = aParam[15];//Filler

                    sSendData = ItemColumn.MakeMessage(aIrtBody, Column.WELCOMECARD_SEARCH.LEN, Column.WELCOMECARD_SEARCH.TYPE);

                    if (sSendData != "")
                    {
                        sBody = sSendData.Substring(Column.WELCOMECARD_SEARCH.LEN[0], sSendData.Length - (Column.WELCOMECARD_SEARCH.LEN[0]));
                        iLen = sBody.Length + Column.WELCOMECARD_SEARCH.LEN[0];
                        sBodyData = iLen.ToString().PadLeft(Column.WELCOMECARD_SEARCH.LEN[0], '0') + sBody;
                        sSendData = sBodyData;
                    }
                    #endregion
                }
                else if (aType == PosConst.WELCOMECARD_TYPE.ISSUE_REGISTER || aType == PosConst.WELCOMECARD_TYPE.ISSUE_CANCEL)
                {
                    #region 발급등록, 발급취소

                    //#20180704 망상 전문 관련 수정 start
                    // 웰컴카드 발급
                    if (aType == PosConst.WELCOMECARD_TYPE.ISSUE_REGISTER)
                    {
                        aParam[0] = "0";    //전체 전문길이
                        aParam[1] = "MC";   //구분
                        aParam[2] = "2100"; //전문유형
                        aParam[3] = "50";   //업무구분
                        aParam[4] = "V100"; //전문버전 
                    }
                    // 웰컴카드 발급취소 
                    else if (aType == PosConst.WELCOMECARD_TYPE.ISSUE_CANCEL)
                    {
                        aParam[0] = "0";    //전체 전문길이
                        aParam[1] = "MC";   //구분
                        aParam[2] = "2200"; //전문유형
                        aParam[3] = "50";   //업무구분
                        aParam[4] = "V100"; //전문버전 
                    }
                    //#20180704 망상 전문 관련 수정 end



                    aIrtBody = new string[Column.WELCOMECARD_ISSUE.LEN.Length];
                    aIrtBody[Column.WELCOMECARD_ISSUE.SEQ.sLen] = aParam[0];//전체 전문길이   
                    aIrtBody[Column.WELCOMECARD_ISSUE.SEQ.sMsgDiv] = aParam[1];//구분 
                    aIrtBody[Column.WELCOMECARD_ISSUE.SEQ.sMsgType] = aParam[2];//전문유형 
                    aIrtBody[Column.WELCOMECARD_ISSUE.SEQ.sMsgGubun] = aParam[3];//업무구분 
                    aIrtBody[Column.WELCOMECARD_ISSUE.SEQ.sMsgVersion] = aParam[4];//전문버전 
                    aIrtBody[Column.WELCOMECARD_ISSUE.SEQ.sYYYYMMDD] = aParam[5];//거래일자 
                    aIrtBody[Column.WELCOMECARD_ISSUE.SEQ.shhmmss] = aParam[6];//거래시간 
                    aIrtBody[Column.WELCOMECARD_ISSUE.SEQ.sApprNo] = aParam[7];//승인번호 
                    aIrtBody[Column.WELCOMECARD_ISSUE.SEQ.sReqCode] = aParam[8];//응답코드 
                    aIrtBody[Column.WELCOMECARD_ISSUE.SEQ.sCardNo] = aParam[9];//카드번호 
                    aIrtBody[Column.WELCOMECARD_ISSUE.SEQ.sHPCCustNo] = aParam[10];//HPC고객번호 
                    aIrtBody[Column.WELCOMECARD_ISSUE.SEQ.sSaleDate] = aParam[11];//영업일자 
                    aIrtBody[Column.WELCOMECARD_ISSUE.SEQ.sStoreCode] = aParam[12];//점포코드 
                    aIrtBody[Column.WELCOMECARD_ISSUE.SEQ.sPosNo] = aParam[13];//POS번호 
                    aIrtBody[Column.WELCOMECARD_ISSUE.SEQ.sBillNo] = aParam[14];//BILL번호 
                    aIrtBody[Column.WELCOMECARD_ISSUE.SEQ.sTelType] = aParam[15];//통신사 구분 
                    aIrtBody[Column.WELCOMECARD_ISSUE.SEQ.sFiller] = aParam[16];//Filler 
                    sSendData = ItemColumn.MakeMessage(aIrtBody, Column.WELCOMECARD_ISSUE.LEN, Column.WELCOMECARD_ISSUE.TYPE);
                    if (sSendData != "")
                    {
                        sBody = sSendData.Substring(Column.WELCOMECARD_ISSUE.LEN[0], sSendData.Length - (Column.WELCOMECARD_ISSUE.LEN[0]));
                        iLen = sBody.Length + Column.WELCOMECARD_ISSUE.LEN[0];
                        sBodyData = iLen.ToString().PadLeft(Column.WELCOMECARD_ISSUE.LEN[0], '0') + sBody;
                        sSendData = sBodyData;
                    }
                    #endregion
                }
                else if (aType == PosConst.WELCOMECARD_TYPE.POS_CLIENT_REGISTER)
                {
                    #region POS고객등록
                    aIrtBody = new string[Column.WELCOMECARD_SERVER_REGISTER.LEN.Length];
                    aIrtBody[Column.WELCOMECARD_SERVER_REGISTER.SEQ.sLen] = aParam[0]; //전체 전문길이
                    aIrtBody[Column.WELCOMECARD_SERVER_REGISTER.SEQ.sMsgDiv] = aParam[1]; //구분
                    aIrtBody[Column.WELCOMECARD_SERVER_REGISTER.SEQ.sMsgType] = aParam[2]; //전문유형
                    aIrtBody[Column.WELCOMECARD_SERVER_REGISTER.SEQ.sMsgGubun] = aParam[3]; //업무구분
                    aIrtBody[Column.WELCOMECARD_SERVER_REGISTER.SEQ.sMsgVersion] = aParam[4]; //전문버전
                    aIrtBody[Column.WELCOMECARD_SERVER_REGISTER.SEQ.sYYYYMMDD] = aParam[5]; //거래일자
                    aIrtBody[Column.WELCOMECARD_SERVER_REGISTER.SEQ.shhmmss] = aParam[6]; //거래시간
                    aIrtBody[Column.WELCOMECARD_SERVER_REGISTER.SEQ.sApprNo] = aParam[7]; //승인번호
                    aIrtBody[Column.WELCOMECARD_SERVER_REGISTER.SEQ.sReqCode] = aParam[8]; //응답코드
                    aIrtBody[Column.WELCOMECARD_SERVER_REGISTER.SEQ.sCardNo] = aParam[9]; //카드번호
                    aIrtBody[Column.WELCOMECARD_SERVER_REGISTER.SEQ.sHPCCustNo] = aParam[10];//HPC고객번호
                    aIrtBody[Column.WELCOMECARD_SERVER_REGISTER.SEQ.sSaleDate] = aParam[11];//영업일자
                    aIrtBody[Column.WELCOMECARD_SERVER_REGISTER.SEQ.sStoreCode] = aParam[12];//점포코드
                    aIrtBody[Column.WELCOMECARD_SERVER_REGISTER.SEQ.sPosNo] = aParam[13];//POS번호
                    aIrtBody[Column.WELCOMECARD_SERVER_REGISTER.SEQ.sBillNo] = aParam[14];//BILL번호
                    aIrtBody[Column.WELCOMECARD_SERVER_REGISTER.SEQ.sFiller] = aParam[15];//Filler
                    sSendData = ItemColumn.MakeMessage(aIrtBody, Column.WELCOMECARD_SERVER_REGISTER.LEN, Column.WELCOMECARD_SERVER_REGISTER.TYPE);

                    if (sSendData != "")
                    {
                        sBody = sSendData.Substring(Column.WELCOMECARD_SERVER_REGISTER.LEN[0], sSendData.Length - (Column.WELCOMECARD_SERVER_REGISTER.LEN[0]));
                        iLen = sBody.Length + Column.WELCOMECARD_SERVER_REGISTER.LEN[0];
                        sBodyData = iLen.ToString().PadLeft(Column.WELCOMECARD_SERVER_REGISTER.LEN[0], '0') + sBody;
                        sSendData = sBodyData;
                    }
                    #endregion
                }
                else if (aType == PosConst.WELCOMECARD_TYPE.HPC_CLIENT_REGISTER)
                {
                    #region HPC고객등록

                    #endregion
                }
                else if (aType == PosConst.WELCOMECARD_TYPE.DC_AGREE || aType == PosConst.WELCOMECARD_TYPE.DC_CANCEL ||
                         aType == PosConst.WELCOMECARD_TYPE.DC_NETAGREE || aType == PosConst.WELCOMECARD_TYPE.DC_NETCANCEL)
                {
                    #region 웰컴카드 할인

                    //#20180704 망상 전문 관련 수정 start
                    //할인
                    if (aType == PosConst.WELCOMECARD_TYPE.DC_AGREE)
                    {
                        aParam[0] = "0"; //전체 전문길이
                        aParam[1] = "MC"; //구분
                        aParam[2] = "0200"; //전문유형
                        aParam[3] = "20"; //업무구분
                        aParam[4] = "V100"; //전문버전  
                    }
                    //할인취소
                    else if (aType == PosConst.WELCOMECARD_TYPE.DC_CANCEL)
                    {
                        aParam[0] = "0"; //전체 전문길이
                        aParam[1] = "MC"; //구분
                        aParam[2] = "0300"; //전문유형
                        aParam[3] = "20"; //업무구분
                        aParam[4] = "V100"; //전문버전
                    }
                    //망상할인취소
                    else if (aType == PosConst.WELCOMECARD_TYPE.DC_NETAGREE)
                    {
                        aParam[0] = "0"; //전체 전문길이
                        aParam[1] = "MC"; //구분
                        aParam[2] = "0400"; //전문유형
                        aParam[3] = "20"; //업무구분
                        aParam[4] = "V100"; //전문버전
                    }
                    //망상할인
                    else if (aType == PosConst.WELCOMECARD_TYPE.DC_NETCANCEL)
                    {
                        aParam[0] = "0"; //전체 전문길이
                        aParam[1] = "MC"; //구분
                        aParam[2] = "0500"; //전문유형
                        aParam[3] = "20"; //업무구분
                        aParam[4] = "V100"; //전문버전
                    }
                    //#20180704 망상 전문 관련 수정 end

                    aIrtBody = new string[Column.WELCOMECARD_DC.LEN.Length];
                    aIrtBody[Column.WELCOMECARD_DC.SEQ.sLen] = aParam[0]; //전체 전문길이
                    aIrtBody[Column.WELCOMECARD_DC.SEQ.sMsgDiv] = aParam[1]; //구분
                    aIrtBody[Column.WELCOMECARD_DC.SEQ.sMsgType] = aParam[2]; //전문유형
                    aIrtBody[Column.WELCOMECARD_DC.SEQ.sMsgGubun] = aParam[3]; //업무구분
                    aIrtBody[Column.WELCOMECARD_DC.SEQ.sMsgVersion] = aParam[4]; //전문버전
                    aIrtBody[Column.WELCOMECARD_DC.SEQ.sYYYYMMDD] = aParam[5]; //거래일자
                    aIrtBody[Column.WELCOMECARD_DC.SEQ.shhmmss] = aParam[6]; //거래시간
                    aIrtBody[Column.WELCOMECARD_DC.SEQ.sApprNo] = aParam[7]; //승인번호
                    aIrtBody[Column.WELCOMECARD_DC.SEQ.sReqCode] = aParam[8]; //응답코드
                    aIrtBody[Column.WELCOMECARD_DC.SEQ.sCardNo] = aParam[9]; //카드번호
                    aIrtBody[Column.WELCOMECARD_DC.SEQ.sHPCustNo] = aParam[10];//HPC고객번호
                    aIrtBody[Column.WELCOMECARD_DC.SEQ.sSaleDate] = aParam[11];//영업일자
                    aIrtBody[Column.WELCOMECARD_DC.SEQ.sStoreCode] = aParam[12];//점포코드
                    aIrtBody[Column.WELCOMECARD_DC.SEQ.sPosNo] = aParam[13];//POS번호
                    aIrtBody[Column.WELCOMECARD_DC.SEQ.sBillNo] = aParam[14];//BILL번호
                    aIrtBody[Column.WELCOMECARD_DC.SEQ.sCard_type] = aParam[15];//입력구분
                    aIrtBody[Column.WELCOMECARD_DC.SEQ.sTarget_Amt] = aParam[16];//대상금액
                    aIrtBody[Column.WELCOMECARD_DC.SEQ.sFiller] = aParam[17];//Filler
                    sSendData = ItemColumn.MakeMessage(aIrtBody, Column.WELCOMECARD_DC.LEN, Column.WELCOMECARD_DC.TYPE);

                    if (sSendData != "")
                    {
                        sBody = sSendData.Substring(Column.WELCOMECARD_DC.LEN[0], sSendData.Length - (Column.WELCOMECARD_DC.LEN[0]));
                        iLen = sBody.Length + Column.WELCOMECARD_DC.LEN[0];
                        sBodyData = iLen.ToString().PadLeft(Column.WELCOMECARD_DC.LEN[0], '0') + sBody;
                        sSendData = sBodyData;
                    }
                    #endregion
                }
            }
            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 sSendData;

        }
        #endregion

        #region 웰컴카드 전문승인
        public string WelcomeCard_Approval(string aTradeDiv, string aType, string aInputType, string[] aParam, ref string[] aRecvdData)
        {
            string sRet = UserCom.RST_ERR;
            string sSendData = string.Empty;
            string sRecvData = string.Empty;

            // 받는
            Hashtable htRecvData = null;
            htRecvData = new Hashtable();
            htRecvData.Clear();

            // 보내는
            Hashtable htReqData = null;
            htReqData = new Hashtable();
            htReqData.Clear();
             
            try
            {
                UserLog.WriteLogFile(UserCom.LOG_IOS,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                     "[WelcomeCard_Approval] Approval Start! (aTradeDiv:" + aTradeDiv + "," + " aType:" + aType + "," + " aInputType:" + aInputType + ")");

                sSendData = MakeBodyData(aType, aParam);

                htReqData.Add(Column.WELCOMECARD.INQ_TYPE, ItemConst.IRT_INQ_TYPE.WELCOME_INFO_INQ);
                htReqData.Add(Column.WELCOMECARD.DATA, sSendData);
                htReqData.Add(Column.WELCOMECARD.RES_CD, "");

                // 승인업체 코드 조회
                string sWccIP = "";
                string sWccPort = "";
                string sVanCD = "";
                sVanCD = PosMstManager.GetMstPayDc(ItemConst.TR_ITEM_ID.MOBILE_COM_POINT, ItemConst.TR_ITEM_ID.MOBILE_COM.WELCOMECARD, PosMst.MST_PAY_DC.DATA.APPR_VEND_CD);
                sWccIP = PosMstManager.GetMstVan(sVanCD, PosMst.MST_VAN.DATA.IP);                
                sWccPort = PosMstManager.GetMstVan(sVanCD, PosMst.MST_VAN.DATA.PORT);
                //if (sWccIP == "") { sWccIP = "10.0.40.134";}
                //if (sWccPort == "") { sWccPort = "9029"; }


                // 요청 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문, [12]입력구분, [13]추후적립여부, [14]적립구분, [15] skt할인상품코드)
                m_cDataCommon.SetSaleApprLog(aTradeDiv, new string[] { ItemConst.TR_ITEM_ID.MOBILE_COM_POINT, ItemConst.TR_ITEM_ID.MOBILE_COM.WELCOMECARD, CmUtil.MidH(aType, 2,4), "S", aParam[9], htReqData[Column.WELCOMECARD.RES_CD].ToString(), "", "", "", "", "", sSendData, "", "", "", "", "" });

                UserLog.WriteLogFile(UserCom.LOG_SOCK,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                     "WelcomeCard_Approval()",
                                     "[SEND :" + sWccIP + ":" + sWccPort + "] " + sSendData);

                // 전문전송 
                //sRet = m_cDataCommon.ExecutePosIrt(ItemConst.COMM_MSG_TYPE.WELCOME_INFO, m_cPosStatus.Base.CommSvrIp, (int)m_cPosStatus.Base.PayInqPort, 10000, htReqData, ref htRecvData, false);
                sRet = m_cDataCommon.ExecutePosIrt(ItemConst.COMM_MSG_TYPE.WELCOME_INFO, sWccIP, int.Parse(sWccPort), 10000, htReqData, ref htRecvData, true);


                UserLog.WriteLogFile(UserCom.LOG_IOS,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                     "[WelcomeCard_Approval] Approval End! (IP: " + sWccIP + " / PORT:" + sWccPort + " + Result :" + sRet.ToString() + ")");

                if (htRecvData == null || htRecvData.Count == 0)
                {
                    UserLog.WriteLogFile(UserCom.LOG_SOCK,
                                         System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                         "WelcomeCard_Approval()",
                                         "[RECV :" + sWccIP + ":" + sWccPort + "] " + "응답 전문이 없습니다.");

                    // 요청 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문, [12]입력구분, [13]추후적립여부, [14]적립구분, [15] skt할인상품코드)
                    m_cDataCommon.SetSaleApprLog(aTradeDiv, new string[] { ItemConst.TR_ITEM_ID.MOBILE_COM_POINT, ItemConst.TR_ITEM_ID.MOBILE_COM.WELCOMECARD, CmUtil.MidH(aType, 2, 4), "R", aParam[9], "", "", "", "", "", "", "", "", "", "", "", "" });
                }
                else
                {
                    UserLog.WriteLogFile(UserCom.LOG_SOCK,
                                         System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                         "WelcomeCard_Approval()",
                                         "[RECV :" + sWccIP + ":" + sWccPort + "] " + htRecvData[Column.WELCOMECARD.DATA].ToString());

                    // 요청 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문, [12]입력구분, [13]추후적립여부, [14]적립구분, [15] skt할인상품코드)
                    m_cDataCommon.SetSaleApprLog(aTradeDiv, new string[] { ItemConst.TR_ITEM_ID.MOBILE_COM_POINT, ItemConst.TR_ITEM_ID.MOBILE_COM.WELCOMECARD, CmUtil.MidH(aType, 2, 4), "R", aParam[9], "", "", "", "", CmUtil.MidH(htRecvData[Column.WELCOMECARD.DATA].ToString(), 50, 5), "", htRecvData[Column.WELCOMECARD.DATA].ToString(), "", "", "", "", "" });
                }

        
                if (sRet != UserCom.RST_OK || htRecvData == null || htRecvData.Count == 0)
                {
                    #region 망상할인, 망상할인취소
                    if (aType == PosConst.WELCOMECARD_TYPE.DC_AGREE || aType == PosConst.WELCOMECARD_TYPE.DC_CANCEL)
                    {
                        UserLog.WriteLogFile(UserCom.LOG_IOS,
                                             System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                             System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                             System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                             "[WelcomeCard_Approval] NET_Approval Start! (aType :" + aType + ")");

                        //#20180605 통신 실패 시 예외처리  start
                        // 받는
                        htRecvData = null;
                        htRecvData = new Hashtable();
                        htRecvData.Clear();

                        // 보내는
                        htReqData = null;
                        htReqData = new Hashtable();
                        htReqData.Clear();
                        //#20180605 통신 실패 시 예외처리  end

                        //#20180704 망상 전문 관련 수정 start
                        sSendData = string.Empty;
                        //#20180704 망상 전문 관련 수정 end

                        // 할인승인 -> 망상할인취소
                        if (aType == PosConst.WELCOMECARD_TYPE.DC_AGREE)
                        { 
                            //DC_NETAGREE
                            sSendData = MakeBodyData(PosConst.WELCOMECARD_TYPE.DC_NETAGREE, aParam);
                            aType = PosConst.WELCOMECARD_TYPE.DC_NETAGREE;
                           
                        }
                        // 할인취소승인 -> 망상할인
                        else if (aType == PosConst.WELCOMECARD_TYPE.DC_CANCEL)
                        { 
                            //DC_NETCANCEL
                            sSendData = MakeBodyData(PosConst.WELCOMECARD_TYPE.DC_NETCANCEL, aParam);
                            aType = PosConst.WELCOMECARD_TYPE.DC_NETCANCEL;
                        }
                         
                        htReqData.Add(Column.WELCOMECARD.INQ_TYPE, ItemConst.IRT_INQ_TYPE.WELCOME_INFO_INQ);
                        htReqData.Add(Column.WELCOMECARD.DATA, sSendData);
                        htReqData.Add(Column.WELCOMECARD.RES_CD, "");

                        UserLog.WriteLogFile(UserCom.LOG_SOCK,
                                             System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                             "[WelcomeCard_Approval] NET_Approval ",
                                             "[SEND :" + sWccIP + ":" + sWccPort + "] " + sSendData);

                        // 요청 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문, [12]입력구분, [13]추후적립여부, [14]적립구분, [15] skt할인상품코드)
                        m_cDataCommon.SetSaleApprLog(aTradeDiv, new string[] { ItemConst.TR_ITEM_ID.MOBILE_COM_POINT, ItemConst.TR_ITEM_ID.MOBILE_COM.WELCOMECARD, CmUtil.MidH(aType, 2, 4), "S", aParam[9], CmUtil.MidH(htReqData[Column.WELCOMECARD.DATA].ToString(), 118, 7), "", "", "", "", "", sSendData, "", "", "", "", "" });
                         

                        //sRet = m_cDataCommon.ExecutePosIrt(ItemConst.COMM_MSG_TYPE.WELCOME_INFO, "10.0.40.134", 9029, 10000, htReqData, ref htRecvData, false);
                        sRet = m_cDataCommon.ExecutePosIrt(ItemConst.COMM_MSG_TYPE.WELCOME_INFO, sWccIP, int.Parse(sWccPort), 10000, htReqData, ref htRecvData, true);

                        UserLog.WriteLogFile(UserCom.LOG_IOS,
                                             System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                             System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                             System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                             "[WelcomeCard_Approval] NET_Approval End! (IP: " + sWccIP + " / PORT:" + sWccPort + " + Result :" + sRet.ToString() + ")");

                        if (htRecvData == null || htRecvData.Count == 0)
                        {
                            UserLog.WriteLogFile(UserCom.LOG_SOCK,
                                                 System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                                 "[WelcomeCard_Approval] NET_Approval ",
                                                 "[RECV :" + sWccIP + ":" + sWccPort + "] " + "응답 전문이 없습니다.");

                            // 요청 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문, [12]입력구분, [13]추후적립여부, [14]적립구분, [15] skt할인상품코드)
                            m_cDataCommon.SetSaleApprLog(aTradeDiv, new string[] { ItemConst.TR_ITEM_ID.MOBILE_COM_POINT, ItemConst.TR_ITEM_ID.MOBILE_COM.WELCOMECARD, CmUtil.MidH(aType, 2, 4), "R", aParam[9], "", "", "", "", "", "", "", "", "", "", "", "" });

                        }
                        else
                        {
                            UserLog.WriteLogFile(UserCom.LOG_SOCK,
                                                 System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                                 "[WelcomeCard_Approval] NET_Approval ",
                                                 "[RECV :" + sWccIP + ":" + sWccPort + "] " + htRecvData[Column.WELCOMECARD.DATA].ToString());

                            // 요청 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문, [12]입력구분, [13]추후적립여부, [14]적립구분, [15] skt할인상품코드)
                            m_cDataCommon.SetSaleApprLog(aTradeDiv, new string[] { ItemConst.TR_ITEM_ID.MOBILE_COM_POINT, ItemConst.TR_ITEM_ID.MOBILE_COM.WELCOMECARD, CmUtil.MidH(aType, 2, 4), "R", aParam[9], CmUtil.MidH(htRecvData[Column.WELCOMECARD.DATA].ToString(), 136, 7), "", "", "", CmUtil.MidH(htRecvData[Column.WELCOMECARD.DATA].ToString(), 50, 5), "", htRecvData[Column.WELCOMECARD.DATA].ToString(), "", "", "", "", "" });

                        }

                        UserLog.WriteLogFile(UserCom.LOG_IOS,
                                              System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                              System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                              System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                              "[WelcomeCard_Approval] NET_Approval End! (Result :" + sRet.ToString() + ")");

                        if (sRet != UserCom.RST_OK)
                        {
                            //망취소 실패 시 로컬에 데이터 저장!
                            Wcc_Net_log_Insert(aType, aParam[9], htReqData, htRecvData);
                        }
                    }
                    #endregion 망상할인, 망상할인취소

                    WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0005));
                    sRet = UserCom.RST_ERR;
                    return sRet;
                }
                // 응답전문 파싱 
                string[] aReq = null;
                string[] aRecv = null;
                sRet = WelcomeCard_Parsing(aType, htReqData, htRecvData, ref aReq, ref aRecv);

                aRecvdData = aRecv;

                UserLog.WriteLogFile(UserCom.LOG_IOS,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                     "[WelcomeCard_Approval] WelcomeCard_Parsing! (Result :" + sRet.ToString() + ")");

                #region 전문 응답 메세지 - 정리하기
                // 발급조회
                if (aType == PosConst.WELCOMECARD_TYPE.ISSUE_SEARCH && aRecv[Column.WELCOMECARD_SEARCH_RECV.SEQ.sReqCode].Trim() != "00000")
                {
                    WinManager.ErrorMessage(aRecv[Column.WELCOMECARD_SEARCH_RECV.SEQ.sMsg1].Trim());
                    sRet = UserCom.RST_ERR;
                    return sRet;
                }
                // 발급요청, 취소 
                else if (aType == PosConst.WELCOMECARD_TYPE.ISSUE_REGISTER && aRecv[Column.WELCOMECARD_ISSUE_RECV.SEQ.sReqCode].Trim() != "00000")
                {
                    WinManager.ErrorMessage(aRecv[Column.WELCOMECARD_ISSUE_RECV.SEQ.sMsg1].Trim());
                    sRet = UserCom.RST_ERR;
                    return sRet;
                }
                // POS 고객등록 
                else if (aType == PosConst.WELCOMECARD_TYPE.POS_CLIENT_REGISTER && aRecv[Column.WELCOMECARD_SERVER_REGISTER_RECV.SEQ.sReqCode].Trim() != "00000")
                {
                    WinManager.ErrorMessage(aRecv[Column.WELCOMECARD_SERVER_REGISTER_RECV.SEQ.sMsg1].Trim());
                    sRet = UserCom.RST_ERR;
                    return sRet;
                }
                // 할인요청,취소 
                else if ((aType == PosConst.WELCOMECARD_TYPE.DC_AGREE ||
                          aType == PosConst.WELCOMECARD_TYPE.DC_CANCEL ||
                          aType == PosConst.WELCOMECARD_TYPE.DC_NETAGREE ||
                          aType == PosConst.WELCOMECARD_TYPE.DC_NETCANCEL) && aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sReqCode].Trim() != "00000")
                {
                    //#20180705 할인취소 시 응답코드가 00400일 때 정상처리 되도록 변경 start
                    //기존
                    //WinManager.ErrorMessage(aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sMsg1].Trim());
                    //sRet = UserCom.RST_ERR;
                    //return sRet;

                    //변경


                    //#20180726 멤버십 할인 반품처리시 승인일자 확인요청 start
                    //기존
                    //if (aType == PosConst.WELCOMECARD_TYPE.DC_CANCEL && aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sReqCode].Trim() != "00400")
                    //변경
                    if ((aType == PosConst.WELCOMECARD_TYPE.DC_CANCEL && (aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sReqCode].Trim() != "00400" && aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sReqCode].Trim() != "00000"))
                        || (aType == PosConst.WELCOMECARD_TYPE.DC_AGREE && aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sReqCode].Trim() != "00000"))
                    //#20180726 멤버십 할인 반품처리시 승인일자 확인요청 end
                    
                    {
                        WinManager.ErrorMessage(aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sMsg1].Trim());
                        sRet = UserCom.RST_ERR;
                        return sRet;
                    }
                    //#20180705 할인취소 시 응답코드가 00400일 때 정상처리 되도록 변경 end
                }
                #endregion 전문 응답 메세지 - 정리하기

                // 응답전문 적용

                //#20180620 반품 시 반품승인번호 표기 start
                //기존
                //if (aType == PosConst.WELCOMECARD_TYPE.DC_AGREE )
                //변경
                if (aType == PosConst.WELCOMECARD_TYPE.DC_AGREE || aType == PosConst.WELCOMECARD_TYPE.DC_CANCEL)
                //#20180620 반품 시 반품승인번호 표기 end
                {
                    sRet = WelcomeCard_Insert(aTradeDiv, aType, aInputType, aReq, aRecv);

                    UserLog.WriteLogFile(UserCom.LOG_IOS,
                                         System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                         System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                         System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                         "[WelcomeCard_Approval] WelcomeCard_Insert! (Result :" + sRet.ToString() + ")");

                    if (sRet != UserCom.RST_OK)
                    {
                        WinManager.ErrorMessage(MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1153));
                        sRet = UserCom.RST_ERR;
                        return sRet;
                    }
                }

                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);
                sRet = UserCom.RST_ERR;
            }
            return sRet;
        }
        #endregion

        #region 웰컴카드 전문파싱
        public string WelcomeCard_Parsing(string aType, Hashtable htReqData, Hashtable htRecvData, ref string[] aReq, ref string[] aRecv)
        {
            int nNowPos = 0;
            string sRet = UserCom.RST_ERR;
            string sSendValue = string.Empty;
            string sRecvValue = string.Empty;
            string[] asSendValue = null;
            string[] asRecvValue = null;
            try
            {
                if (htReqData == null) return sRet;
                if (htRecvData == null) return sRet;

                // send
                foreach (DictionaryEntry entry in htReqData)
                {
                    //Console.WriteLine("{0}, {1}", entry.Key, entry.Value);
                    if ((string)entry.Key == "DATA")
                    {
                        sSendValue = (string)entry.Value;
                        break;
                    }
                }
                // receive
                foreach (DictionaryEntry entry in htRecvData)
                {
                    //Console.WriteLine("{0}, {1}", entry.Key, entry.Value);
                    if ((string)entry.Key == "DATA")
                    {
                        sRecvValue = (string)entry.Value;
                        break;
                    }
                }

                if (sSendValue == "") return sRet;
                if (sRecvValue == "") return sRet;

                if (aType == PosConst.WELCOMECARD_TYPE.ISSUE_SEARCH)
                {
                    #region 발급조회
                    asRecvValue = new string[Column.WELCOMECARD_SEARCH_RECV.LEN.Length];
                    ItemColumn.ParseMessage(Column.WELCOMECARD_SEARCH_RECV.LEN,
                                            Column.WELCOMECARD_SEARCH_RECV.TYPE,
                                            Encoding.Default.GetBytes(sRecvValue),
                                            ref nNowPos,
                                            ref asRecvValue);
                    nNowPos = 0;

                    asSendValue = new string[Column.WELCOMECARD_SEARCH.LEN.Length];
                    ItemColumn.ParseMessage(Column.WELCOMECARD_SEARCH.LEN,
                                            Column.WELCOMECARD_SEARCH.TYPE,
                                            Encoding.Default.GetBytes(sSendValue),
                                            ref nNowPos,
                                            ref asSendValue);
                    #endregion
                }
                else if (aType == PosConst.WELCOMECARD_TYPE.ISSUE_REGISTER || aType == PosConst.WELCOMECARD_TYPE.ISSUE_CANCEL)
                {
                    #region 발급, 취소
                    asRecvValue = new string[Column.WELCOMECARD_ISSUE_RECV.LEN.Length];
                    ItemColumn.ParseMessage(Column.WELCOMECARD_ISSUE_RECV.LEN,
                                            Column.WELCOMECARD_ISSUE_RECV.TYPE,
                                            Encoding.Default.GetBytes(sRecvValue),
                                            ref nNowPos,
                                            ref asRecvValue);
                    nNowPos = 0;

                    asSendValue = new string[Column.WELCOMECARD_ISSUE.LEN.Length];
                    ItemColumn.ParseMessage(Column.WELCOMECARD_ISSUE.LEN,
                                            Column.WELCOMECARD_ISSUE.TYPE,
                                            Encoding.Default.GetBytes(sSendValue),
                                            ref nNowPos,
                                            ref asSendValue);
                    #endregion
                }
                else if (aType == PosConst.WELCOMECARD_TYPE.POS_CLIENT_REGISTER)
                {
                    #region POS고객등록

                    asRecvValue = new string[Column.WELCOMECARD_SERVER_REGISTER_RECV.LEN.Length];
                    ItemColumn.ParseMessage(Column.WELCOMECARD_SERVER_REGISTER_RECV.LEN,
                                            Column.WELCOMECARD_SERVER_REGISTER_RECV.TYPE,
                                            Encoding.Default.GetBytes(sRecvValue),
                                            ref nNowPos,
                                            ref asRecvValue);

                    nNowPos = 0;

                    asSendValue = new string[Column.WELCOMECARD_SERVER_REGISTER.LEN.Length];
                    ItemColumn.ParseMessage(Column.WELCOMECARD_SERVER_REGISTER.LEN,
                                            Column.WELCOMECARD_SERVER_REGISTER.TYPE,
                                            Encoding.Default.GetBytes(sSendValue),
                                            ref nNowPos,
                                            ref asSendValue);
                    #endregion
                }
                else if (aType == PosConst.WELCOMECARD_TYPE.HPC_CLIENT_REGISTER)
                {
                    #region HPC고객등록

                    #endregion
                }
                else if (aType == PosConst.WELCOMECARD_TYPE.DC_AGREE || aType == PosConst.WELCOMECARD_TYPE.DC_CANCEL ||
                         aType == PosConst.WELCOMECARD_TYPE.DC_NETAGREE || aType == PosConst.WELCOMECARD_TYPE.DC_NETCANCEL)
                {
                    #region 웰컴카드 할인
                    asRecvValue = new string[Column.WELCOMECARD_DC_RECV.LEN.Length];
                    ItemColumn.ParseMessage(Column.WELCOMECARD_DC_RECV.LEN,
                                            Column.WELCOMECARD_DC_RECV.TYPE,
                                            Encoding.Default.GetBytes(sRecvValue),
                                            ref nNowPos,
                                            ref asRecvValue);

                    nNowPos = 0;

                    asSendValue = new string[Column.WELCOMECARD_DC.LEN.Length];
                    ItemColumn.ParseMessage(Column.WELCOMECARD_DC.LEN,
                                            Column.WELCOMECARD_DC.TYPE,
                                            Encoding.Default.GetBytes(sSendValue),
                                            ref nNowPos,
                                            ref asSendValue);
                    #endregion
                }
                 
                aRecv = asRecvValue; //응답
                aReq = asSendValue; //요청

                sRet = UserCom.RST_OK;

                return sRet;
            }
            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 UserCom.RST_ERR;
            }
        }
        #endregion

        #region 웰컴카드 할인 데이터 인서트 
        public string WelcomeCard_Insert(string aTradeDiv, string aType, string aInputType, string[] aReq, string[] aRecv)
        {
            string sRet = UserCom.RST_ERR;

            if (aReq == null) return sRet; // 요청데이터
            if (aRecv == null) return sRet;// 응답데이터
            
            //#20180620 반품 시 반품승인번호 표기 start
            //기존
            //if (aType != PosConst.WELCOMECARD_TYPE.DC_AGREE) return sRet;
            //#20180620 반품 시 반품승인번호 표기 end
            
            if (m_cPosStatus.Base.TrainingFlag == "1" || m_cPosStatus.Mst.TestStorYn == "1") return sRet;

            try
            { 
                if (aTradeDiv == PosConst.CANCEL_DIV.NORMAL)
                {
                    // 결제구분 (1:결제, 2:할인)
                    DataRow dr = PosMstManager.GetMstPayDc(new string[] { m_cPosStatus.Base.CmpCd, m_cPosStatus.Base.StoreNo, m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01 });

                    m_cPayItem.PAY_AMT = CmUtil.DoubleParse(aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sDC_Amt].Trim()); // 사용포인트(할인금액)
                    m_cPayItem.PAY_AMT = CmUtil.MathRounds(m_cPayItem.PAY_AMT, PosConst.MATH_ROUND.CEILING, -1);
                    m_cPayItem.PAY_DTL_CD_02 = ""; 
                    
                    //if (PosMstManager.GetMstPayDc(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, PosMst.MST_PAY_DC.DATA.PAY_DC_TYPE) == PosConst.PAY_DC_TYPE.DC)
                    if (CmUtil.GetDataRowStr(dr, PosMst.MST_PAY_DC.DATA.PAY_DC_TYPE) == PosConst.PAY_DC_TYPE.DC)
                    {
                        m_cPayItem.PAY_DTL_CD_03 = "1"; // 할인금액아이템적용여부 (0:미적용, 1:적용)
                        m_cPayItem.PAY_DTL_CD_04 = "";
                        m_cPayItem.PAY_DTL_CD_05 = CmUtil.GetDataRowStr(dr, PosMst.MST_PAY_DC.DATA.PAY_DC_TYPE); // 할인결제구분 (1:결제, 2:할인)         
                    }
                    else
                    {
                        m_cPayItem.PAY_DTL_CD_03 = "0"; //할인금액아이템적용여부 (0:미적용, 1:적용)
                        m_cPayItem.PAY_DTL_CD_04 = ""; 
                        m_cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.PAY; //할인결제구분 (1:결제, 2:할인)
                    }

                    m_cPayItem.AMT_ENTRY_01 = m_cPayItem.PAY_AMT; // 할인금액
                    m_cPayItem.AMT_ENTRY_02 = 0;
                    // 총포인트
                    m_cPayItem.AMT_ENTRY_03 = 0; // CmUtil.DoubleParse(aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sTotDcAmt]);
                    // 가용포인트(할인후결제금액)
                    m_cPayItem.AMT_ENTRY_04 = CmUtil.DoubleParse(aReq[Column.WELCOMECARD_DC.SEQ.sTarget_Amt].Trim()) -
                                              CmUtil.DoubleParse(aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sDC_Amt].Trim()); // 대상금액 - 할인금액 제외 
                    // 잔여포인트
                    m_cPayItem.AMT_ENTRY_05 = 0; // CmUtil.DoubleParse(aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sTotDcAmt]); //총할인금액
                    m_cPayItem.AMT_ENTRY_06 = 0;
                    m_cPayItem.AMT_ENTRY_07 = 0;
                    m_cPayItem.AMT_ENTRY_08 = 0;
                    m_cPayItem.AMT_ENTRY_09 = 0;
                    m_cPayItem.AMT_ENTRY_10 = CmUtil.DoubleParse(aReq[Column.WELCOMECARD_DC.SEQ.sTarget_Amt]); // 대상금액 

                    m_cPayItem.OCCUR_ENTRY_01 = aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sCardNo].Trim(); // 카드번호 
                    m_cPayItem.OCCUR_ENTRY_02 = aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sApprNo].Trim(); // 승인번호


                    //#20180726 멤버십 할인 반품처리시 승인일자 확인요청 start
                    //기존
                    //m_cPayItem.OCCUR_ENTRY_03 = aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sYYYYMMDD].Trim(); // 승인일자
                    //m_cPayItem.OCCUR_ENTRY_04 = aRecv[Column.WELCOMECARD_DC_RECV.SEQ.shhmmss].Trim(); // 승인시간
                    //변경
                    m_cPayItem.OCCUR_ENTRY_03 = CmUtil.MidH(aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sApprDate].Trim(), 0, 8); // 승인일자 
                    m_cPayItem.OCCUR_ENTRY_04 = CmUtil.MidH(aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sApprDate].Trim(), 8, 6); // 승인시간
                    //#20180726 멤버십 할인 반품처리시 승인일자 확인요청 end

                    m_cPayItem.OCCUR_ENTRY_05 = aInputType; //aReq[Column.WELCOMECARD_DC.SEQ.sCard_type].ToString();// 입력 구분
                    m_cPayItem.OCCUR_ENTRY_06 = ""; // 원승인번호
                    m_cPayItem.OCCUR_ENTRY_07 = ""; // 원승인일자
                    m_cPayItem.OCCUR_ENTRY_08 = ItemConst.PAY_APP_DIV.NORMAL; //승인구분

                    m_cPayItem.OCCUR_ENTRY_16 = CmUtil.GetDataRowStr(dr, PosMst.MST_PAY_DC.DATA.APPR_VEND_CD); // VAN 구분
                    m_cPayItem.OCCUR_ENTRY_18 = ""; // 가맹점번호

                    m_cPayItem.OCCUR_ENTRY_19 = aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sCardNo].Trim(); //웰컴카드번호 
                    m_cPayItem.OCCUR_ENTRY_20 = GetPayDtlCdToPayDtlName(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);   // 결제수단명
                    m_cPayItem.OCCUR_ENTRY_21 = GetPayDtlCdToCashBillYn(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);   // 현금영수증 발행여부 
                    m_cPayItem.OCCUR_ENTRY_22 = aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sHPCustNo].Trim(); // hpc 회원번호
                    m_cPayItem.OCCUR_ENTRY_23 = aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sCardDiv].Trim(); // 입력구분(C:실물카드,A: 해피포인트)
                    m_cPayItem.OCCUR_ENTRY_24 = aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sRemainCnt].Trim(); // 잔여횟수
                    m_cPayItem.OCCUR_ENTRY_25 = aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sTotDcAmt].Trim(); // 총할인금액

                    m_cPayItem.CANCEL_DIV = ItemConst.PAY_CANCEL_DIV.NORMAL;

                    m_cPayItem.BILLSPR_NO = m_cTrnStatus.Sale.BillSplitNo; // 빌분리 번호 
                }
                else
                {
                    // 전체금액
                    m_cPayItem.AMT_ENTRY_03 = 0; // CmUtil.DoubleParse(aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sTotDcAmt].Trim());
                    // 대상금액 - 할인금액 제외 
                    m_cPayItem.AMT_ENTRY_04 = CmUtil.DoubleParse(aReq[Column.WELCOMECARD_DC.SEQ.sTarget_Amt].Trim()) -
                                              CmUtil.DoubleParse(aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sDC_Amt].Trim());
                    m_cPayItem.AMT_ENTRY_05 = 0; //CmUtil.DoubleParse(aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sTotDcAmt].Trim());

                  
                    m_cPayItem.OCCUR_ENTRY_06 = m_cPayItem.OCCUR_ENTRY_02; // 원승인번호
                    m_cPayItem.OCCUR_ENTRY_07 = m_cPayItem.OCCUR_ENTRY_03; // 원승인일자                   


                    m_cPayItem.OCCUR_ENTRY_01 = aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sCardNo].Trim(); // 카드번호 
                    m_cPayItem.OCCUR_ENTRY_02 = aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sApprNo].Trim(); // 승인번호

                    //#20180726 멤버십 할인 반품처리시 승인일자 확인요청 start
                    //기존
                    //m_cPayItem.OCCUR_ENTRY_03 = aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sYYYYMMDD].Trim(); // 승인일자  
                    //m_cPayItem.OCCUR_ENTRY_04 = aRecv[Column.WELCOMECARD_DC_RECV.SEQ.shhmmss].Trim(); // 승인시간
                    //변경
                    m_cPayItem.OCCUR_ENTRY_03 = CmUtil.MidH(aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sApprDate].Trim(), 0, 8); // 승인일자 
                    m_cPayItem.OCCUR_ENTRY_04 = CmUtil.MidH(aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sApprDate].Trim(), 8, 6); // 승인시간
                    //#20180726 멤버십 할인 반품처리시 승인일자 확인요청 end

                    m_cPayItem.OCCUR_ENTRY_05 = aRecv[Column.WELCOMECARD_DC.SEQ.sCard_type].Trim(); // 입력구분


                    //m_cPayItem.OCCUR_ENTRY_19 = aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sCardNo].Trim(); //웰컴카드번호 
                    //m_cPayItem.OCCUR_ENTRY_20 = GetPayDtlCdToPayDtlName(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);   // 결제수단명
                    //m_cPayItem.OCCUR_ENTRY_21 = GetPayDtlCdToCashBillYn(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);   // 현금영수증 발행여부 
                    //m_cPayItem.OCCUR_ENTRY_22 = aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sHPCustNo].Trim(); // hpc 회원번호
                    //m_cPayItem.OCCUR_ENTRY_23 = aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sCardDiv].Trim(); // 입력구분(C:실물카드,A: 해피포인트)
                    //m_cPayItem.OCCUR_ENTRY_24 = aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sRemainCnt].Trim(); // 잔여횟수
                    //m_cPayItem.OCCUR_ENTRY_25 = aRecv[Column.WELCOMECARD_DC_RECV.SEQ.sTotDcAmt].Trim(); // 총할인금액

                    //m_cPayItem.CANCEL_DIV = PosConst.CANCEL_DIV.CANCEL; 
                } 
                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;
            }

            return sRet;

        }
        #endregion

        #region 해피앱 고객등록 전송
        public string HPAppClientRegister(string[] sParam)
        {
            string sRet = UserCom.RST_ERR;
 
            string sTradeDiv = sParam.Length >= 1 ? sParam[0] : "";
            string sWccType = sParam.Length >= 2 ? sParam[1] : "";
            string sInputCardNo = sParam.Length >= 3 ? sParam[2] : "";
            string sInputType = sParam.Length >= 4 ? sParam[3] : "";
            string sReqDivCd = sParam.Length >= 5 ? sParam[4] : "";
            string sInputHPWccNo = sParam.Length >= 6 ? sParam[5] : "";
            string sReadingHPData = sParam.Length >= 7 ? sParam[6] : "";
             
            string sAppCardNo = "";
            string sInEncData = "";
            string sInPutData = "";
             
            try
            {
                if (m_cTrnStatus.Head.TradeDiv != ItemConst.TRAN_DIV.NORMAL) return sRet;
                if (m_cPosStatus.Base.TrainingFlag == "1" || m_cPosStatus.Mst.TestStorYn == "1") return sRet;
                if (sReadingHPData == "") return sRet;

                UserLog.WriteLogFile(UserCom.LOG_IOS,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                     "[HPAppClientRegister] " +
                                     " sTradeDiv :" + sTradeDiv + "," +
                                     " sWccType  :" + sWccType + "," +
                                     " sInputCardNo :" + sInputCardNo + "," +
                                     " sInputType :" + sInputType + "," +
                                     " sReqDivCd :" + sReqDivCd + "," +
                                     " sInputHPWccNo :" + sInputHPWccNo + "," +
                                     " sReadingHPData :" + sReadingHPData
                                     );
                //#20180701 웰컴카드 번호 16자리 이상인 경우 16자리만 처리 start
                if (sInputCardNo.Length > 16)
                {
                    sInputCardNo = sInputCardNo.Substring(0,16);
                }
                //#20180701 웰컴카드 번호 16자리 이상인 경우 16자리만 처리 end

                // 추가정보 생성
                string sAddInfo = "";
                sAddInfo += CmUtil.RPadH("", 10);             //요청 사용자ID
                sAddInfo += CmUtil.RPadH(sReqDivCd, 2);       //요청구분코드 40:웰컴카드등록, 41:웰컴카드해지
                sAddInfo += CmUtil.RPadH(sInputCardNo, 160);  //Filler 웰컴카드번호(20자리)
                sAddInfo += CmUtil.RPadH("", 28);             //VReserved

                if (sReadingHPData == PosConst.WELCOMECARD_MSG.HP_REGISTER_DATA)
                {
                    ArrayList alEtcItem = (ArrayList)StateObject.GetItemObject(Column.TR_ETC.ITEM);
                    foreach (Column.TR_ETC.DATA cEtcItem in alEtcItem)
                    {
                        if (cEtcItem.CANCEL_DIV == ItemConst.PAY_CANCEL_DIV.CANCEL) continue;
                        if (cEtcItem.ETC_WAY_CD != ItemConst.TR_ITEM_ID.ETC_INFO_ITEM && cEtcItem.ETC_DTL_CD_01 != ItemConst.TR_ITEM_ID.ETC_INFO.SAVEPOINT) continue;
                        if (cEtcItem.OCCUR_ENTRY_10 == "") continue; //HCP회원번호 
                        //if (cEtcItem.OCCUR_ENTRY_12 != "Y") continue; //해피앱여부 20180628 체크안하도록수정
                        sAppCardNo = cEtcItem.OCCUR_ENTRY_14;
                    }
                }
                else
                {
                    // 조회 데이터 획득
                    Column.TR_ETC.DATA cEtcItem = null;
                    cEtcItem = new Column.TR_ETC.DATA();
                    cEtcItem = (Column.TR_ETC.DATA)m_cHappyPoint.GetPayment(new string[] { });

                    if (cEtcItem.CANCEL_DIV == ItemConst.PAY_CANCEL_DIV.CANCEL) return UserCom.RST_ERR;
                    if (cEtcItem.ETC_WAY_CD != ItemConst.TR_ITEM_ID.ETC_INFO_ITEM || cEtcItem.ETC_DTL_CD_01 != ItemConst.TR_ITEM_ID.ETC_INFO.SAVEPOINT) return UserCom.RST_ERR;
                    if (cEtcItem.OCCUR_ENTRY_10 == "") return UserCom.RST_ERR; //HCP회원번호 
                    //if (cEtcItem.OCCUR_ENTRY_12 != "Y") return UserCom.RST_ERR; //해피앱여부 20180628 체크안하도록수정

                    //#20180628 start
                    //기존
                    /*
                    //sAppCardNo = cEtcItem.OCCUR_ENTRY_14;
                    sAppCardNo = cEtcItem.CanFiller3;
                    */
                    //변경
                    sAppCardNo = cEtcItem.OCCUR_ENTRY_14;
                    //#20180628 end
                } 
                
                if (sAppCardNo.EndsWith("=") == false)
                {
                    sAppCardNo = sAppCardNo + "=";
                }

                // 암호화
                EncryptedCardNo(sAppCardNo, ref sInPutData, ref sInEncData);

                // 승인업체 코드 조회
                string sVanCD = GetPayDtlCdToVanCode(ItemConst.TR_ITEM_ID.ETC_INFO_ITEM, ItemConst.TR_ITEM_ID.ETC_INFO.SAVEPOINT);
                if (sVanCD == "")
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0563);
                    return sRet;
                }

                // 포인트 조회
                string[] saRsp = null;
                sRet = ExecutePointIrt(sTradeDiv, ItemConst.TR_ITEM_ID.ETC_INFO_ITEM, ItemConst.TR_ITEM_ID.ETC_INFO.SAVEPOINT, sVanCD, PosConst.POS_VAN_MASTER.TRADE_ID.VAN_POT_QRY_A, "HPY", sInputType, sInPutData, sInEncData, 0, "", "", "", "", "", "", sAddInfo, ref saRsp, "", "", "1");

                UserLog.WriteLogFile(UserCom.LOG_IOS,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                     "[HPAppClientRegister] ExecutePointIrt (Result :" + sRet.ToString() + ")");

                if (sRet != UserCom.RST_OK)
                {
                    sRet = UserCom.RST_ERR;
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                            System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                            System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                            ex.Message);

                sRet = UserCom.RST_ERR;
            }
            return sRet;
        }
        #endregion

        #region 망취소 데이터 로컬 db 저장
        private string Wcc_Net_log_Insert(string aType, string aCardNo, Hashtable SendData, Hashtable RecvData)
        {
            string sRet = UserCom.RST_ERR;

            int iSeq = 0;
            string sQry = "";
            string sQuery = "";
            string sCardNo = "";
            string sSendText = "";
            string sRecvText = "";
            DataTable dtSeqCnt = null;
            DataRow drSeqCnt = null;
            try
            {
                UserLog.WriteLogFile(UserCom.LOG_IOS,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                     "[Wcc_Net_log_Insert] Start! (aCardNo :" + aCardNo + ")");

                sCardNo = aCardNo;


                if (SendData != null && RecvData.Count != 0)
                {
                    sSendText = SendData[Column.WELCOMECARD.DATA].ToString();
                }
                if (RecvData != null && RecvData.Count != 0)
                {
                    sRecvText = RecvData[Column.WELCOMECARD.DATA].ToString();
                }

                UserLog.WriteLogFile(UserCom.LOG_IOS,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                     "[Wcc_Net_log_Insert] sSendText! " + sSendText + "");

                UserLog.WriteLogFile(UserCom.LOG_IOS,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                     "[Wcc_Net_log_Insert] sRecvText! " + sRecvText + "");

                sQuery  = " SELECT ISNULL(MAX(SEQ) + 1,0) AS SEQ  ";
                sQuery += "   FROM POSLOG..WCC_NET_LOG";
                sQuery += "  WHERE CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                sQuery += "    AND SALE_DT = '" + m_cPosStatus.Base.SaleDate + "'";
                sQuery += "    AND STOR_CD = '" + m_cPosStatus.Base.SubShopNo + "'";
                sQuery += "    AND POS_NO = '" + m_cPosStatus.Base.PosNo + "'"; 
                
                m_cSqlDbService.DBSelect(sQuery, out dtSeqCnt);
                
                if (dtSeqCnt != null && dtSeqCnt.Rows.Count > 0)
                {
                    drSeqCnt = dtSeqCnt.Rows[0];
                    iSeq = Convert.ToInt32(CmUtil.GetDataRowStr(drSeqCnt, "SEQ"));
                }
                  
                sQuery = "";
                sQuery += " INSERT INTO POSLOG..WCC_NET_LOG(CMP_CD,SALE_DT,STOR_CD,POS_NO,SEQ,INPUT_TYPE,INPUT_CARD_NO,SEND_TEXT,RESV_TEXT,SEND_YN,INS_DT) ";
                sQuery += " VALUES('{0}'";
                sQuery += " ,'{1}'";
                sQuery += " ,'{2}'";
                sQuery += " ,'{3}'";
                sQuery += " ,'{4}'";
                sQuery += " ,'{5}'";
                sQuery += " ,'{6}'";
                sQuery += " ,'{7}'";
                sQuery += " ,'{8}'";
                sQuery += " ,'{9}'";
                sQuery += " ,'{10}')";
                sQry = string.Format(sQuery
                                     , m_cPosStatus.Base.CmpCd
                                     , m_cPosStatus.Base.SaleDate
                                     , m_cPosStatus.Base.SubShopNo
                                     , m_cPosStatus.Base.PosNo
                                     , iSeq
                                     , aType
                                     , sCardNo
                                     , sSendText
                                     , sRecvText
                                     , "0"
                                     , DateTime.Now.ToString("yyyyMMddHHmmss"));
                int iQry = 0;
                iQry = m_cSqlDbService.DBExecuteNonQuery(new string[] { sQry });

                if (iQry == 1)
                {
                    sRet = UserCom.RST_OK;
                }
                else
                {
                    UserLog.WriteLogFile(UserCom.LOG_IOS,
                                         System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                         System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                         System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                         "[Wcc_Net_log_Insert] DBExecuteNonQuery Fail! [iQry :" + iQry.ToString() + "]" + sQry);

                    sRet = UserCom.RST_ERR;
                }


                UserLog.WriteLogFile(UserCom.LOG_IOS,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                     "[Wcc_Net_log_Insert] End! (Result :" + sRet.ToString() + ")");

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

                sRet = UserCom.RST_ERR;
            }
            return sRet;
        }
        #endregion
    }
}

