Чут-чут доделал
parent
55e84ef57c
commit
4e1ab770f1
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"DatabseConnection": {
|
||||
"ConnectionString" : "server=localhost;userid=root;password=root;database=bathhousemanagment"
|
||||
"DatabaseConnection": {
|
||||
"ConnectionString" : "server=localhost;user=root;password=root;database=bathhouse"
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ public class OrderRepository
|
|||
public List<Order> GetOrders()
|
||||
{
|
||||
List<Order> result = new();
|
||||
string sql = "select * from orders";
|
||||
string sql = "select o.id as oid, o.client_id as ocid, o.employee_id as eid, o.discount_id as did, o.service_id as sid, o.zone_id as zid, c.name as cname, c.surname as csurname, o.order_time as otime, e.name as ename, e.surname as esurname, d.name as dname, s.name as sname, z.name as zname from `order` o join client c on o.client_id = c.id join employee e on o.employee_id = e.id join discount d on o.discount_id = d.id join service s on o.service_id = s.id join zone z on o.zone_id = z.id \n";
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
|
|
@ -29,14 +29,51 @@ public class OrderRepository
|
|||
{
|
||||
result.Add(new Order
|
||||
{
|
||||
/*
|
||||
Id = reader.GetInt32("id"),
|
||||
ClientId = reader.GetInt32("client_id"),
|
||||
ZoneId = reader.GetInt32("zone_id"),
|
||||
OrderDate = reader.GetDateTime("order_date"),
|
||||
WorkPrice = reader.GetInt32("work_price"),
|
||||
ServiceId = reader.GetInt32("service_id"),
|
||||
EmployeeId = reader.GetInt32("employee_id"),
|
||||
DiscountId = reader.GetInt32("discount_id"),
|
||||
FinalPrice = reader.GetInt32("final_price"),
|
||||
*/
|
||||
Client = new Client()
|
||||
{
|
||||
Id = reader.GetInt32("ocid"),
|
||||
Name = reader.GetString("cname"),
|
||||
Surname = reader.GetString("csurname"),
|
||||
},
|
||||
|
||||
Employee = new Employee()
|
||||
{
|
||||
Id = reader.GetInt32("eid"),
|
||||
Name = reader.GetString("ename"),
|
||||
Surname = reader.GetString("esurname"),
|
||||
},
|
||||
|
||||
Discount = new Discount()
|
||||
{
|
||||
Id = reader.GetInt32("did"),
|
||||
Name = reader.GetString("dname"),
|
||||
},
|
||||
|
||||
Zone = new Zone()
|
||||
{
|
||||
Id = reader.GetInt32("zid"),
|
||||
Name = reader.GetString("zname"),
|
||||
},
|
||||
|
||||
Service = new Service()
|
||||
{
|
||||
Id = reader.GetInt32("sid"),
|
||||
Name = reader.GetString("sname"),
|
||||
},
|
||||
FinalPrice = reader.GetInt32("final_price"),
|
||||
OrderDate = reader.GetDateTime("order_date"),
|
||||
Id = reader.GetInt32("oid"),
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -52,7 +89,7 @@ public class OrderRepository
|
|||
public bool InsertOrder(Order order)
|
||||
{
|
||||
string sql =
|
||||
"insert into `order` (`id`, `client_id`, `zone_id`, `order_date`, `work_price`, `employee_id`, `discount_id`, `final_price`) values (0, @client_id, @client_id, @zone_id, @order_date, @work_price, @employee_id, @discount_id, @final_price)";
|
||||
"insert into `order` (`id`, `client_id`, `zone_id`, `order_date`, `service_id`, `employee_id`, `discount_id`, `final_price`) values (0, @client_id, @client_id, @zone_id, @order_date, @service_id, @employee_id, @discount_id, @final_price)";
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
|
|
@ -61,7 +98,7 @@ public class OrderRepository
|
|||
command.Parameters.AddWithValue("@client_id", order.ClientId);
|
||||
command.Parameters.AddWithValue("@zone_id", order.ZoneId);
|
||||
command.Parameters.AddWithValue("@order_date", order.OrderDate);
|
||||
command.Parameters.AddWithValue("@work_price", order.WorkPrice);
|
||||
command.Parameters.AddWithValue("@service_id", order.ServiceId);
|
||||
command.Parameters.AddWithValue("@employee_id", order.EmployeeId);
|
||||
command.Parameters.AddWithValue("@discount_id", order.DiscountId);
|
||||
command.Parameters.AddWithValue("@final_price", order.FinalPrice);
|
||||
|
|
@ -81,7 +118,7 @@ public class OrderRepository
|
|||
public bool UpdateOrder(Order order)
|
||||
{
|
||||
string sql =
|
||||
"update `order` set client_id = @client_id, zone_id = @zone_id, order_date = @order_date, work_price = @work_price, employee_id = @employee_id, discount_id = @discount_id, final_price = @final_price";
|
||||
"update `order` set client_id = @client_id, zone_id = @zone_id, order_date = @order_date, service_id = @service_id, employee_id = @employee_id, discount_id = @discount_id, final_price = @final_price";
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
|
|
@ -90,7 +127,7 @@ public class OrderRepository
|
|||
command.Parameters.AddWithValue("@client_id", order.ClientId);
|
||||
command.Parameters.AddWithValue("@zone_id", order.ZoneId);
|
||||
command.Parameters.AddWithValue("@order_date", order.OrderDate);
|
||||
command.Parameters.AddWithValue("@work_price", order.WorkPrice);
|
||||
command.Parameters.AddWithValue("@service_id", order.ServiceId);
|
||||
command.Parameters.AddWithValue("@employee_id", order.EmployeeId);
|
||||
command.Parameters.AddWithValue("@discount_id", order.DiscountId);
|
||||
command.Parameters.AddWithValue("@final_price", order.FinalPrice);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,117 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BathHouseManagmet.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MySqlConnector;
|
||||
|
||||
namespace BathHouseManagmet.Database;
|
||||
|
||||
public class ServiceRepository
|
||||
{
|
||||
MySqlConnection connection;
|
||||
|
||||
public ServiceRepository(IOptions<DatabaseConnection> connect)
|
||||
{
|
||||
connection = new MySqlConnection(connect.Value.ConnectionString);
|
||||
}
|
||||
|
||||
public List<Service> GetServices()
|
||||
{
|
||||
List<Service> result = new();
|
||||
string sql = "select * from `service`";
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
using (var command = new MySqlCommand(sql, connection))
|
||||
using (var reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
result.Add(new Service
|
||||
{
|
||||
Id = reader.GetInt32("id"),
|
||||
Name = reader.GetString("name"),
|
||||
Description = reader.GetString("description"),
|
||||
Price = reader.GetInt32("price")
|
||||
});
|
||||
}
|
||||
}
|
||||
connection.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool InsertService(Service service)
|
||||
{
|
||||
string sql = "insert into `service` (`id`, `name`, `description`, `price`) values (0, @name, @description, @price)";
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
using (var command = new MySqlCommand(sql, connection))
|
||||
{
|
||||
command.Parameters.AddWithValue("@id", service.Id);
|
||||
command.Parameters.AddWithValue("@name", service.Name);
|
||||
command.Parameters.AddWithValue("@description", service.Description);
|
||||
command.Parameters.AddWithValue("@price", service.Price);
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
connection.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
connection.Close();
|
||||
return false;
|
||||
}
|
||||
connection.Close();
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool UpdateService(Service service)
|
||||
{
|
||||
string sql = "update `service` set name = @name, description = @description, price = @price";
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
using (var command = new MySqlCommand(sql, connection))
|
||||
{
|
||||
command.Parameters.AddWithValue("@name", service.Name);
|
||||
command.Parameters.AddWithValue("@description", service.Description);
|
||||
command.Parameters.AddWithValue("@price", service.Price);
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
connection.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
connection.Close();
|
||||
return false;
|
||||
}
|
||||
connection.Close();
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool DeleteService(Service service)
|
||||
{
|
||||
string sql = "delete from `service` where `id` =" + service.Id;
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
using (var command = new MySqlCommand(sql, connection))
|
||||
{
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
connection.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
connection.Close();
|
||||
return false;
|
||||
}
|
||||
connection.Close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -8,8 +8,15 @@ public class Order
|
|||
public int ClientId { get; set; }
|
||||
public int ZoneId { get; set; }
|
||||
public DateTime OrderDate { get; set; }
|
||||
public int WorkPrice { get; set; }
|
||||
public int ServiceId { get; set; }
|
||||
public int EmployeeId { get; set; }
|
||||
public int DiscountId { get; set; }
|
||||
public int FinalPrice { get; set; }
|
||||
public Client Client { get; set; }
|
||||
public Employee Employee { get; set; }
|
||||
public Zone Zone { get; set; }
|
||||
public Position Position { get; set; }
|
||||
public Discount Discount { get; set; }
|
||||
public Service Service { get; set; }
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
namespace BathHouseManagmet.Models;
|
||||
|
||||
public class Service
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public int Price { get; set; }
|
||||
}
|
||||
|
|
@ -25,6 +25,12 @@ sealed class Program
|
|||
s.Configure<DatabaseConnection>(c.Configuration.GetSection("DatabaseConnection"));
|
||||
s.AddTransient<MainWindow>();
|
||||
s.AddTransient<MainWindowViewModel>();
|
||||
s.AddTransient<DiscountRepository>();
|
||||
s.AddTransient<ClientRepository>();
|
||||
s.AddTransient<EmployeeRepository>();
|
||||
s.AddTransient<OrderRepository>();
|
||||
s.AddTransient<PositionRepository>();
|
||||
s.AddTransient<ZoneRepository>();
|
||||
}).Build();
|
||||
BuildAvaloniaApp(host.Services)
|
||||
.StartWithClassicDesktopLifetime(args);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,25 @@
|
|||
namespace BathHouseManagmet.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BathHouseManagmet.Database;
|
||||
using BathHouseManagmet.Models;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace BathHouseManagmet.ViewModels;
|
||||
|
||||
public partial class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly EmployeeRepository _employeeRepository;
|
||||
private readonly OrderRepository _orderRepository;
|
||||
|
||||
[ObservableProperty] List<Order> orders;
|
||||
|
||||
public MainWindowViewModel(IServiceProvider serviceProvider, EmployeeRepository employeeRepository, OrderRepository orderRepository)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
_employeeRepository = employeeRepository;
|
||||
_orderRepository = orderRepository;
|
||||
|
||||
Orders = orderRepository.GetOrders();
|
||||
}
|
||||
}
|
||||
|
|
@ -8,5 +8,28 @@
|
|||
x:DataType="vm:MainWindowViewModel"
|
||||
Icon="/Assets/avalonia-logo.ico"
|
||||
Title="BathHouseManagment">
|
||||
|
||||
<StackPanel>
|
||||
<TabControl TabStripPlacement="Left">
|
||||
<TabItem Header="Основная информация">
|
||||
<TabControl TabStripPlacement="Top">
|
||||
<TabItem Header="Заказы">
|
||||
<DataGrid ItemsSource="{Binding Orders}" AutoGenerateColumns="False">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Дата заказа" Binding="{Binding OrderDate}"/>
|
||||
<DataGridTextColumn Header="ID клиента" Binding="{Binding ClientId}"/>
|
||||
<DataGridTextColumn Header="ID скидки" Binding="{Binding DiscountId}"/>
|
||||
<DataGridTextColumn Header="ID Сотрудника" Binding="{Binding EmployeeId}"/>
|
||||
<DataGridTextColumn Header="ID услуги" Binding="{Binding ServiceId}"/>
|
||||
<DataGridTextColumn Header="ID зоны" Binding="{Binding ZoneId}"/>
|
||||
<DataGridTextColumn Header="Окончательная цена" Binding="{Binding FinalPrice}"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</TabItem>
|
||||
<TabItem Header="Сотрудники">
|
||||
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</StackPanel>
|
||||
</Window>
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -13,7 +13,7 @@ using System.Reflection;
|
|||
[assembly: System.Reflection.AssemblyCompanyAttribute("BathHouseManagmet")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4d0b4a63d29885a351c12ee66035741bb67c868f")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+55e84ef57c6abfe4ef4f4ef588ea91f719ce8536")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("BathHouseManagmet")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("BathHouseManagmet")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
00710766fbaba364e5f0fd3c7dc3d271457e9a7b5c0166076f7bdc3704b53eb6
|
||||
af96d54e4de83c2d92c24c535a5ffbc3bfff4696e1e3b1ef13b37dfd8a84647a
|
||||
|
|
|
|||
Loading…
Reference in New Issue