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 PastHistoryDal { 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 past_history where 1=1" + param, new { @id = id, @stauts = stauts }).ToList(); } } public int getCount(string key) { string sql = "select count(1) from dbo.past_history where 1=1"; if (!string.IsNullOrEmpty(key)) { sql += " and inquiry_id like @inquiry_id"; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.ExecuteScalar(sql, new { inquiry_id = "%" + key + "%" }); } } public List getList(string key) { //throw new NotImplementedException(); string sql = "select *,row_number() over(order by id) as rownum from past_history where 1=1"; if (!string.IsNullOrEmpty(key)) { sql += " and inquiry_id like @inquiry_id"; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query(sql, new { inquiry_id = "%" + key + "%" }).ToList(); } } public object save(PastHistoryModel cpm, ERPUser user) { //throw new NotImplementedException(); string sql = ""; if (cpm.id == 0) { sql = @"INSERT INTO [dbo].[past_history] ( [inquiry_id], [disease], [diagnose_date], [util], [treatment], [outcome] ) VALUES ( @inquiry_id, @disease, @diagnose_date, @util, @treatment, @outcome ) "; } else { sql = @"UPDATE [dbo].[past_history] SET [inquiry_id]=@inquiry_id, [disease]=@disease, [diagnose_date]=@diagnose_date, [util]=@util, [treatment]=@treatment, [outcome]=@outcome 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 }; } } } public object delete(string id) { string sql = "delete from past_history where id=@id"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { try { int result = conn.Execute(sql, new { id = id }); if (result > 0) { return new { State = 1, Message = "操作成功!" }; } else return new { State = 0, Message = "操作失败!" }; } catch (Exception ex) { return new { State = 0, Message = ex.Message }; } } } } }