announce_list.aspx.cs
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:4k
源码类别:

OA系统

开发平台:

ASP/ASPX

  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 System.Data.SqlClient;
  12. public partial class web_announcement_announce_list : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         if (!IsPostBack)
  17.         {
  18.             if (Request.QueryString["type_id"] != null)
  19.             {
  20.                 this.SetTable(Request.QueryString["type_id"]);
  21.             }
  22.         }
  23.     }
  24.     protected void SetTable(string type_id)
  25.     {
  26.         DateMgr mgr = new DateMgr();
  27.         string today = mgr.getDate();
  28.         int department_id = 0;
  29.         if (Session["user"] != null)
  30.         {
  31.             department_id = ((User)Session["user"]).Department.Id;
  32.         }
  33.         SqlConnection conn = dbConnection.getConnection();
  34.         conn.Open();
  35.         SqlCommand cmd = new SqlCommand("select id, subject, content, authority, validate_date, cre_user, "+
  36.             "cre_date, attachment, attachment_save_name from OA_ANNOUNCEMENT where type_id="+type_id+
  37.             " and validate_date>='"+today+"' and is_del='N' order by cre_date desc", conn);
  38.         SqlDataReader dr = cmd.ExecuteReader();
  39.         while (dr.Read())
  40.         {
  41.             int flag = 0;
  42.             if (dr["authority"].ToString().Equals("2"))
  43.             {
  44.                 if (this.CheckDepartment(department_id, dr["id"].ToString()))
  45.                 {
  46.                     flag = 1;
  47.                 }
  48.             }
  49.             else
  50.             {
  51.                 flag = 1;
  52.             }
  53.             if (flag == 1)
  54.             { 
  55.                 //添加表格行
  56.                 TableRow tr = new TableRow();
  57.                 TableCell td = new TableCell();
  58.                 Table tbl = new Table();
  59.                 tbl.Width = Unit.Pixel(600);
  60.                 TableHeaderRow thr = new TableHeaderRow();
  61.                 TableHeaderCell thd = new TableHeaderCell();
  62.                 thd.BorderWidth = Unit.Pixel(1);
  63.                 thd.HorizontalAlign = HorizontalAlign.Left;
  64.                 thd.BackColor = System.Drawing.Color.LightGray;
  65.                 thd.Text = dr["subject"].ToString();
  66.                 thr.Cells.Add(thd);
  67.                 tbl.Rows.Add(thr);
  68.                 TableRow tr1 = new TableRow();
  69.                 TableCell td1 = new TableCell();
  70.                 td1.BorderWidth = Unit.Pixel(1);
  71.                 string content = "發佈人:" + dr["cre_user"].ToString()+"<br>";
  72.                 content = content + "發佈時間:" + dr["cre_date"].ToString() + "<br>";
  73.                 content = content + dr["content"].ToString();
  74.                 if (content.Length > 300)
  75.                 {
  76.                     content = content.Substring(0, 300) + "...";
  77.                 }
  78.                 if (!dr["attachment"].ToString().Equals(""))
  79.                 {
  80.                     content = content + "<br>" + "附件:" + dr["attachment"].ToString();
  81.                 }
  82.                 HyperLink hl = new HyperLink();
  83.                 hl.Width = Unit.Pixel(600);
  84.                 hl.Text = content;
  85.                 hl.NavigateUrl = "announce_detail.aspx?a_id=" + dr["id"].ToString();
  86.                 td1.Controls.Add(hl);
  87.                 tr1.Cells.Add(td1);
  88.                 tbl.Rows.Add(tr1);
  89.                 td.Controls.Add(tbl);
  90.                 tr.Cells.Add(td);
  91.                 TblAnnouncement.Rows.Add(tr);
  92.             }
  93.         }
  94.         dr.Close();
  95.         conn.Close();
  96.     }
  97.     protected bool CheckDepartment(int department_id, string announce_id)
  98.     {
  99.         SqlConnection conn = dbConnection.getConnection();
  100.         conn.Open();
  101.         SqlCommand cmd = new SqlCommand("select department_id from OA_ANNOUNCEMENT_DEPARTMENT where a_id="+
  102.             announce_id, conn);
  103.         SqlDataReader dr = cmd.ExecuteReader();
  104.         while (dr.Read())
  105.         { 
  106.             if(Convert.ToInt32(dr["department_id"].ToString()) == department_id)
  107.             {
  108.                 dr.Close();
  109.                 conn.Close();
  110.                 return true;
  111.             }
  112.         }
  113.         dr.Close();
  114.         conn.Close();
  115.         
  116.         return false;
  117.     }
  118. }