using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BLL
{
    /// 
    /// 原材料问题
    /// 
    public static class RowMaterialProblemService
    {
        public static Model.SUBQHSEDB db = Funs.DB;
        /// 
        /// 根据主键获取原材料问题
        /// 
        /// 
        /// 
        public static Model.Report_RowMaterialProblem GetRowMaterialProblemById(string rowMaterialProblemId)
        {
            return Funs.DB.Report_RowMaterialProblem.FirstOrDefault(e => e.RowMaterialProblemId == rowMaterialProblemId);
        }
        /// 
        /// 根据周(月)报Id获取相关原材料问题
        /// 
        /// 
        /// 
        public static List GetRowMaterialProblemByReportId(string reportId)
        {
            return (from x in db.Report_RowMaterialProblem where x.ReportId == reportId select x).ToList();
        }
        /// 
        /// 添加原材料问题
        /// 
        /// 
        public static void AddRowMaterialProblem(Model.Report_RowMaterialProblem rowMaterialProblem)
        {
            Model.SUBQHSEDB db = Funs.DB;
            Model.Report_RowMaterialProblem newRowMaterialProblem = new Model.Report_RowMaterialProblem();
            newRowMaterialProblem.RowMaterialProblemId = rowMaterialProblem.RowMaterialProblemId;
            newRowMaterialProblem.ReportId = rowMaterialProblem.ReportId;
            newRowMaterialProblem.UnitId = rowMaterialProblem.UnitId;
            newRowMaterialProblem.ProblemDesrioption = rowMaterialProblem.ProblemDesrioption;
            newRowMaterialProblem.TreatmentMeasures = rowMaterialProblem.TreatmentMeasures;
            newRowMaterialProblem.ProcessingResults = rowMaterialProblem.ProcessingResults;
            newRowMaterialProblem.Remark = rowMaterialProblem.Remark;
            db.Report_RowMaterialProblem.InsertOnSubmit(newRowMaterialProblem);
            db.SubmitChanges();
        }
        /// 
        /// 根据周(月)报Id删除所有相关原材料问题
        /// 
        /// 
        public static void DeleteRowMaterialProbleByReportId(string reportId)
        {
            Model.SUBQHSEDB db = Funs.DB;
            var q = (from x in db.Report_RowMaterialProblem where x.ReportId == reportId select x).ToList();
            if (q.Count() > 0)
            {
                db.Report_RowMaterialProblem.DeleteAllOnSubmit(q);
                db.SubmitChanges();
            }
        }
    }
}