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

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

/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 삼성포인트
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Service
{
    class PointSamsung : PaymentBase, IPaymentUs
    {

        public PointSamsung()
        {
        }

        #region SearchPayment 결제 조회
        /// <summary>
        /// 결제 조회
        /// </summary>
        /// <param name="aParam"></param>
        /// <param name="aRet"></param>
        /// <returns></returns>
        public string SearchPayment(string[] aParam, ref string[] aRet)
        {
            string sRet = UserCom.RST_ERR;
            string sPosMenuKey = "", sInPutData = "", sInEncData = "";
            try
            {
                sPosMenuKey = aParam[0];                                                                         // 메뉴키
                sInPutData = aParam[2];                                                                          // 입력데이터
                sInEncData = aParam[3];                                                                           // 카드데이터

                string sWCC = aParam[1];                                                                                // 입력구분
                double nPayAmt = CmUtil.DoubleParse(aParam[4]);                                                         // 대상금액

                string sApprDate = aParam[5];                                                                           // 승인일자
                string sApprNo = aParam[6];                                                                             // 승인번호
                string sApprTime = aParam[7];                                                                           // 승인시간

                if (sApprDate.Length == 8) sApprDate.Substring(2, 6);                                                   // 승인일자(YYMMDD)

                string sTrType = PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_AGREE;

                m_cPayItem = new Column.TR_PAYMENT.DATA();      // 결과 저장 변수 생성

                m_cPayItem.PAY_WAY_CD = aParam[8];                                                                      // 결제수단
                m_cPayItem.PAY_DTL_CD_01 = aParam[9];                                                                   // 상세코드

                sRet = ExecuteIrt(PosConst.CANCEL_DIV.NORMAL, sTrType, sWCC, sInPutData, sInEncData, nPayAmt, "", "");
            }
            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 sInPutData);
                CmUtil.ZeroFillClear(ref sInEncData);
                CmUtil.ZeroFillClear(ref aParam);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return sRet;
        }
        #endregion

        #region GetPayment 결제 정보 획득
        /// <summary>
        /// 결제 정보 획득
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public object GetPayment(string[] aParam)
        {
            return m_cPayItem;
        }
        #endregion

        #region SetPayment 결제 등록
        /// <summary>
        /// 결제 등록(SPC 임직원 할인)
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string SetPayment(string[] aParam)
        {
            string sRet = UserCom.RST_ERR;
            string sPosMenuKey = "", sInPutData = "", sInEncData = "";

            try
            {
                sPosMenuKey = aParam[0];                                                                         // 메뉴키
                sInPutData = aParam[2];                                                                          // 입력데이터
                sInEncData = aParam[3];                                                                           // 카드데이터

                string sWCC = aParam[1];                                                                                // 입력구분
                double nPayAmt = CmUtil.DoubleParse(aParam[4]);                                                         // 대상금액

                string sApprDate = aParam[5];                                                                           // 승인일자
                string sApprNo = aParam[6];                                                                             // 승인번호
                string sApprTime = aParam[7];                                                                           // 승인시간

                if (sApprDate.Length == 8) sApprDate.Substring(2, 6);                                                   // 승인일자(YYMMDD)

                string sTrType = "";
                if (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL)
                    sTrType = PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_AGREE;
                else
                    sTrType = PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_CANCEL;

                m_cPayItem = new Column.TR_PAYMENT.DATA();                                                              // 결과 저장 변수 생성

                m_cPayItem.PAY_WAY_CD = aParam[8];                                                                      // 결제수단
                m_cPayItem.PAY_DTL_CD_01 = aParam[9];                                                                   // 상세코드

                sRet = ExecuteIrt(PosConst.CANCEL_DIV.NORMAL, sTrType, sWCC, sInPutData, sInEncData, nPayAmt, sApprDate, sApprNo);
                if (sRet != UserCom.RST_OK) return sRet;

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

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

                //WinManager.ConfirmMessage(sPointType + " " + MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0067));
            }
            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 sInPutData);
                CmUtil.ZeroFillClear(ref sInEncData);
                CmUtil.ZeroFillClear(ref aParam);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return sRet;
        }
        #endregion

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

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

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

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

                sInPutData = m_cPayItem.OCCUR_ENTRY_01;                                                          // 입력데이터
                sInEncData = m_cPayItem.CanFiller1;             // 카드데이터

                string sWCC = m_cPayItem.OCCUR_ENTRY_05;                                                                // 입력구분
                double nPayAmt = m_cPayItem.AMT_ENTRY_01;                                                               // 대상금액
                string sApprDate = m_cPayItem.OCCUR_ENTRY_03;                                                           // 승인일자
                string sApprNo = m_cPayItem.OCCUR_ENTRY_02;                                                             // 승인번호
                string sApprTime = m_cPayItem.OCCUR_ENTRY_04;                                                           // 승인시간

                string sTrType = PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_CANCEL;

                sRet = ExecuteIrt(PosConst.CANCEL_DIV.CANCEL, sTrType, sWCC, sInPutData, sInEncData, nPayAmt, sApprDate, sApprNo);
                if (sRet != UserCom.RST_OK) return sRet;

                m_cPayItem.CANCEL_DIV = PosConst.CANCEL_DIV.CANCEL;

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

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

        #region RefundPayment 결제 반품
        /// <summary>
        /// 결제 반품
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public string RefundPayment(string[] aParam)
        {
            string sRet = UserCom.RST_ERR;
            string sInPutData = "", sInEncData = "";

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

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

                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;

                    sRet = UserCom.RST_OK;
                }
                else
                {

                    sInPutData = m_cPayItem.OCCUR_ENTRY_01;                                                          // 입력데이터
                    sInEncData = m_cPayItem.CanFiller1;             // 카드데이터

                    string sWCC = m_cPayItem.OCCUR_ENTRY_05;                                                                // 입력구분
                    double nPayAmt = m_cPayItem.AMT_ENTRY_01;                                                               // 대상금액
                    string sApprDate = m_cPayItem.OCCUR_ENTRY_03;                                                           // 승인일자
                    string sApprNo = m_cPayItem.OCCUR_ENTRY_02;                                                             // 승인번호
                    string sApprTime = m_cPayItem.OCCUR_ENTRY_04;                                                           // 승인시간

                    string sTrType = PosConst.POS_VAN_MASTER.TRADE_ID.VAN_ICCARD_CANCEL;

                    sRet = ExecuteIrt(PosConst.CANCEL_DIV.CANCEL, sTrType, sWCC, sInPutData, sInEncData, nPayAmt, sApprDate, sApprNo);
                    if (sRet != UserCom.RST_OK) return sRet;
                }
                // 여전법 대응 ///////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref m_cPayItem.CanFiller1);
                //////////////////////////////////////////////////////////////////////////////////
            }
            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 sInPutData);
                CmUtil.ZeroFillClear(ref sInEncData);
                CmUtil.ZeroFillClear(ref aParam);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return sRet;
        }
        #endregion

        #region SetMenualPayment
        public string SetMenualPayment(string[] aParam)
        {
            throw new NotImplementedException();
        }
        #endregion

        #region 조회 실행
        /// <summary>
        /// 조회 실행
        /// </summary>
        public string ExecuteIrt(string sTradeDiv, string sTrType, string sWcc, string sInPutData, string sCardData, double nPayAmt, string sApprDate, string sApprNo)
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                // 연습모드이면 연습 데이터 설정
                if (m_cPosStatus.Base.TrainingFlag == "1" || m_cPosStatus.Mst.TestStorYn == "1" ) return SetTrainingData(sTrType, sWcc, sInPutData, sCardData, nPayAmt, sApprDate, sApprNo);

                // 승인업체 코드 조회
                string sVanCD = PosMstManager.GetMstPayDc(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, PosMst.MST_PAY_DC.DATA.APPR_VEND_CD);
                if (sVanCD == "")
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0563);
                    return sRet;
                }

                // 포인트 조회
                string[] aIrtRsp = null;
                string sRecvData = "";
                sRet = ExecuteSamPointIrt(sTradeDiv, sVanCD, sTrType, sWcc, sInPutData, sCardData, nPayAmt, sApprDate, sApprNo, "", "", "", "", "", ref aIrtRsp, ref sRecvData);
                if (sRet != UserCom.RST_OK) return sRet;

                if (sTradeDiv == PosConst.CANCEL_DIV.NORMAL)
                {
                    m_cPayItem.PAY_AMT = CmUtil.DoubleParse(aIrtRsp[Column.POS_RES_POINT.SEQ.ResTrPoint]);

                    m_cPayItem.PAY_DTL_CD_02 = "";      // 캠페인코드
                    m_cPayItem.PAY_DTL_CD_03 = "1";     // 할인금액 아이템 적용여부
                    m_cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.DC;     // 할인결제구분 (1:결제, 2:할인)

                    m_cPayItem.AMT_ENTRY_01 = CmUtil.DoubleParse(aIrtRsp[Column.POS_RES_POINT.SEQ.ResTrPoint]);       // 사용포인트
                    m_cPayItem.AMT_ENTRY_02 = 0;                                                                      // 제휴 할인 금액
                    m_cPayItem.AMT_ENTRY_03 = CmUtil.DoubleParse(aIrtRsp[Column.POS_RES_POINT.SEQ.ResSavePoint]);     // 총포인트
                    m_cPayItem.AMT_ENTRY_04 = CmUtil.DoubleParse(aIrtRsp[Column.POS_RES_POINT.SEQ.ResUsesPoint]);     // 가용포인트(할인후결제금액)
                    m_cPayItem.AMT_ENTRY_05 = CmUtil.DoubleParse(aIrtRsp[Column.POS_RES_POINT.SEQ.ResSparePoint]);

                    m_cPayItem.OCCUR_ENTRY_01 = sInPutData;         // 카드번호
                    m_cPayItem.OCCUR_ENTRY_02 = aIrtRsp[Column.POS_RES_POINT.SEQ.ResApprNo].Trim();                 // 승인번호
                    m_cPayItem.OCCUR_ENTRY_03 = CmUtil.MidH(aIrtRsp[Column.POS_RES_POINT.SEQ.ResTrDate], 0, 6);     // 승인일자
                    m_cPayItem.OCCUR_ENTRY_04 = CmUtil.MidH(aIrtRsp[Column.POS_RES_POINT.SEQ.ResTrDate], 6, 4);     // 승인시간
                    m_cPayItem.OCCUR_ENTRY_05 = sWcc;               // 입력 구분
                    m_cPayItem.OCCUR_ENTRY_06 = sApprNo;            // 원승인번호
                    m_cPayItem.OCCUR_ENTRY_07 = sApprDate;          // 원승인일자
                    m_cPayItem.OCCUR_ENTRY_08 = ItemConst.PAY_APP_DIV.NORMAL;                                               // 승인구분
                    m_cPayItem.OCCUR_ENTRY_16 = sVanCD;             // VAN 구분
                    m_cPayItem.OCCUR_ENTRY_20 = GetPayDtlCdToPayDtlName(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);   // 결제수단명
                    //m_cPayItem.CanFiller1 = sCardData;

                    m_cPayItem.CANCEL_DIV = ItemConst.PAY_CANCEL_DIV.NORMAL;
                    m_cPayItem.BILLSPR_NO = m_cTrnStatus.Sale.BillSplitNo;              // 빌분리 번호
                }
                else
                {
                    m_cPayItem.AMT_ENTRY_03 = CmUtil.DoubleParse(aIrtRsp[Column.POS_RES_POINT.SEQ.ResSavePoint]);     // 총포인트
                    m_cPayItem.AMT_ENTRY_05 = CmUtil.DoubleParse(aIrtRsp[Column.POS_RES_POINT.SEQ.ResSparePoint]);

                    m_cPayItem.OCCUR_ENTRY_01 = sInPutData;         // 카드번호
                    m_cPayItem.OCCUR_ENTRY_02 = aIrtRsp[Column.POS_RES_POINT.SEQ.ResApprNo].Trim();                 // 승인번호
                    m_cPayItem.OCCUR_ENTRY_03 = CmUtil.MidH(aIrtRsp[Column.POS_RES_POINT.SEQ.ResTrDate], 0, 6);     // 승인일자
                    m_cPayItem.OCCUR_ENTRY_04 = CmUtil.MidH(aIrtRsp[Column.POS_RES_POINT.SEQ.ResTrDate], 6, 4);     // 승인시간
                    m_cPayItem.OCCUR_ENTRY_05 = sWcc;               // 입력 구분
                    m_cPayItem.OCCUR_ENTRY_06 = sApprNo;            // 원승인번호
                    m_cPayItem.OCCUR_ENTRY_07 = sApprDate;          // 원승인일자
                }

                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 sInPutData);
                CmUtil.ZeroFillClear(ref sCardData);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return sRet;
        }

        /// <summary>
        /// 연습 데이터 설정
        /// </summary>
        public string SetTrainingData(string sTrType, string sInPutType, string sInPutData, string sCardData, double nPayAmt, string sApprDate, string sApprNo)
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                string sVanCD = PosMstManager.GetMstPayDc(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, PosMst.MST_PAY_DC.DATA.APPR_VEND_CD);    // 승인업체 코드 조회
                if (sVanCD == "")
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0563);
                    return sRet;
                }

                // 연습모드이면 연습 데이터 설정
                m_cPayItem.PAY_AMT = nPayAmt;
                
                m_cPayItem.PAY_DTL_CD_02 = "";          // 캠페인코드
                m_cPayItem.PAY_DTL_CD_03 = "1";         // 할인금액 아이템 적용여부
                m_cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.DC;         // 할인결제구분 (1:결제, 2:할인)

                m_cPayItem.AMT_ENTRY_01 = nPayAmt;      // 사용포인트
                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_08 = 0;

                m_cPayItem.OCCUR_ENTRY_01 = sInPutData;                         // 카드번호
                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 = sInPutType;         // 입력 구분
                m_cPayItem.OCCUR_ENTRY_06 = sApprNo;            // 원승인번호
                m_cPayItem.OCCUR_ENTRY_07 = sApprDate;          // 원승인일자
                m_cPayItem.OCCUR_ENTRY_08 = ItemConst.PAY_APP_DIV.COMPULSION;   //승인구분
                m_cPayItem.OCCUR_ENTRY_16 = sVanCD;             // VAN 구분
                m_cPayItem.OCCUR_ENTRY_20 = GetPayDtlCdToPayDtlName(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01);   // 결제수단명
                //m_cPayItem.CanFiller1 = sCardData;

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

                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 sInPutData);
                CmUtil.ZeroFillClear(ref sCardData);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return sRet;
        }
        #endregion

        #region 포인트 조회 실행
        /// <summary>
        /// 포인트 조회 실행
        /// </summary>
        private  string ExecuteSamPointIrt(string sTradeDiv, string sVanCD, string sTrType, string sInPutType, string sInPutData, string sCardData, double nPayAmt, string sApprDate, string sApprNo
                        , string sPassWord, string sProductCode, string sReserved, string sCampaign, string sAddInfo, ref string[] aIrtRsp, ref string sRecvData)
        {
            string sSendData = "";         // 송수신 전문
            int nNowPos = 0;
            string sRet = UserCom.RST_ERR;
            try
            {
                // 전문 바디 생성                
                sSendData = MakePointBody(sInPutType, sCardData, nPayAmt, sApprDate, sApprNo, sPassWord, sProductCode, sReserved, sCampaign, sAddInfo);

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

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

                // 요청 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문)
                m_cDataCommon.SetSaleApprLog(sTradeDiv, new string[] { m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sTrType, "S", sInPutData, nPayAmt.ToString(), "", "", "", "", "", sSendData });

                // 포인트 전문 송수신
                sRet = m_cDataCommon.ExecuteCardIrt(sTrType, sSendData, ref sRecvData, true, sInPutData);

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

                byte[] bytes = Encoding.Default.GetBytes(sRecvData);
                aIrtRsp = new string[Column.POS_RES_POINT.LEN.Length];

                ItemColumn.ParseMessage(Column.POS_RES_POINT.LEN, Column.POS_RES_POINT.TYPE, bytes, ref nNowPos, ref aIrtRsp);

                // 응답 - 승인로그 저장   (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문)
                m_cDataCommon.SetSaleApprLog(sTradeDiv, new string[] { m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sTrType, "R"
                                                            , sInPutData, CmUtil.DoubleParse(aIrtRsp[Column.POS_RES_POINT.SEQ.ResTrPoint]).ToString()
                                                            , aIrtRsp[Column.POS_RES_POINT.SEQ.ResApprNo].Trim(), CmUtil.MidH(aIrtRsp[Column.POS_RES_POINT.SEQ.ResTrDate], 0, 6), CmUtil.MidH(aIrtRsp[Column.POS_RES_POINT.SEQ.ResTrDate], 6, 4)
                                                            , aIrtRsp[Column.POS_RES_POINT.SEQ.ResStatus].Trim()
                                                            , aIrtRsp[Column.POS_RES_POINT.SEQ.ResMessage1].Trim() + aIrtRsp[Column.POS_RES_POINT.SEQ.ResMessage2].Trim()
                                                            , sRecvData });

                // - 'O' : 승인 'X' : 거절
                if (aIrtRsp[Column.POS_RES_POINT.SEQ.ResStatus] != "O")
                {
                    sRet = aIrtRsp[Column.POS_RES_POINT.SEQ.ResMessage1].Trim() + "\n" + aIrtRsp[Column.POS_RES_POINT.SEQ.ResMessage2].Trim();
                    WinManager.ErrorMessage(sRet);
                    return sRet;
                }

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

        #region 포인트 요청 전문 바디 생성
        /// <summary>
        /// 포인트 요청 전문 바디 생성
        /// </summary>
        /// <param name="sPointType"></param>
        /// <param name="sInPutType"></param>
        /// <param name="sCardData"></param>
        /// <param name="nPayAmt"></param>
        /// <param name="sApprDate"></param>
        /// <param name="sApprNo"></param>
        /// <returns></returns>
        protected string MakePointBody(string sWcc, string sCardData, double nPayAmt, string sApprDate, string sApprNo
                       , string sPassWord, string sProductCode, string sReserved, string sCampaign, string sAddInfo)
        {
            string sSendData = string.Empty;
            try
            {
                string[] aIrtBody = new string[Column.POS_REQ_POINT.LEN.Length];

                if (m_cDevStatus.ICReader.UseYn == true)     // 여신전문금융업법 적용여부 체크
                    aIrtBody[Column.POS_REQ_POINT.SEQ.ReqDocVer] = PosConst.POS_VAN_MASTER.IRT_VERSION_02;
                else 
                    aIrtBody[Column.POS_REQ_POINT.SEQ.ReqDocVer] = PosConst.POS_VAN_MASTER.IRT_VERSION_01;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqEntryMode] = sWcc;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqTrack2] = sCardData.Trim();
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqFS] = PosConst.VAN_HEXA.FS;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqPointAmt] = nPayAmt.ToString();
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqSaleDiv] = "01";
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqOriginSaleNo] = sApprNo;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqOriginSaleDate] = sApprDate;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqPassWord] = (sPassWord == "") ? "0000000000000000" : sPassWord;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqPointType] = "";
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqProductCode] = sProductCode;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqReserved] = sReserved;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqCampaign] = sCampaign;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqRS] = PosConst.VAN_HEXA.RS;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqAddInfo] = sAddInfo;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqETX] = PosConst.VAN_HEXA.ETX;
                aIrtBody[Column.POS_REQ_POINT.SEQ.ReqCR] = PosConst.VAN_HEXA.CR;

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

        
    }
}
