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;

/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 고객 화면
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Service
{
    public partial class frmCustDisplayPipe : 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;

        /// <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 frmCustDisplayPipe()
        {
            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 frmCustDisplayPipe_Load(object sender, EventArgs e)
        {
            // 컨트롤 초기화
            InitControl();
            // 그리드 초기화
            InitializeGrid();
            // 상품정보 초기화
            ClearSaleItemList();

            StartCustPipe();

            picMediaTop.Tag = "";
            picMediaBtm.Tag = "";
        }

        private void frmCustDisplayPipe_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 frmCustDisplayPipe_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);

                if (m_cPosStatus.Sale.ScreenSizeCust == 1024)
                {
                    this.Size = new Size(1024, 768);
                    FormManager.SetControlSize(lblStoreInfo, 175, 10, 840, 29);

                    FormManager.SetControlSize(pnlMediaTop, 0, 50, 558, 359);
                    FormManager.SetControlSize(pnlMediaBtm, 0, 409, 558, 359);
                    
                    FormManager.SetControlSize(pnlRecvAmt, 559, 50, 465, 275);

                    // 포함 여부에 따라 부가세 표시 
                    if (m_cPosStatus.Mst.TaxAmtIncludeYn == ItemConst.TAX_AMT_INCLUDE_YN.NOT_INCLUDED)
                    {
                        FormManager.SetControlSize(lblQtySaleAmt,  10, 3, 168, 25);
                        FormManager.SetControlSize(lblDiscountAmt, 10, 33, 168, 25);
                        FormManager.SetControlSize(lblVatSvc,      10, 63, 168, 25);
                        FormManager.SetControlSize(lblRecvAmt,     10, 93, 168, 25);
                        FormManager.SetControlSize(lblNetSaleAmt,  10, 123, 168, 35);

                        FormManager.SetControlSize(txtQtySaleAmt,  179, 3, 275, 25);
                        FormManager.SetControlSize(txtDiscountAmt, 179, 33, 275, 25);
                        FormManager.SetControlSize(txtVatSvc,      179, 63, 275, 25);
                        FormManager.SetControlSize(txtRecvAmt,     179, 93, 275, 25);
                        FormManager.SetControlSize(txtNetSaleAmt,  179, 123, 278, 35);

                        FormManager.SetControlSize(lblLine1, 13, 30, 437, 1);
                        FormManager.SetControlSize(lblLine2, 13, 60, 437, 1);
                        FormManager.SetControlSize(lblLine3, 13, 90, 437, 1);
                        FormManager.SetControlSize(lblLine4, 13, 120, 437, 1);

                        lblVatSvc.Visible = true;
                        txtVatSvc.Visible = true;
                        lblLine4.Visible = true;
                    }
                    else
                    {
                        FormManager.SetControlSize(lblQtySaleAmt,  10,  7, 168, 30);
                        FormManager.SetControlSize(lblDiscountAmt, 10, 42, 168, 30);
                        FormManager.SetControlSize(lblRecvAmt,     10, 77, 168, 30);
                        FormManager.SetControlSize(lblNetSaleAmt,  10, 112, 168, 40);

                        FormManager.SetControlSize(txtQtySaleAmt,  179, 7,  275, 30);
                        FormManager.SetControlSize(txtDiscountAmt, 179, 42, 275, 30);
                        FormManager.SetControlSize(txtRecvAmt,     179, 77, 275, 30);
                        FormManager.SetControlSize(txtNetSaleAmt,  179, 112, 278, 40);

                        FormManager.SetControlSize(lblLine1, 13, 40, 437, 1);
                        FormManager.SetControlSize(lblLine2, 13, 75, 437, 1);
                        FormManager.SetControlSize(lblLine3, 13, 110, 437, 1);

                        lblVatSvc.Visible = false;
                        txtVatSvc.Visible = false;
                        lblLine4.Visible = false;

                    }

                    FormManager.SetControlSize(lblHappyPoint, 3, 160, 162, 115);
                    FormManager.SetControlSize(lstPaymentList, 165, 160, 295, 115);
                    FormManager.SetControlSize(lstForeignList, 165, 160, 295, 115);

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

                    lstForeignList.Columns.Clear();
                    lstForeignList.Columns.Add("PAY_NO", 0, HorizontalAlignment.Left);
                    lstForeignList.Columns.Add("PAY_NM", 180, HorizontalAlignment.Left);
                    lstForeignList.Columns.Add("PAY_AMT", 110, HorizontalAlignment.Right);
                }
                else
                {
                    this.Size = new Size(800, 600);
                    FormManager.SetControlSize(lblStoreInfo, 175, 10, 620, 29);

                    FormManager.SetControlSize(pnlMediaTop, 0, 50, 435, 275);
                    FormManager.SetControlSize(pnlMediaBtm, 0, 325, 435, 275);
                    
                    FormManager.SetControlSize(pnlRecvAmt, 435, 50, 365, 275);

                    // 포함 여부에 따라 부가세 표시 
                    if (m_cPosStatus.Mst.TaxAmtIncludeYn == ItemConst.TAX_AMT_INCLUDE_YN.NOT_INCLUDED)
                    {
                        FormManager.SetControlSize(lblQtySaleAmt,  10, 3, 150, 25);
                        FormManager.SetControlSize(lblDiscountAmt, 10, 33, 150, 25);
                        FormManager.SetControlSize(lblVatSvc,      10, 63, 150, 25);
                        FormManager.SetControlSize(lblRecvAmt,     10, 93, 150, 25);
                        FormManager.SetControlSize(lblNetSaleAmt,  10, 120, 150, 32);

                        FormManager.SetControlSize(txtQtySaleAmt,  160, 3, 200, 25);
                        FormManager.SetControlSize(txtDiscountAmt, 160, 32, 200, 25);
                        FormManager.SetControlSize(txtVatSvc,      160, 61, 200, 25);
                        FormManager.SetControlSize(txtRecvAmt,     160, 93, 200, 25);
                        FormManager.SetControlSize(txtNetSaleAmt,  160, 120, 203, 32);

                        FormManager.SetControlSize(lblLine1, 12, 30, 342, 1);
                        FormManager.SetControlSize(lblLine2, 13, 60, 342, 1);
                        FormManager.SetControlSize(lblLine3, 13, 90, 342, 1);
                        FormManager.SetControlSize(lblLine4, 13, 120, 342, 1);

                        lblVatSvc.Visible = true;
                        txtVatSvc.Visible = true;
                        lblLine4.Visible = true;
                    }
                    else
                    {
                        FormManager.SetControlSize(lblQtySaleAmt,  10,  7, 150, 30);
                        FormManager.SetControlSize(lblDiscountAmt, 10, 42, 150, 30);
                        FormManager.SetControlSize(lblRecvAmt,     10, 77, 150, 30);
                        FormManager.SetControlSize(lblNetSaleAmt,  10, 112, 150, 32);

                        FormManager.SetControlSize(txtQtySaleAmt,  160,  7, 200, 30);
                        FormManager.SetControlSize(txtDiscountAmt, 160, 42, 200, 30);
                        FormManager.SetControlSize(txtRecvAmt,     160, 77, 200, 30);
                        FormManager.SetControlSize(txtNetSaleAmt,  160, 112, 203, 32);

                        FormManager.SetControlSize(lblLine1, 13, 39, 342, 1);
                        FormManager.SetControlSize(lblLine2, 13, 74, 342, 1);
                        FormManager.SetControlSize(lblLine3, 13, 109, 342, 1);

                        lblVatSvc.Visible = false;
                        txtVatSvc.Visible = false;
                        lblLine4.Visible = false;
                    }

                    FormManager.SetControlSize(lblHappyPoint, 4, 156, 140, 115);
                    FormManager.SetControlSize(lstPaymentList, 144, 156, 217, 115);
                    FormManager.SetControlSize(lstForeignList, 144, 156, 217, 115);

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

                    lstForeignList.Columns.Clear();
                    lstForeignList.Columns.Add("PAY_NO", 0, HorizontalAlignment.Left);
                    lstForeignList.Columns.Add("PAY_NM", 125, HorizontalAlignment.Left);
                    lstForeignList.Columns.Add("PAY_AMT", 90, HorizontalAlignment.Right);
                }

                //////////////////////////////////////////////////////////////////////////////////////
                // 테마 컬러 설정
                if (m_cPosStatus.ScnMst.ThemeColor.Length == 9)
                {
                    Color colThema = CmUtil.GetColorToString(m_cPosStatus.ScnMst.ThemeColor);
                    pnlRecvAmt.BackColor = colThema;
                    lblQtySaleAmt.BackColor = colThema;
                    lblDiscountAmt.BackColor = colThema;
                    lblVatSvc.BackColor = colThema;
                    lblRecvAmt.BackColor = colThema;
                    lblNetSaleAmt.BackColor = colThema;
                    txtQtySaleAmt.BackColor = colThema;
                    txtDiscountAmt.BackColor = colThema;
                    txtVatSvc.BackColor = colThema;
                    txtRecvAmt.BackColor = colThema;
                    txtNetSaleAmt.BackColor = colThema;

                    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;

                    lblLine1.BackColor = Color.FromArgb(nRed, nGreen, nBlue);
                    lblLine2.BackColor = Color.FromArgb(nRed, nGreen, nBlue);
                    lblLine3.BackColor = Color.FromArgb(nRed, nGreen, nBlue);
                    lblLine4.BackColor = Color.FromArgb(nRed, nGreen, nBlue);
                }

                // 라벨 초기화 및 다국어 처리
                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);
                
                pnlMediaTop.Visible = false;
                picMediaTop.Location = new Point(0, 0);
                picMediaTop.Size = pnlMediaTop.Size;

                //wmpMediaTop.Location = new Point(1, 1);
                //wmpMediaTop.Size = pnlMediaTop.Size;
                //wmpMediaTop.ClientSize = pnlMediaTop.Size;

                pnlMediaBtm.Visible = false;
                picMediaBtm.Location = new Point(0, 0);
                picMediaBtm.Size = pnlMediaBtm.Size;

                //wmpMediaBtm.Location = new Point(0, 0);
                //wmpMediaBtm.Size = pnlMediaBtm.Size;
                //wmpMediaBtm.ClientSize = pnlMediaBtm.Size;
                
                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;
                if (m_cPosStatus.Sale.ScreenSizeCust == 1024)
                {
                    FormManager.SetControlSize(pnlSaleItemGrid, 559, 210, 465, 558);
                    FormManager.SetControlSize(SaleItemGrid, 0, 0, 465, 568);
                    SaleItemGrid.DisplayItemCount = 13;

                    arGridItemWidth = new int[] { 10, 210, 50, 90, 100 };
                }
                else
                {
                    FormManager.SetControlSize(pnlSaleItemGrid, 435, 205, 365, 405);
                    FormManager.SetControlSize(SaleItemGrid, 0, 0, 365, 405);
                    SaleItemGrid.DisplayItemCount = 9;

                    arGridItemWidth = new int[] { 10, 130, 50, 70, 100 };
                }

                string[] arGridItemText = new string[] { 
                                            "",
                                            MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0015),
                                            MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0017),
                                            MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0018),
                                            MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0019)};
                StringAlignment[] arHStringAlignment = new StringAlignment[] { StringAlignment.Center, StringAlignment.Center, StringAlignment.Center, StringAlignment.Center, StringAlignment.Center };

                // Set Item Data Grid Information
                
                SaleItemGrid.GapSize = 0;
                SaleItemGrid.BackColor = Color.White;

                // Row Item
                GridDataItem cGridDataItem = new GridDataItem();
                cGridDataItem.GridItemBackColor = Color.FromArgb(234, 234, 234);
                cGridDataItem.GridItemBackColorClick = Color.White;
                cGridDataItem.GridItemBackImage = null;
                cGridDataItem.GridItemBackImageClick = null;
                cGridDataItem.GridItemData = new System.Collections.Hashtable();

                // Set Column
                for (int nLoop = 0; nLoop < arGridItemWidth.Length; nLoop++)
                {
                    CsmGridExRowData cGridExRowData = new CsmGridExRowData();

                    cGridExRowData.GridItemWidth = arGridItemWidth[nLoop];
                    cGridExRowData.HStringAlignment = arHStringAlignment[nLoop];
                    cGridExRowData.VStringAlignment = StringAlignment.Center;
                    cGridExRowData.GridItemText = arGridItemText[nLoop];
                    cGridExRowData.GridItemValue = arGridItemText[nLoop];
                    cGridExRowData.ForeColor = Color.Black;
                    cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                    cGridExRowData.FontSize = 10;
                    cGridExRowData.FontStyle = FontStyle.Bold;
                    cGridExRowData.ClickEventFlag = false;

                    // Add Column
                    cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);
                }

                // Grid Data Header 설정
                if (m_cPosStatus.Sale.ScreenSizeCust == 1024)
                {
                    SaleItemGrid.SetGridDataHeader(50, cGridDataItem, GRID_EX_ITEM_BORDER_STYLE.BOTTOM, 1, Color.FromArgb(234, 234, 234));
                }
                else
                {
                    SaleItemGrid.SetGridDataHeader(35, cGridDataItem, GRID_EX_ITEM_BORDER_STYLE.BOTTOM, 1, Color.FromArgb(234, 234, 234));
                }
            }
            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 = "";

                lblStoreInfo.MpIntervalMove(5);    // 타이머 시간 설정: 최초 디폴트 10
                lblStoreInfo.MpAdd(cMoveInfo);
                lblStoreInfo.MpLoop = true;
                lblStoreInfo.MpStart();

                pnlMediaTop.Tag = "0";
                pnlMediaBtm.Tag = "0";
                
                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 ";

                //#17270 판매포스 GIF 플레이 제한에 따른 프로그램 변경 요청 start
                sQuery += "   AND UPPER(FILE_NM) NOT LIKE '%.GIF' ";
                //#17270 판매포스 GIF 플레이 제한에 따른 프로그램 변경 요청 end

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


                pnlMediaTop.Visible = true;
                //wmpMediaTop.Visible = false;
                picMediaTop.Visible = true;

                pnlMediaBtm.Visible = true;
                //wmpMediaBtm.Visible = false;
                picMediaBtm.Visible = true;

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

                if (saMedia[0] == PosConst.MEDIA_FILE_DIV.IMAGE)         // 이미지
                {
                    picMediaTop.Tag = PosConst.MEDIA_FILE_DIV.IMAGE;
                    pnlMediaTop.Tag = saMedia[1];

                    picMediaTop.Image = CmUtil.LoadImage(BaseCom.NxCDPPath + PosConst.MST_IMG_PATH.CUSTOMER + saMedia[2]);

                }
                else if (saMedia[0] == PosConst.MEDIA_FILE_DIV.MOVIE)     // 동영상
                {
                    if (saMedia[2].ToUpper().EndsWith("JPG") || saMedia[2].ToUpper().EndsWith("PNG") || saMedia[2].ToUpper().EndsWith("GIF")) return;

                    picMediaTop.Tag = PosConst.MEDIA_FILE_DIV.MOVIE;
                    pnlMediaTop.Tag = "0";
                }

                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;

                if (saMedia[0] == PosConst.MEDIA_FILE_DIV.IMAGE)        // 이미지
                {
                    picMediaBtm.Tag = PosConst.MEDIA_FILE_DIV.IMAGE;
                    pnlMediaBtm.Tag = saMedia[1];
                    picMediaBtm.Image = CmUtil.LoadImage(BaseCom.NxCDPPath + PosConst.MST_IMG_PATH.CUSTOMER + saMedia[2]);
                }
                else if (saMedia[0] == PosConst.MEDIA_FILE_DIV.MOVIE)   // 동영상
                {
                    if (saMedia[2].ToUpper().EndsWith("JPG") || saMedia[2].ToUpper().EndsWith("PNG") || saMedia[2].ToUpper().EndsWith("GIF")) return;

                    picMediaBtm.Tag = PosConst.MEDIA_FILE_DIV.MOVIE;
                    pnlMediaBtm.Tag = "0";
                }

                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;


                // 상단 컨텐츠 체크
                if (picMediaTop.Tag.ToString() == PosConst.MEDIA_FILE_DIV.MOVIE)
                {
                    if (m_sDispWork1 != PosConst.CUST_WOKRING.PLAY)
                    {
                        m_nMediaTopPos++;
                        DisplayMediaTop();
                    }
                }
                else
                {
                    // 이미지
                    pnlMediaTop.Tag = CmUtil.IntParse(pnlMediaTop.Tag.ToString()) - 1;
                    if (CmUtil.IntParse(pnlMediaTop.Tag.ToString()) <= 0)
                    {
                        m_nMediaTopPos++;
                        DisplayMediaTop();
                    }
                }

                // 하단 컨텐츠 체크
                if (m_bMediaCampaign == true && m_sCampaignFileDiv == "")
                {
                    pnlMediaBtm.Tag = CmUtil.IntParse(pnlMediaBtm.Tag.ToString()) - 1;
                    if (CmUtil.IntParse(pnlMediaBtm.Tag.ToString()) <= 0)
                    {
                        DisplayMediaBtm();
                    }
                }
                else
                {
                    if (m_sCampaignFileDiv != "")
                    {
                        DisplayCampaign(m_sCampaignFileDiv, m_sCampaignFileName);
                        m_sCampaignFileDiv = "";
                        m_sCampaignFileName = "";
                    }
                    else
                    {

                        if (picMediaBtm.Tag.ToString() == PosConst.MEDIA_FILE_DIV.MOVIE)
                        {
                            if (m_sDispWork2 != PosConst.CUST_WOKRING.PLAY)
                            {
                                m_nMediaBtmPos++;
                                DisplayMediaBtm();
                            }
                        }
                        else
                        {
                            // 이미지
                            pnlMediaBtm.Tag = CmUtil.IntParse(pnlMediaBtm.Tag.ToString()) - 1;
                            if (CmUtil.IntParse(pnlMediaBtm.Tag.ToString()) <= 0)
                            {
                                m_nMediaBtmPos++;
                                DisplayMediaBtm();
                            }
                        }
                    }
                }

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

                lblStoreInfo.MpStop();
            }
            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;
                }


                if (sFileDiv == PosConst.MEDIA_FILE_DIV.IMAGE)         // 이미지
                {
                    picMediaBtm.Tag = PosConst.MEDIA_FILE_DIV.IMAGE;
                    picMediaBtm.Image = CmUtil.LoadImage(sFullFileName);
                }
                else if (sFileDiv == PosConst.MEDIA_FILE_DIV.MOVIE)     // 동영상
                {
                    picMediaBtm.Tag = PosConst.MEDIA_FILE_DIV.MOVIE;
                }

                PipesMessageSend(PosConst.CUST_TRAN_ID.PIC2, sFullFileName, sFileDiv == PosConst.MEDIA_FILE_DIV.IMAGE ? PosConst.CUST_WOKRING.STOP : PosConst.CUST_WOKRING.PLAY, "N");
                
                
                pnlMediaBtm.Tag = "99999";
                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";
                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)
                {
                    int[] arGridItemWidth;
                    if (m_cPosStatus.Sale.ScreenSizeCust == 1024)
                        arGridItemWidth = new int[] { 10, 210, 50, 90, 100 };
                    else
                        arGridItemWidth = new int[] { 10, 130, 50, 70, 100 };

                    int[] arFontSize = new int[] { 10, 10, 10, 11, 11 };

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

                            // 2017-02-21 요청으로 짝수 배경색 제거

                            //if (iRow % 2 == 0)
                            //{
                            //    cGridDataItem.GridItemBackColor = Color.FromArgb(240, 240, 240);
                            //}
                            //else
                            //{
                                cGridDataItem.GridItemBackColor = Color.White;
                            //}
                            cGridDataItem.GridItemBackColorClick = Color.FromArgb(219, 253, 252);
                            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.FromArgb(3, 3, 3);
                            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.FromArgb(155, 155, 156);
                            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.FromArgb(155, 155, 156);
                            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.FromArgb(3, 3, 3);
                            cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                            cGridExRowData.FontSize = arFontSize[4];
                            cGridExRowData.FontStyle = FontStyle.Regular;
                            cGridExRowData.StrikeThrough = bCancelDiv;
                            cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);

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

                            SaleItemGrid.AddDataGridItem(cGridDataItem, GRID_EX_ITEM_BORDER_STYLE.BOTTOM, 1, Color.FromArgb(236, 236, 236));
                        }
                    }

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

                    SaleItemGrid.SelectIndexItem(nSelRow);
                    SaleItemGrid.Refresh();
                }

                if (m_cPosStatus.Mst.CntryDiv == ItemConst.CNTRY_DIV.KR)
                {
                    // 총수량, 총매출액
                    txtQtySaleAmt.Text = m_cPosStatus.Global.NumericToQuantity(m_cTrnStatus.Head.TotQty) + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0998) + "  "
                            + m_cPosStatus.Global.NumericTOCurrency(m_cTrnStatus.Head.TotSaleAmt * (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL ? 1 : -1))
                            + m_cPosStatus.Global.m_stCultureMaster.strCurrencyName;
                    // 총 할인 금액
                    txtDiscountAmt.Text = m_cPosStatus.Global.NumericTOCurrency(m_cTrnStatus.Head.TotDcAmt * (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL ? 1 : -1))
                            + m_cPosStatus.Global.m_stCultureMaster.strCurrencyName;

                    // 부가세+봉사료
                    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))
                            + m_cPosStatus.Global.m_stCultureMaster.strCurrencyName;


                    //#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) + "EA  " +
                                             (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() + "$"; 
                    }
                }
                else
                {
                    // 총수량, 총매출액
                    txtQtySaleAmt.Text = m_cPosStatus.Global.NumericToQuantity(m_cTrnStatus.Head.TotQty) + MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0998) + "  "
                            + m_cPosStatus.Global.m_stCultureMaster.strCurrencySymbol
                            + m_cPosStatus.Global.NumericTOCurrency(m_cTrnStatus.Head.TotSaleAmt * (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL ? 1 : -1));
                    // 총 할인 금액
                    txtDiscountAmt.Text = m_cPosStatus.Global.m_stCultureMaster.strCurrencySymbol
                            + m_cPosStatus.Global.NumericTOCurrency(m_cTrnStatus.Head.TotDcAmt * (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL ? 1 : -1));

                    // 부가세+봉사료
                    txtVatSvc.Text = m_cPosStatus.Global.m_stCultureMaster.strCurrencySymbol + 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.strCurrencySymbol + m_cPosStatus.Global.NumericTOCurrency(m_cTrnStatus.Head.TotVatAmt);

                    // 내신금액 표시
                    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_0350);
                    lblNetSaleAmt.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0350);

                    // 내실금액 표시 처리
                    txtNetSaleAmt.Text = m_cPosStatus.Global.m_stCultureMaster.strCurrencySymbol +
                            m_cPosStatus.Global.NumericTOCurrency(m_cTrnStatus.Sale.RemainPayAmt * (m_cTrnStatus.Head.TradeDiv == ItemConst.TRAN_DIV.NORMAL ? 1 : -1));
                }
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                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)
                {
                    // 결재내역 리스트 표시
                    if (m_cPosStatus.Sale.ScreenSizeCust == 1024)
                    {
                        FormManager.SetControlSize(pnlSaleItemGrid, 559, 327, 465, 441);
                        FormManager.SetControlSize(SaleItemGrid, 0, 0, 465, 441);
                    }
                    else
                    {
                        FormManager.SetControlSize(pnlSaleItemGrid, 435, 326, 365, 274);
                        FormManager.SetControlSize(SaleItemGrid, 0, 0, 365, 274);
                    }
                }
                else
                {
                    if (m_cPosStatus.Sale.ScreenSizeCust == 1024)
                    {
                        FormManager.SetControlSize(pnlSaleItemGrid, 559, 210, 465, 558);
                        FormManager.SetControlSize(SaleItemGrid, 0, 0, 465, 558);
                    }
                    else
                    {
                        FormManager.SetControlSize(pnlSaleItemGrid, 435, 205, 365, 395);
                        FormManager.SetControlSize(SaleItemGrid, 0, 0, 365, 395);
                    }
                }
                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) + m_cPosStatus.Global.m_stCultureMaster.strCurrencyName;
                }
                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);
                }

                if (m_bMediaCampaign == true) pnlMediaBtm.Tag = "10";       // 캠페인컨텐츠 10초후 종료

                // 거스름 화면 표기 시간(초)
                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)
        {
            //#20181026 #17412 PAS 대왕암공원 - 매출자료조회 frmADMT 오류창 팝업 start
            //기존
            /*
            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;
            }
            */

            //변경
            try
            {
                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;
                }
            }
            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);
            }
            //#20181026 #17412 PAS 대왕암공원 - 매출자료조회 frmADMT 오류창 팝업 end
        }

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