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

namespace BLL
{
    public class DriverPrepareDriverConStudyService
    {
        /// <summary>
        /// 增加--开车资料收集
        /// </summary>
        public static void AddDriverPrepareDriverPlan(Model.DriverPrepare_ConStudy DriverPrepareDriverPlan)
        {
            using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
            {
                Model.DriverPrepare_ConStudy newDriverData = new Model.DriverPrepare_ConStudy();
                newDriverData.ConStudyId = DriverPrepareDriverPlan.ConStudyId;
                newDriverData.ProjectId = DriverPrepareDriverPlan.ProjectId;
                newDriverData.ConstudyName = DriverPrepareDriverPlan.ConstudyName;
                newDriverData.OrganizationMan = DriverPrepareDriverPlan.OrganizationMan;
                newDriverData.Code = DriverPrepareDriverPlan.Code;
                newDriverData.OrganizationDate = DriverPrepareDriverPlan.OrganizationDate;
                newDriverData.AttachUrl = DriverPrepareDriverPlan.AttachUrl;
                newDriverData.Remark = DriverPrepareDriverPlan.Remark;

                db.DriverPrepare_ConStudy.InsertOnSubmit(newDriverData);
                db.SubmitChanges();
            }
        }
        /// <summary>
        /// 修改--开车资料收集
        /// </summary>
        public static void UpdateDriverPrepareDriverPlan(Model.DriverPrepare_ConStudy DriverPrepareDriverPlan)
        {
            using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
            {
                Model.DriverPrepare_ConStudy newDriverData = db.DriverPrepare_ConStudy.FirstOrDefault(e => e.ConStudyId == DriverPrepareDriverPlan.ConStudyId);
                if (newDriverData != null)
                {
                    newDriverData.ProjectId = DriverPrepareDriverPlan.ProjectId;
                    newDriverData.ConstudyName = DriverPrepareDriverPlan.ConstudyName;
                    newDriverData.Code = DriverPrepareDriverPlan.Code;
                    newDriverData.OrganizationMan = DriverPrepareDriverPlan.OrganizationMan;
                    newDriverData.OrganizationDate = DriverPrepareDriverPlan.OrganizationDate;
                    newDriverData.AttachUrl = DriverPrepareDriverPlan.AttachUrl;
                    newDriverData.Remark = DriverPrepareDriverPlan.Remark;
                }
                db.SubmitChanges();
            }
        }

        /// <summary>
        /// 根据主键删除 开车资料收集
        /// </summary>
        /// <param name="DriverDataId"></param>
        public static void DeleteDriverPlan(string ConStudyId)
        {
            using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
            {
                Model.DriverPrepare_ConStudy newDriverData = db.DriverPrepare_ConStudy.FirstOrDefault(e => e.ConStudyId == ConStudyId);
                if (newDriverData != null)
                {
                    db.DriverPrepare_ConStudy.DeleteOnSubmit(newDriverData);
                    db.SubmitChanges();
                }
            }
        }

        /// <summary>
        /// 详情--开车资料收集
        /// </summary>
        public static Model.DriverPrepare_ConStudy GetDriverPlanById(string ConStudyId)
        {
            return Funs.DB.DriverPrepare_ConStudy.FirstOrDefault(e => e.ConStudyId == ConStudyId);
        }
    }
    
}