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

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

/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Win
{
    public partial class frmPayPda : 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 DeviceStatus m_cDevStatus = new DeviceStatus();                     // 디바이스 관리

        private IDataCommonUs m_cDataCommon = null;                                 // POS 공통함수 인터페이스
        private IDataProcessUs m_cDataService = null;
        private IPaymentUs m_cCreditCard = null;

        private bool bNotDoubleClik = false;                                        // 더블 클릭 방지용      
        private DataTable m_dtItemInit = null;                                      // 조회 리스트
        private DataTable m_dtItemInit2 = null;                                      // 조회 리스트

        private string m_sPosMenuKeyIn;
        public string PosMenuKeyIn { set { m_sPosMenuKeyIn = value; } get { return m_sPosMenuKeyIn; } }

        #endregion Variable

        #region 생성자 & 소멸자 & 폼초기화
        public frmPayPda()
        {
            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_cCreditCard = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.CREDITCARD);

            GetBtnImg();
        }

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

        private void frmPayPda_Activated(object sender, EventArgs e)
        { 
        }

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

        private void frmPayPda_FormClosing(object sender, FormClosingEventArgs e)
        {
            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>
        private void InitControl()
        {
            try
            {
                // 이미지 로딩 처리
                picBack.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.POP_SIZE_S);
                this.Size = new Size(788, 402);
                FormManager.MovePopUpForm(this, true, m_cPosStatus.Sale.ScreenSizeUser);
                //this.Location = new Point(216, 173);

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

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

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

                btnSrh.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0004);
                btnEnter.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0126);

                bNotDoubleClik = false;

                InitializeGrid();

            }
            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.CsmGridColumnHeadersFont = new Font(m_cPosStatus.Base.FONT, 12,FontStyle.Bold);  //DataGridView 자체의 컬럼 헤더 폰트
                grdSearchItem.Font = new Font(m_cPosStatus.Base.FONT, 10);
                grdSearchItem.CsmGridColumnHeadersHeight = 32;              //DataGridView 자체의 컬럼 헤더 높이
                grdSearchItem.CsmGridRowsHeight = 28;
                grdSearchItem.CsmGridColumnCount = 25;                       //그리드의 컬럼수
                grdSearchItem.CsmGridShowPageRowsCount = 8;                 //그리드의 한 화면에 보이는 로우수
                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, 90, 90, 160, 123, 100, 123 });   //컬럼넓이 지정(716)
                grdSearchItem.CsmGridAlignment(new int[] { 2, 1, 1, 2, 1, 2, 0 });               //컬럼 정렬 0:왼쪽, 1:가운데, 2:오른쪽

                //각 컬럼별 이름 지정
                grdSearchItem.CsmGridColumnName(0, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0014));
                grdSearchItem.CsmGridColumnName(1, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0445));
                grdSearchItem.CsmGridColumnName(2, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0446));
                grdSearchItem.CsmGridColumnName(3, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0051));
                grdSearchItem.CsmGridColumnName(4, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0053));
                //grdSearchItem.CsmGridColumnName(5, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0050));
                grdSearchItem.CsmGridColumnName(5, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0066));
                grdSearchItem.CsmGridColumnName(6, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0007));

                for (int iRow = 7; iRow <= 26; iRow++)
                {
                    grdSearchItem.CsmGridColumnShowHide(iRow, false);
                }
                
                //그리드 초기화 테이블
                // 그리드 0:NO,1:승인일자,2:승인시간,3:카드번호,4:승인번호,5:거래금액,6:카드명,7:CATID,8:할부개월,9:EntryMode,10:서명FLAF
                //       11:업무구분,12:거래일련번호,13:부가세,14:봉사료,15:발급사코드,16:발급사명,17:매입사코드,18:매입사명,19:원거래일자,20:추적번호
                //       21:가맹점ID,22:응답코드,23:카드구분,24:사업자번호,25:그룹코드
                m_dtItemInit = new DataTable("INIT");
                m_dtItemInit.Columns.Add(new DataColumn("NO", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("TRADE_DT", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("TRADE_TM", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("CARD_NO", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("APP_NO", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("TRADE_AMT", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("CARD_NM", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("CAT_NO", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("INSTAL", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("POS_ENTRY_MODE", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("SIGN_FLAG", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("TRAN_CD", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("TRAN_SEQNO", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("VAT_AMT", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("SVC_AMT", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("ISSUE_CD", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("ISSUE_NM", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("BUY_CD", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("BUY_NM", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("ORG_DT", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("TML_TRACE_NO", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("FRCS_STOR_ID", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("ANSWR_CD", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("CHK_CARD_DIV", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("BIZ_NO", typeof(string)));
                m_dtItemInit.Columns.Add(new DataColumn("MSG_TYPE", typeof(string)));

                m_dtItemInit.Clear();

                m_dtItemInit2 = m_dtItemInit.Clone();

                grdSearchItem.CsmGridDataSource = m_dtItemInit;


            }
            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 GetBtnImg()
        {
            try
            {
                //승인 종류 버튼 테마색상 적용!
                if (m_cPosStatus.ScnMst.ThemeColor.Length == 9)
                {
                    btnEnter.BackColor = CmUtil.GetColorToString(m_cPosStatus.ScnMst.ThemeColor);
                }

                //네이게이션 버튼 이미지 적용!
                btnUp2.Image = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_14X9_UP2_BASIC);
                btnUp.Image = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_14X9_UP1_BASIC);
                btnDw.Image = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_14X9_DOWN1_BASIC);
                btnDw2.Image = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_14X9_DOWN2_BASIC);
                
                if (btnUp2.Image != null) btnUp2.Text = "";
                if (btnUp.Image != null) btnUp.Text = "";
                if (btnDw.Image != null) btnDw.Text = "";
                if (btnDw2.Image != null) btnDw2.Text = "";
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        #endregion 생성자 & 소멸자 & 폼초기화

        #region Control Event

        /// <summary>
        /// 버튼 입력 처리
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnProc_Click(object sender, EventArgs e)
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                if ((UI.CsmButton)sender == btnSrh)
                {
                    //조회
                    SearchData();
                }
                else if ((UI.CsmButton)sender == btnEnter)
                {
                    //등록 처리
                    MenualApproval();
                }

            }
            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)
        {
            try
            {
                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 btnSelProc_Click(object sender, EventArgs e)
        {

            try
            {
                if ((UI.CsmButton)sender == btnUp2)
                {
                    grdSearchItem.CsmGridScroll("PAGE UP");
                }
                else if ((UI.CsmButton)sender == btnUp)
                {
                    grdSearchItem.CsmGridScroll("UP");
                }
                else if ((UI.CsmButton)sender == btnDw)
                {
                    grdSearchItem.CsmGridScroll("DOWN");
                }
                else if ((UI.CsmButton)sender == btnDw2)
                {
                    grdSearchItem.CsmGridScroll("PAGE 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);
            }
        }
        
        #endregion Control Event

        #region User Method

        /// <summary>
        /// 조회 처리
        /// </summary>
        /// <returns></returns>
        private string SearchData()
        {
            string sRet = UserCom.RST_ERR;
            string[] saRecvdData = null;
            DataTable dt = null;

            try
            {
                if (bNotDoubleClik) return sRet;
                bNotDoubleClik = true;
                
                sRet = m_cCreditCard.SearchPayment(new string[] { PosConst.CREDITCARD_SEARCH_TYPE.VAN_CARD_LOG_SEARCH }, ref saRecvdData);
                if (sRet == UserCom.RST_OK)
                {
                    if (saRecvdData[0] == "00")
                    {
                        dt = m_dtItemInit.Clone();

                        string[] aParam = saRecvdData[1].Split(new string[] { "#~" }, StringSplitOptions.None);
                        if (aParam.Length > 0)
                        {
                            for (int iRow = 0; iRow < aParam.Length; iRow++)
                            {
                                DataRow drRow = dt.NewRow();
                                
                                drRow["NO"] = iRow + 1;
                                drRow["MSG_TYPE"] = CmUtil.MidH(aParam[iRow], 0, 4).Trim();
                                drRow["TRAN_CD"] = CmUtil.MidH(aParam[iRow], 4, 2).Trim();
                                drRow["TRAN_SEQNO"] = CmUtil.MidH(aParam[iRow], 6, 12).Trim();
                                drRow["TRADE_DT"] = CmUtil.MidH(aParam[iRow], 18, 8).Trim();
                                drRow["TRADE_TM"] = CmUtil.MidH(aParam[iRow], 26, 6).Trim();
                                drRow["CAT_NO"] = CmUtil.MidH(aParam[iRow], 32, 10).Trim();
                                drRow["CARD_NO"] = CmUtil.MidH(aParam[iRow], 42, 20).Trim();
                                drRow["INSTAL"] = CmUtil.MidH(aParam[iRow], 62, 2).Trim();
                                drRow["APP_NO"] = CmUtil.MidH(aParam[iRow], 64, 12).Trim();
                                drRow["TRADE_AMT"] = m_cPosStatus.Global.NumericTOCurrency(m_cDataService.DoubleParse(CmUtil.MidH(aParam[iRow], 76, 12).Trim()));
                                drRow["VAT_AMT"] = CmUtil.MidH(aParam[iRow], 88, 12).Trim();
                                drRow["SVC_AMT"] = CmUtil.MidH(aParam[iRow], 100, 12).Trim();
                                drRow["ISSUE_CD"] = CmUtil.MidH(aParam[iRow], 112, 4).Trim();
                                drRow["ISSUE_NM"] = CmUtil.MidH(aParam[iRow], 116, 20).Trim();
                                drRow["BUY_CD"] = CmUtil.MidH(aParam[iRow], 136, 4).Trim();
                                drRow["BUY_NM"] = CmUtil.MidH(aParam[iRow], 140, 20).Trim();
                                drRow["CARD_NM"] = CmUtil.MidH(aParam[iRow], 160, 20).Trim();
                                drRow["POS_ENTRY_MODE"] = CmUtil.MidH(aParam[iRow], 180, 2).Trim();
                                drRow["ORG_DT"] = CmUtil.MidH(aParam[iRow], 182, 8).Trim();
                                drRow["TML_TRACE_NO"] = CmUtil.MidH(aParam[iRow], 190, 10).Trim();
                                drRow["FRCS_STOR_ID"] = CmUtil.MidH(aParam[iRow], 200, 15).Trim();
                                drRow["SIGN_FLAG"] = CmUtil.MidH(aParam[iRow], 215, 1).Trim();
                                drRow["ANSWR_CD"] = CmUtil.MidH(aParam[iRow], 216, 2).Trim();
                                drRow["CHK_CARD_DIV"] = CmUtil.MidH(aParam[iRow], 218, 1).Trim();
                                drRow["BIZ_NO"] = CmUtil.MidH(aParam[iRow], 219, 10).Trim();

                                dt.Rows.Add(drRow);
                            }
                        }


                        if (dt == null)
                        {
                            grdSearchItem.CsmGridDataSource = m_dtItemInit;
                        }
                        else
                        {
                            grdSearchItem.CsmGridDataSource = dt;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
                bNotDoubleClik = false;
            }
            bNotDoubleClik = false;
            return sRet;
        }

        /// <summary>
        /// 임의 등록 처리
        /// <param name=""></param>
        /// </summary>
        /// <returns></returns>
        private string MenualApproval()
        {
            string sRet = UserCom.RST_ERR;
            string[] saRecvdData = null;
            
            try
            {
                // 1. 그리드 선택 체크!
                if (grdSearchItem.CsmGridRowsCount == 0)
                {
                    WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0292));
                    return sRet;
                }

                string sSaleAmt = grdSearchItem.CsmGridGetCell(grdSearchItem.CsmGridSelectedRowIndex, 5).Replace(",", "");
                if (m_sPosMenuKeyIn != sSaleAmt)
                {
                    WinManager.ErrorMessage(string.Format(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0291), m_cPosStatus.Global.NumericTOCurrency(m_cDataService.DoubleParse(m_sPosMenuKeyIn))));
                    return sRet;
                }
                

                //2. 등록 가능 여부 체크!
                string sRecv = m_cCreditCard.SearchPayment(new string[] { PosConst.CREDITCARD_SEARCH_TYPE.VAN_CARD_LOG_FINAL, grdSearchItem.CsmGridGetCell(grdSearchItem.CsmGridSelectedRowIndex, 7), grdSearchItem.CsmGridGetCell(grdSearchItem.CsmGridSelectedRowIndex, 12) }, ref saRecvdData);
                if (sRecv == UserCom.RST_ERR)
                {
                    return sRet;
                }
                else if (saRecvdData[0] != "00")
                {
                    // 이미 등록된 거래 입니다.
                    WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0293));
                    return sRet;
                }

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

                //3. 등록 처리
                // 그리드 0:NO,1:승인일자,2:승인시간,3:카드번호,4:승인번호,5:거래금액,6:카드명,7:CATID,8:할부개월,9:EntryMode,10:서명FLAF
                //       11:업무구분,12:거래일련번호,13:부가세,14:봉사료,15:발급사코드,16:발급사명,17:매입사코드,18:매입사명,19:원거래일자,20:추적번호
                //       21:가맹점ID,22:응답코드,23:카드구분,24:사업자번호,25:그룹코드

                aParam[0] = grdSearchItem.CsmGridGetCell(grdSearchItem.CsmGridSelectedRowIndex, 3);
                aParam[1] = grdSearchItem.CsmGridGetCell(grdSearchItem.CsmGridSelectedRowIndex, 9);
                aParam[2] = grdSearchItem.CsmGridGetCell(grdSearchItem.CsmGridSelectedRowIndex, 3);
                aParam[3] = grdSearchItem.CsmGridGetCell(grdSearchItem.CsmGridSelectedRowIndex, 8);
                aParam[4] = sSaleAmt;
                aParam[5] = grdSearchItem.CsmGridGetCell(grdSearchItem.CsmGridSelectedRowIndex, 14);
                aParam[6] = grdSearchItem.CsmGridGetCell(grdSearchItem.CsmGridSelectedRowIndex, 13);
                aParam[7] = "";
                aParam[8] = "";
                aParam[9] = "";
                aParam[10] = "";
                aParam[11] = "";
                aParam[12] = "";
                aParam[13] = grdSearchItem.CsmGridGetCell(grdSearchItem.CsmGridSelectedRowIndex, 4);
                aParam[14] = "";
                aParam[15] = "";
                aParam[16] = grdSearchItem.CsmGridGetCell(grdSearchItem.CsmGridSelectedRowIndex, 17);
                aParam[17] = grdSearchItem.CsmGridGetCell(grdSearchItem.CsmGridSelectedRowIndex, 18);
                aParam[18] = "";
                aParam[19] = "";
                aParam[20] = ItemConst.PAY_APP_DIV.PDA_APPR;
                
      
                sRet = m_cCreditCard.SetMenualPayment(aParam);
                if (sRet == UserCom.RST_OK)
                {
                    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 sRet;
            }
            return sRet;
        }


        #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;
                    case PosConst.OPOS_DEVICE.SCANNER:
                        this.Invoke(new EventHandler(OnScannerEvent));
                        break;
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        /// <summary>
        /// MSR Event
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        private void OnMSREvent(object source, EventArgs e)
        {

        }
        /// <summary>
        /// 스캐너 이벤트 처리
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        private void OnScannerEvent(object source, EventArgs e)
        {
            string sScanData = m_cDevStatus.Scanner.DataLabel;

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

        }

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

        /// <summary>
        /// IC 카드 정보 입력 처리
        /// </summary>
        /// <returns></returns>
        private bool GetIcCardData()
        {
            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;
        }
        #endregion

        

    }

}
