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 NCZSJDal { 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 NCZSJ where 1=1" + param, new { @id = id, @stauts = stauts }).ToList(); } } public int getCount(string key) { string sql = "select count(1) from dbo.NCZSJ where 1=1"; if (!string.IsNullOrEmpty(key)) { sql += " and hzxm like @hzxm"; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.ExecuteScalar(sql, new { hzxm = "%" + 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 NCZSJ where 1=1"; if (!string.IsNullOrEmpty(key)) { sql += " and hzxm like @hzxm"; } 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 { hzxm = "%"+key+"%" }).ToList(); } } public object save(NCZSJModel cpm, ERPUser user) { //throw new NotImplementedException(); cpm.drr = user.TrueName; cpm.drsj = DateTime.Now; string sql = ""; using (IDbConnection conn = CommHelper.GetSqlConnection()) { sql = "select count(1) from NCZSJ where kpbm=@kpbm"; var c1 = conn.ExecuteScalar(sql, new { kpbm = cpm.kpbm }); if(c1>0) return new { State = 1, Message = "重复数据跳过!" }; sql = @"INSERT INTO [dbo].[NCZSJ] ( [kpbm], [hzxm], [yxzjh], [xb], [csrq], [nl], [gzdw], [lxdh], [zzbm], [xxzz], [zd], [tkys], [bgdw], [bklrsj], [drsj], [drr], [icd10], [icdname] ) VALUES ( @kpbm, @hzxm, @yxzjh, @xb, @csrq, @nl, @gzdw, @lxdh, @zzbm, @xxzz, @zd, @tkys, @bgdw, @bklrsj, @drsj, @drr, @icd10, @icdname ) "; 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 int getCountgxb(string key) { string sql = "select count(1) from dbo.gxbSJ where 1=1"; if (!string.IsNullOrEmpty(key)) { sql += " and hzxm like @hzxm"; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.ExecuteScalar(sql, new { hzxm = "%" + key + "%" }); } } public List getListgxb(int page, int pagesize, string key) { //throw new NotImplementedException(); string sql = "select *,row_number() over(order by id) as rownum from gxbSJ where 1=1"; if (!string.IsNullOrEmpty(key)) { sql += " and hzxm like @hzxm"; } 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 { hzxm = "%" + key + "%" }).ToList(); } } public object savegxb(NCZSJModel cpm, ERPUser user) { //throw new NotImplementedException(); cpm.drr = user.TrueName; cpm.drsj = DateTime.Now; string sql = ""; using (IDbConnection conn = CommHelper.GetSqlConnection()) { sql = "select count(1) from gxbSJ where kpbm=@kpbm"; var c1 = conn.ExecuteScalar(sql, new { kpbm = cpm.kpbm }); if (c1 > 0) return new { State = 1, Message = "重复数据跳过!" }; sql = @"INSERT INTO [dbo].[gxbSJ] ( [kpbm], [hzxm], [yxzjh], [xb], [csrq], [nl], [gzdw], [lxdh], [zzbm], [xxzz], [zd], [tkys], [bgdw], [bklrsj], [drsj], [drr], [icd10], [icdname] ) VALUES ( @kpbm, @hzxm, @yxzjh, @xb, @csrq, @nl, @gzdw, @lxdh, @zzbm, @xxzz, @zd, @tkys, @bgdw, @bklrsj, @drsj, @drr, @icd10, @icdname ) "; 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 }; } } } } }