using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Web.UI.WebControls;
namespace BLL
{
public static class Hazard_HazardListService
{
public static Model.SGGLDB db = Funs.DB;
///
/// 要求主键获取危险清单信息
///
/// 主键
///
public static Model.Hazard_HazardList GetHazardList(string hazardListId)
{
return Funs.DB.Hazard_HazardList.FirstOrDefault(e => e.HazardListId == hazardListId);
}
///
/// 查询版本号为空的危险清单的数量
///
/// 危险清单的数量
public static int GetHazardListCountByVersionNoIsNull(string projectId)
{
return (from x in db.Hazard_HazardList where x.VersionNo == null && x.ProjectId == projectId select x).Count();
}
///
/// 根据项目主键和开始、结束时间获得危险源辨识与评价清单的数量
///
/// 项目主键
/// 开始时间
/// 结束时间
///
public static int GetHazardListCountByProjectIdAndDate(string projectId, DateTime startTime, DateTime endTime)
{
var q = (from x in Funs.DB.Hazard_HazardList where x.ProjectId == projectId && x.CompileDate >= startTime && x.CompileDate <= endTime select x).ToList();
return q.Count();
}
///
/// 增加危险源辨识与评价清单信息
///
/// 危险源辨识与评价清单实体
public static void AddHazardList(Model.Hazard_HazardList hazardList)
{
Model.SGGLDB db = Funs.DB;
Model.Hazard_HazardList newHazardList = new Model.Hazard_HazardList
{
HazardListId = hazardList.HazardListId,
HazardListCode = hazardList.HazardListCode,
ProjectId = hazardList.ProjectId,
VersionNo = hazardList.VersionNo,
CompileMan = hazardList.CompileMan,
CompileDate = hazardList.CompileDate,
States = hazardList.States,
WorkStage = hazardList.WorkStage,
Contents = hazardList.Contents,
WorkAreaName = hazardList.WorkAreaName,
IdentificationDate = hazardList.IdentificationDate,
ControllingPerson = hazardList.ControllingPerson
};
Funs.DB.Hazard_HazardList.InsertOnSubmit(newHazardList);
Funs.DB.SubmitChanges();
////增加一条编码记录
BLL.CodeRecordsService.InsertCodeRecordsByMenuIdProjectIdUnitId(BLL.Const.ProjectHazardListMenuId, hazardList.ProjectId, null, hazardList.HazardListId, hazardList.CompileDate);
}
///
/// 修改危险源辨识与评价清单信息
///
/// 危险源辨识与评价清单实体
public static void UpdateHazardList(Model.Hazard_HazardList hazardList)
{
Model.SGGLDB db = Funs.DB;
Model.Hazard_HazardList newHazardList = db.Hazard_HazardList.FirstOrDefault(e => e.HazardListId == hazardList.HazardListId);
if (newHazardList != null)
{
newHazardList.HazardListCode = hazardList.HazardListCode;
//newHazardList.ProjectId = hazardList.ProjectId;
newHazardList.VersionNo = hazardList.VersionNo;
newHazardList.CompileMan = hazardList.CompileMan;
newHazardList.CompileDate = hazardList.CompileDate;
newHazardList.States = hazardList.States;
newHazardList.WorkStage = hazardList.WorkStage;
newHazardList.Contents = hazardList.Contents;
newHazardList.WorkAreaName = hazardList.WorkAreaName;
newHazardList.IdentificationDate = hazardList.IdentificationDate;
newHazardList.ControllingPerson = hazardList.ControllingPerson;
db.SubmitChanges();
}
}
///
/// 根据危险源辨识与评价清单Id删除一个危险源辨识与评价清单信息
///
/// 危险源辨识与评价清单Id
public static void DeleteHazardListByHazardListId(string hazardListId)
{
Model.SGGLDB db = Funs.DB;
Model.Hazard_HazardList hazardList = db.Hazard_HazardList.FirstOrDefault(e => e.HazardListId == hazardListId);
if (hazardList != null)
{
////删除审核流程表
BLL.CommonService.DeleteFlowOperateByID(hazardList.HazardListId);
///删除附件
BLL.CommonService.DeleteAttachFileById(hazardList.HazardListId);
///删除编码表记录
BLL.CodeRecordsService.DeleteCodeRecordsByDataId(hazardList.HazardListId);
db.Hazard_HazardList.DeleteOnSubmit(hazardList);
db.SubmitChanges();
}
}
///
/// 根据用户主键获得危险源辨识与评价清单的数量
///
/// 角色
///
public static int GetHazardListCountByUserId(string userId)
{
var q = (from x in Funs.DB.Hazard_HazardList where x.CompileMan == userId select x).ToList();
return q.Count();
}
///
/// 根据项目主键获得危险源辨识与评价清单的数量
///
/// 项目主键
///
public static int GetHazardListCountByProjectId(string projectId)
{
var q = (from x in Funs.DB.Hazard_HazardList where x.ProjectId == projectId select x).ToList();
return q.Count();
}
}
}