tijian_tieying/web/dccdc.DAL/notice_factor_maintainDal.cs

149 lines
5.7 KiB
C#
Raw Normal View History

2025-02-20 12:14:39 +08:00
using Dapper;
using dccdc.Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dccdc.DAL
{
public class notice_factor_maintainDal
{
public List<notice_factor_maintainModel> GetAllList(string id, string jobsid, string harmfulid,String examId)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = "select * from notice_factor_maintain where 1=1";
if (!string.IsNullOrEmpty(id))
{
sql += " and id=@id";
}
if (!string.IsNullOrEmpty(jobsid))
{
sql += " and jobs_state_maintain_id=@jobsid";
}
if (!string.IsNullOrEmpty(harmfulid))
{
sql += " and harmful_factors_type_maintain_id=@harmfulid";
}
if (!string.IsNullOrEmpty(examId))
{
sql += " and exam_group=@examId";
}
return conn.Query<notice_factor_maintainModel>(sql, new { @id = id, @jobsid = jobsid, @harmfulid = harmfulid, @examId = examId }).ToList();
}
}
public List<notice_factor_maintainModel> GetAllList(string jobsid, string harmfulid, String examId)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = "select * from notice_factor_maintain where 1=1";
if (!string.IsNullOrEmpty(jobsid))
{
sql += " and jobs_state_maintain_id=@jobsid";
}
if (!string.IsNullOrEmpty(harmfulid))
{
sql += " and harmful_factors_type_maintain_id in (" + harmfulid + ")";
}
if (!string.IsNullOrEmpty(examId))
{
sql += " and exam_group_maintain_id=@examId";
}
return conn.Query<notice_factor_maintainModel>(sql, new {@jobsid = jobsid, @examId = examId }).ToList();
}
}
public object save(notice_factor_maintainModel model)
{
string sql = "";
if (model.id == 0)
{
sql = @"INSERT INTO [dbo].[notice_factor_maintain]
([jobs_state_maintain_id]
,[harmful_factors_type_maintain_id]
,[exam_group]
,[exam_group_maintain_id]
,[bussiness_notice])
VALUES
(@jobs_state_maintain_id
,@harmful_factors_type_maintain_id
,@exam_group
,@exam_group_maintain_id
,@bussiness_notice)";
}
else
{
sql = @"UPDATE [dbo].[notice_factor_maintain]
SET [jobs_state_maintain_id] = @jobs_state_maintain_id
,[harmful_factors_type_maintain_id] = @harmful_factors_type_maintain_id
,[exam_group] = @exam_group
,[exam_group_maintain_id] = @exam_group_maintain_id
,[bussiness_notice] = @bussiness_notice
WHERE id=@id";
}
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
try
{
int result = conn.Execute(sql, model);
if (result > 0)
return new { State = 1, Message = "保存成功!" };
else
return new { State = 0, Message = "保存失败!" };
}
catch (Exception ex)
{
return new { State = 0, Message = ex.Message };
}
}
}
public object delete(string id)
{
string sql = "delete from notice_factor_maintain where id=@id";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
try
{
int result = conn.Execute(sql, new { id = id });
if (result > 0)
return new { State = 1, Message = "操作成功!" };
else
return new { State = 0, Message = "操作失败!" };
}
catch (Exception ex)
{
return new { State = 0, Message = ex.Message };
}
}
}
public List<notice_factor_maintainModel> GetAllListByHarmfulid(string jobsid, string harmfulid, string examId)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = "select * from notice_factor_maintain where 1=1";
if (!string.IsNullOrEmpty(jobsid))
{
sql += " and jobs_state_maintain_id=@jobsid";
}
if (!string.IsNullOrEmpty(harmfulid))
{
sql += " and harmful_factors_type_maintain_id in (select id from harmful_factors_type_maintain where code in ("+ harmfulid + "))";
}
if (!string.IsNullOrEmpty(examId))
{
sql += " and exam_group_maintain_id=@examId";
}
return conn.Query<notice_factor_maintainModel>(sql, new { @jobsid = jobsid, @examId = examId }).ToList();
}
}
}
}