ASP.NET API #1
@ -2,7 +2,7 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
x:Class="Presence.Desktop.App"
|
x:Class="Presence.Desktop.App"
|
||||||
xmlns:local="using:Presence.Desktop"
|
xmlns:local="using:Presence.Desktop"
|
||||||
RequestedThemeVariant="Default">
|
RequestedThemeVariant="Light">
|
||||||
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
|
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
|
||||||
|
|
||||||
<Application.DataTemplates>
|
<Application.DataTemplates>
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
using domain.UseCase;
|
using domain.UseCase;
|
||||||
using Presence.Desktop.Models;
|
using Presence.Desktop.Models;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Reactive.Linq;
|
||||||
|
using System.Reactive;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Presence.Desktop.ViewModels
|
namespace Presence.Desktop.ViewModels
|
||||||
{
|
{
|
||||||
@ -33,17 +37,43 @@ namespace Presence.Desktop.ViewModels
|
|||||||
set => this.RaiseAndSetIfChanged(ref _students, value);
|
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()
|
public MainWindowViewModel()
|
||||||
{
|
{
|
||||||
_groupService = null;
|
_groupService = null;
|
||||||
_groups = new();
|
_groups = new();
|
||||||
_students = 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;
|
_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())
|
foreach (var item in _groupService.GetGroupsWithStudents())
|
||||||
{
|
{
|
||||||
GroupPresenter groupPresenter = new GroupPresenter
|
GroupPresenter groupPresenter = new GroupPresenter
|
||||||
@ -67,11 +97,6 @@ namespace Presence.Desktop.ViewModels
|
|||||||
}
|
}
|
||||||
|
|
||||||
_groups = new(groupPresenters);
|
_groups = new(groupPresenters);
|
||||||
|
|
||||||
_students = new();
|
|
||||||
|
|
||||||
this.WhenAnyValue(vm => vm.SelectedGroupItem)
|
|
||||||
.Subscribe(_ => SetStudents());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetStudents()
|
private void SetStudents()
|
||||||
@ -85,5 +110,15 @@ namespace Presence.Desktop.ViewModels
|
|||||||
Students.Add(student);
|
Students.Add(student);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task SelectFile()
|
||||||
|
{
|
||||||
|
SelectedFile = await ShowOpenFileDialog.Handle(Unit.Default);
|
||||||
|
|
||||||
|
if (SelectedFile is object)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,6 @@
|
|||||||
</Design.DataContext>
|
</Design.DataContext>
|
||||||
|
|
||||||
<DockPanel Background="Azure">
|
<DockPanel Background="Azure">
|
||||||
<StackPanel DockPanel.Dock="Bottom">
|
|
||||||
<TextBlock Text="List ↑" HorizontalAlignment="Center"/>
|
|
||||||
</StackPanel>
|
|
||||||
<StackPanel
|
<StackPanel
|
||||||
Spacing="10"
|
Spacing="10"
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
@ -29,20 +26,22 @@
|
|||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ComboBox.ItemTemplate>
|
</ComboBox.ItemTemplate>
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
<ComboBox/>
|
<Button Width="140" HorizontalContentAlignment="Center" Content="Внести студентов" Command="{Binding OpenFileDialog}"/>
|
||||||
<ComboBox/>
|
<ComboBox/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<Border>
|
<Border>
|
||||||
<ListBox Background="Bisque" ItemsSource="{Binding Students}">
|
<ListBox ItemsSource="{Binding Students}">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<TextBlock>
|
<TextBlock>
|
||||||
<MultiBinding StringFormat="{}{0} {1} {2}">
|
<TextBlock.Text>
|
||||||
<Binding Path="LastName"/>
|
<MultiBinding StringFormat="{}{0} {1} {2}">
|
||||||
<Binding Path="FirstName"/>
|
<Binding Path="LastName"/>
|
||||||
<Binding Path="Patronymic"/>
|
<Binding Path="FirstName"/>
|
||||||
</MultiBinding>
|
<Binding Path="Patronymic"/>
|
||||||
|
</MultiBinding>
|
||||||
|
</TextBlock.Text>
|
||||||
</TextBlock>
|
</TextBlock>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
@ -1,12 +1,48 @@
|
|||||||
using Avalonia.Controls;
|
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
|
namespace Presence.Desktop.Views
|
||||||
{
|
{
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : ReactiveWindow<MainWindowViewModel>
|
||||||
{
|
{
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
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