提交rbac

提交设置右键错位的bug
This commit is contained in:
2025-04-08 15:15:02 +08:00
parent ab38ee029a
commit 9f7c6206ca
139 changed files with 27868 additions and 117 deletions

Binary file not shown.

View File

@ -0,0 +1,84 @@
<configuration>
<log4net>
<!--错误日志类-->
<logger name="logerror">
<!--定义记录的日志级别-->
<level value="ALL" />
<!--记录到哪个介质中去-->
<appender-ref ref="ErrorAppender" />
<appender-ref ref="ConsoleAppender" />
</logger>
<!--运行信息日志类-->
<logger name="loginfo">
<level value="ALL" />
<appender-ref ref="InfoAppender" />
<appender-ref ref="ConsoleAppender" />
</logger>
<!--操作日志类-->
<logger name="logoperate">
<level value="ALL" />
<appender-ref ref="OperateAppender" />
<appender-ref ref="ConsoleAppender" />
</logger>
<!--错误日志附加介质-->
<appender name="ErrorAppender" type="log4net.Appender.RollingFileAppender">
<!-- name属性指定其名称,type则是log4net.Appender命名空间的一个类的名称,意思是,指定使用哪种介质-->
<param name="File" value="\\Log\\Error" />
<param name="AppendToFile" value="true" />
<param name="MaximumFileSize" value="10MB" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name= "DatePattern" value= "yyyy-MM-dd&quot;.log&quot;"/>
<param name="lockingModel" type="log4net.Appender.FileAppender+MinimalLock" />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<!--<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n %loggername" />-->
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
<!--信息日志附加介质-->
<appender name="InfoAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="\\Log\\Info" />
<param name="AppendToFile" value="true" />
<param name="MaximumFileSize" value="10MB" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name= "DatePattern" value= "yyyy-MM-dd&quot;.log&quot;"/>
<param name="lockingModel" type="log4net.Appender.FileAppender+MinimalLock" />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<!--<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n %loggername" />-->
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
<!--警告日志附加介质-->
<appender name="OperateAppender" type="log4net.Appender.RollingFileAppender">
<!-- name属性指定其名称,type则是log4net.Appender命名空间的一个类的名称,意思是,指定使用哪种介质-->
<param name="File" value="\\Log\\Operate" />
<param name="AppendToFile" value="true" />
<param name="MaximumFileSize" value="10MB" />
<param name="MaxSizeRollBackups" value="100" />
<param name="StaticLogFileName" value="false" />
<param name= "DatePattern" value= "yyyy-MM-dd&quot;.log&quot;"/>
<param name="lockingModel" type="log4net.Appender.FileAppender+MinimalLock" />
<param name="RollingStyle" value="Date" />
<!--信息日志布局-->
<layout type="log4net.Layout.PatternLayout">
<!--<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n %loggername" />-->
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
</log4net>
</configuration>

View File

@ -12,6 +12,16 @@
<OutputType>WinExe</OutputType>
</PropertyGroup>
<ItemGroup>
<Content Include="Configs\config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<None Include="Configs\log4net.config" />
</ItemGroup>
@ -29,6 +39,7 @@
<ProjectReference Include="..\DH.Devices.Motion\DH.Devices.Motion.csproj" />
<ProjectReference Include="..\DH.Devices.PLC\DH.Devices.PLC.csproj" />
<ProjectReference Include="..\DH.Devices.Vision\DH.Devices.Vision.csproj" />
<ProjectReference Include="..\DH.RBAC\DH.RBAC.csproj" />
<ProjectReference Include="..\DH.UI.Model.Winform\DH.UI.Model.Winform.csproj" />
</ItemGroup>

View File

@ -101,7 +101,7 @@
Name = "LoginWindow";
StartPosition = FormStartPosition.CenterScreen;
Text = "登录界面";
Load += LoginWindow_Load;
ResumeLayout(false);
}

View File

