941 lines
44 KiB
C#
941 lines
44 KiB
C#
using Microsoft.Office.Interop.Word;
|
||
using MiniExcelLibs;
|
||
using Model;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Data.SqlClient;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Web.UI.DataVisualization.Charting;
|
||
using System.Web.UI.WebControls;
|
||
using System.Windows.Media.Animation;
|
||
using static BLL.PipelineService;
|
||
|
||
namespace BLL
|
||
{
|
||
public static class PipelineService
|
||
{
|
||
/// <summary>
|
||
/// 工厂预制
|
||
/// </summary>
|
||
public const string PipeArea_SHOP = "1";
|
||
/// <summary>
|
||
/// 现场施工
|
||
/// </summary>
|
||
public const string PipeArea_FIELD = "2";
|
||
|
||
public const int pageSize = 20;
|
||
public static List<Model.HJGL_Pipeline> hJGL_Pipelines
|
||
{
|
||
|
||
get;
|
||
set;
|
||
|
||
}
|
||
/// <summary>
|
||
/// 实际日期类型
|
||
/// </summary>
|
||
public enum ActDateType
|
||
{
|
||
/// <summary>
|
||
/// 实际开始日期(预制)
|
||
/// </summary>
|
||
ActDateStart_Shop,
|
||
/// <summary>
|
||
/// 实际完成日期(预制)
|
||
/// </summary>
|
||
ActDateEnd_Shop,
|
||
/// <summary>
|
||
/// 实际开始日期(安装)
|
||
/// </summary>
|
||
ActDateStart_FIELD,
|
||
/// <summary>
|
||
/// 实际完成日期(安装)
|
||
/// </summary>
|
||
ActDateEnd_FIELD,
|
||
}
|
||
/// <summary>
|
||
/// 管线划分
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public static ListItem[] GetPipeArea()
|
||
{
|
||
ListItem[] list = new ListItem[2];
|
||
list[0] = new ListItem("工厂预制", PipeArea_SHOP);
|
||
list[1] = new ListItem("现场施工", PipeArea_FIELD);
|
||
return list;
|
||
}
|
||
public static void RestPipelineAndJoints(string projectid)
|
||
{
|
||
PipelineService.hJGL_Pipelines = PipelineService.GetPipelinesByProjectId(projectid);
|
||
WeldJointService.hJGL_WeldJoints = WeldJointService.GetWeldJointByProjectid(projectid);
|
||
}
|
||
/// <summary>
|
||
/// 根据管线ID获取管线信息
|
||
/// </summary>
|
||
/// <param name="pipelineName"></param>
|
||
/// <returns></returns>
|
||
public static Model.HJGL_Pipeline GetPipelineByPipelineId(string pipelineId)
|
||
{
|
||
return Funs.DB.HJGL_Pipeline.FirstOrDefault(e => e.PipelineId == pipelineId);
|
||
}
|
||
/// <summary>
|
||
/// 根据管线id获取管线状态
|
||
/// </summary>
|
||
/// <param name="pipelineId"></param>
|
||
public static void GetStateByPipelineId(string pipelineId)
|
||
{
|
||
var mdoel = GetPipelineByPipelineId(pipelineId);
|
||
var PlanStartDate = mdoel.PlanStartDate;
|
||
var PlanEndDate = mdoel.PlanEndDate;
|
||
var ActStartDate = new DateTime?();
|
||
var ActEndDate = new DateTime?();
|
||
if (!string.IsNullOrEmpty(GetDateByPipelineId(pipelineId, ActDateType.ActDateStart_FIELD)))
|
||
{
|
||
ActStartDate = Convert.ToDateTime(GetDateByPipelineId(pipelineId, ActDateType.ActDateStart_FIELD));
|
||
}
|
||
if (!string.IsNullOrEmpty(GetDateByPipelineId(pipelineId, ActDateType.ActDateEnd_FIELD)))
|
||
{
|
||
ActEndDate = Convert.ToDateTime(GetDateByPipelineId(pipelineId, ActDateType.ActDateEnd_FIELD));
|
||
}
|
||
if (PlanStartDate == null || PlanEndDate == null)
|
||
{
|
||
mdoel.State = 0;
|
||
|
||
UpdatePipeline(mdoel);
|
||
return;
|
||
}
|
||
if (ActStartDate == null && DateTime.Compare(DateTime.Now, PlanStartDate.Value) < 0)
|
||
{
|
||
mdoel.State = 0;
|
||
}
|
||
else if (ActStartDate == null && DateTime.Compare(DateTime.Now, PlanStartDate.Value) > 0)
|
||
{
|
||
mdoel.State = 1;
|
||
}
|
||
else if (ActStartDate != null && DateTime.Compare(ActStartDate.Value, PlanStartDate.Value) < 0 && ActEndDate == null)
|
||
{
|
||
mdoel.State = 2;
|
||
}
|
||
else if (ActStartDate != null && DateTime.Compare(ActStartDate.Value, PlanStartDate.Value) > 0 && ActEndDate == null)
|
||
{
|
||
mdoel.State = 3;
|
||
}
|
||
else if (ActEndDate != null)
|
||
{
|
||
mdoel.State = 4;
|
||
}
|
||
UpdatePipeline(mdoel);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据管线id获取实际开始,实际完成日期
|
||
/// </summary>
|
||
/// <param name="pipelineId"></param>
|
||
/// <param name="actDateType"></param>
|
||
/// <returns></returns>
|
||
public static string GetDateByPipelineId(object pipelineId, ActDateType actDateType)
|
||
{
|
||
string result = "";
|
||
string _pipelineId = pipelineId.ToString();
|
||
string ActDateStart_Shop = "";
|
||
string ActDateEnd_Shop = "";
|
||
string ActDateStart_FIELD = "";
|
||
string ActDateEnd_FIELD = "";
|
||
|
||
var pipemodel = GetPipelineByPipelineId(_pipelineId);
|
||
var joints = BLL.WeldJointService.GetWeldJointsByPipelineId(_pipelineId);
|
||
int joint_Shop_count = joints.Where(x => x.JointAttribute == "预制口").Count();
|
||
int joint_Field_count = joints.Where(x => x.JointAttribute == "安装口").Count();
|
||
var TaskJoints = (from x in Funs.DB.View_HJGL_WeldingTask
|
||
where x.ProjectId == pipemodel.ProjectId && x.PipelineCode == pipemodel.PipelineCode && x.WeldingDailyId != null
|
||
select x).ToList();
|
||
var TaskJoints_Shop = TaskJoints.Where(x => x.JointAttribute == "预制口").ToList();
|
||
var TaskJoints_Field = TaskJoints.Where(x => x.JointAttribute == "安装口").ToList();
|
||
if (TaskJoints_Shop.Count > 0)
|
||
{
|
||
ActDateStart_Shop = TaskJoints_Shop.OrderBy(x => x.TaskDate).First().TaskDate.Value.ToShortDateString();
|
||
}
|
||
if (joint_Shop_count == TaskJoints_Shop.Count && joint_Shop_count > 0)
|
||
{
|
||
ActDateEnd_Shop = TaskJoints_Shop.OrderByDescending(x => x.TaskDate).First().TaskDate.Value.Date.ToShortDateString();
|
||
}
|
||
if (TaskJoints_Field.Count > 0)
|
||
{
|
||
ActDateStart_FIELD = TaskJoints_Field.OrderBy(x => x.TaskDate).First().TaskDate.Value.Date.ToShortDateString();
|
||
}
|
||
if (joint_Field_count == TaskJoints_Field.Count && joint_Field_count > 0)
|
||
{
|
||
ActDateEnd_FIELD = TaskJoints_Field.OrderByDescending(x => x.TaskDate).First().TaskDate.Value.Date.ToShortDateString();
|
||
}
|
||
switch (actDateType)
|
||
{
|
||
case ActDateType.ActDateStart_Shop:
|
||
result = ActDateStart_Shop;
|
||
break;
|
||
case ActDateType.ActDateEnd_Shop:
|
||
result = ActDateEnd_Shop;
|
||
break;
|
||
case ActDateType.ActDateStart_FIELD:
|
||
result = ActDateStart_FIELD;
|
||
break;
|
||
case ActDateType.ActDateEnd_FIELD:
|
||
result = ActDateEnd_FIELD;
|
||
break;
|
||
}
|
||
return result;
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据焊口更改管线和组件(预制)的实际开始日期和完成日期
|
||
/// </summary>
|
||
/// <param name="WeldJointId"></param>
|
||
public static void UpdataDateByWeldJointId(string WeldJointId)
|
||
{
|
||
|
||
DateTime? ActDateStart_FIELD = new DateTime();
|
||
DateTime? ActDateEnd_FIELD = new DateTime();
|
||
|
||
string JointAttribute = "";
|
||
|
||
var model_joint = BLL.WeldJointService.GetWeldJointByWeldJointId(WeldJointId);
|
||
if (model_joint != null)
|
||
{
|
||
JointAttribute = model_joint.JointAttribute;
|
||
var model_pipeline = GetPipelineByPipelineId(model_joint.PipelineId);
|
||
var joints = BLL.WeldJointService.GetWeldJointsByPipelineId(model_joint.PipelineId);
|
||
var TaskJoints = (from x in Funs.DB.View_HJGL_WeldingTask
|
||
where x.ProjectId == model_pipeline.ProjectId && x.PipelineCode == model_pipeline.PipelineCode && x.WeldingDailyId != null
|
||
select x).ToList();
|
||
switch (JointAttribute)
|
||
{
|
||
|
||
case "安装口":
|
||
int joint_Field_count = joints.Where(x => x.JointAttribute == "安装口").Count();
|
||
var TaskJoints_Field = TaskJoints.Where(x => x.JointAttribute == "安装口").ToList();
|
||
|
||
if (TaskJoints_Field.Count > 0)
|
||
{
|
||
model_pipeline.ActStartDate = TaskJoints_Field.OrderBy(x => x.TaskDate).First().TaskDate;
|
||
}
|
||
if (joint_Field_count == TaskJoints_Field.Count && joint_Field_count > 0)
|
||
{
|
||
model_pipeline.IsFinished = true;
|
||
model_pipeline.ActEndDate = TaskJoints_Field.OrderByDescending(x => x.TaskDate).First().TaskDate;
|
||
}
|
||
//model_pipeline.ActStartDate = ActDateStart_FIELD;
|
||
//model_pipeline.ActEndDate = ActDateEnd_FIELD;
|
||
UpdatePipeline(model_pipeline);
|
||
|
||
break;
|
||
}
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// 根据管线code获取管线信息
|
||
/// </summary>
|
||
/// <param name="pipelineCode"></param>
|
||
/// <returns></returns>
|
||
public static Model.HJGL_Pipeline GetPipelineByPipelineCode(string pipelineCode)
|
||
{
|
||
return Funs.DB.HJGL_Pipeline.FirstOrDefault(e => e.PipelineCode == pipelineCode);
|
||
}
|
||
/// <summary>
|
||
/// 根据管线信息筛选管线
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
/// <returns></returns>
|
||
public static List<HJGL_Pipeline> GetHJGL_PipelineList(HJGL_Pipeline model)
|
||
{
|
||
var db = Funs.DB;
|
||
var pipelineList = (from x in Funs.DB.HJGL_Pipeline
|
||
where
|
||
(string.IsNullOrEmpty(model.ProjectId) || x.ProjectId.Contains(model.ProjectId))
|
||
&& (string.IsNullOrEmpty(model.UnitWorkId) || x.UnitWorkId.Contains(model.UnitWorkId))
|
||
&& (string.IsNullOrEmpty(model.PipelineCode) || x.PipelineCode.Contains(model.PipelineCode))
|
||
&& (string.IsNullOrEmpty(model.SingleName) || x.SingleName.Contains(model.SingleName))
|
||
&& (string.IsNullOrEmpty(model.DesignPress) || x.DesignPress.Contains(model.DesignPress))
|
||
/* && (string.IsNullOrEmpty(model.MaterialCode) || x.MaterialCode.Contains(model.MaterialCode))*/
|
||
select x).ToList();
|
||
if (model.IsFinished != null)
|
||
{
|
||
if (model.IsFinished == true)
|
||
{
|
||
pipelineList = pipelineList.Where(x => x.IsFinished == true).ToList();
|
||
}
|
||
else
|
||
{
|
||
pipelineList = pipelineList.Where(x => x.IsFinished == false || x.IsFinished == null).ToList();
|
||
|
||
}
|
||
|
||
}
|
||
return pipelineList;
|
||
}
|
||
public static List<View_HJGL_Pipeline> GetView_HJGL_Pipelines(View_HJGL_Pipeline model)
|
||
{
|
||
var db = Funs.DB;
|
||
var pipelineList = (from x in Funs.DB.View_HJGL_Pipeline
|
||
where
|
||
(string.IsNullOrEmpty(model.ProjectId) || x.ProjectId.Contains(model.ProjectId))
|
||
&& (string.IsNullOrEmpty(model.UnitWorkId) || x.UnitWorkId.Contains(model.UnitWorkId))
|
||
&& (string.IsNullOrEmpty(model.PipelineCode) || x.PipelineCode.Contains(model.PipelineCode))
|
||
&& (string.IsNullOrEmpty(model.SingleName) || x.SingleName.Contains(model.SingleName))
|
||
&& (string.IsNullOrEmpty(model.DesignPress) || x.DesignPress.Contains(model.DesignPress))
|
||
/* && (string.IsNullOrEmpty(model.MaterialCode) || x.MaterialCode.Contains(model.MaterialCode))*/
|
||
select x).ToList();
|
||
if (model.IsFinished != null)
|
||
{
|
||
if (model.IsFinished == true)
|
||
{
|
||
pipelineList = pipelineList.Where(x => x.IsFinished == true).ToList();
|
||
}
|
||
else
|
||
{
|
||
pipelineList = pipelineList.Where(x => x.IsFinished == false || x.IsFinished == null).ToList();
|
||
|
||
}
|
||
|
||
}
|
||
return pipelineList;
|
||
}
|
||
/// <summary>
|
||
/// 根据unitworkId获取所有管线
|
||
/// </summary>
|
||
/// <param name="unitworkId"></param>
|
||
/// <returns></returns>
|
||
public static List<Model.HJGL_Pipeline> GetPipelinesByUnitWordId(string unitworkId)
|
||
{
|
||
|
||
var q = Funs.DB.HJGL_Pipeline.Where(e => e.UnitWorkId == unitworkId).ToList();
|
||
return q;
|
||
}
|
||
/// <summary>
|
||
/// 根据项目获取所有管线
|
||
/// </summary>
|
||
/// <param name="ProjectId"></param>
|
||
/// <returns></returns>
|
||
public static List<Model.HJGL_Pipeline> GetPipelinesByProjectId(string ProjectId)
|
||
{
|
||
|
||
var q = Funs.DB.HJGL_Pipeline.Where(e => e.ProjectId == ProjectId).ToList();
|
||
return q;
|
||
}
|
||
/// <summary>
|
||
/// 根据管线ID获取管线信息
|
||
/// </summary>
|
||
/// <param name="pipelineName"></param>
|
||
/// <returns></returns>
|
||
public static Model.View_HJGL_Pipeline GetViewPipelineByPipelineId(string pipelineId)
|
||
{
|
||
return Funs.DB.View_HJGL_Pipeline.FirstOrDefault(e => e.PipelineId == pipelineId);
|
||
}
|
||
/// <summary>
|
||
/// 根据主项id获取未完成管线
|
||
/// </summary>
|
||
/// <param name="unitworkId"></param>
|
||
/// <returns></returns>
|
||
public static List<string> GetNoComPipelinesByUnitWordId(string unitworkId)
|
||
{
|
||
var q = (from x in Funs.DB.View_HJGL_WeldJoint
|
||
where x.UnitWorkId == unitworkId
|
||
select new
|
||
{
|
||
PipelineId = x.PipelineId,
|
||
WeldingDate = x.WeldingDate,
|
||
PipelineCode = x.PipelineCode
|
||
}).Distinct();
|
||
if (q.Count() == 0)
|
||
{
|
||
return new List<string>();
|
||
}
|
||
var noCompipeline = from x in q
|
||
group x by x.PipelineId into g
|
||
select new
|
||
{
|
||
PipelineId = g.Key,
|
||
Count = (from x2 in g where x2.WeldingDate != null && x2.WeldingDate != "" select x2).Count(),
|
||
};
|
||
var NowComPipelineCode = (from x in q
|
||
join y in noCompipeline on x.PipelineId equals y.PipelineId
|
||
where y.Count == 0
|
||
select x.PipelineCode
|
||
).Distinct().ToList();
|
||
return NowComPipelineCode;
|
||
}
|
||
/// <summary>
|
||
/// 下载预制口管线导入模板
|
||
/// </summary>
|
||
/// <param name="projectid"></param>
|
||
/// <param name="unitworkid"></param>
|
||
public static void DownPipeArea_SHOPFile(string projectid, string unitworkid)
|
||
{
|
||
string templatePath = Funs.RootPath + @"File\Excel\DataOut\WeldingPlanDataOut_SHOP.xlsx";
|
||
string path = Funs.RootPath + @"File\Excel\DataOut\WeldingPlanDataOut_SHOP.xlsx";
|
||
path = path.Replace(".xlsx", string.Format("{0:yyyy-MM-dd-HH-mm}", DateTime.Now) + ".xlsx");
|
||
|
||
string strSql = @"select line.PipelineId+'&'+com.PipelineComponentId as ID
|
||
,line.PipelineId
|
||
,line.PipelineCode
|
||
,line.ProjectId
|
||
,line.UnitWorkId
|
||
,line.UnitId
|
||
,line.SingleNumber
|
||
,line.PipingClassId
|
||
,line.MediumId
|
||
,line.DetectionRateId
|
||
,line.DetectionType
|
||
,line.TestPressure
|
||
,line.TestMedium
|
||
,line.Remark
|
||
,line.PressurePipingClassId
|
||
,line.PipeLenth
|
||
,line.DesignPress
|
||
,line.DesignTemperature
|
||
,line.PCtype
|
||
,line.LeakPressure
|
||
,line.LeakMedium
|
||
,line.VacuumPressure
|
||
,line.PCMedium
|
||
,line.MaterialId
|
||
,line.SingleName
|
||
,line.PipeArea
|
||
,line.WBSId
|
||
,line.PlanStartDate
|
||
,line.PlanEndDate
|
||
,line.ActStartDate
|
||
,line.ActEndDate
|
||
,line.IsFinished
|
||
,line.FlowingSection
|
||
,com.PipelineComponentId
|
||
,com.PreUnit
|
||
,com.PipelineComponentCode
|
||
,com.BoxNumber
|
||
,com.AssembleUnit
|
||
,com.PipeLineMatId
|
||
,com.QRCode
|
||
,com.State
|
||
,com.PlanStartDate as PlanStartDate_SHOP
|
||
,com.PlanEndDate as PlanEndDate_SHOP
|
||
,com.ActStartDate as ActStartDate_SHOP
|
||
,com.ActEndDate as ActEndDate_SHOP
|
||
,unit.UnitWorkName
|
||
from HJGL_Pipeline line
|
||
left join HJGL_Pipeline_Component com on line.PipelineId=com.PipelineId
|
||
left join WBS_UnitWork unit on line.UnitWorkId=unit.UnitWorkId
|
||
WHERE line.ProjectId= @ProjectId and line.PipeArea='1' ";
|
||
List<SqlParameter> listStr = new List<SqlParameter>();
|
||
listStr.Add(new SqlParameter("@ProjectId", projectid));
|
||
if (!string.IsNullOrEmpty(unitworkid) && unitworkid != "2")
|
||
{
|
||
strSql += " AND line.UnitWorkId =@UnitWorkId";
|
||
listStr.Add(new SqlParameter("@UnitWorkId", unitworkid));
|
||
}
|
||
|
||
SqlParameter[] parameter = listStr.ToArray();
|
||
System.Data.DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
||
tb.TableName = "Data";
|
||
var value = new Dictionary<string, object>()
|
||
{
|
||
["Data"] = tb,
|
||
};
|
||
MiniExcel.SaveAsByTemplate(path, templatePath, value);
|
||
HJGL_DataImportService.DownFile(path.Replace(Funs.RootPath, ""), "焊接施工计划(预制).xlsx");
|
||
File.Delete(path);
|
||
}
|
||
/// <summary>
|
||
/// 下载安装口管线导入模板
|
||
/// </summary>
|
||
/// <param name="projectid"></param>
|
||
/// <param name="unitworkid"></param>
|
||
public static void DownPipeArea_FIELDFile(string projectid, string unitworkid)
|
||
{
|
||
string templatePath = Funs.RootPath + @"File\Excel\DataOut\WeldingPlanDataOut2.xlsx";
|
||
string path = Funs.RootPath + @"File\Excel\DataOut\WeldingPlanDataOut2.xlsx";
|
||
path = path.Replace(".xlsx", string.Format("{0:yyyy-MM-dd-HH-mm}", DateTime.Now) + ".xlsx");
|
||
|
||
string strSql = @"select line.PipelineId as ID
|
||
,line.PipelineId
|
||
,(select ISNULL(SUM(ISNULL(jot.Size,0)),0) FROM dbo.HJGL_WeldJoint jot WHERE jot.PipelineId=line.PipelineId) as TotalSize
|
||
,(case when line.PipeArea='1' then (select ISNULL(SUM(ISNULL(jot.Size,0)),0) FROM dbo.HJGL_WeldJoint jot WHERE jot.PipelineId=line.PipelineId and jot.JointAttribute='预制口')
|
||
else (select ISNULL(SUM(ISNULL(jot.Size,0)),0) FROM dbo.HJGL_WeldJoint jot WHERE jot.PipelineId=line.PipelineId) end) as TotalYZSize
|
||
,line.PipelineCode
|
||
,line.ProjectId
|
||
,mat.MaterialCode
|
||
,line.UnitWorkId
|
||
,line.UnitId
|
||
,line.SingleNumber
|
||
,line.PipingClassId
|
||
,line.MediumId
|
||
,line.DetectionRateId
|
||
,line.DetectionType
|
||
,line.TestPressure
|
||
,line.TestMedium
|
||
,line.Remark
|
||
,line.PressurePipingClassId
|
||
,line.PipeLenth
|
||
,line.DesignPress
|
||
,line.DesignTemperature
|
||
,line.PCtype
|
||
,line.LeakPressure
|
||
,line.LeakMedium
|
||
,line.VacuumPressure
|
||
,line.PCMedium
|
||
,line.MaterialId
|
||
,line.SingleName
|
||
,line.PipeArea
|
||
,line.WBSId
|
||
,line.PlanStartDate
|
||
,line.PlanEndDate
|
||
,line.ActStartDate
|
||
,line.ActEndDate
|
||
,line.IsFinished
|
||
,line.FlowingSection
|
||
,unit.UnitWorkName
|
||
from HJGL_Pipeline line
|
||
left join WBS_UnitWork unit on line.UnitWorkId=unit.UnitWorkId
|
||
LEFT JOIN dbo.Base_Material AS mat ON mat.MaterialId=line.MaterialId
|
||
WHERE line.ProjectId= @ProjectId ";
|
||
List<SqlParameter> listStr = new List<SqlParameter>();
|
||
listStr.Add(new SqlParameter("@ProjectId", projectid));
|
||
if (!string.IsNullOrEmpty(unitworkid) && unitworkid != "2")
|
||
{
|
||
strSql += " AND line.UnitWorkId =@UnitWorkId";
|
||
listStr.Add(new SqlParameter("@UnitWorkId", unitworkid));
|
||
}
|
||
|
||
SqlParameter[] parameter = listStr.ToArray();
|
||
System.Data.DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
||
tb.TableName = "Data";
|
||
var value = new Dictionary<string, object>()
|
||
{
|
||
["Data"] = tb,
|
||
};
|
||
MiniExcel.SaveAsByTemplate(path, templatePath, value);
|
||
HJGL_DataImportService.DownFile(path.Replace(Funs.RootPath, ""), "焊接施工计划(安装).xlsx");
|
||
File.Delete(path);
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据管线code查询管线是否存在
|
||
/// </summary>
|
||
/// <param name="isoNo"></param>
|
||
/// <returns></returns>
|
||
public static bool IsExistPipelineCode(string pipelineCode, string workAreaId, string PipelineId)
|
||
{
|
||
Model.SGGLDB db = Funs.DB;
|
||
Model.HJGL_Pipeline q = null;
|
||
if (!string.IsNullOrEmpty(PipelineId))
|
||
{
|
||
q = Funs.DB.HJGL_Pipeline.FirstOrDefault(x => x.PipelineCode == pipelineCode && x.UnitWorkId == workAreaId && x.PipelineId != PipelineId);
|
||
}
|
||
else
|
||
{
|
||
q = Funs.DB.HJGL_Pipeline.FirstOrDefault(x => x.PipelineCode == pipelineCode && x.UnitWorkId == workAreaId);
|
||
}
|
||
|
||
if (q != null)
|
||
{
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据管线code获取管线信息
|
||
/// </summary>
|
||
/// <param name="pipelineCode">管线号</param>
|
||
/// <param name="unitWorkId">主项id</param>
|
||
/// <returns></returns>
|
||
public static HJGL_Pipeline GetPipelineByCode(string pipelineCode, string unitWorkId)
|
||
{
|
||
Model.SGGLDB db = Funs.DB;
|
||
Model.HJGL_Pipeline q = null;
|
||
q = Funs.DB.HJGL_Pipeline.FirstOrDefault(x => x.PipelineCode == pipelineCode && x.UnitWorkId == unitWorkId);
|
||
return q;
|
||
}
|
||
/// <summary>
|
||
/// 添加管线信息
|
||
/// </summary>
|
||
/// <param name="pipeline"></param>
|
||
public static void AddPipeline(Model.HJGL_Pipeline pipeline)
|
||
{
|
||
Model.SGGLDB db = Funs.DB;
|
||
Model.HJGL_Pipeline newPipeline = new Model.HJGL_Pipeline();
|
||
newPipeline.PipelineId = pipeline.PipelineId;
|
||
newPipeline.ProjectId = pipeline.ProjectId;
|
||
//newPipeline.InstallationId = pipeline.InstallationId;
|
||
newPipeline.UnitId = pipeline.UnitId;
|
||
newPipeline.UnitWorkId = pipeline.UnitWorkId;
|
||
newPipeline.PipelineCode = pipeline.PipelineCode;
|
||
newPipeline.SingleName = pipeline.SingleName;
|
||
newPipeline.SingleNumber = pipeline.SingleNumber;
|
||
newPipeline.PipingClassId = pipeline.PipingClassId;
|
||
newPipeline.MediumId = pipeline.MediumId;
|
||
newPipeline.DetectionRateId = pipeline.DetectionRateId;
|
||
newPipeline.DetectionType = pipeline.DetectionType;
|
||
newPipeline.DesignPress = pipeline.DesignPress;
|
||
newPipeline.DesignTemperature = pipeline.DesignTemperature;
|
||
newPipeline.TestPressure = pipeline.TestPressure;
|
||
newPipeline.TestMedium = pipeline.TestMedium;
|
||
newPipeline.PipeLenth = pipeline.PipeLenth;
|
||
newPipeline.PressurePipingClassId = pipeline.PressurePipingClassId;
|
||
newPipeline.Remark = pipeline.Remark;
|
||
newPipeline.LeakPressure = pipeline.LeakPressure;
|
||
newPipeline.LeakMedium = pipeline.LeakMedium;
|
||
newPipeline.VacuumPressure = pipeline.VacuumPressure;
|
||
newPipeline.PCMedium = pipeline.PCMedium;
|
||
newPipeline.PCtype = pipeline.PCtype;
|
||
newPipeline.MaterialId = pipeline.MaterialId;
|
||
newPipeline.State = pipeline.State;
|
||
newPipeline.FlowingSection = pipeline.FlowingSection;
|
||
db.HJGL_Pipeline.InsertOnSubmit(newPipeline);
|
||
db.SubmitChanges();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 修改作业管线
|
||
/// </summary>
|
||
/// <param name="pipeline"></param>
|
||
public static void UpdatePipeline(Model.HJGL_Pipeline pipeline)
|
||
{
|
||
Model.SGGLDB db = Funs.DB;
|
||
Model.HJGL_Pipeline newPipeline = db.HJGL_Pipeline.FirstOrDefault(e => e.PipelineId == pipeline.PipelineId);
|
||
if (newPipeline != null)
|
||
{
|
||
//newPipeline.InstallationId = pipeline.InstallationId;
|
||
newPipeline.UnitId = pipeline.UnitId;
|
||
newPipeline.UnitWorkId = pipeline.UnitWorkId;
|
||
newPipeline.PipelineCode = pipeline.PipelineCode;
|
||
newPipeline.SingleName = pipeline.SingleName;
|
||
newPipeline.SingleNumber = pipeline.SingleNumber;
|
||
newPipeline.PipingClassId = pipeline.PipingClassId;
|
||
newPipeline.MediumId = pipeline.MediumId;
|
||
newPipeline.DetectionRateId = pipeline.DetectionRateId;
|
||
newPipeline.DetectionType = pipeline.DetectionType;
|
||
newPipeline.DesignPress = pipeline.DesignPress;
|
||
newPipeline.DesignTemperature = pipeline.DesignTemperature;
|
||
newPipeline.TestPressure = pipeline.TestPressure;
|
||
newPipeline.TestMedium = pipeline.TestMedium;
|
||
newPipeline.PipeLenth = pipeline.PipeLenth;
|
||
newPipeline.PressurePipingClassId = pipeline.PressurePipingClassId;
|
||
newPipeline.LeakPressure = pipeline.LeakPressure;
|
||
newPipeline.LeakMedium = pipeline.LeakMedium;
|
||
newPipeline.VacuumPressure = pipeline.VacuumPressure;
|
||
newPipeline.PCMedium = pipeline.PCMedium;
|
||
newPipeline.PCtype = pipeline.PCtype;
|
||
newPipeline.Remark = pipeline.Remark;
|
||
newPipeline.MaterialId = pipeline.MaterialId;
|
||
newPipeline.IsFinished = pipeline.IsFinished;
|
||
newPipeline.PlanStartDate = pipeline.PlanStartDate;
|
||
newPipeline.PlanEndDate = pipeline.PlanEndDate;
|
||
newPipeline.ActStartDate = pipeline.ActStartDate;
|
||
newPipeline.ActEndDate = pipeline.ActEndDate;
|
||
newPipeline.WBSId = pipeline.WBSId;
|
||
newPipeline.State = pipeline.State;
|
||
newPipeline.FlowingSection = pipeline.FlowingSection;
|
||
|
||
try
|
||
{
|
||
db.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
|
||
}
|
||
catch (System.Data.Linq.ChangeConflictException ex)
|
||
{
|
||
foreach (System.Data.Linq.ObjectChangeConflict occ in db.ChangeConflicts)
|
||
{
|
||
// 使用Linq缓存中实体对象的值,覆盖当前数据库中的值
|
||
occ.Resolve(System.Data.Linq.RefreshMode.KeepCurrentValues);
|
||
}
|
||
// 这个地方要注意,Catch方法中,我们前面只是指明了怎样来解决冲突,这个地方还需要再次提交更新,这样的话,值 //才会提交到数据库。
|
||
db.SubmitChanges();
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 修改管线划分
|
||
/// </summary>
|
||
/// <param name="pipelineId"></param>
|
||
/// <param name="pipelineArea"></param>
|
||
public static void UpdatePipelineArea(string pipelineId, string pipelineArea)
|
||
{
|
||
Model.SGGLDB db = Funs.DB;
|
||
Model.HJGL_Pipeline newPipeline = db.HJGL_Pipeline.FirstOrDefault(e => e.PipelineId == pipelineId);
|
||
if (newPipeline != null)
|
||
{
|
||
newPipeline.PipeArea = pipelineArea;
|
||
db.SubmitChanges();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新管线是否完成
|
||
/// </summary>
|
||
/// <param name="pipelineId"></param>
|
||
/// <param name="finishDate"></param>
|
||
/// <param name="isFinish"></param>
|
||
public static void UpdatePipelinePlan(string pipelineId, string wbsId, DateTime? planStartDate, DateTime? planEndDate, DateTime? actStartDate, DateTime? actEndDate, bool? isFinish)
|
||
{
|
||
Model.SGGLDB db = Funs.DB;
|
||
Model.HJGL_Pipeline newPipeline = db.HJGL_Pipeline.FirstOrDefault(e => e.PipelineId == pipelineId);
|
||
if (newPipeline != null)
|
||
{
|
||
newPipeline.IsFinished = isFinish;
|
||
newPipeline.PlanStartDate = planStartDate;
|
||
newPipeline.PlanEndDate = planEndDate;
|
||
newPipeline.ActStartDate = actStartDate;
|
||
newPipeline.ActEndDate = actEndDate;
|
||
newPipeline.WBSId = wbsId;
|
||
db.SubmitChanges();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据作业管线Id删除一个作业管线信息
|
||
/// </summary>
|
||
/// <param name="pipelineId"></param>
|
||
public static void DeletePipeline(string pipelineId)
|
||
{
|
||
Model.SGGLDB db = Funs.DB;
|
||
Model.HJGL_Pipeline pipeline = db.HJGL_Pipeline.FirstOrDefault(e => e.PipelineId == pipelineId);
|
||
//var jot = db.HJGL_Pipeline.Where(e => e.PipelineId == pipelineId);
|
||
if (pipeline != null)
|
||
{
|
||
//db.HJGL_Pipeline.DeleteAllOnSubmit(jot);
|
||
db.HJGL_Pipeline.DeleteOnSubmit(pipeline);
|
||
db.SubmitChanges();
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 根据unitworkId删除一个作业管线信息
|
||
/// </summary>
|
||
/// <param name="pipelineId"></param>
|
||
public static void DeletePipelineByUnitworkId(string unitworkId)
|
||
{
|
||
Model.SGGLDB db = Funs.DB;
|
||
var pipeline = db.HJGL_Pipeline.Where(e => e.UnitWorkId == unitworkId);
|
||
if (pipeline != null)
|
||
{
|
||
//db.HJGL_Pipeline.DeleteAllOnSubmit(jot);
|
||
db.HJGL_Pipeline.DeleteAllOnSubmit(pipeline);
|
||
db.SubmitChanges();
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 获取管线名称项
|
||
/// </summary>
|
||
/// <param name="projectId">项目Id</param>
|
||
/// <returns></returns>
|
||
public static ListItem[] GetPipelineList(string unitWorkId)
|
||
{
|
||
List<Model.HJGL_Pipeline> q = (from x in Funs.DB.HJGL_Pipeline where x.UnitWorkId == unitWorkId orderby x.PipelineCode select x).ToList();
|
||
ListItem[] item = new ListItem[q.Count()];
|
||
for (int i = 0; i < q.Count(); i++)
|
||
{
|
||
item[i] = new ListItem(q[i].PipelineCode, q[i].PipelineId.ToString());
|
||
}
|
||
return item;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 管线下拉框
|
||
/// </summary>
|
||
/// <param name="dropName">下拉框名字</param>
|
||
/// <param name="isShowPlease">是否显示请选择</param>
|
||
public static void InitPipelineDownList(FineUIPro.DropDownList dropName, string unitWorkId, bool isShowPlease)
|
||
{
|
||
dropName.DataValueField = "Value";
|
||
dropName.DataTextField = "Text";
|
||
dropName.DataSource = GetPipelineList(unitWorkId);
|
||
dropName.DataBind();
|
||
if (isShowPlease)
|
||
{
|
||
Funs.FineUIPleaseSelect(dropName);
|
||
}
|
||
}
|
||
|
||
public static void BindTreeNodes(FineUIPro.TreeNode node, string pipecode, string ProjectId, int pageSize)
|
||
{
|
||
var pipeline = (from x in Funs.DB.HJGL_Pipeline
|
||
where x.ProjectId == ProjectId && x.UnitWorkId == node.NodeID
|
||
&& x.PipelineCode.Contains(pipecode)
|
||
orderby x.PipelineCode
|
||
select x).ToList();
|
||
var hJGL_WeldJoints = (from x in Funs.DB.HJGL_WeldJoint where x.ProjectId == ProjectId select x).ToList();
|
||
int pageindex = int.Parse(node.CommandName.Split('|')[0]);
|
||
int pageCount = int.Parse(node.CommandName.Split('|')[1]);
|
||
if (pageindex <= pageCount)
|
||
{
|
||
pipeline = pipeline.Skip(pageSize * (pageindex - 1)).Take(pageSize).ToList();
|
||
foreach (var item in pipeline)
|
||
{
|
||
var jotCount = (from x in hJGL_WeldJoints where x.PipelineId == item.PipelineId /*&& x.IsTwoJoint == null*/ select x).Count();
|
||
FineUIPro.TreeNode newNode = new FineUIPro.TreeNode();
|
||
newNode.Text = item.PipelineCode + "【" + jotCount.ToString() + " " + "焊口" + "】";
|
||
newNode.NodeID = item.PipelineId;
|
||
newNode.CommandName = "管线";
|
||
newNode.EnableClickEvent = true;
|
||
node.Nodes.Add(newNode);
|
||
}
|
||
if (pageindex < pageCount)
|
||
{
|
||
FineUIPro.TreeNode newNode = new FineUIPro.TreeNode();
|
||
newNode.Text = "加载";
|
||
newNode.NodeID = SQLHelper.GetNewID();
|
||
newNode.CommandName = "加载";
|
||
newNode.Icon = FineUIPro.Icon.ArrowDown;
|
||
newNode.EnableClickEvent = true;
|
||
node.Nodes.Add(newNode);
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 根据组件材料编码查询管线
|
||
/// </summary>
|
||
/// <param name="node"></param>
|
||
/// <param name="pipecode"></param>
|
||
/// <param name="MaterialCode"></param>
|
||
/// <param name="ProjectId"></param>
|
||
/// <param name="pageSize"></param>
|
||
public static void BindTreeNodes(FineUIPro.TreeNode node, string pipecode, string MaterialCode, string ProjectId, int pageSize)
|
||
{
|
||
//var pipeline = (from x in Funs.DB.HJGL_Pipeline
|
||
// where x.ProjectId == ProjectId && x.UnitWorkId == node.NodeID
|
||
// && x.PipelineCode.Contains(pipecode)
|
||
// orderby x.PipelineCode
|
||
// select x).ToList();
|
||
var pipeline = (from x in Funs.DB.HJGL_Pipeline
|
||
join y in Funs.DB.HJGL_PipeLineMat.Where(m => m.MaterialCode.Contains(MaterialCode)) on x.PipelineId equals y.PipelineId
|
||
where x.ProjectId == ProjectId && x.UnitWorkId == node.NodeID && x.PipelineCode.Contains(pipecode)
|
||
select x).Distinct().ToList();
|
||
var hJGL_WeldJoints = (from x in Funs.DB.HJGL_WeldJoint where x.ProjectId == ProjectId select x).ToList();
|
||
int pageindex = int.Parse(node.CommandName.Split('|')[0]);
|
||
int pageCount = int.Parse(node.CommandName.Split('|')[1]);
|
||
if (pageindex <= pageCount)
|
||
{
|
||
pipeline = pipeline.Skip(pageSize * (pageindex - 1)).Take(pageSize).ToList();
|
||
foreach (var item in pipeline)
|
||
{
|
||
var jotCount = (from x in hJGL_WeldJoints where x.PipelineId == item.PipelineId /*&& x.IsTwoJoint == null*/ select x).Count();
|
||
FineUIPro.TreeNode newNode = new FineUIPro.TreeNode();
|
||
newNode.Text = item.PipelineCode + "【" + jotCount.ToString() + " " + "焊口" + "】";
|
||
newNode.NodeID = item.PipelineId;
|
||
newNode.CommandName = "管线";
|
||
newNode.EnableClickEvent = true;
|
||
node.Nodes.Add(newNode);
|
||
}
|
||
if (pageindex < pageCount)
|
||
{
|
||
FineUIPro.TreeNode newNode = new FineUIPro.TreeNode();
|
||
newNode.Text = "加载";
|
||
newNode.NodeID = SQLHelper.GetNewID();
|
||
newNode.CommandName = "加载";
|
||
newNode.Icon = FineUIPro.Icon.ArrowDown;
|
||
newNode.EnableClickEvent = true;
|
||
node.Nodes.Add(newNode);
|
||
}
|
||
}
|
||
}
|
||
public static void BindTreeNodes(FineUIPro.TreeNode node, bool isExitWPQId, string pipecode, string ProjectId, int pageSize, string pipeArea)
|
||
{
|
||
string pipeAreasql = string.Empty;
|
||
if (pipeArea != BLL.Const._Null)
|
||
{
|
||
pipeAreasql += " AND PipeArea='" + pipeArea + "'";
|
||
}
|
||
if (isExitWPQId)
|
||
{
|
||
string strSql = "SELECT distinct PipelineId, PipelineCode FROM View_HJGL_WeldJoint WHERE IsTwoJoint IS NULL AND UnitWorkId =@UnitWorkId AND WPQId IS NULL" + pipeAreasql;
|
||
List<SqlParameter> listStr = new List<SqlParameter>();
|
||
listStr.Add(new SqlParameter("@UnitWorkId", node.NodeID));
|
||
if (!string.IsNullOrEmpty(pipecode))
|
||
{
|
||
strSql += " and PipelineCode=@PipelineCode ";
|
||
listStr.Add(new SqlParameter("@PipelineCode", "" + pipecode + ""));
|
||
|
||
}
|
||
strSql += " order by PipelineCode";
|
||
SqlParameter[] parameter = listStr.ToArray();
|
||
System.Data.DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter);
|
||
var pipeline = Funs.TableToEntity<Model.PipeLineIdCodeItem>(dt);
|
||
|
||
var hJGL_WeldJoints = (from x in Funs.DB.HJGL_WeldJoint where x.ProjectId == ProjectId select x).ToList();
|
||
int pageindex = int.Parse(node.CommandName.Split('|')[0]);
|
||
int pageCount = int.Parse(node.CommandName.Split('|')[1]);
|
||
|
||
if (pageindex <= pageCount)
|
||
{
|
||
pipeline = pipeline.Skip(pageSize * (pageindex - 1)).Take(pageSize).ToList();
|
||
foreach (var item in pipeline)
|
||
{
|
||
var jotCount = (from x in hJGL_WeldJoints where x.PipelineId == item.PipelineId /*&& x.IsTwoJoint == null*/ select x).Count();
|
||
FineUIPro.TreeNode newNode = new FineUIPro.TreeNode();
|
||
newNode.Text = item.PipelineCode + "【" + jotCount.ToString() + " " + "焊口" + "】";
|
||
newNode.NodeID = item.PipelineId;
|
||
newNode.CommandName = "管线";
|
||
newNode.EnableClickEvent = true;
|
||
node.Nodes.Add(newNode);
|
||
}
|
||
if (pageindex < pageCount)
|
||
{
|
||
FineUIPro.TreeNode newNode = new FineUIPro.TreeNode();
|
||
newNode.Text = "加载";
|
||
newNode.NodeID = SQLHelper.GetNewID();
|
||
newNode.CommandName = "加载";
|
||
newNode.Icon = FineUIPro.Icon.ArrowDown;
|
||
newNode.EnableClickEvent = true;
|
||
node.Nodes.Add(newNode);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
var pipeline = (from x in Funs.DB.HJGL_Pipeline
|
||
where x.ProjectId == ProjectId && x.UnitWorkId == node.NodeID
|
||
&& x.PipelineCode.Contains(pipecode)
|
||
orderby x.PipelineCode
|
||
select x).ToList();
|
||
if (pipeArea != BLL.Const._Null)
|
||
{
|
||
pipeline = pipeline.Where(x => x.PipeArea == pipeArea).ToList();
|
||
}
|
||
var hJGL_WeldJoints = (from x in Funs.DB.HJGL_WeldJoint where x.ProjectId == ProjectId select x).ToList();
|
||
int pageindex = int.Parse(node.CommandName.Split('|')[0]);
|
||
int pageCount = int.Parse(node.CommandName.Split('|')[1]);
|
||
if (pageindex <= pageCount)
|
||
{
|
||
pipeline = pipeline.Skip(pageSize * (pageindex - 1)).Take(pageSize).ToList();
|
||
foreach (var item in pipeline)
|
||
{
|
||
var jotCount = (from x in hJGL_WeldJoints where x.PipelineId == item.PipelineId /*&& x.IsTwoJoint == null*/ select x).Count();
|
||
FineUIPro.TreeNode newNode = new FineUIPro.TreeNode();
|
||
newNode.Text = item.PipelineCode + "【" + jotCount.ToString() + " " + "焊口" + "】";
|
||
newNode.NodeID = item.PipelineId;
|
||
newNode.CommandName = "管线";
|
||
newNode.EnableClickEvent = true;
|
||
node.Nodes.Add(newNode);
|
||
}
|
||
if (pageindex < pageCount)
|
||
{
|
||
FineUIPro.TreeNode newNode = new FineUIPro.TreeNode();
|
||
newNode.Text = "加载";
|
||
newNode.NodeID = SQLHelper.GetNewID();
|
||
newNode.CommandName = "加载";
|
||
newNode.Icon = FineUIPro.Icon.ArrowDown;
|
||
newNode.EnableClickEvent = true;
|
||
node.Nodes.Add(newNode);
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|