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/UserModal.xaml.cs |  153 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 153 insertions(+), 0 deletions(-)

diff --git a/HMI.MenuManage/Modal/UserModal.xaml.cs b/HMI.MenuManage/Modal/UserModal.xaml.cs
new file mode 100644
index 0000000..c48ff24
--- /dev/null
+++ b/HMI.MenuManage/Modal/UserModal.xaml.cs
@@ -0,0 +1,153 @@
+锘縰sing HMI.Core.Util;
+using HMI.MenuManage.Entity;
+using HMI.MenuManage.Util;
+using HMI.UI.DpUtil;
+using HMI.UI.Util;
+using Panuon.WPF.UI;
+using System;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+
+namespace HMI.MenuManage
+{
+    /// <summary>
+    /// ModalWindow.xaml 鐨勪氦浜掗�昏緫
+    /// </summary>
+    public partial class UserModal : WindowX
+    {
+        public UserModal()
+        {
+            this.DataContext = this;
+            InitializeComponent();
+        }
+
+        public UserData Data { get; set; }
+        private ObservableCollection<UserRoleRel> _Roles;
+        public ObservableCollection<UserRoleRel> Roles
+        {
+            get => _Roles;
+            set { Set(ref _Roles, value); }
+        }
+        public SqliteHelper sqliteHelper { get; set; }
+
+        private bool _isProcessing;
+
+        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)
+                {
+                    ToastHelper.Error(this, $"Error锛亄ex.Message}");
+                    e.Cancel = true;
+                    return;
+                }
+                finally
+                {
+                    _isProcessing = false;
+                    ButtonHelper.SetIsPending(okButton, false);
+                }
+            }
+            base.OnClosing(e);
+        }
+
+        private bool ValidateUsername(object value, out string err)
+        {
+            err = null;
+            string segment = string.IsNullOrEmpty(Data.Id) ? "" : $" AND id!='{Data.Id}'";
+            string sql = $"SELECT 1 FROM user WHERE username='{TbUsername.Text}'{segment};";
+            if (sqliteHelper.HasData(sql))
+            {
+                err = string.Format(LangUtil.Get("App.MustBeUnique"), LangUtil.Get("HMI.User.Account"));
+                return false;
+            }
+            return true;
+        }
+
+        private bool ValidateCode(object value, out string err)
+        {
+            err = null;
+            string segment = string.IsNullOrEmpty(Data.Id) ? "" : $" AND id!='{Data.Id}'";
+            string sql = $"SELECT 1 FROM user WHERE code='{TbCode.Text}'{segment};";
+            if (sqliteHelper.HasData(sql))
+            {
+                err = string.Format(LangUtil.Get("App.MustBeUnique"), LangUtil.Get("HMI.User.Code"));
+                return false;
+            }
+            return true;
+        }
+
+        private bool ValidateForm()
+        {
+            bool flag = FormGroupHelper.ValidateForm(formPanel);
+            if (flag)
+            {
+                Data.Code = TbCode.Text;
+                Data.Username = TbUsername.Text;
+                Data.Name = TbName.Text;
+                Data.Password = TbPassword.Password;
+            }
+
+            return flag;
+        }
+
+        public bool? Open(UserData data)
+        {
+            Data = data;
+            TbCode.Text = Data.Code;
+            TbUsername.Text = Data.Username;
+            TbName.Text = Data.Name;
+            TbPassword.Password = Data.Password;
+
+            Roles = UserRoleRelHelper.SelectUserRoleData(sqliteHelper, Data.Username);
+
+            return this.ShowDialog();
+        }
+
+        private void SaveOrUpdateData()
+        {
+            if (string.IsNullOrEmpty(Data.Id))
+            {
+                InsertData(Data);
+            }
+            else
+            {
+                UpdateData(Data);
+            }
+        }
+
+        public void InsertData(UserData data)
+        {
+            string sql = $@"INSERT INTO user (code, username,password,name) 
+                VALUES
+                ('{data.Code}', '{data.Username}','{data.Password}','{data.Name}');";
+            UserRoleRelHelper.SaveUserRoleRel(sqliteHelper, Roles, data, sql, null);
+        }
+
+        public void UpdateData(UserData data)
+        {
+            string sql = $@"UPDATE user SET code='{data.Code}', username='{data.Username}',password='{data.Password}',name='{data.Name}' 
+WHERE id='{data.Id}';";
+            UserRoleRelHelper.SaveUserRoleRel(sqliteHelper, Roles, data, sql, null);
+        }
+    }
+}

--
Gitblit v1.9.1