namespace FineUIPro.Web.HJGL.WeldingReport { using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Text; using BLL; using Newtonsoft.Json.Linq; using AspNet = System.Web.UI.WebControls; public partial class WelderPerformance : PageBase { #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); var pUnit = BLL.Base_UnitService.GetUnitsByProjectUnitType(this.drpProject.SelectedValue, BLL.Const.UnitType_4); ///单位 this.drpUnit.DataTextField = "UnitName"; this.drpUnit.DataValueField = "UnitId"; this.drpUnit.DataSource = pUnit; this.drpUnit.DataBind(); Funs.FineUIPleaseSelect(this.drpUnit); ///项目 this.drpProject.DataTextField = "ProjectCode"; this.drpProject.DataValueField = "ProjectId"; this.drpProject.DataSource = BLL.Base_ProjectService.GetProjectListByUserId(this.CurrUser.UserId, "1"); this.drpProject.DataBind(); Funs.FineUIPleaseSelect(this.drpProject); Funs.FineUIPleaseSelect(this.drpWloName); ////材质 this.drpSteel.DataTextField = "STE_Code"; this.drpSteel.DataValueField = "STE_ID"; this.drpSteel.DataSource = BLL.HJGL_MaterialService.GetSteelList(); this.drpSteel.DataBind(); Funs.FineUIPleaseSelect(this.drpSteel); } } #endregion /// /// 全部行合计 /// private void OutputSummaryData() { if (tb != null) { double totalSize = 0.0f; int totalJoint = 0; int JointNum1 = 0; int totalfilm = 0; int JointPassNum1 = 0; int totalPassfilm = 0; int RepairJoint1 = 0; int repairFilm1 = 0; int RepairJoint2 = 0; int repairFilm2 = 0; int RepairJoint3 = 0; int repairFilm3 = 0; string filmPassRate = ""; string jointPassRate = ""; foreach (DataRow row in tb.Rows) { totalSize += Convert.ToDouble(row["totalSize"]); totalJoint += Convert.ToInt32(row["totalJoint"]); JointNum1 += Convert.ToInt32(row["JointNum1"]); totalfilm += Convert.ToInt32(row["totalfilm"]); JointPassNum1 += Convert.ToInt32(row["JointPassNum1"]); totalPassfilm += Convert.ToInt32(row["totalPassfilm"]); RepairJoint1 += Convert.ToInt32(row["RepairJoint1"]); repairFilm1 += Convert.ToInt32(row["repairFilm1"]); RepairJoint2 += Convert.ToInt32(row["RepairJoint2"]); repairFilm2 += Convert.ToInt32(row["repairFilm2"]); RepairJoint3 += Convert.ToInt32(row["RepairJoint3"]); repairFilm3 += Convert.ToInt32(row["repairFilm3"]); } if (totalfilm != 0) { filmPassRate = (totalPassfilm * 100.0 / totalfilm * 1.0).ToString("0.00") + "%"; } if (JointNum1 != 0) { jointPassRate = (JointPassNum1 * 100.0 / JointNum1 * 1.0).ToString("0.00") + "%"; } JObject summary = new JObject(); summary.Add("tfNumber", "合计"); summary.Add("totalJoint", totalJoint.ToString()); summary.Add("totalSize", totalSize.ToString("F2")); summary.Add("JointNum1", JointNum1.ToString()); summary.Add("totalfilm", totalfilm.ToString()); summary.Add("JointPassNum1", JointPassNum1.ToString()); summary.Add("totalPassfilm", totalPassfilm.ToString()); summary.Add("RepairJoint1", RepairJoint1.ToString()); summary.Add("repairFilm1", repairFilm1.ToString()); summary.Add("RepairJoint2", RepairJoint2.ToString()); summary.Add("repairFilm2", repairFilm2.ToString()); summary.Add("RepairJoint3", RepairJoint3.ToString()); summary.Add("repairFilm3", repairFilm3.ToString()); summary.Add("JointPassRate", jointPassRate.ToString()); summary.Add("JointFilmPassRate", filmPassRate.ToString()); Grid1.SummaryData = summary; } } /// /// 数据表 /// private DataTable tb = null; #region 绑定数据 /// /// 绑定数据 /// private void BindGrid() { string projectIds = String.Join(",", drpProject.SelectedValueArray); List listStr = new List(); if (this.drpIns.SelectedValue != BLL.Const._Null) { listStr.Add(new SqlParameter("@installationId", this.drpIns.SelectedValue)); } else { listStr.Add(new SqlParameter("@installationId", null)); } if (this.drpUnit.SelectedValue != BLL.Const._Null) { listStr.Add(new SqlParameter("@unitcode", this.drpUnit.SelectedValue)); } else { listStr.Add(new SqlParameter("@unitcode", null)); } if (this.drpSteel.SelectedValue != BLL.Const._Null) { listStr.Add(new SqlParameter("@steel", this.drpSteel.SelectedValue)); } else { listStr.Add(new SqlParameter("@steel", null)); } if (this.drpWloName.SelectedValue != BLL.Const._Null) { listStr.Add(new SqlParameter("@WED_ID", this.drpWloName.SelectedValue)); } else { listStr.Add(new SqlParameter("@WED_ID", null)); } if (!string.IsNullOrEmpty(this.txtStarTime.Text)) { listStr.Add(new SqlParameter("@date1", Convert.ToDateTime(this.txtStarTime.Text))); } else { listStr.Add(new SqlParameter("@date1", null)); } if (!string.IsNullOrEmpty(this.txtEndTime.Text)) { listStr.Add(new SqlParameter("@date2", Convert.ToDateTime(this.txtEndTime.Text))); } else { listStr.Add(new SqlParameter("@date2", null)); } if (this.drpProject.SelectedValueArray.Length > 0 && this.drpProject.SelectedValueArray[0] != BLL.Const._Null) { listStr.Add(new SqlParameter("@projectId", projectIds)); } else { listStr.Add(new SqlParameter("@projectId", null)); } SqlParameter[] parameter = listStr.ToArray(); tb = SQLHelper.GetDataTableRunProc("HJGL_sp_rpt_welderPerformance", parameter); this.Grid1.RecordCount = tb.Rows.Count; tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #endregion #region 分页 /// /// 分页 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { this.BindGrid(); } /// /// 分页显示条数下拉框 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { this.Grid1.PageSize = Convert.ToInt32(this.ddlPageSize.SelectedValue); this.BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { this.BindGrid(); } #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(); 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; } sb.AppendFormat("", html); } sb.Append(""); } sb.Append("
{0}
{0}
"); return sb.ToString(); } #endregion #region 下拉框联动事件 /// /// 项目下拉框变化事件 /// /// /// protected void drpProject_OnSelectedIndexChanged(object sender, EventArgs e) { drpIns.Items.Clear(); this.drpUnit.Items.Clear(); ///单位 this.drpWloName.Items.Clear(); ///焊工 if (drpProject.SelectedValueArray.Length > 1) { drpProject.Items[0].Selected = false; } if (drpProject.SelectedValueArray.Length == 0) { drpProject.Items[0].Selected = true; } if (drpProject.SelectedValueArray.Length==1 && this.drpProject.SelectedValueArray[0] != BLL.Const._Null) { var pUnit = BLL.Base_UnitService.GetUnitsByProjectUnitType(drpProject.SelectedValueArray[0], BLL.Const.UnitType_4); this.drpUnit.DataSource = pUnit; this.drpUnit.DataBind(); this.drpIns.Items.Clear(); this.drpIns.DataTextField = "Text"; this.drpIns.DataValueField = "Value"; this.drpIns.DataSource = BLL.Project_InstallationService.GetInstallationList(drpProject.SelectedValueArray[0]); this.drpIns.DataBind(); } Funs.FineUIPleaseSelect(this.drpIns); this.drpIns.SelectedValue = BLL.Const._Null; Funs.FineUIPleaseSelect(this.drpUnit); this.drpUnit.SelectedValue = BLL.Const._Null; Funs.FineUIPleaseSelect(this.drpWloName); this.drpWloName.SelectedValue = BLL.Const._Null; } /// /// 单位下拉框变化事件 /// /// /// protected void drpUnit_OnSelectedIndexChanged(object sender, EventArgs e) { this.drpWloName.Items.Clear(); ///焊工 if (this.drpUnit.SelectedValue != BLL.Const._Null) { this.drpWloName.DataTextField = "Text"; this.drpWloName.DataValueField = "Value"; this.drpWloName.DataSource = BLL.HJGL_PersonManageService.GetProjectWelderCodeListByUnitId(this.drpProject.SelectedValue, this.drpUnit.SelectedValue); this.drpWloName.DataBind(); } Funs.FineUIPleaseSelect(this.drpWloName); this.drpWloName.SelectedValue = BLL.Const._Null; } #endregion } }