我是这样想的:
1、权限的定义:即各个模块及其相应的各个操作进行统一编码。
2、角色的定义:拥有多种权限,对每一个权限都可以设置“允许”或“禁用”。这样,当需要将多个角色的复合权限时,比如果说想要A角色中的B权限和C角色中的D权限,则只需将角色A和B指派给用户,并且将角色A中的B和角色C中的D设置为“允许”,而其它权限设置为“禁用”即可实现此需求。
3、用户与角色:用户同时拥有一个或多个角色。如果角色中有重叠的权限且或有“禁用”,则该权限“禁用”。
这是我的想法,请大家说说你们的想法?
1、权限的定义:即各个模块及其相应的各个操作进行统一编码。
2、角色的定义:拥有多种权限,对每一个权限都可以设置“允许”或“禁用”。这样,当需要将多个角色的复合权限时,比如果说想要A角色中的B权限和C角色中的D权限,则只需将角色A和B指派给用户,并且将角色A中的B和角色C中的D设置为“允许”,而其它权限设置为“禁用”即可实现此需求。
3、用户与角色:用户同时拥有一个或多个角色。如果角色中有重叠的权限且或有“禁用”,则该权限“禁用”。
这是我的想法,请大家说说你们的想法?
解决方案 »
- 如何调用windows服务中的函数????
- 大家好,请教大家一个关于protocal handler的问题。
- 如何在c#中动态创建oracle实例(oracle数据库),并进行创建用户,赋权等操作..以此实现多帐套...请各位大小帮忙啊..
- 关于RowFilter 的一个奇怪问题.
- 请教高手,c#里面如何调用其他项目的报表文件
- 松耦合的程序,sql语句写在哪里?
- 帮我看看!为什么只显示一个标签!
- dataGridView查询后的显示问题?
- 崩溃!visual studio2013安装问题!
- 如何在打包的时候将框架也打进去:)谢谢!!急急“”“
- 怎么在C++与C#间传递数组
- WinForm,向数据库中存储自定义字符
在用户的登陆的时候可以根据用户名查询权限.
给出部分的代码吧:
//---------窗体创建时,将用户的权限数据读入并显示-----------
private void PopedomManage_Load(object sender, System.EventArgs e)
{
this.ds = this.link.SelectDataBase(sendStrSQL,sendTableName);
this.dgrd_Popedom.DataSource = ds.Tables[0];
this.DataGridStateControl(); this.dgrd_Popedom.Select(0);//窗体生成后选中第一行
string selectedUserID = this.ds.Tables[0].Rows[0][0].ToString();//默认选中用户清单中的第一个用户
string tempStrSQL = "select 权限名称 from 权限清单 " + " where 用户编号 = '" + selectedUserID + "'";
popedomDataTable = link.SelectDataBase(tempStrSQL);//读入该用户的权限
for (int i=0;i<popedomDataTable.Rows.Count;i++)//根据权限设置ListBox
{
for (int j=0;j<this.chkLst_Priority.Items.Count;j++)
{
if (this.chkLst_Priority.Items[j].ToString().Trim() == popedomDataTable.Rows[i][0].ToString().Trim())
{
this.chkLst_Priority.SetItemChecked(j,true);
}
}
}
} //-------------设置显示用户信息的表---------------
private void DataGridStateControl()
{
DataGridTableStyle ts = new DataGridTableStyle();
DataGridNoActiveCellColumn aColumnTextColumn;//设置dataGrid格式
ts.AlternatingBackColor = Color.LightGray;
ts.MappingName = this.ds.Tables[0].TableName;
ts.AllowSorting = false;
int numCols = this.ds.Tables[0].Columns.Count;
for (int i = 0;i< numCols;i++)
{
aColumnTextColumn = new DataGridNoActiveCellColumn();
aColumnTextColumn.MappingName = this.ds.Tables[0].Columns[i].ColumnName;
aColumnTextColumn.HeaderText = this.ds.Tables[0].Columns[i].ColumnName;
aColumnTextColumn.NullText = "";
aColumnTextColumn.Format = "F";
ts.GridColumnStyles.Add(aColumnTextColumn);
}
this.dgrd_Popedom.TableStyles.Add(ts);
}
//-------------改变用户的权限,并向数据库中提交----------------
private void chkLst_Priority_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
{
//CheckedListBox控件中的Item的CheckedState属性是由点击CheckedListBox控件而改变时才响应该事件
if (blInitial == false)
{
if (e.CurrentValue.ToString() == "Unchecked")
{
try
{
string strUserName = this.dgrd_Popedom[this.dgrd_Popedom.CurrentCell.RowNumber,0].ToString().Trim();
string strPopedom = this.chkLst_Priority.SelectedItem.ToString();
string tempSendStrSQL = "insert 权限清单 (用户编号,权限名称) values ('" + strUserName +"','"+ strPopedom +"')";
this.link.UpdateDataBase(tempSendStrSQL);
}
catch
{
MessageBox.Show("数据库中的权限修改出错,请重试!","信息");
}
}
else if (e.CurrentValue.ToString() == "Checked")
{
try
{
string strUserName = this.dgrd_Popedom[this.dgrd_Popedom.CurrentCell.RowNumber,0].ToString().Trim();
string strPopedom = this.chkLst_Priority.SelectedItem.ToString();
string tempSendStrSQL = "delete from 权限清单 where (用户编号 = '" + strUserName +"'" +
" and 权限名称 = '" + strPopedom + "')";
this.link.UpdateDataBase(tempSendStrSQL);
}
catch
{
MessageBox.Show("数据库中的权限修改出错!","信息");
}
}
}
} private void dgrd_Popedom_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (this.dgrd_Popedom.CurrentCell.RowNumber >= this.ds.Tables[0].Rows.Count)//防止出现所选的用户不在数据表中的情况
{
return;
}
this.chkLst_Priority.Enabled = true;
blInitial = true; //控制当【权限管理】窗体刚生成时和点击其他用户时使CheckedListBox控件中数据发生改变时不响应ItemCheck事件
//以下代码实现的是当dataGrid中所选用户改变时,根据选中用户权限重新设置listBox的功能
for (int i=0;i<this.chkLst_Priority.Items.Count;i++)//将listBox中所有权限设为未选中
{
this.chkLst_Priority.SetItemChecked(i,false);
}
int intRowNumber = this.dgrd_Popedom.CurrentCell.RowNumber;
string selectedUserID = this.ds.Tables[0].Rows[intRowNumber][0].ToString();
string tempStrSQL = "select 权限名称 from 权限清单 " + " where 用户编号 = '" + selectedUserID + "'";
popedomDataTable = link.SelectDataBase(tempStrSQL);//查询所选用户权限
for (int i=0;i<popedomDataTable.Rows.Count;i++)//重新设置listBox
{
for (int j=0;j<this.chkLst_Priority.Items.Count;j++)
{
if (this.chkLst_Priority.Items[j].ToString().Trim() == popedomDataTable.Rows[i][0].ToString().Trim())
{
this.chkLst_Priority.SetItemChecked(j,true);
}
}
}
blInitial = false;
}
大的系统维护起来非常郁闷。
系统不大的话应该可以根据模块来分配角色。
模块多的话就比较的麻烦唉!
同意!我现在是按模块来分配权限的!
呵呵!
比如一个int型能表示32种权限(2的32次幂)。然后进行权限判断就行了。