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.Collections;
using System.Data;

namespace Cosmos.Win
{
    public partial class frmVipPoint : frm_PayMainBack
    {
        #region 변수 선언
        // if (m_cDevStatus.ICReader.UseYn == true)             // 여전법 인증여부(0:MSR, 1:IC)

        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 IPaymentUs m_cMSRCard = null;                                       // 신용카드 결제 클래스
        private ICampaignUs m_cCampaingMain = null;                                 // 캠페인 관리
        private IDataCommonUs m_cDataCommon = null;                                 // POS 공통함수 인터페이스
        
        private DeviceStatus m_cDevStatus = new DeviceStatus();                     // 디바이스 관리
        private PosOLEDevice.DelegateOlePos delegatePos;
        
        private bool m_bApproval;                                                   //중복 승인 방지 체크
        private bool m_bCardInPut;                                                  //카드 입력 중복 방지
        private string m_InputType = "";                                            //입력구분
        
        private string m_sPayAmtIn;
        public string SetPayAmt { set { m_sPayAmtIn = value; } }                    // 판매등록시 사용자 입력 금액

        private string m_sPosMenuKey;
        /// <summary>
        /// POS 기능키
        /// </summary>
        public string SetPosMenuKey { set { this.m_sPosMenuKey = value; } }

        /// <summary>
        /// 받을금액
        /// </summary>
        private double m_nRemainPayAmt = 0;
        
        #endregion 변수 선언

        #region 생성자 & 소멸자
        public frmVipPoint()
        {
            InitializeComponent();

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

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

            m_cMSRCard = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.MSRCARD);
            m_cDataService = (IDataProcessUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_SERVICE);
            m_cCampaingMain = (ICampaignUs)sManager.InitServiceInstance(ServiceLists.ASV_CAMPAIGN.DLL, ServiceLists.ASV_CAMPAIGN.CAMPAIGN_MAIN);
            m_cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);

