authority.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:18k
源码类别:
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 : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- LoginDAO.CheckLogin(Session, Response, "../", 2);
- if (!IsPostBack)
- {
- this.AddOaTable();
- this.AddKmTable();
- }
- }
- //動態生成選單表格
- protected void AddOaTable()
- {
- 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]+")";
- 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();
- 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();
- 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();
- 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()
- {
- Table mainTable = new Table();
- mainTable.ID = "TblKm";
- 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] + ")";
- 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();
- 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();
- 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();
- 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();
- 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
- {
- SqlCommand cmd = new SqlCommand("select count(*) from OA_USER_GROUP_MAIN where name='" + TxtName.Text + "'", conn);
- cmd.Transaction = tx;
- int count = Convert.ToInt32(cmd.ExecuteScalar());
- if (count == 0)
- {
- int main_id = 1;
- cmd = new SqlCommand("select max(id) from OA_USER_GROUP_MAIN", conn);
- try
- {
- cmd.Transaction = tx;
- main_id = Convert.ToInt32(cmd.ExecuteScalar()) + 1;
- }
- catch { }
- DateMgr mgr = new DateMgr();
- string time = mgr.getDateTime();
- User user = new User();
- if (Session["user"] != null)
- {
- user = (User)Session["user"];
- }
- cmd = new SqlCommand("insert into OA_USER_GROUP_MAIN(id, name, department_id, cre_user, cre_date)" +
- "values(" + main_id + ",'" + TxtName.Text + "',0,'" + user.Emp_name + "','" + time + "')", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- string[] menus = Menus.Value.Split(new char[] { ',' });
- for (int i = 0; i < menus.Length; i++)
- {
- cmd = new SqlCommand("insert into OA_USER_GROUP_DETAIL(main_id, menu_id)" +
- "values(" + main_id + ", '" + menus[i] + "')", conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- }
- //添加規章制度瀏覽權限設定
- 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="+main_id, conn);
- cmd.Transaction = tx;
- cmd.ExecuteNonQuery();
- }
- tx.Commit();
- }
- else
- {
- this.AddOaTable();
- this.AddKmTable();
- TxtName.Focus();
- Response.Write("<script language='javascript'>alert('已存在相同名稱的權限群組, 請重新輸入');</script>");
- }
- }
- catch (Exception ex)
- {
- tx.Rollback();
- Response.Write(ex.Message);
- }
- Response.Redirect("authority_list.aspx");
- conn.Close();
- }
- }