using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; namespace FineUIPro.Web.CQMS.Check { public partial class AdminPenalty : PageBase { /// /// 项目id /// public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } /// /// 1:安全、2:质量 /// public string SysTemType { get { return (string)ViewState["SysTemType"]; } set { ViewState["SysTemType"] = value; } } /// /// 菜单Id /// public string MenuId { get { return (string)ViewState["MenuId"]; } set { ViewState["MenuId"] = value; } } /// /// 页面加载 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.SysTemType = Request.Params["type"] ?? "1"; this.MenuId = BLL.Const.AdminPenaltyMenuId; this.ProjectId = this.CurrUser.LoginProjectId; if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.CurrUser.LoginProjectId) { this.ProjectId = Request.Params["projectId"]; } this.ucTree.UnitId = this.CurrUser.UnitId; this.ucTree.ProjectId = this.ProjectId; if (!string.IsNullOrEmpty(this.ProjectId)) { this.panelLeftRegion.Hidden = true; ////权限按钮方法 this.GetButtonPower(); } UnitService.InitUnitByProjectIdUnitTypeDropDownList(this.drpUnit, this.CurrUser.LoginProjectId, "", true); btnNew.OnClientClick = Window1.GetShowReference(String.Format("AdminPenaltyEdit.aspx?type={0}", this.SysTemType, "编辑 - ")) + "return false;"; // 绑定表格 BindGrid(); } } /// /// 公司级树加载 /// /// /// protected void changeTree(object sender, EventArgs e) { this.ProjectId = this.ucTree.ProjectId; this.GetButtonPower(); if (string.IsNullOrEmpty(this.CurrUser.LoginProjectId)) { btnNew.Hidden = true; } this.BindGrid(); } protected void TextBox_TextChanged(object sender, EventArgs e) { BindGrid(); } /// /// 绑定数据 /// public void BindGrid() { if (string.IsNullOrEmpty(this.ProjectId)) { return; } DataTable tb = ChecklistData(); // 2.获取当前分页数据 //var table = this.GetPagedDataTable(Grid1, tb1); Grid1.RecordCount = tb.Rows.Count; tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } protected DataTable ChecklistData() { string strSql = @" SELECT * FROM dbo.Check_AdminPenalty WHERE ProjectId=@ProjectId "; List listStr = new List(); listStr.Add(new SqlParameter("@ProjectId", this.ProjectId)); if (!string.IsNullOrEmpty(this.txtContent.Text.Trim())) { strSql += " AND PenaltyContent LIKE @Content"; listStr.Add(new SqlParameter("@Content", "%" + this.txtContent.Text.Trim() + "%")); } if (this.drpUnit.SelectedValue != Const._Null) { strSql += " AND UnitId = @Unit"; listStr.Add(new SqlParameter("@Unit", drpUnit.SelectedValue)); } if (!string.IsNullOrWhiteSpace(SysTemType)) { strSql += " AND SysType = @SysType"; listStr.Add(new SqlParameter("@SysType", SysTemType)); } string type = this.drpPenaltyType.SelectedValue.Trim(); string status = this.drpPenaltyStatus.SelectedValue.Trim(); if (!string.IsNullOrWhiteSpace(type)) { strSql += " AND PenaltyType = @Type"; listStr.Add(new SqlParameter("@Type", type)); } if (!string.IsNullOrWhiteSpace(status)) { strSql += " AND PenaltyStatus = @Status"; listStr.Add(new SqlParameter("@Status", status)); } strSql += " ORDER BY CompileDate DESC"; SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); return tb; } /// /// 附件 /// /// /// protected string ConvertAttachFile(object objId) { string fileUrl = string.Empty; var model = BLL.AdminPenaltyService.GetAdminPenaltyById(objId.ToString()); if (model != null) { fileUrl = BLL.AttachFileService.GetBtnFileUrl(model.PenaltyId); } return fileUrl; } #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(); } #endregion #region Grid双击事件 /// /// Grid行双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { btnMenuModify_Click(sender, e); } /// /// 编辑按钮 /// /// /// protected void btnMenuModify_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string codes = Grid1.SelectedRowID.Split(',')[0]; var checks = BLL.AdminPenaltyService.GetAdminPenaltyById(codes); if (checks != null) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("AdminPenaltyEdit.aspx?PenaltyId={0}&type={1}", codes, this.SysTemType))); return; } } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == "0") { return; } var buttonList = BLL.CommonService.GetAllButtonList(this.ProjectId, this.CurrUser.UserId, this.MenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnAdd)) { this.btnNew.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnDelete)) { this.btnMenuDel.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnModify)) { this.btnMenuModify.Hidden = false; } } } #endregion /// /// 删除 /// /// /// protected void btnMenuDel_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string id = Grid1.SelectedRowID.Split(',')[0]; if (CommonService.GetAllButtonPowerList(CurrUser.LoginProjectId, CurrUser.UserId, this.MenuId, Const.BtnDelete)) { BLL.AdminPenaltyService.DeleteAdminPenaltyById(id); BindGrid(); Alert.ShowInTop("删除成功!", MessageBoxIcon.Success); } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Success); } } /// /// 关闭弹出窗 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } #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(); } #endregion } }