103 lines
3.7 KiB
C#
103 lines
3.7 KiB
C#
|
|
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 target_factor_maintainDal
|
|||
|
|
{
|
|||
|
|
public List<target_factor_maintainModel> GetAllList(string id, string jobsid, string harmfulid)
|
|||
|
|
{
|
|||
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|||
|
|
{
|
|||
|
|
string sql = "select * from target_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";
|
|||
|
|
}
|
|||
|
|
return conn.Query<target_factor_maintainModel>(sql, new { @id = id, @jobsid = jobsid, @harmfulid = harmfulid }).ToList();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public object save(target_factor_maintainModel model)
|
|||
|
|
{
|
|||
|
|
string sql = "";
|
|||
|
|
if (model.id == 0)
|
|||
|
|
{
|
|||
|
|
sql = @"INSERT INTO [dbo].[target_factor_maintain]
|
|||
|
|
([jobs_state_maintain_id]
|
|||
|
|
,[harmful_factors_type_maintain_id]
|
|||
|
|
,[target_disease_maintain_id]
|
|||
|
|
,[disease_code]
|
|||
|
|
,[disease_name])
|
|||
|
|
VALUES
|
|||
|
|
(@jobs_state_maintain_id
|
|||
|
|
, @harmful_factors_type_maintain_id
|
|||
|
|
, @target_disease_maintain_id
|
|||
|
|
, @disease_code
|
|||
|
|
, @disease_name)";
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
sql = @"UPDATE [dbo].[target_factor_maintain]
|
|||
|
|
SET[jobs_state_maintain_id] =@jobs_state_maintain_id
|
|||
|
|
,[harmful_factors_type_maintain_id] = @harmful_factors_type_maintain_id
|
|||
|
|
,[target_disease_maintain_id] = @target_disease_maintain_id
|
|||
|
|
,[disease_code] = @disease_code
|
|||
|
|
,[disease_name] = @disease_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 target_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 };
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|