using BLL; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using AspNet = System.Web.UI.WebControls; namespace FineUIPro.Web.ZHGL.ManagementReport { public partial class CheckDaily : PageBase { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ////权限按钮方法 this.GetButtonPower(); Funs.DropDownPageSize(this.ddlPageSize); GetButtonPower(); this.ItemSelectedList = new List(); ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); this.drpStates.DataValueField = "Id"; this.drpStates.DataTextField = "Name"; List handleSteps = new List(); Model.HandleStep handleStep1 = new Model.HandleStep(); handleStep1.Id = "1"; handleStep1.Name = "待整改"; handleSteps.Add(handleStep1); Model.HandleStep handleStep2 = new Model.HandleStep(); handleStep2.Id = "2"; handleStep2.Name = "已整改-待复查验收"; handleSteps.Add(handleStep2); Model.HandleStep handleStep3 = new Model.HandleStep(); handleStep3.Id = "3"; handleStep3.Name = "已闭环"; handleSteps.Add(handleStep3); //Model.HandleStep handleStep4 = new Model.HandleStep(); //handleStep4.Id = "4"; //handleStep4.Name = "已作废"; //handleSteps.Add(handleStep4); this.drpStates.DataSource = handleSteps; ; this.drpStates.DataBind(); Funs.FineUIPleaseSelect(this.drpStates, "按状态"); ListItem[] ProblemTypes = new ListItem[2]; ProblemTypes[0] = new ListItem("日常巡检", "1"); ProblemTypes[1] = new ListItem("专项巡检", "2"); this.drpProblemTypes.DataValueField = "Value"; this.drpProblemTypes.DataTextField = "Text"; this.drpProblemTypes.DataSource = ProblemTypes; this.drpProblemTypes.DataBind(); Funs.FineUIPleaseSelect(this.drpProblemTypes, "按检查类型"); // 绑定表格 //BindGrid(); InitTreeMenu(); } } private void InitTreeMenu() { this.tvControlItem.Nodes.Clear(); TreeNode rootNode = new TreeNode(); rootNode.Text = "项目"; rootNode.NodeID = "0"; rootNode.Expanded = true; this.tvControlItem.Nodes.Add(rootNode); var project = (from x in Funs.DB.Base_Project select new { x.ProjectId, x.ProjectName }).Distinct(); if (project.Count() > 0) { foreach (var pro in project) { TreeNode tnProject = new TreeNode();//年节点 tnProject.Text = SubStr(pro.ProjectName); tnProject.NodeID = pro.ProjectId; tnProject.ToolTip = pro.ProjectName; tnProject.EnableClickEvent = true; rootNode.Nodes.Add(tnProject); } } } protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { BindGrid(); } #region 查询 /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } #endregion #region 分页、关闭窗口 /// /// 分页 /// /// /// /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { BindGrid(); } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == "0") { return; } } #endregion private string SubStr(string str) { string reStr = str; if (!string.IsNullOrEmpty(str) && str.Length > 16) { reStr = str.Substring(0, 14) + ".."; } return reStr; } #region 定义项 /// /// GV被选择项列表 /// public List ItemSelectedList { get { return (List)ViewState["ItemSelectedList"]; } set { ViewState["ItemSelectedList"] = value; } } #endregion /// /// 绑定数据 /// private void BindGrid() { string strSql = "SELECT * FROM View_Hazard_HazardRegister WHERE ProblemTypes ='1' "; //ProblemTypes in ('1' ,'2') List listStr = new List(); if (!string.IsNullOrEmpty(this.CurrUser.LoginProjectId)) { strSql += " AND ProjectId = @ProjectId"; listStr.Add(new SqlParameter("@ProjectId", tvControlItem.SelectedNodeID)); } if (!string.IsNullOrEmpty(this.txtCheckMan.Text.Trim())) { strSql += " AND CheckManName LIKE @CheckMan"; listStr.Add(new SqlParameter("@CheckMan", "%" + this.txtCheckMan.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtType.Text.Trim())) { strSql += " AND RegisterTypesName LIKE @Type"; listStr.Add(new SqlParameter("@Type", "%" + this.txtType.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtWorkAreaName.Text.Trim())) { strSql += " AND WorkAreaName LIKE @WorkAreaName"; listStr.Add(new SqlParameter("@WorkAreaName", "%" + this.txtWorkAreaName.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.dpRiskLevel.SelectedValue.Trim())) { strSql += " AND Risk_Level = @Risk_Level"; listStr.Add(new SqlParameter("@Risk_Level", this.dpRiskLevel.SelectedText)); } if (!string.IsNullOrEmpty(this.drpType.SelectedValue.Trim())) { strSql += " AND CheckCycle=@CheckCycle"; listStr.Add(new SqlParameter("@CheckCycle", this.drpType.SelectedValue)); } if (!string.IsNullOrEmpty(this.txtResponsibilityUnitName.Text.Trim())) { strSql += " AND ResponsibilityUnitName LIKE @ResponsibilityUnitName"; listStr.Add(new SqlParameter("@ResponsibilityUnitName", "%" + this.txtResponsibilityUnitName.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(txtStartTime.Text.Trim())) { strSql += " AND CheckTime >= @StartTime"; listStr.Add(new SqlParameter("@StartTime", this.txtStartTime.Text.Trim())); } if (!string.IsNullOrEmpty(this.txtEndTime.Text.Trim())) { strSql += " AND CheckTime <= @EndTime"; listStr.Add(new SqlParameter("@EndTime", this.txtEndTime.Text.Trim())); } if (!string.IsNullOrEmpty(txtStartRectificationTime.Text.Trim())) { strSql += " AND RectificationTime >= @StartRectificationTime"; listStr.Add(new SqlParameter("@StartRectificationTime", this.txtStartRectificationTime.Text.Trim())); } if (!string.IsNullOrEmpty(this.txtEndRectificationTime.Text.Trim())) { strSql += " AND RectificationTime <= @EndRectificationTime"; listStr.Add(new SqlParameter("@EndRectificationTime", this.txtEndRectificationTime.Text.Trim())); } if (this.drpProblemTypes.SelectedValue != BLL.Const._Null) { strSql += " and ProblemTypes ='" + this.drpProblemTypes.SelectedValue + "' "; } if (this.drpStates.SelectedValue != BLL.Const._Null) { strSql += " AND States LIKE @States"; listStr.Add(new SqlParameter("@States", "%" + this.drpStates.SelectedValue + "%")); } if (!CommonService.IsMainUnitOrAdmin(this.CurrUser.UserId)) { strSql += " AND (ResponsibleUnit =@ResponsibleUnit OR SendUnitId=@SendUnitId)"; listStr.Add(new SqlParameter("@ResponsibleUnit", this.CurrUser.UnitId)); listStr.Add(new SqlParameter("@SendUnitId", this.CurrUser.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(); } #region 表排序、分页、关闭窗口 /// /// 分页 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } /// /// 关闭弹出窗 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } #endregion #region Grid双击事件 /// /// Grid行双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { btnMenuSee_Click(null, null); } #endregion #region 查看 /// /// 查看按钮 /// /// /// protected void btnMenuSee_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string RegistrationId = Grid1.SelectedRowID; var registration = BLL.HSSE_Hazard_HazardRegisterService.GetHazardRegisterByHazardRegisterId(RegistrationId); if (registration != null) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("HiddenRectificationView.aspx?HazardRegisterId={0}", RegistrationId, "查看 - "))); } } #endregion #region 格式化字符串 /// /// 获取整改前图片 /// /// /// protected string ConvertImageUrl(object registrationId) { string url = string.Empty; if (registrationId != null) { var registration = BLL.HSSE_Hazard_HazardRegisterService.GetHazardRegisterByHazardRegisterId(registrationId.ToString()); if (registration != null) { url = BLL.UploadAttachmentService.ShowAttachment("../../", registration.ImageUrl); } } return url; } protected string ConvertProblemTypes(object registrationId) { string url = string.Empty; if (registrationId != null) { if (registrationId.ToString() == "1") { return "日常巡检"; } else if (registrationId.ToString() == "2") { return "专项检查"; } } return url; } /// /// 获取整改前图片(放于Img中) /// /// /// protected string ConvertImageUrlByImage(object registrationId) { string url = string.Empty; if (registrationId != null) { var registration = BLL.HSSE_Hazard_HazardRegisterService.GetHazardRegisterByHazardRegisterId(registrationId.ToString()); if (registration != null) { url = BLL.UploadAttachmentService.ShowImage(ConfigurationManager.AppSettings["SGGLUrl"], registration.ImageUrl); } } return url; } /// /// 获取整改后图片 /// /// /// protected string ConvertImgUrl(object registrationId) { string url = string.Empty; if (registrationId != null) { var registration = BLL.HSSE_Hazard_HazardRegisterService.GetHazardRegisterByHazardRegisterId(registrationId.ToString()); if (registration != null) { url = BLL.UploadAttachmentService.ShowAttachment(ConfigurationManager.AppSettings["SGGLUrl"], registration.RectificationImageUrl); } } return url; } protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } /// /// 获取整改后图片(放于Img中) /// /// /// protected string ConvertImgUrlByImage(object registrationId) { string url = string.Empty; if (registrationId != null) { var registration = BLL.HSSE_Hazard_HazardRegisterService.GetHazardRegisterByHazardRegisterId(registrationId.ToString()); if (registration != null) { url = BLL.UploadAttachmentService.ShowImage("../../", registration.RectificationImageUrl); } } return url; } #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 = 100000; 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) { if (column.ColumnID != "ckbIsSelected" && column.ColumnID != "tfImageUrl1" && column.ColumnID != "tfImageUrl2" && column.ColumnID != "Punish" && column.ColumnID != "Del") { sb.AppendFormat("", column.HeaderText); } } sb.Append(""); foreach (GridRow row in grid.Rows) { sb.Append(""); foreach (GridColumn column in grid.Columns) { if (column.ColumnID != "ckbIsSelected" && column.ColumnID != "tfImageUrl1" && column.ColumnID != "tfImageUrl2" && column.ColumnID != "Punish" && column.ColumnID != "Del") { string html = row.Values[column.ColumnIndex].ToString(); if (column.ColumnID == "tfPageIndex") { html = (row.FindControl("lblPageIndex") as AspNet.Label).Text; } if (column.ColumnID == "tfImageUrl") { html = (row.FindControl("lbtnImageUrl") as AspNet.LinkButton).Text; } if (column.ColumnID == "tfRectificationImageUrl") { html = (row.FindControl("lbtnRectificationImageUrl") as AspNet.LinkButton).Text; } if (column.ColumnID == "ProblemTypes") { html = (row.FindControl("lbProblemTypes") as AspNet.Label).Text; } //if (column.ColumnID == "tfCutPayment") //{ // html = (row.FindControl("lbtnCutPayment") as AspNet.LinkButton).Text; //} sb.AppendFormat("", html); } } sb.Append(""); } sb.Append("
{0}
{0}
"); return sb.ToString(); } #endregion } }