完成个删除变量功能
This commit is contained in:
@@ -273,7 +273,7 @@ public class VarDataRepository
|
|||||||
stopwatch.Start();
|
stopwatch.Start();
|
||||||
using var _db = DbContext.GetInstance();
|
using var _db = DbContext.GetInstance();
|
||||||
|
|
||||||
var dbList = variableDatas.Select(vd => vd.CopyTo<DbVariableData>());
|
var dbList = variableDatas.Select(vd => vd.CopyTo<DbVariableData>()).ToList();
|
||||||
var result = await _db.Deleteable<DbVariableData>(dbList)
|
var result = await _db.Deleteable<DbVariableData>(dbList)
|
||||||
.ExecuteCommandAsync();
|
.ExecuteCommandAsync();
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
|
|||||||
@@ -212,17 +212,18 @@ partial class VariableTableViewModel : ViewModelBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
private async void DeleteVarData()
|
public async Task DeleteVarData(List<VariableData> variablesToDelete)
|
||||||
{
|
{
|
||||||
if (SelectedVariableData == null)
|
if (variablesToDelete == null || !variablesToDelete.Any())
|
||||||
{
|
{
|
||||||
NotificationHelper.ShowMessage("请选择要删除的变量", NotificationType.Warning);
|
NotificationHelper.ShowMessage("请选择要删除的变量", NotificationType.Warning);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var names = string.Join("、", variablesToDelete.Select(v => v.Name));
|
||||||
var confirm = await _dialogService.ShowConfrimeDialog(
|
var confirm = await _dialogService.ShowConfrimeDialog(
|
||||||
"删除确认",
|
"删除确认",
|
||||||
$"确定要删除变量 \"{SelectedVariableData.Name}\" 吗?",
|
$"确定要删除选中的 {variablesToDelete.Count} 个变量吗?\n\n{names}",
|
||||||
"删除");
|
"删除");
|
||||||
|
|
||||||
if (!confirm)
|
if (!confirm)
|
||||||
@@ -230,16 +231,18 @@ partial class VariableTableViewModel : ViewModelBase
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = await _varDataRepository.DeleteAsync(SelectedVariableData);
|
var result = await _varDataRepository.DeleteAsync(variablesToDelete);
|
||||||
if (result > 0)
|
if (result > 0)
|
||||||
{
|
{
|
||||||
var dataName = SelectedVariableData.Name;
|
foreach (var variable in variablesToDelete)
|
||||||
DataVariables.Remove(SelectedVariableData);
|
{
|
||||||
NotificationHelper.ShowMessage($"变量 \"{dataName}\" 删除成功", NotificationType.Success);
|
DataVariables.Remove(variable);
|
||||||
|
}
|
||||||
|
NotificationHelper.ShowMessage($"成功删除 {result} 个变量", NotificationType.Success);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NotificationHelper.ShowMessage($"变量 \"{SelectedVariableData.Name}\" 删除失败", NotificationType.Error);
|
NotificationHelper.ShowMessage("删除变量失败", NotificationType.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|||||||
@@ -70,8 +70,8 @@
|
|||||||
</ui:AppBarButton.Icon>
|
</ui:AppBarButton.Icon>
|
||||||
</ui:AppBarButton>
|
</ui:AppBarButton>
|
||||||
|
|
||||||
<ui:AppBarButton Command="{Binding DeleteVarDataCommand}"
|
<ui:AppBarButton Label="删除变量"
|
||||||
Label="删除变量">
|
Click="DeleteVarData_Click">
|
||||||
<ui:AppBarButton.Icon>
|
<ui:AppBarButton.Icon>
|
||||||
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Delete}" />
|
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Delete}" />
|
||||||
</ui:AppBarButton.Icon>
|
</ui:AppBarButton.Icon>
|
||||||
@@ -141,10 +141,12 @@
|
|||||||
|
|
||||||
</ikw:SimpleStackPanel>
|
</ikw:SimpleStackPanel>
|
||||||
|
|
||||||
<DataGrid Margin="10"
|
<DataGrid x:Name="BasicGridView"
|
||||||
|
Margin="10"
|
||||||
CellEditEnding="DataGrid_OnCellEditEnding"
|
CellEditEnding="DataGrid_OnCellEditEnding"
|
||||||
AutoGenerateColumns="False"
|
AutoGenerateColumns="False"
|
||||||
CanUserSortColumns="True"
|
CanUserSortColumns="True"
|
||||||
|
SelectionMode="Extended"
|
||||||
SelectedItem="{Binding SelectedVariableData}"
|
SelectedItem="{Binding SelectedVariableData}"
|
||||||
ItemsSource="{Binding DataVariables}">
|
ItemsSource="{Binding DataVariables}">
|
||||||
<DataGrid.RowStyle>
|
<DataGrid.RowStyle>
|
||||||
|
|||||||
@@ -108,4 +108,18 @@ public partial class VariableTableView : UserControl
|
|||||||
NotificationHelper.ShowMessage(msg + e.Message, NotificationType.Error);
|
NotificationHelper.ShowMessage(msg + e.Message, NotificationType.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void DeleteVarData_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
_viewModel = (VariableTableViewModel)this.DataContext;
|
||||||
|
var selectedVariables = BasicGridView.SelectedItems.Cast<VariableData>().ToList();
|
||||||
|
if (selectedVariables.Any())
|
||||||
|
{
|
||||||
|
await _viewModel.DeleteVarData(selectedVariables);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NotificationHelper.ShowMessage("请选择要删除的变量", NotificationType.Warning);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user