using BLL; using FineUIPro.Web.Controls; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Text; using AspNet = System.Web.UI.WebControls; namespace FineUIPro.Web.HJGL.WeldingReport { public partial class FilmJointStatistics : PageBase { #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Funs.DropDownPageSize(this.ddlPageSize); this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); BLL.UnitService.InitUnitByProjectIdUnitTypeDropDownList(this.drpUnitId, this.CurrUser.LoginProjectId, BLL.Const.ProjectUnitType_2, true); Funs.FineUIPleaseSelect(this.drpWorkArea); } } #endregion #region 绑定BindGrid /// /// /// private DataTable tb = null; /// /// 绑定数据 /// private void BindGrid() { List listStr = new List { new SqlParameter("@projectId", this.CurrUser.LoginProjectId) }; if (this.drpUnitId.SelectedValue != BLL.Const._Null) { listStr.Add(new SqlParameter("@unitId", this.drpUnitId.SelectedValue)); } else { listStr.Add(new SqlParameter("@unitId", null)); } if (this.drpWorkArea.SelectedValue != BLL.Const._Null) { listStr.Add(new SqlParameter("@workAreaId", this.drpWorkArea.SelectedValue)); } else { listStr.Add(new SqlParameter("@workAreaId", null)); } SqlParameter[] parameter = listStr.ToArray(); tb = SQLHelper.GetDataTableRunProc("sp_rpt_FilmJointStatistics", parameter); this.Grid1.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid1, tb); table.Columns.Add("pt_jot"); foreach(DataRow row in table.Rows) { int pt_jot = 0; try { pt_jot += int.Parse(row["five_pt_jot"].ToString()); } catch (Exception e) { } try { pt_jot += int.Parse(row["ten_pt_jot"].ToString()); } catch (Exception e) { } try { pt_jot += int.Parse(row["twenty_pt_jot"].ToString()); } catch (Exception e) { } try { pt_jot += int.Parse(row["onHundred_pt_jot"].ToString()); } catch (Exception e) { } row["pt_jot"] = pt_jot; } Grid1.DataSource = table; Grid1.DataBind(); } /// /// 改变索引事件 /// /// /// 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 OutputSummaryData() { if (tb != null) { int total_jot = 0;//焊口数 decimal total_size = 0;//吋 int five_bw_jot = 0;//5% 对接焊口(道) int five_extract_jot = 0;//5% 抽拍数(道) int five_fw_jot = 0;//5% 角焊缝焊口数 int five_pt_jot = 0;//5% PT(道) int ten_bw_jot = 0;//10% 对接焊口(道) int ten_extract_jot = 0;//10% 抽拍数(道) int ten_fw_jot = 0;//10% 角焊缝焊口数 int ten_pt_jot = 0;//10% PT(道) int twenty_bw_jot = 0; //20% 对接焊口(道) int twenty_extract_jot = 0; //20% 抽拍数(道) int twenty_fw_jot = 0; //20% 角焊缝焊口数 int twenty_pt_jot = 0;//20% PT(道) int onHundred_bw_jot = 0; //100% 对接焊口(道) int onHundred_extract_jot = 0;//100% 抽拍数(道) int onHundred_fw_jot = 0;//100% 角焊缝焊口数 int onHundred_pt_jot = 0;//100% PT(道) int estimate_check_film = 0;//估计检测拍片数量(6张) foreach (DataRow row in tb.Rows) { total_jot += Funs.GetNewIntOrZero(row["total_jot"].ToString()); total_size += Funs.GetNewDecimalOrZero(row["total_size"].ToString()); five_bw_jot += Funs.GetNewIntOrZero(row["five_bw_jot"].ToString()); five_extract_jot += Funs.GetNewIntOrZero(row["five_extract_jot"].ToString()); five_fw_jot += Funs.GetNewIntOrZero(row["five_fw_jot"].ToString()); five_pt_jot += Funs.GetNewIntOrZero(row["five_pt_jot"].ToString()); ten_bw_jot += Funs.GetNewIntOrZero(row["ten_bw_jot"].ToString()); ten_extract_jot += Funs.GetNewIntOrZero(row["ten_extract_jot"].ToString()); ten_fw_jot += Funs.GetNewIntOrZero(row["ten_fw_jot"].ToString()); ten_pt_jot += Funs.GetNewIntOrZero(row["ten_pt_jot"].ToString()); twenty_bw_jot += Funs.GetNewIntOrZero(row["twenty_bw_jot"].ToString()); twenty_extract_jot += Funs.GetNewIntOrZero(row["twenty_extract_jot"].ToString()); twenty_fw_jot += Funs.GetNewIntOrZero(row["twenty_fw_jot"].ToString()); twenty_pt_jot += Funs.GetNewIntOrZero(row["twenty_pt_jot"].ToString()); onHundred_bw_jot += Funs.GetNewIntOrZero(row["onHundred_bw_jot"].ToString()); onHundred_extract_jot += Funs.GetNewIntOrZero(row["onHundred_extract_jot"].ToString()); onHundred_fw_jot += Funs.GetNewIntOrZero(row["onHundred_fw_jot"].ToString()); onHundred_pt_jot += Funs.GetNewIntOrZero(row["onHundred_pt_jot"].ToString()); estimate_check_film += Funs.GetNewIntOrZero(row["estimate_check_film"].ToString()); } JObject summary = new JObject { { "WorkAreaCode", "合计:" }, { "total_jot", total_jot }, {"total_size",total_size }, {"five_bw_jot",five_bw_jot }, {"five_extract_jot",five_extract_jot }, {"five_fw_jot",five_fw_jot }, {"five_pt_jot",five_pt_jot }, {"ten_bw_jot",ten_bw_jot }, {"ten_extract_jot",ten_extract_jot }, {"ten_fw_jot",ten_fw_jot }, {"ten_pt_jot",ten_pt_jot }, {"twenty_bw_jot",twenty_bw_jot }, {"twenty_extract_jot",twenty_extract_jot }, {"twenty_fw_jot",twenty_fw_jot }, {"twenty_pt_jot",twenty_pt_jot }, {"onHundred_bw_jot",onHundred_bw_jot }, {"onHundred_extract_jot",onHundred_extract_jot }, {"onHundred_fw_jot",onHundred_fw_jot }, {"onHundred_pt_jot",onHundred_pt_jot }, {"estimate_check_film",estimate_check_film } }; Grid1.SummaryData = summary; } } #endregion #region 统计按钮事件 /// /// 统计 /// /// /// protected void BtnAnalyse_Click(object sender, EventArgs e) { BindGrid(); OutputSummaryData(); } #endregion #region 导出按钮 /// 导出按钮 /// /// /// protected void btnOut_Click(object sender, EventArgs e) { 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(); } /// /// 导出方法 /// /// /// private string GetGridTableHtml(Grid grid) { StringBuilder sb = new StringBuilder(); grid.PageSize = this.Grid1.RecordCount; BindGrid(); MultiHeaderTable mht = new MultiHeaderTable(); mht.ResolveMultiHeaderTable(Grid1.Columns); sb.Append(""); sb.Append(""); foreach (List rows in mht.MultiTable) { sb.Append(""); foreach (object[] cell in rows) { int rowspan = Convert.ToInt32(cell[0]); int colspan = Convert.ToInt32(cell[1]); GridColumn column = cell[2] as GridColumn; if (!column.Hidden) { sb.AppendFormat("{3}", rowspan != 1 ? " rowspan=\"" + rowspan + "\"" : "", colspan != 1 ? " colspan=\"" + colspan + "\"" : "", colspan != 1 ? " style=\"text-align:center;\"" : "", column.HeaderText); } } sb.Append(""); } int j = 0; foreach (GridRow row in grid.Rows) { sb.Append(""); int i = 0; foreach (GridColumn column in mht.Columns) { string html = row.Values[column.ColumnIndex].ToString(); if (column.ColumnID == "tfNumber") { html = (row.FindControl("labNumber") as AspNet.Label).Text; } sb.AppendFormat("", html); i++; } j++; sb.Append(""); } var sumary = grid.SummaryData; if (sumary != null) { sb.Append(""); foreach (GridColumn column in grid.Columns) { try { if (column is GroupField) { if (((GroupField)column).Columns != null) { foreach (var item in ((GroupField)column).Columns) { if (sumary.ContainsKey(item.ColumnID)) { sb.AppendFormat("", sumary.GetValue(item.ColumnID).ToString()); } else { sb.AppendFormat("", ""); } } } } else if (column is RenderField) { if (sumary.ContainsKey(column.ColumnID)) { sb.AppendFormat("", sumary.GetValue(column.ColumnID).ToString()); } else { sb.AppendFormat("", ""); } } else { sb.AppendFormat("", ""); } } catch (Exception e) { sb.AppendFormat("", ""); } } sb.Append(""); } sb.Append("
{0}
{0}{0}{0}{0}{0}{0}
"); return sb.ToString(); } #endregion #region 下拉选择事件 /// /// 单位下拉选择事件 /// /// /// < param name="e"> protected void drpUnitId_SelectedIndexChanged(object sender, EventArgs e) { this.drpWorkArea.Items.Clear(); ///区域 if (this.drpUnitId.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpUnitId.SelectedValue)) { BLL.WorkAreaService.InitWorkAreaProjectUnitDropDownList(this.drpWorkArea, this.CurrUser.LoginProjectId, this.drpUnitId.SelectedValue, true); } else { Funs.FineUIPleaseSelect(this.drpWorkArea); } this.drpWorkArea.SelectedIndex = 0; } #endregion } }