using System.Linq;
namespace BLL
{
    /// 
    /// 完工报告
    /// 
    public static class CompletionReportService
    {
        public static Model.CNPCDB db = Funs.DB;
        /// 
        /// 根据主键获取完工报告
        /// 
        /// 
        /// 
        public static Model.Manager_CompletionReport GetCompletionReportById(string completionReportId)
        {
            return Funs.DB.Manager_CompletionReport.FirstOrDefault(e => e.CompletionReportId == completionReportId);
        }
        /// 
        /// 添加完工报告
        /// 
        /// 
        public static void AddCompletionReport(Model.Manager_CompletionReport completionReport)
        {
            Model.CNPCDB db = Funs.DB;
            Model.Manager_CompletionReport newCompletionReport = new Model.Manager_CompletionReport
            {
                CompletionReportId = completionReport.CompletionReportId,
                ProjectId = completionReport.ProjectId,
                CompletionReportCode = completionReport.CompletionReportCode,
                CompletionReportName = completionReport.CompletionReportName,
                FileContent = completionReport.FileContent,
                CompileMan = completionReport.CompileMan,
                CompileDate = completionReport.CompileDate,
                States = completionReport.States
            };
            db.Manager_CompletionReport.InsertOnSubmit(newCompletionReport);
            db.SubmitChanges();
            ////增加一条编码记录
            BLL.CodeRecordsService.InsertCodeRecordsByMenuIdProjectIdUnitId(BLL.Const.ProjectCompletionReportMenuId, completionReport.ProjectId, null, completionReport.CompletionReportId, completionReport.CompileDate);
        }
        /// 
        /// 修改完工报告
        /// 
        /// 
        public static void UpdateCompletionReport(Model.Manager_CompletionReport completionReport)
        {
            Model.CNPCDB db = Funs.DB;
            Model.Manager_CompletionReport newCompletionReport = db.Manager_CompletionReport.FirstOrDefault(e => e.CompletionReportId == completionReport.CompletionReportId);
            if (newCompletionReport != null)
            {
                //newCompletionReport.ProjectId = completionReport.ProjectId;
                newCompletionReport.CompletionReportCode = completionReport.CompletionReportCode;
                newCompletionReport.CompletionReportName = completionReport.CompletionReportName;
                newCompletionReport.FileContent = completionReport.FileContent;
                newCompletionReport.CompileMan = completionReport.CompileMan;
                newCompletionReport.CompileDate = completionReport.CompileDate;
                newCompletionReport.States = completionReport.States;
                db.SubmitChanges();
            }
        }
        /// 
        /// 根据主键删除完工报告
        /// 
        /// 
        public static void DeleteCompletionReportById(string completionReportId)
        {
            Model.CNPCDB db = Funs.DB;
            Model.Manager_CompletionReport completionReport = db.Manager_CompletionReport.FirstOrDefault(e => e.CompletionReportId == completionReportId);
            if (completionReport != null)
            {
                ///删除编码表记录
                BLL.CodeRecordsService.DeleteCodeRecordsByDataId(completionReportId);
                BLL.CommonService.DeleteAttachFileById(completionReportId);//删除附件
                BLL.CommonService.DeleteFlowOperateByID(completionReportId);//删除审核流程
                db.Manager_CompletionReport.DeleteOnSubmit(completionReport);
                db.SubmitChanges();
            }
        }
    }
}