SGGL_SHJ/SGGL/FineUIPro.Web/HJGL/InfoQuery/JointQuery.aspx.cs

876 lines
36 KiB
C#
Raw Normal View History

2022-09-05 16:36:31 +08:00
using BLL;
2023-02-16 17:19:08 +08:00
using MiniExcelLibs;
2022-10-13 18:52:45 +08:00
using Model;
2022-09-05 16:36:31 +08:00
using System;
using System.Collections.Generic;
using System.Data;
2023-02-16 17:19:08 +08:00
using System.IO;
2022-09-05 16:36:31 +08:00
using System.Linq;
using System.Text;
using AspNet = System.Web.UI.WebControls;
using System.Web.Caching;
2022-09-05 16:36:31 +08:00
namespace FineUIPro.Web.HJGL.InfoQuery
{
public partial class JointQuery : PageBase
{
2023-02-14 19:59:12 +08:00
public int pageSize = 20;
2022-10-19 15:49:56 +08:00
public decimal JointComplete
{
get
{
return (decimal)ViewState["JointComplete"];
}
set
{
ViewState["JointComplete"] = value;
}
}
public decimal JointNoComplete
{
get
{
return (decimal)ViewState["JointNoComplete"];
}
set
{
ViewState["JointNoComplete"] = value;
}
}
public int JointPre
{
get
{
return (int)ViewState["JointPre"];
}
set
{
ViewState["JointPre"] = value;
}
}
public int JointNoPre
{
get
{
return (int)ViewState["JointNoPre"];
}
set
{
ViewState["JointNoPre"] = value;
}
}
2022-10-25 22:30:17 +08:00
public string Completed_weldedjunction
{
get
{
return (string)ViewState["Completed_weldedjunction"];
}
set
{
ViewState["Completed_weldedjunction"] = value;
}
}
public string Incomplete_weldjunction
{
get
{
return (string)ViewState["Incomplete_weldjunction"];
}
set
{
ViewState["Incomplete_weldjunction"] = value;
}
}
2023-02-21 17:03:38 +08:00
public static List<Model.View_HJGL_WeldJoint> View_HJGL_WeldJoint = new List<Model.View_HJGL_WeldJoint>();
// 缓存相关常量
private const string CACHE_KEY_PREFIX = "UnitWorkTree_";
private static readonly System.Web.Caching.Cache Cache = System.Web.HttpRuntime.Cache;
/// <summary>
/// 创建TreeNode的副本用于缓存
/// </summary>
/// <param name="sourceNode">源节点</param>
/// <returns>新节点</returns>
private TreeNode CloneTreeNode(TreeNode sourceNode)
{
if (sourceNode == null) return null;
TreeNode newNode = new TreeNode();
newNode.NodeID = sourceNode.NodeID;
newNode.Text = sourceNode.Text;
newNode.ToolTip = sourceNode.ToolTip;
newNode.CommandName = sourceNode.CommandName;
newNode.Selectable = sourceNode.Selectable;
newNode.EnableClickEvent = sourceNode.EnableClickEvent;
newNode.EnableExpandEvent = sourceNode.EnableExpandEvent;
newNode.Expanded = sourceNode.Expanded;
newNode.Icon = sourceNode.Icon;
// 递归复制子节点
if (sourceNode.Nodes != null && sourceNode.Nodes.Count > 0)
{
foreach (TreeNode childNode in sourceNode.Nodes)
{
TreeNode clonedChild = CloneTreeNode(childNode);
if (clonedChild != null)
{
newNode.Nodes.Add(clonedChild);
}
}
}
return newNode;
}
2022-09-05 16:36:31 +08:00
protected void Page_Load(object sender, EventArgs e)
{
ctlAuditFlow.Url = BLL.Project_SysSetService.GetAvevaNetUrl(this.CurrUser.LoginProjectId);
if (!IsPostBack)
{
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
this.InitTreeMenu_WithCache();//加载树
2022-10-19 15:49:56 +08:00
this.JointComplete = 0;
2023-11-26 17:43:05 +08:00
this.JointNoComplete = 0;
this.JointPre = 0;
2022-10-19 15:49:56 +08:00
this.JointNoPre = 0;
2022-09-05 16:36:31 +08:00
}
}
#region --
// 优化后的节点处理方法
private void ProcessUnitWorkNodes(List<Model.WBS_UnitWork> unitWorks, TreeNode parentNode,
Dictionary<string, int> pipelineCountDict,
Dictionary<string, string> unitDict)
{
foreach (var unitWork in unitWorks)
{
// 优化: 使用字典查找,避免数据库查询
int pipelineCount = pipelineCountDict.ContainsKey(unitWork.UnitWorkId) ? pipelineCountDict[unitWork.UnitWorkId] : 0;
string unitName = unitDict.ContainsKey(unitWork.UnitId) ? unitDict[unitWork.UnitId] : "未知单位";
TreeNode treeNode = new TreeNode();
treeNode.NodeID = unitWork.UnitWorkId;
treeNode.Text = unitWork.UnitWorkName + "【" + pipelineCount.ToString() + "】管线";
treeNode.ToolTip = "施工单位:" + unitName;
treeNode.CommandName = 1 + "|" + Funs.GetEndPageNumber(pipelineCount, pageSize);
treeNode.EnableClickEvent = true;
treeNode.EnableExpandEvent = true;
parentNode.Nodes.Add(treeNode);
if (pipelineCount > 0)
{
TreeNode newNode = new TreeNode();
newNode.Text = "加载管线...";
newNode.NodeID = "加载管线...";
treeNode.Nodes.Add(newNode);
}
}
}
/// <summary>
/// 带缓存的树加载方法
/// </summary>
private void InitTreeMenu_WithCache()
{
bool cacheHit = false;
string projectId = this.CurrUser.LoginProjectId;
string cacheKey = CACHE_KEY_PREFIX + projectId;
string searchTerm = this.tvPipeCode.Text.Trim();
// 如果有搜索条件,不使用缓存,直接执行优化查询
if (!string.IsNullOrEmpty(searchTerm))
{
InitTreeMenu_Optimized();
return;
}
// 检查缓存
if (Cache[cacheKey] != null)
{
var cachedData = Cache[cacheKey] as List<TreeNode>;
if (cachedData != null)
{
cacheHit = true;
this.tvControlItem.Nodes.Clear();
foreach (var node in cachedData)
{
this.tvControlItem.Nodes.Add(CloneTreeNode(node));
}
return;
}
}
// 执行优化的初始化逻辑
InitTreeMenu_Optimized();
// 缓存结果
var nodesToCache = new List<TreeNode>();
foreach (TreeNode node in this.tvControlItem.Nodes)
{
nodesToCache.Add(CloneTreeNode(node));
}
Cache.Insert(cacheKey, nodesToCache, null, DateTime.Now.AddMinutes(30), TimeSpan.Zero);
}
/// <summary>
/// 清理项目相关的缓存
/// </summary>
private void ClearProjectCache()
{
string projectId = this.CurrUser.LoginProjectId;
string cacheKey = CACHE_KEY_PREFIX + projectId;
if (Cache[cacheKey] != null)
{
Cache.Remove(cacheKey);
}
}
2022-09-05 16:36:31 +08:00
/// <summary>
/// 优化版本的树加载方法
2022-09-05 16:36:31 +08:00
/// </summary>
private void InitTreeMenu_Optimized()
2022-09-05 16:36:31 +08:00
{
this.tvControlItem.Nodes.Clear();
TreeNode rootNode1 = new TreeNode();
rootNode1.NodeID = "1";
rootNode1.Text = "建筑工程";
rootNode1.CommandName = "建筑工程";
rootNode1.Selectable = false;
this.tvControlItem.Nodes.Add(rootNode1);
TreeNode rootNode2 = new TreeNode();
rootNode2.NodeID = "2";
rootNode2.Text = "安装工程";
rootNode2.CommandName = "安装工程";
rootNode2.Expanded = true;
this.tvControlItem.Nodes.Add(rootNode2);
string projectId = this.CurrUser.LoginProjectId;
string searchTerm = this.tvPipeCode.Text.Trim();
2022-09-05 16:36:31 +08:00
// 优化1: 使用单次查询获取所需数据,减少数据库往返次数
2022-09-05 16:36:31 +08:00
var unitWorkList = (from x in Funs.DB.WBS_UnitWork
where x.ProjectId == projectId
&& x.SuperUnitWork == null
&& x.UnitId != null
&& x.ProjectType != null
2022-09-05 16:36:31 +08:00
select x).ToList();
// 优化2: 批量获取所有相关管线数据避免N+1查询问题
var unitWorkIds = unitWorkList.Select(x => x.UnitWorkId).ToList();
var pipelineQuery = from p in Funs.DB.HJGL_Pipeline
where p.ProjectId == projectId
&& unitWorkIds.Contains(p.UnitWorkId)
select p;
// 如果有搜索条件,添加过滤
if (!string.IsNullOrEmpty(searchTerm))
{
pipelineQuery = pipelineQuery.Where(p => p.PipelineCode.Contains(searchTerm));
2022-09-05 16:36:31 +08:00
}
var pipelineCountDict = (from p in pipelineQuery
group p by p.UnitWorkId into g
select new {
UnitWorkId = g.Key,
Count = g.Count()
}).ToDictionary(x => x.UnitWorkId, x => x.Count);
// 优化3: 批量获取单位信息
var unitIds = unitWorkList.Where(x => x.UnitId != null).Select(x => x.UnitId).Distinct().ToList();
var unitDict = (from u in Funs.DB.Base_Unit
where unitIds.Contains(u.UnitId)
select u).ToDictionary(x => x.UnitId, x => x.UnitName);
// 优化4: 使用Dictionary进行快速查找避免重复查询
List<Model.WBS_UnitWork> unitWork1 = unitWorkList.Where(x => x.ProjectType == "1").ToList();
List<Model.WBS_UnitWork> unitWork2 = unitWorkList.Where(x => x.ProjectType == "2").ToList();
// 处理建筑工程
if (unitWork1.Count > 0)
2022-09-05 16:36:31 +08:00
{
ProcessUnitWorkNodes(unitWork1, rootNode1, pipelineCountDict, unitDict);
}
// 处理安装工程
if (unitWork2.Count > 0)
{
ProcessUnitWorkNodes(unitWork2, rootNode2, pipelineCountDict, unitDict);
2022-09-05 16:36:31 +08:00
}
}
#endregion
#region TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
2023-02-14 19:59:12 +08:00
if (e.CommandName == "加载")
2022-10-15 15:40:49 +08:00
{
2023-02-14 19:59:12 +08:00
string CommandName = e.Node.ParentNode.CommandName;
e.Node.ParentNode.CommandName = (int.Parse(CommandName.Split('|')[0]) + 1) + "|" + int.Parse(CommandName.Split('|')[1]);
TreeNode treeNode = e.Node.ParentNode;
treeNode.Nodes.Remove(e.Node);
BindNodes(e.Node.ParentNode);
2022-10-15 15:40:49 +08:00
}
2023-02-14 19:59:12 +08:00
else
2022-10-15 15:40:49 +08:00
{
2023-02-14 19:59:12 +08:00
this.BindGrid();
2022-09-05 16:36:31 +08:00
2023-02-14 19:59:12 +08:00
}
2023-11-26 17:43:05 +08:00
2022-09-05 16:36:31 +08:00
}
protected void tvControlItem_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
2023-02-14 19:59:12 +08:00
if (e.Node.Nodes[0].NodeID == "加载管线...")
{
e.Node.Nodes.Clear();
BindNodes(e.Node);
}
}
private void BindNodes(TreeNode node)
{
var pipeline = (from x in Funs.DB.HJGL_Pipeline
where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == node.NodeID
&& x.PipelineCode.Contains(this.tvPipeCode.Text.Trim())
orderby x.PipelineCode
select x).ToList();
var hJGL_WeldJoints = (from x in Funs.DB.HJGL_WeldJoint where x.ProjectId == this.CurrUser.LoginProjectId 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();
2022-09-05 16:36:31 +08:00
foreach (var item in pipeline)
{
var jotCount = (from x in hJGL_WeldJoints where x.PipelineId == item.PipelineId /*&& x.IsTwoJoint == null*/ select x).Count();
2022-09-05 16:36:31 +08:00
TreeNode newNode = new TreeNode();
newNode.Text = item.PipelineCode + "【" + jotCount.ToString() + " " + "焊口" + "】";
newNode.NodeID = item.PipelineId;
newNode.CommandName = "管线";
newNode.EnableClickEvent = true;
2023-02-14 19:59:12 +08:00
node.Nodes.Add(newNode);
}
if (pageindex < pageCount)
{
TreeNode newNode = new TreeNode();
newNode.Text = "加载";
newNode.NodeID = SQLHelper.GetNewID();
newNode.CommandName = "加载";
newNode.Icon = Icon.ArrowDown;
newNode.EnableClickEvent = true;
2023-11-26 17:43:05 +08:00
node.Nodes.Add(newNode);
2022-09-05 16:36:31 +08:00
}
}
}
#endregion
private void BindGrid()
{
2023-11-26 17:43:05 +08:00
Model.View_HJGL_WeldJoint model = new Model.View_HJGL_WeldJoint();
2022-10-25 22:30:17 +08:00
model.ProjectId = this.CurrUser.LoginProjectId;
2025-03-09 22:20:21 +08:00
model.WeldJointCode = this.txtWeldJointCode.Text;
2023-11-26 17:43:05 +08:00
if (this.tvControlItem.SelectedNode.CommandName.Split('|').Count() == 2)
2022-09-05 16:36:31 +08:00
{
2022-10-25 22:30:17 +08:00
model.UnitWorkId = this.tvControlItem.SelectedNodeID;
2025-03-09 22:20:21 +08:00
model.WeldJointCode = this.txtWeldJointCode.Text;
var list = BLL.WeldJointService.GetDataBymodel(model, Grid1.PageIndex, Grid1.PageSize);
Grid1.RecordCount = list.Total;
2025-03-09 22:20:21 +08:00
Grid1.DataSource = list.Data;
Grid1.DataBind();
2022-09-05 16:36:31 +08:00
}
else if (this.tvControlItem.SelectedNode.CommandName == "管线")
{
2023-03-21 10:21:07 +08:00
model.PipelineId = this.tvControlItem.SelectedNodeID;
2025-03-09 22:20:21 +08:00
var list = BLL.WeldJointService.GetViewWeldJointsBymodel(model);
View_HJGL_WeldJoint = list;
Grid1.RecordCount = list.Count;
var table = list.Skip(Grid1.PageSize * (Grid1.PageIndex)).Take(Grid1.PageSize).ToList();
Grid1.DataSource = table;
Grid1.DataBind();
}
2022-09-05 16:36:31 +08:00
}
2022-10-25 22:30:17 +08:00
private void get3DParmeter_weldjoint(List<View_HJGL_WeldJoint> model)
{
if (model.Any())
{
var q = model.Where(x => !string.IsNullOrEmpty(x.WeldingDate));//获取已完成焊口
if (q.Any())
{
List<string> Completed_weldedjunctionList = new List<string>();
foreach (var item in q)
{
Completed_weldedjunctionList.Add("/" + item.WeldJointCode);
}
Completed_weldedjunction = string.Join(",", Completed_weldedjunctionList);
}
var q1 = model.Where(x => string.IsNullOrEmpty(x.WeldingDate));//获取未完成管线
if (q1.Any())
{
List<string> Incomplete_weldjunctionList = new List<string>();
foreach (var item in q1)
{
2022-10-28 18:10:36 +08:00
Incomplete_weldjunctionList.Add("/" + item.WeldJointCode);
2022-10-25 22:30:17 +08:00
}
Incomplete_weldjunction = string.Join(",", Incomplete_weldjunctionList);
}
}
}
2022-09-05 16:36:31 +08:00
#region
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
/// <summary>
/// 分页下拉选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
this.BindGrid();
}
#endregion
#region
/// <summary>
/// 统计
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void BtnAnalyse_Click(object sender, EventArgs e)
{
BindGrid();
}
/// <summary>
/// 树查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnTreeFind_Click(object sender, EventArgs e)
{
// 清理缓存以确保获取最新数据(特别是当搜索条件改变时)
ClearProjectCache();
this.InitTreeMenu_WithCache();
2022-09-05 16:36:31 +08:00
//this.BindGrid3(this.tvControlItem.SelectedNodeID);
}
2023-02-16 17:19:08 +08:00
protected void btnrefresh_Click(object sender, EventArgs e)
{
Model.View_HJGL_WeldJoint model = new Model.View_HJGL_WeldJoint();
model.ProjectId = this.CurrUser.LoginProjectId;
if (this.tvControlItem.SelectedNode.CommandName.Split('|').Count() == 2)
{
model.UnitWorkId = this.tvControlItem.SelectedNodeID;
}
else if (this.tvControlItem.SelectedNode.CommandName == "管线")
{
model.PipelineId = this.tvControlItem.SelectedNodeID;
}
model.WeldJointCode = this.txtWeldJointCode.Text;
var list = BLL.WeldJointService.GetViewWeldJointsBymodel(model);
if (!string.IsNullOrEmpty(ctlAuditFlow.Url))
{
get3DParmeter_weldjoint(list);//获取三维所需焊口参数
var q = list.Where(x => !string.IsNullOrEmpty(x.WeldingDate));
var q2 = list.Where(x => x.JointAttribute == "预制口");
var sumcount = list.Count;
this.Grid1.RecordCount = list.Count;
this.JointComplete = q.Count();
this.JointNoComplete = sumcount - JointComplete;
this.JointPre = q2.Count();
this.JointNoPre = sumcount - JointPre;
}
Model.Parameter3D parameter3D = new Model.Parameter3D();
Model.ColorModel colorModel = new Model.ColorModel();
colorModel = BLL.Project_SysSetService.GetColorModel(this.CurrUser.LoginProjectId);
parameter3D.ColorModel = colorModel;
parameter3D.TagNum = "";
parameter3D.ButtonType = "2.1";
parameter3D.ModelName = HJGL_DataImportService.Getlatest3DModelNameByUnitWorkId(tvControlItem.SelectedNodeID);
if (this.tvControlItem.SelectedNode.CommandName.Split('|').Count() == 2)
{
parameter3D.ModelName = HJGL_DataImportService.Getlatest3DModelNameByUnitWorkId(tvControlItem.SelectedNodeID);
parameter3D.Crater_data = "0";
parameter3D.Completed_weldedjunction = Completed_weldedjunction;
parameter3D.Incomplete_weldjunction = Incomplete_weldjunction;
}
else if (this.tvControlItem.SelectedNode.CommandName == "管线")
{
var modelpipeline = PipelineService.GetPipelineByPipelineId(tvControlItem.SelectedNodeID);
if (modelpipeline != null && !string.IsNullOrEmpty(modelpipeline.UnitWorkId))
{
parameter3D.Crater_data = "1";
parameter3D.TagNum = "/" + modelpipeline.PipelineCode;
parameter3D.ModelName = HJGL_DataImportService.Getlatest3DModelNameByUnitWorkId(modelpipeline.UnitWorkId);
}
}
parameter3D.Transparency = colorModel.PipelineComplete;
parameter3D.Finished_color = colorModel.JointCompleteColor;
parameter3D.Incomplete_color = colorModel.JointNOCompleteColor;
ctlAuditFlow.Url_item = BLL.Project_SysSetService.GetAvevaNetUrl_Item(this.CurrUser.LoginProjectId) + parameter3D.ModelName;
ctlAuditFlow.data = parameter3D;
ctlAuditFlow.BindData();
}
2022-09-05 16:36:31 +08:00
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Tree_TextChanged(object sender, EventArgs e)
{
this.InitTreeMenu_WithCache();
2022-09-05 16:36:31 +08:00
this.BindGrid();
}
protected void btnGetChart_Click(object sender, EventArgs e)
{
2023-11-26 17:43:05 +08:00
2022-10-19 15:49:56 +08:00
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("JointQueryChart.aspx?JointComplete={0}&&JointNoComplete={1}&&JointPre={2}&&JointNoPre={3}", JointComplete, JointNoComplete, JointPre, JointNoPre, "编辑 - ")));
2022-09-05 16:36:31 +08:00
}
#endregion
#region
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut_Click(object sender, EventArgs e)
{
2025-06-04 22:46:21 +08:00
string fileName = "";
2025-03-09 22:20:21 +08:00
if (this.tvControlItem.SelectedNode.CommandName.Split('|').Count() == 2) //单位工程
2023-02-21 17:03:38 +08:00
{
Model.View_HJGL_WeldJoint model = new Model.View_HJGL_WeldJoint();
model.UnitWorkId = this.tvControlItem.SelectedNodeID;
var list = BLL.WeldJointService.GetViewWeldJointsBymodel(model);
View_HJGL_WeldJoint = list;
2025-06-04 22:46:21 +08:00
fileName = UnitWorkService.GetNameById(model.UnitWorkId);
}
else if (this.tvControlItem.SelectedNode.CommandName == "管线")
{
fileName = PipelineService.GetPipelineByPipelineId(this.tvControlItem.SelectedNodeID)?.PipelineCode;
}
2023-11-26 17:43:05 +08:00
2023-02-21 17:03:38 +08:00
string path = Funs.RootPath + @"File\Excel\Temp\JointQuery.xlsx";
path = path.Replace(".xlsx", string.Format("{0:yyyy-MM-dd-HH-mm}", DateTime.Now) + ".xlsx");
var q = (from x in View_HJGL_WeldJoint
select new
{
= x.WeldJointCode,
2023-12-01 16:24:41 +08:00
= x.IsWeldOK,
2023-02-21 17:03:38 +08:00
= x.UnitName,
2023-11-26 17:43:05 +08:00
= x.FlowingSection,
= x.TaskCode,
2023-02-21 17:03:38 +08:00
1 = x.Material1Code,
2 = x.Material2Code,
= x.Size,
= x.Dia,
= x.Thickness,
= x.Specification,
= x.WeldTypeCode,
= x.WeldingMethodCode,
WPS编号 = x.WPQCode,
= x.GrooveTypeCode,
2023-11-26 17:43:05 +08:00
= x.WeldingRodCode,
= x.WeldingWireCode,
2023-02-21 17:03:38 +08:00
= x.PreTemperature,
= x.JointAttribute,
= x.WeldingDate,
= x.BackingWelderCode,
= x.BackingWelderTeamGroupName,
2024-06-19 18:52:56 +08:00
= x.CoverWelderCode,
= x.CoverWelderTeamGroupName,
2023-02-21 17:03:38 +08:00
= x.HotProessReportNo,
= x.HotProessResult,
= x.HardReportNo,
= x.HardResult,
= x.TrustBatchCode,
= x.NDECode,
= x.DetectionTypeCode,
= x.DetectionRateCode
2023-02-21 17:03:38 +08:00
}).ToList();
MiniExcel.SaveAs(path, q);
fileName = fileName + "-焊口信息总览.xlsx";
2023-02-21 17:03:38 +08:00
FileInfo info = new FileInfo(path);
long fileSize = info.Length;
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ContentType = "application/x-zip-compressed";
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
System.Web.HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString());
System.Web.HttpContext.Current.Response.TransmitFile(path, 0, fileSize);
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.Close();
File.Delete(path);
//Response.ClearContent();
//string filename = Funs.GetNewFileName();
//Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("焊口台账总览" + filename, System.Text.Encoding.UTF8) + ".xls");
//Response.ContentType = "application/excel";
//Response.ContentEncoding = System.Text.Encoding.UTF8;
//Response.Write(GetGridTableHtml(Grid1));
//Response.End();
2022-09-05 16:36:31 +08:00
}
2025-03-09 22:20:21 +08:00
protected void PrintByUnitWork(string unitWorkId)
{
const int pageSize = 10000;
int pageIndex = 0;
bool isFirstPage = true;
var model = new Model.View_HJGL_WeldJoint
{
ProjectId = this.CurrUser.LoginProjectId,
UnitWorkId = unitWorkId
};
2025-03-09 22:20:21 +08:00
// 生成唯一文件路径带GUID哈希值
string path = $@"{Funs.RootPath}File\Excel\Temp\JointQuery_{Guid.NewGuid().GetHashCode():x}.xlsx";
var AllData = new List<object>();
using (var excelStream = new FileStream(path, FileMode.Create))
{
while (true)
{
// 分页获取数据
var pageData = BLL.WeldJointService.GetDataBymodel(model, pageIndex, pageSize);
if (!pageData.Data.Any()) break;
// 动态转换查询结果
var currentChunk = pageData.Data.Select(x => new
{
= x.WeldJointCode,
= x.IsWeldOK,
= x.UnitName,
= x.FlowingSection,
= x.TaskCode,
2025-03-09 22:20:21 +08:00
1 = x.Material1Code,
2 = x.Material2Code,
= x.Size,
= x.Dia,
= x.Thickness,
= x.Specification,
= x.WeldTypeCode,
= x.WeldingMethodCode,
WPS编号 = x.WPQCode,
= x.GrooveTypeCode,
= x.WeldingRodCode,
= x.WeldingWireCode,
= x.PreTemperature,
= x.JointAttribute,
= x.WeldingDate,
= x.BackingWelderCode,
= x.BackingWelderTeamGroupName,
= x.CoverWelderCode,
= x.CoverWelderTeamGroupName,
= x.HotProessReportNo,
= x.HotProessResult,
= x.HardReportNo,
= x.HardResult,
= x.TrustBatchCode,
= x.NDECode,
= x.DetectionTypeCode,
= x.DetectionRateCode
}).ToList();
2025-03-09 22:20:21 +08:00
AllData.AddRange(currentChunk);
// 内存清理 & 翻页操作
currentChunk = null;
pageIndex++;
2025-03-09 22:20:21 +08:00
GC.Collect(GC.MaxGeneration, GCCollectionMode.Optimized, blocking: true);
}
MiniExcel.SaveAs(path, AllData);
2025-03-09 22:20:21 +08:00
}
string fileName = "焊口信息总览.xlsx";
FileInfo info = new FileInfo(path);
long fileSize = info.Length;
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ContentType = "application/x-zip-compressed";
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
System.Web.HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString());
System.Web.HttpContext.Current.Response.TransmitFile(path, 0, fileSize);
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.Close();
2025-03-09 22:20:21 +08:00
File.Delete(path); // 多保险清理机制
}
2023-02-16 17:19:08 +08:00
protected void btnOutNOComPipeline_Click(object sender, EventArgs e)
{
if (this.tvControlItem.SelectedNode.CommandName.Split('|').Count() == 2)
{
2023-11-26 17:43:05 +08:00
var q = (from x in Funs.DB.View_HJGL_WeldJoint
where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == this.tvControlItem.SelectedNodeID
select new
{
PipelineId = x.PipelineId,
WeldingDate = x.WeldingDate,
WeldJointCode = x.WeldJointCode,
PipelineCode = x.PipelineCode,
Size = x.Size,
2023-02-16 17:19:08 +08:00
});
var noCompipeline = from x in q
2023-11-26 17:43:05 +08:00
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 Noweldjoint = (from x in q
join y in noCompipeline on x.PipelineId equals y.PipelineId
where y.Count == 0
select new
{
= x.WeldJointCode,
线 = x.PipelineCode,
= x.Size
}).ToList();
2023-02-16 17:19:08 +08:00
string path = Funs.RootPath + @"File\Excel\Temp\NoCompleteWeldjoint.xlsx";
path = path.Replace(".xlsx", string.Format("{0:yyyy-MM-dd-HH-mm}", DateTime.Now) + ".xlsx");
MiniExcel.SaveAs(path, Noweldjoint);
2023-11-26 17:43:05 +08:00
2023-02-16 17:19:08 +08:00
string fileName = "未完成管线焊口.xlsx";
FileInfo info = new FileInfo(path);
long fileSize = info.Length;
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ContentType = "application/x-zip-compressed";
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
System.Web.HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString());
System.Web.HttpContext.Current.Response.TransmitFile(path, 0, fileSize);
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.Close();
File.Delete(path);
}
else
{
Alert.Show("请选择主项");
}
2023-11-26 17:43:05 +08:00
2023-02-16 17:19:08 +08:00
}
2022-09-05 16:36:31 +08:00
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
private string GetGridTableHtml(Grid grid)
{
StringBuilder sb = new StringBuilder();
2023-02-16 17:19:08 +08:00
grid.PageSize = 100000;
2022-09-05 16:36:31 +08:00
BindGrid();
sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>");
sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
sb.Append("<tr>");
foreach (GridColumn column in grid.Columns)
{
sb.AppendFormat("<td>{0}</td>", column.HeaderText);
}
sb.Append("</tr>");
foreach (GridRow row in grid.Rows)
{
sb.Append("<tr>");
foreach (GridColumn column in grid.Columns)
{
string html = row.Values[column.ColumnIndex].ToString();
if (column.ColumnID == "tfNumber")
{
html = (row.FindControl("labNumber") as AspNet.Label).Text;
}
sb.AppendFormat("<td>{0}</td>", html);
}
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
#endregion
2022-10-13 18:52:45 +08:00
protected void Grid1_RowClick(object sender, GridRowClickEventArgs e)
{
var Id = Grid1.SelectedRowIDArray;
List<string> weldjointcodes = new List<string>();
foreach (var item in Id)
{
var WeldJointCode = WeldJointService.GetViewWeldJointById(item).WeldJointCode;
weldjointcodes.Add("/" + WeldJointCode);
}
//var q = WeldJointService.GetViewWeldJointById(Grid1.SelectedRowID).PipelineCode;
//var pipecode = "/" + q;
2022-10-13 18:52:45 +08:00
Model.Parameter3D parameter3D = new Model.Parameter3D();
Model.ColorModel colorModel = new Model.ColorModel();
colorModel = BLL.Project_SysSetService.GetColorModel(this.CurrUser.LoginProjectId);
parameter3D.ColorModel = colorModel;
parameter3D.TagNum = string.Join(",", weldjointcodes);
parameter3D.ButtonType = "2.1";
2023-11-26 17:43:05 +08:00
parameter3D.Crater_data = "1";
2023-02-14 19:59:12 +08:00
if (this.tvControlItem.SelectedNode.CommandName.Split('|').Count() == 2)
2022-10-15 15:40:49 +08:00
{
parameter3D.ModelName = HJGL_DataImportService.Getlatest3DModelNameByUnitWorkId(tvControlItem.SelectedNodeID);
}
else if (this.tvControlItem.SelectedNode.CommandName == "管线")
{
var model = PipelineService.GetPipelineByPipelineId(tvControlItem.SelectedNodeID);
if (model != null && !string.IsNullOrEmpty(model.UnitWorkId))
{
parameter3D.ModelName = HJGL_DataImportService.Getlatest3DModelNameByUnitWorkId(model.UnitWorkId);
}
}
2022-10-28 17:01:51 +08:00
parameter3D.Transparency = colorModel.PipelineComplete;
parameter3D.Finished_color = colorModel.JointCompleteColor;
parameter3D.Incomplete_color = colorModel.JointNOCompleteColor;
2023-11-26 17:43:05 +08:00
ctlAuditFlow.Url_item = BLL.Project_SysSetService.GetAvevaNetUrl_Item(this.CurrUser.LoginProjectId) + parameter3D.ModelName;
2022-10-13 18:52:45 +08:00
ctlAuditFlow.data = parameter3D;
ctlAuditFlow.BindData();
}
2023-02-16 17:19:08 +08:00
2023-11-26 17:43:05 +08:00
2022-09-05 16:36:31 +08:00
}
}