229 lines
9.5 KiB
C#
229 lines
9.5 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Web;
|
|
|
|
namespace BLL
|
|
{
|
|
public static class Project_SysSetService
|
|
{
|
|
/// <summary>
|
|
/// 材料炉批号设置编号。
|
|
/// </summary>
|
|
public const string MaterialBatchSetId = "12";
|
|
|
|
/// <summary>
|
|
/// 材料炉批号设置名称。
|
|
/// </summary>
|
|
public const string MaterialBatchSetName = "材料是否使用炉批号";
|
|
|
|
/// <summary>
|
|
/// 获取项目是否使用材料炉批号。未配置时保持历史行为,默认使用炉批号。
|
|
/// </summary>
|
|
public static bool UsesMaterialBatchNumber(string projectId)
|
|
{
|
|
var setting = GetSysSetBySetId(MaterialBatchSetId, projectId);
|
|
return setting == null || setting.IsAuto != false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取关闭材料炉批号设置前的数据兼容性提示。
|
|
/// </summary>
|
|
public static string GetDisableMaterialBatchWarning(string projectId)
|
|
{
|
|
var db = Funs.DB;
|
|
var invalidStockCount = (from stock in db.Tw_MaterialStock
|
|
join material in db.HJGL_MaterialCodeLib on stock.PipeLineMatCode equals material.MaterialCode
|
|
where stock.ProjectId == projectId
|
|
&& stock.StockNum != null
|
|
&& stock.StockNum != 0
|
|
&& material.MaterialCode != material.Code
|
|
select stock.Id).Count();
|
|
|
|
var invalidPlanDetailCount = (from detail in db.Tw_InOutPlanDetail
|
|
join master in db.Tw_InOutPlanMaster on detail.InOutPlanMasterId equals master.Id
|
|
join material in db.HJGL_MaterialCodeLib on detail.MaterialCode equals material.MaterialCode
|
|
where master.ProjectId == projectId
|
|
&& (master.State == (int)TwConst.State.待提交
|
|
|| master.State == (int)TwConst.State.待审核
|
|
|| master.State == (int)TwConst.State.已审核)
|
|
&& material.MaterialCode != material.Code
|
|
select detail.Id).Count();
|
|
|
|
var invalidPipelineMaterialCount = (from material in db.HJGL_PipeLineMat
|
|
join pipeline in db.HJGL_Pipeline on material.PipelineId equals pipeline.PipelineId
|
|
where pipeline.ProjectId == projectId
|
|
&& (material.MaterialCode == null
|
|
|| material.MaterialCode == ""
|
|
|| material.MaterialCode2 == null
|
|
|| material.MaterialCode2 == ""
|
|
|| material.MaterialCode != material.MaterialCode2)
|
|
select material.PipeLineMatId).Count();
|
|
|
|
if (invalidStockCount == 0 && invalidPlanDetailCount == 0 && invalidPipelineMaterialCount == 0)
|
|
{
|
|
return "";
|
|
}
|
|
|
|
return string.Format(
|
|
"无法关闭材料炉批号设置:非零库存主编码不一致 {0} 条;未完成出入库单主编码不一致 {1} 条;管线材料编码未归一化 {2} 条。请先处理后重试。",
|
|
invalidStockCount,
|
|
invalidPlanDetailCount,
|
|
invalidPipelineMaterialCount);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取avevanet 地址
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string GetAvevaNetUrl(string projectId)
|
|
{
|
|
var q = from x in Funs.DB.Project_Sys_Set where x.SetId == "9" && x.ProjectId == projectId select x;
|
|
if (q.Count() == 0)
|
|
{
|
|
return "";
|
|
}
|
|
return q.First().SetValue;
|
|
}
|
|
public static string GetAvevaNetUrl_Item(string projectId)
|
|
{
|
|
string url = "";
|
|
var q = from x in Funs.DB.Project_Sys_Set where x.SetId == "9" && x.ProjectId == projectId select x;
|
|
if (q.Count() == 0)
|
|
{
|
|
return "";
|
|
}
|
|
try
|
|
{
|
|
var uri = new Uri(q.First().SetValue);
|
|
var collection = HttpUtility.ParseQueryString(uri.Query);
|
|
string value = collection["portalid"];
|
|
url = q.First().SetValue + "item/" + value + "%7C";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
url = "";
|
|
}
|
|
|
|
return url;
|
|
}
|
|
public static Model.ColorModel GetColorModel(string projectId)
|
|
{
|
|
Model.ColorModel colorModel = new Model.ColorModel();
|
|
|
|
Model.Project_Sys_Set Model_PipelineNOComplete = BLL.Project_SysSetService.GetSysSetBySetName("管线未完成", projectId);
|
|
if (Model_PipelineNOComplete != null)
|
|
{
|
|
colorModel.PipelineNOComplete = Model_PipelineNOComplete.SetValue;
|
|
}
|
|
Model.Project_Sys_Set Model_PipelineComplete = BLL.Project_SysSetService.GetSysSetBySetName("管线已完成", projectId);
|
|
if (Model_PipelineComplete != null)
|
|
{
|
|
colorModel.PipelineComplete = Model_PipelineComplete.SetValue;
|
|
}
|
|
Model.Project_Sys_Set Model_JointNOCompleteColor = BLL.Project_SysSetService.GetSysSetBySetName("焊口未完成", projectId);
|
|
if (Model_JointNOCompleteColor != null)
|
|
{
|
|
colorModel.JointNOCompleteColor = Model_JointNOCompleteColor.SetValue;
|
|
}
|
|
Model.Project_Sys_Set Model_JointCompleteColor = BLL.Project_SysSetService.GetSysSetBySetName("焊口已完成", projectId);
|
|
if (Model_JointCompleteColor != null)
|
|
{
|
|
colorModel.JointCompleteColor = Model_JointCompleteColor.SetValue;
|
|
}
|
|
|
|
return colorModel;
|
|
|
|
}
|
|
public static bool? IsAuto(string setId, string projectId)
|
|
{
|
|
var q = from x in Funs.DB.Project_Sys_Set where x.SetId == setId && x.ProjectId == projectId select x;
|
|
return q.First().IsAuto;
|
|
}
|
|
public static Model.Project_Sys_Set GetSysSetBySetId(string setId, string projectId)
|
|
{
|
|
return Funs.DB.Project_Sys_Set.Where(x => x.SetId == setId && x.ProjectId == projectId).FirstOrDefault();
|
|
}
|
|
public static Model.Project_Sys_Set GetSysSetBySetName(string setName, string projectId)
|
|
{
|
|
return Funs.DB.Project_Sys_Set.Where(x => x.SetName == setName && x.ProjectId == projectId).FirstOrDefault();
|
|
}
|
|
/// <summary>
|
|
/// 增加系统变量
|
|
/// </summary>
|
|
/// <param name="user">系统变量</param>
|
|
public static void AddSet(Model.Project_Sys_Set set)
|
|
{
|
|
Model.SGGLDB db = Funs.DB;
|
|
Model.Project_Sys_Set newSet = new Model.Project_Sys_Set();
|
|
newSet.SetId = set.SetId;
|
|
newSet.ProjectId = set.ProjectId;
|
|
newSet.SetName = set.SetName;
|
|
newSet.IsAuto = set.IsAuto;
|
|
newSet.SetValue = set.SetValue;
|
|
|
|
db.Project_Sys_Set.InsertOnSubmit(newSet);
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改系统变量
|
|
/// </summary>
|
|
/// <param name="user">系统变量</param>
|
|
public static void UpdateSet(Model.Project_Sys_Set set)
|
|
{
|
|
Model.SGGLDB db = Funs.DB;
|
|
Model.Project_Sys_Set newSet = db.Project_Sys_Set.FirstOrDefault(e => e.SetId == set.SetId && e.ProjectId == set.ProjectId);
|
|
if (newSet != null)
|
|
{
|
|
if (set.SetName != null && set.SetName != "")
|
|
{
|
|
newSet.SetName = set.SetName;
|
|
}
|
|
newSet.IsAuto = set.IsAuto;
|
|
newSet.SetValue = set.SetValue;
|
|
db.SubmitChanges();
|
|
}
|
|
}
|
|
|
|
public static void InsertHjglInit(string projectId)
|
|
{
|
|
for (int i = 1; i <= 5; i++)
|
|
{
|
|
Model.Project_Sys_Set newSet = new Model.Project_Sys_Set();
|
|
newSet.SetId = i.ToString();
|
|
newSet.ProjectId = projectId;
|
|
|
|
if (i == 1)
|
|
{
|
|
newSet.SetName = "焊接日报编号";
|
|
newSet.IsAuto = true;
|
|
}
|
|
if (i == 2)
|
|
{
|
|
newSet.SetName = "点口编号";
|
|
newSet.IsAuto = true;
|
|
}
|
|
if (i == 3)
|
|
{
|
|
newSet.SetName = "无损检测委托单";
|
|
newSet.IsAuto = true;
|
|
}
|
|
if (i == 4)
|
|
{
|
|
newSet.SetName = "引用PDMS导出模板";
|
|
newSet.IsAuto = false;
|
|
}
|
|
if (i == 5)
|
|
{
|
|
newSet.SetName = "组批条件设置";
|
|
newSet.SetValue = "1";
|
|
newSet.SetValue = "1|2|3|4|5";
|
|
}
|
|
|
|
AddSet(newSet);
|
|
}
|
|
}
|
|
}
|
|
}
|