This commit is contained in:
irreaaa 2025-04-02 13:09:44 +03:00
parent 8c009e6908
commit e614e1d967
26 changed files with 149 additions and 40 deletions

View File

@ -7,6 +7,7 @@
<entry key="demofinish/App.axaml" value="demofinish/demofinish.csproj" />
<entry key="demofinish/EditWindow.axaml" value="demofinish/demofinish.csproj" />
<entry key="demofinish/MainWindow.axaml" value="demofinish/demofinish.csproj" />
<entry key="demofinish/Product.axaml" value="demofinish/demofinish.csproj" />
</map>
</option>
</component>

View File

@ -4,6 +4,43 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="demofinish.EditWindow"
x:CompileBindings="False"
Title="EditWindow">
Welcome to Avalonia!
<DockPanel >
<StackPanel Orientation="Vertical" VerticalAlignment="Center" Margin="5">
<TextBlock Text="Наименование:" Margin="5" VerticalAlignment="Center"/>
<TextBox x:Name="NameBox" Width="200" VerticalAlignment="Center" Margin="5"/>
<TextBlock Text="Приоритет:" Margin="5" VerticalAlignment="Center"/>
<TextBox x:Name="PriorityBox" Width="200" VerticalAlignment="Center" Margin="5" />
<TextBlock Text="Имя директора:" Margin="5" VerticalAlignment="Center"/>
<TextBox x:Name="BossNameBox" Width="200" VerticalAlignment="Center" Margin="5" />
<TextBlock Text="ИНН:" Margin="5" VerticalAlignment="Center"/>
<TextBox x:Name="InnBox" Width="200" VerticalAlignment="Center" Margin="5" />
<TextBlock Text="КПП:" Margin="5" VerticalAlignment="Center"/>
<TextBox x:Name="KppBox" Width="200" VerticalAlignment="Center" Margin="5" />
<TextBlock Text="Телефон:" Margin="5" VerticalAlignment="Center"/>
<TextBox x:Name="PhoneBox" Width="200" VerticalAlignment="Center" Margin="5" />
<TextBlock Text="Email:" Margin="5" VerticalAlignment="Center"/>
<TextBox x:Name="EmailBox" Width="200" VerticalAlignment="Center" Margin="5" />
<TextBlock Text="Адрес:" Margin="5" VerticalAlignment="Center"/>
<TextBox x:Name="AdressBox" Width="200" VerticalAlignment="Center" Margin="5" />
<TextBlock Text="Тип агента:" Margin="5" VerticalAlignment="Center"/>
<ComboBox x:Name="AgentTypeBox">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
<StackPanel DockPanel.Dock="Bottom" HorizontalAlignment="Center" Orientation="Horizontal">
<Button Content="Готово" Margin="5" Click="EditAgent_Button"/>
<Button Content="Назад" Click="BackButton" Margin="5"/>
</StackPanel>
</DockPanel>
</Window>

View File

@ -1,13 +1,102 @@
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using demofinish.Models;
using Avalonia.Controls.ApplicationLifetimes;
using System;
namespace demofinish;
public partial class EditWindow : Window
{
private readonly MainWindow.AgentPresenter _selectedAgent;
private readonly User1Context _context;
public EditWindow()
{
InitializeComponent();
}
public EditWindow(MainWindow.AgentPresenter selectedAgent) : this()
{
_selectedAgent = selectedAgent;
_context = new User1Context();
InitializeComponent();
LoadAgentData();
}
private void LoadAgentData()
{
NameBox.Text = _selectedAgent.Title;
AdressBox.Text = _selectedAgent.Address;
PhoneBox.Text = _selectedAgent.Phone;
EmailBox.Text = _selectedAgent.Email;
InnBox.Text = _selectedAgent.Inn;
KppBox.Text = _selectedAgent.Kpp;
BossNameBox.Text = _selectedAgent.Directorname;
PriorityBox.Text = _selectedAgent.Priority.ToString();
var agentTypes = _context.Agenttypes.ToList();
AgentTypeBox.ItemsSource = agentTypes;
var currentType = agentTypes.FirstOrDefault(at => at.Id == _selectedAgent.Agenttypeid);
AgentTypeBox.SelectedItem = currentType;
}
private void BackButton(object? sender, RoutedEventArgs e)
{
Close();
}
private async void EditAgent_Button(object? sender, RoutedEventArgs e)
{
_selectedAgent.Title = NameBox.Text;
_selectedAgent.Address = AdressBox.Text;
_selectedAgent.Phone = PhoneBox.Text;
_selectedAgent.Email = EmailBox.Text;
_selectedAgent.Inn = InnBox.Text;
_selectedAgent.Kpp = KppBox.Text;
_selectedAgent.Directorname = BossNameBox.Text;
if (int.TryParse(PriorityBox.Text, out int priority))
{
_selectedAgent.Priority = priority;
}
if (AgentTypeBox.SelectedItem is Agenttype selectedType)
{
_selectedAgent.Agenttypeid = selectedType.Id;
}
var dbAgent = _context.Agents.FirstOrDefault(a => a.Id == _selectedAgent.Id);
if (dbAgent != null)
{
dbAgent.Title = _selectedAgent.Title;
dbAgent.Address = _selectedAgent.Address;
dbAgent.Phone = _selectedAgent.Phone;
dbAgent.Email = _selectedAgent.Email;
dbAgent.Inn = _selectedAgent.Inn;
dbAgent.Kpp = _selectedAgent.Kpp;
dbAgent.Directorname = _selectedAgent.Directorname;
dbAgent.Priority = _selectedAgent.Priority;
dbAgent.Agenttypeid = _selectedAgent.Agenttypeid;
await _context.SaveChangesAsync();
Close();
}
}
}

