using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    /// <summary>
    /// 其他巡检记录管理
    /// </summary>
    public static class TestRunOthersCheckService
    {
        /// <summary>
        /// 根据主键获取其他巡检记录管理
        /// </summary>
        /// <param name="testRunOthersCheckId"></param>
        /// <returns></returns>
        public static Model.ProduceTestRun_TestRunOthersCheck GetTestRunOthersCheckById(string testRunOthersCheckId)
        {
            return Funs.DB.ProduceTestRun_TestRunOthersCheck.FirstOrDefault(e => e.TestRunOthersCheckId == testRunOthersCheckId);
        }

        /// <summary>
        /// 添加其他巡检记录管理
        /// </summary>
        /// <param name="testRunOthersCheck"></param>
        public static void AddTestRunOthersCheck(Model.ProduceTestRun_TestRunOthersCheck testRunOthersCheck)
        {
            Model.ProduceTestRun_TestRunOthersCheck newTestRunOthersCheck = new Model.ProduceTestRun_TestRunOthersCheck();
            newTestRunOthersCheck.TestRunOthersCheckId = testRunOthersCheck.TestRunOthersCheckId;
            newTestRunOthersCheck.ProjectId = testRunOthersCheck.ProjectId;
            newTestRunOthersCheck.UnitWorkId = testRunOthersCheck.UnitWorkId;
            newTestRunOthersCheck.UnitHead = testRunOthersCheck.UnitHead;
            newTestRunOthersCheck.CheckRecord = testRunOthersCheck.CheckRecord;
            newTestRunOthersCheck.TestRunOthersCheckCode = testRunOthersCheck.TestRunOthersCheckCode;
            newTestRunOthersCheck.CheckMan = testRunOthersCheck.CheckMan;
            newTestRunOthersCheck.Major = testRunOthersCheck.Major;
            newTestRunOthersCheck.StartDate = testRunOthersCheck.StartDate;
            newTestRunOthersCheck.EndDate = testRunOthersCheck.EndDate;
            newTestRunOthersCheck.Description = testRunOthersCheck.Description;
            newTestRunOthersCheck.ProblemsAndSolutions = testRunOthersCheck.ProblemsAndSolutions;
            newTestRunOthersCheck.AttachUrl = testRunOthersCheck.AttachUrl;
            newTestRunOthersCheck.Remark = testRunOthersCheck.Remark;
            Funs.DB.ProduceTestRun_TestRunOthersCheck.InsertOnSubmit(newTestRunOthersCheck);
            Funs.DB.SubmitChanges();
        }

        /// <summary>
        /// 修改其他巡检记录管理
        /// </summary>
        /// <param name="testRunOthersCheck"></param>
        public static void UpdateTestRunOthersCheck(Model.ProduceTestRun_TestRunOthersCheck testRunOthersCheck)
        {
            Model.ProduceTestRun_TestRunOthersCheck newTestRunOthersCheck = Funs.DB.ProduceTestRun_TestRunOthersCheck.FirstOrDefault(e => e.TestRunOthersCheckId == testRunOthersCheck.TestRunOthersCheckId);
            if (newTestRunOthersCheck != null)
            {
                newTestRunOthersCheck.ProjectId = testRunOthersCheck.ProjectId;
                newTestRunOthersCheck.UnitWorkId = testRunOthersCheck.UnitWorkId;
                newTestRunOthersCheck.UnitHead = testRunOthersCheck.UnitHead;
                newTestRunOthersCheck.CheckRecord = testRunOthersCheck.CheckRecord;
                newTestRunOthersCheck.TestRunOthersCheckCode = testRunOthersCheck.TestRunOthersCheckCode;
                newTestRunOthersCheck.CheckMan = testRunOthersCheck.CheckMan;
                newTestRunOthersCheck.Major = testRunOthersCheck.Major;
                newTestRunOthersCheck.StartDate = testRunOthersCheck.StartDate;
                newTestRunOthersCheck.EndDate = testRunOthersCheck.EndDate;
                newTestRunOthersCheck.Description = testRunOthersCheck.Description;
                newTestRunOthersCheck.ProblemsAndSolutions = testRunOthersCheck.ProblemsAndSolutions;
                newTestRunOthersCheck.AttachUrl = testRunOthersCheck.AttachUrl;
                newTestRunOthersCheck.Remark = testRunOthersCheck.Remark;
                Funs.DB.SubmitChanges();
            }
        }

        /// <summary>
        /// 根据主键删除其他巡检记录管理
        /// </summary>
        /// <param name="testRunOthersCheckId"></param>
        public static void DeleteTestRunOthersCheckById(string testRunOthersCheckId)
        {
            Model.ProduceTestRun_TestRunOthersCheck newTestRunOthersCheck = Funs.DB.ProduceTestRun_TestRunOthersCheck.FirstOrDefault(e => e.TestRunOthersCheckId == testRunOthersCheckId);
            if (newTestRunOthersCheck != null)
            {
                if (!string.IsNullOrEmpty(newTestRunOthersCheck.AttachUrl))
                {
                    UploadAttachmentService.DeleteFile(Funs.RootPath, newTestRunOthersCheck.AttachUrl);
                }
                Funs.DB.ProduceTestRun_TestRunOthersCheck.DeleteOnSubmit(newTestRunOthersCheck);
                Funs.DB.SubmitChanges();
            }
        }
    }
}