/// <summary>
/// 绑定权限列表的数据
/// </summary>
/// <param name="roleID">-1则,不获取权限列表的数据</param>
private void DataBindCB(int roleID)
{
DataTable dtbPermission = PermissionDAL.GetList();
DataTable dtbPermissionList = PermissionListDAL.GetList(roleID);
if (dealTypeCur == DealType.Edit) permissionListOld = new List<int>();
foreach (DataRow dr in dtbPermissionList.Rows)
{
if (dealTypeCur == DealType.Edit) permissionListOld.Add(Convert.ToInt32(dr["PermissionID"]));
DataRow[] drCur = dtbPermission.Select("PermissionID=" + dr["PermissionID"].ToString());
if (drCur.Length > 0)
{
dtbPermission.Rows.Remove(drCur[0]);
}
}
cbPermissionUnHas.ValueMember = "PermissionID";
cbPermissionUnHas.DisplayMember = "Description";
cbPermissionUnHas.DataSource = dtbPermission;
cbPermissionHas.ValueMember = "PermissionID";
cbPermissionHas.DisplayMember = "Description";
cbPermissionHas.DataSource = dtbPermissionList;
}
private void btnAddPermission_Click(object sender, EventArgs e)
{
//直接操作数据源,防止出现,设置 DataSource 属性后 无法修改项集合
if (cbPermissionUnHas.SelectedItem == null) return;
DataTable dtbcbPermissionHasSource = (DataTable)cbPermissionHas.DataSource;
DataTable dtbcbPermissionUnHasSource = (DataTable)cbPermissionUnHas.DataSource;
DataRow[] dr = dtbcbPermissionUnHasSource.Select("PermissionID=" + cbPermissionUnHas.SelectedValue.ToString());
if (dr.Length > 0)
{
if (dtbcbPermissionHasSource.Rows.Count == 0)//防止因为没有数据源,而出现无法新建合适的行
{
dtbcbPermissionHasSource.Columns.Add("PermissionID", typeof(int));
dtbcbPermissionHasSource.Columns.Add("Description", typeof(string));
cbPermissionHas.ValueMember = "PermissionID";//重新绑定数据,避免显示出问题
cbPermissionHas.DisplayMember = "Description";
}
DataRow drNew = dtbcbPermissionHasSource.NewRow();
drNew["PermissionID"] = dr[0]["PermissionID"];
drNew["Description"] = dr[0]["Description"];
dtbcbPermissionUnHasSource.Rows.Remove(dr[0]);
dtbcbPermissionHasSource.Rows.Add(drNew);
}
}
private void btnRemovePermission_Click(object sender, EventArgs e)
{
if (cbPermissionHas.SelectedItem == null) return;
DataTable dtbcbPermissionHasSource = (DataTable)cbPermissionHas.DataSource;
DataTable dtbcbPermissionUnHasSource = (DataTable)cbPermissionUnHas.DataSource;
DataRow[] dr = dtbcbPermissionHasSource.Select("PermissionID=" + cbPermissionHas.SelectedValue.ToString());
if (dr.Length > 0)
{
if (dtbcbPermissionUnHasSource.Rows.Count == 0)
{
dtbcbPermissionHasSource.Columns.Add("PermissionID", typeof(int));
dtbcbPermissionUnHasSource.Columns.Add("Description", typeof(string));
cbPermissionUnHas.ValueMember = "PermissionID";
cbPermissionHas.DisplayMember = "Description";
}
DataRow drNew = dtbcbPermissionUnHasSource.NewRow();
drNew["PermissionID"] = dr[0]["PermissionID"];
drNew["Description"] = dr[0]["Description"];
dtbcbPermissionHasSource.Rows.Remove(dr[0]);
dtbcbPermissionUnHasSource.Rows.Add(drNew);
}
}