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;

/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 포인트 사용(OCB,OILBANK,BLUE MEMBER...)
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Win
{
    public partial class frmPntMemberUse : frm_PayMainBack
    {

        #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 IDataCommonUs m_cDataCommon = null;                                 // POS 공통함수 인터페이스
        private IPaymentUs m_cPointMemberUse = null;

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

        private string m_sPosMenuKey;
        /// <summary>
        /// 제휴포인트 사용(OCB,OILBANK,BLUE MEMBER...)
        /// </summary>
        public string SetPosMenuKey { set { this.m_sPosMenuKey = value; } }

        /// <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 bool m_bPassWord = false;
        /// <summary>
        /// 대상 금액
        /// </summary>
        private double m_nDestAmt = 0;

        #endregion 변수 선언

        #region 생성자 & 소멸자 & 폼초기화
        public frmPntMemberUse()
        {
            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_cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);
            m_cPointMemberUse = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.POINTMEMBERUSE);

            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 frmPointMemberUse_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();

            if (m_sPosMenuKey == PosKey.MENU_KEY.OKCASHBACK && PosMstManager.GetPosOption(POS_OPTION.OPT326) != "0" && PosMstManager.GetPosOption(POS_OPTION.OPT326) != "" && m_cDevStatus.ICReader.UseYn != true)       // OCB 직통신
            {
                tmrIcCard.Enabled = false;   // IC리더 콜백 설정
            }
            else
            {
                tmrIcCard.Tag = "";
                tmrIcCard.Enabled = true;   // IC리더 콜백 설정
            }
        }

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

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

        private void frmPointMemberUse_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
            {
                this.Location = new Point(0, 50);
                this.Size = new Size(1024, 525);

                // 이미지 로딩 처리
               // picBack.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.POP_SIZE_S);
                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);


                btnCatApp.Visible = false;

                if (m_sPosMenuKey == PosKey.MENU_KEY.OLIBANK)
                {
                    lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0110);
                }
                else if (m_sPosMenuKey == PosKey.MENU_KEY.OKCASHBACK)
                {
                    lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0112);

                    if (m_cDevStatus.CatTerminal.UseYn == true)
                        btnCatApp.Visible = true;
                }
                else if (m_sPosMenuKey == PosKey.MENU_KEY.BLUE_MEMBERS)
                {
                    lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0113);
                }
                else if (m_sPosMenuKey == PosKey.MENU_KEY.RED_MEMBERS)
                {
                    lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0114);
                }                    

                lblCardNo.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0051);
                lblPassword.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0013);
                lblTotSavePoint.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0071);
                lblUsablePoint.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0070);
                lblUsePoint.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0127);

                btnSearch.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0004);
                btnEnter.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0057);
                btnIcCard.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0132);
                btnPinPad.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0097);
                btnMenual.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0364);
                btnCatApp.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0854);

                // 비밀번호 입력 여부 설정
                m_bPassWord = true;
                if (m_sPosMenuKey == PosKey.MENU_KEY.BLUE_MEMBERS || m_sPosMenuKey == PosKey.MENU_KEY.RED_MEMBERS
                    || m_sPosMenuKey == PosKey.MENU_KEY.OLIBANK) m_bPassWord = false;

                if (m_bPassWord == true)
                {
                    lblPassword.Visible = true;
                    txtPassword.Visible = true;
                    btnPinPad.Visible = true;
                    lblBox2.Visible = true;

                    if (m_sPosMenuKey == PosKey.MENU_KEY.OKCASHBACK && PosMstManager.GetPosOption(POS_OPTION.OPT326) != "0" && PosMstManager.GetPosOption(POS_OPTION.OPT326) != "" && m_cDevStatus.ICReader.UseYn != true)       // OCB 직통신
                    {
                        btnIcCard.Visible = false;
                    }
                    else
                    {
                        // 무결성 실패후 진행시 오류 메시지 표시
                        if (m_cDevStatus.ICReader.UseYn == true)     // 여신전문금융업법 적용여부 체크
                        {
                            //if (m_cDevStatus.ICReader.Integrity_IC_Status != true && m_cDevStatus.ICReader.UseYn == true && m_cDevStatus.ICReader.Integrity_SignPad_Status != true && m_cDevStatus.SignPad.UseYn == true) WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0388);
                            //else 
                            //{
                                if (m_cDevStatus.ICReader.Integrity_IC_Status != true && m_cDevStatus.ICReader.UseYn == true) WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0384);
                            //    if (m_cDevStatus.ICReader.Integrity_SignPad_Status != true && m_cDevStatus.SignPad.UseYn == true) WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0385);
                            //}
                        }
                    }
                }
                else
                {
                    lblPassword.Visible = false;
                    txtPassword.Visible = false;
                    btnPinPad.Visible = false;
                    lblBox2.Visible = false;

                    if (m_sPosMenuKey == PosKey.MENU_KEY.OKCASHBACK && PosMstManager.GetPosOption(POS_OPTION.OPT326) != "0" && PosMstManager.GetPosOption(POS_OPTION.OPT326) != "" && m_cDevStatus.ICReader.UseYn != true)       // OCB 직통신
                    {

                    }
                    else
                    {
                        // 무결성 실패후 진행시 오류 메시지 표시
                        if (m_cDevStatus.ICReader.UseYn == true)     // 여신전문금융업법 적용여부 체크
                        {
                            if (m_cDevStatus.ICReader.Integrity_IC_Status != true && m_cDevStatus.ICReader.UseYn == true) WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0384);
                        }
                    }
                }

                // 수기결제 여부 설정
                if (m_sPosMenuKey == PosKey.MENU_KEY.OLIBANK)
                {
                    btnMenual.Visible = true;
                }
                else
                {
                    btnMenual.Visible = false;
                }

                //*** MoonSeokWoo 2017.10.18 OCB 사용시 할인 제외금액 체크 하는 부분 변경 OCB 사용은 결제.
                //m_nDestAmt = m_cDataService.GetPluTagetAmount(m_sPosMenuKey);
                //if (m_nDestAmt > m_cTrnStatus.Sale.RemainPayAmt) m_nDestAmt = m_cTrnStatus.Sale.RemainPayAmt;
                //txtUsePoint.Text = m_cPosStatus.Global.NumericTOCurrency(m_nDestAmt);                       // 할인 대상 금액


                //#14402 기아레드멤버쉽 할인시 할인 불가 상품 할인 대상에 포함 되는 증상 수정 start
                //기존
                /*
                m_nDestAmt = m_cTrnStatus.Sale.RemainPayAmt;
                */
                //변경
                if (m_sPosMenuKey == PosKey.MENU_KEY.OKCASHBACK)
                {
                    m_nDestAmt = m_cTrnStatus.Sale.RemainPayAmt;
                }
                else
                {
                    m_nDestAmt = m_cDataService.GetPluTagetAmount(m_sPosMenuKey);
                    if (m_nDestAmt > m_cTrnStatus.Sale.RemainPayAmt) m_nDestAmt = m_cTrnStatus.Sale.RemainPayAmt;
                }
                //#14402 기아레드멤버쉽 할인시 할인 불가 상품 할인 대상에 포함 되는 증상 수정 end

                txtUsePoint.Text = m_cPosStatus.Global.NumericTOCurrency(m_nDestAmt);

                InitPayMainBack(m_cPosStatus, m_cDataCommon, m_sPosMenuKey, PosConst.MOT_MSG_TYPE.PAY_STEP_3, "");

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

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

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

                // OCB 카드 등록 여부 체크
                ArrayList alTrEtc = (ArrayList)StateObject.GetItemObject(Column.TR_ETC.ITEM);
                foreach (Column.TR_ETC.DATA cEtcItem in alTrEtc)
                {
                    if (cEtcItem.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL) continue;

                    if (cEtcItem.ETC_WAY_CD == ItemConst.TR_ITEM_ID.ETC_INFO_ITEM && cEtcItem.ETC_DTL_CD_01 == ItemConst.TR_ITEM_ID.ETC_INFO.OCB_SAVE)
                    {
                        m_sInPutType = cEtcItem.OCCUR_ENTRY_05;      // 입력구분
                        m_sInPutData = cEtcItem.OCCUR_ENTRY_01;      // 입력데이터
                        m_sInMaskData = cEtcItem.OCCUR_ENTRY_01;     // 마스킹
                        m_sInEncData = cEtcItem.CanFiller1;          // 카드데이터
                        break;
                    }
                }

                txtCardNo.Value = m_sInMaskData;
                txtCardNo.ReadOnly = false;

                if (m_sInPutData != "")
                {
                    if (SearchTxtInPut() == true)
                    {
                        if (m_bPassWord == true)
                        {
                            txtPassword.Select();
                        }
                        else
                        {
                            txtUsePoint.Select();
                        }
                    }
                    else
                    {
                        txtCardNo.Select();
                    }
                }
                else
                {
                    txtCardNo.Select();
                }

            }
            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 = "";      // 카드데이터

                txtTotSavePoint.Text = "";
                txtUsablePoint.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);
            }
        }
        #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) == btnPinPad)        // 핀패드
                {
                    UnRegIcCallback(); // IC리더 콜백 해지
                    if (GetPinPadData() == true)
                    {
                        bNotDoubleClik = false;
                        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 단말기 승인
                {
                    if (m_sPosMenuKey != PosKey.MENU_KEY.OKCASHBACK)
                    {
                        bNotDoubleClik = false;
                        return;
                    }
                    CompleteTxtInPut(1);
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnMenual)        // 수기결제
                {
                    MenualTxtInPut();
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnExit)
                {
                    bNotDoubleClik = false;

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

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

                            }

                            if (CheckTxtInPut(sender) == false) return;

                            if (SearchTxtInPut() == true)
                            {
                                if (m_bPassWord == true)
                                    txtPassword.Focus();
                                else
                                    txtUsePoint.Focus();
                            }
                        }

                        if (((Cosmos.UI.CsmPosEditBox)sender) == txtPassword)
                        {
                            if (txtPassword.Text == "")
                            {
                                // 비밀번호 입력
                                if (GetPinPadData() == false) return;
                            }
                            if (CheckTxtInPut(sender) == false) return;

                            txtUsePoint.Focus();
                        }

                        if (((Cosmos.UI.CsmPosEditBox)sender) == txtUsePoint)
                        {
                            if (CheckTxtInPut(sender) == 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);
                }
                finally
                {
                    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>
        /// 텍스트박스 활성화 처리
        /// </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)
        {
            return CheckTxtInPut(sender, true);
        }
        private bool CheckTxtInPut(object sender, bool bNotManual)
        {
            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;
                    }

 
                    if (m_sInEncData == "")
                    {
                        if (m_sInPutData == "")
                        {
                            m_sInPutData = txtCardNo.Value;
                            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;
                            }
                            if (m_sInPutData.Contains("=") == true) m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_SWIP;
                        }

                        m_sInMaskData = m_sInPutData;
                        if (bNotManual == true)
                        {
                            if (EncryptedCardNo(m_sInPutData, ref m_sInMaskData, ref m_sInEncData) == false) return false;
                        }
                    }
                }

                if (m_bPassWord == true)
                {
                    // 비밀번호 체크
                    if (sender == null || ((Cosmos.UI.CsmPosEditBox)sender) == txtPassword)
                    {
                        //if (m_sPosMenuKey == PosKey.MENU_KEY.OLIBANK)
                        //{
                        //    if (txtPassword.Value.Length == 0)
                        //    {
                        //        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0074);
                        //        txtPassword.Focus();
                        //        return false;
                        //    }
                        //}
                    }
                }

                // 사용포인트 체크
                if (sender == null || ((Cosmos.UI.CsmPosEditBox)sender) == txtUsePoint)
                {
                    if (m_nDestAmt < m_cDataService.DoubleParse(txtUsePoint.Value))
                    {
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0071);
                        txtUsePoint.Focus();
                        return false;
                    }

                    if (CmUtil.AmountCut(m_cDataService.DoubleParse(txtUsePoint.Value), CmUtil.IntParse(m_cPosStatus.Mst.PayRudDwLoc)) != m_cDataService.DoubleParse(txtUsePoint.Value))
                    {
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0036);    // 입력한 금액은 입력 불가 단위 입니다.
                        txtUsePoint.Focus();
                        return false;
                    }

                    if (txtUsePoint.Value.Length == 0 || m_cDataService.DoubleParse(txtUsePoint.Value) == 0)
                    {
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0071);
                        txtUsePoint.Focus();
                        return false;
                    }

                    if (m_sPosMenuKey != PosKey.MENU_KEY.OLIBANK)
                    {
                        double nApprAmt = m_cDataService.DoubleParse(txtUsePoint.Value);
                        if (m_sPosMenuKey == PosKey.MENU_KEY.BLUE_MEMBERS || m_sPosMenuKey == PosKey.MENU_KEY.RED_MEMBERS)  //|| m_sPosMenuKey == PosKey.MENU_KEY.OLIBANK)
                        {
                            nApprAmt = m_cDataCommon.ExecTermCoopCmpPayDc(m_cDataCommon.GetMenuKeyToPayWayCd(m_sPosMenuKey), m_cDataCommon.GetMenuKeyToPayDtlCd(m_sPosMenuKey), "", m_cDataService.DoubleParse(txtUsePoint.Value));
                            if (m_sPosMenuKey == PosKey.MENU_KEY.BLUE_MEMBERS || m_sPosMenuKey == PosKey.MENU_KEY.RED_MEMBERS)
                            {
                                // 블루 레드 멤버스 승인 금액 100원 단위 절삭 처리
                                nApprAmt = CmUtil.MathRounds(nApprAmt, PosConst.MATH_ROUND.TRANCATE, -2);
                            }
                        }

                        if (m_cDataService.DoubleParse(txtUsablePoint.Text) != 0 && m_cDataService.DoubleParse(txtUsablePoint.Text) < nApprAmt)
                        {
                            WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0072);
                            txtUsePoint.Focus();
                            return false;
                        }

                        if (m_cTrnStatus.Sale.RemainPayAmt < nApprAmt)
                        {
                            WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0073);
                            txtUsePoint.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;
        }
        
        /// <summary>
        /// 입력박스 체크(Cat단말기)
        /// </summary>
        /// <param name="sender"></param>
        /// <returns></returns>
        private bool CheckTxtInPutForCat()
        {
            try
            {
                // 사용포인트 체크
                if (CmUtil.AmountCut(m_cDataService.DoubleParse(txtUsePoint.Value), CmUtil.IntParse(m_cPosStatus.Mst.PayRudDwLoc)) != m_cDataService.DoubleParse(txtUsePoint.Value))
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0036);    // 입력한 금액은 입력 불가 단위 입니다.
                    txtUsePoint.Focus();
                    return false;
                }

                if (txtUsePoint.Value.Length > 10 || m_cDataService.DoubleParse(txtUsePoint.Value) <= 0)
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0071);
                    txtUsePoint.Focus();
                    return false;
                }
                if (m_nDestAmt < m_cDataService.DoubleParse(txtUsePoint.Value))
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0071);
                    txtUsePoint.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>
        /// <returns></returns>
        private bool SearchTxtInPut()
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                if (CheckTxtInPut(txtCardNo) == false) return false;

                // 조회
                string[] saRecvdData = null;
                sRet = m_cPointMemberUse.SearchPayment(new string[] { m_sPosMenuKey, m_sInPutType, m_sInPutData, m_sInEncData }, ref saRecvdData);
                if (sRet != UserCom.RST_OK)
                {
                    InDataToZeroFill();
                    txtCardNo.Focus();
                    return false;
                }

                Column.TR_PAYMENT.DATA cPayItem = (Column.TR_PAYMENT.DATA)m_cPointMemberUse.GetPayment(new string[] { });
                txtUsablePoint.Text = m_cPosStatus.Global.NumericTOCurrency(cPayItem.AMT_ENTRY_04);          // 가용포인트
                txtTotSavePoint.Text = m_cPosStatus.Global.NumericTOCurrency(cPayItem.AMT_ENTRY_03);         // 누적포인트

                txtUsePoint.Text = m_cPosStatus.Global.NumericTOCurrency(m_nDestAmt);
                if (m_sPosMenuKey == PosKey.MENU_KEY.OKCASHBACK)
                {
                    if (cPayItem.AMT_ENTRY_04 < m_nDestAmt) txtUsePoint.Text = m_cPosStatus.Global.NumericTOCurrency(cPayItem.AMT_ENTRY_04);
                }

                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="nFlowMode"></param>
        /// <returns></returns>
        private bool CompleteTxtInPut(int nFlowMode)
        {
            string sRet = UserCom.RST_ERR;
            try
            {

                if (nFlowMode == 1)
                {
                    if (CheckTxtInPutForCat() == false) return false;
                    
                    //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_POINT_USE;

                    //승인처리                                                        0,                     1,      2,           3,          4,   5,  6,  7,  8,  9,  10, 11,       12,     13,  14, 15 
                    sRet = m_cPointMemberUse.SetPayment(new string[] { PosConst.POS_CAT_MASTER.TRAN_TYPE, sAppType, "00", txtUsePoint.Value, "0", "0", "", "", "", "", "", "", m_sPosMenuKey, "", "", "" });
                    if (sRet != UserCom.RST_OK)
                    {
                        txtUsePoint.Focus();
                        return false;
                    }

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

                    double nUsePoint = m_cDataService.DoubleParse(txtUsePoint.Value);
                    if (m_sPosMenuKey == PosKey.MENU_KEY.BLUE_MEMBERS || m_sPosMenuKey == PosKey.MENU_KEY.RED_MEMBERS)
                    {
                        nUsePoint = CmUtil.MathRounds(m_cDataService.DoubleParse(txtUsePoint.Value), PosConst.MATH_ROUND.TRANCATE, -2);
                    }

                    // 포인트 사용 승인 처리
                    sRet = m_cPointMemberUse.SetPayment(new string[] { m_sPosMenuKey, m_sInPutType, m_sInMaskData, m_sInEncData, nUsePoint.ToString(), txtPassword.Value });
                    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>
        /// <returns></returns>
        private bool MenualTxtInPut()
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                if (WinManager.QuestionMessage(POS_MESSAGE.ERROR.MSG_0368) == false) return false;

                if (CheckTxtInPut(null, false) == false) return false;

                // 포인트 사용 수기승인 처리
                sRet = m_cPointMemberUse.SetMenualPayment(new string[] { m_sPosMenuKey, m_sInPutType, m_sInMaskData, m_sInEncData, m_cDataService.DoubleParse(txtUsePoint.Value).ToString(), txtPassword.Value });
                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;
        }
        #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
            {
                if (m_sPosMenuKey == PosKey.MENU_KEY.OKCASHBACK && PosMstManager.GetPosOption(POS_OPTION.OPT326) != "0" && PosMstManager.GetPosOption(POS_OPTION.OPT326) != "" && m_cDevStatus.ICReader.UseYn != true)       // OCB 직통신
                {
                    sInEncData = sInData;
                    sInMaskData = sInData;
                    bRet = true;
                }
                else
                {
                    UnRegIcCallback();              // IC리더 콜백 해지

                    sEncData = m_cDeviceICReader.GetEncryptedCardNo(sInData).Trim();
                    if (CmUtil.MidH(sEncData, 0, 2) == "00")
                    {
                        sInEncData = CmUtil.MidH(sEncData, 2, 512).Trim();                          // 암호화 데이터
                        sInMaskData = CmUtil.MidH(sEncData, 514, sEncData.Length - 514).Trim();     // 마스킹 데이터
                        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 (m_sPosMenuKey == PosKey.MENU_KEY.OKCASHBACK && PosMstManager.GetPosOption(POS_OPTION.OPT326) != "0" && PosMstManager.GetPosOption(POS_OPTION.OPT326) != "" && m_cDevStatus.ICReader.UseYn != true)       // OCB 직통신
                    return true;
    
                if (bCancelCallBack == true) UnRegIcCallback(); // IC리더 콜백 해지

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

                string sRsvStr = "";
                if (m_cDeviceICReader.GetCardInfo_ICReader(PosConst.IC_READER_TRAN_TYPE.POINT, CmUtil.IntParse(txtUsePoint.Value), 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>
        /// 비밀번호 입력 처리
        /// </summary>
        /// <returns></returns>
        private bool GetPinPadData()
        {
            try
            {
                txtPassword.Text = "";
                
                string sPassWord = "";
                if (m_cDeviceSignPad.GetMsg_SignPad(false, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0013), ref sPassWord, 4) == true)
                {
                    txtPassword.Text = sPassWord;

                    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 여전법 대응
        /// <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;
                txtPassword.Value = string.Empty;
            }
            catch (Exception) { }

        }
        #endregion 여전법 대응

        private void lblCardNo_MouseDown(object sender, MouseEventArgs e)
        {
            //if (e.Button == System.Windows.Forms.MouseButtons.Right)
            //{
            //    if (m_sPosMenuKey == PosKey.MENU_KEY.OLIBANK)
            //        m_cDevStatus.Scanner.DataLabel = "7516015102717790";
            //    else if (m_sPosMenuKey == PosKey.MENU_KEY.OKCASHBACK)
            //        m_cDevStatus.Scanner.DataLabel = "2100360697400638";
            //    else
            //        m_cDevStatus.Scanner.DataLabel = "2581104966028022";
            //    OnScannerEvent(null, null);
            //}
        }

        #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(txtUsePoint.Text), 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_sPosMenuKey == PosKey.MENU_KEY.OKCASHBACK && PosMstManager.GetPosOption(POS_OPTION.OPT326) != "0" && PosMstManager.GetPosOption(POS_OPTION.OPT326) != "" && m_cDevStatus.ICReader.UseYn != true)       // OCB 직통신
                    return;

                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

        private void txtCardNo_EditBoxTextChangedEvnet(object sender, EventArgs e)
        {
            try
            {
                txtPassword.Text = "";
                txtTotSavePoint.Text = m_cPosStatus.Global.NumericTOCurrency(0);
                txtUsablePoint.Text = m_cPosStatus.Global.NumericTOCurrency(0);
                txtUsePoint.Text = m_cPosStatus.Global.NumericTOCurrency(0);
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

    }
}
