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 OccupationDiseaseDataImportDal { 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 occupation_disease_data_import where 1=1" + param, new { @id = id, @stauts = stauts }).ToList(); } } public int getCount(string key) { string sql = "select count(1) from dbo.occupation_disease_data_import where 1=1"; if (!string.IsNullOrEmpty(key)) { sql += " and enterprise_id like @enterprise_id"; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.ExecuteScalar(sql, new { enterprise_id = "%" + key + "%" }); } } public List getList(int page, int pagesize, string key) { //throw new NotImplementedException(); string sql = "select *,row_number() over(order by id) as rownum from occupation_disease_data_import where 1=1"; if (!string.IsNullOrEmpty(key)) { sql += " and enterprise_id = @enterprise_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 { enterprise_id = key }).ToList(); } } public object save(OccupationDiseaseDataImportModel cpm) { //throw new NotImplementedException(); string sql = ""; if (cpm.id == 0) { sql = @"INSERT INTO [dbo].[occupation_disease_data_import] ( [enterprise], [enterprise_id], [name], [identity_card], [start_date], [end_date], [util], [workshop], [work_type], [factory], [protect_method], [status] ) VALUES ( @enterprise, @enterprise_id, @name, @identity_card, @start_date, @end_date, @util, @workshop, @work_type, @factory, @protect_method, @status ) "; } else { sql = @"UPDATE [dbo].[occupation_disease_data_import] SET [enterprise]=@enterprise, [enterprise_id]=@enterprise_id, [name]=@name, [identity_card]=@identity_card, [start_date]=@start_date, [end_date]=@end_date, [util]=@util, [workshop]=@workshop, [work_type]=@work_type, [factory]=@factory, [protect_method]=@protect_method, [status]=@status 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 }; } } } } }