using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;
using System.Data;

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

/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 영수증 반품  결제수단(승인결제)별 완료 처리
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Win
{
    public partial class frmRefundPay : Form
    {
        #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 DeviceStatus m_cDevStatus = new DeviceStatus();                     // 디바이스 관리
        private PosOLEDevice.DelegateOlePos delegatePos;

        private IDataProcessUs m_cDataSrv = null;
        private IDataCommonUs m_cDataCommon = null;                                 // POS 공통함수 인터페이스
        private ISaleReceipt m_cTradeDeal = null;
        private ISaleRefundUs m_cSaleRefund = null;                                 // 반품처리
        private IICReaderUs m_cICReader = null;                                     // IC리더기
        private IPaymentUs m_cPayCancel = null;                                     // 결제 취소 공통 

        //#20171227 인천공항 포스연동 start, phj
        private IAirPortTran m_cAirPortTran = null;
        //#20171227 인천공항 포스연동 end, phj

        /// <summary>
        /// 영수증 리스트
        /// </summary>
        private DataTable m_dtSearchList;
        #endregion

        #region 생성자 & 소멸자
        /// <summary>
        /// 
        /// </summary>
        public frmRefundPay()
        {
            InitializeComponent();

            base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw, true);
            //this.UpdateStyles();

            m_cPosStatus = (PosStatus)StateObject.POS;      // POS 기본정보
            m_cTrnStatus = (TranStatus)StateObject.TRAN;    // POS 거래정보
            m_cDevStatus = (DeviceStatus)StateObject.DEVICE;
            delegatePos = new PosOLEDevice.DelegateOlePos(OnDeviceEvent);

            m_cDataSrv = (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_cTradeDeal = (ISaleReceipt)sManager.InitServiceInstance(ServiceLists.BSV_BASIC.DLL, ServiceLists.BSV_BASIC.SALE_RECEIPT);
            m_cSaleRefund = (ISaleRefundUs)sManager.InitServiceInstance(ServiceLists.BSV_SALE.DLL, ServiceLists.BSV_SALE.SALE_REFUND);
            m_cPayCancel = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.PAYMENTCANCEL);
            m_cICReader = (IICReaderUs)sManager.InitServiceInstance(ServiceLists.AGENT_OLEDEVICE.DLL, ServiceLists.AGENT_OLEDEVICE.DEVICE_ICREADER);

            //#20171227 인천공항 포스연동 start, phj
            m_cAirPortTran = (IAirPortTran)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.AIRPORT_TRAN);
            //#20171227 인천공항 포스연동 end, phj
        }
        /// <summary>
        /// 폼로드
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmRefundPay_Load(object sender, EventArgs e)
        {
            UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", "");

            InitControl();
            DisplayGrid();
            this.TopMost = true;
            this.Tag = "START";
        }
        /// <summary>
        /// 폼클로즈
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmRefundPay_FormClosing(object sender, FormClosingEventArgs e)
        {
            UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", lblTitle.Text);
        }
        /// <summary>
        /// 폼엑티브
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmRefundPay_Activated(object sender, EventArgs e)
        {
            PosOLEDevice.SetEventHandle(delegatePos);

            if (!string.IsNullOrEmpty((string)this.Tag) && this.Tag.ToString() == "START")
            {
                this.Tag = "";
                RefundComplete();
            }
        }
        /// <summary>
        /// 폼디엑티브
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmRefundPay_Deactivate(object sender, EventArgs e)
        {
            PosOLEDevice.SetEventHandle(null);
        }
        #endregion 생성자 & 소멸자

        #region 폼 컨트롤 초기화
        /// <summary>
        /// 폼 컨트롤 초기화
        /// </summary>
        private void InitControl()
        {
            try
            {
                // 이미지 로딩 처리
                picBack.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.POP_SIZE_800X600);

                //FormManager.MovePopUpForm(this, false, m_cPosStatus.Sale.ScreenSizeUser);
                FormManager.SetFormAllControlFont(this, m_cPosStatus.Base.FONT);
                FormManager.SetTextBoxGlobalInfo(this, m_cPosStatus.Global.m_stCultureMaster.nGroupingDigits, m_cPosStatus.Global.m_stCultureMaster.strGroupingSymbol
                    , m_cPosStatus.Global.m_stCultureMaster.nDecimalDigits, m_cPosStatus.Global.m_stCultureMaster.strDecimalSymbol);

                btnExit.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.BTN_CLOSE);
                if (btnExit.Image != null) btnExit.Text = "";

                btnUp2.Image = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_14X9_UP2_BASIC);
                btnUp.Image = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_14X9_UP1_BASIC);
                btnDw.Image = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_14X9_DOWN1_BASIC);
                btnDw2.Image = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_14X9_DOWN2_BASIC);

                if (btnUp2.Image != null) btnUp2.Text = "";
                if (btnUp.Image != null) btnUp.Text = "";
                if (btnDw.Image != null) btnDw.Text = "";
                if (btnDw2.Image != null) btnDw2.Text = "";

                //테마색상 적용!
                btnEnter.BackColor = CmUtil.GetColorToString(m_cPosStatus.ScnMst.ThemeColor);

                lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0379);
                lblSaleDate.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0242);
                lblPosNo.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0370);
                lblTradeNo.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0346);

                btnEnter.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0394);
                btnMenual.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0395);

                lblComplete.Text = MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0339);

                txtSaleDate.Text = m_cPosStatus.Global.DateToCulture(m_cTrnStatus.Head.OrgSaleDate);
                txtPosNo.Text = m_cTrnStatus.Head.OrgPosNo;
                txtTradeNo.Text = m_cTrnStatus.Head.OrgTradeNo;

                //lblComplete.SetBounds(10, 120, 780, 470);
                lblComplete.BringToFront();
                lblComplete.Visible = false;
                InitializeGrid();
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        /// <summary>
        /// 그리드 초기화
        /// </summary>
        private void InitializeGrid()
        {
            try
            {
                grdSearchList.CsmGridColumnHeadersVisible = true;           //DataGridView 자체의 컬럼 헤더 Visible 여부

                grdSearchList.CsmGridColumnHeadersFont = new Font(m_cPosStatus.Base.FONT, 11);

                grdSearchList.CsmGridColumnHeadersHeight = 38;              //DataGridView 자체의 컬럼 헤더 높이
                grdSearchList.CsmGridRowsHeight = 40;
                grdSearchList.CsmGridColumnCount = 17;                      //그리드의 컬럼수
                grdSearchList.CsmGridShowPageRowsCount = 9;                 //그리드의 한 화면에 보이는 로우수
                grdSearchList.CsmGridSetHeaderBackColor(236, 238, 239);                             //그리드 헤더 배경색
                grdSearchList.CsmGridDefaultRowBackColor = Color.FromArgb(255, 255, 255);           //그리드 홀수(Default)행의 배경색 지정
                grdSearchList.CsmGridAlternateRowBackColor = Color.FromArgb(251, 253, 255);         //그리드 짝수(Alternate)행의 배경색 지정
                grdSearchList.CsmGridBackGroundColor = Color.FromArgb(251, 253, 255);               //기본 백그라운드 컬러
                grdSearchList.CsmGridHighlightColor = Color.FromArgb(255, 251, 211);                //그리드 선택 백 컬러
                grdSearchList.CsmGridHighlightTextColor = Color.Black;                              //그리드 선택 글자 컬러
                grdSearchList.CsmGridSetColumnWidth(new int[] { 35, 110, 100, 100, 75, 140, 89, 79, 0, 0, 0, 0, 0, 0, 0, 0, 0 });     //컬럼넓이 지정
                grdSearchList.CsmGridAlignment(new int[] { 1, 0, 2, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });                     //컬럼 정렬 0:왼쪽, 1:가운데, 2:오른쪽

                //각 컬럼별 이름 지정(NO, 결제내역, 승인금액, 원승인번호, 원승인시간, 카드번호, 승인구분, 완료여부, 결제코드, 상세코드, 행번호, 승인구분코드, 완료여부코드, 카드재입력구분, 입력구분, T폐이거래일련번호)
                grdSearchList.CsmGridColumnName(0, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0014));
                grdSearchList.CsmGridColumnName(1, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0384));
                grdSearchList.CsmGridColumnName(2, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0396));
                grdSearchList.CsmGridColumnName(3, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0053));
                grdSearchList.CsmGridColumnName(4, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0446));
                grdSearchList.CsmGridColumnName(5, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0051));
                grdSearchList.CsmGridColumnName(6, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0385));
                grdSearchList.CsmGridColumnName(7, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0247));
                grdSearchList.CsmGridColumnName(8, "PAY_WAY_CD");
                grdSearchList.CsmGridColumnName(9, "PAY_DTL_CD");
                grdSearchList.CsmGridColumnName(10, "SEQ_NO");
                grdSearchList.CsmGridColumnName(11, "APP_DIV");
                grdSearchList.CsmGridColumnName(12, "APP_END");
                grdSearchList.CsmGridColumnName(13, "INCARD_YN");
                grdSearchList.CsmGridColumnName(14, "INPUT_TYPE");
                grdSearchList.CsmGridColumnName(15, "TPAY_TRADE_SEQ");
                grdSearchList.CsmGridColumnName(16, "PASSWORD_YN");

                //그리드 초기화 테이블
                m_dtSearchList = new DataTable("INIT");
                m_dtSearchList.Columns.Add(new DataColumn("NO", typeof(string)));
                m_dtSearchList.Columns.Add(new DataColumn("PAY_NAME", typeof(string)));
                m_dtSearchList.Columns.Add(new DataColumn("PAY_AMT", typeof(string)));
                m_dtSearchList.Columns.Add(new DataColumn("ORG_APP_NO", typeof(string)));
                m_dtSearchList.Columns.Add(new DataColumn("ORG_APP_TM", typeof(string)));
                m_dtSearchList.Columns.Add(new DataColumn("PAY_CARD", typeof(string)));
                m_dtSearchList.Columns.Add(new DataColumn("APP_DIV_NM", typeof(string)));
                m_dtSearchList.Columns.Add(new DataColumn("APP_END_NM", typeof(string)));
                m_dtSearchList.Columns.Add(new DataColumn("PAY_WAY_CD", typeof(string)));
                m_dtSearchList.Columns.Add(new DataColumn("PAY_DTL_CD", typeof(string)));
                m_dtSearchList.Columns.Add(new DataColumn("SEQ_NO", typeof(string)));
                m_dtSearchList.Columns.Add(new DataColumn("APP_DIV", typeof(string)));
                m_dtSearchList.Columns.Add(new DataColumn("APP_END", typeof(string)));
                m_dtSearchList.Columns.Add(new DataColumn("INCARD_YN", typeof(string)));
                m_dtSearchList.Columns.Add(new DataColumn("INPUT_TYPE", typeof(string)));
                m_dtSearchList.Columns.Add(new DataColumn("TPAY_TRADE_SEQ", typeof(string)));
                m_dtSearchList.Columns.Add(new DataColumn("PASSWORD_YN", typeof(string)));
                m_dtSearchList.Clear();
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        /// <summary>
        /// 그리드 표시
        /// </summary>
        private void DisplayGrid()
        {
            try
            {
                m_dtSearchList.Clear();

                ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);

                for (int nRow = 0; nRow < alPayItem.Count; nRow++)
                {
                    Column.TR_PAYMENT.DATA cPayItem = (Column.TR_PAYMENT.DATA)alPayItem[nRow];

                    if (cPayItem.CANCEL_DIV == ItemConst.PAY_CANCEL_DIV.CANCEL) continue;

                    if (cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.CASH_ITEM                                                                                       // 현금
                         || cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.GIFT_ITEM                                                                                   // 상품권
                         || (cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.PAYETC_ITEM && cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.PAYETC.BALANCE_VOUCHER)      // 잔액교환권
                         || (cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.PAYETC_ITEM && cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.PAYETC.MEAL_TIKET)           // 식권
                         || cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.FOREIGNEX_ITEM                                                                              // 외화

                        //#20180202 인천공항 VIP 라운지 기능미사용으로 주석처리 start,phj
                        /*
                        // grayber@20180115 인천공항 VIP 라운지 start - 반품 결제코드 추가
                         || cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.PAYETC_ITEM && cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.PAYETC.VIP_LOUNGE     // 인천공항 VIP 라운지
                        // grayber@20180115 인천공항 VIP 라운지 end
                        */
                        //#20180202 인천공항 VIP 라운지 기능미사용으로 주석처리 end,phj

                        //grayber@20180208 코레일 마일리지 입력 start - 반품 분기 코드 추가
                        || (cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.POINT_ITEM && cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.POINT_USE.KORAIL_MILEAGE)        // 코레일 마일리지
                        //grayber@20180208 코레일 마일리지 입력 end

                        )
                    {
                        // 거스름
                        if (cPayItem.AMT_ENTRY_02 > 0)
                        {
                            m_cPosStatus.Sale.ChangeCashAmt = cPayItem.AMT_ENTRY_02;
                        }
                    }

                    bool bADD = false;
                    string sInCardDiv = "0";             // 카드재입력구분 => 0:안함, 1:재입력, 2:기존번호 암호화, 3:현금영수증자진발급
                    string addName = string.Empty;
                    string sPassWordYn = "N";
                    switch (cPayItem.PAY_WAY_CD)
                    {
                        case ItemConst.TR_ITEM_ID.CREDITCARD_ITEM:      // 신용 카드
                        case ItemConst.TR_ITEM_ID.MOBILE_COM_POINT:     // 제휴 통신사
                        case ItemConst.TR_ITEM_ID.POINT_ITEM:           // 포인트 사용
                            bADD = true;

                            //#20171227 인천공항 포스연동 start, phj
                            if (PosMstManager.GetPosOption(POS_OPTION.OPT512) == "1" &&
                                (cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.CREDITCARD_ITEM && 
                                cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.CREDITCARD.CREDIT_CARD))
                            {
                                bADD = false;
                                sInCardDiv = "0";
                            }
                            //grayber@20180208 코레일 마일리지 입력 start - 반품 분기 코드 추가
                            else if (cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.POINT_ITEM && cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.POINT_USE.KORAIL_MILEAGE)
                            {
                                bADD = false;
                                sInCardDiv = "0";
                            }
                            //grayber@20180208 코레일 마일리지 입력 end
                            else
                            {
                                //#20171227 인천공항 포스연동 end, phj
                                if (cPayItem.OCCUR_ENTRY_08 == ItemConst.PAY_APP_DIV.CAT_TERMINAL || cPayItem.OCCUR_ENTRY_08 == ItemConst.PAY_APP_DIV.X_CHARGE)
                                {
                                    sInCardDiv = "2";
                                }
                                else
                                {
                                    if (cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.POINT_ITEM
                                        && (cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.POINT_USE.HAPPY_POINT || cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.POINT_USE.HAPPY_POINT_USE_CHINA))
                                    {
                                        sInCardDiv = "2";
                                        //sInCardDiv = "1";
                                        //sPassWordYn = cPayItem.OCCUR_ENTRY_13;  // 해피포인트사용시 비밀번호 사용여부
                                        //if (cPayItem.OCCUR_ENTRY_14.Trim() != "" && sPassWordYn == "N") sInCardDiv = "2";

                                        //#20170830 IC리더기에서 해피포인트 실물카드 사용 후 반품시 재리딩 하도록 수정 start
                                        if (cPayItem.OCCUR_ENTRY_14.Trim() == "") sInCardDiv = "1";
                                        //#20170830 IC리더기에서 해피포인트 실물카드 사용 후 반품시 재리딩 하도록 수정 end
                                    }
                                    //#20170906 T페이 고도화 작업 phj, start
                                    else if ((cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.MOBILE_COM_POINT && cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_SKT) &&
                                             (cPayItem.OCCUR_ENTRY_01.IndexOf("*") < 0))
                                    {
                                        sInCardDiv = "2";
                                    }
                                    //#20170906 T페이 고도화 작업 phj, end

                                    //#20180413 웰컴카드 신규기능 추가 start,phj
                                    else if ((cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.MOBILE_COM_POINT &&
                                              cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.MOBILE_COM.WELCOMECARD)
                                              && (cPayItem.OCCUR_ENTRY_01.IndexOf("*") < 0))
                                    {
                                        sInCardDiv = "0";
                                    }
                                    //#20180413 웰컴카드 신규기능 추가 end,phj
                                    else
                                    {
                                        sInCardDiv = "1";
                                    }
                                }
                                //#20171227 인천공항 포스연동 start, phj
                            }
                            //#20171227 인천공항 포스연동 end, phj
                            break;
                        case ItemConst.TR_ITEM_ID.EMP_PAY_ITEM:         // 임직원 결제
                            bADD = true;
                            sInCardDiv = "1";
                            break;
                        case ItemConst.TR_ITEM_ID.PAY_ITEM:             // 페이
                            if (cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.PAY.ALIPAY_PAY)
                            {
                                bADD = true;
                                sInCardDiv = "2";
                            }
                            else if (cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.PAY.SMILE_PAY)
                            {
                                bADD = true;
                                sInCardDiv = "1";
                            }
                            else if (cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.PAY.T_PAY)
                            {
                                bADD = true;
                                sInCardDiv = "1";

                                // T폐이 거래일련번호 (통합결제 시 SKT 할인 매칭키)
                                if (string.IsNullOrWhiteSpace(cPayItem.OCCUR_ENTRY_15) == false)
                                {
                                    addName = "(" + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0866) + ")";
                                }
                                sPassWordYn = "Y";
                            }
                            else if (cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.PAY.WECHAT_PAY)
                            {
                                bADD = true;
                                sInCardDiv = "2";
                            }
                            // #Rhee, 20170922 중국 은련페이 추가 start
                            else if (cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.PAY.UNION_PAY)
                            {
                                bADD = true;
                                sInCardDiv = "2";
                            }
                            // #Rhee, 20170922 중국 은련페이 추가 end
                            //#2017.09.11.001;위쳇페이 바이롱 추가 start ;girak.kim 
                            else if (cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.PAY.WECHAT_BIORONG_PAY
                                    || cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.PAY.XIAO_GIFTCARD_PAY)
                            {
                                bADD = true;
                                sInCardDiv = "2";
                            }
                            //#2017.09.11.001;위쳇페이 바이롱 추가 end ;girak.kim 

                            break;
                        case ItemConst.TR_ITEM_ID.COUPON_ITEM:          // 쿠폰
                            if (cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.COUPON.INCARD)
                            {
                                bADD = true;
                                sInCardDiv = "2";
                            }
                            else if (cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.COUPON.ONLINE)
                            {
                                bADD = true;
                            }
                            break;
                        //#20171122 티머니 승인취소창에 표기되도록 수정 start
                        case ItemConst.TR_ITEM_ID.MOBILECASH_ITEM:       // 티머니, 캐시비
                            bADD = true;
                            sInCardDiv = "2";
                            break;
                        //#20171122 티머니 승인취소창에 표기되도록 수정 end
                        case ItemConst.TR_ITEM_ID.MOBILECON_ITEM:       // 모바일쿠폰
                            bADD = true;
                            sInCardDiv = "0";
                            break;
                        case ItemConst.TR_ITEM_ID.PPCARD_ITEM:          // 선불카드
                            //#20171018, 해피기프트(코나머니) 결제코드(신용->선불) 변경 Start, srlee
                            // 기존
                            //if (cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.PPCARD.HP_GIFT)          //해피기프트
                            if (cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.PPCARD.HP_GIFT || cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.PPCARD.HPGIFT_CARD)          //해피기프트
                            //#20171018, 해피기프트(코나머니) 결제코드(신용->선불) 변경 End, srlee
                            {
                                bADD = true;
                                sInCardDiv = "1";
                            }
                            else
                            {
                                bADD = true;
                                sInCardDiv = "0";
                            }
                            break;
                        case ItemConst.TR_ITEM_ID.EMP_DC_ITEM:          // 직원 할인
                            if (cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.EMP_DC.SPC)              //SPC할인
                            {
                                bADD = true;
                                sInCardDiv = "2";
                            }
                            else if (cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.EMP_DC.SPC_PAY)              //SPC할인
                            {
                                bADD = true;
                                sInCardDiv = "2";
                            }
                            else if (cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.EMP_DC.SPC_CHINA)           //SPC할인(중국)
                            {
                                bADD = true;
                                sInCardDiv = "2";
                            }
                            if (cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.EMP_DC.SAMSUNGCARD)      // 삼성 SFC
                            {

                            }
                            break;
                    }
                    if (bADD == true)
                    {

                        string sAppTypeNm = "";

                        if (cPayItem.OCCUR_ENTRY_08 == ItemConst.PAY_APP_DIV.NORMAL || cPayItem.OCCUR_ENTRY_08 == ItemConst.PAY_APP_DIV.X_CHARGE)
                        {
                            sAppTypeNm = "";
                        }
                        else if (cPayItem.OCCUR_ENTRY_08 == ItemConst.PAY_APP_DIV.CAT_TERMINAL)
                        {
                            sAppTypeNm = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0854);
                        }
                        else
                        {
                            sAppTypeNm = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0364);
                        }

                        DataRow drNewRow = m_dtSearchList.NewRow();
                        drNewRow["NO"] = (m_dtSearchList.Rows.Count + 1).ToString();
                        //drNewRow["PAY_NAME"] = cPayItem.OCCUR_ENTRY_20;
                        drNewRow["PAY_NAME"] = cPayItem.OCCUR_ENTRY_20 + addName;
                        drNewRow["PAY_AMT"] = m_cPosStatus.Global.NumericTOCurrency(cPayItem.PAY_AMT);
                        drNewRow["ORG_APP_NO"] = cPayItem.OCCUR_ENTRY_02;
                        drNewRow["ORG_APP_TM"] = CmUtil.StrToTime(cPayItem.OCCUR_ENTRY_04);
                        drNewRow["PAY_CARD"] = cPayItem.OCCUR_ENTRY_01;
                        drNewRow["APP_DIV_NM"] = sAppTypeNm; // cPayItem.OCCUR_ENTRY_08 == ItemConst.PAY_APP_DIV.NORMAL ? "" : MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0364);
                        drNewRow["APP_END_NM"] = "";
                        drNewRow["PAY_WAY_CD"] = cPayItem.PAY_WAY_CD;
                        drNewRow["PAY_DTL_CD"] = cPayItem.PAY_DTL_CD_01;
                        drNewRow["SEQ_NO"] = nRow.ToString();
                        drNewRow["APP_DIV"] = cPayItem.OCCUR_ENTRY_08;
                        drNewRow["APP_END"] = "";
                        drNewRow["INCARD_YN"] = sInCardDiv;
                        drNewRow["INPUT_TYPE"] = cPayItem.OCCUR_ENTRY_05;
                        drNewRow["TPAY_TRADE_SEQ"] = cPayItem.OCCUR_ENTRY_15;
                        drNewRow["PASSWORD_YN"] = sPassWordYn;
                        m_dtSearchList.Rows.Add(drNewRow);
                    }
                }

                ArrayList alEtcItem = (ArrayList)StateObject.GetItemObject(Column.TR_ETC.ITEM);

                for (int nRow = 0; nRow < alEtcItem.Count; nRow++)
                {
                    Column.TR_ETC.DATA cEtcItem = (Column.TR_ETC.DATA)alEtcItem[nRow];

                    if (cEtcItem.CANCEL_DIV == ItemConst.PAY_CANCEL_DIV.CANCEL) continue;

                    bool bADD = false;
                    string sInCardDiv = "0";         // 카드재입력구분 => 0:안함, 1:재입력, 2:기존번호 암호화, 3:현금영수증자진발급
                    switch (cEtcItem.ETC_WAY_CD)
                    {
                        #region
                        case ItemConst.TR_ITEM_ID.ETC_INFO_ITEM:    // 기타수단
                            if (cEtcItem.ETC_DTL_CD_01 == ItemConst.TR_ITEM_ID.ETC_INFO.SAVEPOINT)
                            {

                                bADD = true;

                                if (cEtcItem.OCCUR_ENTRY_08 == ItemConst.PAY_APP_DIV.CAT_TERMINAL)
                                {
                                    sInCardDiv = "2";
                                }
                                else
                                {
                                    sInCardDiv = "1";
                                    if (cEtcItem.OCCUR_ENTRY_14.Trim() != "") sInCardDiv = "2";
                                }
                            }
                            else if (cEtcItem.ETC_DTL_CD_01 == ItemConst.TR_ITEM_ID.ETC_INFO.OCB_SAVE)
                            {
                                bADD = true;
                                if (cEtcItem.OCCUR_ENTRY_08 == ItemConst.PAY_APP_DIV.CAT_TERMINAL)
                                {
                                    sInCardDiv = "2";
                                }
                                else
                                {
                                    sInCardDiv = "1";
                                }

                            }
                            else if (cEtcItem.ETC_DTL_CD_01 == ItemConst.TR_ITEM_ID.ETC_INFO.CASHBILL)
                            {
                                bADD = true;
                                if (cEtcItem.OCCUR_ENTRY_08 == ItemConst.PAY_APP_DIV.CAT_TERMINAL)
                                {
                                    sInCardDiv = "2";
                                }
                                else
                                {
                                    if (cEtcItem.OCCUR_ENTRY_10 == "1")
                                        sInCardDiv = "3";
                                    else
                                        sInCardDiv = "1";
                                }


                                //#20171227 인천공항 포스연동 start, phj
                                if (PosMstManager.GetPosOption(POS_OPTION.OPT512) == "1")
                                {
                                    if (cEtcItem.ETC_WAY_CD == ItemConst.TR_ITEM_ID.ETC_INFO_ITEM &&
                                        cEtcItem.ETC_DTL_CD_01 == ItemConst.TR_ITEM_ID.ETC_INFO.CASHBILL)
                                    {
                                        sInCardDiv = "0";
                                        bADD = false;
                                    }
                                }
                                //#20171227 인천공항 포스연동 end, phj
                            }
                            else if (cEtcItem.ETC_DTL_CD_01 == ItemConst.TR_ITEM_ID.ETC_INFO.ONLINE_CPN)
                            {
                                bADD = true;
                            }
                            else if (cEtcItem.ETC_DTL_CD_01 == ItemConst.TR_ITEM_ID.ETC_INFO.POINT_SAVE_CHINA)
                            {
                                sInCardDiv = "2";
                                bADD = true;
                            }
                            break;
                        #endregion
                    }
                    if (bADD == true)
                    {

                        string sAppTypeNm = "";

                        if (cEtcItem.OCCUR_ENTRY_08 == ItemConst.PAY_APP_DIV.NORMAL)
                        {
                            sAppTypeNm = "";
                        }
                        else if (cEtcItem.OCCUR_ENTRY_08 == ItemConst.PAY_APP_DIV.CAT_TERMINAL)
                        {
                            sAppTypeNm = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0854);
                        }
                        else
                        {
                            sAppTypeNm = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0364);
                        }


                        DataRow drNewRow = m_dtSearchList.NewRow();
                        drNewRow["NO"] = (m_dtSearchList.Rows.Count + 1).ToString();
                        drNewRow["PAY_NAME"] = cEtcItem.OCCUR_ENTRY_20;
                        drNewRow["PAY_AMT"] = m_cPosStatus.Global.NumericTOCurrency(cEtcItem.ETC_AMT);
                        drNewRow["ORG_APP_NO"] = cEtcItem.OCCUR_ENTRY_02;
                        drNewRow["ORG_APP_TM"] = CmUtil.StrToTime(cEtcItem.OCCUR_ENTRY_04);
                        drNewRow["PAY_CARD"] = cEtcItem.OCCUR_ENTRY_01;
                        drNewRow["APP_DIV_NM"] = sAppTypeNm; // cEtcItem.OCCUR_ENTRY_08 == ItemConst.PAY_APP_DIV.NORMAL ? "" : MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0364);
                        drNewRow["APP_END_NM"] = "";
                        drNewRow["PAY_WAY_CD"] = cEtcItem.ETC_WAY_CD;
                        drNewRow["PAY_DTL_CD"] = cEtcItem.ETC_DTL_CD_01;
                        drNewRow["SEQ_NO"] = nRow.ToString();
                        drNewRow["APP_DIV"] = cEtcItem.OCCUR_ENTRY_08;
                        drNewRow["APP_END"] = "";
                        drNewRow["INCARD_YN"] = sInCardDiv;
                        drNewRow["INPUT_TYPE"] = cEtcItem.OCCUR_ENTRY_05;
                        drNewRow["TPAY_TRADE_SEQ"] = "";
                        drNewRow["PASSWORD_YN"] = "N";

                        m_dtSearchList.Rows.Add(drNewRow);
                    }
                }

                // 그리드 적용
                grdSearchList.CsmGridDataSource = m_dtSearchList;
                grdSearchList.CsmGridSelectRow(0);
                grdSearchItem_GridClickEvent(null, 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);
            }
        }
        #endregion

        #region Control Event

        #region 버튼 입력 처리
        /// <summary>
        /// 버튼 입력 처리
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnProc_Click(object sender, EventArgs e)
        {
            try
            {
                if (((Cosmos.UI.CsmButton)sender) == btnEnter)      // 반품승인
                {
                    RefundPayment(ItemConst.PAY_APP_DIV.NORMAL);
                }
                if (((Cosmos.UI.CsmButton)sender) == btnMenual)     // 수기승인
                {
                    RefundPayment(ItemConst.PAY_APP_DIV.PHON_CANCEL);
                }
                if (((Cosmos.UI.CsmButton)sender) == btnExit)       // 닫기
                {
                    foreach (DataRow dr in m_dtSearchList.Rows)
                    {
                        // 반품승인된 결제수단이 있느지 체크
                        if (dr["APP_END"].ToString() == "0")
                        {
                            WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0264);
                            return;
                        }
                    }

                    this.DialogResult = DialogResult.Cancel;
                    this.Close();
                }
            }
            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

        /// <summary>
        /// 조회 그리드 업/다운 클릭 이벤트
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSelProc_Click(object sender, EventArgs e)
        {
            try
            {
                if ((UI.CsmButton)sender == btnUp2)
                {
                    grdSearchList.CsmGridScroll("PAGE UP");
                }
                else if ((UI.CsmButton)sender == btnUp)
                {
                    grdSearchList.CsmGridScroll("UP");
                }
                else if ((UI.CsmButton)sender == btnDw)
                {
                    grdSearchList.CsmGridScroll("DOWN");
                }
                else if ((UI.CsmButton)sender == btnDw2)
                {
                    grdSearchList.CsmGridScroll("PAGE DOWN");
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (DataRow dr in m_dtSearchList.Rows)
                {
                    // 반품승인된 결제수단이 있느지 체크
                    if (dr["APP_END"].ToString() == "0")
                    {
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0264);
                        return;
                    }
                }

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

            }
        }

        /// <summary>
        /// 그리드 클릭 이벤트
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="rowIndex"></param>
        private void grdSearchItem_GridClickEvent(object sender, string rowIndex)
        {
            try
            {
                btnMenual.Visible = false;
                btnEnter.Visible = false;

                if (grdSearchList.CsmGridRowsCount == 0) return;

                int nRow = grdSearchList.CsmGridSelectedRowIndex;
                if (nRow < 0) return;

                // NO, 결제내역, 승인금액, 원승인번호, 원승인시간, 카드번호, 승인구분, 완료여부, 결제코드, 상세코드, 행번호, 승인구분코드, 완료여부코드, 카드재입력구분, 입력구분, T폐이거래일련번호                string sPayName = grdSearchList.CsmGridGetCell(nRow, 1);
                string sPayDtlCD = grdSearchList.CsmGridGetCell(nRow, 9);
                string sAppDiv = grdSearchList.CsmGridGetCell(nRow, 11);
                string sAppEnd = grdSearchList.CsmGridGetCell(nRow, 12);

                // 반품 승인
                if (sAppEnd == "")
                {
                    btnEnter.Visible = true;
                    btnMenual.Visible = 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);
            }
        }

        /// <summary>
        /// 컨트롤 이벤트
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Control_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {

            }
            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 User Method

        /// <summary>
        /// 반품처리
        /// </summary>
        /// <returns></returns>
        private bool RefundPayment(string sMenualKind)
        {
            //#20171020 log 추가 
            UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                    "반품승인 종류 : " + sMenualKind);


            string sRet = "";
            string sCardInfo = "";
            try
            {
                if (grdSearchList.CsmGridRowsCount == 0) return false;

                int nRow = grdSearchList.CsmGridSelectedRowIndex;
                if (nRow < 0) return false;

                int tpayRow = -1;
                int sktRow = -1;
                if (string.IsNullOrWhiteSpace(grdSearchList.CsmGridGetCell(nRow, 15)) == false)
                {
                    if (grdSearchList.CsmGridGetCell(nRow, 9) == ItemConst.TR_ITEM_ID.PAY.T_PAY)
                    {
                        #region  // T페이 통합결제인 경우

                        tpayRow = nRow;

                        // SKT 할인 찾기
                        for (var i = 0; i < grdSearchList.CsmGridRowsCount; i++)
                        {
                            if (grdSearchList.CsmGridGetCell(i, 8) != ItemConst.TR_ITEM_ID.MOBILE_COM_POINT) continue;
                            if (grdSearchList.CsmGridGetCell(i, 9) != ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_SKT) continue;
                            if (grdSearchList.CsmGridGetCell(i, 15) != grdSearchList.CsmGridGetCell(nRow, 15)) continue;

                            sktRow = i;
                            break;
                        }
                        #endregion
                    }
                    else if (grdSearchList.CsmGridGetCell(nRow, 9) == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_SKT)
                    {
                        #region // T페이 통합결제된 SKT할인인 경우

                        sktRow = nRow;

                        // T페이 통합결제 찾기 
                        for (var i = 0; i < grdSearchList.CsmGridRowsCount; i++)
                        {
                            if (grdSearchList.CsmGridGetCell(i, 8) != ItemConst.TR_ITEM_ID.PAY_ITEM) continue;
                            if (grdSearchList.CsmGridGetCell(i, 9) != ItemConst.TR_ITEM_ID.PAY.T_PAY) continue;
                            if (grdSearchList.CsmGridGetCell(i, 15) != grdSearchList.CsmGridGetCell(nRow, 15)) continue;

                            tpayRow = i;
                            nRow = tpayRow;
                            break;
                        }
                        #endregion
                    }
                }

                // NO, 결제내역, 승인금액, 원승인번호, 원승인시간, 카드번호, 승인구분, 완료여부, 결제코드, 상세코드, 행번호, 승인구분코드, 완료여부코드, 카드재입력구분, 입력구분, T폐이거래일련번호                string sPayName = grdSearchList.CsmGridGetCell(nRow, 1);
                string sPayName = grdSearchList.CsmGridGetCell(nRow, 1);
                string sPayAmt = grdSearchList.CsmGridGetCell(nRow, 2);
                string sCardNo = grdSearchList.CsmGridGetCell(nRow, 5);
                string sPayWayCD = grdSearchList.CsmGridGetCell(nRow, 8);
                string sPayDtlCD = grdSearchList.CsmGridGetCell(nRow, 9);
                string sSeqNo = grdSearchList.CsmGridGetCell(nRow, 10);
                string sAppDiv = grdSearchList.CsmGridGetCell(nRow, 11);            // 승인구분(0:정상 그외:수기)
                string sAppEnd = grdSearchList.CsmGridGetCell(nRow, 12);
                string sInCardYn = grdSearchList.CsmGridGetCell(nRow, 13);          // 카드재입력구분 => 0:안함, 1:재입력, 2:기존번호 암호화, 3:현금영수증자진발급
                string sInputType = grdSearchList.CsmGridGetCell(nRow, 14);         // 신용카드 관련 입력 구분
                string sTPayTradeSeq = grdSearchList.CsmGridGetCell(nRow, 15);      // T폐이거래일련번호
                string sPasswordYn = grdSearchList.CsmGridGetCell(nRow, 16);        // 비밀번호 입력 여부


                //#20171020 log 추가 
                UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                     "승인취소 할 건 선택 -> 결제이름 : " + sPayName + "," +
                                     "결제코드 : " + sPayWayCD + "," +
                                     "상세코드 : " + sPayDtlCD + "," +
                                     "승인구분 (0:정상 그외:수기) : " + sAppDiv + "," +
                                     "승인완료여부 : " + sAppEnd + "," +
                                     "카드재입력구분 : " + sInCardYn + "," +
                                     "신용카드 관련 입력 구분 : " + sInputType + "," +
                                     "거래구분 : " + m_cTrnStatus.Head.TradeDiv);

                if (sAppEnd == "0") return false;   // 이미 반품 승인됨

                ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
                ArrayList alEtcItem = (ArrayList)StateObject.GetItemObject(Column.TR_ETC.ITEM);

                string sPassWord = "";
                // 카드번호 입력 받기 
                if (sMenualKind == ItemConst.PAY_APP_DIV.NORMAL && sAppDiv == ItemConst.PAY_APP_DIV.NORMAL && sInCardYn == "1")
                {
                    // Rhee, 2017/10/12 중국 해피포인트 결제 반품시 카드 번호 없이 반품 승인 -- START
                    // 기존
                    //// 카드번호 입력 받기
                    //sCardInfo = m_cPayCancel.SetPayment(new string[] { sPayWayCD, sCardNo, sPayAmt, sPayName, sInputType, sPayDtlCD, sPasswordYn });
                    //if (sCardInfo == "") return false;

                    //grayber@20180208 코레일 마일리지 입력 start - 반품 분기 코드 추가
                    // 기존
                    //if ((sPayWayCD == ItemConst.TR_ITEM_ID.POINT_ITEM && sPayDtlCD == ItemConst.TR_ITEM_ID.POINT_USE.HAPPY_POINT_USE_CHINA) && (sCardNo != ""))

                    // 변경
                    if (sPayWayCD == ItemConst.TR_ITEM_ID.POINT_ITEM &&
                            (
                                (sPayDtlCD == ItemConst.TR_ITEM_ID.POINT_USE.HAPPY_POINT_USE_CHINA) && (sCardNo != "")
                                || (sPayDtlCD == ItemConst.TR_ITEM_ID.POINT_USE.KORAIL_MILEAGE)   // 코레일
                            )
                        )
                    //grayber@20180208 코레일 마일리지 입력 end
                    {
                        // 카드 번호 입력 없이 반품 승인    
                        sCardInfo = "                    ";
                        sCardInfo += "K" + sCardNo;
                    }
                    else
                    {
                        // 카드번호 입력 받기
                        sCardInfo = m_cPayCancel.SetPayment(new string[] { sPayWayCD, sCardNo, sPayAmt, sPayName, sInputType, sPayDtlCD, sPasswordYn });
                        if (sCardInfo == "") return false;
                    }
                    // Rhee, 2017/10/12 중국 해피포인트 결제 반품시 카드 번호 없이 반품 승인 -- END

                    sPassWord = sCardInfo.Substring(0, 20).Trim();
                    sCardInfo = sCardInfo.Substring(20);
                }

                // 카드번호(암호화된 카드 데이터) 설정
                if (sPayWayCD == ItemConst.TR_ITEM_ID.ETC_INFO_ITEM)
                {
                    #region
                    //ArrayList alEtcItem = (ArrayList)StateObject.GetItemObject(Column.TR_ETC.ITEM);
                    Column.TR_ETC.DATA cEtcItem = (Column.TR_ETC.DATA)alEtcItem[CmUtil.IntParse(sSeqNo)];

                    if (sPayDtlCD == ItemConst.TR_ITEM_ID.ETC_INFO.ONLINE_CPN)
                    {
                        // 온라인쿠폰 발행
                    }
                    // 승인요청구분
                    else if ((sAppDiv != ItemConst.PAY_APP_DIV.NORMAL && sAppDiv != ItemConst.PAY_APP_DIV.CAT_TERMINAL) || sMenualKind == ItemConst.PAY_APP_DIV.COMPULSION || sMenualKind == ItemConst.PAY_APP_DIV.PHON_CANCEL)
                    {
                        // 전화취소 => 전화취소승인은 카드번호 입력 없이 반품
                        if (sMenualKind == ItemConst.PAY_APP_DIV.PHON_CANCEL)
                        {
                            if (WinManager.QuestionMessage(POS_MESSAGE.ERROR.MSG_0247) == false) return false;
                            cEtcItem.OCCUR_ENTRY_08 = sMenualKind;
                        }
                        else
                        {
                            WinManager.ConfirmMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0240));
                        }
                    }
                    else if (sInCardYn == "2")
                    {
                        if (sAppDiv != ItemConst.PAY_APP_DIV.CAT_TERMINAL)
                        {
                            // 카드 입력 없이 암호화 후 반품 승인
                            if (sPayDtlCD == ItemConst.TR_ITEM_ID.ETC_INFO.SAVEPOINT)       // 해피 적립
                            {
                                cEtcItem.CanFiller1 = EncryptedCardNo(cEtcItem.OCCUR_ENTRY_14);
                            }
                            else
                            {
                                cEtcItem.CanFiller1 = EncryptedCardNo(cEtcItem.OCCUR_ENTRY_01);
                            }
                        }
                    }
                    else if (sInCardYn == "3")
                    {
                        if (sAppDiv != ItemConst.PAY_APP_DIV.CAT_TERMINAL)
                        {
                            // 현금영수증 자진발급 암호화 후 반품 승인
                            cEtcItem.CanFiller1 = EncryptedCardNo("0100001234");
                        }
                    }
                    else
                    {
                        // 카드 번호 입력 후 반품 승인
                        cEtcItem.OCCUR_ENTRY_05 = sCardInfo.Substring(0, 1);
                        cEtcItem.CanFiller1 = sCardInfo.Substring(1);
                    }
                    #endregion
                }
                else
                {
                    #region
                    //ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
                    Column.TR_PAYMENT.DATA cPayItem = (Column.TR_PAYMENT.DATA)alPayItem[CmUtil.IntParse(sSeqNo)];

                    // 승인요청구분
                    if ((sAppDiv != ItemConst.PAY_APP_DIV.NORMAL && 
                        sAppDiv != ItemConst.PAY_APP_DIV.CAT_TERMINAL && 
                        sAppDiv != ItemConst.PAY_APP_DIV.X_CHARGE) || 
                       sMenualKind == ItemConst.PAY_APP_DIV.COMPULSION || 
                       sMenualKind == ItemConst.PAY_APP_DIV.PHON_CANCEL)
                    {
                        // 전화취소 => 전화취소승인은 카드번호 입력 없이 반품
                        if (sMenualKind == ItemConst.PAY_APP_DIV.PHON_CANCEL)
                        {
                            if (WinManager.QuestionMessage(POS_MESSAGE.ERROR.MSG_0247) == false) return false;
                            cPayItem.OCCUR_ENTRY_08 = sMenualKind;
                        }
                        else
                        {
                            WinManager.ConfirmMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0240));
                        }
                    }
                    else if (sInCardYn == "2")
                    {
                        if (sAppDiv != ItemConst.PAY_APP_DIV.CAT_TERMINAL && sAppDiv != ItemConst.PAY_APP_DIV.X_CHARGE)
                        {
                            // 카드 입력 없이 암호화 후 반품 승인
                            if (sPayWayCD == ItemConst.TR_ITEM_ID.POINT_ITEM && sPayDtlCD == ItemConst.TR_ITEM_ID.POINT_USE.HAPPY_POINT)    // 해피포인트 사용
                            {
                                cPayItem.CanFiller1 = EncryptedCardNo(cPayItem.OCCUR_ENTRY_14);
                            }
                            else
                            {
                                cPayItem.CanFiller1 = EncryptedCardNo(cPayItem.OCCUR_ENTRY_01);
                            }
                        }
                    }
                    else if (sPayWayCD == ItemConst.TR_ITEM_ID.CREDITCARD_ITEM)     // 신용카드
                    {
                        //if (m_cDevStatus.ICReader.UseYn == true)             // 여전법 인증여부(0:MSR, 1:IC)
                        //{
                        cPayItem.CanFiller1 = sCardInfo;
                        //}
                        //else
                        //{


                        //if (sInputType == PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_RF)
                        //{
                        //    cPayItem.CanFiller1 = sCardInfo;
                        //}
                        //else
                        //{
                        //    //MSR
                        //    cPayItem.OCCUR_ENTRY_05 = CmUtil.MidH(sCardInfo, 2, 1);
                        //    //cPayItem.CanFiller1 = CmUtil.MidH(sCardInfo, 1, CmUtil.LenH(sCardInfo));
                        //    cPayItem.CanFiller1 = sCardInfo;
                        //}
                        //}
                    }
                    else if (sPayWayCD == ItemConst.TR_ITEM_ID.MOBILECON_ITEM)
                    {
                        // 모바일콘
                    }
                    else if (sPayWayCD == ItemConst.TR_ITEM_ID.PAY_ITEM && sPayDtlCD == ItemConst.TR_ITEM_ID.PAY.T_PAY)
                    {
                        // T페이 
                        cPayItem.CanFiller2 = sPassWord;                            // 비밀번호 
                        cPayItem.OCCUR_ENTRY_05 = sCardInfo.Substring(0, 1);        // 입력구분 
                        cPayItem.CanFiller1 = sCardInfo.Substring(1);               // 카드번호 
                    }
                    else if (sPayWayCD == ItemConst.TR_ITEM_ID.POINT_ITEM && sPayDtlCD == ItemConst.TR_ITEM_ID.POINT_USE.HAPPY_POINT)
                    {
                        cPayItem.CanFiller2 = sPassWord;                            // 비밀번호 
                        cPayItem.OCCUR_ENTRY_05 = sCardInfo.Substring(0, 1);        // 입력구분 
                        cPayItem.CanFiller1 = sCardInfo.Substring(1);               // 카드번호 
                    }
                    else if (sPayWayCD == ItemConst.TR_ITEM_ID.COUPON_ITEM && sPayDtlCD == ItemConst.TR_ITEM_ID.COUPON.ONLINE)
                    {
                        // 온라인 쿠폰
                    }
                    //#20180413 웰컴카드 신규기능 추가 start,phj
                    else if (sPayWayCD == ItemConst.TR_ITEM_ID.MOBILE_COM_POINT && sPayWayCD == ItemConst.TR_ITEM_ID.MOBILE_COM.WELCOMECARD)
                    {
                        // 웰컴카드
                        //cPayItem.CanFiller1 = OCCUR_ENTRY_19;
                    }
                    //#20180413 웰컴카드 신규기능 추가 end,phj

                    //#20171018, 해피기프트(코나머니) 결제코드(신용->선불) 변경 Start, srlee
                    else if (sPayWayCD == ItemConst.TR_ITEM_ID.PPCARD_ITEM && sPayDtlCD == ItemConst.TR_ITEM_ID.PPCARD.HPGIFT_CARD)
                    {
                        cPayItem.CanFiller1 = sCardInfo;
                    }
                    //#20171018, 해피기프트(코나머니) 결제코드(신용->선불) 변경 End, srlee
                    else
                    {
                        // 카드 번호 입력 후 반품 승인
                        cPayItem.OCCUR_ENTRY_05 = CmUtil.MidH(sCardInfo, 0, 1);
                        cPayItem.CanFiller1 = CmUtil.MidH(sCardInfo, 1, CmUtil.LenH(sCardInfo));
                    }
                    #endregion
                }


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

                // 반품 승인 요청
                sRet = m_cPayCancel.RefundPayment(new string[] { sPayWayCD, sPayDtlCD, sSeqNo });
                if (sRet != UserCom.RST_OK)
                {
                    btnMenual.Visible = true;
                    return false;
                }


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

                DataRow dr = m_dtSearchList.Rows[nRow];
                dr["APP_END_NM"] = sMenualKind == "0" ? MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0394)
                                                      : MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0395);
                dr["APP_END"] = sMenualKind;

                // T페이 통합결제 완료처리 
                if (tpayRow >= 0 && sktRow >= 0)
                {
                    int chkRow = -1;
                    if (nRow == tpayRow) chkRow = sktRow;
                    if (nRow == sktRow) chkRow = tpayRow;
                    if (chkRow >= 0)
                    {
                        DataRow drTmp = m_dtSearchList.Rows[chkRow];
                        drTmp["APP_END_NM"] = dr["APP_END_NM"].ToString();
                        drTmp["APP_END"] = dr["APP_END"].ToString();
                    }
                }

                // 해피콘 취소시 연결된 쿠폰 전체 취소
                if (sPayWayCD == ItemConst.TR_ITEM_ID.MOBILECON_ITEM && sPayDtlCD == ItemConst.TR_ITEM_ID.MOBILECON.HPCON)
                {
                    #region
                    for (int iLoop = 0; iLoop < alPayItem.Count; iLoop++)
                    {
                        Column.TR_PAYMENT.DATA cPayItem = (Column.TR_PAYMENT.DATA)alPayItem[iLoop];
                        if (cPayItem.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL) continue;

                        if (cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.MOBILECON_ITEM && cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.MOBILECON.HPCON)
                        {
                            if (cPayItem.OCCUR_ENTRY_06.Trim() != "")
                            {
                                foreach (DataRow dr2 in m_dtSearchList.Rows)
                                {
                                    if (CmUtil.GetDataRowStr(dr2, "PAY_CARD").Trim() == cPayItem.OCCUR_ENTRY_01 && CmUtil.GetDataRowStr(dr2, "ORG_APP_NO").Trim() == cPayItem.OCCUR_ENTRY_06)
                                    {
                                        dr2["APP_END_NM"] = sMenualKind == "0" ? MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0394)
                                                                               : MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0395);
                                        dr2["APP_END"] = sMenualKind;
                                    }

                                }
                            }
                        }
                    }
                    #endregion
                }

                btnMenual.Visible = false;
                btnEnter.Visible = false;

                // 그리드 적용
                grdSearchList.CsmGridDataSource = m_dtSearchList;

                if (RefundComplete() == false)
                {
                    //nRow++;
                    //if (nRow < grdSearchList.CsmGridRowsCount) grdSearchList.CsmGridSelectRow(nRow);


                    //#20171020 log 추가 
                    UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                         System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                         "반품완료 False! (" + m_cTrnStatus.Head.TradeDiv + ")");
                }

                //#20171020 log 추가 
                UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                                     "반품완료 true! (" + m_cTrnStatus.Head.TradeDiv + ")");


                return 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 false;
            }
            finally
            {
                //여전법 대응!
                //////////////////////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref sCardInfo);
                //////////////////////////////////////////////////////////////////////////////////
            }
        }

        /// <summary>
        /// 반품 완료 처리
        /// </summary>
        private bool RefundComplete()
        {
            string sRet = "";

            try
            {
                foreach (DataRow dr in m_dtSearchList.Rows)
                {
                    // 반품 승인 안된 결제수단이 있느지 체크
                    if (dr["APP_END"].ToString() == "") return false;
                }

                lblComplete.Visible = true;
                this.Update();

                #region 결제수단 중 승인 비대상 반품 처리

                //#20171020 log 추가 
                UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
                    "반품 완료 처리");

                // 결제수단 중 승인 비대상 반품 처리

                ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
                for (int nRow = 0; nRow < alPayItem.Count; nRow++)
                {
                    Column.TR_PAYMENT.DATA cPayItem = (Column.TR_PAYMENT.DATA)alPayItem[nRow];

                    if (cPayItem.CANCEL_DIV == ItemConst.PAY_CANCEL_DIV.CANCEL) continue;

                    bool bExist = false;
                    foreach (DataRow dr in m_dtSearchList.Rows)
                    {
                        if (dr["PAY_WAY_CD"].ToString() == cPayItem.PAY_WAY_CD && dr["PAY_DTL_CD"].ToString() == cPayItem.PAY_DTL_CD_01)
                        {
                            bExist = true;
                            break;
                        }
                    }

                    if (bExist == false)
                    {
                        //#20180410 인천공항 반품 시 원승인번호,원거래일자 저장 start,phj
                        //기존
                        sRet = m_cPayCancel.RefundPayment(new string[] { cPayItem.PAY_WAY_CD, cPayItem.PAY_DTL_CD_01, nRow.ToString() });
                        //sRet = ExecRefundPayment(cPayItem.PAY_WAY_CD, cPayItem.PAY_DTL_CD_01, nRow.ToString());
                      

                        //변경
                        //if (PosMstManager.GetPosOption(POS_OPTION.OPT512) == "1" &&
                        //    cPayItem.PAY_WAY_CD == ItemConst.TR_ITEM_ID.CREDITCARD_ITEM && cPayItem.PAY_DTL_CD_01 == ItemConst.TR_ITEM_ID.CREDITCARD.CREDIT_CARD)
                        //{
                        //    cPayItem.OCCUR_ENTRY_06 = cPayItem.OCCUR_ENTRY_02;
                        //    cPayItem.OCCUR_ENTRY_07 = cPayItem.OCCUR_ENTRY_03;
                        //
                        //    sRet = UserCom.RST_OK;
                        //}
                        //else
                        //{
                        //    sRet = m_cPayCancel.RefundPayment(new string[] { cPayItem.PAY_WAY_CD, cPayItem.PAY_DTL_CD_01, nRow.ToString() });
                        //}
                        //#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 + "()",
                            "1 결제수단 중 반품완료처리(Trade_div) : " + "(" + m_cTrnStatus.Head.TradeDiv + ")");
                    }
                }

                #endregion



                #region 기타수단 중 승인 비대상 반품 처리
                ArrayList alEtcItem = (ArrayList)StateObject.GetItemObject(Column.TR_ETC.ITEM);
                for (int nRow = 0; nRow < alEtcItem.Count; nRow++)
                {
                    Column.TR_ETC.DATA cEtcItem = (Column.TR_ETC.DATA)alEtcItem[nRow];

                    if (cEtcItem.CANCEL_DIV == ItemConst.PAY_CANCEL_DIV.CANCEL) continue;

                    bool bExist = false;
                    foreach (DataRow dr in m_dtSearchList.Rows)
                    {
                        if (dr["PAY_WAY_CD"].ToString() == cEtcItem.ETC_WAY_CD && dr["PAY_DTL_CD"].ToString() == cEtcItem.ETC_DTL_CD_01)
                        {
                            bExist = true;
                            break;
                        }
                    }

                    if (bExist == false)
                    {

                        //#20180410 인천공항 반품 시 원승인번호,원거래일자 저장 start,phj
                        //기존
                        
                        sRet = m_cPayCancel.RefundPayment(new string[] { cEtcItem.ETC_WAY_CD, cEtcItem.ETC_DTL_CD_01, nRow.ToString() });
                        //sRet = ExecRefundPayment(cEtcItem.ETC_WAY_CD, cEtcItem.ETC_DTL_CD_01, nRow.ToString());
                       
                        
                        //변경
                        //if (PosMstManager.GetPosOption(POS_OPTION.OPT512) == "1" &&
                        //    cEtcItem.ETC_WAY_CD == ItemConst.TR_ITEM_ID.ETC_INFO_ITEM && cEtcItem.ETC_DTL_CD_01 == ItemConst.TR_ITEM_ID.ETC_INFO.CASHBILL)
                        //{
                        //    cEtcItem.OCCUR_ENTRY_06 = cEtcItem.OCCUR_ENTRY_02;
                        //    cEtcItem.OCCUR_ENTRY_07 = cEtcItem.OCCUR_ENTRY_03;
                        //
                        //    sRet = UserCom.RST_OK;
                        //}
                        //else
                        //{
                        //    sRet = m_cPayCancel.RefundPayment(new string[] { cEtcItem.ETC_WAY_CD, cEtcItem.ETC_DTL_CD_01, nRow.ToString() });
                        //}
                        //#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 + "()",
                            "2 기타수단 중 반품완료처리(Trade_div) : " + "(" + m_cTrnStatus.Head.TradeDiv + ")");
                    }
                }
                #endregion

                //// 선불카드 판매 - 중국 
                //// 반품시 선불카드 취소 요청
                //if (m_cTrnStatus.Head.TradeKind == ItemConst.TRAN_KIND.CHARGESALE.PREPAID && PosMstManager.GetPosOption(POS_OPTION.OPT046) == "1")
                //{
                //    IPaymentUs m_cSalePreCard = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_SALE.DLL, ServiceLists.BSV_SALE.SALEPRECARD);
                //    ArrayList alTrPluItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);                   // 상품 아이템
                //    foreach (Column.TR_PLU.DATA cPluItem in alTrPluItem)
                //    {
                //        if (cPluItem.BILLSPR_NO != m_cTrnStatus.Sale.BillSplitNo) continue;

                //        if (cPluItem.CANCEL_DIV == "1" || cPluItem.CANCEL_DIV_MAIN == "1") continue;

                //        if (cPluItem.ITEM_DIV == ItemConst.PLU_ITEM_DIV.PREPAID)
                //        {
                //            // 취소 요청
                //            sRet = m_cSalePreCard.CancelPayment(new string[] { "1", cPluItem.SALE_GIFT_NO, "0" });

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


                this.DialogResult = DialogResult.OK;
                this.Close();

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

        ///// <summary>
        ///// 결제 수단별 반품 처리
        ///// </summary>
        ///// <param name="sWayCd"></param>
        ///// <param name="sDtlCd"></param>
        ///// <param name="sSeqNo"></param>
        //private string ExecRefundPayment(string sWayCd, string sDtlCd, string sSeqNo)
        //{
        //    string sRet = UserCom.RST_ERR;

        //    try
        //    {
        //        // 결제 수단 코드
        //        switch (sWayCd)
        //        {
        //            case ItemConst.TR_ITEM_ID.CREDITCARD_ITEM:      // 신용카드
        //                {
        //                    IPaymentUs m_cPayCard = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.CREDITCARD);
        //                    sRet = m_cPayCard.RefundPayment(new string[] { sSeqNo});
        //                    break;
        //                }
        //            case ItemConst.TR_ITEM_ID.MOBILE_COM_POINT:     // 제휴 통신사 할인
        //                {
        //                    if (sDtlCd == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_SKT || sDtlCd == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_KTF || sDtlCd == ItemConst.TR_ITEM_ID.MOBILE_COM.MOBILE_LGT)
        //                    {
        //                        IPaymentUs cMobileComPoint = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.POINTMOBILECOM);
        //                        sRet = cMobileComPoint.RefundPayment(new string[] { sSeqNo });
        //                    }
        //                    else
        //                    {
        //                        IPaymentUs cMemberPointUse = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.POINTMEMBERUSE);
        //                        sRet = cMemberPointUse.RefundPayment(new string[] { sSeqNo });
        //                    }

        //                    break;
        //                }
        //            case ItemConst.TR_ITEM_ID.CASH_ITEM:            // 현금
        //                {
        //                    IPaymentUs m_cPayCash = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.CASH);
        //                    sRet = m_cPayCash.RefundPayment(new string[] { sSeqNo });
        //                    break;
        //                }
        //            case ItemConst.TR_ITEM_ID.COUPON_ITEM:
        //                {
        //                    if (sDtlCd == ItemConst.TR_ITEM_ID.COUPON.INCARD)
        //                    {
        //                        IPaymentUs cMobileComPoint = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.POINTHAPPYCOUPON);
        //                        sRet = cMobileComPoint.RefundPayment(new string[] { sSeqNo });
        //                    }
        //                    else
        //                    {
        //                        IPaymentUs m_cCouponDC = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.COUPONDC);
        //                        sRet = m_cCouponDC.RefundPayment(new string[] { sSeqNo });
        //                    }
        //                    break;
        //                }
        //            case ItemConst.TR_ITEM_ID.MOBILECON_ITEM:
        //                {
        //                    IPaymentUs m_cMobileCoupon = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.MOBILECOUPON);
        //                    sRet = m_cMobileCoupon.RefundPayment(new string[] { sSeqNo });
        //                    break;
        //                }
        //            case ItemConst.TR_ITEM_ID.EMP_DC_ITEM:
        //                {
        //                    if (sDtlCd == ItemConst.TR_ITEM_ID.EMP_DC.SEVERANCE)
        //                    {
        //                        IPaymentUs m_cSeveranceDC = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.SEVERANCEDC);
        //                        sRet = m_cSeveranceDC.RefundPayment(new string[] { sSeqNo });
        //                    }
        //                    else if (sDtlCd == ItemConst.TR_ITEM_ID.EMP_DC.SPC)
        //                    {
        //                        IPaymentUs m_cSPCEmployeeDC = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.SPCEMPLOYEEDC);
        //                        sRet = m_cSPCEmployeeDC.RefundPayment(new string[] { sSeqNo });
        //                    }
        //                    else if (sDtlCd == ItemConst.TR_ITEM_ID.EMP_DC.SAMSUNGCARD)
        //                    {
        //                        sRet = UserCom.RST_OK;
        //                    }
        //                    break;
        //                }
        //            case ItemConst.TR_ITEM_ID.POINT_ITEM:
        //                {
        //                    if (sDtlCd == ItemConst.TR_ITEM_ID.POINT_USE.HAPPY_POINT)
        //                    {
        //                        IPaymentUs cHappyPointUse = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.POINTHAPPYPOINTUSE);
        //                        sRet = cHappyPointUse.RefundPayment(new string[] { sSeqNo });
        //                    }
        //                    break;
        //                }
        //            case ItemConst.TR_ITEM_ID.USER_DC_ITEM:
        //                {
        //                    if (sDtlCd == ItemConst.TR_ITEM_ID.USER_DC.IN_EMP_DC)
        //                    {
        //                        // 입점건물직원할인 취소
        //                        IPaymentUs ciNStorDC = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.iNStorDC);
        //                        sRet = ciNStorDC.RefundPayment(new string[] { sSeqNo });
        //                    }
        //                    break;
        //                }
        //            case ItemConst.TR_ITEM_ID.PAYETC_ITEM:
        //                {
        //                    if (sDtlCd == ItemConst.TR_ITEM_ID.PAYETC.MEAL_TIKET)
        //                    {
        //                        // 식권취소
        //                        IPaymentUs cMealTicket = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.MEALTICKET);
        //                        sRet = cMealTicket.RefundPayment(new string[] { sSeqNo });
        //                    }
        //                    else if (sDtlCd == ItemConst.TR_ITEM_ID.PAYETC.BALANCE_VOUCHER)
        //                    {
        //                        // 잔액교환권 취소
        //                        IPaymentUs cExchangeTicket = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.EXCHANGETICKET);
        //                        sRet = cExchangeTicket.RefundPayment(new string[] { sSeqNo });
        //                    }
        //                    break;
        //                }
        //            case ItemConst.TR_ITEM_ID.GIFT_ITEM:
        //                {
        //                    // 상품권 취소
        //                    IPaymentUs cGift = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.GIFT);
        //                    sRet = cGift.RefundPayment(new string[] { sSeqNo });
        //                    break;
        //                }
        //            case ItemConst.TR_ITEM_ID.CREDIT_ITEM:
        //                {
        //                    // 외상 취소
        //                    IPaymentUs cSaleOnCustomer = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.SALEONCUSTOMER);
        //                    sRet = cSaleOnCustomer.RefundPayment(new string[] { sSeqNo });
        //                    break;
        //                }
        //            case ItemConst.TR_ITEM_ID.FOREIGNEX_ITEM:
        //                {
        //                    // 외화 취소
        //                    IPaymentUs cForeign = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.FOREIGN);
        //                    sRet = cForeign.RefundPayment(new string[] { sSeqNo });
        //                    break;
        //                }
        //            case ItemConst.TR_ITEM_ID.PPCARD_ITEM:
        //                {
        //                    if (sDtlCd == ItemConst.TR_ITEM_ID.PPCARD.PP_CARD)
        //                    {
        //                        // 선불카드 취소
        //                        IPaymentUs cPrepaidCard = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.PREPAIDCARD);
        //                        sRet = cPrepaidCard.RefundPayment(new string[] { sSeqNo });
        //                    }
        //                    else if (sDtlCd == ItemConst.TR_ITEM_ID.PPCARD.HP_GIFT)
        //                    {
        //                        // 해피 기프트 사용 취소
        //                        IPaymentUs cHappyGiftUse = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.HAPPYGIFTUSE);
        //                        sRet = cHappyGiftUse.RefundPayment(new string[] { sSeqNo });
        //                    }
        //                    break;
        //                }
        //            case ItemConst.TR_ITEM_ID.ETC_INFO_ITEM:
        //                {
        //                    if (sDtlCd == ItemConst.TR_ITEM_ID.ETC_INFO.SAVEPOINT)
        //                    {
        //                        // 해피포인트 적립 취소
        //                        IPaymentUs cHappyPoint = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.POINTHAPPYPOINT);
        //                        sRet = cHappyPoint.RefundPayment(new string[] { sSeqNo });
        //                    }
        //                    else if (sDtlCd == ItemConst.TR_ITEM_ID.ETC_INFO.CASHBILL )
        //                    {
        //                        // 현금영수증 취소
        //                        IPaymentUs cCashBill = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.CASHBILL);
        //                        sRet = cCashBill.RefundPayment(new string[] { sSeqNo });
        //                    }
        //                    break;
        //                }
        //            default:
        //                sRet = UserCom.RST_OK;
        //                break;
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
        //            System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
        //    }
        //    return sRet;
        //}


        #endregion

        #region DeviceEvent 관련
        /// <summary>
        /// DeviceEvent 관련
        /// </summary>
        /// <param name="sDevice"></param>
        /// <param name="sData1"></param>
        /// <param name="sData2"></param>
        /// <param name="sData3"></param>
        public void OnDeviceEvent(string sDevice, string sData1, string sData2, string sData3)
        {
            try
            {
                switch (sDevice)
                {
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        /// <summary>
        /// 카드 번호 암호화
        /// </summary>
        /// <param name="sInData"></param>
        /// <returns></returns>
        private string EncryptedCardNo(string sInData)
        {
            string tmpEnc = "";

            try
            {
                tmpEnc = m_cICReader.GetEncryptedCardNo(sInData).Trim();
                if (CmUtil.MidH(tmpEnc, 0, 2) == "00")
                {
                    tmpEnc = CmUtil.MidH(tmpEnc, 2, 512).Trim();
                }
                else
                {
                    // 암호화 처리 실패!
                    UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", "Fail =>" + sInData);
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0280);
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return tmpEnc;
        }
        #endregion DeviceEvent 관련

    }
}
