using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BLL
{
    /// 
    /// 一般设备机具出场报批主表
    /// 
    public static class GeneralEquipmentOutService
    {
        public static Model.SGGLDB db = Funs.DB;
        /// 
        /// 根据主键获取一般设备机具出场报批
        /// 
        /// 
        /// 
        public static Model.InApproveManager_GeneralEquipmentOut GetGeneralEquipmentOutById(string generalEquipmentOutId)
        {
            return Funs.DB.InApproveManager_GeneralEquipmentOut.FirstOrDefault(e => e.GeneralEquipmentOutId == generalEquipmentOutId);
        }
        /// 
        /// 添加一般设备机具出场报批
        /// 
        /// 
        public static void AddGeneralEquipmentOut(Model.InApproveManager_GeneralEquipmentOut generalEquipmentOut)
        {
            Model.SGGLDB db = Funs.DB;
            Model.InApproveManager_GeneralEquipmentOut newGeneralEquipmentOut = new Model.InApproveManager_GeneralEquipmentOut
            {
                GeneralEquipmentOutId = generalEquipmentOut.GeneralEquipmentOutId,
                ProjectId = generalEquipmentOut.ProjectId,
                GeneralEquipmentOutCode = generalEquipmentOut.GeneralEquipmentOutCode,
                UnitId = generalEquipmentOut.UnitId,
                ApplicationDate = generalEquipmentOut.ApplicationDate,
                CarNum = generalEquipmentOut.CarNum,
                CarModel = generalEquipmentOut.CarModel,
                DriverName = generalEquipmentOut.DriverName,
                DriverNum = generalEquipmentOut.DriverNum,
                TransPortStart = generalEquipmentOut.TransPortStart,
                TransPortEnd = generalEquipmentOut.TransPortEnd,
                State = generalEquipmentOut.State,
                CompileMan = generalEquipmentOut.CompileMan,
                CompileDate = generalEquipmentOut.CompileDate
            };
            db.InApproveManager_GeneralEquipmentOut.InsertOnSubmit(newGeneralEquipmentOut);
            db.SubmitChanges();
            CodeRecordsService.InsertCodeRecordsByMenuIdProjectIdUnitId(Const.GeneralEquipmentOutMenuId, generalEquipmentOut.ProjectId, null, generalEquipmentOut.GeneralEquipmentOutId, generalEquipmentOut.CompileDate);
        }
        /// 
        /// 修改一般设备机具出场报批
        /// 
        /// 
        public static void UpdateGeneralEquipmentOut(Model.InApproveManager_GeneralEquipmentOut generalEquipmentOut)
        {
            Model.SGGLDB db = Funs.DB;
            Model.InApproveManager_GeneralEquipmentOut newGeneralEquipmentOut = db.InApproveManager_GeneralEquipmentOut.FirstOrDefault(e => e.GeneralEquipmentOutId == generalEquipmentOut.GeneralEquipmentOutId);
            if (newGeneralEquipmentOut != null)
            {
                //newGeneralEquipmentOut.ProjectId = generalEquipmentOut.ProjectId;
                newGeneralEquipmentOut.GeneralEquipmentOutCode = generalEquipmentOut.GeneralEquipmentOutCode;
                newGeneralEquipmentOut.UnitId = generalEquipmentOut.UnitId;
                newGeneralEquipmentOut.ApplicationDate = generalEquipmentOut.ApplicationDate;
                newGeneralEquipmentOut.CarNum = generalEquipmentOut.CarNum;
                newGeneralEquipmentOut.CarModel = generalEquipmentOut.CarModel;
                newGeneralEquipmentOut.DriverName = generalEquipmentOut.DriverName;
                newGeneralEquipmentOut.DriverNum = generalEquipmentOut.DriverNum;
                newGeneralEquipmentOut.TransPortStart = generalEquipmentOut.TransPortStart;
                newGeneralEquipmentOut.TransPortEnd = generalEquipmentOut.TransPortEnd;
                newGeneralEquipmentOut.State = generalEquipmentOut.State;
                newGeneralEquipmentOut.CompileMan = generalEquipmentOut.CompileMan;
                newGeneralEquipmentOut.CompileDate = generalEquipmentOut.CompileDate;
                db.SubmitChanges();
            }
        }
        /// 
        /// 根据主键删除一般设备机具出场报批
        /// 
        /// 
        public static void DeleteGeneralEquipmentOutById(string generalEquipmentOutId)
        {
            Model.SGGLDB db = Funs.DB;
            Model.InApproveManager_GeneralEquipmentOut generalEquipmentOut = db.InApproveManager_GeneralEquipmentOut.FirstOrDefault(e => e.GeneralEquipmentOutId == generalEquipmentOutId);
            if (generalEquipmentOut != null)
            {
                CommonService.DeleteAttachFileById(generalEquipmentOutId);
                CodeRecordsService.DeleteCodeRecordsByDataId(generalEquipmentOutId);
                BLL.CommonService.DeleteFlowOperateByID(generalEquipmentOutId);  ////删除审核流程表
                db.InApproveManager_GeneralEquipmentOut.DeleteOnSubmit(generalEquipmentOut);
                db.SubmitChanges();
            }
        }
    }
}