技术有限,欢迎高手留下意见!
此次任务是对老师原来用Delphi的语言编的,老师设计的数据库,我用C#语言进行的从新编写,基于C/S结构,使用了三层,WebService等技术。尚有不足,请留下意见,我改之。谢谢!
本次大量编码是第一次,从头至尾均由本人完成收获颇多.
- 权限管理
- 这个是单独拿出来,感觉实现起来技术上并不困难关键是逻辑上颇为头疼,时间用的也挺长 3天左右
大致窗体日上图
本人使用了Telerik.RadControls工具集,控件主要RadTreeView
权限管理主要用Tree控件,向左侧的系统角色金对应右侧的模块主要是为了显示,所以并未做过多设置这里代码主要根据数据库绑定
SystemRole_Tree.Nodes.Clear();
DataTable dt = dadaosoft.Public.App.localhost.Get_SystemRole("IsUsing='true'", "");//获取角色信息
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)//循环遍历
{
RadTreeNode Node = new RadTreeNode();
Node.Text = dr["RoleName"].ToString();
Node.Tag = dr["Id"].ToString();
this.SystemRole_Tree.Nodes.Add(Node);//添加节点
}
}
if (SystemRole_Tree.Nodes.Count > 0)
{
SystemRole_Tree.Nodes[0].Selected = true;//默认选中第一行
}
为角色分配模块(权限)
这个区域主要也是利用了Tree控件,只不过带有复选框的Tree 这样方便对于模块的选择。
主要代码
绑定模块
SystemMenu_Tree.Nodes.Clear();
DataTable dt = dadaosoft.Public.App.localhost.Get_SystemMenu("", "");
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
RadTreeNode Node = new RadTreeNode();
Node.Text = dr["MenuName"].ToString();
Node.Tag = dr["Id"].ToString();
Node.Expand();
string strSql = string.Format("SystemMenuId={0}", Node.Tag.ToString());
DataTable dt_temp = dadaosoft.Public.App.localhost.Get_SystemModule(strSql, "");
if (dt.Rows.Count > 0)
{
foreach (DataRow dr_temp in dt_temp.Rows)
{
RadTreeNode Node_temp = new RadTreeNode();
Node_temp.Text = dr_temp["ModuleName"].ToString();
Node_temp.Tag = dr_temp["Id"].ToString();
Node_temp.ShowCheckBox = true;
Node.Nodes.Add(Node_temp);
}
}
this.SystemMenu_Tree.Nodes.Add(Node);
}
}
为模块绑定复选框
string Node = RoleId;
DataTable dt = dadaosoft.Public.App.localhost.Get_SystemRights("SystemRoleId=" + Node, "");
foreach (DataRow dr in dt.Rows)
{
DataTable dt_temp = dadaosoft.Public.App.localhost.Get_SystemModule("Id=" + dr["SystemModuleId"].ToString(), "");
foreach (DataRow dr_temp in dt_temp.Rows)
{
string MenuName = dadaosoft.Public.App.localhost.Get_MenuNameById(int.Parse(dr_temp["SystemMenuId"].ToString()));//根据SystemMenuId可以确定menuname唯一
for (int i = 0; i < SystemMenu_Tree.Nodes[MenuName].Nodes.Count; i++)
{
if (SystemMenu_Tree.Nodes[MenuName].Nodes[i].Tag.ToString().Equals(dr_temp["Id"].ToString()))
{
SystemMenu_Tree.Nodes[MenuName].Nodes[i].Checked = true;
}
}
}
}
单击确定保存
or (int i = 0; i < SystemMenu_Tree.Nodes.Count; i++)
{
foreach (RadTreeNode rtn in SystemMenu_Tree.Nodes[i].Nodes)
{
if (rtn.Level != 0)
{
string strSql = string.Format("SystemRoleId={0} and SystemModuleId={1}", RoleId, rtn.Tag.ToString());
DataTable dt = dadaosoft.Public.App.localhost.Get_SystemRights(strSql, "");
if (dt.Rows.Count > 0)
{
if (rtn.Checked != true)
{
dadaosoft.Public.localhost.SystemRights model = new dadaosoft.Public.localhost.SystemRights();
model.Id = int.Parse(dt.Rows[0]["Id"].ToString());
if (!dadaosoft.Public.App.localhost.Add_SystemRights(model))
{
dadaosoft.Public.Msg.MsgShow("失败");
return;
}
}
continue;
}
if (rtn.Checked != false)
{
dadaosoft.Public.localhost.SystemRights model = new dadaosoft.Public.localhost.SystemRights();
model.SystemModuleId = int.Parse((rtn.Tag.ToString()));
model.SystemRoleId = int.Parse(RoleId);
if (!dadaosoft.Public.App.localhost.Add_SystemRights(model))
{
MessageBox.Show("失败");
return;
}
}
continue;
}
}
}
}
以上就是权限管理对我来说比较有收获的地方 欢迎批评和意见!
转载于:https://www.cnblogs.com/P-lotor/archive/2011/06/06/2073700.html