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 OtherDiseaseMaintainDal { /// /// 根据id删除其他疾病 /// /// /// public object del(string id) { string sql = @"delete other_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 }; } } } public List GetAllList(string id, string stauts) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string param = ""; if (id != "") { param = " and id =@id"; } if (stauts != "") { param += " and status=@stauts"; } return conn.Query("select * from other_disease_maintain where 1=1" + param, new { @id = id, @stauts = stauts }).ToList(); } } public int getCount(string key) { string sql = "select count(1) from dbo.other_disease_maintain where 1=1"; if (!string.IsNullOrEmpty(key)) { sql += " and code like @code"; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.ExecuteScalar(sql, new { code = "%" + 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 other_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 object save(OtherDiseaseMaintainModel cpm, ERPUser user) { string sql = ""; if (cpm.id == 0) { sql = @"INSERT INTO [dbo].[other_disease_maintain] ( [code], [status], [pinyin_code], [disease_name] ) VALUES ( @code , @status , @pinyin_code , @disease_name ) "; } else { sql = @"UPDATE [dbo].[other_disease_maintain] SET [pinyin_code]=@pinyin_code, [status]=@status, [disease_name]=@disease_name, [code]=@code WHERE id=@id "; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { try { int c = conn.Execute(sql, cpm); if (c > 0) { return new { State = 1, Message = "保存成功!" }; } else { return new { State = 0, Message = "操作失败,请联系管理员!" }; } } catch (Exception ex) { return new { State = 0, Message = ex.Message }; } } } } }