using System;
using System.Collections;
//using System.Windows.Forms;

using Cosmos.UserFrame;
using Cosmos.ServiceProvider;
using Cosmos.Common;
using Cosmos.CommonManager;
using System.Text;
using System.Data;
using Cosmos.BaseFrame;

using System.Text.RegularExpressions;
/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 신용카드
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Service
{
    class CreditCard : PaymentBase, IPaymentUs
    {
        #region Variable

        private SManager sManager = new SManager();                                 // 이 객체를 통해 업무 Service 호출
        private StateServer StateObject = (StateServer)StateServer.GetInstance();   // StateObject : StateServer Object (객체)
        private PosStatus m_cPosStatus = new PosStatus();                           // 기본정보 참조
        private TranStatus m_cTrnStatus = new TranStatus();                         // 거래정보 참조
        private IICReaderUs m_cICReader = null;                                     // IC리더기
        private ISignPadUs m_cSignPad = null;                                       // 싸인패드
        private IDataProcessUs m_cDataService = null;                               // 거래데이터 합계금액 계산 및 관리
        private IDataCommonUs m_cDataCommon = null;                                 // POS 공통함수 인터페이스

        private IMasterUs m_cMater = null;                                          // 마스터 Database

        private ISalePluItemUs m_cPluService = null;
        private DeviceStatus m_cDevStatus = new DeviceStatus();                     // 디바이스 관리

        private readonly string GIFT_REMAIN_TAG = "잔액 :";                          //선불카드 잔액 태그
        private readonly string GIFT_WON_TAG = "원";                                 //선불카드 잔액 태그


        #endregion

        #region 생성자
        public CreditCard()
        {
            m_cPosStatus = (PosStatus)StateObject.POS;      // POS 기본정보
            m_cTrnStatus = (TranStatus)StateObject.TRAN;    // POS 거래정보
            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_cICReader = (IICReaderUs)sManager.InitServiceInstance(ServiceLists.AGENT_OLEDEVICE.DLL, ServiceLists.AGENT_OLEDEVICE.DEVICE_ICREADER);
            m_cMater = (IMasterUs)sManager.InitServiceInstance(ServiceLists.ASV_MASTER.DLL, ServiceLists.ASV_MASTER.PAY_DC_MASTER);
            m_cPluService = (ISalePluItemUs)sManager.InitServiceInstance(ServiceLists.BSV_SALE.DLL, ServiceLists.BSV_SALE.SALE_PLU_ITEM);
            m_cSignPad = (ISignPadUs)sManager.InitServiceInstance(ServiceLists.AGENT_OLEDEVICE.DLL, ServiceLists.AGENT_OLEDEVICE.DEVICE_SIGNPAD);

            m_cDevStatus = (DeviceStatus)StateObject.DEVICE;

        }
        #endregion

        #region 조회 관련 업무
        public string SearchPayment(string[] aParam, ref string[] aRet)
        {

            string sRet = UserCom.RST_ERR;

            try
            {

                if (aParam.Length > 0 && aParam[0] == PosConst.POS_CAT_MASTER.TRAN_TYPE)    //단말기승인
                {

                    ArrayList aPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
                    m_cPayItem = new Column.TR_PAYMENT.DATA();      // 결과 저장 변수 생성

                    m_cPayItem.PAY_WAY_CD = ItemConst.TR_ITEM_ID.CREDITCARD_ITEM;
                    m_cPayItem.PAY_DTL_CD_01 = ItemConst.TR_ITEM_ID.CREDITCARD.CREDIT_CARD;



                    string sRecvdData = "";
                    string sInputType = "";

                    string[] aIrtDTLRsp = new string[Column.POS_RES_SPCN_CAT.LEN.Length];

                    //전문 송/수신
                    if (CatTerminalExecuteIrtCom(aParam[1], PosConst.CANCEL_DIV.NORMAL, aParam, m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, ref aIrtDTLRsp, ref sRecvdData, ref sInputType) == false)
                    {
                        return sRet;
                    }

                    if (aParam[12] == PosConst.CREDITCARD_SEARCH_TYPE.SFC)
                    {
                        if (CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AddItem], 26, 1) == "S") //SFC인지 확인!
                        {
                            sRet = UserCom.RST_OK;
                            aRet[0] = sInputType;
                        }
                    }
                    else if (aParam[12] == PosConst.CREDITCARD_SEARCH_TYPE.M_POINT)
                    {
                        sRet = UserCom.RST_OK;
                        aRet[0] = CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AddItem], 0, 13);
                    }
                }
                else
                {
                    if (aParam[0] == PosConst.CREDITCARD_SEARCH_TYPE.PREFIX)
                    {
                        DataTable dtDataInfo = m_cMater.Select(new string[] { PosMst.MST_CARD_PREFIX.TABLE_NAME, aParam[1] });

                        if (dtDataInfo != null && dtDataInfo.Rows.Count > 0)
                        {
                            DataRow dr = dtDataInfo.Rows[0];

                            aRet[0] = CmUtil.GetDataRowStr(dr, PosMst.MST_CARD_PREFIX.DATA.CARD_DIV);
                            aRet[1] = CmUtil.GetDataRowStr(dr, PosMst.MST_CARD_PREFIX.DATA.PRFX_NM);
                            aRet[2] = CmUtil.GetDataRowStr(dr, PosMst.MST_CARD_PREFIX.DATA.CARD_CMP_CD);
                            aRet[3] = CmUtil.GetDataRowStr(dr, PosMst.MST_CARD_PREFIX.DATA.COOP_CARD_DIV);

                            sRet = UserCom.RST_OK;
                        }
                    }
                    else if (aParam[0] == PosConst.CREDITCARD_SEARCH_TYPE.SFC)
                    {
                        string sRecvdData = "";

                        string sSendData = string.Empty;


                        string sAppId = ""; //승인 구분자

                        if (aParam[1] == PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_IC || aParam[11] == "3" || aParam[9].Trim().Length > 0)  //IC정상 또는 FALLBACK
                        {
                            sAppId = PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_AGREE;
                        }
                        else
                        {
                            sAppId = PosConst.POS_VAN_MASTER.TRADE_ID.VAN_CARD_AGREE;
                        }


                        sSendData = MakeCardICBody(sAppId, aParam, "");

                        // 가맹점 정보 획득(회사승인ID,점포승인ID)
                        string sCmpApprID = PosMstManager.GetMstVan(ItemConst.TR_ITEM_ID.CREDITCARD_ITEM, ItemConst.TR_ITEM_ID.CREDITCARD.CREDIT_CARD, PosMst.MST_VAN.DATA.CMP_APPR_ID);
                        string sApprID = PosMstManager.GetMstVan(ItemConst.TR_ITEM_ID.CREDITCARD_ITEM, ItemConst.TR_ITEM_ID.CREDITCARD.CREDIT_CARD, PosMst.MST_VAN.DATA.APPR_ID);
                        // 신용카드 승인 전문 헤더 생성
                        sSendData = m_cDataCommon.MakeCreditCardHeader(sAppId, sSendData.Length, sCmpApprID, sApprID) + sSendData;

                        //전문전송
                        string sIrtRet = m_cDataCommon.ExecuteCardIrt(sAppId, sSendData, ref sRecvdData, true, aParam[9], aParam[10], "", aParam[1]);
                        if (sIrtRet != UserCom.RST_OK)
                        {
                            return string.Format("|{0} - {1}", sIrtRet, sRecvdData);
                        }

                        byte[] bytes = Encoding.Default.GetBytes(sRecvdData);
                        int nNowPos = ItemColumn.LenMessage(Column.POS_VAN_HEADER.LEN);

                        //IC 승인이 아닐 경우 헤더
                        if (sAppId != PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_AGREE)
                        {
                            nNowPos = 0;
                        }

                        string[] aIrtDTLRsp = new string[Column.POS_RES_CREDITCARDIC.LEN.Length];
                        ItemColumn.ParseMessage(Column.POS_RES_CREDITCARDIC.LEN, Column.POS_RES_CREDITCARDIC.TYPE, bytes, ref nNowPos, ref aIrtDTLRsp);

                        if (aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Status] != "O")
                        {

                            return string.Format("|{0} - {1}{2}", sRet, aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Message1], aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Message2]);
                        }
                        else
                        {
                            //응답 구분자 리턴!
                            aRet[0] = aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Reserved].Trim().ToString();
                        }

                        sRet = UserCom.RST_OK;

                    }
                    else if (aParam[0] == PosConst.CREDITCARD_SEARCH_TYPE.POINT)
                    {
                        string sRecvdData = "";

                        string sSendData = string.Empty;

                        string sAppId = ""; //승인 구분자

                        if (aParam[1] == PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_IC || aParam[11] == "3" || aParam[9].Trim().Length > 0)  //IC정상 또는 FALLBACK
                        {
                            sAppId = PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_AGREE;
                        }
                        else
                        {
                            sAppId = PosConst.POS_VAN_MASTER.TRADE_ID.VAN_CARD_AGREE;
                        }

                        string sReserved = "";
                        if (aParam[18] == ItemConst.CREDITCARD_DC_TY.HYUNDAI_M_POINTS)      // M-Point
                            sReserved = "MINQ";

                        sSendData = MakeCardICBody(sAppId, aParam, sReserved);

                        // 가맹점 정보 획득(회사승인ID,점포승인ID)
                        string sCmpApprID = PosMstManager.GetMstVan(ItemConst.TR_ITEM_ID.CREDITCARD_ITEM, ItemConst.TR_ITEM_ID.CREDITCARD.CREDIT_CARD, PosMst.MST_VAN.DATA.CMP_APPR_ID);
                        string sApprID = PosMstManager.GetMstVan(ItemConst.TR_ITEM_ID.CREDITCARD_ITEM, ItemConst.TR_ITEM_ID.CREDITCARD.CREDIT_CARD, PosMst.MST_VAN.DATA.APPR_ID);
                        // 신용카드 승인 전문 헤더 생성
                        sSendData = m_cDataCommon.MakeCreditCardHeader(sAppId, sSendData.Length, sCmpApprID, sApprID) + sSendData;

                        //전문전송
                        string sIrtRet = m_cDataCommon.ExecuteCardIrt(sAppId, sSendData, ref sRecvdData, true, aParam[9], aParam[10], "", aParam[1]);
                        if (sIrtRet != UserCom.RST_OK)
                        {
                            return string.Format("|{0} - {1}", sIrtRet, sRecvdData);
                        }

                        byte[] bytes = Encoding.Default.GetBytes(sRecvdData);
                        int nNowPos = ItemColumn.LenMessage(Column.POS_VAN_HEADER.LEN);

                        //IC 승인이 아닐 경우 헤더
                        if (sAppId != PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_AGREE)
                        {
                            nNowPos = 0;
                        }

                        string[] aIrtDTLRsp = new string[Column.POS_RES_CREDITCARDIC.LEN.Length];
                        ItemColumn.ParseMessage(Column.POS_RES_CREDITCARDIC.LEN, Column.POS_RES_CREDITCARDIC.TYPE, bytes, ref nNowPos, ref aIrtDTLRsp);

                        if (aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Status] != "O")
                        {

                            return string.Format("|{0} - {1}{2}", sRet, aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Message1], aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Message2]);
                        }
                        else
                        {
                            //응답 구분자 리턴!
                            aRet[0] = aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Notice].ToString();

                            aRet[0] = aRet[0].Replace("MINQ", "");      // M-Point인 경우 특정 문자 변경
                        }
                        sRet = UserCom.RST_OK;

                    }
                    else if (aParam[0] == PosConst.CREDITCARD_SEARCH_TYPE.VAN_CARD_LOG_SEARCH)
                    {
                        //로그 조회
                        sRet = ExecuteIrtVanCardLogSearch(ref aRet);
                    }
                    else if (aParam[0] == PosConst.CREDITCARD_SEARCH_TYPE.VAN_CARD_LOG_FINAL)
                    {
                        //등록 완료 요청!
                        sRet = ExecuteIrtVanCardLogFinal(aParam, ref aRet);
                    }
                }

                return sRet;

            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.ERROR, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
                return UserCom.RST_ERR + ex.Message;

            }
            finally
            {
                //여전법 대응!
                //////////////////////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref aParam);
                //////////////////////////////////////////////////////////////////////////////////
            }
        }
        #endregion 조회 관련 업무

        #region 결제 정보 획득
        /// <summary>
        /// 결제 정보 획득
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public object GetPayment(string[] aParam)
        {
            try
            {
                return null;
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                   System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return null;
        }
        #endregion

        #region 결제 등록 처리
        /// <summary>
        /// 카드 결제 등록 처리
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string SetPayment(string[] aParam)
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                ArrayList aPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
                m_cPayItem = new Column.TR_PAYMENT.DATA();      // 결과 저장 변수 생성

                m_cPayItem.PAY_WAY_CD = ItemConst.TR_ITEM_ID.CREDITCARD_ITEM;
                m_cPayItem.PAY_DTL_CD_01 = ItemConst.TR_ITEM_ID.CREDITCARD.CREDIT_CARD;



                string sAppId = ""; //승인 구분자
                string sDcType = "";


                if (aParam.Length > 0 && aParam[0] == PosConst.XCHARGE.TRANSACTION)  // X-CHARGE 이면...
                {

                    // 0.전문구분, 1.승인금액, 2.원카드번호, 3.원거래아이디, 4.원거래정보
                    sAppId = PosConst.XCHARGE.APPR;
                    sDcType = "";
                    sRet = XChargeExecuteIrt(sAppId, aParam);

                }
                else if (aParam.Length > 0 && aParam[0] == PosConst.POS_CAT_MASTER.TRAN_TYPE)    //단말기승인
                {
                    // 0.전문구분,1.거래유형, 2.할부개월, 3.승인금액 , 4.봉사료, 5.세금, 6.원승인번호, 7.원거래일자, 8.포인트거래구분, 9.상품코드,
                    //10.전표인쇄여부, 11.추가항목, 12.제휴할인코드, 13.제휴할인금액, 14.예비1, 15.예비2

                    sDcType = aParam[12];
                    sRet = CatExecuteIrt(aParam[1], aParam);
                }
                else
                {

                    //0:마스킹 카드번호 1:입력구분 2:카드번호 3:할부개월 4:총금액 5:봉사료
                    //6:세금 7:비밀번호 8:신용카드종류 9:칩데이터 10:사인
                    //11:Fallback구분 12:제휴할인금액(캠페인) 13:원승인번호 14:원승인일자 15:아이템코드
                    //16:매입사코드 17:매입사명 18:할인카드구분 19:할인금액 20:승인구분, 21:매체구분, 22:서비스코드

                    sDcType = aParam[18];


                    if (aParam[1] == PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_RF && aParam[9].Trim().Length > 0)  //RF고 칩데이터가 있으면 재정의
                    {
                        aParam[9] = SetRfIcData(aParam[9]);
                    }

                    if (aParam[1] == PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_IC || aParam[11] == "3" || aParam[9].Trim().Length > 0)  //IC정상 또는 FALLBACK
                    {
                        sAppId = PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_AGREE;
                    }
                    else
                    {
                        sAppId = PosConst.POS_VAN_MASTER.TRADE_ID.VAN_CARD_AGREE;
                    }

                    sRet = ExecuteIrt(sAppId, aParam);

                }

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

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

                    sRet = UserCom.RST_OK;

                }

            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.ERROR, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
                return UserCom.RST_ERR + ex.Message;
            }
            finally
            {
                //메세지 순번 증가
                m_cDataService.SetMsgNoInc(true, false, false);

                //여전법 대응!
                //////////////////////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref aParam);
                //////////////////////////////////////////////////////////////////////////////////
            }

            return sRet;

        }
        #endregion

        #region 결제 취소 처리
        /// <summary>
        /// 카드 결제 취소 처리
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string CancelPayment(string[] aParam)
        {
            string sRet = UserCom.RST_ERR;

            string sCardInfo = "";

            string[] aStr = null;

            string m_sSign = "";

            try
            {

                string[] m_aParam = new string[23];

                //결과 저장
                ArrayList aPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
                m_cPayItem = (Column.TR_PAYMENT.DATA)aPayItem[CmUtil.IntParse(aParam[0])];

                string sAppId = ""; //승인 구분자

                if (m_cPayItem.OCCUR_ENTRY_08.ToString() == ItemConst.PAY_APP_DIV.X_CHARGE)  // X-CHARGE 이면...
                {

                    // 0.전문구분, 1.승인금액, 2.원카드번호, 3.원거래아이디, 4.원거래정보
                    sAppId = PosConst.XCHARGE.VOID;

                    m_aParam[0] = PosConst.XCHARGE.TRANSACTION;
                    m_aParam[1] = m_cPayItem.PAY_AMT.ToString();
                    m_aParam[2] = m_cPayItem.OCCUR_ENTRY_01;
                    m_aParam[3] = m_cPayItem.OCCUR_ENTRY_19;
                    m_aParam[4] = m_cPayItem.OCCUR_ENTRY_18;

                    sRet = XChargeExecuteIrt(sAppId, m_aParam);

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

                }
                else if (m_cPayItem.OCCUR_ENTRY_08.ToString() == ItemConst.PAY_APP_DIV.CAT_TERMINAL)
                {

                    //InParam
                    // 0.전문구분,1.거래유형, 2.할부개월, 3.승인금액 , 4.봉사료, 5.세금, 6.원승인번호, 7.원거래일자, 8.포인트거래구분, 9.상품코드,
                    //10.전표인쇄여부, 11.추가항목, 12.제휴할인코드, 13.제휴할인금액, 14.예비1, 15.예비2

                    sAppId = m_cPayItem.OCCUR_ENTRY_15 == "1" ? PosConst.POS_CAT_MASTER.TRADE_ID.CAT_UNION_CANCEL : PosConst.POS_CAT_MASTER.TRADE_ID.CAT_CARD_CANCEL;

                    m_aParam[0] = PosConst.POS_CAT_MASTER.TRAN_TYPE;
                    m_aParam[1] = sAppId;
                    m_aParam[2] = m_cPayItem.OCCUR_ENTRY_14;
                    m_aParam[3] = m_cPayItem.PAY_AMT.ToString();
                    m_aParam[4] = m_cPayItem.AMT_ENTRY_04.ToString(); //봉사료
                    m_aParam[5] = m_cPayItem.AMT_ENTRY_03.ToString(); //세금
                    m_aParam[6] = m_cPayItem.OCCUR_ENTRY_02;
                    m_aParam[7] = m_cPayItem.OCCUR_ENTRY_03;
                    m_aParam[8] = "";
                    m_aParam[9] = "";
                    m_aParam[10] = "";
                    m_aParam[11] = "";
                    m_aParam[12] = "";
                    m_aParam[13] = "";
                    m_aParam[14] = "";
                    m_aParam[15] = "";

                    sRet = CatExecuteIrt(sAppId, m_aParam);
                    if (sRet != UserCom.RST_OK)
                    {
                        return UserCom.RST_ERR;
                    }
                }
                else
                {

                    if (m_cPayItem.OCCUR_ENTRY_08.ToString() == ItemConst.PAY_APP_DIV.COMPULSION || m_cPayItem.OCCUR_ENTRY_08.ToString() == ItemConst.PAY_APP_DIV.PDA_APPR)
                    {
                        //임의 등록 이면 승인 없이 데이터 처리
                        WinManager.ConfirmMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0240));

                        m_cPayItem.OCCUR_ENTRY_06 = m_cPayItem.OCCUR_ENTRY_02;
                        m_cPayItem.OCCUR_ENTRY_07 = m_cPayItem.OCCUR_ENTRY_03;
                        m_cPayItem.OCCUR_ENTRY_17 = GetSignFlag(m_sSign.Length > 0 ? "1" : "0", m_cPayItem.PAY_AMT);   //사인유무

                    }
                    else
                    {
                        // 정상 승인 거래만 전자서명 처리(2017.05.27)
                        if (GetCancelReSign(m_cPayItem.PAY_AMT, ref m_sSign) == false)
                        {
                            return sRet;
                        }

                        aStr = m_cPayItem.CanFiller1.Split(new string[] { "^!@" }, StringSplitOptions.None);

                        sCardInfo = aStr[1];

                        if (CmUtil.MidH(aStr[0], 2, 1) == PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_RF)
                        {
                            m_aParam[2] = CmUtil.MidH(sCardInfo, 2, 512).Trim();
                            m_aParam[9] = SetRfIcData(CmUtil.MidH(sCardInfo, 1116, 512));
                            m_aParam[1] = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_RF;
                            m_aParam[21] = CmUtil.MidH(sCardInfo, 1, 1);
                            m_aParam[22] = m_cPayItem.OCCUR_ENTRY_23.ToString();

                            // 삼성 페이 체크!
                            if (CmUtil.MidH(sCardInfo, 1628, 2) == "02" && (m_aParam[21] == "D" || m_aParam[21] == "F"))
                            {
                                m_aParam[15] = "02";
                            }
                            else
                            {
                                m_aParam[15] = "";
                            }

                        }
                        else
                        {
                            //sCardInfo = m_cPayItem.CanFiller1;
                            m_aParam[2] = CmUtil.MidH(sCardInfo, 6, 512).Trim();
                            m_aParam[9] = CmUtil.MidH(sCardInfo, 518, 512).Trim();
                            if (CmUtil.MidH(sCardInfo, 4, 2).Trim() == "02")
                            {
                                m_aParam[1] = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_SWIP;
                            }
                            else
                            {
                                m_aParam[1] = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_IC;
                            }
                            m_aParam[11] = CmUtil.MidH(sCardInfo, 3, 1); // == "3" ? "0" : "1";

                            m_aParam[21] = m_cPayItem.OCCUR_ENTRY_24.ToString();
                            m_aParam[22] = CmUtil.MidH(sCardInfo, 1067, 5).Trim();
                            m_aParam[15] = "";
                        }

                        //0:마스킹 카드번호 1:입력구분 2:카드번호 3:할부개월 4:총금액 5:봉사료
                        //6:세금 7:비밀번호 8:신용카드종류 9:칩데이터 10:사인
                        //11:Fallback구분 12:제휴할인금액(캠페인) 13:원승인번호 14:원승인일자 15:아이템코드
                        //16:매입사코드 17:매입사명 18:할인카드구분 19:할인금액 20:승인구분, 21:매체구분, 22:서비스코드

                        m_aParam[3] = m_cPayItem.OCCUR_ENTRY_14.ToString().PadLeft(2, '0');
                        m_aParam[4] = m_cPayItem.PAY_AMT.ToString();
                        m_aParam[5] = m_cPayItem.AMT_ENTRY_04.ToString();
                        m_aParam[6] = m_cPayItem.AMT_ENTRY_03.ToString();
                        m_aParam[7] = m_cPayItem.CanFiller2;    //비밀번호
                        m_aParam[8] = "";    //신용카드종류

                        m_aParam[10] = m_sSign;

                        m_aParam[12] = m_cPayItem.AMT_ENTRY_07.ToString();
                        m_aParam[13] = m_cPayItem.OCCUR_ENTRY_02.ToString();
                        m_aParam[14] = m_cPayItem.OCCUR_ENTRY_03.ToString();


                        m_aParam[16] = "";
                        m_aParam[17] = "";
                        m_aParam[18] = m_cPayItem.PAY_DTL_CD_02.ToString();
                        m_aParam[19] = m_cPayItem.AMT_ENTRY_02.ToString();
                        m_aParam[20] = "";

                        //if (m_aParam[1] == PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_SWIP && m_aParam[11] == "1")  //삼성페이
                        //{
                        //    sAppId = PosConst.POS_VAN_MASTER.TRADE_ID.VAN_CARD_CANCEL;
                        //}
                        //else
                        //{
                        //    sAppId = PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_CANCEL;
                        //}
                        if (m_aParam[1] == PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_IC || m_aParam[11] == "3" || m_aParam[9].Trim().Length > 0)  //IC정상 또는 FALLBACK
                        {
                            sAppId = PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_CANCEL;
                        }
                        else
                        {
                            sAppId = PosConst.POS_VAN_MASTER.TRADE_ID.VAN_CARD_CANCEL;
                        }

                        sRet = ExecuteIrt(sAppId, m_aParam);
                        if (sRet != UserCom.RST_OK)
                        {
                            WinManager.ErrorMessage(sRet);
                            return UserCom.RST_ERR;
                        }
                    }
                }

                m_cPayItem.CANCEL_DIV = ItemConst.PAY_CANCEL_DIV.CANCEL;

                ICampaignUs cCampaingMain = (ICampaignUs)sManager.InitServiceInstance(ServiceLists.ASV_CAMPAIGN.DLL, ServiceLists.ASV_CAMPAIGN.CAMPAIGN_MAIN);
                // 캠페인 취소 처리
                cCampaingMain.CancelCampaignPayment(aParam[0], "");

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

                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 + ex.Message;
            }
            finally
            {
                //여전법 대응!
                //////////////////////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref sCardInfo);
                CmUtil.ZeroFillClear(ref m_cPayItem.CanFiller1);
                CmUtil.ZeroFillClear(ref aParam);
                CmUtil.ZeroFillClear(ref aStr);
                CmUtil.ZeroFillClear(ref m_sSign);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return sRet;
        }
        #endregion

        #region 오타/반품시 처리
        /// <summary>
        /// 오타/반품시 처리
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string RefundPayment(string[] aParam)
        {
            string sRet = UserCom.RST_ERR;

            string sCardInfo = "";
            string[] aStr = null;
            string m_sSign = "";

            try
            {
                UserLog.WriteLogFile(UserCom.LOG_IOS,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                     "CreditCrad.RefundPayment start");


                //#20180410 인천공항 반품 시 원승인번호,원거래일자 저장 start,phj
                //기존
                //#20171227 인천공항 포스연동 start, phj
                if (PosMstManager.GetPosOption(POS_OPTION.OPT512) == "1")
                {
                    UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                        "CreditCrad.RefundPayment return OK");

                    sRet = UserCom.RST_OK;

                    UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                        "CreditCrad.RefundPayment return" + sRet);

                    return sRet;
                }
                //#20171227 인천공항 포스연동 end, phj
                //#20180410 인천공항 반품 시 원승인번호,원거래일자 저장 end,phj

                //#20171020 log 추가 
                UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", " creditcard 거래구분 : " + m_cTrnStatus.Head.TradeDiv);


                string[] m_aParam = new string[23];

                //결과 저장
                ArrayList aPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
                m_cPayItem = (Column.TR_PAYMENT.DATA)aPayItem[CmUtil.IntParse(aParam[0])];

                string sAppId = ""; //승인 구분자

                if (m_cPayItem.OCCUR_ENTRY_08.ToString() == ItemConst.PAY_APP_DIV.X_CHARGE)  // X-CHARGE 이면...
                {

                    // 0.전문구분, 1.승인금액, 2.원카드번호, 3.원거래아이디, 4.원거래정보
                    sAppId = PosConst.XCHARGE.VOID;

                    m_aParam[0] = PosConst.XCHARGE.TRANSACTION;
                    m_aParam[1] = m_cPayItem.PAY_AMT.ToString();
                    m_aParam[2] = m_cPayItem.OCCUR_ENTRY_01;
                    m_aParam[3] = m_cPayItem.OCCUR_ENTRY_19;
                    m_aParam[4] = m_cPayItem.OCCUR_ENTRY_18;

                    sRet = XChargeExecuteIrt(sAppId, m_aParam);

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

                }
                else if (m_cPayItem.OCCUR_ENTRY_08.ToString() == ItemConst.PAY_APP_DIV.CAT_TERMINAL)
                {

                    //InParam
                    // 0.전문구분,1.거래유형, 2.할부개월, 3.승인금액 , 4.봉사료, 5.세금, 6.원승인번호, 7.원거래일자, 8.포인트거래구분, 9.상품코드,
                    //10.전표인쇄여부, 11.추가항목, 12.제휴할인코드, 13.제휴할인금액, 14.예비1, 15.예비2

                    sAppId = m_cPayItem.OCCUR_ENTRY_15 == "1" ? PosConst.POS_CAT_MASTER.TRADE_ID.CAT_UNION_CANCEL : PosConst.POS_CAT_MASTER.TRADE_ID.CAT_CARD_CANCEL;

                    m_aParam[0] = PosConst.POS_CAT_MASTER.TRAN_TYPE;
                    m_aParam[1] = sAppId;
                    m_aParam[2] = m_cPayItem.OCCUR_ENTRY_14;
                    m_aParam[3] = m_cPayItem.PAY_AMT.ToString();
                    m_aParam[4] = m_cPayItem.AMT_ENTRY_04.ToString(); //봉사료
                    m_aParam[5] = m_cPayItem.AMT_ENTRY_03.ToString(); //세금
                    m_aParam[6] = m_cPayItem.OCCUR_ENTRY_02;
                    m_aParam[7] = m_cPayItem.OCCUR_ENTRY_03;
                    m_aParam[8] = "";
                    m_aParam[9] = "";
                    m_aParam[10] = "";
                    m_aParam[11] = "";
                    m_aParam[12] = "";
                    m_aParam[13] = "";
                    m_aParam[14] = "";
                    m_aParam[15] = "";

                    sRet = CatExecuteIrt(sAppId, m_aParam);
                    if (sRet != UserCom.RST_OK)
                    {
                        return UserCom.RST_ERR;
                    }
                }
                else
                {

                    if (m_cPayItem.OCCUR_ENTRY_08.ToString() != ItemConst.PAY_APP_DIV.NORMAL)
                    {
                        //임의 등록 이면 승인 없이 데이터 처리
                        //WinManager.ConfirmMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0240));

                        m_cPayItem.OCCUR_ENTRY_06 = m_cPayItem.OCCUR_ENTRY_02;
                        m_cPayItem.OCCUR_ENTRY_07 = m_cPayItem.OCCUR_ENTRY_03;
                        m_cPayItem.OCCUR_ENTRY_17 = GetSignFlag(m_sSign.Length > 0 ? "1" : "0", m_cPayItem.PAY_AMT);   //사인유무
                    }
                    else
                    {
                        // 정상 승인 거래만 전자서명 처리(2017.05.27)
                        if (GetCancelReSign(m_cPayItem.PAY_AMT, ref m_sSign) == false)
                        {
                            return sRet;
                        }

                        aStr = m_cPayItem.CanFiller1.Split(new string[] { "^!@" }, StringSplitOptions.None);

                        sCardInfo = aStr[1];

                        if (CmUtil.MidH(aStr[0], 2, 1) == PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_RF)
                        {
                            m_aParam[2] = CmUtil.MidH(sCardInfo, 2, 512).Trim();
                            m_aParam[9] = SetRfIcData(CmUtil.MidH(sCardInfo, 1116, 512));
                            m_aParam[1] = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_RF;
                            m_aParam[21] = CmUtil.MidH(sCardInfo, 1, 1);
                            m_aParam[22] = m_cPayItem.OCCUR_ENTRY_23.ToString();

                            // 삼성 페이 체크!
                            if (CmUtil.MidH(sCardInfo, 1628, 2) == "02" && (m_aParam[21] == "D" || m_aParam[21] == "F"))
                            {
                                m_aParam[15] = "02";
                            }
                            else
                            {
                                m_aParam[15] = "";
                            }

                        }
                        else
                        {

                            //sCardInfo = m_cPayItem.CanFiller1;
                            m_aParam[2] = CmUtil.MidH(sCardInfo, 6, 512).Trim();
                            m_aParam[9] = CmUtil.MidH(sCardInfo, 518, 512).Trim();
                            if (CmUtil.MidH(sCardInfo, 4, 2).Trim() == "02")
                            {
                                m_aParam[1] = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_SWIP;
                            }
                            else
                            {
                                m_aParam[1] = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_IC;
                            }
                            m_aParam[11] = CmUtil.MidH(sCardInfo, 3, 1); // == "3" ? "0" : "1";

                            m_aParam[21] = m_cPayItem.OCCUR_ENTRY_24.ToString();
                            m_aParam[22] = CmUtil.MidH(sCardInfo, 1067, 5).Trim();
                            m_aParam[15] = "";
                        }

                        m_aParam[3] = m_cPayItem.OCCUR_ENTRY_14.ToString().PadLeft(2, '0');
                        m_aParam[4] = m_cPayItem.PAY_AMT.ToString();
                        m_aParam[5] = m_cPayItem.AMT_ENTRY_04.ToString();
                        m_aParam[6] = m_cPayItem.AMT_ENTRY_03.ToString();
                        m_aParam[7] = "";    //비밀번호
                        m_aParam[8] = "";    //신용카드종류

                        m_aParam[10] = m_sSign;

                        m_aParam[12] = "";
                        m_aParam[13] = m_cPayItem.OCCUR_ENTRY_02.ToString();
                        m_aParam[14] = m_cPayItem.OCCUR_ENTRY_03.ToString();



                        //if (m_aParam[1] == PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_SWIP && m_aParam[11] == "1")  //삼성페이
                        //{
                        //    sAppId = PosConst.POS_VAN_MASTER.TRADE_ID.VAN_CARD_CANCEL;
                        //}
                        //else
                        //{
                        //    sAppId = PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_CANCEL;
                        //}
                        if (m_aParam[1] == PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_IC || m_aParam[11] == "3" || m_aParam[9].Trim().Length > 0)  //IC정상 또는 FALLBACK
                        {
                            sAppId = PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_CANCEL;
                        }
                        else
                        {
                            sAppId = PosConst.POS_VAN_MASTER.TRADE_ID.VAN_CARD_CANCEL;
                        }

                        sRet = ExecuteIrt(sAppId, m_aParam);

                        //sRet = ExecuteIrt(PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_CANCEL, m_aParam);
                        if (sRet != UserCom.RST_OK)
                        {
                            WinManager.ErrorMessage(sRet);
                            return UserCom.RST_ERR;
                        }

                        //if (m_cPayItem.PAY_DTL_CD_02 == ItemConst.CREDITCARD_DC_TY.CREDIT_SFC)
                        //{
                        //    //SFC 할인 이면 할인 내역 취소!
                        //    CanSFCDc(ItemConst.TR_ITEM_ID.EMP_DC_ITEM, ItemConst.TR_ITEM_ID.EMP_DC.SAMSUNGCARD, m_cPayItem.PAY_DTL_CD_02, m_cPayItem.OCCUR_ENTRY_02);
                        //}
                    }
                }
                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 + ex.Message;
            }
            finally
            {
                //여전법 대응!
                //////////////////////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref sCardInfo);
                CmUtil.ZeroFillClear(ref m_cPayItem.CanFiller1);
                CmUtil.ZeroFillClear(ref aParam);
                CmUtil.ZeroFillClear(ref aStr);
                CmUtil.ZeroFillClear(ref m_sSign);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return sRet;
        }
        #endregion 오타/반품시 처리

        #region 결제 수기 등록(임의등록)
        /// <summary>
        /// 결제 수기 등록(임의등록)
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string SetMenualPayment(string[] aParam)
        {
            try
            {

                //0:마스킹 카드번호 1:입력구분 2:카드번호 3:할부개월 4:총금액 5:봉사료
                //6:세금 7:비밀번호 8:신용카드종류 9:칩데이터 10:사인
                //11:Fallback구분 12:제휴할인금액(캠페인) 13:원승인번호 14:원승인일자 15:아이템코드
                //16:매입사코드 17:매입사명 18:할인카드구분 19:할인금액 20:승인구분 21:매체구분 22:서비스코드


                //결과 저장
                ArrayList aPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
                Column.TR_PAYMENT.DATA m_cPayItem = new Column.TR_PAYMENT.DATA();

                //DataRow dr = PosMstManager.GetMstPayDc(new string[] { m_cPosStatus.Base.CmpCd, m_cPosStatus.Base.StoreNo, ItemConst.TR_ITEM_ID.CREDITCARD_ITEM, ItemConst.TR_ITEM_ID.CREDIT.CREDIT_PAY });

                m_cPayItem.PAY_WAY_CD = ItemConst.TR_ITEM_ID.CREDITCARD_ITEM;
                m_cPayItem.PAY_AMT = CmUtil.DoubleParse(aParam[4]);

                m_cPayItem.BILLSPR_NO = m_cTrnStatus.Sale.BillSplitNo;                                                  // 빌분리 번호

                m_cPayItem.PAY_DTL_CD_01 = ItemConst.TR_ITEM_ID.CREDITCARD.CREDIT_CARD;
                m_cPayItem.PAY_DTL_CD_02 = aParam[18];
                m_cPayItem.PAY_DTL_CD_03 = aParam[13];
                m_cPayItem.PAY_DTL_CD_04 = "";
                m_cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.PAY;

                m_cPayItem.QTY_ENTRY_01 = 0;
                m_cPayItem.QTY_ENTRY_02 = 0;
                m_cPayItem.QTY_ENTRY_03 = 0;
                m_cPayItem.QTY_ENTRY_04 = 0;
                m_cPayItem.QTY_ENTRY_05 = 0;

                m_cPayItem.AMT_ENTRY_01 = CmUtil.DoubleParse(aParam[4]);
                m_cPayItem.AMT_ENTRY_02 = CmUtil.DoubleParse(aParam[19]);  //제휴 할인 금액
                m_cPayItem.AMT_ENTRY_03 = CmUtil.DoubleParse(aParam[6]);
                m_cPayItem.AMT_ENTRY_04 = CmUtil.DoubleParse(aParam[5]);
                m_cPayItem.AMT_ENTRY_05 = 0;
                m_cPayItem.AMT_ENTRY_06 = 0;
                m_cPayItem.AMT_ENTRY_07 = CmUtil.DoubleParse(aParam[12]);  //제휴 할인 금액(캠페인)
                m_cPayItem.AMT_ENTRY_08 = 0;
                m_cPayItem.AMT_ENTRY_09 = 0;
                m_cPayItem.AMT_ENTRY_10 = 0;

                m_cPayItem.OCCUR_ENTRY_01 = aParam[0];   //카드번호
                m_cPayItem.OCCUR_ENTRY_02 = aParam[13];
                m_cPayItem.OCCUR_ENTRY_03 = DateTime.Now.ToString("yyMMdd");
                m_cPayItem.OCCUR_ENTRY_04 = DateTime.Now.ToString("HHmm");
                m_cPayItem.OCCUR_ENTRY_05 = aParam[1];
                m_cPayItem.OCCUR_ENTRY_06 = aParam[13];   //원승인번호
                m_cPayItem.OCCUR_ENTRY_07 = aParam[14];   //원승인일자
                m_cPayItem.OCCUR_ENTRY_08 = aParam[20];   //승인구분
                m_cPayItem.OCCUR_ENTRY_09 = "";
                m_cPayItem.OCCUR_ENTRY_10 = "";
                m_cPayItem.OCCUR_ENTRY_11 = aParam[16];
                m_cPayItem.OCCUR_ENTRY_12 = aParam[17];
                m_cPayItem.OCCUR_ENTRY_13 = aParam[11];   //Fallback 구분
                m_cPayItem.OCCUR_ENTRY_14 = aParam[3];    //할부개월
                m_cPayItem.OCCUR_ENTRY_15 = aParam[7].Trim().Length > 0 ? "1" : "0";   //은련구분
                m_cPayItem.OCCUR_ENTRY_16 = GetPayDtlCdToVanCode(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);       // 승인업체 코드 조회
                m_cPayItem.OCCUR_ENTRY_17 = GetSignFlag(aParam[10].Trim().Length > 0 ? "1" : "0", m_cPayItem.PAY_AMT);   //사인유무
                m_cPayItem.OCCUR_ENTRY_18 = "";   //매체구분
                m_cPayItem.OCCUR_ENTRY_19 = aParam[7];    //비밀번호
                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 = "";
                m_cPayItem.OCCUR_ENTRY_23 = "";
                m_cPayItem.OCCUR_ENTRY_24 = "";
                m_cPayItem.OCCUR_ENTRY_25 = "";

                m_cPayItem.CANCEL_DIV = ItemConst.PAY_CANCEL_DIV.NORMAL;

                aPayItem.Add(m_cPayItem);

                // 결제 금액 재 계산 처리
                m_cDataService.UpdatePayAmount();

                return 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);
            }
            finally
            {
                //여전법 대응!
                //////////////////////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref aParam);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return UserCom.RST_ERR;
        }
        #endregion 결제 수기 등록(임의등록)



        /// <summary>
        /// 조회 실행
        /// </summary>
        /// <param name="sAppType"></param>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string ExecuteIrt(string sAppType, string[] aParam)
        {

            string sRet = UserCom.RST_ERR;
            string sSendData = string.Empty;

            try
            {

                // 연습모드이면 연습 데이터 설정
                if (m_cPosStatus.Base.TrainingFlag == "1" || m_cPosStatus.Mst.TestStorYn == "1") return SetTrainingData(sAppType, aParam);

                string sRecvdData = "";

                sSendData = MakeCardICBody(sAppType, aParam, "");

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

                // 신용카드 승인 전문 헤더 생성
                sSendData = m_cDataCommon.MakeCreditCardHeader(sAppType, sSendData.Length, sCmpApprID, sApprID) + sSendData;


                string sAppLogDiv = "";

                if (sAppType == PosConst.POS_VAN_MASTER.TRADE_ID.VAN_CARD_AGREE || sAppType == PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_AGREE)
                {
                    sAppLogDiv = PosConst.CANCEL_DIV.NORMAL;
                }
                else
                {
                    sAppLogDiv = PosConst.CANCEL_DIV.CANCEL;
                }

                // 승인데이터 중 카드번호 마스킹 처리(2017.05.25)
                string sWriteSendData = CmUtil.MakeLogDataToMask(m_cDevStatus.ICReader.UseYn, "", 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]전문)
                m_cDataCommon.SetSaleApprLog(sAppLogDiv, new string[] { m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sAppType, "S", aParam[0], CmUtil.DoubleParse(aParam[4]).ToString(), "", "", "", "", "", sWriteSendData });

                string sIrtRet = "";

                //전문전송
                sIrtRet = m_cDataCommon.ExecuteCardIrt(sAppType, sSendData, ref sRecvdData, true, aParam[9], aParam[10], "", aParam[1]);

                if (sIrtRet != UserCom.RST_OK)
                {
                    return string.Format("|{0} - {1}", sIrtRet, sRecvdData);
                }

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

                string[] aIrtDTLRsp = new string[Column.POS_RES_CREDITCARDIC.LEN.Length];

                int nNowPos = ItemColumn.LenMessage(Column.POS_VAN_HEADER.LEN);

                //IC 승인이 아닐 경우 헤더
                if (sAppType != PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_AGREE)
                {
                    nNowPos = 0;
                }

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

                // 승인데이터 중 카드번호 마스킹 처리(2017.05.25)
                string sWriteRecvData = CmUtil.MakeLogDataToMask(m_cDevStatus.ICReader.UseYn, "", sRecvdData);
                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]전문)
                m_cDataCommon.SetSaleApprLog(sAppLogDiv, new string[] { m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sAppType, "R"
                                                            , aParam[0], CmUtil.DoubleParse(aParam[4]).ToString()
                                                            , aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.AppNo], CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.AppDatatime], 0, 6), CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.AppDatatime], 6, 4)
                                                            , aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Status].Trim()
                                                            , aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Message1].Trim() + aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Message2].Trim()
                                                            , sWriteRecvData });

                if (aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Status] != "O")
                {

                    return string.Format("|{0} - {1}{2}", sRet, aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Message1], aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Message2]);
                }

                // 발급사 인증 주석 처리 (SPCN요청:2017.06.23)
                ////IC거래 일 경우 처리
                //if (aParam[1] == PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_IC)
                //{
                //    if (SetCardCardIssuer(aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.EMVData], sAppType) == false)
                //    {


                //        //정상 승인 경우만 실패 망취소 처리 한다!
                //        if (sAppType == PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_AGREE)
                //        {
                //            // 망취소 승인로그 저장 처리(2017.06.19)
                //            sWriteSendData = CmUtil.MakeLogDataToMask(m_cDevStatus.ICReader.UseYn, "", 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]전문)
                //            m_cDataCommon.SetSaleApprLog(sAppLogDiv, new string[] { m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sAppType, "S", aParam[0], CmUtil.DoubleParse(aParam[4]).ToString(), "", "", "", "", "", sWriteSendData });

                //            string sRecvMsg = string.Empty;

                //            // 망취소 전송
                //            sIrtRet = m_cDataCommon.ExecuteCardIrt(PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_LINE_CANCEL, sSendData, ref sRecvdData, true, "", "", sRecvdData, aParam[1]);

                //            if (sIrtRet != UserCom.RST_OK)
                //            {
                //                sRecvMsg = MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0060);
                //            }
                //            else
                //            {
                //                byte[] bytTemp = Encoding.Default.GetBytes(sRecvdData);
                //                nNowPos = 0;
                //                aIrtDTLRsp = new string[Column.POS_RES_CREDITCARDIC.LEN.Length];
                //                ItemColumn.ParseMessage(Column.POS_RES_CREDITCARDIC.LEN, Column.POS_RES_CREDITCARDIC.TYPE, bytTemp, ref nNowPos, ref aIrtDTLRsp);
                //                if (aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Status] != "O")
                //                {
                //                    sRecvMsg = MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0060);
                //                }
                //                else
                //                {
                //                    sRecvMsg = MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0061);
                //                }
                //            }
                //            // 망취소 승인로그 저장 처리(2017.06.19)
                //            sWriteRecvData = CmUtil.MakeLogDataToMask(m_cDevStatus.ICReader.UseYn, "", sRecvdData);
                //            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]전문)
                //            m_cDataCommon.SetSaleApprLog(sAppLogDiv, new string[] { m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sAppType, "R"
                //                                            , aParam[0], CmUtil.DoubleParse(aParam[4]).ToString()
                //                                            , aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.AppNo], CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.AppDatatime], 0, 6), CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.AppDatatime], 6, 4)
                //                                            , aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Status].Trim()
                //                                            , aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Message1].Trim() + aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Message2].Trim()
                //                                            , sWriteRecvData });
                //            return sRecvMsg;
                //        }
                //    }

                //}

                //결과 저장

                m_cPayItem.AMT_ENTRY_05 = 0;
                m_cPayItem.AMT_ENTRY_06 = 0;


                var remainValue = int.Parse(aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Message2].Substring(6));

                //선불카드 잔액 저장!
                if (CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Message2], 0, 6).Replace(" ", "") == GIFT_REMAIN_TAG.Replace(" ", ""))
                //if(remainValue  >0)
                {
                    //선불카드 잔액
                    m_cPayItem.OCCUR_ENTRY_22 = Regex.Replace(aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Message2], @"\D", "");     //aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Message2].Replace(GIFT_REMAIN_TAG, "").Replace(GIFT_WON_TAG, "").Trim();

                    //m_cPayItem.OCCUR_ENTRY_22 = remainValue.ToString();
                }
                else if (CmUtil.DoubleParse(aParam[3]) >= 60)
                {
                    // 삼성포인트 잔액
                    // 삼성포인트 잔액
                    string sPoint = aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Notice].Trim();                                           // 잔여포인트
                    sPoint = sPoint.Replace("MINQ", "");

                    m_cPayItem.AMT_ENTRY_05 = CmUtil.DoubleParse(sPoint);                                                                   // 잔여포인트
                    //m_cPayItem.AMT_ENTRY_05 = CmUtil.DoubleParse(aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Notice].Trim());            // 잔여포인트
                    m_cPayItem.AMT_ENTRY_06 = CmUtil.DoubleParse(aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.CustomerInfo].Trim());      // 사용포인트
                }
                else if (aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.IssueCode].Trim() == "56" || aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.IssueCode].Trim() == "57" || aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.IssueCode].Trim() == "46")
                {
                    //지드림, 푸르미, 꿈자람 잔액 - 발급사 코드 56,57,46
                    m_cPayItem.OCCUR_ENTRY_22 = CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Notice], 0, 9).Trim();
                }
                else
                {
                    m_cPayItem.OCCUR_ENTRY_22 = "";
                }


                if (sAppType == PosConst.POS_VAN_MASTER.TRADE_ID.VAN_CARD_CANCEL || sAppType == PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_CANCEL)
                {
                    m_cPayItem.OCCUR_ENTRY_06 = m_cPayItem.OCCUR_ENTRY_02;                                                  // 원승인번호
                    m_cPayItem.OCCUR_ENTRY_07 = m_cPayItem.OCCUR_ENTRY_03;                                                  // 원승인일자
                    m_cPayItem.OCCUR_ENTRY_02 = aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.AppNo];
                    m_cPayItem.OCCUR_ENTRY_03 = CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.AppDatatime], 0, 6);
                    m_cPayItem.OCCUR_ENTRY_17 = GetSignFlag(aParam[10].Trim().Length > 0 ? "1" : "0", m_cPayItem.PAY_AMT);   //사인유무
                }
                else
                {
                    //DataRow dr = PosMstManager.GetMstPayDc(new string[] { m_cPosStatus.Base.CmpCd, m_cPosStatus.Base.StoreNo, ItemConst.TR_ITEM_ID.CREDITCARD_ITEM, ItemConst.TR_ITEM_ID.CREDIT.CREDIT_PAY });

                    m_cPayItem.PAY_AMT = CmUtil.DoubleParse(aParam[4]);

                    m_cPayItem.BILLSPR_NO = m_cTrnStatus.Sale.BillSplitNo;                                                  // 빌분리 번호

                    m_cPayItem.PAY_DTL_CD_02 = aParam[18];
                    m_cPayItem.PAY_DTL_CD_03 = aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.Reserved].ToString().Trim();
                    m_cPayItem.PAY_DTL_CD_04 = "";
                    m_cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.PAY;

                    m_cPayItem.QTY_ENTRY_01 = 0;
                    m_cPayItem.QTY_ENTRY_02 = 0;
                    m_cPayItem.QTY_ENTRY_03 = 0;
                    m_cPayItem.QTY_ENTRY_04 = 0;
                    m_cPayItem.QTY_ENTRY_05 = 0;

                    m_cPayItem.AMT_ENTRY_01 = CmUtil.DoubleParse(aParam[4]);
                    m_cPayItem.AMT_ENTRY_02 = CmUtil.DoubleParse(aParam[19]);  //제휴 할인 금액
                    m_cPayItem.AMT_ENTRY_03 = CmUtil.DoubleParse(aParam[6]);    //세금
                    m_cPayItem.AMT_ENTRY_04 = CmUtil.DoubleParse(aParam[5]);    //봉사료
                    m_cPayItem.AMT_ENTRY_07 = CmUtil.DoubleParse(aParam[12]);  //제휴 할인 금액(캠페인)
                    m_cPayItem.AMT_ENTRY_08 = 0;
                    m_cPayItem.AMT_ENTRY_09 = 0;
                    m_cPayItem.AMT_ENTRY_10 = 0;

                    m_cPayItem.OCCUR_ENTRY_01 = aParam[0];   //카드번호
                    m_cPayItem.OCCUR_ENTRY_02 = aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.AppNo];
                    m_cPayItem.OCCUR_ENTRY_03 = CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.AppDatatime], 0, 6);
                    m_cPayItem.OCCUR_ENTRY_04 = CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.AppDatatime], 6, 4);
                    m_cPayItem.OCCUR_ENTRY_05 = aParam[1];    //입력구분
                    m_cPayItem.OCCUR_ENTRY_06 = "";
                    m_cPayItem.OCCUR_ENTRY_07 = "";
                    m_cPayItem.OCCUR_ENTRY_08 = ItemConst.PAY_APP_DIV.NORMAL;   //승인구분
                    m_cPayItem.OCCUR_ENTRY_09 = aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.IssueCode];
                    m_cPayItem.OCCUR_ENTRY_10 = aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.CardName];
                    m_cPayItem.OCCUR_ENTRY_11 = aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.BuyCode];
                    m_cPayItem.OCCUR_ENTRY_12 = aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.BuyName];
                    m_cPayItem.OCCUR_ENTRY_13 = aParam[11];   //Fallback 구분
                    m_cPayItem.OCCUR_ENTRY_14 = aParam[3];    //할부개월
                    m_cPayItem.OCCUR_ENTRY_15 = aParam[7].Trim().Length > 0 ? "1" : "0";   //은련구분
                    m_cPayItem.OCCUR_ENTRY_16 = GetPayDtlCdToVanCode(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);    // 승인업체 코드 조회
                    m_cPayItem.OCCUR_ENTRY_17 = GetSignFlag(aParam[10].Trim().Length > 0 ? "1" : "0", m_cPayItem.PAY_AMT);   //사인유무
                    m_cPayItem.OCCUR_ENTRY_18 = aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.FranchiseNo];
                    m_cPayItem.OCCUR_ENTRY_19 = aParam[7];    //비밀번호
                    m_cPayItem.OCCUR_ENTRY_20 = aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.CardName].Trim() + ((aParam[8] == "Y") ? "-PayOn" : "");
                    m_cPayItem.OCCUR_ENTRY_21 = GetPayDtlCdToCashBillYn(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);   // 현금영수증 발행여부


                    m_cPayItem.OCCUR_ENTRY_23 = aParam[22];
                    m_cPayItem.OCCUR_ENTRY_24 = aParam[21];
                    m_cPayItem.OCCUR_ENTRY_25 = "";


                    m_cPayItem.CanFiller1 = aParam[2];   //CARD
                    m_cPayItem.CanFiller2 = "";
                    m_cPayItem.CanFiller3 = "";

                    m_cPayItem.CANCEL_DIV = ItemConst.PAY_CANCEL_DIV.NORMAL;

                    // KSN Download 체크
                    if (m_cPayItem.OCCUR_ENTRY_05 == "R")
                    {
                        // 서명패드(RF)
                        if (m_cPosStatus.Base.KSN_SignPad_Download.Trim() == "" && aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.DeviceFunc].ToUpper().Trim() == "K1")
                        {
                            m_cPosStatus.Base.KSN_SignPad_Download = aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.DeviceFunc];

                            CmMessage m_PosSal = CmMessage.MakeMessageFromFile(BaseCom.NxIniPath + PosConst.INI_FILE_NAME.PosSaleInfo);
                            m_PosSal.GetMessage("POSOPEN").MakeMessageOverWrite("KSN_SignPad_Download", m_cPosStatus.Base.KSN_SignPad_Download);
                            m_PosSal.MakeFileFromMessage(BaseCom.NxIniPath + PosConst.INI_FILE_NAME.PosSaleInfo);
                        }
                    }
                    else
                    {
                        // IC 리더기
                        if (m_cPosStatus.Base.KSN_IC_Download.Trim() == "" && aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.DeviceFunc].ToUpper().Trim() == "K1")
                        {
                            m_cPosStatus.Base.KSN_IC_Download = aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.DeviceFunc];

                            CmMessage m_PosSal = CmMessage.MakeMessageFromFile(BaseCom.NxIniPath + PosConst.INI_FILE_NAME.PosSaleInfo);
                            m_PosSal.GetMessage("POSOPEN").MakeMessageOverWrite("KSN_IC_Download", m_cPosStatus.Base.KSN_IC_Download);
                            m_PosSal.MakeFileFromMessage(BaseCom.NxIniPath + PosConst.INI_FILE_NAME.PosSaleInfo);
                        }
                    }

                }

                //사인저장
                if (aParam[10].Trim().Length > 0)
                {
                    //싸인이미지명 변경
                    SetSignImgReName(aIrtDTLRsp[Column.POS_RES_CREDITCARDIC.SEQ.AppNo].ToString());

                    ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);     // 결제 내역 받아 오기
                    SetSignData(alPayItem.Count + 1, aParam[10]);
                }

                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);
            }
            finally
            {
                CmUtil.ZeroFillClear(ref sSendData);
            }

            return sRet;
        }


        /// <summary>
        /// 연습 데이터 설정
        /// </summary>
        public string SetTrainingData(string sAppType, string[] aParam)
        {
            string sRet = UserCom.RST_ERR;

            try
            {
                double dPayAmt = 0;
                double dDcAmt = 0;
                double dtaxAmt = 0;
                double dDcCamp = 0;
                string sCardNo = "";
                string sDivMonth = "";
                string dDcCardCode = "";
                string sCancelFlag = "";

                if (aParam.Length > 0 && aParam[0] == PosConst.POS_CAT_MASTER.TRAN_TYPE)    //단말기승인
                {

                    // 0.전문구분,1.거래유형, 2.할부개월, 3.승인금액 , 4.봉사료, 5.세금, 6.원승인번호, 7.원거래일자, 8.포인트거래구분, 9.상품코드,
                    //10.전표인쇄여부, 11.추가항목, 12.제휴할인코드, 13.제휴할인금액, 14.예비1, 15.예비2
                    dPayAmt = CmUtil.DoubleParse(aParam[3]);
                    dDcAmt = CmUtil.DoubleParse(aParam[13]);
                    sCardNo = "999999**********";
                    sDivMonth = aParam[2];
                    dDcCardCode = aParam[12];
                    dtaxAmt = CmUtil.DoubleParse(aParam[5]);

                    if (sAppType == PosConst.POS_CAT_MASTER.TRADE_ID.CAT_CARD_AGREE || sAppType == PosConst.POS_CAT_MASTER.TRADE_ID.CAT_UNION_AGREE)
                    {
                        sCancelFlag = ItemConst.PAY_CANCEL_DIV.NORMAL;
                    }
                    else
                    {
                        sCancelFlag = ItemConst.PAY_CANCEL_DIV.CANCEL;
                    }

                }
                else
                {
                    //0:마스킹 카드번호 1:입력구분 2:카드번호 3:할부개월 4:총금액 5:봉사료
                    //6:세금 7:비밀번호 8:신용카드종류 9:칩데이터 10:사인
                    //11:Fallback구분 12:제휴할인금액(캠페인) 13:원승인번호 14:원승인일자 15:아이템코드
                    //16:매입사코드 17:매입사명 18:할인카드구분 19:할인금액 20:승인구분

                    dPayAmt = CmUtil.DoubleParse(aParam[4]);
                    dDcAmt = CmUtil.DoubleParse(aParam[19]);
                    dDcCamp = CmUtil.DoubleParse(aParam[12]);
                    sCardNo = aParam[0];
                    sDivMonth = aParam[3];
                    dDcCardCode = aParam[18];
                    dtaxAmt = CmUtil.DoubleParse(aParam[6]);

                    if (sAppType == PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_AGREE || sAppType == PosConst.POS_VAN_MASTER.TRADE_ID.VAN_CARD_AGREE)
                    {
                        sCancelFlag = ItemConst.PAY_CANCEL_DIV.NORMAL;
                    }
                    else
                    {
                        sCancelFlag = ItemConst.PAY_CANCEL_DIV.CANCEL;
                    }
                }

                //DataRow dr = PosMstManager.GetMstPayDc(new string[] { m_cPosStatus.Base.CmpCd, m_cPosStatus.Base.StoreNo, ItemConst.TR_ITEM_ID.CREDITCARD_ITEM, ItemConst.TR_ITEM_ID.CREDIT.CREDIT_PAY });

                m_cPayItem.PAY_WAY_CD = ItemConst.TR_ITEM_ID.CREDITCARD_ITEM;
                m_cPayItem.PAY_AMT = dPayAmt;

                m_cPayItem.BILLSPR_NO = m_cTrnStatus.Sale.BillSplitNo;                                                  // 빌분리 번호

                m_cPayItem.PAY_DTL_CD_01 = ItemConst.TR_ITEM_ID.CREDITCARD.CREDIT_CARD;
                m_cPayItem.PAY_DTL_CD_02 = "";
                m_cPayItem.PAY_DTL_CD_03 = "";
                m_cPayItem.PAY_DTL_CD_04 = "";
                m_cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.PAY;

                m_cPayItem.QTY_ENTRY_01 = 0;
                m_cPayItem.QTY_ENTRY_02 = 0;
                m_cPayItem.QTY_ENTRY_03 = 0;
                m_cPayItem.QTY_ENTRY_04 = 0;
                m_cPayItem.QTY_ENTRY_05 = 0;

                m_cPayItem.AMT_ENTRY_01 = dPayAmt;
                m_cPayItem.AMT_ENTRY_02 = dDcAmt;   //제휴 할인 금액
                m_cPayItem.AMT_ENTRY_03 = dtaxAmt;  //세금
                m_cPayItem.AMT_ENTRY_04 = 0;
                m_cPayItem.AMT_ENTRY_05 = 0;
                m_cPayItem.AMT_ENTRY_06 = 0;
                m_cPayItem.AMT_ENTRY_07 = dDcCamp;
                m_cPayItem.AMT_ENTRY_08 = 0;
                m_cPayItem.AMT_ENTRY_09 = 0;
                m_cPayItem.AMT_ENTRY_10 = 0;

                m_cPayItem.OCCUR_ENTRY_01 = sCardNo;   //카드번호
                m_cPayItem.OCCUR_ENTRY_02 = "99999999";
                m_cPayItem.OCCUR_ENTRY_03 = DateTime.Now.ToString("yyMMdd");
                m_cPayItem.OCCUR_ENTRY_04 = DateTime.Now.ToString("HHmm");
                m_cPayItem.OCCUR_ENTRY_05 = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_KEYIN;
                m_cPayItem.OCCUR_ENTRY_06 = "";   //원승인번호
                m_cPayItem.OCCUR_ENTRY_07 = "";   //원승인일자
                m_cPayItem.OCCUR_ENTRY_08 = ItemConst.PAY_APP_DIV.COMPULSION;
                m_cPayItem.OCCUR_ENTRY_09 = "";
                m_cPayItem.OCCUR_ENTRY_10 = "";
                m_cPayItem.OCCUR_ENTRY_11 = "99";
                m_cPayItem.OCCUR_ENTRY_12 = "";
                m_cPayItem.OCCUR_ENTRY_13 = "0";   //Fallback 구분
                m_cPayItem.OCCUR_ENTRY_14 = sDivMonth;    //할부개월
                m_cPayItem.OCCUR_ENTRY_15 = "0";   //은련구분
                m_cPayItem.OCCUR_ENTRY_16 = GetPayDtlCdToVanCode(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);    // 승인업체 코드 조회
                m_cPayItem.OCCUR_ENTRY_17 = "1";   //사인유무
                m_cPayItem.OCCUR_ENTRY_18 = "";   //매체구분
                m_cPayItem.OCCUR_ENTRY_19 = "";    //비밀번호
                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 = "";
                m_cPayItem.OCCUR_ENTRY_23 = "";
                m_cPayItem.OCCUR_ENTRY_24 = "";
                m_cPayItem.OCCUR_ENTRY_25 = "";

                m_cPayItem.CanFiller1 = "";
                m_cPayItem.CanFiller2 = "";
                m_cPayItem.CanFiller3 = "";

                m_cPayItem.CANCEL_DIV = sCancelFlag;

                sRet = UserCom.RST_OK;

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

            return sRet;

        }

        /// <summary>
        /// 사인유무 체크
        /// </summary>
        /// <param name="sSignDiv"></param>
        /// <param name="dPayAmt"></param>
        /// <returns></returns>
        private string GetSignFlag(string sSignDiv, double dPayAmt)
        {
            string sRet = sSignDiv;

            try
            {
                if (sSignDiv != "1")
                {
                    if (dPayAmt > CmUtil.DoubleParse(CmUtil.IsNull(PosMstManager.GetPosOption(POS_OPTION.OPT007), "50000")))
                    {
                        sRet = "0";
                    }
                    else
                    {
                        sRet = "1";
                    }
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }

            return sRet;
        }

        /// <summary>
        /// Cat 단말기 승인
        /// </summary>
        /// <param name="sAppType"></param>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string CatExecuteIrt(string sAppType, string[] aParam)
        {

            string sRet = UserCom.RST_ERR;

            try
            {

                // 연습모드이면 연습 데이터 설정
                if (m_cPosStatus.Base.TrainingFlag == "1" || m_cPosStatus.Mst.TestStorYn == "1") return SetTrainingData(sAppType, aParam);

                string sRecvdData = "";
                string sAppLogDiv = "";
                string sInputType = "";

                if (sAppType == PosConst.POS_CAT_MASTER.TRADE_ID.CAT_CARD_AGREE || sAppType == PosConst.POS_CAT_MASTER.TRADE_ID.CAT_UNION_AGREE)
                {
                    sAppLogDiv = PosConst.CANCEL_DIV.NORMAL;
                }
                else
                {
                    sAppLogDiv = PosConst.CANCEL_DIV.CANCEL;
                }

                string[] aIrtDTLRsp = new string[Column.POS_RES_SPCN_CAT.LEN.Length];

                //전문 송/수신
                if (CatTerminalExecuteIrtCom(sAppType, sAppLogDiv, aParam, m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, ref aIrtDTLRsp, ref sRecvdData, ref sInputType) == false)
                {
                    return sRet;
                }

                ////결과 저장
                m_cPayItem.AMT_ENTRY_05 = 0;
                m_cPayItem.AMT_ENTRY_06 = 0;

                if (CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.UserCode], 0, 4).StartsWith("SSPT"))
                {
                    // 삼성포인트 잔액
                    m_cPayItem.AMT_ENTRY_05 = CmUtil.DoubleParse(CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AddItem], 0, 13).Trim());       // 잔여포인트
                    m_cPayItem.AMT_ENTRY_06 = CmUtil.DoubleParse(CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AddItem], 13, 13).Trim());      // 사용포인트
                }
                else if (CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.UserCode], 0, 4).StartsWith("MPNT"))
                {
                    // M포인트 잔액
                    m_cPayItem.AMT_ENTRY_05 = CmUtil.DoubleParse(CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AddItem], 0, 13).Trim());       // 잔여포인트
                    m_cPayItem.AMT_ENTRY_06 = CmUtil.DoubleParse(CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AddItem], 13, 13).Trim());      // 사용포인트
                }
                else if (CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.UserCode], 0, 4).StartsWith("0004"))
                {

                    if (aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.IssueCode].Trim() == "56" || aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.IssueCode].Trim() == "57" || aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.IssueCode].Trim() == "46")
                    {
                        //지드림, 푸르미, 꿈자람 잔액 - 발급사 코드 56,57,46
                        m_cPayItem.OCCUR_ENTRY_22 = CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AddItem], 0, 9).Trim();
                    }
                    else
                    {
                        m_cPayItem.OCCUR_ENTRY_22 = "";
                    }
                }
                else
                {
                    m_cPayItem.OCCUR_ENTRY_22 = "";
                }

                if (sAppType == PosConst.POS_CAT_MASTER.TRADE_ID.CAT_CARD_CANCEL)
                {
                    m_cPayItem.OCCUR_ENTRY_06 = m_cPayItem.OCCUR_ENTRY_02;                                                  // 원승인번호
                    m_cPayItem.OCCUR_ENTRY_07 = m_cPayItem.OCCUR_ENTRY_03;                                                  // 원승인일자
                    m_cPayItem.OCCUR_ENTRY_02 = aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AppNo].Trim();
                    m_cPayItem.OCCUR_ENTRY_03 = CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AppDatatime], 0, 6);
                    m_cPayItem.OCCUR_ENTRY_17 = GetSignFlag(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.BuyType].Trim() == "S" ? "1" : "0", m_cPayItem.PAY_AMT);   //사인유무
                }
                else
                {
                    m_cPayItem.PAY_AMT = CmUtil.DoubleParse(aParam[3]);

                    m_cPayItem.BILLSPR_NO = m_cTrnStatus.Sale.BillSplitNo;                                                  // 빌분리 번호

                    m_cPayItem.PAY_DTL_CD_02 = aParam[12];
                    m_cPayItem.PAY_DTL_CD_03 = "";
                    m_cPayItem.PAY_DTL_CD_04 = "";
                    m_cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.PAY;

                    m_cPayItem.QTY_ENTRY_01 = 0;
                    m_cPayItem.QTY_ENTRY_02 = 0;
                    m_cPayItem.QTY_ENTRY_03 = 0;
                    m_cPayItem.QTY_ENTRY_04 = 0;
                    m_cPayItem.QTY_ENTRY_05 = 0;

                    m_cPayItem.AMT_ENTRY_01 = CmUtil.DoubleParse(aParam[3]);
                    m_cPayItem.AMT_ENTRY_02 = CmUtil.DoubleParse(aParam[13]);  //제휴 할인 금액
                    m_cPayItem.AMT_ENTRY_03 = CmUtil.DoubleParse(aParam[5]);
                    m_cPayItem.AMT_ENTRY_04 = CmUtil.DoubleParse(aParam[4]);
                    m_cPayItem.AMT_ENTRY_07 = 0;
                    m_cPayItem.AMT_ENTRY_08 = 0;
                    m_cPayItem.AMT_ENTRY_09 = 0;
                    m_cPayItem.AMT_ENTRY_10 = 0;

                    m_cPayItem.OCCUR_ENTRY_01 = aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.CardBinData].Trim() + "*********";   //카드번호
                    m_cPayItem.OCCUR_ENTRY_02 = aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AppNo].Trim();
                    m_cPayItem.OCCUR_ENTRY_03 = CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AppDatatime], 0, 6);
                    m_cPayItem.OCCUR_ENTRY_04 = CmUtil.MidH(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.AppDatatime], 6, 4);
                    m_cPayItem.OCCUR_ENTRY_05 = sInputType;    //입력구분
                    m_cPayItem.OCCUR_ENTRY_06 = "";
                    m_cPayItem.OCCUR_ENTRY_07 = "";
                    m_cPayItem.OCCUR_ENTRY_08 = ItemConst.PAY_APP_DIV.CAT_TERMINAL;   //승인구분
                    m_cPayItem.OCCUR_ENTRY_09 = aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.IssueCode].Trim();
                    m_cPayItem.OCCUR_ENTRY_10 = aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.CardName].Trim();
                    m_cPayItem.OCCUR_ENTRY_11 = aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.BuyCode].Trim();
                    m_cPayItem.OCCUR_ENTRY_12 = aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.BuyName].Trim();
                    m_cPayItem.OCCUR_ENTRY_13 = aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.PosEntryMode].Trim() == "04" ? "1" : "0";   //Fallback 구분
                    m_cPayItem.OCCUR_ENTRY_14 = aParam[2];    //할부개월
                    m_cPayItem.OCCUR_ENTRY_15 = aParam[1] == PosConst.POS_CAT_MASTER.TRADE_ID.CAT_UNION_AGREE ? "1" : "0";   //은련구분
                    m_cPayItem.OCCUR_ENTRY_16 = GetPayDtlCdToVanCode(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);  //VAN 구분
                    m_cPayItem.OCCUR_ENTRY_17 = GetSignFlag(aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.BuyType].Trim() == "S" ? "1" : "0", m_cPayItem.PAY_AMT);   //사인유무
                    m_cPayItem.OCCUR_ENTRY_18 = aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.FranchiseNo];
                    m_cPayItem.OCCUR_ENTRY_19 = "";    //비밀번호
                    m_cPayItem.OCCUR_ENTRY_20 = aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.CardName].Trim() + ((aParam[8] == "Y") ? "-PayOn" : "");
                    m_cPayItem.OCCUR_ENTRY_21 = GetPayDtlCdToCashBillYn(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);  //현금영수증 발행여부

                    m_cPayItem.OCCUR_ENTRY_23 = aIrtDTLRsp[Column.POS_RES_SPCN_CAT.SEQ.ServiceCode].Trim();  //서비스코드
                    m_cPayItem.OCCUR_ENTRY_24 = ""; // aParam[21];
                    m_cPayItem.OCCUR_ENTRY_25 = "";


                    m_cPayItem.CanFiller1 = ""; //aParam[2];   //CARD
                    m_cPayItem.CanFiller2 = "";
                    m_cPayItem.CanFiller3 = "";

                    m_cPayItem.CANCEL_DIV = ItemConst.PAY_CANCEL_DIV.NORMAL;
                }

                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);
            }
            finally
            {
                //CmUtil.ZeroFillClear(ref sSendData);
            }

            return sRet;
        }

        #region 싸인 bitmap 이름 변경
        /// <summary>
        /// 싸인 bitmap 이름 변경
        /// </summary>
        /// <param name="sAppNo"></param>
        private void SetSignImgReName(string sAppNo)
        {
            try
            {
                string sSourcePath = BaseCom.NxDataPath + "SIGN\\SIGN.BMP";
                string sTagetPath = string.Format("{0}{1}{2}{3}{4}{5}.BMP", BaseCom.NxDataPath, "SIGN\\", m_cPosStatus.Base.SaleDate, m_cPosStatus.Base.PosNo, m_cPosStatus.Base.TradeNo, sAppNo);

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

        #endregion 싸인 bitmap 이름 변경

        #region 취소 거래 싸인 받기
        /// <summary>
        /// 취소거래 싸인 받기
        /// </summary>
        /// <returns></returns>
        private bool GetCancelReSign(double dPayAmt, ref string m_sSign)
        {

            //bool bRet = false;

            m_sSign = "";

            try
            {
                //싸인 받기
                if (m_cPayItem.PAY_AMT > CmUtil.DoubleParse(CmUtil.IsNull(PosMstManager.GetPosOption(POS_OPTION.OPT007), "50000")))
                {


                    if (m_cDevStatus.SignPad.UseYn == true)
                    {
                        string sPath = BaseCom.NxDataPath + "SIGN\\";

                        CmUtil.CreateDirectory(sPath);

                        //if (m_cSignPad.GetSign_SignPad((int)dPayAmt, sPath, "SIGN.BMP", ref m_sSign) == false)
                        if (m_cSignPad.GetSign_SignPadEx(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0557), m_cPosStatus.Global.NumericTOCurrency(dPayAmt) + " " + m_cPosStatus.Global.m_stCultureMaster.strCurrencyName
                            , "", "", sPath, "SIGN.BMP", ref m_sSign) == false)
                        {

                            if (WinManager.QuestionMessage(POS_MESSAGE.ERROR.MSG_0550) == false)
                            {
                                return false;
                            }

                            m_sSign = "";
                        }
                    }
                    else
                    {
                        UserLog.WriteLogFile(UserCom.LOG_DEBUG,
                                     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 (함수명))
                                     "Not Use SingPad Skip!");
                    }
                }
            }
            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 true;
        }
        #endregion 취소 거래 싸인 받기

        #region 신용카드 전문 바디 생성
        /// <summary>
        /// 신용 카드 바디 생성
        /// </summary>
        /// <param name="sDivMonth"></param>
        /// <param name="sCardRecvAmt"></param>
        /// <param name="sUnionPayDiv"></param>
        /// <returns></returns>
        private string MakeCardICBody(string sAppType, string[] aParam, string Reserved)
        {

            string sSendData = string.Empty;
            string[] aIrtBody = null;
            try
            {

                if (sAppType == PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_AGREE || sAppType == PosConst.POS_VAN_MASTER.TRADE_ID.VAN_CARD_AGREE)
                {
                    aIrtBody = new string[Column.POS_REQ_CREDITCARDIC.LEN.Length];

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

                    aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.EntryMode] = aParam[1];
                    aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.TrackII] = aParam[2];
                    aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.TrackIIFS] = PosConst.VAN_HEXA.FS;
                    aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.DivMonth] = aParam[3];
                    aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.TotAmt] = aParam[4];
                    aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.ServiceAmt] = aParam[5];
                    aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.ServiceAmtGS] = PosConst.VAN_HEXA.GS;
                    aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.Vat] = aParam[6];

                    if (string.IsNullOrEmpty(aParam[7]) == true)    //비밀번호 존재시 은련 카드
                    {
                        aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.WKI] = "AA";
                        aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.PassWord] = "";
                        aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.ECSLevel] = "";

                    }
                    else
                    {
                        aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.WKI] = "83";   //확인 완료!
                        aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.PassWord] = aParam[7];
                        aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.ECSLevel] = "E";
                    }

                    aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.ItemCode] = aParam[15];
                    aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.CustmerInfo] = "";
                    aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.Domain] = "";
                    aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.ServerIP] = "";
                    aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.MallBizNo] = "";
                    aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.Reserved] = Reserved;
                    aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.BizDiv] = "";
                    aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.MediaDiv] = aParam[21];
                    aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.CorporationDiv] = "";
                    aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.CardKind] = aParam[8];
                    aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.ETX] = PosConst.VAN_HEXA.ETX;
                    aIrtBody[Column.POS_REQ_CREDITCARDIC.SEQ.CR] = PosConst.VAN_HEXA.CR;

                    // 신용카드 승인 요청 전문 생성
                    sSendData = ItemColumn.MakeMessage(aIrtBody, Column.POS_REQ_CREDITCARDIC.LEN, Column.POS_REQ_CREDITCARDIC.TYPE);
                }
                else if (sAppType == PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_CANCEL || sAppType == PosConst.POS_VAN_MASTER.TRADE_ID.VAN_CARD_CANCEL)
                {
                    aIrtBody = new string[Column.POS_REQ_CREDITCARDIC_CANCEL.LEN.Length];

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

                    aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.EntryMode] = aParam[1];
                    aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.TrackII] = aParam[2];
                    aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.TrackIIFS] = PosConst.VAN_HEXA.FS;
                    aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.DivMonth] = aParam[3];
                    aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.TotAmt] = aParam[4];
                    aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.ServiceAmt] = aParam[5];
                    aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.ServiceAmtGS] = PosConst.VAN_HEXA.GS;
                    aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.Vat] = aParam[6];

                    if (string.IsNullOrEmpty(aParam[7]) == true)    //비밀번호 존재시 은련 카드
                    {
                        aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.WKI] = "AA";
                        aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.PassWord] = "";
                        aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.ECSLevel] = "";

                    }
                    else
                    {
                        aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.WKI] = "BB";   //확인필요!
                        aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.PassWord] = aParam[7];
                        aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.ECSLevel] = "E";
                    }

                    aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.OrgAppNo] = aParam[13];
                    aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.OrgAppDate] = aParam[14];

                    aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.ItemCode] = "";
                    aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.CustmerInfo] = "";

                    aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.Reserved] = "";
                    aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.BizDiv] = "";
                    aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.MediaDiv] = aParam[21];
                    aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.CorporationDiv] = "";
                    aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.CardKind] = aParam[8];
                    aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.ETX] = PosConst.VAN_HEXA.ETX;
                    aIrtBody[Column.POS_REQ_CREDITCARDIC_CANCEL.SEQ.CR] = PosConst.VAN_HEXA.CR;

                    // 신용카드 승인 요청 전문 생성
                    sSendData = ItemColumn.MakeMessage(aIrtBody, Column.POS_REQ_CREDITCARDIC_CANCEL.LEN, Column.POS_REQ_CREDITCARDIC_CANCEL.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 aIrtBody);
            }
            return sSendData;

        }
        #endregion

        #region 카드 발급사 인증 요청
        /// <summary>
        /// 발급사 인증 요청
        /// </summary>
        /// <param name="sIcChipData"></param>
        /// <returns></returns>
        private bool SetCardCardIssuer(string sIcChipData, string AppGbn)
        {

            string sRecvEmv = string.Empty;
            bool bRet = false;

            try
            {

                int nFs = sIcChipData.IndexOf(PosConst.VAN_HEXA.FS) + 1;
                sIcChipData = CmUtil.MidH(sIcChipData, nFs, sIcChipData.Length).Trim();

                if (AppGbn == PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_CANCEL)
                    sIcChipData += PosConst.VAN_HEXA.FS + PosConst.VAN_HEXA.FS + PosConst.VAN_HEXA.FS;

                if (m_cICReader.CardIssuer_ICReader(sIcChipData, ref sRecvEmv) == true)
                {
                    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

        #region 사인데이터 저장
        /// <summary>
        /// 사인데이터 저장
        /// </summary>
        /// <param name="iSeq"></param>
        /// <param name="sSignData"></param>
        private void SetSignData(int iSeq, string sSignData)
        {
            try
            {
                ArrayList aSignItem = (ArrayList)StateObject.GetItemObject(Column.TR_SIGN.ITEM);
                Column.TR_SIGN.DATA cSignItem = new Column.TR_SIGN.DATA();

                cSignItem.SEQ = aSignItem.Count + 1;
                cSignItem.PAY_SEQ = iSeq;
                cSignItem.SIGN_TIME = DateTime.Now.ToString("HHmmss");
                cSignItem.SIGN_DATA = sSignData;

                aSignItem.Add(cSignItem);

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

        }
        #endregion


        #region ExecuteIrtVanCardLogSearch(이동 단말기 로그 조회)

        /// <summary>
        /// 이동단말기 승인 로그 조회
        /// </summary>
        /// <param name="aParam"></param>
        /// <param name="aRet"></param>
        /// <returns></returns>
        private string ExecuteIrtVanCardLogSearch(ref string[] aRet)
        {
            string sRet = UserCom.RST_ERR;
            int iRecvTimeOut = 10000;

            Hashtable htRecvData = new Hashtable();
            Hashtable htSendData = new Hashtable();

            try
            {
                //// 연습모드이면 연습 데이터 설정
                //if (m_cPosStatus.Base.TrainingFlag == "1")
                //{
                //    aRet[0] = "01";
                //    return UserCom.RST_OK;
                //}

                // 조회
                htSendData.Add(Column.IQ_VAN_CARD_APPLOG.DATA.INQ_TYPE, ItemConst.IRT_INQ_TYPE.VAN_CARDLOG_SEARCH);
                htSendData.Add(Column.IQ_VAN_CARD_APPLOG.DATA.STOR_CD, m_cPosStatus.Base.StoreNo);
                htSendData.Add(Column.IQ_VAN_CARD_APPLOG.DATA.SALE_DT, DateTime.Now.ToString("yyyyMMdd"));
                htSendData.Add(Column.IQ_VAN_CARD_APPLOG.DATA.CATID, "");
                htSendData.Add(Column.IQ_VAN_CARD_APPLOG.DATA.DATA_CNT, "0");
                htSendData.Add(Column.IQ_VAN_CARD_APPLOG.DATA.APPR_DATA, "");
                htSendData.Add(Column.IQ_VAN_CARD_APPLOG.DATA.RES_CD, "");

                sRet = m_cDataCommon.ExecutePosIrt(ItemConst.COMM_MSG_TYPE.POSIRT, m_cPosStatus.Base.CommSvrIp, (int)m_cPosStatus.Base.BizInqPort, iRecvTimeOut, htSendData, ref htRecvData);
                if (sRet != UserCom.RST_OK)
                {
                    WinManager.ErrorMessage(sRet);
                    sRet = UserCom.RST_ERR;
                    return sRet;
                }


                if (htRecvData[Column.IQ_VAN_CARD_APPLOG.DATA.RES_CD].ToString() == "09")
                {
                    WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0289));
                }

                aRet = new string[] { htRecvData[Column.IQ_VAN_CARD_APPLOG.DATA.RES_CD].ToString(), htRecvData[Column.IQ_VAN_CARD_APPLOG.DATA.APPR_DATA].ToString() };

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

        #region ExecuteIrtVanCardLogFinal(이동 단말기 등록 완료 요청)

        /// <summary>
        /// 이동 단말기 등록 완료 요청
        /// </summary>
        /// <param name="aRet"></param>
        /// <returns></returns>
        private string ExecuteIrtVanCardLogFinal(string[] aParam, ref string[] aRet)
        {
            string sRet = UserCom.RST_ERR;
            int iRecvTimeOut = 10000;

            Hashtable htRecvData = new Hashtable();
            Hashtable htSendData = new Hashtable();

            try
            {
                // 연습모드이면 연습 데이터 설정
                if (m_cPosStatus.Base.TrainingFlag == "1")
                {
                    aRet[0] = "00";
                    return UserCom.RST_OK;
                }

                // 조회
                htSendData.Add(Column.IQ_VAN_CARD_APPLOG_FINAL.DATA.INQ_TYPE, ItemConst.IRT_INQ_TYPE.VAN_CARDLOG_FINAL);
                htSendData.Add(Column.IQ_VAN_CARD_APPLOG_FINAL.DATA.STOR_CD, m_cPosStatus.Base.StoreNo);
                htSendData.Add(Column.IQ_VAN_CARD_APPLOG_FINAL.DATA.SALE_DT, DateTime.Now.ToString("yyyyMMdd"));
                htSendData.Add(Column.IQ_VAN_CARD_APPLOG_FINAL.DATA.CATID, aParam[1]);
                htSendData.Add(Column.IQ_VAN_CARD_APPLOG_FINAL.DATA.TRAN_SEQ, aParam[2]);
                htSendData.Add(Column.IQ_VAN_CARD_APPLOG_FINAL.DATA.RES_CD, "");

                sRet = m_cDataCommon.ExecutePosIrt(ItemConst.COMM_MSG_TYPE.POSIRT, m_cPosStatus.Base.CommSvrIp, (int)m_cPosStatus.Base.BizInqPort, iRecvTimeOut, htSendData, ref htRecvData);
                if (sRet != UserCom.RST_OK)
                {
                    WinManager.ErrorMessage(sRet);
                    sRet = UserCom.RST_ERR;
                    return sRet;
                }
                aRet = new string[] { htRecvData[Column.IQ_VAN_CARD_APPLOG_FINAL.DATA.RES_CD].ToString() };

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

        #region RF IC DATA 전문 생성
        /// <summary>
        /// RF IC DATA 전문 생성
        /// </summary>
        /// <param name="sInIcData"></param>
        /// <returns></returns>
        private string SetRfIcData(string sInIcData)
        {

            string sOutIcdata = "";

            try
            {
                if (sInIcData != "")
                {
                    sOutIcdata += CmUtil.MidH(sInIcData, 0, 12).Trim();		//DeviceSeqNum
                    sOutIcdata += CmUtil.MidH(sInIcData, 12, 2).Trim();		//PanSeqNum
                    sOutIcdata += CmUtil.MidH(sInIcData, 14, 16).Trim();	//AddPosInfo
                    sOutIcdata += CmUtil.MidH(sInIcData, 30, 64).Trim();	//Iad
                    sOutIcdata += CmUtil.MidH(sInIcData, 94, 32).Trim();	//DFN
                    sOutIcdata += CmUtil.MidH(sInIcData, 126, 16).Trim();	//ARQC
                    sOutIcdata += CmUtil.MidH(sInIcData, 142, 2).Trim();	//CID
                    sOutIcdata += CmUtil.MidH(sInIcData, 144, 8).Trim();	//UTN
                    sOutIcdata += CmUtil.MidH(sInIcData, 152, 4).Trim();	//ATC
                    sOutIcdata += CmUtil.MidH(sInIcData, 156, 10).Trim();	//TVR
                    sOutIcdata += CmUtil.MidH(sInIcData, 166, 6).Trim();	//TTD
                    sOutIcdata += CmUtil.MidH(sInIcData, 172, 2).Trim();	//TST
                    sOutIcdata += CmUtil.MidH(sInIcData, 174, 4).Trim();	//AIP
                    sOutIcdata += CmUtil.MidH(sInIcData, 178, 6).Trim();	//CVMR
                    sOutIcdata += CmUtil.MidH(sInIcData, 184, 6).Trim();	//TC
                    sOutIcdata += CmUtil.MidH(sInIcData, 190, 2).Trim();	//TT
                    sOutIcdata += CmUtil.MidH(sInIcData, 192, 8).Trim();	//IFDSN
                    sOutIcdata += CmUtil.MidH(sInIcData, 200, 2).Trim();	//TSCC
                    sOutIcdata += CmUtil.MidH(sInIcData, 202, 4).Trim();	//AVN
                    sOutIcdata += CmUtil.MidH(sInIcData, 206, 4).Trim();	//TSC
                    sOutIcdata += CmUtil.MidH(sInIcData, 210, 4).Trim();	//PEM
                    //#20170929 페이온 리딩시 칩데이터가 들어온 경우 칩데이터 그대로 승인전문에 넣도록 수정 start
                    sOutIcdata += CmUtil.MidH(sInIcData, 214, 298).Trim();	//삼성페이 서비스데이터
                    //#20170929 페이온 리딩시 칩데이터가 들어온 경우 칩데이터 그대로 승인전문에 넣도록 수정 end
                }

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

        #region X-CHARGE 승인/취소
        /// <summary>
        /// X-CHARGE 승인/취소
        /// </summary>
        /// <param name="sAppType"></param>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string XChargeExecuteIrt(string sAppType, string[] aParam)
        {

            string sRet = UserCom.RST_ERR;

            string sCardNo = string.Empty;
            string sCardNm = string.Empty;
            string sAppNo = string.Empty;
            string sInputFlag = string.Empty;
            string sXcTrandID = string.Empty;
            string sMessage = string.Empty;
            string sReceipt = string.Empty;
            string sValid = string.Empty;

            try
            {

                string sAppDiv = "";    //승인구분

                // 카드번호 입력 화면
                frmXCharge fForm = (frmXCharge)FormManager.GetForm(FormManager.FORM_PAY_XCHARGE_APPR);
                if (fForm == null)
                {
                    fForm = new frmXCharge();
                    FormManager.AddForm(FormManager.FORM_PAY_XCHARGE_APPR, fForm);
                }

                fForm.SetAppType = sAppType;    // 승인구분
                fForm.SetAppAmt = aParam[1];    // 승인금액
                fForm.SetCardNo = aParam[2];    // 원카드번호
                fForm.SetXcTrandID = aParam[3]; // 원거래아이디
                fForm.SetReceipt = aParam[4];   // 원거래정보

                // 요청 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문)
                m_cDataCommon.SetSaleApprLog(sAppType == PosConst.XCHARGE.VOID ? PosConst.CANCEL_DIV.CANCEL : PosConst.CANCEL_DIV.NORMAL
                    , new string[] { m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sAppType, "S", "", CmUtil.DoubleParse(aParam[1]).ToString(), "", "", "", "", "", "" });

                System.Windows.Forms.DialogResult drResult = fForm.ShowDialog();

                sCardNo = fForm.GetCardNo.Trim();
                sValid = fForm.GetValid.Trim();
                sCardNm = fForm.GetCardNm.Trim();
                sAppNo = fForm.GetAppNo.Trim();
                sInputFlag = fForm.GetInputFlag;
                sXcTrandID = fForm.GetXcTrandID.Trim();
                sMessage = fForm.GetMessage.Trim();
                sReceipt = fForm.SetReceipt.Trim();

                string sAppDate = DateTime.Now.ToString("yyMMdd");
                string sAppTime = DateTime.Now.ToString("HHmmss");

                // 응답 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문)
                m_cDataCommon.SetSaleApprLog(sAppType == PosConst.XCHARGE.VOID ? PosConst.CANCEL_DIV.CANCEL : PosConst.CANCEL_DIV.NORMAL
                        , new string[] { m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sAppType, "R"
                        , sCardNm, CmUtil.DoubleParse(aParam[1]).ToString(), sAppNo, sAppDate, sAppTime
                        , drResult == System.Windows.Forms.DialogResult.OK ? "O":"X", sMessage.Trim(), "" });

                if (drResult != System.Windows.Forms.DialogResult.OK)
                {
                    sMessage = fForm.GetMessage;
                    if (string.IsNullOrEmpty(sMessage) == false) WinManager.ErrorMessage(sMessage);
                    return sRet;
                }


                // 연습모드이면 연습 데이터 설정
                if (m_cPosStatus.Base.TrainingFlag == "1" || m_cPosStatus.Mst.TestStorYn == "1")
                {
                    sAppDiv = ItemConst.PAY_APP_DIV.COMPULSION;
                }
                else
                {
                    sAppDiv = ItemConst.PAY_APP_DIV.X_CHARGE;
                }


                if (sAppType == PosConst.XCHARGE.VOID)
                {
                    m_cPayItem.OCCUR_ENTRY_06 = m_cPayItem.OCCUR_ENTRY_02;  // 원승인번호
                    m_cPayItem.OCCUR_ENTRY_07 = m_cPayItem.OCCUR_ENTRY_03;  // 원승인일자
                    m_cPayItem.OCCUR_ENTRY_02 = sAppNo.Trim();              // 승인번호
                    m_cPayItem.OCCUR_ENTRY_03 = sAppDate;                   // 승인일자
                    m_cPayItem.OCCUR_ENTRY_04 = sAppTime;                   // 승인시간
                    m_cPayItem.OCCUR_ENTRY_13 = sValid;                     // Fallback 구분 => 미국유효기간(yyMM)
                    m_cPayItem.OCCUR_ENTRY_18 = sReceipt;                   // 거래정보
                    m_cPayItem.OCCUR_ENTRY_19 = sXcTrandID;                 // 승인 아이디(취소시)
                }
                else
                {
                    m_cPayItem.PAY_AMT = CmUtil.DoubleParse(aParam[1]);

                    m_cPayItem.PAY_DTL_CD_02 = "";
                    m_cPayItem.PAY_DTL_CD_03 = "";
                    m_cPayItem.PAY_DTL_CD_04 = "";
                    m_cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.PAY;

                    m_cPayItem.QTY_ENTRY_01 = 0;
                    m_cPayItem.QTY_ENTRY_02 = 0;
                    m_cPayItem.QTY_ENTRY_03 = 0;
                    m_cPayItem.QTY_ENTRY_04 = 0;
                    m_cPayItem.QTY_ENTRY_05 = 0;

                    m_cPayItem.AMT_ENTRY_01 = m_cPayItem.PAY_AMT;
                    m_cPayItem.AMT_ENTRY_02 = 0;
                    m_cPayItem.AMT_ENTRY_03 = 0;
                    m_cPayItem.AMT_ENTRY_04 = 0;
                    m_cPayItem.AMT_ENTRY_05 = 0;
                    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 = 0;

                    m_cPayItem.OCCUR_ENTRY_01 = sCardNo;                            // 카드번호
                    m_cPayItem.OCCUR_ENTRY_02 = sAppNo;                             // 승인번호
                    m_cPayItem.OCCUR_ENTRY_03 = sAppDate;                           // 승인일자
                    m_cPayItem.OCCUR_ENTRY_04 = sAppTime;                           // 승인시간
                    m_cPayItem.OCCUR_ENTRY_05 = sInputFlag;                         // 입력구분
                    m_cPayItem.OCCUR_ENTRY_06 = "";                                 // 원승인번호
                    m_cPayItem.OCCUR_ENTRY_07 = "";                                 // 원승인일자
                    m_cPayItem.OCCUR_ENTRY_08 = sAppDiv;                            // 승인구분
                    m_cPayItem.OCCUR_ENTRY_09 = "";                                 // 발급사코드
                    m_cPayItem.OCCUR_ENTRY_10 = "";                                 // 발급사명
                    m_cPayItem.OCCUR_ENTRY_11 = "";                                 // 매입사코드
                    m_cPayItem.OCCUR_ENTRY_12 = "";                                 // 매입사명
                    m_cPayItem.OCCUR_ENTRY_13 = sValid;                             // Fallback 구분 => 미국유효기간(yyMM)
                    m_cPayItem.OCCUR_ENTRY_14 = "0";                                // 할부개월
                    m_cPayItem.OCCUR_ENTRY_15 = "0";                                // 은련구분
                    m_cPayItem.OCCUR_ENTRY_16 = "";                                 // VAN 구분
                    m_cPayItem.OCCUR_ENTRY_17 = "";                                 // 사인유무
                    m_cPayItem.OCCUR_ENTRY_18 = sReceipt;                           // 가맹점코드
                    m_cPayItem.OCCUR_ENTRY_19 = sXcTrandID;                         // 승인아이디(취소시 사용)
                    m_cPayItem.OCCUR_ENTRY_20 = sCardNm;                            // 카드명
                    m_cPayItem.OCCUR_ENTRY_21 = ItemConst.PAY_CASHBILL_DIV.NO;      // 현금영수증 발행여부
                    m_cPayItem.OCCUR_ENTRY_22 = "";                                 // 선불카드잔액
                    m_cPayItem.OCCUR_ENTRY_23 = "";                                 // 서비스코드
                    m_cPayItem.OCCUR_ENTRY_24 = "";                                 // 매체구분
                    m_cPayItem.OCCUR_ENTRY_25 = "";

                    m_cPayItem.CanFiller1 = "";
                    m_cPayItem.CanFiller2 = "";
                    m_cPayItem.CanFiller3 = "";

                    m_cPayItem.BILLSPR_NO = m_cTrnStatus.Sale.BillSplitNo;          // 빌분리 번호
                    m_cPayItem.CANCEL_DIV = ItemConst.PAY_CANCEL_DIV.NORMAL;
                }

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

        #endregion

    }
}
