using FineUIPro;
using Model;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace BLL
{
    /// 
    /// 项目信息
    /// 
    public static class SYHSEData_HiddenDangersService
    {
        public static Model.CNPCDB db = Funs.DB;
        #region 获取列表信息
        /// 
        /// 记录数
        /// 
        public static int count
        {
            get;
            set;
        }
        /// 
        /// 定义变量
        /// 
        private static IQueryable getDataLists = from x in db.SYHSEData_HiddenDangers select x;
        /// 
        ///   数据列表
        /// 
        /// 单位ID
        /// 开始日期
        /// 结束日期
        /// 
        /// 
        public static IEnumerable getListData(string projectId,string type, string startTime, string endTime, Grid Grid1)
        {
            IQueryable getDataList = getDataLists.OrderByDescending(x => x.CheckDate);
            if (!string.IsNullOrEmpty(projectId) && projectId != Const._Null)
            {
                getDataList = getDataList.Where(e => e.ProjectId == projectId);
            }
            if (!string.IsNullOrEmpty(startTime))
            {
                getDataList = getDataList.Where(e => e.CheckDate >= Funs.GetNewDateTime(startTime));
            }
            if (!string.IsNullOrEmpty(type))
            {
                getDataList = getDataList.Where(e => e.Type== type);
            }
            if (!string.IsNullOrEmpty(endTime))
            {
                getDataList = getDataList.Where(e => e.CheckDate <= Funs.GetNewDateTime(endTime));
            }
            count = getDataList.Count();
            if (count == 0)
            {
                return null;
            }
            getDataList = SortConditionHelper.SortingAndPaging(getDataList, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
            return from x in getDataList
                   select new
                   {
                       x.Id,
                       x.UnitId,
                       x.ProjectId,
                       x.DangerDes,
                       x.CheckDate,
                       x.CheckUnit,
                       x.CheckPerson,
                       x.ConfirmPerson,
                       x.RiskLevel,
                       x.RiskAddress,
                       x.ResponseMan,
                       x.RectificationStatus,
                       x.Status,
                       x.CreateMan,
                       x.CreateDate,
                       x.PicBefore,                       
                       x.Type,
                       x.PicAfter,
                       x.ResponseUnit
                   };
        }
        #endregion
        #region 根据Id删除一个信息
        /// 
        /// 根据Id删除一个信息
        /// 
        /// 
        public static void DeleteProjectById(string id)
        {
            using (Model.CNPCDB db = new Model.CNPCDB(Funs.ConnString))
            {
                var getData = db.SYHSEData_HiddenDangers.FirstOrDefault(e => e.Id == id);
                if (getData != null)
                {
                    db.SYHSEData_HiddenDangers.DeleteOnSubmit(getData);
                    db.SubmitChanges();
                }
            }
        }
        #endregion
    }
}