Agents/Functions/AgentEidtor.axaml.cs

70 lines
2.1 KiB
C#
Raw Normal View History

using Avalonia;
using Avalonia.Controls;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using System.Reflection;
using System;
using Agents.Models;
using System.Collections.ObjectModel;
using Avalonia.Interactivity;
using System.Linq;
using System.Runtime.ExceptionServices;
using Avalonia.Media;
namespace Agents;
public partial class AgentEidtor : Window
{
static User11Context db = new User11Context();
ObservableCollection<Agent> AgentsitemSource = new ObservableCollection<Agent>(db.Agents.OrderBy(it => it.Title));
public AgentEidtor()
{
InitializeComponent();
ListAgents.ItemsSource = AgentsitemSource;
}
2025-04-05 17:05:02 +00:00
private void ListAgents_SelectionChanged(object? sender, Avalonia.Controls.SelectionChangedEventArgs e)
{
2025-04-05 17:05:02 +00:00
Agent agent = db.Agents.Where(it => it == ListAgents.SelectedItem).First();
TextNewPriority.Text = agent.Priority.ToString();
TextNewInn.Text = agent.Inn;
TextNewKPP.Text = agent.Kpp;
TextNewAddress.Text = agent.Address;
TextNewDirectorname.Text = agent.Directorname;
TextNewEmail.Text = agent.Email;
}
2025-04-05 17:05:02 +00:00
private void ButtonChange(object sender, RoutedEventArgs e) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
try
{
Agent agent = db.Agents.Where(it => it == ListAgents.SelectedItem).First();
float a = float.Parse(TextNewPriority.Text);
agent.Priority = Convert.ToInt32(a);
agent.Inn = TextNewInn.Text;
agent.Kpp = TextNewKPP.Text;
agent.Directorname = TextNewDirectorname.Text;
agent.Address = TextNewAddress.Text;
agent.Email = TextNewEmail.Text;
db.SaveChanges();
2025-04-05 17:05:02 +00:00
Status.Foreground = Brushes.White;
Status.Text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
}
catch
{
Status.Foreground = Brushes.Red;
Status.Text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
}
}
2025-04-05 17:05:02 +00:00
void Exit(object sender, RoutedEventArgs e) // <20><><EFBFBD><EFBFBD><EFBFBD>
{
new MainWindow().Show();
Close();
}
}