using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

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

namespace Cosmos.Service
{
    class SchKtchOrder : IDataServiceUs
    {
        private SManager sManager = new SManager();                                 // 이 객체를 통해 업무 Service 호출

        private PosStatus m_cPosStatus = new PosStatus();                           //기본정보 참조
        private IMasterUs m_cMstService = null;                                     // 마스터 인터페이스
        private StateServer StateObject = (StateServer)StateServer.GetInstance();   // StateObject : StateServer Object (객체)


        public SchKtchOrder()
        {
            m_cPosStatus = (PosStatus)StateObject.POS;      // POS 기본정보
            m_cMstService = (IMasterUs)sManager.InitServiceInstance(ServiceLists.ASV_MASTER.DLL, ServiceLists.ASV_MASTER.POS_MASTER);
        }

        /// <summary>
        /// 주방주문 내역 가져오기
        /// </summary>
        /// <param name="aParam"></param>
        /// <returns></returns>
        public object GetData(string[] aParam)
        {
            string sSaleDt = aParam[0];
            string sTblNo = aParam[1];
            string sTradeNo = aParam[2];
            string sOrdTime = aParam[3];

            string sQuery = "";
            string sRet = UserCom.ERROR;

            sSaleDt = aParam[0];
            sTradeNo = aParam[1];
            sOrdTime = aParam[2];
            sTblNo = aParam[3];

            try
            {
                sQuery = "";
                sQuery += " SELECT A.SALE_DT";
                //sQuery += "       ,A.POS_NO"; -- 결제 데이터를 기반으로 조회 하므로 POS번호는 단순 결제한 POS 번호만을 이야기 한다. 그래서 제외
                sQuery += "       ,A.TRADE_NO";
                sQuery += "       ,A.SEQ";
                sQuery += "       ,A.ORD_TIME";
                //sQuery += "       ,A.FLOOR_CD";
                sQuery += "       ,A.TBL_NO";
                sQuery += "       ,B.SHTCUT_ITEMNM";
                sQuery += "       ,A.ITEM_DIV";
                sQuery += "       ,A.SALE_QTY";
                //sQuery += "       ,A.CANCEL_DIV";
                sQuery += "  FROM [POSLOG].[dbo].[TR_SALE_DETAIL] AS A WITH(NOLOCK)";
	            sQuery += "    LEFT OUTER JOIN [POSMST].[dbo].[MST_ITEM] AS B ";
                sQuery += "    ON A.CMP_CD = B.CMP_CD ";
                sQuery += "    AND A.STOR_CD = B.STOR_CD ";
                sQuery += "    AND A.SUB_SHOP_CD = B.SUB_STOR_CD ";
                sQuery += "    AND A.ITEM_PLU_CD = B.ITEM_CD";
                sQuery += " WHERE A.CMP_CD = '" + m_cPosStatus.Base.CmpCd + "'";
                sQuery += " AND A.SALE_DT = '" + sSaleDt + "'";
                sQuery += " AND A.STOR_CD = '" + m_cPosStatus.Base.StoreNo + "'";
                //sQuery += " WHERE A.CMP_CD = 'PCKR'";
                //sQuery += " AND A.SALE_DT = '" + sSaleDt + "'";
                //sQuery += " AND A.STOR_CD = '0016868'";

                if (sTradeNo != "") 
                {
                    sQuery += " AND A.TRADE_NO = '' ";
                }
                if (sOrdTime != "")
                {
                    sQuery += " AND A.ORD_TIME = '' ";
                }
                if (sTblNo != "")
                {
                    sQuery += " AND A.TBL_NO = ''";
                } 
                
                DataTable dtDataInfo = m_cMstService.Select(new string[] { sQuery });

                if (dtDataInfo != null && dtDataInfo.Rows.Count > 0)
                {
                    return dtDataInfo;
                }
                return null;
            }
            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 null;
        }

        public string Execute(string[] aParam)
        {
            throw new NotImplementedException();
        }

        public string SetData(object oParam)
        {
            throw new NotImplementedException();
        }
    }
}
