201 lines
8.3 KiB
C#
201 lines
8.3 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using AntdUI;
|
||
using DH.Commons.Base;
|
||
using DH.Commons.Models;
|
||
using DHSoftware.Views;
|
||
|
||
namespace DHSoftware
|
||
{
|
||
public partial class RBACWindow : Window
|
||
{
|
||
public RBACWindow()
|
||
{
|
||
InitializeComponent();
|
||
menu1.SelectChanged += Menu1_SelectChanged;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 窗体对象实例
|
||
/// </summary>
|
||
private static RBACWindow _instance;
|
||
|
||
internal static RBACWindow Instance
|
||
{
|
||
get
|
||
{
|
||
if (_instance == null || _instance.IsDisposed)
|
||
_instance = new RBACWindow();
|
||
return _instance;
|
||
}
|
||
}
|
||
private void Menu1_SelectChanged(object sender, MenuSelectEventArgs e)
|
||
{
|
||
MenuItem clickedItem = e.Value;
|
||
|
||
if (clickedItem != null)
|
||
{
|
||
if (clickedItem.PARENTITEM == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
switch (clickedItem.PARENTITEM.Text)
|
||
{
|
||
case "用户管理":
|
||
foreach (var tab in tabs1.Pages)
|
||
{
|
||
if (tab is AntdUI.TabPage existingTab && existingTab.Text == $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}")
|
||
{
|
||
tabs1.SelectedTab = existingTab;
|
||
return;
|
||
}
|
||
}
|
||
|
||
CameraBase? CameraBase = ConfigModel.CameraBaseList.Where(c => c.CameraName == clickedItem.Text).FirstOrDefault();
|
||
if (CameraBase == null)
|
||
{
|
||
CameraBase = new CameraBase();
|
||
}
|
||
UserControl control = null;
|
||
control = new CameraControl(this, CameraBase);
|
||
if (control != null)
|
||
{
|
||
//容器添加控件,需要调整dpi
|
||
control.Dock = DockStyle.Fill;
|
||
AutoDpi(control);
|
||
AntdUI.TabPage tabPage = new AntdUI.TabPage()
|
||
{
|
||
Text = $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}",
|
||
ReadOnly = false,
|
||
};
|
||
tabPage.Controls.Add(control);
|
||
tabs1.Pages.Add(tabPage);
|
||
|
||
tabs1.SelectedTab = tabPage;
|
||
|
||
}
|
||
break;
|
||
|
||
case "角色管理":
|
||
// 检查是否已存在同名 TabPage
|
||
foreach (var tab in tabs1.Pages)
|
||
{
|
||
if (tab is AntdUI.TabPage existingTab && existingTab.Text == $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}")
|
||
{
|
||
|
||
tabs1.SelectedTab = existingTab;
|
||
return;
|
||
}
|
||
}
|
||
DetectionConfig? detectionConfig = ConfigModel.DetectionList.Where(c => c.Name == clickedItem.Text).FirstOrDefault();
|
||
if (detectionConfig == null)
|
||
{
|
||
detectionConfig = new DetectionConfig();
|
||
}
|
||
UserControl control1 = null;
|
||
control1 = new DetectControl(this, detectionConfig);
|
||
if (control1 != null)
|
||
{
|
||
//容器添加控件,需要调整dpi
|
||
control1.Dock = DockStyle.Fill;
|
||
AutoDpi(control1);
|
||
AntdUI.TabPage tabPage = new AntdUI.TabPage()
|
||
{
|
||
Text = $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}",
|
||
ReadOnly = false,
|
||
};
|
||
tabPage.Controls.Add(control1);
|
||
tabs1.Pages.Add(tabPage);
|
||
tabs1.SelectedTab = tabPage;
|
||
|
||
}
|
||
break;
|
||
|
||
case "权限管理":
|
||
foreach (var tab in tabs1.Pages)
|
||
{
|
||
if (tab is AntdUI.TabPage existingTab && existingTab.Text == $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}")
|
||
{
|
||
tabs1.SelectedTab = existingTab; // 直接跳转到已存在的 TabPage
|
||
|
||
return;
|
||
}
|
||
}
|
||
//先获取是否存在该名称的配置
|
||
//如果没有新建项
|
||
PLCBase? pLCBase = ConfigModel.PLCBaseList.Where(c => c.PLCName == clickedItem.Text).FirstOrDefault();
|
||
if (pLCBase == null)
|
||
{
|
||
pLCBase = new PLCBase();
|
||
}
|
||
UserControl control2 = null;
|
||
control = new MotionControl(this, pLCBase);
|
||
if (control != null)
|
||
{
|
||
//容器添加控件,需要调整dpi
|
||
control.Dock = DockStyle.Fill;
|
||
AutoDpi(control);
|
||
AntdUI.TabPage tabPage = new AntdUI.TabPage()
|
||
{
|
||
Text = $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}",
|
||
ReadOnly = false,
|
||
};
|
||
tabPage.Controls.Add(control);
|
||
tabs1.Pages.Add(tabPage);
|
||
tabs1.SelectedTab = tabPage;
|
||
}
|
||
break;
|
||
case "其他设置":
|
||
foreach (var tab in tabs1.Pages)
|
||
{
|
||
if (tab is AntdUI.TabPage existingTab && existingTab.Text == $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}")
|
||
{
|
||
tabs1.SelectedTab = existingTab; // 直接跳转到已存在的 TabPage
|
||
return;
|
||
}
|
||
}
|
||
|
||
if (clickedItem.Text == "全局设置")
|
||
{
|
||
//先获取是否存在该名称的配置
|
||
//如果没有新建项
|
||
GlobalConfig? global = ConfigModel
|
||
.GlobalList.FirstOrDefault();
|
||
if (global == null)
|
||
{
|
||
global = new GlobalConfig();
|
||
}
|
||
|
||
UserControl control3 = null;
|
||
control = new GlobalControl(this, global);
|
||
if (control != null)
|
||
{
|
||
//容器添加控件,需要调整dpi
|
||
control.Dock = DockStyle.Fill;
|
||
AutoDpi(control);
|
||
AntdUI.TabPage tabPage = new AntdUI.TabPage()
|
||
{
|
||
Text = $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}",
|
||
ReadOnly = false,
|
||
};
|
||
tabPage.Controls.Add(control);
|
||
tabs1.Pages.Add(tabPage);
|
||
tabs1.SelectedTab = tabPage;
|
||
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|