Notice.aspx.cs
上传用户:tiancihang
上传日期:2014-03-12
资源大小:21387k
文件大小:7k
源码类别:

.net编程

开发平台:

C#

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using com.etong.user;
  12. using com.etong.Inform;
  13. public partial class SysManage_Notice : System.Web.UI.Page
  14. {    
  15.     protected void Page_Load(object sender, EventArgs e)
  16.     {
  17.         if (!IsPostBack)
  18.         {            
  19.             Notice notice = new Notice();
  20.             CheckUserInfo checkuserinfo = (CheckUserInfo)Session["CheckUserInfo"];
  21.             DataView dv = new DataView();
  22.             int userid = checkuserinfo.UserID;
  23.             //int userid = 0;
  24.             dv = notice.NoticeSearch(userid,-1);
  25.             //dv=notice.NoticeSearch(0,0);          
  26.             GridView1.DataSource = dv;
  27.             GridView1.DataBind();          
  28.             
  29.         }
  30.         this.GridView1.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
  31.     }
  32.     protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
  33.     {
  34.         CheckUserInfo checkuserinfo = (CheckUserInfo)Session["CheckUserInfo"];
  35.        // DataView dv = new DataView();
  36.         //int roleid = checkuserinfo.RoleID;
  37.         int userid = checkuserinfo.UserID;
  38.         //int userid = 0;
  39.         int currentpageindex;
  40.         currentpageindex = Convert.ToInt32(e.NewPageIndex);
  41.         if (currentpageindex == -2)
  42.         {
  43.             TextBox txtNewPageIndex;
  44.             txtNewPageIndex = GridView1.BottomPagerRow.FindControl("LinkTextBoxNewPage") as TextBox;
  45.             if (txtNewPageIndex != null)
  46.             {
  47.                 try
  48.                 {
  49.                     currentpageindex = Convert.ToInt32(txtNewPageIndex.Text) - 1;
  50.                 }
  51.                 catch
  52.                 {
  53.                     currentpageindex = 0;
  54.                 }
  55.             }
  56.         }
  57.         currentpageindex = currentpageindex < 0 ? 0 : currentpageindex;
  58.         currentpageindex = currentpageindex >= GridView1.PageCount ? GridView1.PageCount - 1 : currentpageindex;
  59.         GridView1.PageIndex = currentpageindex;
  60.         Notice notice = new Notice();
  61.         DataView dv = notice.NoticeSearch(userid, -1);
  62.         dv.Sort = (string)ViewState["sortFieldName"];
  63.         this.GridView1.DataSource = dv;
  64.         this.GridView1.DataBind();
  65.     }
  66.     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  67.     {
  68.         if (e.Row.RowType == DataControlRowType.DataRow)
  69.         {
  70.             int iRow;
  71.             iRow = e.Row.DataItemIndex;
  72.             iRow = iRow % 2;
  73.             if (iRow > 0)
  74.                 e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='#f0f0f0';");
  75.             else
  76.                 e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';");
  77.             e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#E8F2FA';");
  78.         }
  79.     }
  80.     protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
  81.     {
  82.         CheckUserInfo checkuserinfo = (CheckUserInfo)Session["CheckUserInfo"];
  83.         //DataView dv = new DataView();
  84.         //int roleid = checkuserinfo.RoleID;
  85.         int userid = checkuserinfo.UserID;
  86.         //int userid = 0;
  87.         try
  88.         {
  89.             int noticeid = Convert.ToInt16(GridView1.DataKeys[e.RowIndex].Value.ToString());
  90.             Notice notice = new Notice();
  91.             notice.NoticeDelete(noticeid);
  92.             GridView1.DataSource = notice.NoticeSearch(userid,0);
  93.             GridView1.DataBind();
  94.             ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('系统提示:删除记录成功!');</script>");
  95.         }
  96.         catch (Exception ex)
  97.         {
  98.             ClientScript.RegisterStartupScript(this.GetType(), "errorMessage", "<script>alert('" + ex.Message.Replace("'", "").Replace("rn", "") + "');</script>");
  99.         }
  100.     }
  101.     protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
  102.     {
  103.         int noticeid = Convert.ToInt16(GridView1.DataKeys[e.NewEditIndex].Value.ToString());
  104.         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>");
  105.     }
  106.     protected void pSDel_Click(object sender, ImageClickEventArgs e)
  107.     {
  108.         CheckUserInfo checkuserinfo = (CheckUserInfo)Session["CheckUserInfo"];
  109.           // DataView dv = new DataView();            
  110.         //int roleid = checkuserinfo.RoleID;
  111.         int userid = checkuserinfo.UserID;
  112.         //int userid = 0;
  113.         DateTime starttime = Convert.ToDateTime(TB_start.Text.ToString());
  114.         DateTime endtime = Convert.ToDateTime(TB_end.Text.ToString());
  115.         DataSet ds = new DataSet();
  116.         Notice notice = new Notice();
  117.         ds = notice.NoticeSearch(starttime, endtime);
  118.         if (ds.Tables[0].Rows.Count > 0)
  119.         {
  120.             try
  121.             {                
  122.                 notice.NoticeDelete(userid, starttime, endtime);
  123.                 GridView1.DataSource = notice.NoticeSearch(userid,0);
  124.                 GridView1.DataBind();
  125.                 ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('系统提示:删除记录成功!');</script>");
  126.             }
  127.             catch (Exception ex)
  128.             {
  129.                 ClientScript.RegisterStartupScript(this.GetType(), "errorMessage", "<script>alert('" + ex.Message.Replace("'", "").Replace("rn", "") + "');</script>");
  130.             }
  131.         }
  132.         else
  133.         {
  134.             ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('系统提示:不存在此时间段的记录!');</script>");
  135.         }
  136.     }
  137.     protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
  138.     {
  139.         Notice notice = new Notice();
  140.         CheckUserInfo checkuserinfo = (CheckUserInfo)Session["CheckUserInfo"];
  141.         DataView dv = new DataView();
  142.         //int roleid = checkuserinfo.RoleID;
  143.         int userid = checkuserinfo.UserID;
  144.         //int userid = 0;
  145.         dv = notice.NoticeSearch(userid, -1);            
  146.       
  147.         dv.Sort = e.SortExpression + GetSortDirection(e.SortExpression);
  148.         ViewState["sortFieldName"] = dv.Sort;
  149.         GridView1.DataSource = dv;
  150.         GridView1.DataBind();  
  151.     }
  152.     public string GetSortDirection(string fieldName)
  153.     {
  154.         if (fieldName != null)
  155.         {
  156.             string currentSortDirection = ViewState[fieldName] as string;
  157.             if (currentSortDirection == null) currentSortDirection = " ASC";
  158.             else if (currentSortDirection == " ASC") currentSortDirection = " DESC";
  159.             else currentSortDirection = " ASC";
  160.             ViewState[fieldName] = currentSortDirection;
  161.             return currentSortDirection;
  162.         }
  163.         else
  164.         {
  165.             return null;
  166.         }
  167.     }
  168. }