@ -1,4 +1,7 @@
using AntdUI;
using DH.RBAC.Logic.Sys;
using DH.RBAC.Model.Sys;
using DH.RBAC.Utility.Other;
using DHSoftware.Models;
using DHSoftware.Services;
@ -6,9 +9,15 @@ namespace DHSoftware
{
public partial class LoginWindow : AntdUI.Window
{
private SysUserLogic userlogic;
private SysUserLogOnLogic userLogOnLogic;
private SysPermissionLogic permissionLogic;
public LoginWindow()
{
InitializeComponent();
userlogic = new SysUserLogic();
userLogOnLogic = new SysUserLogOnLogic();
permissionLogic = new SysPermissionLogic();
// 关键设置:允许窗体优先接收按键事件
this.KeyPreview = true;
@ -18,6 +27,7 @@ namespace DHSoftware
button_cancel.Click += Button_cancel_Click;
}
private void Login_KeyDown(object? sender, KeyEventArgs e)
{
// 监听回车键
@ -40,7 +50,7 @@ namespace DHSoftware
/// </summary>
private static LoginWindow _instance;
internal static LoginWindow Instance
public static LoginWindow Instance
{
get
{
@ -50,74 +60,79 @@ namespace DHSoftware
}
}
public MainWindow parentForm;
private void Button_cancel_Click(object? sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
this.Dispose();
}
private void Button_ok_Click(object? sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(iptName.Text))
string userName = iptName.Text;
string password = iptPwd.Text;
if (StringHelper.IsNullOrEmpty(userName))
{
AntdUI.Message.warn(this, "用户名不能为空", autoClose: 3);
return;
}
if (string.IsNullOrWhiteSpace(iptPwd.Text))
{
AntdUI.Message.warn(this, "密码不能为空!", autoClose: 3);
return;
}
if (AuthService.Login(iptName.Text, iptPwd.Text))
{
if (this.Owner is MainWindow parent)
{
List<string> UserPermissions = AuthService.GetUserPermissions();
// 检查当前用户是否有权限
if (AuthService.HasPermission("system:config"))
{
parent.ShowConfig = true;
}
else
{
parent.ShowConfig = false;
}
if (AuthService.HasPermission("system:loadscheme"))
{
parent.Loadscheme = true;
}
else
{
parent.Loadscheme = false;
}
if (AuthService.HasPermission("system:addscheme"))
{
parent.Addscheme = true;
}
else
{
parent.Addscheme = false;
}
if (AuthService.HasPermission("system:deletescheme"))
{
parent.Deleteschememe = true;
}
else
{
parent.Deleteschememe = false;
}
AntdUI.Message.warn(this, "请输入用户名!", autoClose: 3);
parent.LoginName = iptName.Text;
}
this.Dispose();
return;
}
if (StringHelper.IsNullOrEmpty(password))
{
AntdUI.Message.warn(this, "请输入密码!", autoClose: 3);
return;
}
password = password.MD5Encrypt();
var userEntity = userlogic.GetByUserName(userName);
if (userEntity == null)
{
AntdUI.Message.warn(this, "该账户不存在,请重新输入!", autoClose: 3);
return;
}
if (!userEntity.IsEnabled)
{
AntdUI.Message.warn(this, "该账户已被禁用,请联系管理员!", autoClose: 3);
return;
}
var userLogOnEntity = userLogOnLogic.GetByAccount(userEntity.Id);
string inputPassword = password.DESEncrypt(userLogOnEntity.SecretKey).MD5Encrypt();
if (inputPassword != userLogOnEntity.Password)
{
AntdUI.Message.warn(this, "密码错误,请重新输入!", autoClose: 3);
return;
}
userLogOnLogic.UpdateLogin(userLogOnEntity);
DH.RBAC.Common.GlobalConfig.CurrentUser = userEntity;
List<SysPermission> list;
if (userlogic.ContainsUser("admin", DH.RBAC.Common.GlobalConfig.CurrentUser.Id))
{
list = permissionLogic.GetList();
}
else
{
AntdUI.Message.warn(this, "用户名或密码错误,登录失败!", autoClose: 3);
list = permissionLogic.GetList(DH.RBAC.Common.GlobalConfig.CurrentUser.Id);
}
if (list.IsNullOrEmpty())
{
AntdUI.Message.warn(this, "网络或服务器异常,请稍后重试!", autoClose: 3);
return;
}
DH.RBAC.Common.GlobalConfig.PermissionList = list;
DialogResult = DialogResult.OK;
parentForm.ButtonPermissionList = DH.RBAC.Common.GlobalConfig.PermissionList.ToList();
this.Dispose();
}
private void LoginWindow_Load(object sender, EventArgs e)
{
}
}
}

View File

