From 3a471ae651b228231bebb3a2d438baa1d4ac0261 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期五, 21 十一月 2025 08:57:52 +0800
Subject: [PATCH] 优化
---
HMI.MenuManage/Modal/MenuModal.xaml.cs | 279 +++++++++++++++++++++++++------------------------------
1 files changed, 126 insertions(+), 153 deletions(-)
diff --git a/HMI.MenuManage/Modal/MenuModal.xaml.cs b/HMI.MenuManage/Modal/MenuModal.xaml.cs
index 173b514..35d2ffb 100644
--- a/HMI.MenuManage/Modal/MenuModal.xaml.cs
+++ b/HMI.MenuManage/Modal/MenuModal.xaml.cs
@@ -1,14 +1,17 @@
-锘縰sing System;
-using System.ComponentModel;
-using System.Reflection;
-using System.Windows;
-using Microsoft.Win32;
-using Panuon.WPF.UI;
-using HMI.Core.Annotation;
-using HMI.Core.Entity;
-using HMI.Core.Exceptions;
+锘縰sing HMI.Core.Annotation;
using HMI.Core.Util;
using HMI.MenuManage.Entity;
+using HMI.UI.DpUtil;
+using HMI.UI.Util;
+using Microsoft.Win32;
+using Panuon.WPF.UI;
+using System;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Data;
+using System.Reflection;
+using System.Windows;
+using System.Windows.Controls;
namespace HMI.MenuManage
{
@@ -19,6 +22,7 @@
{
public MenuModal()
{
+ DataContext = this;
InitializeComponent();
}
@@ -26,6 +30,14 @@
public SqliteHelper sqliteHelper { get; set; }
private bool _isProcessing;
+
+ private ObservableCollection<MenuData> parentSource;
+
+ public ObservableCollection<MenuData> ParentSource
+ {
+ get { return parentSource; }
+ set { Set(ref parentSource, value); }
+ }
protected override void OnClosing(CancelEventArgs e)
{
@@ -52,7 +64,8 @@
}
catch (Exception ex)
{
- Panuon.WPF.UI.Toast.Show(this, "Error锛�", ToastPosition.Top);
+ MenuManage.PluginLog.Error("Modal Commit Error.", ex);
+ ToastHelper.Error(this, ex.Message);
e.Cancel = true;
return;
}
@@ -65,141 +78,84 @@
base.OnClosing(e);
}
- private bool ValidateForm()
+ public bool ValidateCode(object value, out string err)
{
- try
+ err = null;
+ string segment = string.IsNullOrEmpty(Data.Id) ? "" : $" AND id!='{Data.Id}'";
+ string sql = $"SELECT 1 FROM menu WHERE code='{TbCode.Text}'{segment};";
+ if (sqliteHelper.HasData(sql))
{
- FormValidateException ex = new FormValidateException();
- string segment = string.IsNullOrEmpty(Data.Id) ? "" : $" AND id!='{Data.Id}'";
- string sql = $"SELECT 1 FROM menu WHERE code='{TbCode.Text}'{segment};";
- if (string.IsNullOrEmpty(TbCode.Text))
- {
- ex.Result.Add(new FormGroupValidateResult("璇疯緭鍏ヨ彍鍗曠紪鍙�", FgCode));
- }
- else if (sqliteHelper.HasData(sql))
- {
- ex.Result.Add(new FormGroupValidateResult("鑿滃崟缂栧彿涓嶈兘閲嶅", FgCode));
- }
- else
- {
- FgCode.ValidateResult = ValidateResult.None;
- FgCode.Message = null;
- }
-
- if (string.IsNullOrEmpty(TbName.Text))
- {
- ex.Result.Add(new FormGroupValidateResult("璇疯緭鍏ヨ彍鍗曞悕绉�", FgName));
- }
- else
- {
- FgName.ValidateResult = ValidateResult.None;
- FgName.Message = null;
- }
-
- if(string.IsNullOrEmpty(TbIcon.Text))
- {
- ex.Result.Add(new FormGroupValidateResult("璇烽�夋嫨鑿滃崟鍥炬爣", FgIcon));
- }
- else
- {
- FgIcon.ValidateResult = ValidateResult.None;
- FgIcon.Message = null;
- }
-
- if (string.IsNullOrEmpty(TbLevel.Text))
- {
- ex.Result.Add(new FormGroupValidateResult("璇烽�夋嫨鑿滃崟绾у埆", FgLevel));
- }
- else
- {
- FgLevel.ValidateResult = ValidateResult.None;
- FgLevel.Message = null;
- }
-
- if (TbLevel.Text == "2")
- {
- if (string.IsNullOrEmpty(TbType.Text))
- {
- ex.Result.Add(new FormGroupValidateResult("璇烽�夋嫨鑿滃崟绫诲瀷", FgType));
- }
- else
- {
- FgType.ValidateResult = ValidateResult.None;
- FgType.Message = null;
- }
-
- if (string.IsNullOrEmpty(TbParentCode.Text))
- {
- ex.Result.Add(new FormGroupValidateResult("璇烽�夋嫨涓婄骇鑿滃崟", FgParentCode));
- }
- else
- {
- FgParentCode.ValidateResult = ValidateResult.None;
- FgParentCode.Message = null;
- }
-
- if (string.IsNullOrEmpty(TbDllPath.Text))
- {
- ex.Result.Add(new FormGroupValidateResult("璇烽�夋嫨Dll璺緞", FgDllPath));
- }
- else
- {
- FgDllPath.ValidateResult = ValidateResult.None;
- FgDllPath.Message = null;
- }
-
- if (string.IsNullOrEmpty(TbClassName.Text))
- {
- ex.Result.Add(new FormGroupValidateResult("璇疯緭鍏ョ被鍚�", FgClassName));
- }
- else
- {
- FgClassName.ValidateResult = ValidateResult.None;
- FgClassName.Message = null;
- }
-
- }
- else {
-
- }
-
- if (!ex.Success) {
- throw ex;
- }
- }
- catch (FormValidateException ex)
- {
- foreach (var data in ex.Result)
- {
- var fg = (FormGroup)data.Sender;
- fg.ValidateResult = ValidateResult.Error;
- fg.Message = data.Message;
- }
+ err = this.lang("App.MustBeUnique", LangUtil.Get("HMI.Menu.Code")); ;
return false;
}
-
- Data.Code = TbCode.Text;
- Data.Name = TbName.Text;
- Data.IconPath = TbIcon.Text;
- Data.Level = TbLevel.Text;
- Data.Type = TbType.Text;
- Data.ParentCode = TbParentCode.Text;
- Data.DllPath = TbDllPath.Text;
- Data.ClassName = TbClassName.Text;
return true;
+ }
+
+ public bool ValidateName(object value, out string err)
+ {
+ err = null;
+ string segment = string.IsNullOrEmpty(Data.Id) ? "" : $" AND id!='{Data.Id}'";
+ string sql = $"SELECT 1 FROM menu WHERE name='{TbName.Text}'{segment};";
+ if (sqliteHelper.HasData(sql))
+ {
+ err = string.Format(LangUtil.Get("App.MustBeUnique"), LangUtil.Get("HMI.Menu.Name"));
+ return false;
+ }
+ return true;
+ }
+
+ private bool ValidateForm()
+ {
+ //PreValidate();
+ bool flag = FormGroupHelper.ValidateForm(formPanel);
+ if (flag)
+ {
+ Data.Code = TbCode.Text;
+ Data.Name = TbName.Text;
+ Data.Icon = TbIcon.Text;
+ Data.Level = TbLevel.Text;
+ Data.Type = TbType.Text;
+ Data.ParentCode = TbParentCode.SelectedValue?.ToString();
+ Data.DllPath = TbDllPath.Text;
+ Data.ClassName = TbClassName.Text;
+ Data.Sort = NiSort.Value;
+ }
+ return flag;
+ }
+
+ private void RefreshParentCode()
+ {
+ ObservableCollection<MenuData> datas = new ObservableCollection<MenuData>();
+ string sql = $"SELECT code,name FROM menu WHERE level = 1 ORDER By id;";
+ DataTable dt = sqliteHelper.GetDataTable(sql);
+ if (dt != null)
+ {
+ foreach (DataRow dr in dt.Rows)
+ {
+ var menu = new MenuData
+ {
+ Code = dr["code"].ToString(),
+ Name = dr["name"].ToString(),
+ };
+ datas.Add(menu);
+ }
+ }
+ ParentSource = datas;
}
public bool? Open(MenuData data)
{
+ RefreshParentCode();
Data = data;
TbCode.Text = Data.Code;
TbName.Text = Data.Name;
- TbIcon.Text = Data.IconPath;
+ TbIcon.Text = Data.Icon;
TbLevel.SelectedValue = Data.Level;
TbType.SelectedValue = Data.Type;
- TbParentCode.Text = Data.ParentCode;
+ TbParentCode.SelectedValue = Data.ParentCode;
TbDllPath.Text = Data.DllPath;
TbClassName.Text = Data.ClassName;
+ NiSort.Value = Data.Sort;
return this.ShowDialog();
}
@@ -217,45 +173,53 @@
public void InsertMenu(MenuData data)
{
- string sql = $@"INSERT INTO menu (code,name,iconPath,level,type,parentCode,dllPath,className)
+ string sql = $@"INSERT INTO menu (code,name,icon,level,type,parentCode,dllPath,className,sort)
VALUES
- ('{data.Code}','{data.Name}','{data.IconPath}','{data.Level}','{data.Type}','{data.ParentCode}',
- '{data.DllPath}','{data.ClassName}');";
+ ('{data.Code}','{data.Name}','{data.Icon}','{data.Level}','{data.Type}','{data.ParentCode}',
+ '{data.DllPath}','{data.ClassName}',{data.Sort});";
sqliteHelper.ExecuteSql(sql);
}
public void UpdateMenu(MenuData data)
{
string sql = $@"UPDATE menu SET code='{data.Code}',name='{data.Name}',
-iconPath='{data.IconPath}',level='{data.Level}',type='{data.Type}',parentCode='{data.ParentCode}',
-dllPath='{data.DllPath}',className='{data.ClassName}' WHERE id='{data.Id}';";
+icon='{data.Icon}',level='{data.Level}',type='{data.Type}',parentCode='{data.ParentCode}',
+dllPath='{data.DllPath}',className='{data.ClassName}',sort={data.Sort} WHERE id='{data.Id}';";
sqliteHelper.ExecuteSql(sql);
}
private void IconSelect_Click(object sender, RoutedEventArgs e)
{
- string BasePath = PathHelper.IconFolder;
+ //string BasePath = PathHelper.IconFolder;
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "(*.*)|*.*";
- openFileDialog.InitialDirectory = BasePath;
- openFileDialog.Title = "閫夋嫨鍥剧墖";
- openFileDialog.Multiselect = false;
+ //OpenFileDialog openFileDialog = new OpenFileDialog();
+ //openFileDialog.Filter = "(*.*)|*.*";
+ //openFileDialog.InitialDirectory = BasePath;
+ //openFileDialog.Title = "閫夋嫨鍥剧墖";
+ //openFileDialog.Multiselect = false;
- if (openFileDialog.ShowDialog() == true)
+ //if (openFileDialog.ShowDialog() == true)
+ //{
+ // string FileName = openFileDialog.FileName;
+ // if (!FileName.StartsWith(BasePath))
+ // {
+ // (this, "璇峰皢鍥炬爣绉诲姩鑷崇▼搴廔con鐩綍涓嬶紒", ToastPosition.Top);
+ // }
+ // else
+ // {
+ // TbIcon.Text = FileName.Replace(BasePath, ".");
+ // }
+ //}
+ IconSelector selector = new IconSelector
{
- string FileName = openFileDialog.FileName;
- if (!FileName.StartsWith(BasePath))
- {
- Panuon.WPF.UI.Toast.Show(this, "璇峰皢鍥炬爣绉诲姩鑷崇▼搴廔con鐩綍涓嬶紒", ToastPosition.Top);
- }
- else
- {
- TbIcon.Text = FileName.Replace(BasePath, ".");
- }
+ Title = LangUtil.Get("App.SelectIcon"),
+ Owner = this
+ };
+ if (selector.Open(Data.Icon) == true)
+ {
+ TbIcon.Text = selector.Data;
}
-
}
private void DllSelect_Click(object sender, RoutedEventArgs e)
@@ -265,7 +229,7 @@
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "(*.dll)|*.dll";
openFileDialog.InitialDirectory = pluginPath;
- openFileDialog.Title = "閫夋嫨鏂囦欢";
+ openFileDialog.Title = LangUtil.Get("App.SelectFile");
openFileDialog.Multiselect = false;
if (openFileDialog.ShowDialog() == true)
@@ -273,7 +237,7 @@
string FileName = openFileDialog.FileName;
if (!FileName.StartsWith(pluginPath))
{
- Panuon.WPF.UI.Toast.Show(this, "璇峰皢鎻掍欢绉诲姩鑷崇▼搴廝lugin鐩綍涓嬶紒", ToastPosition.Top);
+ ToastHelper.Warning(this, LangUtil.Get("App.Msg.PluginMustInPluginFolder"));
}
else
{
@@ -294,5 +258,14 @@
}
}
}
+
+ private void TbLevel_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ bool flag = (((ComboBoxItem)e.AddedItems[0])?.Content?.ToString() == "2");
+ FormGroupHelper.SetIsRequired(FgType, flag);
+ FormGroupHelper.SetIsRequired(FgParentCode, flag);
+ FormGroupHelper.SetIsRequired(FgDllPath, flag);
+ FormGroupHelper.SetIsRequired(FgClassName, flag);
+ }
}
}
--
Gitblit v1.9.1