提交代码

This commit is contained in:
2023-11-23 16:50:57 +08:00
parent aedd071d96
commit 1530dd850b
27 changed files with 974 additions and 250 deletions
@@ -1,8 +1,10 @@
using BLL;
using NPOI.SS.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
@@ -839,27 +841,171 @@ namespace FineUIPro.Web.HJGL.WeldingManage
#endregion
#region
/// <summary>
/// 导出焊口信息
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut_Click(object sender, EventArgs e)
{
//var iso = BLL.Pipeline_PipelineService.GetPipelineByPipelineId(this.tvControlItem.SelectedNodeID);
//var workArea = BLL.Project_WorkAreaService.GetProject_WorkAreaByWorkAreaId(this.tvControlItem.SelectedNodeID);
//if (iso != null)
//{
// PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("JointInfoOut.aspx?PipelineId={0}", this.tvControlItem.SelectedNodeID, "导出 - ")));
//}
//else if (workArea != null)
//{
// PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("JointInfoOut.aspx?WorkAreaId={0}", this.tvControlItem.SelectedNodeID, "导出 - ")));
//}
//else
//{
// Alert.ShowInTop("请选择"PipelineOrArea, MessageBoxIcon.Warning);
//}
string rootPath = Server.MapPath("~/");
string initTemplatePath = string.Empty;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
string filePath = string.Empty;
initTemplatePath = Const.JotTwoDesignTemplateUrl;
uploadfilepath = rootPath + initTemplatePath;
string constructionLogId = this.tvControlItem.SelectedNodeID;
Model.SGGLDB db = Funs.DB;
var workEfficiencys = from x in db.ZHGL_ConstructionLogWorkEfficiency
where x.ConstructionLogId == constructionLogId
select x;
var persons = from x in db.ZHGL_ConstructionLogPerson
where x.ConstructionLogId == constructionLogId
select x;
var machines = from x in db.ZHGL_ConstructionLogMachine
where x.ConstructionLogId == constructionLogId
select x;
if (this.Grid1.Rows.Count > 0)
{
newUrl = uploadfilepath.Replace(".xlsx", "(" + string.Format("{0:yyyy-MM-dd}", DateTime.Now) + ")" + ".xlsx");
File.Copy(uploadfilepath, newUrl);
// 第一步:读取文件流
NPOI.SS.UserModel.IWorkbook workbook;
using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
{
workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream);
}
// 创建单元格样式
NPOI.SS.UserModel.ICellStyle cellStyle0 = workbook.CreateCellStyle();
cellStyle0.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle0.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
cellStyle0.WrapText = true;
var font = workbook.CreateFont();
font.FontHeightInPoints = 11;
font.IsBold = false;
cellStyle0.SetFont(font);
// 第二步:创建新数据行
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
int rowCount = 2;
for (int i = 0; i < this.Grid1.Rows.Count; i++)
{
NPOI.SS.UserModel.IRow row1 = sheet.CreateRow(rowCount);
NPOI.SS.UserModel.ICell cell;
cell = row1.CreateCell(0);
cell.CellStyle = cellStyle0;
cell.SetCellValue((i+1).ToString());
cell = row1.CreateCell(1);
cell.CellStyle = cellStyle0;
cell.SetCellValue(this.Grid1.Rows[i].Values[2].ToString());
cell = row1.CreateCell(2);
cell.CellStyle = cellStyle0;
cell.SetCellValue(this.Grid1.Rows[i].Values[3].ToString());
cell = row1.CreateCell(3);
cell.CellStyle = cellStyle0;
cell.SetCellValue(this.Grid1.Rows[i].Values[4].ToString());
cell = row1.CreateCell(4);
cell.CellStyle = cellStyle0;
string date1 = this.Grid1.Rows[i].Values[5].ToString();
if (!string.IsNullOrEmpty(date1))
{
date1 = string.Format("{0:yyyy-MM-dd}",Funs.GetNewDateTime(date1));
}
cell.SetCellValue(date1);
cell = row1.CreateCell(5);
cell.CellStyle = cellStyle0;
cell.SetCellValue(this.Grid1.Rows[i].Values[6].ToString());
cell = row1.CreateCell(6);
cell.CellStyle = cellStyle0;
string date2 = this.Grid1.Rows[i].Values[7].ToString();
if (!string.IsNullOrEmpty(date2))
{
date2 = string.Format("{0:yyyy-MM-dd}", Funs.GetNewDateTime(date2));
}
cell.SetCellValue(date2);
cell = row1.CreateCell(7);
cell.CellStyle = cellStyle0;
string weldJointCode = string.Empty;
var weldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(this.Grid1.Rows[i].RowID);
if (weldJoint != null)
{
weldJointCode = weldJoint.WeldJointCode;
}
cell.SetCellValue(weldJointCode);
cell = row1.CreateCell(8);
cell.CellStyle = cellStyle0;
cell.SetCellValue(this.Grid1.Rows[i].Values[10].ToString());
cell = row1.CreateCell(9);
cell.CellStyle = cellStyle0;
cell.SetCellValue(this.Grid1.Rows[i].Values[11].ToString());
cell = row1.CreateCell(10);
cell.CellStyle = cellStyle0;
cell.SetCellValue(this.Grid1.Rows[i].Values[12].ToString());
cell = row1.CreateCell(11);
cell.CellStyle = cellStyle0;
cell.SetCellValue(this.Grid1.Rows[i].Values[13].ToString());
cell = row1.CreateCell(12);
cell.CellStyle = cellStyle0;
cell.SetCellValue(this.Grid1.Rows[i].Values[14].ToString());
cell = row1.CreateCell(13);
cell.CellStyle = cellStyle0;
cell.SetCellValue(this.Grid1.Rows[i].Values[15].ToString());
cell = row1.CreateCell(14);
cell.CellStyle = cellStyle0;
cell.SetCellValue(this.Grid1.Rows[i].Values[16].ToString());
cell = row1.CreateCell(15);
cell.CellStyle = cellStyle0;
cell.SetCellValue(this.Grid1.Rows[i].Values[17].ToString());
cell = row1.CreateCell(16);
cell.CellStyle = cellStyle0;
cell.SetCellValue(this.Grid1.Rows[i].Values[18].ToString());
cell = row1.CreateCell(17);
cell.CellStyle = cellStyle0;
cell.SetCellValue(this.Grid1.Rows[i].Values[20].ToString());
cell = row1.CreateCell(18);
cell.CellStyle = cellStyle0;
cell.SetCellValue(this.Grid1.Rows[i].Values[21].ToString());
cell = row1.CreateCell(19);
cell.CellStyle = cellStyle0;
cell.SetCellValue(this.Grid1.Rows[i].Values[22].ToString());
cell = row1.CreateCell(20);
cell.CellStyle = cellStyle0;
cell.SetCellValue(this.Grid1.Rows[i].Values[27].ToString());
rowCount++;
}
// 第三步:写入文件流
using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write))
{
workbook.Write(stream);
workbook.Close();
}
string fileName = Path.GetFileName(newUrl);
FileInfo info = new FileInfo(newUrl);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(newUrl, 0, fileSize);
Response.Flush();
Response.Close();
File.Delete(newUrl);
}
else
{
ShowNotify("无数据可导出!", MessageBoxIcon.Warning);
}
}
/// <summary>
@@ -887,47 +1033,6 @@ namespace FineUIPro.Web.HJGL.WeldingManage
// Alert.ShowInTop("请选择"PipelinetFirst, MessageBoxIcon.Warning);
//}
}
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
private string GetGridTableHtml(Grid grid)
{
StringBuilder sb = new StringBuilder();
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)
{
if (column.HeaderText != "序号")
{
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("lblNumber") as AspNet.Label).Text;
sb.AppendFormat("<td>{0}</td>", html);
}
//sb.AppendFormat("<td>{0}</td>", html);
}
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
#endregion
#region