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 frmCustSearch : Form
    {

        #region 변수 선언

        private SManager sManager = new SManager();                                 // 이 객체를 통해 업무 Service 호출
        private StateServer StateObject = (StateServer)StateServer.GetInstance();   // StateObject : StateServer Object (객체)
        private PosStatus m_cPosStatus = new PosStatus();                           // 기본정보 참조
        private TranStatus m_cTrnStatus = new TranStatus();                         // 거래정보 참조        
        private DeviceStatus m_cDevStatus = new DeviceStatus();                     // 디바이스 관리

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

        private string m_sSearchType;
        public string SearchType { set { m_sSearchType = value; } get { return m_sSearchType; } }
        private string m_sSearchCD;
        public string SearchCD { set { m_sSearchCD = value; } get { return m_sSearchCD; } }
        private string m_sPosMenuKeyOut;
        public string PosMenuKeyOut { set { m_sPosMenuKeyOut = value; } get { return m_sPosMenuKeyOut; } }
        // 기타입출금 고객명 저장
        private string m_sPosMenuKeyOut2;
        public string PosMenuKeyOut2 { set { m_sPosMenuKeyOut2 = value; } get { return m_sPosMenuKeyOut2; } }

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

        private string m_sPosMenuKey;                                               // 입력코드
        /// <summary>
        /// 구분
        /// </summary>
        public string SetPosMenuKey { set { this.m_sPosMenuKey = value; } get { return m_sPosMenuKey; } }         

        /// <summary>
        /// 입력구분
        /// </summary>
        private string m_sInPutType = "";
        /// <summary>
        /// 입력데이터
        /// </summary>
        private string m_sInPutData = "";
        /// <summary>
        /// 카드데이터
        /// </summary>
        private string m_sInEncData = "";
        /// <summary>
        /// 결제구분
        /// </summary>
        private string m_sPay_DC_Grp_Type = "";
        /// <summary>
        /// 결제상세구분
        /// </summary>
        private string m_sPay_DC_CD = "";
        /// <summary>
        /// 조회구분
        /// </summary>
        private string m_InqType = "";
        #endregion 변수 선언

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

        private void frmCustSearch_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 frmCustSearch_Activated(object sender, EventArgs e)
        { 
        }

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

        private void frmCustSearch_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);
                if (m_sSearchCD != "ZZZZ")
                {
                    //this.Location = new Point(216, 173);
                    FormManager.MovePopUpForm(this, true, m_cPosStatus.Sale.ScreenSizeUser);
                }
                else
                {
                    FormManager.MovePopUpForm(this, false, m_cPosStatus.Sale.ScreenSizeUser);
                    //this.StartPosition = FormStartPosition.CenterParent;
                }

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

                //버튼이미지 적용
                btnAllPgUp.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_14X9_UP2_BASIC);
                btnAllPgUp.ImageAlign = ContentAlignment.MiddleCenter;
                btnAllPgUp.BorderStyle = BorderStyle.None;
                btnAllPgDw.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_14X9_DOWN2_BASIC);
                btnAllPgDw.ImageAlign = ContentAlignment.MiddleCenter;
                btnAllPgDw.BorderStyle = BorderStyle.None;
                btnAllUp.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_14X9_UP1_BASIC);
                btnAllUp.ImageAlign = ContentAlignment.MiddleCenter;
                btnAllUp.BorderStyle = BorderStyle.None;
                btnAllDw.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_14X9_DOWN1_BASIC);
                btnAllDw.ImageAlign = ContentAlignment.MiddleCenter;
                btnAllDw.BorderStyle = BorderStyle.None;

                if (btnAllPgUp.Image != null) btnAllPgUp.Text = "";
                if (btnAllPgDw.Image != null) btnAllPgDw.Text = "";
                if (btnAllUp.Image != null) btnAllUp.Text = "";
                if (btnAllDw.Image != null) btnAllDw.Text = "";

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

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

                // 타이틀
                if (m_sPosMenuKey == PosKey.MENU_KEY.PREPAID_CARDS) lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0305);

                m_sPay_DC_Grp_Type = ItemConst.TR_ITEM_ID.PPCARD_ITEM;
                m_sPay_DC_CD = ItemConst.TR_ITEM_ID.PPCARD.PP_CARD;

                if (m_sSearchType == ItemConst.IRT_INQ_TYPE.SALEONCREDIT_CUSTINQ)
                {
                    lblCustID.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0663);                    // 고객정보
                }
                else
                {
                    lblCustID.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0369);                        // 검색코드
                }

                btnSearch.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0004);                        // 조회
                btnEnter.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0144);                         // 선택
                
                m_sInPutType = "";                                                                                  // 입력구분
                m_sInPutData = "";                                                                                  // 입력데이터
                m_sInEncData = "";                                                                                  // 카드데이터
                
                m_sPosMenuKeyOut = "";

                bNotDoubleClik = false;
                dgvData.Rows.Clear();

                if (m_sSearchCD != "ZZZZ")
                {
                    DataGridSetting(0);                                                                                 // 그리드 초기화

                    txtCustID.Text = m_sSearchCD;                                                                       // 고객번호
                    txtCustID.Select();
                    txtCustID.SelectText();
                }
                else
                {
                    txtCustID.Text = "";

                    // 전체 조회일 경우에는 총 외상 잔액을 보여준다.
                    DataGridSetting(1);                                                                                 // 그리드 초기화
                }

                if (txtCustID.Text.Length > 0 || m_sSearchCD == "ZZZZ")
                    btnProc_Click(btnSearch, null);
            }
            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 dgvCustInfo_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                btnProc_Click(btnEnter, null);
            }
            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 btnProc_Click(object sender, EventArgs e)
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                if (bNotDoubleClik) return;
                bNotDoubleClik = true;

                if ((UI.CsmButton)sender == btnAllUp)                               // 상단 그리드 Up
                {
                    if (dgvData.Rows.Count == 0) goto Skip_Next;

                    if (dgvData.CurrentRow.Index > 0)
                    {
                        for (int iLoop = dgvData.CurrentRow.Index - 1; iLoop >= 0; iLoop--)
                        {
                            if (dgvData.Rows[iLoop].Visible == false) continue;

                            dgvData.Rows[iLoop].Selected = true;
                            dgvData.Rows[iLoop].Cells[dgvData.CurrentCell.ColumnIndex].Selected = true;
                            break;
                        }
                    }
                }
                else if ((UI.CsmButton)sender == btnAllDw)                          // 상단 그리드 Down
                {
                    if (dgvData.Rows.Count == 0) goto Skip_Next;

                    if (dgvData.CurrentRow.Index < dgvData.Rows.Count - 1)
                    {
                        for (int iLoop = dgvData.CurrentRow.Index + 1; iLoop <= dgvData.Rows.Count - 1; iLoop++)
                        {
                            if (dgvData.Rows[iLoop].Visible == false) continue;

                            dgvData.Rows[iLoop].Selected = true;
                            dgvData.Rows[iLoop].Cells[dgvData.CurrentCell.ColumnIndex].Selected = true;
                            break;
                        }
                    }
                }
                else if ((UI.CsmButton)sender == btnAllPgUp)                               // 상단 그리드 PgUp
                {
                    if (dgvData.Rows.Count == 0
                        || dgvData.CurrentRow.Index <= 0) goto Skip_Next;

                    int nPageRow = 5;
                    int iLoop = dgvData.CurrentRow.Index - nPageRow;
                    if (iLoop <= 0) iLoop = 0;

                    dgvData.Rows[iLoop].Selected = true;
                    dgvData.Rows[iLoop].Cells[dgvData.CurrentCell.ColumnIndex].Selected = true;
                }
                else if ((UI.CsmButton)sender == btnAllPgDw)                          // 상단 그리드 PgDown
                {
                    if (dgvData.Rows.Count == 0) goto Skip_Next;

                    int nPageRow = 5;
                    int iLoop = dgvData.CurrentRow.Index + nPageRow;

                    if (iLoop >= dgvData.Rows.Count - 1) iLoop = dgvData.Rows.Count - 1;

                    if (iLoop != dgvData.CurrentRow.Index)
                    {
                        dgvData.Rows[iLoop].Selected = true;
                        dgvData.Rows[iLoop].Cells[dgvData.CurrentCell.ColumnIndex].Selected = true;
                    }
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnSearch)                     // 조회
                {
                    sRet = SearchTxtInPut();
                    if (sRet != UserCom.RST_OK) goto Skip_Next;
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnEnter)                 // 선택
                {                    
                    // 선택
                    sRet = CompleteTxtInPut();
                    if (sRet != UserCom.RST_OK) goto Skip_Next;

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                    goto Skip_Next;
                }
                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);
                bNotDoubleClik = false;
            }
            Skip_Next:
            bNotDoubleClik = false;
        }

        /// <summary>
        /// 닫기
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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

        #region 텍스트박스 키 입력 이벤트 처리 
        /// <summary>
        /// 텍스트박스 키 입력 이벤트 처리
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="sFuncValue"></param>
        private void txtEditBox_EditBoxKeyDownEvent(object sender, string sFuncValue)
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                if (sFuncValue == PosKey.MENU_KEY.ENTER)
                {
                    if (((Cosmos.UI.CsmPosEditBox)sender) == txtCustID)
                    {
                        //DataGridSetting(1);
                        sRet = SearchTxtInPut();
                    }
                    else if (((DataGridView)sender) == dgvData)
                    {
                        // 선택
                        sRet = CompleteTxtInPut();
                        if (sRet != UserCom.RST_OK) return;

                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }

                }
                else if (sFuncValue == PosKey.MENU_KEY.CLEAR)
                {
                    if (((Cosmos.UI.CsmPosEditBox)sender) == txtCustID)
                    {
                        txtCustID.Value = "";
                    }
                }
                else if (sFuncValue == PosKey.MENU_KEY.ESC_PREVIOUS)
                { 
                    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 txtCardNo_EditBoxTextChangedEvnet(object sender, EventArgs e)
        {
            m_sInPutType = "";                                                                                  // 입력구분
            m_sInPutData = "";                                                                                  // 입력데이터
            m_sInEncData = "";                                                                                  // 카드데이터

        }

        #endregion

        #region 텍스트박스 입력 유효성 체크
        /// <summary>
        /// 텍스트박스 입력 유효성 체크
        /// </summary>
        /// <param name="sender"></param>
        /// <returns></returns>
        private bool CheckTxtInPut(object sender, bool bSearchMode)
        {
            try
            {
                // 특정 문자값 제거
                try
                {
                    if (m_cDevStatus.Msr.STX != "" && txtCustID.Value.StartsWith(m_cDevStatus.Msr.STX)) txtCustID.Value = txtCustID.Value.Substring(1);

                    int iLastEtx = txtCustID.Value.LastIndexOf(m_cDevStatus.Msr.ETX);
                    if (m_cDevStatus.Msr.ETX != "" && iLastEtx > 0) txtCustID.Value = CmUtil.MidH(txtCustID.Value, 0, iLastEtx);
                }
                catch { }

                if (m_sSearchCD != "ZZZZ")
                {
                    //안호성차장 요청 으로 주석처리 20170223
                    //// 코드 체크
                    //if (txtCustID.Text.Length <= 0 && bSearchMode != true)
                    //{
                    //    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0258);
                    //    return false;
                    //}
                }

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

        #region 텍스트박스 입력 완료 처리
        /// <summary>
        /// 결제 처리
        /// </summary>
        /// <param name="nFlowMode"></param>
        /// <returns></returns>
        private string CompleteTxtInPut()
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                // 승인
                if (dgvData.RowCount <= 0) return sRet;

                DataGridViewRow dView = this.dgvData.SelectedRows[0];

                // 고객 조회일 경우에는 어떤 사람을 선택했는지 확인 알림창을 띄워준다.
                if (m_sSearchType == ItemConst.IRT_INQ_TYPE.SALEONCREDIT_CUSTINQ)
                {
                    if (WinManager.QuestionMessage(string.Format(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0634), dView.Cells[1].Value.ToString())) == false)
                    {
                        return sRet;
                    }
                }

                m_sPosMenuKeyOut = dView.Cells[0].Value.ToString();
                m_sPosMenuKeyOut2 = dView.Cells[1].Value.ToString();

                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);
                sRet = UserCom.RST_ERR;
            }
            return sRet;
        }
        
        /// <summary>
        /// 조회 처리
        /// </summary>
        /// <returns></returns>
        private string SearchTxtInPut()
        {
            string sRet = UserCom.RST_ERR;
            string[] saRecvdData = null;

            try
            {
                // 조회
                dgvData.Rows.Clear();

                if (CheckTxtInPut(null, false) != true) return sRet;

                sRet = m_cPrepaidCard.SearchPayment(new string[] { m_sSearchType, m_sPay_DC_Grp_Type, m_sPay_DC_CD, m_InqType, txtCustID.Text, m_sInPutType }, ref saRecvdData);
                if (sRet != UserCom.RST_OK) return sRet;

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

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

                    if (aRecvData.Length > 0)
                    {
                        int iRow = dgvData.Rows.Add();

                        dgvData.Rows[iRow].Visible = true;

                        dgvData.Rows[iRow].Cells[0].ReadOnly = false;
                        dgvData.Rows[iRow].DefaultCellStyle.ForeColor = Color.Black;
                        dgvData.Rows[iRow].DefaultCellStyle.SelectionForeColor = Color.Black;

                        dgvData.Rows[iRow].HeaderCell.Value = (iRow + 1).ToString();

                        //if (txtCustID.Text == "")
                        //{ 
                            // 전체 조회일 경우 총 외상 잔액을 보여준다.
                            dgvData.Rows[iRow].Cells[0].Value = aRecvData[0].ToString();                                                            // 고객번호
                            dgvData.Rows[iRow].Cells[1].Value = aRecvData[3].ToString();                                                            // 고객명
                            dgvData.Rows[iRow].Cells[2].Value = aRecvData[2].ToString();                                                            // 전화번호
                            if (aRecvData.Length >= 4)
                                dgvData.Rows[iRow].Cells[3].Value = m_cPosStatus.Global.NumericTOCurrency(m_cDataService.DoubleParse(aRecvData[4].ToString())); // 잔액
                        //}
                        //else
                        //{
                        //    dgvData.Rows[iRow].Cells[0].Value = aRecvData[0].ToString();                                                            // 고객번호
                        //    dgvData.Rows[iRow].Cells[1].Value = aRecvData[3].ToString();                                                            // 고객명
                        //    dgvData.Rows[iRow].Cells[2].Value = aRecvData[2].ToString();                                                            // 전화번호
                        //}
                    }
                }
                dgvData.Select();

                return sRet;
            }
            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 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
            {
                if (sScanData.Length > 0 && m_sInPutData == "")
                {
                    m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_BARCODE;
                    m_sInPutData = sScanData;

                    txtCustID.Text = m_sInPutData;

                    ///                if (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL) SearchTxtInPut();
                }
            }
            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

        #region 그리드 설정 
        private double DataGridSetting(int iWorkMode)
        {
            int[] arColumnsWidth = { };
            int[] arColumnsAlignment = { };

            try
            {
                // 초기화 
                dgvData.Rows.Clear();
                dgvData.Columns.Clear(); 

                dgvData.AllowUserToAddRows = false;
                dgvData.EnableHeadersVisualStyles = false;
                dgvData.RowsDefaultCellStyle.BackColor = Color.White;
                dgvData.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(249, 249, 249);
                dgvData.Font = this.Font;
                dgvData.DefaultCellStyle.Font = new Font(m_cPosStatus.Base.FONT, 9);
                //dgvData.DefaultCellStyle.SelectionBackColor = Color.Transparent;

                dgvData.Font = new Font(m_cPosStatus.Base.FONT, 9);
                dgvData.RowHeadersDefaultCellStyle.Font = new Font(m_cPosStatus.Base.FONT, 10);

                dgvData.Columns.Add("CUST_ID", MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0306));
                dgvData.Columns.Add("CUST_NM", MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0278));
                dgvData.Columns.Add("CUST_TEL", MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0279));
                dgvData.Columns.Add("CUST_AMT", MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0623));

                if (iWorkMode == 1)
                {
                    arColumnsWidth = new int[] { 90, 90, 110, 90 };
                    arColumnsAlignment = new int[] { 0, 0, 0, 2 };

                    //dgvData.Columns.Add("CUST_NO", MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0306));
                    //dgvData.Columns.Add("CUST_NM", MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0278));
                    //dgvData.Columns.Add("CUST_TEL", MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0279));
                    

                    // 타이틀 설정
                    // 고객 전체 조회일 경우 외상 잔액을 보여준다.
                    //dgvData.Columns[0].HeaderText = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0306);
                    //dgvData.Columns[1].HeaderText = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0278);
                    //dgvData.Columns[2].HeaderText = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0279);
                    //dgvData.Columns[3].HeaderText = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0289);
                    //dgvData.Refresh();
                }
                else
                {
//                    arColumnsWidth = new int[] { 110, 150, 120, 0 };
                    arColumnsWidth = new int[] { 110, 110, 80, 80 };
                    arColumnsAlignment = new int[] { 0, 0, 0, 2 };

                    // 타이틀 설정
                    //dgvData.Columns[0].HeaderText = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0306);
                    //dgvData.Columns[1].HeaderText = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0278);
                    //dgvData.Columns[2].HeaderText = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0279);
                    //dgvData.Refresh();
                }

                dgvData.ColumnHeadersHeight = 30;
                dgvData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
                dgvData.RowHeadersVisible = false;
                dgvData.AllowUserToAddRows = false;
                dgvData.Font = new Font(m_cPosStatus.Base.FONT, 9);

                for (int nLoop = 0; nLoop < dgvData.ColumnCount; nLoop++)
                {
                    dgvData.Columns[nLoop].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                    dgvData.Columns[nLoop].Width = arColumnsWidth[nLoop];
                    dgvData.Columns[nLoop].Resizable = DataGridViewTriState.True;
                    dgvData.Columns[nLoop].ReadOnly = true;

                    switch (arColumnsAlignment[nLoop])
                    {
                        case 0:
                            dgvData.Columns[nLoop].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
                            break;
                        case 1:
                            dgvData.Columns[nLoop].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                            break;
                        default:
                            dgvData.Columns[nLoop].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                            break;
                    }

                    dgvData.Columns[nLoop].SortMode = DataGridViewColumnSortMode.NotSortable;
                }

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

        private void dgvData_KeyPress(object sender, KeyPressEventArgs e)
        {

        }

        private void dgvData_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.Enter)
                    btnProc_Click(btnEnter, null);
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }

        }



    }

}
