Начальный этап

This commit is contained in:
maxnes3 2023-03-27 21:53:15 +04:00
parent cbe4ef67ce
commit 853795e9d7
37 changed files with 1341 additions and 126 deletions

View File

@ -0,0 +1,120 @@
using ComputersShopContracts.BindingModels;
using ComputersShopContracts.BusinessLogicContracts;
using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts;
using ComputersShopContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopBusinessLogic.BusinessLogics
{
public class ClientLogic : IClientLogic
{
private readonly ILogger _logger;
private readonly IClientStorage _clientStorage;
public ClientLogic(ILogger<ClientLogic> logger, IClientStorage clientStorage)
{
_logger = logger;
_clientStorage = clientStorage;
}
public bool Create(ClientBindingModel model)
{
CheckModel(model);
if (_clientStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(ClientBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_clientStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public ClientViewModel? ReadElement(ClientSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ClientFIO:{ClientFIO}. Id:{ Id}", model.ClientFIO, model.Id);
var element = _clientStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<ClientViewModel>? ReadList(ClientSearchModel? model)
{
_logger.LogInformation("ReadList. ClientFIO:{ClientFIO}. Id:{Id}", model?.ClientFIO, model?.Id);
var list = model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(ClientBindingModel model)
{
CheckModel(model);
if (_clientStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(ClientBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ClientFIO))
{
throw new ArgumentNullException("Нет ФИО клиента", nameof(model.ClientFIO));
}
if (string.IsNullOrEmpty(model.Email))
{
throw new ArgumentNullException("У клиента отсутствует почта", nameof(model.Email));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("У клиента отсутствует пароль", nameof(model.Email));
}
_logger.LogInformation("Client. ClientID:{Id}. ClientFIO: {ClientFIO}. Email:{ Email}. Password: { Password}", model.Id, model.ClientFIO, model.Email, model.Password);
var element = _clientStorage.GetElement(new ClientSearchModel
{
Email = model.Email
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Такой клиент уже существует");
}
}
}
}

View File

@ -0,0 +1,17 @@
using ComputersShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopContracts.BindingModels
{
public class ClientBindingModel : IClientModel
{
public int Id { get; set; }
public string ClientFIO { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
}
}

View File

@ -12,6 +12,7 @@ namespace ComputersShopContracts.BindingModels
{
public int Id { get; set; }
public int ComputerId { get; set; }
public int ClientId { get; set; }
public int Count { get; set; }
public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;

View File

@ -0,0 +1,24 @@
using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels;
using ComputersShopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopContracts.BusinessLogicContracts
{
public interface IClientLogic
{
List<ClientViewModel>? ReadList(ClientSearchModel? model);
ClientViewModel? ReadElement(ClientSearchModel model);
bool Create(ClientBindingModel model);
bool Update(ClientBindingModel model);
bool Delete(ClientBindingModel model);
}
}

View File

@ -0,0 +1,20 @@
using ComputersShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopContracts.SearchModels
{
public class ClientSearchModel
{
public int? Id { get; set; }
public string? ClientFIO { get; set; }
public string? Email { get; set; }
public string? Password { get; set; }
}
}

View File

@ -11,5 +11,6 @@ namespace ComputersShopContracts.SearchModels
public int? Id { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public int? ClientId { get; set; }
}
}

View File

@ -0,0 +1,26 @@
using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels;
using ComputersShopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopContracts.StoragesContracts
{
public interface IClientStorage
{
List<ClientViewModel> GetFullList();
List<ClientViewModel> GetFilteredList(ClientSearchModel model);
ClientViewModel? GetElement(ClientSearchModel model);
ClientViewModel? Insert(ClientBindingModel model);
ClientViewModel? Update(ClientBindingModel model);
ClientViewModel? Delete(ClientBindingModel model);
}
}

View File

@ -0,0 +1,24 @@
using ComputersShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopContracts.ViewModels
{
public class ClientViewModel : IClientModel
{
public int Id { get; set; }
[DisplayName("ФИО клиента")]
public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Логин (эл. почта)")]
public string Email { get; set; } = string.Empty;
[DisplayName("Пароль")]
public string Password { get; set; } = string.Empty;
}
}

View File

@ -14,6 +14,9 @@ namespace ComputersShopContracts.ViewModels
[DisplayName("Номер")]
public int Id { get; set; }
public int ComputerId { get; set; }
public int ClientId { get; set; }
[DisplayName("Фамилия клиента")]
public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Компьютер")]
public string ComputerName { get; set; } = string.Empty;
[DisplayName("Количество")]

View File

@ -14,7 +14,7 @@ namespace ComputersShopDataBaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=ComputersShopDatabaseFull;Username=postgres;Password=adam200396789");
optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=ComputersShopDatabaseFullLab5;Username=postgres;Password=adam200396789");
}
base.OnConfiguring(optionsBuilder);
}
@ -22,6 +22,7 @@ namespace ComputersShopDataBaseImplement
public virtual DbSet<Computer> Computers { set; get; }
public virtual DbSet<ComputerComponent> ComputerComponents { set; get; }
public virtual DbSet<Order> Orders { set; get; }
}
public virtual DbSet<Client> Clients { set; get; }
}
}

View File

@ -0,0 +1,92 @@
using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts;
using ComputersShopContracts.ViewModels;
using ComputersShopDataBaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopDataBaseImplement.Implements
{
public class ClientStorage : IClientStorage
{
public ClientViewModel? Delete(ClientBindingModel model)
{
using var context = new ComputersShopDataBase();
var res = context.Clients.FirstOrDefault(x => x.Id == model.Id);
if (res != null)
{
context.Clients.Remove(res);
context.SaveChanges();
}
return res?.GetViewModel;
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
using var context = new ComputersShopDataBase();
if (model.Id.HasValue)
return context.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
if (model.Email != null && model.Password != null)
return context.Clients
.FirstOrDefault(x => x.Email.Equals(model.Email)
&& x.Password.Equals(model.Password))
?.GetViewModel;
if (model.Email != null)
return context.Clients.FirstOrDefault(x => x.Email.Equals(model.Email))?.GetViewModel;
return null;
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{
if (model == null)
{
return new();
}
if (model.Id.HasValue)
{
var res = GetElement(model);
return res != null ? new() { res } : new();
}
if (model.Email != null)
{
using var context = new ComputersShopDataBase();
return context.Clients
.Where(x => x.Email.Contains(model.Email))
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public List<ClientViewModel> GetFullList()
{
using var context = new ComputersShopDataBase();
return context.Clients.Select(x => x.GetViewModel).ToList();
}
public ClientViewModel? Insert(ClientBindingModel model)
{
using var context = new ComputersShopDataBase();
var res = Client.Create(model);
if (res != null)
{
context.Clients.Add(res);
context.SaveChanges();
}
return res?.GetViewModel;
}
public ClientViewModel? Update(ClientBindingModel model)
{
using var context = new ComputersShopDataBase();
var res = context.Clients.FirstOrDefault(x => x.Id == model.Id);
res?.Update(model);
context.SaveChanges();
return res?.GetViewModel;
}
}
}

View File

@ -17,49 +17,60 @@ namespace ComputersShopDataBaseImplement.Implements
public OrderViewModel? Delete(OrderBindingModel model)
{
using var context = new ComputersShopDataBase();
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
var element = context.Orders.Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
context.Orders.Remove(element);
context.SaveChanges();
return GetViewModel(element);
}
return null;
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
using var context = new ComputersShopDataBase();
if (!model.Id.HasValue)
{
return null;
}
using var context = new ComputersShopDataBase();
return GetViewModel(context.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)));
return GetViewModel(context.Orders.Include(x => x.Client).FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id));
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue)
if (model.Id.HasValue)
{
return new();
var result = GetElement(model);
return result != null ? new() { result } : new();
}
using var context = new ComputersShopDataBase();
return context.Orders.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo).Select(x => GetViewModel(x)).ToList();
if (model.DateFrom.HasValue && model.DateTo.HasValue)
{
return context.Orders
.Where(x => model.DateFrom <= x.DateCreate.Date && x.DateCreate <= model.DateTo)
.Include(x => x.Client)
.Select(x => GetViewModel(x))
.ToList();
}
if (model.ClientId.HasValue)
{
return context.Orders
.Where(x => x.Client.Id == model.ClientId)
.Include(x => x.Client)
.Select(x => GetViewModel(x))
.ToList();
}
return new();
}
public List<OrderViewModel> GetFullList()
{
using var context = new ComputersShopDataBase();
return context.Orders.Select(x => GetViewModel(x)).ToList();
return context.Orders
.Include(x => x.Client)
.Select(x => GetViewModel(x))
.ToList();
}
public OrderViewModel? Insert(OrderBindingModel model)
@ -80,17 +91,15 @@ namespace ComputersShopDataBaseImplement.Implements
public OrderViewModel? Update(OrderBindingModel model)
{
using var context = new ComputersShopDataBase();
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
var order = context.Orders
.Include(x => x.Client)
.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
}
order.Update(model);
context.SaveChanges();
return GetViewModel(order);
}
@ -98,8 +107,10 @@ namespace ComputersShopDataBaseImplement.Implements
{
var viewModel = order.GetViewModel;
using var context = new ComputersShopDataBase();
var element = context.Computers.FirstOrDefault(x => x.Id == order.ComputerId);
viewModel.ComputerName = element.ComputerName;
var comp = context.Computers.FirstOrDefault(x => x.Id == order.ComputerId);
var client = context.Clients.FirstOrDefault(x => x.Id == order.ClientId);
viewModel.ComputerName = comp.ComputerName;
viewModel.ClientFIO = client.ClientFIO;
return viewModel;
}
}

