133 lines
4.7 KiB
C#
133 lines
4.7 KiB
C#
using Dapper;
|
||
using dccdc.Models;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace dccdc.DAL
|
||
{
|
||
public class charge_detailDal
|
||
{
|
||
public int getCount(string key)
|
||
{
|
||
string sql = "select count(1) from charge_detail where 1=1";
|
||
if (!string.IsNullOrEmpty(key))
|
||
{
|
||
sql += " and ()";
|
||
}
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
return conn.ExecuteScalar<int>(sql, new { area_name = "%" + key + "%" });
|
||
}
|
||
}
|
||
public List<charge_detailModel> getList(int page, int pagesize, string key)
|
||
{
|
||
string sql = "select *,row_number() over(order by id) as rownum from charge_detail where 1=1";
|
||
if (!string.IsNullOrEmpty(key))
|
||
{
|
||
sql += " and ()";
|
||
}
|
||
sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize;
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
return conn.Query<charge_detailModel>(sql, new { area_name = "%" + key + "%" }).ToList();
|
||
}
|
||
}
|
||
|
||
public List<charge_detailModel> GetAllList(string id)
|
||
{
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
string param = "";
|
||
if (id != "")
|
||
{
|
||
param += " and id=@id";
|
||
}
|
||
|
||
string sql = "select * from charge_detail where 1=1 ";
|
||
return conn.Query<charge_detailModel>(sql + param, new { id = id }).ToList();
|
||
}
|
||
}
|
||
|
||
|
||
public object save(charge_detailModel ct)
|
||
{
|
||
string sql = "";
|
||
if (ct.id == 0)
|
||
{
|
||
sql = @"INSERT INTO [dbo].[charge_detail]
|
||
([chargeid]
|
||
,[projectid]
|
||
,[projectname]
|
||
,[money]
|
||
,[count])
|
||
VALUES
|
||
(@chargeid
|
||
,@projectid
|
||
,@projectname
|
||
,@money
|
||
,@count)";
|
||
}
|
||
else
|
||
{
|
||
sql = @"UPDATE [dbo].[charge_detail]
|
||
SET [chargeid] = @chargeid
|
||
,[projectid] = @projectid
|
||
,[projectname] = @projectname
|
||
,[money] = @money
|
||
,[count] = @count
|
||
WHERE id=@id";
|
||
}
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
try
|
||
{
|
||
int c = conn.Execute(sql, ct);
|
||
if (c > 0)
|
||
{
|
||
return new { State = 1, Message = "保存成功!" };
|
||
}
|
||
else
|
||
{
|
||
return new { State = 0, Message = "操作失败,请联系管理员!" };
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return new { State = 0, Message = ex.Message };
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="chargeid"></param>
|
||
/// <param name="jmlx">0:减免附加,1:全部减免</param>
|
||
/// <returns></returns>
|
||
public List<charge_detailModel> GetModelsBychargeId(string chargeid, string jmlx, string ids)
|
||
{
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
string sql = "";
|
||
sql = jmlx == "1" ? "select * from charge_detail where chargeid=@chargeid " : "select * from charge_detail where chargeid=@chargeid and pid<>-1 ";
|
||
if (ids == "")
|
||
{
|
||
sql = @" select d.* from jmmx mx join jmsq sq on sq.id=mx.jmsqid join YMDJ dj on dj.id=sq.ymdjid
|
||
join charge_detail d on d.id=mx.detailid
|
||
where dj.chargeid=@chargeid";
|
||
sql = jmlx == "1" ? "select * from charge_detail where chargeid=@chargeid " : "select * from charge_detail where chargeid=@chargeid and pid<>-1 ";
|
||
}
|
||
else
|
||
{
|
||
sql = "select * from charge_detail where id in (" + ids.Trim(',') + ")";
|
||
}
|
||
return conn.Query<charge_detailModel>(sql, new { chargeid = chargeid }).ToList();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|