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

117 lines
3.8 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 szyd_cgfsDal
{
public List<szyd_cgfsModel> GetAllTreeList()
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.Query<szyd_cgfsModel>("select * from szyd_cgfs", new { @zt = 1 }).ToList();
}
}
public List<szyd_cgfsModel> GetAllList()
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
return conn.Query<szyd_cgfsModel>("select * from szyd_cgfs where zt=1 ").ToList();
}
}
public List<szyd_cgfsModel> GetListByKey(string key)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = "select * from szyd_cgfs where zt=1";
if (!string.IsNullOrEmpty(key))
{
sql += " and title like @key";
}
return conn.Query<szyd_cgfsModel>(sql, new { key = "%" + key + "%" }).ToList();
}
}
public szyd_cgfsModel GetmodelByName(string name)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
List<szyd_cgfsModel> model = conn.Query<szyd_cgfsModel>("select * from szyd_cgfs where title=@name", new { name = name }).ToList();
if (model.Any())
{
return model[0];
}
return null;
}
}
public List<szyd_cgfsModel> GetAllList(string id)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string param = "";
if (id != "")
{
param = " and id=@id";
}
return conn.Query<szyd_cgfsModel > ("select * from szyd_cgfs where 1=1" + param, new { @id = id }).ToList();
}
}
public bool Add(szyd_cgfsModel model)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = @"INSERT INTO [dccdc].[dbo].[szyd_cgfs]
([cgfs]
,[zt])
VALUES
(@cgfs
,@zt)";
return (conn.Execute(sql, model) != 0 ? true : false);
}
}
public bool Update(szyd_cgfsModel model)
{
using (IDbConnection conn = CommHelper.GetSqlConnection())
{
string sql = @"UPDATE [dccdc].[dbo].[szyd_cgfs]
SET [cgfs] = @cgfs
,[zt] = @zt
WHERE id=@id";
return (conn.Execute(sql, model) != 0 ? true : false);
}
}
public object delete(string id)
{
string sql = "delete from szyd_cgfs 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 };
}
}
}
}
}