View File

@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace ComputersShopDataBaseImplement.Migrations
{
[DbContext(typeof(ComputersShopDataBase))]
[Migration("20230227200236_Init")]
partial class Init
[Migration("20230327172507_InitMigration")]
partial class InitMigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -25,6 +25,31 @@ namespace ComputersShopDataBaseImplement.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
@ -99,6 +124,9 @@ namespace ComputersShopDataBaseImplement.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("integer");
b.Property<int>("ComputerId")
.HasColumnType("integer");
@ -119,6 +147,8 @@ namespace ComputersShopDataBaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("ComputerId");
b.ToTable("Orders");
@ -145,13 +175,24 @@ namespace ComputersShopDataBaseImplement.Migrations
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Order", b =>
{
b.HasOne("ComputersShopDataBaseImplement.Models.Computer", "Computer")
b.HasOne("ComputersShopDataBaseImplement.Models.Client", "Client")
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputersShopDataBaseImplement.Models.Computer", null)
.WithMany("Orders")
.HasForeignKey("ComputerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Computer");
b.Navigation("Client");
});
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Client", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Component", b =>

View File

@ -7,11 +7,26 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace ComputersShopDataBaseImplement.Migrations
{
/// <inheritdoc />
public partial class Init : Migration
public partial class InitMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Clients",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ClientFIO = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Clients", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Components",
columns: table => new
@ -74,6 +89,7 @@ namespace ComputersShopDataBaseImplement.Migrations
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ComputerId = table.Column<int>(type: "integer", nullable: false),
ClientId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false),
Sum = table.Column<double>(type: "double precision", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false),
@ -83,6 +99,12 @@ namespace ComputersShopDataBaseImplement.Migrations
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Computers_ComputerId",
column: x => x.ComputerId,
@ -101,6 +123,11 @@ namespace ComputersShopDataBaseImplement.Migrations
table: "ComputerComponents",
column: "ComputerId");
migrationBuilder.CreateIndex(
name: "IX_Orders_ClientId",
table: "Orders",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_Orders_ComputerId",
table: "Orders",
@ -119,6 +146,9 @@ namespace ComputersShopDataBaseImplement.Migrations
migrationBuilder.DropTable(
name: "Components");
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropTable(
name: "Computers");
}

