tijian_tieying/web/dccdc.DAL/summaryreport_factor_symptomDal.cs

117 lines
4.3 KiB
C#
Raw Permalink 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 summaryreport_factor_symptomDal
{
public List<summaryreport_factor_symptomModel> GetAllList(string id, string jobsid, string harmfulid)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = "select * from summaryreport_factor_symptom 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";
}
return conn.Query<summaryreport_factor_symptomModel>(sql, new { @id = id, @jobsid = jobsid, @harmfulid = harmfulid }).ToList();
}
}
public List<summaryreport_factor_symptomModel> GetAllList(string jobsid, string harmfulid)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = "select * from summaryreport_factor_symptom 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+"))";
}
return conn.Query<summaryreport_factor_symptomModel>(sql, new {@jobsid = jobsid}).ToList();
}
}
public object save(summaryreport_factor_symptomModel model)
{
string sql = "";
if (model.id == 0)
{
sql = @"INSERT INTO [dbo].[summaryreport_factor_symptom]
([jobs_state_maintain_id]
,[harmful_factors_type_maintain_id]
,[symptom_code]
,[symptom_name])
VALUES
(@jobs_state_maintain_id
,@harmful_factors_type_maintain_id
,@symptom_code
,@symptom_name)";
}
else
{
sql = @"UPDATE [dbo].[summaryreport_factor_symptom]
SET [jobs_state_maintain_id] = @jobs_state_maintain_id
,[harmful_factors_type_maintain_id] = @harmful_factors_type_maintain_id
,[symptom_code] = @symptom_code
,[symptom_name] = @symptom_name
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 summaryreport_factor_symptom 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 };
}
}
}
}
}