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(sql).ToList().Count; } } /// /// 根据id获取体检症状列表 /// /// /// /// /// public List 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(sql, new { id = "%" + id + "%" }).ToList(); } } public List 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(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); } } /// /// 根据id删除体检症状 /// /// /// 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 }; } } } } }