11
This commit is contained in:
@@ -30,8 +30,8 @@
|
||||
</f:Button>
|
||||
<f:Button ID="btnDownLoad" runat="server" Text="下载模板" Icon="ApplicationGo" ToolTip="下载模板" OnClick="btnDownLoad_Click">
|
||||
</f:Button>
|
||||
<%--<f:Button ID="btnOut" Icon="Pencil" runat="server" Text="导出" ToolTip="导出错误列表" ValidateForms="SimpleForm1"
|
||||
OnClick="btnOut_Click" Hidden="true"></f:Button>--%>
|
||||
<f:Button ID="btnOut" Icon="Pencil" runat="server" Text="导出" ToolTip="导出错误列表"
|
||||
EnableAjax="false" DisableControlBeforePostBack="false" OnClick="btnOut_Click" ></f:Button>
|
||||
</Items>
|
||||
</f:Toolbar>
|
||||
</Toolbars>
|
||||
@@ -63,7 +63,7 @@
|
||||
<f:FormRow>
|
||||
<Items>
|
||||
<f:Grid ID="Grid1" ShowBorder="true" Hidden="true" ShowHeader="false" Title="委托单导入错误日志" runat="server" EnableCollapse="false"
|
||||
DataKeyNames="ID" PageSize="100" AllowPaging="true">
|
||||
DataKeyNames="ID" PageSize="100" AllowPaging="true" Height="560px">
|
||||
<Columns>
|
||||
<f:RowNumberField />
|
||||
<f:RenderField ColumnID="RowID" Width="80px" DataField="RowID" HeaderText="行号" />
|
||||
@@ -77,7 +77,7 @@
|
||||
<f:RenderField ColumnID="UnitCode" MinWidth="80" DataField="UnitCode" HeaderText="检测单位编号" />
|
||||
<f:RenderField ColumnID="SurfaceState" MinWidth="80" DataField="SurfaceState" HeaderText="表面状态" />
|
||||
<f:RenderField ColumnID="Opportunity" MinWidth="80" DataField="Opportunity" HeaderText="检测时机" />
|
||||
<f:TemplateField HeaderText="错误原因" MinWidth="500">
|
||||
<f:TemplateField HeaderText="错误原因" MinWidth="500" ColumnID="Remark">
|
||||
<ItemTemplate>
|
||||
<asp:Label ID="lablRemark" runat="server" Text='<%#Eval("Remark") %>' ForeColor="Red"></asp:Label>
|
||||
</ItemTemplate>
|
||||
|
||||
@@ -4,11 +4,14 @@ using System.Data;
|
||||
using System.Data.OleDb;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web.UI;
|
||||
using BLL;
|
||||
using FineUIPro.Web.common.ProjectSet;
|
||||
using FineUIPro.Web.Common.ProjectSet;
|
||||
using AspNet = System.Web.UI.WebControls;
|
||||
using Model;
|
||||
using NPOI.HSSF.Util;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
|
||||
namespace FineUIPro.Web.WeldingProcess.TrustManage
|
||||
{
|
||||
@@ -24,6 +27,19 @@ namespace FineUIPro.Web.WeldingProcess.TrustManage
|
||||
/// 错误集合
|
||||
/// </summary>
|
||||
public static string errorInfos = string.Empty;
|
||||
|
||||
public string BatchCode
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)ViewState["BatchCode"];
|
||||
}
|
||||
set
|
||||
{
|
||||
ViewState["BatchCode"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 加载页面
|
||||
@@ -98,6 +114,7 @@ namespace FineUIPro.Web.WeldingProcess.TrustManage
|
||||
var pipeList = from x in Funs.DB.Pipeline_Pipeline where x.ProjectId == this.CurrUser.LoginProjectId select x;
|
||||
List<Model.TrustBatchImportErrorLog> logListData = new List<Model.TrustBatchImportErrorLog>();
|
||||
string BatchNo = DateTime.Now.ToString("yyyyMMddHHmmss");
|
||||
BatchCode = BatchNo;
|
||||
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
|
||||
{
|
||||
string result = string.Empty;
|
||||
@@ -376,7 +393,7 @@ namespace FineUIPro.Web.WeldingProcess.TrustManage
|
||||
|
||||
|
||||
}
|
||||
void BindGrid1(string batchNo)
|
||||
private void BindGrid1(string batchNo)
|
||||
{
|
||||
var result = Funs.DB.TrustBatchImportErrorLog.Where(t => t.BatchNo == batchNo).OrderBy(t => t.RowID).ToList();
|
||||
this.Grid1.DataSource = result;
|
||||
@@ -572,9 +589,182 @@ namespace FineUIPro.Web.WeldingProcess.TrustManage
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
|
||||
protected void btnOut_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
string rootPath = Server.MapPath("~/") + Const.ExcelUrl;
|
||||
//模板文件
|
||||
string TempletFileName = rootPath + "TrustErrorOut.xlsx";
|
||||
//导出文件
|
||||
string filePath = rootPath + DateTime.Now.ToString("yyyyMMddhhmmss") + "\\";
|
||||
if (!Directory.Exists(filePath))
|
||||
{
|
||||
Directory.CreateDirectory(filePath);
|
||||
}
|
||||
string ReportFileName = filePath + "out.xlsx";
|
||||
|
||||
FileStream file = new FileStream(TempletFileName, FileMode.Open, FileAccess.Read);
|
||||
XSSFWorkbook hssfworkbook = new XSSFWorkbook(file);
|
||||
|
||||
#region JointComprehensive
|
||||
XSSFSheet reportModel = (XSSFSheet)hssfworkbook.GetSheet("Sheet1");
|
||||
|
||||
XSSFFont cs_content_Font1 = (XSSFFont)hssfworkbook.CreateFont(); //创建字体
|
||||
cs_content_Font1.FontName = "sans-serif";//字体
|
||||
cs_content_Font1.FontHeightInPoints = 9; //字体大小
|
||||
|
||||
ICellStyle style = hssfworkbook.CreateCellStyle();
|
||||
style.SetFont(cs_content_Font1);
|
||||
|
||||
XSSFFont cs_content_Font = (XSSFFont)hssfworkbook.CreateFont(); //创建字体
|
||||
cs_content_Font.FontName = "sans-serif";//字体
|
||||
cs_content_Font.FontHeightInPoints = 10; //字体大小
|
||||
cs_content_Font.Color = HSSFColor.Red.Index;
|
||||
|
||||
IDataFormat dataformat = hssfworkbook.CreateDataFormat();
|
||||
ICellStyle styleDate = hssfworkbook.CreateCellStyle();
|
||||
styleDate.SetFont(cs_content_Font1);
|
||||
styleDate.DataFormat = dataformat.GetFormat("yyyy-mm-dd");
|
||||
|
||||
// 排序
|
||||
var result = Funs.DB.TrustBatchImportErrorLog.Where(t => t.BatchNo == this.BatchCode).OrderBy(t => t.RowID).ToList();
|
||||
|
||||
if (result.Count > 0)
|
||||
{
|
||||
var rowIndex = 1;
|
||||
foreach (var itemOver in result)
|
||||
{
|
||||
if (reportModel.GetRow(rowIndex) == null) reportModel.CreateRow(rowIndex);
|
||||
|
||||
#region 列赋值
|
||||
//行号
|
||||
if (reportModel.GetRow(rowIndex).GetCell(0) == null) reportModel.GetRow(rowIndex).CreateCell(0);
|
||||
reportModel.GetRow(rowIndex).GetCell(0).SetCellValue(itemOver.RowID.ToString());
|
||||
reportModel.GetRow(rowIndex).GetCell(0).CellStyle = style; //将字体绑定到样式
|
||||
|
||||
//委托单
|
||||
if (reportModel.GetRow(rowIndex).GetCell(1) == null) reportModel.GetRow(rowIndex).CreateCell(1);
|
||||
reportModel.GetRow(rowIndex).GetCell(1).SetCellValue(itemOver.TrustBatchCode);
|
||||
reportModel.GetRow(rowIndex).GetCell(1).CellStyle = style;
|
||||
//装置
|
||||
if (reportModel.GetRow(rowIndex).GetCell(2) == null) reportModel.GetRow(rowIndex).CreateCell(2);
|
||||
reportModel.GetRow(rowIndex).GetCell(2).SetCellValue(itemOver.InstallCode);
|
||||
reportModel.GetRow(rowIndex).GetCell(2).CellStyle = style;
|
||||
//区域
|
||||
if (reportModel.GetRow(rowIndex).GetCell(3) == null) reportModel.GetRow(rowIndex).CreateCell(3);
|
||||
reportModel.GetRow(rowIndex).GetCell(3).SetCellValue(itemOver.AreaCode);
|
||||
reportModel.GetRow(rowIndex).GetCell(3).CellStyle = style;
|
||||
//管线号
|
||||
if (reportModel.GetRow(rowIndex).GetCell(4) == null) reportModel.GetRow(rowIndex).CreateCell(4);
|
||||
reportModel.GetRow(rowIndex).GetCell(4).SetCellValue(itemOver.PipelineCode);
|
||||
reportModel.GetRow(rowIndex).GetCell(4).CellStyle = style;
|
||||
|
||||
//焊口号
|
||||
if (reportModel.GetRow(rowIndex).GetCell(5) == null) reportModel.GetRow(rowIndex).CreateCell(5);
|
||||
reportModel.GetRow(rowIndex).GetCell(5).SetCellValue(itemOver.WeldJointCode);
|
||||
reportModel.GetRow(rowIndex).GetCell(5).CellStyle = style;
|
||||
|
||||
//探伤类型
|
||||
if (reportModel.GetRow(rowIndex).GetCell(6) == null) reportModel.GetRow(rowIndex).CreateCell(6);
|
||||
reportModel.GetRow(rowIndex).GetCell(6).SetCellValue(itemOver.DetectionType);
|
||||
reportModel.GetRow(rowIndex).GetCell(6).CellStyle = style;
|
||||
|
||||
//委托日期
|
||||
if (reportModel.GetRow(rowIndex).GetCell(7) == null) reportModel.GetRow(rowIndex).CreateCell(7);
|
||||
reportModel.GetRow(rowIndex).GetCell(7).SetCellValue(itemOver.TrustDate);
|
||||
reportModel.GetRow(rowIndex).GetCell(7).CellStyle = style;
|
||||
|
||||
//检测单位
|
||||
if (reportModel.GetRow(rowIndex).GetCell(8) == null) reportModel.GetRow(rowIndex).CreateCell(8);
|
||||
reportModel.GetRow(rowIndex).GetCell(8).SetCellValue(itemOver.UnitCode);
|
||||
reportModel.GetRow(rowIndex).GetCell(8).CellStyle = style;
|
||||
//表面
|
||||
if (reportModel.GetRow(rowIndex).GetCell(9) == null) reportModel.GetRow(rowIndex).CreateCell(9);
|
||||
reportModel.GetRow(rowIndex).GetCell(9).SetCellValue(itemOver.SurfaceState);
|
||||
reportModel.GetRow(rowIndex).GetCell(9).CellStyle = style;
|
||||
|
||||
//检测时机
|
||||
if (reportModel.GetRow(rowIndex).GetCell(10) == null) reportModel.GetRow(rowIndex).CreateCell(10);
|
||||
reportModel.GetRow(rowIndex).GetCell(10).SetCellValue(itemOver.Opportunity);
|
||||
reportModel.GetRow(rowIndex).GetCell(10).CellStyle = style;
|
||||
//错误
|
||||
if (reportModel.GetRow(rowIndex).GetCell(11) == null) reportModel.GetRow(rowIndex).CreateCell(11);
|
||||
reportModel.GetRow(rowIndex).GetCell(11).SetCellValue(itemOver.Remark.Replace("|",","));
|
||||
reportModel.GetRow(rowIndex).GetCell(11).CellStyle = style;
|
||||
|
||||
#endregion
|
||||
|
||||
rowIndex++;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
reportModel.ForceFormulaRecalculation = true;
|
||||
|
||||
using (FileStream filess = System.IO.File.OpenWrite(ReportFileName))
|
||||
{
|
||||
hssfworkbook.Write(filess);
|
||||
}
|
||||
FileInfo filet = new FileInfo(ReportFileName);
|
||||
Response.Clear();
|
||||
Response.Charset = "GB2312";
|
||||
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
|
||||
Response.AddHeader("Content-Disposition", "attachment; filename=委托单错误日志_" + Server.UrlEncode(DateTime.Now.ToString("yyyyMMddhhmmss") + ".xlsx"));
|
||||
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
|
||||
Response.AddHeader("Content-Length", filet.Length.ToString());
|
||||
// 指定返回的是一个不能被客户端读取的流,必须被下载
|
||||
Response.ContentType = "application/ms-excel";
|
||||
// 把文件流发送到客户端
|
||||
Response.WriteFile(filet.FullName);
|
||||
// 停止页面的执行
|
||||
Response.End();
|
||||
|
||||
//Response.ClearContent();
|
||||
//string filename = Funs.GetNewFileName();
|
||||
//Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(Resources.Lan.JointComprehensive + filename, System.Text.Encoding.UTF8) + ".xls");
|
||||
//Response.ContentType = "application/excel";
|
||||
//Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
//Response.Write(GetGridTableHtml(Grid1));
|
||||
//Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导出方法
|
||||
/// </summary>
|
||||
/// <param name="grid"></param>
|
||||
/// <returns></returns>
|
||||
private string GetGridTableHtml(Grid grid)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
grid.PageSize = 10000;
|
||||
BindGrid1(this.BatchCode);
|
||||
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 == "Remark")
|
||||
{
|
||||
html = (row.FindControl("lablRemark") as AspNet.Label).Text;
|
||||
}
|
||||
sb.AppendFormat("<td>{0}</td>", html);
|
||||
}
|
||||
|
||||
sb.Append("</tr>");
|
||||
}
|
||||
|
||||
sb.Append("</table>");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -77,6 +77,15 @@ namespace FineUIPro.Web.WeldingProcess.TrustManage
|
||||
/// </remarks>
|
||||
protected global::FineUIPro.Button btnDownLoad;
|
||||
|
||||
/// <summary>
|
||||
/// btnOut 控件。
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 自动生成的字段。
|
||||
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||
/// </remarks>
|
||||
protected global::FineUIPro.Button btnOut;
|
||||
|
||||
/// <summary>
|
||||
/// fuAttachUrl 控件。
|
||||
/// </summary>
|
||||
|
||||
@@ -227,7 +227,7 @@
|
||||
</f:Window>
|
||||
<f:Window ID="Window4" Title="委托单导入" Hidden="true" EnableIFrame="true"
|
||||
EnableMaximize="true" Target="Parent" EnableResize="true" runat="server" IsModal="false" OnClose="Window4_Close"
|
||||
CloseAction="HidePostBack" Width="1200px" Height="640px">
|
||||
CloseAction="HidePostBack" Width="1300px" Height="760px">
|
||||
</f:Window>
|
||||
<f:Menu ID="Menu1" runat="server">
|
||||
<f:MenuButton ID="btnMenuCancel" OnClick="btnMenuCancel_Click" EnablePostBack="true"
|
||||
|
||||
Reference in New Issue
Block a user