View File

@ -9,7 +9,10 @@
<DockPanel>
<StackPanel DockPanel.Dock="Top" Margin="10" HorizontalAlignment="Center" Orientation="Horizontal">
<AutoCompleteBox x:Name="SearchBox" Watermark="Поиск" FilterMode="StartsWith" HorizontalAlignment="Center" Margin="5" Width="200"/>
<StackPanel Orientation="Vertical" Margin="5">
<TextBlock Text=""/>
<AutoCompleteBox x:Name="SearchBox" Watermark="Поиск" FilterMode="StartsWith" HorizontalAlignment="Center" Margin="5" Width="200"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="5">
<TextBlock Text="Тип агента"/>
<ComboBox x:Name="TypeAgentCombobox" Margin="5" Width="200">
@ -45,7 +48,7 @@
</StackPanel>
</StackPanel>
<ListBox x:Name="AgentListBox">
<ListBox x:Name="AgentListBox" SelectionChanged="AgentListBox_OnSelectionChanged">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="3"/>

View File

@ -241,5 +241,15 @@ namespace demofinish
{
new AddAgent_Window().ShowDialog(this);
}
private void AgentListBox_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (AgentListBox.SelectedItem is AgentPresenter selectedAgent)
{
var editWindow = new EditWindow(selectedAgent);
editWindow.ShowDialog(this);
}
}
}
}

View File

@ -10,7 +10,7 @@ public partial class Agent
{
public int Id { get; set; }
public string Title { get; set; } = null!;
public string? Title { get; set; } = null!;
public int Agenttypeid { get; set; }

View File

@ -1,11 +0,0 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="demofinish.Product"
Title="Product">
</Window>

View File

@ -1,17 +0,0 @@
using Avalonia.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace demofinish
{
public partial class Product : Window
{
public Product()
{
InitializeComponent();
}
}
}

View File

@ -1 +1 @@
4beb2b980d074404d0ba635d434440b61c4fc94b2b026606a450646029801330
fdd6aec688d5c63eb81de35eaccb215d250e623e506a16f54b2f7bc8e848834f

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("demofinish")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+90bb8777172395f69e346d10fc0a2c18a084d30f")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8c009e6908c827bf6a1d1272b6019949a641ac9c")]
[assembly: System.Reflection.AssemblyProductAttribute("demofinish")]
[assembly: System.Reflection.AssemblyTitleAttribute("demofinish")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
91f9c82542ea7ce88c75b51ac0884916ce99761483acd5d6f9fe30f69a84a69a
af193fa632a0477765702f8f317fecad5f881bbfcdd590732dcd8277d098e7e3

View File

@ -32,6 +32,3 @@ build_metadata.AdditionalFiles.SourceItemGroup = AvaloniaXaml
[C:/Users/prdb/RiderProjects/demka/demofinish/MainWindow.axaml]
build_metadata.AdditionalFiles.SourceItemGroup = AvaloniaXaml
[C:/Users/prdb/RiderProjects/demka/demofinish/Product.axaml]
build_metadata.AdditionalFiles.SourceItemGroup = AvaloniaXaml

View File

@ -1 +1 @@
794db34d271b78dc26eb8952122868bffa04252fc220655d145e0e2c17e7029c
acc396a0a6e37aaf884563d01dbdce926298067eebc03e206ee5e786c68604ef

View File

@ -1 +1 @@
17434938584649473
17434938679777777