using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using BLL; namespace FineUIPro.Web.common.Notice { public partial class Notice : PageBase { #region 加载页面 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.GetButtonPower(); btnFinalFile.OnClientClick = Window2.GetShowReference("NoticeFinalFile.aspx") + "return false"; ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); // 绑定表格 BindGrid(); } } #endregion #region 绑定数据 protected void rblType_SelectedIndexChanged(object sender, EventArgs e) { BindGrid(); } /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } /// /// 绑定数据 /// private void BindGrid() { List q = (from x in Funs.DB.View_Common_Notice orderby x.NoticeCode select x).ToList(); if (this.rblType.SelectedValue == "0") { if (!string.IsNullOrEmpty(this.CurrUser.LoginProjectId)) { q = q.Where(e => e.SystemId == this.CurrUser.LoginSystemId && e.ProjectId == this.CurrUser.LoginProjectId).ToList(); } else { q = q.Where(e => e.SystemId == this.CurrUser.LoginSystemId).ToList(); } } else { if (!string.IsNullOrEmpty(this.CurrUser.LoginProjectId)) { q = q.Where(e => e.IsRelease == true && (e.AccessSystemId.Contains(this.CurrUser.LoginSystemId + "#") && e.AccessProjectId.Contains(this.CurrUser.LoginProjectId)) || (e.SystemId == this.CurrUser.LoginSystemId && e.ProjectId == this.CurrUser.LoginProjectId)).ToList(); } else { q = q.Where(e => e.IsRelease == true && (e.AccessSystemId.Contains(this.CurrUser.LoginSystemId + "#") || e.SystemId == this.CurrUser.LoginSystemId)).ToList(); } } if (!string.IsNullOrEmpty(txtNoticeCode.Text.Trim())) { q = q.Where(e => e.NoticeCode.Contains(txtNoticeCode.Text.Trim())).ToList(); } if (!string.IsNullOrEmpty(txtSartTime.Text.Trim())) { q = q.Where(e => e.CompileDate >= Funs.GetNewDateTime(txtSartTime.Text.Trim())).ToList(); } if (!string.IsNullOrEmpty(txtEndTime.Text.Trim())) { q = q.Where(e => e.CompileDate <= Funs.GetNewDateTime(txtEndTime.Text.Trim())).ToList(); } Grid1.RecordCount = q.Count(); // 2.获取当前分页数据 var table = GetPagedDataTable(Grid1.PageIndex, Grid1.PageSize); Grid1.DataSource = table; Grid1.DataBind(); } /// /// 分页 /// /// private List GetPagedDataTable(int pageIndex, int pageSize) { List source = new List(); source = (from x in Funs.DB.View_Common_Notice orderby x.NoticeCode select x).ToList(); if (this.rblType.SelectedValue == "0") { if (!string.IsNullOrEmpty(this.CurrUser.LoginProjectId)) { source = source.Where(e => e.SystemId == this.CurrUser.LoginSystemId && e.ProjectId == this.CurrUser.LoginProjectId).ToList(); } else { source = source.Where(e => e.SystemId == this.CurrUser.LoginSystemId).ToList(); } } else { if (!string.IsNullOrEmpty(this.CurrUser.LoginProjectId)) { source = source.Where(e => e.IsRelease == true && (e.AccessSystemId.Contains(this.CurrUser.LoginSystemId + "#") && e.AccessProjectId.Contains(this.CurrUser.LoginProjectId)) || (e.SystemId == this.CurrUser.LoginSystemId && e.ProjectId == this.CurrUser.LoginProjectId)).ToList(); } else { source = source.Where(e => e.IsRelease == true && (e.AccessSystemId.Contains(this.CurrUser.LoginSystemId + "#") || e.SystemId == this.CurrUser.LoginSystemId)).ToList(); } } if (!string.IsNullOrEmpty(txtNoticeCode.Text.Trim())) { source = source.Where(e => e.NoticeCode.Contains(txtNoticeCode.Text.Trim())).ToList(); } if (!string.IsNullOrEmpty(txtSartTime.Text.Trim())) { source = source.Where(e => e.CompileDate >= Funs.GetNewDateTime(txtSartTime.Text.Trim())).ToList(); } if (!string.IsNullOrEmpty(txtEndTime.Text.Trim())) { source = source.Where(e => e.CompileDate <= Funs.GetNewDateTime(txtEndTime.Text.Trim())).ToList(); } List paged = new List(); int rowbegin = pageIndex * pageSize; int rowend = (pageIndex + 1) * pageSize; if (rowend > source.Count()) { rowend = source.Count(); } for (int i = rowbegin; i < rowend; i++) { paged.Add(source[i]); } return paged; } 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_FilterChange(object sender, EventArgs e) { BindGrid(); } protected void Window1_Close(object sender, EventArgs e) { BindGrid(); } #endregion #region Grid点击事件 /// /// Grid1行点击事件 /// /// /// protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) { string rowID = Grid1.DataKeys[e.RowIndex][0].ToString(); Model.Common_Notice notice = BLL.Common_NoticeService.GetNoticeByNoticeId(rowID); if (notice != null) { if (e.CommandName == "click") { if (this.GetRolePowerBySystemMenuId(BLL.Const.BtnAuditing)) { if (notice.State == Const.Common_Notice_ApproveCompleted) { ScriptManager.RegisterStartupScript(this, typeof(string), "_alert", "alert('此通知已经办理完结!')", true); } else if (notice.State == Const.Common_Notice_Compile) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("AddNotice.aspx?noticeId={0}", rowID, "编辑 - "))); } else { Model.Common_NoticeSign noticeSign = BLL.Common_NoticeSignService.GetNoticeSignByNoticeId(rowID); if (this.CurrUser.UserId == noticeSign.SignMan || this.CurrUser.UserId == BLL.Const.GlyId) { if (notice.State == Const.Common_Notice_ReCompile) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("AddNotice.aspx?noticeId={0}", rowID, "编辑 - "))); } else { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("NoticeSign.aspx?noticeId={0}", rowID, "编辑 - "))); } } else { ShowNotify("你不是指定的办理人,不能操作此条信息!", MessageBoxIcon.Warning); } } } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } if (e.CommandName == "upIsRelease") { if (this.GetRolePowerBySystemMenuId(BLL.Const.BtnIssuance)) { if (notice.State == Const.Common_Notice_ApproveCompleted) { if (Convert.ToBoolean(notice.IsRelease)) { notice.IsRelease = false; } else { notice.IsRelease = true; } BLL.Common_NoticeService.UpdateNotice(notice); BindGrid(); } else { ShowNotify("此条信息未办理完成,不能发布!", MessageBoxIcon.Warning); } } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } if (e.CommandName == "particular") { if (notice.Flag == "1") //定稿文件 { PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("NoticeFinalFile.aspx?noticeId={0}", rowID, "编辑 - "))); } else { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("NoticeSignParticular.aspx?noticeId={0}", rowID, "编辑 - "))); } } if (e.CommandName == "del") { if (this.GetRolePowerBySystemMenuId(BLL.Const.BtnDelete) && this.rblType.SelectedValue == "0") { string rootPath = Server.MapPath("~/"); rootPath = rootPath.Substring(0, rootPath.Length - 1); BLL.Common_NoticeSignService.DeleteNoticeSignByNoticeId(rowID); BLL.Common_NoticeService.DeleteNotice(rowID); BLL.Sys_LogService.AddLog(Const.System_1, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除通知"); BindGrid(); //ScriptManager.RegisterStartupScript(this, typeof(string), "_alert", "alert('删除成功!')", true); } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } } } #endregion #region 增加、删除数据方法 /// /// 增加按钮事件 /// /// /// protected void btnNew_Click(object sender, EventArgs e) { if (this.GetRolePowerBySystemMenuId(BLL.Const.BtnCompile)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("AddNotice.aspx", "编辑 - "))); } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } /// /// 右键删除事件 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { this.DeleteData(); } /// /// 删除方法 /// private void DeleteData() { if (this.GetRolePowerBySystemMenuId(BLL.Const.BtnDelete) && this.rblType.SelectedValue == "0") { if (Grid1.SelectedRowIndexArray.Length > 0) { foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); BLL.Common_NoticeSignService.DeleteNoticeSignByNoticeId(rowID); BLL.Common_NoticeService.DeleteNotice(rowID); BLL.Sys_LogService.AddLog(Const.System_1, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除通知"); } BindGrid(); //PageContext.RegisterStartupScript("onNewButtonClick();"); } } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } #endregion #region 权限设置 /// /// 权限设置 /// private void GetButtonPower() { if (this.CurrUser.LoginSystemId == Const.System_1) { if (!BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.Common_NoticeMenuId, BLL.Const.BtnDelete)) { this.btnMenuDelete.Hidden = true; } if (!BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.Common_NoticeMenuId, BLL.Const.BtnModify)) { this.btnMenuDelete.Hidden = true; } } } #endregion #region 根据不同的系统id得到该菜单的权限 /// /// 根据不同的系统id得到该菜单的权限 /// /// 按钮类型 /// private bool GetRolePowerBySystemMenuId(string btnType) { bool isRole = false; if (this.CurrUser.LoginSystemId == Const.System_1) { isRole = BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.Common_NoticeMenuId, btnType); } return isRole; } #endregion } }