设置用户角色,根据角色是、获取角色获取用户类型
登录可直接使用SqlDataReader取值
登录可直接使用SqlDataReader取值
解决方案 »
- 关于用C#更改桌面背景失败
- oracle存储过程的中有一个IN的参数问题
- 大家看看这句话的意思
- 关于VS2005中使用水晶报表的问题,谢谢大家帮忙!爆急!!
- 如何保存不同字符串产生的哈稀码是唯一的
- .net winform(C#)连接远程的oracle的语句怎么写?
- Button.Click -= EventHandler( OnClick) 去除按键OnClick事件的方法怎么写?
- 无法将类型为“Common.Pack”的对象强制转换为类型“Common.Pack”。”(System.InvalidCastException)
- 有如下提示是什么原因:当我打开一个解决方案时提示:web服务器运行的不是asp.net1.1版本.
- 菜鸟提问在C#怎么判断字符串能否转换为数值型?用思念方法可以解决这个问题?
- 两个Form怎么用Struct传资料
- C#怎么制作工具窗口
//---------窗体创建时,将用户的权限数据读入并显示-----------
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;
}
每次登录时,根据用户ID、密码、用户类别一起核对