📄 messagemanage.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Office.BLL;
using Office.Model;
using System.Collections.Generic;
public partial class Message_MessageManage_MessageManage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.grwMessages.Visible = false;
}
}
# region 查找
private void Search()
{
this.grwMessages.DataSourceID = null;
if (rdbThisDay.Checked)
{
DateTime beg = Convert.ToDateTime(DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day);
DateTime end = beg.AddDays(1);
this.grwMessages.DataSource = MessageManager.GetMessagesByTime(beg, end);
this.grwMessages.DataBind();
}
else if (this.rdbThisWeek.Checked)
{
if (DateTime.Now.DayOfWeek.ToString().Equals("Monday"))
{
DateTime beg = Convert.ToDateTime(DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day);
DateTime end = beg.AddDays(7);
this.grwMessages.DataSource = MessageManager.GetMessagesByTime(beg, end);
this.grwMessages.DataBind();
}
else if (DateTime.Now.DayOfWeek.ToString().Equals("Tuesday "))
{
DateTime beg = Convert.ToDateTime(DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day);
DateTime begin = beg.AddDays(-1);
DateTime end = beg.AddDays(6);
this.grwMessages.DataSource = MessageManager.GetMessagesByTime(begin, end);
this.grwMessages.DataBind();
}
else if (DateTime.Now.DayOfWeek.ToString().Equals("Wednesday"))
{
DateTime beg = Convert.ToDateTime(DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day);
DateTime begin = beg.AddDays(-2);
DateTime end = beg.AddDays(5);
this.grwMessages.DataSource = MessageManager.GetMessagesByTime(begin, end);
this.grwMessages.DataBind();
}
else if (DateTime.Now.DayOfWeek.ToString().Equals("Thursday"))
{
DateTime beg = Convert.ToDateTime(DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day);
DateTime begin = beg.AddDays(-3);
DateTime end = beg.AddDays(4);
this.grwMessages.DataSource = MessageManager.GetMessagesByTime(begin, end);
this.grwMessages.DataBind();
}
else if (DateTime.Now.DayOfWeek.ToString().Equals("Friday"))
{
DateTime beg = Convert.ToDateTime(DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day);
DateTime begin = beg.AddDays(-4);
DateTime end = beg.AddDays(3);
this.grwMessages.DataSource = MessageManager.GetMessagesByTime(begin, end);
this.grwMessages.DataBind();
}
else if (DateTime.Now.DayOfWeek.ToString().Equals("Saturday"))
{
DateTime beg = Convert.ToDateTime(DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day);
DateTime begin = beg.AddDays(-5);
DateTime end = beg.AddDays(2);
this.grwMessages.DataSource = MessageManager.GetMessagesByTime(begin, end);
this.grwMessages.DataBind();
}
else if (DateTime.Now.DayOfWeek.ToString().Equals("Sunday"))
{
DateTime beg = Convert.ToDateTime(DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day);
DateTime begin = beg.AddDays(-6);
DateTime end = beg.AddDays(1);
this.grwMessages.DataSource = MessageManager.GetMessagesByTime(begin, end);
this.grwMessages.DataBind();
}
}
else if (rdbThisMonth.Checked)
{
int day = 0 - DateTime.Now.Day;
DateTime beg = Convert.ToDateTime(DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day);
DateTime begin = beg.AddDays(day);
DateTime end = begin.AddMonths(1);
this.grwMessages.DataSource = MessageManager.GetMessagesByTime(begin, end);
this.grwMessages.DataBind();
}
else
{
string beginTime = this.tbxBeginTime.Text;
string endTime = this.tbxEndTime.Text;
if (beginTime != "" && endTime != "")
{
DateTime begint = Convert.ToDateTime(beginTime);
DateTime endt = Convert.ToDateTime(endTime);
this.grwMessages.DataSource = MessageManager.GetMessagesByTime(begint, endt);
this.grwMessages.DataBind();
}
}
}
# endregion
# region GRIDVIEW空间数据绑定
protected void grwMessages_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label l2 = e.Row.FindControl("Label2") as Label;
int index = Convert.ToInt32(l2.Text);
MessageType type = MessageTypeManager.GetMessageTypeByMessageTypeId(index);
Label l5 = e.Row.FindControl("Label5") as Label;
l5.Text = type.MessageTypeName;
Label l3 = e.Row.FindControl("Label3") as Label;
string userId = l3.Text;
UserInfo user = UserInfoManager.GetUserInfoByUserId(userId);
Label l6 = e.Row.FindControl("Label6") as Label;
l6.Text = user.UserName;
Label l7 = e.Row.FindControl("Label7") as Label;
LinkButton ib1 = e.Row.FindControl("LinkButton1") as LinkButton;
ib1.Text = l7.Text;
Label l1 = e.Row.FindControl("Label1") as Label;
int dex = Convert.ToInt32(l1.Text);
List<MessageToUser> toUser = MessageToUserManager.GetMessageToUser(dex);
LinkButton ib2 = e.Row.FindControl("LinkButton2") as LinkButton;
if (toUser.Count == 1 && toUser[0].ToUserId == "0")
{
ib2.Text = "所有人";
}
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#ff9900'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
e.Row.Attributes["style"] = "Cursor:hand";
ImageButton ibn = (ImageButton)e.Row.FindControl("ImageButton1");
ibn.Attributes.Add("onclick", "return confirm('您确定删除吗?')");
Button b1 = e.Row.FindControl("Button1") as Button;
Label l4 = e.Row.FindControl("Label4") as Label;
int i = Convert.ToInt32(l4.Text);
if (i == 1)
{
b1.Enabled = false;
ibn.Enabled = false;
}
}
}
# endregion
#region 行数据编辑
protected void grwMessages_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Look")
{
Session["mess"] = e.CommandArgument.ToString();
// Response.Write("<script language=javascript>window.open('MessageShow.aspx',toolbar='no',menubar='no',height='100',width='100',resizable='no')</script>");
string js = "<script language=javascript>" +
"window.open('MessageShow.aspx','newwindow', 'height=600, width=800, top=100, " +
"left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, " +
"status=no');</script>";
Page.RegisterStartupScript("js", js);
}
else if (e.CommandName == "fabu")
{
UserInfo user = (UserInfo)Session["User"];
if (user.Role.RoleId == 0 || user.Role.RoleId == 1 || user.Role.RoleId == 11)
{
Response.Write("<script>alert('对不起,您没有该操作权限!!!')</script>");
return;
}
else
{
string messId = e.CommandArgument.ToString();
int index = Convert.ToInt32(messId);
Message mess = MessageManager.GetMessageByMessageId(index);
mess.IfPublish = 1;
MessageManager.ModifyMessage(mess);
Response.Write("<script>alert('发布成功!!!')</script>");
Search();
}
}
else if (e.CommandName == "Edit")
{
UserInfo user = (UserInfo)Session["User"];
if (user.Role.RoleId == 0 || user.Role.RoleId == 1 || user.Role.RoleId == 11)
{
Response.Write("<script>alert('对不起,您没有该操作权限!!!')</script>");
return;
}
else
{
string messId = e.CommandArgument.ToString();
int index = Convert.ToInt32(messId);
Message mess = MessageManager.GetMessageByMessageId(index);
if (mess.IfPublish == 1)
{
Response.Write("<script>alert('消息已发布,操作失败!!!')</script>");
return;
}
else
{
Session["command"] = "edit";
Session["MessageEdit"] = mess;
string js = "<script language=javascript>" +
"window.open('MessageEdit.aspx','newwindow', 'height=600, width=800, top=100, " +
"left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, " +
"status=no');</script>";
Page.RegisterStartupScript("js", js);
// Response.Write("<script language=javascript>window.open('MessageEdit.aspx',toolbar='no',menubar='no',height='200',width='200',resizable='no')</script>");
}
}
}
else if (e.CommandName == "delete")
{
string messId = e.CommandArgument.ToString();
int index = Convert.ToInt32(messId);
MessageManager.DeleteMessageById(index);
MessageToUserManager.DeleteMessageToUserByMessageId(index);
Response.Write("<script>alert('删除成功!!!')</script>");
Search();
}
}
#endregion
protected void ibtnNewMessageAdd_Click(object sender, ImageClickEventArgs e)
{
Session["command"] = "add";
string js = "<script language=javascript>" +
"window.open('MessageEdit.aspx','newwindow', 'height=600, width=800, top=100, " +
"left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, " +
"status=no');</script>";
Page.RegisterStartupScript("js", js);
//Response.Write("<script language=javascript>window.open('MessageEdit.aspx',toolbar='no',menubar='no',height='600',width='800',resizable='no')</script>");
}
protected void lbtNewMessageAdd_Click(object sender, EventArgs e)
{
Session["command"] = "add";
string js = "<script language=javascript>" +
"window.open('MessageEdit.aspx','newwindow', 'height=600, width=800, top=100, " +
"left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, " +
"status=no');</script>";
Page.RegisterStartupScript("js", js);
// Response.Write("<script language=javascript>window.open('MessageEdit.aspx',toolbar='no',menubar='no',height='600',width='800',resizable='no')</script>");
}
protected void Ibt_Search_Click(object sender, ImageClickEventArgs e)
{
this.grwMessages.Visible = true;
Search();
}
#region
protected void grwMessages_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
}
protected void grwMessages_RowEditing(object sender, GridViewEditEventArgs e)
{
}
#endregion
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -