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 contraindicat_factor_maintainDal { public List GetAllList(string id, string jobsid, string harmfulid) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { string sql = "select * from contraindicat_factor_maintain where 1=1"; if (!string.IsNullOrEmpty(id)) { sql += " and id=@id"; } if (!string.IsNullOrEmpty(jobsid)) { sql += " and jobs_state_maintain_id=@jobsid"; } if (!string.IsNullOrEmpty(harmfulid)) { sql += " and harmful_factors_type_maintain_id=@harmfulid"; } return conn.Query(sql, new { @id = id, @jobsid = jobsid, @harmfulid = harmfulid }).ToList(); } } public object save(contraindicat_factor_maintainModel model) { string sql = ""; if (model.id == 0) { sql = @"INSERT INTO [dbo].[contraindicat_factor_maintain] ([jobs_state_maintain_id] ,[harmful_factors_type_maintain_id] ,[contraindicat_maintain_id] ,[contraindicat_code] ,[contraindicat_name]) VALUES (@jobs_state_maintain_id ,@harmful_factors_type_maintain_id ,@harmful_factors_type_maintain_id ,@contraindicat_code ,@contraindicat_name)"; } else { sql = @"UPDATE [dbo].[contraindicat_factor_maintain] SET [jobs_state_maintain_id] = @jobs_state_maintain_id ,[harmful_factors_type_maintain_id] = @harmful_factors_type_maintain_id ,[contraindicat_maintain_id] = @contraindicat_maintain_id ,[contraindicat_code] = @contraindicat_code ,[contraindicat_name] =@contraindicat_name WHERE id=@id"; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { try { int result = conn.Execute(sql, model); if (result > 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 contraindicat_factor_maintain 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 }; } } } } }