using System.Collections.Generic;
using System.Linq;
namespace BLL
{
    /// 
    /// 热处理报告
    /// 
    public static class HotProessReportService
    {
        /// 
        /// 根据主键获取热处理报告
        /// 
        /// 
        /// 
        public static Model.HJGL_HotProess_Report GetHotProessReportById(string hotProessReportId)
        {
            return Funs.DB.HJGL_HotProess_Report.FirstOrDefault(e => e.HotProessReportId == hotProessReportId);
        }
        public static List GetHotProessReportListById(string hotProessTrustItemId)
        {
            return (from x in Funs.DB.HJGL_HotProess_Report where x.HotProessTrustItemId== hotProessTrustItemId select x).ToList();
        }
        /// 
        /// 添加热处理报告
        /// 
        /// 
        public static void AddHotProessReport(Model.HJGL_HotProess_Report hotProessReport)
        {
            Model.SGGLDB db = Funs.DB;
            Model.HJGL_HotProess_Report newHotProessReport = new Model.HJGL_HotProess_Report();
            newHotProessReport.HotProessReportId = hotProessReport.HotProessReportId;
            newHotProessReport.HotProessTrustItemId = hotProessReport.HotProessTrustItemId;
            newHotProessReport.WeldJointId = hotProessReport.WeldJointId;
            newHotProessReport.PointCount = hotProessReport.PointCount;
            newHotProessReport.RequiredT = hotProessReport.RequiredT;
            newHotProessReport.ActualT = hotProessReport.ActualT;
            newHotProessReport.RequestTime = hotProessReport.RequestTime;
            newHotProessReport.ActualTime = hotProessReport.ActualTime;
            newHotProessReport.RecordChartNo = hotProessReport.RecordChartNo;
            db.HJGL_HotProess_Report.InsertOnSubmit(newHotProessReport);
            db.SubmitChanges();
        }
        /// 
        /// 修改热处理报告
        /// 
        /// 
        public static void UpdateHotProessReport(Model.HJGL_HotProess_Report hotProessReport)
        {
            Model.SGGLDB db = Funs.DB;
            Model.HJGL_HotProess_Report newHotProessReport = db.HJGL_HotProess_Report.FirstOrDefault(e => e.HotProessReportId == hotProessReport.HotProessReportId);
            if (newHotProessReport != null)
            {
                newHotProessReport.PointCount = hotProessReport.PointCount;
                newHotProessReport.RequiredT = hotProessReport.RequiredT;
                newHotProessReport.ActualT = hotProessReport.ActualT;
                newHotProessReport.RequestTime = hotProessReport.RequestTime;
                newHotProessReport.ActualTime = hotProessReport.ActualTime;
                newHotProessReport.RecordChartNo = hotProessReport.RecordChartNo;
                db.SubmitChanges();
            }
        }
        /// 
        /// 根据主键删除热处理报告
        /// 
        /// 
        public static void DeleteHotProessReportById(string hotProessReportId)
        {
            Model.SGGLDB db = Funs.DB;
            Model.HJGL_HotProess_Report hotProessReport = db.HJGL_HotProess_Report.FirstOrDefault(e => e.HotProessReportId == hotProessReportId);
            if (hotProessReport != null)
            {
                db.HJGL_HotProess_Report.DeleteOnSubmit(hotProessReport);
                db.SubmitChanges();
            }
        }
        /// 
        /// 根据热处理委托主键删除热处理报告
        /// 
        /// 
        public static void DeleteAllHotProessReportById(string hotProessTrustItemId)
        {
            Model.SGGLDB db = Funs.DB;
            var hotProessReport = from x in Funs.DB.HJGL_HotProess_Report where x.HotProessTrustItemId == hotProessTrustItemId select x;
            if (hotProessReport.ToList().Count>0)
            {
                db.HJGL_HotProess_Report.DeleteAllOnSubmit(hotProessReport);
                db.SubmitChanges();
            }
        }
    }
}