using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BLL
{
    /// 
    /// 施工过程问题
    /// 
    public static class ConstructionProblemsService
    {
        public static Model.SGGLDB db = Funs.DB;
        /// 
        /// 根据主键获取施工过程问题
        /// 
        /// 
        /// 
        public static Model.Report_ConstructionProblems GetConstructionProblemsById(string constructionProblemsId)
        {
            return Funs.DB.Report_ConstructionProblems.FirstOrDefault(e => e.ConstructionProblemsId == constructionProblemsId);
        }
        /// 
        /// 根据周(月)报Id获取施工过程问题
        /// 
        /// 
        /// 
        public static List GetConstructionProblemsByReportId(string reportId)
        {
            return (from x in Funs.DB.Report_ConstructionProblems where x.ReportId == reportId select x).ToList();
        }
        /// 
        /// 根据周(月)报Id获取施工过程问题视图列表
        /// 
        /// 
        /// 
        public static List GetConstructionProblemsViewListByReportId(string reportId)
        {
            return (from x in Funs.DB.View_Report_ConstructionProblems where x.ReportId == reportId select x).ToList();
        }
        /// 
        /// 添加施工过程问题
        /// 
        /// 
        public static void AddConstructionProblems(Model.Report_ConstructionProblems constructionProblems)
        {
            Model.SGGLDB db = Funs.DB;
            Model.Report_ConstructionProblems newConstructionProblems = new Model.Report_ConstructionProblems();
            newConstructionProblems.ConstructionProblemsId = constructionProblems.ConstructionProblemsId;
            newConstructionProblems.ReportId = constructionProblems.ReportId;
            newConstructionProblems.UnitId = constructionProblems.UnitId;
            newConstructionProblems.ProblemDesrioption = constructionProblems.ProblemDesrioption;
            newConstructionProblems.TreatmentMeasures = constructionProblems.TreatmentMeasures;
            newConstructionProblems.ProcessingResults = constructionProblems.ProcessingResults;
            newConstructionProblems.Remark = constructionProblems.Remark;
            db.Report_ConstructionProblems.InsertOnSubmit(newConstructionProblems);
            db.SubmitChanges();
        }
        /// 
        /// 根据周(月)报Id删除所有相关明细信息
        /// 
        /// 
        public static void DeleteConstructionProblemsByReportId(string reportId)
        {
            Model.SGGLDB db = Funs.DB;
            var q = (from x in db.Report_ConstructionProblems where x.ReportId == reportId select x).ToList();
            if (q.Count() > 0)
            {
                db.Report_ConstructionProblems.DeleteAllOnSubmit(q);
                db.SubmitChanges();
            }
        }
    }
}