123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- 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
- /// <summary>
- /// 获取列表
- /// </summary>
- /// <param name="start"></param>
- /// <param name="filter"></param>
- /// <param name="sort"></param>
- /// <param name="order"></param>
- /// <returns></returns>
- public IEnumerable<UrlConfig> GetUrlConfigList(int start, int length, string filter, string sort, string order, ref string errorinfo)
- {
- var list = CurrDb.FindListForCondition<UrlConfig>($" {filter} order by {sort} {order} limit {start - 1},{length}",
- ref errorinfo);
- return list;
- }
- /// <summary>
- /// 获取单个实体
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public UrlConfig GetUrlConfig(int id)
- {
- var model = CurrDb.FindEntityFor<UrlConfig>(id);
- return model;
- }
- /// <summary>
- /// 根据类别code查询url
- /// </summary>
- /// <param name="typeCode"></param>
- /// <returns></returns>
- public IEnumerable<UrlConfig> GetUrlConfigByType(string typeCode)
- {
- var urlConfig = CurrDb.FindList<UrlConfig>($"select * from UrlConfig where FType=0 and FCode='{typeCode}'").FirstOrDefault();
- if (urlConfig == null)
- {
- return null;
- }
- return CurrDb.FindList<UrlConfig>($"select * from UrlConfig where FType={urlConfig.ID}");
- }
- /// <summary>
- /// 更新
- /// </summary>
- /// <param name="t"></param>
- /// <returns></returns>
- 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<UrlConfig>(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<UrlConfig>(sql).FirstOrDefault();
- if (temp != null)
- {
- errorinfo = "Url已存在";
- return 0;
- }
- }
- return CurrDb.UpdateFor<UrlConfig>(model, usercode);
- }
- catch (Exception e)
- {
- errorinfo = e.Message;
- return 0;
- }
- }
- /// <summary>
- /// 新增
- /// </summary>
- /// <param name="t"></param>
- /// <returns></returns>
- public int InsertUrlConfig(UrlConfig model, ref string errorinfo)
- {
- try
- {
- var sql = $"select * from UrlConfig where fcode='{model.FCode}'";
- var temp = CurrDb.FindList<UrlConfig>(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<UrlConfig>(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<UrlConfig>(id);
- }
- catch (Exception e)
- {
- errorinfo = e.Message;
- return 0;
- }
- }
- /// <summary>
- /// 获取总的记录数
- /// </summary>
- /// <param name="filter"></param>
- /// <returns></returns>
- public int GetUrlConfigCount(string filter)
- {
- string sql = string.Format($"SELECT COUNT(1) FROM urlconfig a WHERE 1=1 {filter}");
- return Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "0");
- }
- #endregion
- }
- }
|