tijian_tieying/web/dccdc.DAL/ExamGroupPreposeConditionMaintainDal.cs
2025-02-20 12:14:39 +08:00

129 lines
4.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using dccdc.Models;
using Dapper;
namespace dccdc.DAL
{
public class ExamGroupPreposeConditionMaintainDal
{
public ExamGroupPreposeConditionMaintainModel Getmodel(string id)
{
string sql = "select * from exam_group_prepose_condition_maintain where id =@id";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.Query<ExamGroupPreposeConditionMaintainModel>(sql, new { id = id }).First();
}
}
public int getCount(string key)
{
string sql = "select count(1) from dbo.[exam_group_prepose_condition_maintain] where 1=1";
if (!string.IsNullOrEmpty(key))
{
sql += " and exam_group_maintain_id like @team_name";
}
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.ExecuteScalar<int>(sql, new { team_name = "%" + key + "%" });
}
}
/// <summary>
/// 根据小组名称获取体检小组和前置条件列表
/// </summary>
/// <param name="page"></param>
/// <param name="pagesize"></param>
/// <param name="key"></param>
/// <returns></returns>
public List<ExamGroupPreposeConditionMaintainModel> getList(int page, int pagesize, string key)
{
//throw new NotImplementedException();
string sql = "select *,row_number() over(order by id desc) as rownum from [exam_group_prepose_condition_maintain] where 1=1";
if (!string.IsNullOrEmpty(key))
{
sql += " and exam_group_maintain_id like @team_name";
}
sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize;
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.Query<Models.ExamGroupPreposeConditionMaintainModel>(sql, new { team_name = "%" + key + "%" }).ToList();
}
}
public bool Update(ExamGroupPreposeConditionMaintainModel model)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = @"UPDATE [dbo].[exam_group_prepose_condition_maintain]
SET [team_name] = @team_name
,[exam_group_maintain_id] = @exam_group_maintain_id
,[prepose_condition] = @prepose_condition
,[exam_prepose_condition_maintain_id] = @exam_prepose_condition_maintain_id
,[status] = @status
,[creator] = @creator
,[create_time] = @create_time
WHERE id=@id";
return (conn.Execute(sql, model) != 0 ? true : false);
}
}
public bool Add(ExamGroupPreposeConditionMaintainModel model)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = @"INSERT INTO [dbo].[exam_group_prepose_condition_maintain]
([team_name]
,[exam_group_maintain_id]
,[prepose_condition]
,[exam_prepose_condition_maintain_id]
,[status]
,[creator]
,[create_time])
VALUES
(@team_name
,@exam_group_maintain_id
,@prepose_condition
,@exam_prepose_condition_maintain_id
,@status
,@creator
,@create_time)";
return (conn.Execute(sql, model) != 0 ? true : false);
}
}
/// <summary>
/// 根据id删除体检小组前置
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public object del(string id)
{
string sql = @"delete exam_group_prepose_condition_maintain where id=@id";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
try
{
int c = conn.Execute(sql, new { id = id });
if (c > 0)
{
return new { State = 1, Message = "操作成功!" };
}
else
{
return new { State = 0, Message = "操作失败,请联系管理员!" };
}
}
catch (Exception ex)
{
return new { State = 0, Message = ex.Message };
}
}
}
}
}