feat(hjgl): 增加焊接日志导出与管道预制汇总
补充俄文焊接日志导出和管道预制汇总报表,统一菜单、数据库脚本与导出模板,便于按日报或单位工程查看和交付施工统计数据。
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using BLL;
|
||||
using MiniExcelLibs;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
@@ -728,6 +730,135 @@ namespace FineUIPro.Web.HJGL.WeldingManage
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导出俄文焊接日志。
|
||||
/// </summary>
|
||||
protected void btnWeldingLogOut_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (tvControlItem.SelectedNode == null
|
||||
|| (tvControlItem.SelectedNode.CommandName != "UnitWork"
|
||||
&& tvControlItem.SelectedNode.CommandName != "WeldingDaily"))
|
||||
{
|
||||
Alert.ShowInTop("请选择单位工程或焊接日报!", MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
string unitWorkId = null;
|
||||
string weldingDailyId = null;
|
||||
string fileName;
|
||||
if (tvControlItem.SelectedNode.CommandName == "WeldingDaily")
|
||||
{
|
||||
weldingDailyId = tvControlItem.SelectedNodeID;
|
||||
var daily = BLL.WeldingDailyService.GetPipeline_WeldingDailyByWeldingDailyId(weldingDailyId);
|
||||
if (daily == null || daily.ProjectId != this.CurrUser.LoginProjectId)
|
||||
{
|
||||
Alert.ShowInTop("所选焊接日报不存在!", MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
var unitWork = UnitWorkService.getUnitWorkByUnitWorkId(daily.UnitWorkId);
|
||||
fileName = "焊接日志-" + (unitWork == null ? string.Empty : unitWork.UnitWorkName + "-")
|
||||
+ daily.WeldingDailyCode + ".xlsx";
|
||||
}
|
||||
else
|
||||
{
|
||||
unitWorkId = tvControlItem.SelectedNodeID;
|
||||
var unitWork = BLL.UnitWorkService.getUnitWorkByUnitWorkId(unitWorkId);
|
||||
if (unitWork == null || unitWork.ProjectId != this.CurrUser.LoginProjectId)
|
||||
{
|
||||
Alert.ShowInTop("所选单位工程不存在!", MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
fileName = "焊接日志-" + unitWork.UnitWorkName + "-" + txtMonth.Text.Trim() + ".xlsx";
|
||||
}
|
||||
|
||||
DataTable data = BLL.WeldingDailyService.GetWeldingLogExportData(
|
||||
this.CurrUser.LoginProjectId, unitWorkId, weldingDailyId, txtMonth.Text.Trim());
|
||||
if (data.Rows.Count == 0)
|
||||
{
|
||||
Alert.ShowInTop("无数据,无法导出!", MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] fileBytes;
|
||||
var workbook = new XSSFWorkbook();
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
ISheet sheet = workbook.CreateSheet("Сварочный журнал");
|
||||
ICellStyle headerStyle = workbook.CreateCellStyle();
|
||||
headerStyle.Alignment = HorizontalAlignment.Center;
|
||||
headerStyle.VerticalAlignment = VerticalAlignment.Center;
|
||||
headerStyle.WrapText = true;
|
||||
headerStyle.BorderTop = BorderStyle.Thin;
|
||||
headerStyle.BorderRight = BorderStyle.Thin;
|
||||
headerStyle.BorderBottom = BorderStyle.Thin;
|
||||
headerStyle.BorderLeft = BorderStyle.Thin;
|
||||
IFont headerFont = workbook.CreateFont();
|
||||
headerFont.IsBold = true;
|
||||
headerFont.FontHeightInPoints = 10;
|
||||
headerStyle.SetFont(headerFont);
|
||||
|
||||
ICellStyle dataStyle = workbook.CreateCellStyle();
|
||||
dataStyle.Alignment = HorizontalAlignment.Center;
|
||||
dataStyle.VerticalAlignment = VerticalAlignment.Center;
|
||||
dataStyle.WrapText = true;
|
||||
dataStyle.BorderTop = BorderStyle.Thin;
|
||||
dataStyle.BorderRight = BorderStyle.Thin;
|
||||
dataStyle.BorderBottom = BorderStyle.Thin;
|
||||
dataStyle.BorderLeft = BorderStyle.Thin;
|
||||
|
||||
IRow headerRow = sheet.CreateRow(0);
|
||||
headerRow.HeightInPoints = 90;
|
||||
for (int columnIndex = 0; columnIndex < data.Columns.Count; columnIndex++)
|
||||
{
|
||||
ICell cell = headerRow.CreateCell(columnIndex);
|
||||
cell.SetCellValue(data.Columns[columnIndex].ColumnName);
|
||||
cell.CellStyle = headerStyle;
|
||||
}
|
||||
|
||||
for (int rowIndex = 0; rowIndex < data.Rows.Count; rowIndex++)
|
||||
{
|
||||
IRow row = sheet.CreateRow(rowIndex + 1);
|
||||
row.HeightInPoints = 30;
|
||||
for (int columnIndex = 0; columnIndex < data.Columns.Count; columnIndex++)
|
||||
{
|
||||
ICell cell = row.CreateCell(columnIndex);
|
||||
object value = data.Rows[rowIndex][columnIndex];
|
||||
if (columnIndex == 0 && value != DBNull.Value)
|
||||
{
|
||||
cell.SetCellValue(Convert.ToDouble(value));
|
||||
}
|
||||
else
|
||||
{
|
||||
cell.SetCellValue(value == DBNull.Value ? string.Empty : value.ToString());
|
||||
}
|
||||
cell.CellStyle = dataStyle;
|
||||
}
|
||||
}
|
||||
|
||||
int[] columnWidths = { 6, 45, 25, 35, 25, 25, 16, 45, 24, 18, 26, 24, 24, 28, 35, 45, 35 };
|
||||
for (int i = 0; i < columnWidths.Length; i++)
|
||||
{
|
||||
sheet.SetColumnWidth(i, columnWidths[i] * 256);
|
||||
}
|
||||
sheet.CreateFreezePane(0, 1);
|
||||
sheet.FitToPage = true;
|
||||
sheet.PrintSetup.Landscape = true;
|
||||
sheet.PrintSetup.FitWidth = 1;
|
||||
workbook.Write(stream);
|
||||
fileBytes = stream.ToArray();
|
||||
}
|
||||
|
||||
HttpResponse response = HttpContext.Current.Response;
|
||||
response.Clear();
|
||||
response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
||||
response.AddHeader("Content-Disposition", "attachment;filename="
|
||||
+ HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
|
||||
response.AddHeader("Content-Length", fileBytes.Length.ToString());
|
||||
response.BinaryWrite(fileBytes);
|
||||
response.Flush();
|
||||
HttpContext.Current.ApplicationInstance.CompleteRequest();
|
||||
}
|
||||
|
||||
protected void btnMenuDeleteDetail_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Grid1.SelectedRowID))
|
||||
|
||||
Reference in New Issue
Block a user