using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace BLL
{
    public static class HotProessManageService
    {
        public static Model.SUBQHSEDB db = Funs.DB;
        /// 
        /// 记录数
        /// 
        private static int count
        {
            get;
            set;
        }
        /// 
        /// 获取分页列表
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        public static IEnumerable GetListData(string projectId, string pipelineManageCode,string jointInfoCode, string hotProessReportCode, string hotHardManageCode, int startRowIndex, int maximumRows)
        {
            IQueryable q = from x in db.ProcessControl_HotProessManage
                                                                 where x.ProjectId == projectId
                                                                 orderby x.HotHardManageCode descending
                                                                 select x;
            if (!string.IsNullOrEmpty(projectId))
            {
                q = q.Where(e => e.ProjectId == projectId);
            }
            if (!string.IsNullOrEmpty(jointInfoCode))
            {
                q = q.Where(e => e.JointInfoCode.Contains(jointInfoCode));
            }
            if (!string.IsNullOrEmpty(pipelineManageCode))
            {
                q = q.Where(e => e.PipelineManageCode.Contains(pipelineManageCode));
            }
            if (!string.IsNullOrEmpty(hotProessReportCode))
            {
                q = q.Where(e => e.HotProessReportCode.Contains(hotProessReportCode));
            }
            if (!string.IsNullOrEmpty(hotHardManageCode))
            {
                q = q.Where(e => e.HotHardManageCode.Contains(hotHardManageCode));
            }
            count = q.Count();
            if (count == 0)
            {
                return new object[] { "" };
            }
            return from x in q.Skip(startRowIndex).Take(maximumRows)
                   select new
                   {
                       x.HotProessManageId,
                       x.ProjectId,
                       x.PipelineManageCode,
                       x.JointInfoCode,
                       x.STE_ID,
                       x.Specification,
                       x.HotProessReportCode,
                       x.HotHardManageCode,
                       x.CompileMan
                   };
        }
        /// 
        /// 获取分页列表数
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        public static int GetListCount(string projectId, string pipelineManageCode, string jointInfoCode, string hotProessReportCode, string hotHardManageCode)
        {
            return count;
        }
        /// 
        /// 根据主键获取热处理检测
        /// 
        /// 
        /// 
        public static Model.ProcessControl_HotProessManage GetHotProessManageById(string hotProessManageId)
        {
            return Funs.DB.ProcessControl_HotProessManage.FirstOrDefault(e => e.HotProessManageId == hotProessManageId);
        }
        /// 
        /// 添加热处理检测
        /// 
        /// 
        public static void AddHotProessManage(Model.ProcessControl_HotProessManage hotProessManage)
        {
            Model.SUBQHSEDB db = Funs.DB;
            Model.ProcessControl_HotProessManage newHotProessManage = new Model.ProcessControl_HotProessManage();
            newHotProessManage.HotProessManageId = hotProessManage.HotProessManageId;
            newHotProessManage.ProjectId = hotProessManage.ProjectId;
            newHotProessManage.PipelineManageCode = hotProessManage.PipelineManageCode;
            newHotProessManage.JointInfoCode = hotProessManage.JointInfoCode;
            newHotProessManage.STE_ID = hotProessManage.STE_ID;
            newHotProessManage.Specification = hotProessManage.Specification;
            newHotProessManage.HotProessReportCode = hotProessManage.HotProessReportCode;
            newHotProessManage.HotHardManageCode = hotProessManage.HotHardManageCode;
            newHotProessManage.CompileMan = hotProessManage.CompileMan;
            db.ProcessControl_HotProessManage.InsertOnSubmit(newHotProessManage);
            db.SubmitChanges();
        }
        /// 
        /// 修改热处理检测
        /// 
        /// 
        public static void UpdateHotProessManage(Model.ProcessControl_HotProessManage hotProessManage)
        {
            Model.SUBQHSEDB db = Funs.DB;
            Model.ProcessControl_HotProessManage newHotProessManage = db.ProcessControl_HotProessManage.FirstOrDefault(e => e.HotProessManageId == hotProessManage.HotProessManageId);
            if (newHotProessManage != null)
            {
                newHotProessManage.ProjectId = hotProessManage.ProjectId;
                newHotProessManage.PipelineManageCode = hotProessManage.PipelineManageCode;
                newHotProessManage.JointInfoCode = hotProessManage.JointInfoCode;
                newHotProessManage.STE_ID = hotProessManage.STE_ID;
                newHotProessManage.Specification = hotProessManage.Specification;
                newHotProessManage.HotProessReportCode = hotProessManage.HotProessReportCode;
                newHotProessManage.HotHardManageCode = hotProessManage.HotHardManageCode;
                //newHotProessManage.CompileMan = hotProessManage.CompileMan;
                db.SubmitChanges();
            }
        }
        /// 
        /// 根据主键删除热处理检测
        /// 
        /// 
        public static void DeleteHotProessManage(string hotProessManageId)
        {
            Model.SUBQHSEDB db = Funs.DB;
            Model.ProcessControl_HotProessManage inspectionManagement = db.ProcessControl_HotProessManage.FirstOrDefault(e => e.HotProessManageId == hotProessManageId);
            if (inspectionManagement != null)
            {
                db.ProcessControl_HotProessManage.DeleteOnSubmit(inspectionManagement);
                db.SubmitChanges();
            }
        }
    }
}