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 frmIntegrity : 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 IDatabaseSQL m_cSqlDbService = null;                                // 데이터베이스 관리
        private IICReaderUs m_cDeviceICReader = null;
        private IIntegrity m_cIntegrity = null;

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

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

        private string m_sDeviceType ;                                                
        /// <summary>
        /// 장비 구분
        /// </summary>
        public string SetDeviceType { set { this.m_sDeviceType = value; } }

        /// <summary>
        /// 조회구분 (1:자료조회, 2:매출조회, 3:영수증메모조회)
        /// </summary>
        private string m_sSearchType;                                              

        /// <summary>
        /// 무결성 내역
        /// </summary>
        private DataTable m_dt_Integrity;

        /// <summary>
        /// 상호인증 내역
        /// </summary>
        private DataTable m_dt_Certify;

        /// <summary>
        /// 입력구분
        /// </summary>
        private string m_sInPutType = "";
        /// <summary>
        /// 입력데이터
        /// </summary>
        private string m_sInPutData = "";
        /// <summary>
        /// 카드데이터
        /// </summary>
        private string m_sInEncData = "";

        private bool m_bAutoMode;                                                
        /// <summary>
        /// 자동 처리 구분
        /// </summary>
        public bool SetAutoMode { set { this.m_bAutoMode = value; } }

        string m_sCheckDevice = "";

        #endregion 변수 선언

        #region 생성자 & 소멸자 & 폼초기화
        public frmIntegrity()
        {
            if (m_bAutoMode == true) this.Hide();

            InitializeComponent();

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

            m_cPosStatus = (PosStatus)StateObject.POS;      // POS 기본정보
            m_cTrnStatus = (TranStatus)StateObject.TRAN;    // Tran 거래정보 
            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_cDeviceICReader = (IICReaderUs)sManager.InitServiceInstance(ServiceLists.AGENT_OLEDEVICE.DLL, ServiceLists.AGENT_OLEDEVICE.DEVICE_ICREADER);
            m_cSqlDbService = (IDatabaseSQL)sManager.InitServiceInstance(ServiceLists.AGENT_DATABASE.DLL, ServiceLists.AGENT_DATABASE.DATABASE_MSSQL);
            m_cIntegrity = (IIntegrity)sManager.InitServiceInstance(ServiceLists.BSV_ADMIN.DLL, ServiceLists.BSV_ADMIN.INTEGRITY);
        }

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

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

        private void frmIntegrity_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()
        {
            StringBuilder sbVer = null;
            string sRet = UserCom.RST_ERR;
            try
            {
                if (m_cPosStatus.Sale.ScreenSizeUser == 1024)
                {
                    // 이미지 로딩 처리
                    picBack.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.POP_FULL_SIZE);
                    //this.Size = new Size(1024, 696);
                    //this.Location = new Point(0, 50);
                    FormManager.SetControlSize(picBack, 0, 0, 1024, 696);
                    FormManager.SetControlSize(this, 0, 50, picBack.Size.Width, picBack.Size.Height);

                    FormManager.SetControlSize(this.lblTitle, 16, 1, 950, 50);
                    FormManager.SetControlSize(this.btnExit, 965, 1, 58, 50);
                    FormManager.SetControlSize(this.lblTitle1, 16, 143, 140, 18);
                    FormManager.SetControlSize(this.grdIntegrity, 16, 177, 460, 429);
                    FormManager.SetControlSize(this.btnDw2_Integrity, 475, 498, 29, 108);
                    FormManager.SetControlSize(this.btnDw_Integrity, 475, 391, 29, 108);
                    FormManager.SetControlSize(this.btnUp_Integrity, 475, 284, 29, 108);
                    FormManager.SetControlSize(this.btnUp2_Integrity, 475, 177, 29, 108);
                    FormManager.SetControlSize(this.btnIntegrityCheck, 390, 132, 114, 40);
                    FormManager.SetControlSize(this.lblSaleDate, 681, 71, 122, 40);
                    FormManager.SetControlSize(this.label2, 681, 70, 326, 2);
                    FormManager.SetControlSize(this.btnIntegritySealect, 288, 132, 100, 40);
                    FormManager.SetControlSize(this.btnCertify_Select, 806, 131, 100, 40);
                    FormManager.SetControlSize(this.btnCertify_KeyDownload, 908, 131, 100, 40);
                    FormManager.SetControlSize(this.grdCertify, 519, 177, 460, 429);
                    FormManager.SetControlSize(this.btnDw2_Certify, 978, 498, 29, 108);
                    FormManager.SetControlSize(this.btnDw_Certify, 978, 391, 29, 108);
                    FormManager.SetControlSize(this.btnUp_Certify, 978, 284, 29, 108);
                    FormManager.SetControlSize(this.btnUp2_Certify, 978, 177, 29, 108);
                    FormManager.SetControlSize(this.lblTitle2, 516, 143, 121, 18);
                    FormManager.SetControlSize(this.lblICVer, 30, 620, 154, 18);
                    FormManager.SetControlSize(this.btnICReader, 16, 68, 199, 50);
                    FormManager.SetControlSize(this.btnSignPad, 220, 68, 199, 50);
                    FormManager.SetControlSize(this.label3, 16, 117, 992, 1);
                    FormManager.SetControlSize(this.lblSignPadVer, 29, 654, 155, 18);
                    FormManager.SetControlSize(this.lblPOSVer, 533, 620, 196, 18);
                    FormManager.SetControlSize(this.btnFromDate, 965, 78, 26, 26);
                    FormManager.SetControlSize(this.txtDateFrom, 817, 78, 147, 26);
                    FormManager.SetControlSize(this.lblBox1, 802, 71, 205, 40);
                }
                else 
                {
                    // 이미지 로딩 처리
                    //picBack.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.POP_SIZE_800X600);
                    //FormManager.SetControlSize(picBack, 0, 0, 768, 768);
                    //FormManager.SetControlSize(this, 0, 0, picBack.Size.Width, picBack.Size.Height);

                    //FormManager.SetControlSize(this.lblTitle, 16, 1, 728, 50);
                    //FormManager.SetControlSize(this.btnExit, 741, 1, 58, 50);
                    //FormManager.SetControlSize(this.lblTitle1, 22, 143, 140, 18);
                    FormManager.SetControlSize(this.grdIntegrity, 8, 177, 342, 429);
                    //FormManager.SetControlSize(this.btnDw2_Integrity, 363, 421, 29, 83);
                    //FormManager.SetControlSize(this.btnDw_Integrity, 363, 340, 29, 82);
                    //FormManager.SetControlSize(this.btnUp_Integrity, 363, 259, 29, 82);
                    //FormManager.SetControlSize(this.btnUp2_Integrity, 363, 177, 29, 83);
                    //FormManager.SetControlSize(this.btnIntegrityCheck, 278, 132, 114, 40);
                    //FormManager.SetControlSize(this.lblSaleDate, 451, 71, 122, 40);
                    //FormManager.SetControlSize(this.label2, 451, 70, 326, 2);
                    //FormManager.SetControlSize(this.btnIntegritySealect, 176, 132, 100, 40);
                    //FormManager.SetControlSize(this.btnCertify_Select, 575, 131, 100, 40);
                    //FormManager.SetControlSize(this.btnCertify_KeyDownload, 677, 131, 100, 40);
                    FormManager.SetControlSize(this.grdCertify, 391, 177, 342, 429);
                    //FormManager.SetControlSize(this.btnDw2_Certify, 748, 421, 29, 83);
                    //FormManager.SetControlSize(this.btnDw_Certify, 748, 340, 29, 82);
                    //FormManager.SetControlSize(this.btnUp_Certify, 748, 259, 29, 82);
                    //FormManager.SetControlSize(this.btnUp2_Certify, 748, 177, 29, 83);
                    //FormManager.SetControlSize(this.lblTitle2, 404, 143, 121, 18);
                    //FormManager.SetControlSize(this.lblICVer, 36, 518, 154, 18);
                    //FormManager.SetControlSize(this.btnICReader, 22, 68, 199, 50);
                    //FormManager.SetControlSize(this.btnSignPad, 226, 68, 199, 50);
                    //FormManager.SetControlSize(this.label3, 22, 117, 756, 1);
                    //FormManager.SetControlSize(this.lblSignPadVer, 35, 552, 155, 18);
                    //FormManager.SetControlSize(this.lblPOSVer, 421, 518, 196, 18);
                    //FormManager.SetControlSize(this.btnFromDate, 735, 78, 26, 26);
                    //FormManager.SetControlSize(this.txtDateFrom, 587, 78, 147, 26);
                    //FormManager.SetControlSize(this.lblBox1, 572, 71, 205, 40);
                }
                // 이미지 로딩 처리
                //picBack.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.POP_FULL_SIZE);
                //this.Size = new Size(1024, 696);
                //this.Location = new Point(0, 50);

                FormManager.SetFormAllControlFont(this, m_cPosStatus.Base.FONT);
                FormManager.SetTextBoxGlobalInfo(this, m_cPosStatus.Global.m_stCultureMaster.nGroupingDigits, m_cPosStatus.Global.m_stCultureMaster.strGroupingSymbol
                    , m_cPosStatus.Global.m_stCultureMaster.nDecimalDigits, m_cPosStatus.Global.m_stCultureMaster.strDecimalSymbol);

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

                btnUp2_Integrity.Image = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_14X9_UP2_BASIC);
                btnUp_Integrity.Image = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_14X9_UP1_BASIC);
                btnDw_Integrity.Image = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_14X9_DOWN1_BASIC);
                btnDw2_Integrity.Image = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_14X9_DOWN2_BASIC);

                if (btnUp2_Integrity.Image != null) btnUp2_Integrity.Text = "";
                if (btnUp_Integrity.Image != null) btnUp_Integrity.Text = "";
                if (btnDw_Integrity.Image != null) btnDw_Integrity.Text = "";
                if (btnDw2_Integrity.Image != null) btnDw2_Integrity.Text = "";

                btnUp2_Certify.Image = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_14X9_UP2_BASIC);
                btnUp_Certify.Image = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_14X9_UP1_BASIC);
                btnDw_Certify.Image = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_14X9_DOWN1_BASIC);
                btnDw2_Certify.Image = CmUtil.LoadImage(BaseCom.NxImgPath + ImageManager.NAVIBTN_14X9_DOWN2_BASIC);

                if (btnUp2_Certify.Image != null) btnUp2_Certify.Text = "";
                if (btnUp_Certify.Image != null) btnUp_Certify.Text = "";
                if (btnDw_Certify.Image != null) btnDw_Certify.Text = "";
                if (btnDw2_Certify.Image != null) btnDw2_Certify.Text = "";

                lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0573);
                lblSaleDate.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0354);

                lblTitle1.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0582);
                btnIntegritySealect.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0004);                  // 무결성 조회
                btnIntegrityCheck.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0574);                    // 무결성 검사

                btnICReader.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0605);                          // IC 리더기
                btnSignPad.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0606);                           // 서명패드

                lblTitle2.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0583);
                btnCertify_Select.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0004);                    // 상호인증 조회
                btnCertify_KeyDownload.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0572);               // 상호인증

                txtDateFrom.InputTypeFormat = m_cPosStatus.Global.m_stCultureMaster.strDatePattern;
                txtDateFrom.Text = m_cPosStatus.Global.DateToCulture(System.DateTime.Now.ToString("yyyyMMdd"));

                bNotDoubleClik = false;

                btnICReader.BackColor = Color.FromArgb(0, 192, 192);
                btnSignPad.BackColor = Color.FromArgb(109, 110, 113);

                m_sCheckDevice = PosConst.POS_CARD_READER_DEVICE_TYPE.IC_READER;

                btnSignPad.Visible = false; 
                
                if (m_cDevStatus.SignPad.UseYn != true) btnSignPad.Visible = false;

                // 서명패드 버전 정보                
                lblPOSVer.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0610) + CmUtil.MidH(m_cPosStatus.Base.Auth_POS_SW_Ver.ToString(), 0, 16);
                //lblPOSVer.Text += "\n                   " + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0611) + CmUtil.MidH(m_cPosStatus.Base.Auth_POS_SW_Ver.ToString(), 0, 11);
                //lblPOSVer.Text += "\n                   " + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0612) + CmUtil.RightH(m_cPosStatus.Base.Auth_POS_SW_Ver.ToString(), 4);

                if (m_bAutoMode != true)
                {
                    // 자동인 경우 잔상이 남아 표시 제한
                    btnICReader.Visible = true;
                    btnSignPad.Visible = false;
                    label3.Visible = true;
                    lblSaleDate.Visible = true;
                    txtDateFrom.Visible = true;
                    btnFromDate.Visible = true;

                    label2.Visible = true;
                    lblBox1.Visible = true;

                    lblTitle1.Visible = true;
                    btnIntegritySealect.Visible = true;
                    btnIntegrityCheck.Visible = true;
                    grdIntegrity.Visible = true;
                    btnUp2_Integrity.Visible = true;
                    btnUp_Integrity.Visible = true;
                    btnDw_Integrity.Visible = true;
                    btnDw2_Integrity.Visible = true;

                    lblTitle2.Visible = true;
                    btnCertify_Select.Visible = true;
                    btnCertify_KeyDownload.Visible = true;
                    grdCertify.Visible = true;
                    btnUp2_Certify.Visible = true;
                    btnUp_Certify.Visible = true;
                    btnDw_Certify.Visible = true;
                    btnDw2_Certify.Visible = true;

                    lblICVer.Visible = true;
                    lblSignPadVer.Visible = false;
                    lblPOSVer.Visible = true;

                    //WinManager.ShowSearchMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0361), this);
                    if (m_cDevStatus.ICReader.UseYn == true)
                    {
                        // ic 리더기 버전 정보
                        sbVer = m_cDeviceICReader.SetAuthInfoString(PosConst.POS_CARD_READER_DEVICE_TYPE.IC_READER);
                        lblICVer.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0593);
                        if (sbVer.ToString() != "")
                            lblICVer.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0593) + CmUtil.MidH(sbVer.ToString(), 0, 16);
                    }
                    if (m_cDevStatus.SignPad.UseYn == true)
                    {
                        // 서명패드 버전 정보
                        //sbVer = m_cDeviceICReader.SetAuthInfoString(PosConst.POS_CARD_READER_DEVICE_TYPE.SAIGNPAD);
                        //lblSignPadVer.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0609);
                        //if (sbVer.ToString() != "")
                        //    lblSignPadVer.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0609) + CmUtil.MidH(sbVer.ToString(), 0, 16);
                    }
                    InitializeGrid();                                                                                   // 그리드 초기화      
                    DataGridSetting("01");                                                                              // 무결성 로그 조회
                    DataGridSetting("02");                                                                              // 상호인증 로그 조회
                }
                else
                {
                    // 자동인 경우 잔상이 남아 표시 제한
                    btnICReader.Visible = false;
                    btnSignPad.Visible = false;
                    label3.Visible = false;
                    lblSaleDate.Visible = false;
                    txtDateFrom.Visible = false;
                    btnFromDate.Visible = false;
                    label2.Visible = false;
                    lblBox1.Visible = false;

                    lblTitle1.Visible = false;
                    btnIntegritySealect.Visible = false;
                    btnIntegrityCheck.Visible = false;
                    grdIntegrity.Visible = false;
                    btnUp2_Integrity.Visible = false;
                    btnUp_Integrity.Visible = false;
                    btnDw_Integrity.Visible = false;
                    btnDw2_Integrity.Visible = false;

                    lblTitle2.Visible = false;
                    btnCertify_Select.Visible = false;
                    btnCertify_KeyDownload.Visible = false;
                    grdCertify.Visible = false;
                    btnUp2_Certify.Visible = false;
                    btnUp_Certify.Visible = false;
                    btnDw_Certify.Visible = false;
                    btnDw2_Certify.Visible = false;

                    lblICVer.Visible = false;
                    lblSignPadVer.Visible = false;
                    lblPOSVer.Visible = false;

                    if (m_sPosMenuKey == PosKey.MENU_KEY.POS_CERTIFY_KEYDOWNLOAD)
                    {
                        // KSN Download
                        if (m_cDevStatus.SignPad.UseYn == true)
                        {
                            if (m_sDeviceType.Trim() == "" || m_sDeviceType == PosConst.POS_CARD_READER_DEVICE_TYPE.SAIGNPAD)
                            {
                                // 상호인증 서명패드
                                sRet = LS_Certify_KeyDownload(PosConst.POS_CARD_READER_DEVICE_TYPE.SAIGNPAD);

                                if (sRet == UserCom.RST_OK)
                                {
                                    // KSN Download 상태값 초기화
                                    m_cPosStatus.Base.KSN_SignPad_Download = "";

                                    CmMessage m_PosSal = CmMessage.MakeMessageFromFile(BaseCom.NxIniPath + PosConst.INI_FILE_NAME.PosSaleInfo);
                                    m_PosSal.GetMessage("POSOPEN").MakeMessageOverWrite("KSN_SignPad_Download", m_cPosStatus.Base.KSN_SignPad_Download);
                                    m_PosSal.MakeFileFromMessage(BaseCom.NxIniPath + PosConst.INI_FILE_NAME.PosSaleInfo);
                                }
                            }
                        }

                        if (m_cDevStatus.ICReader.UseYn == true)
                        {
                            if (m_sDeviceType.Trim() == "" || m_sDeviceType == PosConst.POS_CARD_READER_DEVICE_TYPE.IC_READER)
                            {
                                // 상호인증 IC 리더기
                                sRet = LS_Certify_KeyDownload(PosConst.POS_CARD_READER_DEVICE_TYPE.IC_READER);

                                if (sRet == UserCom.RST_OK)
                                {
                                    // KSN Download 상태값 초기화
                                    m_cPosStatus.Base.KSN_IC_Download = "";

                                    CmMessage m_PosSal = CmMessage.MakeMessageFromFile(BaseCom.NxIniPath + PosConst.INI_FILE_NAME.PosSaleInfo);
                                    m_PosSal.GetMessage("POSOPEN").MakeMessageOverWrite("KSN_IC_Download", m_cPosStatus.Base.KSN_IC_Download);
                                    m_PosSal.MakeFileFromMessage(BaseCom.NxIniPath + PosConst.INI_FILE_NAME.PosSaleInfo);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (m_cDevStatus.SignPad.UseYn == true)
                        {
                            if (m_sDeviceType.Trim() == "" || m_sDeviceType == PosConst.POS_CARD_READER_DEVICE_TYPE.SAIGNPAD)
                            {
                                // 무결성 체크 서명패드
                                ExIntegrityCheck(PosConst.POS_CARD_READER_DEVICE_TYPE.SAIGNPAD);
                            }
                        }

                        if (m_cDevStatus.ICReader.UseYn == true)
                        {
                            if (m_sDeviceType.Trim() == "" || m_sDeviceType == PosConst.POS_CARD_READER_DEVICE_TYPE.IC_READER)
                            {
                                // 무결성 체크 IC 리더기
                                ExIntegrityCheck(PosConst.POS_CARD_READER_DEVICE_TYPE.IC_READER);
                            }
                        }
                    }
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                    return;
                }
            }
            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
            {
                //WinManager.HideSearchMessage(this);
            }
        }
        #endregion

        #region 버튼 입력 처리
        /// <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 == btnICReader)
                {
                    btnICReader.BackColor = Color.FromArgb(0, 192, 192);
                    btnSignPad.BackColor = Color.FromArgb(109, 110, 113);
                    m_sCheckDevice = PosConst.POS_CARD_READER_DEVICE_TYPE.IC_READER;

                    DataGridSetting("01");
                    DataGridSetting("02");
                }
                else if ((UI.CsmButton)sender == btnSignPad)
                {
                    btnSignPad.BackColor = Color.FromArgb(0, 192, 192);
                    btnICReader.BackColor = Color.FromArgb(109, 110, 113);
                    m_sCheckDevice = PosConst.POS_CARD_READER_DEVICE_TYPE.SAIGNPAD;

                    DataGridSetting("01");
                    DataGridSetting("02");
                }
                else if ((UI.CsmButton)sender == btnUp2_Integrity)
                {
                    grdIntegrity.CsmGridScroll("PAGE UP");
                }
                else if ((UI.CsmButton)sender == btnUp_Integrity)
                {
                    grdIntegrity.CsmGridScroll("UP");
                }
                else if ((UI.CsmButton)sender == btnDw_Integrity)
                {
                    grdIntegrity.CsmGridScroll("DOWN");
                }
                else if ((UI.CsmButton)sender == btnDw2_Integrity)
                {
                    grdIntegrity.CsmGridScroll("PAGE DOWN");
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnIntegrityCheck )          // 무결성 체크
                {
                    sRet = ExIntegrityCheck(m_sCheckDevice);

                    bNotDoubleClik = false;
                    if (sRet != UserCom.RST_OK) return;
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnIntegritySealect)          // 무결성 체크 내역 조회
                {
                    DataGridSetting("01");
                }

                else if ((UI.CsmButton)sender == btnUp2_Certify)
                {
                    grdCertify.CsmGridScroll("PAGE UP");
                }
                else if ((UI.CsmButton)sender == btnUp_Certify)
                {
                    grdCertify.CsmGridScroll("UP");
                }
                else if ((UI.CsmButton)sender == btnDw_Certify)
                {
                    grdCertify.CsmGridScroll("DOWN");
                }
                else if ((UI.CsmButton)sender == btnDw2_Certify)
                {
                    grdCertify.CsmGridScroll("PAGE DOWN");
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnCertify_KeyDownload)       // 상호인증
                {
                    sRet = LS_Certify_KeyDownload(m_sCheckDevice);

                    bNotDoubleClik = false;
                    if (sRet != UserCom.RST_OK) return;
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnCertify_Select)          // 상호인증 내역 조회
                {
                    DataGridSetting("02");
                }

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

        /// <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)
        {
            try
            {
                if (sFuncValue == PosKey.MENU_KEY.ENTER)
                {


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

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

        }
        #endregion 

        #region 텍스트박스 입력 유효성 체크
        /// <summary>
        /// 텍스트박스 입력 유효성 체크
        /// </summary>
        /// <param name="sender"></param>
        /// <returns></returns>
        private bool CheckTxtInPut(object sender)
        {
            try
            {
                //if (sender == null || ((Cosmos.UI.CsmPosEditBox)sender) == txtCardNo)
                //{
                //    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0189);
                //    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="sDeviceType"></param>
        /// <returns></returns>
        private string ExIntegrityCheck(string sDeviceType)
        { 
            string sStatus = "Y";
            string sMsg = "";
            StringBuilder sbVer = null;
            string sRet = UserCom.RST_ERR;
            try
            {
                //string sRsltTime = null;
                //if (sDeviceType == PosConst.POS_CARD_READER_DEVICE_TYPE.IC_READER)
                //    WinManager.ShowSearchMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0351));
                //else
                //    WinManager.ShowSearchMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0381));

                //sRet = m_cDeviceICReader.IntegrityCheck_ICReader(sDeviceType, ref sRsltTime);
                //WinManager.HideSearchMessage(this);

                if (sDeviceType == PosConst.POS_CARD_READER_DEVICE_TYPE.IC_READER)
                    sMsg = MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0351);
                else
                    sMsg = MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0381);

                sRet = WinAdmin.ShowForm(new string[] { FormManager.FORM_CERTIFY_INTEGRITY_THREAD, PosConst.SCFBA_BIZ_TYPE.INTEGRITY, sDeviceType, PosConst.SCFBA_PROC_TYPE.MANUAL, sMsg });                

                if (sRet != UserCom.RST_OK)
                {
                    if (sDeviceType == PosConst.POS_CARD_READER_DEVICE_TYPE.IC_READER)
                    {
                        //WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0345);

                        // ic 리더기 버전 정보
                        sbVer = m_cDeviceICReader.SetAuthInfoString(PosConst.POS_CARD_READER_DEVICE_TYPE.IC_READER);
                        lblICVer.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0593);
                        if (sbVer.ToString() != "")
                            lblICVer.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0593) + CmUtil.MidH(sbVer.ToString(), 0, 16);
                    }
                    else
                    {
                        //WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0380);

                        // 서명패드 버전 정보
                        sbVer = m_cDeviceICReader.SetAuthInfoString(PosConst.POS_CARD_READER_DEVICE_TYPE.SAIGNPAD);
                        lblSignPadVer.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0609);
                        if (sbVer.ToString() != "")
                            lblSignPadVer.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0609) + CmUtil.MidH(sbVer.ToString(), 0, 16);

                    }

                    sStatus = "N";
                }
                else
                {
                    if (sDeviceType == PosConst.POS_CARD_READER_DEVICE_TYPE.IC_READER)
                    {
                        // ic 리더기 버전 정보
                        sbVer = m_cDeviceICReader.SetAuthInfoString(PosConst.POS_CARD_READER_DEVICE_TYPE.IC_READER);
                        lblICVer.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0593);
                        if (sbVer.ToString() != "")
                            lblICVer.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0593) + CmUtil.MidH(sbVer.ToString(), 0, 16);
                    }
                    else
                    {
                        // 서명패드 버전 정보
                        sbVer = m_cDeviceICReader.SetAuthInfoString(PosConst.POS_CARD_READER_DEVICE_TYPE.SAIGNPAD);
                        lblSignPadVer.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0609);
                        if (sbVer.ToString() != "")
                            lblSignPadVer.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0609) + CmUtil.MidH(sbVer.ToString(), 0, 16);

                    }
                }
                //LS_StatusSave(PosConst.SCFBA_BIZ_TYPE.INTEGRITY, sDeviceType, (m_bAutoMode == true) ? "A" : "M", sRsltTime, sStatus);

                // 재조회
                if (m_bAutoMode != true) DataGridSetting(PosConst.SCFBA_BIZ_TYPE.INTEGRITY); 

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

                //txtCardNo.Text = m_sInPutData;

