To Be Continued
parent
b169a275b4
commit
cbf2b3c1d3
|
|
@ -81,6 +81,6 @@ public abstract class BaseRepository<T> : IRepository<T>, IDisposable where T :
|
|||
}
|
||||
public void Dispose()
|
||||
{
|
||||
connection.Dispose();
|
||||
connection.Close();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AvaloniaApplication14_autoTest_190326.Models;
|
||||
using AvaloniaApplication14_Di_test_1125.Models;
|
||||
using AvaloniaApplication14_Inventory_300326.Models.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MySqlConnector;
|
||||
|
||||
namespace AvaloniaApplication14_Inventory_300326.Models.DataBase;
|
||||
|
||||
public class EmployeeRepository : BaseRepository<Employee>, IDisposable
|
||||
{
|
||||
public EmployeeRepository(IOptions<DatabaseSettings> ConnectionString) : base(ConnectionString)
|
||||
{
|
||||
OpenConnection();
|
||||
}
|
||||
|
||||
public override List<Employee>? GetAll()
|
||||
{
|
||||
string sql = "SELECT * FROM `Employees`";
|
||||
List<Employee> result = new List<Employee>();
|
||||
try
|
||||
{
|
||||
using var mc = new MySqlCommand(sql, connection);
|
||||
using var reader = mc.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
Employee employee = new Employee()
|
||||
{
|
||||
Id = reader.GetInt32("Id"),
|
||||
FullName = reader.GetString("FullName"),
|
||||
PositionId = reader.GetInt32("PositionId"),
|
||||
};
|
||||
result.Add(employee);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public override Employee? GetById(int id)
|
||||
{
|
||||
string sql = "SELECT * FROM `Employees` WHERE Id = @Id";
|
||||
Employee result = null;
|
||||
try
|
||||
{
|
||||
using var mc = new MySqlCommand(sql, connection);
|
||||
mc.Parameters.AddWithValue("@Id", id);
|
||||
using var reader = mc.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
result = new Employee()
|
||||
{
|
||||
Id = reader.GetInt32("Id"),
|
||||
FullName = reader.GetString("FullName"),
|
||||
PositionId = reader.GetInt32("PositionId"),
|
||||
};
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public override bool Delete(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Update(Employee item)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Add(Employee item)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AvaloniaApplication14_autoTest_190326.Models;
|
||||
using AvaloniaApplication14_Di_test_1125.Models;
|
||||
using AvaloniaApplication14_Inventory_300326.Models.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MySqlConnector;
|
||||
|
||||
namespace AvaloniaApplication14_Inventory_300326.Models.DataBase;
|
||||
|
||||
public class EquipmeentRepository : BaseRepository<Equipment>, IDisposable
|
||||
{
|
||||
public EquipmeentRepository(IOptions<DatabaseSettings> ConnectionString) : base(ConnectionString)
|
||||
{
|
||||
OpenConnection();
|
||||
}
|
||||
|
||||
public override List<Equipment>? GetAll()
|
||||
{
|
||||
string sql = "select * from `Equipment`";
|
||||
List<Equipment> result = new List<Equipment>();
|
||||
try
|
||||
{
|
||||
using var mc = new MySqlCommand(sql, connection);
|
||||
mc.ExecuteNonQuery();
|
||||
using var reader = mc.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
Equipment equipment = new Equipment()
|
||||
{
|
||||
Id = reader.GetInt32("Id"),
|
||||
Name = reader.GetString("Name"),
|
||||
InvNumber = reader.GetString("InvNumber"),
|
||||
Date = reader.GetDateOnly("PurchaseDate"),
|
||||
Cost = reader.GetDecimal("Cost"),
|
||||
IsWrittenOff = reader.GetBoolean("IsWrittenOff"),
|
||||
CurrentEmployeeId = reader.GetInt32("CurrentEmployeeId")
|
||||
};
|
||||
result.Add(equipment);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public override Equipment? GetById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Delete(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Update(Equipment item)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Add(Equipment item)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ public class Equipment : DBObj
|
|||
public string InvNumber { get; set; }
|
||||
public string Name { get; set; }
|
||||
public DateOnly Date { get; set; }
|
||||
public int Cost { get; set; }
|
||||
public decimal Cost { get; set; }
|
||||
public bool IsWrittenOff {get; set;}
|
||||
public int CurrentEmployeeId { get; set; }
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
|
||||
namespace AvaloniaApplication14_Inventory_300326.Models.Models;
|
||||
|
||||
public class EquipmentVisual
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string InvNumber { get; set; }
|
||||
public string Name { get; set; }
|
||||
public DateOnly Date { get; set; }
|
||||
public decimal Cost { get; set; }
|
||||
public string IsWrittenOff {get; set;}
|
||||
public Employee CurrentEmployee { get; set; }
|
||||
|
||||
public void CreateFromEquipment(Equipment equipment)
|
||||
{
|
||||
Id = equipment.Id;
|
||||
InvNumber = equipment.InvNumber;
|
||||
Name = equipment.Name;
|
||||
Date = equipment.Date;
|
||||
Cost = equipment.Cost;
|
||||
IsWrittenOff = equipment.IsWrittenOff?"Да":"Нет";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
using Avalonia;
|
||||
using System;
|
||||
using AvaloniaApplication14_Di_test_1125.Models;
|
||||
using AvaloniaApplication14_Inventory_300326.Models.DataBase;
|
||||
using AvaloniaApplication14_Inventory_300326.ViewModels;
|
||||
using AvaloniaApplication14_Inventory_300326.Views;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
|
@ -25,6 +26,7 @@ sealed class Program
|
|||
service.Configure<DatabaseSettings>(context.Configuration.GetSection("DatabaseSettings"));
|
||||
service.AddTransient<MainWindow>();
|
||||
service.AddTransient<MainWindowViewModel>();
|
||||
service.AddTransient<EquipmeentRepository>();
|
||||
}).Build();
|
||||
|
||||
BuildAvaloniaApp(host.Services)
|
||||
|
|
|
|||
|
|
@ -1,17 +1,26 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Data;
|
||||
using AvaloniaApplication14_Inventory_300326.Models.DataBase;
|
||||
using AvaloniaApplication14_Inventory_300326.Models.Models;
|
||||
using AvaloniaApplication14_Inventory_300326.Views;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace AvaloniaApplication14_Inventory_300326.ViewModels;
|
||||
|
||||
public partial class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
private MainWindow _currentWindow;
|
||||
private IServiceProvider _serviceProvider;
|
||||
|
||||
[ObservableProperty] private ObservableCollection<Entity> _entities;
|
||||
[ObservableProperty] private Entity _selectedEntity;
|
||||
[ObservableProperty] private ObservableCollection<EquipmentVisual> _techs;
|
||||
[ObservableProperty] private ObservableCollection<Employee> _employees;
|
||||
[ObservableProperty] private ObservableCollection<Position> _positions;
|
||||
|
||||
partial void OnEntitiesChanged(ObservableCollection<Entity> value)
|
||||
{
|
||||
|
|
@ -20,22 +29,27 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||
|
||||
partial void OnSelectedEntityChanged(Entity value)
|
||||
{
|
||||
switch (value.Id)
|
||||
if (_currentWindow != null)
|
||||
{
|
||||
case 0:
|
||||
switch (value.Id)
|
||||
{
|
||||
case 0:
|
||||
|
||||
break;
|
||||
case 1:
|
||||
|
||||
break;
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
|
||||
break;
|
||||
case 2:
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MainWindowViewModel()
|
||||
public MainWindowViewModel(IServiceProvider serviceProvider, EquipmeentRepository equipmeentRepository)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
|
||||
Entities = new();
|
||||
|
||||
Entities.Add(new Entity(){Id = 0, Name = "Техника"});
|
||||
|
|
@ -43,8 +57,26 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||
Entities.Add(new Entity(){Id = 2, Name = "Должности"});
|
||||
|
||||
SelectedEntity = Entities[0];
|
||||
List<Equipment> test = equipmeentRepository.GetAll();
|
||||
|
||||
Techs = new ObservableCollection<EquipmentVisual>();
|
||||
}
|
||||
|
||||
public List<EquipmentVisual> ConvertListEqToEqVis(List<Equipment> equipments)
|
||||
{
|
||||
List<EquipmentVisual> result = new List<EquipmentVisual>();
|
||||
foreach (var item in equipments)
|
||||
{
|
||||
EquipmentVisual eq = new EquipmentVisual();
|
||||
using (var empRepo = _serviceProvider.GetRequiredService<EmployeeRepository>())
|
||||
{
|
||||
eq.CreateFromEquipment(item);
|
||||
eq.CurrentEmployee = empRepo.GetById(item.CurrentEmployeeId);
|
||||
}
|
||||
result.Add(eq);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void SetScreen(MainWindow window)
|
||||
{
|
||||
_currentWindow = window;
|
||||
|
|
|
|||
|
|
@ -19,9 +19,30 @@
|
|||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
<ScrollViewer x:Name="ScrollViewerForDatagrid">
|
||||
|
||||
</ScrollViewer>
|
||||
<Grid RowDefinitions="*" ColumnDefinitions="*">
|
||||
<ScrollViewer>
|
||||
<DataGrid x:Name="ScrollViewerDataGridTech" ItemsSource="{Binding Techs}">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Инвентарный номер" Binding="{Binding InvNumber}"></DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Название" Binding="{Binding Name}"></DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Дата приобретения" Binding="{Binding Date}"></DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Стоимость" Binding="{Binding Cost}"></DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Списано ли" Binding="{Binding IsWrittenOff}"></DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Текущий владелец" Binding="{Binding CurrentEmployeeId}"></DataGridTextColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</ScrollViewer>
|
||||
<ScrollViewer>
|
||||
<DataGrid x:Name="ScrollViewerDataGridEmpl" ItemsSource="{Binding Employees}">
|
||||
|
||||
</DataGrid>
|
||||
</ScrollViewer>
|
||||
<ScrollViewer>
|
||||
<DataGrid x:Name="ScrollViewerDataGridPos" ItemsSource="{Binding Positions}">
|
||||
|
||||
</DataGrid>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
<TabItem Header="Операции">
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"DatabaseSettings": {
|
||||
"ConnectionString": "server=192.168.200.13;user=student;password=student;database=auto_service_db"
|
||||
"ConnectionString": "server=192.168.200.13;user=student;password=student;database=TechInventory"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
|
@ -13,7 +13,7 @@ using System.Reflection;
|
|||
[assembly: System.Reflection.AssemblyCompanyAttribute("AvaloniaApplication14_Inventory_300326")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+87bcd6176eb43df17d7b079092cb9e1b53850c6e")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+b169a275b4b92a8d251235436b93bd0960f3e459")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("AvaloniaApplication14_Inventory_300326")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("AvaloniaApplication14_Inventory_300326")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
b1305692aaf9ea52dd6e8e5b2f0805a7d6dc4ecebd5c9a4f90e93bdc05375d82
|
||||
8207d089541f27ef630877f99fb8ddb693d2b2d0d47fd66842c9106296f96e66
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
09f782a9500158492fe24bbc2960ab4ec88cc1ab647d05341362637bd6f000ce
|
||||
05243996e8958daf2ebabc094115b0206a262c6457c45b77b7c6600d3aa1f314
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1 +1 @@
|
|||
17750958785606392
|
||||
17751742412854983
|
||||
|
|
@ -1 +1 @@
|
|||
17750958843205400
|
||||
17751742412854983
|
||||
Loading…
Reference in New Issue