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 frmHPGiftReChangeNew : 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 IPaymentUs m_cHappyGiftNew_ReChange = null;
        private ISaleCompleteUs m_cSaleComplete = null;                             // 거래 완료처리
        private IICReaderUs m_cDeviceICReader = null;
        //20171030 dkshin 서명패드 모델명, 버전 체크하여 RF버튼 보이기/숨기기(모델명150P이고 AT02버전 이상일때 보이기)
        private ISignPadUs m_cDeviceSignPad = 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 = "";
        //#20171201, 해피기프트(신) 수정 Start
        /// <summary>
        /// TRADE_DIV (0:정상, 1:반품)
        /// </summary>
        private string mTradeDiv = "";
        //#20171201, 해피기프트(신) 수정 End
        /// <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 = "";

        /// <summary>
        /// FALLBACK 구분
        /// </summary>
        private string m_sFallDiv = "";
        /// <summary>
        /// 서비스구분
        /// </summary>
        private string m_sServiceCode = "";
        #endregion

        #region 생성자 & 소멸자
        public frmHPGiftReChangeNew()
        {
            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);
            m_cHappyGiftNew_ReChange = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.HPGIFTCARD);
            //20171030 dkshin 서명패드 모델명, 버전 체크하여 RF버튼 보이기/숨기기(모델명150P이고 AT02버전 이상일때 보이기)
            m_cDeviceSignPad = (ISignPadUs)sManager.InitServiceInstance(ServiceLists.AGENT_OLEDEVICE.DLL, ServiceLists.AGENT_OLEDEVICE.DEVICE_SIGNPAD);

            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리더 콜백 해지
            //#20171201, 해피기프트(신) 수정 Start
            InDataToZeroFill();
            //#20171201, 해피기프트(신) 수정 End

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

                //20171019 dkshin 해피기프트(신) 충전 라벨 이름 변경
                //lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0351);
                lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1027);

                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);
                btnBalanceSearch.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0403);
                btnIC.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0132);

                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 = "";
                //#20171201, 해피기프트(신) 수정 Start
                mTradeDiv = "";
                //#20171201, 해피기프트(신) 수정 End
                mExp_DT = "";

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

                //#20171201, 해피기프트(신) 수정 Start
                //btnTitle_Click(btnTitle01, null);
                btnTitle_Click(btnTitle02, null);
                //#20171201, 해피기프트(신) 수정 End

                //#20180131, 해피기프트카드(신) 충전 수정 Start
                cbTradeType.SelectedIndex = 0; // 거래구분 초기화 안되는 증상
                //#20180131, 해피기프트카드(신) 충전 수정 End

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

                //#20171201, 해피기프트(신) 수정 Start
                //m_TranType = PosConst.POS_HAPPYGIFT_INQ_TYPE.RECHANGE_CANCEL;
                m_TranType = PosConst.POS_HAPPYGIFT_INQ_TYPE.RECHANGE;
                //#20171201, 해피기프트(신) 수정 End

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

                SetFuncSelectColor("");

                txtCardNo.Select();

                //20171030 dkshin 서명패드 모델명, 버전 체크하여 RF버튼 보이기/숨기기(모델명150P이고 AT02버전 이상일때 보이기) start
                string retVal = string.Empty;
                string sFWver = string.Empty;
                string sModelName = string.Empty; 
                int iFWver = 0;
                //#20171110, 해피기프트(신) 사인패드 사용일 경우만 펌웨어 버전 체크하도록 수정 Start, srlee
                //if (m_cDeviceSignPad.GetSignPadInfo(ref retVal) == true)
                if ((m_cDevStatus.SignPad.UseYn == true) &&
                    (m_cDeviceSignPad.GetSignPadInfo(ref retVal) == true))
                //20171110, 해피기프트(신) 사인패드 사용일 경우만 펌웨어 버전 체크하도록 수정 End, srlee
                {
                    sModelName = CmUtil.MidH(retVal, 0, 9).Trim(); //모델명
                    retVal = CmUtil.MidH(retVal, 10, 19).Trim(); // 펌웨어 버전
                    sFWver = CmUtil.MidH(retVal, 0, 2);
                    iFWver = CmUtil.IntParse(CmUtil.MidH(retVal, 2, 4));
                }
                //#20180201, 해피기프트(신) RF카드 사인패드 펌웨어 AT02. AI07, AL04 이상만 적용되도록 수정 Start
                //if (sModelName.Equals("SN-150P") && iFWver >= 2 && sFWver.Equals("AT"))
                //if (sModelName.Equals("SN-150P") &&
                //   ((iFWver >= 2 && sFWver.Equals("AT")) || (iFWver >= 7 && sFWver.Equals("AI"))))   // AT04 OR AI07 이상
                if ((iFWver >= 2 && sFWver.Equals("AT")) || (iFWver >= 7 && sFWver.Equals("AI")) || (iFWver >= 4 && sFWver.Equals("AL")))               
                //#20180201, 해피기프트(신) RF카드 사인패드 펌웨어 AT02. AI07, AL04 이상만 적용되도록 수정 End
                    btnRF.Visible = true;
                else
                    btnRF.Visible = false;
                // 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);
            }
        }

        /// <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;
                    txtChargeAmt.Value = "0";

                    btnSrh.Visible = false;
                    BtnPrt.Visible = false;
                    btnOpen.Location = new System.Drawing.Point(564, 209);
                    btnOpen.Visible = true;
                    //#20171201, 해피기프트(신) 수정 Start
                    btnBalanceSearch.Visible = true;
                    SetFuncSelectColor("");
                    //#20171201, 해피기프트(신) 수정 End

                }
                else
                {
                    pnlCharge.Location = new Point(8, 206);
                    pnlCharge.Visible = true;
                    btnAppy.Visible = false;
                    btnReChangeCan.Visible = true;
                    btnSrh.Visible = true;
                    BtnPrt.Visible = true;
                    btnOpen.Visible = false;
                    //#20171201, 해피기프트(신) 수정 Start
                    btnBalanceSearch.Visible = false;
                    //#20171201, 해피기프트(신) 수정 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);
            }
        }



        /// <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));    //전체                
                //#20180131, 해피기프트카드(신) 충전 수정 Start
                //cbTradeType.Items.Add("1-" + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0360));    //충전/조회
                cbTradeType.Items.Add("1-" + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0356));    //충전승인
                //#20180131, 해피기프트카드(신) 충전 수정 Start
                cbTradeType.Items.Add("2-" + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0357));    //충전취소

                //#20180131, 해피기프트카드(신) 충전 수정 Start
                //cbTradeType.SelectedIndex = 0; // 거래구분 초기화 안되는 증상
                //#20180131, 해피기프트카드(신) 충전 수정 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);
            }

        }


        #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;
                string sMsg = "";

                if (((Cosmos.UI.CsmButton)sender) == btnIC)
                {
                    //카드 읽기
                    if (m_TranType == PosConst.POS_HAPPYGIFT_INQ_TYPE.RECHANGE) // IC충전
                    {
                        //#20171201, 해피기프트(신) 수정 Start
                        /*if (m_cDataService.DoubleParse(txtChargeAmt.Value.ToString()) < 10000)// IC개시
                            GetIcCardData(e != null ? true : false, 0);
                        else
                        {
                            //개시 된 카드 인지 확인  후 충전
                            if (GetIcCardData(true, 0) != true)
                            {
                                bNotDoubleClik = false;
                                return;
                            }

                            if (OpenTxtInPut(ref sMsg) != true)
                                GetIcCardData(e != null ? true : false, CmUtil.IntParse(txtChargeAmt.Text));
                        }*/

                        GetIcCardData(e != null ? true : false, CmUtil.IntParse(txtChargeAmt.Text));
                        //#20171201, 해피기프트(신) 수정 End
                    }
                    else
                    {
                        if (grdSearchItem.CsmGridRowsCount > 0)//IC충전취소
                        {
                            int iRow = grdSearchItem.CsmGridSelectedRowIndex;
                            GetIcCardData(true, CmUtil.IntParse(m_dtItemInit.Rows[iRow]["SALE_AMT"].ToString()));
                        }
                        else
                            GetIcCardData(e != null ? true : false, 0);
                    }

                }
                else if (((Cosmos.UI.CsmButton)sender) == btnRF)
                {
                    if (m_TranType == PosConst.POS_HAPPYGIFT_INQ_TYPE.RECHANGE) // RF충전
                    {
                        //#20171201, 해피기프트(신) 수정 Start
                        // 기존
                        /*
                        if (m_cDataService.DoubleParse(txtChargeAmt.Value.ToString()) < 10000)// RF개시                       
                            GetRfCardData("0");
                        else
                        {
                            //카드 읽기
                            if (GetRfCardData("0") != true)
                            {
                                bNotDoubleClik = false;
                                return;
                            }
                            
                            //개시 된 카드 인지 확인
                            if (OpenTxtInPut(ref sMsg) != true)
                                GetRfCardData(txtChargeAmt.Value.ToString());
                        }
                        */
                        GetRfCardData(txtChargeAmt.Value.ToString());
                        //#20171201, 해피기프트(신) 수정 End
                    }
                    else
                    {
                        if (grdSearchItem.CsmGridRowsCount > 0)//RF충전취소
                        {
                            int iRow = grdSearchItem.CsmGridSelectedRowIndex;
                            GetRfCardData(m_dtItemInit.Rows[iRow]["SALE_AMT"].ToString());
                        }
                        else
                            GetRfCardData("0");
                    }
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnBalanceSearch) // 잔액조회
                {
                    SearchTxtInPut();

                    //#20171201, 해피기프트(신) 수정 Start
                    if (txtCardNo.Value == "") tmrIcCard.Enabled = true;
                    //#20171201, 해피기프트(신) 수정 End
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnAppy) // 충전
                {
                    m_TranType = PosConst.POS_HAPPYGIFT_INQ_TYPE.RECHANGE;

                    CompleteTxtInPut(ItemConst.TRAN_KIND.CHARGESALE.CHARGE, m_TranType);

                    //#20171201, 해피기프트(신) 수정 Start
                    if (txtCardNo.Value == "") tmrIcCard.Enabled = true;
                    //#20171201, 해피기프트(신) 수정 End
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnSrh) // 이력조회
                {
                    txtCardNo.Text = "";

                    string sTradeType = cbTradeType.Text.Substring(0, 1);

                    LF_LocalSearch(sTradeType);
                }
                else if (((Cosmos.UI.CsmButton)sender) == BtnPrt) // 출력
                {
                    HpGiftPrint();
                }                
                else if (((Cosmos.UI.CsmButton)sender) == btnReChangeCan) // 충전취소
                {
                    m_TranType = PosConst.POS_HAPPYGIFT_INQ_TYPE.RECHANGE_CANCEL;

                    CompleteTxtInPut(ItemConst.TRAN_KIND.CHARGESALE.CHARGE, m_TranType);

                    //#20171201, 해피기프트(신) 수정 Start
                    if (txtCardNo.Value == "") tmrIcCard.Enabled = true;
                    //#20171201, 해피기프트(신) 수정 End
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnOpen) // 개시
                {
                    //#20180131, 해피기프트카드(신) 카드번호 입력 전 개시 시도 시 오류메시지 두번 뜨는 현상 수정 Start
                    //if (OpenTxtInPut(ref sMsg) != true)
                    //    WinManager.ErrorMessage(sMsg); //카드번호 오류 확인 요망 메세지
                    OpenTxtInPut(ref sMsg);
                    //#20180131, 해피기프트카드(신) 카드번호 입력 전 개시 시도 시 오류메시지 두번 뜨는 현상 수정 End

                    //#20171201, 해피기프트(신) 수정 Start
                    if (txtCardNo.Value == "") tmrIcCard.Enabled = true;
                    //#20171201, 해피기프트(신) 수정 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);
            }
            bNotDoubleClik = false;
        }
        #endregion

        #region IC 카드 정보 입력 처리
        /// <summary>
        /// IC 카드 정보 입력 처리
        /// </summary>
        /// <returns></returns>
        private bool GetIcCardData(bool bCancelCallBack, int nSaleAmt)
        {
            string sRsvStr = "";
            try
            {
                m_sInPutType = "";
                m_sInPutData = "";
                m_sInEncData = "";
                m_sFallDiv = "";
                m_sServiceCode = "";

                if (m_cDevStatus.ICReader.UseYn == true)     // 여신전문금융업법 적용여부 체크
                {
                    if (bCancelCallBack == true) UnRegIcCallback(); // IC리더 콜백 해지

                    txtCardNo.Value = "";
                    txtCardNo.ReadOnly = false;

                }
                else
                {
                    // MSR
                    return true;
                }

                if (m_cDeviceICReader.GetCardInfo_ICReader(PosConst.IC_READER_TRAN_TYPE.CREDIT, nSaleAmt, ref sRsvStr) == true)
                {
                    if (CmUtil.MidH(sRsvStr, 0, 2) == "00")
                    {
                        txtCardNo.Value = CmUtil.MidH(sRsvStr, 1030, 37).Trim();   // 마스킹 카드번호
                        m_sInPutData = CmUtil.MidH(sRsvStr, 518, 512).Trim();      // IC Chip Data
                        m_sInEncData = CmUtil.MidH(sRsvStr, 6, 512).Trim();        // Track|| 데이터

                        if (CmUtil.MidH(sRsvStr, 4, 2).Trim() == "02")             // PosEntryMode(02:Swipe, 03: IC)
                        {
                            m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_SWIP;
                        }
                        else
                        {
                            m_sInPutType = 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";   // 거래매체유형(0:미지정, 1:MS, 2:IC, 3:Fallback)

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

                txtCardNo.Text = "";
                txtReMainAmt.Text = "";
                //#20171201, 해피기프트(신) 수정 Start                
                txtCardNo.Value = "";
                m_sInPutType = "";                                                                                  // 입력구분
                m_sInPutData = "";                                                                                  // 입력데이터
                m_sInEncData = "";                                                                                  // 카드데이터
                
                tmrIcCard.Enabled = true;
                //#20171201, 해피기프트(신) 수정 End
                
            }
            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);

                txtCardNo.Text = "";
                txtReMainAmt.Text = "";
                //#20171201, 해피기프트(신) 수정 Start                
                txtCardNo.Value = "";
                m_sInPutType = "";                                                                                  // 입력구분
                m_sInPutData = "";                                                                                  // 입력데이터
                m_sInEncData = "";                                                                                  // 카드데이터

                tmrIcCard.Enabled = true;
                //#20171201, 해피기프트(신) 수정 End
                
            }
        }
        #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();

                //#20171201, 해피기프트(신) 수정 Start
                //txtCardNo.Text = "";
                //#20171201, 해피기프트(신) 수정 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);
            }
        }

        #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;

                #region 주석
                //// 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;
                //        }
                //    }
                //}
                #endregion

                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;
                            //#20171201, 해피기프트(신) 수정 Start
                            btnPay4.Location = new System.Drawing.Point(22, 263);
                            //#20171201, 해피기프트(신) 수정 End
                        }
                        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;
                            //#20171201, 해피기프트(신) 수정 Start
                            btnPay5.Location = new System.Drawing.Point(164, 263);
                            //#20171201, 해피기프트(신) 수정 End
                        }
                        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;
                            //#20171201, 해피기프트(신) 수정 Start
                            btnPay6.Location = new System.Drawing.Point(305, 263);
                            //#20171201, 해피기프트(신) 수정 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);
            }
        }

        #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
            {
                //#20171201, 해피기프트(신) 수정 Start
                //여전법 대응!
                //////////////////////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref m_sInPutData);
                CmUtil.ZeroFillClear(ref m_sInEncData);
                //////////////////////////////////////////////////////////////////////////////////
                //#20171201, 해피기프트(신) 수정 End
                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;
                    }

                    //#20171201, 해피기프트(신) 수정 Start
                    if (sInqType == PosConst.POS_HAPPYGIFT_INQ_TYPE.SEARCH)
                    {
                        if (m_sInPutType == PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_IC)
                        {
                            // IC리더 카드 읽기
                            if (GetIcCardData(true, 0) != true)
                            {
                                bNotDoubleClik = false;
                                return false;
                            }
                        }
                        else if (m_sInPutType == PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_RF)
                        {
                            if (GetRfCardData("0") != true)
                            {
                                bNotDoubleClik = false;
                                return false;
                            }
                        }
                    }
                    //#20171201, 해피기프트(신) 수정 End
                }

                if (bSearchMode == false)                                   // 충전, 충전취소
                {
                    //#20171201, 해피기프트(신) 수정 Start
                    //if (sInqType != PosConst.POS_HAPPYGIFT_INQ_TYPE.RECHANGE_CANCEL)
                    if (sInqType == PosConst.POS_HAPPYGIFT_INQ_TYPE.RECHANGE)
                    //#20171201, 해피기프트(신) 수정 End
                    {
                        //#20171129, 해피기프트(신) MS매장 RF카드 IC승인되도록 수정 Start
                        if (m_cDataService.DoubleParse(txtChargeAmt.Value.ToString()) < 5000)
                        {
                            string sMsg = string.Format(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0243), m_cPosStatus.Global.NumericTOCurrency(5000));
                            WinManager.ErrorMessage(sMsg);
                            txtChargeAmt.Focus();
                            return false;
                        }

                        if (m_cDataService.DoubleParse(txtChargeAmt.Value.ToString()) > 500000)
                        {
                            WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0036);
                            txtChargeAmt.Focus();
                            return false;
                        }

                        if ( 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;
                        }
                        //#20171129, 해피기프트(신) MS매장 RF카드 IC승인되도록 수정 End

                    }

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

                        //#20171201, 해피기프트(신) 수정 Start
                        if (mTradeDiv.Trim() == "1")
                        {
                            WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0229); // 메시지 등록 필요
                            txtCardNo.Value = "";
                            return false;
                        }
                        //#20171201, 해피기프트(신) 수정 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);
                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;
            //#20171201, 해피기프트(신) 수정 Start
            string sChargeMode = string.Empty;
            string sChargeAmt = string.Empty;
            //#20171201, 해피기프트(신) 수정 End

            try
            {
                //#20171201, 해피기프트(신) 수정 Start
                //if (CheckTxtInPut(null, true, "") == false) return false;
                if (CheckTxtInPut(null, false, "") == false) return false;
                //#20171201, 해피기프트(신) 수정 End
            
                //#20171129, 해피기프트(신) MS매장 RF카드 IC승인되도록 수정 Start
                if (m_cDevStatus.ICReader.UseYn == true)     // 여신전문금융업법 적용여부 체크
                {
                    if (m_sInPutData == "" && m_sInEncData == "") // IC 모드여도 키인 OR 바코드 스캔 시 MS 전문 타도록 수정
                    {
                        m_sInEncData = m_cDataCommon.MSR_CardNoCheck(txtCardNo.Value, "0000", ref m_sInPutType);    // 유효기간 '0000'

                        m_sInPutData = "";     
                    }
                    else
                    {
                        //EncryptedCardNo(m_sInPutData, ref m_sInEncData, ref m_sInPutData);
                        if (m_sInPutType == PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_RF)
                        {
                            string m_sInPutDataTemp = m_sInPutData;
                            EncryptedCardNo(m_sInEncData, ref m_sInEncData, ref m_sInPutData);
                            m_sInPutData = m_sInPutDataTemp;
                        }
                    }
                }
                else
                {
                    if (m_sInPutType != PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_RF)
                    {
                        m_sInEncData = m_cDataCommon.MSR_CardNoCheck(txtCardNo.Value, "0000", ref m_sInPutType);    // 유효기간 '0000'
                        m_sInPutData = "";
                    }
                }
                //#20171129, 해피기프트(신) MS매장 RF카드 IC승인되도록 수정 End


                // 선택된 값
                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;
                    }

                    mApprNo = m_dtItemInit.Rows[iRow]["APPR_NO"].ToString();                                                                        // 승인번호
                    mApprDate = m_dtItemInit.Rows[iRow]["APPR_DATE"].ToString();                                                                    // 승인일자

                    //#20171201, 해피기프트(신) 수정 Start
                    //txtChargeAmt.Text = m_cPosStatus.Global.NumericTOCurrency(m_cDataService.DoubleParse(m_dtItemInit.Rows[iRow]["SALE_AMT"].ToString()));  // 거래금액                    
     
                    //if (m_sInPutType == PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_KEYIN)
                    //{
                    //    m_sInEncData = m_cDataCommon.MSR_CardNoCheck(txtCardNo.Value, "0000", ref m_sInPutType);    // 유효기간 '0000'
                    //    m_sInPutData = "";
                    //}

                    //string[] aRet = new string[1];

                    //string[] aParam = new string[] { PosConst.HPGIFTCARD_SEARCH_TYPE.HPGIFTCARD_RECHANGE_CANCEL, m_sInPutType, m_sInEncData, "", m_cDataService.DoubleParse(txtChargeAmt.Text).ToString(), "0", "0", "", "", m_sInPutData, "", m_sFallDiv, "0", mApprNo, mApprDate, "", "", "", "", "", "", "", txtCardNo.Text };
                    //sRet = m_cHappyGiftNew_ReChange.SearchPayment(aParam, ref aRet);

                    sChargeAmt = m_dtItemInit.Rows[iRow]["SALE_AMT"].ToString();                                                                    //거래금액
                    mTradeDiv = m_dtItemInit.Rows[iRow]["TRADE_DIV"].ToString();                                                                    // TRADE_DIV
                    sChargeMode = PosConst.HPGIFTCARD_SEARCH_TYPE.HPGIFTCARD_RECHANGE_CANCEL;
                    //#20171201, 해피기프트(신) 수정 End
                }
                else
                {
                    mApprNo = "";
                    mApprDate = "";

                    //#20171201, 해피기프트(신) 수정 Start
                    //string[] aRet = new string[1];

                    //string[] aParam = new string[] { PosConst.HPGIFTCARD_SEARCH_TYPE.HPGIFTCARD_RECHANGE, m_sInPutType, m_sInEncData, "", m_cDataService.DoubleParse(txtChargeAmt.Text).ToString(), "0", "0", "", "", m_sInPutData, "", m_sFallDiv, "0", "", "", "", "", "", "", "", "", "", txtCardNo.Text };
                    //sRet = m_cHappyGiftNew_ReChange.SearchPayment(aParam, ref aRet);

                    sChargeAmt = txtChargeAmt.Text;
                    sChargeMode = PosConst.HPGIFTCARD_SEARCH_TYPE.HPGIFTCARD_RECHANGE;
                    //#20171201, 해피기프트(신) 수정 End
                }

                //#20171201, 해피기프트(신) 수정 Start
                if (CheckTxtInPut(null, false, sInqType) == false) return false;

                string[] aRet = new string[1];

                string[] aParam = new string[] { sChargeMode, m_sInPutType, m_sInEncData, "", m_cDataService.DoubleParse(sChargeAmt).ToString(), "0", "0", "", "", m_sInPutData, "", m_sFallDiv, "0", mApprNo, mApprDate, "", "", "", "", "", "", "", txtCardNo.Value };
                sRet = m_cHappyGiftNew_ReChange.SearchPayment(aParam, ref aRet);
                //#20171201, 해피기프트(신) 수정 End

                //#20171129, 해피기프트(신) MS매장 RF카드 IC승인되도록 수정 Start
                //if (sRet != UserCom.RST_OK) return false;
                if (sRet != UserCom.RST_OK)
                {
                    WinManager.ErrorMessage(sRet);
                    padInPut.SetActiveFocus();

                    txtCardNo.Value = "";
                    txtCardNo.Select();
                    return false;
                }
                //#20171129, 해피기프트(신) MS매장 RF카드 IC승인되도록 수정 End

                // 헤더 정보 설정
                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;

                    //#20171201, 해피기프트(신) 수정 Start
                    //m_cTrnStatus.Head.OrgPosNo = m_cPosStatus.Base.PosNo;
                    //m_cTrnStatus.Head.OrgSaleDate = sOrgSaleDT;
                    //m_cTrnStatus.Head.OrgTradeNo = m_cPosStatus.Base.PosNo; //reg_no
                    //#20171201, 해피기프트(신) 수정 End

                }
                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_cHappyGiftNew_ReChange.GetPayment(new string[] { });
                //txtChargeAmt.Text = m_cPosStatus.Global.NumericTOCurrency(m_cEtcItem.AMT_ENTRY_04);          // 잔액

                mApprNo = "";
                mApprDate = "";

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

                m_sInPutType = "";
                m_sInPutData = "";
                m_sInEncData = "";

                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 m_sInPutData);
                //////////////////////////////////////////////////////////////////////////////////

            }


            return false;
        }

        /// <summary>
        /// 조회 처리
        /// </summary>
        /// <returns></returns>
        private bool SearchTxtInPut()
        {
            string sRet = UserCom.RST_ERR;

            //string sCardNo = "";
            string sInPutType = m_sInPutType;
            string sInPutData = m_sInPutData;
            string sInEncData = m_sInEncData;
            string sPayAmt = "";

            try
            {
                if (CheckTxtInPut(null, true, PosConst.POS_HAPPYGIFT_INQ_TYPE.SEARCH) == false) return false;


                // IC 모드여도 키인 OR 바코드 스캔 시 MS 전문 타도록 수정
                if (m_cDevStatus.ICReader.UseYn == true)     // 여신전문금융업법 적용여부 체크
                {
                    if (m_sInPutData == "" && m_sInEncData == "")
                    {
                        m_sInEncData = m_cDataCommon.MSR_CardNoCheck(txtCardNo.Value, "0000", ref m_sInPutType);    // 유효기간 '0000'
                        m_sInPutData = "";
                        m_sFallDiv = "0";
                        sPayAmt = "1";
                    }
                    else
                    {
                        //EncryptedCardNo(m_sInPutData, ref m_sInEncData, ref m_sInPutData);
                        if (m_sInPutType == PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_RF)
                        {
                            string m_sInPutDataTemp = m_sInPutData;
                            EncryptedCardNo(m_sInEncData, ref m_sInEncData, ref m_sInPutData);
                            m_sInPutData = m_sInPutDataTemp;
                        }
                        sPayAmt = "0";
                    }
                }
                else
                {
                    //#20171129, 해피기프트(신) MS매장 RF카드 IC승인되도록 수정 Start
                    // 기존
                    //m_sInEncData = m_cDataCommon.MSR_CardNoCheck(txtCardNo.Value, "0000", ref m_sInPutType);    // 유효기간 '0000'
                    //m_sInPutData = "";

                    if (m_sInPutType != PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_RF)
                    {
                        m_sInEncData = m_cDataCommon.MSR_CardNoCheck(txtCardNo.Value, "0000", ref m_sInPutType);    // 유효기간 '0000'
                        m_sInPutData = "";
                    }
                    //#20171129, 해피기프트(신) MS매장 RF카드 IC승인되도록 수정 End
                }

                string[] aRet = new string[1];

                //string sPayAmt = "0";
                //txtBeforeBalanceAmt.Text = "0";

                //0:마스킹 카드번호 1:입력구분 2:카드번호 3:할부개월 4:총금액 5:봉사료
                //6:세금 7:비밀번호 8:신용카드종류 9:칩데이터 10:사인
                //11:Fallback구분 12:제휴할인금액 13:원승인번호 14:원승인일자 15:아이템코드
                //16:매입사코드 17:매입사명

                // 조회요청                                                          0            1          2        3        4    5    6  7   8           9  10          11  12   13  14  15  16  17  18  19  20  21                
                //string[] aParam = new string[] { PosConst.CREDITCARD_SEARCH_TYPE.POINT, m_InputType, m_sCardNo, sMonDiv, sPayAmt, "0", "0", "", "", m_sIcChip, "", m_sFallDiv, "0", "", "", "", "", "", "", "", "", "" };

                string[] aParam = new string[] { PosConst.HPGIFTCARD_SEARCH_TYPE.HPGIFTCARD_SEARCH, m_sInPutType, m_sInEncData, "", sPayAmt, "0", "0", "", "", m_sInPutData, "", m_sFallDiv, "0", "", "", "", "", "", "", "", "", "" };

                sRet = m_cHappyGiftNew_ReChange.SearchPayment(aParam, ref aRet);

                if (sRet != UserCom.RST_OK)
                {
                    WinManager.ErrorMessage(sRet);
                    padInPut.SetActiveFocus();

                    txtCardNo.Value = "";
                    txtCardNo.Select();
                    return false;
                }
                //#20171201, 해피기프트(신) 수정 Start
                else
                {
                    string sMsg = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0623) + " [ " + m_cPosStatus.Global.NumericTOCurrency(CmUtil.DoubleParse(aRet[0])) + " ] ";
                    WinManager.ConfirmMessage(sMsg);
                }
                //#20171201, 해피기프트(신) 수정 End

                //Column.TR_ETC.DATA m_cEtcItem = (Column.TR_ETC.DATA)m_cHappyGiftCard_ReChange.GetPayment(new string[] { });

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

                txtReMainAmt.Text = m_cPosStatus.Global.NumericTOCurrency(CmUtil.DoubleParse(aRet[0]));          // 카드잔액
                txtReMainAmt.Tag = "1";

                //#20171201, 해피기프트(신) 수정 Start
                m_TranType = PosConst.POS_HAPPYGIFT_INQ_TYPE.RECHANGE;  // 잔액조회 버튼 충전탭에서만 보이도록 변경 
                //#20171201, 해피기프트(신) 수정 End

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

        //개시
        private bool OpenTxtInPut(ref string sRet)
        {
            sRet = UserCom.RST_ERR;

            //string sCardNo = "";
            string sInPutType = m_sInPutType;
            string sInPutData = m_sInPutData;
            string sInEncData = m_sInEncData;
            string sPayAmt = "";

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


                // IC 모드여도 키인 OR 바코드 스캔 시 MS 전문 타도록 수정
                if (m_cDevStatus.ICReader.UseYn == true)     // 여신전문금융업법 적용여부 체크
                {
                    if (m_sInPutData == "" && m_sInEncData == "")
                    {
                        m_sInEncData = m_cDataCommon.MSR_CardNoCheck(txtCardNo.Value, "0000", ref m_sInPutType);    // 유효기간 '0000'
                        m_sInPutData = "";
                        m_sFallDiv = "0";
                        sPayAmt = "1";
                    }
                    else
                    {
                        //EncryptedCardNo(m_sInPutData, ref m_sInEncData, ref m_sInPutData);
                        if (m_sInPutType == PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_RF)
                        {
                            string m_sInPutDataTemp = m_sInPutData;
                            EncryptedCardNo(m_sInEncData, ref m_sInEncData, ref m_sInPutData);
                            m_sInPutData = m_sInPutDataTemp;
                        }
                        sPayAmt = "0";
                    }
                }
                else
                {
                    //#20171129, 해피기프트(신) MS매장 RF카드 IC승인되도록 수정 Start
                    // 기존
                    //m_sInEncData = m_cDataCommon.MSR_CardNoCheck(txtCardNo.Value, "0000", ref m_sInPutType);    // 유효기간 '0000'
                    //m_sInPutData = "";

                    if (m_sInPutType != PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_RF)
                    {
                        m_sInEncData = m_cDataCommon.MSR_CardNoCheck(txtCardNo.Value, "0000", ref m_sInPutType);    // 유효기간 '0000'
                        m_sInPutData = "";
                    }
                    //#20171129, 해피기프트(신) MS매장 RF카드 IC승인되도록 수정 End
                }

                string[] aRet = new string[1];

                //0:마스킹 카드번호 1:입력구분 2:카드번호 3:할부개월 4:총금액 5:봉사료
                //6:세금 7:비밀번호 8:신용카드종류 9:칩데이터 10:사인
                //11:Fallback구분 12:제휴할인금액 13:원승인번호 14:원승인일자 15:아이템코드
                //16:매입사코드 17:매입사명

                // 조회요청                                                          0            1          2        3        4    5    6  7   8           9  10          11  12   13  14  15  16  17  18  19  20  21                
                //string[] aParam = new string[] { PosConst.CREDITCARD_SEARCH_TYPE.POINT, m_InputType, m_sCardNo, sMonDiv, sPayAmt, "0", "0", "", "", m_sIcChip, "", m_sFallDiv, "0", "", "", "", "", "", "", "", "", "" };

                string[] aParam = new string[] { PosConst.HPGIFTCARD_SEARCH_TYPE.HPGIFTCARD_OPEN, m_sInPutType, m_sInEncData, "", sPayAmt, "0", "0", "", "", m_sInPutData, "", m_sFallDiv, "0", "", "", "", "", "", "", "", "", "" };

                sRet = m_cHappyGiftNew_ReChange.SearchPayment(aParam, ref aRet);

                if (sRet != UserCom.RST_OK)
                {
                    //#20180131, 해피기프트카드(신) 카드번호 입력 전 개시 시도 시 오류메시지 두번 뜨는 현상 수정 Start
                    WinManager.ErrorMessage(sRet); //카드번호 오류 확인 요망 메세지
                    //#20180131, 해피기프트카드(신) 카드번호 입력 전 개시 시도 시 오류메시지 두번 뜨는 현상 수정 End
                    padInPut.SetActiveFocus();

                    txtCardNo.Value = "";
                    txtCardNo.Select();

                    m_sInPutType = "";
                    sInPutData = "";
                    sInEncData = "";

                    return false;
                }

                m_sInPutType = "";
                sInPutData = "";
                sInEncData = "";

                //개시되었습니다. 메세지추가
                WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0736);
                //this.DialogResult = DialogResult.OK;

                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 로컬 조회
        private string LF_LocalSearch(string cbTradeType)
        {
            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.AMT_ENTRY_01, 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 += "AND ESH.TRADE_KINDPER	IN ('40') \n";

                if (cbTradeType == "1")//충전
                    sQuery += "AND ESH.TRADE_DIV = '0' \n";
                else if (cbTradeType == "2")//충전취소
                    sQuery += "AND ESH.TRADE_DIV = '1' \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");

                            //#20180131, 해피기프트카드(신) 충전 수정 Start
                            /*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);*/
                            if (sTRADE_KINDPER == "40")
                            {
                                if (sTRADE_DIV == "1")
                                    sTranType = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0357);
                                else
                                    sTranType = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0356);
                            }
                            //#20180131, 해피기프트카드(신) 충전 수정 End

                            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(btnIC, 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

        private bool GetRfCardData(string SaleAmt)
        {
            string sRsvStr = "";
            try
            {
                txtCardNo.Value = "";


                //카드 정보 입력
                if (m_cDeviceICReader.GetRfEtcCardInfo("G", SaleAmt, "", "", "", ref sRsvStr) == false)
                {
                    if (sRsvStr != "") WinManager.ErrorMessage(sRsvStr);
                    return false;
                }

                txtCardNo.Value = CmUtil.MidH(sRsvStr, 1, 16).Trim();
                m_sInEncData = CmUtil.MidH(sRsvStr, 1, 40).Trim();// Track|| 데이터
                m_sInPutData = CmUtil.MidH(sRsvStr, 81, 512).Trim();// chip data

                m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_RF;


                return true;
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            finally
            {
                // 여전법 대응////////////////////////////////////////////////////////////////////
                CmUtil.ZeroFillClear(ref sRsvStr);
                //////////////////////////////////////////////////////////////////////////////////
            }
            return false;
        }

        //#20171201, 해피기프트(신) 수정 Start
        /// 충전금액 변경 시 카드번호 초기화
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtChargeAmt_EditBoxTextChangedEvnet(object sender, EventArgs e)
        {
            //if (txtCardNo.Value != null && txtCardNo.Value != "")
            if ((txtCardNo.Value != null && txtCardNo.Value != "") &&
                (m_sInPutType == PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_RF || m_sInPutType == PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_IC))
            {
                WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0744);

                txtCardNo.Value = "";
                m_sInPutData = "";
                m_sInEncData = "";
                m_sInPutType = "";
            }
        }
        //#20171201, 해피기프트(신) 수정 End
    }
}
