using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BLL
{
    /// 
    /// 运行记录管理
    /// 
    public static class PropertyRunRecordService
    {
        /// 
        /// 根据主键获取运行记录管理信息
        /// 
        /// 
        /// 
        public static Model.ProduceProperty_PropertyRunRecord GetPropertyRunRecordById(string PropertyRunRecordId)
        {
            return Funs.DB.ProduceProperty_PropertyRunRecord.FirstOrDefault(e => e.PropertyRunRecordId == PropertyRunRecordId);
        }
        /// 
        /// 添加运行记录管理信息
        /// 
        /// 
        public static void AddPropertyRunRecord(Model.ProduceProperty_PropertyRunRecord PropertyRunRecord)
        {
            Model.ProduceProperty_PropertyRunRecord newPropertyRunRecord = new Model.ProduceProperty_PropertyRunRecord();
            newPropertyRunRecord.PropertyRunRecordId = PropertyRunRecord.PropertyRunRecordId;
            newPropertyRunRecord.ProjectId = PropertyRunRecord.ProjectId;
            newPropertyRunRecord.Code = PropertyRunRecord.Code;
            newPropertyRunRecord.UnitWorkId = PropertyRunRecord.UnitWorkId;
            newPropertyRunRecord.InstallationMan = PropertyRunRecord.InstallationMan;
            newPropertyRunRecord.RecordName = PropertyRunRecord.RecordName;
            newPropertyRunRecord.RecordCode = PropertyRunRecord.RecordCode;
            newPropertyRunRecord.RecordMan = PropertyRunRecord.RecordMan;
            newPropertyRunRecord.StartDate = PropertyRunRecord.StartDate;
            newPropertyRunRecord.EndDate = PropertyRunRecord.EndDate;
            newPropertyRunRecord.RecordInstructions = PropertyRunRecord.RecordInstructions;
            newPropertyRunRecord.ProblemsSolutions = PropertyRunRecord.ProblemsSolutions;
            newPropertyRunRecord.AttachUrl = PropertyRunRecord.AttachUrl;
            newPropertyRunRecord.Remark = PropertyRunRecord.Remark;
            Funs.DB.ProduceProperty_PropertyRunRecord.InsertOnSubmit(newPropertyRunRecord);
            Funs.DB.SubmitChanges();
        }
        /// 
        /// 修改运行记录管理
        /// 
        /// 
        public static void UpdatePropertyRunRecord(Model.ProduceProperty_PropertyRunRecord PropertyRunRecord)
        {
            Model.ProduceProperty_PropertyRunRecord newPropertyRunRecord = Funs.DB.ProduceProperty_PropertyRunRecord.FirstOrDefault(e => e.PropertyRunRecordId == PropertyRunRecord.PropertyRunRecordId);
            if (newPropertyRunRecord != null)
            {
                newPropertyRunRecord.Code = PropertyRunRecord.Code;
                newPropertyRunRecord.UnitWorkId = PropertyRunRecord.UnitWorkId;
                newPropertyRunRecord.InstallationMan = PropertyRunRecord.InstallationMan;
                newPropertyRunRecord.RecordName = PropertyRunRecord.RecordName;
                newPropertyRunRecord.RecordCode = PropertyRunRecord.RecordCode;
                // newPropertyRunRecord.RecordMan = PropertyRunRecord.RecordMan;
                newPropertyRunRecord.StartDate = PropertyRunRecord.StartDate;
                newPropertyRunRecord.EndDate = PropertyRunRecord.EndDate;
                newPropertyRunRecord.RecordInstructions = PropertyRunRecord.RecordInstructions;
                newPropertyRunRecord.ProblemsSolutions = PropertyRunRecord.ProblemsSolutions;
                newPropertyRunRecord.AttachUrl = PropertyRunRecord.AttachUrl;
                newPropertyRunRecord.Remark = PropertyRunRecord.Remark;
                Funs.DB.SubmitChanges();
            }
        }
        /// 
        /// 根据主键删除运行记录管理
        /// 
        /// 
        public static void DeletePropertyRunRecord(string PropertyRunRecordId)
        {
            Model.ProduceProperty_PropertyRunRecord PropertyRunRecord = Funs.DB.ProduceProperty_PropertyRunRecord.FirstOrDefault(e => e.PropertyRunRecordId == PropertyRunRecordId);
            if (PropertyRunRecord != null)
            {
                if (!string.IsNullOrEmpty(PropertyRunRecord.AttachUrl))
                {
                    BLL.UploadAttachmentService.DeleteFile(Funs.RootPath, PropertyRunRecord.AttachUrl);//删除附件
                }
                Funs.DB.ProduceProperty_PropertyRunRecord.DeleteOnSubmit(PropertyRunRecord);
                Funs.DB.SubmitChanges();
            }
        }
    }
}