using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using dccdc.Models; using Dapper; using dccdc.Models.DTO; namespace dccdc.DAL { public class ym_jzlcDal { public int getYmJzlcCount() { string sql = "select count(1) from ym_jzlc"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { List list = conn.Query(sql).ToList(); return list.FirstOrDefault(); } } public object getYmJzlcList(int page, int pagesize) { string sql = "select *,row_number() over(order by bm) as rownum from ym_jzlc where 1=1"; sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize; using (IDbConnection conn = CommHelper.GetSqlConnection()) { return conn.Query(sql).ToList(); } } public List getAllList() { string sql = "select * from ym_jzlc order by id desc"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { List list = conn.Query(sql).ToList(); return list; } } public Models.ym_jzlcjl getYmjzlcjlByErtbm(string ertbm) { string sql = "select * from ym_jzlcjl where ertbm=@ertbm order by jdid desc"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { Models.ym_jzlcjl list = conn.Query(sql, new { ertbm = ertbm }).First(); return list; } } public Models.ym_jzlc getYmjzlcByErtbm(string jdbm) { string sql = "select * from ym_jzlc where jdid=@jdbm order by jgts desc"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { Models.ym_jzlc list = conn.Query(sql, new { jdbm = jdbm }).First(); return list; } } public List getAllListByErtbm(string ertbm) { string sql = "select * from ym_jzlc where jdid in (select jdid from jiezhongmianyi_tiaomadayin where id=@ertbm)"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { List list = conn.Query(sql,new { ertbm = ertbm }).ToList(); return list; } } public List getAllJzlcList(string ertbm) { string sql = "select * from ym_jzlc where jdid not in (select jdid from jiezhongmianyi_tiaomadayin where id=@ertbm)"; string sql1 = "select * from ym_jzlc where jdid in (select jdid from jiezhongmianyi_tiaomadayin where id=@ertbm)"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { List list = conn.Query(sql, new { ertbm = ertbm }).ToList(); List list1 = conn.Query(sql1, new { ertbm = ertbm }).ToList(); var arrcount = list1.Union(list).ToList(); return arrcount; } } public List getAllYMJDList() { string sql = "select * from ym_jd order by id desc"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { List list = conn.Query(sql).ToList(); return list; } } public Models.ym_jzlc getYmJzlcModel(object id) { string sql = "select * from ym_jzlc where id = @id"; using (IDbConnection conn = CommHelper.GetSqlConnection()) { List list = conn.Query(sql, new { id = id }).ToList(); return list.FirstOrDefault(); } } public bool Update(Models.ym_jzlc model) { using (var conn = CommHelper.GetSqlConnection()) { string sql = @"UPDATE [dbo].[ym_jzlc] SET [lcmc] = @lcmc ,[ymid] = @ymid ,[jdid] = @jdid ,[jgts]=@jgts WHERE id=@id"; return (conn.Execute(sql, model) != 0 ? true : false); } } public bool Add(Models.ym_jzlc model) { using (var conn = CommHelper.GetSqlConnection()) { string sql = @"INSERT INTO [dbo].[ym_jzlc] ([lcmc] ,[ymid] ,[jdid],[jgts]) VALUES (@lcmc ,@ymid ,@jdid,@jgts)"; return (conn.Execute(sql, model) != 0 ? true : false); } } /// /// 分页 /// /// 需要返回实体 /// 查询sql /// 参数 /// 当前第几页 /// 每页显示数量 /// 返回符合条件的总数 /// 排序字段默认ID /// 排序类型默认DESC /// public List getListPager(string sql, object parms, int page, int pagesize, out int count, string orderfield = "id", string storetype = "desc") where T : new() { count = 0; string countsql = ""; countsql = "select count(1) from " + sql.Substring(sql.IndexOf("from") + 4); using (var conn = CommHelper.GetSqlConnection()) { count = conn.ExecuteScalar(countsql, parms); string listsql = "select * from (" + sql.Insert(sql.IndexOf("select") + 6, " ROW_NUMBER() over ( ORDER BY " + orderfield + " " + storetype + ") rownum,") + ")a where rownum>((" + page + "-1)*" + pagesize + ") and rownum<=(" + page + "*" + pagesize + ")"; return conn.Query(listsql, parms).ToList(); } } } }