tijian_tieying/web/dccdc.DAL/ym_jzlcDal.cs
2025-02-20 12:14:39 +08:00

172 lines
6.5 KiB
C#

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<int> list = conn.Query<int>(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<Models.ym_jzlc>(sql).ToList();
}
}
public List<Models.ym_jzlc> getAllList()
{
string sql = "select * from ym_jzlc order by id desc";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
List<Models.ym_jzlc> list = conn.Query<Models.ym_jzlc>(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<Models.ym_jzlcjl>(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<Models.ym_jzlc>(sql, new { jdbm = jdbm }).First();
return list;
}
}
public List<Models.ym_jzlc> 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<Models.ym_jzlc> list = conn.Query<Models.ym_jzlc>(sql,new { ertbm = ertbm }).ToList();
return list;
}
}
public List<Models.ym_jzlc> 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<Models.ym_jzlc> list = conn.Query<Models.ym_jzlc>(sql, new { ertbm = ertbm }).ToList();
List<Models.ym_jzlc> list1 = conn.Query<Models.ym_jzlc>(sql1, new { ertbm = ertbm }).ToList();
var arrcount = list1.Union(list).ToList();
return arrcount;
}
}
public List<Models.ym_jd> getAllYMJDList()
{
string sql = "select * from ym_jd order by id desc";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
List<Models.ym_jd> list = conn.Query<Models.ym_jd>(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<Models.ym_jzlc> list = conn.Query<Models.ym_jzlc>(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);
}
}
/// <summary>
/// 分页
/// </summary>
/// <typeparam name="T">需要返回实体</typeparam>
/// <param name="sql">查询sql</param>
/// <param name="parms">参数</param>
/// <param name="page">当前第几页</param>
/// <param name="pagesize">每页显示数量</param>
/// <param name="count">返回符合条件的总数</param>
/// <param name="orderfield">排序字段默认ID</param>
/// <param name="storetype">排序类型默认DESC</param>
/// <returns></returns>
public List<T> getListPager<T>(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<int>(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<T>(listsql, parms).ToList();
}
}
}
}