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

203 lines
6.9 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 xmjfsrDal
{
public List<xmjfsrModel> GetAllList(string id)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = "select * from xmjfsr where 1=1";
if (!string.IsNullOrEmpty(id))
{
sql += " and id=@id";
}
return conn.Query<xmjfsrModel>(sql, new { @id = id }).ToList();
}
}
public List<xmjfsrModel> GetAllList(string id, string zt)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = "select * from xmjfsr where 1=1";
if (!string.IsNullOrEmpty(id))
{
sql += " and id=@id";
}
if (!string.IsNullOrEmpty(zt))
{
sql += " and zt=@zt";
}
return conn.Query<xmjfsrModel>(sql, new { @id = id, @zt = zt }).ToList();
}
}
public object save(xmjfsrModel model, int sqrid)
{
string sql = "";
string upsql = "";
if (model.id == 0)
{
sql = @"INSERT INTO [dbo].[xmjfsr]
([jfid]
,[nf]
,[srly]
,[fzr]
,[srje]
,[yj]
,[dzsj]
,[ksids]
,[ksmcs]
,[tjr]
,[tjsj]
,[zt])
VALUES
(@jfid
,@nf
,@srly
,@fzr
,@srje
,@yj
,@dzsj
,@ksids
,@ksmcs
,@tjr
,@tjsj
,@zt) select SCOPE_IDENTITY()";
upsql = "update xmjingfei set srje+=@srje where id=@id";
}
else
{
sql = @"UPDATE [dbo].[xmjfsr]
SET [jfid] = @jfid
,[nf] = @nf
,[srly] = @srly
,[fzr] = @fzr
,[srje] = @srje
,[yj] = @yj
,[dzsj] = @dzsj
,[ksids] = @ksids
,[ksmcs] = @ksmcs
,[tjr] = @tjr
,[tjsj] = @tjsj
,[zt] = @zt
WHERE id=@id";
}
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
try
{
if (upsql != "")
{
conn.Execute(upsql, new { id = model.jfid, srje = model.srje });
}
if (model.id == 0)
{
int sqdid = conn.Query<int>(sql, model).FirstOrDefault();
//附件修改
string sqlfj = @"update sqfile set sqid=" + sqdid + " where type='经费收入' and sqid=0 and sqrid=" + sqrid;
conn.Execute(sqlfj);
return new { State = 1, Message = "操作成功", id = sqdid };
}
else
{
conn.Execute(sql, model);
return new { State = 1, Message = "操作成功" };
}
}
catch (Exception ex)
{
return new { State = 0, Message = ex.Message };
}
}
}
public object delete(string id)
{
string sql = "delete from xmjfsr where id=@id";
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
try
{
int result = conn.Execute(sql, new { id = id });
if (result > 0)
return new { State = 1, Message = "操作成功!" };
else
return new { State = 0, Message = "操作失败!" };
}
catch (Exception ex)
{
return new { State = 0, Message = ex.Message };
}
}
}
public int getCount(string key)
{
string sql = "select count(1) from dbo.xmjfsr where 1=1";
if (!string.IsNullOrEmpty(key))
{
sql += " and srly like @key";
}
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.ExecuteScalar<int>(sql, new { key = "%" + key + "%" });
}
}
public List<xmjfsrModel> getPage(int page, int pagesize, string key)
{
string sql = "select *,row_number() over(order by id) as rownum from xmjfsr where 1=1";
if (!string.IsNullOrEmpty(key))
{
sql += " and srly like @key";
}
sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize;
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.Query<Models.xmjfsrModel>(sql, new { key = "%" + key + "%" }).ToList();
}
}
public int getCount2(string where)
{
string sql = "select count(1) from xmjfsr";
if (!string.IsNullOrEmpty(where))
{
sql += " where " + where;
}
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.ExecuteScalar<int>(sql);
}
}
public List<xmjfsrModel> getPage2(int page, int pagesize, string where)
{
string sql = "select *,row_number() over(order by id desc) as rownum from xmjfsr"; //产生序列号的时候排序
if (!string.IsNullOrEmpty(where))
{
sql += " where " + where;
}
sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize;
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.Query<Models.xmjfsrModel>(sql).ToList();
}
}
}
}