Files
6098-5/Cowain.Preheat.BLL/ProcessParamService.cs
T

144 lines
5.3 KiB
C#
Raw Normal View History

2026-05-28 22:11:13 +08:00
using Cowain.Preheat.Common.Core;
using Cowain.Preheat.Common.Enums;
using Cowain.Preheat.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using Unity;
namespace Cowain.Preheat.BLL
{
public class ProcessParamService : ServiceBase
{
public ProcessParamService(IUnityContainer unityContainer) : base(unityContainer)
{
}
public bool UpdateProcessParam(int paraID, string JSONPara)
{
using (var Context = new PreheatEntities())
{
string sql = $@"select count(*) from TProcessParameter where Id={paraID} and Parameters='{JSONPara}'";
if (GetDataTable(sql).Rows[0][0].ToString() == "1")
{
return true;
}
//保存老的,方便追查
sql = $@"select Parameters from TProcessParameter where Id={paraID} limit 1";
var param = Context.Database.SqlQuery<string>(sql).FirstOrDefault();
_unityContainer.Resolve<LogService>().AddLog("WorkOrderService.AddParaLog:" + param + "->"
+ JSONPara, E_LogType.Operate.ToString());
sql = $@"UPDATE TProcessParameter set Parameters='{JSONPara}' WHERE Id={paraID}";
return Context.Database.ExecuteSqlCommand(sql) > 0 ? true : false;
}
}
//所有的配方
public List<TProcessParameter> GetAllFormula()
{
using (var Context = new PreheatEntities())
{
var formulaList = Context.Set<TProcessParameter>().Where(x => x.BaseFalg != true).OrderBy(x => x.Id).ToList();
return formulaList;
}
}
public int UpdateCurrentJobNum(int ID)
{
string sql = $@"call ProcUpdateCurrentJob({ID})";
using (var Context = new PreheatEntities())
{
return Context.Database.ExecuteSqlCommand(sql);
}
}
public List<TProcessParameter> QueryFormulas(string formulaName)
{
using (var Context = new PreheatEntities())
{
return Context.Set<TProcessParameter>().Where(x => x.ProcessParamName == formulaName).ToList();
}
}
public TProcessParameter QueryFormulaById(int formulaId, string parametersJson)
{
using (var Context = new PreheatEntities())
{
var query = Context.Set<TProcessParameter>().Where(x => x.Id == formulaId && x.Parameters == parametersJson).FirstOrDefault();
return query;
}
}
public string GetProcessParam(int id)
{
string sql = $@"SELECT Parameters FROM TProcessParameter WHERE Id={id}";
using (var Context = new PreheatEntities())
{
return Context.Database.SqlQuery<string>(sql).FirstOrDefault();
}
}
public TProcessParameter GetParaByID(int operationID)
{
using (var Context = new PreheatEntities())
{
var query = Context.Set<TProcessParameter>().Where(x => x.Id == operationID).ToList().FirstOrDefault();
return query;
}
}
public bool CreateNewProcessPara(string processParaName, out string errorMessage)
{
errorMessage = "";
string sql = $@"select count(*) from TProcessParameter where ProcessParamName='{processParaName}'";
if (GetDataTable(sql).Rows[0][0].ToString() != "0")
{
errorMessage = "名称重复!";
return false;
}
sql = $@"INSERT INTO TProcessParameter(ProcessParamName,Parameters,BaseFalg)
SELECT '{processParaName}' ProcessName,tp.Parameters,0 FROM TProcessParameter tp
WHERE tp.BaseFalg=1;";
using (var Context = new PreheatEntities())
{
return Context.Database.ExecuteSqlCommand(sql) > 0 ? true : false;
}
}
public List<TProcessParameter> QueryFormula(string formulaName)
{
using (var Context = new PreheatEntities())
{
var queryList = Context.Set<TProcessParameter>().Where(x => x.ProcessParamName == formulaName).ToList();
return queryList;
}
}
public TProcessParameter GetCurrentParam()
{
using (var Context = new PreheatEntities())
{
return (from proInfo in Context.Set<TProductionInformation>()
join param in Context.Set<TProcessParameter>() on proInfo.ProcessParamId equals param.Id
where proInfo.CurrentProduct == true
select param).FirstOrDefault();
}
}
public TProcessParameter GetProcessParam(string jobNum)
{
using (var Context = new PreheatEntities())
{
return (from proInfo in Context.Set<TProductionInformation>()
where proInfo.JobNum == jobNum
join param in Context.Set<TProcessParameter>() on proInfo.ProcessParamId equals param.Id
select param).FirstOrDefault();
}
}
}
}