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-10-20
    /// </summary>
    public class QTYCompletionRateBLL : BaseBLL
    {
        public DataResult<List<QTYCompletionRateDModel>> GetAllList(QTYCompletionRateDModel condition)
        {
            DataResult<List<QTYCompletionRateDModel>> result = new DataResult<List<QTYCompletionRateDModel>>();
            try
            {
                result.Result = new QTYCompletionRateDAL().GetAllList(condition);
                result.IsSuccess = true;
                return result;
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Msg = ex.ToString();
                return result;
            }
        }
        //注塑
        public DataResult<List<QTYCompletionRateDModel>> GetAllListNew1(QTYCompletionRateDModel condition)
        {
            DataResult<List<QTYCompletionRateDModel>> result = new DataResult<List<QTYCompletionRateDModel>>();
            try
            {
                //result.Result = new QTYCompletionRateDAL().GetAllListNew1(condition);
                var qtys = new QTYCompletionRateDAL().GetAllListNew1(condition);
                //var materials = new MaterialBLL().GetAllList(new Material());
                //foreach (QTYCompletionRateDModel item in qtys)
                //{
                //    //处理人
                //    if (!string.IsNullOrEmpty(item.MATERIAL_CODE))
                //    {
                //        var material = materials.FirstOrDefault(x => x.MATERIAL_CODE == item.MATERIAL_CODE);
                //        if (material != null)
                //        {
                //            item.MATERIAL_NAME = material.MATERIAL_NAME;
                //            item.MATERIAL_SHORT = material.MATERIAL_SHORT;
                //        }
                //    }
                //}
                result.Result = qtys;
                result.IsSuccess = true;
                return result;
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Msg = ex.ToString();
                return result;
            }
        }
        //门板
        public DataResult<List<QTYCompletionRateDModel>> GetAllListNew2(QTYCompletionRateDModel condition)
        {
            DataResult<List<QTYCompletionRateDModel>> result = new DataResult<List<QTYCompletionRateDModel>>();
            try
            {
                //result.Result = new QTYCompletionRateDAL().GetAllListNew2(condition);
                var qtys = new QTYCompletionRateDAL().GetAllListNew2(condition);
                //var materials = new MaterialBLL().GetAllList(new Material());
                //foreach (QTYCompletionRateDModel item in qtys)
                //{
                //    //处理人
                //    if (!string.IsNullOrEmpty(item.MATERIAL_CODE))
                //    {
                //        var material = materials.FirstOrDefault(x => x.MATERIAL_CODE == item.MATERIAL_CODE);
                //        if (material != null)
                //        {
                //            item.MATERIAL_NAME = material.MATERIAL_NAME;
                //            item.MATERIAL_SHORT = material.MATERIAL_SHORT;
                //        }
                //    }
                //}
                result.Result = qtys;
                result.IsSuccess = true;
                return result;
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Msg = ex.ToString();
                return result;
            }
        }
        //仪表板
        public DataResult<List<QTYCompletionRateDModel>> GetAllListNew3(QTYCompletionRateDModel condition)
        {
            DataResult<List<QTYCompletionRateDModel>> result = new DataResult<List<QTYCompletionRateDModel>>();
            try
            {
                var qtys = new QTYCompletionRateDAL().GetAllListNew3(condition);
                //var materials = new MaterialBLL().GetAllList(new Material());
                //foreach (QTYCompletionRateDModel item in qtys)
                //{
                //    //处理人
                //    if (!string.IsNullOrEmpty(item.MATERIAL_CODE))
                //    {
                //        var material = materials.FirstOrDefault(x => x.MATERIAL_CODE == item.MATERIAL_CODE);
                //        if (material != null)
                //        {
                //            item.MATERIAL_NAME = material.MATERIAL_NAME;
                //            item.MATERIAL_SHORT = material.MATERIAL_SHORT;
                //        }
                //    }
                //}
                result.Result = qtys;
                result.IsSuccess = true;
                return result;
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Msg = ex.ToString();
                return result;
            }
        }

        #region 导出数据
        /// <summary>
        /// 获取导出的数据
        /// </summary>
        /// <param name="user">查询条件</param>
        /// <returns>数据</returns>
        public DataResult<DataTable> GetExportData(QTYCompletionRateDModel model)
        {
            DataResult<DataTable> result = new DataResult<DataTable>();
            try
            {
                result.IsSuccess = true;
                result.Result = new QTYCompletionRateDAL().GetExportData(model);
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Msg = "导出错误!";
            }
            return result;
        }
        #endregion

    }
}