using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BLL
{
    /// 
    /// 运行报表管理
    /// 
    public static class PropertyRunReportService
    {
        /// 
        /// 根据主键获取运行报表管理信息
        /// 
        /// 
        /// 
        public static Model.ProduceProperty_PropertyRunReport GetPropertyRunReportById(string PropertyRunReportId)
        {
            return Funs.DB.ProduceProperty_PropertyRunReport.FirstOrDefault(e => e.PropertyRunReportId == PropertyRunReportId);
        }
        /// 
        /// 添加运行报表管理信息
        /// 
        /// 
        public static void AddPropertyRunReport(Model.ProduceProperty_PropertyRunReport PropertyRunReport)
        {
            Model.ProduceProperty_PropertyRunReport newPropertyRunReport = new Model.ProduceProperty_PropertyRunReport();
            newPropertyRunReport.PropertyRunReportId = PropertyRunReport.PropertyRunReportId;
            newPropertyRunReport.ProjectId = PropertyRunReport.ProjectId;
            newPropertyRunReport.Code = PropertyRunReport.Code;
            newPropertyRunReport.UnitWorkId = PropertyRunReport.UnitWorkId;
            newPropertyRunReport.InstallationMan = PropertyRunReport.InstallationMan;
            newPropertyRunReport.ReportName = PropertyRunReport.ReportName;
            newPropertyRunReport.ReportCode = PropertyRunReport.ReportCode;
            newPropertyRunReport.ReportMan = PropertyRunReport.ReportMan;
            newPropertyRunReport.StartDate = PropertyRunReport.StartDate;
            newPropertyRunReport.EndDate = PropertyRunReport.EndDate;
            newPropertyRunReport.AttachUrl = PropertyRunReport.AttachUrl;
            newPropertyRunReport.Remark = PropertyRunReport.Remark;
            Funs.DB.ProduceProperty_PropertyRunReport.InsertOnSubmit(newPropertyRunReport);
            Funs.DB.SubmitChanges();
        }
        /// 
        /// 修改运行报表管理
        /// 
        /// 
        public static void UpdatePropertyRunReport(Model.ProduceProperty_PropertyRunReport PropertyRunReport)
        {
            Model.ProduceProperty_PropertyRunReport newPropertyRunReport = Funs.DB.ProduceProperty_PropertyRunReport.FirstOrDefault(e => e.PropertyRunReportId == PropertyRunReport.PropertyRunReportId);
            if (newPropertyRunReport != null)
            {
                newPropertyRunReport.Code = PropertyRunReport.Code;
                newPropertyRunReport.UnitWorkId = PropertyRunReport.UnitWorkId;
                newPropertyRunReport.InstallationMan = PropertyRunReport.InstallationMan;
                newPropertyRunReport.ReportName = PropertyRunReport.ReportName;
                newPropertyRunReport.ReportCode = PropertyRunReport.ReportCode;
                //newPropertyRunReport.ReportMan = PropertyRunReport.ReportMan;
                newPropertyRunReport.StartDate = PropertyRunReport.StartDate;
                newPropertyRunReport.EndDate = PropertyRunReport.EndDate;
                newPropertyRunReport.AttachUrl = PropertyRunReport.AttachUrl;
                newPropertyRunReport.Remark = PropertyRunReport.Remark;
                Funs.DB.SubmitChanges();
            }
        }
        /// 
        /// 根据主键删除运行报表管理
        /// 
        /// 
        public static void DeletePropertyRunReport(string PropertyRunReportId)
        {
            Model.ProduceProperty_PropertyRunReport PropertyRunReport = Funs.DB.ProduceProperty_PropertyRunReport.FirstOrDefault(e => e.PropertyRunReportId == PropertyRunReportId);
            if (PropertyRunReport != null)
            {
                if (!string.IsNullOrEmpty(PropertyRunReport.AttachUrl))
                {
                    BLL.UploadAttachmentService.DeleteFile(Funs.RootPath, PropertyRunReport.AttachUrl);//删除附件
                }
                Funs.DB.ProduceProperty_PropertyRunReport.DeleteOnSubmit(PropertyRunReport);
                Funs.DB.SubmitChanges();
            }
        }
    }
}