206 lines
7.0 KiB
C#
206 lines
7.0 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 sqbxmx2Dal
|
|
{
|
|
public List<sqbxmx2Model> GetAllList(string id)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string sql = "select * from sqbxmx2 where 1=1";
|
|
if (!string.IsNullOrEmpty(id))
|
|
{
|
|
sql += " and id=@id";
|
|
}
|
|
return conn.Query<sqbxmx2Model>(sql, new { @id = id }).ToList();
|
|
}
|
|
}
|
|
|
|
public List<sqbxmx2Model> GetType(string type, string bxdid)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string sql = "select * from sqbxmx2 where type=@type and bxdid=@bxdid";
|
|
return conn.Query<sqbxmx2Model>(sql, new { @type = type, @bxdid = bxdid }).ToList();
|
|
}
|
|
}
|
|
|
|
public List<sqbxmx2Model> GetAllList(string id, string zt)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string sql = "select * from sqbxmx2 where 1=1";
|
|
if (!string.IsNullOrEmpty(id))
|
|
{
|
|
sql += " and id=@id";
|
|
}
|
|
if (!string.IsNullOrEmpty(zt))
|
|
{
|
|
sql += " and zt=@zt";
|
|
}
|
|
return conn.Query<sqbxmx2Model>(sql, new { @id = id, @zt = zt }).ToList();
|
|
}
|
|
}
|
|
|
|
public List<sqbxmx2Model> GetListByParent(string parentid)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string sql = "select * from sqbxmx2 where 1=1 and sqdid=@parentid";
|
|
return conn.Query<sqbxmx2Model>(sql, new { parentid = parentid }).ToList();
|
|
}
|
|
}
|
|
|
|
public object save(sqbxmx2Model model)
|
|
{
|
|
string sql = "";
|
|
if (model.id == 0)
|
|
{
|
|
sql = @"INSERT INTO [dccdc].[dbo].[sqbxmx2]
|
|
([sqdid]
|
|
,[title]
|
|
,[content]
|
|
,[kmid]
|
|
,[kmmc]
|
|
,[sl]
|
|
,[je]
|
|
,[czsj])
|
|
VALUES
|
|
(@sqdid
|
|
,@title
|
|
,@conten
|
|
,@kmid
|
|
,@kmmc
|
|
,@sl
|
|
,@je
|
|
,@czsj)";
|
|
}
|
|
else
|
|
{
|
|
sql = @"UPDATE [dccdc].[dbo].[sqbxmx2]
|
|
SET [sqdid] = @sqdid
|
|
,[title] = @title
|
|
,[content] = @content
|
|
,[kmid] = @kmid
|
|
,[kmmc] = @kmmc
|
|
,[sl] = @sl
|
|
,[je] = @je
|
|
,[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 AddList(List<sqbxmx2Model> models)
|
|
{
|
|
string sql = @"INSERT INTO [dbo].[sqbxmx2]
|
|
([type]
|
|
,[bxdid]
|
|
,[content]
|
|
,[kmid]
|
|
,[kmmc]
|
|
,[ysid]
|
|
,[xmmc]
|
|
,[je]
|
|
,[czsj]
|
|
,[czyid]
|
|
,[czyname])
|
|
VALUES
|
|
(@type
|
|
,@bxdid
|
|
,@content
|
|
,@kmid
|
|
,@kmmc
|
|
,@ysid
|
|
,@xmmc
|
|
,@je
|
|
,@czsj
|
|
,@czyid
|
|
,@czyname)";
|
|
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 sqbxmx2 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.sqbxmx2 where 1=1";
|
|
if (!string.IsNullOrEmpty(key))
|
|
{
|
|
sql += " and mc like @key";
|
|
}
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
return conn.ExecuteScalar<int>(sql, new { key = "%" + key + "%" });
|
|
}
|
|
}
|
|
|
|
public List<sqbxmx2Model> getPage(int page, int pagesize, string key)
|
|
{
|
|
string sql = "select *,row_number() over(order by id) as rownum from sqbxmx2 where 1=1";
|
|
if (!string.IsNullOrEmpty(key))
|
|
{
|
|
sql += " and mc 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.sqbxmx2Model>(sql, new { key = "%" + key + "%" }).ToList();
|
|
}
|
|
}
|
|
}
|
|
}
|