/// <summary>
/// 初始化左侧树形结构
/// </summary>
private void InitNavBarControl()
{
navBarTree.Groups.Clear();
NavBarGroupControlContainer container = null;
TreeList tv = null;
KeyValuePair<string, string>[] namesAndCaptions = new KeyValuePair<string, string>[4] { new KeyValuePair<string, string>("navBar1", NAVBAR_CAE_PROCESS), new KeyValuePair<string, string>("navBar2", NAVBAR_TEMPLATE), new KeyValuePair<string, string>("navBar3", NAVBAR_WF), new KeyValuePair<string, string>("navBar4", NAVBAR_TOOL) };
for (int i = 0; i < 4; i++)
{
container = new NavBarGroupControlContainer();
navBarTree.Controls.Add(container);
//添加Group
NavBarGroup group = new NavBarGroup();
group.Name = namesAndCaptions[i].Key;
group.Caption = namesAndCaptions[i].Value;
group.ControlContainer = container;
group.Expanded = true;
group.GroupClientHeight = 410;
group.GroupStyle = NavBarGroupStyle.ControlContainer;
navBarTree.Groups.Add(group);
}
//添加Item
for (int i = 0; i < navBarTree.Groups.Count; i++)
{
//样式
tv = new TreeList() { Name = "TreeList" + i , Caption = namesAndCaptions[i].Value };
tv.Dock = DockStyle.Fill;
tv.RowHeight = 25;
tv.OptionsBehavior.Editable = false;
tv.OptionsSelection.MultiSelect = false;
tv.OptionsDragAndDrop.DragNodesMode = DragNodesMode.Single; //拖拽开关
navBarTree.Controls[i].Controls.Add(tv); //必须在这个位置添加控件
//注册事件
tv.DragOver += tv_DragOver;
tv.AfterFocusNode += tv_AfterFocusNode;
var lstCAEDic = BLLSysSetting.BllSysDictionary.GetDicListByGroupCode(DictionaryEnum.CAEType);
if (navBarTree.Groups[i].Name == namesAndCaptions[i].Key)
{
if (namesAndCaptions[i].Value == NAVBAR_CAE_PROCESS)
{
if (!lstCAEDic.HasValue())
{
System.Diagnostics.Debug.WriteLine("frmSimWorkflow GetDicListByGroupCode error");
return;
}
tv.DataSource = lstCAEDic;
tv.KeyFieldName = "id";
tv.PopulateColumns();
foreach (TreeListColumn col in tv.Columns)
{
if (col.FieldName == nameof(SysDictionary.itemLabel))
{
col.Caption = "CAE过程名称";
col.Width = 150;
}
else
{
col.Visible = false;
}
}
}
else if (namesAndCaptions[i].Value == NAVBAR_TEMPLATE)
{
if (!lstCAEDic.HasValue())
{
System.Diagnostics.Debug.WriteLine("frmSimWorkflow GetDicListByGroupCode error");
return;
}
TreeListColumn colCode = new TreeListColumn() { Caption = "Code"};
TreeListColumn colName = new TreeListColumn() { Caption = "名称"};
tv.Columns.Add(colCode);
tv.Columns.Add(colName);
tv.Columns[0].Visible = false; //必须先添加列后设置Visible
tv.Columns[1].Visible = true;
tv.Refresh();
foreach (var item in lstCAEDic)
{
tv.BeginUnboundLoad();
TreeListNode node = tv.AppendNode(item, -1);
node.Tag = item;
node.SetValue(0, item.itemCode);
node.SetValue(1, item.itemLabel);
tv.EndUnboundLoad();
}
}
else if (namesAndCaptions[i].Value == NAVBAR_WF)
{
var lstDic = BLLSimFlow.BllSimWorkflow.GetListByWhere(new SimWorkflow() { flagStatus = 0 });
tv.DataSource = lstDic;
tv.KeyFieldName = "id";
tv.PopulateColumns();
foreach (TreeListColumn col in tv.Columns)
{
if (col.FieldName == nameof(SimWorkflow.flowName))
{
col.Caption = "流程名称";
col.Width = 150;
}
else
{
col.Visible = false;
}
}
}
else if (namesAndCaptions[i].Value == NAVBAR_TOOL)
{
var lstDic = BLLSimTools.BllSimTool.GetListByWhere(new SimTool { flagStatus = 0 });
tv.DataSource = lstDic;
tv.KeyFieldName = "id";
tv.PopulateColumns();
foreach (TreeListColumn col in tv.Columns)
{
if (col.FieldName == nameof(SimTool.simToolName))
{
col.Caption = "工具名称";
col.Width = 150;
}
else
{
col.Visible = false;
}
}
}
//取消默认焦点
tv.FocusedNode = null;
tv.SetFocusedNode(null);
}
}
}