@ -51,6 +51,7 @@
lblNum = new Label();
label2 = new Label();
pageHeader1 = new AntdUI.PageHeader();
lbInBackend = new AntdUI.Label();
labuph = new Label();
divider2 = new AntdUI.Divider();
tabMain = new AntdUI.TabPage();
@ -237,6 +238,7 @@
//
// pageHeader1
//
pageHeader1.Controls.Add(lbInBackend);
pageHeader1.Controls.Add(labuph);
pageHeader1.Controls.Add(divider2);
pageHeader1.DividerShow = true;
@ -248,6 +250,19 @@
pageHeader1.TabIndex = 7;
pageHeader1.Text = "UPH";
//
// lbInBackend
//
lbInBackend.BackColor = Color.Transparent;
lbInBackend.Dock = DockStyle.Right;
lbInBackend.ForeColor = Color.FromArgb(46, 108, 227);
lbInBackend.Location = new Point(949, 10);
lbInBackend.Name = "lbInBackend";
lbInBackend.Size = new Size(75, 30);
lbInBackend.TabIndex = 3;
lbInBackend.Tag = "sys-back";
lbInBackend.Text = "系统后台";
lbInBackend.Visible = false;
//
// labuph
//
labuph.AutoSize = true;
@ -454,6 +469,7 @@
btnDeleteProject.Name = "btnDeleteProject";
btnDeleteProject.Size = new Size(68, 40);
btnDeleteProject.TabIndex = 19;
btnDeleteProject.Tag = "sys-deletescheme";
btnDeleteProject.Text = "删除";
btnDeleteProject.Visible = false;
//
@ -463,6 +479,7 @@
btnAddProject.Name = "btnAddProject";
btnAddProject.Size = new Size(68, 40);
btnAddProject.TabIndex = 18;
btnAddProject.Tag = "sys-addscheme";
btnAddProject.Text = "新增";
btnAddProject.Visible = false;
//
@ -472,6 +489,7 @@
btnLoadProject.Name = "btnLoadProject";
btnLoadProject.Size = new Size(68, 40);
btnLoadProject.TabIndex = 17;
btnLoadProject.Tag = "sys-loadscheme";
btnLoadProject.Text = "载入";
btnLoadProject.Visible = false;
//
@ -484,6 +502,7 @@
sltProjects.Name = "sltProjects";
sltProjects.Size = new Size(214, 40);
sltProjects.TabIndex = 16;
sltProjects.Tag = "sys-schemelist";
//
// segmented1
//
@ -547,6 +566,7 @@
segmentedItem5.BadgeSvg = null;
segmentedItem5.IconActiveSvg = resources.GetString("segmentedItem5.IconActiveSvg");
segmentedItem5.IconSvg = resources.GetString("segmentedItem5.IconSvg");
segmentedItem5.ID = "sys-setbutton";
segmentedItem5.Text = "设置";
segmented1.Items.Add(segmentedItem1);
segmented1.Items.Add(segmentedItem2);
@ -635,5 +655,6 @@
private Label lblstarttime2;
private Label label7;
private AntdUI.Panel pnlLog;
private AntdUI.Label lbInBackend;
}
}

View File

