ChengDa_English/SGGL/FineUIPro.Web/HJGL/WeldingReport/JointComprehensive.aspx.cs

396 lines
18 KiB
C#
Raw 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 System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using AspNet = System.Web.UI.WebControls;
using System.Linq;
using System.IO;
using NPOI.XSSF.UserModel;
using NPOI.SS.UserModel;
using System.Threading;
namespace FineUIPro.Web.HJGL.WeldingReport
{
public partial class JointComprehensive : PageBase
{
public static int percent { get; set; }
public static string url { get; set; }
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
percent = 0;
url = "";
Funs.DropDownPageSize(this.ddlPageSize);
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
//单位
// var unit = BLL.UnitService.GetUnitByUnitId(this.CurrUser.UnitId);
// if (unit != null && unit.UnitTypeId == BLL.Const.ProjectUnitType_2)
if (this.CurrUser.UnitId != Const.UnitId_CD && this.CurrUser.UnitId != Const.hfnbdId)
{
BLL.WorkAreaService.InitWorkAreaProjectUnitDropDownList(this.drpWorkArea, this.CurrUser.LoginProjectId, this.CurrUser.UnitId, true);
}
else
{
var supervisonUnit = BLL.WorkAreaService.IsSupervisor(this.CurrUser.UnitId, this.CurrUser.LoginProjectId);
if (supervisonUnit)
{
BLL.WorkAreaService.InitWorkAreaProjectUnitDropDownList(this.drpWorkArea, this.CurrUser.LoginProjectId, this.CurrUser.UnitId, true);
}
else
{
BLL.WorkAreaService.InitWorkAreaByProjectId(this.drpWorkArea, this.CurrUser.LoginProjectId, true);
}
}
BindGrid();
}
}
#endregion
#region BindGrid
/// <summary>
///
/// </summary>
private DataTable tb = null;
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
string strSql = @"SELECT *"
+ @" FROM V_JOINTVIEW WHERE 1=1 ";
List<SqlParameter> listStr = new List<SqlParameter>();
strSql += " AND ProjectId = @ProjectId";
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
if (this.drpWorkArea.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpWorkArea.SelectedValue))
{
strSql += " AND WorkAreaId =@workareaId";
listStr.Add(new SqlParameter("@workareaId", this.drpWorkArea.SelectedValue));
}
if (this.CurrUser.UnitId!=Const.UnitId_CD&&this.CurrUser.UserId!=Const.hfnbdId)
{
strSql += " AND UnitId = @UnitId";
listStr.Add(new SqlParameter("@UnitId", this.CurrUser.UnitId));
}
if (!string.IsNullOrEmpty(this.txtJointDesc.Text.Trim()))
{
strSql += " AND JOT_JointDesc LIKE @JOT_JointDesc";
listStr.Add(new SqlParameter("@JOT_JointDesc", "%" + this.txtJointDesc.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(this.txtIsoNo.Text.Trim()))
{
strSql += " AND ISO_ISONO LIKE @isoNo";
listStr.Add(new SqlParameter("@isoNo", "%" + this.txtIsoNo.Text.Trim() + "%"));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
/// <summary>
/// 改变索引事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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();
}
#endregion
#region
protected void btnOut_Click(object sender, EventArgs e)
{
percent = 0;
url = "";
string strSql = @"SELECT *"
+ @" FROM V_JOINTVIEW WHERE ";
List<SqlParameter> listStr = new List<SqlParameter>();
strSql += " ProjectId = @ProjectId";
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
if (this.drpWorkArea.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpWorkArea.SelectedValue))
{
strSql += " AND WorkAreaId =@workareaId";
listStr.Add(new SqlParameter("@workareaId", this.drpWorkArea.SelectedValue));
}
if (this.CurrUser.UnitId != Const.UnitId_CD && this.CurrUser.UserId != Const.hfnbdId)
{
strSql += " AND UnitId = @UnitId";
listStr.Add(new SqlParameter("@UnitId", this.CurrUser.UnitId));
}
if (!string.IsNullOrEmpty(this.txtJointDesc.Text.Trim()))
{
strSql += " AND JOT_JointDesc LIKE @JOT_JointDesc";
listStr.Add(new SqlParameter("@JOT_JointDesc", "%" + this.txtJointDesc.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(this.txtIsoNo.Text.Trim()))
{
strSql += " AND ISO_ISONO LIKE @isoNo";
listStr.Add(new SqlParameter("@isoNo", "%" + this.txtIsoNo.Text.Trim() + "%"));
}
Thread t = new Thread(new ThreadStart(() => { btnOut(strSql, listStr.ToArray()); }));
t.Start();
PageContext.RegisterStartupScript("printX()");
}
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut(string strSql, SqlParameter[] parameter)
{
//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();
// SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
string rootPath = Server.MapPath("~/") + Const.ExcelUrl;
//模板文件
string TempletFileName = Server.MapPath("~/") + "File/Excel/HJGL_DataOut/焊口综合信息.xlsx";
//导出文件
string filePath = rootPath + DateTime.Now.ToString("yyyyMMddhhmmss") + "\\";
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
string ReportFileName = filePath + "焊口综合信息" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xlsx";
FileStream file = new FileStream(TempletFileName, FileMode.Open, FileAccess.Read);
XSSFWorkbook hssfworkbook = new XSSFWorkbook(file);
ICellStyle styleCenter = hssfworkbook.CreateCellStyle();
styleCenter.VerticalAlignment = VerticalAlignment.Center;
styleCenter.Alignment = HorizontalAlignment.Center;
styleCenter.BorderLeft = BorderStyle.Thin;
styleCenter.BorderTop = BorderStyle.Thin;
styleCenter.BorderRight = BorderStyle.Thin;
styleCenter.BorderBottom = BorderStyle.Thin;
styleCenter.WrapText = true;
IFont font = styleCenter.GetFont(hssfworkbook);
font.Color = 10;//颜色
font.FontHeightInPoints = 10;//字体高度与excel中的字号一致
styleCenter.SetFont(font);
XSSFSheet recordSheet = (XSSFSheet)hssfworkbook.GetSheet("焊口综合信息");
// recordSheet.AddMergedRegion(new CellRangeAddress(0, 0, 8, 9));
for (int i = 1; i <= tb.Rows.Count; i++)
{
try
{
var row = recordSheet.CreateRow(i);
row.CreateCell(0).SetCellValue("" + i);
row.CreateCell(1).SetCellValue(tb.Rows[i]["WorkAreaCode"] != DBNull.Value ? tb.Rows[i]["WorkAreaCode"].ToString() : "");
row.CreateCell(2).SetCellValue(tb.Rows[i]["ISO_ISONO"] != DBNull.Value ? tb.Rows[i]["ISO_ISONO"].ToString() : "");
row.CreateCell(3).SetCellValue(tb.Rows[i]["JOT_BelongPipe"] != DBNull.Value ? tb.Rows[i]["JOT_BelongPipe"].ToString() : "");
row.CreateCell(4).SetCellValue(tb.Rows[i]["JOT_JointNo"] != DBNull.Value ? tb.Rows[i]["JOT_JointNo"].ToString() : "");
row.CreateCell(5).SetCellValue(tb.Rows[i]["JOT_Dia"] != DBNull.Value ? ((decimal)tb.Rows[i]["JOT_Dia"]).ToString("##.#") : "");
row.CreateCell(6).SetCellValue(tb.Rows[i]["JOT_Sch"] != DBNull.Value ? tb.Rows[i]["JOT_Sch"].ToString() : "");
row.CreateCell(7).SetCellValue(tb.Rows[i]["JOT_FactSch"] != DBNull.Value ? tb.Rows[i]["JOT_FactSch"].ToString() : "");
row.CreateCell(8).SetCellValue(tb.Rows[i]["MetalType"] != DBNull.Value ? tb.Rows[i]["MetalType"].ToString() : "");
row.CreateCell(9).SetCellValue(tb.Rows[i]["JOT_CellWelder"] != DBNull.Value ? tb.Rows[i]["JOT_CellWelder"].ToString() : "");
row.CreateCell(10).SetCellValue(tb.Rows[i]["JOT_FloorWelder"] != DBNull.Value ? tb.Rows[i]["JOT_FloorWelder"].ToString() : "");
row.CreateCell(11).SetCellValue(tb.Rows[i]["WeldingMethodName"] != DBNull.Value ? tb.Rows[i]["WeldingMethodName"].ToString() : "");
row.CreateCell(12).SetCellValue(tb.Rows[i]["DetectionRate"] != DBNull.Value ? tb.Rows[i]["DetectionRate"].ToString() : "");
row.CreateCell(13).SetCellValue(tb.Rows[i]["SER_NAME"] != DBNull.Value ? tb.Rows[i]["SER_NAME"].ToString() : "");
row.CreateCell(14).SetCellValue(tb.Rows[i]["JOT_WeldDate"] != DBNull.Value ? ((DateTime)tb.Rows[i]["JOT_WeldDate"]).ToString("yyyy-MM-dd") : "");
row.CreateCell(15).SetCellValue(tb.Rows[i]["JOT_DailyReportNo"] != DBNull.Value ? tb.Rows[i]["JOT_DailyReportNo"].ToString() : "");
row.CreateCell(16).SetCellValue(tb.Rows[i]["CH_TRUSTCODE1"] != DBNull.Value ? tb.Rows[i]["CH_TRUSTCODE1"].ToString() : "");
row.CreateCell(17).SetCellValue(tb.Rows[i]["ProessName"] != DBNull.Value ? tb.Rows[i]["ProessName"].ToString() : "");
row.CreateCell(18).SetCellValue(tb.Rows[i]["JOT_HotRpt"] != DBNull.Value ? tb.Rows[i]["JOT_HotRpt"].ToString() : "");
row.CreateCell(19).SetCellValue(tb.Rows[i]["CHT_CHECKDATE"] != DBNull.Value ? ((DateTime)tb.Rows[i]["CHT_CHECKDATE"]).ToString("yyyy-MM-dd") : "");
row.CreateCell(20).SetCellValue(tb.Rows[i]["JOT_Size"] != DBNull.Value ? tb.Rows[i]["JOT_Size"].ToString() : "");
row.CreateCell(21).SetCellValue(tb.Rows[i]["WMT_MatCode"] != DBNull.Value ? tb.Rows[i]["WMT_MatCode"].ToString() : "");
row.CreateCell(22).SetCellValue(tb.Rows[i]["WMT_Matname"] != DBNull.Value ? tb.Rows[i]["WMT_Matname"].ToString() : "");
row.CreateCell(23).SetCellValue(tb.Rows[i]["HsCode"] != DBNull.Value ? tb.Rows[i]["HsCode"].ToString() : "");
row.CreateCell(24).SetCellValue(tb.Rows[i]["Hsname"] != DBNull.Value ? tb.Rows[i]["Hsname"].ToString() : "");
row.CreateCell(25).SetCellValue(tb.Rows[i]["JOT_JointDesc"] != DBNull.Value ? tb.Rows[i]["JOT_JointDesc"].ToString() : "");
row.CreateCell(26).SetCellValue(tb.Rows[i]["If_dkName"] != DBNull.Value ? tb.Rows[i]["If_dkName"].ToString() : "");
row.CreateCell(27).SetCellValue(tb.Rows[i]["HotHardCode"] != DBNull.Value ? tb.Rows[i]["HotHardCode"].ToString() : "");
row.CreateCell(28).SetCellValue(tb.Rows[i]["HotHardDate"] != DBNull.Value ? ((DateTime)tb.Rows[i]["HotHardDate"]).ToString("yyyy-MM-dd") : "");
if ((int)(90 * i / tb.Rows.Count) > percent)
{
percent = (int)(90 * i / tb.Rows.Count);
}
}
catch (Exception)
{
}
}
using (FileStream filess = File.OpenWrite(ReportFileName))
{
hssfworkbook.Write(filess);
hssfworkbook.Close();
filess.Flush();
filess.Close();
}
//PageContext.RegisterStartupScript(Window5.GetShowReference(String.Format("../../ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId={3}", BLL.Const.HJGL_JointInfoReportId, isoId, varValue, this.CurrUser.LoginProjectId)));
percent = 100;
url = ReportFileName.Replace(Server.MapPath("~/"),"");
//
//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();
}
[System.Web.Services.WebMethod]
public static int getPercent()
{
return percent;
}
[System.Web.Services.WebMethod]
public static string getUrl()
{
return url;
}
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
private string GetGridTableHtml(Grid grid)
{
StringBuilder sb = new StringBuilder();
grid.PageSize = this.Grid1.RecordCount;
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 style=\"vnd.ms-excel.numberformat:@\" >{0}</td>", html);
}
sb.Append("</tr>");
}
var sumary = grid.SummaryData;
if (sumary != null)
{
foreach (GridColumn column in grid.Columns)
{
try
{
if (sumary.ContainsKey(column.ColumnID))
{
sb.AppendFormat("<td style=\"vnd.ms-excel.numberformat:@\" >{0}</td>", sumary.GetValue(column.ColumnID).ToString());
}
else
{
sb.AppendFormat("<td style=\"vnd.ms-excel.numberformat:@\" >{0}</td>", "");
}
}
catch (Exception e)
{
sb.AppendFormat("<td style=\"vnd.ms-excel.numberformat:@\" >{0}</td>", "");
}
}
}
sb.Append("</table>");
return sb.ToString();
}
#endregion
}
}