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

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

namespace Cosmos.Win
{
    public partial class frmHPGiftReChange : Form
    {

        #region Variable

        private SManager sManager = new SManager();                                 // 이 객체를 통해 업무 Service 호출
        private StateServer StateObject = (StateServer)StateServer.GetInstance();   // StateObject : StateServer Object (객체)
        private PosStatus m_cPosStatus = new PosStatus();                           // 기본정보 참조
        private TranStatus m_cTrnStatus = new TranStatus();                         // 거래정보 참조
        private IDataProcessUs m_cDataService = null;
        private ISalePluItemUs m_cPluService = null;                                //판매 등록 관리
        private IDataCommonUs m_cDataCommon = null;                                 // POS 공통함수 인터페이스
        //private ISaleReserved m_cSaleBasic = null;
        private IPaymentUs m_cHappyGift_ReChange = null;
        private ISaleCompleteUs m_cSaleComplete = null;                             // 거래 완료처리
        private IICReaderUs m_cDeviceICReader = null;

        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 DataTable m_dtItemInit;                                             // 조회 상품 리스트

        private string m_sPosMenuKeyOut;
        public string PosMenuKeyOut { set { m_sPosMenuKeyOut = value; } get { return m_sPosMenuKeyOut; } }
        private string m_sPosMenuKey;                                               // SPC 임직원 할인
        /// <summary>
        /// 할인 구분
        /// </summary>
        public string SetPosMenuKey { set { this.m_sPosMenuKey = value; } }

        private readonly Color m_clrSelectFont = Color.FromArgb(102, 102, 102);
        private readonly Color m_clrSelectback = Color.FromArgb(255, 255, 255);

        private readonly Color m_clrNonSelectFont = Color.White;
        private readonly Color m_clrNonSelectback = Color.FromArgb(70, 86, 98);

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

        /// <summary>
        /// 결제 그룹 코드
        /// </summary>
        private string mPay_DC_Type = "";                                          
        /// <summary>
        /// 결제 상세 코드
        /// </summary>
        private string mPay_DC_CD = "";                                          

        /// <summary>
        /// 승인번호
        /// </summary>
        private string mApprNo = "";
        /// <summary>
        /// 승인일자
        /// </summary>
        private string mApprDate = "";
        /// <summary>
        /// 유효기간
        /// </summary>
        private string mExp_DT = "";

        /// <summary>
        /// 입력구분
        /// </summary>
        private string m_sInPutType = "";
        /// <summary>
        /// 입력데이터
        /// </summary>
        private string m_sInPutData = "";
        /// <summary>
        /// 카드데이터
        /// </summary>
        private string m_sInEncData = "";

        /// <summary>
        /// 전문구분
        /// </summary>
        private string m_TranType = "";
        #endregion
        
        #region 생성자 & 소멸자
        public frmHPGiftReChange()
        {
            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_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_cPluService = (ISalePluItemUs)sManager.InitServiceInstance(ServiceLists.BSV_SALE.DLL, ServiceLists.BSV_SALE.SALE_PLU_ITEM);
            m_cSaleComplete = (ISaleCompleteUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.SALE_COMPLETE);
            m_cDeviceICReader = (IICReaderUs)sManager.InitServiceInstance(ServiceLists.AGENT_OLEDEVICE.DLL, ServiceLists.AGENT_OLEDEVICE.DEVICE_ICREADER);

            //m_cSaleBasic = (ISaleReserved)sManager.InitServiceInstance(ServiceLists.BSV_BASIC.DLL, ServiceLists.BSV_BASIC.RESERVED_FINSH);
            m_cHappyGift_ReChange = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.HAPPYGIFTRECHANGE);

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