            delegatePos = new PosOLEDevice.DelegateOlePos(OnDeviceEvent);

        }

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

            // 고객화면 캠페인 컨텐츠 표시
            m_cCampaingMain.CustDisplayCampaign(ItemConst.CPI_CUST_PAY_TYPE.CREDTCARD);
        }

        private void frmVipPoint_FormClosing(object sender, FormClosingEventArgs e)
        {
            InDataToZeroFill();
            UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", lblTitle.Text);
        }

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

        #endregion 생성자 & 소멸자

        #region 폼 컨트롤 초기화
        /// <summary>
        /// 폼 컨트롤 초기화
        /// </summary>
        private void InitControl()
        {
            try
            {
                
                this.Location = new Point(0, 50);
                this.Size = new Size(1024, 525);
                
                FormManager.SetFormAllControlFont(this, m_cPosStatus.Base.FONT);
                FormManager.SetTextBoxGlobalInfo(this, m_cPosStatus.Global.m_stCultureMaster.nGroupingDigits, m_cPosStatus.Global.m_stCultureMaster.strGroupingSymbol
                    , m_cPosStatus.Global.m_stCultureMaster.nDecimalDigits, m_cPosStatus.Global.m_stCultureMaster.strDecimalSymbol);

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

                btnEnter.BackColor = CmUtil.GetColorToString(m_cPosStatus.ScnMst.ThemeColor);

                lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1002);
                lblCardNo.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0051);

                lblPayAmt.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0049);
                lblDivMonth.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0050);
                lblValidDate.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0052);
                lblDcAmt.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0036);
                lblAppAmt.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0066);
                                
                btnMenu1.Text = "";
                btnMenu2.Text = "";
                btnMenu3.Text = "";
                btnMenu4.Text = "";
                                
                txtCardNo.Text = "";
                txtPayAmt.Text = "";

                txtDivMonth.Text = "";
                txtValidDate.Text = "";

                txtDcAmt.Text = m_cPosStatus.Global.NumericTOCurrency(0);
                txtAppAmt.Text = m_cPosStatus.Global.NumericTOCurrency(0);
                                
                txtPayAmt.Enabled = true;

                m_bCardInPut = false;

                txtPayAmt.Enabled = true;
                txtDivMonth.Enabled = true;

                btnEnter.Visible = false;

                txtCardNo.InputType = UI.InputType.CardNo;

                string sPayamt = m_cPosStatus.Global.NumericTOCurrency(0);

                if (string.IsNullOrEmpty(m_sPayAmtIn)) m_sPayAmtIn = "";

                m_nRemainPayAmt = m_cTrnStatus.Sale.RemainPayAmt;
                if (m_sPayAmtIn != "")
                {
                    if (m_nRemainPayAmt < CmUtil.DoubleParse(m_sPayAmtIn))
                    {
                        sPayamt = m_cPosStatus.Global.NumericTOCurrency(m_nRemainPayAmt);
                    }
                    else
                    {
                        sPayamt = m_cPosStatus.Global.NumericTOCurrency(m_cDataService.DoubleParse(m_sPayAmtIn));
                    }
                }
                else
                {
                    sPayamt = m_cPosStatus.Global.NumericTOCurrency(m_nRemainPayAmt);
                }
                txtPayAmt.Text = sPayamt;  // 결제 대상 금액

                if (string.IsNullOrEmpty(m_cPosStatus.Sale.SaleMainPayStep)) m_cPosStatus.Sale.SaleMainPayStep = "3";
                if (string.IsNullOrEmpty(m_sPosMenuKey)) m_sPosMenuKey = PosKey.MENU_KEY.CREDIT_CARD;
                InitPayMainBack(m_cPosStatus, m_cDataCommon, m_sPosMenuKey, PosConst.MOT_MSG_TYPE.PAY_STEP_3, "");

                txtAppAmt.Text = sPayamt;

                m_sPayAmtIn = "";

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

                //txtPayAmt.Select();
                //txtPayAmt.SelectText();
                txtCardNo.Select();

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

        #endregion

        #region Control Event

        /// <summary>
        /// 결제 금액 변경 이벤트
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtPayAmt_EditBoxTextChangedEvnet(object sender, EventArgs e)
        {
            try
            {
                txtEditBoxClear(true);
                txtAppAmt.Value = txtPayAmt.Value;                
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.ToString());
            }
        }


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

                if (((Cosmos.UI.CsmButton)sender).Text == "") return;   //텍스트가 없는것은 무시

                if (((Cosmos.UI.CsmButton)sender).Name.StartsWith("btnMenu")) SetFuncSelectColor(sender, true);

                if (((Cosmos.UI.CsmButton)sender) == btnEnter) // 승인
                {
                    txtEditBox_EditBoxKeyDownEvent(null, PosKey.MENU_KEY.APPROVAL);
                }
                
                padInPut.SetActiveFocus();
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            finally
            {
                if (((Cosmos.UI.CsmButton)sender).Name.StartsWith("btnMenu")) SetFuncSelectColor(sender, false);
            }
        }

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


                //if (bSelected == true)
                //{
                //    ((UI.CsmButton)sender).BackColor = Color.FromArgb(70, 86, 98);
                //    ((UI.CsmButton)sender).ForeColor = Color.White;
                //}
                //else
                //{
                //    ((UI.CsmButton)sender).BackColor = Color.White;
                //    ((UI.CsmButton)sender).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);
            }
        }
        #endregion

        #region 텍스트박스 활성화 처리
        /// <summary>
        /// 텍스트박스 활성화 처리
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtEditBox_EnterEvent(object sender, EventArgs e)
        {
            try
            {
                padInPut.SetActiveControl = (Control)sender;
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
        #endregion

        #region 텍스트박스 키 입력 이벤트 처리
        /// <summary>
        /// 텍스트박스 키 입력 이벤트 처리
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="sFuncValue"></param>
        private void txtEditBox_EditBoxKeyDownEvent(object sender, string sFuncValue)
        {
            try
            {
                if (sFuncValue == PosKey.MENU_KEY.ENTER)
                {
                    if (((Cosmos.UI.CsmPosEditBox)sender) == txtPayAmt)
                    {
                        if (CheckTxtInPut(txtPayAmt) == false) return;
                        txtCardNo.Focus();
                    }
                    else if (((Cosmos.UI.CsmPosEditBox)sender) == txtCardNo)
                    {
                        CardDataDisplay();

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

                        if (txtValidDate.Value.Length != 4)
                            txtValidDate.Focus();
                        else
                            txtDivMonth.Focus();
                    }
                    else if (((Cosmos.UI.CsmPosEditBox)sender) == txtValidDate)
                    {
                        if (CheckTxtInPut(txtValidDate) == false) return;

                        txtDivMonth.Focus();
                    }
                    //else if (((Cosmos.UI.CsmPosEditBox)sender) == txtDivMonth)
                    //{
                    //    if (CheckTxtInPut(txtDivMonth) == false) return;

                    //    txtEditBox_EditBoxKeyDownEvent(null, PosKey.MENU_KEY.APPROVAL);
                    //}
                }
                else if (sFuncValue == PosKey.MENU_KEY.CLEAR)
                {

                    if (((Cosmos.UI.CsmPosEditBox)sender) == txtValidDate)
                    {
                        txtValidDate.Text = "";
                    }
                    else
                    {
                        if (((Cosmos.UI.CsmPosEditBox)sender).ReadOnly == false) ((Cosmos.UI.CsmPosEditBox)sender).Text = "";
                    }

                }
                else if (sFuncValue == PosKey.MENU_KEY.ESC_PREVIOUS)
                {

                    ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
                    // 캠페인 취소 처리
                    m_cCampaingMain.CancelCampaignPayment(alPayItem.Count.ToString(), "");


                    this.DialogResult = DialogResult.Cancel;
                    this.Close();
                }
                else if (sFuncValue == PosKey.MENU_KEY.APPROVAL)
                {
                    if (CheckTxtInPut(null) == false)
                    {
                        return;
                    }
                    CompleteTxtInPut();
                }                
            }
            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 txtCardNo_EditBoxTextChangedEvnet(object sender, EventArgs e)
        {
            txtEditBoxClear(false);
        }
        #endregion
               
        #region 텍스트박스 입력 유효성 체크

        /// <summary>
        /// 텍스트박스 입력 유효성 체크
        /// </summary>
        /// <param name="sender"></param>
        /// <returns></returns>
        private bool CheckTxtInPut(object sender)
        {
            try
            {
                // 결제 금액 체크
                if (sender == null || ((Cosmos.UI.CsmPosEditBox)sender) == txtPayAmt)
                {

                    if (m_cDataService.DoubleParse(txtPayAmt.Value) == 0)
                    {
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0038);
                        return false;
                    }

                    if (txtPayAmt.Value.Length > 10)
                    {
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0035);    // 입력한 금액이 너무 큰 금액 입니다.
                        return false;
                    }

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

                    if (m_cDataService.DoubleParse(txtAppAmt.Value) > m_cTrnStatus.Sale.RemainPayAmt)
                    {
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0039);
                        return false;
                    }

                    return true;
                }

                if (sender == null || ((Cosmos.UI.CsmPosEditBox)sender) == txtCardNo)
                {

                    if (txtCardNo.Value.Length < 6)
                    {
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0037);
                        txtCardNo.Select();
                        return false;
                    }
                    else
                    {
                        string sCardNo = m_cDataCommon.MSR_CardNoCheck(txtCardNo.Value, txtValidDate.Value, ref m_InputType);

                        int index = sCardNo.IndexOf("=");

                        if (index > 0 && sCardNo.Trim().Length >= 37)
                        {
                            txtValidDate.Value = CmUtil.MidH(sCardNo, index + 1, 4);
                            txtValidDate.Update();
                        }
                    }
                }
                if (sender == null || ((Cosmos.UI.CsmPosEditBox)sender) == txtValidDate)
                {
                    // 유효기간 입력 여부
                    if (txtCardNo.Value != "")
                    {
                        string sCardNo = m_cDataCommon.MSR_CardNoCheck(txtCardNo.Value, txtValidDate.Value, ref m_InputType);

                        int index = sCardNo.IndexOf("=");

                        if (index > 0 && sCardNo.Trim().Length >= 37)
                        {
                            txtValidDate.Value = CmUtil.MidH(sCardNo, index + 1, 4);
                        }
                    }

                    if (txtValidDate.Value.Length != 4)
                    {
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0581);
                        txtValidDate.Select();
                        return false;
                    }
                    else
                    {
                        txtValidDate.Value = txtValidDate.Value.ToString().PadLeft(4, '0');
                        txtValidDate.Update();
                    }
                    txtDivMonth.Select();
                }

                if (sender == null || ((Cosmos.UI.CsmPosEditBox)sender) == txtDivMonth)
                {
                    // 할부개월 입력 여부
                    if (txtDivMonth.Value == "")
                    {
                        txtDivMonth.Value = "00";
                    }
                    else
                    {
                        txtDivMonth.Value = txtDivMonth.Value.ToString().PadLeft(2, '0');
                    }

                }

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

        #region 텍스트박스 입력 완료 처리
        /// <summary>
        /// 텍스트박스 입력 완료 처리
        /// </summary>
        /// <param name="nFlowMode"></param>
        /// <returns></returns>
        private bool CompleteTxtInPut()
        {
            string sRet = UserCom.RST_ERR;
            
            try
            {

                if (m_bApproval == true) return false;
                m_bApproval = true;
                //임의 등록

                sRet = MenualApproval();
                m_bApproval = false;

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

                // 캠페인 할인결제 확정 처리 => 키값
                ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
                m_cCampaingMain.CompleteCampaignPayment((alPayItem.Count - 1).ToString());

                this.DialogResult = DialogResult.OK;
                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);
                return false;
            }
            return true;
        }
        #endregion


        #endregion Control Event

        #region User Method

        /// <summary>
        /// 입력박스 클리어
        /// </summary>
        /// <param name="bCardClear"></param>
        private void txtEditBoxClear(bool bCardClear)
        {
            try
            {
                txtDcAmt.Text = m_cPosStatus.Global.NumericTOCurrency(0);
                txtValidDate.Text = "";
                btnEnter.Visible = false;

                if (bCardClear == true) txtCardNo.Value = "";
            }
            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 카드데이터 화면 표시
        /// <summary>
        /// 카드데이터 화면 표시
        /// </summary>
        /// <returns></returns>
        private void CardDataDisplay()
        {
            try
            {
                // 캠페인 처리 => 키값(취소시사용),카드번호,캠페인대상,지불구분,지불금액
                ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
                double nDisAmt = m_cCampaingMain.ExecuteCampaignPayment(alPayItem.Count.ToString(), CmUtil.RPadH(txtCardNo.Text, 32) , ItemConst.CPI_CUST_PAY_TYPE.CREDTCARD, m_cDataService.DoubleParse(txtPayAmt.Value));
                txtDcAmt.Text = m_cPosStatus.Global.NumericTOCurrency(nDisAmt);                                                                     // 캠페인 할인금액
                txtAppAmt.Text = m_cPosStatus.Global.NumericTOCurrency(CmUtil.DoubleSubtraction(m_cDataService.DoubleParse(txtPayAmt.Value), nDisAmt));     // 승인금액

                btnEnter.Visible = true;

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

        #region 카드번호 조회
        /// <summary>
        /// 카드번호 조회
        /// <param name="sCardData"></param>
        /// <param name="bMenual"></param>
        /// <param name="sUniEtcData"></param>
        /// </summary>
        /// <returns></returns>
        private bool CardSearch(string sCardData, bool bMenual, string sUniEtcData, bool bNFCCard)
        {
            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);
                return false;
            }
            return true;
        }
        #endregion

        #region 임의 등록 처리
        /// <summary>
        /// 임의 등록 처리
        /// <param name=""></param>
        /// </summary>
        /// <returns></returns>
        private string MenualApproval()
        {

            string sRet = UserCom.RST_ERR;
            string sCardNo = "";

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

            try
            {
                string sDivMonth = txtDivMonth.Value.ToString();
                                
                sCardNo = m_cDataCommon.MSR_CardNoCheck(txtCardNo.Value, txtValidDate.Value, ref m_InputType);
                

                //임의 등록 처리
                sRet = m_cMSRCard.SetMenualPayment(new string[] { 
                    sCardNo, m_InputType, txtCardNo.Value, txtDivMonth.Value, m_cDataService.DoubleParse(txtAppAmt.Value).ToString(), "0", "0", "", "99",MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0364)
                  , "", "", m_cDataService.DoubleParse(txtDcAmt.Value).ToString(), txtValidDate.Value,"","", "","","", "",ItemConst.PAY_APP_DIV.COMPULSION,"","", "", "" });

            }
            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;
            }
            return sRet;
        }
        #endregion 임의 등록 처리
        

        /// <summary>
        /// ZeroFill 초기화
        /// </summary>
        private void InDataToZeroFill()
        {
            try
            {
                txtCardNo.Value = string.Empty;

            }
            catch (Exception) { }

        }


        #endregion User Method

        #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
            {
                bool bRet = CardSearch(m_cDevStatus.Msr.Track2Data, false, "", false);
                if (bRet == false)
                {
                    txtCardNo.Text = "";
                    txtCardNo.Select();
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
        #endregion MSR Event


        private void btnExit_Click(object sender, EventArgs e)
        {
            try
            {
                txtEditBox_EditBoxKeyDownEvent(null, PosKey.MENU_KEY.ESC_PREVIOUS);
            }
            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 DeviceEvent 관련


    }
}
