From 9d1660270272180cd71147d6ddd53d1382643d2e Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 02 十一月 2026 18:00:14 +0800
Subject: [PATCH] merge: 并入远程 Initial commit 作为历史根节点

---
 HMI.MenuManage/Modal/MenuModal.xaml.cs |  271 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 271 insertions(+), 0 deletions(-)

diff --git a/HMI.MenuManage/Modal/MenuModal.xaml.cs b/HMI.MenuManage/Modal/MenuModal.xaml.cs
new file mode 100644
index 0000000..35d2ffb
--- /dev/null
+++ b/HMI.MenuManage/Modal/MenuModal.xaml.cs
@@ -0,0 +1,271 @@
+锘縰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
+{
+    /// <summary>
+    /// ModalWindow.xaml 鐨勪氦浜掗�昏緫
+    /// </summary>
+    public partial class MenuModal : WindowX
+    {
+        public MenuModal()
+        {
+            DataContext = this;
+            InitializeComponent();
+        }
+
+        public MenuData Data { get; set; }
+        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)
+        {
+            //Press Continue Button
+            if (DialogResult == true)
+            {
+                if (_isProcessing)
+                {
+                    e.Cancel = true;
+                    return;
+                }
+                var okButton = WindowXModalDialog.GetOKButton(this);
+                try
+                {
+                    _isProcessing = true;
+                    ButtonHelper.SetIsPending(okButton, true);
+                    if (!ValidateForm())
+                    {
+                        e.Cancel = true;
+                        return;
+                    }
+
+                    SaveOrUpdateData();
+                }
+                catch (Exception ex)
+                {
+                    MenuManage.PluginLog.Error("Modal Commit Error.", ex);
+                    ToastHelper.Error(this, ex.Message);
+                    e.Cancel = true;
+                    return;
+                }
+                finally
+                {
+                    _isProcessing = false;
+                    ButtonHelper.SetIsPending(okButton, false);
+                }
+            }
+            base.OnClosing(e);
+        }
+
+        public bool ValidateCode(object value, out string err)
+        {
+            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))
+            {
+                err = this.lang("App.MustBeUnique", LangUtil.Get("HMI.Menu.Code")); ;
+                return false;
+            }
+            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.Icon;
+            TbLevel.SelectedValue = Data.Level;
+            TbType.SelectedValue = Data.Type;
+            TbParentCode.SelectedValue = Data.ParentCode;
+            TbDllPath.Text = Data.DllPath;
+            TbClassName.Text = Data.ClassName;
+            NiSort.Value = Data.Sort;
+            return this.ShowDialog();
+        }
+
+        private void SaveOrUpdateData()
+        {
+            if (string.IsNullOrEmpty(Data.Id))
+            {
+                InsertMenu(Data);
+            }
+            else
+            {
+                UpdateMenu(Data);
+            }
+        }
+
+        public void InsertMenu(MenuData data)
+        {
+            string sql = $@"INSERT INTO menu (code,name,icon,level,type,parentCode,dllPath,className,sort) 
+                VALUES
+                ('{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}',
+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;
+
+            //OpenFileDialog openFileDialog = new OpenFileDialog();
+            //openFileDialog.Filter = "(*.*)|*.*";
+            //openFileDialog.InitialDirectory = BasePath;
+            //openFileDialog.Title = "閫夋嫨鍥剧墖";
+            //openFileDialog.Multiselect = false;
+
+            //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
+            {
+                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)
+        {
+            string pluginPath = PathHelper.PluginFolder();
+
+            OpenFileDialog openFileDialog = new OpenFileDialog();
+            openFileDialog.Filter = "(*.dll)|*.dll";
+            openFileDialog.InitialDirectory = pluginPath;
+            openFileDialog.Title = LangUtil.Get("App.SelectFile");
+            openFileDialog.Multiselect = false;
+
+            if (openFileDialog.ShowDialog() == true)
+            {
+                string FileName = openFileDialog.FileName;
+                if (!FileName.StartsWith(pluginPath))
+                {
+                    ToastHelper.Warning(this, LangUtil.Get("App.Msg.PluginMustInPluginFolder"));
+                }
+                else
+                {
+                    TbDllPath.Text = FileName.Replace(pluginPath, ".");
+                    try
+                    {
+                        object[] infos = Assembly.LoadFrom(FileName).GetCustomAttributes(typeof(PluginClassNameAttribute), false);
+                        if (infos != null && infos.Length > 0)
+                        {
+                            PluginClassNameAttribute attr = (PluginClassNameAttribute)infos[0];
+                            TbClassName.Text = attr.ClassName;
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+
+                    }
+                }
+            }
+        }
+
+        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