📄 explorerform.cs
字号:
//----------------------------------------------------------------
// <copyright file="ExplorerForm.cs" >
// Copyright (c) Wenzy , All rights reserved.
// author:温正宇 E-Mail:wenzy@tom.com MyBlog:wenzy.cnblogs.com
// All rights reserved.
// </copyright>
//----------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MemberShipDAL.DataObject;
using WMFConfig.Bussiness;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Document;
using MemberShipDAL.DataObject.DataResourcesTableAdapters;
namespace WMFConfig
{
/// <summary>
/// 权限配置工具
/// </summary>
public partial class ExplorerForm : Form
{
#region 变量定义
/// <summary>
/// 标记数据是否已经加载完毕
/// </summary>
public static bool privilegeInited = false;
/// <summary>
/// 开始被拖拽的节点
/// </summary>
private TreeNode dragNode = null;
/// <summary>
/// 临时的用于选择的节点
/// </summary>
private TreeNode tempDropNode = null;
/// <summary>
/// 计时器,用户滚动
/// </summary>
private Timer timer = new Timer();
/// <summary>
/// 计时器,节点展开
/// </summary>
private Timer timerExpand = new Timer();
#endregion
#region 系统事件
public ExplorerForm()
{
InitializeComponent();
timer.Interval = 200;
timer.Tick += new EventHandler(timer_Tick);
timerExpand.Interval = 1000;
timerExpand.Tick += new EventHandler(timerExpand_Tick);
}
private void ExplorerForm_Load(object sender, EventArgs e)
{
InitForm();
//以c#的方式高亮,初始化文本框
txtIcs_Content.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy("C#");
txtIcs_Content.Encoding = System.Text.Encoding.Default;
}
private void 退出xToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Dispose();
Application.Exit();
}
private void 关于AToolStripMenuItem_Click(object sender, EventArgs e)
{
using (AboutForm a = new AboutForm())
{
a.ShowDialog();
}
}
/// <summary>
/// 操作日志
/// </summary>
/// <param name="logText"></param>
/// <param name="showTime"></param>
private void SysLog(string logText, bool showTime)
{
if (logText.Trim() == string.Empty)
return;
if (showTime)
logText = "[" + DateTime.Now.ToString() + "]:" + logText;
toolStripStatusInfo.Text = logText;
logText = logText + "\n\n";
txt_OptLog.Text = logText + txt_OptLog.Text;
}
#endregion
#region TabControl事件
/// <summary>
/// 如果数据还没有保存,那就提示用户要保存数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tabControl1_Deselecting(object sender, TabControlCancelEventArgs e)
{
if (this.dataResources.HasChanges())
{
if (MessageBox.Show("您还没有保存数据,确定要离开[" + e.TabPage.Text + "]操作?", "保存数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
{
this.dataResources.RejectChanges();
}
else
{
e.Cancel = true;
}
}
}
//给这些数据进行重新绑定
private void tabControl1_Selected(object sender, TabControlEventArgs e)
{
try
{
switch (e.TabPage.Name)
{
case "tabPagePrivilege":
//绑定权限表
Privilegebind();
lbl_TableName.Text = "与[" + trv_Resources.SelectedNode.Text + "]权限组(ResourceGroup)相关的权限记录,共 " + wmfPrivilegeBindingSource.Count.ToString() + " 条";
break;
case "tabPageResManage":
this.dataResources.wmf_Resources.Clear();
this.wmf_ResourcesTableAdapter.Fill(this.dataResources.wmf_Resources);
lbl_TableName.Text = "与资源(Resource)相关的权限记录,共 " + wmfPrivilegeBindingSource.Count.ToString() + " 条";
break;
case "tabPageResGroup":
this.dataResources.wmf_ResourcesGroup.Clear();
this.wmf_ResourcesGroupTableAdapter.Fill(this.dataResources.wmf_ResourcesGroup);
lbl_TableName.Text = "与[" + trv_Resources.SelectedNode.Text + "]权限组(ResourceGroup)相关的权限记录,共 " + wmfPrivilegeBindingSource.Count.ToString() + " 条";
break;
case "tabOperation":
this.dataResources.wmf_Operation.Clear();
this.wmf_OperationTableAdapter.Fill(this.dataResources.wmf_Operation);
lbl_TableName.Text = "与操作(Operation)相关的权限记录,共 " + wmfPrivilegeBindingSource.Count.ToString() + " 条";
break;
default:
break;
}
DataSelectByTree();
this.dataResources.wmf_Privilege.Clear();
this.wmf_PrivilegeTableAdapter.Fill(this.dataResources.wmf_Privilege);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
throw;
}
}
#endregion
#region 系统初始化,数据绑定
/// <summary>
/// 数据初始化
/// </summary>
private void InitForm()
{
this.dataResources.wmf_Resources.Clear();
this.dataResources.wmf_ResourcesGroup.Clear();
this.dataResources.wmf_Operation.Clear();
this.dataResources.wmf_Privilege.Clear();
// TODO: 这行代码将数据加载到表“dataResources.wmf_Privilege”中。
this.wmf_PrivilegeTableAdapter.Fill(this.dataResources.wmf_Privilege);
// TODO: 这行代码将数据加载到表“dataResources.wmf_Operation”中。
this.wmf_OperationTableAdapter.Fill(this.dataResources.wmf_Operation);
// TODO: 这行代码将数据加载到表“dataResources.wmf_ResourcesGroup”中。
this.wmf_ResourcesGroupTableAdapter.Fill(this.dataResources.wmf_ResourcesGroup);
// TODO: 这行代码将数据加载到表“dataResources.wmf_Resources”中。
this.wmf_ResourcesTableAdapter.Fill(this.dataResources.wmf_Resources);
//判断是否有数据,如果没有,提示并退出
if (this.dataResources.wmf_ResourcesGroup.Rows.Count == 0)
{
this.Hide();
MessageBox.Show("资源组的根节点未建立,请先运行在Web项目下的App_Data下的BaseData.sql,建立起基本的数据,再打开本系统", "RMF:基本数据尚未建立", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Dispose();
//退出程序
Application.Exit();
}
//绑定资源树
trv_Resources.Nodes.Clear();
new ResourcesBLL().ResourcesTreeBind("", null, dataResources.wmf_ResourcesGroup, trv_Resources);
trv_Resources.ExpandAll();
//绑定权限表
Privilegebind();
}
/// <summary>
/// 选择树以后,重新绑定列表
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void trv_Resources_AfterSelect(object sender, TreeViewEventArgs e)
{
DataSelectByTree();
Privilegebind();
}
//绑定权限表
private void Privilegebind()
{
privilegeInited = false;
/*this.dataResources.wmf_Resources.Clear();
this.dataResources.wmf_ResourcesGroup.Clear();
this.dataResources.wmf_Operation.Clear();
this.dataResources.wmf_Privilege.Clear();
// TODO: 这行代码将数据加载到表“dataResources.wmf_Privilege”中。
this.wmf_PrivilegeTableAdapter.Fill(this.dataResources.wmf_Privilege);
// TODO: 这行代码将数据加载到表“dataResources.wmf_Operation”中。
this.wmf_OperationTableAdapter.Fill(this.dataResources.wmf_Operation);
// TODO: 这行代码将数据加载到表“dataResources.wmf_ResourcesGroup”中。
this.wmf_ResourcesGroupTableAdapter.Fill(this.dataResources.wmf_ResourcesGroup);
// TODO: 这行代码将数据加载到表“dataResources.wmf_Resources”中。
this.wmf_ResourcesTableAdapter.Fill(this.dataResources.wmf_Resources);*/
new PrivilegeBLL().PrivilegeBind(trv_Resources.SelectedNode.Name, this.dataResources.wmf_Operation, this.dataResources.wmf_Resources, this.dataResources.wmf_Privilege, dg_Privilege);
privilegeInited = true;
}
/// <summary>
/// 根据树选择数据内容
/// </summary>
private void DataSelectByTree()
{
try
{
this.dataResources.wmf_Privilege.Clear();
// TODO: 这行代码将数据加载到表“dataResources.wmf_Privilege”中。
this.wmf_PrivilegeTableAdapter.Fill(this.dataResources.wmf_Privilege);
switch (tabControl1.SelectedTab.Name)
{
case "tabPageResGroup":
wmfResourcesBindingSource.Filter = string.Empty;
wmfResourcesGroupBindingSource.Filter = "[ParentId]='" + trv_Resources.SelectedNode.Name + "'";
break;
case "tabPagePrivilege":
break;
case "tabPageResManage":
wmfResourcesGroupBindingSource.Filter = string.Empty;
wmfResourcesBindingSource.Filter = "[ResourceGroupId]='" + trv_Resources.SelectedNode.Name + "'";
break;
case "tabOperation":
break;
default:
break;
}
//过滤Privilege,包括tabPageResGroup(权限组管理)都要过滤
if (toolStripDisplayPrivilege.Checked && ((tabControl1.SelectedTab.Name == "tabPageResGroup") || (tabControl1.SelectedTab.Name == "tabPagePrivilege")))
{
StringBuilder privilegeFilter = new StringBuilder("Resourcesid = '");
foreach (DataResources.wmf_ResourcesRow resRow in this.dataResources.wmf_Resources.Select("ResourceGroupId='" + trv_Resources.SelectedNode.Name + "'"))
{
privilegeFilter.Append(resRow.ResourcesId + "' or Resourcesid = '");
}
int lastOr = privilegeFilter.ToString().LastIndexOf("or");
if (lastOr > 0)
{
privilegeFilter.Remove(lastOr, privilegeFilter.Length - lastOr);
}
else
{
privilegeFilter.Remove(0, privilegeFilter.Length);
}
this.wmfPrivilegeBindingSource.Filter = privilegeFilter.ToString();
lbl_TableName.Text = "与[" + trv_Resources.SelectedNode.Text + "]权限组(ResourceGroup)相关的权限记录,共 " + wmfPrivilegeBindingSource.Count.ToString() + " 条";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -