152 lines
7.9 KiB
C#
152 lines
7.9 KiB
C#
|
|
using BLL;
|
||
|
|
using MiniExcelLibs;
|
||
|
|
using Model;
|
||
|
|
using System;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System.IO;
|
||
|
|
using System.Linq;
|
||
|
|
|
||
|
|
namespace FineUIPro.Web.HJGL.InfoQuery
|
||
|
|
{
|
||
|
|
public partial class PipeLengthOverview : PageBase
|
||
|
|
{
|
||
|
|
protected void Page_Load(object sender, EventArgs e)
|
||
|
|
{
|
||
|
|
if (!IsPostBack)
|
||
|
|
{
|
||
|
|
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
|
||
|
|
InitTreeMenu();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void InitTreeMenu()
|
||
|
|
{
|
||
|
|
tvControlItem.Nodes.Clear();
|
||
|
|
TreeNode civilNode = new TreeNode { NodeID = "1", Text = "建筑工程", Selectable = false };
|
||
|
|
TreeNode installNode = new TreeNode { NodeID = "2", Text = "安装工程", Selectable = false, Expanded = true };
|
||
|
|
tvControlItem.Nodes.Add(civilNode);
|
||
|
|
tvControlItem.Nodes.Add(installNode);
|
||
|
|
|
||
|
|
string projectId = CurrUser.LoginProjectId;
|
||
|
|
// 管长识别表无项目归属,必须通过管线号关联项目管线,防止跨项目展示同名管线的识别结果。
|
||
|
|
var recordCounts = (from pipeLength in Funs.DB.HJGL_DrawingRecognition_PipeLengths
|
||
|
|
join pipeline in Funs.DB.HJGL_Pipeline on pipeLength.Pipe_no equals pipeline.PipelineCode
|
||
|
|
where pipeline.ProjectId == projectId && pipeline.UnitWorkId != null
|
||
|
|
group pipeLength by pipeline.UnitWorkId into groupItem
|
||
|
|
select new { UnitWorkId = groupItem.Key, Count = groupItem.Count() }).ToDictionary(x => x.UnitWorkId, x => x.Count);
|
||
|
|
var unitWorks = (from unitWork in Funs.DB.WBS_UnitWork
|
||
|
|
where unitWork.ProjectId == projectId && unitWork.SuperUnitWork == null && unitWork.UnitId != null && unitWork.ProjectType != null
|
||
|
|
orderby unitWork.UnitWorkCode
|
||
|
|
select unitWork).ToList();
|
||
|
|
var unitIds = unitWorks.Where(x => x.UnitId != null).Select(x => x.UnitId).Distinct().ToList();
|
||
|
|
var unitNames = (from unit in Funs.DB.Base_Unit where unitIds.Contains(unit.UnitId) select unit).ToDictionary(x => x.UnitId, x => x.UnitName);
|
||
|
|
|
||
|
|
foreach (var unitWork in unitWorks)
|
||
|
|
{
|
||
|
|
int count = recordCounts.ContainsKey(unitWork.UnitWorkId) ? recordCounts[unitWork.UnitWorkId] : 0;
|
||
|
|
TreeNode node = new TreeNode();
|
||
|
|
node.NodeID = unitWork.UnitWorkId;
|
||
|
|
node.Text = unitWork.UnitWorkName + "【" + count + "】管段";
|
||
|
|
node.ToolTip = "施工单位:" + (unitNames.ContainsKey(unitWork.UnitId) ? unitNames[unitWork.UnitId] : "");
|
||
|
|
node.EnableClickEvent = true;
|
||
|
|
(unitWork.ProjectType == "1" ? civilNode : installNode).Nodes.Add(node);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
|
||
|
|
{
|
||
|
|
Grid1.PageIndex = 0;
|
||
|
|
BindGrid();
|
||
|
|
}
|
||
|
|
|
||
|
|
private void BindGrid()
|
||
|
|
{
|
||
|
|
string unitWorkId = tvControlItem.SelectedNodeID;
|
||
|
|
if (string.IsNullOrEmpty(unitWorkId))
|
||
|
|
{
|
||
|
|
Grid1.RecordCount = 0;
|
||
|
|
Grid1.DataSource = new List<HJGL_DrawingRecognition_PipeLengths>();
|
||
|
|
Grid1.DataBind();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
var query = ApplySort(GetCurrentQuery(unitWorkId));
|
||
|
|
Grid1.RecordCount = query.Count();
|
||
|
|
Grid1.DataSource = query.Skip(Grid1.PageIndex * Grid1.PageSize).Take(Grid1.PageSize).ToList();
|
||
|
|
Grid1.DataBind();
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 汇总当前WBS节点和页面筛选条件,保证列表与导出数据完全一致。
|
||
|
|
/// </summary>
|
||
|
|
private IQueryable<HJGL_DrawingRecognition_PipeLengths> GetCurrentQuery(string unitWorkId)
|
||
|
|
{
|
||
|
|
string pipeNo = txtPipeNo.Text.Trim();
|
||
|
|
string dn = txtDn.Text.Trim();
|
||
|
|
var query = from pipeLength in Funs.DB.HJGL_DrawingRecognition_PipeLengths
|
||
|
|
join pipeline in Funs.DB.HJGL_Pipeline on pipeLength.Pipe_no equals pipeline.PipelineCode
|
||
|
|
where pipeline.ProjectId == CurrUser.LoginProjectId && pipeline.UnitWorkId == unitWorkId
|
||
|
|
select pipeLength;
|
||
|
|
if (!string.IsNullOrEmpty(pipeNo)) query = query.Where(x => x.Pipe_no.Contains(pipeNo));
|
||
|
|
if (!string.IsNullOrEmpty(dn)) query = query.Where(x => x.Dn.Contains(dn));
|
||
|
|
return query;
|
||
|
|
}
|
||
|
|
|
||
|
|
private IQueryable<HJGL_DrawingRecognition_PipeLengths> ApplySort(IQueryable<HJGL_DrawingRecognition_PipeLengths> query)
|
||
|
|
{
|
||
|
|
bool descending = Grid1.SortDirection == "DESC";
|
||
|
|
switch (Grid1.SortField)
|
||
|
|
{
|
||
|
|
case "Pipe_page_no": return descending ? query.OrderByDescending(x => x.Pipe_page_no) : query.OrderBy(x => x.Pipe_page_no);
|
||
|
|
case "Group_index": return descending ? query.OrderByDescending(x => x.Group_index) : query.OrderBy(x => x.Group_index);
|
||
|
|
case "Pos_no": return descending ? query.OrderByDescending(x => x.Pos_no) : query.OrderBy(x => x.Pos_no);
|
||
|
|
case "Length_mm": return descending ? query.OrderByDescending(x => x.Length_mm) : query.OrderBy(x => x.Length_mm);
|
||
|
|
case "Dn": return descending ? query.OrderByDescending(x => x.Dn) : query.OrderBy(x => x.Dn);
|
||
|
|
default: return descending ? query.OrderByDescending(x => x.Pipe_no) : query.OrderBy(x => x.Pipe_no);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected void btnQuery_Click(object sender, EventArgs e) { Grid1.PageIndex = 0; BindGrid(); }
|
||
|
|
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); }
|
||
|
|
protected void Grid1_Sort(object sender, GridSortEventArgs e) { Grid1.SortField = e.SortField; Grid1.SortDirection = e.SortDirection; BindGrid(); }
|
||
|
|
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); Grid1.PageIndex = 0; BindGrid(); }
|
||
|
|
|
||
|
|
protected void btnOut_Click(object sender, EventArgs e)
|
||
|
|
{
|
||
|
|
string unitWorkId = tvControlItem.SelectedNodeID;
|
||
|
|
if (string.IsNullOrEmpty(unitWorkId))
|
||
|
|
{
|
||
|
|
ShowNotify("请先选择WBS目录", MessageBoxIcon.Warning);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 导出所有满足当前筛选条件的记录,不受列表分页大小限制。
|
||
|
|
var data = ApplySort(GetCurrentQuery(unitWorkId)).Select(x => new
|
||
|
|
{
|
||
|
|
管线号 = x.Pipe_no,
|
||
|
|
管线页码 = x.Pipe_page_no,
|
||
|
|
分组序号 = x.Group_index,
|
||
|
|
位置编号 = x.Pos_no,
|
||
|
|
长度毫米 = x.Length_mm,
|
||
|
|
公称直径DN = x.Dn
|
||
|
|
}).ToList();
|
||
|
|
string path = Path.Combine(Funs.RootPath, "File", "Excel", "Temp", "PipeLengthOverview" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".xlsx");
|
||
|
|
MiniExcel.SaveAs(path, data);
|
||
|
|
DownloadExcel(path, "管长信息总览.xlsx");
|
||
|
|
}
|
||
|
|
|
||
|
|
private void DownloadExcel(string path, string fileName)
|
||
|
|
{
|
||
|
|
FileInfo info = new FileInfo(path);
|
||
|
|
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", info.Length.ToString());
|
||
|
|
System.Web.HttpContext.Current.Response.TransmitFile(path, 0, info.Length);
|
||
|
|
System.Web.HttpContext.Current.Response.Flush();
|
||
|
|
System.Web.HttpContext.Current.Response.Close();
|
||
|
|
File.Delete(path);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|