View File

@ -22,6 +22,31 @@ namespace ComputersShopDataBaseImplement.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
@ -96,6 +121,9 @@ namespace ComputersShopDataBaseImplement.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("integer");
b.Property<int>("ComputerId")
.HasColumnType("integer");
@ -116,6 +144,8 @@ namespace ComputersShopDataBaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("ComputerId");
b.ToTable("Orders");
@ -142,13 +172,24 @@ namespace ComputersShopDataBaseImplement.Migrations
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Order", b =>
{
b.HasOne("ComputersShopDataBaseImplement.Models.Computer", "Computer")
b.HasOne("ComputersShopDataBaseImplement.Models.Client", "Client")
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputersShopDataBaseImplement.Models.Computer", null)
.WithMany("Orders")
.HasForeignKey("ComputerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Computer");
b.Navigation("Client");
});
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Client", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Component", b =>

View File

@ -0,0 +1,64 @@
using ComputersShopContracts.BindingModels;
using ComputersShopContracts.ViewModels;
using ComputersShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopDataBaseImplement.Models
{
public class Client : IClientModel
{
[Required]
public string ClientFIO { get; private set; } = string.Empty;
[Required]
public string Email { get; private set; } = string.Empty;
[Required]
public string Password { get; private set; } = string.Empty;
public int Id { get; private set; }
[ForeignKey("ClientId")]
public virtual List<Order> Orders { get; set; } = new();
public static Client? Create(ClientBindingModel model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
ClientFIO = model.ClientFIO,
Email = model.Email,
Password = model.Password
};
}
public void Update(ClientBindingModel model)
{
if (model == null)
{
return;
}
ClientFIO = model.ClientFIO;
Email = model.Email;
Password = model.Password;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
ClientFIO = ClientFIO,
Email = Email,
Password = Password,
};
}
}

