using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BLL
{
    /// 
    /// 标准规范
    /// 
    public static class ConstructionStandardListProjectService
    {
        /// 
        /// 根据项目标准规范清单Id获取一个项目标准规范清单信息
        /// 
        /// 项目标准规范清单Id
        /// 一个项目标准规范清单实体
        public static Model.CQMS_Law_ConstructionStandardListProject GetConstructionStandardListProjectByStandardCode(int standardCode, string projectId)
        {
            return Funs.DB.CQMS_Law_ConstructionStandardListProject.FirstOrDefault(x => x.StandardCode == standardCode && x.ProjectId == projectId);
        }
        /// 
        /// 查询的项目标准规范信息的数量
        /// 
        /// 项目标准规范信息的数量
        public static int GetCountConstructionStandardListProject(string projectId)
        {
            return (from x in Funs.DB.CQMS_Law_ConstructionStandardListProject where x.ProjectId == projectId select x).Count();
        }
        /// 
        /// 查询最大的项目标准规范序号
        /// 
        /// 最大的项目标准规范序号
        public static int GetMaxStandardCode(string projectId)
        {
            return (from x in Funs.DB.CQMS_Law_ConstructionStandardListProject where x.ProjectId == projectId select x.StandardCode).Max();
        }
        /// 
        /// 增加项目标准规范清单信息
        /// 
        /// 项目标准规范清单实体
        public static void AddConstructionStandardListProject(Model.CQMS_Law_ConstructionStandardListProject ConstructionStandardListProject)
        {
            Model.CQMS_Law_ConstructionStandardListProject newConstructionStandardListProject = new Model.CQMS_Law_ConstructionStandardListProject();
            newConstructionStandardListProject.StandardCode = ConstructionStandardListProject.StandardCode;
            newConstructionStandardListProject.ProjectId = ConstructionStandardListProject.ProjectId;
            newConstructionStandardListProject.StandardGrade = ConstructionStandardListProject.StandardGrade;
            newConstructionStandardListProject.StandardNo = ConstructionStandardListProject.StandardNo;
            newConstructionStandardListProject.StandardName = ConstructionStandardListProject.StandardName;
            newConstructionStandardListProject.AttachUrl = ConstructionStandardListProject.AttachUrl;
            newConstructionStandardListProject.Memo = ConstructionStandardListProject.Memo;
            newConstructionStandardListProject.Status = ConstructionStandardListProject.Status;
            newConstructionStandardListProject.ImpDate = ConstructionStandardListProject.ImpDate;
            newConstructionStandardListProject.PubDate = ConstructionStandardListProject.PubDate;
            newConstructionStandardListProject.UseLevel = ConstructionStandardListProject.UseLevel;
            newConstructionStandardListProject.StandardType = ConstructionStandardListProject.StandardType;
            newConstructionStandardListProject.ReplaceStandard = ConstructionStandardListProject.ReplaceStandard;
            newConstructionStandardListProject.IsSelected1 = ConstructionStandardListProject.IsSelected1;
            newConstructionStandardListProject.IsSelected2 = ConstructionStandardListProject.IsSelected2;
            newConstructionStandardListProject.IsSelected3 = ConstructionStandardListProject.IsSelected3;
            newConstructionStandardListProject.IsSelected4 = ConstructionStandardListProject.IsSelected4;
            newConstructionStandardListProject.IsSelected5 = ConstructionStandardListProject.IsSelected5;
            newConstructionStandardListProject.IsSelected6 = ConstructionStandardListProject.IsSelected6;
            newConstructionStandardListProject.IsSelected7 = ConstructionStandardListProject.IsSelected7;
            newConstructionStandardListProject.IsSelected8 = ConstructionStandardListProject.IsSelected8;
            newConstructionStandardListProject.IsSelected9 = ConstructionStandardListProject.IsSelected9;
            newConstructionStandardListProject.IsSelected10 = ConstructionStandardListProject.IsSelected10;
            Funs.DB.CQMS_Law_ConstructionStandardListProject.InsertOnSubmit(newConstructionStandardListProject);
            Funs.DB.SubmitChanges();
        }
        /// 
        /// 修改项目标准规范清单信息
        /// 
        /// 项目标准规范清单实体
        public static void UpdateConstructionStandardListProject(Model.CQMS_Law_ConstructionStandardListProject ConstructionStandardListProject)
        {
            Model.CQMS_Law_ConstructionStandardListProject newConstructionStandardListProject = Funs.DB.CQMS_Law_ConstructionStandardListProject.FirstOrDefault(e => e.StandardCode == ConstructionStandardListProject.StandardCode && e.ProjectId == ConstructionStandardListProject.ProjectId);
            if (newConstructionStandardListProject != null)
            {
                newConstructionStandardListProject.StandardGrade = ConstructionStandardListProject.StandardGrade;
                newConstructionStandardListProject.StandardNo = ConstructionStandardListProject.StandardNo;
                newConstructionStandardListProject.StandardName = ConstructionStandardListProject.StandardName;
                newConstructionStandardListProject.AttachUrl = ConstructionStandardListProject.AttachUrl;
                newConstructionStandardListProject.Memo = ConstructionStandardListProject.Memo;
                newConstructionStandardListProject.Status = ConstructionStandardListProject.Status;
                newConstructionStandardListProject.ImpDate = ConstructionStandardListProject.ImpDate;
                newConstructionStandardListProject.PubDate = ConstructionStandardListProject.PubDate;
                newConstructionStandardListProject.UseLevel = ConstructionStandardListProject.UseLevel;
                newConstructionStandardListProject.StandardType = ConstructionStandardListProject.StandardType;
                newConstructionStandardListProject.ReplaceStandard = ConstructionStandardListProject.ReplaceStandard;
                newConstructionStandardListProject.IsSelected1 = ConstructionStandardListProject.IsSelected1;
                newConstructionStandardListProject.IsSelected2 = ConstructionStandardListProject.IsSelected2;
                newConstructionStandardListProject.IsSelected3 = ConstructionStandardListProject.IsSelected3;
                newConstructionStandardListProject.IsSelected4 = ConstructionStandardListProject.IsSelected4;
                newConstructionStandardListProject.IsSelected5 = ConstructionStandardListProject.IsSelected5;
                newConstructionStandardListProject.IsSelected6 = ConstructionStandardListProject.IsSelected6;
                newConstructionStandardListProject.IsSelected7 = ConstructionStandardListProject.IsSelected7;
                newConstructionStandardListProject.IsSelected8 = ConstructionStandardListProject.IsSelected8;
                newConstructionStandardListProject.IsSelected9 = ConstructionStandardListProject.IsSelected9;
                newConstructionStandardListProject.IsSelected10 = ConstructionStandardListProject.IsSelected10;
                Funs.DB.SubmitChanges();
            }
        }
        /// 
        /// 根据项目标准规范清单Id删除一个项目标准规范清单信息
        /// 
        /// 项目标准规范清单Id
        public static void DeleteConstructionStandardListProject(int standardCode, string projectId)
        {
            Model.CQMS_Law_ConstructionStandardListProject ConstructionStandardListProject = Funs.DB.CQMS_Law_ConstructionStandardListProject.First(e => e.StandardCode == standardCode && e.ProjectId == projectId);
            if (ConstructionStandardListProject != null)
            {
                Funs.DB.CQMS_Law_ConstructionStandardListProject.DeleteOnSubmit(ConstructionStandardListProject);
                Funs.DB.SubmitChanges();
            }
        }
        /// 
        /// 根据项目ID删除所有标准规范
        /// 
        /// 
        public static void DeleteConstructionStandardListByProjectId(string projectId)
        {
            var ConstructionStandardList = from x in Funs.DB.CQMS_Law_ConstructionStandardListProject where x.ProjectId == projectId select x;
            if (ConstructionStandardList != null)
            {
                Funs.DB.CQMS_Law_ConstructionStandardListProject.DeleteAllOnSubmit(ConstructionStandardList);
                Funs.DB.SubmitChanges();
            }
        }
        /// 
        /// 根据项目信息获取项目标准规范标准级别列表
        /// 
        /// 
        /// 
        public static List GetStandardGradeDistinctList(string projectId)
        {
            return ((from x in Funs.DB.CQMS_Law_ConstructionStandardListProject where x.ProjectId == projectId orderby x.StandardGrade select x.StandardGrade).Distinct()).ToList();
        }
    }
}