protected void btnAdd_Click(object sender, EventArgs e)
    {
        PEmpPermissionsData empPermissionsData = new PEmpPermissionsData();
        PEmpPermissionsBB empPermissionsBB = new PEmpPermissionsBB();
        HEemployeeBB eemployeeBB = new HEemployeeBB();
        try
        {
            //删除当前人员所有权限
            empPermissionsBB.DeleteRecordByEmp(this.EmpId, 2);

            //保存权限
            CheckBox checkBox = new CheckBox();
            foreach (DataListItem item in this.DataList1.Items)
            {
                //获取ItemoNo
                Label label = (Label)item.FindControl("itemNo");
                string itemNo = label.Text;
                if (itemNo.IndexOf('-') >= 0)
                {
                    itemNo = itemNo.Substring(itemNo.LastIndexOf('-') + 1);
                }

                foreach (System.Web.UI.Control control in item.Controls)
                {
                    if (control.GetType() == checkBox.GetType())
                    {
                        if (((CheckBox)control).Checked == true && !eemployeeBB.HasPermissions(this.EmpId, itemNo, ((CheckBox)control).ToolTip))
                        {
                            //保存权限
                            empPermissionsData.empId = this.EmpId;
                            empPermissionsData.itemNo = itemNo;
                            empPermissionsData.permissionsTypeNo = ((CheckBox)control).ToolTip;
                            empPermissionsData.isSpecial = false;
                            empPermissionsBB.AddRecord(empPermissionsData);
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
            return;
        }
        finally
        {
            empPermissionsBB.Dispose();
            eemployeeBB.Dispose();
        }

        this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('保存成功!');", true);
    }
示例#2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string idValue = Request.Params["id"];
            if (idValue != null)
            {
                int id = int.Parse(idValue);
                //删除节点的同时,删除TreeFunction、角色权限、人员权限
                STreeData treeData = new STreeData();
                STreeBB treeBB = new STreeBB();
                STreeFunctionBB treeFunctionBB = new STreeFunctionBB();
                PRolePermissionsBB rolePermissionsBB = new PRolePermissionsBB();
                PEmpPermissionsBB empPermissionsBB = new PEmpPermissionsBB();
                try
                {
                    treeData = treeBB.GetModel(id);
                    treeBB.DeleteRecord(id);
                    treeFunctionBB.DeleteRecordByNode(id);
                    rolePermissionsBB.DeleteRecordByItem(treeData.itemNo);
                    empPermissionsBB.DeleteRecordByItem(treeData.itemNo);

                    this.RefreshApplicationPageUrlTable();
                    this.RefreshApplicationTreeTable();

                    ClientScript.RegisterStartupScript(this.GetType(), "CloseSubmit", "CloseSubmit()", true);
                }
                catch (Exception ex)
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
                    return;
                }
                finally
                {
                    treeBB.Dispose();
                    treeFunctionBB.Dispose();
                    rolePermissionsBB.Dispose();
                    empPermissionsBB.Dispose();
                }
            }
        }
    }
    /// <summary>
    /// 根据当前人员绑定DataList
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        PEmpPermissionsBB empPermissionsBB = new PEmpPermissionsBB();
        STreeFunctionBB treeFunctionBB = new STreeFunctionBB();
        HEemployeeBB eemployeeBB = new HEemployeeBB();
        SCommBB commBB = new SCommBB();
        DataSet perDs = new DataSet();
        DataSet ds = new DataSet();
        try
        {
            HtmlInputHidden hid = (HtmlInputHidden)e.Item.FindControl("nodeId");
            string nodeId = hid.Value;

            Label label = (Label)e.Item.FindControl("itemNo");
            string itemNo = label.Text;
            if (itemNo.IndexOf('-') >= 0)
            {
                itemNo = itemNo.Substring(itemNo.LastIndexOf('-') + 1);
            }

            //除了超级管理员,其他用户只能在自己的权限列表范围之内进行分配
            if (this.IsHaveRole(1))
            {
                ds = treeFunctionBB.GetList("nodeId=" + nodeId);
            }
            else
            {
                ds = commBB.Query("select distinct permissionsTypeId,permissionsTypeNo as functionNo,permissionsTypeNm as functionNm from vSTree where empId="
                    + this.currentUser.empId.ToString() + " and nodeId=" + nodeId + " order by permissionsTypeId");
            }

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                DataRow row = ds.Tables[0].Rows[i];

                //添加文本“<TD></TD>"以控制格式
                HtmlGenericControl td = new HtmlGenericControl();
                td.InnerHtml = "</td><td>";
                e.Item.Controls.Add(td);

                CheckBox checkBox = new CheckBox();
                checkBox.ID = "checkBox" + i.ToString();
                checkBox.Text = row["functionNm"].ToString();
                checkBox.ToolTip = row["functionNo"].ToString();

                //给checkBox赋值
                if (eemployeeBB.HasPermissions(this.EmpId, itemNo, row["functionNo"].ToString()))
                {
                    checkBox.Checked = true;
                }
                e.Item.Controls.Add(checkBox);
            }
        }
        finally
        {
            empPermissionsBB.Dispose();
            treeFunctionBB.Dispose();
            eemployeeBB.Dispose();
            commBB.Dispose();
        }
    }