authority_edit.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:22k
源码类别:
OA系统
开发平台:
ASP/ASPX
- 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 System.Data.SqlClient;
- public partial class web_system_authority_edit : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- LoginDAO.CheckLogin(Session, Response, "../", 2);
- if (!IsPostBack)
- {
- ArrayList ids = new ArrayList();
- if (Request.QueryString["g_id"] != null)
- {
- ids = this.getMenuIds(Request.QueryString["g_id"]);
- }
- this.AddOaTable(ids);
- this.AddKmTable(ids);
- }
- }
- protected ArrayList getMenuIds(string group_id)
- {
- ArrayList ids = new ArrayList();
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select menu_id from OA_USER_GROUP_DETAIL where main_id="+group_id, conn);
- SqlDataReader dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- ids.Add(dr["menu_id"].ToString());
- }
- dr.Close();
- cmd = new SqlCommand("select name from OA_USER_GROUP_MAIN where id="+group_id, conn);
- TxtName.Text = cmd.ExecuteScalar().ToString();
- conn.Close();
- return ids;
- }
- protected ArrayList GetDirEdit(string main_id)
- {
- ArrayList dirEdits = new ArrayList();
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select menu_id from OA_USER_GROUP_DETAIL where main_id=" +
- main_id + " and function_id='edit'", conn);
- SqlDataReader dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- dirEdits.Add(dr["menu_id"].ToString());
- }
- dr.Close();
- conn.Close();
- return dirEdits;
- }
- //動態生成選單表格
- protected void AddOaTable(ArrayList menus)
- {
- Table mainTable = new Table();
- mainTable.BorderWidth = Unit.Pixel(1);
- mainTable.HorizontalAlign = HorizontalAlign.Center;
- PnlOa.Controls.Add(mainTable);
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- ArrayList ids = new ArrayList();
- ArrayList names = new ArrayList();
- SqlCommand cmd = new SqlCommand("select id, name from OA_SYS_CHILD_MENU where id=78 or id=22 or id=24 or id=161 order by name", conn);
- SqlDataReader dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- ids.Add(dr["id"].ToString());
- names.Add(dr["name"].ToString());
- }
- dr.Close();
- for (int i = 0; i < ids.Count; i++)
- {
- TableRow tr1 = new TableRow();
- tr1.BorderWidth = Unit.Pixel(1);
- TableCell td1 = new TableCell();
- td1.Width = Unit.Pixel(150);
- tr1.HorizontalAlign = HorizontalAlign.Left;
- CheckBox cb = new CheckBox();
- cb.ID = "chk" + ids[i].ToString();
- cb.Text = names[i].ToString();
- cb.InputAttributes["parent"] = "1";
- cb.InputAttributes["value"] = ids[i].ToString();
- cb.InputAttributes["onclick"] = "check(" + ids[i] + ")";
- cb.Checked = false;
- for (int m = 0; m < menus.Count; m++)
- {
- if(menus[m].Equals(ids[i]))
- {
- cb.Checked = true;
- break;
- }
- }
- td1.Controls.Add(cb);
- tr1.Cells.Add(td1);
- td1.BorderWidth = Unit.Pixel(1);
- ArrayList ids1 = new ArrayList();
- ArrayList names1 = new ArrayList();
- cmd = new SqlCommand("select id, name from OA_SYS_CHILD_MENU where parent_id=" + ids[i] + " and is_open='Y' order by name", conn);
- dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- ids1.Add(dr["id"].ToString());
- names1.Add(dr["name"].ToString());
- }
- dr.Close();
- Table tb1 = new Table();
- TableCell td2 = new TableCell();
- td2.BorderWidth = Unit.Pixel(1);
- td2.Width = Unit.Pixel(750);
- for (int j = 0; j < ids1.Count; j++)
- {
- TableRow tr2 = new TableRow();
- TableCell td3 = new TableCell();
- td3.BorderWidth = Unit.Pixel(1);
- td3.Width = Unit.Pixel(200);
- tr2.HorizontalAlign = HorizontalAlign.Left;
- cb = new CheckBox();
- cb.InputAttributes["parent"] = ids[i].ToString();
- cb.InputAttributes["value"] = ids1[j].ToString();
- cb.InputAttributes["onclick"] = "check(" + ids1[j] + ")";
- cb.ID = "chk" + ids1[j].ToString();
- cb.Text = names1[j].ToString();
- cb.Checked = false;
- for (int m = 0; m < menus.Count; m++)
- {
- if (menus[m].Equals(ids1[j]))
- {
- cb.Checked = true;
- break;
- }
- }
- td3.Controls.Add(cb);
- tr2.Cells.Add(td3);
- ArrayList ids2 = new ArrayList();
- ArrayList names2 = new ArrayList();
- cmd = new SqlCommand("select id, name from OA_SYS_CHILD_MENU where parent_id=" + ids1[j] + " and is_open='Y' order by name", conn);
- dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- ids2.Add(dr["id"].ToString());
- names2.Add(dr["name"].ToString());
- }
- dr.Close();
- Table tb2 = new Table();
- TableCell td5 = new TableCell();
- td5.BorderWidth = Unit.Pixel(1);
- td5.Width = Unit.Pixel(500);
- for (int k = 0; k < ids2.Count; k++)
- {
- TableRow tr3 = new TableRow();
- TableCell td4 = new TableCell();
- td4.BorderWidth = Unit.Pixel(1);
- td4.Width = Unit.Pixel(220);
- tr3.HorizontalAlign = HorizontalAlign.Left;
- cb = new CheckBox();
- cb.InputAttributes["parent"] = ids1[j].ToString();
- cb.InputAttributes["value"] = ids2[k].ToString();
- cb.InputAttributes["onclick"] = "check(" + ids2[k] + ")";
- cb.ID = "chk" + ids2[k].ToString();
- cb.Text = names2[k].ToString();
- cb.Checked = false;
- for (int m = 0; m < menus.Count; m++)
- {
- if (menus[m].Equals(ids2[k]))
- {
- cb.Checked = true;
- break;
- }
- }
- td4.Controls.Add(cb);
- tr3.Cells.Add(td4);
- tb2.Rows.Add(tr3);
- ArrayList ids3 = new ArrayList();
- ArrayList names3 = new ArrayList();
- cmd = new SqlCommand("select id, name from OA_SYS_CHILD_MENU where parent_id=" + ids2[k] + " and is_open='Y' order by name", conn);
- dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- ids3.Add(dr["id"].ToString());
- names3.Add(dr["name"].ToString());
- }
- dr.Close();
- TableCell td6 = new TableCell();
- td6.VerticalAlign = VerticalAlign.Top;
- Table tb3 = new Table();
- for (int l = 0; l < ids3.Count; l++)
- {
- TableRow tr4 = new TableRow();
- TableCell td7 = new TableCell();
- td7.BorderWidth = Unit.Pixel(1);
- td7.Width = Unit.Pixel(280);
- td7.VerticalAlign = VerticalAlign.Top;
- tr3.HorizontalAlign = HorizontalAlign.Left;
- cb = new CheckBox();
- cb.InputAttributes["parent"] = ids2[k].ToString();
- cb.InputAttributes["value"] = ids3[l].ToString();
- cb.InputAttributes["onclick"] = "check(" + ids3[l] + ")";
- cb.ID = "chk" + ids3[l].ToString();
- cb.Text = names3[l].ToString();
- cb.Checked = false;
- for (int m = 0; m < menus.Count; m++)
- {
- if (menus[m].Equals(ids3[l]))
- {
- cb.Checked = true;
- break;
- }
- }
- td7.Controls.Add(cb);
- tr4.Cells.Add(td7);
- tb3.Rows.Add(tr4);
- }
- td6.Controls.Add(tb3);
- tr3.Cells.Add(td6);
- }
- td5.Controls.Add(tb2);
- tr2.Cells.Add(td5);
- tb1.Rows.Add(tr2);
- }
- td2.Controls.Add(tb1);
- tr1.Cells.Add(td2);
- mainTable.Rows.Add(tr1);
- }
- mainTable.Rows.Add(new TableRow());
- conn.Close();
- }
- protected void AddKmTable(ArrayList menus)
- {
- ArrayList dirEdits = this.GetDirEdit(Request.QueryString["g_id"]);
- Table mainTable = new Table();
- mainTable.BorderWidth = Unit.Pixel(1);
- mainTable.HorizontalAlign = HorizontalAlign.Center;
- PnlKm.Controls.Add(mainTable);
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- ArrayList ids = new ArrayList();
- ArrayList names = new ArrayList();
- SqlCommand cmd = new SqlCommand("select id, name from OA_SYS_CHILD_MENU where parent_id=77 and is_open='Y' order by name", conn);
- SqlDataReader dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- ids.Add(dr["id"].ToString());
- names.Add(dr["name"].ToString());
- }
- dr.Close();
- for (int i = 0; i < ids.Count; i++)
- {
- TableRow tr1 = new TableRow();
- tr1.BorderWidth = Unit.Pixel(1);
- TableCell td1 = new TableCell();
- td1.Width = Unit.Pixel(150);
- tr1.HorizontalAlign = HorizontalAlign.Left;
- CheckBox cb = new CheckBox();
- cb.ID = "chk" + ids[i].ToString();
- cb.Text = names[i].ToString();
- cb.InputAttributes["parent"] = "1";
- cb.InputAttributes["value"] = ids[i].ToString();
- cb.InputAttributes["onclick"] = "check(" + ids[i] + ")";
- cb.Checked = false;
- for (int m = 0; m < menus.Count; m++)
- {
- if (menus[m].Equals(ids[i]))
- {
- cb.Checked = true;
- break;
- }
- }
- td1.Controls.Add(cb);
- tr1.Cells.Add(td1);
- td1.BorderWidth = Unit.Pixel(1);
- ArrayList ids1 = new ArrayList();
- ArrayList names1 = new ArrayList();
- cmd = new SqlCommand("select id, name from OA_SYS_CHILD_MENU where parent_id=" + ids[i] + " and is_open='Y' order by name", conn);
- dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- ids1.Add(dr["id"].ToString());
- names1.Add(dr["name"].ToString());
- }
- dr.Close();
- Table tb1 = new Table();
- TableCell td2 = new TableCell();
- td2.BorderWidth = Unit.Pixel(1);
- td2.Width = Unit.Pixel(750);
- int max_dir = 0;
- for (int j = 0; j < ids1.Count; j++)
- {
- TableRow tr2 = new TableRow();
- TableCell td3 = new TableCell();
- td3.BorderWidth = Unit.Pixel(1);
- td3.Width = Unit.Pixel(200);
- tr2.HorizontalAlign = HorizontalAlign.Left;
- cb = new CheckBox();
- cb.InputAttributes["parent"] = ids[i].ToString();
- cb.InputAttributes["value"] = ids1[j].ToString();
- cb.InputAttributes["onclick"] = "check(" + ids1[j] + ")";
- cb.ID = "chk" + ids1[j].ToString();
- cb.Text = names1[j].ToString();
- cb.Checked = false;
- for (int m = 0; m < menus.Count; m++)
- {
- if (menus[m].Equals(ids1[j]))
- {
- cb.Checked = true;
- break;
- }
- }
- td3.Controls.Add(cb);
- tr2.Cells.Add(td3);
- ArrayList ids2 = new ArrayList();
- ArrayList names2 = new ArrayList();
- cmd = new SqlCommand("select id, name from OA_SYS_CHILD_MENU where parent_id=" + ids1[j] + " and is_open='Y' order by name", conn);
- dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- ids2.Add(dr["id"].ToString());
- names2.Add(dr["name"].ToString());
- }
- dr.Close();
- Table tb2 = new Table();
- TableCell td5 = new TableCell();
- td5.BorderWidth = Unit.Pixel(1);
- td5.Width = Unit.Pixel(500);
- if (!ids[i].Equals("16"))
- {
- for (int k = 0; k < ids2.Count; k++)
- {
- TableRow tr3 = new TableRow();
- TableCell td4 = new TableCell();
- td4.BorderWidth = Unit.Pixel(1);
- td4.Width = Unit.Pixel(220);
- tr3.HorizontalAlign = HorizontalAlign.Left;
- cb = new CheckBox();
- cb.InputAttributes["parent"] = ids1[j].ToString();
- cb.InputAttributes["value"] = ids2[k].ToString();
- cb.InputAttributes["onclick"] = "check(" + ids2[k] + ")";
- cb.ID = "chk" + ids2[k].ToString();
- cb.Text = names2[k].ToString();
- cb.Checked = false;
- for (int m = 0; m < menus.Count; m++)
- {
- if (menus[m].Equals(ids2[k]))
- {
- cb.Checked = true;
- break;
- }
- }
- td4.Controls.Add(cb);
- tr3.Cells.Add(td4);
- tb2.Rows.Add(tr3);
- ArrayList ids3 = new ArrayList();
- ArrayList names3 = new ArrayList();
- cmd = new SqlCommand("select id, name from OA_SYS_CHILD_MENU where parent_id=" + ids2[k] + " and is_open='Y' order by name", conn);
- dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- ids3.Add(dr["id"].ToString());
- names3.Add(dr["name"].ToString());
- }
- dr.Close();
- TableCell td6 = new TableCell();
- td6.VerticalAlign = VerticalAlign.Top;
- Table tb3 = new Table();
- for (int l = 0; l < ids3.Count; l++)
- {
- TableRow tr4 = new TableRow();
- TableCell td7 = new TableCell();
- td7.BorderWidth = Unit.Pixel(1);
- td7.Width = Unit.Pixel(280);
- td7.VerticalAlign = VerticalAlign.Top;
- tr3.HorizontalAlign = HorizontalAlign.Left;
- cb = new CheckBox();
- cb.InputAttributes["parent"] = ids2[k].ToString();
- cb.InputAttributes["value"] = ids3[l].ToString();
- cb.InputAttributes["onclick"] = "check(" + ids3[l] + ")";
- cb.ID = "chk" + ids3[l].ToString();
- cb.Text = names3[l].ToString();
- cb.Checked = false;
- for (int m = 0; m < menus.Count; m++)
- {
- if (menus[m].Equals(ids3[l]))
- {
- cb.Checked = true;
- break;
- }
- }
- td7.Controls.Add(cb);
- tr4.Cells.Add(td7);
- tb3.Rows.Add(tr4);
- }
- td6.Controls.Add(tb3);
- tr3.Cells.Add(td6);
- }
- }
- else
- {
- if (Convert.ToInt32(ids1[j]) > max_dir)
- {
- max_dir = Convert.ToInt32(ids1[j]);
- }
- TableRow trDir = new TableRow();
- TableCell tdDir = new TableCell();
- tdDir.VerticalAlign = VerticalAlign.Top;
- RadioButtonList rb = new RadioButtonList();
- rb.ID = "rb" + ids1[j];
- rb.RepeatDirection = RepeatDirection.Horizontal;
- ListItem item = new ListItem();
- item.Selected = true;
- item.Value = "view" + ids1[j];
- item.Text = "瀏覽<br><br>";
- rb.Items.Add(item);
- item = new ListItem();
- for (int o = 0; o < dirEdits.Count; o++)
- {
- if (dirEdits[o].ToString().Equals(ids1[j]))
- {
- item.Selected = true;
- }
- }
- item.Value = "edit" + ids1[j];
- item.Text = "編輯<br><br>";
- rb.Items.Add(item);
- tdDir.Controls.Add(rb);
- trDir.Cells.Add(tdDir);
- tb2.Rows.Add(trDir);
- MaxDir.Value = max_dir.ToString();
- }
- td5.Controls.Add(tb2);
- tr2.Cells.Add(td5);
- tb1.Rows.Add(tr2);
- }
- td2.Controls.Add(tb1);
- tr1.Cells.Add(td2);
- mainTable.Rows.Add(tr1);
- }
- mainTable.Rows.Add(new TableRow());
- conn.Close();
- }
- protected void BtnOk_Click(object sender, EventArgs e)
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlTransaction tx = conn.BeginTransaction();
- try
- {
- string id = "0";
- if (Request.QueryString["g_id"] != null)
- {
- id = Request.QueryString["g_id"];
- }
- DateMgr mgr = new DateMgr();
- string time = mgr.getDateTime();
- User user = new User();
- if (Session["user"] != null)
- {
- user = (User)Session["user"];
- }
- SqlCommand cmd = new SqlCommand("update OA_USER_GROUP_MAIN set name='"+TxtName.Text+"', upd_user='"+user.Emp_name+"', upd_date='"+time+"' where id="+id, conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- //刪除原來的權限群組
- cmd = new SqlCommand("delete from OA_USER_GROUP_DETAIL where main_id="+id, conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- string[] menus = Menus.Value.Split(new char[] { ',' });
- for (int i = 0; i < menus.Length; i++)
- {
- try
- {
- cmd = new SqlCommand("insert into OA_USER_GROUP_DETAIL(main_id, menu_id)" +
- "values(" + id + ", " + menus[i] + ")", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- }
- catch { }
- }
- //添加規章制度瀏覽權限設定
- string[] dir_edit = DirEdit.Value.Split(new char[] { ';' });
- for (int i = 0; i < dir_edit.Length - 1; i++)
- {
- cmd = new SqlCommand("update OA_USER_GROUP_DETAIL set function_id='edit' where menu_id=" + dir_edit[i] + " and main_id=" + id, conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- }
- tx.Commit();
- }
- catch (Exception ex)
- {
- tx.Rollback();
- Response.Write(ex.Message);
- }
- Response.Redirect("authority_list.aspx");
- conn.Close();
- }
- }