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

/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 테스트 모드
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Win
{
    public partial class frmTestMode : 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 PosOLEDevice.DelegateOlePos delegatePos;

        private IDataProcessUs m_cDataSrv = null;
        private IDataCommonUs m_cDataCommon = null;
        private IDataServiceUs m_cTestMode = null;                                  // 테스트모드 서비스

        private string m_sTestEntryId; 
        /// <summary>
        /// 시험항목 코드
        /// </summary>
        public string TestEntryId { get { return this.m_sTestEntryId; } set { this.m_sTestEntryId = value; } }
        private string m_sTestEntryNm;
        /// <summary>
        /// 시험항목 명
        /// </summary>
        public string TestEntryNm { get { return this.m_sTestEntryNm; } set { this.m_sTestEntryNm = value; } }
        private int m_nTestErrPrmt_Cnt;
        /// <summary>
        /// 시험 오류허용횟수
        /// </summary>
        public int TestErrPrmtCnt { get { return this.m_nTestErrPrmt_Cnt; } set { this.m_nTestErrPrmt_Cnt = value; } }
        private int m_nTestLimitTime;
        /// <summary>
        /// 시험 응시제한시간
        /// </summary>
        public int TestLimitTime { get { return this.m_nTestLimitTime; } set { this.m_nTestLimitTime = value; } }
        private string m_sTestEntryExpln;
        /// <summary>
        /// 시험항목 설명
        /// </summary>
        public string TestEntryExpln { get { return this.m_sTestEntryExpln; } set { this.m_sTestEntryExpln = value; } }

        /// <summary>
        /// 시험모드 상세정보
        /// </summary>
        private DataTable m_dtTestModeDtlInfo;
        /// <summary>
        /// 시험모드 상세위치
        /// </summary>
        private DataTable m_dtTestModeDtlLoc;

        /// <summary>
        /// 시험 오류횟수
        /// </summary>
        private int m_nTestErrCnt = 0;
        /// <summary>
        /// 시험 상세순번
        /// </summary>
        private int m_nTestDtlSeq = 0;
        /// <summary>
        /// 시험 화면표시 시간
        /// </summary>
        private int m_nScrnDispHour = 0;
        /// <summary>
        /// 시험 시작 시간
        /// </summary>
        private DateTime m_tmrTestStartTime;

        #endregion 변수 선언

        #region 생성자 & 소멸자 & 폼초기화
        public frmTestMode()
        {
            InitializeComponent();

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

            m_cPosStatus = (PosStatus)StateObject.POS;     
            m_cTrnStatus = (TranStatus)StateObject.TRAN;  
            m_cDevStatus = (DeviceStatus)StateObject.DEVICE;

            m_cDataSrv = (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_cTestMode = (IDataServiceUs)sManager.InitServiceInstance(ServiceLists.BSV_ADMIN.DLL, ServiceLists.BSV_ADMIN.TEST_MODE);  

            delegatePos = new PosOLEDevice.DelegateOlePos(OnDeviceEvent);
        }

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

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

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

        private void frmTestMode_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 + "()", "");
        }

        /// <summary>
        /// 폼 컨트롤 초기화
        /// </summary>
        private void InitControl()
        {
            try
            {
                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);

                this.Location = new Point(0, 0); this.Size = new Size(1024, 768);
                picBack.Location = new Point(0, 0); picBack.Size = new Size(1024, 768);

                lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0243);
                lblStep.Text = "";
                lblError.Text = "";

                padInPut.ClearBtnText = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0817);
                padInPut.SearchBtnText = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1018);

                btnExpln.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0249); // 시험확인
                btnPrev.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0250);  // 이전
                btnNext.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0251);  // 다음
                btnExit.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0008);  // 종료
                
                txtInPut.Text = "";

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

        /// <summary>
        /// 시험모드 상세 데이터 조회
        /// </summary>
        private void LoadMaster()
        {
            try
            {
                m_nTestErrCnt = 0;
                m_nTestDtlSeq = 0;
                m_tmrTestStartTime = DateTime.Now;

                m_dtTestModeDtlInfo = (DataTable)m_cTestMode.GetData(new string[] { PosMst.MST_TEST_MODE_DTL_INFO.TABLE_NAME, m_sTestEntryId });
                if (m_dtTestModeDtlInfo == null || m_dtTestModeDtlInfo.Rows.Count == 0)
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0163);    //시험 상세 정보가 없습니다.
                    return;
                }
                
                DisplayTestMode(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);
            }
        }
        #endregion

        /// <summary>
        /// 시험모드 상세 데이터 화면표시
        /// </summary>
        private void DisplayTestMode(bool m_bDtlSeqInc)
        {
            try
            {
                if (m_dtTestModeDtlInfo == null || m_dtTestModeDtlInfo.Rows.Count == 0) return;
                
                if ( m_bDtlSeqInc == true) m_nTestDtlSeq++;

                if (m_nTestDtlSeq >= m_dtTestModeDtlInfo.Rows.Count)
                {
                    // 시험종료
                    if (m_nTestErrCnt > m_nTestErrPrmt_Cnt)    
                    {
                        // 오류회수 초과
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0164);        // 오류회수 초과로 시험을 통과하지 못하였습니다.
                        
                        this.DialogResult = DialogResult.Cancel;
                        this.Close();
                        return;
                    }
                    else if ( m_nTestLimitTime > 0 )
                    {
                        DateTime tmrEndTime = m_tmrTestStartTime.AddMinutes(m_nTestLimitTime);
                        if (tmrEndTime < DateTime.Now)
                        {
                            WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0218);    // 제한시간 초과로 시험을 통과하지 못하였습니다.

                            this.DialogResult = DialogResult.Cancel;
                            this.Close();
                            return;
                        }
                    }

                    WinManager.ConfirmMessage(POS_MESSAGE.ERROR.MSG_0165);          // 시험을 통과 하였습니다.
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                    return;
                }

                DataRow drInfo = m_dtTestModeDtlInfo.Rows[m_nTestDtlSeq];

                string sDtlSeq = CmUtil.GetDataRowStr(drInfo, PosMst.MST_TEST_MODE_DTL_INFO.DATA.DTL_SEQ);

                string sPosScrnType = CmUtil.GetDataRowStr(drInfo, PosMst.MST_TEST_MODE_DTL_INFO.DATA.POS_SCRN_TYPE);
                if (sPosScrnType != "0") sPosScrnType = m_cPosStatus.Base.DesignType;

                m_dtTestModeDtlLoc = (DataTable)m_cTestMode.GetData(new string[] { PosMst.MST_TEST_MODE_DTL_LOC.TABLE_NAME, m_sTestEntryId, sDtlSeq, sPosScrnType });
                if (m_dtTestModeDtlLoc == null || m_dtTestModeDtlLoc.Rows.Count == 0)
                {
                    padInPut.Visible = false;
                    txtInPut.Visible = false;
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0167);    //시험 상세 위치가 없습니다.
                    return;
                }
                DataRow drLoc = m_dtTestModeDtlLoc.Rows[0];

                lblExpln.Text = "▶ " + CmUtil.GetDataRowStr(drInfo, PosMst.MST_TEST_MODE_DTL_INFO.DATA.DTL_SEQ_EXPLN);

                string sImageFileName = BaseCom.NxCDPPath + PosConst.MST_IMG_PATH.TEST_MODE + CmUtil.GetDataRowStr(drLoc, PosMst.MST_TEST_MODE_DTL_LOC.DATA.IMG_FILE_NM);
                picBack.Image = CmUtil.LoadImage(sImageFileName);
                if (picBack.Image == null)
                {
                    padInPut.Visible = false;
                    txtInPut.Visible = false;
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0166);    //시험 상세 이미지가 없습니다.
                    return;
                }
                // 시험화면 표시 시간
                m_nScrnDispHour = CmUtil.GetDataRowInt(drInfo, PosMst.MST_TEST_MODE_DTL_INFO.DATA.SCRN_DISP_HOUR);
                if (m_nScrnDispHour > 0)
                {
                    padInPut.Visible = false;
                    txtInPut.Visible = false;

                    tmrScrnDispHour.Interval = m_nScrnDispHour * 1000;
                    tmrScrnDispHour.Enabled = true;
                    return;
                }

                // 숫자패드 사용유형
                string sNumPadUseType = CmUtil.GetDataRowStr(drInfo, PosMst.MST_TEST_MODE_DTL_INFO.DATA.NUM_PAD_USE_TYPE);
                if ( CmUtil.IntParse(sNumPadUseType) == 0)
                {
                    padInPut.Visible = false;
                }
                else
                {
                    if (CmUtil.IntParse(sNumPadUseType) == 1)       
                    {
                        padInPut.Use4By4 = false;
                        padInPut.DesignType = UI.DesignType.Design_A;
                    }
                    else if (CmUtil.IntParse(sNumPadUseType) == 2)     
                    {
                        padInPut.Use4By4 = false;
                        padInPut.DesignType = UI.DesignType.Design_B;
                    }
                    else if (CmUtil.IntParse(sNumPadUseType) == 3)    
                    {
                        padInPut.Use4By4 = false;
                        padInPut.DesignType = UI.DesignType.Design_C;
                    }
                    else 
                    {
                        padInPut.Use4By4 = true;
                        padInPut.DesignType = UI.DesignType.POPUP;
                    }
                    padInPut.Location = new Point(CmUtil.GetDataRowInt(drLoc, PosMst.MST_TEST_MODE_DTL_LOC.DATA.NUM_PAD_START_LOC_X), CmUtil.GetDataRowInt(drLoc, PosMst.MST_TEST_MODE_DTL_LOC.DATA.NUM_PAD_START_LOC_Y));
                    padInPut.Visible = true;
                }

                // 입력박스 사용유형
                string sInputBoxUseYn = CmUtil.GetDataRowStr(drInfo, PosMst.MST_TEST_MODE_DTL_INFO.DATA.INPUT_BOX_USE_YN);
                if (CmUtil.IntParse(sInputBoxUseYn) == 0)
                {
                    txtInPut.Visible = false;
                }
                else
                {
                    txtInPut.Text = "";
                    txtInPut.Location = new Point(CmUtil.GetDataRowInt(drLoc, PosMst.MST_TEST_MODE_DTL_LOC.DATA.INPUT_BOX_START_LOC_X), CmUtil.GetDataRowInt(drLoc, PosMst.MST_TEST_MODE_DTL_LOC.DATA.INPUT_BOX_START_LOC_Y));
                    txtInPut.Size = new Size(CmUtil.GetDataRowInt(drLoc, PosMst.MST_TEST_MODE_DTL_LOC.DATA.INPUT_BOX_FNSH_LOC_X) - CmUtil.GetDataRowInt(drLoc, PosMst.MST_TEST_MODE_DTL_LOC.DATA.INPUT_BOX_START_LOC_X),
                                             CmUtil.GetDataRowInt(drLoc, PosMst.MST_TEST_MODE_DTL_LOC.DATA.INPUT_BOX_FNSH_LOC_Y) - CmUtil.GetDataRowInt(drLoc, PosMst.MST_TEST_MODE_DTL_LOC.DATA.INPUT_BOX_START_LOC_Y));
                    txtInPut.Visible = true;
                }

                lblStep.Text = "▶ STEP : " + string.Format("{0:D2} / {1:D2}", m_nTestDtlSeq, m_dtTestModeDtlInfo.Rows.Count);
                lblError.Text = "▶ ERROR : " + string.Format("{0:D2} / {1:D2}", m_nTestErrCnt, m_nTestErrPrmt_Cnt);
            }
            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>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnProc_Click(object sender, EventArgs e)
        {
            try
            {
                if (((Cosmos.UI.CsmButton)sender) == btnExpln)              // 시험확인
                {
                    if (m_sTestEntryExpln == "")
                        WinManager.ConfirmMessage(POS_MESSAGE.ERROR.MSG_0163, m_sTestEntryNm);
                    else
                        WinManager.ConfirmMessage(m_sTestEntryExpln, m_sTestEntryNm);
                }
                if (((Cosmos.UI.CsmButton)sender) == btnPrev)               // 이전
                {
                    if (m_nTestDtlSeq > 0) m_nTestDtlSeq--;
                    DisplayTestMode(false);
                }
                if (((Cosmos.UI.CsmButton)sender) == btnNext)               // 다음
                {
                    if (WinManager.QuestionMessage(POS_MESSAGE.ERROR.MSG_0168) == true)     // 다음화면 진행시 시험을 통과 할수 없습니다. 그래도 진행 하시겠습니까?
                    {
                        m_nTestErrCnt = m_nTestErrPrmt_Cnt + 1;
                        DisplayTestMode(true);
                    }
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnExit)          // 종료
                {
                    this.DialogResult = DialogResult.Cancel;
                    this.Close();
                }
                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);
            }
        }
        #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)
                {
                    CheckTestMode("INPUT", txtInPut.Value);
                }
                else if (sFuncValue == PosKey.MENU_KEY.CLEAR)
                {
                    if (((Cosmos.UI.CsmPosEditBox)sender).ReadOnly == false) ((Cosmos.UI.CsmPosEditBox)sender).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);
            }
        }

        /// <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 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)
        {
            try
            {                
                string sMsrData = m_cDevStatus.Msr.Track2Data;
                CheckTestMode("MSR", sMsrData);
                
            }
            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="source"></param>
        /// <param name="e"></param>
        private void OnScannerEvent(object source, EventArgs e)
        {
            try
            {
                string sScanData = m_cDevStatus.Scanner.DataLabel;
                CheckTestMode("SCAN", sScanData);
            }
            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

        /// <summary>
        /// 화면 표시시간 경과 이벤트 처리
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tmrScrnDispHour_Tick(object sender, EventArgs e)
        {
            try
            {
                tmrScrnDispHour.Enabled = false;

                DisplayTestMode(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);
            }
        }
        
        /// <summary>
        /// 입력 정홤성 체크
        /// </summary>
        /// <param name="sInType"></param>
        /// <param name="sInData"></param>
        private void CheckTestMode(string sInType, string sInData)
        {
            try
            {
                DataRow drInfo = m_dtTestModeDtlInfo.Rows[m_nTestDtlSeq];
                DataRow drLoc = m_dtTestModeDtlLoc.Rows[0];

                // 시험화면 표시 시간
                m_nScrnDispHour = CmUtil.GetDataRowInt(drInfo, PosMst.MST_TEST_MODE_DTL_INFO.DATA.SCRN_DISP_HOUR);
                if (m_nScrnDispHour > 0) return;

                if ( sInType == "INPUT")
                {
                    // 입력박스 입력
                    string sInputBoxUseYn = CmUtil.GetDataRowStr(drInfo, PosMst.MST_TEST_MODE_DTL_INFO.DATA.INPUT_BOX_USE_YN);
                    if (CmUtil.IntParse(sInputBoxUseYn) == 0) return;

                    int nMinLen = CmUtil.GetDataRowInt(drInfo, PosMst.MST_TEST_MODE_DTL_INFO.DATA.INPUT_BOX_DATA_MIN_LEN);
                    if ( nMinLen > 0 && sInData.Length < nMinLen)
                    {
                        m_nTestErrCnt++;
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0169);    // 입력박스 테이터를 확인 하세요.
                        return;
                    }
                    int nMaxLen = CmUtil.GetDataRowInt(drInfo, PosMst.MST_TEST_MODE_DTL_INFO.DATA.INPUT_BOX_DATA_MAX_LEN);
                    if (nMaxLen > 0 && sInData.Length > nMaxLen)
                    {
                        m_nTestErrCnt++;
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0169);    // 입력박스 테이터를 확인 하세요.
                        return;
                    }
                    string sCheckPrefix = CmUtil.GetDataRowStr(drInfo, PosMst.MST_TEST_MODE_DTL_INFO.DATA.INPUT_BOX_CHECK_PREFIX);
                    if (sCheckPrefix.Length > 0 && sInData.StartsWith(sCheckPrefix) == false)
                    {
                        m_nTestErrCnt++;
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0169);    // 입력박스 테이터를 확인 하세요.
                        return;
                    }
                }

                if ( sInType == "SCAN" || sInType == "MSR")
                {
                    // 장치사용 유형(00:미사용, 01:SCAN, 02:MSR)
                    string sDeviceUseType = CmUtil.GetDataRowStr(drInfo, PosMst.MST_TEST_MODE_DTL_INFO.DATA.DEVICE_USE_TYPE);
                    if (sInType == "SCAN" && sDeviceUseType != "01")
                    {
                        m_nTestErrCnt++;
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0170);    // 입력장치 유형을 확인 하세요.
                        return;
                    }
                    if (sInType == "MSR" && sDeviceUseType != "02")
                    {
                        m_nTestErrCnt++;
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0170);    // 입력장치 유형을 확인 하세요.
                        return;
                    }

                    int nMinLen = CmUtil.GetDataRowInt(drInfo, PosMst.MST_TEST_MODE_DTL_INFO.DATA.DEVICE_DATA_MIN_LEN);
                    if (nMinLen > 0 && sInData.Length < nMinLen)
                    {
                        m_nTestErrCnt++;
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0171);    // 입력장치 테이터를 확인 하세요.
                        return;
                    }
                    int nMaxLen = CmUtil.GetDataRowInt(drInfo, PosMst.MST_TEST_MODE_DTL_INFO.DATA.DEVICE_DATA_MAX_LEN);
                    if (nMaxLen > 0 && sInData.Length > nMaxLen)
                    {
                        m_nTestErrCnt++;
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0171);    // 입력장치 테이터를 확인 하세요.
                        return;
                    }
                    string sCheckPrefix = CmUtil.GetDataRowStr(drInfo, PosMst.MST_TEST_MODE_DTL_INFO.DATA.DEVICE_PREFIX_CHECK);
                    if (sCheckPrefix.Length > 0 && sInData.StartsWith(sCheckPrefix) == false)
                    {
                        m_nTestErrCnt++;
                        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0171);    // 입력장치 테이터를 확인 하세요.
                        return;
                    }
                }

                DisplayTestMode(true);
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                   System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            finally
            {
                lblError.Text = "▶ ERROR : " + string.Format("{0:D2} / {1:D2}", m_nTestErrCnt, m_nTestErrPrmt_Cnt);
            }
        }
        
        /// <summary>
        /// 마우스 입력 체크
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void picBack_MouseClick(object sender, MouseEventArgs e)
        {
            try
            {
                DataRow drInfo = m_dtTestModeDtlInfo.Rows[m_nTestDtlSeq];
                DataRow drLoc = m_dtTestModeDtlLoc.Rows[0];

                // 시험화면 표시 시간
                m_nScrnDispHour = CmUtil.GetDataRowInt(drInfo, PosMst.MST_TEST_MODE_DTL_INFO.DATA.SCRN_DISP_HOUR);
                if (m_nScrnDispHour > 0) return;

                // 터치사용 여부
                string sTouchUseYn = CmUtil.GetDataRowStr(drInfo, PosMst.MST_TEST_MODE_DTL_INFO.DATA.TOUCH_USE_YN);
                if (CmUtil.IntParse(sTouchUseYn) == 0) return;

                int nX = e.X;
                int nY = e.Y;

                if (nX < CmUtil.GetDataRowInt(drLoc, PosMst.MST_TEST_MODE_DTL_LOC.DATA.TOUCH_START_LOC_X) || nX > CmUtil.GetDataRowInt(drLoc, PosMst.MST_TEST_MODE_DTL_LOC.DATA.TOUCH_FNSH_LOC_X))
                {
                    m_nTestErrCnt++;
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0172);    // 터치 선택 위치를 확인 하세요.
                    return;
                }

                if (nY < CmUtil.GetDataRowInt(drLoc, PosMst.MST_TEST_MODE_DTL_LOC.DATA.TOUCH_START_LOC_Y) || nY > CmUtil.GetDataRowInt(drLoc, PosMst.MST_TEST_MODE_DTL_LOC.DATA.TOUCH_FNSH_LOC_Y))
                {
                    m_nTestErrCnt++;
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0172);    // 터치 선택 위치를 확인 하세요.
                    return;
                }

                DisplayTestMode(true);
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                   System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            finally
            {
                lblError.Text = "▶ ERROR : " + string.Format("{0:D2} / {1:D2}", m_nTestErrCnt, m_nTestErrPrmt_Cnt);
            }
        }

        private void picBack_Click(object sender, EventArgs e)
        {

        }

    }
}
