using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Data; using BLL; using System.Text; using Newtonsoft.Json.Linq; using AspNet = System.Web.UI.WebControls; namespace FineUIPro.Web.HJGL.WeldingReport { public partial class UnitWorkareaAnalyze : PageBase { #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Funs.DropDownPageSize(this.ddlPageSize); this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); List units = new List(); var pUnit = BLL.ProjectUnitService.GetProjectUnitByUnitIdProjectId(this.CurrUser.LoginProjectId, this.CurrUser.UnitId); if (pUnit == null || pUnit.UnitType == Const.ProjectUnitType_1) { units = BLL.UnitService.GetUnitByProjectIdUnitTypeList(this.CurrUser.LoginProjectId, BLL.Const.ProjectUnitType_2); this.drpUnit.DataTextField = "UnitName"; this.drpUnit.DataValueField = "UnitId"; this.drpUnit.DataSource = units; this.drpUnit.DataBind(); this.drpUnit.SelectedValue = CurrUser.UnitId; Funs.FineUIPleaseSelect(this.drpUnit); Funs.FineUIPleaseSelect(this.drpInstallation); } else { units = BLL.UnitService.GetSubUnitsListBySupervisorUnitId(this.CurrUser.LoginProjectId, this.CurrUser.UnitId); this.drpUnit.Enabled = false; this.drpUnit.DataTextField = "UnitName"; this.drpUnit.DataValueField = "UnitId"; this.drpUnit.DataSource = units; this.drpUnit.DataBind(); this.drpUnit.SelectedValue = CurrUser.UnitId; Project_InstallationService.InitInstallationDropDownList(this.drpInstallation, this.CurrUser.LoginProjectId, true); this.drpInstallation.SelectedValue = BLL.Const._Null; } ///单位 Funs.FineUIPleaseSelect(this.drpWorkArea); ////钢材类型 this.drpSteType.DataTextField = "Text"; this.drpSteType.DataValueField = "Value"; this.drpSteType.DataSource = BLL.DropListService.HJGL_GetSteTypeList(); this.drpSteType.DataBind(); Funs.FineUIPleaseSelect(this.drpSteType); //显示列 Model.Sys_UserShowColumns c = BLL.UserShowColumnsService.GetColumnsByUserId(this.CurrUser.UserId, Const.UnitAreaAnalyzeMenuId); if (c != null) { this.GetShowColumn(c.Columns); } BindGrid(); } } /// /// /// private DataTable tb = null; /// /// 绑定数据 /// private void BindGrid() { List listStr = new List { new SqlParameter("@projectId", this.CurrUser.LoginProjectId) }; if (this.drpUnit.SelectedValue != BLL.Const._Null) { listStr.Add(new SqlParameter("@UnitNo", this.drpUnit.SelectedValue)); } else { listStr.Add(new SqlParameter("@UnitNo", null)); } if (this.drpInstallation.SelectedValue != BLL.Const._Null) { listStr.Add(new SqlParameter("@installationId", this.drpInstallation.SelectedValue)); } else { listStr.Add(new SqlParameter("@installationId", null)); } if (this.drpWorkArea.SelectedValue != BLL.Const._Null) { listStr.Add(new SqlParameter("@AreaNo", this.drpWorkArea.SelectedValue)); } else { listStr.Add(new SqlParameter("@AreaNo", null)); } if (!string.IsNullOrEmpty(this.txtStarTime.Text)) { listStr.Add(new SqlParameter("@startTime", this.txtStarTime.Text.Trim())); } else { listStr.Add(new SqlParameter("@startTime", null)); } if (!string.IsNullOrEmpty(this.txtEndTime.Text)) { listStr.Add(new SqlParameter("@endTime", this.txtEndTime.Text.Trim())); } else { listStr.Add(new SqlParameter("@endTime", null)); } if (BLL.WorkAreaService.IsSupervisor(this.CurrUser.UnitId, this.CurrUser.LoginProjectId)) { listStr.Add(new SqlParameter("@supervisorUnitId", this.CurrUser.UnitId)); } else { listStr.Add(new SqlParameter("@supervisorUnitId", null)); } if (this.drpSteType.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpSteType.SelectedValue)) { listStr.Add(new SqlParameter("@ste_steeltype", this.drpSteType.SelectedValue)); } else { listStr.Add(new SqlParameter("@ste_steeltype", null)); } if (this.cb_IsStandard.SelectedIndexArray != null && this.cb_IsStandard.SelectedIndexArray.Length==1) { listStr.Add(new SqlParameter("@IsStandard", this.cb_IsStandard.SelectedValueArray[0])); } else { listStr.Add(new SqlParameter("@IsStandard", null)); } SqlParameter[] parameter = listStr.ToArray(); tb = SQLHelper.GetDataTableRunProc("sp_rpt_UnitWorkareaAnalyze", parameter); this.Grid1.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); OutputSummaryData(); } /// /// 改变索引事件 /// /// /// 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 /// /// 全部行合计 /// private void OutputSummaryData() { if (tb != null) { int total_jot = 0; int total_sjot = 0; int total_fjot = 0; int cut_total_jot = 0; double total_din = 0.0f; double total_Sdin = 0.0f; double total_Fdin = 0.0f; int finished_total_jot_bq = 0; int finished_total_sjot_bq = 0; int finished_total_fjot_bq = 0; double finished_total_din_bq = 0.0f; double finished_total_Sdin_bq = 0.0f; double finished_total_Fdin_bq = 0.0f; int finished_total_jot = 0; int finished_total_sjot = 0; int finished_total_fjot = 0; double finished_total_din = 0.0f; double finished_total_sdin = 0.0f; double finished_total_Fdin = 0.0f; //string filmPassRate = ""; //string jointPassRate = ""; foreach (DataRow row in tb.Rows) { total_jot += Convert.ToInt32(row["total_jot"]); total_sjot += Convert.ToInt32(row["total_sjot"]); total_fjot += Convert.ToInt32(row["total_fjot"]); cut_total_jot += Convert.ToInt32(row["cut_total_jot"]); total_din += Convert.ToDouble(row["total_din"]); total_Sdin += Convert.ToDouble(row["total_Sdin"]); total_Fdin += Convert.ToDouble(row["total_Fdin"]); finished_total_jot_bq += Convert.ToInt32(row["finished_total_jot_bq"]); finished_total_sjot_bq += Convert.ToInt32(row["finished_total_sjot_bq"]); finished_total_fjot_bq += Convert.ToInt32(row["finished_total_fjot_bq"]); finished_total_din_bq += Convert.ToDouble(row["finished_total_din_bq"]); finished_total_Sdin_bq += Convert.ToDouble(row["finished_total_Sdin_bq"]); finished_total_Fdin_bq += Convert.ToDouble(row["finished_total_Fdin_bq"]); finished_total_jot += Convert.ToInt32(row["finished_total_jot"]); finished_total_sjot += Convert.ToInt32(row["finished_total_sjot"]); finished_total_fjot += Convert.ToInt32(row["finished_total_fjot"]); finished_total_din += Convert.ToDouble(row["finished_total_din"]); finished_total_sdin += Convert.ToDouble(row["finished_total_sdin"]); finished_total_Fdin += Convert.ToDouble(row["finished_total_Fdin"]); } //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 { { "tfNumber", "合计" }, { "total_jot", total_jot.ToString() }, { "total_sjot", total_sjot.ToString() }, { "total_fjot", total_fjot.ToString() }, { "cut_total_jot", cut_total_jot.ToString() }, { "total_din", total_din.ToString("F2") }, { "total_Sdin", total_Sdin.ToString("F2") }, { "total_Fdin", total_Fdin.ToString("F2") }, { "finished_total_jot_bq", finished_total_jot_bq.ToString() }, { "finished_total_sjot_bq", finished_total_sjot_bq.ToString() }, { "finished_total_fjot_bq", finished_total_fjot_bq.ToString() }, { "finished_total_din_bq", finished_total_din_bq.ToString("F2") }, { "finished_total_Sdin_bq", finished_total_Sdin_bq.ToString("F2") }, { "finished_total_Fdin_bq", finished_total_Fdin_bq.ToString("F2") }, { "finished_total_jot", finished_total_jot.ToString() }, { "finished_total_sjot", finished_total_sjot.ToString() }, { "finished_total_fjot", finished_total_fjot.ToString() }, { "finished_total_din", finished_total_din.ToString("F2") }, { "finished_total_sdin", finished_total_sdin.ToString("F2") }, { "finished_total_Fdin", finished_total_Fdin.ToString("F2") } }; Grid1.SummaryData = summary; } } #region 选择要显示列 /// /// 选择显示列 /// /// /// protected void btnSelectColumn_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ShowColumn.aspx?menuId={0}", BLL.Const.UnitAreaAnalyzeMenuId, "显示列 - "))); } protected void Window1_Close(object sender, WindowCloseEventArgs e) { this.BindGrid(); // 显示列 Model.Sys_UserShowColumns c = BLL.UserShowColumnsService.GetColumnsByUserId(this.CurrUser.UserId, BLL.Const.UnitAreaAnalyzeMenuId); if (c != null) { this.GetShowColumn(c.Columns); } } /// /// 显示的列 /// /// private void GetShowColumn(string column) { if (!string.IsNullOrEmpty(column)) { for (int i = 0; i < Grid1.Columns.Count; i++) { this.Grid1.Columns[i].Hidden = true; } List columns = column.Split(',').ToList(); foreach (var item in columns) { this.Grid1.Columns[Convert.ToInt32(item)].Hidden = false; } } } #endregion #region 统计按钮事件 /// /// 统计 /// /// /// protected void BtnAnalyse_Click(object sender, EventArgs e) { BindGrid(); } #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(); 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(""); } var sumary = grid.SummaryData; if (sumary != null) { foreach (GridColumn column in grid.Columns) { try { if (sumary.ContainsKey(column.ColumnID)) { sb.AppendFormat("", sumary.GetValue(column.ColumnID).ToString()); } else { sb.AppendFormat("", ""); } } catch (Exception e) { sb.AppendFormat("", ""); } } } sb.Append("
{0}
{0}
{0}{0}{0}
"); return sb.ToString(); } #endregion #region 下拉选择事件 /// /// 单位下拉选择事件 /// /// /// < param name="e"> protected void drpUnit_SelectedIndexChanged(object sender, EventArgs e) { this.drpInstallation.Items.Clear(); ///装置 this.drpWorkArea.Items.Clear(); ///区域 Project_InstallationService.InitInstallationDropDownList(this.drpInstallation, this.CurrUser.LoginProjectId, true); this.drpInstallation.SelectedValue = BLL.Const._Null; Funs.FineUIPleaseSelect(this.drpWorkArea); this.drpWorkArea.SelectedValue = BLL.Const._Null; BindGrid(); } /// /// /// /// /// protected void drpInstallation_SelectedIndexChanged(object sender, EventArgs e) { this.drpWorkArea.Items.Clear(); WorkAreaService.InitWorkAreaProjectInstallUnitDropDownList(this.drpWorkArea, this.CurrUser.LoginProjectId, this.drpInstallation.SelectedValue, this.drpUnit.SelectedValue, true); this.drpWorkArea.SelectedValue = BLL.Const._Null; BindGrid(); } #endregion } }