            ComboBoxInit();

        }
        /// <summary>
        /// 폼로드
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmCheck_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리더 콜백 설정
        }
        /// <summary>
        /// 폼클로즈
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmCheck_FormClosing(object sender, FormClosingEventArgs e)
        {
            tmrIcCard.Tag = "CLOSE";
            UnRegIcCallback();          // IC리더 콜백 해지

            UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", lblTitle.Text);
        }
        /// <summary>
        /// 폼엑티브
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmCheck_Activated(object sender, EventArgs e)
        {
            PosOLEDevice.SetEventHandle(delegatePos);
        }
        /// <summary>
        /// 폼디엑티브
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmCheck_Deactivate(object sender, EventArgs e)
        {
            PosOLEDevice.SetEventHandle(null);
        }

        #endregion 생성자 & 소멸자
        
        #region 폼 컨트롤 초기화
        /// <summary>
        /// 폼 컨트롤 초기화
        /// </summary>
        private void InitControl()
        {
            try
            {
                // 이미지 로딩 처리
                picBack.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.POP_SIZE_800X600);
                //this.Size = new Size(800, 544);

                btnUp.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_210X48_UP1_BASIC);
                btnUp.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_210X48_UP1_PRESS);
                btnDw.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_210X48_DOWN1_BASIC);
                btnDw.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_210X48_DOWN1_PRESS);
                                
                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);

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

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

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

                btnSrh.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0877);
                BtnPrt.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0257);

                btnAppy.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0356);
                btnReChangeCan.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0357);
                //btnRefund.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0358);
                //btnRefundCan.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0401);
                btnSearch.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0403);
                btnMenu1.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0132);

                //btnRefund.Visible = false;
                //btnRefundCan.Visible = false;
                bNotDoubleClik = false;

                btnTitle01.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0355);
                btnTitle02.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0360);
                
                lblSaleDate.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0354);
                lblTradeType.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0067);
                lblCardNo.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0051);
                lblReMainAmt.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0352);
                lblChargeAmt.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0359);

                InitializeGrid();

                SetChargeAmt();

                m_sPosMenuKeyOut = "";
                mApprNo = "";
                mApprDate = "";
                mExp_DT = "";

                m_sInPutType = "";      // 입력구분
                m_sInPutData = "";      // 입력데이터
                m_sInEncData = "";       // 카드데이터

                btnTitle_Click(btnTitle01, null);

                txtCardNo.Text = "";
                txtChargeAmt.Text = "0";
                txtReMainAmt.Text = "0";

                txtDateFrom.InputTypeFormat = m_cPosStatus.Global.m_stCultureMaster.strDatePattern;
                txtDateFrom.Value = System.DateTime.Now.ToString("yyyyMM01");
                txtDateTo.InputTypeFormat = m_cPosStatus.Global.m_stCultureMaster.strDatePattern;
                txtDateTo.Value = System.DateTime.Now.ToString("yyyyMMdd");

                m_TranType = PosConst.POS_HAPPYGIFT_INQ_TYPE.RECHANGE_CANCEL;

                // 기능 버튼 설정 체크
                FormManager.SetbtnMenu(txtCardNo, m_cDevStatus.ICReader.UseYn, btnMenu1, btnMenu2, btnMenu3, btnMenu4);

                SetFuncSelectColor("");

                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>
        /// <param name="bScnFlg">false = 충전, True = 조회/취소/환불</param>
        private void SetScreen(bool bScnFlg)
        {
            try
            {
                if (bScnFlg == false)
                {
                    pnlCharge.Visible = false;
                    btnAppy.Visible = true;
                    btnReChangeCan.Visible = false;
                    //btnRefund.Visible = false;
                    //btnRefundCan.Visible = false;
                    txtChargeAmt.Value = "0";

                    btnSrh.Visible = false;
                    BtnPrt.Visible = false;
                }
                else
                {
                    pnlCharge.Location = new Point(8, 206);
                    pnlCharge.Visible = true;
                    btnAppy.Visible = false;
                    btnReChangeCan.Visible = true;
                    //btnRefund.Visible = true;
                    //btnRefundCan.Visible = true;
                    btnSrh.Visible = true;
                    BtnPrt.Visible = true;
                }

                //btnRefund.Visible = false;
                //btnRefundCan.Visible = 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);
            }
        }



        /// <summary>
        /// 그리드 초기화
        /// </summary>
        private void InitializeGrid()
        {
            try
            {
                // 상품권 등록정보 표시 그리드
                grdSearchItem.CsmGridColumnHeadersVisible = true;                                           //DataGridView 자체의 컬럼 헤더 Visible 여부
                grdSearchItem.CsmGridColumnHeadersHeight = 39;                                              //DataGridView 자체의 컬럼 헤더 높이
                grdSearchItem.CsmGridColumnHeadersFont = new Font(m_cPosStatus.Base.FONT, 12, FontStyle.Bold);
                grdSearchItem.Font = new Font(m_cPosStatus.Base.FONT, 12);

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


                //각 컬럼별 이름 지정
                grdSearchItem.CsmGridColumnName(0, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0014));
                grdSearchItem.CsmGridColumnName(1, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0361)); //충전일자
                grdSearchItem.CsmGridColumnName(2, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0362)); //충전시간
                grdSearchItem.CsmGridColumnName(3, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0359)); //충전금액
                grdSearchItem.CsmGridColumnName(4, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0020)); //비고
                grdSearchItem.CsmGridColumnName(5, "APPR_NO");
                grdSearchItem.CsmGridColumnName(6, "APPR_DATE");
                grdSearchItem.CsmGridColumnName(7, "REG_NO");
                grdSearchItem.CsmGridColumnName(8, "TRADE_DIV");
                grdSearchItem.CsmGridColumnName(9, "TRADE_KINDPER");
                grdSearchItem.CsmGridColumnName(10, "JOURNAL_DATA");
                                                
                //그리드 초기화 테이블
                m_dtItemInit = new DataTable("INIT");
                m_dtItemInit.Columns.Add(new DataColumn("NO", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("SALE_DT", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("SALE_TM", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("SALE_AMT", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("TRADE_KIND", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("APPR_NO", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("APPR_DATE", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("REG_NO", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("TRADE_DIV", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("TRADE_KINDPER", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("JOURNAL_DATA", typeof(string)));
                
                
                m_dtItemInit.Clear();

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


        /// <summary>
        /// 콤보박스 초기화
        /// </summary>
        private void ComboBoxInit()
        {

            try
            {
                cbTradeType.Items.Add("0-" + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0226));    //전체
                cbTradeType.Items.Add("1-" + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0360));    //충전
                cbTradeType.Items.Add("2-" + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0357));    //충전취소
                //cbTradeType.Items.Add("3-" + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0358));    //환불
                //cbTradeType.Items.Add("4-" + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0401));    //환불취소

                cbTradeType.SelectedIndex = 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);
            }

        }


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

                if (((Cosmos.UI.CsmButton)sender) == btnMenu1)               // 카드 등록
                {
                    // 카드정보 읽기
                    if (GetIcCardData(e != null ? true : false) == true)
                    {
                        if (m_TranType == PosConst.POS_HAPPYGIFT_INQ_TYPE.RECHANGE)
                            SearchTxtInPut("1");            // 잔액조회
                        else
                            SearchTxtInPut("0");            // 이력조회
                    }
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnSrh) // 조회
                {
                    if (txtCardNo.Value.Length <= 0)
                    {
                        if (GetIcCardData(true) != true)
                        {
                            bNotDoubleClik = false;
                            return;
                        }

                    }
                    SearchTxtInPut("0");
                }
                else if (((Cosmos.UI.CsmButton)sender) == BtnPrt) // 출력
                {
                    HpGiftPrint();
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnSearch) // 잔액조회
                {
                    if (txtCardNo.Value.Length <= 0)
                    {
                        if (GetIcCardData(true) != true)
                        {
                            bNotDoubleClik = false;
                            return;
                        }

                    }
                    SearchTxtInPut("1"); 
                }
                //else if (((Cosmos.UI.CsmButton)sender) == btnRefund) // 환불
                //{
                //    CompleteTxtInPut(ItemConst.TRAN_KIND.CHARGESALE.REFUND, PosConst.POS_HAPPYGIFT_INQ_TYPE.REFUND);
                //}
                //else if (((Cosmos.UI.CsmButton)sender) == btnRefundCan) // 환불취소
                //{
                //    CompleteTxtInPut(ItemConst.TRAN_KIND.CHARGESALE.REFUND, PosConst.POS_HAPPYGIFT_INQ_TYPE.REFUND_CANCEL);
                //}
                else if (((Cosmos.UI.CsmButton)sender) == btnAppy) // 충전
                {
                    if (txtCardNo.Value.Length <= 0)
                    {
                        if (GetIcCardData(true) != true)
                        {
                            bNotDoubleClik = false; 
                            return;
                        }

                    }

                    m_TranType = PosConst.POS_HAPPYGIFT_INQ_TYPE.RECHANGE;

                    CompleteTxtInPut(ItemConst.TRAN_KIND.CHARGESALE.CHARGE, m_TranType);
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnReChangeCan) // 충전취소
                {
                    if (txtCardNo.Value.Length <= 0)
                    {
                        if (GetIcCardData(true) != true)
                        {
                            bNotDoubleClik = false;
                            return;
                        }

                    }

                    m_TranType = PosConst.POS_HAPPYGIFT_INQ_TYPE.RECHANGE_CANCEL;

                    CompleteTxtInPut(ItemConst.TRAN_KIND.CHARGESALE.CHARGE, m_TranType);
                }
                
            }
            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 IC 카드 정보 입력 처리
        /// <summary>
        /// IC 카드 정보 입력 처리
        /// </summary>
        /// <returns></returns>
        private bool GetIcCardData(bool bCancelCallBack)
        {
            try
            {
                if (bCancelCallBack == true) UnRegIcCallback(); // IC리더 콜백 해지

                m_sInPutType = "";
                m_sInPutData = "";
                m_sInEncData = "";
                txtCardNo.Value = "";
                txtCardNo.ReadOnly = false;

                string sRsvStr = "";
                if (m_cDeviceICReader.GetCardInfo_ICReader(PosConst.IC_READER_TRAN_TYPE.POINT, 0, ref sRsvStr, true) == true)
                {
                    if (CmUtil.MidH(sRsvStr, 0, 2) == "00")
                    {
                        txtCardNo.Value = CmUtil.MidH(sRsvStr, 1030, 37).Trim();

                        m_sInEncData = CmUtil.MidH(sRsvStr, 6, 512).Trim();
                        m_sInPutData = CmUtil.MidH(sRsvStr, 1030, 37).Trim();

                        if (CmUtil.MidH(sRsvStr, 4, 2).Trim() == "02")
                        {
                            m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_SWIP;
                        }
                        else
                        {
                            m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_IC;
                        }
                        //tmrIcCard.Enabled = true;       // IC리더 콜백 설정
                        return true;
                    }
                }

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

        #region 조회 그리드 업/다운 클릭 이벤트
        /// <summary>
        /// 조회 그리드 업/다운 클릭 이벤트
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSelProc_Click(object sender, EventArgs e)
        {
            try
            {
                if ((UI.CsmButton)sender == btnUp)
                {
                    grdSearchItem.CsmGridScroll("UP");
                }
                else if ((UI.CsmButton)sender == btnDw)
                {
                    grdSearchItem.CsmGridScroll("DOWN");
                }
            }

            catch (Exception ex)
            {

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


        /// <summary>
        /// 버튼 선택 색상 변경
        /// </summary>
        /// <param name="sBtnName"></param>
        private void SetFuncSelectColor(string sBtnName)
        {
            try
            {

                foreach (Control c in this.Controls)
                {
                    if (c is Cosmos.UI.CsmButton)
                    {

                        if (c.Name.StartsWith("btnPay") && c.Name.Length == 7)
                        {
                            if (c.Name == sBtnName)
                            {
                                c.BackColor = Color.FromArgb(70, 86, 98);
                                c.ForeColor = Color.White;
                            }
                            else
                            {
                                c.BackColor = Color.White;
                                c.ForeColor = Color.FromArgb(70, 86, 98);
                            }
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
               
        /// <summary>
        /// 번호 변경시 기존 조회값 초기화
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtCardNo_EditBoxTextChangedEvnet(object sender, EventArgs e)
        {
            m_sInPutType = "";                                                                                  // 입력구분
            m_sInPutData = "";                                                                                  // 입력데이터
            m_sInEncData = "";                                                                                  // 카드데이터

            txtReMainAmt.Text = "0";
            txtReMainAmt.Tag = "";
            txtChargeAmt.Text = "0";

            m_dtItemInit.Clear();
            grdSearchItem.CsmGridDataSource = m_dtItemInit;
        }

        /// <summary>
        /// 입력박스 이벤트
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="sFuncValue"></param>
        private void txtEditBox_EditBoxKeyDownEvent(object sender, string sFuncValue)
        {
            try
            {
                if (sFuncValue == PosKey.MENU_KEY.ENTER)
                {
                    //조회
                    SearchTxtInPut("1");
                }
                else if (sFuncValue == PosKey.MENU_KEY.APPROVAL)  //승인
                {
                    
                }
                else if (sFuncValue == PosKey.MENU_KEY.CANCEL)  //취소
                {

                }
                else if (sFuncValue == PosKey.MENU_KEY.REFUND)  //환불
                {

                }
                else if (sFuncValue == PosKey.MENU_KEY.CLEAR)
                {
                    if (((Cosmos.UI.CsmPosEditBox)sender).ReadOnly == false) ((Cosmos.UI.CsmPosEditBox)sender).Text = "";

                    if (((Cosmos.UI.CsmPosEditBox)sender) == txtCardNo)
                    {
                        m_sInPutType = "";
                        m_sInPutData = "";
                        m_sInEncData = "";
                        txtCardNo.ReadOnly = false;
                        tmrIcCard.Enabled = true;
                    }
                
                }
                else if (sFuncValue == PosKey.MENU_KEY.ESC_PREVIOUS)
                {
                    m_sPosMenuKeyOut = "";
                    this.DialogResult = DialogResult.Cancel;
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
        /// <summary>
        /// 입력박스 엔터 이벤트
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="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);
            }
        }

        /// <summary>
        /// 종료
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExit_Click(object sender, EventArgs e)
        {
            txtEditBox_EditBoxKeyDownEvent(null, PosKey.MENU_KEY.ESC_PREVIOUS);
        }

        /// <summary>
        /// 콤보박스 이벤트
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbTradeType_TextChanged(object sender, EventArgs e)
        {
            try
            {
                //조회 
                HpGiftSearch();
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        /// <summary>
        /// 타이틀 선택 이벤트
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnTitle_Click(object sender, EventArgs e)
        {
            if ((UI.CsmButton)sender == btnTitle01)
            {
                // 조회/충전 이력
                m_TranType = PosConst.POS_HAPPYGIFT_INQ_TYPE.RECHANGE_CANCEL;

                btnTitle01.ForeColor = m_clrNonSelectFont;
                btnTitle01.BackColor = m_clrNonSelectback;
                btnTitle02.ForeColor = m_clrSelectFont;
                btnTitle02.BackColor = m_clrSelectback;

                SetScreen(true);
            }
            else
            {                
                // 충전
                m_TranType = PosConst.POS_HAPPYGIFT_INQ_TYPE.RECHANGE;

                btnTitle01.ForeColor = m_clrSelectFont;
                btnTitle01.BackColor = m_clrSelectback;
                btnTitle02.ForeColor = m_clrNonSelectFont;
                btnTitle02.BackColor = m_clrNonSelectback;

                txtChargeAmt.Text = "0";
                SetScreen(false);
            }
        }
        #endregion 

        /// <summary>
        /// 충전 금액 add
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPay_Click(object sender, EventArgs e)
        {
            try
            {
                txtChargeAmt.Value = CmUtil.DoubleAdd(m_cDataService.DoubleParse(txtChargeAmt.Value), m_cDataService.DoubleParse(((UI.CsmButton)sender).Tag.ToString())).ToString();

                SetFuncSelectColor(((UI.CsmButton)sender).Name);

                txtChargeAmt.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);
            }
        }

        #endregion

        #region User Method
        /// <summary>
        /// 해피기프트 데이터 조회
        /// </summary>
        private void HpGiftSearch()
        {
            try
            {
                //DataTable dt = null;

                //dt = m_cSaleBasic.SearchReservedFinshList(dtpReservedDate.Value.ToString("yyyyMMdd"), cbReservedType.Text.Substring(0, 1), txtReservedCustNo.Text);

                //if(dt == null || dt.Rows.Count == 0)
                //{
                //    //데이터 없음!
                //    grdSearchItem.CsmGridDataSource = m_dtItemInit;
                //    txtPrtData.Text = "";
                //    txtPrtData.Tag = "";
                //}
                //else
                //{
                //    string sData ="";
                //    string sTime = "";

                //    foreach (DataRow dr in dt.Rows)
                //    {
                //        sData = m_cPosStatus.Global.DateToCulture(CmUtil.MidH(dr["RESERV_DT"].ToString(),0,8));
                //        sTime = CmUtil.StrToTime(CmUtil.MidH(dr["RESERV_DT"].ToString(),8,6));

                //        dr["RESERV_DT"] = string.Format("{0} \n{1}", sData, sTime);

                //        sData = m_cPosStatus.Global.DateToCulture(CmUtil.MidH(dr["REG_RESERV_DT"].ToString(),0,8));
                //        sTime = CmUtil.StrToTime(CmUtil.MidH(dr["REG_RESERV_DT"].ToString(),8,6));

                //        dr["REG_RESERV_DT"] = string.Format("{0} \n{1}", sData, sTime);

                //        dr["AFTER"] = m_cPosStatus.Global.NumericTOCurrency(m_cDataService.DoubleParse(dr["AFTER"].ToString()));
                //        dr["BEFORE"] = m_cPosStatus.Global.NumericTOCurrency(m_cDataService.DoubleParse(dr["BEFORE"].ToString()));
                //    }
                    
                //    //그리드 적용!
                //    grdSearchItem.CsmGridDataSource = dt;
                //    grdSearchItem.CsmGridSelectRow(0);
                    
                //}

                //txtReservedCustNo.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 SetChargeAmt()
        {
            DataTable dtData = null;
            int nRow = 0;
            try
            {
                string sPayamt = m_cPosStatus.Global.NumericTOCurrency(m_cTrnStatus.Sale.RemainPayAmt);
                txtChargeAmt.Text = "0"; // sPayamt;  // 결제 대상 금액
                
                btnPay1.Text = sPayamt;     // 결제 대상 금액
                btnPay1.Tag = "0" + m_cTrnStatus.Sale.RemainPayAmt.ToString();

                btnPay2.Visible = false;
                btnPay3.Visible = false;
                btnPay4.Visible = false;
                btnPay5.Visible = false;
                btnPay6.Visible = false;

                //// 0:pay, 1:Add
                //dtData = m_cDataCommon.SeletCommonCode(PosConst.COMMON_CODE_GROUP.Z0001, "");
                //nRow = 0;
                //if ( dtData != null && dtData.Rows.Count > 0)
                //{
                //    foreach (DataRow dr in dtData.Rows)
                //    {
                //        nRow++;
                //        if (nRow == 1)
                //        {
                //            double nCashCeiling = CmUtil.MathRounds(m_cTrnStatus.Sale.RemainPayAmt, PosConst.MATH_ROUND.CEILING, CmUtil.GetDataRowInt(dr, PosMst.MST_COMMON.DATA.CHAR_VAL_TITLE_VAL_01));

                //            btnPay2.Text = m_cPosStatus.Global.NumericTOCurrency(nCashCeiling);
                //            btnPay2.Tag = "0" + nCashCeiling.ToString();
                //            btnPay2.Visible = true;
                //        }
                //        if (nRow == 2)
                //        {
                //            double nCashCeiling = CmUtil.MathRounds(m_cTrnStatus.Sale.RemainPayAmt, PosConst.MATH_ROUND.CEILING, CmUtil.GetDataRowInt(dr, PosMst.MST_COMMON.DATA.CHAR_VAL_TITLE_VAL_01));

                //            btnPay3.Text = m_cPosStatus.Global.NumericTOCurrency(nCashCeiling);
                //            btnPay3.Tag = "0" + nCashCeiling.ToString();
                //            btnPay3.Visible = true;
                //        }
                //    }
                //}

                dtData = m_cDataCommon.SeletCommonCode(PosConst.COMMON_CODE_GROUP.Z0002, "");
                nRow = 0;
                if (dtData != null && dtData.Rows.Count > 0)
                {
                    foreach (DataRow dr in dtData.Rows)
                    {
                        nRow++;
                        if (nRow == 1)
                        {
                            btnPay4.Text = "+" + CmUtil.GetDataRowStr(dr, PosMst.MST_COMMON.DATA.CD_NM);
                            btnPay4.Tag = CmUtil.GetDataRowStr(dr, PosMst.MST_COMMON.DATA.CHAR_VAL_TITLE_VAL_01);
                            btnPay4.Visible = true;
                        }
                        if (nRow == 2)
                        {
                            btnPay5.Text = "+" + CmUtil.GetDataRowStr(dr, PosMst.MST_COMMON.DATA.CD_NM);
                            btnPay5.Tag = CmUtil.GetDataRowStr(dr, PosMst.MST_COMMON.DATA.CHAR_VAL_TITLE_VAL_01);
                            btnPay5.Visible = true;
                        }
                        if (nRow == 3)
                        {
                            btnPay6.Text = "+" + CmUtil.GetDataRowStr(dr, PosMst.MST_COMMON.DATA.CD_NM);
                            btnPay6.Tag = CmUtil.GetDataRowStr(dr, PosMst.MST_COMMON.DATA.CHAR_VAL_TITLE_VAL_01);
                            btnPay6.Visible = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                   System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        #endregion

        #region 영수증 출력
        /// <summary>
        /// 영수증 출력
        /// </summary>
        /// <returns></returns>
        private bool HpGiftPrint()
        {

            bool bRet = false;

            try
            {
                if (grdSearchItem.CsmGridRowsCount <= 0) return bRet;

                int iRow = grdSearchItem.CsmGridSelectedRowIndex;

                if (grdSearchItem.CsmGridRowsCount <= 0) return false;

                //// 영수증 출력
                return m_cSaleComplete.PosSaleRePrint(m_dtItemInit.Rows[iRow]["JOURNAL_DATA"].ToString());
                
            }
            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;
        }


        #region 여전법 처리
        /// <summary>
        /// ZeroFill 초기화
        /// </summary>
        private void InDataToZeroFill()
        {
            try
            {
                txtCardNo.Value = string.Empty;

            }
            catch (Exception) { }

        }


        #endregion 여전법 처리


        #endregion
               
        #region DeviceEvent 관련
        /// <summary>
        /// DeviceEvent 관련
        /// </summary>
        /// <param name="sDevice"></param>
        /// <param name="sData1"></param>
        /// <param name="sData2"></param>
        /// <param name="sData3"></param>
        public void OnDeviceEvent(string sDevice, string sData1, string sData2, string sData3)
        {
            try
            {
                switch (sDevice)
                {
                    case PosConst.OPOS_DEVICE.MSR:
                        this.Invoke(new EventHandler(OnMSREvent));
                        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);
            }
        }

        #region MSR Event
        /// <summary>
        /// MSR Event
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        private void OnMSREvent(object source, EventArgs e)
        {
            try
            {
                
            }
            catch (Exception ex)
            {
               WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
        #endregion MSR Event



        #endregion DeviceEvent 관련


        #region 텍스트박스 입력 유효성 체크
        /// <summary>
        /// 텍스트박스 입력 유효성 체크
        /// </summary>
        /// <param name="sender"></param>
        /// <returns></returns>
        private bool CheckTxtInPut(object sender, bool bSearchMode, string sInqType)
        {
            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 < 6)
                    {
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0037);
                        txtCardNo.Select();
                        txtCardNo.SelectText();
                        return false;
                    }
                }

                if (bSearchMode == true)
                {
                    if (txtDateFrom.Visible == true && txtDateFrom.Value.Length != 8)
                    {
                        WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0536));
                        txtDateFrom.Select();
                        txtDateFrom.SelectText();
                        return false;
                    }
                    if (txtDateTo.Visible == true && txtDateTo.Value.Length != 8)
                    {
                        WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0536));
                        txtDateTo.Select();
                        txtDateTo.SelectText();
                        return false;
                    }
                }

                if (bSearchMode == false)
                {
                    if (sInqType != PosConst.POS_HAPPYGIFT_INQ_TYPE.RECHANGE_CANCEL)
                    {
                        //if (txtReMainAmt.Tag.ToString() != "1")
                        //{
                        //    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0272);
                        //    txtCardNo.Focus();
                        //    return false;
                        //}

                        if (m_cDataService.DoubleParse(txtChargeAmt.Value.ToString()) < 10000)
                        {
                            string sMsg = string.Format(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0243), m_cPosStatus.Global.NumericTOCurrency(10000));
                            WinManager.ErrorMessage(sMsg);
                            txtChargeAmt.Focus();
                            return false;
                        }

                        if (txtChargeAmt.Value.Length > 10 || m_cDataService.LongParse(txtChargeAmt.Value) <= 0)
                        {
                            WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0036);
                            txtChargeAmt.Focus();
                            return false;
                        }

                        if (CmUtil.AmountCut(m_cDataService.DoubleParse(txtChargeAmt.Value), CmUtil.IntParse(m_cPosStatus.Mst.PayRudDwLoc)) != m_cDataService.DoubleParse(txtChargeAmt.Value))
                        {
                            WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0036);
                            txtChargeAmt.Focus();
                            return false;
                        }

                    }

                    if (sInqType == PosConst.POS_HAPPYGIFT_INQ_TYPE.RECHANGE_CANCEL)
                    {
                        if (grdSearchItem.CsmGridRowsCount <= 0)
                        {
                            WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0273);
                            txtCardNo.Select();
                            txtCardNo.SelectText();
                            return false;
                        }

                        if (mApprNo.Trim() == "")
                        {
                            WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0271);
                            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="sTranKind"></param>
        /// <returns></returns>
        private bool CompleteTxtInPut(string sTranKind, string sInqType)
        {
            string sRet = UserCom.RST_ERR;
            string sInPutType = m_sInPutType;
            string sInPutData = m_sInPutData;
            string sInEncData = m_sInEncData;

            try
            {
                if (CheckTxtInPut(null, true, "") == false) return false;

                if (m_sInEncData == "")
                {
                    if (m_sInPutData == "")
                    {
                        sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_KEYIN;
                        sInPutData = txtCardNo.Value;
                    }
                    EncryptedCardNo(sInPutData, ref sInEncData, ref sInPutData);
                }                

                // 선택된 값
                if (sInqType == PosConst.POS_HAPPYGIFT_INQ_TYPE.RECHANGE_CANCEL)
                {
                    // 충전취소
                    int iRow = grdSearchItem.CsmGridSelectedRowIndex;
                    if (grdSearchItem.CsmGridRowsCount <= 0)
                    {
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0273);
                        return false;
                    }
                    txtChargeAmt.Text = m_cPosStatus.Global.NumericTOCurrency(m_cDataService.DoubleParse(m_dtItemInit.Rows[iRow]["SALE_AMT"].ToString()));  // 거래금액
                    mApprNo = m_dtItemInit.Rows[iRow]["APPR_NO"].ToString();                                                                        // 승인번호
                    mApprDate = m_dtItemInit.Rows[iRow]["APPR_DATE"].ToString();                                                                    // 승인일자
                }
                else
                {
                    mApprNo = "";
                    mApprDate = "";
                }
                mPay_DC_Type = ItemConst.TR_ITEM_ID.ETC_INFO_ITEM;                                                                              // 결제 그룹 코드
                mPay_DC_CD = ItemConst.TR_ITEM_ID.ETC_INFO.HAPPYGIFT;                                                                           // 결제 상세 코드

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

                // 승인 처리
                sRet = m_cHappyGift_ReChange.SetPayment(new string[] { m_sPosMenuKey, sInPutType, sInPutData, sInEncData, m_cDataService.DoubleParse(txtChargeAmt.Value).ToString(), sInqType, mApprNo, mApprDate, mPay_DC_Type, mPay_DC_CD, sInqType, m_cDataService.DoubleParse(txtReMainAmt.Text).ToString(), mExp_DT });

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

                // 헤더 정보 설정
                m_cTrnStatus.Head.TradeKind = sTranKind;
                if (sInqType == PosConst.POS_HAPPYGIFT_INQ_TYPE.RECHANGE || sInqType == PosConst.POS_HAPPYGIFT_INQ_TYPE.REFUND)
                {
                    // 충전/환불은 정상
                    m_cTrnStatus.Head.TradeDiv = ItemConst.TRAN_DIV.NORMAL;
                }
                else
                {   
                    // 충전취소/환불취소는 취소
                    m_cTrnStatus.Head.TradeDiv = ItemConst.TRAN_DIV.REFUND;
                }
                m_cTrnStatus.Head.TotSaleAmt = m_cDataService.DoubleParse(txtChargeAmt.Text);
                m_cTrnStatus.Head.TotQty = 1;

                Column.TR_ETC.DATA m_cEtcItem = (Column.TR_ETC.DATA)m_cHappyGift_ReChange.GetPayment(new string[] { });
                txtReMainAmt.Text = m_cPosStatus.Global.NumericTOCurrency(m_cEtcItem.AMT_ENTRY_04);          // 잔액

                mApprNo = "";

                if (sInqType == PosConst.POS_HAPPYGIFT_INQ_TYPE.RECHANGE || sInqType == PosConst.POS_HAPPYGIFT_INQ_TYPE.REFUND)
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0553);
                else
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0554);

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


            return false;
        }
        
        /// <summary>
        /// 조회 처리
        /// </summary>
        /// <returns></returns>
        private bool SearchTxtInPut(string sSearchType)
        {
            string sRet = UserCom.RST_ERR;
            string sTranType = "";

            string sInPutType = m_sInPutType;
            string sInPutData = m_sInPutData;
            string sInEncData = m_sInEncData;

            try
            {
                if (CheckTxtInPut(null, true, "") == false) return false;

                if (m_sInEncData == "")
                {
                    if (m_sInPutData == "")
                    {
                        sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_KEYIN;
                        sInPutData = txtCardNo.Value;
                    }
                    EncryptedCardNo(sInPutData, ref sInEncData, ref sInPutData);
                }

                //string sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_KEYIN;
                //sInPutData = txtCardNo.Value;

                // 조회
                string[] saRecvdData = null;

                if (sSearchType == "1")
                {
                    txtReMainAmt.Text = "0";
                    txtReMainAmt.Tag = "";
                    mExp_DT = "";
                }
                else
                {
                    m_dtItemInit.Clear();
                }
                mPay_DC_Type = ItemConst.TR_ITEM_ID.ETC_INFO_ITEM;                      // 결제 그룹 코드
                mPay_DC_CD = ItemConst.TR_ITEM_ID.ETC_INFO.HAPPYGIFT;                   // 결제 상세 코드

                string sDateFrom = m_cPosStatus.Global.CultureToDate(txtDateFrom.Text);
                string sDateTo = m_cPosStatus.Global.CultureToDate(txtDateTo.Text);

                sRet = m_cHappyGift_ReChange.SearchPayment(new string[] { m_sPosMenuKey, sInPutType, sInPutData, sInEncData, "1", "", "", "", mPay_DC_Type, mPay_DC_CD, sSearchType, cbTradeType.SelectedIndex.ToString(), sDateFrom, sDateTo }, ref saRecvdData);
                if (sRet != UserCom.RST_OK)
                {
                    // 서버 조회 실패시 로컬 조회
                    LF_LocalSearch();

                    txtCardNo.Select();
                    txtCardNo.SelectText();

                    return false;
                }
                if (sSearchType == "0")
                {
                    m_dtItemInit.Clear();

                    if (saRecvdData.Length > 0)
                    {
                        for (int iLoop = 0; iLoop < saRecvdData.Length; iLoop++)
                        {
                            if (saRecvdData[iLoop].Trim().Length <= 0) continue;

                            string[] aRecvData = saRecvdData[iLoop].Split(new string[] { "|" }, StringSplitOptions.None);

                            if (aRecvData.Length > 0)
                            {
                                DataRow drNewRow = m_dtItemInit.NewRow();

                                sTranType = "";
                                if (aRecvData[4] == "40") sTranType = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0360);
                                if (aRecvData[4] == "41") sTranType = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0358);
                                if (aRecvData[3] == "1") sTranType += MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0010);

                                drNewRow["NO"] = (iLoop + 1).ToString();
                                drNewRow["SALE_DT"] = string.Format("{0:0000-00-00}", m_cDataService.DoubleParse(aRecvData[0]));            // 거래일자
                                drNewRow["SALE_TM"] = string.Format("{0:00:00}", m_cDataService.DoubleParse(aRecvData[1]));                 // 거래시간
                                drNewRow["SALE_AMT"] = m_cPosStatus.Global.NumericTOCurrency(m_cDataService.DoubleParse(aRecvData[5]));    // 거래금액
                                drNewRow["TRADE_KIND"] = sTranType;                                                                 // 비고
                                drNewRow["APPR_NO"] = aRecvData[6].Trim().ToString();                                               // 승인번호
                                drNewRow["APPR_DATE"] = aRecvData[7].Trim().ToString();                                             // 승인일자
                                drNewRow["REG_NO"] = aRecvData[2].Trim().ToString();                                                // 거래번호
                                drNewRow["TRADE_DIV"] = aRecvData[3].Trim().ToString();                                             // 거래구분
                                drNewRow["TRADE_KINDPER"] = aRecvData[4].Trim().ToString();                                         // 거래종별
                                drNewRow["JOURNAL_DATA"] = aRecvData[8].ToString();                                                 // 저널

                                m_dtItemInit.Rows.Add(drNewRow);
                            }
                        }
                        grdSearchItem.CsmGridDataSource = m_dtItemInit;
                        grdSearchItem.CsmGridSelectRow(0);
                    }
                    else
                    {
                        LF_LocalSearch();
                    }
                }
                else
                {
                    Column.TR_ETC.DATA m_cEtcItem = (Column.TR_ETC.DATA)m_cHappyGift_ReChange.GetPayment(new string[] { });

                    mExp_DT = m_cEtcItem.OCCUR_ENTRY_11;
                    txtReMainAmt.Text = m_cPosStatus.Global.NumericTOCurrency(m_cEtcItem.AMT_ENTRY_04);          // 거래전 잔액
                    txtReMainAmt.Tag = "1";
                } 
                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 sInPutData);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return false;
        }
        #endregion 

        #region 로컬 조회
        private string LF_LocalSearch()
        {
            int iLoop = 0;
            string sTranType = "";
            string sRet = UserCom.RST_ERR;
            try
            {
                string sDateFrom = m_cPosStatus.Global.CultureToDate(txtDateFrom.Text);
                string sDateTo = m_cPosStatus.Global.CultureToDate(txtDateTo.Text);

                string sQuery = "";
                sQuery += "SELECT  \n";
                sQuery += "		ESE.SALE_DT						AS SALE_DT   \n";
                sQuery += "	,	ESE.OCCUR_ENTRY_04				AS SALE_TM    \n";
                sQuery += "	,	ESE.REG_NO						AS REG_NO    \n";
                sQuery += "	,	ESH.TRADE_DIV					AS TRADE_DIV \n";
                sQuery += "	,	ESH.TRADE_KINDPER				AS TRADE_KINDPER \n";
                sQuery += "	,	ISNULL(ESE.ETC_AMT, 0)			AS SALE_AMT \n";
                sQuery += "	,	ISNULL(ESE.OCCUR_ENTRY_02,' ')	AS APPR_NO  \n";
                sQuery += "	,	ISNULL(ESE.OCCUR_ENTRY_03,' ')  AS APPR_DATE \n";
                sQuery += "	,	ISNULL(ESJ.JOURNAL_DATA,' ')    AS JOURNAL_DATA \n";
                sQuery += "FROM  \n";
                sQuery += "	POSLOG..ETC_SALE_ETC				ESE \n";
                sQuery += "	LEFT JOIN POSLOG..ETC_SALE_HEADER	ESH \n";
                sQuery += "		ON	ESH.CMP_CD		= ESE.CMP_CD \n";
                sQuery += "		AND ESH.SALE_DT		= ESE.SALE_DT \n";
                sQuery += "		AND ESH.STOR_CD		= ESE.STOR_CD \n";
                sQuery += "		AND ESH.POS_NO		= ESE.POS_NO \n";
                sQuery += "		AND ESH.REG_NO		= ESE.REG_NO \n";
                sQuery += "	LEFT JOIN POSLOG..ETC_SALE_JOURNAL	ESJ \n";
                sQuery += "		ON	ESJ.CMP_CD		= ESE.CMP_CD \n";
                sQuery += "		AND ESJ.SALE_DT		= ESE.SALE_DT \n";
                sQuery += "		AND ESJ.STOR_CD		= ESE.STOR_CD \n";
                sQuery += "		AND ESJ.POS_NO		= ESE.POS_NO \n";
                sQuery += "		AND ESJ.REG_NO		= ESE.REG_NO \n";
                sQuery += "WHERE  \n";
                sQuery += "	ESE.CMP_CD			= '" + m_cPosStatus.Base.CmpCd + "' \n";
                sQuery += "AND ESE.SALE_DT			BETWEEN '" + sDateFrom + "' AND  '" + sDateTo + "' \n";
                sQuery += "AND ESE.STOR_CD			= '" + m_cPosStatus.Base.StoreNo + "' \n";
                sQuery += "AND ESE.OCCUR_ENTRY_01	= '" + txtCardNo.Text.Trim() + "' \n";
                sQuery += "AND ESH.TRADE_KINDPER	IN ('40', '41') \n";
                sQuery += "ORDER BY  \n";
                sQuery += "	ESE.SALE_DT DESC \n";
                sQuery += ",	ESE.REG_NO DESC \n";
                sQuery = sQuery.Replace("\t", " ");

                DataTable dtData = new DataTable();

                IDatabaseSQL m_cSqlDbService = (IDatabaseSQL)sManager.InitServiceInstance(ServiceLists.AGENT_DATABASE.DLL, ServiceLists.AGENT_DATABASE.DATABASE_MSSQL);
                m_cSqlDbService.SetDBConnectionString(m_cPosStatus.Base.LocalDbSource, m_cPosStatus.Base.LocalDbCatalog, m_cPosStatus.Base.LocalDbUserID, m_cPosStatus.Base.LocalDbPassword);

                m_cSqlDbService.DBSelect(sQuery, out dtData);

                if (dtData != null)
                {
                    if (dtData.Rows.Count > 0)
                    {
                        m_dtItemInit.Clear();

                        foreach (DataRow dr in dtData.Rows)
                        {
                            DataRow drNewRow = m_dtItemInit.NewRow();

                            string sSALE_DT = CmUtil.GetDataRowStr(dr, "SALE_DT");
                            string sSALE_TM = CmUtil.GetDataRowStr(dr, "SALE_TM");
                            string sSALE_AMT = CmUtil.GetDataRowStr(dr, "SALE_AMT");
                            string sAPPR_NO = CmUtil.GetDataRowStr(dr, "APPR_NO");
                            string sAPPR_DATE = CmUtil.GetDataRowStr(dr, "APPR_DATE");
                            string sREG_NO = CmUtil.GetDataRowStr(dr, "REG_NO");
                            string sTRADE_DIV = CmUtil.GetDataRowStr(dr, "TRADE_DIV");
                            string sTRADE_KINDPER = CmUtil.GetDataRowStr(dr, "TRADE_KINDPER");
                            string sJOURNAL_DATA = CmUtil.GetDataRowStr(dr, "JOURNAL_DATA");

                            if (sTRADE_KINDPER == "40") sTranType = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0360);
                            if (sTRADE_KINDPER == "41") sTranType = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0358);
                            if (sTRADE_DIV == "1") sTranType += MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0010);

                            drNewRow["NO"] = (iLoop + 1).ToString();
                            drNewRow["SALE_DT"] = string.Format("{0:0000-00-00}", m_cDataService.DoubleParse(sSALE_DT));            // 거래일자
                            drNewRow["SALE_TM"] = string.Format("{0:00:00}", m_cDataService.DoubleParse(sSALE_TM));                 // 거래시간
                            drNewRow["SALE_AMT"] = m_cPosStatus.Global.NumericTOCurrency(m_cDataService.DoubleParse(sSALE_AMT));    // 거래금액
                            drNewRow["TRADE_KIND"] = sTranType;                                                             // 비고
                            drNewRow["APPR_NO"] = sAPPR_NO;                                                                 // 승인번호
                            drNewRow["APPR_DATE"] = sAPPR_DATE;                                                             // 승인일자
                            drNewRow["REG_NO"] = sREG_NO;                                                                   // 거래번호
                            drNewRow["TRADE_DIV"] = sTRADE_DIV;                                                             // 거래구분
                            drNewRow["TRADE_KINDPER"] = sTRADE_KINDPER;                                                     // 거래종별
                            drNewRow["JOURNAL_DATA"] = sJOURNAL_DATA;                                                       // 저널

                            iLoop++;
                            m_dtItemInit.Rows.Add(drNewRow);
                        }
                        grdSearchItem.CsmGridDataSource = m_dtItemInit;
                        grdSearchItem.CsmGridSelectRow(0);
                    }

                    sRet = UserCom.RST_OK;
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            return sRet;
        }
        #endregion

        #region 카드 번호 암호화
        /// <summary>
        /// 카드 번호 암호화
        /// </summary>
        /// <param name="sInData"></param>
        /// <param name="sCardData"></param>
        /// <param name="sCardNo"></param>
        /// <returns></returns>
        private string EncryptedCardNo(string sInData, ref string sCardData, ref string sCardNo)
        {
            string sEncData = sInData;

            try
            {
                UnRegIcCallback();              // IC리더 콜백 해지

                sEncData = m_cDeviceICReader.GetEncryptedCardNo(sInData).Trim();

                if (CmUtil.MidH(sEncData, 0, 2) == "00")
                {
                    sCardData = CmUtil.MidH(sEncData, 2, 512).Trim();
                    sCardNo = CmUtil.MidH(sEncData, 514, sEncData.Length - 514).Trim();
                }
                else
                {
                    //암호화 처리 실패!
                    UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", "Fail =>" + sInData);
                }

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

        #region 달력 클릭
        /// <summary>
        /// 달력 클릭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnFromDate_Click(object sender, EventArgs e)
        {
            try
            {
                string sDate = WinBasic.ShowForm(new string[] { FormManager.FORM_CALENDAR });
                if (sDate != "") txtDateFrom.Value = sDate;
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        private void btnDateTo_Click(object sender, EventArgs e)
        {
            try
            {
                string sDate = WinBasic.ShowForm(new string[] { FormManager.FORM_CALENDAR });
                if (sDate != "") txtDateTo.Value = sDate;
            }
            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 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(txtChargeAmt.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(btnMenu1, 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)
                        {
                            m_sInPutType = "";                                              // 입력구분
                            m_sInPutData = "";                                              // 입력데이터
                            m_sInEncData = "";                                              // 카드데이터

                            txtCardNo.Value = CmUtil.MidH(str.ToString(), 512, 40).Trim();

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

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