SGGL_SHJ/SGGL/BLL/HJGL/WeldingManage/PipelineComponentService.cs

497 lines
20 KiB
C#
Raw Normal View History

2023-02-20 10:49:51 +08:00
using System;
2023-11-08 17:26:59 +08:00
using System.Collections;
2023-02-20 10:49:51 +08:00
using System.Collections.Generic;
2023-11-08 17:26:59 +08:00
using System.Data;
2022-09-05 16:36:31 +08:00
using System.Linq;
using System.Web.UI.WebControls;
2023-09-11 11:40:38 +08:00
using Model;
2023-11-08 17:26:59 +08:00
using NPOI.SS.Formula.Functions;
2022-09-05 16:36:31 +08:00
namespace BLL
{
public class HJGL_PipelineComponentService
{
2024-11-06 09:36:10 +08:00
/// <summary>
2024-11-06 09:59:54 +08:00
/// 待整改
2024-11-06 09:36:10 +08:00
/// </summary>
2024-11-06 09:59:54 +08:00
public static int StatePenRec = -2;
/// <summary>
/// 已整改
/// </summary>
public static int StateRec = -1;
2022-09-05 16:36:31 +08:00
/// <summary>
/// 未验收
/// </summary>
2024-11-06 09:59:54 +08:00
public static int State0 = 0;
2023-11-08 17:26:59 +08:00
2022-09-05 16:36:31 +08:00
/// <summary>
/// 已验收
/// </summary>
2024-11-06 09:59:54 +08:00
public static int State1 = 1;
2023-11-08 17:26:59 +08:00
2022-09-05 16:36:31 +08:00
/// <summary>
/// 已装箱
/// </summary>
2024-11-06 09:59:54 +08:00
public static int State2 = 2;
2024-10-09 17:20:12 +08:00
2023-02-20 10:49:51 +08:00
2023-11-08 17:26:59 +08:00
/// <summary>
/// 获取状态名称
/// </summary>
/// <returns></returns>
2022-09-05 16:36:31 +08:00
public static ListItem[] GetState()
{
2024-11-06 09:59:54 +08:00
ListItem[] list = new ListItem[5];
list[0] = new ListItem("未验收", State0.ToString());
list[1] = new ListItem("已验收", State1.ToString());
list[2] = new ListItem("已出库", State2.ToString());
list[3] = new ListItem("待整改", StatePenRec.ToString());
list[4] = new ListItem("已整改", StateRec.ToString());
2022-09-05 16:36:31 +08:00
return list;
}
2023-11-08 17:26:59 +08:00
/// <summary>
/// 生产状态
/// </summary>
/// <returns></returns>
2023-02-20 10:49:51 +08:00
public static ListItem[] GetProductionState()
{
ListItem[] list = new ListItem[3];
list[0] = new ListItem("未开始", "0");
list[1] = new ListItem("已开始", "1");
list[2] = new ListItem("已完成", "2");
return list;
}
2022-09-05 16:36:31 +08:00
/// <summary>
/// 根据ID获取组件信息
/// </summary>
/// <param name="pipelineName"></param>
/// <returns></returns>
public static Model.HJGL_Pipeline_Component GetPipelineComponentById(string pipelineComponentId)
{
return Funs.DB.HJGL_Pipeline_Component.FirstOrDefault(e => e.PipelineComponentId == pipelineComponentId);
}
public static Model.HJGL_Pipeline_Component GetPipelineComponentByCodeandpipelineId(string pipelineComponentCode, string pipelineId)
{
var q = Funs.DB.HJGL_Pipeline_Component.FirstOrDefault(x => x.PipelineComponentCode == pipelineComponentCode && x.PipelineId == pipelineId);
return q;
}
/// <summary>
/// 根据材料信息id获取组件信息
/// </summary>
/// <param name="pipeLineMatId"></param>
/// <returns></returns>
public static Model.HJGL_Pipeline_Component GetPipelineComponentByMatId(string pipeLineMatId)
{
return Funs.DB.HJGL_Pipeline_Component.FirstOrDefault(e => e.PipeLineMatId == pipeLineMatId);
}
2023-11-08 17:26:59 +08:00
/// <summary>
/// 获取打印实体
/// </summary>
/// <param name="PipelineComponentId"></param>
/// <param name="PipelineId"></param>
/// <param name="IsCheckPrint"></param>
/// <returns></returns>
public static IEnumerable<PipelineComponentPrintDto> GetPrintModelByPipelineComponentIds(
string[] PipelineComponentId, string[] PipelineId, bool IsCheckPrint)
{
var db = Funs.DB;
var query =
from com in db.HJGL_Pipeline_Component
join mat in db.HJGL_PipeLineMat on com.PipeLineMatId equals mat.PipeLineMatId into matJoin
from mat in matJoin.DefaultIfEmpty()
join pipe in db.HJGL_Pipeline on com.PipelineId equals pipe.PipelineId into pipeJoin
from pipe in pipeJoin.DefaultIfEmpty()
join punit in db.Base_Unit on com.PreUnit equals punit.UnitId into punitJoin
from punit in punitJoin.DefaultIfEmpty()
join aunit in db.Base_Unit on com.AssembleUnit equals aunit.UnitId into aunitJoin
from aunit in aunitJoin.DefaultIfEmpty()
join unitwork in db.WBS_UnitWork on pipe.UnitWorkId equals unitwork.UnitWorkId into unitworkJoin
from unitwork in unitworkJoin.DefaultIfEmpty()
join mater in db.Base_Material on pipe.MaterialId equals mater.MaterialId into materJoin
from mater in materJoin.DefaultIfEmpty()
where com.QRCode != ""
orderby com.PipelineComponentCode,com.PipelineId
select new PipelineComponentPrintDto
{
PipelineComponentId = com.PipelineComponentId,
PipelineComponentCode = com.PipelineComponentCode,
BoxNumber = com.BoxNumber,
UnitWorkName = unitwork.UnitWorkName,
PipelineId = com.PipelineId,
PreUnit = punit.UnitName,
AssembleUnit = aunit.UnitName,
PrefabricatedComponents = mat.PrefabricatedComponents,
QRCode = com.QRCode,
State = com.State,
PlanStartDate = string.Format("yyyy-MM-dd", pipe.PlanStartDate),
PipelineCode = pipe.PipelineCode,
FlowingSection = pipe.FlowingSection,
QRCode2 = "PrePipeline$" + com.PipelineComponentId,
MaterialCode = mater.MaterialCode,
IsPrint = com.IsPrint
};
var result = query.ToList();
if (PipelineComponentId!=null &&PipelineComponentId.Length > 0)
{
result = result.Where(x => PipelineComponentId.Contains(x.PipelineComponentId.ToString())).ToList();
}
if (PipelineId != null && PipelineId.Length > 0)
{
result = result.Where(x => PipelineId.Contains(x.PipelineId.ToString())).ToList();
}
2023-11-30 11:03:07 +08:00
//if (IsCheckPrint != null & IsCheckPrint ==true)
//{
// result = result.Where(x => x.IsPrint==false||x.IsPrint==null).ToList();
//}
2023-11-08 17:26:59 +08:00
return result;
}
2022-09-05 16:36:31 +08:00
/// <summary>
/// 判断管线组件Code是否存在
/// </summary>
/// <param name="pipelineComponentCode"></param>
/// <param name="pipelineComponentId"></param>
/// <returns></returns>
public static bool IsExistPipelineComponentCode(string pipelineComponentCode, string pipelineId, string pipelineComponentId)
{
Model.SGGLDB db = Funs.DB;
Model.HJGL_Pipeline_Component q = null;
if (!string.IsNullOrEmpty(pipelineComponentId))
{
q = Funs.DB.HJGL_Pipeline_Component.FirstOrDefault(x => x.PipelineComponentCode == pipelineComponentCode && x.PipelineId == pipelineId && x.PipelineComponentId != pipelineComponentId);
}
else
{
q = Funs.DB.HJGL_Pipeline_Component.FirstOrDefault(x => x.PipelineComponentCode == pipelineComponentCode && x.PipelineId == pipelineId);
}
if (q != null)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 根据管线材料id同步组件
/// </summary>
public static void SyncPipelineComponentByMatId(string pipeLineMatId)
{
var model_mat = BLL.PipelineMatService.GetPipeLineMat(pipeLineMatId);
var PipelineId = model_mat.PipelineId;
var PipeArea = BLL.PipelineService.GetPipelineByPipelineId(PipelineId).PipeArea;
if (PipeArea=="1")
{
// var model = GetPipelineComponentByMatId(pipeLineMatId);
var model = GetPipelineComponentByCodeandpipelineId(model_mat.PrefabricatedComponents,PipelineId);
if (model!=null)
{
model.PipelineId = PipelineId;
model.PipelineComponentCode = model_mat.PrefabricatedComponents;
model.DrawingName = model_mat.PrefabricatedComponents.Substring(0, model_mat.PrefabricatedComponents.LastIndexOf('-')).Replace("\"", "");
2024-11-06 09:59:54 +08:00
model.State = State0;
2023-02-20 10:49:51 +08:00
model.ProductionState = 0;
2022-09-05 16:36:31 +08:00
UpdatePipelineComponent(model);
}
else
{
model=new Model.HJGL_Pipeline_Component();
model.PipelineComponentId = SQLHelper.GetNewID();
model.PipelineId = PipelineId;
model.PipelineComponentCode = model_mat.PrefabricatedComponents;
2024-09-27 18:17:21 +08:00
model.DrawingName = model_mat.PrefabricatedComponents?.Substring(0, model_mat.PrefabricatedComponents.LastIndexOf('-')).Replace("\"", "");
2024-11-06 09:59:54 +08:00
model.State = State0;
2023-02-20 10:49:51 +08:00
model.ProductionState = 0;
2023-11-08 17:26:59 +08:00
model.IsPrint = false;
2022-09-05 16:36:31 +08:00
AddPipelineComponent(model);
}
}
}
/// <summary>
/// 添加作业管线
/// </summary>
/// <param name="pipeline"></param>
public static void AddPipelineComponent(Model.HJGL_Pipeline_Component pipeline)
{
Model.SGGLDB db = Funs.DB;
Model.HJGL_Pipeline_Component newPipeline = new Model.HJGL_Pipeline_Component();
2023-11-09 17:22:24 +08:00
pipeline.IsPrint = false;
2022-09-05 16:36:31 +08:00
newPipeline.PipelineComponentId = pipeline.PipelineComponentId;
newPipeline.PipelineId = pipeline.PipelineId;
newPipeline.PreUnit = pipeline.PreUnit;
newPipeline.PipelineComponentCode = pipeline.PipelineComponentCode;
newPipeline.BoxNumber = pipeline.BoxNumber;
newPipeline.AssembleUnit = pipeline.AssembleUnit;
newPipeline.PipeLineMatId = pipeline.PipeLineMatId;
newPipeline.State= pipeline.State;
newPipeline.QRCode= pipeline.QRCode;
newPipeline.PlanStartDate = pipeline.PlanStartDate;
newPipeline.PlanEndDate = pipeline.PlanEndDate;
newPipeline.ActStartDate = pipeline.ActStartDate;
newPipeline.ActEndDate = pipeline.ActEndDate;
2022-09-23 22:29:48 +08:00
newPipeline.DrawingName = pipeline.DrawingName;
2022-10-15 15:40:49 +08:00
newPipeline.ReceiveMan= pipeline.ReceiveMan;
newPipeline.ReceiveDate= pipeline.ReceiveDate;
2023-02-20 10:49:51 +08:00
newPipeline.ProductionState= pipeline.ProductionState;
2023-11-08 17:26:59 +08:00
newPipeline.IsPrint= pipeline.IsPrint;
2024-11-06 09:36:10 +08:00
newPipeline.Remark = pipeline.Remark;
2022-09-05 16:36:31 +08:00
db.HJGL_Pipeline_Component.InsertOnSubmit(newPipeline);
db.SubmitChanges();
}
/// <summary>
/// 修改作业管线
/// </summary>
/// <param name="pipeline"></param>
public static void UpdatePipelineComponent(Model.HJGL_Pipeline_Component pipeline)
{
Model.SGGLDB db = Funs.DB;
Model.HJGL_Pipeline_Component newPipeline = db.HJGL_Pipeline_Component.FirstOrDefault(e => e.PipelineComponentId == pipeline.PipelineComponentId);
if (newPipeline != null)
{
newPipeline.PipelineId = pipeline.PipelineId;
newPipeline.PreUnit = pipeline.PreUnit;
newPipeline.PipelineComponentCode = pipeline.PipelineComponentCode;
newPipeline.BoxNumber = pipeline.BoxNumber;
newPipeline.AssembleUnit = pipeline.AssembleUnit;
newPipeline.PipeLineMatId = pipeline.PipeLineMatId;
newPipeline.State = pipeline.State;
newPipeline.QRCode = pipeline.QRCode;
newPipeline.PlanStartDate = pipeline.PlanStartDate;
newPipeline.PlanEndDate = pipeline.PlanEndDate;
newPipeline.ActStartDate = pipeline.ActStartDate;
newPipeline.ActEndDate = pipeline.ActEndDate;
2022-09-23 22:29:48 +08:00
newPipeline.DrawingName = pipeline.DrawingName;
2022-10-15 15:40:49 +08:00
newPipeline.ReceiveMan = pipeline.ReceiveMan;
newPipeline.ReceiveDate = pipeline.ReceiveDate;
2023-02-20 10:49:51 +08:00
newPipeline.ProductionState = pipeline.ProductionState;
2023-11-08 17:26:59 +08:00
newPipeline.IsPrint=pipeline.IsPrint;
2024-11-06 09:36:10 +08:00
newPipeline.Remark = pipeline.Remark;
2022-09-05 16:36:31 +08:00
db.SubmitChanges();
}
}
2023-11-08 17:26:59 +08:00
/// <summary>
/// 修改出库状态
/// </summary>
/// <param name="pipelineComponentId"></param>
/// <param name="BoxNumber"></param>
2022-10-15 15:40:49 +08:00
public static void UpdateOutState(string pipelineComponentId,string BoxNumber)
2022-09-05 16:36:31 +08:00
{
var q=GetPipelineComponentById(pipelineComponentId);
2024-11-06 09:59:54 +08:00
if (q.State==State1)
2022-09-05 16:36:31 +08:00
{
2024-11-06 09:59:54 +08:00
q.State = State2;
2022-10-15 15:40:49 +08:00
q.BoxNumber=BoxNumber;
2022-09-05 16:36:31 +08:00
UpdatePipelineComponent(q);
}
2023-02-20 10:49:51 +08:00
}
2023-11-08 17:26:59 +08:00
/// <summary>
/// 修改打印状态
/// </summary>
/// <param name="PipelineComponentId"></param>
public static void UpdateIsPrint(string[] PipelineComponentId)
{
var componentsToUpdate = Funs.DB.HJGL_Pipeline_Component
.Where(c => PipelineComponentId.Contains(c.PipelineComponentId));
foreach (var component in componentsToUpdate)
{
component.IsPrint = true;
}
Funs.DB.SubmitChanges();
}
2023-02-20 10:49:51 +08:00
/// <summary>
/// 修改生产状态
/// </summary>
/// <param name="pipelineComponentId"></param>
/// <param name="BoxNumber"></param>
public static void UpdateProductionState(string pipelineComponentId, int state, DateTime TaskDate)
{
var q = GetPipelineComponentById(pipelineComponentId);
if (q!=null)
{
q.ProductionState = state;
if (state==2)
{
q.ActEndDate = TaskDate;
}
else if(state==1)
{
if (q.ActStartDate ==null)
{
q.ActStartDate = TaskDate;
}
else
{
if (DateTime.Compare(TaskDate,q.ActStartDate.Value) < 0)
{
q.ActStartDate = TaskDate;
}
}
}
UpdatePipelineComponent(q);
}
2022-09-05 16:36:31 +08:00
}
/// <summary>
/// 根据作业管线Id删除一个作业管线信息
/// </summary>
/// <param name="pipelineId"></param>
public static void DeletePipelineComponent(string pipelineComponentId)
{
Model.SGGLDB db = Funs.DB;
Model.HJGL_Pipeline_Component pipeline = db.HJGL_Pipeline_Component.FirstOrDefault(e => e.PipelineComponentId == pipelineComponentId);
if (pipeline != null)
{
db.HJGL_Pipeline_Component.DeleteOnSubmit(pipeline);
db.SubmitChanges();
}
}
/// <summary>
/// 根据管线材料id删除对应组件
/// </summary>
/// <param name="pipeLineMatId"></param>
public static void DeletePipelineComponentByMatId(string pipeLineMatId)
{
Model.SGGLDB db = Funs.DB;
var mdoel = db.HJGL_Pipeline_Component.Where(e => e.PipeLineMatId == pipeLineMatId);
if (mdoel != null)
{
db.HJGL_Pipeline_Component.DeleteAllOnSubmit(mdoel);
db.SubmitChanges();
}
}
/// <summary>
/// 根据管线id删除组件
/// </summary>
/// <param name="pipelineId"></param>
public static void DeletePipelineComponentBypipelineId(string pipelineId)
{
Model.SGGLDB db = Funs.DB;
var mdoel = db.HJGL_Pipeline_Component.Where(e => e.PipelineId == pipelineId);
if (mdoel != null)
{
db.HJGL_Pipeline_Component.DeleteAllOnSubmit(mdoel);
db.SubmitChanges();
}
}
2023-09-11 11:40:38 +08:00
2022-09-05 16:36:31 +08:00
/// <summary>
/// 获取已经验收的预制组件
/// </summary>
2023-09-11 11:40:38 +08:00
/// <param name="projectId"></param>
/// <param name="pipelineCode"></param>
/// <param name="pipelineComponentCode"></param>
2022-09-05 16:36:31 +08:00
/// <returns></returns>
2023-09-11 11:40:38 +08:00
public static List<HJGL_Pipeline_Component> GetAcceptedPipelineComponent(string projectId, string pipelineCode,
string pipelineComponentCode,string flowingSection)
2022-09-05 16:36:31 +08:00
{
Model.SGGLDB db = Funs.DB;
var q = (from x in db.HJGL_Pipeline_Component
join y in db.HJGL_Pipeline on x.PipelineId equals y.PipelineId
2024-11-06 09:59:54 +08:00
where y.ProjectId.Contains(projectId) && x.State.Equals(State1) &&
2023-09-11 11:40:38 +08:00
(string.IsNullOrEmpty(pipelineCode) || y.PipelineCode.Contains(pipelineCode)) &&
(string.IsNullOrEmpty(pipelineComponentCode) || x.PipelineComponentCode.Contains(pipelineComponentCode)) &&
(string.IsNullOrEmpty(flowingSection) || y.FlowingSection.Contains(flowingSection))
2022-09-05 16:36:31 +08:00
select x).ToList();
return q;
2022-10-19 15:49:56 +08:00
}
public static List<Model.HJGL_Pipeline_Component> GetComponentByPipelineId(string PipelineId)
{
Model.SGGLDB db = Funs.DB;
var q = (from x in db.HJGL_Pipeline_Component
where x.PipelineId == PipelineId
select x).OrderBy(x=>x.PlanStartDate).ToList();
return q;
2022-09-05 16:36:31 +08:00
}
2023-09-11 11:40:38 +08:00
///// <summary>
///// 管线下拉框
///// </summary>
///// <param name="dropName">下拉框名字</param>
///// <param name="isShowPlease">是否显示请选择</param>
//public static void InitPipelineDownList(FineUIPro.DropDownList dropName,string projectid, string pipelineCode,
// string pipelineComponentCode, bool isShowPlease)
//{
// dropName.DataValueField = "PipelineComponentId";
// dropName.DataTextField = "PipelineComponentCode";
// dropName.DataSource = GetAcceptedPipelineComponent(projectid, pipelineCode, pipelineComponentCode);
// dropName.DataBind();
// if (isShowPlease)
// {
// Funs.FineUIPleaseSelect(dropName);
// }
//}
2022-09-23 22:29:48 +08:00
public static void InitMainItemDownList(FineUIPro.DropDownList dropName, bool isShowPlease)
{
dropName.DataValueField = "Value";
dropName.DataTextField = "Text";
dropName.DataSource = GetState();
dropName.DataBind();
if (isShowPlease)
{
Funs.FineUIPleaseSelect(dropName);
}
}
2023-02-20 10:49:51 +08:00
public static void InitMainItemDownProductionStateList(FineUIPro.DropDownList dropName, bool isShowPlease)
{
dropName.DataValueField = "Value";
dropName.DataTextField = "Text";
dropName.DataSource = GetProductionState();
dropName.DataBind();
if (isShowPlease)
{
Funs.FineUIPleaseSelect(dropName);
}
}
2022-09-05 16:36:31 +08:00
}
2023-11-08 17:26:59 +08:00
public class PipelineComponentPrintDto
{
public string PipelineComponentId { get; set; }
public string PipelineComponentCode { get; set; }
public string BoxNumber { get; set; }
public string UnitWorkName { get; set; }
public string PipelineId { get; set; }
public string PreUnit { get; set; }
public string AssembleUnit { get; set; }
public string PrefabricatedComponents { get; set; }
public string QRCode { get; set; }
public int? State { get; set; }
public string PlanStartDate { get; set; }
public string PipelineCode { get; set; }
public string FlowingSection { get; set; }
public string QRCode2 { get; set; }
public string MaterialCode { get; set; }
public bool? IsPrint { get; set; }
}
2022-09-05 16:36:31 +08:00
}