using MaxCommunication.DataBase.Document;
using PmsSecondaryPackaging.Interface.Model.Carrier;
using PmsSecondaryPackaging.Interface.Model.StepBook;
using PmsSecondaryPackaging.Interface.Model.TaskBook;
using PmsSecondaryPackaging.TaskManager.TaskBookBehavior;
using ProjectManagementSystem.NHibernateDBHelper;
using System.Collections.Generic;
using System.Threading;

namespace ProjectManagementSystem.TaskBookEvent
{
    public class TaskBookBehavior_61008 : BaseTaskBookBehavior
    {
        public TaskBookBehavior_61008() : base(61008)
        {

        }
        public override bool TaskBookSetting(TaskDetailInfoModel taskDetailInfo, List<StepDetailInfoModel> taskStepInfoList, CarrierInfoModel carrierInfo)
        {
            //IsEnable = false; Asynchronous = true;
            return base.TaskBookSetting(taskDetailInfo, taskStepInfoList, carrierInfo);
        }


        public override bool TaskBookTermination(TaskDetailInfoModel taskDetailInfo, List<StepDetailInfoModel> taskStepInfoList, CarrierInfoModel carrierInfo)
        {
            return base.TaskBookTermination(taskDetailInfo, taskStepInfoList, carrierInfo);
        }

        public override bool TaskBookOperator(TaskDetailInfoModel taskDetailInfo, List<StepDetailInfoModel> taskStepInfoList, CarrierInfoModel carrierInfo)
        {
            bool successed = false;
            StepDetailInfoModel currentStep = taskStepInfoList.Find(p => p.StepId == taskDetailInfo.CurrentStepID);
            string strCurWareHouse = currentStep.WareHouseID;
            try
            {
                using (var session = WMSDBModelHelper.Session)
                {
                    var result = session.QueryOver<WareHouseLocation>().Where(p => p.LocationCode == strCurWareHouse).List();
                    if (result.Count > 0)
                    {
                        WareHouseLocation order = result[0];
                        order.Status = "2";
                        session.Update(order);
                        TextDocument.WriteFile(@"PMS/Log", "下料61008", string.Format("更新当前目标库位：{0}，小车：{1}，置满", order.LocationCode, taskDetailInfo.Carrier));

                    }
                    session.Flush();
                    successed = true;

                }
            }
            catch
            {

            }
            return successed;
        }
    }
}

