diff --git a/WinFormUchetLab/UchetLabBusinessLogic/BusinessLogic/CheckerLogic.cs b/WinFormUchetLab/UchetLabBusinessLogic/BusinessLogic/CheckerLogic.cs new file mode 100644 index 0000000..9053249 --- /dev/null +++ b/WinFormUchetLab/UchetLabBusinessLogic/BusinessLogic/CheckerLogic.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UchetLabContracts.BindingModels; +using UchetLabContracts.BusinessLogicsContracts; +using UchetLabContracts.SearchModels; +using UchetLabContracts.StorageContracts; +using UchetLabContracts.ViewModels; + +namespace UchetLabBusinessLogic.BusinessLogic +{ + public class CheckerLogic : ICheckerLogic + { + ICheckerStorage _checkerStorage; + + public CheckerLogic(ICheckerStorage checkerStorage) + { + _checkerStorage = checkerStorage; + } + + public bool Create(CheckerBindingModel model) + { + CheckModel(model); + if (_checkerStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Delete(CheckerBindingModel model) + { + CheckModel(model, false); + if (_checkerStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public CheckerViewModel? ReadElement(CheckerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + var element = _checkerStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public List? ReadList(CheckerSearchModel? model) + { + var list = model == null ? _checkerStorage.GetFullList() : _checkerStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public bool Update(CheckerBindingModel model) + { + CheckModel(model); + if (_checkerStorage.Update(model) == null) + { + return false; + } + return true; + } + private void CheckModel(CheckerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.FIO)) + { + throw new ArgumentNullException("проверяющий не указан", nameof(model.FIO)); + } + } + } +} diff --git a/WinFormUchetLab/UchetLabBusinessLogic/BusinessLogic/LabLogic.cs b/WinFormUchetLab/UchetLabBusinessLogic/BusinessLogic/LabLogic.cs new file mode 100644 index 0000000..4f72b9e --- /dev/null +++ b/WinFormUchetLab/UchetLabBusinessLogic/BusinessLogic/LabLogic.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UchetLabContracts.BindingModels; +using UchetLabContracts.BusinessLogicsContracts; +using UchetLabContracts.SearchModels; +using UchetLabContracts.StorageContracts; +using UchetLabContracts.ViewModels; + +namespace UchetLabBusinessLogic.BusinessLogic +{ + public class LabLogic : ILabLogic + { + ILabStorage _labStorage; + + public LabLogic(ILabStorage labStorage) + { + _labStorage = labStorage; + } + + public bool Create(LabBindingModel model) + { + CheckModel(model); + if (_labStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Delete(LabBindingModel model) + { + CheckModel(model, false); + if (_labStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public LabViewModel? ReadElement(LabSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + var element = _labStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public List? ReadList(LabSearchModel? model) + { + var list = model == null ? _labStorage.GetFullList() : _labStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public bool Update(LabBindingModel model) + { + CheckModel(model); + if (_labStorage.Update(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(LabBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.LabTask)) + { + throw new ArgumentNullException("Нет задания лабораторной", nameof(model.LabTask)); + } + if (string.IsNullOrEmpty(model.Checker)) + { + throw new ArgumentNullException("Нет проверяющего лабораторной", nameof(model.Checker)); + } + if (string.IsNullOrEmpty(model.TaskImage)) + { + throw new ArgumentNullException("Нет картинки для лабораторной", nameof(model.TaskImage)); + } + } + } +} diff --git a/WinFormUchetLab/UchetLabBusinessLogic/UchetLabBusinessLogic.csproj b/WinFormUchetLab/UchetLabBusinessLogic/UchetLabBusinessLogic.csproj new file mode 100644 index 0000000..70c00e4 --- /dev/null +++ b/WinFormUchetLab/UchetLabBusinessLogic/UchetLabBusinessLogic.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/WinFormUchetLab/UchetLabContracts/BindingModels/CheckerBindingModel.cs b/WinFormUchetLab/UchetLabContracts/BindingModels/CheckerBindingModel.cs new file mode 100644 index 0000000..85a69b2 --- /dev/null +++ b/WinFormUchetLab/UchetLabContracts/BindingModels/CheckerBindingModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UchetLabDataModels.Models; + +namespace UchetLabContracts.BindingModels +{ + public class CheckerBindingModel : ICheckerModel + { + public int Id { get; set; } + public string FIO { get; set; } = string.Empty; + } +} diff --git a/WinFormUchetLab/UchetLabContracts/BindingModels/LabBindingModel.cs b/WinFormUchetLab/UchetLabContracts/BindingModels/LabBindingModel.cs new file mode 100644 index 0000000..5eb0c33 --- /dev/null +++ b/WinFormUchetLab/UchetLabContracts/BindingModels/LabBindingModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UchetLabDataModels.Models; + +namespace UchetLabContracts.BindingModels +{ + public class LabBindingModel : IlabModel + { + public int Id { get; set; } + public string LabTask { get; set; } = string.Empty; + public string TaskImage { get; set; } = string.Empty; + public string Checker { get; set; } = string.Empty; + public DateTime CheckDate { get; set; } = DateTime.Now; + } +} diff --git a/WinFormUchetLab/UchetLabContracts/BusinessLogicsContracts/ICheckerLogic.cs b/WinFormUchetLab/UchetLabContracts/BusinessLogicsContracts/ICheckerLogic.cs new file mode 100644 index 0000000..338f50d --- /dev/null +++ b/WinFormUchetLab/UchetLabContracts/BusinessLogicsContracts/ICheckerLogic.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UchetLabContracts.BindingModels; +using UchetLabContracts.SearchModels; +using UchetLabContracts.ViewModels; + +namespace UchetLabContracts.BusinessLogicsContracts +{ + public interface ICheckerLogic + { + List? ReadList(CheckerSearchModel? model); + CheckerViewModel? ReadElement(CheckerSearchModel model); + bool Create(CheckerBindingModel model); + bool Update(CheckerBindingModel model); + bool Delete(CheckerBindingModel model); + } +} diff --git a/WinFormUchetLab/UchetLabContracts/BusinessLogicsContracts/ILabLogic.cs b/WinFormUchetLab/UchetLabContracts/BusinessLogicsContracts/ILabLogic.cs new file mode 100644 index 0000000..9d8e7bb --- /dev/null +++ b/WinFormUchetLab/UchetLabContracts/BusinessLogicsContracts/ILabLogic.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UchetLabContracts.BindingModels; +using UchetLabContracts.SearchModels; +using UchetLabContracts.ViewModels; + +namespace UchetLabContracts.BusinessLogicsContracts +{ + public interface ILabLogic + { + List? ReadList(LabSearchModel? model); + LabViewModel? ReadElement(LabSearchModel model); + bool Create(LabBindingModel model); + bool Update(LabBindingModel model); + bool Delete(LabBindingModel model); + } +} diff --git a/WinFormUchetLab/UchetLabContracts/SearchModels/CheckerSearchModel.cs b/WinFormUchetLab/UchetLabContracts/SearchModels/CheckerSearchModel.cs new file mode 100644 index 0000000..207bdb6 --- /dev/null +++ b/WinFormUchetLab/UchetLabContracts/SearchModels/CheckerSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UchetLabContracts.SearchModels +{ + public class CheckerSearchModel + { + public int? Id { get; set; } + } +} diff --git a/WinFormUchetLab/UchetLabContracts/SearchModels/LabSearchModel.cs b/WinFormUchetLab/UchetLabContracts/SearchModels/LabSearchModel.cs new file mode 100644 index 0000000..5d279b5 --- /dev/null +++ b/WinFormUchetLab/UchetLabContracts/SearchModels/LabSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UchetLabContracts.SearchModels +{ + public class LabSearchModel + { + public int? Id { get; set; } + } +} diff --git a/WinFormUchetLab/UchetLabContracts/StorageContracts/ICheckerStorage.cs b/WinFormUchetLab/UchetLabContracts/StorageContracts/ICheckerStorage.cs new file mode 100644 index 0000000..fcff121 --- /dev/null +++ b/WinFormUchetLab/UchetLabContracts/StorageContracts/ICheckerStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UchetLabContracts.BindingModels; +using UchetLabContracts.SearchModels; +using UchetLabContracts.ViewModels; + +namespace UchetLabContracts.StorageContracts +{ + public interface ICheckerStorage + { + List GetFullList(); + List GetFilteredList(CheckerSearchModel model); + CheckerViewModel? GetElement(CheckerSearchModel model); + CheckerViewModel? Insert(CheckerBindingModel model); + CheckerViewModel? Update(CheckerBindingModel model); + CheckerViewModel? Delete(CheckerBindingModel model); + } +} diff --git a/WinFormUchetLab/UchetLabContracts/StorageContracts/ILabStorage.cs b/WinFormUchetLab/UchetLabContracts/StorageContracts/ILabStorage.cs new file mode 100644 index 0000000..459fcf1 --- /dev/null +++ b/WinFormUchetLab/UchetLabContracts/StorageContracts/ILabStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UchetLabContracts.BindingModels; +using UchetLabContracts.SearchModels; +using UchetLabContracts.ViewModels; + +namespace UchetLabContracts.StorageContracts +{ + public interface ILabStorage + { + List GetFullList(); + List GetFilteredList(LabSearchModel model); + LabViewModel? GetElement(LabSearchModel model); + LabViewModel? Insert(LabBindingModel model); + LabViewModel? Update(LabBindingModel model); + LabViewModel? Delete(LabBindingModel model); + } +} diff --git a/WinFormUchetLab/UchetLabContracts/UchetLabContracts.csproj b/WinFormUchetLab/UchetLabContracts/UchetLabContracts.csproj new file mode 100644 index 0000000..9f4ab5d --- /dev/null +++ b/WinFormUchetLab/UchetLabContracts/UchetLabContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/WinFormUchetLab/UchetLabContracts/ViewModels/CheckerViewModel.cs b/WinFormUchetLab/UchetLabContracts/ViewModels/CheckerViewModel.cs new file mode 100644 index 0000000..18b4b62 --- /dev/null +++ b/WinFormUchetLab/UchetLabContracts/ViewModels/CheckerViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UchetLabDataModels.Models; + +namespace UchetLabContracts.ViewModels +{ + public class CheckerViewModel : ICheckerModel + { + public int Id { get; set; } + public string FIO { get; set; } = string.Empty; + } +} diff --git a/WinFormUchetLab/UchetLabContracts/ViewModels/LabViewModel.cs b/WinFormUchetLab/UchetLabContracts/ViewModels/LabViewModel.cs new file mode 100644 index 0000000..f4e6ac0 --- /dev/null +++ b/WinFormUchetLab/UchetLabContracts/ViewModels/LabViewModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UchetLabDataModels.Models; + +namespace UchetLabContracts.ViewModels +{ + public class LabViewModel : IlabModel + { + public int Id { get; set; } + public string LabTask { get; set; } = string.Empty; + public string TaskImage { get; set; } = string.Empty; + public string Checker { get; set; } = string.Empty; + public DateTime CheckDate { get; set; } = DateTime.Now; + } +} diff --git a/WinFormUchetLab/UchetLabDataModels/Models/ICheckerModel.cs b/WinFormUchetLab/UchetLabDataModels/Models/ICheckerModel.cs new file mode 100644 index 0000000..0e088ed --- /dev/null +++ b/WinFormUchetLab/UchetLabDataModels/Models/ICheckerModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UchetLabDataModels.Models +{ + public interface ICheckerModel + { + public string FIO { get;} + } +} diff --git a/WinFormUchetLab/UchetLabDataModels/Models/IlabModel.cs b/WinFormUchetLab/UchetLabDataModels/Models/IlabModel.cs new file mode 100644 index 0000000..f09e53f --- /dev/null +++ b/WinFormUchetLab/UchetLabDataModels/Models/IlabModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UchetLabDataModels.Models +{ + public interface IlabModel + { + public string LabTask { get; } + public string TaskImage { get; } + public string Checker { get; } + public DateTime CheckDate { get; } + } +} diff --git a/WinFormUchetLab/UchetLabDataModels/UchetLabDataModels.csproj b/WinFormUchetLab/UchetLabDataModels/UchetLabDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/WinFormUchetLab/UchetLabDataModels/UchetLabDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/WinFormUchetLab/UchetLabDatabaseImplement/Implements/CheckerStorage.cs b/WinFormUchetLab/UchetLabDatabaseImplement/Implements/CheckerStorage.cs new file mode 100644 index 0000000..f60c276 --- /dev/null +++ b/WinFormUchetLab/UchetLabDatabaseImplement/Implements/CheckerStorage.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UchetLabContracts.BindingModels; +using UchetLabContracts.SearchModels; +using UchetLabContracts.StorageContracts; +using UchetLabContracts.ViewModels; +using UchetLabDatabaseImplement.Models; + +namespace UchetLabDatabaseImplement.Implements +{ + public class CheckerStorage : ICheckerStorage + { + public CheckerViewModel? Delete(CheckerBindingModel model) + { + using var context = new UchetLabDataBase(); + var element = context.Checkers.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Checkers.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public CheckerViewModel? GetElement(CheckerSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new UchetLabDataBase(); + return context.Checkers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + + public List GetFilteredList(CheckerSearchModel model) + { + using var context = new UchetLabDataBase(); + return context.Checkers + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new UchetLabDataBase(); + return context.Checkers + .Select(x => x.GetViewModel) + .ToList(); + } + + public CheckerViewModel? Insert(CheckerBindingModel model) + { + using var context = new UchetLabDataBase(); + using var transaction = context.Database.BeginTransaction(); + { + try + { + var newEl = Checker.Create(model); + if (newEl == null) + { + transaction.Rollback(); + return null; + } + context.Checkers.Add(newEl); + + context.SaveChanges(); + context.Database.CommitTransaction(); + + return newEl.GetViewModel; + } + catch (Exception) + { + transaction.Rollback(); + return null; + } + } + } + + public CheckerViewModel? Update(CheckerBindingModel model) + { + using var context = new UchetLabDataBase(); + using var transaction = context.Database.BeginTransaction(); + { + try + { + var el = context.Checkers.FirstOrDefault(x => x.Id == model.Id); + if (el == null) + { + transaction.Rollback(); + return null; + } + el.Update(model); + + context.SaveChanges(); + context.Database.CommitTransaction(); + + return el.GetViewModel; + } + catch (Exception) + { + transaction.Rollback(); + return null; + } + } + } + } +} diff --git a/WinFormUchetLab/UchetLabDatabaseImplement/Implements/LabStorage.cs b/WinFormUchetLab/UchetLabDatabaseImplement/Implements/LabStorage.cs new file mode 100644 index 0000000..7464ae9 --- /dev/null +++ b/WinFormUchetLab/UchetLabDatabaseImplement/Implements/LabStorage.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UchetLabContracts.BindingModels; +using UchetLabContracts.SearchModels; +using UchetLabContracts.StorageContracts; +using UchetLabContracts.ViewModels; +using UchetLabDatabaseImplement.Models; + +namespace UchetLabDatabaseImplement.Implements +{ + public class LabStorage : ILabStorage + { + public LabViewModel? Delete(LabBindingModel model) + { + using var context = new UchetLabDataBase(); + var element = context.Labs.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Labs.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public LabViewModel? GetElement(LabSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new UchetLabDataBase(); + return context.Labs.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + + public List GetFilteredList(LabSearchModel model) + { + using var context = new UchetLabDataBase(); + return context.Labs + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new UchetLabDataBase(); + return context.Labs + .Select(x => x.GetViewModel) + .ToList(); + } + + public LabViewModel? Insert(LabBindingModel model) + { + using var context = new UchetLabDataBase(); + using var transaction = context.Database.BeginTransaction(); + { + try + { + var newEl = Lab.Create(model); + if (newEl == null) + { + transaction.Rollback(); + return null; + } + context.Labs.Add(newEl); + + context.SaveChanges(); + context.Database.CommitTransaction(); + + return newEl.GetViewModel; + } + catch (Exception) + { + transaction.Rollback(); + return null; + } + } + } + + public LabViewModel? Update(LabBindingModel model) + { + using var context = new UchetLabDataBase(); + using var transaction = context.Database.BeginTransaction(); + { + try + { + var el = context.Labs.FirstOrDefault(x => x.Id == model.Id); + if (el == null) + { + transaction.Rollback(); + return null; + } + el.Update(model); + + context.SaveChanges(); + context.Database.CommitTransaction(); + + return el.GetViewModel; + } + catch (Exception) + { + transaction.Rollback(); + return null; + } + } + } + } +} diff --git a/WinFormUchetLab/UchetLabDatabaseImplement/Migrations/20241006183154_InitialCreate.Designer.cs b/WinFormUchetLab/UchetLabDatabaseImplement/Migrations/20241006183154_InitialCreate.Designer.cs new file mode 100644 index 0000000..73b24a8 --- /dev/null +++ b/WinFormUchetLab/UchetLabDatabaseImplement/Migrations/20241006183154_InitialCreate.Designer.cs @@ -0,0 +1,75 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using UchetLabDatabaseImplement; + +#nullable disable + +namespace UchetLabDatabaseImplement.Migrations +{ + [DbContext(typeof(UchetLabDataBase))] + [Migration("20241006183154_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("UchetLabDatabaseImplement.Models.Checker", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Checker"); + }); + + modelBuilder.Entity("UchetLabDatabaseImplement.Models.Lab", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CheckDate") + .HasColumnType("datetime2"); + + b.Property("Checker") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("LabTask") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TaskImage") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Labs"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WinFormUchetLab/UchetLabDatabaseImplement/Migrations/20241006183154_InitialCreate.cs b/WinFormUchetLab/UchetLabDatabaseImplement/Migrations/20241006183154_InitialCreate.cs new file mode 100644 index 0000000..93daaa0 --- /dev/null +++ b/WinFormUchetLab/UchetLabDatabaseImplement/Migrations/20241006183154_InitialCreate.cs @@ -0,0 +1,54 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace UchetLabDatabaseImplement.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Checker", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FIO = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Checker", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Labs", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + LabTask = table.Column(type: "nvarchar(max)", nullable: false), + TaskImage = table.Column(type: "nvarchar(max)", nullable: false), + Checker = table.Column(type: "nvarchar(max)", nullable: false), + CheckDate = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Labs", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Checker"); + + migrationBuilder.DropTable( + name: "Labs"); + } + } +} diff --git a/WinFormUchetLab/UchetLabDatabaseImplement/Migrations/UchetLabDataBaseModelSnapshot.cs b/WinFormUchetLab/UchetLabDatabaseImplement/Migrations/UchetLabDataBaseModelSnapshot.cs new file mode 100644 index 0000000..35adead --- /dev/null +++ b/WinFormUchetLab/UchetLabDatabaseImplement/Migrations/UchetLabDataBaseModelSnapshot.cs @@ -0,0 +1,72 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using UchetLabDatabaseImplement; + +#nullable disable + +namespace UchetLabDatabaseImplement.Migrations +{ + [DbContext(typeof(UchetLabDataBase))] + partial class UchetLabDataBaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("UchetLabDatabaseImplement.Models.Checker", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Checker"); + }); + + modelBuilder.Entity("UchetLabDatabaseImplement.Models.Lab", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CheckDate") + .HasColumnType("datetime2"); + + b.Property("Checker") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("LabTask") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TaskImage") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Labs"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/WinFormUchetLab/UchetLabDatabaseImplement/Models/Checker.cs b/WinFormUchetLab/UchetLabDatabaseImplement/Models/Checker.cs new file mode 100644 index 0000000..dabd9a0 --- /dev/null +++ b/WinFormUchetLab/UchetLabDatabaseImplement/Models/Checker.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UchetLabContracts.BindingModels; +using UchetLabContracts.ViewModels; +using UchetLabDataModels.Models; + +namespace UchetLabDatabaseImplement.Models +{ + public class Checker : ICheckerModel + { + public int Id { get; private set; } + [Required] + public string FIO { get; private set; } = string.Empty; + public static Checker? Create(CheckerBindingModel model) + { + return new Checker() + { + Id = model.Id, + FIO = model.FIO, + }; + } + + public void Update(CheckerBindingModel model) + { + FIO = model.FIO; + } + public CheckerViewModel GetViewModel => new() + { + Id = Id, + FIO = FIO, + }; + } +} diff --git a/WinFormUchetLab/UchetLabDatabaseImplement/Models/Lab.cs b/WinFormUchetLab/UchetLabDatabaseImplement/Models/Lab.cs new file mode 100644 index 0000000..75deac0 --- /dev/null +++ b/WinFormUchetLab/UchetLabDatabaseImplement/Models/Lab.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UchetLabContracts.BindingModels; +using UchetLabContracts.StorageContracts; +using UchetLabContracts.ViewModels; +using UchetLabDataModels.Models; + +namespace UchetLabDatabaseImplement.Models +{ + public class Lab : IlabModel + { + public int Id { get; private set; } + [Required] + public string LabTask { get; private set; } = string.Empty; + [Required] + public string TaskImage { get; private set; } = string.Empty; + [Required] + public string Checker { get; private set; } = string.Empty; + public DateTime CheckDate { get; private set; } = DateTime.Now; + public static Lab? Create(LabBindingModel model) + { + return new Lab() + { + Id = model.Id, + LabTask = model.LabTask, + TaskImage = model.TaskImage, + Checker = model.Checker, + CheckDate = model.CheckDate, + }; + } + public void Update(LabBindingModel model) + { + LabTask = model.LabTask; + TaskImage = model.TaskImage; + Checker = model.Checker; + CheckDate = model.CheckDate; + } + public LabViewModel GetViewModel => new() + { + Id = Id, + LabTask = LabTask, + TaskImage = TaskImage, + Checker = Checker, + CheckDate = CheckDate, + }; + } +} diff --git a/WinFormUchetLab/UchetLabDatabaseImplement/UchetLabDataBase.cs b/WinFormUchetLab/UchetLabDatabaseImplement/UchetLabDataBase.cs new file mode 100644 index 0000000..86691d1 --- /dev/null +++ b/WinFormUchetLab/UchetLabDatabaseImplement/UchetLabDataBase.cs @@ -0,0 +1,24 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UchetLabDatabaseImplement.Models; + +namespace UchetLabDatabaseImplement +{ + public class UchetLabDataBase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=UchetLabDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + public virtual DbSet Labs { set; get; } + public virtual DbSet Checkers { set; get; } + } +} diff --git a/WinFormUchetLab/UchetLabDatabaseImplement/UchetLabDatabaseImplement.csproj b/WinFormUchetLab/UchetLabDatabaseImplement/UchetLabDatabaseImplement.csproj new file mode 100644 index 0000000..e4c86fe --- /dev/null +++ b/WinFormUchetLab/UchetLabDatabaseImplement/UchetLabDatabaseImplement.csproj @@ -0,0 +1,23 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/WinFormUchetLab/WinFormUchetLab.sln b/WinFormUchetLab/WinFormUchetLab.sln new file mode 100644 index 0000000..9af638b --- /dev/null +++ b/WinFormUchetLab/WinFormUchetLab.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35208.52 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormUchetLab", "WinFormUchetLab\WinFormUchetLab.csproj", "{C8C620EA-CCC9-4031-8753-57647F65440E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UchetLabDataModels", "UchetLabDataModels\UchetLabDataModels.csproj", "{AC162555-3770-4CB5-A5DF-7F85135D49B4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UchetLabContracts", "UchetLabContracts\UchetLabContracts.csproj", "{4DF262DD-81DF-4B26-8978-5334DE8E9F67}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UchetLabBusinessLogic", "UchetLabBusinessLogic\UchetLabBusinessLogic.csproj", "{D7D2300F-78BE-49A4-9733-1A2B52192864}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UchetLabDatabaseImplement", "UchetLabDatabaseImplement\UchetLabDatabaseImplement.csproj", "{F6CB8BDD-E2B3-4449-B150-7D67FA013611}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C8C620EA-CCC9-4031-8753-57647F65440E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C8C620EA-CCC9-4031-8753-57647F65440E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C8C620EA-CCC9-4031-8753-57647F65440E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C8C620EA-CCC9-4031-8753-57647F65440E}.Release|Any CPU.Build.0 = Release|Any CPU + {AC162555-3770-4CB5-A5DF-7F85135D49B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AC162555-3770-4CB5-A5DF-7F85135D49B4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AC162555-3770-4CB5-A5DF-7F85135D49B4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AC162555-3770-4CB5-A5DF-7F85135D49B4}.Release|Any CPU.Build.0 = Release|Any CPU + {4DF262DD-81DF-4B26-8978-5334DE8E9F67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4DF262DD-81DF-4B26-8978-5334DE8E9F67}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4DF262DD-81DF-4B26-8978-5334DE8E9F67}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4DF262DD-81DF-4B26-8978-5334DE8E9F67}.Release|Any CPU.Build.0 = Release|Any CPU + {D7D2300F-78BE-49A4-9733-1A2B52192864}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D7D2300F-78BE-49A4-9733-1A2B52192864}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D7D2300F-78BE-49A4-9733-1A2B52192864}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D7D2300F-78BE-49A4-9733-1A2B52192864}.Release|Any CPU.Build.0 = Release|Any CPU + {F6CB8BDD-E2B3-4449-B150-7D67FA013611}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F6CB8BDD-E2B3-4449-B150-7D67FA013611}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F6CB8BDD-E2B3-4449-B150-7D67FA013611}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F6CB8BDD-E2B3-4449-B150-7D67FA013611}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8146D85F-915C-4290-A88E-599819ADEFDD} + EndGlobalSection +EndGlobal diff --git a/WinFormUchetLab/WinFormUchetLab/Form1.Designer.cs b/WinFormUchetLab/WinFormUchetLab/Form1.Designer.cs new file mode 100644 index 0000000..83cb014 --- /dev/null +++ b/WinFormUchetLab/WinFormUchetLab/Form1.Designer.cs @@ -0,0 +1,58 @@ +namespace WinFormUchetLab +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + controlDataTableTable1 = new ControlsLibraryNet60.Data.ControlDataTableTable(); + SuspendLayout(); + // + // controlDataTableTable1 + // + controlDataTableTable1.Location = new Point(0, 0); + controlDataTableTable1.Margin = new Padding(4, 5, 4, 5); + controlDataTableTable1.Name = "controlDataTableTable1"; + controlDataTableTable1.SelectedRowIndex = -1; + controlDataTableTable1.Size = new Size(799, 447); + controlDataTableTable1.TabIndex = 0; + // + // Form1 + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(controlDataTableTable1); + Name = "Form1"; + Text = "Form1"; + ResumeLayout(false); + } + + #endregion + + private ControlsLibraryNet60.Data.ControlDataTableTable controlDataTableTable1; + } +} diff --git a/WinFormUchetLab/WinFormUchetLab/Form1.cs b/WinFormUchetLab/WinFormUchetLab/Form1.cs new file mode 100644 index 0000000..ff5dd08 --- /dev/null +++ b/WinFormUchetLab/WinFormUchetLab/Form1.cs @@ -0,0 +1,15 @@ +using System.Windows.Forms; +using UchetLabContracts.BindingModels; +using UchetLabContracts.BusinessLogicsContracts; + +namespace WinFormUchetLab +{ + public partial class Form1 : Form + { + + public Form1() + { + InitializeComponent(); + } + } +} diff --git a/WinFormUchetLab/WinFormUchetLab/Form1.resx b/WinFormUchetLab/WinFormUchetLab/Form1.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/WinFormUchetLab/WinFormUchetLab/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WinFormUchetLab/WinFormUchetLab/Program.cs b/WinFormUchetLab/WinFormUchetLab/Program.cs new file mode 100644 index 0000000..b74e3b1 --- /dev/null +++ b/WinFormUchetLab/WinFormUchetLab/Program.cs @@ -0,0 +1,17 @@ +namespace WinFormUchetLab +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Form1()); + } + } +} \ No newline at end of file diff --git a/WinFormUchetLab/WinFormUchetLab/WinFormUchetLab.csproj b/WinFormUchetLab/WinFormUchetLab/WinFormUchetLab.csproj new file mode 100644 index 0000000..3f75ab3 --- /dev/null +++ b/WinFormUchetLab/WinFormUchetLab/WinFormUchetLab.csproj @@ -0,0 +1,29 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + \ No newline at end of file