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

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

namespace Cosmos.Win
{
    public partial class frmTableItemMove : Form, IFormTableItemMoveUs
    {
        private SManager sManager = new SManager();                                 
        private StateServer StateObject = (StateServer)StateServer.GetInstance();   
        private PosStatus m_cPosStatus;                                             
        private TranStatus m_cTrnStatus;                                            

        private ITableUs m_cTableSvr = null;                                        

        private Hashtable htTableItems = new Hashtable();

        private DataTable dtLeftGrid;
        private DataTable dtRightGrid;

        public DataTable LeftGrid { get { return dtLeftGrid; } }

        public DataTable RightGrid { get { return dtRightGrid; } }

        /// <summary>
        /// 첫번째 선택된 테이블의 층코드
        /// </summary>
        private string m_sFirstSelectedFloorCd = string.Empty;
        public string FirstSelectedFloorCd { get { return m_sFirstSelectedFloorCd; } set { m_sFirstSelectedFloorCd = value; } }
        /// <summary>
        /// 첫번째 선택된 테이블의 테이블코드
        /// </summary>
        private string m_sFirstSelectedTableNo = string.Empty;
        public string FirstSelectedTableNo { get { return m_sFirstSelectedTableNo; } set { m_sFirstSelectedTableNo = value; } }


        /// <summary>
        /// 두번째 선택된 테이블의 층코드
        /// </summary>
        private string m_sSecondSelectedFloorCd = string.Empty;
        public string SecondSelectedFloorCd { get { return m_sSecondSelectedFloorCd; } set { m_sSecondSelectedFloorCd = value; } }
        /// <summary>
        /// 두번째 선택된 테이블의 테이블코드
        /// </summary>
        private string m_sSecondSelectedTableNo = string.Empty;
        public string SecondSelectedTableNo { get { return m_sSecondSelectedTableNo; } set { m_sSecondSelectedTableNo = value; } }

        private bool isBusy = false; 

