authority_list.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_system_authority_list : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         LoginDAO.CheckLogin(Session, Response, "../", 2);
  17.         if (!IsPostBack)
  18.         {
  19.             GroupList.DataKeyNames = new string[] { "id" };
  20.         }
  21.     }
  22.     protected void GroupList_RowCreated(object sender, GridViewRowEventArgs e)
  23.     {
  24.         if (e.Row.RowType == DataControlRowType.DataRow)
  25.         {
  26.             LinkButton btnDelete = (LinkButton)e.Row.FindControl("BtnDelete");
  27.             btnDelete.CommandArgument = GroupList.DataKeys[e.Row.RowIndex].Value.ToString(); 
  28.             SqlConnection conn = dbConnection.getConnection();
  29.             conn.Open();
  30.             LinkButton BtnCount = (LinkButton)e.Row.FindControl("BtnEmpCount");
  31.             SqlCommand cmd = new SqlCommand("select count(id) from OA_EMPLOYEE where user_group="+GroupList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
  32.             BtnCount.Text = cmd.ExecuteScalar().ToString();
  33.             BtnCount.PostBackUrl = "authority_employee_list.aspx?g_id=" + GroupList.DataKeys[e.Row.RowIndex].Value.ToString();
  34.             LinkButton btn = (LinkButton)e.Row.FindControl("BtnDelete");
  35.             if (!BtnCount.Text.Equals("0"))
  36.             {
  37.                 btn.OnClientClick = "";
  38.                 btn.Enabled = false;
  39.             }
  40.             btn = (LinkButton)e.Row.FindControl("BtnName");
  41.             cmd = new SqlCommand("select name from OA_USER_GROUP_MAIN where id=" + GroupList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
  42.             btn.Text = cmd.ExecuteScalar().ToString();
  43.             btn.PostBackUrl = "authority_edit.aspx?g_id=" + GroupList.DataKeys[e.Row.RowIndex].Value.ToString();
  44.             conn.Close();
  45.         }
  46.     }
  47.     protected void GroupList_RowDataBound(object sender, GridViewRowEventArgs e)
  48.     {
  49.         //行高亮
  50.         if (e.Row.RowType == DataControlRowType.DataRow)
  51.         {
  52.             e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;");
  53.             e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
  54.             //e.Row.Attributes.Add("onclick", "location.href='authority_edit.aspx?g_id=" + GroupList.DataKeys[e.Row.RowIndex].Value.ToString() + "'");
  55.         }
  56.     }
  57.     protected void GroupList_RowCommand(object sender, GridViewCommandEventArgs e)
  58.     {
  59.         if (e.CommandName.Equals("DeleteData"))
  60.         {
  61.             string id = e.CommandArgument.ToString();
  62.             //點擊刪除按鈕
  63.             try
  64.             {
  65.                 SqlConnection conn = dbConnection.getConnection();
  66.                 conn.Open();
  67.                 SqlCommand cmd = new SqlCommand("delete from OA_USER_GROUP_MAIN where id="+id, conn);
  68.                 cmd.ExecuteNonQuery();
  69.                 conn.Close();
  70.                 GroupList.DataBind();
  71.             }
  72.             catch (Exception ex)
  73.             {
  74.                 Response.Write("delete from OA_USER_GROUP_MAIN where id=" + id);
  75.                 Response.Write(ex.Message);
  76.             }
  77.         }
  78.     }
  79. }