Basf_TCC7/HJGL/FineUIPro.Web/WeldingProcess/WeldingReport/PipelineTraceList.aspx.cs

389 lines
14 KiB
C#
Raw Normal View History

2024-10-17 21:46:32 +08:00
using BLL;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NPOI.HSSF.Util;
using NPOI.POIFS.Properties;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System.IO;
using System.Security.Policy;
using System.Threading;
using MiniExcelLibs;
namespace FineUIPro.Web.WeldingProcess.WeldingReport
{
public partial class PipelineTraceList : PageBase
{
public static int percent { get; set; }
public static string url { get; set; }
[System.Web.Services.WebMethod]
public static int getPercent()
{
return percent;
}
[System.Web.Services.WebMethod]
public static string getUrl()
{
return url;
}
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
BLL.Project_WorkAreaService.InitWorkAreaDropDownList(this.drpWorkAreaId, true, this.CurrUser.LoginProjectId, string.Empty, string.Empty, string.Empty, Resources.Lan.PleaseSelect);//区域
}
}
private DataTable GetDataTable()
{
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
if (drpWorkAreaId.SelectedValue != Const._Null && drpWorkAreaId.SelectedValue != null)
{
string[] areaList = drpWorkAreaId.SelectedValueArray;
string workAreaIds = string.Join(",", areaList);
listStr.Add(new SqlParameter("@workAreaIds", workAreaIds));
// listStr.Add(new SqlParameter("@workAreaId", this.drpWorkAreaId.SelectedValue));
}
if (!string.IsNullOrEmpty(drpPipeLine.SelectedValue) && drpPipeLine.SelectedValue != Const._Null)
{
string[] pipeList = drpPipeLine.SelectedValueArray;
string pipeLineIds = string.Join(",", pipeList);
listStr.Add(new SqlParameter("@pipelineIds", pipeLineIds));
}
else
{
listStr.Add(new SqlParameter("@pipelineIds", null));
}
if (!string.IsNullOrEmpty(txtTestPackageNo.Text.Trim()))
{
listStr.Add(new SqlParameter("@TestPackageNo", '%'+txtTestPackageNo.Text.Trim()+"%"));
}
else
{
listStr.Add(new SqlParameter("@TestPackageNo", null));
}
//if (!string.IsNullOrEmpty(this.drpWorkAreaId.Text.Trim()))
//{
// listStr.Add(new SqlParameter("@pipelineCode", this.txtPipelineCode.Text.Trim()));
//}
//else
//{
// listStr.Add(new SqlParameter("@pipelineCode", null));
//}
SqlParameter[] parameter = listStr.ToArray();
DataTable dt = SQLHelper.GetDataTableRunProc("sp_rpt_JointComprehensive", parameter);
return dt;
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
DataTable tb = GetDataTable();
this.Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
var distinctPipelineCode = tb.AsEnumerable().GroupBy(row => row.Field<string>("PipelineId")).Select(group => group.First());
var distinctSingleNumber = tb.AsEnumerable().GroupBy(row => row.Field<string>("SingleNumber")).Select(group => group.First());
var backingWelder = tb.AsEnumerable().Where(row => row.Field<string>("BackingWelderCode") != null).GroupBy(row => row.Field<string>("BackingWelderCode")).Select(group => group.First());
var coverWelder = tb.AsEnumerable().Where(row => row.Field<string>("CoverWelderCode") != null).GroupBy(row => row.Field<string>("CoverWelderCode")).Select(group => group.First());
var jotNum = from x in tb.AsEnumerable()
group x by new { pipe = x.Field<string>("PipelineId"), jot = x.Field<string>("WeldJointCode"), Size = x.Field<string>("JOT_Size") }
into g
select new { pipe = g.Key.pipe, jot = g.Key.jot, Size = g.Key.Size };
JObject summary = new JObject();
summary.Add("tfNumber", "合计");
summary.Add("SingleNumber", distinctSingleNumber.Count().ToString());
summary.Add("PipelineCode", distinctPipelineCode.Count().ToString());
summary.Add("WeldJointCode", jotNum.Count());
summary.Add("BackingWelderCode", backingWelder.Count().ToString());
summary.Add("CoverWelderCode", coverWelder.Count().ToString());
Grid1.SummaryData = summary;
}
protected void drpWorkAreaId_OnSelectedIndexChanged(object sender, EventArgs e)
{
string[] workAreaIds = drpWorkAreaId.SelectedValueArray;
if (workAreaIds.Length == 1)
{
BLL.Pipeline_PipelineService.InitPipelineDropDownList(drpPipeLine, workAreaIds[0], Resources.Lan.PleaseSelect);
}
}
/// <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
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut_Click(object sender, EventArgs e)
{
percent = 0;
url = "";
Thread t = new Thread(new ThreadStart(() => { Export(); }));
t.Start();
PageContext.RegisterStartupScript("showProcessBar()");
}
private void Export()
{
string templatePath = Funs.RootPath + @"File\Excel\HJGL_DataOut\管道追溯表.xlsx";
string path = Funs.RootPath + @"File\Excel\Temp\管道追溯表.xlsx";
path = path.Replace(".xlsx", string.Format("{0:yyyy-MM-dd-HH-mm}", DateTime.Now) + ".xlsx");
DataTable tb = GetDataTable();
DataColumn dc = null;
dc = tb.Columns.Add("Index", Type.GetType("System.Int32"));
dc = tb.Columns.Add("WeldSilk", Type.GetType("System.String"));
dc = tb.Columns.Add("WeldFlux", Type.GetType("System.String"));
int totalNum = tb.Rows.Count;
var rowIndex = 1;
foreach (DataRow row in tb.Rows)
{
row["Index"] = row.Table.Rows.IndexOf(row) + 1;
row["WeldSilk"] = ConvertWeldSilk(row["WeldSilkId"]);
row["WeldFlux"] = ConvertWeldFlux(row["WeldSilkId"]);
if ((int)(90 * (rowIndex) / totalNum) > percent)
{
percent = (int)(100 * (rowIndex) / totalNum);
}
rowIndex++;
}
tb.TableName = "Data";
var value = new Dictionary<string, object>()
{
["Data"] = tb,
};
MiniExcel.SaveAsByTemplate(path, templatePath, value);
percent = 100;
url = path.Replace(Server.MapPath("~/"), "");
/*string fileName = "管道追溯表.xlsx";
FileInfo info = new FileInfo(path);
long fileSize = info.Length;
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", fileSize.ToString());
System.Web.HttpContext.Current.Response.TransmitFile(path, 0, fileSize);
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.Close();
File.Delete(path);*/
}
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
//private string GetGridTableHtml(Grid grid)
//{
// StringBuilder sb = new StringBuilder();
// grid.PageSize = 500000;
// 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;
// }
// if (column.ColumnID == "tfIsHotProess")
// {
// html = (row.FindControl("lblIsHotProess") as AspNet.Label).Text;
// }
// if (column.ColumnID == "tfif_dk")
// {
// html = (row.FindControl("lblif_dk") as AspNet.Label).Text;
// }
// sb.AppendFormat("<td>{0}</td>", html);
// }
// sb.Append("</tr>");
// }
// sb.Append("</table>");
// return sb.ToString();
//}
#endregion
#region
/// <summary>
/// 是否热处理
/// </summary>
/// <param name="isHotProess"></param>
/// <returns></returns>
protected string ConvertIsHotProess(object isHotProess)
{
if (isHotProess != null)
{
if (isHotProess.ToString() == "True")
{
return Resources.Lan.Yes;
}
else
{
return Resources.Lan.No;
}
}
return null;
}
/// <summary>
/// 是否点口
/// </summary>
/// <param name="if_dk"></param>
/// <returns></returns>
protected string Convertif_dk(object if_dk)
{
if (if_dk != null)
{
if (if_dk.ToString() == "1")
{
return Resources.Lan.Yes;
}
else
{
return Resources.Lan.No;
}
}
return null;
}
protected string ConvertWeldSilk(object WeldSilkId)
{
string weldSilkName = string.Empty;
if (WeldSilkId != null)
{
string[] weldSilkIds = WeldSilkId.ToString().Split(',');
if (weldSilkIds.Count() > 0)
{
foreach (string s in weldSilkIds)
{
var silk = BLL.Base_ConsumablesService.GetConsumablesByConsumablesId(s);
if (silk != null)
{
weldSilkName = weldSilkName + silk.ConsumablesName + ',';
}
}
if (weldSilkName.Length > 0)
{
weldSilkName = weldSilkName.Substring(0, weldSilkName.Length - 1);
}
}
}
return weldSilkName;
}
protected string ConvertWeldFlux(object WeldSilkId)
{
string weldFlux = string.Empty;
string[] weldSilkIds = WeldSilkId.ToString().Split(',');
if (weldSilkIds.Count() > 0)
{
foreach (string s in weldSilkIds)
{
var silk = BLL.Base_ConsumablesService.GetConsumablesByConsumablesId(s);
if (silk != null && !string.IsNullOrEmpty(silk.UserFlux))
{
weldFlux = weldFlux + silk.UserFlux + ',';
}
}
if (weldFlux.Length > 0)
{
weldFlux = weldFlux.Substring(0, weldFlux.Length - 1);
}
}
return weldFlux;
}
#endregion
}
}