using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BLL
{
    public static class ProjectArchitectureReportService
    {
        /// 
        /// 建筑行业能源节约与生态环境保护汇总表
        /// 
        /// 建筑行业能源节约与生态环境保护汇总表Id
        /// 建筑行业能源节约与生态环境保护汇总表
        public static Model.Environmental_ProjectArchitectureReport GetArchitectureReportByArchitectureReportId(string ArchitectureReportId)
        {
            return Funs.DB.Environmental_ProjectArchitectureReport.FirstOrDefault(e => e.ArchitectureReportId == ArchitectureReportId);
        }
        /// 
        /// 建筑行业能源节约与生态环境保护汇总表
        /// 
        /// 单位Id
        ///  年度  param >
        /// 月份
        /// 建筑行业能源节约与生态环境保护汇总表
        public static Model.Environmental_ProjectArchitectureReport GetArchitectureReportByProjectIdAndYearAndQuarters(string projectId, int year, int Month)
        {
            return Funs.DB.Environmental_ProjectArchitectureReport.FirstOrDefault(e => e.ProjectId == projectId && e.Month == Month && e.Year == year);
        }
        /// 
        /// 根据单位Id获取建筑行业能源节约与生态环境保护汇总表集合
        /// 
        /// 单位Id
        /// 建筑行业能源节约与生态环境保护汇总表集合
        public static List GetArchitectureReportsByProjectId(string ProjectId)
        {
            return (from x in Funs.DB.View_Environmental_ProjectArchitectureReport where x.ProjectId == ProjectId orderby x.FillingDate descending select x).ToList();
        }
        /// 
        /// 增加建筑行业能源节约与生态环境保护汇总表
        /// 
        /// 建筑行业能源节约与生态环境保护汇总表实体
        public static void AddArchitectureReport(Model.Environmental_ProjectArchitectureReport ArchitectureReport)
        {
            Model.Environmental_ProjectArchitectureReport newArchitectureReport = new Model.Environmental_ProjectArchitectureReport
            {
                ArchitectureReportId = ArchitectureReport.ArchitectureReportId,
                Year = ArchitectureReport.Year,
                Month = ArchitectureReport.Month,
                ProjectId = ArchitectureReport.ProjectId,
                FillingDate = ArchitectureReport.FillingDate,
                DutyPerson = ArchitectureReport.DutyPerson,
                FillingMan = ArchitectureReport.FillingMan,
                UpState = ArchitectureReport.UpState,
            };
            Funs.DB.Environmental_ProjectArchitectureReport.InsertOnSubmit(newArchitectureReport);
            Funs.DB.SubmitChanges();
        }
        /// 
        /// 修改建筑行业能源节约与生态环境保护汇总表
        /// 
        /// 建筑行业能源节约与生态环境保护汇总表实体
        public static void UpdateArchitectureReport(Model.Environmental_ProjectArchitectureReport ArchitectureReport)
        {
            Model.Environmental_ProjectArchitectureReport newArchitectureReport = Funs.DB.Environmental_ProjectArchitectureReport.FirstOrDefault(e => e.ArchitectureReportId == ArchitectureReport.ArchitectureReportId);
            if (newArchitectureReport != null)
            {
                newArchitectureReport.Year = ArchitectureReport.Year;
                newArchitectureReport.Month = ArchitectureReport.Month;
                newArchitectureReport.ProjectId = ArchitectureReport.ProjectId;
                newArchitectureReport.FillingDate = ArchitectureReport.FillingDate;
                newArchitectureReport.DutyPerson = ArchitectureReport.DutyPerson;
                newArchitectureReport.UpState = ArchitectureReport.UpState;
                Funs.DB.SubmitChanges();
            }
        }
        /// 
        /// 根据Id获取数据
        /// 
        /// 
        public static void DeleteArchitectureReportByArchitectureReportId(string ArchitectureReportId)
        {
            Model.Environmental_ProjectArchitectureReport newArchitectureReport = Funs.DB.Environmental_ProjectArchitectureReport.FirstOrDefault(e => e.ArchitectureReportId == ArchitectureReportId);
            if (newArchitectureReport != null)
            {
                Funs.DB.Environmental_ProjectArchitectureReport.DeleteOnSubmit(newArchitectureReport);
                Funs.DB.SubmitChanges();
            }
        }
        /// 
        /// 根据报表单位,报表时间判断是否存在
        /// 
        /// Id
        /// 
        public static Model.Environmental_ProjectArchitectureReport GetArchitectureReportByProjectIdDate(string ProjectId, int year, int Month)
        {
            return Funs.DB.Environmental_ProjectArchitectureReport.FirstOrDefault(e => e.ProjectId == ProjectId && e.Year == year && e.Month == Month);
        }
        /// 
        /// 根据报表单位,报表年份获取对应集合
        /// 
        /// Id
        /// 
        public static List GetArchitectureReportByProjectIdYear(string ProjectId, int year)
        {
            return (from x in Funs.DB.Environmental_ProjectArchitectureReport where x.ProjectId == ProjectId && x.Year == year select x).ToList();
        }
    }
}