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

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_menu : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         if (!IsPostBack)
  17.         {
  18.             this.MakeTree();
  19.         }
  20.     }
  21.     protected void MakeTree()
  22.     {
  23.         TreeNode root = new TreeNode();
  24.         root.Text = "公告通知";
  25.         SqlConnection conn = dbConnection.getConnection();
  26.         conn.Open();
  27.         SqlCommand cmd = new SqlCommand("select id, name from OA_ANNOUNCEMENT_TYPE order by sequence", conn);
  28.         SqlDataReader dr = cmd.ExecuteReader();
  29.         while (dr.Read())
  30.         {
  31.             TreeNode node = new TreeNode();
  32.             node.Text = dr["name"].ToString()+ "(" + this.GetCount(dr["id"].ToString()) + ")";
  33.             node.Target = "main";
  34.             node.NavigateUrl = "announce_list.aspx?type_id=" + dr["id"].ToString();
  35.             root.ChildNodes.Add(node);
  36.         }
  37.         dr.Close();
  38.         conn.Close();
  39.         MenuTree.Nodes.Add(root);
  40.     }
  41.     protected int GetCount(string type_id)
  42.     {
  43.         int department_id = 0;
  44.         if (Session["user"] != null)
  45.         {
  46.             department_id = ((User)Session["user"]).Department.Id;
  47.         }
  48.         DateMgr mgr = new DateMgr();
  49.         string today = mgr.getDate();
  50.         SqlConnection conn = dbConnection.getConnection();
  51.         conn.Open();
  52.         int count = 0;
  53.         SqlCommand cmd = new SqlCommand("select id, authority from OA_ANNOUNCEMENT where type_id=" + type_id +
  54.             " and validate_date>='" + today + "' and is_del='N'", conn);
  55.         SqlDataReader dr = cmd.ExecuteReader();
  56.         while (dr.Read())
  57.         {
  58.             int flag = 0;
  59.             if (dr["authority"].ToString().Equals("2"))
  60.             {
  61.                 if (this.CheckDepartment(department_id, dr["id"].ToString()))
  62.                 {
  63.                     flag = 1;
  64.                 }
  65.             }
  66.             else
  67.             {
  68.                 flag = 1;
  69.             }
  70.             if (flag == 1)
  71.             {
  72.                 count++;
  73.             }
  74.         }
  75.         conn.Close();
  76.         return count;
  77.     }
  78.     protected bool CheckDepartment(int department_id, string announce_id)
  79.     {
  80.         SqlConnection conn = dbConnection.getConnection();
  81.         conn.Open();
  82.         SqlCommand cmd = new SqlCommand("select department_id from OA_ANNOUNCEMENT_DEPARTMENT where a_id=" +
  83.             announce_id, conn);
  84.         SqlDataReader dr = cmd.ExecuteReader();
  85.         while (dr.Read())
  86.         {
  87.             if (Convert.ToInt32(dr["department_id"].ToString()) == department_id)
  88.             {
  89.                 dr.Close();
  90.                 conn.Close();
  91.                 return true;
  92.             }
  93.         }
  94.         dr.Close();
  95.         conn.Close();
  96.         return false;
  97.     }
  98. }