View File

@ -16,6 +16,8 @@ namespace ComputersShopDataBaseImplement.Models
[Required]
public int ComputerId { get; set; }
[Required]
public int ClientId { get; set; }
[Required]
public int Count { get; set; }
[Required]
public double Sum { get; set; }
@ -27,7 +29,9 @@ namespace ComputersShopDataBaseImplement.Models
public DateTime? DateImplement { get; set; }
public int Id { get; set; }
public Client Client { get; set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
@ -38,6 +42,7 @@ namespace ComputersShopDataBaseImplement.Models
{
Id = model.Id,
ComputerId = model.ComputerId,
ClientId = model.ClientId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
@ -60,6 +65,7 @@ namespace ComputersShopDataBaseImplement.Models
{
Id = Id,
ComputerId = ComputerId,
ClientId = ClientId,
Count = Count,
Sum = Sum,
Status = Status,

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopDataModels.Models
{
public interface IClientModel : IId
{
string ClientFIO { get; }
string Email { get; }
string Password { get; }
}
}

View File

@ -10,6 +10,7 @@ namespace ComputersShopDataModels.Models
public interface IOrderModel : IId
{
int ComputerId { get; }
int ClientId { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }

View File

@ -14,9 +14,11 @@ namespace ComputersShopFileImplement
private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string ComputerFileName = "Computer.xml";
private readonly string ClientFileName = "Client.xml";
public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; }
public List<Computer> Computers { get; private set; }
public List<Client> Clients { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
@ -28,11 +30,13 @@ namespace ComputersShopFileImplement
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
public void SaveComputers() => SaveData(Computers, ComputerFileName, "Computers", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement);
private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Computers = LoadData(ComputerFileName, "Computer", x => Computer.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{

View File

@ -0,0 +1,96 @@
using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts;
using ComputersShopContracts.ViewModels;
using ComputersShopFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopFileImplement.Implements
{
public class ClientStorage : IClientStorage
{
private readonly DataFileSingleton _source;
public ClientStorage()
{
_source = DataFileSingleton.GetInstance();
}
public ClientViewModel? Delete(ClientBindingModel model)
{
var res = _source.Clients.FirstOrDefault(x => x.Id == model.Id);
if (res != null)
{
_source.Clients.Remove(res);
_source.SaveClients();
}
return res?.GetViewModel;
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
if (model.Id.HasValue)
return _source.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
if (model.Email != null && model.Password != null)
return _source.Clients
.FirstOrDefault(x => x.Email.Equals(model.Email)
&& x.Password.Equals(model.Password))
?.GetViewModel;
if (model.Email != null)
return _source.Clients.FirstOrDefault(x => x.Email.Equals(model.Email))?.GetViewModel;
return null;
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{
if (model == null)
{
return new();
}
if (model.Id.HasValue)
{
var res = GetElement(model);
return res != null ? new() { res } : new();
}
if (model.Email != null)
{
return _source.Clients
.Where(x => x.Email.Contains(model.Email))
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public List<ClientViewModel> GetFullList()
{
return _source.Clients.Select(x => x.GetViewModel).ToList();
}
public ClientViewModel? Insert(ClientBindingModel model)
{
model.Id = _source.Clients.Count > 0 ? _source.Clients.Max(x => x.Id) + 1 : 1;
var res = Client.Create(model);
if (res != null)
{
_source.Clients.Add(res);
_source.SaveClients();
}
return res?.GetViewModel;
}
public ClientViewModel? Update(ClientBindingModel model)
{
var res = _source.Clients.FirstOrDefault(x => x.Id == model.Id);
if (res != null)
{
res.Update(model);
_source.SaveClients();
}
return res?.GetViewModel;
}
}
}

View File

@ -31,11 +31,22 @@ namespace ComputersShopFileImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue)
if (!model.Id.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue)
{
return new();
return source.Orders
.Where(x => model.DateFrom <= x.DateCreate.Date && x.DateCreate <= model.DateTo)
.Select(x => GetViewModel(x))
.ToList();
}
return source.Orders.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo).Select(x => GetViewModel(x)).ToList();
if (!model.Id.HasValue && model.ClientId.HasValue)
{
return source.Orders
.Where(x => x.ClientId == model.ClientId)
.Select(x => GetViewModel(x))
.ToList();
}
var result = GetElement(model);
return result != null ? new() { result } : new();
}
public List<OrderViewModel> GetFullList()
@ -90,6 +101,14 @@ namespace ComputersShopFileImplement.Implements
break;
}
}
foreach (var client in source.Clients)
{
if (client.Id == order.ClientId)
{
viewModel.ClientFIO = client.ClientFIO;
break;
}
}
return viewModel;
}
}

View File

@ -0,0 +1,78 @@
using ComputersShopContracts.BindingModels;
using ComputersShopContracts.ViewModels;
using ComputersShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace ComputersShopFileImplement.Models
{
public class Client : IClientModel
{
public string ClientFIO { get; private set; } = string.Empty;
public string Email { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty;
public int Id { get; private set; }
public static Client? Create(ClientBindingModel model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
ClientFIO = model.ClientFIO,
Email = model.Email,
Password = model.Password
};
}
public static Client? Create(XElement element)
{
if (element == null)
{
return null;
}
return new()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ClientFIO = element.Element("FIO")!.Value,
Email = element.Element("Email")!.Value,
Password = element.Element("Password")!.Value,
};
}
public void Update(ClientBindingModel model)
{
if (model == null)
{
return;
}
ClientFIO = model.ClientFIO;
Email = model.Email;
Password = model.Password;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
ClientFIO = ClientFIO,
Email = Email,
Password = Password,
};
public XElement GetXElement => new("Client",
new XAttribute("Id", Id),
new XElement("FIO", ClientFIO),
new XElement("Email", Email),
new XElement("Password", Password)
);
}
}

View File

@ -15,6 +15,8 @@ namespace ComputersShopFileImplement.Models
{
public int ComputerId { get; private set; }
public int ClientId { get; set; }
public int Count { get; private set; }
public double Sum { get; private set; }
@ -37,6 +39,7 @@ namespace ComputersShopFileImplement.Models
{
Id = model.Id,
ComputerId = model.ComputerId,
ClientId = model.ClientId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
@ -55,6 +58,7 @@ namespace ComputersShopFileImplement.Models
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ComputerId = Convert.ToInt32(element.Element("ComputerId")!.Value),
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null),
@ -77,11 +81,7 @@ namespace ComputersShopFileImplement.Models
{
return;
}
ComputerId = model.ComputerId;
Count = model.Count;
Sum = model.Sum;
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
}
@ -89,6 +89,7 @@ namespace ComputersShopFileImplement.Models
{
Id = Id,
ComputerId = ComputerId,
ClientId = ClientId,
Count = Count,
Sum = Sum,
Status = Status,
@ -99,6 +100,7 @@ namespace ComputersShopFileImplement.Models
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XElement("ComputerId", ComputerId),
new XElement("ClientId", ClientId),
new XElement("Count", Count.ToString()),
new XElement("Sum", Sum.ToString()),
new XElement("Status", Status.ToString()),

View File

@ -13,11 +13,13 @@ namespace ComputersShopListImplement
public List<Component> Components { get; set; }
public List<Order> Orders { get; set; }
public List<Computer> Computers { get; set; }
public List<Client> Clients { get; set; }
private DataListSingleton()
{
Components = new List<Component>();
Orders = new List<Order>();
Computers = new List<Computer>();
Clients = new List<Client>();
}
public static DataListSingleton GetInstance()
{

View File

@ -0,0 +1,120 @@
using ComputersShopContracts.BindingModels;
using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts;
using ComputersShopContracts.ViewModels;
using ComputersShopListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopListImplement.Implements
{
public class ClientStorage : IClientStorage
{
private readonly DataListSingleton _source;
public ClientStorage()
{
_source = DataListSingleton.GetInstance();
}
public ClientViewModel? Delete(ClientBindingModel model)
{
for (int i = 0; i < _source.Clients.Count; ++i)
{
if (_source.Clients[i].Id == model.Id)
{
var element = _source.Clients[i];
_source.Clients.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
if (model.Id.HasValue)
{
foreach (var client in _source.Clients)
{
if (client.Id == model.Id)
{
return client.GetViewModel;
}
}
}
else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
{
foreach (var client in _source.Clients)
{
if (client.Email == model.Email && client.Password == model.Password)
{
return client.GetViewModel;
}
}
}
return null;
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{
var result = new List<ClientViewModel>();
if (string.IsNullOrEmpty(model.Email))
{
return result;
}
foreach (var client in _source.Clients)
{
if (client.Email.Contains(model.Email))
{
result.Add(client.GetViewModel);
}
}
return result;
}
public List<ClientViewModel> GetFullList()
{
var result = new List<ClientViewModel>();
foreach (var client in _source.Clients)
{
result.Add(client.GetViewModel);
}
return result;
}
public ClientViewModel? Insert(ClientBindingModel model)
{
model.Id = 1;
foreach (var client in _source.Clients)
{
if (model.Id <= client.Id)
{
model.Id = client.Id + 1;
}
}
var newClient = Client.Create(model);
if (newClient == null)
{
return null;
}
_source.Clients.Add(newClient);
return newClient.GetViewModel;
}
public ClientViewModel? Update(ClientBindingModel model)
{
foreach (var client in _source.Clients)
{
if (client.Id == model.Id)
{
client.Update(model);
return client.GetViewModel;
}
}
return null;
}
}
}

View File

@ -31,15 +31,19 @@ namespace OrdersShopListImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
var result = new List<OrderViewModel>();
if (model == null)
foreach (var order in _source.Orders)
{
return result;
}
foreach (var Order in _source.Orders)
{
if (Order.Id == model.Id || model.DateFrom <= Order.DateCreate && Order.DateCreate <= model.DateTo)
if (order.Id == model.Id)
{
result.Add(GetViewModel(Order));
return new() { GetViewModel(order) };
}
else if (model.DateFrom.HasValue && model.DateTo.HasValue && model.DateFrom <= order.DateCreate.Date && order.DateCreate.Date <= model.DateTo)
{
result.Add(GetViewModel(order));
}
else if (model.ClientId.HasValue && order.ClientId == model.ClientId)
{
result.Add(GetViewModel(order));
}
}
return result;
@ -114,7 +118,15 @@ namespace OrdersShopListImplement.Implements
break;
}
}
return viewModel;
foreach (var client in _source.Clients)
{
if (client.Id == order.ClientId)
{
viewModel.ClientFIO = client.ClientFIO;
break;
}
}
return viewModel;
}
}
}

View File

@ -0,0 +1,50 @@
using ComputersShopContracts.BindingModels;
using ComputersShopContracts.ViewModels;
using ComputersShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputersShopListImplement.Models
{
public class Client : IClientModel
{
public int Id { get; set; }
public string ClientFIO { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public static Client? Create(ClientBindingModel? model)
{
if (model == null)
{
return null;
}
return new Client()
{
Id = model.Id,
ClientFIO = model.ClientFIO,
Email = model.Email,
Password = model.Password
};
}
public void Update(ClientBindingModel? model)
{
if (model == null)
{
return;
}
ClientFIO = model.ClientFIO;
Email = model.Email;
Password = model.Password;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
ClientFIO = ClientFIO,
Email = Email,
Password = Password
};
}
}

View File

@ -18,6 +18,8 @@ namespace ComputersShopListImplement.Models
public int ComputerId { get; private set; }
public int ClientId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
@ -38,6 +40,7 @@ namespace ComputersShopListImplement.Models
{
Id = model.Id,
ComputerId = model.ComputerId,
ClientId = model.ClientId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
@ -59,6 +62,7 @@ namespace ComputersShopListImplement.Models
{
Id = Id,
ComputerId = ComputerId,
ClientId = ClientId,
Count = Count,
Sum = Sum,
Status = Status,

View File

@ -0,0 +1,93 @@
namespace ComputersShopView
{
partial class FormClients
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
dataGridView = new DataGridView();
buttonDel = new Button();
buttonRef = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Left;
dataGridView.Location = new Point(0, 0);
dataGridView.Margin = new Padding(3, 2, 3, 2);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(381, 338);
dataGridView.TabIndex = 0;
//
// buttonDel
//
buttonDel.Location = new Point(414, 9);
buttonDel.Margin = new Padding(3, 2, 3, 2);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(82, 22);
buttonDel.TabIndex = 1;
buttonDel.Text = "Удалить";
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += ButtonDel_Click;
//
// buttonRef
//
buttonRef.Location = new Point(414, 46);
buttonRef.Margin = new Padding(3, 2, 3, 2);
buttonRef.Name = "buttonRef";
buttonRef.Size = new Size(82, 22);
buttonRef.TabIndex = 2;
buttonRef.Text = "Обновить";
buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += ButtonRef_Click;
//
// FormClients
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(522, 338);
Controls.Add(buttonRef);
Controls.Add(buttonDel);
Controls.Add(dataGridView);
Margin = new Padding(3, 2, 3, 2);
Name = "FormClients";
Text = "Клиенты";
Load += FormClients_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonDel;
private Button buttonRef;
}
}

View File

@ -0,0 +1,84 @@
using ComputersShopContracts.BindingModels;
using ComputersShopContracts.BusinessLogicContracts;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ComputersShopView
{
public partial class FormClients : Form
{
private readonly ILogger _logger;
private readonly IClientLogic _logic;
public FormClients(ILogger<FormClients> logger, IClientLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormClients_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка клиентов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки клиентов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
try
{
if (!_logic.Delete(new ClientBindingModel { Id = id }))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
_logger.LogInformation("Удаление клиента");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления клиента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
LoadData();
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -28,107 +28,127 @@
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.comboBoxComputer = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label();
this.textBoxCount = new System.Windows.Forms.TextBox();
this.textBoxSum = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
label1 = new Label();
comboBoxComputer = new ComboBox();
label2 = new Label();
textBoxCount = new TextBox();
textBoxSum = new TextBox();
label3 = new Label();
button1 = new Button();
button2 = new Button();
comboBoxClient = new ComboBox();
labelClients = new Label();
SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 15);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(74, 15);
this.label1.TabIndex = 0;
this.label1.Text = "Компьютер:";
label1.AutoSize = true;
label1.Location = new Point(12, 15);
label1.Name = "label1";
label1.Size = new Size(74, 15);
label1.TabIndex = 0;
label1.Text = "Компьютер:";
//
// comboBoxComputer
//
this.comboBoxComputer.FormattingEnabled = true;
this.comboBoxComputer.Location = new System.Drawing.Point(92, 12);
this.comboBoxComputer.Name = "comboBoxComputer";
this.comboBoxComputer.Size = new System.Drawing.Size(251, 23);
this.comboBoxComputer.TabIndex = 1;
this.comboBoxComputer.SelectedIndexChanged += new System.EventHandler(this.comboBoxComputer_SelectedIndexChanged);
comboBoxComputer.FormattingEnabled = true;
comboBoxComputer.Location = new Point(92, 12);
comboBoxComputer.Name = "comboBoxComputer";
comboBoxComputer.Size = new Size(251, 23);
comboBoxComputer.TabIndex = 1;
comboBoxComputer.SelectedIndexChanged += comboBoxComputer_SelectedIndexChanged;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 44);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(75, 15);
this.label2.TabIndex = 2;
this.label2.Text = "Количество:";
label2.AutoSize = true;
label2.Location = new Point(12, 44);
label2.Name = "label2";
label2.Size = new Size(75, 15);
label2.TabIndex = 2;
label2.Text = "Количество:";
//
// textBoxCount
//
this.textBoxCount.Location = new System.Drawing.Point(92, 41);
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(251, 23);
this.textBoxCount.TabIndex = 3;
this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged);
textBoxCount.Location = new Point(92, 41);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(251, 23);
textBoxCount.TabIndex = 3;
textBoxCount.TextChanged += TextBoxCount_TextChanged;
//
// textBoxSum
//
this.textBoxSum.Location = new System.Drawing.Point(92, 70);
this.textBoxSum.Name = "textBoxSum";
this.textBoxSum.ReadOnly = true;
this.textBoxSum.Size = new System.Drawing.Size(251, 23);
this.textBoxSum.TabIndex = 5;
textBoxSum.Location = new Point(92, 70);
textBoxSum.Name = "textBoxSum";
textBoxSum.ReadOnly = true;
textBoxSum.Size = new Size(251, 23);
textBoxSum.TabIndex = 5;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 73);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(48, 15);
this.label3.TabIndex = 4;
this.label3.Text = "Сумма:";
label3.AutoSize = true;
label3.Location = new Point(12, 73);
label3.Name = "label3";
label3.Size = new Size(48, 15);
label3.TabIndex = 4;
label3.Text = "Сумма:";
//
// button1
//
this.button1.Location = new System.Drawing.Point(187, 99);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 6;
this.button1.Text = "Сохранить";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.ButtonSave_Click);
button1.Location = new Point(187, 134);
button1.Name = "button1";
button1.Size = new Size(75, 23);
button1.TabIndex = 6;
button1.Text = "Сохранить";
button1.UseVisualStyleBackColor = true;
button1.Click += ButtonSave_Click;
//
// button2
//
this.button2.Location = new System.Drawing.Point(268, 99);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 7;
this.button2.Text = "Отмена";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.ButtonCancel_Click);
button2.Location = new Point(268, 134);
button2.Name = "button2";
button2.Size = new Size(75, 23);
button2.TabIndex = 7;
button2.Text = "Отмена";
button2.UseVisualStyleBackColor = true;
button2.Click += ButtonCancel_Click;
//
// comboBoxClient
//
comboBoxClient.FormattingEnabled = true;
comboBoxClient.Location = new Point(94, 99);
comboBoxClient.Name = "comboBoxClient";
comboBoxClient.Size = new Size(251, 23);
comboBoxClient.TabIndex = 9;
//
// labelClients
//
labelClients.AutoSize = true;
labelClients.Location = new Point(14, 102);
labelClients.Name = "labelClients";
labelClients.Size = new Size(49, 15);
labelClients.TabIndex = 8;
labelClients.Text = "Клиент:";
//
// FormCreateOrder
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(357, 130);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBoxSum);
this.Controls.Add(this.label3);
this.Controls.Add(this.textBoxCount);
this.Controls.Add(this.label2);
this.Controls.Add(this.comboBoxComputer);
this.Controls.Add(this.label1);
this.Name = "FormCreateOrder";
this.Text = "Заказ";
this.Load += new System.EventHandler(this.FormCreateOrder_Load);
this.ResumeLayout(false);
this.PerformLayout();
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(357, 169);
Controls.Add(comboBoxClient);
Controls.Add(labelClients);
Controls.Add(button2);
Controls.Add(button1);
Controls.Add(textBoxSum);
Controls.Add(label3);
Controls.Add(textBoxCount);
Controls.Add(label2);
Controls.Add(comboBoxComputer);
Controls.Add(label1);
Name = "FormCreateOrder";
Text = "Заказ";
Load += FormCreateOrder_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
@ -141,5 +161,7 @@
private Label label3;
private Button button1;
private Button button2;
private ComboBox comboBoxClient;
private Label labelClients;
}
}

