This commit is contained in:
2024-09-27 18:17:21 +08:00
parent be070f85e2
commit 064a849b97
73 changed files with 3248 additions and 589 deletions
@@ -1,4 +1,5 @@
using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
@@ -10,7 +11,9 @@ namespace FineUIPro.Web.HJGL.WeldingManage
public partial class WeldMatMatch : PageBase
{
public int pageSize = PipelineService.pageSize;
//public Dictionary<string, string> dicSeclectPipeLine = new Dictionary<string, string>();
public static List<Model.Tw_PipeMatMatchOutput> tw_PipeMatMatchOutputs ;
public static decimal Rate = 0;
public string PipeArea
{
get
@@ -33,15 +36,27 @@ namespace FineUIPro.Web.HJGL.WeldingManage
ViewState["Line_No"] = value;
}
}
public Dictionary<string, string> dicSeclectPipeLine
{
get
{
return (Dictionary<string, string>)ViewState["dicSeclectPipeLine"];
}
set
{
ViewState["dicSeclectPipeLine"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
//ctlAuditFlow.Url = BLL.Project_SysSetService.GetAvevaNetUrl(this.CurrUser.LoginProjectId);
if (!IsPostBack)
{
tw_PipeMatMatchOutputs=new List<Model.Tw_PipeMatMatchOutput>();
PipeArea = Request.Params["PipeArea"];
HJGL_MaterialService.materialStockItems_FIELD = new List<Model.MaterialStockItem>();
HJGL_MaterialService.materialStockItems_SHOP = new List<Model.MaterialStockItem>();
dicSeclectPipeLine=new Dictionary<string, string>();
this.InitTreeMenu();//加载树
}
}
@@ -161,9 +176,10 @@ namespace FineUIPro.Web.HJGL.WeldingManage
}
var pipeline = (from x in Funs.DB.HJGL_Pipeline
where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == node.NodeID
&& x.PipelineCode.Contains(this.txtPipelineCode.Text.Trim())
&& x.PipelineCode.Contains(this.txtPipelineCode.Text.Trim())
orderby x.PipelineCode
select x).ToList();
pipeline= pipeline.Where(x => NowComPipelineCode.Contains(x.PipelineCode)).ToList();
int pageindex = int.Parse(node.CommandName.Split('|')[0]);
int pageCount = int.Parse(node.CommandName.Split('|')[1]);
if (pageindex <= pageCount)
@@ -171,10 +187,10 @@ namespace FineUIPro.Web.HJGL.WeldingManage
pipeline = pipeline.Skip(pageSize * (pageindex - 1)).Take(pageSize).ToList();
foreach (var item in pipeline)
{
if (!NowComPipelineCode.Contains(item.PipelineCode))
/*if (!NowComPipelineCode.Contains(item.PipelineCode))
{
continue;
}
}*/
TreeNode newNode = new TreeNode();
newNode.Text = item.PipelineCode ;
newNode.NodeID = item.PipelineId;
@@ -229,13 +245,137 @@ namespace FineUIPro.Web.HJGL.WeldingManage
}
else
{
this.BindGrid();
// this.BindGrid();
}
}
#endregion
#region
private void BindGrid()
{
string strSql = @"SELECT lib.MaterialCode,lib.MaterialName,lib.MaterialUnit,
lib.MaterialSpec,lib.MaterialMade,lib.MaterialDef,sum(pipe.Number)as Number ,
'0' as MatchNum,'否' AS CheckState
FROM dbo.HJGL_PipeLineMat pipe
LEFT JOIN dbo.HJGL_MaterialCodeLib lib ON lib.MaterialCode = pipe.MaterialCode
WHERE PipelineId=@PipelineId
group by lib.MaterialCode,lib.MaterialName,lib.MaterialUnit,
lib.MaterialSpec,lib.MaterialMade,lib.MaterialDef ";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@PipelineId", this.tvControlItem.SelectedNodeID));
SqlParameter[] parameter = listStr.ToArray();
DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
Grid1.DataSource = dt;
Grid1.DataBind();
}
void BindGrid2()
{
var result = tw_PipeMatMatchOutputs
.GroupBy(item => new { item.PipelineId, item.PipelineCode }) // 按 PipelineId 和 PipelineCode 分组
.Select(group => new
{
PipelineId = group.Key.PipelineId, // 当前组的 PipelineId
PipelineCode = group.Key.PipelineCode, // 当前组的 PipelineCode
AverageMatchRate = group.Average(item => item.MatchRate) // 计算平均 MatchRate
})
.ToList(); // 转换为 List
// 如果需要将结果转换为自定义类型,可以这样做
List<Tw_PipeMatMatchOutput> output = result.Select(r => new Tw_PipeMatMatchOutput
{
PipelineId = r.PipelineId,
PipelineCode = r.PipelineCode,
MatchRate = r.AverageMatchRate,
MatchRateString = Math.Round((decimal)r.AverageMatchRate * 100, 2).ToString() + "%"
}).ToList();
Grid2.DataSource = output;
Grid2.DataBind();
Rate = Math.Round((decimal)output.Average(item => item.MatchRate) * 100, 2);
lbRate.Text = "匹配率:" + Rate.ToString() + "%";
}
void BindGrid3()
{
Grid3.DataSource = dicSeclectPipeLine;
Grid3.DataBind();
}
#endregion
#region
protected void Grid1_RowDataBound(object sender, GridRowEventArgs e)
{
// DataRowView row = e.DataItem as DataRowView;
/* string code = Grid1.DataKeys[e.RowIndex][0].ToString();
var num= decimal.Parse(Grid1.DataKeys[e.RowIndex][1].ToString()) ;
bool istrue = HJGL_MaterialService.isInStockByMaterialCode(code,num,PipeArea, this.CurrUser.LoginProjectId);
if (istrue)
{
e.RowCssClass = "color1";
}*/
}
protected void Grid2_RowClick(object sender, GridRowClickEventArgs e)
{
var tb = tw_PipeMatMatchOutputs.Where(x => x.PipelineId == Grid2.SelectedRowID).ToList();
Grid1.DataSource = tb;
Grid1.DataBind();
}
protected void Grid1_RowClick(object sender, GridRowClickEventArgs e)
{
Model.Parameter3D parameter3D = new Model.Parameter3D();
Model.ColorModel colorModel = new Model.ColorModel();
colorModel = BLL.Project_SysSetService.GetColorModel(this.CurrUser.LoginProjectId);
parameter3D.ColorModel = colorModel;
parameter3D.ButtonType = "3";
if (this.tvControlItem.SelectedNode.CommandName == "单位工程")
{
parameter3D.ModelName = HJGL_DataImportService.Getlatest3DModelNameByUnitWorkId(tvControlItem.SelectedNodeID);
}
else if (this.tvControlItem.SelectedNode.CommandName == "管线")
{
var modelpipe = PipelineService.GetPipelineByPipelineId(tvControlItem.SelectedNodeID);
if (modelpipe != null && !string.IsNullOrEmpty(modelpipe.UnitWorkId))
{
bool istrue = BLL.HJGL_MaterialService.isInStockByPipeline(tvControlItem.SelectedNodeID, this.CurrUser.LoginProjectId);
if (istrue)
{
Line_No = "/" + modelpipe.PipelineCode;
}
// parameter3D.Line_No = Line_No;
parameter3D.ModelName = HJGL_DataImportService.Getlatest3DModelNameByUnitWorkId(modelpipe.UnitWorkId);
var pipecode = "/" + modelpipe.PipelineCode;
parameter3D.TagNum = pipecode;
}
}
//ctlAuditFlow.Url_item = BLL.Project_SysSetService.GetAvevaNetUrl_Item(this.CurrUser.LoginProjectId) + parameter3D.ModelName;
//ctlAuditFlow.data = parameter3D;
//ctlAuditFlow.BindData();
}
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortField = e.SortField;
BindGrid();
}
#endregion
#region
protected void btnNew_Click(object sender, EventArgs e)
{
}
protected void btnrefresh_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
@@ -276,20 +416,7 @@ namespace FineUIPro.Web.HJGL.WeldingManage
this.hdUnitWorkId.Text = this.tvControlItem.SelectedNode.ParentNode.NodeID;
this.BindGrid();
}
if (PipeArea == PipelineService.PipeArea_SHOP)
{
var list = BLL.HJGL_PipelineComponentService.GetComponentByPipelineId(pipeline.PipelineId);
if (list != null && list.Count() > 0)
{
lbPlanStartDate.Text = list.First().PlanStartDate.ToString();
}
}
else if (PipeArea == PipelineService.PipeArea_FIELD)
{
lbPlanStartDate.Text = pipeline.PlanStartDate.HasValue ? pipeline.PlanStartDate.Value.ToShortDateString() : "";
}
if (pipeline != null && !string.IsNullOrEmpty(pipeline.UnitWorkId))
{
bool istrue = BLL.HJGL_MaterialService.isInStockByPipeline(tvControlItem.SelectedNodeID, this.CurrUser.LoginProjectId);
@@ -311,103 +438,6 @@ namespace FineUIPro.Web.HJGL.WeldingManage
}
}
private void BindGrid()
{
string strSql = @"SELECT lib.MaterialCode,lib.MaterialName,lib.MaterialUnit,
lib.MaterialSpec,lib.MaterialMade,lib.MaterialDef,sum(pipe.Number)as Number ,
'0' as MatchNum,'否' AS CheckState
FROM dbo.HJGL_PipeLineMat pipe
LEFT JOIN dbo.HJGL_MaterialCodeLib lib ON lib.MaterialCode = pipe.MaterialCode
WHERE PipelineId=@PipelineId
group by lib.MaterialCode,lib.MaterialName,lib.MaterialUnit,
lib.MaterialSpec,lib.MaterialMade,lib.MaterialDef ";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@PipelineId", this.tvControlItem.SelectedNodeID));
SqlParameter[] parameter = listStr.ToArray();
DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
Grid1.DataSource = dt;
Grid1.DataBind();
}
protected void Grid1_RowDataBound(object sender, GridRowEventArgs e)
{
// DataRowView row = e.DataItem as DataRowView;
string code = Grid1.DataKeys[e.RowIndex][0].ToString();
var num= decimal.Parse(Grid1.DataKeys[e.RowIndex][1].ToString()) ;
bool istrue = HJGL_MaterialService.isInStockByMaterialCode(code,num,PipeArea, this.CurrUser.LoginProjectId);
if (istrue)
{
e.RowCssClass = "color1";
}
}
protected string ConvertGetStockNum(object MaterialCode)
{
return BLL.HJGL_MaterialService.GetStockNumByCode(MaterialCode.ToString(), this.CurrUser.LoginProjectId, PipeArea).ToString();
}
#endregion
#region
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortField = e.SortField;
BindGrid();
}
#endregion
/// <summary>
/// 匹配
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click(object sender, EventArgs e)
{
}
protected void Grid1_RowClick(object sender, GridRowClickEventArgs e)
{
Model.Parameter3D parameter3D = new Model.Parameter3D();
Model.ColorModel colorModel = new Model.ColorModel();
colorModel = BLL.Project_SysSetService.GetColorModel(this.CurrUser.LoginProjectId);
parameter3D.ColorModel = colorModel;
parameter3D.ButtonType = "3";
if (this.tvControlItem.SelectedNode.CommandName == "单位工程")
{
parameter3D.ModelName = HJGL_DataImportService.Getlatest3DModelNameByUnitWorkId(tvControlItem.SelectedNodeID);
}
else if (this.tvControlItem.SelectedNode.CommandName == "管线")
{
var modelpipe = PipelineService.GetPipelineByPipelineId(tvControlItem.SelectedNodeID);
if (modelpipe != null && !string.IsNullOrEmpty(modelpipe.UnitWorkId))
{
bool istrue = BLL.HJGL_MaterialService.isInStockByPipeline(tvControlItem.SelectedNodeID, this.CurrUser.LoginProjectId);
if (istrue)
{
Line_No ="/"+ modelpipe.PipelineCode;
}
// parameter3D.Line_No = Line_No;
parameter3D.ModelName = HJGL_DataImportService.Getlatest3DModelNameByUnitWorkId(modelpipe.UnitWorkId);
var pipecode = "/" + modelpipe.PipelineCode;
parameter3D.TagNum = pipecode;
}
}
//ctlAuditFlow.Url_item = BLL.Project_SysSetService.GetAvevaNetUrl_Item(this.CurrUser.LoginProjectId) + parameter3D.ModelName;
//ctlAuditFlow.data = parameter3D;
//ctlAuditFlow.BindData();
}
protected void btnStatisticsMat_Click(object sender, EventArgs e)
{
@@ -422,15 +452,167 @@ namespace FineUIPro.Web.HJGL.WeldingManage
}
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//protected void btnQuery_Click(object sender, EventArgs e)
//{
// this.BindGrid();
//}
protected void btnAddPipelineMatchMat_Click(object sender, EventArgs e)
{
if (this.tvControlItem.SelectedNode.CommandName == "管线")
{
if (dicSeclectPipeLine.Where(x => x.Key == this.tvControlItem.SelectedNodeID).Count() == 0)
{
dicSeclectPipeLine.Add(this.tvControlItem.SelectedNodeID, this.tvControlItem.SelectedNode.Text);
tw_PipeMatMatchOutputs = TwArrivalStatisticsService.GetPipeMatMatch(this.CurrUser.LoginProjectId, dicSeclectPipeLine.Keys.ToList(), "工厂预制");
BindGrid3();
BindGrid2();
}
}
}
protected void btnDeletePipelineMatchMat_Click(object sender, EventArgs e)
{
if (Grid3.SelectedRowID != "")
{
dicSeclectPipeLine.Remove(Grid3.SelectedRowID);
tw_PipeMatMatchOutputs = TwArrivalStatisticsService.GetPipeMatMatch(this.CurrUser.LoginProjectId, dicSeclectPipeLine.Keys.ToList(), "工厂预制");
BindGrid3();
BindGrid2();
}
}
protected void btnGenTask_Click(object sender, EventArgs e)
{
if (Rate<(decimal)0.8)
{
ShowNotify(" 匹配率小于80%,请重新匹配!", MessageBoxIcon.Warning);
return;
}
SaveTask();
Response.Redirect(Request.Url.ToString());
}
private void SaveTask()
{
var weldingRods = from x in Funs.DB.Base_Consumables where x.ConsumablesType == "2" select x;
var weldingWires = from x in Funs.DB.Base_Consumables where x.ConsumablesType == "1" select x;
var toDoMatterList = (from x in Funs.DB.View_HJGL_NoWeldJointFind
where dicSeclectPipeLine.Keys.ToList().Contains(x.PipelineId) && x.WeldingDailyId == null && x.WeldTaskId == null
select x).ToList();
var selectRowId = (from x in Funs.DB.View_HJGL_NoWeldJointFind
where dicSeclectPipeLine.Keys.ToList().Contains(x.PipelineId) && x.WeldingDailyId == null && x.WeldTaskId == null
select x).ToList();
foreach (var weldjoint in selectRowId)
{
string canWeldingRodName = string.Empty;
string canWeldingWireName = string.Empty;
Model.HJGL_WeldTask NewTask = new Model.HJGL_WeldTask();
NewTask.ProjectId = this.CurrUser.LoginProjectId;
NewTask.UnitWorkId = PipelineService.GetPipelineByPipelineId(weldjoint.PipelineId)?.UnitWorkId;
NewTask.UnitId = this.CurrUser.UnitId;
NewTask.TaskCode = BLL.WeldTaskService.GetTaskCodeByDate(this.CurrUser.LoginProjectId, DateTime.Now.Date.ToString("yyyy-MM-dd"), NewTask.UnitWorkId, this.CurrUser.UnitId);
NewTask.WeldTaskId = SQLHelper.GetNewID();
NewTask.WeldJointId = weldjoint.WeldJointId;
var oldWeldTask = BLL.WeldTaskService.GetWeldTaskByWeldJointId(NewTask.WeldJointId);
if (oldWeldTask != null)
{
ShowNotify("所选焊口已存在任务单,无法保存!", MessageBoxIcon.Warning);
return;
}
Model.HJGL_WeldJoint weldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(NewTask.WeldJointId);
if (weldJoint != null)
{
NewTask.WeldingRod = weldJoint.WeldingRod;
NewTask.WeldingWire = weldJoint.WeldingWire;
//获取可替代焊丝焊条
var mat = BLL.Base_MaterialService.GetMaterialByMaterialId(weldJoint.Material1Id);
string matClass = mat.MaterialClass;
var matRod = weldingRods.FirstOrDefault(x => x.ConsumablesId == weldJoint.WeldingRod);
if (matRod != null)
{
foreach (var item in weldingRods)
{
if (matClass == "Fe-1" || matClass == "Fe-3")
{
if (IsCoverClass(matRod.SteelType, item.SteelType))
{
canWeldingRodName = canWeldingRodName + item.ConsumablesName + ",";
}
}
else
{
if (matRod.SteelType == item.SteelType)
{
canWeldingRodName = canWeldingRodName + item.ConsumablesName + ",";
}
}
}
if (!string.IsNullOrEmpty(canWeldingRodName))
{
NewTask.CanWeldingRodName = canWeldingRodName.Substring(0, canWeldingRodName.Length - 1);
}
}
var matWire = weldingWires.FirstOrDefault(x => x.ConsumablesId == weldJoint.WeldingWire);
if (matWire != null)
{
foreach (var item in weldingWires)
{
if (matClass == "Fe-1" || matClass == "Fe-3")
{
if (IsCoverClass(matWire.SteelType, item.SteelType))
{
canWeldingWireName = canWeldingWireName + item.ConsumablesName + ",";
}
}
else
{
if (matWire.SteelType == item.SteelType)
{
canWeldingWireName = canWeldingWireName + item.ConsumablesName + ",";
}
}
}
if (!string.IsNullOrEmpty(canWeldingWireName))
{
NewTask.CanWeldingWireName = canWeldingWireName.Substring(0, canWeldingWireName.Length - 1);
}
}
}
NewTask.JointAttribute = weldJoint.JointAttribute;
NewTask.TaskDate = DateTime.Now.Date;
NewTask.Tabler = this.CurrUser.PersonId;
NewTask.TableDate = DateTime.Now;
weldJoint.WeldingMode = "手动";
BLL.WeldJointService.UpdateWeldJoint(weldJoint);
BLL.WeldTaskService.AddWeldTask(NewTask);
}
}
private bool IsCoverClass(string wpsClass, string matClass)
{
bool isCover = false;
int wpsSn = 0;
int matSn = 0;
if (wpsClass.Length > 2 && matClass.Length > 2)
{
string wpsPre = wpsClass.Substring(0, wpsClass.Length - 2);
string matPre = matClass.Substring(0, matClass.Length - 2);
string wps = wpsClass.Substring(wpsClass.Length - 1, 1);
wpsSn = Funs.GetNewInt(wps).HasValue ? Funs.GetNewInt(wps).Value : 0;
string mat = matClass.Substring(matClass.Length - 1, 1);
matSn = Funs.GetNewInt(mat).HasValue ? Funs.GetNewInt(mat).Value : 0;
if (wpsPre == matPre && matSn >= wpsSn)
{
return true;
}
}
return isCover;
}
#endregion
}
}