From 99df058a665ea04065a23e729ec79a2f23f79881 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期二, 20 五月 2025 16:59:43 +0800
Subject: [PATCH] 优化
---
HMI.ParameterManage/ProductModal.xaml.cs | 111 +++++++++++--------------------------------------------
1 files changed, 23 insertions(+), 88 deletions(-)
diff --git a/HMI.ParameterManage/ProductModal.xaml.cs b/HMI.ParameterManage/ProductModal.xaml.cs
index d67793d..bececf3 100644
--- a/HMI.ParameterManage/ProductModal.xaml.cs
+++ b/HMI.ParameterManage/ProductModal.xaml.cs
@@ -1,18 +1,10 @@
-锘縰sing System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.ComponentModel;
-using System.Linq;
-using System.Reflection;
-using System.Windows;
-using Microsoft.Win32;
+锘縰sing HMI.Core.Entity;
+using HMI.ParameterManage.Model;
+using HMI.UI.DpUtil;
+using HMI.UI.Util;
using Panuon.WPF.UI;
-using HMI.Core.Annotation;
-using HMI.Core.Entity;
-using HMI.Core.Exceptions;
-using HMI.Core.Util;
-using HMI.ParameterManage.Entity;
-using HMI.UI;
+using System;
+using System.ComponentModel;
namespace HMI.ParameterManage
{
@@ -21,15 +13,17 @@
/// </summary>
public partial class ProductModal : WindowX
{
- public ProductModal()
+
+ private XmlModel DataModel;
+
+ public ProductModal(XmlModel dataModel)
{
+ DataModel = dataModel;
this.DataContext = this;
InitializeComponent();
}
public ProductData Data { get; set; }
-
- public SqliteHelper sqliteHelper { get; set; }
private bool _isProcessing;
@@ -54,11 +48,11 @@
return;
}
- SaveOrUpdateData();
+ DataModel.SaveOrUpdateData(Data);
}
catch (Exception ex)
{
- Panuon.WPF.UI.Toast.Show(this, "Error锛�", ToastPosition.Top);
+ ToastHelper.Error(this, $"Error: {ex.Message}");
e.Cancel = true;
return;
}
@@ -71,50 +65,20 @@
base.OnClosing(e);
}
+ private bool ValidateName(object value, out string msg)
+ {
+ return DataModel.ValidateProductName(value, out msg);
+ }
+
private bool ValidateForm()
{
- try
+ bool flag = FormGroupHelper.ValidateForm(formPanel);
+ if (flag)
{
-
- //
-
- FormValidateException ex = new FormValidateException();
- string segment = string.IsNullOrEmpty(Data.Id) ? "" : $" AND id!='{Data.Id}'";
- string sql = $"SELECT 1 FROM product WHERE name='{TbName.Text}'{segment};";
- if (string.IsNullOrEmpty(TbName.Text))
- {
- ex.Result.Add(new FormGroupValidateResult("璇疯緭鍏ヤ骇鍝佸悕绉�", FgName));
- }
- else if (sqliteHelper.HasData(sql))
- {
- ex.Result.Add(new FormGroupValidateResult("浜у搧鍚嶇О涓嶈兘閲嶅", FgName));
- }
- else
- {
- FgName.ValidateResult = ValidateResult.None;
- FgName.Message = null;
- }
-
- if (!ex.Success)
- {
- throw ex;
- }
+ Data.Name = TbName.Text;
+ Data.IsMaster = TbIsMaster.IsChecked == true;
}
- catch (FormValidateException ex)
- {
- foreach (var data in ex.Result)
- {
- var fg = (FormGroup)data.Sender;
- fg.ValidateResult = ValidateResult.Error;
- fg.Message = data.Message;
- }
- return false;
- }
-
- Data.Name = TbName.Text;
- Data.IsMaster = TbIsMaster.IsChecked == true;
- Data.ParentId = TbParentId.Text;
- return true;
+ return flag;
}
public bool? Open(ProductData data)
@@ -125,35 +89,6 @@
TbParentId.Text = Data.ParentId;
return this.ShowDialog();
- }
-
- private void SaveOrUpdateData()
- {
- if (string.IsNullOrEmpty(Data.Id))
- {
- InsertData(Data);
- }
- else
- {
- UpdateData(Data);
- }
- }
-
- public void InsertData(ProductData data)
- {
- string sql = $@"INSERT INTO product (name,isMaster,parentId)
- VALUES
- ('{data.Name}',{(data.IsMaster ? 1 : 0)} ,{data.ParentId} );";
- sqliteHelper.ExecuteSql(sql);
- }
-
-
-
- public void UpdateData(ProductData data)
- {
- string sql = $@"UPDATE product SET name='{data.Name}',isMaster='{(data.IsMaster ? 1 : 0)}',parentId = {data.ParentId}
-WHERE id='{data.Id}';";
- sqliteHelper.ExecuteSql(sql);
}
}
}
--
Gitblit v1.9.1