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 作为历史根节点
---
Plugin.DeviceConfig/VersionManageModal.xaml.cs | 207 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 207 insertions(+), 0 deletions(-)
diff --git a/Plugin.DeviceConfig/VersionManageModal.xaml.cs b/Plugin.DeviceConfig/VersionManageModal.xaml.cs
new file mode 100644
index 0000000..ea2c2fd
--- /dev/null
+++ b/Plugin.DeviceConfig/VersionManageModal.xaml.cs
@@ -0,0 +1,207 @@
+using HMI.UI.Util;
+using Panuon.WPF.UI;
+using Plugin.DeviceConfig.Entity;
+using Plugin.DeviceConfig.Model;
+using System;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Windows;
+
+namespace Plugin.DeviceConfig
+{
+ /// <summary>
+ /// VersionManageModal.xaml 鐨勪氦浜掗�昏緫
+ /// </summary>
+ public partial class VersionManageModal : WindowX
+ {
+ private DeviceConfigModel _model;
+ private ObservableCollection<VersionDisplayItem> _versions = new();
+ private bool _changed;
+
+ public VersionManageModal()
+ {
+ DataContext = this;
+ InitializeComponent();
+ }
+
+ /// <summary>
+ /// 鎵撳紑寮圭獥
+ /// </summary>
+ public bool? Open(DeviceConfigModel model)
+ {
+ _model = model;
+ versionListView.ItemsSource = _versions;
+ LoadVersions();
+ return ShowDialog();
+ }
+
+ private void LoadVersions()
+ {
+ try
+ {
+ var list = _model.GetConfigVersions();
+ _versions.Clear();
+ foreach (var v in list)
+ {
+ _versions.Add(new VersionDisplayItem
+ {
+ VersionId = v.VersionId,
+ Status = v.Status,
+ Hash = v.Hash,
+ HashShort = v.Hash.Length > 16 ? v.Hash.Substring(0, 16) + "..." : v.Hash,
+ Author = v.Author,
+ Timestamp = v.Timestamp,
+ DiffDescription = v.DiffDescription,
+ });
+ }
+ }
+ catch (Exception ex)
+ {
+ ToastHelper.Error($"鍔犺浇鐗堟湰鍒楄〃澶辫触: {ex.Message}");
+ }
+ }
+
+ #region 鎿嶄綔
+
+ private void PublishBtn_Click(object sender, RoutedEventArgs e)
+ {
+ try
+ {
+ var selected = versionListView.SelectedItem as VersionDisplayItem;
+ if (selected == null)
+ {
+ ToastHelper.Warning("璇峰厛閫変腑涓�涓増鏈�");
+ return;
+ }
+ if (selected.Status != VersionStatus.Draft)
+ {
+ ToastHelper.Warning("鍙湁 Draft 鐘舵�佺殑鐗堟湰鍙互鍙戝竷");
+ return;
+ }
+
+ if (MsgBoxHelper.WarnMessage(this, $"纭畾瑕佸彂甯冪増鏈� [{selected.VersionId}] 鍚楋紵") != MessageBoxResult.OK)
+ return;
+
+ // 璁$畻鏈�鏂� Hash
+ var hash = _model.ComputeConfigHash();
+ selected.Hash = hash;
+ selected.HashShort = hash.Length > 16 ? hash.Substring(0, 16) + "..." : hash;
+ selected.Status = VersionStatus.Published;
+ selected.Timestamp = DateTime.Now;
+
+ var ver = new DeviceConfigVersion
+ {
+ VersionId = selected.VersionId,
+ Status = VersionStatus.Published,
+ Hash = hash,
+ Author = selected.Author,
+ Timestamp = DateTime.Now,
+ DiffDescription = selected.DiffDescription,
+ };
+ _model.SaveConfigVersion(ver);
+
+ _changed = true;
+ LoadVersions();
+ ToastHelper.Success($"鐗堟湰 [{selected.VersionId}] 宸插彂甯�");
+ }
+ catch (Exception ex)
+ {
+ ToastHelper.Error($"鍙戝竷澶辫触: {ex.Message}");
+ }
+ }
+
+ private void ApplyBtn_Click(object sender, RoutedEventArgs e)
+ {
+ try
+ {
+ var selected = versionListView.SelectedItem as VersionDisplayItem;
+ if (selected == null)
+ {
+ ToastHelper.Warning("璇峰厛閫変腑涓�涓増鏈�");
+ return;
+ }
+ if (selected.Status != VersionStatus.Published)
+ {
+ ToastHelper.Warning("鍙湁 Published 鐘舵�佺殑鐗堟湰鍙互搴旂敤");
+ return;
+ }
+
+ // 妫�鏌ュ綋鍓� Effective 鐗堟湰
+ var currentEffective = _versions.FirstOrDefault(v => v.Status == VersionStatus.Effective);
+ if (currentEffective != null)
+ {
+ if (MsgBoxHelper.WarnMessage(this,
+ $"褰撳墠宸叉湁鐢熸晥鐗堟湰 [{currentEffective.VersionId}]锛屽簲鐢ㄦ柊鐗堟湰灏嗘浛鎹㈠畠銆俓n鏄惁缁х画锛�") != MessageBoxResult.OK)
+ {
+ return;
+ }
+
+ // 灏嗗師 Effective 鏀瑰洖 Published
+ _model.UpdateVersionStatus(currentEffective.VersionId, VersionStatus.Published.ToString());
+ }
+
+ if (MsgBoxHelper.WarnMessage(this, $"纭畾瑕佸皢 [{selected.VersionId}] 璁句负鐢熸晥鐗堟湰鍚楋紵") != MessageBoxResult.OK)
+ return;
+
+ _model.UpdateVersionStatus(selected.VersionId, VersionStatus.Effective.ToString());
+ _changed = true;
+ LoadVersions();
+ ToastHelper.Success($"鐗堟湰 [{selected.VersionId}] 宸茶涓虹敓鏁堢増鏈�");
+ }
+ catch (Exception ex)
+ {
+ ToastHelper.Error($"搴旂敤鐗堟湰澶辫触: {ex.Message}");
+ }
+ }
+
+ private void DetailBtn_Click(object sender, RoutedEventArgs e)
+ {
+ try
+ {
+ var selected = versionListView.SelectedItem as VersionDisplayItem;
+ if (selected == null)
+ {
+ ToastHelper.Warning("璇峰厛閫変腑涓�涓増鏈�");
+ return;
+ }
+
+ tbDetailHash.Text = selected.Hash;
+ tbDetailDiff.Text = selected.DiffDescription;
+ tbDetailAuthor.Text = $"{selected.Author} @ {selected.Timestamp:yyyy-MM-dd HH:mm:ss}";
+ detailPanel.Visibility = Visibility.Visible;
+ }
+ catch (Exception ex)
+ {
+ ToastHelper.Error($"鍔犺浇璇︽儏澶辫触: {ex.Message}");
+ }
+ }
+
+ private void RfhBtn_Click(object sender, RoutedEventArgs e)
+ {
+ LoadVersions();
+ ToastHelper.Success("宸插埛鏂�");
+ }
+
+ private void CloseBtn_Click(object sender, RoutedEventArgs e)
+ {
+ DialogResult = _changed;
+ Close();
+ }
+
+ #endregion
+ }
+
+ /// <summary>
+ /// 鐗堟湰鏄剧ず椤�
+ /// </summary>
+ public class VersionDisplayItem
+ {
+ public string VersionId { get; set; } = string.Empty;
+ public VersionStatus Status { get; set; }
+ public string Hash { get; set; } = string.Empty;
+ public string HashShort { get; set; } = string.Empty;
+ public string Author { get; set; } = string.Empty;
+ public DateTime Timestamp { get; set; }
+ public string DiffDescription { get; set; } = string.Empty;
+ }
+}
--
Gitblit v1.9.1