164 lines
5.3 KiB
C#
164 lines
5.3 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 areaDal
|
|
{
|
|
public List<areaModel> GetAllTreeList()
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
return conn.Query<areaModel>("select * from area", new { @zt = 1 }).ToList();
|
|
}
|
|
}
|
|
public List<areaModel> GetAllList()
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
return conn.Query<areaModel>("select * from area where zt=1 order by cy desc").ToList();
|
|
}
|
|
}
|
|
|
|
public List<areaModel> GetListByKey(string key)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string sql = "select * from area where zt=1";
|
|
if (!string.IsNullOrEmpty(key))
|
|
{
|
|
sql += " and title like @key";
|
|
}
|
|
return conn.Query<areaModel>(sql, new { key = "%" + key + "%" }).ToList();
|
|
}
|
|
}
|
|
|
|
public areaModel GetmodelByName(string name)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
List<areaModel> model = conn.Query<areaModel>("select * from area where title=@name", new { name = name }).ToList();
|
|
if (model.Any())
|
|
{
|
|
return model[0];
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public List<areaModel> GetAllList(string id)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string param = "";
|
|
if (id != "")
|
|
{
|
|
param = " and id=@id";
|
|
}
|
|
return conn.Query<areaModel>("select * from area where 1=1" + param, new { @id = id }).ToList();
|
|
}
|
|
}
|
|
|
|
|
|
public List<areaModel> GetChild(string id)
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string param = "";
|
|
if (id != "")
|
|
{
|
|
param = " and pid=@id";
|
|
}
|
|
return conn.Query<areaModel>("select * from area where 1=1" + param, new { @id = id }).ToList();
|
|
}
|
|
}
|
|
public bool Add(areaModel model)
|
|
{
|
|
try
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string sql = @"INSERT INTO [dccdc].[dbo].[area]
|
|
([pid]
|
|
,[name]
|
|
,[code]
|
|
,[level]
|
|
,[cy]
|
|
,[bz]
|
|
,[bz2]
|
|
,[zt])
|
|
VALUES
|
|
(@pid
|
|
,@name
|
|
,@code
|
|
,@level
|
|
,@cy
|
|
,@bz
|
|
,@bz2
|
|
,@zt)";
|
|
return (conn.Execute(sql, model) != 0 ? true : false);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
public bool Update(areaModel model)
|
|
{
|
|
try
|
|
{
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|
{
|
|
string sql = @"UPDATE [dccdc].[dbo].[area]
|
|
SET [pid] = @pid
|
|
,[name] = @name
|
|
,[code] = @code
|
|
,[level] = @level
|
|
,[cy] = @cy
|
|
,[bz] = @bz
|
|
,[bz2] = @bz2
|
|
,[zt] = @zt
|
|
WHERE id=@id";
|
|
return (conn.Execute(sql, model) != 0 ? true : false);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public object delete(string id)
|
|
{
|
|
string sql = "delete from area 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 };
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|