using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using AspNet = System.Web.UI.WebControls; namespace FineUIPro.Web.HSSE.Check { public partial class SupervisionNotice : PageBase { #region 定义项 /// /// 主键 /// public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { // 表头过滤 //FilterDataRowItem = FilterDataRowItemImplement; if (!IsPostBack) { this.ProjectId = this.CurrUser.LoginProjectId; if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.CurrUser.LoginProjectId) { this.ProjectId = Request.Params["projectId"]; } ////权限按钮方法 this.GetButtonPower(); btnNew.OnClientClick = Window1.GetShowReference("SupervisionNoticeEdit.aspx") + "return false;"; ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); // 绑定表格 BindGrid(); } } /// /// 绑定数据 /// private void BindGrid() { string strSql = @"SELECT SupervisionNotice.SupervisionNoticeId," + @"SupervisionNotice.ProjectId," + @"CodeRecords.Code AS SupervisionNoticeCode," + @"SupervisionNotice.UnitId," + @"SupervisionNotice.WorkAreaId," + @"SupervisionNotice.CheckedDate," + @"SupervisionNotice.WrongContent," + @"SupervisionNotice.SignPerson," + @"SupervisionNotice.SignDate," + @"SupervisionNotice.CompleteStatus," + @"SupervisionNotice.DutyPerson," + @"SupervisionNotice.CompleteDate," + @"SupervisionNotice.IsRectify," + @"SupervisionNotice.CheckPerson," + @"SupervisionNotice.AttachUrl," + @"Unit.UnitName," + @"WorkArea.WorkAreaName," + @"Person.UserName AS CheckPersonName" + @" FROM Check_SupervisionNotice AS SupervisionNotice " + @" LEFT JOIN Base_Project AS Project ON Project.ProjectId = SupervisionNotice.ProjectId " + @" LEFT JOIN Base_Unit AS Unit ON Unit.UnitId = SupervisionNotice.UnitId " + @" LEFT JOIN ProjectData_WorkArea AS WorkArea ON WorkArea.WorkAreaId = SupervisionNotice.WorkAreaId " + @" LEFT JOIN Sys_User AS Users ON SupervisionNotice.SignPerson = Users.UserId " + @" LEFT JOIN Sys_User AS Person ON Person.UserId = SupervisionNotice.CheckPerson " + @" LEFT JOIN Sys_CodeRecords AS CodeRecords ON SupervisionNotice.SupervisionNoticeId = CodeRecords.DataId WHERE 1=1 "; List listStr = new List(); strSql += " AND SupervisionNotice.ProjectId = @ProjectId"; listStr.Add(new SqlParameter("@ProjectId", this.ProjectId)); /// 施工分包 只看到自己单位 if (BLL.ProjectUnitService.GetProjectUnitTypeByProjectIdUnitId(this.ProjectId, this.CurrUser.UnitId)) { strSql += " AND SupervisionNotice.UnitId = @UnitId"; ///责任单位 listStr.Add(new SqlParameter("@UnitId", this.CurrUser.UnitId)); } if (!string.IsNullOrEmpty(this.txtSupervisionNoticeCode.Text.Trim())) { strSql += " AND SupervisionNoticeCode LIKE @SupervisionNoticeCode"; listStr.Add(new SqlParameter("@SupervisionNoticeCode", "%" + this.txtSupervisionNoticeCode.Text.Trim() + "%")); } SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); 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 TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } #endregion #region 过滤表头、排序、分页、关闭窗口 /// /// 过滤表头 /// /// /// protected void Grid1_FilterChange(object sender, EventArgs e) { BindGrid(); } /// /// 分页 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(); } /// /// 分页显示条数下拉框 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } /// /// 关闭弹出窗 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } #endregion #region Grid双击事件 /// /// Grid行双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string SupervisionNoticeId = Grid1.SelectedRowID; var SupervisionNotice = BLL.SupervisionNoticeService.GetSupervisionNoticeById(SupervisionNoticeId); if (SupervisionNotice != null) { if (!string.IsNullOrEmpty(SupervisionNotice.CheckPerson)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SupervisionNoticeView.aspx?SupervisionNoticeId={0}", SupervisionNoticeId, "查看 - "))); } else { if (this.btnAuditing.Hidden == true) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SupervisionNoticeEdit.aspx?SupervisionNoticeId={0}", SupervisionNoticeId, "编辑 - "))); } else { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SupervisionNoticeEdit.aspx?states=check&SupervisionNoticeId={0}", SupervisionNoticeId, "审核 - "))); } } } } #endregion #region 编辑 /// /// 编辑按钮 /// /// /// protected void btnMenuModify_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string SupervisionNoticeId = Grid1.SelectedRowID; var SupervisionNotice = BLL.SupervisionNoticeService.GetSupervisionNoticeById(SupervisionNoticeId); if (SupervisionNotice != null) { if (!string.IsNullOrEmpty(SupervisionNotice.CheckPerson)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SupervisionNoticeView.aspx?SupervisionNoticeId={0}", SupervisionNoticeId, "查看 - "))); } else { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SupervisionNoticeEdit.aspx?SupervisionNoticeId={0}", SupervisionNoticeId, "编辑 - "))); } } } #endregion #region 审核 /// /// 审核 /// /// /// protected void btnAuditing_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string SupervisionNoticeId = Grid1.SelectedRowID; var SupervisionNotice = BLL.SupervisionNoticeService.GetSupervisionNoticeById(SupervisionNoticeId); if (SupervisionNotice != null) { if (!string.IsNullOrEmpty(SupervisionNotice.CheckPerson)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SupervisionNoticeView.aspx?SupervisionNoticeId={0}", SupervisionNoticeId, "查看 - "))); } else { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SupervisionNoticeEdit.aspx?states=check&SupervisionNoticeId={0}", SupervisionNoticeId, "审核 - "))); } } } #endregion #region 删除 /// /// 批量删除 /// /// /// protected void btnMenuDel_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length > 0) { foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); var SupervisionNotice = BLL.SupervisionNoticeService.GetSupervisionNoticeById(rowID); if (SupervisionNotice != null) { BLL.LogService.AddSys_Log(this.CurrUser, SupervisionNotice.SupervisionNoticeCode, SupervisionNotice.SupervisionNoticeId, BLL.Const.ProjectSupervisionNoticeMenuId, BLL.Const.BtnDelete); BLL.SupervisionNoticeService.DeleteSupervisionNoticeById(rowID); } } BindGrid(); ShowNotify("删除数据成功!(表格数据已重新绑定)"); } } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == "0") { return; } var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.ProjectSupervisionNoticeMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnAdd)) { this.btnNew.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnModify)) { this.btnMenuModify.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnDelete)) { this.btnMenuDel.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnAuditing)) { this.btnAuditing.Hidden = false; } } } #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; this.Grid1.PageSize = 500; this.BindGrid(); 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("lblNumber") as AspNet.Label).Text; } //if (column.ColumnID == "CheckArea") //{ // html = (row.FindControl("lblCheckArea") as AspNet.Label).Text; //} sb.AppendFormat("", html); } sb.Append(""); } sb.Append("
{0}
{0}
"); return sb.ToString(); } #endregion } }