@ -8,6 +8,7 @@ using DH.Devices.Camera;
using DH.Devices.Motion;
using DH.Devices.PLC;
using DH.Devices.Vision;
using DH.RBAC.Model.Sys;
using DHSoftware.Languages;
using DHSoftware.Models;
using DHSoftware.Utils;
@ -169,7 +170,94 @@ namespace DHSoftware
segmented1.Items.Remove(itemToHide);
}
}
public List<SysPermission> ButtonPermissionList
{
set
{
lbName.Text = DH.RBAC.Common.GlobalConfig.CurrentUser.Account;
List<SysPermission> list = value;
SetPermission(list, this.Controls);
}
}
private void SetPermission(List<SysPermission> list, Control.ControlCollection controls)
{
foreach (Control control in controls)
{
if (control.HasChildren)
{
SetPermission(list, control.Controls);
continue;
}
if (control is AntdUI.Button button)
{
HandleButtonVisibility(button, list);
continue;
}
if (control is AntdUI.Label label)
{
HandleLabelVisibility(label, list);
continue;
}
if (control is AntdUI.Segmented segmented)
{
HandleSegmentedItems(segmented, list);
}
}
}
/// <summary>
/// 处理 Segmented 控件的权限逻辑
/// </summary>
private void HandleSegmentedItems(Segmented segmented, List<SysPermission> permissions)
{
SysPermission permission = permissions.FirstOrDefault(p => p.EnCode == itemToHide.ID);
bool itemExists = segmented.Items.Contains(itemToHide);
if (permission != null)
{
if (!itemExists)
{
segmented.Items.Insert(4, itemToHide);
}
}
else
{
if (itemExists)
{
segmented.Items.Remove(itemToHide);
}
}
}
/// <summary>
/// 处理 Button 可见性
/// </summary>
private void HandleButtonVisibility(AntdUI.Button button, List<SysPermission> permissions)
{
if (button.Tag is string tag && !string.IsNullOrEmpty(tag))
{
bool hasPermission = permissions.Any(p => p.EnCode == tag);
button.Visible = hasPermission;
}
}
/// <summary>
/// 处理 Label 可见性
/// </summary>
private void HandleLabelVisibility(AntdUI.Label label, List<SysPermission> permissions)
{
if (label.Tag is string tag && !string.IsNullOrEmpty(tag))
{
bool hasPermission = permissions.Any(p => p.EnCode == tag);
label.Visible = hasPermission;
}
}
public MainWindow()
{
InitializeComponent();
@ -425,6 +513,13 @@ namespace DHSoftware
LoggerHelper.LogPrefix = "Process";
OnLog -= LogDisplay;
OnLog += LogDisplay;
lbInBackend.Click += LbInBackend_Click;
}
private void LbInBackend_Click(object? sender, EventArgs e)
{
DH.RBAC.RBACWindow.Instance.Show();
}
private void BtnDeleteProject_Click(object? sender, EventArgs e)
@ -1068,7 +1163,7 @@ namespace DHSoftware
private void HandleLoginButton()
{
// Add the code for the "登录" button click here
LoginWindow.Instance.Owner = this;
LoginWindow.Instance.parentForm = this;
LoginWindow.Instance.Show();
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Microsoft ResX Schema
Version 2.0
@ -48,7 +48,7 @@
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter

View File

@ -2,12 +2,18 @@
using System.Drawing;
using System.Windows.Forms;
using AntdUI;
using DH.Commons.Base;
using DH.Commons.Enums;
using DH.Commons.Helper;
using DH.Commons.Models;
using DH.RBAC.Common;
using DH.RBAC.Logic.Base;
using DH.RBAC.Utility.Extension;
using DH.RBAC.Utility.Other;
using DHSoftware.Utils;
using DHSoftware.Views;
using Microsoft.VisualBasic.Logging;
using GlobalConfig = DH.RBAC.Common.GlobalConfig;
namespace DHSoftware
{
@ -40,14 +46,24 @@ namespace DHSoftware
UpdateStep(10, "正在加载数据库", true);
try
{
DatabaseUtil.InitializeDatabase();
MyConfig config = File.ReadAllText(MyEnvironment.RootPath("Configs/config.json")).ToObject<MyConfig>();
GlobalConfig.Config = config;
string message = "";
bool flag = BaseLogic.InitDB(config.DbType, config.DbHost, config.DbName, config.DbUserName, config.DbPassword, ref message);
if (!flag)
{
Console.Write(message);
return;
}
//DatabaseUtil.InitializeDatabase();
}
catch (Exception ex)
{
SystemModel.CurrentStatus = EnumStatus.;
Modal.open(WelcomeWindow.Instance, "错误!", ex.ToString(), TType.Error);
SystemModel.CurrentStatus = EnumStatus.;
Modal.open(WelcomeWindow.Instance, "错误!", ex.ToString(), TType.Error);
}
UpdateStep(30, "正在加载解决方案", true);
try
{

View File

@ -96,6 +96,7 @@
btnSave.Name = "btnSave";
btnSave.Size = new Size(63, 28);
btnSave.TabIndex = 2;
btnSave.Tag = "sys-setsave";
btnSave.Text = "保存";
//
// btnAdd
@ -111,6 +112,7 @@
btnAdd.Placement = AntdUI.TAlignFrom.TL;
btnAdd.Size = new Size(63, 28);
btnAdd.TabIndex = 1;
btnAdd.Tag = "sys-setadd";
btnAdd.Text = "新增";
btnAdd.Trigger = AntdUI.Trigger.Hover;
//

View File

@ -4,6 +4,9 @@ using DH.Commons.Helper;
using DH.Commons.Models;
using DHSoftware.Utils;
using DH.Commons.Base;
using DH.RBAC.Model.Sys;
using System.Reflection;
using ScrollBar = AntdUI.ScrollBar;
namespace DHSoftware.Views
{
@ -227,6 +230,8 @@ namespace DHSoftware.Views
private void InitData()
{
ButtonPermissionList = DH.RBAC.Common.GlobalConfig.PermissionList.ToList();
btnAdd.Items.Clear();
btnAdd.Items.Add("相机设置");
btnAdd.Items.Add("工位设置");
@ -316,18 +321,137 @@ namespace DHSoftware.Views
}
return null;
}
public List<SysPermission> ButtonPermissionList
{
set
{
List<SysPermission> list = value;
SetPermission(list, this.Controls);
}
}
private void SetPermission(List<SysPermission> list, Control.ControlCollection controls)
{
foreach (Control control in controls)
{
if (control.HasChildren)
{
SetPermission(list, control.Controls);
continue;
}
if (control is AntdUI.Button button)
{
HandleButtonVisibility(button, list);
continue;
}
if (control is AntdUI.Label label)
{
HandleLabelVisibility(label, list);
continue;
}
if (control is AntdUI.Dropdown dropdown)
{
HandleDropdownVisibility(dropdown, list);
continue;
}
}
}
private void HandleDropdownVisibility(Dropdown dropdown, List<SysPermission> permissions)
{
if (dropdown.Tag is string tag && !string.IsNullOrEmpty(tag))
{
bool hasPermission = permissions.Any(p => p.EnCode == tag);
dropdown.Visible = hasPermission;
}
}
/// <summary>
/// 处理 Button 可见性
/// </summary>
private void HandleButtonVisibility(AntdUI.Button button, List<SysPermission> permissions)
{
if (button.Tag is string tag && !string.IsNullOrEmpty(tag))
{
bool hasPermission = permissions.Any(p => p.EnCode == tag);
button.Visible = hasPermission;
}
}
/// <summary>
/// 处理 Label 可见性
/// </summary>
private void HandleLabelVisibility(AntdUI.Label label, List<SysPermission> permissions)
{
if (label.Tag is string tag && !string.IsNullOrEmpty(tag))
{
bool hasPermission = permissions.Any(p => p.EnCode == tag);
label.Visible = hasPermission;
}
}
private bool isUpdatingTabs = false;
public static int GetMenuScrollValue(Menu menu)
{
try
{
// 通过反射获取内部 ScrollBar 的 Value
var scrollBarField = typeof(Menu).GetField("ScrollBar",
BindingFlags.NonPublic | BindingFlags.Instance);
if (scrollBarField != null)
{
var scrollBar = scrollBarField.GetValue(menu) as ScrollBar;
return scrollBar?.Value ?? 0;
}
}
catch { /* 异常处理 */ }
return 0;
}
public static MenuItem FindClickedMenuItem(Menu menu, Point clickPoint)
{
int scrollY = GetMenuScrollValue(menu);
// 调整点击坐标为内容坐标系(叠加滚动偏移)
Point adjustedPoint = new Point(clickPoint.X, clickPoint.Y + scrollY);
return TraverseMenuItems(menu.Items, adjustedPoint);
}
private static MenuItem TraverseMenuItems(MenuItemCollection items, Point adjustedPoint)
{
foreach (MenuItem item in items)
{
if (!item.Visible) continue;
// 检查当前项是否命中
if (item.Rect.Contains(adjustedPoint)) return item;
// 如果子菜单展开且存在子项,递归查找
if (item.Expand && item.Sub != null && item.Sub.Count > 0)
{
var childResult = TraverseMenuItems(item.Sub, adjustedPoint);
if (childResult != null) return childResult;
}
}
return null;
}
private void menu1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
// 转换坐标到控件内部坐标系(考虑滚动条)
Point clickPoint = new Point(e.X, e.Y + menu1.ScrollBar.Value);
// 递归查找命中的菜单项
MenuItem clickedItem = FindClickedItem(menu1.Items, clickPoint);
var menu = sender as Menu;
if (menu == null) return;
// 获取命中的 MenuItem
MenuItem clickedItem = FindClickedMenuItem(menu, e.Location);
if (clickedItem != null)
{
@ -355,20 +479,24 @@ namespace DHSoftware.Views
switch (it.Text)
{
case "删除相机":
menu1.Remove(clickedItem);
foreach (var tab in tabs1.Pages)
var result = AntdUI.Modal.open(this, "删除警告!", $"确定删除{clickedItem.Text}", TType.Warn);
if (result == DialogResult.OK)
{
if (tab is AntdUI.TabPage existingTab && existingTab.Text == $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}")
menu1.Remove(clickedItem);
foreach (var tab in tabs1.Pages)
{
isUpdatingTabs = true;
tabs1.Pages.Remove(tab);
ConfigModel.CameraBaseList.RemoveAll(c => c.CameraName == clickedItem.Text);
isUpdatingTabs = false;
currControl = existingTab.Controls.Count > 0 ? existingTab.Controls[0] as UserControl : null;
return;
if (tab is AntdUI.TabPage existingTab && existingTab.Text == $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}")
{
isUpdatingTabs = true;
tabs1.Pages.Remove(tab);
ConfigModel.CameraBaseList.RemoveAll(c => c.CameraName == clickedItem.Text);
isUpdatingTabs = false;
currControl = existingTab.Controls.Count > 0 ? existingTab.Controls[0] as UserControl : null;
return;
}
}
ConfigModel.CameraBaseList.RemoveAll(c => c.CameraName == clickedItem.Text);
}
ConfigModel.CameraBaseList.RemoveAll(c => c.CameraName == clickedItem.Text);
break;
case "重命名":
@ -437,19 +565,23 @@ namespace DHSoftware.Views
switch (it.Text)
{
case "删除工位":
menu1.Remove(clickedItem);
foreach (var tab in tabs1.Pages)
var result = AntdUI.Modal.open(this, "删除警告!", $"确定删除{clickedItem.Text}", TType.Warn);
if (result == DialogResult.OK)
{
if (tab is AntdUI.TabPage existingTab && existingTab.Text == $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}")
menu1.Remove(clickedItem);
foreach (var tab in tabs1.Pages)
{
isUpdatingTabs = true;
tabs1.Pages.Remove(tab);
isUpdatingTabs = false;
currControl = existingTab.Controls.Count > 0 ? existingTab.Controls[0] as UserControl : null;
return;
if (tab is AntdUI.TabPage existingTab && existingTab.Text == $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}")
{
isUpdatingTabs = true;
tabs1.Pages.Remove(tab);
isUpdatingTabs = false;
currControl = existingTab.Controls.Count > 0 ? existingTab.Controls[0] as UserControl : null;
return;
}
}
ConfigModel.DetectionList.RemoveAll(c => c.Name == clickedItem.Text);
}
ConfigModel.DetectionList.RemoveAll(c => c.Name == clickedItem.Text);
break;
case "重命名":
@ -519,22 +651,25 @@ namespace DHSoftware.Views
switch (it.Text)
{
case "删除运控":
menu1.Remove(clickedItem);
foreach (var tab in tabs1.Pages)
var result = AntdUI.Modal.open(this, "删除警告!", $"确定删除{clickedItem.Text}", TType.Warn);
if (result == DialogResult.OK)
{
if (tab is AntdUI.TabPage existingTab && existingTab.Text == $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}")
menu1.Remove(clickedItem);
foreach (var tab in tabs1.Pages)
{
isUpdatingTabs = true;
//tabs1.SelectedTab = existingTab; // 直接跳转到已存在的 TabPage
tabs1.Pages.Remove(tab);
ConfigModel.PLCBaseList.RemoveAll(c => c.PLCName == clickedItem.Text);
isUpdatingTabs = false;
currControl = existingTab.Controls.Count > 0 ? existingTab.Controls[0] as UserControl : null;
return;
if (tab is AntdUI.TabPage existingTab && existingTab.Text == $"{clickedItem.PARENTITEM.Text}-{clickedItem.Text}")
{
isUpdatingTabs = true;
//tabs1.SelectedTab = existingTab; // 直接跳转到已存在的 TabPage
tabs1.Pages.Remove(tab);
ConfigModel.PLCBaseList.RemoveAll(c => c.PLCName == clickedItem.Text);
isUpdatingTabs = false;
currControl = existingTab.Controls.Count > 0 ? existingTab.Controls[0] as UserControl : null;
return;
}
}
ConfigModel.PLCBaseList.RemoveAll(c => c.PLCName == clickedItem.Text);
}
ConfigModel.PLCBaseList.RemoveAll(c => c.PLCName == clickedItem.Text);
break;
case "重命名":
@ -587,25 +722,6 @@ namespace DHSoftware.Views
}
}
private MenuItem FindClickedItem(MenuItemCollection items, Point clickPoint)
{
foreach (MenuItem item in items)
{
// 检查当前项是否可见且包含点击坐标
if (item.Visible && item.Rect.Contains(clickPoint))
{
return item;
}
// 递归检查子项(如果展开)
if (item.Expand && item.Sub != null)
{
var childResult = FindClickedItem(item.Sub, clickPoint);
if (childResult != null) return childResult;
}
}
return null;
}
private void btnAdd_SelectedValueChanged(object sender, ObjectNEventArgs e)
{