View File

@ -19,13 +19,15 @@ namespace ComputersShopView
private readonly ILogger _logger;
private readonly IComputerLogic _logicC;
private readonly IOrderLogic _logicO;
private readonly IClientLogic _clientLogic;
public FormCreateOrder(ILogger<FormCreateOrder> logger, IComputerLogic logicC, IOrderLogic logicO)
public FormCreateOrder(ILogger<FormCreateOrder> logger, IComputerLogic logicC, IOrderLogic logicO, IClientLogic clientLogic)
{
InitializeComponent();
_logger = logger;
_logicC = logicC;
_logicO = logicO;
_clientLogic = clientLogic;
}
private void FormCreateOrder_Load(object sender, EventArgs e)
@ -42,7 +44,14 @@ namespace ComputersShopView
comboBoxComputer.DataSource = list;
comboBoxComputer.SelectedItem = null;
}
var clients = _clientLogic.ReadList(null);
if (clients != null)
{
comboBoxClient.DisplayMember = "ClientFIO";
comboBoxClient.ValueMember = "Id";
comboBoxClient.DataSource = clients;
comboBoxClient.SelectedItem = null;
}
}
catch (Exception ex)
{
@ -100,13 +109,14 @@ namespace ComputersShopView
var operationResult = _logicO.CreateOrder(new OrderBindingModel
{
ComputerId = Convert.ToInt32(comboBoxComputer.SelectedValue),
ClientId = Convert.ToInt32(comboBoxClient.SelectedValue),
Count = Convert.ToInt32(textBoxCount.Text),
Sum = Convert.ToDouble(textBoxSum.Text)
});
if (!operationResult)
{
throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах.");
}
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();

View File

@ -42,13 +42,14 @@
buttonOrderReady = new Button();
buttonIssuedOrder = new Button();
buttonRef = new Button();
клиентыToolStripMenuItem = new ToolStripMenuItem();
menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// menuStrip
//
menuStrip.Items.AddRange(new ToolStripItem[] { справочникToolStripMenuItem, отчётыToolStripMenuItem });
menuStrip.Items.AddRange(new ToolStripItem[] { справочникToolStripMenuItem, отчётыToolStripMenuItem, клиентыToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(1047, 24);
@ -163,6 +164,13 @@
buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += ButtonRef_Click;
//
// клиентыToolStripMenuItem
//
клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
клиентыToolStripMenuItem.Size = new Size(66, 20);
клиентыToolStripMenuItem.Text = "клиенты";
клиентыToolStripMenuItem.Click += ClientsToolStripMenuItem_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(7F, 15F);
@ -202,5 +210,6 @@
private ToolStripMenuItem списокКомпонентовToolStripMenuItem;
private ToolStripMenuItem компонентыПоКомпьютерамToolStripMenuItem;
private ToolStripMenuItem списокЗаказовToolStripMenuItem;
private ToolStripMenuItem клиентыToolStripMenuItem;
}
}

View File

@ -197,6 +197,15 @@ namespace ComputersShopView
}
}
private void ClientsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
if (service is FormClients form)
{
form.ShowDialog();
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();

View File

@ -39,17 +39,20 @@ namespace ComputersShopView
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IComputerStorage, ComputerStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IComputerLogic, ComputerLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<AbstractSaveToWord, SaveToWord>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
services.AddTransient<FormMain>();
services.AddTransient<FormClients>();
services.AddTransient<FormComponent>();
services.AddTransient<FormComponents>();
services.AddTransient<FormCreateOrder>();