Skip to content

Commit 3cfd38c

Browse files
committed
Dialog Style
1 parent 5bba11e commit 3cfd38c

6 files changed

Lines changed: 185 additions & 14 deletions

File tree

src/Tender.Desktop/App.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ private static void ConfigureServices(IServiceCollection services)
9494
services.AddSingleton<IEsgXlsmExporter, EsgTemplateXlsmExporter>();
9595
services.AddSingleton<ISaveFileDialogService, WpfSaveFileDialogService>();
9696
services.AddSingleton<IErrorSummaryDialog, WpfErrorSummaryDialog>();
97+
services.AddSingleton<IMigrateDataRootDialog, WpfMigrateDataRootDialog>();
9798
services.AddSingleton<IUpdateChecker, GitHubUpdateChecker>();
9899
services.AddSingleton<IDataCleanupService, DataCleanupService>();
99100
services.AddSingleton<INotificationService, NotificationService>();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Tender.Desktop.Services;
2+
3+
public enum MigrateChoice
4+
{
5+
Cancel,
6+
Keep,
7+
Migrate,
8+
}
9+
10+
public interface IMigrateDataRootDialog
11+
{
12+
/// <summary>顯示資料搬移確認對話框,回傳使用者選擇。</summary>
13+
MigrateChoice Ask(string oldRoot, string newRoot);
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Windows;
2+
using Tender.Desktop.Views;
3+
4+
namespace Tender.Desktop.Services;
5+
6+
public sealed class WpfMigrateDataRootDialog : IMigrateDataRootDialog
7+
{
8+
public MigrateChoice Ask(string oldRoot, string newRoot)
9+
{
10+
var dlg = new MigrateDataRootDialog
11+
{
12+
Owner = Application.Current?.Windows.OfType<Window>().FirstOrDefault(w => w.IsActive)
13+
?? Application.Current?.MainWindow,
14+
};
15+
dlg.Initialize(oldRoot, newRoot);
16+
dlg.ShowDialog();
17+
return dlg.Result;
18+
}
19+
}

src/Tender.Desktop/ViewModels/AppSettingsViewModel.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections.ObjectModel;
22
using System.IO;
3-
using System.Windows;
43
using CommunityToolkit.Mvvm.ComponentModel;
54
using CommunityToolkit.Mvvm.Input;
65
using Tender.Core.Constants;
@@ -16,6 +15,7 @@ public partial class AppSettingsViewModel : ObservableObject
1615
private readonly IAppSettingsRepository _repo;
1716
private readonly IScheduledTaskInstaller _taskInstaller;
1817
private readonly IDataPaths _paths;
18+
private readonly IMigrateDataRootDialog _migrateDialog;
1919

2020
[ObservableProperty]
2121
private string _scheduledTime = "17:00";
@@ -54,11 +54,13 @@ public partial class AppSettingsViewModel : ObservableObject
5454
public AppSettingsViewModel(
5555
IAppSettingsRepository repo,
5656
IScheduledTaskInstaller taskInstaller,
57-
IDataPaths paths)
57+
IDataPaths paths,
58+
IMigrateDataRootDialog migrateDialog)
5859
{
5960
_repo = repo;
6061
_taskInstaller = taskInstaller;
6162
_paths = paths;
63+
_migrateDialog = migrateDialog;
6264
// 列出所有支援的招標方式(從 TenderMethodMapping 取出名稱)
6365
foreach (var name in TenderMethodMapping.BusinessNameToOptionValue.Keys)
6466
{
@@ -173,13 +175,13 @@ private async Task SaveAsync(CancellationToken ct)
173175

174176
if (rootChanged)
175177
{
176-
var migrate = AskMigrate(_initialDataRoot, newRoot);
177-
if (migrate == MessageBoxResult.Cancel)
178+
var choice = AskMigrate(_initialDataRoot, newRoot);
179+
if (choice == MigrateChoice.Cancel)
178180
{
179181
StatusMessage = "已取消變更資料儲存位置";
180182
return;
181183
}
182-
if (migrate == MessageBoxResult.Yes)
184+
if (choice == MigrateChoice.Migrate)
183185
{
184186
try
185187
{
@@ -213,19 +215,15 @@ private async Task SaveAsync(CancellationToken ct)
213215

214216
/// <summary>
215217
/// 詢問是否搬移舊 DataRoot 內容到新位置。
216-
/// 舊位置不存在或空目錄時,直接回 No(不需搬移)。
218+
/// 舊位置不存在或空目錄時,直接回 Keep(不需搬移、也不需詢問)。
217219
/// </summary>
218-
private static MessageBoxResult AskMigrate(string oldRoot, string newRoot)
220+
private MigrateChoice AskMigrate(string oldRoot, string newRoot)
219221
{
220-
if (!Directory.Exists(oldRoot)) return MessageBoxResult.No;
222+
if (!Directory.Exists(oldRoot)) return MigrateChoice.Keep;
221223
var hasContent = Directory.EnumerateFileSystemEntries(oldRoot).Any();
222-
if (!hasContent) return MessageBoxResult.No;
224+
if (!hasContent) return MigrateChoice.Keep;
223225

224-
return MessageBox.Show(
225-
$"資料儲存位置將變更為:\n{newRoot}\n\n是否將現有資料從舊位置搬移過去?\n\n舊位置:{oldRoot}\n\n是 = 複製後刪除舊位置\n否 = 保留舊資料,新位置從零開始\n取消 = 不變更位置",
226-
"資料搬移",
227-
MessageBoxButton.YesNoCancel,
228-
MessageBoxImage.Question);
226+
return _migrateDialog.Ask(oldRoot, newRoot);
229227
}
230228

231229
private static bool IsNestedPath(string a, string b)
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<Window x:Class="Tender.Desktop.Views.MigrateDataRootDialog"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
Title="資料搬移"
5+
Height="360" Width="560"
6+
WindowStartupLocation="CenterOwner"
7+
ShowInTaskbar="False"
8+
ResizeMode="NoResize"
9+
Background="{StaticResource BgMainBrush}"
10+
FontFamily="Microsoft JhengHei UI">
11+
<DockPanel>
12+
<Border DockPanel.Dock="Top" Padding="18,14"
13+
Background="{StaticResource BgCardBrush}"
14+
BorderBrush="{StaticResource BorderBrush}"
15+
BorderThickness="0,0,0,1">
16+
<DockPanel>
17+
<Border Width="3" Background="{StaticResource PrimaryBrush}" CornerRadius="1.5" Margin="0,2,10,2" />
18+
<TextBlock Text="變更資料儲存位置"
19+
Style="{StaticResource HeaderTextStyle}"
20+
FontSize="16" VerticalAlignment="Center" />
21+
</DockPanel>
22+
</Border>
23+
24+
<Border DockPanel.Dock="Bottom" Padding="14"
25+
Background="{StaticResource BgCardBrush}"
26+
BorderBrush="{StaticResource BorderBrush}"
27+
BorderThickness="0,1,0,0">
28+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
29+
<Button Content="取消" Padding="22,5" Margin="0,0,8,0"
30+
IsCancel="True" Click="Cancel_Click" />
31+
<Button Content="保留舊資料" Padding="14,5" Margin="0,0,8,0"
32+
Click="Keep_Click" />
33+
<Button Content="搬移到新位置" Padding="14,5"
34+
IsDefault="True" Click="Migrate_Click"
35+
Style="{StaticResource PrimaryButtonStyle}" />
36+
</StackPanel>
37+
</Border>
38+
39+
<StackPanel Margin="20,18,20,18">
40+
<TextBlock TextWrapping="Wrap"
41+
Foreground="{StaticResource TextPrimaryBrush}"
42+
FontSize="13" Margin="0,0,0,14">
43+
即將變更資料儲存位置。請選擇如何處理舊位置下的現有資料:
44+
</TextBlock>
45+
46+
<Border Background="{StaticResource BgCardBrush}"
47+
BorderBrush="{StaticResource BorderBrush}"
48+
BorderThickness="1" CornerRadius="5"
49+
Padding="12,10" Margin="0,0,0,8">
50+
<Grid>
51+
<Grid.ColumnDefinitions>
52+
<ColumnDefinition Width="64" />
53+
<ColumnDefinition Width="*" />
54+
</Grid.ColumnDefinitions>
55+
<TextBlock Grid.Column="0" Text="舊位置"
56+
Foreground="{StaticResource TextSecondaryBrush}"
57+
FontSize="12" VerticalAlignment="Top" Margin="0,2,8,0" />
58+
<TextBlock x:Name="OldRootText" Grid.Column="1"
59+
Foreground="{StaticResource TextPrimaryBrush}"
60+
FontSize="12" TextWrapping="Wrap" />
61+
</Grid>
62+
</Border>
63+
64+
<Border Background="{StaticResource PrimaryLightBrush}"
65+
BorderBrush="{StaticResource PrimaryBrush}"
66+
BorderThickness="1" CornerRadius="5"
67+
Padding="12,10" Margin="0,0,0,14">
68+
<Grid>
69+
<Grid.ColumnDefinitions>
70+
<ColumnDefinition Width="64" />
71+
<ColumnDefinition Width="*" />
72+
</Grid.ColumnDefinitions>
73+
<TextBlock Grid.Column="0" Text="新位置"
74+
Foreground="{StaticResource PrimaryDarkBrush}"
75+
FontSize="12" FontWeight="SemiBold"
76+
VerticalAlignment="Top" Margin="0,2,8,0" />
77+
<TextBlock x:Name="NewRootText" Grid.Column="1"
78+
Foreground="{StaticResource TextPrimaryBrush}"
79+
FontSize="12" FontWeight="SemiBold" TextWrapping="Wrap" />
80+
</Grid>
81+
</Border>
82+
83+
<Border Background="{StaticResource WarningLightBrush}"
84+
BorderBrush="{StaticResource WarningBrush}"
85+
BorderThickness="1" CornerRadius="5"
86+
Padding="12,8">
87+
<TextBlock Foreground="{StaticResource TextSecondaryBrush}"
88+
TextWrapping="Wrap" FontSize="12">
89+
<Run Text="搬移到新位置" FontWeight="SemiBold" Foreground="{StaticResource PrimaryDarkBrush}" />
90+
<Run Text=":複製整棵資料夾後刪除舊位置。" />
91+
<LineBreak />
92+
<Run Text="保留舊資料" FontWeight="SemiBold" Foreground="{StaticResource TextPrimaryBrush}" />
93+
<Run Text=":舊位置不動,新位置從零開始。" />
94+
</TextBlock>
95+
</Border>
96+
</StackPanel>
97+
</DockPanel>
98+
</Window>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.Windows;
2+
using Tender.Desktop.Services;
3+
4+
namespace Tender.Desktop.Views;
5+
6+
public partial class MigrateDataRootDialog : Window
7+
{
8+
public MigrateChoice Result { get; private set; } = MigrateChoice.Cancel;
9+
10+
public MigrateDataRootDialog()
11+
{
12+
InitializeComponent();
13+
}
14+
15+
public void Initialize(string oldRoot, string newRoot)
16+
{
17+
OldRootText.Text = oldRoot;
18+
NewRootText.Text = newRoot;
19+
}
20+
21+
private void Migrate_Click(object sender, RoutedEventArgs e)
22+
{
23+
Result = MigrateChoice.Migrate;
24+
DialogResult = true;
25+
Close();
26+
}
27+
28+
private void Keep_Click(object sender, RoutedEventArgs e)
29+
{
30+
Result = MigrateChoice.Keep;
31+
DialogResult = true;
32+
Close();
33+
}
34+
35+
private void Cancel_Click(object sender, RoutedEventArgs e)
36+
{
37+
Result = MigrateChoice.Cancel;
38+
DialogResult = false;
39+
Close();
40+
}
41+
}

0 commit comments

Comments
 (0)