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

213 lines
7.4 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 sqysmxDal
{
public List<sqysmxModel> GetAllList(string id)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = "select * from sqysmx where 1=1";
if (!string.IsNullOrEmpty(id))
{
sql += " and id=@id";
}
return conn.Query<sqysmxModel>(sql, new { @id = id }).ToList();
}
}
public List<sqysmxModel> GetAllList(string id, string zt)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = "select * from sqysmx where 1=1";
if (!string.IsNullOrEmpty(id))
{
sql += " and id=@id";
}
if (!string.IsNullOrEmpty(zt))
{
sql += " and zt=@zt";
}
return conn.Query<sqysmxModel>(sql, new { @id = id, @zt = zt }).ToList();
}
}
public List<sqysmxModel> GetListByParent(string parentid)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = "select * from sqysmx where 1=1 and sqdid=@parentid";
return conn.Query<sqysmxModel>(sql, new { parentid = parentid }).ToList();
}
}
public object save(sqysmxModel model)
{
string sql = "";
if (model.id == 0)
{
sql = @"INSERT INTO [dbo].[sqysmx]
([sqdid]
,[kmid]
,[kmmc]
,[sl]
,[dj]
,[czsj])
VALUES
(@sqdid
,@kmid
,@kmmc
,@sl
,@dj
,@czsj)";
}
else
{
sql = @"UPDATE [dbo].[sqysmx]
SET [sqdid] = @sqdid
,[kmid] = @kmid
,[kmmc] = @kmmc
,[sl] = @sl
,[dj] = @dj
,[czsj] = @czsj
WHERE id=@id";
}
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
try
{
int result = conn.Execute(sql, model);
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 object updateYyje(string items)
{
string sql = @"UPDATE [dbo].[sqysmx] SET [yyje] = [yyje]+ @yyje,[syje3] =[dj]- [yyje]- @yyje WHERE id=@id";
List<sqysmxModel> models = new List<sqysmxModel>();
sqysmxModel m;
foreach (string item in items.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
string[] itemss = item.Split('|');
if (itemss.Length == 2)
{
m = new sqysmxModel();
m.id = Convert.ToInt32(itemss[0]);
m.yyje = Convert.ToDecimal(itemss[1]);
models.Add(m);
}
}
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
try
{
conn.Execute(sql, models);
return new { State = 1, Message = "操作成功" };
}
catch (Exception ex)
{
return new { State = 0, Message = ex.Message };
}
}
}
public object delete(string id)
{
string sql = "delete from sqysmx 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.sqysmx where 1=1";
if (!string.IsNullOrEmpty(key))
{
sql += " and kmmc like @key";
}
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.ExecuteScalar<int>(sql, new { key = "%" + key + "%" });
}
}
public List<sqysmxModel> getPage(int page, int pagesize, string key)
{
string sql = "select *,row_number() over(order by id) as rownum from sqysmx where 1=1";
if (!string.IsNullOrEmpty(key))
{
sql += " and kmmc 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.sqysmxModel>(sql, new { key = "%" + key + "%" }).ToList();
}
}
//报销明细
public List<dynamic> getBXMX(string where)
{
string sql = @"select a.*,(a.dj-a.yyje) as syje2,0 as syje,[sqdh],[sqsj],b.[tjsj],[sqrid],[sqr],[ksid],[ksmc],[je],[je2],[je3],[year],[bz],[mx],[fyly],b.zt,c.xmmc from sqysmx a
left join sqys b on a.sqdid=b.id left join xmjingfei c on b.xmjfid=c.id where b.zt = 8";
if (!string.IsNullOrEmpty(where))
{
sql += where;
}
using (var conn = CommHelper.GetSqlConnection())
{
return conn.Query(sql, new { where = where }).ToList();
}
}
//报销历史
public List<dynamic> getBXLS(string where)
{
string sql = @"select aa.*,aa.id as idN,aa.czsj as czsjN,aa.je as jeN,bb.* from sqyssy aa left join
(select a.*,(a.dj-a.yyje) as syje,[sqdh],[sqsj],[tjsj],[sqrid],[sqr],[ksid],[ksmc],[je],[je2],[je3],[year],[bz],[mx],[fyly],[zt] from sqysmx a left join sqys b on a.sqdid=b.id) bb on aa.ysmxid=bb.id where 1=1";
if (!string.IsNullOrEmpty(where))
{
sql += where;
}
using (var conn = CommHelper.GetSqlConnection())
{
return conn.Query(sql, new { where = where }).ToList();
}
}
}
}