138 lines
4.7 KiB
C#
138 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 sqyssyDal
|
|
{
|
|
public List<sqyssyModel> GetAllTreeList()
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
return conn.Query<sqyssyModel>("select * from sqyssy", new { @zt = 1 }).ToList();
|
|
}
|
|
}
|
|
public List<sqyssyModel> GetAllList()
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
return conn.Query<sqyssyModel>("select * from sqyssy where zt=1 ").ToList();
|
|
}
|
|
}
|
|
|
|
public List<sqyssyModel> GetListByKey(string type, string sqid)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string sql = "select * from sqyssy where type=@type and sqid =@sqid";
|
|
return conn.Query<sqyssyModel>(sql, new { type = type, sqid = sqid }).ToList();
|
|
}
|
|
}
|
|
|
|
public sqyssyModel GetmodelByName(string name)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
List<sqyssyModel> model = conn.Query<sqyssyModel>("select * from sqyssy where title=@name", new { name = name }).ToList();
|
|
if (model.Any())
|
|
{
|
|
return model[0];
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public List<sqyssyModel> GetAllList(string id)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string param = "";
|
|
if (id != "")
|
|
{
|
|
param = " and id=@id";
|
|
}
|
|
return conn.Query<sqyssyModel>("select * from sqyssy where 1=1" + param, new { @id = id }).ToList();
|
|
}
|
|
}
|
|
|
|
public bool Add(sqyssyModel model)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string sql = @"INSERT INTO [dbo].[sqyssy]
|
|
([type]
|
|
,[ysmxid]
|
|
,[je]
|
|
,[bxdid]
|
|
,[czsj]
|
|
,[czyid]
|
|
,[czyname])
|
|
VALUES
|
|
(@type
|
|
,@ysmxid
|
|
,@je
|
|
,@bxdid
|
|
,@czsj
|
|
,@czyid
|
|
,@czyname)";
|
|
return (conn.Execute(sql, model) != 0 ? true : false);
|
|
}
|
|
}
|
|
|
|
public object AddList(List<sqyssyModel> models)
|
|
{
|
|
string sql = @"INSERT INTO [dbo].[sqyssy]
|
|
([type]
|
|
,[ysmxid]
|
|
,[je]
|
|
,[bxdid]
|
|
,[czsj]
|
|
,[czyid]
|
|
,[czyname])
|
|
VALUES
|
|
(@type
|
|
,@ysmxid
|
|
,@je
|
|
,@bxdid
|
|
,@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 bool Update(sqyssyModel model)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string sql = @"UPDATE [dbo].[sqyssy]
|
|
SET [type] = @type
|
|
,[ysmxid] = @ysmxid
|
|
,[je] = @je
|
|
,[bxdid] = @bxdid
|
|
,[czsj] = @czsj
|
|
,[czyid] = @czyid
|
|
,[czyname] = @czyname
|
|
WHERE id=@id";
|
|
return (conn.Execute(sql, model) != 0 ? true : false);
|
|
}
|
|
}
|
|
}
|
|
}
|