460 lines
21 KiB
C#
460 lines
21 KiB
C#
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.WebControls;
|
||
|
||
namespace BLL
|
||
{
|
||
public static class PipelineService
|
||
{
|
||
/// <summary>
|
||
/// 工厂预制
|
||
/// </summary>
|
||
public const string PipeArea_SHOP="1";
|
||
/// <summary>
|
||
/// 现场安装
|
||
/// </summary>
|
||
public const string PipeArea_FIELD = "2";
|
||
public static ListItem[] GetPipeArea()
|
||
{
|
||
ListItem[] list = new ListItem[2];
|
||
list[0] = new ListItem("工厂预制", PipeArea_SHOP);
|
||
list[1] = new ListItem("现场安装", PipeArea_FIELD);
|
||
return list;
|
||
}
|
||
|
||
/// <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);
|
||
}
|
||
public static Model.HJGL_Pipeline GetPipelineByPipelineCode(string pipelineCode)
|
||
{
|
||
return Funs.DB.HJGL_Pipeline.FirstOrDefault(e => e.PipelineCode == pipelineCode);
|
||
}
|
||
public static List<View_HJGL_Pipeline> GetView_HJGL_Pipelines(View_HJGL_Pipeline model)
|
||
{
|
||
var db = Funs.DB;
|
||
var pipelineList =( from x in 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>
|
||
/// 根据管线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>
|
||
/// 下载预制口管线导入模板
|
||
/// </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
|
||
,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();
|
||
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
|
||
,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
|
||
,unit.UnitWorkName
|
||
from HJGL_Pipeline line
|
||
left join WBS_UnitWork unit on line.UnitWorkId=unit.UnitWorkId
|
||
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();
|
||
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>
|
||
/// 添加作业管线
|
||
/// </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;
|
||
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;
|
||
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();
|
||
}
|
||
}
|
||
}
|
||
|
||
// 管线划分
|
||
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);
|
||
}
|
||
}
|
||
}
|
||
}
|