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 frmMobileCouponHappyConLog : 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_cDataService = null;
        private IPaymentUs m_cMobileCoupon = null;
        private IICReaderUs m_cDeviceICReader = null;
        private ISalePluItemUs m_cPluService = null;                                // 판매 등록 관리

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

        private IDataCommonUs m_cDataCommon = null;

        private string mPay_DC_Type = "";                                           // 결제 그룹 코드
        private string mPay_DC_CD = "";                                             // 결제 상세 코드

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

        private string m_sCouponCD;                                              
        /// <summary>
        /// 외부 입력 쿠폰번호
        /// </summary>
        public string SetCouponCD { set { this.m_sCouponCD = value; } }

        private string m_sVCouponCD;
        /// <summary>
        /// 외부 입력 가상 쿠폰번호
        /// </summary>
        public string SetVCouponCD { set { this.m_sVCouponCD = value; } }

        private string[] m_sCouponInfo;
        /// <summary>
        /// 외부 입력 가상 쿠폰번호
        /// </summary>
        public string[] SetCouponInfo { set { this.m_sCouponInfo = value; } }
        
        /// <summary>
        /// 입력구분
        /// </summary>
        private string m_sInPutType = "";    
        /// <summary>
        /// 입력데이터
        /// </summary>
        private string m_sInPutData = "";    
        /// <summary>
        /// 카드데이터
        /// </summary>
        private string m_sInEncData = "";
        /// <summary>
        /// 사용가능/불가 펼기기 상태
        /// </summary>
        private bool m_bUseViewMode = false;
        /// <summary>
        /// 결제금액 체크용
        /// </summary>
        private double m_nSaleAmount = 0; 
 
        #endregion 변수 선언

        #region 생성자 & 소멸자 & 폼초기화
        public frmMobileCouponHappyConLog()
        {
            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_cDeviceICReader = (IICReaderUs)sManager.InitServiceInstance(ServiceLists.AGENT_OLEDEVICE.DLL, ServiceLists.AGENT_OLEDEVICE.DEVICE_ICREADER);
            m_cPluService = (ISalePluItemUs)sManager.InitServiceInstance(ServiceLists.BSV_SALE.DLL, ServiceLists.BSV_SALE.SALE_PLU_ITEM);
            m_cMobileCoupon = (IPaymentUs)sManager.InitServiceInstance(ServiceLists.BSV_PAYMENT.DLL, ServiceLists.BSV_PAYMENT.MOBILECOUPON_HAPPYCON);
            m_cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);

            delegatePos = new PosOLEDevice.DelegateOlePos(OnDeviceEvent);
        }

        private void frmMobileCouponHappyConLog_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 frmMobileCouponHappyConLog_Activated(object sender, EventArgs e)
        {
            PosOLEDevice.SetEventHandle(delegatePos);
        }

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

        private void frmMobileCouponHappyConLog_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
            {
                // 이미지 로딩 처리
                this.Size = new Size(800, 578);
                this.Location = new Point(1024 - 800 - 10, 768 - 600);
                picBack.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.POP_SIZE_800X578);
                picBack.Location = new Point(0, 0);

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

                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 = "";

                if (m_sPosMenuKey == PosKey.MENU_KEY.MOBILE_COUPON_HAPPYCON_SCH)
                {
                    FormManager.MovePopUpForm(this, false, m_cPosStatus.Sale.ScreenSizeUser);
                }

                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 = "";

                // 모바일쿠폰
                if (m_sPosMenuKey == PosKey.MENU_KEY.MOBILE_COUPON_HAPPYCON) lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0630);
                else if (m_sPosMenuKey == PosKey.MENU_KEY.MOBILE_COUPON_HAPPYCON_SCH) lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0630);

                lblVCouponNo.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0139);
                lblVCouponNo.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0618);

                m_sInPutType = "";                      // 입력구분
                m_sInPutData = "";                      // 입력데이터
                m_sInEncData = "";                      // 카드데이터

                m_bUseViewMode = false;
                bNotDoubleClik = false;
                m_nSaleAmount = 0;

                mPay_DC_Type = "";                      // 결제 그룹 코드
                mPay_DC_CD = "";                        // 결제 상세 코드

                txtCouponNo.Text = m_sCouponCD;
                txtVCouponNo.Text = m_sVCouponCD;

                DataGridSetting(0, ref m_sCouponInfo);  // 초기화
                DataGridSetting(1, ref m_sCouponInfo);  // 추가

                txtVCouponNo.Select();
                txtVCouponNo.SelectText();
            }
            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 btnProc_Click(object sender, EventArgs e)
        {
            string[] aRet = null;

            try
            {
                if (bNotDoubleClik) return;
                bNotDoubleClik = true;

                if ((UI.CsmButton)sender == btnAllUp)                               // 상단 그리드 Up
                {
                    if (dgvData.Rows.Count == 0)
                    {
                        bNotDoubleClik = false;
                        return;
                    }
                    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)
                    {
                        bNotDoubleClik = false;
                        return;
                    }
                    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;
                        }
                    }
                } 
            }
            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)
                {
                    if (((Cosmos.UI.CsmPosEditBox)sender) == txtVCouponNo)
                    { 
                        return;
                    }
                    //else if (((Cosmos.UI.CsmPosEditBox)sender) == txtCouponAmt)
                    //{
                    //    if (txtCardNo.Text == "")
                    //    {
                    //        SearchTxtInPut();
                    //        return;
                    //    }

                    //    if (txtCardNM.Text == "")
                    //    {
                    //        SearchTxtInPut();
                    //        return;
                    //    }

                    //    if (CheckTxtInPut(sender, false) == false) return;

                    //    if (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL)
                    //    {
                    //        CompleteTxtInPut();             // 할인 승인 처리
                    //    }
                    //}
                }
                else if (sFuncValue == PosKey.MENU_KEY.CLEAR)
                {
                    if (((Cosmos.UI.CsmPosEditBox)sender).ReadOnly == false) ((Cosmos.UI.CsmPosEditBox)sender).Text = "";
                    if (((Cosmos.UI.CsmPosEditBox)sender) == txtVCouponNo)
                    {
                        m_sInPutType = "";    
                        m_sInPutData = "";
                        m_sInEncData = "";    
                        txtVCouponNo.ReadOnly = false;
                    }
                }
                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
            { 
            }
            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
            {
                 
            }
            catch (Exception ex)
            {
               WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
                return false;
            }
            return true;
        }
        #endregion

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

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

        /// <summary>
        /// 조회 처리
        /// </summary>
        /// <returns></returns>
        private bool SearchTxtInPut(string sSearchType, string sCouponNo, string VirtualCouponNo)
        {
            string[] aRet = null;
            string sRet = UserCom.RST_ERR;
            string sCoponinfo = "";
            string[] saRecvdData = null;
            string sInPutType = "";
            string sInPutData = "";
            string sInEncData = "";

            try
            {
                
                return 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);
            }
            return false;
        }
        #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;
                if (sMsrData.Length > 0 && m_sInPutData == "")
                {
                    m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_SWIP;
                    m_sInPutData = sMsrData;
                    
                    txtVCouponNo.Text = m_sInPutData;
                    txtVCouponNo.ReadOnly = 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="source"></param>
        /// <param name="e"></param>
        private void OnScannerEvent(object source, EventArgs e)
        {
            try
            {
                string sScanData = m_cDevStatus.Scanner.DataLabel;
                if (sScanData.Length > 0 && m_sInPutData == "")
                {
                    m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_BARCODE_CP;
                    m_sInPutData = sScanData;
                    
                    txtVCouponNo.Text = m_sInPutData;
                    txtVCouponNo.ReadOnly = 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="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
            {
                sEncData = m_cDeviceICReader.GetEncryptedCardNo(sInData).Trim();

                if (CmUtil.MidH(sEncData, 0, 2) == "00")
                {
                    sCardData = CmUtil.MidH(sEncData, 2, 512).Trim();
                    sCardNo = CmUtil.MidH(sEncData, 514, sEncData.Length - 514).Trim();
                }
                else
                {
                    //암호화 처리 실패!
                    UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", "Fail =>" + sInData);
                }
            }
            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
            {
                m_sInPutType = "";
                m_sInPutData = "";
                m_sInEncData = "";
                txtVCouponNo.Value = "";
                txtVCouponNo.ReadOnly = false;

                string sRsvStr = "";
                if (m_cDeviceICReader.GetCardInfo_ICReader(PosConst.IC_READER_TRAN_TYPE.POINT, 1, ref sRsvStr) == true)
                {
                    if (CmUtil.MidH(sRsvStr, 0, 2) == "00")
                    {
                        txtVCouponNo.Value = CmUtil.MidH(sRsvStr, 1030, 37).Trim(); 

                        m_sInEncData = CmUtil.MidH(sRsvStr, 6, 512).Trim();
                        m_sInPutData = CmUtil.MidH(sRsvStr, 1030, 37).Trim();
                        m_sInPutType = PosConst.POS_VAN_MASTER.INPUT_TYPE.VAN_SWIP;

                        txtVCouponNo.ReadOnly = true;
                        return 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);
            }
            return false;
        }
        #endregion
          
        #region 그리드 설정 및 사용
        private string DataGridSetting(int iWorkMode, ref string[] aRet)
        {
            string sRet = UserCom.RST_ERR;
            try
            {
                if (iWorkMode == 0)
                {
                    #region 초기화
                    dgvData.Rows.Clear();

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

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

                    // 타이틀 설정
                    dgvData.Columns[0].HeaderText = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0053);
                    dgvData.Columns[1].HeaderText = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0532);
                    dgvData.Columns[2].HeaderText = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0308);
                    dgvData.Columns[3].HeaderText = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0623);
                    dgvData.Columns[4].HeaderText = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0631);
                    dgvData.Columns[5].HeaderText = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0632);
                    dgvData.Columns[6].HeaderText = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0633);
                    #endregion
                }
                else if (iWorkMode == 1)
                {
                    #region 추가
                    if (aRet != null)
                    {
                        if (aRet.Length > 0)
                        {
                            int index = 3;
                            for (int iLoop = 0; iLoop < m_cDataService.DoubleParse(aRet[2].Trim()); iLoop++)
                            {
                                // 상세 목록
                                int iRow = dgvData.Rows.Add();
                                dgvData.Rows[iRow].Height = 30;
                                dgvData.Rows[iRow].DefaultCellStyle.BackColor = Color.White;
                                dgvData.Rows[iRow].Visible = true;
                                dgvData.Rows[iRow].Cells[0].Value = aRet[index++].Trim();                                                               // 승인번호

                                string sState = aRet[index++].Trim();
                                string sStateMsg = "";
                                if (sState == "D") sStateMsg = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0629);
                                else if (sState == "N") sStateMsg = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0010);
                                else if (sState == "C") sStateMsg = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0634);
                                else if (sState == "R") sStateMsg = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0358);

                                dgvData.Rows[iRow].Cells[1].Value = sStateMsg;                                                                          // 구분
                                dgvData.Rows[iRow].Cells[2].Value = m_cPosStatus.Global.NumericTOCurrency(m_cDataService.DoubleParse(aRet[index++].Trim()));    // 사용금액
                                dgvData.Rows[iRow].Cells[3].Value = m_cPosStatus.Global.NumericTOCurrency(m_cDataService.DoubleParse(aRet[index++].Trim()));    // 잔액
                                dgvData.Rows[iRow].Cells[4].Value = aRet[index++].Trim();                                                               // 사용일시
                                dgvData.Rows[iRow].Cells[5].Value = aRet[index++].Trim();                                                               // 매장코드
                                dgvData.Rows[iRow].Cells[6].Value = aRet[index++].Trim();                                                               // 매장명
                            }
                        }
                    }
                    #endregion 
                }
                dgvData.Refresh();
                dgvData.Select();

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