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 加载 /// /// 加载页面 /// /// /// 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 listStr = new List(); 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; } /// /// 绑定数据 /// 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("PipelineId")).Select(group => group.First()); var distinctSingleNumber = tb.AsEnumerable().GroupBy(row => row.Field("SingleNumber")).Select(group => group.First()); var backingWelder = tb.AsEnumerable().Where(row => row.Field("BackingWelderCode") != null).GroupBy(row => row.Field("BackingWelderCode")).Select(group => group.First()); var coverWelder = tb.AsEnumerable().Where(row => row.Field("CoverWelderCode") != null).GroupBy(row => row.Field("CoverWelderCode")).Select(group => group.First()); var jotNum = from x in tb.AsEnumerable() group x by new { pipe = x.Field("PipelineId"), jot = x.Field("WeldJointCode"), Size = x.Field("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); } } /// /// 改变索引事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } /// /// 分页下拉选择事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { this.BindGrid(); } #endregion #region 统计按钮事件 /// /// 统计 /// /// /// protected void BtnAnalyse_Click(object sender, EventArgs e) { BindGrid(); } #endregion #region 导出按钮 /// 导出按钮 /// /// /// 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() { ["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);*/ } /// /// 导出方法 /// /// /// //private string GetGridTableHtml(Grid grid) //{ // StringBuilder sb = new StringBuilder(); // grid.PageSize = 500000; // BindGrid(); // sb.Append(""); // sb.Append(""); // sb.Append(""); // foreach (GridColumn column in grid.Columns) // { // sb.AppendFormat("", column.HeaderText); // } // sb.Append(""); // foreach (GridRow row in grid.Rows) // { // sb.Append(""); // 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("", html); // } // sb.Append(""); // } // sb.Append("
{0}
{0}
"); // return sb.ToString(); //} #endregion #region 格式化字符串 /// /// 是否热处理 /// /// /// protected string ConvertIsHotProess(object isHotProess) { if (isHotProess != null) { if (isHotProess.ToString() == "True") { return Resources.Lan.Yes; } else { return Resources.Lan.No; } } return null; } /// /// 是否点口 /// /// /// 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 } }