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

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

/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 해피포인트 거래후 적립
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Win
{
    public partial class frmPointHappyPointAfter : Form
    {

        #region 변수 선언

        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 PosOLEDevice.DelegateIcReader delegateReader;                       // IC리더 콜백
        //#20170918 IC 콜백 함수 변경 start
        //포인트창에서 해피제휴 신용카드 리딩시 IC 우선 거래로 인해 '카드를 읽혀 주세요' 팝업 나오는 현상 수정.
        /*
        private PosOLEDevice.CallbackIc delegateReaderCardInfo;                     // IC리더 콜백(CardInfo)
        private bool m_bCardInPut;                                                  //카드 입력 중복 방지
        private string m_sIcChip;                                                   //IC CHIP DATA(EMV)
        private string m_InputType = ""; //PosConst.POS_VAN_MASTER.VAN_KEYIN;       //입력구분
        private string m_sCardNo;                                                   //입력 카드 번호
        private string m_sFallDiv;                                                  //FallBack구분
        private string m_sServiceCode;                                              //서비스코드
        */
        //#20170918 IC 콜백 함수 변경 end

        private IICReaderUs m_cDeviceICReader = null;
        private ISignPadUs m_cDeviceSignPad = null;
        private IDataProcessUs m_cDataService = null;                               // 거래데이터 합계금액 계산 및 관리
        private IPaymentUs m_cHappyPointAfter = null;

        private bool bNotDoubleClik = false;                                        // 더블 클릭 방지용

        /// <summary>
        /// 입력구분
        /// </summary>
        private string m_sInPutType = "";
        /// <summary>
        /// 입력데이터
        /// </summary>
        private string m_sInPutData = "";
        /// <summary>
        /// 마스킹데이터
        /// </summary>
        private string m_sInMaskData = "";
        /// <summary>
        /// 카드데이터(암호화)
        /// </summary>
        private string m_sInEncData = "";
        /// <summary>
        /// 승인카드번호
        /// </summary>
        private string m_sAppCardNo = "";
        /// <summary>
        /// 조회 성공 여부
        /// </summary>
        private bool m_bSearchSuccess = false;

        /// <summary>
        /// 판매시간
        /// </summary>
        private string m_sSaleDateTime = "";
        public string SaleDateTime { set { this.m_sSaleDateTime = value; } }
        /// <summary>
        /// 영수금액
        /// </summary>
        private double m_nNetSaleAmt = 0;
        public double NetSaleAmt { set { this.m_nNetSaleAmt = value; } }
        /// <summary>
        /// 추후적립 대상금액
        /// </summary>
        private double m_nAfterSaveAmt = 0;
        public double AfterSaveAmt { set { this.m_nAfterSaveAmt = value; } }
        /// <summary>
        /// 추후적립 대상정보
        /// </summary>
        private string m_sAfterSaveInfo = "";
        public string AfterSaveInfo { set { this.m_sAfterSaveInfo = value; } }

        #endregion 변수 선언

        #region 생성자 & 소멸자 & 폼초기화
        public frmPointHappyPointAfter()
        {
            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;

            m_cDeviceICReader = (IICReaderUs)sManager.InitServiceInstance(ServiceLists.AGENT_OLEDEVICE.DLL, ServiceLists.AGENT_OLEDEVICE.DEVICE_ICREADER);
            m_cDeviceSignPad = (ISignPadUs)sManager.InitServiceInstance(ServiceLists.AGENT_OLEDEVICE.DLL, ServiceLists.AGENT_OLEDEVICE.DEVICE_SIGNPAD);
            m_cDataService = (IDataProcessUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_SERVICE);
            m_cHappyPointAfter = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.POINTHAPPYPOINTAFTER);

            delegatePos = new PosOLEDevice.DelegateOlePos(OnDeviceEvent);
            delegateReader = new PosOLEDevice.DelegateIcReader(OnIcReaderCallBack);     // IC리더 콜백
            //#20170918 IC 콜백 함수 변경 start
            //포인트창에서 해피제휴 신용카드 리딩시 IC 우선 거래로 인해 '카드를 읽혀 주세요' 팝업 나오는 현상 수정.
            //delegateReaderCardInfo = new PosOLEDevice.CallbackIc(OnIcReaderCallBackCardInfo);     // IC리더 콜백(CardInfo)
            //#20170918 IC 콜백 함수 변경 end
        }

        private void frmPointHappyPointAfter_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();

            tmrIcCard.Tag = "";
            tmrIcCard.Enabled = true;   // IC리더 콜백 설정
        }

        private void frmPointHappyPointAfter_Activated(object sender, EventArgs e)
        {
            PosOLEDevice.SetEventHandle(delegatePos);
        }

        private void frmPointHappyPointAfter_Deactivate(object sender, EventArgs e)
        {
            PosOLEDevice.SetEventHandle(null);
        }

        private void frmPointHappyPointAfter_FormClosing(object sender, FormClosingEventArgs e)
        {
            tmrIcCard.Tag = "CLOSE";

            // 마우스(이중클릭방지)
            Point nPoint = System.Windows.Forms.Cursor.Position;
            Cursor.Clip = new System.Drawing.Rectangle(1024, 0, 1, 1);

            UnRegIcCallback();          // IC리더 콜백 해지
            InDataToZeroFill();
            UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", lblTitle.Text);

            // 마우스(이중클릭방지)
            Cursor.Clip = Screen.PrimaryScreen.Bounds;
            Cursor.Position = nPoint;
        }

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

                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 = "";

                //테마색상 적용!
                btnEnter.BackColor = CmUtil.GetColorToString(m_cPosStatus.ScnMst.ThemeColor);
                padInPut.ThemeColor = m_cPosStatus.ScnMst.ThemeColor;
                padInPut.ClearBtnText = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0817);
                padInPut.SearchBtnText = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1018);

                lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0327);

                lblSaleDateTime.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0414);
                lblCardNo.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0051);
                lblPayAmt.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0098);
                lblTotSavePoint.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0071);
                lblUsablePoint.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0070);
                lblBasicPoint.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0728);
                lblAddPoint.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0729);
                lblAddPointNm.Text = "";

                btnSearch.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0004);
                btnEnter.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0134);
                btnIcCard.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0132);
                btnRfCard.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0580);
                btnPopCard.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0878);
                btnPinPad.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0097);
                btnCatApp.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0854);

                //#12283 PB 천안신세계_해피포인트 부정적립 경구 문구 삽입요청 start, phj
                WarningMsg.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1079);
                WarningMsg.BringToFront();
                //#12283 PB 천안신세계_해피포인트 부정적립 경구 문구 삽입요청 end, phj

                txtSaleDateTime.Text = m_sSaleDateTime;

                txtPayAmt.Text = m_cPosStatus.Global.NumericTOCurrency(m_nAfterSaveAmt);

                // 기능 버튼 설정 체크
                FormManager.SetbtnMenu(txtCardNo, m_cDevStatus.ICReader.UseYn, btnIcCard, btnRfCard, btnPopCard, btnPinPad);

                ClearCardInfo();                // 카드 입력 정보 클리어
                bNotDoubleClik = false;

                if (m_cDevStatus.CatTerminal.UseYn == false)
                    btnCatApp.Visible = false;
                else
                    btnCatApp.Visible = true;

                txtCardNo.Text = "";
                txtCardNo.ReadOnly = false;
                txtCardNo.Select();

                txtPayAmt.ReadOnly = 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>
        private void ClearCardInfo()
        {
            try
            {
                m_sInPutType = "";      // 입력구분
                m_sInPutData = "";      // 입력데이터
                m_sInMaskData = "";     // 마스킹
                m_sInEncData = "";      // 카드데이터
                m_sAppCardNo = "";      // 승인카드번호

                txtUsablePoint.Text = "";
                txtTotSavePoint.Text = "";
                txtBasicPoint.Text = "";
                txtAddPoint.Text = "";
                m_bSearchSuccess = false;

                txtPayAmt.ReadOnly = 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);
            }
        }
        #endregion

        #region 버튼 입력 처리
        /// <summary>
        /// 버튼 입력 처리
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnProc_Click(object sender, EventArgs e)
        {
            try
            {
                if (bNotDoubleClik) return;
                bNotDoubleClik = true;

                if (((Cosmos.UI.CsmButton)sender) == btnIcCard)               // 카드입력
                {
                    if (GetIcCardData(e != null ? true : false) == true)
                    {
                        bNotDoubleClik = false;
                        txtEditBox_EditBoxKeyDownEvent(txtCardNo, PosKey.MENU_KEY.ENTER);
                    }
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnRfCard)        // RF카드
                {
                    UnRegIcCallback(); // IC리더 콜백 해지
                    if (GetRfCardData() == true)
                    {
                        bNotDoubleClik = false;
                        txtEditBox_EditBoxKeyDownEvent(txtCardNo, PosKey.MENU_KEY.ENTER);
                    }
                    if (txtCardNo.Value == "") tmrIcCard.Enabled = true;
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnPopCard)        // POP카드
                {
                    UnRegIcCallback(); // IC리더 콜백 해지
                    if (GetPopCardData() == true)
                    {
                        bNotDoubleClik = false;
                        txtEditBox_EditBoxKeyDownEvent(txtCardNo, PosKey.MENU_KEY.ENTER);
                    }
                    if (txtCardNo.Value == "") tmrIcCard.Enabled = true;
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnPinPad)        // 핀패드
                {
                    UnRegIcCallback(); // IC리더 콜백 해지
                    if (GetPinPadData() == true)
                        txtEditBox_EditBoxKeyDownEvent(txtCardNo, PosKey.MENU_KEY.ENTER);
                    if (txtCardNo.Value == "") tmrIcCard.Enabled = true;
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnSearch)        // 조회
                {
                    SearchTxtInPut();
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnEnter)         // 승인
                {
                    CompleteTxtInPut(0);
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnCatApp)        // Cat 단말기 승인
                {
                    CompleteTxtInPut(1);
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnExit)
                {
                    bNotDoubleClik = false;

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

        #region 텍스트박스 키 입력 이벤트 처리
        /// <summary>
        /// 텍스트박스 키 입력 이벤트 처리
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="sFuncValue"></param>
        private void txtEditBox_EditBoxKeyDownEvent(object sender, string sFuncValue)
        {
            try
            {
                if (bNotDoubleClik) return;
                bNotDoubleClik = true;

                if (sFuncValue == PosKey.MENU_KEY.ENTER)
                {
                    if (((Cosmos.UI.CsmPosEditBox)sender) == txtCardNo)
                    {
                        if (txtCardNo.Text == "")
                        {
                            if (GetIcCardData(true) == false)
                            {
                                bNotDoubleClik = false;
                                return;   // 카드정보 읽기
                            }
                        }

                        if (CheckTxtInPut(sender) == false)
                        {
                            bNotDoubleClik = false;
                            return;
                        }

                        if (txtTotSavePoint.Text == "")
                            SearchTxtInPut();       // 조회
                        else
                            txtPayAmt.Focus();
                    }
                    if (((Cosmos.UI.CsmPosEditBox)sender) == txtPayAmt)
                    {
                        if (txtCardNo.Text == "")
                        {
                            bNotDoubleClik = false;
                            return;     
                        }

                        if (CheckTxtInPut(sender) == false)
                        {
                            bNotDoubleClik = false;
                            return;
                        }
                        
                        CompleteTxtInPut(0);     // 적립
                    }

                }
                else if (sFuncValue == PosKey.MENU_KEY.CLEAR)
                {
                    if (((Cosmos.UI.CsmPosEditBox)sender) == txtCardNo)
                    {
                        ClearCardInfo();        // 카드 입력 정보 클리어
                        tmrIcCard.Enabled = true;
                    }

                    if (((Cosmos.UI.CsmPosEditBox)sender).ReadOnly == false) ((Cosmos.UI.CsmPosEditBox)sender).Text = "";
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            bNotDoubleClik = false;
        }

        /// <summary>
        /// 텍스트박스 활성화 처리
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtEditBox_EnterEvent(object sender, EventArgs e)
        {
            try
            {
                padInPut.SetActiveControl = (Control)sender;
            }
            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 텍스트박스 입력 유효성 체크
        /// <summary>
        /// 텍스트박스 입력 유효성 체크
        /// </summary>
        /// <param name="sender"></param>
        /// <returns></returns>
        private bool CheckTxtInPut(object sender)
        {
            try
            {
                // 특정 문자값 제거
                try
                {
                    if (m_cDevStatus.Msr.STX != "" && txtCardNo.Value.StartsWith(m_cDevStatus.Msr.STX)) txtCardNo.Value = txtCardNo.Value.Substring(1);

                    int iLastEtx = txtCardNo.Value.LastIndexOf(m_cDevStatus.Msr.ETX);
                    if (m_cDevStatus.Msr.ETX != "" && iLastEtx > 0) txtCardNo.Value = CmUtil.MidH(txtCardNo.Value, 0, iLastEtx);
                }
                catch { }

                // 카드번호 길이 체크
                if (sender == null || ((Cosmos.UI.CsmPosEditBox)sender) == txtCardNo)
                {
                    if (txtCardNo.Value.Length < 10)
                    {
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0037);
                        txtCardNo.Focus();
                        return false;
                    }

                    // 입력된 카드번호 변경 체크
                    //#20170913 현금영수증, 포인트카드 마스킹 미적용 start
                    //카드번호를 비교시 16자리까지만 비교 하도록 수정
                    //기존
                    /*
                    if (txtCardNo.Value != m_sInPutData)
                    {
                        ClearCardInfo();        // 카드 입력 정보 클리어
                    }
                    */
                    //변경
                    
                    string sCardTemp = "";
                    string sInputTemp = "";
                    if (txtCardNo.Value.Length > 16)
                    {
                        sCardTemp = txtCardNo.Value.Substring(0, 16);
                    }
                    else
                    {
                        sCardTemp = txtCardNo.Value.Substring(0, txtCardNo.Value.Length);
                    }

                    if (m_sInPutData.Length > 16)
                    {
                        sInputTemp = m_sInPutData.Substring(0, 16);
                    }
                    else
                    {
                        sInputTemp = m_sInPutData.Substring(0, m_sInPutData.Length);
                    }

                    if (sCardTemp != sInputTemp)
                    {
                        ClearCardInfo();        // 카드 입력 정보 클리어
                    }
                    
                    //#20170913 현금영수증, 포인트카드 마스킹 미적용 end

                    if (m_sInEncData == "")
                    {
                        if (m_sInPutData == "")
                        {
                            m_sInPutData = txtCardNo.Value;
                            if (m_sInPutData.Length > 16 && CmUtil.IsNumber(m_sInPutData.Substring(16, 1)) == false)
                            {
                                if (CmUtil.CheckHappyMobileCard(m_sInPutData) == false)
                                {
                                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0037);
                                    ClearCardInfo();        // 카드 입력 정보 클리어
                                    txtCardNo.Focus();
                                    txtCardNo.SelectText();
                                    return false;
                                }
                                m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_MOBILE_SWIP;
                                txtCardNo.Value = m_sInPutData; // .Substring(0, 16);
                            }
                            else
                            {
                                m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_KEYIN;
                            }
                            if (m_sInPutData.Contains("=") == true) m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_SWIP;
                        }
                        if (EncryptedCardNo(m_sInPutData, ref m_sInMaskData, ref m_sInEncData) == false) return false;

                        m_sAppCardNo = m_sInPutData;        // 승인카드번호
                    }
                }

                if (sender == null || ((Cosmos.UI.CsmPosEditBox)sender) == txtPayAmt)
                {
                    if (CmUtil.DoubleParse(txtPayAmt.Value) > m_nAfterSaveAmt)
                    {
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0597);
                        txtPayAmt.Focus();
                        return false;
                    }
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
                return false;
            }
            return true;
        }
        #endregion

        #region 텍스트박스 입력 완료 처리
        /// <summary>
        /// 해피포인트 카드 등록 처리
        /// </summary>
        /// <param name="nFlowMode"></param>
        /// <returns></returns>
        private bool CompleteTxtInPut(int nFlowMode)
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                if (nFlowMode == 1)
                {

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

                    string sAppType = PosConst.POS_CAT_MASTER.TRADE_ID.CAT_HAPPY_SAVE;
                    string sItemCode = "";  // 상품 코드 설정

                    //적립 포인트는 클래스에서 셋팅함!
                    //승인처리                                                   0,                          1,       2,   3,   4,   5,   6,  7,   8,     9,      10,  11, 12, 13, 14, 15 
                    sRet = m_cHappyPointAfter.SetPayment(new string[] { PosConst.POS_CAT_MASTER.TRAN_TYPE, sAppType, "00", txtPayAmt.Value, "0", "0", "", "", "04", sItemCode, "", "", "", "", "", "" , m_nAfterSaveAmt.ToString()});

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

                }
                else
                {
                    if (CheckTxtInPut(null) == false) return false;

                    if (m_bSearchSuccess == false)
                    {
                        // 조회
                        if (SearchTxtInPut() == false) return false;
                    }

                    // 해피포인트 추후적립 등록 처리
                    sRet = m_cHappyPointAfter.SetPayment(new string[] { m_sInPutType, m_sInMaskData, m_sInEncData, m_nNetSaleAmt.ToString(), txtPayAmt.Value, m_sAfterSaveInfo, m_sAppCardNo, m_nAfterSaveAmt.ToString() });
                    if (sRet != UserCom.RST_OK)
                    {
                        txtCardNo.SelectText();
                        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>
        /// <returns></returns>
        private bool SearchTxtInPut()
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                if (CheckTxtInPut(null) == false) return false;

                txtUsablePoint.Text = "";
                txtTotSavePoint.Text = "";
                lblAddPointNm.Text = "";

                m_bSearchSuccess = false;

                // 조회
                string[] saRecvdData = null;
                sRet = m_cHappyPointAfter.SearchPayment(new string[] { m_sInPutType, m_sInMaskData, m_sInEncData, "1", m_sAppCardNo }, ref saRecvdData);
                if (sRet != UserCom.RST_OK)
                {
                    txtCardNo.SelectText();
                    return false;
                }

                //#20170913 현금영수증, 포인트카드 마스킹 미적용 start
                //조회 성공시 카드번호 16자리까지만 표기
                
                if (txtCardNo.Value.Length > 16)
                {
                    txtCardNo.Value = txtCardNo.Value.Substring(0, 16);
                }
                else
                {
                    txtCardNo.Value = txtCardNo.Value.Substring(0, txtCardNo.Value.Length);
                }
                
                //#20170913 현금영수증, 포인트카드 마스킹 미적용 end
                
                // 조회 데이터 획득
                Column.TR_ETC.DATA cEtcItem = (Column.TR_ETC.DATA)m_cHappyPointAfter.GetPayment(new string[] { });
                if (m_sInPutData.StartsWith(PosConst.HP_CARD_PRIFIX) == false && cEtcItem.HP_ADD_INFO_SCH.Trim() != "")     // 제휴카드 조회
                {
                    int nNowPos = 0;
                    string[] aIrtRsp = new string[Column.POINT_ADD_INFO_SEARCH.LEN.Length];
                    ItemColumn.ParseMessage(Column.POINT_ADD_INFO_SEARCH.LEN, Column.POINT_ADD_INFO_SEARCH.TYPE, Encoding.Default.GetBytes(cEtcItem.HP_ADD_INFO_SCH), ref nNowPos, ref aIrtRsp);

                    // 고객정보 중에서 첫번째 카드 선택
                    string sMemInfo = aIrtRsp[Column.POINT_ADD_INFO_SEARCH.SEQ.pointMEMINFO].Trim();
                    if (sMemInfo.Length >= 17 && CmUtil.LongParse(sMemInfo.Substring(0, 1)) > 0)
                    {
                        string sInPutData = sMemInfo.Substring(1, 16).Trim();        // 카드번호
                        string sInMaskData = "";
                        if (EncryptedCardNo(sInPutData, ref sInMaskData, ref m_sInEncData) == false) return false;
                        cEtcItem.CanFiller1 = m_sInEncData;

                        cEtcItem.OCCUR_ENTRY_14 = m_sAppCardNo = sInPutData;        // 승인카드번호
                    }
                }

                txtUsablePoint.Text = m_cPosStatus.Global.NumericTOCurrency(cEtcItem.AMT_ENTRY_04);          // 가용포인트
                txtTotSavePoint.Text = m_cPosStatus.Global.NumericTOCurrency(cEtcItem.AMT_ENTRY_03);         // 누적포인트

                // 적립등록 중 적립예정 포인트 표시
                IDataCommonUs cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);

                // 적립예정포인트
                double nSavePoint = (long)CmUtil.MathRounds(CmUtil.MathAmtPercent(m_nAfterSaveAmt, m_cPosStatus.Mst.HpyPntAccumRate), PosConst.MATH_ROUND.CEILING, 0);
                //double nSavePoint = cDataCommon.ExecTermCoopCmpPayDc(cEtcItem.ETC_WAY_CD, cEtcItem.ETC_DTL_CD_01, "", m_nAfterSaveAmt);  // 적립예정 포인트
                txtBasicPoint.Text = m_cPosStatus.Global.NumericTOCurrency(nSavePoint);

                // 추가적립 정보[캠페인코드(10)+대상상품금액(15)+추가적립여부(1)+추가적립상세코드(2)+본사부담금(7)+매장부담금(7)]
                double nAddSavePnt = 0;
                if (m_sAfterSaveInfo != "")
                {
                    if (m_sAfterSaveInfo.Substring(25).StartsWith("N") == true) txtBasicPoint.Text = "0";
                    nAddSavePnt = m_cDataService.DoubleParse(m_sAfterSaveInfo.Substring(28, 7));

                    ICampaignUs cCampaingMain = (ICampaignUs)sManager.InitServiceInstance(ServiceLists.ASV_CAMPAIGN.DLL, ServiceLists.ASV_CAMPAIGN.CAMPAIGN_MAIN);
                    lblAddPointNm.Text = cCampaingMain.GetCampaignName(m_sAfterSaveInfo.Substring(0, 10).Trim(), 0);
                }
                txtAddPoint.Text = m_cPosStatus.Global.NumericTOCurrency(nAddSavePnt);

                m_bSearchSuccess = true;

                txtPayAmt.ReadOnly = false;
                txtPayAmt.Focus();

                //#20180821 해피포인트 고객이름 마스킹 start
                IDataCommonUs m_cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);
                if (cEtcItem.HP_CUST_NAME != "") { cEtcItem.HP_CUST_NAME = m_cDataCommon.NameMasking(cEtcItem.HP_CUST_NAME); }
                //#20180821 해피포인트 고객이름 마스킹 end

                //#10805 dkshin 추후적립 고객명 표시
                lblTitle.Text += "  [ " + cEtcItem.HP_CUST_NAME + " ]";
                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;
        }
        #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
            {
                if (bNotDoubleClik) return;
                bNotDoubleClik = true;

                switch (sDevice)
                {
                    case PosConst.OPOS_DEVICE.MSR:
                        this.Invoke(new EventHandler(OnMSREvent));
                        break;
                    case PosConst.OPOS_DEVICE.SCANNER:
                        this.Invoke(new EventHandler(OnScannerEvent));
                        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);
                bNotDoubleClik = false;
            }
            bNotDoubleClik = false;
        }

        /// <summary>
        /// MSR Event
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        private void OnMSREvent(object source, EventArgs e)
        {
            try
            {
                string sMsrData = m_cDevStatus.Msr.Track2Data;
                if (sMsrData.Length > 0)
                {
                    m_sInEncData = "";
                    m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_SWIP;
                    m_sInPutData = sMsrData;

                    txtCardNo.Value = m_sInPutData.Length > 16 ? m_sInPutData.Substring(0, 16) : m_sInPutData;

                    txtEditBox_EditBoxKeyDownEvent(txtCardNo, PosKey.MENU_KEY.ENTER);
                }
            }
            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="source"></param>
        /// <param name="e"></param>
        private void OnScannerEvent(object source, EventArgs e)
        {
            try
            {
                string sScanData = m_cDevStatus.Scanner.DataLabel;
                if (sScanData.Length > 0)
                {
                    m_sInEncData = "";
                    m_sInPutData = sScanData;
                    if (m_sInPutData.Length > 16 && CmUtil.IsNumber(m_sInPutData.Substring(16, 1)) == false)
                    {
                        m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_MOBILE_SWIP;
                        txtCardNo.Value = m_sInPutData.Substring(0, 16);
                    }
                    else
                    {
                        m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_KEYIN;
                        txtCardNo.Value = m_sInPutData;
                    }

                    txtEditBox_EditBoxKeyDownEvent(txtCardNo, PosKey.MENU_KEY.ENTER);
                }
            }
            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>
        /// <param name="sInMaskData"></param>
        /// <param name="sInEncData"></param>
        /// <returns></returns>
        private bool EncryptedCardNo(string sInData, ref string sInMaskData, ref string sInEncData)
        {
            string sEncData = sInData;
            bool bRet = false;
            try
            {
                UnRegIcCallback();              // IC리더 콜백 해지

                //#20170913 현금영수증, 포인트카드 마스킹 미적용 start
                // "0"인 경우 마스킹 미처리
                //기존
                //sEncData = m_cDeviceICReader.GetEncryptedCardNo(sInData).Trim();
                //변경
                sEncData = m_cDeviceICReader.GetEncryptedCardNo(sInData, "0").Trim();
                //#20170913 현금영수증, 포인트카드 마스킹 미적용 end

                if (CmUtil.MidH(sEncData, 0, 2) == "00")
                {
                    sInEncData = CmUtil.MidH(sEncData, 2, 512).Trim();                          // 암호화 데이터
                    sInMaskData = CmUtil.MidH(sEncData, 514, sEncData.Length - 514).Trim();     // 마스킹 데이터

                    //#20170913 현금영수증, 포인트카드 마스킹 미적용 start
                    sInMaskData = CmUtil.MidH(sInMaskData, 0, 6) + "********";
                    //#20170913 현금영수증, 포인트카드 마스킹 미적용 end

                    bRet = true;
                }
                else
                {
                    //암호화 처리 실패!
                    UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", "Fail =>" + sInData);
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0280);
                }
                if (txtCardNo.Value == "") tmrIcCard.Enabled = true;    // IC리더 콜백 설정
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return bRet;
        }

        /// <summary>
        /// IC 카드 정보 입력 처리
        /// </summary>
        /// <returns></returns>
        private bool GetIcCardData(bool bCancelCallBack)
        {
            try
            {
                if (bCancelCallBack == true) UnRegIcCallback(); // IC리더 콜백 해지

                txtCardNo.Value = "";
                ClearCardInfo();        // 카드 입력 정보 클리어

                string sRsvStr = "";
                if (m_cDeviceICReader.GetCardInfo_ICReader(PosConst.IC_READER_TRAN_TYPE.POINT, 0, ref sRsvStr) == true)
                {
                    if (CmUtil.MidH(sRsvStr, 0, 2) == "00")
                    {
                        m_sInEncData = CmUtil.MidH(sRsvStr, 6, 512).Trim();
                        m_sInMaskData = CmUtil.MidH(sRsvStr, 1030, 37).Trim();
                        m_sInPutData = m_sInMaskData;
                        m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_SWIP;

                        txtCardNo.Value = m_sInPutData.Length > 16 ? m_sInPutData.Substring(0, 16) : m_sInPutData;

                        //tmrIcCard.Enabled = true;       // IC리더 콜백 설정
                        return true;
                    }
                }
                if (txtCardNo.Value == "") tmrIcCard.Enabled = true;       // IC리더 콜백 설정
                // WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0321);
            }
            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>
        /// RF 카드 정보 입력 처리
        /// </summary>
        /// <returns></returns>
        private bool GetRfCardData()
        {
            string sRsvStr = "";
            try
            {
                txtCardNo.Value = "";
                ClearCardInfo();        // 카드 입력 정보 클리어

                //카드 정보 입력
                if (m_cDeviceICReader.GetRfCreditCardInfo("1", m_cTrnStatus.Head.NetSaleAmt.ToString(), "", "", "", ref sRsvStr) == false)
                {
                    if (sRsvStr != "") WinManager.ErrorMessage(sRsvStr);
                    return false;
                }

                m_sInEncData = CmUtil.MidH(sRsvStr, 2, 512).Trim();
                m_sInMaskData = CmUtil.MidH(sRsvStr, 514, 40).Trim();

                m_sInPutData = m_sInMaskData;
                m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_RF;

                txtCardNo.Value = m_sInPutData.Length > 16 ? m_sInPutData.Substring(0, 16) : m_sInPutData;
                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);
            }
            finally
            {
                // 여전법 대응////////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref sRsvStr);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return false;
        }

        /// <summary>
        /// POP 카드 정보 입력 처리
        /// </summary>
        /// <returns></returns>
        private bool GetPopCardData()
        {
            string sRsvStr = "";
            try
            {
                txtCardNo.Value = "";
                ClearCardInfo();        // 카드 입력 정보 클리어

                if (m_cDeviceICReader.RfPrepaidCardInfo(ref sRsvStr) == false)
                {
                    if (sRsvStr != "") WinManager.ErrorMessage(sRsvStr);
                    return false;
                }
                if (sRsvStr.StartsWith("T") == true)
                {
                    m_sInPutData = sRsvStr.Substring(7, 16).Trim();
                }
                else if (sRsvStr.StartsWith("E") == true)
                {
                    m_sInPutData = sRsvStr.Substring(1, 20).Trim();
                }
                else
                {
                    return false;
                }

                bool bRet = EncryptedCardNo(m_sInPutData, ref m_sInMaskData, ref m_sInEncData);
                if (bRet == true)
                {
                    m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_RF;
                    txtCardNo.Text = m_sInPutData;
                }
                return bRet;

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

        /// <summary>
        /// 전화번호 입력 처리
        /// </summary>
        /// <returns></returns>
        private bool GetPinPadData()
        {
            try
            {
                txtCardNo.Value = "";
                ClearCardInfo();        // 카드 입력 정보 클리어

                string sRsvStr = "";
                if (m_cDeviceSignPad.GetMsg_SignPad(false, MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0324), ref sRsvStr) == false)
                {
                    // WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0321);
                    return false;
                }
                txtCardNo.Value = sRsvStr;
                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;
        }
        #endregion

        private void lblCardNo_MouseDown(object sender, MouseEventArgs e)
        {
            //if (e.Button == System.Windows.Forms.MouseButtons.Right)
            //{
            //    m_cDevStatus.Scanner.DataLabel = "8231124183433925%";
            //    OnScannerEvent(null, null);
            //}
        }

        #region 여전법 대응
        /// <summary>
        /// ZeroFill 초기화
        /// </summary>
        private void InDataToZeroFill()
        {
            try
            {

                //여전법 대응!
                //////////////////////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref m_sInPutData);
                CmUtil.ZeroFillClear(ref m_sInEncData);
                CmUtil.ZeroFillClear(ref m_sInMaskData);
                //////////////////////////////////////////////////////////////////////////////////

                txtCardNo.Value = string.Empty;
            }
            catch (Exception) { }

        }
        #endregion 여전법 대응

        #region IC리더 콜백 관련
        /// <summary>
        /// IC리더 콜백 설정
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tmrIcCard_Tick(object sender, EventArgs e)
        {
            try
            {
                if (m_cDevStatus.ICReader.UseYn != true)             // 여전법 인증여부(0:MSR, 1:IC)
                {
                    tmrIcCard.Enabled = false;
                    return;
                }

                if (tmrIcCard.Tag == null || tmrIcCard.Tag.ToString() == "")
                {
                    // IC리더 콜백 설정
                    if (bNotDoubleClik) return;

                    tmrIcCard.Enabled = false;

                    //#20170918 IC 콜백 함수 변경 start
                    //포인트창에서 해피제휴 신용카드 리딩시 IC 우선 거래로 인해 '카드를 읽혀 주세요' 팝업 나오는 현상 수정.
                    //기존
                    m_cDeviceICReader.RegIcCallback(delegateReader);
                    //변경
                    //string sApprID = PosMstManager.GetMstVan(ItemConst.TR_ITEM_ID.CREDITCARD_ITEM, ItemConst.TR_ITEM_ID.CREDITCARD.CREDIT_CARD, PosMst.MST_VAN.DATA.APPR_ID);
                    //m_cDeviceICReader.RegIcCallbackCardInfo(sApprID, m_cDataService.IntParse(txtPayAmt.Value), delegateReaderCardInfo);
                    //#20170918 IC 콜백 함수 변경 end
                }
                else if (tmrIcCard.Tag.ToString() == "MSR")
                {
                    // MSR 카드 읽기
                    tmrIcCard.Enabled = false;
                    tmrIcCard.Tag = "";
                    tmrIcCard.Interval = 500;

                    bNotDoubleClik = false;
                    txtEditBox_EditBoxKeyDownEvent(txtCardNo, PosKey.MENU_KEY.ENTER);

                    tmrIcCard.Enabled = true;
                }
                else if (tmrIcCard.Tag.ToString() == "IC")
                {
                    // IC리더 카드 읽기
                    tmrIcCard.Enabled = false;
                    tmrIcCard.Tag = "";
                    tmrIcCard.Interval = 500;

                    bNotDoubleClik = false;
                    btnProc_Click(btnIcCard, null);
                }
                else
                    tmrIcCard.Enabled = false;
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        delegate void DelegateIcReaderCallBack(int rc, StringBuilder str);
        /// <summary>
        /// IC리더 콜백 함수
        /// </summary>
        /// <param name="num"></param>
        /// <param name="str"></param>
        public void OnIcReaderCallBack(int num, StringBuilder str)
        {
            try
            {
                if (txtCardNo.InvokeRequired)
                {
                    DelegateIcReaderCallBack d = new DelegateIcReaderCallBack(OnIcReaderCallBack);
                    this.Invoke(d, new object[] { num, str });
                }
                else
                {
                    if (bNotDoubleClik) return;
                    bNotDoubleClik = true;

                    if (num == 1)
                    {
                        // IC 카드
                        tmrIcCard.Tag = "IC";
                        tmrIcCard.Interval = 100;
                    }
                    else
                    {
                        // MSR 카드
                        if (str.ToString().StartsWith("EN") == true)
                        {
                            ClearCardInfo();        // 카드 입력 정보 클리어

                            m_sInEncData = CmUtil.MidH(str.ToString(), 0, 512).Trim();
                            m_sInMaskData = CmUtil.MidH(str.ToString(), 512, 40).Trim();
                            m_sInPutData = m_sInMaskData;
                            m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_SWIP;

                            txtCardNo.Value = m_sInPutData;
                            tmrIcCard.Tag = "MSR";

                            tmrIcCard.Interval = 100;
                        }
                        else
                        {
                            tmrIcCard.Interval = 500;
                        }
                    }
                    tmrIcCard.Enabled = true;

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

        /// <summary>
        /// IC리더 콜백 해지
        /// </summary>
        private void UnRegIcCallback()
        {
            try
            {
                if (m_cDevStatus.ICReader.UseYn == true)     // 여신전문금융업법 적용여부 체크
                {
                    tmrIcCard.Enabled = false;

                    //#20170918 IC 콜백 함수 변경 start
                    //포인트창에서 해피제휴 신용카드 리딩시 IC 우선 거래로 인해 '카드를 읽혀 주세요' 팝업 나오는 현상 수정.
                    //기존
                    m_cDeviceICReader.UnRegIcCallback();
                    //변경
                    //m_cDeviceICReader.UnRegIcCallbackCardInfo();
                    //#20170918 IC 콜백 함수 변경 end
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        //#20170918 IC 콜백 함수 변경 start
        //포인트창에서 해피제휴 신용카드 리딩시 IC 우선 거래로 인해 '카드를 읽혀 주세요' 팝업 나오는 현상 수정.
        /*
        delegate void DelegateWriteLog(int returnValue, StringBuilder returnData);
        /// <summary>
        /// IC리더 콜백 함수(CardInfo)
        /// </summary>
        /// <param name="returnValue"></param>
        /// <param name="returnData"></param>
        public void OnIcReaderCallBackCardInfo(int returnValue, StringBuilder returnData)
        {
            if (txtCardNo.InvokeRequired)
            {
                DelegateWriteLog d = new DelegateWriteLog(OnIcReaderCallBackCardInfo);
                this.Invoke(d, new object[] { returnValue, returnData });
            }
            else
            {
                if (m_bCardInPut) return;
                m_bCardInPut = true;

                if (returnValue > 0)
                {
                    string sRsvStr = returnData.ToString();
                    if (CmUtil.MidH(sRsvStr, 0, 2) == "00")
                    {
                        m_sCardNo = CmUtil.MidH(sRsvStr, 6, 512).Trim();
                        txtCardNo.Value = CmUtil.MidH(sRsvStr, 1030, 37).Trim();
                        m_sIcChip = CmUtil.MidH(sRsvStr, 518, 512).Trim();
                        if (CmUtil.MidH(sRsvStr, 4, 2).Trim() == "02")
                        {
                            m_InputType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_SWIP;
                        }
                        else
                        {
                            m_InputType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_IC;
                        }
                        m_sServiceCode = CmUtil.MidH(sRsvStr, 1067, 5).Trim();
                        m_sFallDiv = CmUtil.MidH(sRsvStr, 3, 1); // == "3" ? "0" : "1";

                        // IC 카드(CardInfo)
                        tmrIcCard.Tag = "ICREADER";
                        tmrIcCard.Interval = 100;
                        tmrIcCard.Enabled = true;

                        m_bCardInPut = false;
                    }
                }
            }

        }
        */
        //#20170918 IC 콜백 함수 변경 end

        #endregion
    }
}
