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 ExamGroupPreposeConditionMaintainDal { public ExamGroupPreposeConditionMaintainModel Getmodel(string id) { string sql = "select * from exam_group_prepose_condition_maintain where id =@id"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query(sql, new { id = id }).First(); } } public int getCount(string key) { string sql = "select count(1) from dbo.[exam_group_prepose_condition_maintain] where 1=1"; if (!string.IsNullOrEmpty(key)) { sql += " and exam_group_maintain_id like @team_name"; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.ExecuteScalar(sql, new { team_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 [exam_group_prepose_condition_maintain] where 1=1"; if (!string.IsNullOrEmpty(key)) { sql += " and exam_group_maintain_id like @team_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 { team_name = "%" + key + "%" }).ToList(); } } public bool Update(ExamGroupPreposeConditionMaintainModel model) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string sql = @"UPDATE [dbo].[exam_group_prepose_condition_maintain] SET [team_name] = @team_name ,[exam_group_maintain_id] = @exam_group_maintain_id ,[prepose_condition] = @prepose_condition ,[exam_prepose_condition_maintain_id] = @exam_prepose_condition_maintain_id ,[status] = @status ,[creator] = @creator ,[create_time] = @create_time WHERE id=@id"; return (conn.Execute(sql, model) != 0 ? true : false); } } public bool Add(ExamGroupPreposeConditionMaintainModel model) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string sql = @"INSERT INTO [dbo].[exam_group_prepose_condition_maintain] ([team_name] ,[exam_group_maintain_id] ,[prepose_condition] ,[exam_prepose_condition_maintain_id] ,[status] ,[creator] ,[create_time]) VALUES (@team_name ,@exam_group_maintain_id ,@prepose_condition ,@exam_prepose_condition_maintain_id ,@status ,@creator ,@create_time)"; return (conn.Execute(sql, model) != 0 ? true : false); } } /// /// 根据id删除体检小组前置 /// /// /// public object del(string id) { string sql = @"delete exam_group_prepose_condition_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 }; } } } } }