Вроде 3 готова

This commit is contained in:
Ismailov_Rovshan 2023-11-16 00:09:22 +04:00
parent 4bcc573fbb
commit a68eabe9c7
23 changed files with 1717 additions and 26 deletions

View File

@ -0,0 +1,125 @@
using OrdersContracts.BindingModels;
using OrdersContracts.StorageContracts;
using OrdersContracts.ViewModels;
using OrdersDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrdersDatabaseImplement.Implements
{
public class OrderStorage : IOrderStorage
{
public void Delete(OrderBindingModel model)
{
var context = new OrdersDatabase();
var order = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
if (order != null)
{
context.Orders.Remove(order);
context.SaveChanges();
}
else
{
throw new Exception("Заказ не найден");
}
}
public OrderViewModel GetElement(OrderBindingModel model)
{
if (model == null)
{
return null;
}
using var context = new OrdersDatabase();
var order = context.Orders
.ToList()
.FirstOrDefault(rec => rec.Id == model.Id);
return order != null ? CreateModel(order) : null;
}
public List<OrderViewModel> GetFilteredList(OrderBindingModel model)
{
var context = new OrdersDatabase();
return context.Orders
.Where(order => order.Name.Contains(model.Name) && order.Status.Contains(model.Status))
.ToList()
.Select(CreateModel)
.ToList();
}
public List<OrderViewModel> GetFullList()
{
using (var context = new OrdersDatabase())
{
return context.Orders
.ToList()
.Select(CreateModel)
.ToList();
}
}
public void Insert(OrderBindingModel model)
{
var context = new OrdersDatabase();
var transaction = context.Database.BeginTransaction();
try
{
context.Orders.Add(CreateModel(model, new Order()));
context.SaveChanges();
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
}
public void Update(OrderBindingModel model)
{
var context = new OrdersDatabase();
var transaction = context.Database.BeginTransaction();
try
{
var order = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
if (order == null)
{
throw new Exception("Заказ не найден");
}
CreateModel(model, order);
context.SaveChanges();
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
}
private static Order CreateModel(OrderBindingModel model, Order order)
{
order.Amount = model.Amount;
order.Name = model.Name;
order.Status = model.Status;
order.Info = model.Info;
return order;
}
private OrderViewModel CreateModel(Order order)
{
return new OrderViewModel
{
Id = order.Id,
Amount = order.Amount.ToString(),
Name = order.Name,
Status = order.Status,
Info = order.Info
};
}
}
}

View File

@ -0,0 +1,120 @@
using OrdersContracts.BindingModels;
using OrdersContracts.StorageContracts;
using OrdersContracts.ViewModels;
using OrdersDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrdersDatabaseImplement.Implements
{
public class StatusStorage : IStatusStorage
{
public void Delete(StatusBindingModel model)
{
var context = new OrdersDatabase();
var status = context.Statuses.FirstOrDefault(rec => rec.Id == model.Id);
if (status != null)
{
context.Statuses.Remove(status);
context.SaveChanges();
}
else
{
throw new Exception("Статус не найден");
}
}
public StatusViewModel GetElement(StatusBindingModel model)
{
if (model == null)
{
return null;
}
using var context = new OrdersDatabase();
var status = context.Statuses
.ToList()
.FirstOrDefault(rec => rec.Id == model.Id || rec.Name == model.Name);
return status != null ? CreateModel(status) : null;
}
public List<StatusViewModel> GetFilteredList(StatusBindingModel model)
{
if (model == null)
{
return null;
}
using var context = new OrdersDatabase();
return context.Statuses
.Where(rec => rec.Name.Contains(model.Name))
.Select(CreateModel)
.ToList();
}
public List<StatusViewModel> GetFullList()
{
using var context = new OrdersDatabase();
return context.Statuses
.Select(CreateModel)
.ToList();
}
public void Insert(StatusBindingModel model)
{
var context = new OrdersDatabase();
var transaction = context.Database.BeginTransaction();
try
{
context.Statuses.Add(CreateModel(model, new Status()));
context.SaveChanges();
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
}
public void Update(StatusBindingModel model)
{
var context = new OrdersDatabase();
var transaction = context.Database.BeginTransaction();
try
{
var status = context.Statuses.FirstOrDefault(rec => rec.Id == model.Id);
if (status == null)
{
throw new Exception("Статус не найден");
}
CreateModel(model, status);
context.SaveChanges();
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
}
private static Status CreateModel(StatusBindingModel model, Status status)
{
status.Name = model.Name;
return status;
}
private static StatusViewModel CreateModel(Status status)
{
return new StatusViewModel
{
Id = status.Id,
Name = status.Name
};
}
}
}

View File

@ -0,0 +1,75 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using OrdersDatabaseImplement;
#nullable disable
namespace OrdersDatabaseImplement.Migrations
{
[DbContext(typeof(OrdersDatabase))]
[Migration("20231114172558_mig2")]
partial class mig2
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.11")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("OrdersDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int?>("Amount")
.HasColumnType("integer");
b.Property<string>("Info")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Orders");
});
modelBuilder.Entity("OrdersDatabaseImplement.Models.Status", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Statuses");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,54 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace OrdersDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class mig2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Orders",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
Info = table.Column<string>(type: "text", nullable: false),
Status = table.Column<string>(type: "text", nullable: false),
Amount = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Statuses",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Statuses", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Orders");
migrationBuilder.DropTable(
name: "Statuses");
}
}
}

View File

@ -0,0 +1,72 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using OrdersDatabaseImplement;
#nullable disable
namespace OrdersDatabaseImplement.Migrations
{
[DbContext(typeof(OrdersDatabase))]
partial class OrdersDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.11")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("OrdersDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int?>("Amount")
.HasColumnType("integer");
b.Property<string>("Info")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Orders");
});
modelBuilder.Entity("OrdersDatabaseImplement.Models.Status", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Statuses");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrdersDatabaseImplement.Models
{
public class Order
{
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string Info { get; set; }
[Required]
public string Status { get; set; }
public int? Amount { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrdersDatabaseImplement.Models
{
public class Status
{
public int Id { get; set; }
[Required]
public string Name { get; set; }
}
}

View File

@ -0,0 +1,20 @@
using Microsoft.EntityFrameworkCore;
using OrdersDatabaseImplement.Models;
namespace OrdersDatabaseImplement
{
public class OrdersDatabase : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=OrdersDatabase;Username=postgres;Password=postgres");
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Order> Orders { set; get; }
public virtual DbSet<Status> Statuses { set; get; }
}
}

View File

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OrdersContracts\OrdersContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -1,21 +0,0 @@
using OrdersContracts.BindingModels;
using OrdersContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrdersContracts.StorageContracts
{
public interface IStatusStorage
{
List<StatusViewModel> GetFullList();
List<StatusViewModel> GetFilteredList(StatusBindingModel model);
StatusViewModel GetElement(StatusBindingModel model);
void Insert(StatusBindingModel model);
void Update(StatusBindingModel model);
void Delete(StatusBindingModel model);
}
}

View File

@ -5,6 +5,7 @@
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>

View File

@ -4,12 +4,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 17.3.32901.215
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinForms", "WinForms\WinForms.csproj", "{10D1B0BE-6B52-41E6-8B57-4AFC49A26F17}"
ProjectSection(ProjectDependencies) = postProject
{00C86B65-4E95-4917-B348-398DCF0885C3} = {00C86B65-4E95-4917-B348-398DCF0885C3}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VisualComponentsLib", "VisualComponentsLib\VisualComponentsLib.csproj", "{EF8D5392-CB3C-429E-BB8F-A7353F56E1D8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrdersContracts", "OrdersContracts\OrdersContracts.csproj", "{82FC5A5D-EA93-49E2-BC93-8AE514148FA0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrdersContracts", "OrdersContracts\OrdersContracts.csproj", "{82FC5A5D-EA93-49E2-BC93-8AE514148FA0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrderBusinessLogic", "OrderBusinessLogic\OrderBusinessLogic.csproj", "{071BD445-8513-4B12-A60C-2531F2B795F5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrderBusinessLogic", "OrderBusinessLogic\OrderBusinessLogic.csproj", "{071BD445-8513-4B12-A60C-2531F2B795F5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrdersDatabaseImplement", "OrdersDatabaseImplement\OrdersDatabaseImplement.csproj", "{00C86B65-4E95-4917-B348-398DCF0885C3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -33,6 +38,10 @@ Global
{071BD445-8513-4B12-A60C-2531F2B795F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{071BD445-8513-4B12-A60C-2531F2B795F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{071BD445-8513-4B12-A60C-2531F2B795F5}.Release|Any CPU.Build.0 = Release|Any CPU
{00C86B65-4E95-4917-B348-398DCF0885C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00C86B65-4E95-4917-B348-398DCF0885C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00C86B65-4E95-4917-B348-398DCF0885C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00C86B65-4E95-4917-B348-398DCF0885C3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

159
WinForms/WinForms/FormMain.Designer.cs generated Normal file
View File

@ -0,0 +1,159 @@

namespace WinForms
{
partial class FormMain
{
/// <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()
{
this.components = new System.ComponentModel.Container();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.добавитьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.редактироватьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.удалитьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.сохранитьВВордToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.сохранитьВЭксельToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.сохранитьВПдфToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.статусыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.wordText1 = new VisualCompLib.Components.WordText(this.components);
this.excelChart1 = new Lab2.ChartComponent(this.components);
this.componentDocumentWithTableMultiHeaderPdf1 = new ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableMultiHeaderPdf(this.components);
this.myTreeView1 = new kop.components.TreeClassView();
this.contextMenuStrip1.SuspendLayout();
this.SuspendLayout();
//
// contextMenuStrip1
//
this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.добавитьToolStripMenuItem,
this.редактироватьToolStripMenuItem,
this.удалитьToolStripMenuItem,
this.сохранитьВВордToolStripMenuItem,
this.сохранитьВЭксельToolStripMenuItem,
this.сохранитьВПдфToolStripMenuItem,
this.статусыToolStripMenuItem});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(267, 172);
//
// добавитьToolStripMenuItem
//
this.добавитьToolStripMenuItem.Name = обавитьToolStripMenuItem";
this.добавитьToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.A)));
this.добавитьToolStripMenuItem.Size = new System.Drawing.Size(266, 24);
this.добавитьToolStripMenuItem.Text = "Добавить";
this.добавитьToolStripMenuItem.Click += new System.EventHandler(this.добавитьToolStripMenuItem_Click);
//
// редактироватьToolStripMenuItem
//
this.редактироватьToolStripMenuItem.Name = "редактироватьToolStripMenuItem";
this.редактироватьToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.U)));
this.редактироватьToolStripMenuItem.Size = new System.Drawing.Size(266, 24);
this.редактироватьToolStripMenuItem.Text = "Редактировать";
this.редактироватьToolStripMenuItem.Click += new System.EventHandler(this.редактироватьToolStripMenuItem_Click);
//
// удалитьToolStripMenuItem
//
this.удалитьToolStripMenuItem.Name = "удалитьToolStripMenuItem";
this.удалитьToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.D)));
this.удалитьToolStripMenuItem.Size = new System.Drawing.Size(266, 24);
this.удалитьToolStripMenuItem.Text = "Удалить";
this.удалитьToolStripMenuItem.Click += new System.EventHandler(this.удалитьToolStripMenuItem_Click);
//
// сохранитьВВордToolStripMenuItem
//
this.сохранитьВВордToolStripMenuItem.Name = "сохранитьВВордToolStripMenuItem";
this.сохранитьВВордToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S)));
this.сохранитьВВордToolStripMenuItem.Size = new System.Drawing.Size(266, 24);
this.сохранитьВВордToolStripMenuItem.Text = "Сохранить в Ворд";
this.сохранитьВВордToolStripMenuItem.Click += new System.EventHandler(this.сохранитьВВордToolStripMenuItem_Click);
//
// сохранитьВЭксельToolStripMenuItem
//
this.сохранитьВЭксельToolStripMenuItem.Name = "сохранитьВЭксельToolStripMenuItem";
this.сохранитьВЭксельToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.C)));
this.сохранитьВЭксельToolStripMenuItem.Size = new System.Drawing.Size(266, 24);
this.сохранитьВЭксельToolStripMenuItem.Text = "Сохранить в Эксель";
this.сохранитьВЭксельToolStripMenuItem.Click += new System.EventHandler(this.сохранитьВЭксельToolStripMenuItem_Click);
//
// сохранитьВПдфToolStripMenuItem
//
this.сохранитьВПдфToolStripMenuItem.Name = "сохранитьВПдфToolStripMenuItem";
this.сохранитьВПдфToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.T)));
this.сохранитьВПдфToolStripMenuItem.Size = new System.Drawing.Size(266, 24);
this.сохранитьВПдфToolStripMenuItem.Text = "Сохранить в пдф";
this.сохранитьВПдфToolStripMenuItem.Click += new System.EventHandler(this.сохранитьВПдфToolStripMenuItem_Click);
//
// статусыToolStripMenuItem
//
this.статусыToolStripMenuItem.Name = "статусыToolStripMenuItem";
this.статусыToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Tab)));
this.статусыToolStripMenuItem.Size = new System.Drawing.Size(266, 24);
this.статусыToolStripMenuItem.Text = "Статусы";
this.статусыToolStripMenuItem.Click += new System.EventHandler(this.статусыToolStripMenuItem_Click);
//
// myTreeView1
//
this.myTreeView1.Location = new System.Drawing.Point(12, 12);
this.myTreeView1.Name = "myTreeView1";
this.myTreeView1.Size = new System.Drawing.Size(658, 374);
this.myTreeView1.TabIndex = 1;
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(682, 398);
this.Controls.Add(this.myTreeView1);
this.Name = "FormMain";
this.Text = "Учет клиентов";
this.Load += new System.EventHandler(this.FormMain_Load);
this.contextMenuStrip1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private ContextMenuStrip contextMenuStrip1;
private ToolStripMenuItem добавитьToolStripMenuItem;
private ToolStripMenuItem редактироватьToolStripMenuItem;
private ToolStripMenuItem удалитьToolStripMenuItem;
private ToolStripMenuItem сохранитьВВордToolStripMenuItem;
private ToolStripMenuItem сохранитьВЭксельToolStripMenuItem;
private ToolStripMenuItem сохранитьВПдфToolStripMenuItem;
private ToolStripMenuItem статусыToolStripMenuItem;
private VisualCompLib.Components.WordText wordText1;
//private TreeClassView myTreeView1;
private Lab2.ChartComponent excelChart1;
private ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableMultiHeaderPdf componentDocumentWithTableMultiHeaderPdf1;
private kop.components.TreeClassView myTreeView1;
}
}

