Files
6098-5/Cowain.Preheat.BLL/SysSetupService.cs
T
2026-05-28 22:11:13 +08:00

104 lines
3.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity;
using Cowain.Preheat.Model;
namespace Cowain.Preheat.BLL
{
public class SysSetupService : ServiceBase
{
public Dictionary<string, string> ParaDic = new Dictionary<string, string>();
public SysSetupService(IUnityContainer unityContainer) : base(unityContainer)
{
GetAllParam();
}
public List<TSysSetup> GetAll()
{
using (var Context = new PreheatEntities())
{
return Context.Set<TSysSetup>().OrderBy(item => item.Id).ToList();
}
}
public void GetAllParam()
{
ParaDic.Clear();
List<TSysSetup> list = null;
using (var Context = new PreheatEntities())
{
list = Context.Set<TSysSetup>().OrderBy(item => item.Id).ToList();
}
foreach (var item in list)
{
ParaDic.Add(item.ParamCode, item.ParamValue);
}
}
public string GetValueByParaID(string paraID)
{
return ParaDic[paraID];
}
public string GetValueByID(long ID)
{
using (var Context = new PreheatEntities())
{
var pi = (from ts in Context.Set<TSysSetup>()
where ts.Id == ID
select ts).FirstOrDefault();
return pi.ParamValue;
}
}
public bool UpdateValue(long ID, string value)
{
using (var Context = new PreheatEntities())
{
var pi = (from ts in Context.Set<TSysSetup>()
where ts.Id == ID
select ts).FirstOrDefault();
pi.ParamValue = value;
var b = Context.SaveChanges() > 0 ? true : false;
GetAllParam();
return b;
}
}
public bool UpdateValue(string paramCode, string value)
{
using (var Context = new PreheatEntities())
{
var pi = (from ts in Context.Set<TSysSetup>()
where ts.ParamCode == paramCode
select ts).FirstOrDefault();
pi.ParamValue = value;
var b = Context.SaveChanges() > 0 ? true : false;
GetAllParam();
return b;
}
}
public List<TSysSetup> GetAllParaWithoutToogleButton()
{
using (var Context = new PreheatEntities())
{
var list = Context.Set<TSysSetup>().OrderBy(item => item.Id).ToList();
string sql = $@"SELECT ti.JSON->>'$.CMD' CMD FROM TMenuInfo ti where ti.MenuType=2;";
var table = GetDataTable(sql);
List<TSysSetup> rtnList = new List<TSysSetup>();
foreach (var item in list)
{
if (table.Select($@"CMD='{item.ParamCode.Trim()}'").Count() != 1)
{
rtnList.Add(item);
}
}
return rtnList;
}
}
}
}