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 TargetDiseaseMaintainDal { public List GetAllList(string id) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string param = ""; if (id != "") { param = " and id=@id"; } return conn.Query("select * from target_disease_maintain where 1=1 "+ param,new {@id=id}).ToList(); } } public List GetAllList2() { using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query("select * from target_disease_maintain where 1=1 and status='是'").ToList(); } } public int getCount(string key) { string sql = "select count(1) from dbo.target_disease_maintain where 1=1"; if (!string.IsNullOrEmpty(key)) { sql += " and disease_name like @disease_name"; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.ExecuteScalar(sql, new { @disease_name = "%" + key + "%" }); } } /// /// 根据目标疾病名称获取目标疾病列表 /// /// /// /// /// public List getList(int page, int pagesize, string key) { //throw new NotImplementedException(); string sql = "select *,row_number() over(order by id desc) as rownum from target_disease_maintain where 1=1"; if (!string.IsNullOrEmpty(key)) { sql += " and disease_name like @disease_name"; } sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize; using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query(sql, new { disease_name = "%" + key + "%" }).ToList(); } } public bool Add(TargetDiseaseMaintainModel model) { string sql = @"INSERT INTO [target_disease_maintain] ([code] ,[disease_name] ,[disease_type] ,[status] ,[pinyin_code] ,[creator] ,[create_time]) VALUES (@code ,@disease_name ,@disease_type ,@status ,@pinyin_code ,@creator ,@create_time)"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { return (conn.Execute(sql, model) != 0 ? true : false); } } public bool Update(TargetDiseaseMaintainModel model) { string sql = @"UPDATE [target_disease_maintain] SET [code] = @code ,[disease_name] = @disease_name ,[disease_type] = @disease_type ,[status] = @status ,[pinyin_code] =@pinyin_code ,[creator] = @creator ,[create_time] = @create_time WHERE id=@id"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { return (conn.Execute(sql, model) != 0 ? true : false); } } /// /// 根据id删除目标疾病 /// /// /// public object del(string id) { string sql = @"delete target_disease_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 }; } } } } }