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

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

        #region 劳务人员列表
        /// <summary>
        /// 记录数
        /// </summary>
        public static int count
        {
            get;
            set;
        }

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

        /// <summary>
        /// 数据列表
        /// </summary>
        /// <param name="projetcId"></param>
        /// <param name="unitId"></param>
        /// <param name="workPostId"></param>
        /// <param name="name"></param>
        /// <param name="idCard"></param>
        /// <param name="states"></param>
        /// <param name="Grid1"></param>
        /// <returns></returns>
        public static IEnumerable getListData(string projetcId, string unitId, string name, string idCard, string states, Grid Grid1)
        {
            IQueryable<Model.View_SitePerson_Person> 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 (!string.IsNullOrEmpty(states) && states != "-2")
            {
                if (states == "1")
                {
                    getDataList = getDataList.Where(e => e.IsUsed == true);
                }
                else {
                    getDataList = getDataList.Where(e => e.IsUsed == false);
                }
                
            }
            if (!string.IsNullOrEmpty(name))
            {
                getDataList = getDataList.Where(e => e.PersonName.Contains(name));
            }
            if (!string.IsNullOrEmpty(idCard))
            {
                getDataList = getDataList.Where(e => e.IdentityCard.Contains(idCard));
            }
            count = getDataList.Count();
            if (count == 0)
            {
                return null;
            }
            getDataList = SortConditionHelper.SortingAndPaging(getDataList.OrderBy(x => x.UnitId), Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
            return from x in getDataList
                   select new
                   {
                       //ProjectPersonId = x.SitePersonId + "#" + x.PersonId,
                       ProjectPersonId =x.PersonId,
                       x.PersonName,
                       x.CardNo,
                       x.IdentityCard,
                       x.Sex,
                       x.SexName,
                       x.UnitId,
                       x.UnitName,
                       x.WorkPostId,
                       x.WorkPostName,
                       x.ProjectId,
                       ProjectName = db.Base_Project.First(u => u.ProjectId == x.ProjectId).ShortName,
                       x.TeamGroupId,
                       x.TeamGroupName,
                       x.InTime,
                       x.OutTime,
                       x.States,
                       OutName = (x.States == "2" ? "是" : "否"),
                       x.StarMark,
                       x.StarLevelId,
                       x.LevelValue,
                   };
        }
        #endregion
    }
}