using FineUIPro;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace BLL
{
    public class ProjectConstructionLogService
    {
        public static Model.SGGLDB db = Funs.DB;

        #region 获取人员列表信息
        /// <summary>
        /// 记录数
        /// </summary>
        public static int count
        {
            get;
            set;
        }

        /// <summary>
        /// 定义变量
        /// </summary>
        private static IQueryable<Model.InformationProject_ConstructionLog> getDataLists = from x in db.InformationProject_ConstructionLog
                                                                                           select x;

        /// <summary>
        /// 数据列表
        /// </summary>
        /// <param name="unitId"></param>
        /// <param name="projetcId"></param>
        /// <param name="name"></param>
        /// <param name="Grid1"></param>
        /// <returns></returns>
        public static IEnumerable getListData(string projetcId, string unitId, DateTime? startTime, DateTime? endTime, Grid Grid1)
        {
            IQueryable<Model.InformationProject_ConstructionLog> getDataList = getDataLists;
            if (!string.IsNullOrEmpty(projetcId) && projetcId != Const._Null)
            {
                getDataList = getDataList.Where(e => e.ProjectId == projetcId);
            }
            if (!string.IsNullOrEmpty(unitId) && unitId != Const._Null)
            {
                getDataList = getDataList.Where(e => e.UnitId == unitId);
            }

            if (startTime.HasValue)
            {
                getDataList = getDataList.Where(e => e.WorkDate >= startTime);
            }
            if (endTime.HasValue)
            {
                getDataList = getDataList.Where(e => e.WorkDate <= endTime);
            }

            count = getDataList.Count();
            if (count == 0)
            {
                return null;
            }
            var getData = from x in getDataList select new { x.ProjectId, x.UnitId, x.WorkDate };
            return from x in SortConditionHelper.SortingAndPaging(getData.Distinct(), Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize)
                   select new
                   {
                       ID = (x.UnitId ?? x.ProjectId + "|" + Convert.ToString(x.WorkDate ?? DateTime.Now)),
                       x.ProjectId,
                       ProjectName = ProjectService.GetProjectNameByProjectId(x.ProjectId),
                       x.UnitId,
                       UnitName = UnitService.GetUnitNameByUnitId(x.UnitId),
                       x.WorkDate,
                   };
        }
        #endregion
    }
}