using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BLL
{
    /// 
    /// 热处理明细
    /// 
    public static class HotProessTrustItemService
    {
        /// 
        /// 根据主键获取热处理明细
        /// 
        /// 
        /// 
        public static Model.HJGL_HotProess_TrustItem GetHotProessTrustItemById(string hotProessTrustItemId)
        {
            return Funs.DB.HJGL_HotProess_TrustItem.FirstOrDefault(e => e.HotProessTrustItemId == hotProessTrustItemId);
        }
        /// 
        /// 根据热处理Id获取相关明细信息
        /// 
        /// 
        /// 
        public static List GetHotProessTrustItemByHotProessTrustId(string hotProessTrustId)
        {
            return (from x in Funs.DB.HJGL_HotProess_TrustItem where x.HotProessTrustId == hotProessTrustId select x).ToList();
        }
        /// 
        /// 添加热处理明细
        /// 
        /// 
        public static void AddHotProessTrustItem(Model.HJGL_HotProess_TrustItem hotProessTrustItem)
        {
            Model.SGGLDB db = Funs.DB;
            Model.HJGL_HotProess_TrustItem newHotProessTrustItem = new Model.HJGL_HotProess_TrustItem();
            newHotProessTrustItem.HotProessTrustItemId = SQLHelper.GetNewID(typeof(Model.HJGL_HotProess_TrustItem));
            newHotProessTrustItem.HotProessTrustId = hotProessTrustItem.HotProessTrustId;
            newHotProessTrustItem.WeldJointId = hotProessTrustItem.WeldJointId;
            newHotProessTrustItem.IsPass = hotProessTrustItem.IsPass;
            newHotProessTrustItem.IsHardness = hotProessTrustItem.IsHardness;
            newHotProessTrustItem.IsTrust = hotProessTrustItem.IsTrust;
            newHotProessTrustItem.HardTrustItemID = hotProessTrustItem.HardTrustItemID;
            db.HJGL_HotProess_TrustItem.InsertOnSubmit(newHotProessTrustItem);
            db.SubmitChanges();
        }
        /// 
        /// 修改热处理
        /// 
        /// 
        public static void UpdateHotProessTrustItem(Model.HJGL_HotProess_TrustItem hotProessTrustItem)
        {
            Model.SGGLDB db = Funs.DB;
            Model.HJGL_HotProess_TrustItem newHotProessTrustItem = db.HJGL_HotProess_TrustItem.FirstOrDefault(e => e.HotProessTrustItemId == hotProessTrustItem.HotProessTrustItemId);
            if (newHotProessTrustItem != null)
            {
                newHotProessTrustItem.HotProessTrustId = hotProessTrustItem.HotProessTrustId;
                newHotProessTrustItem.WeldJointId = hotProessTrustItem.WeldJointId;
                newHotProessTrustItem.IsPass = hotProessTrustItem.IsPass;
                newHotProessTrustItem.IsHardness = hotProessTrustItem.IsHardness;
                newHotProessTrustItem.IsTrust = hotProessTrustItem.IsTrust;
                newHotProessTrustItem.HardTrustItemID = hotProessTrustItem.HardTrustItemID;
                db.SubmitChanges();
            }
        }
        /// 
        /// 修改热处理反馈及硬度委托信息
        /// 
        /// 
        public static void UpdateHotProessFeedback(Model.HJGL_HotProess_TrustItem hotProessTrustItem)
        {
            Model.SGGLDB db = Funs.DB;
            Model.HJGL_HotProess_TrustItem newHotProessTrustItem = db.HJGL_HotProess_TrustItem.FirstOrDefault(e => e.HotProessTrustItemId == hotProessTrustItem.HotProessTrustItemId);
            if (newHotProessTrustItem != null)
            {
                newHotProessTrustItem.IsCompleted = hotProessTrustItem.IsCompleted;
                newHotProessTrustItem.IsHardness = hotProessTrustItem.IsHardness;
                db.SubmitChanges();
            }
        }
        /// 
        /// 根据热处理主键删除相关明细信息
        /// 
        /// 
        public static void DeleteHotProessTrustItemById(string hotProessTrustId)
        {
            Model.SGGLDB db = Funs.DB;
            var hotProessTrustItem = (from x in db.HJGL_HotProess_TrustItem where x.HotProessTrustId == hotProessTrustId select x).ToList();
            if (hotProessTrustItem != null)
            {
                db.HJGL_HotProess_TrustItem.DeleteAllOnSubmit(hotProessTrustItem);
                db.SubmitChanges();
            }
        }
        /// 
        /// 根据项目ID、热处理Id获取相关明细视图信息
        /// 
        /// 
        /// 
        /// 
        public static List GetViewHotProessTrustItem(string projectId, string hotProessTrustId)
        {
            return (from x in Funs.DB.View_HJGL_HotProess_TrustItem where x.ProjectId == projectId && x.HotProessTrustId == hotProessTrustId select x).ToList();
        }
    }
}