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 SGWarningDetailsEdit : PageBase { #region 定义项 /// /// 项目主键 /// public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } public string UnitId { get => (string)ViewState["UnitId"]; set => ViewState["UnitId"] = value; } public string UnitWorkId { get => (string)ViewState["UnitWorkId"]; set => ViewState["UnitWorkId"] = value; } public string WorkPostId { get => (string)ViewState["WorkPostId"]; set => ViewState["WorkPostId"] = value; } public string StartTime { get => (string)ViewState["StartTime"]; set => ViewState["StartTime"] = value; } public string EndTime { get => (string)ViewState["EndTime"]; set => ViewState["EndTime"] = value; } private static string Version = "1"; #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ProjectId = this.CurrUser.LoginProjectId; // 判断projectId参数是否为空 if (!string.IsNullOrEmpty(Request.Params["projectId"])) { this.ProjectId = Request.Params["projectId"]; } Funs.DropDownPageSize(this.ddlPageSize); ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); BLL.UnitService.GetUnit(this.drpUnit, this.ProjectId, true);//单位 this.txtStartTime.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now.AddDays(-30)); this.txtEndTime.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now.AddDays(30)); WorkPostService.InitWorkPostDropDownList(this.drpWorkPost, true); //岗位 UnitWorkService.InitUnitWorkDownList(drpUnitWork, this.ProjectId, true); //单位工程(装置) this.UnitId = Request.Params["unitId"]; this.UnitWorkId = Request.Params["unitWorkId"]; this.WorkPostId = Request.Params["workPostId"]; this.StartTime = Request.Params["startTime"]; this.EndTime = Request.Params["endTime"]; if (!string.IsNullOrEmpty(this.UnitId)) { this.drpUnit.SelectedValue = UnitId; } if (!string.IsNullOrEmpty(this.UnitWorkId)) { this.drpUnitWork.SelectedValue = UnitWorkId; } if (!string.IsNullOrEmpty(this.WorkPostId)) { this.drpWorkPost.SelectedValue = WorkPostId; } if (!string.IsNullOrEmpty(this.StartTime)) { this.txtStartTime.Text = StartTime; } if (!string.IsNullOrEmpty(this.EndTime)) { this.txtEndTime.Text = EndTime; } var sgMan = Funs.DB.JDGL_SGManPower.Where(x => x.ProjectId == this.ProjectId).OrderByDescending(x => x.Version) .FirstOrDefault(); if (sgMan != null) { Version = sgMan.Version; } // 绑定表格 BindGrid(); } } /// /// 绑定数据 /// private void BindGrid() { string strSql = @"SELECT p.Id, p.ProjectId, p.UnitId, p.UnitWorkId, p.WorkPostId, p.Version, p.Quantity, p.PlanDate, ISNULL(a.ActualQuantity, 0) AS ActualQuantity FROM JDGL_SGManPower p LEFT JOIN ( SELECT * from View_EmployInOutRecord ) a ON p.ProjectId = a.ProjectId AND p.UnitId = a.UnitId AND p.WorkPostId = a.PostId AND p.PlanDate = a.RecordDate AND ISNULL(p.UnitWorkId, '') = ISNULL(a.UnitWorkId, '') where p.Version = '" + Version + "'"; List listStr = new List(); if (!string.IsNullOrEmpty(this.ProjectId)) { strSql += " AND p.ProjectId = @ProjectId "; listStr.Add(new SqlParameter("@ProjectId", this.ProjectId)); } if (!string.IsNullOrEmpty(this.drpUnit.SelectedValue) && this.drpUnit.SelectedValue != "null") { strSql += " AND p.UnitId = @UnitId "; listStr.Add(new SqlParameter("@UnitId", this.drpUnit.SelectedValue)); } if (!string.IsNullOrEmpty(this.drpUnitWork.SelectedValue) && this.drpUnitWork.SelectedValue != "null") { strSql += " AND p.UnitWorkId = @UnitWorkId "; listStr.Add(new SqlParameter("@UnitWorkId", this.drpUnitWork.SelectedValue)); } if (!string.IsNullOrEmpty(this.drpWorkPost.SelectedValue) && this.drpWorkPost.SelectedValue != "null") { strSql += " AND p.WorkPostId = @WorkPostId "; listStr.Add(new SqlParameter("@WorkPostId", this.drpWorkPost.SelectedValue)); } if (!string.IsNullOrEmpty(this.txtStartTime.Text)) { strSql += " AND p.PlanDate >= @StartTime "; listStr.Add(new SqlParameter("@StartTime", Convert.ToDateTime(this.txtStartTime.Text))); } if (!string.IsNullOrEmpty(this.txtEndTime.Text)) { strSql += " AND p.PlanDate <= @EndTime "; listStr.Add(new SqlParameter("@EndTime", Convert.ToDateTime(this.txtEndTime.Text))); } strSql += " ORDER BY p.PlanDate, p.UnitId, p.UnitWorkId, p.WorkPostId"; 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(); } #endregion #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; } #endregion #region 查询事件 /// /// 查询 /// /// /// protected void btnQuery_OnClick(object sender, EventArgs e) { if (drpUnit.SelectedValue != Const._Null && !string.IsNullOrEmpty(drpUnit.SelectedValue)) { UnitId = drpUnit.SelectedValue; } if (drpUnitWork.SelectedValue != Const._Null && !string.IsNullOrEmpty(drpUnitWork.SelectedValue)) { UnitWorkId = drpUnitWork.SelectedValue; } if (drpWorkPost.SelectedValue != Const._Null && !string.IsNullOrEmpty(drpWorkPost.SelectedValue)) { WorkPostId = drpWorkPost.SelectedValue; } if ( !string.IsNullOrEmpty(this.txtStartTime.Text)) { StartTime = this.txtStartTime.Text; } if ( !string.IsNullOrEmpty(this.txtStartTime.Text)) { EndTime = this.txtEndTime.Text; } this.BindGrid(); } #endregion } }