133 lines
4.9 KiB
C#
133 lines
4.9 KiB
C#
using Cowain.Bake.Common.Enums;
|
|
using Cowain.Bake.Model;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Unity;
|
|
|
|
namespace Cowain.Bake.BLL
|
|
{
|
|
public class ProcessParamService : ServiceBase
|
|
{
|
|
public ProcessParamService(IUnityContainer unityContainer) : base(unityContainer)
|
|
{
|
|
|
|
}
|
|
|
|
public bool UpdateProcessParam(int paraID, string JSONPara)
|
|
{
|
|
using (var Context = new BakingEntities())
|
|
{
|
|
//保存老的,方便追查
|
|
string 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 BakingEntities())
|
|
{
|
|
var formulaList = Context.Set<TProcessParameter>().Where(x => x.BaseFalg != true).OrderBy(x => x.Id).ToList();
|
|
return formulaList;
|
|
}
|
|
}
|
|
|
|
|
|
public bool UpdateCurrentJobNum(int ID)
|
|
{
|
|
string sql = $@"call ProcUpdateCurrentJob({ID})";
|
|
using (var Context = new BakingEntities())
|
|
{
|
|
return Context.Database.ExecuteSqlCommand(sql) != 0;
|
|
}
|
|
}
|
|
|
|
public List<TProcessParameter> QueryFormulas(string formulaName)
|
|
{
|
|
using (var Context = new BakingEntities())
|
|
{
|
|
return Context.Set<TProcessParameter>().Where(x => x.ProcessParamName == formulaName).ToList();
|
|
}
|
|
}
|
|
public TProcessParameter QueryFormulaById(int formulaId, string parametersJson)
|
|
{
|
|
using (var Context = new BakingEntities())
|
|
{
|
|
var query = Context.Set<TProcessParameter>().Where(x => x.Id == formulaId && x.Parameters == parametersJson).FirstOrDefault();
|
|
return query;
|
|
}
|
|
|
|
}
|
|
|
|
public TProcessParameter GetReProcessParam(string jobNum)
|
|
{
|
|
using (var Context = new BakingEntities())
|
|
{
|
|
return (from proInfo in Context.Set<TProductionInformation>()
|
|
where proInfo.JobNum == jobNum
|
|
join param in Context.Set<TProcessParameter>() on proInfo.ReProcessParamId equals param.Id
|
|
select param).FirstOrDefault();
|
|
}
|
|
}
|
|
|
|
public string GetProcessParam(int id)
|
|
{
|
|
string sql = $@"SELECT Parameters FROM TProcessParameter WHERE Id={id}";
|
|
using (var Context = new BakingEntities())
|
|
{
|
|
return Context.Database.SqlQuery<string>(sql).FirstOrDefault();
|
|
}
|
|
|
|
}
|
|
public TProcessParameter Get(int id)
|
|
{
|
|
using (var Context = new BakingEntities())
|
|
{
|
|
return Context.Set<TProcessParameter>().Where(x => x.Id == id).FirstOrDefault();
|
|
}
|
|
}
|
|
public bool CreateNewProcessParam(string processParaName)
|
|
{
|
|
using (var Context = new BakingEntities())
|
|
{
|
|
string sql = $@"select count(*) from TProcessParameter where ProcessParamName='{processParaName}'";
|
|
if (0 != Context.Database.SqlQuery<int>(sql).First())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
sql = $@"INSERT INTO TProcessParameter(ProcessParamName,Parameters,BaseFalg,CreateTime)
|
|
SELECT '{processParaName}' ProcessName,tp.Parameters,0,now() FROM TProcessParameter tp
|
|
WHERE tp.BaseFalg=1;";
|
|
return Context.Database.ExecuteSqlCommand(sql) != 0;
|
|
}
|
|
}
|
|
public List<TProcessParameter> QueryFormula(string formulaName)
|
|
{
|
|
using (var Context = new BakingEntities())
|
|
{
|
|
var queryList = Context.Set<TProcessParameter>().Where(x => x.ProcessParamName == formulaName).ToList();
|
|
return queryList;
|
|
}
|
|
}
|
|
|
|
public TProcessParameter GetProcessParam(string jobNum)
|
|
{
|
|
using (var Context = new BakingEntities())
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
}
|