using Cksoft.Data;
using DllEapEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DllEapDal
{
public class UrlConfigDal
{
private IDatabase CurrDb;
public UrlConfigDal(IDatabase db)
{
CurrDb = db;
}
#region UrlConfig
///
/// 获取列表
///
///
///
///
///
///
public IEnumerable GetUrlConfigList(int start, int length, string filter, string sort, string order, ref string errorinfo)
{
var list = CurrDb.FindListForCondition($" {filter} order by {sort} {order} limit {start - 1},{length}",
ref errorinfo);
return list;
}
///
/// 获取单个实体
///
///
///
public UrlConfig GetUrlConfig(int id)
{
var model = CurrDb.FindEntityFor(id);
return model;
}
///
/// 根据类别code查询url
///
///
///
public IEnumerable GetUrlConfigByType(string typeCode)
{
var urlConfig = CurrDb.FindList($"select * from UrlConfig where FType=0 and FCode='{typeCode}'").FirstOrDefault();
if (urlConfig == null)
{
return null;
}
return CurrDb.FindList($"select * from UrlConfig where FType={urlConfig.ID}");
}
///
/// 更新
///
///
///
public int UpdateUrlConfig(UrlConfig model, string usercode, ref string errorinfo)
{
try
{
var sql = $"select * from UrlConfig where fcode='{model.FCode}' and id<>'{model.ID}'";
var temp = CurrDb.FindList(sql).FirstOrDefault();
if (temp != null)
{
errorinfo = "代码已存在";
return 0;
}
if (model.FType > 0)
{
sql = $"select * from UrlConfig where FType={model.FType} and Url='{model.Url}' and id<>'{model.ID}'";
temp = CurrDb.FindList(sql).FirstOrDefault();
if (temp != null)
{
errorinfo = "Url已存在";
return 0;
}
}
return CurrDb.UpdateFor(model, usercode);
}
catch (Exception e)
{
errorinfo = e.Message;
return 0;
}
}
///
/// 新增
///
///
///
public int InsertUrlConfig(UrlConfig model, ref string errorinfo)
{
try
{
var sql = $"select * from UrlConfig where fcode='{model.FCode}'";
var temp = CurrDb.FindList(sql).FirstOrDefault();
if (temp != null)
{
errorinfo = "代码已存在";
return 0;
}
if (model.FType > 0)
{
sql = $"select * from UrlConfig where FType={model.FType} and Url='{model.Url}'";
temp = CurrDb.FindList(sql).FirstOrDefault();
if (temp != null)
{
errorinfo = "Url已存在";
return 0;
}
}
return CurrDb.InsertFor(model, model.RecCode);
}
catch (Exception e)
{
errorinfo = e.Message;
return 0;
}
}
public int DeleteUrlConfig(int id, ref string errorinfo)
{
try
{
if (id <= 0)
{
errorinfo = "url不存在";
return 0;
}
return CurrDb.DeleteFor(id);
}
catch (Exception e)
{
errorinfo = e.Message;
return 0;
}
}
///
/// 获取总的记录数
///
///
///
public int GetUrlConfigCount(string filter)
{
string sql = string.Format($"SELECT COUNT(1) FROM urlconfig a WHERE 1=1 {filter}");
return Convert.ToInt32(CurrDb.FindList(sql).FirstOrDefault() ?? "0");
}
#endregion
}
}