Notice.aspx.cs
上传用户:tiancihang
上传日期:2014-03-12
资源大小:21387k
文件大小:7k
- 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 com.etong.user;
- using com.etong.Inform;
- public partial class SysManage_Notice : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- Notice notice = new Notice();
- CheckUserInfo checkuserinfo = (CheckUserInfo)Session["CheckUserInfo"];
- DataView dv = new DataView();
- int userid = checkuserinfo.UserID;
- //int userid = 0;
- dv = notice.NoticeSearch(userid,-1);
- //dv=notice.NoticeSearch(0,0);
- GridView1.DataSource = dv;
- GridView1.DataBind();
-
- }
- this.GridView1.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
- }
- protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
- {
- CheckUserInfo checkuserinfo = (CheckUserInfo)Session["CheckUserInfo"];
- // DataView dv = new DataView();
- //int roleid = checkuserinfo.RoleID;
- int userid = checkuserinfo.UserID;
- //int userid = 0;
- int currentpageindex;
- currentpageindex = Convert.ToInt32(e.NewPageIndex);
- if (currentpageindex == -2)
- {
- TextBox txtNewPageIndex;
- txtNewPageIndex = GridView1.BottomPagerRow.FindControl("LinkTextBoxNewPage") as TextBox;
- if (txtNewPageIndex != null)
- {
- try
- {
- currentpageindex = Convert.ToInt32(txtNewPageIndex.Text) - 1;
- }
- catch
- {
- currentpageindex = 0;
- }
- }
- }
- currentpageindex = currentpageindex < 0 ? 0 : currentpageindex;
- currentpageindex = currentpageindex >= GridView1.PageCount ? GridView1.PageCount - 1 : currentpageindex;
- GridView1.PageIndex = currentpageindex;
- Notice notice = new Notice();
- DataView dv = notice.NoticeSearch(userid, -1);
- dv.Sort = (string)ViewState["sortFieldName"];
- this.GridView1.DataSource = dv;
- this.GridView1.DataBind();
- }
- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- int iRow;
- iRow = e.Row.DataItemIndex;
- iRow = iRow % 2;
- if (iRow > 0)
- e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='#f0f0f0';");
- else
- e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';");
- e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#E8F2FA';");
- }
- }
- protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
- {
- CheckUserInfo checkuserinfo = (CheckUserInfo)Session["CheckUserInfo"];
- //DataView dv = new DataView();
- //int roleid = checkuserinfo.RoleID;
- int userid = checkuserinfo.UserID;
- //int userid = 0;
- try
- {
- int noticeid = Convert.ToInt16(GridView1.DataKeys[e.RowIndex].Value.ToString());
- Notice notice = new Notice();
- notice.NoticeDelete(noticeid);
- GridView1.DataSource = notice.NoticeSearch(userid,0);
- GridView1.DataBind();
- ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('系统提示:删除记录成功!');</script>");
- }
- catch (Exception ex)
- {
- ClientScript.RegisterStartupScript(this.GetType(), "errorMessage", "<script>alert('" + ex.Message.Replace("'", "").Replace("rn", "") + "');</script>");
- }
- }
- protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
- {
- int noticeid = Convert.ToInt16(GridView1.DataKeys[e.NewEditIndex].Value.ToString());
- ClientScript.RegisterStartupScript(this.GetType(), "", "<script> window.showModalDialog('NoticeUpdate.aspx?NoticeID=" + noticeid + "','','help:0;dialogWidth=600px;dialogHeight=300px,status=no;scroll=no;window.location.replace(window.location.href);')</script>");
- }
- protected void pSDel_Click(object sender, ImageClickEventArgs e)
- {
- CheckUserInfo checkuserinfo = (CheckUserInfo)Session["CheckUserInfo"];
- // DataView dv = new DataView();
- //int roleid = checkuserinfo.RoleID;
- int userid = checkuserinfo.UserID;
- //int userid = 0;
- DateTime starttime = Convert.ToDateTime(TB_start.Text.ToString());
- DateTime endtime = Convert.ToDateTime(TB_end.Text.ToString());
- DataSet ds = new DataSet();
- Notice notice = new Notice();
- ds = notice.NoticeSearch(starttime, endtime);
- if (ds.Tables[0].Rows.Count > 0)
- {
- try
- {
- notice.NoticeDelete(userid, starttime, endtime);
- GridView1.DataSource = notice.NoticeSearch(userid,0);
- GridView1.DataBind();
- ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('系统提示:删除记录成功!');</script>");
- }
- catch (Exception ex)
- {
- ClientScript.RegisterStartupScript(this.GetType(), "errorMessage", "<script>alert('" + ex.Message.Replace("'", "").Replace("rn", "") + "');</script>");
- }
- }
- else
- {
- ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('系统提示:不存在此时间段的记录!');</script>");
- }
- }
- protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
- {
- Notice notice = new Notice();
- CheckUserInfo checkuserinfo = (CheckUserInfo)Session["CheckUserInfo"];
- DataView dv = new DataView();
- //int roleid = checkuserinfo.RoleID;
- int userid = checkuserinfo.UserID;
- //int userid = 0;
- dv = notice.NoticeSearch(userid, -1);
-
- dv.Sort = e.SortExpression + GetSortDirection(e.SortExpression);
- ViewState["sortFieldName"] = dv.Sort;
- GridView1.DataSource = dv;
- GridView1.DataBind();
- }
- public string GetSortDirection(string fieldName)
- {
- if (fieldName != null)
- {
- string currentSortDirection = ViewState[fieldName] as string;
- if (currentSortDirection == null) currentSortDirection = " ASC";
- else if (currentSortDirection == " ASC") currentSortDirection = " DESC";
- else currentSortDirection = " ASC";
- ViewState[fieldName] = currentSortDirection;
- return currentSortDirection;
- }
- else
- {
- return null;
- }
- }
- }