更新UI和文件处理逻辑
在 MainWindow.xaml 中,<Border> 元素增加 MinWidth="300" 属性。 在 Excel2Prompt.cs 中,增加提示列的代码。 在 ImportExcelPage.xaml 中,更新 <TextBlock> 的 Text 属性。 在 ImportExcelPage.xaml 中,<hc:TabControl> 增加 ShowCloseButton 和 ShowContextMenu 属性。 在 ImportExcelPage.xaml 中,增加 <ToolBar> 元素,包含 Button 和 Label。 在 ImportExcelPage.xaml.cs 中,Grid_DragEnter 方法增加可见性设置。 在 ImportExcelPage.xaml.cs 中,调整 Grid_Drop 和 Grid_DragLeave 方法的缩进。 在 ImportViewModel.cs 中,FileDrop 方法改为 Task,并增加文件扩展名检查。
This commit is contained in:
parent
d9b0f3bf1e
commit
d1d2bebcd1
|
|
@ -54,6 +54,7 @@
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Border
|
<Border
|
||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
|
MinWidth="300"
|
||||||
Margin="0,0,0,10"
|
Margin="0,0,0,10"
|
||||||
Padding="2"
|
Padding="2"
|
||||||
Background="#fff"
|
Background="#fff"
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ public class Excel2Prompt
|
||||||
- Missing values: 7007
|
- Missing values: 7007
|
||||||
*/
|
*/
|
||||||
var prompts = new List<string>();
|
var prompts = new List<string>();
|
||||||
|
prompts.Add("This Excel file contains the following columns:" );
|
||||||
var dataList = excelData.ToList();
|
var dataList = excelData.ToList();
|
||||||
|
|
||||||
foreach (var column in columns)
|
foreach (var column in columns)
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
FontSize="20"
|
FontSize="20"
|
||||||
Foreground="White"
|
Foreground="White"
|
||||||
Text="拖拽到此处放开" />
|
Text="拖拽Excel文件(.xls)到此处放开" />
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
@ -69,7 +69,11 @@
|
||||||
Content="{Binding}"
|
Content="{Binding}"
|
||||||
ContentTemplate="{StaticResource LoadingMask}"
|
ContentTemplate="{StaticResource LoadingMask}"
|
||||||
Visibility="{Binding IsLoading, Converter={StaticResource Boolean2VisibilityConverter}}" />
|
Visibility="{Binding IsLoading, Converter={StaticResource Boolean2VisibilityConverter}}" />
|
||||||
<hc:TabControl Grid.Column="0" Margin="5,5,7,5">
|
<hc:TabControl
|
||||||
|
Grid.Column="0"
|
||||||
|
Margin="5,5,7,5"
|
||||||
|
ShowCloseButton="False"
|
||||||
|
ShowContextMenu="False">
|
||||||
<hc:TabItem Header="预览">
|
<hc:TabItem Header="预览">
|
||||||
<DataGrid
|
<DataGrid
|
||||||
x:Name="ExcelDataPreviewGrid"
|
x:Name="ExcelDataPreviewGrid"
|
||||||
|
|
@ -91,6 +95,15 @@
|
||||||
<RowDefinition Height="50" />
|
<RowDefinition Height="50" />
|
||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="*" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
|
<ToolBar
|
||||||
|
Grid.Row="0"
|
||||||
|
AllowDrop="False"
|
||||||
|
Header="操作">
|
||||||
|
<Button Content="导出文件" />
|
||||||
|
<Label>
|
||||||
|
<CheckBox Content="示例数据" />
|
||||||
|
</Label>
|
||||||
|
</ToolBar>
|
||||||
<hc:TextBox
|
<hc:TextBox
|
||||||
Grid.Row="1"
|
Grid.Row="1"
|
||||||
Padding="5"
|
Padding="5"
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ public partial class ImportExcelPage : Page, IView, IRecipient<UpdateDataGridCol
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
DropFileMask.Visibility = System.Windows.Visibility.Visible;
|
||||||
}
|
}
|
||||||
private void Grid_DragEnter(object sender, System.Windows.DragEventArgs e)
|
private void Grid_DragEnter(object sender, System.Windows.DragEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
@ -53,6 +54,7 @@ public partial class ImportExcelPage : Page, IView, IRecipient<UpdateDataGridCol
|
||||||
ViewModel.FileDrop(files);
|
ViewModel.FileDrop(files);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Grid_DragLeave(object sender, System.Windows.DragEventArgs e)
|
private void Grid_DragLeave(object sender, System.Windows.DragEventArgs e)
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ namespace ExcelHelper.Views.ViewModels;
|
||||||
public partial class ImportViewModel : ObservableRecipient, IViewModel
|
public partial class ImportViewModel : ObservableRecipient, IViewModel
|
||||||
{
|
{
|
||||||
|
|
||||||
public void FileDrop(string[] files)
|
public Task FileDrop(string[] files)
|
||||||
{
|
{
|
||||||
IsLoading = true;
|
IsLoading = true;
|
||||||
ExcelFiles.Clear();
|
ExcelFiles.Clear();
|
||||||
|
|
@ -29,11 +29,18 @@ public partial class ImportViewModel : ObservableRecipient, IViewModel
|
||||||
MaxRow = 0;
|
MaxRow = 0;
|
||||||
foreach (var item in files)
|
foreach (var item in files)
|
||||||
{
|
{
|
||||||
|
if(!item.EndsWith(".xlsx") && !item.EndsWith(".xls"))
|
||||||
|
{
|
||||||
|
WeakReferenceMessenger.Default.Send(new ErrorDialogMessage("请拖入Excel文件!"));
|
||||||
|
IsLoading = false;
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
ExcelFiles.Add(item);
|
ExcelFiles.Add(item);
|
||||||
}
|
}
|
||||||
//ReadForExcel(ExcelFiles.First());
|
//ReadForExcel(ExcelFiles.First());
|
||||||
CurrentFilePath = ExcelFiles.FirstOrDefault();
|
CurrentFilePath = ExcelFiles.FirstOrDefault();
|
||||||
IsLoading = false;
|
IsLoading = false;
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void ReadForExcel(string path, bool isReload = false)
|
public async void ReadForExcel(string path, bool isReload = false)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue