205 lines
6.9 KiB
C#
205 lines
6.9 KiB
C#
using BLL;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web.UI.WebControls;
|
|
|
|
namespace FineUIPro.Web.BaseInfo
|
|
{
|
|
public partial class DataBase : PageBase
|
|
{
|
|
#region 加载
|
|
/// <summary>
|
|
/// 加载页面
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
GetButtonPower();
|
|
InitTreeMenu();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 加载树
|
|
/// <summary>
|
|
/// 加载树
|
|
/// </summary>
|
|
private void InitTreeMenu()
|
|
{
|
|
this.tvControlItem.Nodes.Clear();
|
|
|
|
TreeNode rootNode = new TreeNode();
|
|
rootNode.Text = "资料库";
|
|
rootNode.NodeID = "0";
|
|
rootNode.EnableExpandEvent = true;
|
|
rootNode.Expanded = true;
|
|
this.tvControlItem.Nodes.Add(rootNode);
|
|
this.GetNodes(rootNode.Nodes, rootNode, null);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 遍历节点
|
|
/// </summary>
|
|
/// <param name="nodes"></param>
|
|
/// <param name="rootNode"></param>
|
|
/// <param name="parentId"></param>
|
|
private void GetNodes(TreeNodeCollection nodes, TreeNode rootNode, string parentId)
|
|
{
|
|
if (parentId == null)
|
|
{
|
|
var dataTypes = (from x in Funs.DB.DataBase_DataType where x.SuperDataTypeId == "0" && x.DataTypeId != Const.DataTypeConstructId orderby x.SortIndex select x).ToList();
|
|
foreach (var item in dataTypes)
|
|
{
|
|
TreeNode rootNode1 = new TreeNode();
|
|
rootNode1.Text = item.DataTypeName;
|
|
rootNode1.NodeID = item.DataTypeId;
|
|
rootNode1.ToolTip = item.DataTypeName;
|
|
rootNode1.EnableClickEvent = true;
|
|
nodes.Add(rootNode1);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var dataTypes = (from x in Funs.DB.DataBase_DataType where x.SuperDataTypeId == parentId orderby x.SortIndex select x).ToList();
|
|
foreach (var item in dataTypes)
|
|
{
|
|
TreeNode rootNode1 = new TreeNode();
|
|
rootNode1.Text = item.DataTypeName;
|
|
rootNode1.NodeID = item.DataTypeId;
|
|
rootNode1.ToolTip = item.DataTypeName;
|
|
rootNode1.EnableClickEvent = true;
|
|
nodes.Add(rootNode1);
|
|
}
|
|
}
|
|
for (int i = 0; i < nodes.Count; i++)
|
|
{
|
|
GetNodes(nodes[i].Nodes, nodes[i], nodes[i].NodeID);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 维护
|
|
/// <summary>
|
|
/// 增加
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnMenuAdd_Click(object sender, EventArgs e)
|
|
{
|
|
string id = this.tvControlItem.SelectedNodeID;
|
|
if (!string.IsNullOrEmpty(id))
|
|
{
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("DataBaseEdit.aspx?dataTypeId={0}&&type={1}", id, "add", "编辑 - ")));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnMenuModify_Click(object sender, EventArgs e)
|
|
{
|
|
string id = this.tvControlItem.SelectedNodeID;
|
|
if (!string.IsNullOrEmpty(id) && id != "0")
|
|
{
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("DataBaseEdit.aspx?dataTypeId={0}&&type={1}", id, "edit", "编辑 - ")));
|
|
}
|
|
else
|
|
{
|
|
Alert.ShowInTop("请选择资料类别", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnMenuDel_Click(object sender, EventArgs e)
|
|
{
|
|
string id = this.tvControlItem.SelectedNodeID;
|
|
if (!string.IsNullOrEmpty(id) && id != "0")
|
|
{
|
|
Model.DataBase_DataType division = BLL.DataTypeService.GetDataTypeById(id);
|
|
if (division != null)
|
|
{
|
|
List<Model.DataBase_DataType> dataTypes = BLL.DataTypeService.GetDataTypesBySuperDataTypeId(id);
|
|
if (dataTypes.Count > 0) //含有子类别
|
|
{
|
|
DeleteDetail(dataTypes);
|
|
}
|
|
BLL.DataTypeService.DeleteDataTypeById(id);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Alert.ShowInTop("请选择资料类别", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
InitTreeMenu();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 循环删除子级类别
|
|
/// </summary>
|
|
/// <param name="dataTypes"></param>
|
|
private void DeleteDetail(List<Model.DataBase_DataType> dataTypes)
|
|
{
|
|
foreach (var d in dataTypes)
|
|
{
|
|
List<Model.DataBase_DataType> childDataTypes = BLL.DataTypeService.GetDataTypesBySuperDataTypeId(d.DataTypeId);
|
|
if (childDataTypes.Count > 0)
|
|
{
|
|
DeleteDetail(childDataTypes);
|
|
}
|
|
BLL.DataTypeService.DeleteDataTypeById(d.DataTypeId);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 关闭弹出窗口
|
|
/// <summary>
|
|
/// 关闭弹出窗口
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Window1_Close(object sender, WindowCloseEventArgs e)
|
|
{
|
|
InitTreeMenu();
|
|
}
|
|
#endregion
|
|
|
|
#region 获取按钮权限
|
|
/// <summary>
|
|
/// 获取按钮权限
|
|
/// </summary>
|
|
/// <param name="button"></param>
|
|
/// <returns></returns>
|
|
private void GetButtonPower()
|
|
{
|
|
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.CQMSDataBaseMenuId);
|
|
if (buttonList.Count() > 0)
|
|
{
|
|
if (buttonList.Contains(BLL.Const.BtnAdd))
|
|
{
|
|
this.btnMenuAdd.Hidden = false;
|
|
}
|
|
if (buttonList.Contains(BLL.Const.BtnModify))
|
|
{
|
|
this.btnMenuModify.Hidden = false;
|
|
}
|
|
if (buttonList.Contains(BLL.Const.BtnDelete))
|
|
{
|
|
this.btnMenuDel.Hidden = false;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
} |