View File

@ -0,0 +1,238 @@
using ComponentsLibraryNet60.DocumentWithTable;
using ComponentsLibraryNet60.Models;
using Lab2;
using OrdersContracts.BindingModels;
using OrdersContracts.BusinessLogicContracts;
using OrdersContracts.ViewModels;
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;
using VisualComponentsLib.Components;
namespace WinForms
{
public partial class FormMain : Form
{
private readonly IOrderLogic _orderLogic;
private readonly IStatusLogic _statusLogic;
public FormMain(IOrderLogic orderLogic, IStatusLogic statusLogic)
{
_orderLogic = orderLogic;
_statusLogic = statusLogic;
InitializeComponent();
List<string> stringToHierachy = new List<string>() { "Status", "Amount", "Id", "Name" };
myTreeView1.setHierarchy(stringToHierachy);
ContextMenuStrip = contextMenuStrip1;
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _orderLogic.Read(null);
for (int i = 0; i < list.Count; i++)
{
if (list[i].Amount == null || list[i].Amount == "") { list[i].Amount = "нет"; }
}
myTreeView1.setData(list);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void AddNewElement()
{
var service = Program.ServiceProvider?.GetService(typeof(FormOrder));
if (!(service is FormOrder form)) return;
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
private void UpdateElement()
{
var service = Program.ServiceProvider?.GetService(typeof(FormOrder));
if (!(service is FormOrder form)) return;
var selectedOrder = myTreeView1.GetSelectedClass<OrderBindingModel>();
if (selectedOrder != null)
{
form.Id = Convert.ToInt32((selectedOrder as OrderBindingModel).Id);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
else
{
MessageBox.Show("Выберите клиента для редактирования");
}
}
private void DeleteElement()
{
if (MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
var selectedOrder = myTreeView1.GetSelectedClass<OrderBindingModel>();
int id = Convert.ToInt32((selectedOrder as OrderBindingModel).Id);
try
{
_orderLogic.Delete(new OrderBindingModel { Id = id });
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
LoadData();
}
}
private void CreateWord()
{
string fileName = "";
using (var dialog = new SaveFileDialog { Filter = "docx|*.docx" })
{
if (dialog.ShowDialog() == DialogResult.OK)
{
fileName = dialog.FileName.ToString();
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
List<string> textList = new List<string>();
var list = _orderLogic.Read(null);
if (list != null)
{
foreach (var item in list)
{
if (item.Amount != null && item.Amount != "")
{
string orders = string.Concat("ФИО: ", item.Name, " Отзывы: ", item.Info);
textList.Add(orders);
}
}
string[] textArray = textList.ToArray();
wordText1.CreateWordText(new(fileName, "Документ по клиентам, совершавшим покупки (ФИО клиента и его отзывы)", textArray));
}
}
private void createExcel()
{
string fileName = "";
using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" })
{
if (dialog.ShowDialog() == DialogResult.OK)
{
fileName = dialog.FileName.ToString();
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
var statuses = _statusLogic.Read(null);
var orders = _orderLogic.Read(null);
List<(string, int)> dates = new List<(string, int)>();
for (int i = 0; i < statuses.Count; i++)
{
int counter = 0;
for (int j = 0; j < orders.Count; j++)
{
if (orders[j].Status == statuses[i].Name && orders[j].Amount != null) counter++;
}
dates.Add((statuses[i].Name, counter));
}
excelChart1.Load(new ChartInfo
{
Path = fileName,
Title = "Сколько клиентов какого статуса совершали покупки",
DiagrammTitle = "Круговая диаграмма",
Data = dates,
});
}
private void CreatePdf()
{
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
string fileName = "";
using (var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" })
{
if (dialog.ShowDialog() == DialogResult.OK)
{
fileName = dialog.FileName.ToString();
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
var orders = _orderLogic.Read(null);
for (int i = 0; i < orders.Count; i++)
{
if (orders[i].Amount == null || orders[i].Amount == "") { orders[i].Amount = "нет"; }
}
componentDocumentWithTableMultiHeaderPdf1.CreateDoc(new ComponentDocumentWithTableHeaderDataConfig<OrderViewModel>
{
FilePath = fileName,
Header = "Отчет по клиентам",
ColumnsRowsWidth = new List<(int, int)> { (5, 5), (10, 5), (15, 0), (15, 0) },
Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)>
{
(0, 0, "Id", "Id"),
(1, 0, "ФИО", "Name"),
(2, 0, "Статус", "Status"),
(3, 0, "Сумма покупок", "Amount")
},
Data = orders
});
}
private void статусыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormStatus));
if (!(service is FormStatus form)) return;
form.ShowDialog();
}
private void сохранитьВПдфToolStripMenuItem_Click(object sender, EventArgs e)
{
CreatePdf();
}
private void сохранитьВЭксельToolStripMenuItem_Click(object sender, EventArgs e)
{
createExcel();
}
private void сохранитьВВордToolStripMenuItem_Click(object sender, EventArgs e)
{
CreateWord();
}
private void удалитьToolStripMenuItem_Click(object sender, EventArgs e)
{
DeleteElement();
}
private void редактироватьToolStripMenuItem_Click(object sender, EventArgs e)
{
UpdateElement();
}
private void добавитьToolStripMenuItem_Click(object sender, EventArgs e)
{
AddNewElement();
}
}
}

View File

@ -0,0 +1,72 @@
<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>
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>149, 17</value>
</metadata>
<metadata name="wordText1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>335, 17</value>
</metadata>
<metadata name="excelChart1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="componentDocumentWithTableMultiHeaderPdf1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>459, 17</value>
</metadata>
</root>

190
WinForms/WinForms/FormOrder.Designer.cs generated Normal file
View File

@ -0,0 +1,190 @@
namespace WinForms
{
partial class FormOrder
{
/// <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()
{
this.textBoxName = new System.Windows.Forms.TextBox();
this.LabelFIO = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.myDropDownList1 = new VisualComponentsLib.MyDropDownList();
this.label2 = new System.Windows.Forms.Label();
this.textBoxInfos = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.controlInputNullableInt1 = new ControlsLibraryNet60.Input.ControlInputNullableInt();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBoxName
//
this.textBoxName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBoxName.Location = new System.Drawing.Point(12, 34);
this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(323, 27);
this.textBoxName.TabIndex = 2;
//
// LabelFIO
//
this.LabelFIO.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.LabelFIO.AutoSize = true;
this.LabelFIO.Location = new System.Drawing.Point(12, 9);
this.LabelFIO.Name = "LabelFIO";
this.LabelFIO.Size = new System.Drawing.Size(42, 20);
this.LabelFIO.TabIndex = 3;
this.LabelFIO.Text = "ФИО";
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 77);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(52, 20);
this.label1.TabIndex = 4;
this.label1.Text = "Статус";
//
// myDropDownList1
//
this.myDropDownList1.Location = new System.Drawing.Point(12, 101);
this.myDropDownList1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.myDropDownList1.Name = "myDropDownList1";
this.myDropDownList1.SelectedValue = "";
this.myDropDownList1.Size = new System.Drawing.Size(195, 48);
this.myDropDownList1.TabIndex = 5;
//
// label2
//
this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 144);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(79, 20);
this.label2.TabIndex = 6;
this.label2.Text = "Описание";
//
// textBoxInfos
//
this.textBoxInfos.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBoxInfos.Location = new System.Drawing.Point(12, 168);
this.textBoxInfos.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.textBoxInfos.Name = "textBoxInfos";
this.textBoxInfos.Size = new System.Drawing.Size(323, 27);
this.textBoxInfos.TabIndex = 7;
//
// label3
//
this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 199);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(116, 20);
this.label3.TabIndex = 8;
this.label3.Text = "Сумма покупок";
//
// controlInputNullableInt1
//
this.controlInputNullableInt1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.controlInputNullableInt1.Location = new System.Drawing.Point(14, 227);
this.controlInputNullableInt1.Margin = new System.Windows.Forms.Padding(5, 8, 5, 8);
this.controlInputNullableInt1.Name = "controlInputNullableInt1";
this.controlInputNullableInt1.Size = new System.Drawing.Size(321, 39);
this.controlInputNullableInt1.TabIndex = 13;
this.controlInputNullableInt1.Value = null;
//
// buttonSave
//
this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.buttonSave.Location = new System.Drawing.Point(12, 269);
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(323, 31);
this.buttonSave.TabIndex = 14;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.Location = new System.Drawing.Point(12, 308);
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(323, 31);
this.buttonCancel.TabIndex = 15;
this.buttonCancel.Text = "Отменить";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// FormOrder
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(347, 368);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.controlInputNullableInt1);
this.Controls.Add(this.label3);
this.Controls.Add(this.textBoxInfos);
this.Controls.Add(this.label2);
this.Controls.Add(this.myDropDownList1);
this.Controls.Add(this.label1);
this.Controls.Add(this.LabelFIO);
this.Controls.Add(this.textBoxName);
this.Name = "FormOrder";
this.Text = "FormOrder";
this.Load += new System.EventHandler(this.FormOrder_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private TextBox textBoxName;
private Label LabelFIO;
private Label label1;
private VisualComponentsLib.MyDropDownList myDropDownList1;
private Label label2;
private TextBox textBoxInfos;
private Label label3;
private ControlsLibraryNet60.Input.ControlInputNullableInt controlInputNullableInt1;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,111 @@
using OrdersContracts.BindingModels;
using OrdersContracts.BusinessLogicContracts;
using OrdersContracts.ViewModels;
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 WinForms
{
public partial class FormOrder : Form
{
public int Id { set { id = value; } }
private readonly IOrderLogic _logic;
private readonly IStatusLogic _logicS;
private int? id;
public FormOrder(IOrderLogic logic, IStatusLogic logicS)
{
InitializeComponent();
_logic = logic;
_logicS = logicS;
}
private void FormOrder_Load(object sender, EventArgs e)
{
List<StatusViewModel> viewS = _logicS.Read(null);
if (viewS != null)
{
List<string> list = new List<string>();
foreach (StatusViewModel s in viewS)
{
list.Add(s.Name);
}
myDropDownList1.LoadValues(list);
}
if (id.HasValue)
{
try
{
OrderViewModel view = _logic.Read(new OrderBindingModel { Id = id.Value })?[0];
if (view != null)
{
textBoxInfos.Text = view.Info;
textBoxName.Text = view.Name;
myDropDownList1.SelectedValue = view.Status;
if (view.Amount != null)
{
controlInputNullableInt1.Value = Int32.Parse(view.Amount);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните имя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(myDropDownList1.SelectedValue))
{
MessageBox.Show("Выберите заказ", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (textBoxInfos.Text == null)
{
MessageBox.Show("Заполните описание", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
int? amount = controlInputNullableInt1.Value;
try
{
_logic.CreateOrUpdate(new OrderBindingModel
{
Id = id,
Info = textBoxInfos.Text,
Name = textBoxName.Text,
Status = myDropDownList1.SelectedValue.ToString(),
Amount = amount
});
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

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>

69
WinForms/WinForms/FormStatus.Designer.cs generated Normal file
View File

@ -0,0 +1,69 @@
namespace WinForms
{
partial class FormStatus
{
/// <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()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(14, 13);
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(270, 292);
this.dataGridView.TabIndex = 0;
this.dataGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellEndEdit);
this.dataGridView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dataGridView_KeyDown);
//
// FormStatus
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(297, 321);
this.Controls.Add(this.dataGridView);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormStatus";
this.Text = "Статусы";
this.Load += new System.EventHandler(this.FormStatus_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
}
}

View File

@ -0,0 +1,117 @@
using OrdersContracts.BindingModels;
using OrdersContracts.BusinessLogicContracts;
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 WinForms
{
public partial class FormStatus : Form
{
private readonly IStatusLogic statusLogic;
BindingList<StatusBindingModel> list;
public FormStatus(IStatusLogic _statusLogic)
{
InitializeComponent();
statusLogic = _statusLogic;
list = new BindingList<StatusBindingModel>();
dataGridView.AllowUserToAddRows = false;
}
private void LoadData()
{
try
{
var list1 = statusLogic.Read(null);
list.Clear();
foreach (var item in list1)
{
list.Add(new StatusBindingModel
{
Id = item.Id,
Name = item.Name,
});
}
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns[0].Visible = false;
dataGridView.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void FormStatus_Load(object sender, EventArgs e)
{
LoadData();
}
private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
var typeName = (string)dataGridView.CurrentRow.Cells[1].Value;
if (!string.IsNullOrEmpty(typeName))
{
if (dataGridView.CurrentRow.Cells[0].Value != null)
{
statusLogic.CreateOrUpdate(new StatusBindingModel()
{
Id = Convert.ToInt32(dataGridView.CurrentRow.Cells[0].Value),
Name = (string)dataGridView.CurrentRow.Cells[1].EditedFormattedValue
});
}
else
{
statusLogic.CreateOrUpdate(new StatusBindingModel()
{
Name = (string)dataGridView.CurrentRow.Cells[1].EditedFormattedValue
});
}
}
else
{
MessageBox.Show("Введена пустая строка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
LoadData();
}
private void dataGridView_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Insert)
{
if (dataGridView.Rows.Count == 0)
{
list.Add(new StatusBindingModel());
dataGridView.DataSource = new BindingList<StatusBindingModel>(list);
dataGridView.CurrentCell = dataGridView.Rows[0].Cells[1];
return;
}
if (dataGridView.Rows[dataGridView.Rows.Count - 1].Cells[1].Value != null)
{
list.Add(new StatusBindingModel());
dataGridView.DataSource = new BindingList<StatusBindingModel>(list);
dataGridView.CurrentCell = dataGridView.Rows[dataGridView.Rows.Count - 1].Cells[1];
return;
}
}
if (e.KeyData == Keys.Delete)
{
if (MessageBox.Show("Удалить выбранный элемент", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
statusLogic.Delete(new StatusBindingModel() { Id = (int)dataGridView.CurrentRow.Cells[0].Value });
LoadData();
}
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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

@ -1,17 +1,39 @@
using Microsoft.Extensions.DependencyInjection;
using OrderBusinessLogic;
using OrdersContracts.BusinessLogicContracts;
using OrdersContracts.StorageContracts;
using OrdersDatabaseImplement.Implements;
namespace WinForms
{
internal static class Program
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary>
/// The main entry point for the application.
/// </summary>
[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 FormWord());
IServiceCollection services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetService<FormMain>());
}
private static void ConfigureServices(IServiceCollection services)
{
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IStatusLogic, StatusLogic>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IStatusStorage, StatusStorage>();
services.AddTransient<FormMain>();
services.AddTransient<FormOrder>();
services.AddTransient<FormStatus>();
}
}
}

View File

@ -9,6 +9,20 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ComponentsLibraryNet60" Version="1.0.0" />
<PackageReference Include="ControlsLibraryNet60" Version="1.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="UnvisableConponents" Version="1.0.0" />
<PackageReference Include="VisableComponents" Version="1.0.1" />
<PackageReference Include="VisualCompLib" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OrderBusinessLogic\OrderBusinessLogic.csproj" />
<ProjectReference Include="..\OrdersDatabaseImplement\OrdersDatabaseImplement.csproj" />
<ProjectReference Include="..\VisualComponentsLib\VisualComponentsLib.csproj" />
</ItemGroup>