ZHJA_HJGL/HJGL_ZH/FineUIPro.Web/common/Notice/Notice.aspx.cs

385 lines
15 KiB
C#

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();
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
List<Model.View_Common_Notice> 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();
}
/// <summary>
/// 分页
/// </summary>
/// <returns></returns>
private List<Model.View_Common_Notice> GetPagedDataTable(int pageIndex, int pageSize)
{
List<Model.View_Common_Notice> source = new List<Model.View_Common_Notice>();
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<Model.View_Common_Notice> paged = new List<Model.View_Common_Notice>();
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();
}
/// <summary>
/// 分页下拉选择
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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点击事件
/// <summary>
/// Grid1行点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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
/// <summary>
/// 增加按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
}
/// <summary>
/// 右键删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
this.DeleteData();
}
/// <summary>
/// 删除方法
/// </summary>
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
/// <summary>
/// 权限设置
/// </summary>
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得到该菜单的权限
/// <summary>
/// 根据不同的系统id得到该菜单的权限
/// </summary>
/// <param name="btn">按钮类型</param>
/// <returns></returns>
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
}
}