using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; namespace FineUIPro.Web.JDGL.SGManPower { public partial class SGWarningDetails : PageBase { #region 定义项 /// /// 项目主键 /// public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } public string WarningType { get => (string)ViewState["WarningType"]; set => ViewState["WarningType"] = value; } #endregion protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Funs.DropDownPageSize(this.ddlPageSize); ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); this.ProjectId = Request.Params["projectId"]; this.WarningType = Request.Params["warningType"]; // 绑定表格 BindGrid(); } } private void BindGrid() { string strSql = @"SELECT * from SGManPower_WarningResult where 1=1 "; List listStr = new List(); if (!string.IsNullOrEmpty(this.ProjectId)) { strSql += " AND ProjectId = @ProjectId "; listStr.Add(new SqlParameter("@ProjectId", this.ProjectId)); } if (!string.IsNullOrEmpty(this.WarningType)) { strSql += " AND WarningType = @WarningType "; listStr.Add(new SqlParameter("@WarningType", this.WarningType)); } strSql += " ORDER BY UnitId"; SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } /// /// 右键编辑事件 /// /// /// protected void btnMenuView_Click(object sender, EventArgs e) { this.EditData(); } /// /// 编辑数据方法 /// private void EditData() { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning); return; } var result = Funs.DB.SGManPower_WarningResult.FirstOrDefault(x => x.WarningId == Grid1.SelectedRowID); PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SGWarningDetailsEdit.aspx?projectId={0}&unitId={1}&unitWorkId={2}&workPostId={3}&startTime={4}&endTime={5}", result.ProjectId, result.UnitId, result.UnitWorkId, result.WorkPostId, result.StartDate, result.EndDate, "编辑 - "))); } #region 分页、关闭窗口 /// /// 分页 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; 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) { BindGrid(); } #endregion #region 格式化字符串 /// /// 格式化受伤情况 /// /// /// protected string ConvertWorkPostName(object workPostId) { string name = string.Empty; if (workPostId != null) { name = BLL.WorkPostService.getWorkPostNameById(workPostId.ToString()); } return name; } protected string ConvertUnitName(object unitId) { string name = string.Empty; if (unitId != null) { name = UnitService.GetUnitNameByUnitId(unitId); } return name; } /// /// 格式装置 /// /// /// protected string ConvertUnitWorkName(object unitWorkId) { string name = string.Empty; if (unitWorkId != null) { name = BLL.UnitWorkService.GetNameById(unitWorkId.ToString()); } return name; } // 在页面中添加格式化方法 protected string ConvertBiasPercent(object biasValue) { if (biasValue != null && decimal.TryParse(biasValue.ToString(), out decimal value)) { return (value * 100).ToString("F2") + "%"; } return "0.00%"; } #endregion } }