protected void btnSave_Click(object sender, EventArgs e)
    {
        PRolePermissionsData rolePermissionsData = new PRolePermissionsData();
        SCommBB commBB = new SCommBB();
        PRolePermissionsBB rolePermissionsBB = new PRolePermissionsBB();
        try
        {
            //删除当前角色所有权限
            rolePermissionsBB.DeleteRecordByRole(this.RoleId, 2);

            //保存权限
            string strPermissions = "";
            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)
                        {
                            strPermissions += itemNo + "," + ((CheckBox)control).ToolTip + ",0|";
                        }
                    }
                }
            }
            //保存权限
            commBB.ExecuteSql("exec sys_BatchSavePermissions " + this.RoleId.ToString() + ",'" + strPermissions.Remove(strPermissions.Length - 1) + "'");
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
            return;
        }
        finally
        {
            commBB.Dispose();
            rolePermissionsBB.Dispose();
        }

        this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('保存成功!');", true);
    }
Esempio n. 2
0
 /// <summary>
 /// ɾ��
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnDel_Click(object sender, EventArgs e)
 {
     PRoleBB roleBB = new PRoleBB();
     PUserRoleBB userRoleBB = new PUserRoleBB();
     PRolePermissionsBB rolePermissionsBB = new PRolePermissionsBB();
     //��ȡѡ�е�����Id
     try
     {
         foreach (GridViewRow gvrow in this.grid.Rows)
         {
             CheckBox chkId = (CheckBox)gvrow.FindControl("chkId");
             int id = Convert.ToInt32(this.grid.DataKeys[gvrow.RowIndex]["id"]);
             if (chkId.Checked == true)
             {
                 PRoleData roleData = new PRoleData();
                 roleData = roleBB.GetModel(id);
                 if (roleData.isSys)
                 {
                     this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"����λΪϵͳ��λ�����޷�ɾ����\");", true);
                     return;
                 }
                 else
                 {
                     //ɾ����ɫ��ͬʱ��ɾ����Ա��ɫ����ɫȨ��
                     roleBB.DeleteRecord(id);
                     userRoleBB.DeleteRecordByRole(id);
                     rolePermissionsBB.DeleteRecordByRole(id, 2);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
         return;
     }
     finally
     {
         roleBB.Dispose();
         userRoleBB.Dispose();
         rolePermissionsBB.Dispose();
     }
     this.BindGrid();
 }