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

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

/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 결제 공통 모듈(공통 함수)
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Service
{
    class PaymentBase
    {
        protected SManager sManager = new SManager();                                 // 이 객체를 통해 업무 Service 호출
        protected StateServer StateObject = (StateServer)StateServer.GetInstance();   // StateObject : StateServer Object (객체)
        protected PosStatus m_cPosStatus = new PosStatus();                           // 기본정보 참조
        protected TranStatus m_cTrnStatus = new TranStatus();                         // 거래정보 참조
        protected DeviceStatus m_cDevStatus = new DeviceStatus();                     // 디바이스 관리

        protected IDataProcessUs m_cDataService = null;                               // 거래데이터 합계금액 계산 및 관리
        protected IDataCommonUs m_cDataCommon = null;                                 // POS 공통함수 인터페이스
        protected ICampaignUs m_cCampaingMain = null;                                 // 캠페인 관리
        protected IICReaderUs m_cDeviceICReader = null;
        protected ICatTerminalUs m_cCatTerminal = null;                               // CAT 단말기


        /// <summary>
        ///  Van 정보
        /// </summary>
        protected class VanInfo
        {
            public string Pay_DC_Type = "";                 // 결제 그룹 코드
            public string Pay_DC_CD = "";                   // 결제 상세 코드
            public string ServerIP = "";                    // 서버 IP
            public string ServerPort = "";                  // 서버 Port
            public string Appr_ID = "";                     // 제휴사 ID
        }
        protected VanInfo m_cVanInfo = new VanInfo();

        /// <summary>
        /// 현재 등록중인 결제 정보
        /// </summary>
        protected Column.TR_PAYMENT.DATA m_cPayItem = null;

        /// <summary>
        /// 에러메시지 출력여부
        /// </summary>
        protected bool m_bErrMsgShow = true;

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

            m_cDataService = (IDataProcessUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_SERVICE);
            m_cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);
            m_cCampaingMain = (ICampaignUs)sManager.InitServiceInstance(ServiceLists.ASV_CAMPAIGN.DLL, ServiceLists.ASV_CAMPAIGN.CAMPAIGN_MAIN);
            m_cDeviceICReader = (IICReaderUs)sManager.InitServiceInstance(ServiceLists.AGENT_OLEDEVICE.DLL, ServiceLists.AGENT_OLEDEVICE.DEVICE_ICREADER);
            m_cCatTerminal = (ICatTerminalUs)sManager.InitServiceInstance(ServiceLists.AGENT_OLEDEVICE.DLL, ServiceLists.AGENT_OLEDEVICE.DEVICE_CATTERMINAL);

        }

        #region GetMenuKeyToPayWayCd  결제수단코드 획득
        /// <summary>
        /// 결제수단코드 획득
        /// </summary>
        /// <param name="sPosMenuKey"></param>
        /// <returns></returns>
        protected string GetMenuKeyToPayWayCd(string sPosMenuKey)
        {
            string sPayWayCd = "";
            try
            {
                sPayWayCd = m_cDataCommon.GetMenuKeyToPayWayCd(sPosMenuKey);
            }
            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 sPayWayCd;
        }
        #endregion

        #region GetMenuKeyToPayDtlCd 결제세부코드 획득
        /// <summary>
        /// 결제세부코드 획득
        /// </summary>
        /// <param name="sPosMenuKey"></param>
        /// <returns></returns>
        protected string GetMenuKeyToPayDtlCd(string sPosMenuKey)
        {
            string sPayDtlCd = "";
            try
            {
                sPayDtlCd = m_cDataCommon.GetMenuKeyToPayDtlCd(sPosMenuKey);
            }
            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 sPayDtlCd;
        }
        #endregion

        #region GetPayDtlCdToPayDtlName 결제명 획득
        /// <summary>
        /// 결제명 획득
        /// </summary>
        /// <param name="sPayWayCd"></param>
        /// <param name="sPayDtlCd"></param>
        /// <returns></returns>
        protected string GetPayDtlCdToPayDtlName(string sPayWayCd, string sPayDtlCd)
        {
            string sPayDtlName = "";
            try
            {
                // 결제할인 마스터에서 결제수단명 획득
                sPayDtlName = PosMstManager.GetMstPayDc(sPayWayCd, sPayDtlCd, PosMst.MST_PAY_DC.DATA.PAY_DC_NM);         // 결제수단명
                if (sPayDtlName != "") return sPayDtlName;

                if ( sPayWayCd == ItemConst.TR_ITEM_ID.MOBILE_COM_POINT)
                {
                    if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_SKT)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0072);
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_KTF)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0073);
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_LGT)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0074);
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILE_COM.OILBANK_POINT)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0110);
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILE_COM.HBLUE_M_POINT)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0113);
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILE_COM.KRED_M_POINT)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0114);
                    //#20180413 웰컴카드 신규기능 추가 start,phj
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILE_COM.WELCOMECARD)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1138);
                    //#20180413 웰컴카드 신규기능 추가 end,phj
                }
                else if (sPayWayCd == ItemConst.TR_ITEM_ID.POINT_ITEM)
                {
                    if (sPayDtlCd == ItemConst.TR_ITEM_ID.POINT_USE.HAPPY_POINT)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0109);   // 해피포인트
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.POINT_USE.OKCASHBACK_POINT)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0112);   // OCB

                    //grayber@20180208 코레일 마일리지 입력 start - 결제 수단명 획득 추가
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.POINT_USE.KORAIL_MILEAGE)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1096);   // 코레일 마일리지
                    //grayber@20180208 코레일 마일리지 입력 end
                }
                else if (sPayWayCd == ItemConst.TR_ITEM_ID.COUPON_ITEM)
                {
                    if (sPayDtlCd == ItemConst.TR_ITEM_ID.COUPON.NORMAL)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0166);   // 일반쿠폰
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.COUPON.STORE)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0167);   // 매장쿠폰
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.COUPON.CAKE_CHANGE)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0738);   // 케익교환권
                }
                else if (sPayWayCd == ItemConst.TR_ITEM_ID.EMP_DC_ITEM)
                {
                    if (sPayDtlCd == ItemConst.TR_ITEM_ID.EMP_DC.SPC)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0158);   // SPC 임직원 할인
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.EMP_DC.SPC_PAY)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1008);   // SPC 임직원 할인(결제)
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.EMP_DC.SEVERANCE)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0185);   // 세브란스
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.EMP_DC.SAMSUNGCARD)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0170);   // 삼성카드
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.EMP_DC.SPC_CHINA)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0158);   // SPC 임직원 할인 - 중국
                }
                else if (sPayWayCd == ItemConst.TR_ITEM_ID.MOBILECON_ITEM)
                {
                    if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILECON.GIFTCON)                        // 기프트콘
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0201);
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILECON.QPCON)                     // 큐티콘
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0202);
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILECON.HARTCON)                   // 하트콘
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0203);
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILECON.G_MARKET)                  // 지마켓
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0204);
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILECON.SAMSUNG_MOBILE)            // 삼성모바일
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0205);
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILECON.SHINHAN_HPCON)             // 신한해피콘
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0206);
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILECON.HPCON)                     // 해피콘
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0207);
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILECON.AUCTIONCON)                // 옥션
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0208);
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILECON.E_BAYCON)                  // 슈퍼브랜드딜
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0209);
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILECON.TMON)                      // 디몬
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0210);
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILECON.GIFTSHOW)                  // 기프티쇼
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0211);               
                }
                else if (sPayWayCd == ItemConst.TR_ITEM_ID.PAYETC_ITEM)
                {
                    if (sPayDtlCd == ItemConst.TR_ITEM_ID.PAYETC.MEAL_TIKET)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0258);   // 식권
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.PAYETC.BALANCE_VOUCHER)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0265);   // 잔액교환권
                }
                else if (sPayWayCd == ItemConst.TR_ITEM_ID.PPCARD_ITEM)
                {
                    if (sPayDtlCd == ItemConst.TR_ITEM_ID.PPCARD.HP_GIFT)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0351);   // 해피 기프트 사용
                }
                else if (sPayWayCd == ItemConst.TR_ITEM_ID.EMP_PAY_ITEM)
                {
                    sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0387);       // SPC 임직원 결제
                }
                else if (sPayWayCd == ItemConst.TR_ITEM_ID.USER_DC_ITEM)
                {
                    if (sPayDtlCd == ItemConst.TR_ITEM_ID.USER_DC.TOTAL_DC_AMT)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0159);   // 전체 금액 할인
                    if (sPayDtlCd == ItemConst.TR_ITEM_ID.USER_DC.TOTAL_DC_RATE)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0160);   // 전체 % 할인
                }
                else if (sPayWayCd == ItemConst.TR_ITEM_ID.PAY_ITEM)
                {
                    if (sPayDtlCd == ItemConst.TR_ITEM_ID.PAY.ALIPAY_PAY)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0172);   // 알리페이
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.PAY.WECHAT_PAY)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0971);   // 위챗페이
                    // #Rhee, 20170922 중국 은련페이 추가 start
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.PAY.UNION_PAY)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1037);   // 은련모바일페이
                    // #Rhee, 20170922 중국 은련페이 추가 end
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.PAY.SMILE_PAY)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0834);   // 스마일페이
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.PAY.T_PAY)
                        sPayDtlName = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0835);   // T페이
                }
            }
            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 sPayDtlName;
        }
        #endregion

        #region GetPayDtlCdToVanCode 승인업체코드 획득
        /// <summary>
        /// 승인업체코드 획득
        /// </summary>
        /// <param name="sPayWayCd"></param>
        /// <param name="sPayDtlCd"></param>
        /// <returns></returns>
        protected string GetPayDtlCdToVanCode(string sPayWayCd, string sPayDtlCd)
        {
            try
            {
                return PosMstManager.GetMstPayDc(sPayWayCd, sPayDtlCd, PosMst.MST_PAY_DC.DATA.APPR_VEND_CD);         // 승인업체코드
            }
            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 "";
        }
        #endregion

        #region GetPayDtlCdToCashBillYn 현금영수증발행여부 획득
        /// <summary>
        /// 현금영수증발행여부 획득
        /// </summary>
        /// <param name="sPayWayCd"></param>
        /// <param name="sPayDtlCd"></param>
        /// <returns></returns>
        protected string GetPayDtlCdToCashBillYn(string sPayWayCd, string sPayDtlCd)
        {
            try
            {
                return PosMstManager.GetMstPayDc(sPayWayCd, sPayDtlCd, PosMst.MST_PAY_DC.DATA.CASH_BILL_ISSUE_YN);  // 현금영수증발행여부
            }
            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 "0";
        }
        #endregion

        #region 포인트 조회 실행
        /// <summary>
        /// 포인트 조회 실행
        /// </summary>
        //#해피앱 추후적립 start, sskim
        //기존
        /*
        protected string ExecutePointIrt(string sTradeDiv, string sPAY_WAY_CD, string sPAY_DTL_CD_01, string sVanCD, string sTrType, string sPointType, string sInPutType, string sInPutData, string sInEncData, double nPayAmt, string sApprDate, string sApprNo
                        , string sPassWord, string sProductCode, string sReserved, string sCampaign, string sAddInfo, ref string[] aIrtRsp
                        , string sAfterSaveYn, string sCustID)
        */
        //변경
        protected string ExecutePointIrt(string sTradeDiv, string sPAY_WAY_CD, string sPAY_DTL_CD_01, string sVanCD, string sTrType, string sPointType, string sInPutType, string sInPutData, string sInEncData, double nPayAmt, string sApprDate, string sApprNo
                        , string sPassWord, string sProductCode, string sReserved, string sCampaign, string sAddInfo, ref string[] aIrtRsp
                        , string sAfterSaveYn, string sCustID, string sHpAppAfterSaveYN = "", bool showMessage = false)
        //#해피앱 추후적립 end, sskim
        {
            string sSendData = "", sRecvData = "";
            int nNowPos = 0;
            string sRet = UserCom.RST_ERR;
            try
            {
                // 포인트 전문 바디 생성
                //#해피앱 추후적립 start, sskim
                //전문 바디 생성시 해피앱 추후적립 여부 추가로 넘긴다.
                //기존
                //sSendData = MakePointBody(sPointType, sInPutType, sInEncData, nPayAmt, sApprDate, sApprNo, sPassWord, sProductCode, sReserved, sCampaign, sAddInfo);
                //변경
                if (sHpAppAfterSaveYN == "1")
                {
                    sSendData = MakePointBody(sPointType, sInPutType, sInEncData, nPayAmt, sApprDate, sApprNo, sPassWord, sProductCode, sReserved, sCampaign, sAddInfo, sHpAppAfterSaveYN);
                }
                else
                {
                    sSendData = MakePointBody(sPointType, sInPutType, sInEncData, nPayAmt, sApprDate, sApprNo, sPassWord, sProductCode, sReserved, sCampaign, sAddInfo);
                }
                //#해피앱 추후적립 end, sskim

                // 가맹점 정보 획득(회사승인ID,점포승인ID)
                string sCmpApprID = PosMstManager.GetMstVan(sVanCD, PosMst.MST_VAN.DATA.CMP_APPR_ID);
                string sApprID = PosMstManager.GetMstVan(sVanCD, PosMst.MST_VAN.DATA.APPR_ID);

                // 포인트 전문 헤더 생성
                sSendData = m_cDataCommon.MakeCreditCardHeader(sTrType, sSendData.Length, sCmpApprID, sApprID) + sSendData;

                // 승인데이터 중 카드번호 마스킹 처리(2017.05.25)
                string sWriteSendData = CmUtil.MakeLogDataToMask(m_cDevStatus.ICReader.UseYn, sInEncData, sSendData);
                UserLog.WriteLogFile(UserCom.LOG_SOCK, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                    "[SEND:" + sWriteSendData);
              
                // 요청 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문, [12]입력구분, [13]추후적립여부, [14]적립구분, [15] skt할인상품코드)
                m_cDataCommon.SetSaleApprLog(sTradeDiv, new string[] { sPAY_WAY_CD, sPAY_DTL_CD_01, sTrType, "S", sInPutData, nPayAmt.ToString(), "", "", "", "", "", sWriteSendData, sInPutType, sAfterSaveYn, CmUtil.MidH(sAddInfo, 1, 2), sProductCode, sCustID });

                // 포인트 전문 송수신
                //#20180418 고객 구매이력 정보 표시 및 해피쿠폰 발송 start, 20180503
                //해피쿠폰 발송시 승인 메시지 변경 '포인트 조회중입니다.' -> '쿠폰 발송중입니다.'
                //기존
                //sRet = m_cDataCommon.ExecuteCardIrt(sTrType, sSendData, ref sRecvData, true, sInPutType);
                //변경
                sRet = m_cDataCommon.ExecuteCardIrt(sTrType, sSendData, ref sRecvData, false, sInPutType, sPAY_WAY_CD, sPAY_DTL_CD_01);
                //#20180418 고객 구매이력 정보 표시 및 해피쿠폰 발송 end, 20180503

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

                //#20171116 온라인 쿠폰 제품군코드,상품코드 존재 시 할인 대상이 변경되도록 추가 start, phj
                //기존
                /*
                byte[] bytes = Encoding.Default.GetBytes(sRecvData);
                aIrtRsp = new string[Column.POS_RES_POINT.LEN.Length];
                ItemColumn.ParseMessage(Column.POS_RES_POINT.LEN, Column.POS_RES_POINT.TYPE, bytes, ref nNowPos, ref aIrtRsp);
                */

                //변경
                //온라인쿠폰 조회일 때는  POS_RES_HPCOUPON으로 파싱될 수 있도록 분기처리 해준다. 
                if (sTrType == PosConst.POS_VAN_MASTER.TRADE_ID.VAN_HPY_ELC_A)
                {
                    byte[] bytes = Encoding.Default.GetBytes(sRecvData);
                    aIrtRsp = new string[Column.POS_RES_HPCOUPON.LEN.Length];
                    ItemColumn.ParseMessage(Column.POS_RES_HPCOUPON.LEN, Column.POS_RES_HPCOUPON.TYPE, bytes, ref nNowPos, ref aIrtRsp);
                }
                else
                {
                    byte[] bytes = Encoding.Default.GetBytes(sRecvData);
                    aIrtRsp = new string[Column.POS_RES_POINT.LEN.Length];
                    ItemColumn.ParseMessage(Column.POS_RES_POINT.LEN, Column.POS_RES_POINT.TYPE, bytes, ref nNowPos, ref aIrtRsp);
                }
                //#20171116 온라인 쿠폰 제품군코드,상품코드 존재 시 할인 대상이 변경되도록 추가 end, phj

                // 승인데이터 중 카드번호 마스킹 처리(2017.05.25)
                string sWriteRecvData = CmUtil.MakeLogDataToMask(m_cDevStatus.ICReader.UseYn, sInEncData, sRecvData);
                UserLog.WriteLogFile(UserCom.LOG_SOCK, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                    "[RECV:" + sWriteRecvData);

                // 응답 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문, [12]입력구분, [13]추후적립여부, [14]적립구분, [15] skt할인상품코드)
                m_cDataCommon.SetSaleApprLog(sTradeDiv, new string[] { sPAY_WAY_CD, sPAY_DTL_CD_01, sTrType, "R"
                                                            , sInPutData, CmUtil.DoubleParse(aIrtRsp[Column.POS_RES_POINT.SEQ.ResTrPoint]).ToString()
                                                            , aIrtRsp[Column.POS_RES_POINT.SEQ.ResApprNo].Trim(), CmUtil.MidH(aIrtRsp[Column.POS_RES_POINT.SEQ.ResTrDate], 0, 6), CmUtil.MidH(aIrtRsp[Column.POS_RES_POINT.SEQ.ResTrDate], 6, 4)
                                                            , aIrtRsp[Column.POS_RES_POINT.SEQ.ResStatus].Trim()
                                                            , aIrtRsp[Column.POS_RES_POINT.SEQ.ResMessage1].Trim() + aIrtRsp[Column.POS_RES_POINT.SEQ.ResMessage2].Trim()
                                                            , sWriteRecvData
                                                            , sInPutType, sAfterSaveYn, CmUtil.MidH(sAddInfo, 1, 2), sProductCode, sCustID });
                // - 'O' : 승인 'X' : 거절
                if (aIrtRsp[Column.POS_RES_POINT.SEQ.ResStatus] != "O")
                {
                    if (sPointType == "HGF")        // 해피기프트 응답메시지
                    {
                        sRet = aIrtRsp[Column.POS_RES_POINT.SEQ.ResAddRespon].Trim();
                        if (sRet.Trim() == "" || sRet.Trim() == "0000000000")
                        {
                            sRet = aIrtRsp[Column.POS_RES_POINT.SEQ.ResMessage1].Trim() + "\n" + aIrtRsp[Column.POS_RES_POINT.SEQ.ResMessage2].Trim();
                        }
                    }
                    else
                    {
                        //#20170828 해피포인트 관련 승인 에러시 문구에 '해피포인트' 문구 추가 start
                        //기존
                        //sRet = aIrtRsp[Column.POS_RES_POINT.SEQ.ResMessage1].Trim() + "\n" + aIrtRsp[Column.POS_RES_POINT.SEQ.ResMessage2].Trim();
                        //변경
                        if ((sPAY_WAY_CD == ItemConst.TR_ITEM_ID.ETC_INFO_ITEM && sPAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.ETC_INFO.SAVEPOINT) ||
                            (sPAY_WAY_CD == ItemConst.TR_ITEM_ID.POINT_ITEM && sPAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.POINT_USE.HAPPY_POINT))
                        {
                            sRet = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0789) + "\n" + aIrtRsp[Column.POS_RES_POINT.SEQ.ResMessage1].Trim() + "\n" + aIrtRsp[Column.POS_RES_POINT.SEQ.ResMessage2].Trim();
                        }
                        else
                        {
                            sRet = aIrtRsp[Column.POS_RES_POINT.SEQ.ResMessage1].Trim() + "\n" + aIrtRsp[Column.POS_RES_POINT.SEQ.ResMessage2].Trim();
                        }
                        //#20170828 해피포인트 관련 승인 에러시 문구에 '해피포인트' 문구 추가 end
                    }
                    if (showMessage) WinManager.ErrorMessage(sRet);
                    return sRet;
                }

                sRet = UserCom.RST_OK;
            }
            catch (Exception ex)
            {
                if (showMessage) WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            finally
            {
                //여전법 대응!
                //////////////////////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref sSendData);
                CmUtil.ZeroFillClear(ref sInPutData);
                CmUtil.ZeroFillClear(ref sInEncData);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return sRet;
        }
        #endregion

        #region 포인트 요청 전문 바디 생성
        /// <summary>
        /// 포인트 요청 전문 바디 생성
        /// </summary>
        /// <param name="sPointType"></param>
        /// <param name="sInPutType"></param>
        /// <param name="sInEncData"></param>
        /// <param name="nPayAmt"></param>
        /// <param name="sApprDate"></param>
        /// <param name="sApprNo"></param>
        /// <returns></returns>
        //#해피앱 추후적립 start, sskim
        //기존
        /*
        protected string MakePointBody(string sPointType, string sInPutType, string sInEncData, double nPayAmt, string sApprDate, string sApprNo
                       , string sPassWord, string sProductCode, string sReserved, string sCampaign, string sAddInfo)
        */
        //변경
        protected string MakePointBody(string sPointType, string sInPutType, string sInEncData, double nPayAmt, string sApprDate, string sApprNo
                       , string sPassWord, string sProductCode, string sReserved, string sCampaign, string sAddInfo, string sHpAppAfterSaveYN = "")
        //#해피앱 추후적립 end, sskim
        {
            string sSendData = string.Empty;
            try
            {
                string[] aIrtBody = new string[Column.POS_REQ_POINT.LEN.Length];

                if (m_cDevStatus.ICReader.UseYn == true)     // 여신전문금융업법 적용여부 체크
                    aIrtBody[Column.POS_REQ_POINT.SEQ.ReqDocVer] = PosConst.POS_VAN_MASTER.IRT_VERSION_02;
                else
                    aIrtBody[Column.POS_REQ_POINT.SEQ.ReqDocVer] = PosConst.POS_VAN_MASTER.IRT_VERSION_01;

                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqEntryMode] = sInPutType;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqTrack2] = sInEncData.Trim();
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqFS] = PosConst.VAN_HEXA.FS;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqPointAmt] = nPayAmt.ToString();

                //#해피앱 추후적립 start, sskim
                //해피앱 추후적립 승인취소시 판매구분은 31(해피포인트 기타업무)로 설정.
                //기존
                //aIrtBody[Column.POS_REQ_POINT.SEQ.ReqSaleDiv] = "01";
                //변경
                if (sHpAppAfterSaveYN == "1")
                {
                    aIrtBody[Column.POS_REQ_POINT.SEQ.ReqSaleDiv] = "31";
                }
                else
                {
                    aIrtBody[Column.POS_REQ_POINT.SEQ.ReqSaleDiv] = "01";
                }
                //#해피앱 추후적립 end, sskim

                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqOriginSaleNo] = sApprNo;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqOriginSaleDate] = sApprDate;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqPassWord] = (sPassWord == "") ? "0000000000000000" : sPassWord;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqPointType] = sPointType;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqProductCode] = sProductCode;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqReserved] = sReserved;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqCampaign] = sCampaign; 
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqRS] = PosConst.VAN_HEXA.RS;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqAddInfo] = sAddInfo;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqETX] = PosConst.VAN_HEXA.ETX;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqCR] = PosConst.VAN_HEXA.CR;

                // 포인트 요청 전문 생성
                sSendData = ItemColumn.MakeMessage(aIrtBody, Column.POS_REQ_POINT.LEN, Column.POS_REQ_POINT.TYPE);
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                   System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            finally
            {
                // 여전법 대응 ///////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref sInEncData);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return sSendData;
        }
        #endregion

        #region CODE 변환(포인트구분 획득)
        /// <summary>
        /// 포인트구분 획득
        /// </summary>
        /// <param name="sPosMenuKey"></param>
        /// <returns></returns>
        protected string GetMenuKeyToPointType(string sPosMenuKey)
        {
            string sPointType = "";

            try
            {
                if (sPosMenuKey == PosKey.MENU_KEY.HAPPY_POINT_USE)
                    sPointType = "HPY";
                else if (sPosMenuKey == PosKey.MENU_KEY.SKT)
                    sPointType = "SKT";
                else if (sPosMenuKey == PosKey.MENU_KEY.KT)
                    sPointType = "KTF";
                else if (sPosMenuKey == PosKey.MENU_KEY.LGT)
                    sPointType = "LGT";
                else if (sPosMenuKey == PosKey.MENU_KEY.OLIBANK)
                    sPointType = "HOB";
                else if (sPosMenuKey == PosKey.MENU_KEY.OKCASHBACK)
                    sPointType = "OCB";
                else if (sPosMenuKey == PosKey.MENU_KEY.BLUE_MEMBERS)
                    sPointType = "BLU";
                else if (sPosMenuKey == PosKey.MENU_KEY.RED_MEMBERS)
                    sPointType = "BLU";
                else if (sPosMenuKey == PosKey.MENU_KEY.SPC_EMPLOYEE_DC)
                    sPointType = "SPC";
                else if (sPosMenuKey == PosKey.MENU_KEY.SPC_EMPLOYEE_DC_PAY)
                    sPointType = "SPC";
                else if (sPosMenuKey == PosKey.MENU_KEY.ALIPAY)
                    sPointType = "ALP";
                else if (sPosMenuKey == PosKey.MENU_KEY.KT_VIP || sPosMenuKey == PosKey.MENU_KEY.KT_DOUBLE)
                    sPointType = "KTF";
                else if (sPosMenuKey == PosKey.MENU_KEY.SMILE_PAY )
                    sPointType = "SMP";
                else if (sPosMenuKey == PosKey.MENU_KEY.T_PAY)
                    sPointType = "TPY";
                else if (sPosMenuKey == PosKey.MENU_KEY.HAPPY_GIFTCARD )
                    sPointType = "HGF";
                //#20180413 웰컴카드 신규기능 추가 start,phj
                else if (sPosMenuKey == PosKey.MENU_KEY.WELCOMECARD_DC )
                    sPointType = "MC";
                //#20180413 웰컴카드 신규기능 추가 startend,phj
            }
            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 sPointType;
        }

        protected string GetPayDtlCdToPointType(string sPayWayCd, string sPayDtlCd)
        {
            string sPointType = "";
            try
            {
                if (sPayWayCd == ItemConst.TR_ITEM_ID.MOBILE_COM_POINT)
                {
                    if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_SKT)
                        sPointType = "SKT";
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_KTF)
                        sPointType = "KTF";
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_LGT)
                        sPointType = "LGT";
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILE_COM.OILBANK_POINT)
                        sPointType = "HOB";
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILE_COM.HBLUE_M_POINT)
                        sPointType = "BLU";
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILE_COM.KRED_M_POINT)
                        sPointType = "BLU";
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_KT_VIP)
                        sPointType = "KTF";
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_KT_DOUBLE)
                        sPointType = "KTF";
                    //#20180413 웰컴카드 신규기능 추가 start,phj
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.MOBILE_COM.WELCOMECARD)
                        sPointType = "MC";
                    //#20180413 웰컴카드 신규기능 추가 end,phj
                }
                else if (sPayWayCd == ItemConst.TR_ITEM_ID.POINT_ITEM)
                {
                    if (sPayDtlCd == ItemConst.TR_ITEM_ID.POINT_USE.HAPPY_POINT)
                        sPointType = "HPY";
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.POINT_USE.OKCASHBACK_POINT)
                        sPointType = "OCB";
                }
                else if (sPayWayCd == ItemConst.TR_ITEM_ID.EMP_DC_ITEM)
                {
                    if (sPayDtlCd == ItemConst.TR_ITEM_ID.EMP_DC.SPC)
                        sPointType = "SPC";
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.EMP_DC.SPC_PAY)
                        sPointType = "SPC";
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.EMP_DC.SPC_CHINA)
                        sPointType = "SPC";
                }
                else if (sPayWayCd == ItemConst.TR_ITEM_ID.PAY_ITEM)
                {
                    if (sPayDtlCd == ItemConst.TR_ITEM_ID.PAY.ALIPAY_PAY)
                        sPointType = "ALP";
                    // #Rhee, 20170922 중국 은련페이 추가 start
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.PAY.UNION_PAY)
                        sPointType = "UNP";
                    // #Rhee, 20170922 중국 은련페이 추가 end
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.PAY.SMILE_PAY)
                        sPointType = "SMP";
                    else if (sPayDtlCd == ItemConst.TR_ITEM_ID.PAY.T_PAY)
                        sPointType = "TPY";
                }
                else if (sPayWayCd == ItemConst.TR_ITEM_ID.PPCARD_ITEM)
                {
                    if (sPayDtlCd == ItemConst.TR_ITEM_ID.PPCARD.HP_GIFT)
                        sPointType = "HGF";
                }
            }
            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 sPointType;
        }
        #endregion

        #region 통신사 할인 금액 설정
        ///// <summary>
        ///// 상품별 통신사 할인 금액 설정
        ///// </summary>
        ///// <param name="sCoopDcDiv"></param>
        ///// <param name="nTotDcAmt"></param>
        ///// <param name="nTotSaleAmt"></param>
        ///// <returns></returns>
        //public double SetPluCoopCardDcAmount(string sCoopDcDiv, double nTotDcAmt, double nTotSaleAmt)
        //{
        //    double nApplyAmt = 0, nDisAmt = 0, nMaxAmt = 0;
        //    int nMaxRow = 0;

        //    try
        //    {
        //        ArrayList alSaleItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);

        //        for (int i = 0; i < alSaleItem.Count; i++)
        //        {
        //            Column.TR_PLU.DATA cPluItem = (Column.TR_PLU.DATA)alSaleItem[i];

        //            if (cPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL || cPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.CANCEL) continue;    // 지정취소
        //            if (cPluItem.COOP_CARD_DC_NOADM_YN == "1") continue;    // 통신사 할인 불가 여부(0:가능, 1:불가)

        //            nDisAmt = CmUtil.DoubleMultiplication(nTotDcAmt, CmUtil.DoubleDivision(cPluItem.BILL_AMT, nTotSaleAmt));
        //            nDisAmt = CmUtil.MathRounds(nDisAmt, m_cPosStatus.Mst.DcRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.DcRudDwLoc));

        //            if (sCoopDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.OILBANK_POINT
        //                || sCoopDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.HBLUE_M_POINT || sCoopDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.KRED_M_POINT)
        //            {
        //                // 제휴 포인트 할인
        //                cPluItem.POINT_DC_DIV = sCoopDcDiv;
        //                cPluItem.POINT_DC_AMT = nDisAmt;
        //            }
        //            else
        //            {
        //                // 통신사 할인
        //                cPluItem.COOP_CARD_DC_DIV = sCoopDcDiv;
        //                cPluItem.COOP_CARD_DC_AMT = nDisAmt;
        //            }

        //            m_cDataService.UpdatePluItemAmount(cPluItem);

        //            nApplyAmt = CmUtil.DoubleAdd(nApplyAmt, nDisAmt);
        //            if (nMaxAmt == 0 || nMaxAmt < cPluItem.BILL_AMT)
        //            {
        //                nMaxAmt = cPluItem.BILL_AMT;
        //                nMaxRow = i;
        //            }
        //        }

        //        // 자투리 금액 
        //        if (nTotDcAmt != nApplyAmt)
        //        {
        //            Column.TR_PLU.DATA cPluItem = (Column.TR_PLU.DATA)alSaleItem[nMaxRow];

        //            if (sCoopDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.OILBANK_POINT
        //                || sCoopDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.HBLUE_M_POINT || sCoopDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.KRED_M_POINT)
        //            {
        //                // 제휴 포인트 할인
        //                cPluItem.POINT_DC_AMT = CmUtil.DoubleAdd(cPluItem.POINT_DC_AMT, CmUtil.DoubleSubtraction(nTotDcAmt, nApplyAmt));
        //            }
        //            else
        //            {
        //                // 통신사 할인
        //                cPluItem.COOP_CARD_DC_AMT = CmUtil.DoubleAdd(cPluItem.COOP_CARD_DC_AMT, CmUtil.DoubleSubtraction(nTotDcAmt, nApplyAmt));
        //            }

        //            m_cDataService.UpdatePluItemAmount(cPluItem);
        //        }

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

        

        ///// <summary>
        ///// 상품별 통신사 할인 금액 삭제
        ///// </summary>
        ///// <returns></returns>
        //public double ClearPluCoopCardDcAmount(string sCoopDcDiv)
        //{
        //    try
        //    {
        //        ArrayList alSaleItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);

        //        for (int i = 0; i < alSaleItem.Count; i++)
        //        {
        //            Column.TR_PLU.DATA cPluItem = (Column.TR_PLU.DATA)alSaleItem[i];
        //            if (cPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL || cPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.CANCEL) continue;// 지정취소

        //            if (sCoopDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.OILBANK_POINT
        //                || sCoopDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.HBLUE_M_POINT || sCoopDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.KRED_M_POINT)
        //            {
        //                // 제휴포인트 할인
        //                if (cPluItem.POINT_DC_AMT > 0)
        //                {
        //                    cPluItem.POINT_DC_DIV = "";
        //                    cPluItem.POINT_DC_AMT = 0;

        //                    m_cDataService.UpdatePluItemAmount(cPluItem);
        //                }
        //            }
        //            else
        //            {
        //                // 통신사 할인
        //                if (cPluItem.COOP_CARD_DC_AMT > 0)
        //                {
        //                    cPluItem.COOP_CARD_DC_DIV = "";
        //                    cPluItem.COOP_CARD_DC_AMT = 0;

        //                    m_cDataService.UpdatePluItemAmount(cPluItem);
        //                }
        //            }
        //        }
        //    }
        //    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 0;
        //}
        #endregion

        #region 상품아이템에 할인 금액 설정
        /// <summary>
        /// 상품아이템에 할인 금액 설정
        /// </summary>
        /// <param name="nSelRow"></param>
        /// <param name="sPayDcDiv">결제수단코드</param>
        /// <param name="sCouponCd">쿠폰일때 쿠폰코드</param>
        /// <param name="nTotDcAmt">할인금액</param>
        /// <returns></returns>
        public double SetPluDiscountAmount(int nSelRow, string sPayDcDiv, string sCouponCd, double nTotDcAmt)
        {
            return SetPluDiscountAmount(nSelRow, sPayDcDiv, sCouponCd, nTotDcAmt, false);
        }
        public double SetPluDiscountAmount(int nSelRow, string sPayDcDiv, string sCouponCd, double nTotDcAmt, bool bAddDcAmt)
        {
            double nTotSaleAmt = 0, nApplyAmt = 0, nMaxAmt = 0;     
            int nMaxRow = 0;

            try
            {
                ArrayList alSaleItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);
                if (nSelRow >= 0)
                {
                    ///////////////////////////////////////////////////////////////////////////////////////////////
                    // 특정 상품대상 할인 처리
                    ///////////////////////////////////////////////////////////////////////////////////////////////
                    Column.TR_PLU.DATA cPluItem = (Column.TR_PLU.DATA)alSaleItem[nSelRow];

                    // 상품아이템에 할인 금액 설정
                    SetPluDiscountAmount(cPluItem, sPayDcDiv, sCouponCd, nTotDcAmt, bAddDcAmt);

                    return nTotDcAmt;
                }

                ///////////////////////////////////////////////////////////////////////////////////////////////
                // 전체 상품대상 할인 처리
                ///////////////////////////////////////////////////////////////////////////////////////////////
                // 메뉴코드 획득
                string sMenuKey = m_cDataCommon.GetPayCdToMenuKey(sPayDcDiv.Substring(0, 2), sPayDcDiv.Substring(2, 2));

                // 대상 상품 합계금액 획득
                for (int i = 0; i < alSaleItem.Count; i++)
                {
                    Column.TR_PLU.DATA cPluItem = (Column.TR_PLU.DATA)alSaleItem[i];

                    // 대상상품 할인 가능여부 체크
                    if (m_cDataService.CheckPluDiscountAble(sMenuKey, cPluItem) == false) continue;
                        
                    nTotSaleAmt = CmUtil.DoubleAdd(nTotSaleAmt, cPluItem.BILL_AMT);     // 매출금액
                }

                // 대상 상품에 할인금액 분배
                for (int i = 0; i < alSaleItem.Count; i++)
                {
                    Column.TR_PLU.DATA cPluItem = (Column.TR_PLU.DATA)alSaleItem[i];

                    // 대상상품 할인 가능여부 체크
                    if (m_cDataService.CheckPluDiscountAble(sMenuKey, cPluItem) == false) continue;

                    double nDisAmt = CmUtil.DoubleMultiplication(nTotDcAmt, CmUtil.DoubleDivision(cPluItem.BILL_AMT, nTotSaleAmt));
                    nDisAmt = CmUtil.MathRounds(nDisAmt, m_cPosStatus.Mst.ItemRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.ItemRudDwLoc));

                    // 상품아이템에 할인 금액 설정
                    SetPluDiscountAmount(cPluItem, sPayDcDiv, sCouponCd, nDisAmt, bAddDcAmt);
                    // 할인적용금액 합계
                    nApplyAmt = CmUtil.DoubleAdd(nApplyAmt, nDisAmt);       
                        
                    if (nMaxAmt == 0 || nMaxAmt < cPluItem.BILL_AMT)
                    {
                        nMaxAmt = cPluItem.BILL_AMT;
                        nMaxRow = i;
                    }
                }

                // 자투리 금액 발생(금액 큰 상품에 설정)
                if (nTotDcAmt != nApplyAmt && !nApplyAmt.Equals(0))
                {
                    Column.TR_PLU.DATA cPluItem = (Column.TR_PLU.DATA)alSaleItem[nMaxRow];
                    // 상품아이템에 할인 금액 설정
                    SetPluDiscountAmount(cPluItem, sPayDcDiv, sCouponCd, CmUtil.DoubleSubtraction(nTotDcAmt, nApplyAmt), true);
                }
            }
            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 nTotDcAmt;
        }

        /// <summary>
        /// 상품아이템에 할인 금액 설정
        /// </summary>
        public double SetPluDiscountAmount(Column.TR_PLU.DATA cPluItem, string sPayDcDiv, string sCouponCd, double nTotDcAmt, bool bAddDcAmt)
        {
            try
            {
                if (sPayDcDiv.Substring(0, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM_POINT &&
                   (sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.OILBANK_POINT || sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.HBLUE_M_POINT
                        || sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.KRED_M_POINT))
                {
                    // 제휴포인트 할인
                    cPluItem.POINT_DC_DIV = sPayDcDiv;
                    if ( bAddDcAmt == true)
                        cPluItem.POINT_DC_AMT = CmUtil.DoubleAdd(cPluItem.POINT_DC_AMT, nTotDcAmt);
                    else
                        cPluItem.POINT_DC_AMT = nTotDcAmt;
                }
                else if (sPayDcDiv.Substring(0, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM_POINT &&
                        (sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_SKT || sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_LGT
                            || sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_KTF || sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_KT_VIP
                            || sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_KT_DOUBLE
                             //#20180413 웰컴카드 신규기능 추가 start,phj
                            || sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.WELCOMECARD
                            //#20180413 웰컴카드 신규기능 추가 end,phj
                        ))
                {
                    // 통신사 할인
                    cPluItem.COOP_CARD_DC_DIV = sPayDcDiv;

                    if ( bAddDcAmt == true)
                        cPluItem.COOP_CARD_DC_AMT = CmUtil.DoubleAdd(cPluItem.COOP_CARD_DC_AMT, nTotDcAmt);
                    else
                        cPluItem.COOP_CARD_DC_AMT = nTotDcAmt;
                }
                else if (sPayDcDiv.Substring(0, 2) == ItemConst.TR_ITEM_ID.COUPON_ITEM &&
                        (sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.COUPON.STORE || sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.COUPON.INCARD
                            || sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.COUPON.ONLINE))
                {
                    // 쿠폰 할인
                    cPluItem.CPN_DC_DIV = sPayDcDiv;
                    cPluItem.CPN_NO = sCouponCd;
                    if ( bAddDcAmt == true)
                        cPluItem.CPN_DC_AMT = CmUtil.DoubleAdd(cPluItem.CPN_DC_AMT, nTotDcAmt);
                    else
                        cPluItem.CPN_DC_AMT = nTotDcAmt;
                }
                else if (sPayDcDiv.Substring(0, 2) == ItemConst.TR_ITEM_ID.USER_DC_ITEM &&
                        (sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.USER_DC.KAIST_DC))
                {
                    // 임의할인
                    cPluItem.DC_DIV = sPayDcDiv;
                    cPluItem.DC_TYPE = "1";
                    if (bAddDcAmt == true)
                        cPluItem.ITEM_DC_AMT = CmUtil.DoubleAdd(cPluItem.ITEM_DC_AMT, nTotDcAmt);
                    else
                        cPluItem.ITEM_DC_AMT = nTotDcAmt;
                }
                else if (sPayDcDiv.Substring(0, 2) == ItemConst.TR_ITEM_ID.ORDER_ITEM &&
                        (sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.ORDER.HPORDER_REVDC))
                {
                    // 기타할인
                    cPluItem.ETC_DC_DIV = sPayDcDiv;
                    if (bAddDcAmt == true)
                        cPluItem.ETC_DC_AMT = CmUtil.DoubleAdd(cPluItem.ETC_DC_AMT, nTotDcAmt);
                    else
                        cPluItem.ETC_DC_AMT = nTotDcAmt;
                }
                m_cDataService.UpdatePluItemAmount(cPluItem);
            }
            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 nTotDcAmt;
        }

        /// <summary>
        /// 상품아이템에 할인 금액 삭제
        /// </summary>
        /// <param name="sPayDcDiv"></param>
        /// <param name="sCouponCd"></param>
        /// <returns></returns>
        public double ClearPluDiscountAmount(string sPayDcDiv, string sCouponCd)
        {
            try
            {
                ArrayList alSaleItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);

                for (int i = 0; i < alSaleItem.Count; i++)
                {
                    Column.TR_PLU.DATA cPluItem = (Column.TR_PLU.DATA)alSaleItem[i];

                    if (cPluItem.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL || cPluItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.CANCEL) continue;// 지정취소

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

        /// <summary>
        /// 상품아이템에 할인 금액 삭제
        /// </summary>
        /// <param name="cPluItem"></param>
        /// <param name="sPayDcDiv"></param>
        /// <param name="sCouponCd"></param>
        /// <param name="nSubDcAmt"></param>
        /// <returns></returns>
        public double ClearPluDiscountAmount(Column.TR_PLU.DATA cPluItem, string sPayDcDiv, string sCouponCd, double nSubDcAmt)
        {
            double nDcAmt = 0;
            try
            {
                if (sPayDcDiv.Substring(0, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM_POINT &&
                    (sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.OILBANK_POINT || sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.HBLUE_M_POINT
                        || sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.KRED_M_POINT))
                {
                    // 제휴포인트 할인
                    nDcAmt = (cPluItem.POINT_DC_AMT > nSubDcAmt) ? nSubDcAmt : cPluItem.POINT_DC_AMT;
                    if (nSubDcAmt > 0)
                        cPluItem.POINT_DC_AMT = CmUtil.DoubleSubtraction(cPluItem.POINT_DC_AMT, nDcAmt);
                    else
                        cPluItem.POINT_DC_AMT = 0;

                    if (cPluItem.POINT_DC_AMT <= 0)  cPluItem.POINT_DC_DIV = "0000";
                }
                else if (sPayDcDiv.Substring(0, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM_POINT &&
                        (sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_SKT || sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_LGT
                            || sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_KTF || sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_KT_VIP
                            //#20180413 웰컴카드 신규기능 추가 start,phj
                            || sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.WELCOMECARD
                            //#20180413 웰컴카드 신규기능 추가 end,phj
                            || sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_KT_DOUBLE))
                {
                    // 통신사 할인
                    nDcAmt = (cPluItem.COOP_CARD_DC_AMT > nSubDcAmt) ? nSubDcAmt : cPluItem.COOP_CARD_DC_AMT;
                    if (nSubDcAmt > 0)
                        cPluItem.COOP_CARD_DC_AMT = CmUtil.DoubleSubtraction(cPluItem.COOP_CARD_DC_AMT, nDcAmt);
                    else
                        cPluItem.COOP_CARD_DC_AMT = 0;

                    if (cPluItem.COOP_CARD_DC_AMT == 0) cPluItem.COOP_CARD_DC_DIV = "0000";
                }
                else if (sPayDcDiv.Substring(0, 2) == ItemConst.TR_ITEM_ID.COUPON_ITEM &&
                        (sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.COUPON.STORE || sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.COUPON.INCARD
                            || sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.COUPON.ONLINE))
                {
                    if (cPluItem.CPN_DC_DIV == sPayDcDiv && cPluItem.CPN_NO == sCouponCd)
                    {
                        // 쿠폰 할인
                        nDcAmt = (cPluItem.CPN_DC_AMT > nSubDcAmt) ? nSubDcAmt : cPluItem.CPN_DC_AMT;
                        if (nSubDcAmt > 0)
                            cPluItem.CPN_DC_AMT = CmUtil.DoubleSubtraction(cPluItem.CPN_DC_AMT, nDcAmt);
                        else
                            cPluItem.CPN_DC_AMT = 0;

                        if (cPluItem.CPN_DC_AMT == 0)
                        {
                            cPluItem.CPN_DC_DIV = "0000";
                            cPluItem.CPN_NO = "";
                        }
                    }
                }
                else if (sPayDcDiv.Substring(0, 2) == ItemConst.TR_ITEM_ID.USER_DC_ITEM &&
                       (sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.USER_DC.KAIST_DC))
                {
                    // 임의할인
                    nDcAmt = (cPluItem.ITEM_DC_AMT > nSubDcAmt) ? nSubDcAmt : cPluItem.ITEM_DC_AMT;
                    if (nSubDcAmt > 0)
                        cPluItem.ITEM_DC_AMT = CmUtil.DoubleSubtraction(cPluItem.ITEM_DC_AMT, nDcAmt);
                    else
                        cPluItem.ITEM_DC_AMT = 0;

                    if (cPluItem.ITEM_DC_AMT <= 0)
                    {
                        cPluItem.DC_DIV = "0000";
                        cPluItem.DC_TYPE = "0";
                    }
                }
                else if (sPayDcDiv.Substring(0, 2) == ItemConst.TR_ITEM_ID.ORDER_ITEM &&
                        (sPayDcDiv.Substring(2, 2) == ItemConst.TR_ITEM_ID.ORDER.HPORDER_REVDC))
                {
                    // 기타할인
                    nDcAmt = (cPluItem.ETC_DC_AMT > nSubDcAmt) ? nSubDcAmt : cPluItem.ETC_DC_AMT;
                    if (nSubDcAmt > 0)
                        cPluItem.ETC_DC_AMT = CmUtil.DoubleSubtraction(cPluItem.ETC_DC_AMT, nDcAmt);
                    else
                        cPluItem.ETC_DC_AMT = 0;

                    if (cPluItem.ETC_DC_AMT <= 0) cPluItem.ETC_DC_DIV = "0000";
                }
                m_cDataService.UpdatePluItemAmount(cPluItem);
            }
            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 nDcAmt;
        }
        /// <summary>
        /// 상품아이템에 할인 금액 삭제
        /// </summary>
        /// <param name="sPayDcDiv"></param>
        /// <param name="sCouponCd"></param>
        /// <returns></returns>
        public double SubPluDiscountAmount(string sPayDcDiv, string sCouponCd, double nTotDcAmt)
        {
            double nTotSaleAmt = 0, nApplyAmt = 0, nMaxAmt = 0;
            int nMaxRow = 0;
            try
            {
                ArrayList alSaleItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);
                ///////////////////////////////////////////////////////////////////////////////////////////////
                // 전체 상품대상 할인 처리
                ///////////////////////////////////////////////////////////////////////////////////////////////
                // 메뉴코드 획득
                string sMenuKey = m_cDataCommon.GetPayCdToMenuKey(sPayDcDiv.Substring(0, 2), sPayDcDiv.Substring(2, 2));

                // 대상 상품 합계금액 획득
                for (int i = 0; i < alSaleItem.Count; i++)
                {
                    Column.TR_PLU.DATA cPluItem = (Column.TR_PLU.DATA)alSaleItem[i];

                    // 대상상품 할인 가능여부 체크
                    if (m_cDataService.CheckPluDiscountAble(sMenuKey, cPluItem) == false) continue;
                        
                    nTotSaleAmt = CmUtil.DoubleAdd(nTotSaleAmt, cPluItem.BILL_AMT);     // 매출금액
                }

                // 대상 상품에 할인금액 분배 하여 복구
                for (int i = 0; i < alSaleItem.Count; i++)
                {
                    Column.TR_PLU.DATA cPluItem = (Column.TR_PLU.DATA)alSaleItem[i];

                    // 대상상품 할인 가능여부 체크
                    if (m_cDataService.CheckPluDiscountAble(sMenuKey, cPluItem) == false) continue;

                    double nDisAmt = CmUtil.DoubleMultiplication(nTotDcAmt, CmUtil.DoubleDivision(cPluItem.BILL_AMT, nTotSaleAmt));
                    nDisAmt = CmUtil.MathRounds(nDisAmt, m_cPosStatus.Mst.ItemRudDwLocMethd, CmUtil.IntParse(m_cPosStatus.Mst.ItemRudDwLoc));

                    // 상품아이템에 할인 금액 복구
                    nDisAmt = ClearPluDiscountAmount(cPluItem, sPayDcDiv, sCouponCd, nDisAmt);
                    // 할인적용금액 합계
                    nApplyAmt = CmUtil.DoubleAdd(nApplyAmt, nDisAmt);       
                        
                    if (nMaxAmt == 0 || nMaxAmt < cPluItem.BILL_AMT)
                    {
                        nMaxAmt = cPluItem.BILL_AMT;
                        nMaxRow = i;
                    }
                }

                // 자투리 금액 발생(금액 큰 상품에 설정)
                if (nTotDcAmt != nApplyAmt)
                {
                    Column.TR_PLU.DATA cPluItem = (Column.TR_PLU.DATA)alSaleItem[nMaxRow];
                    // 상품아이템에 할인 금액 설정
                    ClearPluDiscountAmount(cPluItem, sPayDcDiv, sCouponCd, CmUtil.DoubleSubtraction(nTotDcAmt, nApplyAmt));
                }
            }
            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 nTotDcAmt;
        }
        /// <summary>
        /// 상품별 통신사 할인 금액 설정(VIP 증정 => 최고 단가 상품 1개만 적용)
        /// </summary>
        /// <param name="sCoopDcDiv"></param>
        /// <returns></returns>
        public double SetPluMaxOneCoopCardDcAmount(string sCoopDcDiv, string sCmpGradeCd, double nDisAmt)
        {
            double nSalePrice = 0;
            try
            {
                ArrayList alSaleItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);

                // 제휴사(통신사) VIP증정 대상 상품 체크
                int nSelRow = -1;
                nSalePrice = m_cDataCommon.SrarchTermCoopCmpDcItem(sCoopDcDiv.Substring(0, 2), sCoopDcDiv.Substring(2, 2), sCmpGradeCd, ref nSelRow);
                if (nSelRow < 0) return 0;

                // 
                Column.TR_PLU.DATA cPluItem = (Column.TR_PLU.DATA)alSaleItem[nSelRow];

                // 상품아이템에 할인 금액 설정
                SetPluDiscountAmount(cPluItem, sCoopDcDiv, "", nDisAmt, false);
            }
            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 nDisAmt;
        }
        #endregion

        #region 카드 번호 암호화
        /// <summary>
        /// 카드 번호 암호화
        /// </summary>
        /// <param name="sInData"></param>
        /// <param name="sInMaskData">마스킹데이터</param>
        /// <param name="sInEncData">암호화데이터</param>
        /// <returns></returns>
        protected bool EncryptedCardNo(string sInData, ref string sInMaskData, ref string sInEncData)
        {
            try
            {
                // 카드번호 암호화 처리
                string sEncData = m_cDeviceICReader.GetEncryptedCardNo(sInData).Trim();
                if (CmUtil.MidH(sEncData, 0, 2) == "00")
                {
                    sInEncData = CmUtil.MidH(sEncData, 2, 512).Trim();                          // 암호화 데이터
                    sInMaskData = CmUtil.MidH(sEncData, 514, sEncData.Length - 514).Trim();     // 마스킹 데이터

                    return true;
                }
                else
                {
                    // 암호화 처리 실패!
                    UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", "Fail =>" + sInData);
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0280);
                }
            }
            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 false;
        }
        #endregion

        #region Cat 단말기 전문생성
        /// <summary>
        /// Cat 단말기 전문생성
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        protected string MakeCatTerminalData(string sAppLogDiv, string[] aParam)
        {

            string sSendData = string.Empty;
            string[] aIrtBody = null;
            try
            {
                switch (m_cPosStatus.Base.OlePosCATModel)
                {
                    case PosConst.CAT_MODEL_DIV._KOR_SPCN:
                        {
                            #region
                            //단말기 출력 여부 옵션 셋팅! 
                            if (CmUtil.IsNull(PosMstManager.GetPosOption(POS_OPTION.OPT407), "0") == "1")
                                aParam[10] = "P";
                            else
                                aParam[10] = "";

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

                            aIrtBody[Column.POS_REQ_SPCN_CAT.SEQ.TranType] = aParam[0];
                            aIrtBody[Column.POS_REQ_SPCN_CAT.SEQ.TrandeType] = aParam[1];
                            aIrtBody[Column.POS_REQ_SPCN_CAT.SEQ.DivMonth] = aParam[2];
                            aIrtBody[Column.POS_REQ_SPCN_CAT.SEQ.TotAmt] = aParam[3];
                            aIrtBody[Column.POS_REQ_SPCN_CAT.SEQ.ServiceAmt] = aParam[4];
                            aIrtBody[Column.POS_REQ_SPCN_CAT.SEQ.Vat] = aParam[5];
                            aIrtBody[Column.POS_REQ_SPCN_CAT.SEQ.OrgAppNo] = aParam[6];
                            aIrtBody[Column.POS_REQ_SPCN_CAT.SEQ.OrgDate] = aParam[7];
                            aIrtBody[Column.POS_REQ_SPCN_CAT.SEQ.PointTradeType] = aParam[8];
                            aIrtBody[Column.POS_REQ_SPCN_CAT.SEQ.GoodsCode] = aParam[9];
                            aIrtBody[Column.POS_REQ_SPCN_CAT.SEQ.PrintFlag] = aParam[10];
                            aIrtBody[Column.POS_REQ_SPCN_CAT.SEQ.AddItem] = aParam[11];

                            sSendData = ItemColumn.MakeMessage(aIrtBody, Column.POS_REQ_SPCN_CAT.LEN, Column.POS_REQ_SPCN_CAT.TYPE);
                            #endregion
                            break;
                        }
                    case PosConst.CAT_MODEL_DIV._CHN_SAND:
                        {
                            // 샨더
                            #region
                            aIrtBody = new string[Column.POS_REQ_SAND_CAT.LEN.Length];

                            aIrtBody[Column.POS_REQ_SAND_CAT.SEQ.OperateType] = "A0";
                            aIrtBody[Column.POS_REQ_SAND_CAT.SEQ.TransType] = (sAppLogDiv == PosConst.CANCEL_DIV.NORMAL ? "30" : "40");
                            aIrtBody[Column.POS_REQ_SAND_CAT.SEQ.CardType] = aParam[16];
                            aIrtBody[Column.POS_REQ_SAND_CAT.SEQ.CashRegNo] = CmUtil.RightH(m_cPosStatus.Base.CashierNo, 3);
                            aIrtBody[Column.POS_REQ_SAND_CAT.SEQ.CasherNo] = CmUtil.RightH(m_cPosStatus.Base.CashierNo, 3);
                            aIrtBody[Column.POS_REQ_SAND_CAT.SEQ.Amount] = CmUtil.DoubleParse(CmUtil.DoubleMultiplication(CmUtil.DoubleParse(aParam[3]), 100).ToString()).ToString();
                            aIrtBody[Column.POS_REQ_SAND_CAT.SEQ.CashTraceNo] = DateTime.Now.ToString("HHmmss");
                            aIrtBody[Column.POS_REQ_SAND_CAT.SEQ.OrignTrace] = aParam[6];
                            aIrtBody[Column.POS_REQ_SAND_CAT.SEQ.Reserved] = "";

                            sSendData = ItemColumn.MakeMessage(aIrtBody, Column.POS_REQ_SAND_CAT.LEN, Column.POS_REQ_SAND_CAT.TYPE);
                            #endregion
                            break;
                        }
                    case PosConst.CAT_MODEL_DIV._CHN_UNION:
                        {
                            // 은련
                            #region
                            //전문값 형식 오류로 수정,Column.POS_REQ_UNION_CAT.TYPE 함께 수정; girak.kim;2017.08.18
                            //AS-IS 참고하여 자릿수에 뒤에 공백 붙인것을 앞으로, 숫자 자리숫에 공백은 0로 치환 등
                            //기존 : 92      000     0010          20170817                  630                                                                                                    
                            //>>    (공백)8,8,2,(0)12,공백(8),공백(12),공백(6),3,공백(100)
                            aIrtBody = new string[Column.POS_REQ_UNION_CAT.LEN.Length];

                            aIrtBody[Column.POS_REQ_UNION_CAT.SEQ.PosNo] = m_cPosStatus.Base.PosNo;
                            aIrtBody[Column.POS_REQ_UNION_CAT.SEQ.CasherNo] = CmUtil.RightH(m_cPosStatus.Base.CashierNo, 8); //CmUtil.RightH(m_cPosStatus.Base.CashierNo, 3);
                            aIrtBody[Column.POS_REQ_UNION_CAT.SEQ.TransType] = (sAppLogDiv == PosConst.CANCEL_DIV.NORMAL ? "00" : "01");
                            aIrtBody[Column.POS_REQ_UNION_CAT.SEQ.Amount] = CmUtil.DoubleParse(CmUtil.DoubleMultiplication(CmUtil.DoubleParse(aParam[3]), 100).ToString()).ToString();
                            aIrtBody[Column.POS_REQ_UNION_CAT.SEQ.AppDate] = aParam[7].Trim();// (aParam[7].Trim() == "" ? DateTime.Now.ToString("yyyyMMdd") : aParam[7].Trim());
                            aIrtBody[Column.POS_REQ_UNION_CAT.SEQ.OriginVAppno] = "";
                            aIrtBody[Column.POS_REQ_UNION_CAT.SEQ.OriginCAppno] = aParam[6];
                            string sNow = DateTime.Now.ToString("hhmmssfff");
                            aIrtBody[Column.POS_REQ_UNION_CAT.SEQ.LRCCheckSum] = CmUtil.MidH(sNow, 3, 1) + CmUtil.MidH(sNow, 5, 1) + CmUtil.MidH(sNow, 7, 1);
                            aIrtBody[Column.POS_REQ_UNION_CAT.SEQ.AllPeople] = "";

                            sSendData = ItemColumn.MakeMessage(aIrtBody, Column.POS_REQ_UNION_CAT.LEN, Column.POS_REQ_UNION_CAT.TYPE);
                            #endregion
                            break;
                        }
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                   System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);

            }
            finally
            {
                CmUtil.ZeroFillClear(ref aIrtBody);
            }
            return sSendData;

        }
        #endregion

        #region Cat단말기 전문 송/수신 처리

        /// <summary>
        /// Cat단말기 전문 생성 및 송/수신 공통 처리
        /// </summary>
        /// <param name="sAppType"></param>
        /// <param name="sAppLogDiv"></param>
        /// <param name="aParam"></param>
        /// <param name="sWayCd"></param>
        /// <param name="sDtlCd"></param>
        /// <param name="aIrtDTLRsp"></param>
        /// <param name="sRecvMsg"></param>
        /// <param name="sInputType"></param>
        /// <returns></returns>
        protected bool CatTerminalExecuteIrtCom(string sAppType, string sAppLogDiv, string[] aParam, string sWayCd, string sDtlCd, ref string[] aIrtDTLRsp, ref string sRecvMsg, ref string sInputType)
        {
            return CatTerminalExecuteIrtCom(sAppType, sAppLogDiv, aParam, sWayCd, sDtlCd, ref aIrtDTLRsp, ref  sRecvMsg, ref sInputType, true);
        }
        
        /// <summary>
        /// Cat단말기 전문 생성 및 송/수신 공통 처리
        /// </summary>
        /// <param name="sAppType"></param>
        /// <param name="sAppLogDiv"></param>
        /// <param name="aParam"></param>
        /// <param name="sWayCd"></param>
        /// <param name="sDtlCd"></param>
        /// <param name="aIrtDTLRsp"></param>
        /// <param name="sRecvMsg"></param>
        /// <param name="sInputType"></param>
        /// <param name="bMsgView"></param>
        /// <returns></returns>
        protected bool CatTerminalExecuteIrtCom(string sAppType, string sAppLogDiv, string[] aParam, string sWayCd, string sDtlCd, ref string[] aIrtDTLRsp, ref string sRecvMsg, ref string sInputType, bool bMsgView)
        {
            bool bRet = false;            
            string sSendData = "";
            int iRet = -99;

            try
            {
                string sRecvdData = "";

                // 전송 데이터 생성
                sSendData = MakeCatTerminalData(sAppLogDiv, aParam);

                //UserLog.WriteLogFile(UserCom.LOG_SOCK, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                //                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                //                    "[SEND:[" + sSendData+"]");
                // 요청 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문)
                m_cDataCommon.SetSaleApprLog(sAppLogDiv, new string[] { sWayCd, sDtlCd, sAppType, "S", "", CmUtil.DoubleParse(aParam[3]).ToString(), "", "", "", "", "", sSendData });

                UserLog.WriteLogFile(UserCom.LOG_SOCK, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                   System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                   "[SEND:[" + sSendData + "]"); 

                //전문전송
                iRet = m_cCatTerminal.SPCNSecuCatApprove(sSendData, ref sRecvdData);

                if (iRet < 0)
                {
                    sRecvMsg = string.Format("{0} - {1}", iRet, sRecvdData);
                    UserLog.WriteLogFile(UserCom.LOG_ERROR,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                     sRecvMsg);

                    if (bMsgView == true)
                        WinManager.ErrorMessage(sRecvMsg);
                    

                    return false;
                }

                UserLog.WriteLogFile(UserCom.LOG_SOCK, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                    "[RECV<<:" + sRecvdData);

                byte[] bytes = Encoding.Default.GetBytes(sRecvdData);

                switch (m_cPosStatus.Base.OlePosCATModel)
                {
                    case PosConst.CAT_MODEL_DIV._KOR_SPCN:
                        {
                            // 국내 SPNC

                            int nNowPos = 2;

                            ItemColumn.ParseMessage(Column.POS_RES_SPCN_CAT.LEN, Column.POS_RES_SPCN_CAT.TYPE, bytes, ref nNowPos, ref aIrtDTLRsp);


                            // 응답 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문)
                            m_cDataCommon.SetSaleApprLog(sAppLogDiv, new string[] { sWayCd, sDtlCd, sAppType, "R"
                                                            , aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.CardBinData], CmUtil.DoubleParse(aParam[3]).ToString()
                                                            , aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AppNo], CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AppDatatime], 0, 6), CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AppDatatime], 6, 4)
                                                            , aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.Status].Trim()
                                                            , aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.Message].Trim()
                                                            , sRecvdData });


                            if (aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.Status].Trim() != "00")
                            {
                                sRecvMsg = string.Format("{0} - {1}", aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.Status], aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.Message]);
                                UserLog.WriteLogFile(UserCom.LOG_ERROR,
                                                 System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                                 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                                 System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                                 sRecvMsg);

                                if (bMsgView == true)
                                    WinManager.ErrorMessage(sRecvMsg);

                                return false;
                            }

                            switch (aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.PosEntryMode].Trim())
                            {
                                case "02":
                                case "04":
                                    sInputType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_SWIP;
                                    break;
                                case "03":
                                    sInputType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_IC;
                                    break;
                                default:
                                    sInputType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_KEYIN;
                                    break;
                            }

                            //추가 항목 첫번째 *표 제거!
                            if (aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AddItem].StartsWith("*") && aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AddItem].Trim().Length > 0)
                                aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AddItem] = aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AddItem].Substring(1);

                            break;
                        }

                    case PosConst.CAT_MODEL_DIV._CHN_SAND:
                        {
                            // 샨더

                            int nNowPos = 0;
                            ItemColumn.ParseMessage(Column.POS_RES_SAND_CAT.LEN, Column.POS_RES_SAND_CAT.TYPE, bytes, ref nNowPos, ref aIrtDTLRsp);


                            // 응답 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문)
                            m_cDataCommon.SetSaleApprLog(sAppLogDiv, new string[] { sWayCd, sDtlCd, sAppType, "R"
                                                            , aIrtDTLRsp[Column.POS_RES_SAND_CAT.SEQ.CardNo], CmUtil.DoubleParse(aParam[3]).ToString()
                                                            , aIrtDTLRsp[Column.POS_RES_SAND_CAT.SEQ.Auth_Code], CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SAND_CAT.SEQ.TransDate], 0, 8), CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SAND_CAT.SEQ.TransTime], 0, 6)
                                                            , aIrtDTLRsp[Column.POS_RES_SAND_CAT.SEQ.ResponseCode].Trim()
                                                            , aIrtDTLRsp[Column.POS_RES_SAND_CAT.SEQ.ResponseMsg].Trim()
                                                            , sRecvdData });


                            if (aIrtDTLRsp[Column.POS_RES_SAND_CAT.SEQ.ResponseCode].Trim() != "00")
                            {
                                sRecvMsg = string.Format("{0} - {1}", aIrtDTLRsp[Column.POS_RES_SAND_CAT.SEQ.ResponseCode], aIrtDTLRsp[Column.POS_RES_SAND_CAT.SEQ.ResponseMsg]);
                                UserLog.WriteLogFile(UserCom.LOG_ERROR,
                                                 System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                                 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                                 System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                                 sRecvMsg);

                                if (bMsgView == true)
                                    WinManager.ErrorMessage(sRecvMsg);

                                return false;
                            }
                            break;
                        }
                    case PosConst.CAT_MODEL_DIV._CHN_UNION:
                        {
                            // 은련

                            int nNowPos = 0;
                            ItemColumn.ParseMessage(Column.POS_RES_UNION_CAT.LEN, Column.POS_RES_UNION_CAT.TYPE, bytes, ref nNowPos, ref aIrtDTLRsp);


                            // 응답 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문)
                            m_cDataCommon.SetSaleApprLog(sAppLogDiv, new string[] { sWayCd, sDtlCd, sAppType, "R"
                                                            , aIrtDTLRsp[Column.POS_RES_UNION_CAT.SEQ.CardNo], CmUtil.DoubleParse(aParam[3]).ToString()
                                                            , aIrtDTLRsp[Column.POS_RES_UNION_CAT.SEQ.Auth_Code], CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_UNION_CAT.SEQ.AppDate], 0, 8), CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_UNION_CAT.SEQ.AppTime], 0, 6)
                                                            , aIrtDTLRsp[Column.POS_RES_UNION_CAT.SEQ.ResponseCode].Trim()
                                                            , aIrtDTLRsp[Column.POS_RES_UNION_CAT.SEQ.ResponseMsg].Trim()
                                                            , sRecvdData });                            

                            if (aIrtDTLRsp[Column.POS_RES_UNION_CAT.SEQ.ResponseCode].Trim() != "00")
                            {
                                sRecvMsg = string.Format("{0} - {1}", aIrtDTLRsp[Column.POS_RES_UNION_CAT.SEQ.ResponseCode], aIrtDTLRsp[Column.POS_RES_UNION_CAT.SEQ.ResponseMsg]);
                                UserLog.WriteLogFile(UserCom.LOG_ERROR,
                                                 System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                                 System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                                 System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                                 sRecvMsg);

                                if (bMsgView == true)
                                    WinManager.ErrorMessage(sRecvMsg);

                                return false;
                            }
                            break;
                        }
                }

                bRet = true;
            }
            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 bRet;
        }
        #endregion

        /// <summary>
        /// 기타 아이템 컷팅 공통
        /// </summary>
        /// <param name="sCutType"></param>
        /// <param name="sAddItem"></param>
        /// <param name="aParam"></param>
        /// <returns></returns>
        protected bool AddItemCutCom(string sCutType, string sAddItem, ref string[] aParam)
        {
            bool bRet = false;

            try
            {
                switch (sCutType)
                {
                    case "0":   //승인일시
                        aParam = new string[] { CmUtil.MidH(sAddItem, 0, 6), CmUtil.MidH(sAddItem, 6, 4) };
                        break;
                    case "1":   //주1) 포인트 정보
                        aParam = new string[] { CmUtil.MidH(sAddItem, 0, 9), CmUtil.MidH(sAddItem, 9, 9), CmUtil.MidH(sAddItem, 18, 9) };
                        break;
                    case "2":   //주2) 유가보조
                        aParam = new string[] { CmUtil.MidH(sAddItem, 0, 4), CmUtil.MidH(sAddItem, 4, 1), CmUtil.MidH(sAddItem, 5, 10), 
                                                CmUtil.MidH(sAddItem, 15, 1), CmUtil.MidH(sAddItem, 16, 10), CmUtil.MidH(sAddItem, 26, 4), 
                                                CmUtil.MidH(sAddItem, 30, 1), CmUtil.MidH(sAddItem, 31, 1), CmUtil.MidH(sAddItem, 32, 6), 
                                                CmUtil.MidH(sAddItem, 38, 8) };
                        break;
                    case "3":   //주3) 삼성포인트 정보
                        aParam = new string[] { CmUtil.MidH(sAddItem, 0, 4), CmUtil.MidH(sAddItem, 4, 13), CmUtil.MidH(sAddItem, 17, 13) };
                        break;
                    case "4":   //주4) 출력메세지(지드림,푸르미,꿈자람) 잔여 포인트
                        aParam = new string[] { CmUtil.MidH(sAddItem, 0, 4), CmUtil.MidH(sAddItem, 4, 9) };
                        break;
                }

                bRet = true;
            }
            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 bRet;
        }

    }

}
