SGGL_JT/SUBQHSE/BLL/HSSE/Check/SafetyOfficerCheckService.cs

158 lines
6.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Web.UI.WebControls;
using Model;
namespace BLL
{
public class SafetyOfficerCheckService
{
public static Model.SUBQHSEDB db = Funs.DB;
/// <summary>
/// 添加
/// </summary>
/// <param name="model"></param>
public static void Add(Check_SafetyOfficerCheck model) {
SUBQHSEDB db = Funs.DB;
model.CompileDate = DateTime.Now;
db.Check_SafetyOfficerCheck.InsertOnSubmit(model);
db.SubmitChanges();
}
/// <summary>
/// 修改
/// </summary>
/// <param name="model"></param>
public static void Update(Check_SafetyOfficerCheck model) {
Model.SUBQHSEDB db = Funs.DB;
Check_SafetyOfficerCheck newModel = db.Check_SafetyOfficerCheck.FirstOrDefault(x => x.SafetyOfficerCheckId == model.SafetyOfficerCheckId);
if (newModel!=null)
{
//把附件表的路径复制过来
Model.AttachFile file = BLL.AttachFileService.GetAttachFile(model.SafetyOfficerCheckId, Const.Check_SafetyOfficerCheckMenuId);
newModel.HandleIdea = model.HandleIdea;
newModel.ReceiveMan = model.ReceiveMan;
newModel.State = model.State;
newModel.CompileDate = model.CompileDate;
newModel.CompileMan = model.CompileMan;
if (file != null)
{
newModel.ImageUrl = file.AttachUrl;
}
db.SubmitChanges();
}
}
/// <summary>
/// 删除
/// </summary>
/// <param name="modelId">主键ID</param>
public static void Delete(string modelId)
{
SUBQHSEDB db = Funs.DB;
Check_SafetyOfficerCheck model = db.Check_SafetyOfficerCheck.FirstOrDefault(e => e.SafetyOfficerCheckId == modelId);
if (model != null)
{
try
{
BLL.UploadFileService.DeleteFile(Funs.RootPath, model.ImageUrl);//删除整改前图片
}
catch (Exception)
{
}
db.Check_SafetyOfficerCheck.DeleteOnSubmit(model);
db.SubmitChanges();
}
}
/// <summary>
/// 小程序获取列表
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
public static List<Model.Customization.ListSafetyOfficer> getSafetyOfficerList(string state,string userid)
{
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString))
{
var list = from x in db.Check_SafetyOfficerCheck
orderby x.CompileDate descending
select new Model.Customization.ListSafetyOfficer
{
SafetyOfficerCheckId=x.SafetyOfficerCheckId,
HandleIdea=x.HandleIdea,
ReceiveMan=x.ReceiveMan,
ReceiveManName =db.Sys_User.First(z=>z.UserId==x.ReceiveMan).UserName,
CompileMan=x.CompileMan,
CompileManName = db.Sys_User.First(y => y.UserId == x.CompileMan).UserName,
CompileDate= string.Format("{0:yyyy-MM-dd}", x.CompileDate),
State=x.State,
State_Cn= returnState(x.State),
ImageUrl=x.ImageUrl
};
if (!string.IsNullOrEmpty(state))
{
list=list.Where(x => x.State == state);
}
if (!string.IsNullOrEmpty(userid))
{
//编写人是自己 或接收人是自己并且状态是已提交的
list=list.Where(x => x.CompileMan == userid || (x.ReceiveMan == userid && x.State=="1"));
}
return list.ToList();
}
}
/// <summary>
/// 小程序获取详情
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
public static Model.Customization.ListSafetyOfficer getSafetyOfficerItem(string SafetyOfficerCheckId)
{
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString))
{
var list = from x in db.Check_SafetyOfficerCheck
orderby x.CompileDate descending
select new Model.Customization.ListSafetyOfficer
{
SafetyOfficerCheckId = x.SafetyOfficerCheckId,
HandleIdea = x.HandleIdea,
ReceiveMan = x.ReceiveMan,
ReceiveManName = db.Sys_User.First(z => z.UserId == x.ReceiveMan).UserName,
CompileMan = x.CompileMan,
CompileManName = db.Sys_User.First(y => y.UserId == x.CompileMan).UserName,
CompileDate = string.Format("{0:yyyy-MM-dd}", x.CompileDate),
State = x.State,
State_Cn = returnState(x.State),
ImageUrl = x.ImageUrl
};
return list.Where(x=>x.SafetyOfficerCheckId== SafetyOfficerCheckId).First();
}
}
private static string returnState(string states) {
if (states=="0")
{
return "待提交";
}
else if (states == "1")
{
return "待生成日常巡检";
}
else
{
return "已生成日常巡检";
}
}
}
}