ASP.NET API #1
@ -2,7 +2,7 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="Presence.Desktop.App"
|
||||
xmlns:local="using:Presence.Desktop"
|
||||
RequestedThemeVariant="Default">
|
||||
RequestedThemeVariant="Light">
|
||||
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
|
||||
|
||||
<Application.DataTemplates>
|
||||
|
@ -1,10 +1,14 @@
|
||||
using domain.UseCase;
|
||||
using Presence.Desktop.Models;
|
||||
using System;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive;
|
||||
using System.Linq;
|
||||
using ReactiveUI;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Presence.Desktop.ViewModels
|
||||
{
|
||||
@ -33,17 +37,43 @@ namespace Presence.Desktop.ViewModels
|
||||
set => this.RaiseAndSetIfChanged(ref _students, value);
|
||||
}
|
||||
|
||||
public Interaction<Unit, string?> ShowOpenFileDialog;
|
||||
private string? _selectedFile;
|
||||
public string? SelectedFile
|
||||
{
|
||||
get => _selectedFile;
|
||||
set => this.RaiseAndSetIfChanged(ref _selectedFile, value);
|
||||
}
|
||||
|
||||
public ICommand OpenFileDialog { get; }
|
||||
|
||||
public MainWindowViewModel()
|
||||
{
|
||||
_groupService = null;
|
||||
_groups = new();
|
||||
_students = new();
|
||||
OpenFileDialog = ReactiveCommand.CreateFromTask(SelectFile);
|
||||
}
|
||||
|
||||
public MainWindowViewModel(IGroupUseCase gService, IGroupUseCase groupService, ObservableCollection<GroupPresenter> groups, ObservableCollection<StudentPresenter> students)
|
||||
public MainWindowViewModel(IGroupUseCase gService)
|
||||
{
|
||||
_groupService = gService;
|
||||
ShowOpenFileDialog = new Interaction<Unit, string?>();
|
||||
OpenFileDialog = ReactiveCommand.CreateFromTask(SelectFile);
|
||||
|
||||
_students = new();
|
||||
|
||||
this.WhenAnyValue(vm => vm.SelectedGroupItem)
|
||||
.Subscribe(_ =>
|
||||
{
|
||||
RefreshGroups();
|
||||
SetStudents();
|
||||
});
|
||||
}
|
||||
|
||||
private void RefreshGroups()
|
||||
{
|
||||
groupPresenters.Clear();
|
||||
foreach (var item in _groupService.GetGroupsWithStudents())
|
||||
{
|
||||
GroupPresenter groupPresenter = new GroupPresenter
|
||||
@ -67,11 +97,6 @@ namespace Presence.Desktop.ViewModels
|
||||
}
|
||||
|
||||
_groups = new(groupPresenters);
|
||||
|
||||
_students = new();
|
||||
|
||||
this.WhenAnyValue(vm => vm.SelectedGroupItem)
|
||||
.Subscribe(_ => SetStudents());
|
||||
}
|
||||
|
||||
private void SetStudents()
|
||||
@ -85,5 +110,15 @@ namespace Presence.Desktop.ViewModels
|
||||
Students.Add(student);
|
||||
}
|
||||
|
||||
private async Task SelectFile()
|
||||
{
|
||||
SelectedFile = await ShowOpenFileDialog.Handle(Unit.Default);
|
||||
|
||||
if (SelectedFile is object)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -14,9 +14,6 @@
|
||||
</Design.DataContext>
|
||||
|
||||
<DockPanel Background="Azure">
|
||||
<StackPanel DockPanel.Dock="Bottom">
|
||||
<TextBlock Text="List ↑" HorizontalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
<StackPanel
|
||||
Spacing="10"
|
||||
HorizontalAlignment="Center"
|
||||
@ -29,20 +26,22 @@
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
<ComboBox/>
|
||||
<Button Width="140" HorizontalContentAlignment="Center" Content="Внести студентов" Command="{Binding OpenFileDialog}"/>
|
||||
<ComboBox/>
|
||||
</StackPanel>
|
||||
<Border>
|
||||
<ListBox Background="Bisque" ItemsSource="{Binding Students}">
|
||||
<ListBox ItemsSource="{Binding Students}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock>
|
||||
<MultiBinding StringFormat="{}{0} {1} {2}">
|
||||
<Binding Path="LastName"/>
|
||||
<Binding Path="FirstName"/>
|
||||
<Binding Path="Patronymic"/>
|
||||
</MultiBinding>
|
||||
<TextBlock>
|
||||
<TextBlock.Text>
|
||||
<MultiBinding StringFormat="{}{0} {1} {2}">
|
||||
<Binding Path="LastName"/>
|
||||
<Binding Path="FirstName"/>
|
||||
<Binding Path="Patronymic"/>
|
||||
</MultiBinding>
|
||||
</TextBlock.Text>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
|
@ -1,12 +1,48 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Avalonia.ReactiveUI;
|
||||
using Presence.Desktop.ViewModels;
|
||||
using ReactiveUI;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Presence.Desktop.Views
|
||||
{
|
||||
public partial class MainWindow : Window
|
||||
public partial class MainWindow : ReactiveWindow<MainWindowViewModel>
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.WhenActivated(action =>
|
||||
{
|
||||
action(ViewModel.ShowOpenFileDialog.RegisterHandler(ShowOpenFileDialogAsync));
|
||||
});
|
||||
}
|
||||
|
||||
public static FilePickerFileType FileCsv { get; } = new("Comma-Separated Values")
|
||||
{
|
||||
Patterns = ["*.csv"],
|
||||
AppleUniformTypeIdentifiers = ["public.comma-separated-values-text"],
|
||||
MimeTypes = ["application/vnd.ms-excel", "text/csv"]
|
||||
};
|
||||
|
||||
private async Task ShowOpenFileDialogAsync(InteractionContext<Unit, string?> interaction)
|
||||
{
|
||||
var topLevel = GetTopLevel(this);
|
||||
FilePickerOpenOptions fpOptions = new FilePickerOpenOptions
|
||||
{
|
||||
AllowMultiple = false,
|
||||
Title = "students csv",
|
||||
FileTypeFilter = [FileCsv]
|
||||
};
|
||||
var storageFile = await topLevel.StorageProvider.OpenFilePickerAsync(fpOptions);
|
||||
|
||||
interaction.SetOutput(storageFile.First().Path.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user