using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMFrameWork.Data;
using QMAPP.MESReport.Entity.LineQTY;
using QMAPP.MESReport.DAL.LineQTY;
using QMAPP.BLL;
using QMAPP.Entity;
using System.Data;
using QMAPP.MD.BLL;
using QMAPP.MD.Entity;

namespace QMAPP.MESReport.BLL.LineQTY
{
    /// <summary>
    /// 节拍统计
    /// 于子清
    /// 2017-11-1
    /// </summary>
    public class ProduceCycleTimeBLL : BaseBLL
    {
        public DataResult<List<ProduceCycleTimeDModel>> GetAllList(ProduceCycleTimeDModel condition)
        {
            DataResult<List<ProduceCycleTimeDModel>> result = new DataResult<List<ProduceCycleTimeDModel>>();
            try
            {
                result.Result = new ProduceCycleTimeDAL().GetAllList(condition);
                result.IsSuccess = true;
                return result;
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Msg = ex.ToString();
                return result;
            }
        }
        public DataResult<List<ProduceCycleTimeDModel>> GetAllListShift(ProduceCycleTimeDModel condition)
        {
            DataResult<List<ProduceCycleTimeDModel>> result = new DataResult<List<ProduceCycleTimeDModel>>();
            try
            {
                result.Result = new ProduceCycleTimeDAL().GetAllListShift(condition);
                var workCells = new WorkCellBLL().GetWorkCellList(new WorkCell());
                foreach (ProduceCycleTimeDModel item in result.Result)
                {
                    item.OK_QTY = (Int32.Parse(item.QTY) - Int32.Parse(item.NOK_QTY)).ToString();
                    //中文名
                    if (!string.IsNullOrEmpty(item.WORKCELL_CODE))
                    {
                        var workCell = workCells.FirstOrDefault(x => x.WORKCELL_CODE == item.WORKCELL_CODE);
                        if (workCell != null)
                        {
                            item.WORKCELL_NAME = workCell.WORKCELL_NAME;
                        }
                    }
                }
                result.IsSuccess = true;
                return result;
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Msg = ex.ToString();
                return result;
            }
        }
    }
}