using System;
using System.Text;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;

using Cosmos.Win;
using Cosmos.BaseFrame;
using Cosmos.UserFrame;
using Cosmos.ServiceProvider;
using Cosmos.Common;
using Cosmos.CommonManager;
using Cosmos.UI;
using System.IO;

//#16577 결제창 내부 봉투 추가 기능 도입 start

/*-----------------------------------------------------------------------------------------------*/
// 설      명 : 봉투 추가
// 작  성  자 : 
// 변경  이력 : 
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Win
{
    public partial class frmAddBag : Form
    {

        #region 변수 선언

        private SManager sManager = new SManager();                                 // 이 객체를 통해 업무 Service 호출
        private StateServer StateObject = (StateServer)StateServer.GetInstance();   // StateObject : StateServer Object (객체)
        private PosStatus m_cPosStatus = new PosStatus();                           // 기본정보 참조
        private TranStatus m_cTrnStatus = new TranStatus();                         // 거래정보 참조        
        private DeviceStatus m_cDevStatus = new DeviceStatus();                     // 디바이스 관리
        private ISalePluItemUs m_cPluService = null;                                // 판매 등록 관리

        //#16577 결제창 내부 봉투 추가 기능 도입 start, 20180920
        private IDataCommonUs m_cDataCommon = null;                                 // POS 공통함수 인터페이스
        //#16577 결제창 내부 봉투 추가 기능 도입 end, 20180920

        private string m_sPosMenuKeyOut;
        public string PosMenuKeyOut { set { m_sPosMenuKeyOut = value; } get { return m_sPosMenuKeyOut; } }
        
        #endregion 변수 선언

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

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

            m_cPosStatus = (PosStatus)StateObject.POS;      // POS 기본정보
            m_cTrnStatus = (TranStatus)StateObject.TRAN;    // POS 거래정보 
            m_cDevStatus = (DeviceStatus)StateObject.DEVICE;
            m_cPluService = (ISalePluItemUs)sManager.InitServiceInstance(ServiceLists.BSV_SALE.DLL, ServiceLists.BSV_SALE.SALE_PLU_ITEM);

            //#16577 결제창 내부 봉투 추가 기능 도입 start, 20180920
            m_cDataCommon = (IDataCommonUs)sManager.InitServiceInstance(ServiceLists.ASV_DATA_PROCESS.DLL, ServiceLists.ASV_DATA_PROCESS.DATA_COMMON);
            //#16577 결제창 내부 봉투 추가 기능 도입 end, 20180920

        }

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

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

        /// <summary>
        /// 폼 컨트롤 초기화
        /// </summary>
        private void InitControl()
        {
            try
            {
                // 이미지 로딩 처리
                picBack.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.POP_SIZE_800X600);

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

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

                lblTitle.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1182);         // 봉투 추가
                lblProd.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1183);          // 고객님, 종이봉투(100)원인데 구입하시겠어요?
                btn_AllClear.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1184);     // 초기화
                btnSave.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1185);          // 적용
                lblItemSumAmt.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1186);    // 소계
                lblItemTotAmt.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_1187);    // 합계(구매제품포함)

                lblItemSumQty.Text    = "0";     // 소계 수량
                lblItemSumAmtTxt.Text = "0";     // 소계 금액
                lblItemTotAmtTxt.Text = m_cPosStatus.Global.NumericTOCurrency(m_cTrnStatus.Sale.RemainPayAmt);     // 합계(구매제품포함)

                m_sPosMenuKeyOut = "";

                // 그리드 초기화
                InitializeGrid();

                // 봉투 상품 화면 표시
                LoadBagDisplay();

                //#16577 결제창 내부 봉투 추가 기능 도입 start, 20180920
                // 추가한 봉투 상품 그리드에 표시
                LoadBagGrdDisplay();
                //#16577 결제창 내부 봉투 추가 기능 도입 end, 20180920
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
        #endregion

        #region 그리드 설정 및 사용
        /// <summary>
        /// 그리드 초기화
        /// </summary>
        private void InitializeGrid()
        {
            try
            {
                // 봉투 등록정보 표시 그리드
                int[] arGridItemWidth = new int[] { 0 };
                bool[] arGridItemClickEventFlag = new bool[] { true };
                string[] arGridItemText = new string[] { "" };

                //#16577 결제창 내부 봉투 추가 기능 도입 start, 20180920
                //기존
                //int[] arFontSize = new int[] { 9, 11, 11, 11, 11, 11, 11 };
                //변경
                int[] arFontSize = new int[] { 11, 11, 11, 11, 11, 11, 11, 11 };
                //#16577 결제창 내부 봉투 추가 기능 도입 end, 20180920

                StringAlignment[] arHStringAlignment = new StringAlignment[] { StringAlignment.Center };

                //#16577 결제창 내부 봉투 추가 기능 도입 start, 20180920
                //기존
                //arGridItemWidth = new int[] { 0, 0, 0, 240, 80, 50, 80 };
                //변경
                arGridItemWidth = new int[] { 0, 0, 0, 240, 80, 50, 80, 0 };
                //#16577 결제창 내부 봉투 추가 기능 도입 end, 20180920

                SaleItemGrid.DisplayItemCount = 6;

                //#16577 결제창 내부 봉투 추가 기능 도입 start, 20180920
                //기존
                /*
                arGridItemText = new string[] { string.Empty,
                                                string.Empty,
                                                string.Empty,
                                                MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0015),
                                                MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0016),
                                                MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0017),
                                                MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0348)};
                */
                //변경
                arGridItemText = new string[] { string.Empty,
                                                string.Empty,
                                                string.Empty,
                                                MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0015),
                                                MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0016),
                                                MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0017),
                                                MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0348),
                                                string.Empty};
                //#16577 결제창 내부 봉투 추가 기능 도입 end, 20180920

                //#16577 결제창 내부 봉투 추가 기능 도입 start, 20180920
                //기존
                //arHStringAlignment = new StringAlignment[] { StringAlignment.Center, StringAlignment.Center, StringAlignment.Center, StringAlignment.Center, StringAlignment.Far, StringAlignment.Far, StringAlignment.Far };
                //변경
                arHStringAlignment = new StringAlignment[] { StringAlignment.Center, StringAlignment.Center, StringAlignment.Center, StringAlignment.Center, StringAlignment.Far, StringAlignment.Far, StringAlignment.Far, StringAlignment.Center };
                //#16577 결제창 내부 봉투 추가 기능 도입 end, 20180920

                //#16577 결제창 내부 봉투 추가 기능 도입 start, 20180920
                //기존
                //arGridItemClickEventFlag = new bool[] { false, false, false, false, false, false, false };
                //변경
                arGridItemClickEventFlag = new bool[] { false, false, false, false, false, false, false, false };
                //#16577 결제창 내부 봉투 추가 기능 도입 end, 20180920

                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 = arFontSize[nLoop];

                    cGridExRowData.FontStyle = FontStyle.Bold;
                    cGridExRowData.ClickEventFlag = arGridItemClickEventFlag[nLoop];

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

                // Grid Data Header 설정
                SaleItemGrid.SetGridDataHeader(36, cGridDataItem, GRID_EX_ITEM_BORDER_STYLE.BOTTOM, 1, Color.FromArgb(234, 234, 234));
                SaleItemGrid.Invalidate();
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
        #endregion

        #region 버튼 입력 처리
        /// <summary>
        /// 버튼 입력 처리
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnProc_Click(object sender, EventArgs e)
        {
            try
            {
                if ((Cosmos.UI.CsmButton)sender == btnUpS)
                {
                    SaleItemGrid.ButtonUpProc();
                }
                else if ((Cosmos.UI.CsmButton)sender == btnDwS)
                {
                    SaleItemGrid.ButtonDownProc();
                }
                else if (((Cosmos.UI.CsmButton)sender) == btn_AllClear)
                {
                    //#16577 결제창 내부 봉투 추가 기능 도입 start, 20180920
                    //기존
                    /*
                    // 그리드 초기화
                    SaleItemGrid.RemoveAll();
                    SaleItemGrid.Refresh();

                    //소계 수량, 소계 금액, 합계(구매제품포함) 계산
                    GrdItemSum(dSumAmt);
                    */
                    //변경
                    // 그리드 상품이 있는 경우 일괄 삭제 후 등록 여부
                    if (SaleItemGrid.GridDataItems.Count > 0)
                    {
                        // 적용된 봉투 상품을 일괄 삭제 후 등록 하시겠습니까?
                        if (WinManager.QuestionMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0804)) == false)
                        {
                            return;
                        }

                        // 그리드 초기화
                        SaleItemGrid.RemoveAll();
                        SaleItemGrid.Refresh();

                        //공통코드에 등록된 봉투 상품 일괄 제거
                        DelAllBagItem();

                        // 상품 판매가 계산
                        m_cPluService.ItemAmountExeccute(true, true);

                        //결제등록 정보 화면 표시
                        IFormSaleMainUs cFormSaleMain = (IFormSaleMainUs)FormManager.GetForm(FormManager.FORM_SAL_MAIN);
                        cFormSaleMain.DisplayPayment();           // 결제등록정보 화면표시

                        //소계 수량, 소계 금액, 합계(구매제품포함) 계산
                        GrdItemSum();
                    }
                    //#16577 결제창 내부 봉투 추가 기능 도입 end, 20180920
                }
                else if (((Cosmos.UI.CsmButton)sender) == btnSave)
                {
                    if (SaveData() == false)
                    {
                        WinManager.ConfirmMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0803));
                    }
                    else
                    {
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }

        /// <summary>
        /// 닫기
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExit_Click(object sender, EventArgs e)
        {
            try
            {
                m_sPosMenuKeyOut = "";
                this.DialogResult = DialogResult.Cancel;
                this.Close();
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
        #endregion Control Event

        #region 봉투 상품 화면 표시
        /// <summary>
        /// 봉투 상품 화면 표시
        /// </summary>
        /// <returns></returns>
        public bool LoadBagDisplay()
        {
            try
            {
                // 공통코드(T0042)의 상품코드와 상품마스터(MST_ITEM) 데이터 표시
                DataTable dtFuncKey = m_cPluService.SearchMenuMaster("MST_ITEM_ADD_BAG");
                if (dtFuncKey == null || dtFuncKey.Rows.Count <= 0)
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0800); // 사용 가능한 상품이 없습니다.
                    return false;
                }

                // 봉투 상품 초기화
                btnBagMenu.SetMenuButtonCount(4, 2);                                            // 메뉴버튼갯수 설정
                btnBagMenu.BackColor = CmUtil.GetColorToString("223223223");
                btnBagMenu.VisibleUpDown = false;
                btnBagMenu.BackColorUpDown = Color.White;
                btnBagMenu.ForeColorUpDown = Color.Black;

                // 이미지 표현시 사용
                string sUseMenuImage = PosMstManager.GetPosOption(POS_OPTION.OPT105);           // 메뉴 이미지 사용여부

                btnBagMenu.ClearMenuButtonInfo();                                               // 설정된 메뉴정보 초기화

                foreach (DataRow dr in dtFuncKey.Rows)
                {
                    Cosmos.UI.CsmMenu.MenuBtnInfo cMenuInfo = new Cosmos.UI.CsmMenu.MenuBtnInfo();

                    cMenuInfo.sClassCode = "00";                                                                        // 대분류코드
                    cMenuInfo.sGroupCode = "0000";                                                                      // 중분류코드

                    cMenuInfo.nSeqNo = CmUtil.GetDataRowInt(dr, "SEQ");                                                 // 표시순번
                    // 메뉴 키 값 = 서브점포코드(10) + 메뉴코드(6)
                    string sMenuCode = CmUtil.RPadH(CmUtil.GetDataRowStr(dr, PosMst.MST_ITEM.DATA.SUB_STOR_CD), 10)
                                     + CmUtil.GetDataRowStr(dr, PosMst.MST_ITEM.DATA.ITEM_CD);

                    cMenuInfo.sMenuCode = sMenuCode;                                                                    // 메뉴 연결코드
                    cMenuInfo.sMenuName = CmUtil.RPadH(CmUtil.GetDataRowStr(dr, PosMst.MST_ITEM.DATA.SHTCUT_ITEMNM), 50);                 // 메뉴 명

                    if (PosMstManager.GetPosOption(POS_OPTION.OPT005) == "0")
                        cMenuInfo.sMenuPrice = CmUtil.RPadH(m_cPosStatus.Global.NumericTOCurrency(CmUtil.GetDataRowDouble(dr, PosMst.MST_ITEM.DATA.TAKE_OUT_SALE_AMT)), 30);      // 메뉴 가격
                    else
                        cMenuInfo.sMenuPrice = CmUtil.RPadH(m_cPosStatus.Global.NumericTOCurrency(CmUtil.GetDataRowDouble(dr, PosMst.MST_ITEM.DATA.TAKE_IN_SALE_AMT)), 30);       // 메뉴 가격

                    // 메뉴 키 값 = 서브점포코드(10) + 메뉴코드(6) + 상품명(50) + 단가(30)
                    cMenuInfo.sMenuCode = cMenuInfo.sMenuCode + cMenuInfo.sMenuName + cMenuInfo.sMenuPrice;

                    cMenuInfo.cBackColor = Color.White;                                                                 // 버튼 백 컬러
                    cMenuInfo.cForeColorName = Color.Black;                                                             // 메뉴명 컬러
                    cMenuInfo.cForeColorPrice = Color.Red;                                                              // 메뉴가격 컬러
                    cMenuInfo.fFontSizeName = 10;                                                                       // 메뉴명 폰트 사이즈
                    cMenuInfo.fFontSizePrice = 10;                                                                      // 메뉴 가격 폰트 사이즈
                    cMenuInfo.nButtonSize = 0;                                                                          // 메뉴버튼 사이즈(0:일반,1:가로확대,2:세로확대,3:가로세로확대)
                    cMenuInfo.cMenuImage = "";

                    // 이미지 표현시 사용

                    if (sUseMenuImage != "0")
                    {
                        cMenuInfo.cMenuImage = BaseCom.NxCDPPath + PosConst.MST_IMG_PATH.ITEM + CmUtil.GetDataRowStr(dr, PosMst.MST_ITEM.DATA.ITEM_CD) + ".PNG";
                        if (File.Exists(cMenuInfo.cMenuImage) == false)
                        {
                            cMenuInfo.cMenuImage = BaseCom.NxCDPPath + PosConst.MST_IMG_PATH.ITEM + CmUtil.GetDataRowStr(dr, PosMst.MST_ITEM.DATA.RPST_ITEM_CD) + ".PNG";
                        }
                    }

                    btnBagMenu.AddMenuButtonInfo(cMenuInfo);
                }

                // 표시 그룹
                btnBagMenu.DisplayMenuButton("00", "0000");

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

        //#16577 결제창 내부 봉투 추가 기능 도입 start, 20180920
        #region 추가한 봉투 상품 그리드에 표시
        /// <summary>
        /// 추가한 봉투 상품 그리드에 표시
        /// </summary>
        /// <returns></returns>
        public bool LoadBagGrdDisplay()
        {
            try
            {
                DataTable dtData = new DataTable();

                // 공통코드에 등록된 봉투 상품 일괄 제거
                // 공통코드에 봉투상품 가져오기
                dtData = m_cDataCommon.ChkAddBagMstCmm();

                // 공통코드에 봉투상품이 존재하는 경우
                if (dtData != null && dtData.Rows.Count != 0)
                {
                    // 상품정보
                    ArrayList aSaleItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);

                    // 상품정보를 돌면서 봉투상품 일괄 제거
                    for (int iLoop = 0; iLoop < aSaleItem.Count; iLoop++)
                    {
                        Column.TR_PLU.DATA cSaleItem = (Column.TR_PLU.DATA)aSaleItem[iLoop];

                        foreach (DataRow dr in dtData.Rows)
                        {
                            if (cSaleItem.ITEM_PLU_CD == CmUtil.GetDataRowStr(dr, "CHAR_VAL_TITLE_VAL_01"))
                            {
                                #region 그리드 기본 설정
                                // 그리드 컬럼 폭
                                int[] arGridItemWidth;

                                arGridItemWidth = new int[] { 0, 0, 0, 240, 80, 50, 80, 0 };

                                // 그리드 폰트
                                int[] arFontSize = new int[] { 11, 11, 11, 11, 11, 11, 11, 11 };

                                #endregion 그리드 기본 설정

                                #region 선택 상품 그리드에 추가

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

                                // Row Item
                                GridDataItem cGridDataItem = new GridDataItem();
                                cGridDataItem.GridItemBackColor = Color.FromArgb(255, 255, 255);
                                cGridDataItem.GridItemBackColorClick = Color.FromArgb(219, 253, 252);
                                cGridDataItem.GridItemBackImage = null;
                                cGridDataItem.GridItemBackImageClick = null;
                                cGridDataItem.GridItemData = new System.Collections.Hashtable();

                                CsmGridExRowData cGridExRowData = new CsmGridExRowData();

                                // No
                                cGridExRowData.GridItemWidth = arGridItemWidth[0];
                                cGridExRowData.ClickEventFlag = false;
                                cGridExRowData.HStringAlignment = StringAlignment.Center;
                                cGridExRowData.VStringAlignment = StringAlignment.Center;
                                cGridExRowData.GridItemText = (SaleItemGrid.GridDataItems.Count + 1).ToString();
                                cGridExRowData.GridItemValue = (SaleItemGrid.GridDataItems.Count + 1).ToString();
                                cGridExRowData.ForeColor = Color.Black;
                                cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                                cGridExRowData.FontSize = arFontSize[0];
                                cGridExRowData.FontStyle = FontStyle.Regular;
                                cGridExRowData.StrikeThrough = false;
                                cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);

                                // 상품코드
                                cGridExRowData = new CsmGridExRowData();
                                cGridExRowData.GridItemWidth = arGridItemWidth[1];
                                cGridExRowData.ClickEventFlag = false;
                                cGridExRowData.HStringAlignment = StringAlignment.Center;
                                cGridExRowData.VStringAlignment = StringAlignment.Center;
                                cGridExRowData.GridItemText = cSaleItem.ITEM_PLU_CD;
                                cGridExRowData.GridItemValue = cSaleItem.ITEM_PLU_CD;
                                cGridExRowData.ForeColor = Color.Black;
                                cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                                cGridExRowData.FontSize = arFontSize[1];
                                cGridExRowData.FontStyle = FontStyle.Regular;
                                cGridExRowData.StrikeThrough = false;
                                cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);

                                // 서브점포코드
                                cGridExRowData = new CsmGridExRowData();
                                cGridExRowData.GridItemWidth = arGridItemWidth[2];
                                cGridExRowData.ClickEventFlag = false;
                                cGridExRowData.HStringAlignment = StringAlignment.Center;
                                cGridExRowData.VStringAlignment = StringAlignment.Center;
                                cGridExRowData.GridItemText = cSaleItem.SUB_SHOP_CD;
                                cGridExRowData.GridItemValue = cSaleItem.SUB_SHOP_CD;
                                cGridExRowData.ForeColor = Color.Black;
                                cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                                cGridExRowData.FontSize = arFontSize[2];
                                cGridExRowData.FontStyle = FontStyle.Regular;
                                cGridExRowData.StrikeThrough = false;
                                cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);

                                // 상품명
                                cGridExRowData = new CsmGridExRowData();
                                cGridExRowData.GridItemWidth = arGridItemWidth[3];
                                cGridExRowData.ClickEventFlag = true;
                                cGridExRowData.HStringAlignment = StringAlignment.Near;
                                cGridExRowData.VStringAlignment = StringAlignment.Center;
                                cGridExRowData.GridItemText = cSaleItem.ITEM_NAME;
                                cGridExRowData.GridItemValue = cSaleItem.ITEM_NAME;
                                cGridExRowData.ForeColor = Color.Black;
                                cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                                cGridExRowData.FontSize = arFontSize[3];
                                cGridExRowData.FontStyle = FontStyle.Regular;
                                cGridExRowData.StrikeThrough = false;
                                cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);

                                // 단가
                                cGridExRowData = new CsmGridExRowData();
                                cGridExRowData.GridItemWidth = arGridItemWidth[4];
                                cGridExRowData.ClickEventFlag = true;
                                cGridExRowData.HStringAlignment = StringAlignment.Far;
                                cGridExRowData.VStringAlignment = StringAlignment.Center;
                                cGridExRowData.GridItemText = cSaleItem.SALE_PRC.ToString();
                                cGridExRowData.GridItemValue = cSaleItem.SALE_PRC.ToString();
                                cGridExRowData.ForeColor = Color.Black;
                                cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                                cGridExRowData.FontSize = arFontSize[4];
                                cGridExRowData.FontStyle = FontStyle.Regular;
                                cGridExRowData.StrikeThrough = false;
                                cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);

                                // 수량
                                cGridExRowData = new CsmGridExRowData();
                                cGridExRowData.GridItemWidth = arGridItemWidth[5];
                                cGridExRowData.ClickEventFlag = true;
                                cGridExRowData.HStringAlignment = StringAlignment.Far;
                                cGridExRowData.VStringAlignment = StringAlignment.Center;
                                cGridExRowData.GridItemText = cSaleItem.SALE_QTY.ToString();
                                cGridExRowData.GridItemValue = cSaleItem.SALE_QTY.ToString();
                                cGridExRowData.ForeColor = Color.Black;
                                cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                                cGridExRowData.FontSize = arFontSize[5];
                                cGridExRowData.FontStyle = FontStyle.Regular;
                                cGridExRowData.StrikeThrough = false;
                                cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);

                                // 금액
                                cGridExRowData = new CsmGridExRowData();
                                cGridExRowData.GridItemWidth = arGridItemWidth[6];
                                cGridExRowData.ClickEventFlag = true;
                                cGridExRowData.HStringAlignment = StringAlignment.Far;
                                cGridExRowData.VStringAlignment = StringAlignment.Center;
                                cGridExRowData.GridItemText = cSaleItem.SALE_AMT.ToString();
                                cGridExRowData.GridItemValue = cSaleItem.SALE_AMT.ToString();
                                cGridExRowData.ForeColor = Color.Black;
                                cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                                cGridExRowData.FontSize = arFontSize[6];
                                cGridExRowData.FontStyle = FontStyle.Regular;
                                cGridExRowData.StrikeThrough = false;
                                cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);

                                // 상품리스트 추가여부
                                cGridExRowData = new CsmGridExRowData();
                                cGridExRowData.GridItemWidth = arGridItemWidth[7];
                                cGridExRowData.ClickEventFlag = false;
                                cGridExRowData.HStringAlignment = StringAlignment.Center;
                                cGridExRowData.VStringAlignment = StringAlignment.Center;
                                cGridExRowData.GridItemText = "1";
                                cGridExRowData.GridItemValue = "1";
                                cGridExRowData.ForeColor = Color.Black;
                                cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                                cGridExRowData.FontSize = arFontSize[7];
                                cGridExRowData.FontStyle = FontStyle.Regular;
                                cGridExRowData.StrikeThrough = false;
                                cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);

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

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

                                #endregion 선택 상품 그리드에 추가

                                #region 소계 수량, 소계, 합계(구매제품포함) 계산
                                GrdItemSum(false);
                                #endregion 소계 수량, 소계, 합계(구매제품포함) 계산

                                break;
                            }
                        }
                    }
                }
                return false;

            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
                return false;
            }
        }
        #endregion 추가한 봉투 상품 그리드에 표시
        //#16577 결제창 내부 봉투 추가 기능 도입 end, 20180920

        #region 봉투 상품 선택
        /// <summary>
        /// 봉투 상품 선택
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="sMenuCode"></param>
        private void btnBagMenu_MenuClickHandler(object sender, string sMenuCode)
        {
            try
            {
                if (sMenuCode == "") return;

                //#16577 결제창 내부 봉투 추가 기능 도입 start, 20180920
                // 그리드 상품이 있는 경우 일괄 삭제 후 등록 여부
                if (SaleItemGrid.GridDataItems.Count > 0)
                {
                    if (addItemYN() == false)
                    {
                        // 적용된 봉투 상품을 일괄 삭제 후 등록 하시겠습니까?
                        if (WinManager.QuestionMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0804)) == false)
                        {
                            return;
                        }

                        // 그리드 초기화
                        SaleItemGrid.RemoveAll();
                        SaleItemGrid.Refresh();

                        //공통코드에 등록된 봉투 상품 일괄 제거
                        DelAllBagItem();

                        // 상품 판매가 계산
                        m_cPluService.ItemAmountExeccute(true, true);

                        //결제등록 정보 화면 표시
                        IFormSaleMainUs cFormSaleMain = (IFormSaleMainUs)FormManager.GetForm(FormManager.FORM_SAL_MAIN);
                        cFormSaleMain.DisplayPayment();           // 결제등록정보 화면표시

                        //소계 수량, 소계 금액, 합계(구매제품포함) 계산
                        GrdItemSum();


                    }

                }
                //#16577 결제창 내부 봉투 추가 기능 도입 end, 20180920

                UserLog.WriteLogFile(UserCom.LOG_DEBUG,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                     "** Add Item -> sMenuCode :" + sMenuCode);

                #region 그리드 기본 설정
                // 그리드 컬럼 폭
                int[] arGridItemWidth;

                //#16577 결제창 내부 봉투 추가 기능 도입 start, 20180920
                //기존
                //arGridItemWidth = new int[] { 0, 0, 0, 240, 80, 50, 80 };
                //변경
                arGridItemWidth = new int[] { 0, 0, 0, 240, 80, 50, 80, 0 };
                //#16577 결제창 내부 봉투 추가 기능 도입 end, 20180920

                // 그리드 폰트

                //#16577 결제창 내부 봉투 추가 기능 도입 start, 20180920
                //기존
                //int[] arFontSize = new int[] { 9, 11, 11, 11, 11, 11, 11 };
                //변경
                int[] arFontSize = new int[] { 11, 11, 11, 11, 11, 11, 11, 11 };
                //#16577 결제창 내부 봉투 추가 기능 도입 end, 20180920

                #endregion 그리드 기본 설정

                #region 선택 상품 그리드에 추가

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

                // Row Item
                GridDataItem cGridDataItem = new GridDataItem();
                cGridDataItem.GridItemBackColor = Color.FromArgb(255, 255, 255);
                cGridDataItem.GridItemBackColorClick = Color.FromArgb(219, 253, 252);
                cGridDataItem.GridItemBackImage = null;
                cGridDataItem.GridItemBackImageClick = null;
                cGridDataItem.GridItemData = new System.Collections.Hashtable();

                CsmGridExRowData cGridExRowData = new CsmGridExRowData();

                // No
                cGridExRowData.GridItemWidth = arGridItemWidth[0];
                cGridExRowData.ClickEventFlag = false;
                cGridExRowData.HStringAlignment = StringAlignment.Center;
                cGridExRowData.VStringAlignment = StringAlignment.Center;
                cGridExRowData.GridItemText = (SaleItemGrid.GridDataItems.Count + 1).ToString();
                cGridExRowData.GridItemValue = (SaleItemGrid.GridDataItems.Count + 1).ToString();
                cGridExRowData.ForeColor = Color.Black;
                cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                cGridExRowData.FontSize = arFontSize[0];
                cGridExRowData.FontStyle = FontStyle.Regular;
                cGridExRowData.StrikeThrough = false;
                cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);

                // 상품코드
                cGridExRowData = new CsmGridExRowData();
                cGridExRowData.GridItemWidth = arGridItemWidth[1];
                cGridExRowData.ClickEventFlag = false;
                cGridExRowData.HStringAlignment = StringAlignment.Center;
                cGridExRowData.VStringAlignment = StringAlignment.Center;
                cGridExRowData.GridItemText = CmUtil.MidH(sMenuCode, 10, 6).Trim();
                cGridExRowData.GridItemValue = CmUtil.MidH(sMenuCode, 10, 6).Trim();
                cGridExRowData.ForeColor = Color.Black;
                cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                cGridExRowData.FontSize = arFontSize[1];
                cGridExRowData.FontStyle = FontStyle.Regular;
                cGridExRowData.StrikeThrough = false;
                cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);

                // 서브점포코드
                cGridExRowData = new CsmGridExRowData();
                cGridExRowData.GridItemWidth = arGridItemWidth[2];
                cGridExRowData.ClickEventFlag = false;
                cGridExRowData.HStringAlignment = StringAlignment.Center;
                cGridExRowData.VStringAlignment = StringAlignment.Center;
                cGridExRowData.GridItemText = CmUtil.MidH(sMenuCode, 0, 10).Trim();
                cGridExRowData.GridItemValue = CmUtil.MidH(sMenuCode, 0, 10).Trim();
                cGridExRowData.ForeColor = Color.Black;
                cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                cGridExRowData.FontSize = arFontSize[2];
                cGridExRowData.FontStyle = FontStyle.Regular;
                cGridExRowData.StrikeThrough = false;
                cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);

                // 상품명
                cGridExRowData = new CsmGridExRowData();
                cGridExRowData.GridItemWidth = arGridItemWidth[3];
                cGridExRowData.ClickEventFlag = true;
                cGridExRowData.HStringAlignment = StringAlignment.Near;
                cGridExRowData.VStringAlignment = StringAlignment.Center;
                cGridExRowData.GridItemText = CmUtil.MidH(sMenuCode, 16, 50).Trim();
                cGridExRowData.GridItemValue = CmUtil.MidH(sMenuCode, 16, 50).Trim();
                cGridExRowData.ForeColor = Color.Black;
                cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                cGridExRowData.FontSize = arFontSize[3];
                cGridExRowData.FontStyle = FontStyle.Regular;
                cGridExRowData.StrikeThrough = false;
                cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);

                // 단가
                cGridExRowData = new CsmGridExRowData();
                cGridExRowData.GridItemWidth = arGridItemWidth[4];
                cGridExRowData.ClickEventFlag = true;
                cGridExRowData.HStringAlignment = StringAlignment.Far;
                cGridExRowData.VStringAlignment = StringAlignment.Center;
                cGridExRowData.GridItemText = CmUtil.MidH(sMenuCode, 66, 30).Trim();
                cGridExRowData.GridItemValue = CmUtil.MidH(sMenuCode, 66, 30).Trim();
                cGridExRowData.ForeColor = Color.Black;
                cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                cGridExRowData.FontSize = arFontSize[4];
                cGridExRowData.FontStyle = FontStyle.Regular;
                cGridExRowData.StrikeThrough = false;
                cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);

                // 수량
                cGridExRowData = new CsmGridExRowData();
                cGridExRowData.GridItemWidth = arGridItemWidth[5];
                cGridExRowData.ClickEventFlag = true;
                cGridExRowData.HStringAlignment = StringAlignment.Far;
                cGridExRowData.VStringAlignment = StringAlignment.Center;
                cGridExRowData.GridItemText = "1";
                cGridExRowData.GridItemValue = "1";
                cGridExRowData.ForeColor = Color.Black;
                cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                cGridExRowData.FontSize = arFontSize[5];
                cGridExRowData.FontStyle = FontStyle.Regular;
                cGridExRowData.StrikeThrough = false;
                cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);

                // 금액
                cGridExRowData = new CsmGridExRowData();
                cGridExRowData.GridItemWidth = arGridItemWidth[6];
                cGridExRowData.ClickEventFlag = true;
                cGridExRowData.HStringAlignment = StringAlignment.Far;
                cGridExRowData.VStringAlignment = StringAlignment.Center;
                cGridExRowData.GridItemText = CmUtil.MidH(sMenuCode, 66, 30).Trim();
                cGridExRowData.GridItemValue = CmUtil.MidH(sMenuCode, 66, 30).Trim();
                cGridExRowData.ForeColor = Color.Black;
                cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                cGridExRowData.FontSize = arFontSize[6];
                cGridExRowData.FontStyle = FontStyle.Regular;
                cGridExRowData.StrikeThrough = false;
                cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);

                //#16577 결제창 내부 봉투 추가 기능 도입 start, 20180920
                //변경
                // 상품리스트 추가여부
                cGridExRowData = new CsmGridExRowData();
                cGridExRowData.GridItemWidth = arGridItemWidth[7];
                cGridExRowData.ClickEventFlag = false;
                cGridExRowData.HStringAlignment = StringAlignment.Center;
                cGridExRowData.VStringAlignment = StringAlignment.Center;
                cGridExRowData.GridItemText = "0";
                cGridExRowData.GridItemValue = "0";
                cGridExRowData.ForeColor = Color.Black;
                cGridExRowData.FontName = m_cPosStatus.Base.FONT;
                cGridExRowData.FontSize = arFontSize[7];
                cGridExRowData.FontStyle = FontStyle.Regular;
                cGridExRowData.StrikeThrough = false;
                cGridDataItem.GridItemData.Add(cGridDataItem.GridItemData.Count, cGridExRowData);
                //#16577 결제창 내부 봉투 추가 기능 도입 end, 20180920

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

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

                #endregion 선택 상품 그리드에 추가

                #region 소계 수량, 소계, 합계(구매제품포함) 계산
                GrdItemSum();
                #endregion 소계 수량, 소계, 합계(구매제품포함) 계산
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                    System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }
        }
        #endregion

        #region 소계 수량, 소계 금액, 합계(구매제품포함) 계산
        //#16577 결제창 내부 봉투 추가 기능 도입 start, 20180920
        //기존
        //private bool GrdItemSum()
        //변경
        private bool GrdItemSum(bool bAddSumAmt = true)
        //#16577 결제창 내부 봉투 추가 기능 도입 end, 20180920
        {
            bool bRet = false;

            try
            {
                #region 상품이 없는 경우 초기화

                UserLog.WriteLogFile(UserCom.LOG_DEBUG,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                     "** GrdItemSum -> GridItem Count :" + SaleItemGrid.GridDataItems.Count.ToString());

                // 상품이 없는 경우 초기화
                if (SaleItemGrid.GridDataItems.Count <= 0)
                {
                    lblItemSumQty.Text    = "0";     // 소계 수량
                    lblItemSumAmtTxt.Text = "0";     // 소계 금액
                    lblItemTotAmtTxt.Text = m_cPosStatus.Global.NumericTOCurrency(m_cTrnStatus.Sale.RemainPayAmt);     // 합계(구매제품포함)

                    return false;
                }
                #endregion 상품이 없는 경우 초기화

                #region 소계 수량, 소계 금액, 합계(구매제품포함) 계산
                // 그리드 데이터
                Hashtable htSaleItemGrid = SaleItemGrid.GridDataItems;

                GridDataItem cGridDataItem = null;
                CsmGridExRowData cGridExRowData = null;

                double dSumQty = 0;              // 소계 수량
                double dSumAmt = 0;              // 소계 금액

                // 소계 계산
                // 그리드 돌면서 수량, 금액 합산
                for (int iRow = 0; iRow < SaleItemGrid.GridDataItems.Count; iRow++)
                {
                    cGridDataItem = (GridDataItem)htSaleItemGrid[iRow];

                    // 소계 수량
                    cGridExRowData = (CsmGridExRowData)cGridDataItem.GridItemData[5];
                    dSumQty += CmUtil.DoubleParse(cGridExRowData.GridItemValue);

                    // 소계 금액
                    cGridExRowData = (CsmGridExRowData)cGridDataItem.GridItemData[6];
                    dSumAmt += CmUtil.DoubleParse(cGridExRowData.GridItemValue);
                }

                // 소계 수량
                lblItemSumQty.Text = m_cPosStatus.Global.NumericTOCurrency(dSumQty);
                // 소계 금액
                lblItemSumAmtTxt.Text = m_cPosStatus.Global.NumericTOCurrency(dSumAmt);

                //#16577 결제창 내부 봉투 추가 기능 도입 start, 20180920
                // 합계(구매제품포함)
                //기존
                //lblItemTotAmtTxt.Text = m_cPosStatus.Global.NumericTOCurrency(CmUtil.DoubleAdd(m_cTrnStatus.Sale.RemainPayAmt, dSumAmt));
                //변경
                // 소계를 합계에 합산 할지 여부
                if (bAddSumAmt == true)
                {
                    lblItemTotAmtTxt.Text = m_cPosStatus.Global.NumericTOCurrency(CmUtil.DoubleAdd(m_cTrnStatus.Sale.RemainPayAmt, dSumAmt));
                }
                else
                {
                    lblItemTotAmtTxt.Text = m_cPosStatus.Global.NumericTOCurrency(m_cTrnStatus.Sale.RemainPayAmt);
                }
                //#16577 결제창 내부 봉투 추가 기능 도입 end, 20180920

                UserLog.WriteLogFile(UserCom.LOG_DEBUG,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                     "** GrdItemSum -> ItemSumQty: " + lblItemSumQty.Text + ", ItemSumAmt: " + lblItemSumAmtTxt.Text + ", ItemTotAmt: " + lblItemTotAmtTxt.Text);

                #endregion 소계 수량, 소계 금액, 합계(구매제품포함) 계산

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

            return bRet;
        }
        #endregion 소계 수량, 소계 금액, 합계(구매제품포함) 계산

        #region 적용
        private bool SaveData()
        {
            bool bRet = false;

            try
            {
                //#16577 결제창 내부 봉투 추가 기능 도입 start, 20180920
                //기존
                /*
                // 선택된 상품이 없는 경우 나간다.
                if (SaleItemGrid.GridDataItems.Count <= 0)
                {
                    WinManager.ErrorMessage(POS_MESSAGE.ERROR.MSG_0800); // 사용 가능한 상품이 없습니다.
                    return false;
                }
                */
                //변경

                // 그리드 상품이 없는 경우 봉투 상품 일괄 삭제
                if (SaleItemGrid.GridDataItems.Count <= 0)
                {
                    //공통코드에 등록된 봉투 상품 일괄 제거
                    DelAllBagItem();
                    return true;
                }

                // 추가될 상품이 없는 경우
                if (addItemYN() == false)
                {
                    m_sPosMenuKeyOut = "^";

                    UserLog.WriteLogFile(UserCom.LOG_DEBUG,
                                         System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                         System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                         System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                         "** SaveData -> m_sPosMenuKeyOut: " + m_sPosMenuKeyOut);

                    return true;
                }
                //#16577 결제창 내부 봉투 추가 기능 도입 end, 20180920

                // 그리드 데이터
                Hashtable htSaleItemGrid = SaleItemGrid.GridDataItems;
       
                GridDataItem cGridDataItem = null;
                CsmGridExRowData cGridExRowData = null;

                // 그리드 돌면서 상품코드만 취합
                for (int iRow = 0; iRow < SaleItemGrid.GridDataItems.Count; iRow++)
                {
                    cGridDataItem = (GridDataItem)htSaleItemGrid[iRow];

                    //#16577 결제창 내부 봉투 추가 기능 도입 start, 20180920
                    // 상품리스트 추가여부
                    cGridExRowData = (CsmGridExRowData)cGridDataItem.GridItemData[7];

                    // 추가 했던 상품은 추가하지 않는다.
                    if (cGridExRowData.GridItemValue.ToString() == "1")
                    {
                        continue;
                    }
                    //#16577 결제창 내부 봉투 추가 기능 도입 end, 20180920

                    // 상품코드
                    cGridExRowData = (CsmGridExRowData)cGridDataItem.GridItemData[1];

                    m_sPosMenuKeyOut += cGridExRowData.GridItemValue.ToString() + "^";
                }

                UserLog.WriteLogFile(UserCom.LOG_DEBUG,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                     "** SaveData -> m_sPosMenuKeyOut: " + m_sPosMenuKeyOut);

                //정상 종료 확인
                if (m_sPosMenuKeyOut.Trim() == "")
                {
                    bRet = false;
                }
                else
                {
                    bRet = true;
                }
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }

            return bRet;
        }
        #endregion 적용

        //#16577 결제창 내부 봉투 추가 기능 도입 start, 20180920
        #region 추가할 상품 존재 여부
        private bool addItemYN()
        {
            bool bRet = false;
            int iAddCnt = 0;
            DataTable dtData = new DataTable();

            try
            {
                // 그리드에 상품이 없는 경우
                if (SaleItemGrid.GridDataItems.Count <= 0)
                {
                    UserLog.WriteLogFile(UserCom.LOG_DEBUG,
                                         System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                         System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                         System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                         "** addItemYN -> false");

                    return false;
                }

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

                GridDataItem cGridDataItem = null;
                CsmGridExRowData cGridExRowData = null;

                // 그리드 돌면서 상품코드만 취합
                for (int iRow = 0; iRow < SaleItemGrid.GridDataItems.Count; iRow++)
                {
                    cGridDataItem = (GridDataItem)htSaleItemGrid[iRow];

                    // 상품리스트 추가여부
                    cGridExRowData = (CsmGridExRowData)cGridDataItem.GridItemData[7];

                    // 추가 해야 할 상품
                    if (cGridExRowData.GridItemValue.ToString() == "0")
                    {
                        iAddCnt++;

                        UserLog.WriteLogFile(UserCom.LOG_DEBUG,
                                             System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                             System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                             System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                             "** addItemYN -> true");

                        return true;
                    }
                }

                UserLog.WriteLogFile(UserCom.LOG_DEBUG,
                                     System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                     System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                     "** addItemYN -> false");
            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
            }

            return bRet;
        }
        #endregion 추가할 상품 존재 여부

        #region 공통코드에 등록된 봉투 상품 일괄 제거
        private bool DelAllBagItem()
        {
            DataTable dtData = new DataTable();

            try
            {
                // 공통코드에 등록된 봉투 상품 일괄 제거 
                // 공통코드에 봉투상품 가져오기
                dtData = m_cDataCommon.ChkAddBagMstCmm();

                // 공통코드에 봉투상품이 존재하는 경우
                if (dtData != null && dtData.Rows.Count != 0)
                {
                    // 상품정보
                    ArrayList aSaleItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);

                    // 상품정보를 돌면서 봉투상품 일괄 제거
                    for (int iLoop = 0; iLoop < aSaleItem.Count; iLoop++)
                    {
                        Column.TR_PLU.DATA cSaleItem = (Column.TR_PLU.DATA)aSaleItem[iLoop];

                        foreach (DataRow dr in dtData.Rows)
                        {
                            if (cSaleItem.ITEM_PLU_CD == CmUtil.GetDataRowStr(dr, "CHAR_VAL_TITLE_VAL_01"))
                            {
                                aSaleItem.Remove(cSaleItem);
                                iLoop--;
                                break;
                            }
                        }
                    }
                }

                UserLog.WriteLogFile(UserCom.LOG_DEBUG,
                                        System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,      // Project Name (프로젝트명)
                                        System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +  // Class Name (Class Name (클래스명))
                                        System.Reflection.MethodBase.GetCurrentMethod().Name + "()",                // Function Name (Function Name (함수명))
                                        "** DelAllBagItem");

                return true;

            }
            catch (Exception ex)
            {
                WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                     System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
                
                return false;
            }
        }
        #endregion 공통코드에 등록된 봉투 상품 일괄 제거

        //#16577 결제창 내부 봉투 추가 기능 도입 end, 20180920

        #region DeviceEvent 관련
        /// <summary>
        /// DeviceEvent 관련
        /// </summary>
        /// <param name="sDevice"></param>
        /// <param name="sData1"></param>
        /// <param name="sData2"></param>
        /// <param name="sData3"></param>
        public void OnDeviceEvent(string sDevice, string sData1, string sData2, string sData3)
        {

        }

        /// <summary>
        /// MSR Event
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        private void OnMSREvent(object source, EventArgs e)
        {

        }
        /// <summary>
        /// 스캐너 이벤트 처리
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        private void OnScannerEvent(object source, EventArgs e)
        {

        }
        #endregion

    }

}