///                if (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL) SearchTxtInPut();
            }

        }

        /// <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 그리드 초기화
        /// <summary>
        /// 그리드 초기화
        /// </summary>
        private void InitializeGrid()
        {
            try
            {
                grdIntegrity.CsmGridColumnHeadersVisible = true;           //DataGridView 자체의 컬럼 헤더 Visible 여부
                grdIntegrity.CsmGridColumnHeadersFont = new Font(m_cPosStatus.Base.FONT, 12);                                
                grdIntegrity.CsmGridColumnCount = 4;                       //그리드의 컬럼수                
                grdIntegrity.CsmGridSetHeaderBackColor(236, 238, 239);                                  //그리드 헤더 배경색
                grdIntegrity.CsmGridDefaultRowBackColor   = Color.FromArgb(255, 255, 255);              //그리드 홀수(Default)행의 배경색 지정
                grdIntegrity.CsmGridAlternateRowBackColor = Color.FromArgb(251, 253, 255);              //그리드 짝수(Alternate)행의 배경색 지정
                grdIntegrity.CsmGridBackGroundColor       = Color.FromArgb(251, 253, 255);              //기본 백그라운드 컬러
                grdIntegrity.CsmGridHighlightColor        = Color.FromArgb(255, 251, 211);              //그리드 선택 백 컬러
                grdIntegrity.CsmGridHighlightTextColor    = Color.Black;                                //그리드 선택 글자 컬러
                grdIntegrity.CsmGridAlignment(new int[] { 2, 1, 1, 1  });               //컬럼 정렬 0:왼쪽, 1:가운데, 2:오른쪽
                grdIntegrity.CsmGridSetSortMode(new int[] { 1, 1, 1, 1});

                if (m_cPosStatus.Sale.ScreenSizeUser == 1024)
                {
                    grdIntegrity.CsmGridColumnHeadersHeight = 37;              //DataGridView 자체의 컬럼 헤더 높이
                    grdIntegrity.CsmGridRowsHeight = 39;
                    grdIntegrity.CsmGridShowPageRowsCount = 10;                //그리드의 한 화면에 보이는 로우수
                    grdIntegrity.CsmGridSetColumnWidth(new int[] { 65, 95, 205, 95 });   //컬럼넓이 지정 (460)
                }
                else
                {
                    grdIntegrity.CsmGridColumnHeadersHeight = 37;              //DataGridView 자체의 컬럼 헤더 높이
                    grdIntegrity.CsmGridRowsHeight = 39;
                    grdIntegrity.CsmGridShowPageRowsCount = 10;                //그리드의 한 화면에 보이는 로우수
                    grdIntegrity.CsmGridSetColumnWidth(new int[] { 40, 60, 182, 60 });   //컬럼넓이 지정 (342)
                }


                //각 컬럼별 이름 지정(영업일자,POS번호,판매금액,거래번호,거래시간,거래구분,)
                grdIntegrity.CsmGridColumnName(0, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0014));
                grdIntegrity.CsmGridColumnName(1, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0532));
                grdIntegrity.CsmGridColumnName(2, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0530));
                grdIntegrity.CsmGridColumnName(3, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0421));

                //그리드 초기화 테이블
                m_dt_Integrity = new DataTable("INIT");
                m_dt_Integrity.Columns.Add(new DataColumn("SEQ", typeof(string)));
                m_dt_Integrity.Columns.Add(new DataColumn("PROC_TYPE", typeof(string)));
                m_dt_Integrity.Columns.Add(new DataColumn("CHECK_DT", typeof(string)));
                m_dt_Integrity.Columns.Add(new DataColumn("CHECK_FLAG", typeof(string)));
                m_dt_Integrity.Clear();

                grdCertify.CsmGridColumnHeadersVisible = true;           //DataGridView 자체의 컬럼 헤더 Visible 여부
                grdCertify.CsmGridColumnHeadersFont = new Font(m_cPosStatus.Base.FONT, 12);
                grdCertify.CsmGridColumnCount = 4;                                                  //그리드의 컬럼수               
                grdCertify.CsmGridSetHeaderBackColor(236, 238, 239);                                //그리드 헤더 배경색
                grdCertify.CsmGridDefaultRowBackColor   = Color.FromArgb(255, 255, 255);            //그리드 홀수(Default)행의 배경색 지정
                grdCertify.CsmGridAlternateRowBackColor = Color.FromArgb(251, 253, 255);            //그리드 짝수(Alternate)행의 배경색 지정
                grdCertify.CsmGridBackGroundColor       = Color.FromArgb(251, 253, 255);            //기본 백그라운드 컬러
                grdCertify.CsmGridHighlightColor        = Color.FromArgb(255, 251, 211);            //그리드 선택 백 컬러
                grdCertify.CsmGridHighlightTextColor    = Color.Black;                              //그리드 선택 글자 컬러
                grdCertify.CsmGridAlignment(new int[] { 2, 1, 1, 1 });               //컬럼 정렬 0:왼쪽, 1:가운데, 2:오른쪽
                grdCertify.CsmGridSetSortMode(new int[] { 1, 1, 1, 1 });

                if (m_cPosStatus.Sale.ScreenSizeUser == 1024)
                {
                    grdCertify.CsmGridColumnHeadersHeight = 37;              //DataGridView 자체의 컬럼 헤더 높이
                    grdCertify.CsmGridRowsHeight = 39;
                    grdCertify.CsmGridShowPageRowsCount = 10;                //그리드의 한 화면에 보이는 로우수
                    grdCertify.CsmGridSetColumnWidth(new int[] { 65, 95, 205, 95 });   //컬럼넓이 지정 (460)
                }
                else
                {
                    grdCertify.CsmGridColumnHeadersHeight = 37;              //DataGridView 자체의 컬럼 헤더 높이
                    grdCertify.CsmGridRowsHeight = 39;
                    grdCertify.CsmGridShowPageRowsCount = 10;                //그리드의 한 화면에 보이는 로우수
                    grdCertify.CsmGridSetColumnWidth(new int[] { 40, 60, 182, 60 });  //컬럼넓이 지정 (342)
                }
                
                //각 컬럼별 이름 지정(영업일자,POS번호,판매금액,거래번호,거래시간,거래구분,)
                grdCertify.CsmGridColumnName(0, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0014));
                grdCertify.CsmGridColumnName(1, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0532));
                grdCertify.CsmGridColumnName(2, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0530));
                grdCertify.CsmGridColumnName(3, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0421));

                //그리드 초기화 테이블
                m_dt_Certify = new DataTable("INIT");
                m_dt_Certify.Columns.Add(new DataColumn("SEQ", typeof(string)));
                m_dt_Certify.Columns.Add(new DataColumn("PROC_TYPE", typeof(string)));
                m_dt_Certify.Columns.Add(new DataColumn("CHECK_DT", typeof(string)));
                m_dt_Certify.Columns.Add(new DataColumn("CHECK_FLAG", typeof(string)));
                m_dt_Certify.Clear();

            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
        #endregion
        
        #region 그리드 설정 및 사용
        private double DataGridSetting(string sSearchType)
        {
            DataTable dtData = null;
            try
            {
                if (txtDateFrom.Visible == true && txtDateFrom.Value.Length != 8)
                {
                    WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0536));
                    txtDateFrom.Select();
                    txtDateFrom.SelectText();
                    return 0;
                }

                string sDateFrom = m_cPosStatus.Global.CultureToDate(txtDateFrom.Text);

                // 자료 조회
                dtData = m_cIntegrity.SelectIntegrityLog(new string[] { sDateFrom, sSearchType, m_sCheckDevice });

                if (sSearchType == "01")
                {
                    m_dt_Integrity.Clear();

                    //무결성 내역
                    if (dtData != null && dtData.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dtData.Rows)
                        {
                            string sGetDate = "";

                            DataRow drNewRow = m_dt_Integrity.NewRow();
                            drNewRow["SEQ"] = CmUtil.GetDataRowStr(dr, "SEQ");

                            sGetDate = CmUtil.GetDataRowStr(dr, "PROC_TYPE");
                            drNewRow["PROC_TYPE"] = (sGetDate == "A") ? MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0586) : MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0587);

                            sGetDate = CmUtil.GetDataRowStr(dr, "CHECK_DT");
                            drNewRow["CHECK_DT"] = m_cPosStatus.Global.DateToCulture(CmUtil.MidH(sGetDate, 0, 8)) + ", " + string.Format("{0:00:00:00}", m_cDataService.LongParse(CmUtil.MidH(sGetDate, 8, 6)));

                            sGetDate = CmUtil.GetDataRowStr(dr, "CHECK_FLAG");
                            drNewRow["CHECK_FLAG"] = (sGetDate == "Y") ? MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0584) : MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0585);

                            m_dt_Integrity.Rows.Add(drNewRow);
                        }
                    }

                    grdIntegrity.CsmGridDataSource = m_dt_Integrity;
                    grdIntegrity.CsmGridIndicateForeColor = Color.Red;
                    grdIntegrity.CsmGridSelectRow(0);
                }
                else
                {
                    m_dt_Certify.Clear();

                    //상호인증 내역 
                    if (dtData != null && dtData.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dtData.Rows)
                        {
                            string sGetDate = "";

                            DataRow drNewRow = m_dt_Certify.NewRow();
                            drNewRow["SEQ"] = CmUtil.GetDataRowStr(dr, "SEQ");

                            sGetDate = CmUtil.GetDataRowStr(dr, "PROC_TYPE");
                            drNewRow["PROC_TYPE"] = (sGetDate == "A") ? MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0586) : MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0587);

                            sGetDate = CmUtil.GetDataRowStr(dr, "CHECK_DT");
                            drNewRow["CHECK_DT"] = m_cPosStatus.Global.DateToCulture(CmUtil.MidH(sGetDate, 0, 8)) + ", " + string.Format("{0:00:00:00}", m_cDataService.LongParse(CmUtil.MidH(sGetDate, 8, 6)));

                            drNewRow["CHECK_FLAG"] = CmUtil.GetDataRowStr(dr, "CHECK_FLAG");
                            sGetDate = CmUtil.GetDataRowStr(dr, "CHECK_FLAG");
                            drNewRow["CHECK_FLAG"] = (sGetDate == "Y") ? MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0584) : MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0585);

                            m_dt_Certify.Rows.Add(drNewRow);
                        }
                    }

                    grdCertify.CsmGridDataSource = m_dt_Certify;
                    grdCertify.CsmGridIndicateForeColor = Color.Red;
                    grdCertify.CsmGridSelectRow(0);
                }

                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 

        #region 상호인증
        /// <summary>
        /// 상호인증
        /// </summary>
        /// <param name="sDeviceType"></param>
        /// <returns></returns>
        private string LS_Certify_KeyDownload(string sDeviceType)
        {
            string sStatus = "Y";
            string sMsg = "";
            string sRet = UserCom.RST_ERR;
            try
            {
                //if (sDeviceType == PosConst.POS_CARD_READER_DEVICE_TYPE.IC_READER)
                //    WinManager.ShowSearchMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0352));
                //else
                //    WinManager.ShowSearchMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0383));

                //string sTerminerID = PosMstManager.GetMstVan(ItemConst.TR_ITEM_ID.CREDITCARD_ITEM, ItemConst.TR_ITEM_ID.CREDITCARD.CREDIT_CARD, PosMst.MST_VAN.DATA.APPR_ID);
                //sRet = m_cDeviceICReader.KeyDownload_ICReader(sDeviceType, sTerminerID);
                //WinManager.HideSearchMessage(this);

                if (sDeviceType == PosConst.POS_CARD_READER_DEVICE_TYPE.IC_READER)
                    sMsg = MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0352);
                else
                    sMsg = MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0383);

                sRet = WinAdmin.ShowForm(new string[] { FormManager.FORM_CERTIFY_INTEGRITY_THREAD, PosConst.SCFBA_BIZ_TYPE.CERTIFICATION, sDeviceType, PosConst.SCFBA_PROC_TYPE.MANUAL, sMsg });                
                //if (sRet != UserCom.RST_OK)
                //{
                //    if (sDeviceType == PosConst.POS_CARD_READER_DEVICE_TYPE.IC_READER)
                //        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0344);
                //    else
                //        WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0382);

                //    sStatus = "N";
                //}
                //else
                    //WinManager.ConfirmMessage(POS_MESSAGE.ERROR.MSG_0346);

                //LS_StatusSave(PosConst.SCFBA_BIZ_TYPE.CERTIFICATION, sDeviceType, (m_bAutoMode == true) ? "A" : "M", "", sStatus);

                // 재조회
                if (m_bAutoMode != true) DataGridSetting(PosConst.SCFBA_BIZ_TYPE.CERTIFICATION); 

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

            }
            return sRet;
        }
        #endregion

        #region 처리 내역 저장
        /// <summary>
        /// 처리 내역 저장
        /// </summary>
        /// <param name="sType"></param>
        /// <param name="sCheckDate"></param>
        /// <param name="sStatus"></param>
        /// <returns></returns>
        private string LS_StatusSave(string sType, string sDeviceType, string sProcType, string sCheckDate, string sStatus)
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                // 무결성 로그 생성
                m_cSqlDbService.SetDBConnectionString(m_cPosStatus.Base.LocalDbSource, m_cPosStatus.Base.LocalDbCatalog, m_cPosStatus.Base.LocalDbUserID, m_cPosStatus.Base.LocalDbPassword);
                m_cSqlDbService.Begin();

                string sSql = "";
                sSql = "";
                sSql += "INSERT INTO POSLOG..ETC_INTEGRITY_LOG \n";
                sSql += "  ( CMP_CD, SALE_DT, STOR_CD, POS_NO, DEVICE_TYPE, CHECK_TYPE, SEQ, PROC_TYPE, CHECK_DT, CHECK_FLAG) \n";
                sSql += "SELECT '" + m_cPosStatus.Base.CmpCd +"'								CMP_CD \n";
                sSql += "	,	'" + DateTime.Now.ToString("yyyyMMdd") + "'					    SALE_DT \n";
                sSql += "	,	'" + m_cPosStatus.Base.StoreNo + "'							    STOR_CD \n";
                sSql += "	,	'" + m_cPosStatus.Base.PosNo + "'								POS_NO \n";
                sSql += "	,	'" + sDeviceType + "'								            DEVICE_TYPE \n";
                sSql += "	,	'" + sType + "'								                    CHECK_TYPE \n";
                sSql += "	,	(SELECT ISNULL(MAX(SEQ), 0) + 1 \n";
                sSql += "			FROM POSLOG..ETC_INTEGRITY_LOG \n";
                sSql += "			WHERE CMP_CD	= '" + m_cPosStatus.Base.CmpCd + "' \n";
                sSql += "			AND SALE_DT		= '" + DateTime.Now.ToString("yyyyMMdd") + "' \n";
                sSql += "			AND STOR_CD		= '" + m_cPosStatus.Base.StoreNo + "' \n";
                sSql += "			AND POS_NO		= '" + m_cPosStatus.Base.PosNo + "'  \n";
                sSql += "			AND DEVICE_TYPE	= '" + sDeviceType + "'  \n";
                sSql += "			AND CHECK_TYPE	= '" + sType + "')		SEQ \n";
                sSql += "   , '" + sProcType + "'                                               PROC_TYPE \n";
                if (sCheckDate.Trim() == "")
                {
                    sSql += "	,	'" + DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.ToString("HHmmss") + "' CHECK_DT \n";
                }
                else
                {
                    sSql += "	,	'" + sCheckDate.Trim() + "'					                    CHECK_DT \n";
                }
                sSql += "	,	'" + sStatus +"'									            CHECK_FLAG \n";

                sSql = sSql.Replace("\t", " ");

                if (m_cSqlDbService.DBExecuteNonQuery(sSql) != UserCom.OK)
                {
                    m_cSqlDbService.Rollback();
                     
                    return sRet;
                }
                m_cSqlDbService.Commit();

                // 재조회
                if (m_bAutoMode != true) DataGridSetting(sType); 

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

            }
            return sRet;
        }
        #endregion 

        #region 달력 클릭
        /// <summary>
        /// 달력 클릭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnFromDate_Click(object sender, EventArgs e)
        {
            try
            {
                string sDate = WinBasic.ShowForm(new string[] { FormManager.FORM_CALENDAR });
                if (sDate != "") txtDateFrom.Text = m_cPosStatus.Global.DateToCulture(sDate);
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        } 
        #endregion


    }

}
