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

140 lines
4.3 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 SymptomsMaintainDal
{
public int getCount(string id)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = "select * from symptoms_maintain";
if (id != "")
{
sql += " and id=" + id;
}
return conn.Query<SymptomsMaintainModel>(sql).ToList().Count;
}
}
/// <summary>
/// 根据id获取体检症状列表
/// </summary>
/// <param name="id"></param>
/// <param name="page"></param>
/// <param name="pagesize"></param>
/// <returns></returns>
public List<SymptomsMaintainModel> GetAllList(string id, int page, int pagesize)
{
//throw new NotImplementedException();
string sql = "select *,row_number() over(order by id desc) as rownum from [symptoms_maintain] where 1=1";
if (!string.IsNullOrEmpty(id))
{
sql += " and id = @id";
}
sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize;
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.Query<Models.SymptomsMaintainModel>(sql, new { id = "%" + id + "%" }).ToList();
}
}
public List<SymptomsMaintainModel> GetAllListN(string id,string status)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = "select * from symptoms_maintain where 1=1";
if(id!="")
{
sql += " and id=" + id;
}
if(status!="")
{
sql += " and status='"+status+"'";
}
return conn.Query<Models.SymptomsMaintainModel>(sql).ToList();
}
}
public bool Add(SymptomsMaintainModel model)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = @"INSERT INTO [symptoms_maintain]
([code]
,[symptoms_name]
,[symptoms_type]
,[default_status]
,[pinyin_code]
,[status]
,[creator]
,[create_time])
VALUES
(@code
,@symptoms_name
,@symptoms_type
,@default_status
,@pinyin_code
,@status
,@creator
,@create_time)";
return (conn.Execute(sql, model) != 0 ? true : false);
}
}
public bool Update(SymptomsMaintainModel model)
{
string sql = @"UPDATE [symptoms_maintain]
SET [code] =@code
,[symptoms_name] = @symptoms_name
,[symptoms_type] = @symptoms_type
WHERE id=@id
";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
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 symptoms_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 };
}
}
}
}
}