        public frmTableItemMove()
        {
            try
            {
                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_cTableSvr = (ITableUs)sManager.InitServiceInstance(ServiceLists.BSV_TABLE.DLL, ServiceLists.BSV_TABLE.TABLE_SERVICE);
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR,
                                     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 (함수명))
                                     ex.Message);
            }
        }

        private void frmTableItemMove_Load(object sender, EventArgs e)
        {
            try
            {
                UserLog.WriteLogFile(UserCom.LOG_IOS, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
                                                      System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
                                                      System.Reflection.MethodBase.GetCurrentMethod().Name + "()", "");
                InitControls();
                InitializeGrid();
                SetGridData();
                isBusy = 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);
            }
        }

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

        private void InitControls()
        {
            try
            {
                this.picBack.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.POP_SIZE_800X600);
                this.picBack.Location = new Point(0, 0);
                this.picBack.SendToBack();
                this.Size = this.picBack.Size = this.picBack.Image.Size;
                
                FormManager.MovePopUpForm(this, false, m_cPosStatus.Sale.ScreenSizeUser);
                FormManager.SetFormAllControlFont(this, m_cPosStatus.Base.FONT);

                //테마색상 적용!
                btnEnter.BackColor = CmUtil.GetColorToString(m_cPosStatus.ScnMst.ThemeColor);
                btnExit.Image = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.BTN_CLOSE);
                if (btnExit.Image != null) btnExit.Text = "";

                btnGridUp1.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_170X48_UP1_BASIC);
                btnGridUp1.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_170X48_UP1_PRESS);
                btnGridUp1.BorderStyle = BorderStyle.None;

                btnGridDn1.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_170X48_DOWN1_BASIC);
                btnGridDn1.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_170X48_DOWN1_PRESS);
                btnGridDn1.BorderStyle = BorderStyle.None;

                btnGridUp2.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_170X48_UP1_BASIC);
                btnGridUp2.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_170X48_UP1_PRESS);
                btnGridUp2.BorderStyle = BorderStyle.None;

                btnGridDn2.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_170X48_DOWN1_BASIC);
                btnGridDn2.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.NAVIBTN_170X48_DOWN1_PRESS);
                btnGridDn2.BorderStyle = BorderStyle.None;

                btnToRightAll.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.BUTTON_RIGHT_ALL_ARROW_BASIC);
                btnToRightAll.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.BUTTON_RIGHT_ALL_ARROW_PRESS);
                btnToRightAll.BorderStyle = BorderStyle.None;
                if (btnToRightAll.DefaultImage != null) btnToRightAll.Text = string.Empty;

                btnToRight.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.BUTTON_RIGHT_ARROW_BASIC);
                btnToRight.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.BUTTON_RIGHT_ARROW_PRESS);
                btnToRight.BorderStyle = BorderStyle.None;
                if (btnToRight.DefaultImage != null) btnToRight.Text = string.Empty;

                btnToLeft.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.BUTTON_LEFT_ARROW_BASIC);
                btnToLeft.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.BUTTON_LEFT_ARROW_PRESS);
                btnToLeft.BorderStyle = BorderStyle.None;
                if (btnToLeft.DefaultImage != null) btnToLeft.Text = string.Empty;

                btnToLeftAll.DefaultImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.BUTTON_LEFT_ALL_ARROW_BASIC);
                btnToLeftAll.ClickImage = ImageManager.GetImage(BaseCom.NxImgPath, ImageManager.BUTTON_LEFT_ALL_ARROW_PRESS);
                btnToLeftAll.BorderStyle = BorderStyle.None;
                if (btnToLeftAll.DefaultImage != null) btnToLeftAll.Text = string.Empty;

                btnEnter.Text = MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0009);
            }
            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);
            }
        }

        private void InitializeGrid()
        {
            try
            {
                #region 왼쪽 Grid 설정

                gridTargetTable1.CsmGridClear();
                
                gridTargetTable1.CsmGridColumnHeadersVisible = true;
                gridTargetTable1.CsmGridColumnHeadersHeight = 41;
                gridTargetTable1.CsmGridColumnHeadersFont = new Font(m_cPosStatus.Base.FONT, 10, FontStyle.Bold);
                
                gridTargetTable1.CsmGridColumnCount = 13;
                gridTargetTable1.CsmGridRowsHeight = 39;
                gridTargetTable1.CsmGridShowPageRowsCount = 8;
                gridTargetTable1.Font = new Font(m_cPosStatus.Base.FONT, 10, FontStyle.Regular);

                gridTargetTable1.CsmGridSetHeaderBackColor(236, 238, 239);                                              //그리드 헤더 배경색
                gridTargetTable1.CsmGridDefaultRowBackColor = Color.FromArgb(255, 255, 255);                            //그리드 홀수(Default)행의 배경색 지정
                gridTargetTable1.CsmGridAlternateRowBackColor = Color.FromArgb(251, 253, 255);                          //그리드 짝수(Alternate)행의 배경색 지정
                gridTargetTable1.CsmGridBackGroundColor = Color.FromArgb(251, 253, 255);                                //기본 백그라운드 컬러
                gridTargetTable1.CsmGridHighlightColor = Color.FromArgb(255, 251, 211);                                 //그리드 선택 백 컬러
                gridTargetTable1.CsmGridHighlightTextColor = Color.Black;                                               //그리드 선택 글자 컬러

                //컬럼 넓이 지정
                gridTargetTable1.CsmGridSetColumnWidth(new int[] { 190, 60, 90, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });
                //컬럼별 정렬 기준 설정(0:왼쪽, 1:가운데, 2:오른쪽)
                gridTargetTable1.CsmGridAlignment(new int[] { 0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0 });

                //특정컬럼 Visible 여부 설정
                gridTargetTable1.CsmGridColumnShowHide(3, false);
                gridTargetTable1.CsmGridColumnShowHide(4, false);
                gridTargetTable1.CsmGridColumnShowHide(5, false);
                gridTargetTable1.CsmGridColumnShowHide(6, false);
                gridTargetTable1.CsmGridColumnShowHide(7, false);
                gridTargetTable1.CsmGridColumnShowHide(8, false);
                gridTargetTable1.CsmGridColumnShowHide(9, false);
                gridTargetTable1.CsmGridColumnShowHide(10, false);
                gridTargetTable1.CsmGridColumnShowHide(11, false);
                gridTargetTable1.CsmGridColumnShowHide(12, false);

                //각 컬럼별 이름 설정
                gridTargetTable1.CsmGridColumnName(0, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0015));      // 상품명
                gridTargetTable1.CsmGridColumnName(1, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0017));      // 수량
                gridTargetTable1.CsmGridColumnName(2, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0348));      // 판매금액
                gridTargetTable1.CsmGridColumnName(3, string.Empty);    
                gridTargetTable1.CsmGridColumnName(4, string.Empty);    
                gridTargetTable1.CsmGridColumnName(5, string.Empty);    
                gridTargetTable1.CsmGridColumnName(6, string.Empty);    
                gridTargetTable1.CsmGridColumnName(7, string.Empty);    
                gridTargetTable1.CsmGridColumnName(8, string.Empty);
                gridTargetTable1.CsmGridColumnName(9, string.Empty);
                gridTargetTable1.CsmGridColumnName(10, string.Empty);
                gridTargetTable1.CsmGridColumnName(11, string.Empty);
                gridTargetTable1.CsmGridColumnName(12, string.Empty);

                // 그리드 테이블
                dtLeftGrid = new DataTable();
                dtLeftGrid.Columns.Add(new DataColumn("ITEM_NM", typeof(string)));
                dtLeftGrid.Columns.Add(new DataColumn("QTY", typeof(string)));
                dtLeftGrid.Columns.Add(new DataColumn("AMT", typeof(string)));

                dtLeftGrid.Columns.Add(new DataColumn("REF", typeof(string)));
                dtLeftGrid.Columns.Add(new DataColumn("CANCEL_DIV", typeof(string)));
                dtLeftGrid.Columns.Add(new DataColumn("ITEM_DIV", typeof(string)));
                dtLeftGrid.Columns.Add(new DataColumn("ITEM_MEMO", typeof(string)));
                dtLeftGrid.Columns.Add(new DataColumn("SALE_PRC", typeof(double)));
                dtLeftGrid.Columns.Add(new DataColumn("BILL_AMT", typeof(double)));
                dtLeftGrid.Columns.Add(new DataColumn("DC_TYPE", typeof(string)));
                dtLeftGrid.Columns.Add(new DataColumn("ITEM_DC_AMT", typeof(double)));
                dtLeftGrid.Columns.Add(new DataColumn("EXCEP_DC_AMT", typeof(double)));
                dtLeftGrid.Columns.Add(new DataColumn("SET_DC_AMT", typeof(double)));

                gridTargetTable1.CsmGridDataSource = dtLeftGrid;

                #endregion

                #region 오른쪽 Grid 설정

                gridTargetTable2.CsmGridClear();

                gridTargetTable2.CsmGridColumnHeadersVisible = true;
                gridTargetTable2.CsmGridColumnHeadersHeight = 41;
                gridTargetTable2.CsmGridColumnHeadersFont = new Font(m_cPosStatus.Base.FONT, 10, FontStyle.Bold);

                gridTargetTable2.CsmGridColumnCount = 13;
                gridTargetTable2.CsmGridRowsHeight = 39;
                gridTargetTable2.CsmGridShowPageRowsCount = 8;
                gridTargetTable2.Font = new Font(m_cPosStatus.Base.FONT, 10, FontStyle.Regular);

                gridTargetTable2.CsmGridSetHeaderBackColor(236, 238, 239);                                              //그리드 헤더 배경색
                gridTargetTable2.CsmGridDefaultRowBackColor = Color.FromArgb(255, 255, 255);                            //그리드 홀수(Default)행의 배경색 지정
                gridTargetTable2.CsmGridAlternateRowBackColor = Color.FromArgb(251, 253, 255);                          //그리드 짝수(Alternate)행의 배경색 지정
                gridTargetTable2.CsmGridBackGroundColor = Color.FromArgb(251, 253, 255);                                //기본 백그라운드 컬러
                gridTargetTable2.CsmGridHighlightColor = Color.FromArgb(255, 251, 211);                                 //그리드 선택 백 컬러
                gridTargetTable2.CsmGridHighlightTextColor = Color.Black;                                               //그리드 선택 글자 컬러

                //컬럼 넓이 지정
                gridTargetTable2.CsmGridSetColumnWidth(new int[] { 190, 60, 90, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });
                //컬럼별 정렬 기준 설정(0:왼쪽, 1:가운데, 2:오른쪽)
                gridTargetTable2.CsmGridAlignment(new int[] { 0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0 });

                //특정컬럼 Visible 여부 설정
                gridTargetTable2.CsmGridColumnShowHide(3, false);
                gridTargetTable2.CsmGridColumnShowHide(4, false);
                gridTargetTable2.CsmGridColumnShowHide(5, false);
                gridTargetTable2.CsmGridColumnShowHide(6, false);
                gridTargetTable2.CsmGridColumnShowHide(7, false);
                gridTargetTable2.CsmGridColumnShowHide(8, false);
                gridTargetTable2.CsmGridColumnShowHide(9, false);
                gridTargetTable2.CsmGridColumnShowHide(10, false);
                gridTargetTable2.CsmGridColumnShowHide(11, false);
                gridTargetTable2.CsmGridColumnShowHide(12, false);

                //각 컬럼별 이름 설정
                gridTargetTable2.CsmGridColumnName(0, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0015));      // 상품명
                gridTargetTable2.CsmGridColumnName(1, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0017));      // 수량
                gridTargetTable2.CsmGridColumnName(2, MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0348));      // 판매금액
                gridTargetTable2.CsmGridColumnName(3, string.Empty);
                gridTargetTable2.CsmGridColumnName(4, string.Empty);
                gridTargetTable2.CsmGridColumnName(5, string.Empty);
                gridTargetTable2.CsmGridColumnName(6, string.Empty);
                gridTargetTable2.CsmGridColumnName(7, string.Empty);
                gridTargetTable2.CsmGridColumnName(8, string.Empty);
                gridTargetTable2.CsmGridColumnName(9, string.Empty);
                gridTargetTable2.CsmGridColumnName(10, string.Empty);
                gridTargetTable2.CsmGridColumnName(11, string.Empty);
                gridTargetTable2.CsmGridColumnName(12, string.Empty);

                // 그리드 테이블 
                dtRightGrid = new DataTable();
                dtRightGrid.Columns.Add(new DataColumn("ITEM_NM", typeof(string)));
                dtRightGrid.Columns.Add(new DataColumn("QTY", typeof(string)));
                dtRightGrid.Columns.Add(new DataColumn("AMT", typeof(string)));

                dtRightGrid.Columns.Add(new DataColumn("REF", typeof(string)));
                dtRightGrid.Columns.Add(new DataColumn("CANCEL_DIV", typeof(string)));
                dtRightGrid.Columns.Add(new DataColumn("ITEM_DIV", typeof(string)));
                dtRightGrid.Columns.Add(new DataColumn("ITEM_MEMO", typeof(string)));
                dtRightGrid.Columns.Add(new DataColumn("SALE_PRC", typeof(double)));
                dtRightGrid.Columns.Add(new DataColumn("BILL_AMT", typeof(double)));
                dtRightGrid.Columns.Add(new DataColumn("DC_TYPE", typeof(string)));
                dtRightGrid.Columns.Add(new DataColumn("ITEM_DC_AMT", typeof(double)));
                dtRightGrid.Columns.Add(new DataColumn("EXCEP_DC_AMT", typeof(double)));
                dtRightGrid.Columns.Add(new DataColumn("SET_DC_AMT", typeof(double)));

                gridTargetTable2.CsmGridDataSource = dtRightGrid;

                #endregion
            }
            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>
        /// 왼쪽/오른쪽 DataGridView Data 설정
        /// </summary>
        private void SetGridData()
        {
            DataTable dtData = null;
            string sReturn = string.Empty;
            string sFloorNm = string.Empty;
            string sTableNm = string.Empty;

            try
            {
                #region 첫번째 그리드 Title 설정
                sReturn = m_cTableSvr.SelectFloor(new string[] { PosConst.QueryTagDef.QueryFloorDef.FLOOR_CD_SEARCH, m_sFirstSelectedFloorCd }, out dtData);
                if (sReturn == UserCom.RST_OK && dtData.Rows.Count > 0)
                {
                    sFloorNm = CmUtil.GetDataRowStr(dtData.Rows[0], "FLOOR_NM");
                }

                sReturn = m_cTableSvr.SelectTable(new string[] { PosConst.QueryTagDef.QueryTableDef.TABLE_NO_FLOOR_CD_SEARCH, m_sFirstSelectedFloorCd, m_sFirstSelectedTableNo }, out dtData);
                if (sReturn == UserCom.RST_OK)
                {
                    if (dtData.Rows.Count > 0)
                    {
                        #region (삭제) 2017.01.31, 테이블표시 구분은 테이블명으로 고정한다.
                        // 2017.01.31, 테이블표시 구분은 테이블명으로 고정한다.
                        //switch (CmUtil.GetDataRowStr(dtData.Rows[0], "TBL_DISP_DIV"))
                        //{ 
                        //    case PosConst.TABLE_DISP_FLAG.TABLE_NAME:
                        //        sTableNm = CmUtil.GetDataRowStr(dtData.Rows[0], "TBL_NM");
                        //        break; 
                        //    case PosConst.TABLE_DISP_FLAG.TABLE_NO_NAME:
                        //        sTableNm = m_sFirstSelectedTableNo + "【" + CmUtil.GetDataRowStr(dtData.Rows[0], "TBL_NM") + "】";
                        //        break;
                        //    default:
                        //        sTableNm = m_sFirstSelectedTableNo;
                        //        break; 
                        //} 
                        #endregion

                        sTableNm = CmUtil.GetDataRowStr(dtData.Rows[0], "TBL_NM").Trim();
                    }
                }

                lblTargetTable1.Text = sFloorNm + " - " + sTableNm;

                #endregion

                #region 두번째 그리드 Title 설정
                sReturn = m_cTableSvr.SelectFloor(new string[] { PosConst.QueryTagDef.QueryFloorDef.FLOOR_CD_SEARCH, m_sSecondSelectedFloorCd }, out dtData);
                if (sReturn == UserCom.RST_OK)
                {
                    if (dtData.Rows.Count > 0)
                    {
                        sFloorNm = CmUtil.GetDataRowStr(dtData.Rows[0], "FLOOR_NM");
                    }
                }

                sReturn = m_cTableSvr.SelectTable(new string[] { PosConst.QueryTagDef.QueryTableDef.TABLE_NO_FLOOR_CD_SEARCH, m_sSecondSelectedFloorCd, m_sSecondSelectedTableNo }, out dtData);
                if (sReturn == UserCom.RST_OK)
                {
                    if (dtData.Rows.Count > 0)
                    {
                        #region (삭제) 2017.01.31, 테이블표시 구분은 테이블명으로 고정한다.
                        // 2017.01.31, 테이블표시 구분은 테이블명으로 고정한다.
                        //switch (CmUtil.GetDataRowStr(dtData.Rows[0], "TBL_DISP_DIV"))
                        //{
                        //    case PosConst.TABLE_DISP_FLAG.TABLE_NAME:
                        //        sTableNm = CmUtil.GetDataRowStr(dtData.Rows[0], "TBL_NM");
                        //        break;
                        //    case PosConst.TABLE_DISP_FLAG.TABLE_NO_NAME:
                        //        sTableNm = m_sSecondSelectedTableNo + "【" + CmUtil.GetDataRowStr(dtData.Rows[0], "TBL_NM") + "】";
                        //        break;
                        //    default:
                        //        sTableNm = m_sSecondSelectedTableNo;
                        //        break;
                        //} 
                        #endregion

                        sTableNm = CmUtil.GetDataRowStr(dtData.Rows[0], "TBL_NM").Trim();
                    }
                }

                lblTargetTable2.Text = sFloorNm + " - " + sTableNm;
                #endregion

                #region 첫번째 그리드 Data 설정
                // 그리드 초기화
                gridTargetTable1.CsmGridClear();
                dtLeftGrid.Clear();

                sReturn = m_cTableSvr.SelectTableOrderItem(new string[] { PosConst.ORDER_TYPE.NORMAL, m_sFirstSelectedFloorCd, m_sFirstSelectedTableNo }, out dtData);
                if (sReturn != UserCom.RST_OK)
                {
                    return;
                }
                for (var i = 0; i < dtData.Rows.Count; i++)
                {
                    DataRow drData = dtData.Rows[i];
                    DataRow newRow = dtLeftGrid.NewRow();

                    var isCancel = CmUtil.GetDataRowStr(drData, "CANCEL_DIV") == PosConst.CANCEL_DIV.CANCEL ? true : false;
                    var itemMemo = CmUtil.GetDataRowStr(drData, "MSG1").Trim()
                                 + CmUtil.GetDataRowStr(drData, "MSG2").Trim()
                                 + CmUtil.GetDataRowStr(drData, "MSG3").Trim();
                    var itemRef  = CmUtil.GetDataRowStr(drData, "ORD_DIV") + "|"
                                 + CmUtil.GetDataRowStr(drData, "FLOOR_CD") + "|"
                                 + CmUtil.GetDataRowStr(drData, "TBL_NO") + "|"
                                 //+ CmUtil.GetDataRowStr(drData, "SEQ");
                                 + (i + 1).ToString();
                    
                    newRow["ITEM_NM"] = CmUtil.GetDataRowStr(drData, "SHTCUT_ITEMNM");
                    newRow["QTY"] = isCancel ? string.Empty 
                                             : CmUtil.GetDataRowStr(drData, "SALE_QTY");
                    newRow["AMT"] = isCancel ? MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0429)
                                             : m_cPosStatus.Global.NumericTOCurrency(CmUtil.GetDataRowDouble(drData, "BILL_AMT"));
                    newRow["REF"] = itemRef;
                    newRow["CANCEL_DIV"] = CmUtil.GetDataRowStr(drData, "CANCEL_DIV");
                    newRow["ITEM_DIV"] = CmUtil.GetDataRowStr(drData, "ITEM_DIV");
                    newRow["ITEM_MEMO"] = itemMemo.Trim();
                    newRow["SALE_PRC"] = CmUtil.GetDataRowDouble(drData, "SALE_PRC");
                    newRow["BILL_AMT"] = CmUtil.GetDataRowDouble(drData, "BILL_AMT");
                    newRow["DC_TYPE"] = CmUtil.GetDataRowStr(drData, "DC_TYPE").Trim();
                    newRow["ITEM_DC_AMT"] = CmUtil.GetDataRowDouble(drData, "ITEM_DC_AMT");
                    newRow["EXCEP_DC_AMT"] = CmUtil.GetDataRowDouble(drData, "EXCEP_DC_AMT");
                    newRow["SET_DC_AMT"] = CmUtil.GetDataRowDouble(drData, "SET_DC_AMT");

                    dtLeftGrid.Rows.Add(newRow);
                }

                gridTargetTable1.CsmGridDataSource = dtLeftGrid;
                gridTargetTable1.CsmGridSelectRow(0);
                gridTargetTable1.Refresh();
                #endregion

                #region 두번째 그리드 Data 설정
                // 그리드 초기화
                gridTargetTable2.CsmGridClear();
                dtRightGrid.Clear();

                sReturn = m_cTableSvr.SelectTableOrderItem(new string[] { PosConst.ORDER_TYPE.NORMAL, m_sSecondSelectedFloorCd, m_sSecondSelectedTableNo }, out dtData);
                if (sReturn != UserCom.RST_OK)
                {
                    return;
                }
                for (var i = 0; i < dtData.Rows.Count; i++)
                {
                    DataRow drData = dtData.Rows[i];
                    DataRow newRow = dtRightGrid.NewRow();

                    var isCancel = CmUtil.GetDataRowStr(drData, "CANCEL_DIV") == PosConst.CANCEL_DIV.CANCEL ? true : false;
                    var itemMemo = CmUtil.GetDataRowStr(drData, "MSG1").Trim()
                                 + CmUtil.GetDataRowStr(drData, "MSG2").Trim()
                                 + CmUtil.GetDataRowStr(drData, "MSG3").Trim();
                    var itemRef  = CmUtil.GetDataRowStr(drData, "ORD_DIV") + "|"
                                 + CmUtil.GetDataRowStr(drData, "FLOOR_CD") + "|"
                                 + CmUtil.GetDataRowStr(drData, "TBL_NO") + "|"
                                 //+ CmUtil.GetDataRowStr(drData, "SEQ");
                                 + (i + 1).ToString();
                    
                    newRow["ITEM_NM"] = CmUtil.GetDataRowStr(drData, "SHTCUT_ITEMNM");
                    newRow["QTY"] = isCancel ? string.Empty 
                                             : CmUtil.GetDataRowStr(drData, "SALE_QTY");
                    newRow["AMT"] = isCancel ? MessageManager.GetLabelMessage(POS_MESSAGE.LABEL.MSG_0429)
                                             : m_cPosStatus.Global.NumericTOCurrency(CmUtil.GetDataRowDouble(drData, "BILL_AMT"));
                    newRow["REF"] = itemRef;
                    newRow["CANCEL_DIV"] = CmUtil.GetDataRowStr(drData, "CANCEL_DIV");
                    newRow["ITEM_DIV"] = CmUtil.GetDataRowStr(drData, "ITEM_DIV");
                    newRow["ITEM_MEMO"] = itemMemo.Trim();
                    newRow["SALE_PRC"] = CmUtil.GetDataRowDouble(drData, "SALE_PRC");
                    newRow["BILL_AMT"] = CmUtil.GetDataRowDouble(drData, "BILL_AMT");
                    newRow["DC_TYPE"] = CmUtil.GetDataRowStr(drData, "DC_TYPE").Trim();
                    newRow["ITEM_DC_AMT"] = CmUtil.GetDataRowDouble(drData, "ITEM_DC_AMT");
                    newRow["EXCEP_DC_AMT"] = CmUtil.GetDataRowDouble(drData, "EXCEP_DC_AMT");
                    newRow["SET_DC_AMT"] = CmUtil.GetDataRowDouble(drData, "SET_DC_AMT");

                    dtRightGrid.Rows.Add(newRow);
                }

                gridTargetTable2.CsmGridDataSource = dtRightGrid;
                gridTargetTable2.CsmGridSelectRow(0);
                gridTargetTable2.Refresh();
                #endregion
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR,
                                     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 (함수명))
                                     ex.Message);
            }
        }

        private void btnGrid_Click(object sender, EventArgs e)
        {
            try
            {
                if ((Cosmos.UI.CsmButton)sender == btnGridUp1)
                {
                    gridTargetTable1.CsmGridScroll("UP");
                }
                else if ((Cosmos.UI.CsmButton)sender == btnGridDn1)
                {
                    gridTargetTable1.CsmGridScroll("DOWN");
                }
                else if ((Cosmos.UI.CsmButton)sender == btnGridUp2)
                {
                    gridTargetTable2.CsmGridScroll("UP");
                }
                else if ((Cosmos.UI.CsmButton)sender == btnGridDn2)
                {
                    gridTargetTable2.CsmGridScroll("DOWN");
                }
            }
            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);
            }
        }

        private void btnGrid_MouseDown(object sender, MouseEventArgs e)
        {
            try
            {
                ((Cosmos.UI.CsmButton)sender).BorderStyle = BorderStyle.FixedSingle;
            }
            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);
            }
        }

        private void btnGrid_MouseUp(object sender, MouseEventArgs e)
        {
            try
            {
                ((Cosmos.UI.CsmButton)sender).BorderStyle = BorderStyle.None;
            }
            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);
            }
        }

        private void btnMove_Click(object sender, EventArgs e)
        {
            if (isBusy) return;
            isBusy = true;
            try
            {
                if (sender == btnToRight || sender == btnToRightAll)
                {
                    var selectIndex = gridTargetTable1.CsmGridSelectedRowIndex;

                    // 취소상품
                    if (CmUtil.GetDataRowStr(dtLeftGrid.Rows[selectIndex], "CANCEL_DIV") != PosConst.CANCEL_DIV.NORMAL)
                    {
                        WinManager.ConfirmMessage(POS_MESSAGE.ERROR.MSG_0017);
                        return;
                    }
                    // 세트자식
                    if (CmUtil.GetDataRowStr(dtLeftGrid.Rows[selectIndex], "ITEM_DIV") == ItemConst.PLU_ITEM_DIV.SET_DETL)
                    {
                        WinManager.ConfirmMessage(POS_MESSAGE.ERROR.MSG_0120);
                        return;
                    }
                    // 부가상품
                    if (CmUtil.GetDataRowStr(dtLeftGrid.Rows[selectIndex], "ITEM_DIV") == ItemConst.PLU_ITEM_DIV.OPT_MENU)
                    {
                        WinManager.ConfirmMessage(POS_MESSAGE.ERROR.MSG_0122);
                        return;
                    }
                    // 세트할인
                    //if (CmUtil.GetDataRowStr(dtLeftGrid.Rows[iSelectedRow], "ITEM_DIV") == ItemConst.PLU_ITEM_DIV.SET_DIS)
                    if (CmUtil.GetDataRowDouble(dtLeftGrid.Rows[selectIndex], "SET_DC_AMT") > 0)
                    {
                        WinManager.ConfirmMessage(POS_MESSAGE.ERROR.MSG_0121);
                        return;
                    }
                    // 소계할인
                    if (CmUtil.GetDataRowDouble(dtLeftGrid.Rows[selectIndex], "ITEM_DC_AMT") > 0 &&
                        CmUtil.GetDataRowStr(dtLeftGrid.Rows[selectIndex], "DC_TYPE") == ItemConst.PLU_DC_TYPE.DC_SUM)
                    {
                        WinManager.ConfirmMessage(POS_MESSAGE.ERROR.MSG_0688);
                        return; 
                    }

                    var moveType = sender == btnToRightAll ? "ALL" : "ONE";
                    if (CmUtil.GetDataRowDouble(dtLeftGrid.Rows[selectIndex], "QTY") == 1) moveType = "ALL";
                    if (moveType == "ONE")
                    {
                        if (CmUtil.GetDataRowDouble(dtLeftGrid.Rows[selectIndex], "ITEM_DC_AMT") > 0)
                        {
                            if (CmUtil.GetDataRowStr(dtLeftGrid.Rows[selectIndex], "DC_TYPE").Trim() == ItemConst.PLU_DC_TYPE.DC_SUM) return; 
                            if (WinManager.QuestionMessage(POS_MESSAGE.ERROR.MSG_0681) == false) return;
                            moveType = "ALL";
                        }
                    }
                    if (moveType == "ONE")
                    {
                        if (CmUtil.GetDataRowDouble(dtLeftGrid.Rows[selectIndex], "EXCEP_DC_AMT") > 0)
                        {
                            if (WinManager.QuestionMessage(POS_MESSAGE.ERROR.MSG_0681) == false) return;
                            moveType = "ALL";
                        }
                    }
                    if (moveType == "ONE")
                    {
                        if (CmUtil.GetDataRowStr(dtLeftGrid.Rows[selectIndex], "ITEM_DIV") == ItemConst.PLU_ITEM_DIV.SET_MAIN)
                        {
                            if (WinManager.QuestionMessage(POS_MESSAGE.ERROR.MSG_0687) == false) return;
                            moveType = "ALL";
                        }
                    }
                    if (moveType == "ONE")
                    {
                        if (selectIndex + 1 < dtLeftGrid.Rows.Count)
                        {
                            var isSubItem = true;
                            var nextItemDiv = CmUtil.GetDataRowStr(dtLeftGrid.Rows[selectIndex + 1], "ITEM_DIV");
                            if (nextItemDiv == ItemConst.PLU_ITEM_DIV.NORMAL) isSubItem = false;
                            if (nextItemDiv == ItemConst.PLU_ITEM_DIV.SET_DIS) isSubItem = false; 
                            if (nextItemDiv == ItemConst.PLU_ITEM_DIV.SET_MAIN) isSubItem = false; 
                            if (isSubItem)
                            {
                                if (WinManager.QuestionMessage(POS_MESSAGE.ERROR.MSG_0687) == false) return;
                                moveType = "ALL";
                            }
                        }
                    }
                    if (moveType == "ONE")
                    {
                        if (string.IsNullOrWhiteSpace(CmUtil.GetDataRowStr(dtLeftGrid.Rows[selectIndex], "ITEM_MEMO")) == false)
                        {
                            if (WinManager.QuestionMessage(POS_MESSAGE.ERROR.MSG_0686) == false) return;
                            moveType = "ALL";
                        }
                    }

                    var idx = ItemMoveExcute(dtLeftGrid, dtRightGrid, selectIndex, moveType);
                    if (idx >= 0) gridTargetTable2.CsmGridSelectRow(idx);
                }
                else if (sender == btnToLeft || sender == btnToLeftAll)
                {
                    var selectIndex = gridTargetTable2.CsmGridSelectedRowIndex;

                    // 취소상품
                    if (CmUtil.GetDataRowStr(dtRightGrid.Rows[selectIndex], "CANCEL_DIV") != PosConst.CANCEL_DIV.NORMAL)
                    {
                        WinManager.ConfirmMessage(POS_MESSAGE.ERROR.MSG_0017);
                        return;
                    }
                    // 세트자식
                    if (CmUtil.GetDataRowStr(dtRightGrid.Rows[selectIndex], "ITEM_DIV") == ItemConst.PLU_ITEM_DIV.SET_DETL)
                    {
                        WinManager.ConfirmMessage(POS_MESSAGE.ERROR.MSG_0120);
                        return;
                    }
                    // 부가상품
                    if (CmUtil.GetDataRowStr(dtRightGrid.Rows[selectIndex], "ITEM_DIV") == ItemConst.PLU_ITEM_DIV.OPT_MENU)
                    {
                        WinManager.ConfirmMessage(POS_MESSAGE.ERROR.MSG_0122);
                        return;
                    }
                    // 세트할인 
                    //if (CmUtil.GetDataRowStr(dtRightGrid.Rows[iSelectedRow], "ITEM_DIV") == ItemConst.PLU_ITEM_DIV.SET_DIS)
                    if (CmUtil.GetDataRowDouble(dtRightGrid.Rows[selectIndex], "SET_DC_AMT") > 0)
                    {
                        WinManager.ConfirmMessage(POS_MESSAGE.ERROR.MSG_0121);
                        return;
                    }
                    // 소계할인
                    if (CmUtil.GetDataRowDouble(dtRightGrid.Rows[selectIndex], "ITEM_DC_AMT") > 0 &&
                        CmUtil.GetDataRowStr(dtRightGrid.Rows[selectIndex], "DC_TYPE") == ItemConst.PLU_DC_TYPE.DC_SUM)
                    {
                        WinManager.ConfirmMessage(POS_MESSAGE.ERROR.MSG_0688);
                        return;
                    }

                    var moveType = sender == btnToLeftAll ? "ALL" : "ONE";
                    if (CmUtil.GetDataRowDouble(dtRightGrid.Rows[selectIndex], "QTY") == 1) moveType = "ALL";
                    if (moveType == "ONE")
                    {
                        if (CmUtil.GetDataRowDouble(dtRightGrid.Rows[selectIndex], "ITEM_DC_AMT") > 0)
                        {
                            if (CmUtil.GetDataRowStr(dtRightGrid.Rows[selectIndex], "DC_TYPE").Trim() == ItemConst.PLU_DC_TYPE.DC_SUM) return;
                            if (WinManager.QuestionMessage(POS_MESSAGE.ERROR.MSG_0681) == false) return;
                            moveType = "ALL";
                        }
                    }
                    if (moveType == "ONE")
                    {
                        if (CmUtil.GetDataRowDouble(dtRightGrid.Rows[selectIndex], "EXCEP_DC_AMT") > 0)
                        {
                            if (WinManager.QuestionMessage(POS_MESSAGE.ERROR.MSG_0681) == false) return;
                            moveType = "ALL";
                        }
                    }
                    if (moveType == "ONE")
                    {
                        if (CmUtil.GetDataRowStr(dtRightGrid.Rows[selectIndex], "ITEM_DIV") == ItemConst.PLU_ITEM_DIV.SET_MAIN)
                        {
                            if (WinManager.QuestionMessage(POS_MESSAGE.ERROR.MSG_0687) == false) return;
                            moveType = "ALL";
                        }
                    }
                    if (moveType == "ONE")
                    {
                        if (selectIndex + 1 < dtRightGrid.Rows.Count)
                        {
                            var isSubItem = true;
                            var nextItemDiv = CmUtil.GetDataRowStr(dtRightGrid.Rows[selectIndex + 1], "ITEM_DIV");
                            if (nextItemDiv == ItemConst.PLU_ITEM_DIV.NORMAL) isSubItem = false;
                            if (nextItemDiv == ItemConst.PLU_ITEM_DIV.SET_DIS) isSubItem = false;
                            if (nextItemDiv == ItemConst.PLU_ITEM_DIV.SET_MAIN) isSubItem = false;
                            if (isSubItem)
                            {
                                if (WinManager.QuestionMessage(POS_MESSAGE.ERROR.MSG_0687) == false) return;
                                moveType = "ALL";
                            }
                        }
                    }
                    if (moveType == "ONE")
                    {
                        if (string.IsNullOrWhiteSpace(CmUtil.GetDataRowStr(dtRightGrid.Rows[selectIndex], "ITEM_MEMO")) == false)
                        {
                            if (WinManager.QuestionMessage(POS_MESSAGE.ERROR.MSG_0686) == false) return;
                            moveType = "ALL";
                        }
                    }

                    var idx = ItemMoveExcute(dtRightGrid, dtLeftGrid, selectIndex, moveType);
                    if (idx >= 0) gridTargetTable1.CsmGridSelectRow(idx);
                }
            }
            catch (Exception ex)
            {
                UserLog.WriteLogFile(UserCom.LOG_ERROR,
                                     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 (함수명))
                                     ex.Message);
            }
            finally
            {
                gridTargetTable1.Invalidate();
                gridTargetTable2.Invalidate(); 
                isBusy = false; 
            }
        }

        private void btnMove_MouseDown(object sender, MouseEventArgs e)
        {
            try
            {
                ((Cosmos.UI.CsmButton)sender).BorderStyle = BorderStyle.FixedSingle;
            }
            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);
            }
        }

        private void btnMove_MouseUp(object sender, MouseEventArgs e)
        {
            try
            {
                ((Cosmos.UI.CsmButton)sender).BorderStyle = BorderStyle.None;
            }
            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);
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            try
            {
                this.DialogResult = DialogResult.Ignore;
                this.Close();
            }
            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);
            }
        }

        private void btnEnter_Click(object sender, EventArgs e)
        {
            try
            {
                string sReturn = m_cTableSvr.UpdateMenuItemMove();
                if (sReturn != UserCom.RST_OK)
                {
                    this.DialogResult = DialogResult.Cancel;
                    return; 
                }

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

            }
        }

        private int ItemMoveExcute(DataTable fromTable, DataTable toTable, int selectIndex, string moveType)
        {
            int retIndex = -1;

            try
            {
                var addItems = new ArrayList();
                var delItems = new ArrayList();
                
                DataRow fromItem = fromTable.Rows[selectIndex];
                DataRow toItem = null;

                var temp = CmUtil.GetDataRowStr(fromTable.Rows[selectIndex], "REF");
                for (var i = 0; i < toTable.Rows.Count; i++)
                {
                    var dr = toTable.Rows[i];
                    if (temp == CmUtil.GetDataRowStr(dr, "REF"))
                    {
                        toItem = dr;
                        retIndex = i;
                        break;
                    }
                }
                if (toItem == null)
                {
                    var moveQty = moveType == "ALL" ? CmUtil.GetDataRowInt(fromItem, "QTY") : 1;
                    var moveAmt = moveType == "ALL"
                                ? CmUtil.DoubleParse(CmUtil.GetDataRowStr(fromItem, "BILL_AMT"))
                                : CmUtil.GetDataRowDouble(fromItem, "SALE_PRC") * moveQty; 

                    toItem = toTable.NewRow();

                    toItem["ITEM_NM"] = CmUtil.GetDataRowStr(fromItem, "ITEM_NM");
                    toItem["QTY"] = moveQty.ToString();
                    toItem["AMT"] = m_cPosStatus.Global.NumericTOCurrency(moveAmt);
                    toItem["REF"] = CmUtil.GetDataRowStr(fromItem, "REF");
                    toItem["CANCEL_DIV"] = CmUtil.GetDataRowStr(fromItem, "CANCEL_DIV");
                    toItem["ITEM_DIV"] = CmUtil.GetDataRowStr(fromItem, "ITEM_DIV");
                    toItem["ITEM_MEMO"] = CmUtil.GetDataRowStr(fromItem, "ITEM_MEMO");
                    toItem["SALE_PRC"] = CmUtil.GetDataRowDouble(fromItem, "SALE_PRC");
                    toItem["BILL_AMT"] = moveAmt;
                    toItem["DC_TYPE"] = CmUtil.GetDataRowStr(fromItem, "DC_TYPE");
                    toItem["ITEM_DC_AMT"] = CmUtil.GetDataRowDouble(fromItem, "ITEM_DC_AMT");
                    toItem["EXCEP_DC_AMT"] = CmUtil.GetDataRowDouble(fromItem, "EXCEP_DC_AMT");
                    toItem["SET_DC_AMT"] = CmUtil.GetDataRowDouble(fromItem, "SET_DC_AMT");

                    addItems.Add(toItem);
                    retIndex = toTable.Rows.Count;

                    var remainQty = CmUtil.GetDataRowInt(fromItem, "QTY") - moveQty;
                    var remainAmt = CmUtil.GetDataRowDouble(fromItem, "BILL_AMT") - moveAmt;
                    fromItem["QTY"] = remainQty.ToString();
                    fromItem["AMT"] = m_cPosStatus.Global.NumericTOCurrency(remainAmt);
                    fromItem["BILL_AMT"] = remainAmt;

                    if (remainQty < 1) delItems.Add(fromItem);                    
                }
                else
                {
                    var moveQty = moveType == "ALL" ? CmUtil.GetDataRowInt(fromItem, "QTY") : 1;
                    var moveAmt = moveType == "ALL"
                                ? CmUtil.DoubleParse(CmUtil.GetDataRowStr(fromItem, "BILL_AMT"))
                                : CmUtil.GetDataRowDouble(fromItem, "SALE_PRC") * moveQty; 

                    toItem["QTY"] = (CmUtil.GetDataRowInt(toItem, "QTY") + moveQty).ToString();
                    toItem["AMT"] = m_cPosStatus.Global.NumericTOCurrency(CmUtil.GetDataRowDouble(toItem, "BILL_AMT") + moveAmt);
                    toItem["BILL_AMT"] = CmUtil.GetDataRowDouble(toItem, "BILL_AMT") + moveAmt;

                    var remainQty = CmUtil.GetDataRowInt(fromItem, "QTY") - moveQty;
                    var remainAmt = CmUtil.GetDataRowDouble(fromItem, "BILL_AMT") - moveAmt;
                    fromItem["QTY"] = remainQty.ToString();
                    fromItem["AMT"] = m_cPosStatus.Global.NumericTOCurrency(remainAmt);
                    fromItem["BILL_AMT"] = remainAmt;

                    if (remainQty < 1) delItems.Add(fromItem);
                }

                if (moveType == "ALL" || CmUtil.GetDataRowInt(fromItem, "QTY") == 1)
                {
                    // 하위구성품이동 
                    if (selectIndex + 1 < fromTable.Rows.Count)
                    {
                        for (var i = selectIndex + 1; i < fromTable.Rows.Count; i++)
                        {
                            var fromSubItem = fromTable.Rows[i];
                            var subItemDiv = CmUtil.GetDataRowStr(fromSubItem, "ITEM_DIV") ;
                            if (subItemDiv == ItemConst.PLU_ITEM_DIV.NORMAL) break;
                            if (subItemDiv == ItemConst.PLU_ITEM_DIV.SET_DIS) break;
                            if (subItemDiv == ItemConst.PLU_ITEM_DIV.SET_MAIN) break;
                            
                            var toSubItem = toTable.NewRow();

                            toSubItem["ITEM_NM"] = CmUtil.GetDataRowStr(fromSubItem, "ITEM_NM");
                            toSubItem["QTY"] = CmUtil.GetDataRowStr(fromSubItem, "QTY");
                            toSubItem["AMT"] = CmUtil.GetDataRowStr(fromSubItem, "AMT");
                            toSubItem["REF"] = CmUtil.GetDataRowStr(fromSubItem, "REF");
                            toSubItem["CANCEL_DIV"] = CmUtil.GetDataRowStr(fromSubItem, "CANCEL_DIV");
                            toSubItem["ITEM_DIV"] = CmUtil.GetDataRowStr(fromSubItem, "ITEM_DIV");
                            toSubItem["ITEM_MEMO"] = CmUtil.GetDataRowStr(fromSubItem, "ITEM_MEMO");
                            toSubItem["SALE_PRC"] = CmUtil.GetDataRowDouble(fromSubItem, "SALE_PRC");
                            toSubItem["BILL_AMT"] = CmUtil.GetDataRowDouble(fromSubItem, "BILL_AMT");
                            toSubItem["DC_TYPE"] = CmUtil.GetDataRowStr(fromSubItem, "DC_TYPE");
                            toSubItem["ITEM_DC_AMT"] = CmUtil.GetDataRowDouble(fromSubItem, "ITEM_DC_AMT");
                            toSubItem["EXCEP_DC_AMT"] = CmUtil.GetDataRowDouble(fromSubItem, "EXCEP_DC_AMT");
                            toSubItem["SET_DC_AMT"] = CmUtil.GetDataRowDouble(fromSubItem, "SET_DC_AMT");

                            addItems.Add(toSubItem);
                            delItems.Add(fromSubItem);
                        } 
                    }
                }

                foreach (DataRow dr in delItems)
                {
                    fromTable.Rows.Remove(dr);
                }
                foreach (DataRow dr in addItems)
                {
                    toTable.Rows.Add(dr);
                }

                return retIndex;
            }
            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 -1; 
            }
        }
    }
}
