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

876 lines
36 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BLL;
using MiniExcelLibs;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using AspNet = System.Web.UI.WebControls;
using System.Web.Caching;
namespace FineUIPro.Web.HJGL.InfoQuery
{
public partial class JointQuery : PageBase
{
public int pageSize = 20;
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;
}
}
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;
}
}
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;
}
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();//加载树
this.JointComplete = 0;
this.JointNoComplete = 0;
this.JointPre = 0;
this.JointNoPre = 0;
}
}
#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);
}
}
/// <summary>
/// 优化版本的树加载方法
/// </summary>
private void InitTreeMenu_Optimized()
{
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();
// 优化1: 使用单次查询获取所需数据,减少数据库往返次数
var unitWorkList = (from x in Funs.DB.WBS_UnitWork
where x.ProjectId == projectId
&& x.SuperUnitWork == null
&& x.UnitId != null
&& x.ProjectType != null
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));
}
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)
{
ProcessUnitWorkNodes(unitWork1, rootNode1, pipelineCountDict, unitDict);
}
// 处理安装工程
if (unitWork2.Count > 0)
{
ProcessUnitWorkNodes(unitWork2, rootNode2, pipelineCountDict, unitDict);
}
}
#endregion
#region TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
if (e.CommandName == "加载")
{
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);
}
else
{
this.BindGrid();
}
}
protected void tvControlItem_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
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();
foreach (var item in pipeline)
{
var jotCount = (from x in hJGL_WeldJoints where x.PipelineId == item.PipelineId /*&& x.IsTwoJoint == null*/ select x).Count();
TreeNode newNode = new TreeNode();
newNode.Text = item.PipelineCode + "【" + jotCount.ToString() + " " + "焊口" + "】";
newNode.NodeID = item.PipelineId;
newNode.CommandName = "管线";
newNode.EnableClickEvent = true;
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;
node.Nodes.Add(newNode);
}
}
}
#endregion
private void BindGrid()
{
Model.View_HJGL_WeldJoint model = new Model.View_HJGL_WeldJoint();
model.ProjectId = this.CurrUser.LoginProjectId;
model.WeldJointCode = this.txtWeldJointCode.Text;
if (this.tvControlItem.SelectedNode.CommandName.Split('|').Count() == 2)
{
model.UnitWorkId = this.tvControlItem.SelectedNodeID;
model.WeldJointCode = this.txtWeldJointCode.Text;
var list = BLL.WeldJointService.GetDataBymodel(model, Grid1.PageIndex, Grid1.PageSize);
Grid1.RecordCount = list.Total;
Grid1.DataSource = list.Data;
Grid1.DataBind();
}
else if (this.tvControlItem.SelectedNode.CommandName == "管线")
{
model.PipelineId = this.tvControlItem.SelectedNodeID;
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();
}
}
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)
{
Incomplete_weldjunctionList.Add("/" + item.WeldJointCode);
}
Incomplete_weldjunction = string.Join(",", Incomplete_weldjunctionList);
}
}
}
#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();
//this.BindGrid3(this.tvControlItem.SelectedNodeID);
}
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();
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Tree_TextChanged(object sender, EventArgs e)
{
this.InitTreeMenu_WithCache();
this.BindGrid();
}
protected void btnGetChart_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("JointQueryChart.aspx?JointComplete={0}&&JointNoComplete={1}&&JointPre={2}&&JointNoPre={3}", JointComplete, JointNoComplete, JointPre, JointNoPre, "编辑 - ")));
}
#endregion
#region
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut_Click(object sender, EventArgs e)
{
string fileName = "";
if (this.tvControlItem.SelectedNode.CommandName.Split('|').Count() == 2) //单位工程
{
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;
fileName = UnitWorkService.GetNameById(model.UnitWorkId);
}
else if (this.tvControlItem.SelectedNode.CommandName == "管线")
{
fileName = PipelineService.GetPipelineByPipelineId(this.tvControlItem.SelectedNodeID)?.PipelineCode;
}
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,
= x.IsWeldOK,
= x.UnitName,
= x.FlowingSection,
= x.TaskCode,
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();
MiniExcel.SaveAs(path, q);
fileName = 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);
//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();
}
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
};
// 生成唯一文件路径带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,
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();
AllData.AddRange(currentChunk);
// 内存清理 & 翻页操作
currentChunk = null;
pageIndex++;
GC.Collect(GC.MaxGeneration, GCCollectionMode.Optimized, blocking: true);
}
MiniExcel.SaveAs(path, AllData);
}
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); // 多保险清理机制
}
protected void btnOutNOComPipeline_Click(object sender, EventArgs e)
{
if (this.tvControlItem.SelectedNode.CommandName.Split('|').Count() == 2)
{
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,
});
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 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();
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);
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("请选择主项");
}
}
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
private string GetGridTableHtml(Grid grid)
{
StringBuilder sb = new StringBuilder();
grid.PageSize = 100000;
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
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;
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";
parameter3D.Crater_data = "1";
if (this.tvControlItem.SelectedNode.CommandName.Split('|').Count() == 2)
{
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);
}
}
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();
}
}
}