alielie
2025-11-24 9211ec11c112e18cd99e77f889a01110a70031ce
HMI.MenuManage/Modal/RoleModal.xaml.cs
@@ -1,17 +1,12 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
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;
using HMI.Core.Util;
using 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
{
@@ -65,7 +60,7 @@
                }
                catch (Exception ex)
                {
                    Panuon.WPF.UI.Toast.Show(this, "Error!", ToastPosition.Top);
                    ToastHelper.Error(this, $"Error!{ex.Message}");
                    e.Cancel = true;
                    return;
                }
@@ -78,58 +73,30 @@
            base.OnClosing(e);
        }
        private bool ValidateForm()
        private 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 user WHERE username='{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 user WHERE username='{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 (!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.MustUnique", this.lang("HMI.Role.Code"));
                return false;
            }
            Data.Code = TbCode.Text;
            Data.Name = TbName.Text;
            return true;
        }
        private bool ValidateForm()
        {
            bool flag = FormGroupHelper.ValidateForm(formPanel);
            if (flag)
            {
                Data.Code = TbCode.Text;
                Data.Name = TbName.Text;
            }
            return flag;
        }
        public bool? Open(RoleData data)
        {
            Data = data;