using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BLL
{
    /// 
    /// 开车物资计划
    /// 
    public static class GoodsPlanService
    {
        /// 
        /// 根据主键获取开车物资计划信息
        /// 
        /// 
        /// 
        public static Model.DriverGoods_GoodsPlan GetGoodsPlanById(string GoodsPlanId)
        {
            return Funs.DB.DriverGoods_GoodsPlan.FirstOrDefault(e => e.GoodsPlanId == GoodsPlanId);
        }
        /// 
        /// 添加开车物资计划信息
        /// 
        /// 
        public static void AddGoodsPlan(Model.DriverGoods_GoodsPlan GoodsPlan)
        {
            Model.DriverGoods_GoodsPlan newGoodsPlan = new Model.DriverGoods_GoodsPlan();
            newGoodsPlan.GoodsPlanId = GoodsPlan.GoodsPlanId;
            newGoodsPlan.ProjectId = GoodsPlan.ProjectId;
            newGoodsPlan.Code = GoodsPlan.Code;
            newGoodsPlan.PlanName = GoodsPlan.PlanName;
            newGoodsPlan.PlanCode = GoodsPlan.PlanCode;
            newGoodsPlan.CompileMan = GoodsPlan.CompileMan;
            newGoodsPlan.ApprovalDate = GoodsPlan.ApprovalDate;
            newGoodsPlan.AttachUrl = GoodsPlan.AttachUrl;
            newGoodsPlan.Remark = GoodsPlan.Remark;
            Funs.DB.DriverGoods_GoodsPlan.InsertOnSubmit(newGoodsPlan);
            Funs.DB.SubmitChanges();
        }
        /// 
        /// 修改开车物资计划
        /// 
        /// 
        public static void UpdateGoodsPlan(Model.DriverGoods_GoodsPlan GoodsPlan)
        {
            Model.DriverGoods_GoodsPlan newGoodsPlan = Funs.DB.DriverGoods_GoodsPlan.FirstOrDefault(e => e.GoodsPlanId == GoodsPlan.GoodsPlanId);
            if (newGoodsPlan != null)
            {
                newGoodsPlan.Code = GoodsPlan.Code;
                newGoodsPlan.PlanName = GoodsPlan.PlanName;
                newGoodsPlan.PlanCode = GoodsPlan.PlanCode;
                //newGoodsPlan.CompileMan = GoodsPlan.CompileMan;
                newGoodsPlan.ApprovalDate = GoodsPlan.ApprovalDate;
                newGoodsPlan.AttachUrl = GoodsPlan.AttachUrl;
                newGoodsPlan.Remark = GoodsPlan.Remark;
                Funs.DB.SubmitChanges();
            }
        }
        /// 
        /// 根据主键删除开车物资计划
        /// 
        /// 
        public static void DeleteGoodsPlan(string GoodsPlanId)
        {
            Model.DriverGoods_GoodsPlan GoodsPlan = Funs.DB.DriverGoods_GoodsPlan.FirstOrDefault(e => e.GoodsPlanId == GoodsPlanId);
            if (GoodsPlan != null)
            {
                if (!string.IsNullOrEmpty(GoodsPlan.AttachUrl))
                {
                    BLL.UploadAttachmentService.DeleteFile(Funs.RootPath, GoodsPlan.AttachUrl);//删除附件
                }
                Funs.DB.DriverGoods_GoodsPlan.DeleteOnSubmit(GoodsPlan);
                Funs.DB.SubmitChanges();
            }
        }
    }
}