解决合并冲突
This commit is contained in:
@ -12,7 +12,21 @@
|
||||
<OutputType>WinExe</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Services\AuthService.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="db\config.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AntdUI" Version="1.8.9" />
|
||||
<PackageReference Include="SqlSugarCore" Version="5.1.4.185" />
|
||||
@ -25,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>
|
||||
|
||||
@ -40,4 +55,14 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Services\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="db\db.sqlite">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
2
DHSoftware/LoginWindow.Designer.cs
generated
2
DHSoftware/LoginWindow.Designer.cs
generated
@ -101,7 +101,7 @@
|
||||
Name = "LoginWindow";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "登录界面";
|
||||
Load += LoginWindow_Load;
|
||||
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,23 @@
|
||||
using AntdUI;
|
||||
using DH.RBAC.Logic.Sys;
|
||||
using DH.RBAC.Model.Sys;
|
||||
using DH.RBAC.Utility.Other;
|
||||
using DHSoftware.Models;
|
||||
using DHSoftware.Services;
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
9
DHSoftware/MainWindow.Designer.cs
generated
9
DHSoftware/MainWindow.Designer.cs
generated
@ -483,6 +483,7 @@
|
||||
btnDeleteProject.Name = "btnDeleteProject";
|
||||
btnDeleteProject.Size = new Size(68, 40);
|
||||
btnDeleteProject.TabIndex = 19;
|
||||
btnDeleteProject.Tag = "sys-deletescheme";
|
||||
btnDeleteProject.Text = "删除";
|
||||
btnDeleteProject.Visible = false;
|
||||
//
|
||||
@ -492,6 +493,7 @@
|
||||
btnAddProject.Name = "btnAddProject";
|
||||
btnAddProject.Size = new Size(68, 40);
|
||||
btnAddProject.TabIndex = 18;
|
||||
btnAddProject.Tag = "sys-addscheme";
|
||||
btnAddProject.Text = "新增";
|
||||
btnAddProject.Visible = false;
|
||||
//
|
||||
@ -501,6 +503,7 @@
|
||||
btnLoadProject.Name = "btnLoadProject";
|
||||
btnLoadProject.Size = new Size(68, 40);
|
||||
btnLoadProject.TabIndex = 17;
|
||||
btnLoadProject.Tag = "sys-loadscheme";
|
||||
btnLoadProject.Text = "载入";
|
||||
btnLoadProject.Visible = false;
|
||||
//
|
||||
@ -513,6 +516,7 @@
|
||||
sltProjects.Name = "sltProjects";
|
||||
sltProjects.Size = new Size(214, 40);
|
||||
sltProjects.TabIndex = 16;
|
||||
sltProjects.Tag = "sys-schemelist";
|
||||
//
|
||||
// segmented1
|
||||
//
|
||||
@ -576,6 +580,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);
|
||||
@ -672,6 +677,10 @@
|
||||
private Label lblOEE_Total;
|
||||
private Label lblStartTime;
|
||||
private Label label10;
|
||||
private Label lblstarttime2;
|
||||
private Label label7;
|
||||
private AntdUI.Panel pnlLog;
|
||||
private AntdUI.Label lbInBackend;
|
||||
private DataGridView dgvProductNums;
|
||||
private TableLayoutPanel tableLayoutPanel3;
|
||||
}
|
||||
|
@ -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;
|
||||
@ -179,7 +180,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();
|
||||
@ -750,6 +838,13 @@ namespace DHSoftware
|
||||
OnLog -= LogDisplay;
|
||||
OnLog += LogDisplay;
|
||||
|
||||
lbInBackend.Click += LbInBackend_Click;
|
||||
}
|
||||
|
||||
private void LbInBackend_Click(object? sender, EventArgs e)
|
||||
{
|
||||
DH.RBAC.RBACWindow.Instance.Show();
|
||||
|
||||
OnUpdateCamResult -= UpdateCamResult;
|
||||
|
||||
OnUpdateCamResult += UpdateCamResult;
|
||||
@ -1570,7 +1665,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();
|
||||
}
|
||||
|
||||
|
@ -1,23 +1,35 @@
|
||||
using System;
|
||||
using System.Data.Entity;
|
||||
using System.Drawing;
|
||||
using System.Reflection;
|
||||
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 Newtonsoft.Json;
|
||||
using GlobalConfig = DH.RBAC.Common.GlobalConfig;
|
||||
|
||||
namespace DHSoftware
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
|
||||
private static MainWindow mainWindow;
|
||||
/// <summary>
|
||||
/// 应用程序的主入口点。
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
|
||||
/// <summary>
|
||||
/// 应用程序的主入口点。
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
|
||||
static void Main()
|
||||
{
|
||||
// 必须在第一个窗口创建前调用以下两行
|
||||
@ -40,14 +52,25 @@ namespace DHSoftware
|
||||
UpdateStep(10, "正在加载数据库", true);
|
||||
try
|
||||
{
|
||||
DatabaseUtil.InitializeDatabase();
|
||||
MyConfig config = File.ReadAllText(MyEnvironment.RootPath("db/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
|
||||
{
|
||||
|
@ -1,151 +0,0 @@
|
||||
using DHSoftware.Models;
|
||||
using SqlSugar;
|
||||
|
||||
namespace DHSoftware.Utils
|
||||
{
|
||||
public static class DatabaseUtil
|
||||
{
|
||||
private static readonly string DatabasePath = Path.Combine(
|
||||
Application.StartupPath,
|
||||
"db",
|
||||
"RBACSystem.sqlite"
|
||||
);
|
||||
|
||||
public static void InitializeDatabase()
|
||||
{
|
||||
EnsureDirectoryExists();
|
||||
using (var db = GetDatabase())
|
||||
{
|
||||
// 检查初始化状态(通过检查是否存在系统表)
|
||||
bool isInitialized = db.DbMaintenance.IsAnyTable("RolePermission");
|
||||
|
||||
if (!isInitialized)
|
||||
{
|
||||
// 创建所有表
|
||||
db.CodeFirst.InitTables(
|
||||
typeof(User),
|
||||
typeof(Role),
|
||||
typeof(Permission),
|
||||
typeof(UserRole),
|
||||
typeof(RolePermission)
|
||||
);
|
||||
|
||||
// 初始化基础数据
|
||||
InitializeSeedData(db);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static SqlSugarClient GetDatabase()
|
||||
{
|
||||
return new SqlSugarClient(new ConnectionConfig()
|
||||
{
|
||||
ConnectionString = $"Data Source={DatabasePath};",
|
||||
DbType = DbType.Sqlite,
|
||||
IsAutoCloseConnection = true,
|
||||
InitKeyType = InitKeyType.Attribute
|
||||
});
|
||||
}
|
||||
|
||||
private static void EnsureDirectoryExists()
|
||||
{
|
||||
var directory = Path.GetDirectoryName(DatabasePath);
|
||||
if (!Directory.Exists(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
}
|
||||
|
||||
private static void InitializeSeedData(SqlSugarClient db)
|
||||
{
|
||||
// 初始化角色
|
||||
var adminRole = GetOrCreateRole(db, "admin", "系统管理员");
|
||||
var userRole = GetOrCreateRole(db, "user", "普通用户");
|
||||
|
||||
// 初始化权限
|
||||
var permissions = new List<Permission>
|
||||
{
|
||||
new Permission { Code = "system:access", Name = "访问系统" },
|
||||
new Permission { Code = "user:view", Name = "查看用户" },
|
||||
new Permission { Code = "user:edit", Name = "管理用户" },
|
||||
new Permission { Code = "role:manage", Name = "角色管理" },
|
||||
new Permission { Code = "system:config", Name = "配置权限" },
|
||||
new Permission { Code = "system:loadscheme", Name = "加载方案" },
|
||||
new Permission { Code = "system:addscheme", Name = "新增方案" },
|
||||
new Permission { Code = "system:deletescheme", Name = "删除方案" }
|
||||
};
|
||||
InitializePermissions(db, permissions);
|
||||
|
||||
// 分配权限给管理员角色
|
||||
AssignPermissionsToRole(db, adminRole.Id, permissions.Select(p => p.Code).ToList());
|
||||
|
||||
// 创建默认管理员
|
||||
CreateAdminUser(db);
|
||||
}
|
||||
|
||||
private static Role GetOrCreateRole(SqlSugarClient db, string roleName, string description)
|
||||
{
|
||||
var role = db.Queryable<Role>()
|
||||
.First(r => r.RoleName == roleName);
|
||||
|
||||
if (role == null)
|
||||
{
|
||||
role = new Role
|
||||
{
|
||||
RoleName = roleName,
|
||||
Description = description
|
||||
};
|
||||
role.Id = db.Insertable(role).ExecuteReturnIdentity();
|
||||
}
|
||||
return role;
|
||||
}
|
||||
|
||||
private static void InitializePermissions(SqlSugarClient db, List<Permission> permissions)
|
||||
{
|
||||
foreach (var p in permissions)
|
||||
{
|
||||
if (!db.Queryable<Permission>().Any(x => x.Code == p.Code))
|
||||
{
|
||||
db.Insertable(p).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void AssignPermissionsToRole(SqlSugarClient db, int roleId, List<string> permissionCodes)
|
||||
{
|
||||
var existing = db.Queryable<RolePermission>()
|
||||
.Where(rp => rp.RoleId == roleId)
|
||||
.Select(rp => rp.PermissionCode)
|
||||
.ToList();
|
||||
|
||||
foreach (var code in permissionCodes.Except(existing))
|
||||
{
|
||||
db.Insertable(new RolePermission
|
||||
{
|
||||
RoleId = roleId,
|
||||
PermissionCode = code
|
||||
}).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
private static void CreateAdminUser(SqlSugarClient db)
|
||||
{
|
||||
if (!db.Queryable<User>().Any(u => u.UserName == "admin"))
|
||||
{
|
||||
var admin = new User
|
||||
{
|
||||
UserName = "admin",
|
||||
Password = HashHelper.MD5Encrypt("admin123"),
|
||||
LastLoginTime = null
|
||||
};
|
||||
admin.Id = db.Insertable(admin).ExecuteReturnIdentity();
|
||||
|
||||
db.Insertable(new UserRole
|
||||
{
|
||||
UserId = admin.Id,
|
||||
RoleId = db.Queryable<Role>().First(r => r.RoleName == "admin").Id
|
||||
}).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
2
DHSoftware/Views/SettingWindow.Designer.cs
generated
2
DHSoftware/Views/SettingWindow.Designer.cs
generated
@ -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;
|
||||
//
|
||||
|
@ -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)
|
||||
{
|
||||
|
BIN
DHSoftware/db/config.json
Normal file
BIN
DHSoftware/db/config.json
Normal file
Binary file not shown.
BIN
DHSoftware/db/db.sqlite
Normal file
BIN
DHSoftware/db/db.sqlite
Normal file
Binary file not shown.
Reference in New Issue
Block a user