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 YMDJMXDal { public int getCount(string ymdjbid) { string sql = "select count(1) from dbo.YMDJMX where 1=1 "; if (!string.IsNullOrEmpty(ymdjbid)) { sql += " and ymdjbid = @ymdjbid"; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.ExecuteScalar(sql, new { ymdjbid = ymdjbid }); } } public YMDJMX getById(string id) { string sql = "select * from dbo.YMDJMX where 1=1 and id = " + id; ; using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query(sql).FirstOrDefault(); } } public List GetYmsList(string ymList) { using (IDbConnection conn = CommHelper.GetSqlConnection()) { List vaccineList = new List(); string[] ymLists = ymList.Split(','); for (int i = 0; i < ymLists.Length; i++) { string sql = "select * from vaccine where status='是' and id in (@ymList)"; vaccineList.Add(conn.Query(sql, new { ymList = ymLists[i] }).First()); } return vaccineList; } } public List GetYmjzlcList(string jdid) { //throw new NotImplementedException(); string sql = "select * from vaccine where status='是' and id in (select ymid from ym_jzlc where jdid=@jdid)"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query(sql, new { jdid = jdid }).ToList(); } } public JiezhongmianyitiaomaModel GetJzymTmdy(string id) { //throw new NotImplementedException(); string sql = "select * from jiezhongmianyi_tiaomadayin where barcode=@id"; int newid; if (int.TryParse(id, out newid)) { sql = "select * from jiezhongmianyi_tiaomadayin where id=@id"; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query(sql, new { id = id }).FirstOrDefault(); } } public ym_yyjl getYmyyjl(string id) { //throw new NotImplementedException(); string sql = "select * from ym_yyjl where ertbm=@id order by id desc"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query(sql, new { id = id }).FirstOrDefault(); } } public List getMX(string ymdjbid) { //throw new NotImplementedException(); string sql = "select YMDJMX.*,vaccine.name as ymmc from YMDJMX left join vaccine on YMDJMX.ymid = vaccine.id where 1 = 1 and ymsl>zssl"; if (!string.IsNullOrEmpty(ymdjbid)) { sql += " and YMDJMX.ymdjbid = @ymdjbid"; } using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query(sql, new { ymdjbid = ymdjbid }).ToList(); } } //public JiezhongmianyitiaomaModel GetJzymTmdy(string id) //{ // //throw new NotImplementedException(); // string sql = "select * from jiezhongmianyi_tiaomadayin where id=@id"; // using (IDbConnection conn = CommHelper.GetSqlConnection()) // { // return conn.Query(sql, new { id = id }).FirstOrDefault(); // } //} //public List GetYmjzlcList(string jdid) //{ // //throw new NotImplementedException(); // string sql = "select * from vaccine where status='是' and id in (select ymid from ym_jzlc where jdid=@jdid)"; // using (IDbConnection conn = CommHelper.GetSqlConnection()) // { // return conn.Query(sql, new { jdid = jdid }).ToList(); // } //} //public List GetYmsList(string ymList) //{ // using (IDbConnection conn = CommHelper.GetSqlConnection()) // { // List vaccineList = new List(); // string[] ymLists = ymList.Split(','); // for (int i = 0; i < ymLists.Length; i++) // { // string sql = "select * from vaccine where status='是' and id in (@ymList)"; // vaccineList.Add(conn.Query(sql, new { ymList = ymLists[i] }).First()); // } // return vaccineList; // } //} //public ym_yyjl getYmyyjl(string id) //{ // //throw new NotImplementedException(); // string sql = "select * from ym_yyjl where ertbm=@id order by id desc"; // using (IDbConnection conn = CommHelper.GetSqlConnection()) // { // return conn.Query(sql, new { id = id }).FirstOrDefault(); // } //} public List getList(int page, int pagesize, string ymdjbid) { //throw new NotImplementedException(); string sql = "select *,row_number() over(order by id) as rownum from YMDJMX where 1=1"; if (!string.IsNullOrEmpty(ymdjbid)) { sql += " and ymdjbid = @ymdjbid"; } 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 { ymdjbid = ymdjbid }).ToList(); } } public object save(YMDJMX cpm) { //throw new NotImplementedException(); string sql = ""; if (cpm.id == 0) { sql = @"INSERT INTO [dbo].[YMDJMX] ([ymdjbid], [ymid], [ymsl], [sfje], [zssl], [ymdj] ) VALUES (@ymdjbid, @ymid, @ymsl, @sfje, @zssl, @ymdj ) "; } else { sql = @"UPDATE [dbo].[YMDJMX] SET [ymdjbid]= @ymdjbid, [ymid]= @ymid, [ymsl]= @ymsl, [sfje]= @sfje, [zssl]= @zssl, [ymdj]= @ymdj 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 saves(List cpm) { //throw new NotImplementedException(); string sql = ""; sql = @"INSERT INTO [dbo].[YMDJMX] ([ymdjbid], [ymid], [ymsl], [sfje], [zssl], [ymdj] ) VALUES (@ymdjbid, @ymid, @ymsl, @sfje, @zssl, @ymdj ) "; 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 }; } } } } }