using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BLL
{
///
/// 安全隐患主表
///
public static class RectifyService
{
public static Model.SGGLDB db = Funs.DB;
///
/// 根据主键获取安全隐患
///
///
///
public static Model.Technique_Rectify GetRectifyById(string rectifyId)
{
return Funs.DB.Technique_Rectify.FirstOrDefault(e => e.RectifyId == rectifyId);
}
///
/// 根据上一节点id获取安全隐患
///
///
///
public static List GetRectifyBySupRectifyId(string supRectifyId)
{
return (from x in Funs.DB.Technique_Rectify where x.SupRectifyId == supRectifyId select x).ToList();
}
///
/// 添加安全隐患
///
///
public static void AddRectify(Model.Technique_Rectify rectify)
{
Model.SGGLDB db = Funs.DB;
Model.Technique_Rectify newRectify = new Model.Technique_Rectify
{
RectifyId = rectify.RectifyId,
RectifyCode = rectify.RectifyCode,
RectifyName = rectify.RectifyName,
SupRectifyId = rectify.SupRectifyId,
IsEndLever = rectify.IsEndLever
};
newRectify.UpState = newRectify.UpState;
db.Technique_Rectify.InsertOnSubmit(newRectify);
db.SubmitChanges();
}
///
/// 修改安全隐患
///
///
public static void UpdateRectify(Model.Technique_Rectify rectify)
{
Model.SGGLDB db = Funs.DB;
Model.Technique_Rectify newRectify = db.Technique_Rectify.FirstOrDefault(e => e.RectifyId == rectify.RectifyId);
if (newRectify != null)
{
newRectify.RectifyCode = rectify.RectifyCode;
newRectify.RectifyName = rectify.RectifyName;
newRectify.SupRectifyId = rectify.SupRectifyId;
newRectify.IsEndLever = rectify.IsEndLever;
newRectify.UpState = newRectify.UpState;
db.SubmitChanges();
}
}
///
/// 根据主键删除安全隐患
///
///
public static void DeleteRectify(string rectifyId)
{
Model.SGGLDB db = Funs.DB;
Model.Technique_Rectify rectify = db.Technique_Rectify.FirstOrDefault(e => e.RectifyId == rectifyId);
if (rectify != null)
{
db.Technique_Rectify.DeleteOnSubmit(rectify);
db.SubmitChanges();
}
}
///
/// 是否可删除资源节点
///
///
/// true-可以,false-不可以
public static bool IsDeleteRectify(string rectifyId)
{
bool isDelete = true;
var rectify = BLL.RectifyService.GetRectifyById(rectifyId);
if (rectify != null)
{
if (rectify.IsBuild == true)
{
isDelete = false;
}
if (rectify.IsEndLever == true)
{
var detailCout = Funs.DB.Technique_RectifyItem.FirstOrDefault(x => x.RectifyId == rectifyId);
if (detailCout != null)
{
isDelete = false;
}
}
else
{
var supItemSetCount = BLL.RectifyService.GetRectifyBySupRectifyId(rectifyId);
if (supItemSetCount.Count() > 0)
{
isDelete = false;
}
}
}
return isDelete;
}
}
}