using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Runtime.InteropServices;
using System.IO;

using Cosmos.BaseFrame;
using Cosmos.UserFrame;
using Cosmos.ServiceProvider;
using Cosmos.Common;
using Cosmos.CommonManager;
using Cosmos.UI;
using System.Threading;

//#16569 파스쿠찌 드라이브 스루 기능 개발 요청 start
/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 드라이브 스루 고객 화면
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Service
{
    public partial class frmCustDisplayPipeDT : Form
    {

        #region Variable
        private SManager sManager = new SManager();                                 //이 객체를 통해 업무 Service 호출
        private StateServer StateObject = (StateServer)StateServer.GetInstance();   //StateObject : StateServer Object(객체)
        private PosStatus m_cPosStatus = new PosStatus();                           //기본정보 참조
        private TranStatus m_cTrnStatus = new TranStatus();                         //거래정보 참조

        private IMasterUs m_cMstService = null;                                     //마스터 관리

        private ArrayList m_alMediaTop = new ArrayList();                           // 상단이미지 리스트
        private ArrayList m_alMediaBtm = new ArrayList();                           // 하단이미지 리스트
        private int m_nMediaTopPos = 0;
        private int m_nMediaBtmPos = 0;

        //#20180830 드라이브스루 고객용 모니터 start - 20180907
        private int iRow_Height = 0;
        //#20180830 드라이브스루 고객용 모니터 end - 20180907

        /// <summary>
        /// 캠페인 미디어 표시 여부
        /// </summary>
        private bool m_bMediaCampaign = false;  
        /// <summary>
        /// 캠페인 미디어 구분
        /// </summary>               
        public string m_sCampaignFileDiv = "";
        /// <summary>
        /// 캠페인 미디어 파일명
        /// </summary>
        public string m_sCampaignFileName = "";

        #region FFMPEG 설정 관련 변수

        private string m_sDispWork1 = PosConst.CUST_WOKRING.STOP;   //디스플레이 1 상태값
        private string m_sDispWork2 = PosConst.CUST_WOKRING.STOP;   //디스플레이 2 상태값
        
        private PipeServer _pipeServer; //파이프 서버
        private PipeClient _pipeClient; //파이프 클라언트
                
        #endregion

        #endregion

        #region 생성자 및 소멸자
        public frmCustDisplayPipeDT()
        {
            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_cMstService = (IMasterUs)sManager.InitServiceInstance(ServiceLists.ASV_MASTER.DLL, ServiceLists.ASV_MASTER.POS_MASTER);
        }

        private void frmCustDisplayPipeDT_FormClosing(object sender, FormClosingEventArgs e)
        {
            PipeClear();
            UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", "");
        }

        private void frmCustDisplayPipeDT_Load(object sender, EventArgs e)
        {
            // 컨트롤 초기화
            InitControl();
            // 그리드 초기화
            InitializeGrid();
            // 상품정보 초기화
            ClearSaleItemList();

            StartCustPipe();
        }

        private void frmCustDisplayPipeDT_LocationChanged(object sender, EventArgs e)
        {
            try
            {
                // 폼 크기 설정
                //this.Location = new Point((int)m_cPosStatus.Sale.ScreenSizeUser, 0);
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        #endregion

        #region 컨트롤 및 그리드 초기화
        /// <summary>
        /// 폼 컨트롤 초기화
        /// </summary>
        private void InitControl()
        {
            try
            {
                FormManager.SetFormAllControlFont(this, m_cPosStatus.Base.FONT);

                //////////////////////////////////////////////////////////////////////////////////////
                // 폼 크기 설정
                this.Location = new Point((int)m_cPosStatus.Sale.ScreenSizeUser, 0);

                /*
                picLogo.Image = ImageManager.GetImage(BaseCom.NxCDPPath + PosConst.MST_IMG_PATH.CDP_COM, m_cPosStatus.ScnMst.BrandCiImg);
                if (picLogo.Image != null)
                    CmUtil.FileCopy(BaseCom.NxCDPPath + PosConst.MST_IMG_PATH.CDP_COM + m_cPosStatus.ScnMst.BrandCiImg, BaseCom.NxCDPPath + PosConst.MST_IMG_PATH.CDP_COM + ImageManager.BRADN_CI, false);
                else
                    picLogo.Image = ImageManager.GetImage(BaseCom.NxCDPPath + PosConst.MST_IMG_PATH.CDP_COM, ImageManager.BRADN_CI);
                */

                this.Size = new Size(768, 1024);

                picLogo.BringToFront();
                panel1.BringToFront();

                FormManager.SetControlSize(pnlRecvAmt, 0, 1059, 768, 115);
                FormManager.SetControlSize(pnlPay, 0, 0, 768, 115);

                //FormManager.SetControlSize(lblQty, 310, 217, 135, 37);  // 총 수량 label
                //FormManager.SetControlSize(lblDiscountAmt, 451, 217, 145, 37);  // 총 할인 label
                //FormManager.SetControlSize(lblQtySaleAmt, 601, 217, 154, 37);   // 총 금액 label
                //FormManager.SetControlSize(lblNetSaleAmt, 91, 211, 116, 42);    // 결제금액 label

                //FormManager.SetControlSize(txtQty, 311, 270, 134, 72);    // 총 수량 text
                //FormManager.SetControlSize(txtDiscountAmt, 451, 270, 145, 72);  //총 할인 text
                //FormManager.SetControlSize(txtQtySaleAmt, 602, 270, 153, 72);   //총 금액 text
                
                //FormManager.SetControlSize(txtRecvAmt, 179, 77, 275, 30);
                //FormManager.SetControlSize(txtNetSaleAmt, 14, 260, 270, 82);

                lblRecvAmt.Visible = false;
                txtRecvAmt.Visible = false;

                lblVatSvc.Visible = false;
                txtVatSvc.Visible = false;
                  
                FormManager.SetControlSize(lblHappyPoint, 0, 0, 300, 150);
                FormManager.SetControlSize(lstPaymentList, 300, 0, 468, 150);
                FormManager.SetControlSize(lstForeignList, 300, 82, 468, 67); 

                lstPaymentList.Columns.Clear();
                lstPaymentList.Columns.Add("PAY_NO", 0, HorizontalAlignment.Left);
                lstPaymentList.Columns.Add("PAY_NM", 260, HorizontalAlignment.Left);
                lstPaymentList.Columns.Add("PAY_AMT", 190, HorizontalAlignment.Right);

                lstForeignList.Columns.Clear();
                lstForeignList.Columns.Add("PAY_NO", 0, HorizontalAlignment.Left);
                lstForeignList.Columns.Add("PAY_NM", 260, HorizontalAlignment.Left);
                lstForeignList.Columns.Add("PAY_AMT", 190, HorizontalAlignment.Right);

                FormManager.SetControlSize(pnlSaleItemGrid, 0, 254, 768, 654);
                FormManager.SetControlSize(SaleItemGrid, 0, 0, 768, 654);

                //#20180830 드라이브스루 고객용 모니터 start - 20180907
                //기존
                //SaleItemGrid.DisplayItemCount = 12;
                //변경
                SaleItemGrid.DisplayItemCount = 9;
                //#20180830 드라이브스루 고객용 모니터 end - 20180907
                

                lblHappyPoint.Visible = false;
                lstPaymentList.Visible = false;

                //////////////////////////////////////////////////////////////////////////////////////
                // 테마 컬러 설정
                if (m_cPosStatus.ScnMst.ThemeColor.Length == 9)
                {
                    Color colThema = CmUtil.GetColorToString(m_cPosStatus.ScnMst.ThemeColor);

                    int nRed = CmUtil.IntParse(m_cPosStatus.ScnMst.ThemeColor.Substring(0, 3)) - 20;
                    if (nRed < 0) nRed = 0;
                    int nGreen = CmUtil.IntParse(m_cPosStatus.ScnMst.ThemeColor.Substring(3, 3)) - 20;
                    if (nGreen < 0) nGreen = 0;
                    int nBlue = CmUtil.IntParse(m_cPosStatus.ScnMst.ThemeColor.Substring(6, 3)) - 20;
                    if (nBlue < 0) nBlue = 0;
                }

                // 라벨 초기화 및 다국어 처리
                lblQty.Text = "총 수량"; //PosConst.SALE_DISP_SPCL_CHAR.QTY_AMT_CHR + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0035);
                lblQtySaleAmt.Text = "총 금액"; //PosConst.SALE_DISP_SPCL_CHAR.QTY_AMT_CHR + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0035);
                lblDiscountAmt.Text = "총 할인"; //PosConst.SALE_DISP_SPCL_CHAR.DC_AMT_CHR + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0036);
                lblVatSvc.Text = ""; // PosConst.SALE_DISP_SPCL_CHAR.VAT_SVC_CHR + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0981);
                lblRecvAmt.Text = ""; // PosConst.SALE_DISP_SPCL_CHAR.RECV_AMT_CHR + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0349);
                //lblNetSaleAmt.Text = m_cPosStatus.Global.m_stCultureMaster.strCurrencySymbol + " " + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0350);
                lblNetSaleAmt.Text = "결제금액"; //MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0350);
                                
                ReSizeMdiaTop(true);
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }


        /// <summary>
        /// 폼 컨트롤 초기화
        /// </summary>
        private void ReSizeMdiaTop(bool bFull)
        {
            try
            {
                // 고객용동영상 관련(0:사용안함, 1:사용함(고정), 2:사용함(가변))
                if (PosMstManager.GetPosOption(POS_OPTION.OPT103) != "2") return;

                /*
                if (m_cPosStatus.Sale.ScreenSizeCust == 1024)
                {
                    if (bFull == true)
                    {
                        if (pnlMediaTop.Width == 1024) return;
                        FormManager.SetControlSize(pnlMediaTop, 0, 50, 1024, 768 - 50);
                    }
                    else
                    {
                        if (pnlMediaTop.Width == 558) return;
                        FormManager.SetControlSize(pnlMediaTop, 0, 50, 558, 359);
                    }
                }
                else
                {
                    if (bFull == true)
                    {
                        if (pnlMediaTop.Width == 800) return;
                        FormManager.SetControlSize(pnlMediaTop, 0, 50, 800, 600 - 50);
                    }
                    else
                    {
                        if (pnlMediaTop.Width == 435) return;
                        FormManager.SetControlSize(pnlMediaTop, 0, 50, 435, 275);
                    }
                }

                picMediaTop.Location = new Point(0, 0);
                picMediaTop.Size = pnlMediaTop.Size;
                //wmpMediaTop.Location = new Point(0, 0);
                //wmpMediaTop.Size = pnlMediaTop.Size;
                */
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }


        /// <summary>
        /// 그리드 초기화
        /// </summary>
        private void InitializeGrid()
        {
            try
            {
                int[] arGridItemWidth;

                //FormManager.SetControlSize(pnlSaleItemGrid, 0, 254, 768, 623);
                //FormManager.SetControlSize(SaleItemGrid, 0, 0, 768, 623);
                //SaleItemGrid.DisplayItemCount = 11;

                arGridItemWidth = new int[] { 10, 310, 100, 150, 190, 10 };

                // Set Item Data Grid Information
                
                SaleItemGrid.GapSize = 0;
                //SaleItemGrid.BackColor = Color.Black;
                SaleItemGrid.GridDataHeaderHeight = 0;
                
                //#20180830 드라이브스루 고객용 모니터 start - 20180907
                iRow_Height = (pnlSaleItemGrid.Height - lblHappyPoint.Height) / 6; //84
                //#20180830 드라이브스루 고객용 모니터 end - 20180907

            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
        #endregion

        #region StartCustDisplay(고객용 컨텐츠 로딩 처리)
        /// <summary>
        /// 고객용 컨텐츠 로딩 처리
        /// </summary>
        public void StartCustDisplay()
        {
            string sQuery = "";
            try
            {
                string sInfoText;
                if (m_cPosStatus.Mst.CdpUseYn == "1")
                    sInfoText = m_cPosStatus.Mst.CdpMessage;
                else
                    sInfoText = string.Format(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0245), CmUtil.GetDataRowStr(PosMstManager.GetMstStore(), PosMst.MST_STORE.DATA.STORNM));

                Cosmos.UI.CsmPosMovePanel.MovePanelInfo cMoveInfo = new Cosmos.UI.CsmPosMovePanel.MovePanelInfo();

                cMoveInfo.BackColor = Color.FromArgb(37, 37, 37);
                cMoveInfo.ForeColor = Color.White;
                cMoveInfo.MoveKind = "1";           // 0:좌->우, 1:우->좌, 4:깜박임
                cMoveInfo.MoveText = sInfoText;
                cMoveInfo.ResvCode = "";

                m_nMediaTopPos = 0;
                m_nMediaBtmPos = 0;

                m_alMediaTop.Clear();
                m_alMediaBtm.Clear();

                // 마스터 고객화면 로딩
                sQuery = " SELECT * FROM POSMST..MST_CUST_DSP ";
                sQuery += " WHERE CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                sQuery += "   AND STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                //sQuery += "   AND '" + m_cPosStatus.Base.SaleDate + "' BETWEEN START_DT AND FNSH_DT ";
                sQuery += "   AND '" + DateTime.Now.ToString("yyyyMMdd") + "' BETWEEN START_DT AND FNSH_DT ";
                sQuery += "   AND USE_YN  = '" + PosConst.MST_USE_YN.YES + "'";
                sQuery += " ORDER BY DISP_DIV DESC, SEQ ";

                DataTable dtDspData = m_cMstService.Select(new string[] { sQuery });
                if (dtDspData == null || dtDspData.Rows.Count == 0) return;

                foreach (DataRow dr in dtDspData.Rows)
                {
                    if (CmUtil.GetDataRowStr(dr, PosMst.MST_CUST_DSP.DATA.DISP_KIND) != "1" && CmUtil.GetDataRowStr(dr, PosMst.MST_CUST_DSP.DATA.DISP_KIND) != "2") continue; // 표시종류(1:메인, 2:컨텐츠)

                    string sDow = CmUtil.GetDataRowStr(dr, PosMst.MST_CUST_DSP.DATA.DOW);
                    if (sDow.Length >= 7)
                    {
                        DateTime dt = new DateTime(int.Parse(m_cPosStatus.Base.SaleDate.Substring(0, 4)), int.Parse(m_cPosStatus.Base.SaleDate.Substring(4, 2)), int.Parse(m_cPosStatus.Base.SaleDate.Substring(6, 2)));

                        if (sDow.Substring((int)dt.DayOfWeek, 1) == "0") continue;
                    }

                    if (CmUtil.GetDataRowStr(dr, PosMst.MST_CUST_DSP.DATA.DISP_KIND) == "1")         // 표시종류(1:메인, 2:컨텐츠)
                    {
                        // 파일구분(1:이미지,2:동영상), 표시시간, 파일명
                        m_alMediaTop.Add(new string[] { CmUtil.GetDataRowStr(dr, PosMst.MST_CUST_DSP.DATA.FILE_TYPE)
                                                      , CmUtil.GetDataRowStr(dr, PosMst.MST_CUST_DSP.DATA.FILE_TIME)
                                                      , CmUtil.GetDataRowStr(dr, PosMst.MST_CUST_DSP.DATA.FILE_NM) 
                                                      , CmUtil.GetDataRowStr(dr, PosMst.MST_CUST_DSP.DATA.START_HOUR)
                                                      , CmUtil.GetDataRowStr(dr, PosMst.MST_CUST_DSP.DATA.FNSH_HOUR)});
                    }
                    else if (CmUtil.GetDataRowStr(dr, PosMst.MST_CUST_DSP.DATA.DISP_KIND) == "2")
                    {
                        // 파일구분(1:이미지,2:동영상), 표시시간, 파일명
                        m_alMediaBtm.Add(new string[] { CmUtil.GetDataRowStr(dr, PosMst.MST_CUST_DSP.DATA.FILE_TYPE)
                                                      , CmUtil.GetDataRowStr(dr, PosMst.MST_CUST_DSP.DATA.FILE_TIME)
                                                      , CmUtil.GetDataRowStr(dr, PosMst.MST_CUST_DSP.DATA.FILE_NM) 
                                                      , CmUtil.GetDataRowStr(dr, PosMst.MST_CUST_DSP.DATA.START_HOUR)
                                                      , CmUtil.GetDataRowStr(dr, PosMst.MST_CUST_DSP.DATA.FNSH_HOUR)});
                    }
                }

                DisplayMediaTop();
                DisplayMediaBtm();

                tmrMedia.Enabled = true;
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
        #endregion
                
        #region  DisplayMedia(컨텐츠 표시)

        //public delegate void NewMessageDelegate();
        
        /// <summary>
        /// 상단 컨텐츠 표시
        /// </summary>
        public void DisplayMediaTop()
        {
            try
            {
                if (m_alMediaTop.Count <= 0) return;

                if (m_nMediaTopPos >= m_alMediaTop.Count) m_nMediaTopPos = 0;

                // 파일구분(1:이미지,2:동영상), 표시시간, 파일명
                string[] saMedia = (string[])m_alMediaTop[m_nMediaTopPos];
                if (File.Exists(BaseCom.NxCDPPath + PosConst.MST_IMG_PATH.CUSTOMER + saMedia[2]) == false)
                {
                    return;
                }
                if (saMedia[3].Length >= 6 && saMedia[4].Length >= 6)
                {
                    if (CmUtil.IntParse(saMedia[3]) > CmUtil.IntParse(DateTime.Now.ToString("HHmmss")) || CmUtil.IntParse(saMedia[4]) < CmUtil.IntParse(DateTime.Now.ToString("HHmmss"))) return;
                }

                //PipesMessageSend(PosConst.CUST_TRAN_ID.PIC1, BaseCom.NxCDPPath + PosConst.MST_IMG_PATH.CUSTOMER + saMedia[2], saMedia[0] == PosConst.MEDIA_FILE_DIV.IMAGE ? PosConst.CUST_WOKRING.STOP : PosConst.CUST_WOKRING.PLAY, "N");

            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        /// <summary>
        /// 하단 컨텐츠 표시
        /// </summary>
        public void DisplayMediaBtm()
        {
            try
            {
                m_bMediaCampaign = false;

                if (m_alMediaBtm.Count <= 0) return;

                if (m_nMediaBtmPos >= m_alMediaBtm.Count) m_nMediaBtmPos = 0;

                // 파일구분(1:이미지,2:동영상), 표시시간, 파일명
                string[] saMedia = (string[])m_alMediaBtm[m_nMediaBtmPos];
                if (File.Exists(BaseCom.NxCDPPath + PosConst.MST_IMG_PATH.CUSTOMER + saMedia[2]) == false) return;

                if (CmUtil.IntParse(saMedia[3]) > CmUtil.IntParse(DateTime.Now.ToString("HHmmss")) || CmUtil.IntParse(saMedia[4]) < CmUtil.IntParse(DateTime.Now.ToString("HHmmss"))) return;

                //PipesMessageSend(PosConst.CUST_TRAN_ID.PIC2, BaseCom.NxCDPPath + PosConst.MST_IMG_PATH.CUSTOMER + saMedia[2], saMedia[0] == PosConst.MEDIA_FILE_DIV.IMAGE ? PosConst.CUST_WOKRING.STOP : PosConst.CUST_WOKRING.PLAY, "N");

            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, 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 tmrMedia_Tick(object sender, EventArgs e)
        {
            try
            {
                tmrMedia.Enabled = false;

                CheckPipeServer();
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
            tmrMedia.Enabled = true;
        }

        /// <summary>
        /// 파이프 서버 체크
        /// </summary>
        private void CheckPipeServer()
        {
            try
            {
                //#20180626 파이프 서버 체크시 null 여부 로그 추가 start
                //기존
                /*
                if (_pipeServer.PipeConnected == false)
                    StartCustPipe();
                */
                //변경
                if (_pipeServer != null)
                {
                    if (_pipeServer.PipeConnected == false)
                        StartCustPipe();
                }
                else
                {
                    UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                         System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", "_pipeServer = null");
                }
                //#20180626 파이프 서버 체크시 null 여부 로그 추가 end
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
        

        #endregion

        #region StopCustDisplay(컨텐츠 표시 종료)
        /// <summary>
        /// 컨텐츠 표시 종료
        /// </summary>
        public void StopCustDisplay()
        {
            try
            {
                //wmpMediaTop.Ctlcontrols.stop();
                //wmpMediaTop.URL = "";
                //wmpMediaBtm.Ctlcontrols.stop();
                //wmpMediaBtm.URL = "";
                tmrMedia.Enabled = false;

                //StopCustPipe();
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
        #endregion

        #region 캠페인 컨텐츠 표시

        /// <summary>
        /// 캠페인 컨텐츠 표시
        /// </summary>
        public void DisplayCampaign(string sFileDiv, string sFileName)
        {
            try
            {
                string sFullFileName = BaseCom.NxCDPPath + PosConst.MST_IMG_PATH.CAMPAIGN + sFileName;

                if (sFileName == "" || File.Exists(sFullFileName) == false)
                {
                    if (m_bMediaCampaign == true) DisplayMediaBtm();
                    return;
                }

                //PipesMessageSend(PosConst.CUST_TRAN_ID.PIC2, sFullFileName, sFileDiv == PosConst.MEDIA_FILE_DIV.IMAGE ? PosConst.CUST_WOKRING.STOP : PosConst.CUST_WOKRING.PLAY, "N");
                
                m_bMediaCampaign = true;
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
        #endregion

        #region 상품등록 정보 화면 표시
        /// <summary>
        /// 상품 정보 클리어
        /// </summary>
        public void ClearSaleItemList()
        {
            try
            {
                ReSizeMdiaTop(true);

                // 그리드 초기화
                SaleItemGrid.RemoveAll();
                
                // 판매 금액 초기화
                txtQtySaleAmt.Text = "0";
                txtQty.Text = "0";
                txtDiscountAmt.Text = "0";
                txtNetSaleAmt.Text = "0";
                txtRecvAmt.Text = "0";
                txtVatSvc.Text = "0";
                
                // 결제리스트 초기화
                lstPaymentList.Items.Clear();

                //if (m_bMediaCampaign == true) DisplayMediaBtm();

                //m_bMediaCampaign = false;

                tmrDisplayInit.Enabled = false;
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        /// <summary>
        /// 상품등록 정보 화면 표시
        /// </summary>
        public void DisplaySaleItemList(bool bPluDisp, bool bPayDisp, string sForeignInfo, int nSelRow)
        {
            try
            {
                //#20170905 미군기지 환율 표시 start
                double dUsarmyEx = CmUtil.DoubleParse(CmUtil.IsNull(PosMstManager.GetPosOption(POS_OPTION.OPT509), "0"));
                double dTotDcAmtItem = 0;
                double dBillAmtItem = 0;
                //#20170905 미군기지 환율 표시 end

                ReSizeMdiaTop(false);

                if (bPluDisp == true)// || bPluDisp == false
                {
                    // 그리드 초기화
                    //SaleItemGrid.RemoveAll();

                    int[] arGridItemWidth;

                    arGridItemWidth = new int[] { 10, 310, 100, 150, 190, 10 };
                    
                    //#20180830 드라이브스루 고객용 모니터 start - 20180907
                    //기존
                    //int[] arFontSize = new int[] { 17, 17, 17, 18, 18, 17 };
                    //변경
                    int[] arFontSize = new int[] { 20, 20, 20, 21, 21, 20 };
                    //#20180830 드라이브스루 고객용 모니터 end - 20180907

                    Hashtable htSaleItemGrid = SaleItemGrid.GridDataItems;          //그리드 데이터

                    ArrayList alPluItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);

                    int nGridDataCount = 0;
                    for (int iRow = 0; iRow < alPluItem.Count; iRow++)
                    {
                        Column.TR_PLU.DATA cItem = (Column.TR_PLU.DATA)alPluItem[iRow];

                        bool bCancelDiv = false;
                        if (cItem.CANCEL_DIV == "1" || cItem.CANCEL_DIV_MAIN == "1") bCancelDiv = true;

                        if (bCancelDiv == true && m_cPosStatus.Sale.DutchPayFlg == "1") continue;

                        //#20170905 미군기지 환율 표시 start
                        if (dUsarmyEx > 0)
                        {
                            dTotDcAmtItem = CmUtil.MathRounds(cItem.TOT_DC_AMT / dUsarmyEx, PosConst.MATH_ROUND.ROUND, 2);
                            dBillAmtItem = CmUtil.MathRounds(cItem.BILL_AMT / dUsarmyEx, PosConst.MATH_ROUND.CEILING, 2);
                        }
                        //#20170905 미군기지 환율 표시 end

                        nGridDataCount++;
                        if (SaleItemGrid.GetItemCount() > iRow)
                        {
                            GridDataItem cGridDataItem = (GridDataItem)htSaleItemGrid[iRow];
                            CsmGridExRowData cGridExRowData;

                            // 과세구분
                            cGridExRowData = (CsmGridExRowData)cGridDataItem.GridItemData[0];
                            cGridExRowData.GridItemText = cItem.ITEM_TAX_DIV == PosConst.ITEM_TAX_DIV.FREE || cItem.NOTAX_DIV == PosConst.ITEM_NOTAX_DIV.YES ? "*" : "";
                            cGridExRowData.StrikeThrough = bCancelDiv;
                            cGridExRowData.GridItemValue = cItem.ITEM_TAX_DIV == PosConst.ITEM_TAX_DIV.FREE || cItem.NOTAX_DIV == PosConst.ITEM_NOTAX_DIV.YES ? "*" : "";

                            // 상품명
                            cGridExRowData = (CsmGridExRowData)cGridDataItem.GridItemData[1];
                            cGridExRowData.GridItemText = cItem.ITEM_NAME;
                            cGridExRowData.StrikeThrough = bCancelDiv;
                            cGridExRowData.GridItemValue = cItem.ITEM_PLU_CD;
                           
                            // 수량
                            cGridExRowData = (CsmGridExRowData)cGridDataItem.GridItemData[2];
                            cGridExRowData.GridItemText = cItem.SALE_QTY.ToString();
                            cGridExRowData.GridItemValue = cItem.SALE_QTY.ToString();
                            cGridExRowData.StrikeThrough = bCancelDiv;
                            // 할인
                            cGridExRowData = (CsmGridExRowData)cGridDataItem.GridItemData[3];

                            //#20170905 미군기지 환율 표시 start
                            //기존
                            //cGridExRowData.GridItemText = m_cPosStatus.Global.NumericTOCurrency(cItem.TOT_DC_AMT);
                            //cGridExRowData.GridItemValue = cItem.TOT_DC_AMT.ToString();
                            //변경
                            if (dUsarmyEx > 0)
                            {
                                cGridExRowData.GridItemText = dTotDcAmtItem.ToString();
                                cGridExRowData.GridItemValue = dTotDcAmtItem.ToString();
                            }
                            else
                            {
                                cGridExRowData.GridItemText = m_cPosStatus.Global.NumericTOCurrency(cItem.TOT_DC_AMT);
                                cGridExRowData.GridItemValue = cItem.TOT_DC_AMT.ToString();
                            }
                            //#20170905 미군기지 환율 표시 end
                            cGridExRowData.StrikeThrough = bCancelDiv;

                            // 금액
                            cGridExRowData = (CsmGridExRowData)cGridDataItem.GridItemData[4];
                            //#20170905 미군기지 환율 표시 start
                            //기존
                            //cGridExRowData.GridItemText = m_cPosStatus.Global.NumericTOCurrency(cItem.BILL_AMT);
                            //cGridExRowData.GridItemValue = cItem.BILL_AMT.ToString();
                            //변경
                            if (dUsarmyEx > 0)
                            {
                                cGridExRowData.GridItemText = dBillAmtItem.ToString();
                                cGridExRowData.GridItemValue = dBillAmtItem.ToString();
                            }
                            else
                            {
                                cGridExRowData.GridItemText = m_cPosStatus.Global.NumericTOCurrency(cItem.BILL_AMT);
                                cGridExRowData.GridItemValue = cItem.BILL_AMT.ToString();
                            }
                            //#20170905 미군기지 환율 표시 end
                            cGridExRowData.StrikeThrough = bCancelDiv;
                        }
                        else
                        {
                            // Row Item
                            GridDataItem cGridDataItem = new GridDataItem();
                            cGridDataItem.GridItemBackColor = Color.Black;
                            cGridDataItem.GridItemBackColorClick = Color.Black;
                            cGridDataItem.GridItemBackImage = null;
                            cGridDataItem.GridItemBackImageClick = null;
                            cGridDataItem.GridItemData = new System.Collections.Hashtable();

                            CsmGridExRowData cGridExRowData;

                            // 과세 구분
                            cGridExRowData = new CsmGridExRowData();
                            cGridExRowData.GridItemWidth = arGridItemWidth[0];
                            cGridExRowData.HStringAlignment = StringAlignment.Near;
                            cGridExRowData.VStringAlignment = StringAlignment.Center;
                            cGridExRowData.GridItemText = cItem.ITEM_TAX_DIV == PosConst.ITEM_TAX_DIV.FREE || cItem.NOTAX_DIV == PosConst.ITEM_NOTAX_DIV.YES ? "*" : "";
                                                       

                            cGridExRowData.GridItemValue = cItem.ITEM_TAX_DIV == PosConst.ITEM_TAX_DIV.FREE || cItem.NOTAX_DIV == PosConst.ITEM_NOTAX_DIV.YES ? "*" : "";
                            cGridExRowData.ForeColor = Color.Red;
                            cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                            cGridExRowData.FontSize = arFontSize[0];
                            cGridExRowData.FontStyle = FontStyle.Regular;
                            cGridExRowData.StrikeThrough = bCancelDiv;
                            cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);

                            // 상품명
                            cGridExRowData = new CsmGridExRowData();
                            cGridExRowData.GridItemWidth = arGridItemWidth[1];
                            cGridExRowData.HStringAlignment = StringAlignment.Near;
                            cGridExRowData.VStringAlignment = StringAlignment.Center;
                            cGridExRowData.GridItemText = cItem.ITEM_NAME;

                            cGridExRowData.GridItemValue = cItem.ITEM_PLU_CD;
                            cGridExRowData.ForeColor = Color.White;
                            cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                            cGridExRowData.FontSize = arFontSize[1];
                            cGridExRowData.FontStyle = FontStyle.Regular;
                            cGridExRowData.StrikeThrough = bCancelDiv;
                            cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);

                            // 수량
                            cGridExRowData = new CsmGridExRowData();
                            cGridExRowData.GridItemWidth = arGridItemWidth[2];
                            cGridExRowData.HStringAlignment = StringAlignment.Far;
                            cGridExRowData.VStringAlignment = StringAlignment.Center;
                            cGridExRowData.GridItemText = cItem.SALE_QTY.ToString();

                            cGridExRowData.GridItemValue = cItem.SALE_QTY.ToString();
                            cGridExRowData.ForeColor = Color.White;
                            cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                            cGridExRowData.FontSize = arFontSize[2];
                            cGridExRowData.FontStyle = FontStyle.Regular;
                            cGridExRowData.StrikeThrough = bCancelDiv;
                            cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);

                            // 할인
                            cGridExRowData = new CsmGridExRowData();
                            cGridExRowData.GridItemWidth = arGridItemWidth[3];
                            cGridExRowData.HStringAlignment = StringAlignment.Far;
                            cGridExRowData.VStringAlignment = StringAlignment.Center;

                            //#20170905 미군기지 환율 표시 start
                            //기존
                            //cGridExRowData.GridItemText = m_cPosStatus.Global.NumericTOCurrency(cItem.TOT_DC_AMT);
                            //cGridExRowData.GridItemValue = cItem.TOT_DC_AMT.ToString();
                            //변경
                            if (dUsarmyEx > 0)
                            {
                                cGridExRowData.GridItemText = dTotDcAmtItem.ToString();
                                cGridExRowData.GridItemValue = dTotDcAmtItem.ToString();
                            }
                            else
                            {
                                cGridExRowData.GridItemText = m_cPosStatus.Global.NumericTOCurrency(cItem.TOT_DC_AMT);
                                cGridExRowData.GridItemValue = cItem.TOT_DC_AMT.ToString();
                            }
                            //#20170905 미군기지 환율 표시 end


                            cGridExRowData.ForeColor = Color.White;
                            cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                            cGridExRowData.FontSize = arFontSize[3];
                            cGridExRowData.FontStyle = FontStyle.Regular;
                            cGridExRowData.StrikeThrough = bCancelDiv;
                            cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);

                            // 금액
                            cGridExRowData = new CsmGridExRowData();
                            cGridExRowData.GridItemWidth = arGridItemWidth[4];
                            cGridExRowData.HStringAlignment = StringAlignment.Far;
                            cGridExRowData.VStringAlignment = StringAlignment.Center;

                            //#20170905 미군기지 환율 표시 start
                            //기존
                            //cGridExRowData.GridItemText = m_cPosStatus.Global.NumericTOCurrency(cItem.BILL_AMT);
                            //cGridExRowData.GridItemValue = cItem.BILL_AMT.ToString();
                            //변경
                            if (dUsarmyEx > 0)
                            {
                                cGridExRowData.GridItemText = dBillAmtItem.ToString();
                                cGridExRowData.GridItemValue = dBillAmtItem.ToString();
                            }
                            else
                            {
                                cGridExRowData.GridItemText = m_cPosStatus.Global.NumericTOCurrency(cItem.BILL_AMT);
                                cGridExRowData.GridItemValue = cItem.BILL_AMT.ToString();
                            }
                            //#20170905 미군기지 환율 표시 end

                            cGridExRowData.ForeColor = Color.White;
                            cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                            cGridExRowData.FontSize = arFontSize[4];
                            cGridExRowData.FontStyle = FontStyle.Regular;
                            cGridExRowData.StrikeThrough = bCancelDiv;

                            cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);


                            //#20180830 드라이브스루 고객용 모니터 start - 20180907
                            //기존
                            //SaleItemGrid.AddDataGridItem(cGridDataItem, GRID_EX_ITEM_BORDER_STYLE.NONE, 1, Color.Gray);
                            //변경
                            SaleItemGrid.AddDataGridItem(cGridDataItem, GRID_EX_ITEM_BORDER_STYLE.ALL, 1, Color.Black);
                            //#20180830 드라이브스루 고객용 모니터 end - 20180907
                            
                        }
                    }

                    if (SaleItemGrid.GridDataItems.Count > nGridDataCount)
                    {
                        while (SaleItemGrid.GridDataItems.Count > nGridDataCount)
                        {
                            SaleItemGrid.RemoveAt(SaleItemGrid.GridDataItems.Count - 1);
                        }
                    }

                    SaleItemGrid.SelectIndexItem(SaleItemGrid.GridDataItems.Count - 1);
                    SaleItemGrid.Refresh();
                }

                // 총수량
                txtQty.Text = m_cPosStatus.Global.NumericToQuantity(m_cTrnStatus.Head.TotQty);

                // 총매출액
                txtQtySaleAmt.Text = m_cPosStatus.Global.NumericTOCurrency(m_cTrnStatus.Head.TotSaleAmt * (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL ? 1 : -1));
                // 총 할인 금액
                txtDiscountAmt.Text = m_cPosStatus.Global.NumericTOCurrency(m_cTrnStatus.Head.TotDcAmt * (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL ? 1 : -1));

                // 부가세+봉사료
                txtVatSvc.Text = m_cPosStatus.Global.NumericTOCurrency(CmUtil.DoubleAdd(m_cTrnStatus.Head.SvcFeeAmt, m_cPosStatus.Mst.TaxAmtIncludeYn == ItemConst.TAX_AMT_INCLUDE_YN.NOT_INCLUDED ? m_cTrnStatus.Head.SvcFeeVat : 0))
                        + m_cPosStatus.Global.m_stCultureMaster.strCurrencyName + "/ "
                        + m_cPosStatus.Global.NumericTOCurrency(m_cTrnStatus.Head.TotVatAmt) + m_cPosStatus.Global.m_stCultureMaster.strCurrencyName;

                // 내신금액 표시
                txtRecvAmt.Text = m_cPosStatus.Global.NumericTOCurrency(m_cPosStatus.Sale.PayRecvedAmt * (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL ? 1 : -1))
                        + m_cPosStatus.Global.m_stCultureMaster.strCurrencyName;

                //lblNetSaleAmt.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0350);
                // 내실금액 표시 처리
                txtNetSaleAmt.Text = m_cPosStatus.Global.NumericTOCurrency(m_cTrnStatus.Sale.RemainPayAmt * (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL ? 1 : -1));


                //#20170905 미군기지 환율 표시 start
                //미군기지 환율 사용인 경우 달러로 표기
                if (dUsarmyEx > 0)
                {
                    //총 매출액
                    double dTotSaleAmt = CmUtil.MathRounds(m_cTrnStatus.Head.TotSaleAmt / dUsarmyEx, PosConst.MATH_ROUND.CEILING, 2);
                    //총 할인금액
                    double dTotDcAmt = CmUtil.MathRounds(m_cTrnStatus.Head.TotDcAmt / dUsarmyEx, PosConst.MATH_ROUND.ROUND, 2);
                    //총 봉사료
                    double dSvcFeeTemp = CmUtil.DoubleAdd(m_cTrnStatus.Head.SvcFeeAmt, m_cPosStatus.Mst.TaxAmtIncludeYn == ItemConst.TAX_AMT_INCLUDE_YN.NOT_INCLUDED ? m_cTrnStatus.Head.SvcFeeVat : 0);
                    double dSvcFee = CmUtil.MathRounds(dSvcFeeTemp / dUsarmyEx, PosConst.MATH_ROUND.ROUND, 2);
                    //총 부가세
                    double dTotVatAmt = CmUtil.MathRounds(m_cTrnStatus.Head.TotVatAmt / dUsarmyEx, PosConst.MATH_ROUND.CEILING, 2);
                    //내신금액
                    double dRecvAmt = CmUtil.MathRounds(m_cPosStatus.Sale.PayRecvedAmt / dUsarmyEx, PosConst.MATH_ROUND.ROUND, 2);
                    //내실금액
                    double dRemainPayAmt = CmUtil.MathRounds(m_cTrnStatus.Sale.RemainPayAmt / dUsarmyEx, PosConst.MATH_ROUND.ROUND, 2);

                    // 총수량
                    txtQtySaleAmt.Text = m_cPosStatus.Global.NumericToQuantity(m_cTrnStatus.Head.TotQty);
                    // 총매출액
                    txtQtySaleAmt.Text = (dTotSaleAmt * (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL ? 1 : -1)).ToString();
                    // 총 할인 금액
                    txtDiscountAmt.Text = (dTotDcAmt * (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL ? 1 : -1)).ToString();
                    // 부가세+봉사료
                    txtVatSvc.Text = dSvcFee.ToString() + "/ " + dTotVatAmt.ToString();
                    // 내신금액 표시
                    txtRecvAmt.Text = (dRecvAmt * (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL ? 1 : -1)).ToString() ;
                    //lblNetSaleAmt.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0350);
                    // 내실금액 표시 처리
                    txtNetSaleAmt.Text = (dRemainPayAmt * (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL ? 1 : -1)).ToString(); 
                }

                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                bool bExistPay = false;
                if (bPayDisp == true)
                {
                    // 결제내역 화면 표시
                    lstPaymentList.Items.Clear();

                    // 결제내역 화면 처리
                    ArrayList alPayment = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
                    for (int iRow = 0; iRow < alPayment.Count; iRow++)
                    {
                        Column.TR_PAYMENT.DATA cPayItem = (Column.TR_PAYMENT.DATA)alPayment[iRow];

                        if (cPayItem.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL) continue;

                        if (cPayItem.BILLSPR_NO != m_cTrnStatus.Sale.BillSplitNo) continue;
                        
                        ListViewItem lvData = new ListViewItem(iRow.ToString());
                        
                        lvData.SubItems.Add(cPayItem.OCCUR_ENTRY_20);

                        //#20170905 미군기지 환율 표시 start
                        //기존
                        //lvData.SubItems.Add(m_cPosStatus.Global.NumericTOCurrency(cPayItem.PAY_AMT));
                        //변경
                        if (dUsarmyEx > 0)
                        {
                            lvData.SubItems.Add((CmUtil.MathRounds(cPayItem.PAY_AMT / dUsarmyEx, PosConst.MATH_ROUND.ROUND, 2)).ToString());
                        }
                        else
                        {
                            lvData.SubItems.Add(m_cPosStatus.Global.NumericTOCurrency(cPayItem.PAY_AMT));
                        }
                        //#20170905 미군기지 환율 표시 end

                        lstPaymentList.Items.Add(lvData);
                        bExistPay = true;
                    }

                    // 해피포인트 등록 내역
                    lblHappyPoint.Text = "";
                    ArrayList alEtcItem = (ArrayList)StateObject.GetItemObject(Column.TR_ETC.ITEM);
                    foreach (Column.TR_ETC.DATA cEtcItem in alEtcItem)
                    {
                        if (cEtcItem.CANCEL_DIV == ItemConst.PAY_CANCEL_DIV.CANCEL) continue;

                        if (cEtcItem.ETC_WAY_CD == ItemConst.TR_ITEM_ID.ETC_INFO_ITEM && cEtcItem.ETC_DTL_CD_01 == ItemConst.TR_ITEM_ID.ETC_INFO.SAVEPOINT)
                        {
                            //#20180821 해피포인트 고객이름 마스킹 start
                            //기존
                            //if (cEtcItem.HP_CUST_NAME.Length > 2)
                            //    lblHappyPoint.Text = "[ " + cEtcItem.HP_CUST_NAME.Substring(0, 1) + "*" + cEtcItem.HP_CUST_NAME.Substring(2) + " ]" + "\n\r";
                            //else
                            //    lblHappyPoint.Text = "[ " + cEtcItem.HP_CUST_NAME + " ]" + "\n\r";
                            //변경
                            IDataCommonUs m_cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);
                            if (cEtcItem.HP_CUST_NAME != "") { cEtcItem.HP_CUST_NAME = m_cDataCommon.NameMasking(cEtcItem.HP_CUST_NAME); }
                            lblHappyPoint.Text = "[ " + cEtcItem.HP_CUST_NAME + " ]" + "\n\r";
                            //#20180821 해피포인트 고객이름 마스킹 end

                            lblHappyPoint.Text += MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0228) + ": " + m_cPosStatus.Global.NumericTOCurrency(cEtcItem.AMT_ENTRY_03) + "\n\r";    // 누적포인트
                            lblHappyPoint.Text += MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0229) + ": " + m_cPosStatus.Global.NumericTOCurrency(cEtcItem.AMT_ENTRY_04) + "\n\r";    // 가용포인트
                            if (cEtcItem.HP_EXT_POINT > 0)
                            {
                                lblHappyPoint.Text += MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0164) + ": " + m_cPosStatus.Global.NumericTOCurrency(cEtcItem.HP_EXT_POINT) + "\n\r";// 소멸예정
                            }
                            if (m_cTrnStatus.Sale.RemainPayAmt <= 0 && cEtcItem.ETC_AMT > 0)
                            {
                                lblHappyPoint.Text += MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0728) + ": " + m_cPosStatus.Global.NumericTOCurrency(cEtcItem.ETC_AMT) + "\n\r";     // 적립포인트
                            }
                            bExistPay = true;
                            break;
                        }
                        else if (cEtcItem.ETC_WAY_CD == ItemConst.TR_ITEM_ID.ETC_INFO_ITEM && cEtcItem.ETC_DTL_CD_01 == ItemConst.TR_ITEM_ID.ETC_INFO.OCB_SAVE)
                        {
                            lblHappyPoint.Text = " [  OCB  ]" + "\n\r";
                            lblHappyPoint.Text += MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0228) + ": " + m_cPosStatus.Global.NumericTOCurrency(cEtcItem.AMT_ENTRY_03) + "\n\r";       // 누적포인트
                            lblHappyPoint.Text += MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0229) + ": " + m_cPosStatus.Global.NumericTOCurrency(cEtcItem.AMT_ENTRY_04) + "\n\r";       // 가용포인트
                            if (m_cTrnStatus.Sale.RemainPayAmt <= 0 && cEtcItem.ETC_AMT > 0)
                            {
                                lblHappyPoint.Text += MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0728) + ": " + m_cPosStatus.Global.NumericTOCurrency(cEtcItem.ETC_AMT) + "\n\r";     // 적립포인트
                            }
                            bExistPay = true;
                            break;
                        }
                    }
                }

                if (sForeignInfo != "")
                {
                    // 외화내역 화면 표시
                    lstForeignList.Items.Clear();
                    string[] saForeInfo = sForeignInfo.Split('|');
                    for (int i = 0; i < saForeInfo.Length; i += 2)
                    {
                        if (saForeInfo[i] == "") continue;

                        ListViewItem lvData = new ListViewItem(i.ToString());

                        lvData.SubItems.Add(saForeInfo[i]);
                        lvData.SubItems.Add(saForeInfo[i + 1]);

                        lstForeignList.Items.Add(lvData);
                    }
                    bExistPay = true;
                    lstForeignList.Visible = true;
                }
                else
                {
                    lstForeignList.Visible = false;
                }

                if ( bExistPay == true)
                {
                    // 결재내역 리스트 표시
                    //FormManager.SetControlSize(pnlSaleItemGrid, 0, 254, 768, 440);
                    //FormManager.SetControlSize(SaleItemGrid, 0, 0, 768, 440);

                    //#20180830 드라이브스루 고객용 모니터 start - 20180907
                    //기존
                    //if (SaleItemGrid.GridDataItems.Count > 9)
                    //변경
                    if (SaleItemGrid.GridDataItems.Count > 7)
                    //#20180830 드라이브스루 고객용 모니터 end - 20180907
                    {
                        int iMoveTop = 0;
                        int iGrdCnt = 0;
                        int iTemp = 0;
                        iGrdCnt = SaleItemGrid.GridDataItems.Count;
                        iTemp = SaleItemGrid.GridDataItems.Count;
                        if (iTemp > 12) iTemp = 12;
                       
                        //#20180830 드라이브스루 고객용 모니터 start - 20180907
                        //기존
                        //iMoveTop = iTemp - 9;
                        //변경
                        iMoveTop = iTemp - 7;
                        //#20180830 드라이브스루 고객용 모니터 end - 20180907

                        //#20180830 드라이브스루 고객용 모니터 start - 20180907
                        //기존
                        //iMoveTop = iMoveTop * 54;
                        //변경
                        iMoveTop = iMoveTop * 2;
                        //#20180830 드라이브스루 고객용 모니터 end - 20180907

                        //#20180830 드라이브스루 고객용 모니터 start - 20180907
                        //기존
                        //FormManager.SetControlSize(pnlSaleItemGrid, 0, 254 - iMoveTop, 768, 667);
                        //FormManager.SetControlSize(SaleItemGrid, 0, 0, 768, 667);
                        
                        //변경 - line 6
                        //84 * 6
                        //FormManager.SetControlSize(pnlSaleItemGrid, 0, 254 - iMoveTop, 768, 84 * 6);
                        //FormManager.SetControlSize(SaleItemGrid, 0, 0, 768, 84 * 6);

                        //변경 - line 7
                        FormManager.SetControlSize(pnlSaleItemGrid, 0, 254 - iMoveTop, 768, 84 * 6);
                        FormManager.SetControlSize(SaleItemGrid, 0, 0, 768, 84 * 6);
                        //#20180830 드라이브스루 고객용 모니터 end - 20180907

                    } 
                    //SaleItemGrid.DisplayItemCount = 11;
                    //SaleItemGrid.Refresh();
                     
                    FormManager.SetControlSize(pnlRecvAmt, 0, 759, 768, 265);
                    FormManager.SetControlSize(pnlPay, 0, 150, 768, 115); 
                    
                    lblHappyPoint.Visible = true;
                    lstPaymentList.Visible = true;
                    //pnlRecvAmt.BringToFront();
                }
                else
                {
                    FormManager.SetControlSize(pnlSaleItemGrid, 0, 254, 768, 654);
                    FormManager.SetControlSize(SaleItemGrid, 0, 0, 768, 654);
                    //SaleItemGrid.DisplayItemCount = 11;
                    //SaleItemGrid.Refresh();
                    

                    FormManager.SetControlSize(pnlRecvAmt, 0, 1059, 768, 115);
                    FormManager.SetControlSize(pnlPay, 0, 0, 768, 115);

                    lblHappyPoint.Visible = false;
                    lstPaymentList.Visible = false;
                    //pnlRecvAmt.back();
                }

                SaleItemGrid.Refresh();
                
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
        
        /// <summary>
        /// 상품 선택 처리
        /// </summary>
        public void DisplaySaleItemSelect(int nSelRow)
        {
            try
            {
                SaleItemGrid.SelectIndexItem(nSelRow);
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
        #endregion

        #region 거래완료시 거스름 표시
        /// <summary>
        /// 거래완료시 거스름 표시
        /// </summary>
        public void SaleCompleteDisplay(double nChangeAmt)
        {
            try
            {
                if (m_cPosStatus.Mst.CntryDiv == ItemConst.CNTRY_DIV.KR)
                {
                    // 내신금액 표시
                    txtRecvAmt.Text = m_cPosStatus.Global.NumericTOCurrency(m_cPosStatus.Sale.PayRecvedAmt * (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL ? 1 : -1))
                            + m_cPosStatus.Global.m_stCultureMaster.strCurrencyName;

                    // 받을금액 표시 자리에 거스름 표시
                    //lblNetSaleAmt.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0212);
                    txtNetSaleAmt.Text = m_cPosStatus.Global.NumericTOCurrency(nChangeAmt);
                }
                else
                {
                    // 내신금액 표시
                    txtRecvAmt.Text = m_cPosStatus.Global.m_stCultureMaster.strCurrencySymbol +
                            m_cPosStatus.Global.NumericTOCurrency(m_cPosStatus.Sale.PayRecvedAmt * (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL ? 1 : -1));

                    // 받을금액 표시 자리에 거스름 표시
                    //lblNetSaleAmt.Text = m_cPosStatus.Global.m_stCultureMaster.strCurrencySymbol + " " + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0212);
                    //lblNetSaleAmt.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0212);

                    txtNetSaleAmt.Text = m_cPosStatus.Global.m_stCultureMaster.strCurrencySymbol + m_cPosStatus.Global.NumericTOCurrency(nChangeAmt);
                }

                // 거스름 화면 표기 시간(초)
                int nInitSecond = CmUtil.IntParse(PosMstManager.GetPosOption(POS_OPTION.OPT108));
                if (nInitSecond <= 0 || nInitSecond > 999)
                    tmrDisplayInit.Interval = 5000;
                else
                    tmrDisplayInit.Interval = 1000 * nInitSecond;
                tmrDisplayInit.Enabled = true;
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
        #endregion 
        
        #region 동영상 관련 처리(FFMPEG)
        /// <summary>
        /// 파이프 및 이벤트 등록 시작
        /// </summary>
        private void StartCustPipe()
        {
            try
            {
                _pipeServer = new PipeServer();
                _pipeServer.PipeMessage += new DelegateMessage(PipesMessageHandler);
                _pipeServer.Listen(PosConst.CUST_PIPE_NAME.CUST_POS_SERVER);
            }
            catch (Exception ex)
            {
               UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        /// <summary>
        /// Pipe Server Recv Message Callback
        /// </summary>
        /// <param name="NewMessage"></param>
        public delegate void NewMessageDelegate(string NewMessage); //Pipe Server Recv Message Callback

        /// <summary>
        /// 서버 응답
        /// </summary>
        /// <param name="message"></param>
        private void PipesMessageHandler(string message)
        {
            try
            {
                if (this.InvokeRequired)
                {
                    this.Invoke(new NewMessageDelegate(PipesMessageHandler), message);
                }
                else
                {
                    string[] aRecv = message.Split(new string[] { PosConst.CUST_VARIABLE.FS.ToString() }, StringSplitOptions.None);

                    if (aRecv[1].ToString().Equals(PosConst.CUST_TRAN_ID.R_PIC1))
                    {
                        m_sDispWork1 = aRecv[2];
                    }
                    else if (aRecv[1].ToString().Equals(PosConst.CUST_TRAN_ID.R_PIC2))
                    {
                        m_sDispWork2 = aRecv[2];
                    }
                }
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                       System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }

        }

        /// <summary>
        /// 파이프 전문 생성
        /// </summary>
        /// <param name="sDispFlag"></param>
        /// <param name="sFullPath"></param>
        /// <param name="sMessage"></param>
        /// <param name="sSoundFlag"></param>
        private void PipesMessageSend(string sDispFlag, string sFullPath, string sMessage, string sSoundFlag)
        {
            try
            {

                string sSendData = PosConst.CUST_SYNC.PP_ASYNC;

                sSendData += AddFs(sDispFlag);

                sSendData += AddFs(sMessage);

                sSendData += AddFs(@sFullPath);

                /*
                if (sDispFlag == PosConst.CUST_TRAN_ID.PIC1)
                {
                    sSendData += AddFs(picMediaTop.Width.ToString());
                    sSendData += AddFs(picMediaTop.Height.ToString());
                    sSendData += AddFs(picMediaTop.Handle.ToString());

                    m_sDispWork1 = sMessage;
                }
                else
                {
                    sSendData += AddFs(picMediaBtm.Width.ToString());
                    sSendData += AddFs(picMediaBtm.Height.ToString());
                    sSendData += AddFs(picMediaBtm.Handle.ToString());

                    m_sDispWork2 = sMessage;
                }
                */

                sSendData += AddFs(sSoundFlag);

                if (PipeClient(sSendData) == false)
                {
                    if (sDispFlag == PosConst.CUST_TRAN_ID.PIC1)
                    {
                        m_sDispWork1 = PosConst.CUST_WOKRING.STOP;
                    }
                    else
                    {
                        m_sDispWork2 = PosConst.CUST_WOKRING.STOP;
                    }
                }
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                       System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }

        }

        /// <summary>
        /// 구분자 추가
        /// </summary>
        /// <param name="sData"></param>
        /// <returns></returns>
        private string AddFs(string sData)
        {
            return PosConst.CUST_VARIABLE.FS + sData;
        }

        /// <summary>
        /// 파이프 전문 전송
        /// </summary>
        /// <param name="sPipeName"></param>
        /// <param name="sendMsg"></param>
        private bool PipeClient(string sendMsg)
        {

            bool bRet = false;

            try
            {
                // 실행 파일이 없으면 종료
                if (File.Exists(BaseCom.NxBinPath + PosConst.CUST_PIPE_NAME.CUST_PROCESS_EX) == false) return bRet;

                _pipeClient = new PipeClient();
                if (_pipeClient.Send(sendMsg, PosConst.CUST_PIPE_NAME.CUST_DOUALPLAY, 2000) == false)
                {
                    DualPlayStartNkill();
                }
                else
                {
                    bRet = true;
                }
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                       System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message + "파이프 연결 실패로 재기동 >>>");
                //dualplay 재기동!!!!
                DualPlayStartNkill();
            }

            return bRet;
        }

        /// <summary>
        /// 동영상 플레이어 재 가동
        /// </summary>
        /// <returns></returns>
        private bool DualPlayStartNkill()
        {
            try
            {
                int iDelay = 1000;

                m_sDispWork1 = PosConst.CUST_WOKRING.STOP;
                m_sDispWork2 = PosConst.CUST_WOKRING.STOP;


                if (File.Exists(BaseCom.NxBinPath + PosConst.CUST_PIPE_NAME.CUST_PROCESS_EX) == false) return false;
                
                System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName(PosConst.CUST_PIPE_NAME.CUST_PROCESS);
                if (p.GetLength(0) > 0)
                {
                    p[0].Kill();

                    Delay(iDelay);
                }

                string strappname = BaseCom.NxBinPath + PosConst.CUST_PIPE_NAME.CUST_PROCESS_EX;
                System.Diagnostics.Process.Start(strappname);

                Delay(iDelay);

                return true;

            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }

            return false;
        }

        /// <summary>
        /// 딜레이
        /// </summary>
        /// <param name="MS"></param>
        /// <returns></returns>
        private void Delay(int MS)
        {
            DateTime ThisMoment = DateTime.Now;
            TimeSpan duration = new TimeSpan(0, 0, 0, 0, MS);
            DateTime AfterWards = ThisMoment.Add(duration);
            while (AfterWards >= ThisMoment)
            {
                System.Windows.Forms.Application.DoEvents();
                ThisMoment = DateTime.Now;
            }
        }

        /// <summary>
        /// 파이프 및 이벤트 종료
        /// </summary>
        private void PipeClear()
        {
            try
            {
                _pipeClient = null;
                _pipeServer.PipeMessage -= new DelegateMessage(PipesMessageHandler);
                _pipeServer = null;
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_IOS, 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 tmrDisplayInit_Tick(object sender, EventArgs e)
        {
            try
            {
                tmrDisplayInit.Enabled = false;

                DisplaySaleItemList(false, false, "", 0);
                ClearSaleItemList();
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
    }
}

