Compare commits

...

10 Commits

86 changed files with 6733 additions and 77 deletions

View File

@ -0,0 +1,26 @@
using ProjectWorkshop.Entities.Enums;
namespace ProjectWorkshop.Entities;
public class Assembler
{
public int ID { get; private set; }
public string FullName { get; private set; } = string.Empty;
public AssemblerRank AssemblerRank { get; private set; }
public DateTime WorkExperience { get; private set; }
public static Assembler CreateEntity(int id, string fullName, AssemblerRank assemblerRank, DateTime? dateTime = null)
{
return new Assembler
{
ID = id,
FullName = fullName,
AssemblerRank = assemblerRank,
WorkExperience = dateTime ?? DateTime.Now
};
}
}

View File

@ -0,0 +1,26 @@
namespace ProjectWorkshop.Entities;
public class AssemblerShift
{
public int ID { get; private set; }
public int WorkHours { get; private set; }
public int AssemblerID_Assembler { get; private set; }
public int ShiftID_Shift { get; private set; }
public DateTime AssemblerShiftDate { get; private set; }
public static AssemblerShift CreateOperation(int id, int workHours, int assemblerID, int shiftID_Shift, DateTime? shiftDate = null)
{
return new AssemblerShift
{
ID = id,
WorkHours = workHours,
AssemblerID_Assembler = assemblerID,
ShiftID_Shift = shiftID_Shift,
AssemblerShiftDate = shiftDate ?? DateTime.Now
};
}
}

View File

@ -0,0 +1,42 @@
using ProjectWorkshop.Entities.Enums;
namespace ProjectWorkshop.Entities;
public class Assembly
{
public int ID { get; private set; }
public int Count { get; private set; }
public int AssemblerID_Assembler { get; private set; }
public IEnumerable<ProductAssembly> ProductAssembly { get; private set; } = [];
public DateTime AssemblyDate { get; private set; }
public static Assembly CreateOperation(int id, int count, int assemblerID, IEnumerable<ProductAssembly> productAssembly, DateTime? assemblyDate = null)
{
return new Assembly
{
ID = id,
Count = count,
AssemblerID_Assembler = assemblerID,
ProductAssembly = productAssembly,
AssemblyDate = assemblyDate ?? DateTime.Now
};
}
public static Assembly CreateOperation(TempProductAssembly tempProductAssembly, IEnumerable<ProductAssembly> productAssemblies)
{
return new Assembly
{
ID = tempProductAssembly.ID,
Count = tempProductAssembly.Count,
AssemblerID_Assembler = tempProductAssembly.AssemblyID_Assembly,
ProductAssembly = productAssemblies,
AssemblyDate = tempProductAssembly.AssemblyDate
};
}
}

View File

@ -0,0 +1,12 @@
namespace ProjectWorkshop.Entities.Enums;
public enum AssemblerRank
{
None = 0,
Ordinary = 1,
Senior = 2,
Head = 3
}

View File

@ -0,0 +1,13 @@
namespace ProjectWorkshop.Entities.Enums;
[Flags]
public enum ProductType
{
None = 0,
Electronics = 1,
Furniture = 2,
CarParts = 4
}

View File

@ -0,0 +1,25 @@
using ProjectWorkshop.Entities.Enums;
namespace ProjectWorkshop.Entities;
public class Product
{
public int ID { get; private set; }
public string ProductName { get; private set; } = string.Empty;
public double Price { get; private set; }
public ProductType ProductType { get; private set; }
public static Product CreateEntity(int id, string productName, double price, ProductType productType)
{
return new Product
{
ID = id,
ProductName = productName ?? string.Empty,
Price = price,
ProductType = productType
};
}
}

View File

@ -0,0 +1,23 @@
namespace ProjectWorkshop.Entities;
public class ProductAssembly
{
public int ID { get; private set; }
public int ProductID_Product { get; private set; }
public int AssemblyID_Assembly { get; private set; }
public int Count { get; private set; }
public static ProductAssembly CreateElement(int id, int productID, int assemblyID, int count)
{
return new ProductAssembly
{
ID = id,
ProductID_Product = productID,
AssemblyID_Assembly = assemblyID,
Count = count
};
}
}

View File

@ -0,0 +1,17 @@
namespace ProjectWorkshop.Entities;
public class Shift
{
public int ID { get; private set; }
public DateTime ShiftDate { get; private set; }
public static Shift CreateEntity(int id, DateTime? dateTime = null)
{
return new Shift
{
ID = id,
ShiftDate = dateTime ?? DateTime.Now
};
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWorkshop.Entities;
public class TempProductAssembly
{
public int ID { get; private set; }
public int ProductID_Product { get; private set; }
public int AssemblyID_Assembly { get; private set; }
public int Count { get; private set; }
public DateTime AssemblyDate { get; private set; }
}

View File

@ -1,39 +0,0 @@
namespace ProjectWorkshop
{
partial class Form1
{
/// <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.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

@ -1,10 +0,0 @@
namespace ProjectWorkshop
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,171 @@
namespace ProjectWorkshop
{
partial class FormWorkshop
{
/// <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()
{
menuStrip = new MenuStrip();
справочникиToolStripMenuItem = new ToolStripMenuItem();
AssemblersToolStripMenuItem = new ToolStripMenuItem();
ShiftsToolStripMenuItem = new ToolStripMenuItem();
ProductsToolStripMenuItem = new ToolStripMenuItem();
операцииToolStripMenuItem = new ToolStripMenuItem();
AssemblyToolStripMenuItem = new ToolStripMenuItem();
AssemblerShiftToolStripMenuItem = new ToolStripMenuItem();
отчетыToolStripMenuItem = new ToolStripMenuItem();
DirectoryReportToolStripMenuItem = new ToolStripMenuItem();
AssembliesReportToolStripMenuItem = new ToolStripMenuItem();
AssemblyDestributionToolStripMenuItem = new ToolStripMenuItem();
menuStrip.SuspendLayout();
SuspendLayout();
//
// menuStrip
//
menuStrip.ImageScalingSize = new Size(32, 32);
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, операцииToolStripMenuItem, отчетыToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Padding = new Padding(3, 1, 0, 1);
menuStrip.Size = new Size(729, 24);
menuStrip.TabIndex = 0;
menuStrip.Text = "menuStrip1";
//
// справочникиToolStripMenuItem
//
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { AssemblersToolStripMenuItem, ShiftsToolStripMenuItem, ProductsToolStripMenuItem });
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
справочникиToolStripMenuItem.Size = new Size(94, 22);
справочникиToolStripMenuItem.Text = "Справочники";
//
// AssemblersToolStripMenuItem
//
AssemblersToolStripMenuItem.Name = "AssemblersToolStripMenuItem";
AssemblersToolStripMenuItem.Size = new Size(134, 22);
AssemblersToolStripMenuItem.Text = "Сборщики";
AssemblersToolStripMenuItem.Click += AssemblersToolStripMenuItem_Click;
//
// ShiftsToolStripMenuItem
//
ShiftsToolStripMenuItem.Name = "ShiftsToolStripMenuItem";
ShiftsToolStripMenuItem.Size = new Size(134, 22);
ShiftsToolStripMenuItem.Text = "Смены";
ShiftsToolStripMenuItem.Click += ShiftsToolStripMenuItem_Click;
//
// ProductsToolStripMenuItem
//
ProductsToolStripMenuItem.Name = "ProductsToolStripMenuItem";
ProductsToolStripMenuItem.Size = new Size(134, 22);
ProductsToolStripMenuItem.Text = "Изделия";
ProductsToolStripMenuItem.Click += ProductsToolStripMenuItem_Click_1;
//
// операцииToolStripMenuItem
//
операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { AssemblyToolStripMenuItem, AssemblerShiftToolStripMenuItem });
операцииToolStripMenuItem.Name = "операцииToolStripMenuItem";
операцииToolStripMenuItem.Size = new Size(75, 22);
операцииToolStripMenuItem.Text = "Операции";
//
// AssemblyToolStripMenuItem
//
AssemblyToolStripMenuItem.Name = "AssemblyToolStripMenuItem";
AssemblyToolStripMenuItem.Size = new Size(165, 22);
AssemblyToolStripMenuItem.Text = "Сборка";
AssemblyToolStripMenuItem.Click += AssemblyToolStripMenuItem_Click;
//
// AssemblerShiftToolStripMenuItem
//
AssemblerShiftToolStripMenuItem.Name = "AssemblerShiftToolStripMenuItem";
AssemblerShiftToolStripMenuItem.Size = new Size(165, 22);
AssemblerShiftToolStripMenuItem.Text = "Выйти на смену ";
AssemblerShiftToolStripMenuItem.Click += AssemblerShiftToolStripMenuItem_Click;
//
// отчетыToolStripMenuItem
//
отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem, AssembliesReportToolStripMenuItem, AssemblyDestributionToolStripMenuItem });
отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
отчетыToolStripMenuItem.Size = new Size(60, 22);
отчетыToolStripMenuItem.Text = "Отчеты";
//
// DirectoryReportToolStripMenuItem
//
DirectoryReportToolStripMenuItem.Name = "DirectoryReportToolStripMenuItem";
DirectoryReportToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.W;
DirectoryReportToolStripMenuItem.Size = new Size(280, 22);
DirectoryReportToolStripMenuItem.Text = "Документ со справочниками";
DirectoryReportToolStripMenuItem.Click += DirectoryReportToolStripMenuItem_Click;
//
// AssembliesReportToolStripMenuItem
//
AssembliesReportToolStripMenuItem.Name = "AssembliesReportToolStripMenuItem";
AssembliesReportToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.E;
AssembliesReportToolStripMenuItem.Size = new Size(280, 22);
AssembliesReportToolStripMenuItem.Text = "Отчет по сборкам";
AssembliesReportToolStripMenuItem.Click += AssembliesReportToolStripMenuItem_Click;
//
// AssemblyDestributionToolStripMenuItem
//
AssemblyDestributionToolStripMenuItem.Name = "AssemblyDestributionToolStripMenuItem";
AssemblyDestributionToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.P;
AssemblyDestributionToolStripMenuItem.Size = new Size(280, 22);
AssemblyDestributionToolStripMenuItem.Text = "Распределение сборок";
AssemblyDestributionToolStripMenuItem.Click += AssemblyDestributionToolStripMenuItem_Click;
//
// FormWorkshop
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
BackgroundImage = Properties.Resources.цех;
BackgroundImageLayout = ImageLayout.Stretch;
ClientSize = new Size(729, 368);
Controls.Add(menuStrip);
MainMenuStrip = menuStrip;
Margin = new Padding(2, 1, 2, 1);
Name = "FormWorkshop";
StartPosition = FormStartPosition.CenterScreen;
Text = "Цех";
menuStrip.ResumeLayout(false);
menuStrip.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
private MenuStrip menuStrip;
private ToolStripMenuItem справочникиToolStripMenuItem;
private ToolStripMenuItem операцииToolStripMenuItem;
private ToolStripMenuItem отчетыToolStripMenuItem;
private ToolStripMenuItem AssemblyToolStripMenuItem;
private ToolStripMenuItem AssemblerShiftToolStripMenuItem;
private ToolStripMenuItem AssemblersToolStripMenuItem;
private ToolStripMenuItem ShiftsToolStripMenuItem;
private ToolStripMenuItem ProductsToolStripMenuItem;
private ToolStripMenuItem DirectoryReportToolStripMenuItem;
private ToolStripMenuItem AssembliesReportToolStripMenuItem;
private ToolStripMenuItem AssemblyDestributionToolStripMenuItem;
}
}

View File

@ -0,0 +1,114 @@
using ProjectWorkshop.Forms;
using Unity;
namespace ProjectWorkshop
{
public partial class FormWorkshop : Form
{
private readonly IUnityContainer _container;
public FormWorkshop(IUnityContainer container)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
}
private void AssemblersToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormAssemblers>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ShiftsToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormShifts>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ProductsToolStripMenuItem_Click_1(object sender, EventArgs e)
{
try
{
_container.Resolve<FormProducts>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void AssemblyToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormAssemblies>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void AssemblerShiftToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormAssemblerShifts>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void DirectoryReportToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormDirectoryReport>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void AssembliesReportToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormAssemblersReport>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void AssemblyDestributionToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormAssemblyDistributionReport>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -0,0 +1,123 @@
<?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>
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,140 @@
namespace ProjectWorkshop.Forms
{
partial class FormAssembler
{
/// <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()
{
labelFullName = new Label();
textBoxFullName = new TextBox();
labelAssemblerRank = new Label();
comboBoxAssemblerRank = new ComboBox();
labelWorkExperience = new Label();
dateTimePickerWorkExperience = new DateTimePicker();
buttonSave = new Button();
buttonCancel = new Button();
SuspendLayout();
//
// labelFullName
//
labelFullName.AutoSize = true;
labelFullName.Location = new Point(43, 52);
labelFullName.Name = "labelFullName";
labelFullName.Size = new Size(194, 32);
labelFullName.TabIndex = 0;
labelFullName.Text = "ФИО Сборщика:";
//
// textBoxFullName
//
textBoxFullName.Location = new Point(278, 52);
textBoxFullName.Name = "textBoxFullName";
textBoxFullName.Size = new Size(324, 39);
textBoxFullName.TabIndex = 1;
//
// labelAssemblerRank
//
labelAssemblerRank.AutoSize = true;
labelAssemblerRank.Location = new Point(85, 198);
labelAssemblerRank.Name = "labelAssemblerRank";
labelAssemblerRank.Size = new Size(94, 32);
labelAssemblerRank.TabIndex = 2;
labelAssemblerRank.Text = "Разряд:";
//
// comboBoxAssemblerRank
//
comboBoxAssemblerRank.FormattingEnabled = true;
comboBoxAssemblerRank.Location = new Point(278, 198);
comboBoxAssemblerRank.Name = "comboBoxAssemblerRank";
comboBoxAssemblerRank.Size = new Size(324, 40);
comboBoxAssemblerRank.TabIndex = 3;
//
// labelWorkExperience
//
labelWorkExperience.AutoSize = true;
labelWorkExperience.Location = new Point(59, 349);
labelWorkExperience.Name = "labelWorkExperience";
labelWorkExperience.Size = new Size(162, 32);
labelWorkExperience.TabIndex = 4;
labelWorkExperience.Text = "Стаж работы:";
//
// dateTimePickerWorkExperience
//
dateTimePickerWorkExperience.Location = new Point(278, 344);
dateTimePickerWorkExperience.Name = "dateTimePickerWorkExperience";
dateTimePickerWorkExperience.Size = new Size(324, 39);
dateTimePickerWorkExperience.TabIndex = 5;
//
// buttonSave
//
buttonSave.Location = new Point(87, 505);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(150, 46);
buttonSave.TabIndex = 6;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(387, 505);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(150, 46);
buttonCancel.TabIndex = 7;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// FormAssembler
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(636, 623);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(dateTimePickerWorkExperience);
Controls.Add(labelWorkExperience);
Controls.Add(comboBoxAssemblerRank);
Controls.Add(labelAssemblerRank);
Controls.Add(textBoxFullName);
Controls.Add(labelFullName);
Name = "FormAssembler";
Text = "Сборщик";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label labelFullName;
private TextBox textBoxFullName;
private Label labelAssemblerRank;
private ComboBox comboBoxAssemblerRank;
private Label labelWorkExperience;
private DateTimePicker dateTimePickerWorkExperience;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,89 @@
using ProjectWorkshop.Entities;
using ProjectWorkshop.Entities.Enums;
using ProjectWorkshop.Repositories;
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 ProjectWorkshop.Forms
{
public partial class FormAssembler : Form
{
private readonly IAssemblerRepository _assemblerRepository;
private int? _assemblerID;
public int Id
{
set
{
try
{
var assembler = _assemblerRepository.ReadAssemblerByID(value);
if (assembler == null)
{
throw new InvalidDataException(nameof(assembler));
}
_assemblerID = assembler.ID;
textBoxFullName.Text = assembler.FullName;
comboBoxAssemblerRank.SelectedItem = assembler.AssemblerRank;
dateTimePickerWorkExperience.Value = assembler.WorkExperience;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
public FormAssembler(IAssemblerRepository assemblerRepository)
{
InitializeComponent();
comboBoxAssemblerRank.DataSource = Enum.GetValues(typeof(AssemblerRank));
_assemblerRepository = assemblerRepository ??
throw new ArgumentNullException(nameof(assemblerRepository));
}
private void ButtonSave_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(textBoxFullName.Text))
{
throw new Exception("Имеется незаполненное поле");
}
if (_assemblerID.HasValue)
{
_assemblerRepository.UpdateAssembler(CreateAssembler(_assemblerID.Value));
}
else
{
_assemblerRepository.CreateAssembler(CreateAssembler(0));
}
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
Close();
}
private Assembler CreateAssembler(int id) => Assembler.CreateEntity(id,
textBoxFullName.Text, (AssemblerRank)comboBoxAssemblerRank.SelectedItem!, dateTimePickerWorkExperience.Value);
}
}

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
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
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>
@ -26,36 +26,36 @@
<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
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
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
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
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
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
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
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->

View File

@ -0,0 +1,143 @@
namespace ProjectWorkshop.Forms
{
partial class FormAssemblerShift
{
/// <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()
{
labelWorkHours = new Label();
numericUpDownWorkHours = new NumericUpDown();
labelAssembler = new Label();
labelShiftDate = new Label();
comboBoxAssembler = new ComboBox();
comboBoxShiftDate = new ComboBox();
buttonSave = new Button();
buttonCancel = new Button();
((System.ComponentModel.ISupportInitialize)numericUpDownWorkHours).BeginInit();
SuspendLayout();
//
// labelWorkHours
//
labelWorkHours.AutoSize = true;
labelWorkHours.Location = new Point(64, 76);
labelWorkHours.Name = "labelWorkHours";
labelWorkHours.Size = new Size(216, 32);
labelWorkHours.TabIndex = 0;
labelWorkHours.Text = "Отработать часов:";
//
// numericUpDownWorkHours
//
numericUpDownWorkHours.Location = new Point(370, 74);
numericUpDownWorkHours.Name = "numericUpDownWorkHours";
numericUpDownWorkHours.Size = new Size(298, 39);
numericUpDownWorkHours.TabIndex = 1;
//
// labelAssembler
//
labelAssembler.AutoSize = true;
labelAssembler.Location = new Point(99, 193);
labelAssembler.Name = "labelAssembler";
labelAssembler.Size = new Size(122, 32);
labelAssembler.TabIndex = 2;
labelAssembler.Text = "Сборщик:";
//
// labelShiftDate
//
labelShiftDate.AutoSize = true;
labelShiftDate.Location = new Point(79, 308);
labelShiftDate.Name = "labelShiftDate";
labelShiftDate.Size = new Size(157, 32);
labelShiftDate.TabIndex = 3;
labelShiftDate.Text = "Дата выхода:";
//
// comboBoxAssembler
//
comboBoxAssembler.FormattingEnabled = true;
comboBoxAssembler.Location = new Point(370, 193);
comboBoxAssembler.Name = "comboBoxAssembler";
comboBoxAssembler.Size = new Size(298, 40);
comboBoxAssembler.TabIndex = 4;
//
// comboBoxShiftDate
//
comboBoxShiftDate.FormattingEnabled = true;
comboBoxShiftDate.Location = new Point(370, 308);
comboBoxShiftDate.Name = "comboBoxShiftDate";
comboBoxShiftDate.Size = new Size(298, 40);
comboBoxShiftDate.TabIndex = 5;
//
// buttonSave
//
buttonSave.Location = new Point(99, 477);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(150, 46);
buttonSave.TabIndex = 6;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(432, 477);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(150, 46);
buttonCancel.TabIndex = 7;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// FormAssemblerShift
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(755, 621);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(comboBoxShiftDate);
Controls.Add(comboBoxAssembler);
Controls.Add(labelShiftDate);
Controls.Add(labelAssembler);
Controls.Add(numericUpDownWorkHours);
Controls.Add(labelWorkHours);
Name = "FormAssemblerShift";
Text = "Выход на смену";
((System.ComponentModel.ISupportInitialize)numericUpDownWorkHours).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label labelWorkHours;
private NumericUpDown numericUpDownWorkHours;
private Label labelAssembler;
private Label labelShiftDate;
private ComboBox comboBoxAssembler;
private ComboBox comboBoxShiftDate;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,71 @@
using ProjectWorkshop.Entities;
using ProjectWorkshop.Repositories;
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 ProjectWorkshop.Forms
{
public partial class FormAssemblerShift : Form
{
private readonly IAssemblerShiftRepository _assemblerShiftRepository;
public FormAssemblerShift(IAssemblerShiftRepository assemblerShiftRepository, IShiftRepository shiftRepository,
IAssemblerRepository assemblerRepository)
{
InitializeComponent();
_assemblerShiftRepository = assemblerShiftRepository ??
throw new ArgumentNullException(nameof(assemblerShiftRepository));
numericUpDownWorkHours.Value = 1;
comboBoxAssembler.DataSource = assemblerRepository.ReadAssemblers();
comboBoxAssembler.DisplayMember = "FullName";
comboBoxAssembler.ValueMember = "ID";
comboBoxShiftDate.DataSource = shiftRepository.ReadShifts().ToList();
comboBoxShiftDate.DisplayMember = "ShiftDate";
comboBoxShiftDate.ValueMember = "ID";
}
private void ButtonSave_Click(object sender, EventArgs e)
{
try
{
if (numericUpDownWorkHours.Value < 1 || comboBoxAssembler.SelectedIndex < 0 || comboBoxShiftDate.SelectedIndex < 0)
{
throw new Exception("Имеются незаполненные поля");
}
var selectedShift = (dynamic)comboBoxShiftDate.SelectedItem;
DateTime shiftDate = selectedShift.ShiftDate;
var assemblerShift = AssemblerShift.CreateOperation(0,
(int)numericUpDownWorkHours.Value,
(int)comboBoxAssembler.SelectedValue!,
(int)comboBoxShiftDate.SelectedValue!,
shiftDate);
_assemblerShiftRepository.CreateAssemblerShift(assemblerShift);
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
Close();
}
}
}

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

@ -0,0 +1,102 @@
namespace ProjectWorkshop.Forms
{
partial class FormAssemblerShifts
{
/// <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()
{
panel = new Panel();
buttonAdd = new Button();
dataGridViewAssemblerShifts = new DataGridView();
panel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewAssemblerShifts).BeginInit();
SuspendLayout();
//
// panel
//
panel.Controls.Add(buttonAdd);
panel.Dock = DockStyle.Right;
panel.Location = new Point(582, 0);
panel.Margin = new Padding(2, 1, 2, 1);
panel.Name = "panel";
panel.Size = new Size(143, 367);
panel.TabIndex = 0;
//
// buttonAdd
//
buttonAdd.BackgroundImage = Properties.Resources.plus;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(35, 22);
buttonAdd.Margin = new Padding(2, 1, 2, 1);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(82, 68);
buttonAdd.TabIndex = 0;
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// dataGridViewAssemblerShifts
//
dataGridViewAssemblerShifts.AllowUserToAddRows = false;
dataGridViewAssemblerShifts.AllowUserToDeleteRows = false;
dataGridViewAssemblerShifts.AllowUserToResizeColumns = false;
dataGridViewAssemblerShifts.AllowUserToResizeRows = false;
dataGridViewAssemblerShifts.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewAssemblerShifts.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewAssemblerShifts.Dock = DockStyle.Fill;
dataGridViewAssemblerShifts.Location = new Point(0, 0);
dataGridViewAssemblerShifts.Margin = new Padding(2, 1, 2, 1);
dataGridViewAssemblerShifts.MultiSelect = false;
dataGridViewAssemblerShifts.Name = "dataGridViewAssemblerShifts";
dataGridViewAssemblerShifts.ReadOnly = true;
dataGridViewAssemblerShifts.RowHeadersVisible = false;
dataGridViewAssemblerShifts.RowHeadersWidth = 82;
dataGridViewAssemblerShifts.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewAssemblerShifts.Size = new Size(582, 367);
dataGridViewAssemblerShifts.TabIndex = 1;
//
// FormAssemblerShifts
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(725, 367);
Controls.Add(dataGridViewAssemblerShifts);
Controls.Add(panel);
Margin = new Padding(2, 1, 2, 1);
Name = "FormAssemblerShifts";
Text = "Выходы на смену";
Load += FormAssemblerShifts_Load;
panel.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridViewAssemblerShifts).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panel;
private Button buttonAdd;
private DataGridView dataGridViewAssemblerShifts;
}
}

View File

@ -0,0 +1,54 @@
using ProjectWorkshop.Repositories;
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 Unity;
namespace ProjectWorkshop.Forms
{
public partial class FormAssemblerShifts : Form
{
private readonly IUnityContainer _container;
private readonly IAssemblerShiftRepository _assemblerShiftRepository;
public FormAssemblerShifts(IUnityContainer container, IAssemblerShiftRepository assemblerShiftRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_assemblerShiftRepository = assemblerShiftRepository ??
throw new ArgumentNullException(nameof(assemblerShiftRepository));
}
private void FormAssemblerShifts_Load(object sender, EventArgs e)
{
try
{
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormAssemblerShift>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridViewAssemblerShifts.DataSource = _assemblerShiftRepository.ReadAssemblerShifts();
}
}

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

@ -0,0 +1,127 @@
namespace ProjectWorkshop.Forms
{
partial class FormAssemblers
{
/// <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()
{
panel = new Panel();
buttonDel = new Button();
buttonUpd = new Button();
buttonAdd = new Button();
dataGridViewAssemblers = new DataGridView();
panel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewAssemblers).BeginInit();
SuspendLayout();
//
// panel
//
panel.Controls.Add(buttonDel);
panel.Controls.Add(buttonUpd);
panel.Controls.Add(buttonAdd);
panel.Dock = DockStyle.Right;
panel.Location = new Point(1279, 0);
panel.Name = "panel";
panel.Size = new Size(313, 850);
panel.TabIndex = 0;
//
// buttonDel
//
buttonDel.BackgroundImage = Properties.Resources.minus;
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
buttonDel.Location = new Point(83, 479);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(150, 145);
buttonDel.TabIndex = 2;
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += ButtonDel_Click;
//
// buttonUpd
//
buttonUpd.BackgroundImage = Properties.Resources.pencil;
buttonUpd.BackgroundImageLayout = ImageLayout.Stretch;
buttonUpd.Location = new Point(83, 255);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(150, 145);
buttonUpd.TabIndex = 1;
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += ButtonUpd_Click;
//
// buttonAdd
//
buttonAdd.BackgroundImage = Properties.Resources.plus;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(83, 39);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(150, 145);
buttonAdd.TabIndex = 0;
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// dataGridViewAssemblers
//
dataGridViewAssemblers.AllowUserToAddRows = false;
dataGridViewAssemblers.AllowUserToDeleteRows = false;
dataGridViewAssemblers.AllowUserToResizeColumns = false;
dataGridViewAssemblers.AllowUserToResizeRows = false;
dataGridViewAssemblers.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewAssemblers.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewAssemblers.Dock = DockStyle.Fill;
dataGridViewAssemblers.Location = new Point(0, 0);
dataGridViewAssemblers.MultiSelect = false;
dataGridViewAssemblers.Name = "dataGridViewAssemblers";
dataGridViewAssemblers.ReadOnly = true;
dataGridViewAssemblers.RowHeadersVisible = false;
dataGridViewAssemblers.RowHeadersWidth = 82;
dataGridViewAssemblers.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewAssemblers.Size = new Size(1279, 850);
dataGridViewAssemblers.TabIndex = 1;
//
// FormAssemblers
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1592, 850);
Controls.Add(dataGridViewAssemblers);
Controls.Add(panel);
Name = "FormAssemblers";
StartPosition = FormStartPosition.CenterParent;
Text = "Сборщики";
Load += FormAssemblers_Load;
panel.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridViewAssemblers).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panel;
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
private DataGridView dataGridViewAssemblers;
}
}

View File

@ -0,0 +1,115 @@
using ProjectWorkshop.Repositories;
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 Unity;
namespace ProjectWorkshop.Forms
{
public partial class FormAssemblers : Form
{
private readonly IUnityContainer _container;
private readonly IAssemblerRepository _assemblerRepository;
public FormAssemblers(IUnityContainer container, IAssemblerRepository assemblerRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_assemblerRepository = assemblerRepository ??
throw new ArgumentNullException(nameof(assemblerRepository));
}
private void FormAssemblers_Load(object sender, EventArgs e)
{
try
{
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormAssembler>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
{
return;
}
try
{
var form = _container.Resolve<FormAssembler>();
form.Id = findId;
form.ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при изменении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
{
return;
}
if (MessageBox.Show("Удалить запись?", "Удаление",
MessageBoxButtons.YesNo) != DialogResult.Yes)
{
return;
}
try
{
_assemblerRepository.DeleteAssembler(findId);
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при удалении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridViewAssemblers.DataSource = _assemblerRepository.ReadAssemblers();
private bool TryGetIdentifierFromSelectedRow(out int id)
{
id = 0;
if (dataGridViewAssemblers.SelectedRows.Count < 1)
{
MessageBox.Show("Нет выбранной записи", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
id = Convert.ToInt32(dataGridViewAssemblers.SelectedRows[0].Cells["ID"].Value);
return true;
}
}
}

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

@ -0,0 +1,172 @@
namespace ProjectWorkshop.Forms
{
partial class FormAssemblersReport
{
/// <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()
{
labelFilePath = new Label();
labelDateFrom = new Label();
dateTimePickerStart = new DateTimePicker();
textBoxFilePath = new TextBox();
buttonSelectFilePath = new Button();
buttonBuild = new Button();
dateTimePickerEnd = new DateTimePicker();
labelDateTo = new Label();
labelAssembler = new Label();
comboBoxAssembler = new ComboBox();
SuspendLayout();
//
// labelFilePath
//
labelFilePath.AutoSize = true;
labelFilePath.Location = new Point(27, 22);
labelFilePath.Margin = new Padding(2, 0, 2, 0);
labelFilePath.Name = "labelFilePath";
labelFilePath.Size = new Size(90, 15);
labelFilePath.TabIndex = 0;
labelFilePath.Text = "Путь до файла:";
//
// labelDateFrom
//
labelDateFrom.AutoSize = true;
labelDateFrom.Location = new Point(27, 94);
labelDateFrom.Margin = new Padding(2, 0, 2, 0);
labelDateFrom.Name = "labelDateFrom";
labelDateFrom.Size = new Size(77, 15);
labelDateFrom.TabIndex = 1;
labelDateFrom.Text = "Дата начала:";
//
// dateTimePickerStart
//
dateTimePickerStart.Location = new Point(137, 91);
dateTimePickerStart.Margin = new Padding(2, 1, 2, 1);
dateTimePickerStart.Name = "dateTimePickerStart";
dateTimePickerStart.Size = new Size(217, 23);
dateTimePickerStart.TabIndex = 2;
//
// textBoxFilePath
//
textBoxFilePath.Location = new Point(137, 22);
textBoxFilePath.Margin = new Padding(2, 1, 2, 1);
textBoxFilePath.Name = "textBoxFilePath";
textBoxFilePath.Size = new Size(217, 23);
textBoxFilePath.TabIndex = 3;
//
// buttonSelectFilePath
//
buttonSelectFilePath.Location = new Point(356, 22);
buttonSelectFilePath.Margin = new Padding(2, 1, 2, 1);
buttonSelectFilePath.Name = "buttonSelectFilePath";
buttonSelectFilePath.Size = new Size(23, 18);
buttonSelectFilePath.TabIndex = 4;
buttonSelectFilePath.UseVisualStyleBackColor = true;
buttonSelectFilePath.Click += ButtonSelectFilePath_Click;
//
// buttonBuild
//
buttonBuild.Location = new Point(137, 175);
buttonBuild.Margin = new Padding(2, 1, 2, 1);
buttonBuild.Name = "buttonBuild";
buttonBuild.Size = new Size(103, 25);
buttonBuild.TabIndex = 5;
buttonBuild.Text = "Сформировать";
buttonBuild.UseVisualStyleBackColor = true;
buttonBuild.Click += ButtonBuild_Click;
//
// dateTimePickerEnd
//
dateTimePickerEnd.Location = new Point(137, 130);
dateTimePickerEnd.Margin = new Padding(2, 1, 2, 1);
dateTimePickerEnd.Name = "dateTimePickerEnd";
dateTimePickerEnd.Size = new Size(217, 23);
dateTimePickerEnd.TabIndex = 7;
//
// labelDateTo
//
labelDateTo.AutoSize = true;
labelDateTo.Location = new Point(27, 132);
labelDateTo.Margin = new Padding(2, 0, 2, 0);
labelDateTo.Name = "labelDateTo";
labelDateTo.Size = new Size(71, 15);
labelDateTo.TabIndex = 6;
labelDateTo.Text = "Дата конца:";
//
// labelAssembler
//
labelAssembler.AutoSize = true;
labelAssembler.Location = new Point(42, 60);
labelAssembler.Margin = new Padding(2, 0, 2, 0);
labelAssembler.Name = "labelAssembler";
labelAssembler.Size = new Size(63, 15);
labelAssembler.TabIndex = 8;
labelAssembler.Text = "Сборщик:";
//
// comboBoxAssembler
//
comboBoxAssembler.FormattingEnabled = true;
comboBoxAssembler.Location = new Point(137, 59);
comboBoxAssembler.Margin = new Padding(2, 1, 2, 1);
comboBoxAssembler.Name = "comboBoxAssembler";
comboBoxAssembler.Size = new Size(217, 23);
comboBoxAssembler.TabIndex = 9;
//
// FormAssemblersReport
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(431, 211);
Controls.Add(comboBoxAssembler);
Controls.Add(labelAssembler);
Controls.Add(dateTimePickerEnd);
Controls.Add(labelDateTo);
Controls.Add(buttonBuild);
Controls.Add(buttonSelectFilePath);
Controls.Add(textBoxFilePath);
Controls.Add(dateTimePickerStart);
Controls.Add(labelDateFrom);
Controls.Add(labelFilePath);
Margin = new Padding(2, 1, 2, 1);
Name = "FormAssemblersReport";
Text = "Отчет по сборщикам";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label labelFilePath;
private Label labelDateFrom;
private DateTimePicker dateTimePickerStart;
private TextBox textBoxFilePath;
private Button buttonSelectFilePath;
private Button buttonBuild;
private DateTimePicker dateTimePickerEnd;
private Label labelDateTo;
private Label labelAssembler;
private ComboBox comboBoxAssembler;
}
}

View File

@ -0,0 +1,78 @@
using ProjectWorkshop.Reports;
using ProjectWorkshop.Repositories;
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 Unity;
namespace ProjectWorkshop.Forms
{
public partial class FormAssemblersReport : Form
{
private readonly IUnityContainer _container;
public FormAssemblersReport(IUnityContainer container, IAssemblerRepository assemblerRepository)
{
InitializeComponent();
_container = container ?? throw new ArgumentNullException(nameof(container));
comboBoxAssembler.DataSource = assemblerRepository.ReadAssemblers();
comboBoxAssembler.DisplayMember = "Name";
comboBoxAssembler.ValueMember = "ID";
}
private void ButtonSelectFilePath_Click(object sender, EventArgs e)
{
var sfd = new SaveFileDialog()
{
Filter = "Excel Files | *.xlsx"
};
if (sfd.ShowDialog() != DialogResult.OK)
{
return;
}
textBoxFilePath.Text = sfd.FileName;
}
private void ButtonBuild_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(textBoxFilePath.Text))
{
throw new Exception("Отсутствует имя файла для отчета");
}
if (dateTimePickerEnd.Value < dateTimePickerStart.Value)
{
throw new Exception("Дата начала должна быть раньше даты окончания");
}
if (comboBoxAssembler.SelectedIndex < 0)
{
throw new Exception("Не выбран сборщик");
}
if (_container.Resolve<TableReport>().CreateTable(textBoxFilePath.Text, (int)comboBoxAssembler.SelectedValue!,
dateTimePickerStart.Value, dateTimePickerEnd.Value))
{
MessageBox.Show("Документ сформирован", "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Возникли ошибки при формировании документа. Подробности в логах", "Формирование документа",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при создании очета",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

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

@ -0,0 +1,117 @@
namespace ProjectWorkshop.Forms
{
partial class FormAssemblies
{
/// <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()
{
panel = new Panel();
buttonDel = new Button();
buttonAdd = new Button();
dataGridViewAssemblies = new DataGridView();
panel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewAssemblies).BeginInit();
SuspendLayout();
//
// panel
//
panel.Controls.Add(buttonDel);
panel.Controls.Add(buttonAdd);
panel.Dock = DockStyle.Right;
panel.Location = new Point(572, 0);
panel.Margin = new Padding(2, 1, 2, 1);
panel.Name = "panel";
panel.Size = new Size(150, 374);
panel.TabIndex = 0;
//
// buttonDel
//
buttonDel.BackgroundImage = Properties.Resources.minus;
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
buttonDel.Location = new Point(36, 143);
buttonDel.Margin = new Padding(2, 1, 2, 1);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(81, 71);
buttonDel.TabIndex = 1;
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += ButtonDel_Click;
//
// buttonAdd
//
buttonAdd.BackgroundImage = Properties.Resources.plus;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(36, 19);
buttonAdd.Margin = new Padding(2, 1, 2, 1);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(81, 71);
buttonAdd.TabIndex = 0;
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// dataGridViewAssemblies
//
dataGridViewAssemblies.AllowUserToAddRows = false;
dataGridViewAssemblies.AllowUserToDeleteRows = false;
dataGridViewAssemblies.AllowUserToResizeColumns = false;
dataGridViewAssemblies.AllowUserToResizeRows = false;
dataGridViewAssemblies.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewAssemblies.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewAssemblies.Dock = DockStyle.Fill;
dataGridViewAssemblies.Location = new Point(0, 0);
dataGridViewAssemblies.Margin = new Padding(2, 1, 2, 1);
dataGridViewAssemblies.MultiSelect = false;
dataGridViewAssemblies.Name = "dataGridViewAssemblies";
dataGridViewAssemblies.ReadOnly = true;
dataGridViewAssemblies.RowHeadersVisible = false;
dataGridViewAssemblies.RowHeadersWidth = 82;
dataGridViewAssemblies.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewAssemblies.Size = new Size(572, 374);
dataGridViewAssemblies.TabIndex = 1;
//
// FormAssemblies
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(722, 374);
Controls.Add(dataGridViewAssemblies);
Controls.Add(panel);
Margin = new Padding(2, 1, 2, 1);
Name = "FormAssemblies";
Text = "Сборки";
Load += FormAssemblies_Load;
panel.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridViewAssemblies).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panel;
private Button buttonDel;
private Button buttonAdd;
private DataGridView dataGridViewAssemblies;
}
}

View File

@ -0,0 +1,93 @@
using ProjectWorkshop.Repositories;
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 Unity;
namespace ProjectWorkshop.Forms
{
public partial class FormAssemblies : Form
{
private readonly IUnityContainer _container;
private readonly IAssemblyRepository _assemblyRepository;
public FormAssemblies(IUnityContainer container, IAssemblyRepository assemblyRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_assemblyRepository = assemblyRepository ??
throw new ArgumentNullException(nameof(assemblyRepository));
}
private void FormAssemblies_Load(object sender, EventArgs e)
{
try
{
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormAssembly>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
{
return;
}
if (MessageBox.Show("Удалить запись?", "Удаление",
MessageBoxButtons.YesNo) != DialogResult.Yes)
{
return;
}
try
{
_assemblyRepository.DeleteAssembly(findId);
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при удалении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridViewAssemblies.DataSource = _assemblyRepository.ReadAssemblies();
private bool TryGetIdentifierFromSelectedRow(out int id)
{
id = 0;
if (dataGridViewAssemblies.SelectedRows.Count < 1)
{
MessageBox.Show("Нет выбранной записи", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
id = Convert.ToInt32(dataGridViewAssemblies.SelectedRows[0].Cells["ID"].Value);
return true;
}
}
}

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

@ -0,0 +1,171 @@
namespace ProjectWorkshop.Forms
{
partial class FormAssembly
{
/// <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()
{
labelAssembler = new Label();
comboBoxAssembler = new ComboBox();
groupBox = new GroupBox();
dataGridViewAssemblies = new DataGridView();
ColumnProductName = new DataGridViewComboBoxColumn();
ColumnCount = new DataGridViewTextBoxColumn();
buttonSave = new Button();
buttonCancel = new Button();
labelAssemblyDate = new Label();
dateTimePickerAssemblyDate = new DateTimePicker();
groupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewAssemblies).BeginInit();
SuspendLayout();
//
// labelAssembler
//
labelAssembler.AutoSize = true;
labelAssembler.Location = new Point(50, 71);
labelAssembler.Name = "labelAssembler";
labelAssembler.Size = new Size(122, 32);
labelAssembler.TabIndex = 0;
labelAssembler.Text = "Сборщик:";
//
// comboBoxAssembler
//
comboBoxAssembler.FormattingEnabled = true;
comboBoxAssembler.Location = new Point(242, 71);
comboBoxAssembler.Name = "comboBoxAssembler";
comboBoxAssembler.Size = new Size(386, 40);
comboBoxAssembler.TabIndex = 1;
//
// groupBox
//
groupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
groupBox.Controls.Add(dataGridViewAssemblies);
groupBox.Location = new Point(50, 177);
groupBox.Name = "groupBox";
groupBox.Size = new Size(618, 602);
groupBox.TabIndex = 2;
groupBox.TabStop = false;
//
// dataGridViewAssemblies
//
dataGridViewAssemblies.AllowUserToResizeColumns = false;
dataGridViewAssemblies.AllowUserToResizeRows = false;
dataGridViewAssemblies.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewAssemblies.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewAssemblies.Columns.AddRange(new DataGridViewColumn[] { ColumnProductName, ColumnCount });
dataGridViewAssemblies.Location = new Point(3, 35);
dataGridViewAssemblies.MultiSelect = false;
dataGridViewAssemblies.Name = "dataGridViewAssemblies";
dataGridViewAssemblies.RowHeadersVisible = false;
dataGridViewAssemblies.RowHeadersWidth = 82;
dataGridViewAssemblies.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewAssemblies.Size = new Size(612, 553);
dataGridViewAssemblies.TabIndex = 0;
//
// ColumnProductName
//
ColumnProductName.HeaderText = "Название изделия";
ColumnProductName.MinimumWidth = 10;
ColumnProductName.Name = "ColumnProductName";
//
// ColumnCount
//
ColumnCount.HeaderText = "Количество";
ColumnCount.MinimumWidth = 10;
ColumnCount.Name = "ColumnCount";
//
// buttonSave
//
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonSave.Location = new Point(110, 823);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(150, 46);
buttonSave.TabIndex = 3;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Location = new Point(439, 823);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(150, 46);
buttonCancel.TabIndex = 4;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// labelAssemblyDate
//
labelAssemblyDate.AutoSize = true;
labelAssemblyDate.Location = new Point(50, 137);
labelAssemblyDate.Name = "labelAssemblyDate";
labelAssemblyDate.Size = new Size(156, 32);
labelAssemblyDate.TabIndex = 5;
labelAssemblyDate.Text = "Дата сборки:";
//
// dateTimePickerAssemblyDate
//
dateTimePickerAssemblyDate.Location = new Point(242, 132);
dateTimePickerAssemblyDate.Name = "dateTimePickerAssemblyDate";
dateTimePickerAssemblyDate.Size = new Size(386, 39);
dateTimePickerAssemblyDate.TabIndex = 6;
//
// FormAssembly
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(715, 912);
Controls.Add(dateTimePickerAssemblyDate);
Controls.Add(labelAssemblyDate);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(groupBox);
Controls.Add(comboBoxAssembler);
Controls.Add(labelAssembler);
Name = "FormAssembly";
Text = "Сборка";
groupBox.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridViewAssemblies).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label labelAssembler;
private ComboBox comboBoxAssembler;
private GroupBox groupBox;
private DataGridView dataGridViewAssemblies;
private DataGridViewComboBoxColumn ColumnProductName;
private DataGridViewTextBoxColumn ColumnCount;
private Button buttonSave;
private Button buttonCancel;
private Label labelAssemblyDate;
private DateTimePicker dateTimePickerAssemblyDate;
}
}

View File

@ -0,0 +1,100 @@
using ProjectWorkshop.Entities;
using ProjectWorkshop.Repositories;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ProjectWorkshop.Forms
{
public partial class FormAssembly : Form
{
private readonly IAssemblyRepository _assemblyRepository;
public FormAssembly(IAssemblyRepository assemblyRepository, IAssemblerRepository assemblerRepository, IProductRepository productRepository)
{
InitializeComponent();
_assemblyRepository = assemblyRepository ?? throw new ArgumentNullException(nameof(assemblyRepository));
comboBoxAssembler.DataSource = assemblerRepository.ReadAssemblers();
comboBoxAssembler.DisplayMember = "FullName";
comboBoxAssembler.ValueMember = "ID";
var products = productRepository.ReadProducts()
.Select(p => new { p.ProductName, p.ID })
.ToList();
ColumnProductName.DataSource = products;
ColumnProductName.DisplayMember = "ProductName";
ColumnProductName.ValueMember = "ID";
}
private void ButtonSave_Click(object sender, EventArgs e)
{
try
{
if (dataGridViewAssemblies.RowCount < 1 || comboBoxAssembler.SelectedIndex < 0)
{
throw new Exception("Имеются незаполненные поля");
}
var productAssemblies = CreateListProductAssemblyFromDataGrid();
if (!productAssemblies.Any())
{
throw new Exception("Добавьте хотя бы один продукт для сборки.");
}
var totalCount = productAssemblies.Sum(pa => pa.Count);
var assemblyDate = dateTimePickerAssemblyDate.Value;
_assemblyRepository.CreateAssembly(Assembly.CreateOperation(
id: 0,
count: totalCount,
assemblerID: (int)comboBoxAssembler.SelectedValue!,
assemblyDate: assemblyDate,
productAssembly: productAssemblies
));
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
Close();
}
private List<ProductAssembly> CreateListProductAssemblyFromDataGrid()
{
var list = new List<ProductAssembly>();
foreach (DataGridViewRow row in dataGridViewAssemblies.Rows)
{
if (row.Cells["ColumnProductName"].Value == null || row.Cells["ColumnCount"].Value == null)
{
continue;
}
list.Add(ProductAssembly.CreateElement(
id: 0,
productID: Convert.ToInt32(row.Cells["ColumnProductName"].Value),
assemblyID: 0,
count: Convert.ToInt32(row.Cells["ColumnCount"].Value)
));
}
return list;
}
}
}

View File

@ -0,0 +1,126 @@
<?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>
<metadata name="ColumnProductName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -0,0 +1,107 @@
namespace ProjectWorkshop.Forms
{
partial class FormAssemblyDistributionReport
{
/// <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()
{
buttonSelectFileName = new Button();
labelFileName = new Label();
labelDate = new Label();
dateTimePickerDate = new DateTimePicker();
buttonCreate = new Button();
SuspendLayout();
//
// buttonSelectFileName
//
buttonSelectFileName.Location = new Point(37, 29);
buttonSelectFileName.Name = "buttonSelectFileName";
buttonSelectFileName.Size = new Size(75, 23);
buttonSelectFileName.TabIndex = 0;
buttonSelectFileName.Text = "Выбрать";
buttonSelectFileName.UseVisualStyleBackColor = true;
buttonSelectFileName.Click += ButtonSelectFileName_Click;
//
// labelFileName
//
labelFileName.AutoSize = true;
labelFileName.Location = new Point(132, 33);
labelFileName.Name = "labelFileName";
labelFileName.Size = new Size(36, 15);
labelFileName.TabIndex = 1;
labelFileName.Text = "Файл";
//
// labelDate
//
labelDate.AutoSize = true;
labelDate.Location = new Point(37, 83);
labelDate.Name = "labelDate";
labelDate.Size = new Size(35, 15);
labelDate.TabIndex = 2;
labelDate.Text = "Дата:";
//
// dateTimePickerDate
//
dateTimePickerDate.Location = new Point(89, 77);
dateTimePickerDate.Name = "dateTimePickerDate";
dateTimePickerDate.Size = new Size(200, 23);
dateTimePickerDate.TabIndex = 3;
//
// buttonCreate
//
buttonCreate.Location = new Point(105, 141);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(110, 23);
buttonCreate.TabIndex = 4;
buttonCreate.Text = "Сформировать";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreate_Click;
//
// FormAssemblyDistributionReport
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(333, 193);
Controls.Add(buttonCreate);
Controls.Add(dateTimePickerDate);
Controls.Add(labelDate);
Controls.Add(labelFileName);
Controls.Add(buttonSelectFileName);
Name = "FormAssemblyDistributionReport";
Text = "Распределение сборок";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonSelectFileName;
private Label labelFileName;
private Label labelDate;
private DateTimePicker dateTimePickerDate;
private Button buttonCreate;
}
}

View File

@ -0,0 +1,71 @@
using ProjectWorkshop.Reports;
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 Unity;
namespace ProjectWorkshop.Forms
{
public partial class FormAssemblyDistributionReport : Form
{
private string _fileName = string.Empty;
private readonly IUnityContainer _container;
public FormAssemblyDistributionReport(IUnityContainer container)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
}
private void ButtonSelectFileName_Click(object sender, EventArgs e)
{
var sfd = new SaveFileDialog()
{
Filter = "Pdf Files | *.pdf"
};
if (sfd.ShowDialog() == DialogResult.OK)
{
_fileName = sfd.FileName;
labelFileName.Text = Path.GetFileName(_fileName);
}
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(_fileName))
{
throw new Exception("Отсутствует имя файла для отчета");
}
if
(_container.Resolve<ChartReport>().CreateChart(_fileName, dateTimePickerDate.Value))
{
MessageBox.Show("Документ сформирован",
"Формирование документа",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Возникли ошибки при формировании документа. Подробности в логах",
"Формирование документа",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при создании очета",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

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

@ -0,0 +1,99 @@
namespace ProjectWorkshop.Forms
{
partial class FormDirectoryReport
{
/// <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()
{
checkBoxProducts = new CheckBox();
checkBoxAssemblers = new CheckBox();
checkBoxShifts = new CheckBox();
buttonBuild = new Button();
SuspendLayout();
//
// checkBoxProducts
//
checkBoxProducts.AutoSize = true;
checkBoxProducts.Location = new Point(63, 66);
checkBoxProducts.Name = "checkBoxProducts";
checkBoxProducts.Size = new Size(140, 36);
checkBoxProducts.TabIndex = 0;
checkBoxProducts.Text = "Изделия";
checkBoxProducts.UseVisualStyleBackColor = true;
//
// checkBoxAssemblers
//
checkBoxAssemblers.AutoSize = true;
checkBoxAssemblers.Location = new Point(63, 162);
checkBoxAssemblers.Name = "checkBoxAssemblers";
checkBoxAssemblers.Size = new Size(163, 36);
checkBoxAssemblers.TabIndex = 1;
checkBoxAssemblers.Text = "Сборщики";
checkBoxAssemblers.UseVisualStyleBackColor = true;
//
// checkBoxShifts
//
checkBoxShifts.AutoSize = true;
checkBoxShifts.Location = new Point(63, 262);
checkBoxShifts.Name = "checkBoxShifts";
checkBoxShifts.Size = new Size(122, 36);
checkBoxShifts.TabIndex = 2;
checkBoxShifts.Text = "Смены";
checkBoxShifts.UseVisualStyleBackColor = true;
//
// buttonBuild
//
buttonBuild.Location = new Point(370, 156);
buttonBuild.Name = "buttonBuild";
buttonBuild.Size = new Size(235, 46);
buttonBuild.TabIndex = 3;
buttonBuild.Text = "Сформировать";
buttonBuild.UseVisualStyleBackColor = true;
buttonBuild.Click += buttonBuild_Click;
//
// FormDirectoryReport
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(712, 345);
Controls.Add(buttonBuild);
Controls.Add(checkBoxShifts);
Controls.Add(checkBoxAssemblers);
Controls.Add(checkBoxProducts);
Name = "FormDirectoryReport";
Text = "Выбор справочников";
ResumeLayout(false);
PerformLayout();
}
#endregion
private CheckBox checkBoxProducts;
private CheckBox checkBoxAssemblers;
private CheckBox checkBoxShifts;
private Button buttonBuild;
}
}

View File

@ -0,0 +1,66 @@
using ProjectWorkshop.Reports;
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 Unity;
namespace ProjectWorkshop.Forms
{
public partial class FormDirectoryReport : Form
{
private readonly IUnityContainer _container;
public FormDirectoryReport(IUnityContainer container)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
}
private void buttonBuild_Click(object sender, EventArgs e)
{
try
{
if (!checkBoxProducts.Checked &&
!checkBoxAssemblers.Checked && !checkBoxShifts.Checked)
{
throw new Exception("Не выбран ни один справочник для выгрузки");
}
var sfd = new SaveFileDialog()
{
Filter = "Docx Files | *.docx"
};
if (sfd.ShowDialog() != DialogResult.OK)
{
throw new Exception("Не выбран файла для отчета");
}
if
(_container.Resolve<DocReport>().CreateDoc(sfd.FileName,
checkBoxProducts.Checked,
checkBoxAssemblers.Checked,
checkBoxShifts.Checked))
{
MessageBox.Show("Документ сформирован",
"Формирование документа",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах",
"Формирование документа",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при создании отчета", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

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

@ -0,0 +1,143 @@
namespace ProjectWorkshop.Forms
{
partial class FormProduct
{
/// <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()
{
labelProductName = new Label();
labelProductType = new Label();
labelPrice = new Label();
textBoxProductName = new TextBox();
numericUpDownPrice = new NumericUpDown();
checkedListBoxProductType = new CheckedListBox();
buttonSave = new Button();
buttonCancel = new Button();
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit();
SuspendLayout();
//
// labelProductName
//
labelProductName.AutoSize = true;
labelProductName.Location = new Point(52, 73);
labelProductName.Name = "labelProductName";
labelProductName.Size = new Size(222, 32);
labelProductName.TabIndex = 0;
labelProductName.Text = "Название изделия:";
//
// labelProductType
//
labelProductType.AutoSize = true;
labelProductType.Location = new Point(77, 431);
labelProductType.Name = "labelProductType";
labelProductType.Size = new Size(157, 32);
labelProductType.TabIndex = 1;
labelProductType.Text = "Тип изделия:";
//
// labelPrice
//
labelPrice.AutoSize = true;
labelPrice.Location = new Point(86, 226);
labelPrice.Name = "labelPrice";
labelPrice.Size = new Size(136, 32);
labelPrice.TabIndex = 2;
labelPrice.Text = "Стоимость:";
//
// textBoxProductName
//
textBoxProductName.Location = new Point(318, 73);
textBoxProductName.Name = "textBoxProductName";
textBoxProductName.Size = new Size(332, 39);
textBoxProductName.TabIndex = 3;
//
// numericUpDownPrice
//
numericUpDownPrice.Location = new Point(318, 224);
numericUpDownPrice.Maximum = new decimal(new int[] { 1000000000, 0, 0, 0 });
numericUpDownPrice.Name = "numericUpDownPrice";
numericUpDownPrice.Size = new Size(332, 39);
numericUpDownPrice.TabIndex = 4;
//
// checkedListBoxProductType
//
checkedListBoxProductType.FormattingEnabled = true;
checkedListBoxProductType.Location = new Point(318, 361);
checkedListBoxProductType.Name = "checkedListBoxProductType";
checkedListBoxProductType.Size = new Size(332, 184);
checkedListBoxProductType.TabIndex = 5;
//
// buttonSave
//
buttonSave.Location = new Point(110, 640);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(150, 46);
buttonSave.TabIndex = 6;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(426, 640);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(150, 46);
buttonCancel.TabIndex = 7;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// FormProduct
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(729, 765);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(checkedListBoxProductType);
Controls.Add(numericUpDownPrice);
Controls.Add(textBoxProductName);
Controls.Add(labelPrice);
Controls.Add(labelProductType);
Controls.Add(labelProductName);
Name = "FormProduct";
Text = "Изделие";
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label labelProductName;
private Label labelProductType;
private Label labelPrice;
private TextBox textBoxProductName;
private NumericUpDown numericUpDownPrice;
private CheckedListBox checkedListBoxProductType;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,123 @@
using ProjectWorkshop.Entities;
using ProjectWorkshop.Entities.Enums;
using ProjectWorkshop.Repositories;
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 ProjectWorkshop.Forms
{
public partial class FormProduct : Form
{
private readonly IProductRepository _productRepository;
private int? _productID;
public int Id
{
set
{
try
{
var product = _productRepository.ReadProductByID(value);
if (product == null)
{
throw new InvalidDataException(nameof(product));
}
foreach (ProductType elem in Enum.GetValues(typeof(ProductType)))
{
if ((elem & product.ProductType) != 0)
{
checkedListBoxProductType.SetItemChecked(checkedListBoxProductType.Items.IndexOf(elem), true);
}
}
textBoxProductName.Text = product.ProductName;
numericUpDownPrice.Value = (int)product.Price;
_productID = value;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
public FormProduct(IProductRepository productRepository, IAssemblerRepository assemblerRepository)
{
InitializeComponent();
_productRepository = productRepository ??
throw new ArgumentNullException(nameof(productRepository));
foreach (var elem in Enum.GetValues(typeof(ProductType)))
{
checkedListBoxProductType.Items.Add(elem);
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(textBoxProductName.Text) || checkedListBoxProductType.CheckedItems.Count == 0)
{
throw new Exception("Имеются незаполненные поля");
}
if (_productID.HasValue)
{
_productRepository.UpdateProduct(CreateProduct(_productID.Value));
}
else
{
_productRepository.CreateProduct(CreateProduct(0));
}
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
Close();
}
private Product CreateProduct(int id)
{
ProductType productType = ProductType.None;
foreach (var elem in checkedListBoxProductType.CheckedItems)
{
productType |= (ProductType)elem;
}
if (string.IsNullOrEmpty(textBoxProductName.Text))
{
throw new Exception("Название продукта не может быть пустым");
}
return Product.CreateEntity(
id,
textBoxProductName.Text,
Convert.ToDouble(numericUpDownPrice.Value),
productType
);
}
}
}

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

@ -0,0 +1,126 @@
namespace ProjectWorkshop.Forms
{
partial class FormProducts
{
/// <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()
{
panel = new Panel();
buttonDel = new Button();
buttonUpd = new Button();
buttonAdd = new Button();
dataGridViewProducts = new DataGridView();
panel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewProducts).BeginInit();
SuspendLayout();
//
// panel
//
panel.Controls.Add(buttonDel);
panel.Controls.Add(buttonUpd);
panel.Controls.Add(buttonAdd);
panel.Dock = DockStyle.Right;
panel.Location = new Point(903, 0);
panel.Name = "panel";
panel.Size = new Size(257, 757);
panel.TabIndex = 0;
//
// buttonDel
//
buttonDel.BackgroundImage = Properties.Resources.minus;
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
buttonDel.Location = new Point(53, 535);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(150, 151);
buttonDel.TabIndex = 2;
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += ButtonDel_Click;
//
// buttonUpd
//
buttonUpd.BackgroundImage = Properties.Resources.pencil;
buttonUpd.BackgroundImageLayout = ImageLayout.Stretch;
buttonUpd.Location = new Point(53, 288);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(150, 151);
buttonUpd.TabIndex = 1;
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += ButtonUpd_Click;
//
// buttonAdd
//
buttonAdd.BackgroundImage = Properties.Resources.plus;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(55, 50);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(150, 151);
buttonAdd.TabIndex = 0;
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// dataGridViewProducts
//
dataGridViewProducts.AllowUserToAddRows = false;
dataGridViewProducts.AllowUserToDeleteRows = false;
dataGridViewProducts.AllowUserToResizeColumns = false;
dataGridViewProducts.AllowUserToResizeRows = false;
dataGridViewProducts.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewProducts.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewProducts.Dock = DockStyle.Fill;
dataGridViewProducts.Location = new Point(0, 0);
dataGridViewProducts.MultiSelect = false;
dataGridViewProducts.Name = "dataGridViewProducts";
dataGridViewProducts.ReadOnly = true;
dataGridViewProducts.RowHeadersVisible = false;
dataGridViewProducts.RowHeadersWidth = 82;
dataGridViewProducts.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewProducts.Size = new Size(903, 757);
dataGridViewProducts.TabIndex = 1;
//
// FormProducts
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1160, 757);
Controls.Add(dataGridViewProducts);
Controls.Add(panel);
Name = "FormProducts";
Text = "Изделия";
Load += FormProducts_Load;
panel.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridViewProducts).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panel;
private Button buttonUpd;
private Button buttonAdd;
private DataGridView dataGridViewProducts;
private Button buttonDel;
}
}

View File

@ -0,0 +1,111 @@
using ProjectWorkshop.Repositories;
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 Unity;
namespace ProjectWorkshop.Forms
{
public partial class FormProducts : Form
{
private readonly IUnityContainer _container;
private readonly IProductRepository _productRepository;
public FormProducts(IUnityContainer container, IProductRepository productRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_productRepository = productRepository ??
throw new ArgumentNullException(nameof(productRepository));
}
private void FormProducts_Load(object sender, EventArgs e)
{
try
{
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormProduct>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findID))
{
return;
}
try
{
var form = _container.Resolve<FormProduct>();
form.Id = findID;
form.ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
{
return;
}
if (MessageBox.Show("Удалить запись?", "Удаление",
MessageBoxButtons.YesNo) != DialogResult.Yes)
{
return;
}
try
{
_productRepository.DeleteProduct(findId);
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при удалении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridViewProducts.DataSource = _productRepository.ReadProducts();
private bool TryGetIdentifierFromSelectedRow(out int id)
{
id = 0;
if (dataGridViewProducts.SelectedRows.Count < 1)
{
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
id =
Convert.ToInt32(dataGridViewProducts.SelectedRows[0].Cells["ID"].Value);
return true;
}
}
}

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

@ -0,0 +1,95 @@
namespace ProjectWorkshop.Forms
{
partial class FormShift
{
/// <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()
{
labelShiftDate = new Label();
dateTimePickerShiftDate = new DateTimePicker();
buttonSave = new Button();
buttonCancel = new Button();
SuspendLayout();
//
// labelShiftDate
//
labelShiftDate.AutoSize = true;
labelShiftDate.Location = new Point(57, 166);
labelShiftDate.Name = "labelShiftDate";
labelShiftDate.Size = new Size(264, 32);
labelShiftDate.TabIndex = 0;
labelShiftDate.Text = "Дата выхода на смену:";
//
// dateTimePickerShiftDate
//
dateTimePickerShiftDate.Location = new Point(358, 166);
dateTimePickerShiftDate.Name = "dateTimePickerShiftDate";
dateTimePickerShiftDate.Size = new Size(400, 39);
dateTimePickerShiftDate.TabIndex = 1;
//
// buttonSave
//
buttonSave.Location = new Point(114, 317);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(150, 46);
buttonSave.TabIndex = 2;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(484, 317);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(150, 46);
buttonCancel.TabIndex = 3;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// FormShift
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(dateTimePickerShiftDate);
Controls.Add(labelShiftDate);
Name = "FormShift";
Text = "Смена";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label labelShiftDate;
private DateTimePicker dateTimePickerShiftDate;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,78 @@
using ProjectWorkshop.Entities;
using ProjectWorkshop.Repositories;
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 ProjectWorkshop.Forms
{
public partial class FormShift : Form
{
private readonly IShiftRepository _shiftRepository;
private int? _shiftID;
public int Id
{
set
{
try
{
var shift = _shiftRepository.ReadShiftByID(value);
if (shift == null)
{
throw new InvalidOperationException(nameof(shift));
}
_shiftID = shift.ID;
dateTimePickerShiftDate.Value = shift.ShiftDate;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
public FormShift(IShiftRepository shiftRepository)
{
InitializeComponent();
_shiftRepository = shiftRepository ??
throw new ArgumentNullException(nameof(shiftRepository));
}
private void ButtonSave_Click(object sender, EventArgs e)
{
try
{
if (_shiftID.HasValue)
{
_shiftRepository.UpdateShift(CreateShift(_shiftID.Value));
}
else
{
_shiftRepository.CreateShift(CreateShift(0));
}
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
Close();
}
private Shift CreateShift(int id) => Shift.CreateEntity(id, dateTimePickerShiftDate.Value);
}
}

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

@ -0,0 +1,124 @@
namespace ProjectWorkshop.Forms
{
partial class FormShifts
{
/// <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()
{
panel = new Panel();
buttonDel = new Button();
buttonUpd = new Button();
buttonAdd = new Button();
dataGridViewShifts = new DataGridView();
panel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewShifts).BeginInit();
SuspendLayout();
//
// panel
//
panel.Controls.Add(buttonDel);
panel.Controls.Add(buttonUpd);
panel.Controls.Add(buttonAdd);
panel.Dock = DockStyle.Right;
panel.Location = new Point(962, 0);
panel.Name = "panel";
panel.Size = new Size(326, 768);
panel.TabIndex = 0;
//
// buttonDel
//
buttonDel.BackgroundImage = Properties.Resources.minus;
buttonDel.BackgroundImageLayout = ImageLayout.Stretch;
buttonDel.Location = new Point(93, 542);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(150, 151);
buttonDel.TabIndex = 2;
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += ButtonDel_Click;
//
// buttonUpd
//
buttonUpd.BackgroundImage = Properties.Resources.pencil;
buttonUpd.BackgroundImageLayout = ImageLayout.Stretch;
buttonUpd.Location = new Point(93, 294);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(150, 151);
buttonUpd.TabIndex = 1;
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += ButtonUpd_Click;
//
// buttonAdd
//
buttonAdd.BackgroundImage = Properties.Resources.plus;
buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
buttonAdd.Location = new Point(93, 59);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(150, 151);
buttonAdd.TabIndex = 0;
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// dataGridViewShifts
//
dataGridViewShifts.AllowUserToResizeColumns = false;
dataGridViewShifts.AllowUserToResizeRows = false;
dataGridViewShifts.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewShifts.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewShifts.Dock = DockStyle.Fill;
dataGridViewShifts.Location = new Point(0, 0);
dataGridViewShifts.MultiSelect = false;
dataGridViewShifts.Name = "dataGridViewShifts";
dataGridViewShifts.ReadOnly = true;
dataGridViewShifts.RowHeadersVisible = false;
dataGridViewShifts.RowHeadersWidth = 82;
dataGridViewShifts.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewShifts.Size = new Size(962, 768);
dataGridViewShifts.TabIndex = 1;
//
// FormShifts
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1288, 768);
Controls.Add(dataGridViewShifts);
Controls.Add(panel);
Name = "FormShifts";
Text = "Смены";
Load += FormShifts_Load;
panel.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridViewShifts).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panel;
private Button buttonAdd;
private DataGridView dataGridViewShifts;
private Button buttonDel;
private Button buttonUpd;
}
}

View File

@ -0,0 +1,110 @@
using ProjectWorkshop.Repositories;
using ProjectWorkshop.Repositories.Implementations;
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 Unity;
namespace ProjectWorkshop.Forms
{
public partial class FormShifts : Form
{
private readonly IUnityContainer _container;
private readonly IShiftRepository _shiftRepository;
public FormShifts(IUnityContainer container, IShiftRepository shiftRepository)
{
InitializeComponent();
_container = container ?? throw new ArgumentNullException(nameof(container));
_shiftRepository = shiftRepository ?? throw new ArgumentNullException(nameof(shiftRepository));
}
private void FormShifts_Load(object sender, EventArgs e)
{
try
{
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormShift>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findID))
{
return;
}
try
{
var form = _container.Resolve<FormShift>();
form.Id = findID;
form.ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (!TryGetIdentifierFromSelectedRow(out var findId))
{
return;
}
if (MessageBox.Show("Удалить запись?", "Удаление",
MessageBoxButtons.YesNo) != DialogResult.Yes)
{
return;
}
try
{
_shiftRepository.DeleteShift(findId);
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при удалении",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridViewShifts.DataSource = _shiftRepository.ReadShifts();
private bool TryGetIdentifierFromSelectedRow(out int id)
{
id = 0;
if (dataGridViewShifts.SelectedRows.Count < 1)
{
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
id =
Convert.ToInt32(dataGridViewShifts.SelectedRows[0].Cells["ID"].Value);
return true;
}
}
}

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,3 +1,12 @@
using ProjectWorkshop.Repositories.Implementations;
using ProjectWorkshop.Repositories;
using Unity;
using ProjectWorkshop.Repositories.Implementation;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Serilog;
using Unity.Microsoft.Logging;
namespace ProjectWorkshop
{
internal static class Program
@ -11,7 +20,37 @@ namespace ProjectWorkshop
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
Application.Run(CreateContainer().Resolve<FormWorkshop>());
}
private static IUnityContainer CreateContainer()
{
var container = new UnityContainer();
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
container.RegisterType<IAssemblerRepository, AssemblerRepository>();
container.RegisterType<IAssemblerShiftRepository, AssemblerShiftRepository>();
container.RegisterType<IAssemblyRepository, AssemblyRepository>();
container.RegisterType<IProductAssemblyRepository, ProductAssemblyRepository>();
container.RegisterType<IProductRepository, ProductRepository>();
container.RegisterType<IShiftRepository, ShiftRepository>();
container.RegisterType<IConnectionString, ConnectionString>();
return container;
}
private static LoggerFactory CreateLoggerFactory()
{
var loggerFactory = new LoggerFactory();
loggerFactory.AddSerilog(new LoggerConfiguration()
.ReadFrom.Configuration(new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build())
.CreateLogger());
return loggerFactory;
}
}
}

View File

@ -8,4 +8,46 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="DocumentFormat.OpenXml" Version="3.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Npgsql" Version="9.0.2" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="Unity" Version="5.11.10" />
<PackageReference Include="Unity.Microsoft.Logging" Version="5.11.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -0,0 +1,103 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ProjectWorkshop.Properties {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectWorkshop.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap minus {
get {
object obj = ResourceManager.GetObject("minus", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap pencil {
get {
object obj = ResourceManager.GetObject("pencil", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap plus {
get {
object obj = ResourceManager.GetObject("plus", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap цех {
get {
object obj = ResourceManager.GetObject("цех", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -0,0 +1,133 @@
<?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>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="minus" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\minus.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="цех" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\цех.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="plus" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\plus.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="pencil" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\pencil.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View File

@ -0,0 +1,68 @@
using Microsoft.Extensions.Logging;
using ProjectWorkshop.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ProjectWorkshop.Reports
{
internal class ChartReport
{
private readonly IAssemblyRepository _assemblyRepository;
private readonly IAssemblerRepository _assemblerRepository;
private readonly ILogger<ChartReport> _logger;
public ChartReport(IAssemblyRepository assemblyRepository, IAssemblerRepository assemblerRepository, ILogger<ChartReport> logger)
{
_assemblyRepository = assemblyRepository ??
throw new ArgumentNullException(nameof(assemblyRepository));
_assemblerRepository = assemblerRepository ??
throw new ArgumentNullException(nameof(assemblerRepository));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public bool CreateChart(string filePath, DateTime dateTime)
{
try
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var data = GetData(dateTime);
new PdfBuilder(filePath)
.AddHeader("Сборки изделий")
.AddPieChart("Количество сборок по сборщикам", data)
.Build();
return true;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при формировании документа");
return false;
}
}
private List<(string Caption, double Value)> GetData(DateTime dateTime)
{
var assemblies = _assemblyRepository
.ReadAssemblies()
.Where(x => x.AssemblyDate.Date == dateTime.Date)
.GroupBy(x => x.AssemblerID_Assembler)
.Select(group => new
{
AssemblerId = group.Key,
AssemblyCount = group.Count()
})
.ToList();
var assemblerNames = _assemblerRepository.ReadAssemblers()
.ToDictionary(a => a.ID, a => a.FullName);
return assemblies
.Select(x => (assemblerNames.ContainsKey(x.AssemblerId) ? assemblerNames[x.AssemblerId] : $"Сборщик {x.AssemblerId}", (double)x.AssemblyCount))
.ToList();
}
}
}

View File

@ -0,0 +1,84 @@
using Microsoft.Extensions.Logging;
using ProjectWorkshop.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWorkshop.Reports;
internal class DocReport
{
private readonly IAssemblerRepository _assemblerRepository;
private readonly IProductRepository _productRepository;
private readonly IShiftRepository _shiftRepository;
private readonly ILogger<DocReport> _logger;
public DocReport(IAssemblerRepository assemblerRepository, IProductRepository productRepository, IShiftRepository shiftRepository, ILogger<DocReport> logger)
{
_assemblerRepository = assemblerRepository ?? throw new ArgumentNullException(nameof(assemblerRepository));
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
_shiftRepository = shiftRepository ?? throw new ArgumentNullException(nameof(shiftRepository));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public bool CreateDoc(string filePath, bool incAssemblers, bool incProducts, bool incShifts)
{
try
{
var builder = new WordBuilder(filePath).AddHeader("Документ со справочниками");
if (incAssemblers)
{
builder.AddParagraph("Сборщики").AddTable([2400, 2400, 2400], GetAssemblers());
}
if (incProducts)
{
builder.AddParagraph("Изделия").AddTable([2400, 2400, 2400], GetProducts());
}
if (incShifts)
{
builder.AddParagraph("Смены").AddTable([7200], GetShifts());
}
builder.Build();
return true;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при формировании документа");
return false;
}
}
private List<string[]> GetProducts()
{
return [
["Название изделия", "Стоимость", "Дата сборки"],
.. _productRepository
.ReadProducts()
.Select(x => new string[] { x.ProductName, x.Price.ToString(), x.ProductType.ToString()}),
];
}
private List<string[]> GetAssemblers()
{
return [
["ФИО Сборщика", "Разряд", "Стаж работы"],
.. _assemblerRepository
.ReadAssemblers()
.Select(x => new string[] { x.FullName, x.AssemblerRank.ToString(), x.WorkExperience.ToString() }),
];
}
private List<string[]> GetShifts()
{
return [
["Дата выхода на смену"],
.. _shiftRepository
.ReadShifts()
.Select(x => new string[] { x.ShiftDate.ToString()}),
];
}
}

View File

@ -0,0 +1,316 @@
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using DocumentFormat.OpenXml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectLibrary.Reports;
internal class ExcelBuilder
{
private readonly string _filePath;
private readonly SheetData _sheetData;
private readonly MergeCells _mergeCells;
private readonly Columns _columns;
private uint _rowIndex = 0;
public ExcelBuilder(string filePath)
{
if (string.IsNullOrWhiteSpace(filePath))
{
throw new ArgumentNullException(nameof(filePath));
}
if (File.Exists(filePath))
{
File.Delete(filePath);
}
_filePath = filePath;
_sheetData = new SheetData();
_mergeCells = new MergeCells();
_columns = new Columns();
_rowIndex = 1;
}
public ExcelBuilder AddHeader(string header, int startIndex, int count)
{
CreateCell(startIndex, _rowIndex, header, StyleIndex.BoldTextWithoutBorder);
for (int i = startIndex + 1; i < startIndex + count; ++i)
{
CreateCell(i, _rowIndex, "", StyleIndex.SimpleTextWithoutBorder);
}
_mergeCells.Append(new MergeCell()
{
Reference = new StringValue($"{GetExcelColumnName(startIndex)}{_rowIndex}:{GetExcelColumnName(startIndex + count - 1)}{_rowIndex}")
});
_rowIndex++;
return this;
}
public ExcelBuilder AddParagraph(string text, int columnIndex)
{
CreateCell(columnIndex, _rowIndex++, text, StyleIndex.SimpleTextWithoutBorder);
return this;
}
public ExcelBuilder AddTable(int[] columnsWidths, List<string[]> data)
{
if (columnsWidths == null || columnsWidths.Length == 0)
{
throw new ArgumentNullException(nameof(columnsWidths));
}
if (data == null || data.Count == 0)
{
throw new ArgumentNullException(nameof(data));
}
if (data.Any(x => x.Length != columnsWidths.Length))
{
throw new InvalidOperationException("widths.Length != data.Length");
}
uint counter = 1;
int coef = 2;
_columns.Append(columnsWidths.Select(x => new Column
{
Min = counter,
Max = counter++,
Width = x * coef,
CustomWidth = true
}));
for (var j = 0; j < data.First().Length; ++j)
{
CreateCell(j, _rowIndex, data.First()[j], StyleIndex.BoldTextWithBorder);
}
_rowIndex++;
for (var i = 1; i < data.Count - 1; ++i)
{
for (var j = 0; j < data[i].Length; ++j)
{
CreateCell(j, _rowIndex, data[i][j], StyleIndex.SimpleTextWithBorder);
}
_rowIndex++;
}
for (var j = 0; j < data.Last().Length; ++j)
{
CreateCell(j, _rowIndex, data.Last()[j], StyleIndex.BoldTextWithBorder);
}
_rowIndex++;
return this;
}
public void Build()
{
using var spreadsheetDocument = SpreadsheetDocument.Create(_filePath, SpreadsheetDocumentType.Workbook);
var workbookpart = spreadsheetDocument.AddWorkbookPart();
GenerateStyle(workbookpart);
workbookpart.Workbook = new Workbook();
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet();
if (_columns.HasChildren)
{
worksheetPart.Worksheet.Append(_columns);
}
worksheetPart.Worksheet.Append(_sheetData);
var sheets = spreadsheetDocument.WorkbookPart!.Workbook.AppendChild(new Sheets());
var sheet = new Sheet()
{
Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
SheetId = 1,
Name = "Лист 1"
};
sheets.Append(sheet);
if (_mergeCells.HasChildren)
{
worksheetPart.Worksheet.InsertAfter(_mergeCells,
worksheetPart.Worksheet.Elements<SheetData>().First());
}
}
private static void GenerateStyle(WorkbookPart workbookPart)
{
var workbookStylesPart = workbookPart.AddNewPart<WorkbookStylesPart>();
workbookStylesPart.Stylesheet = new Stylesheet();
var fonts = new Fonts()
{
Count = 2,
KnownFonts = BooleanValue.FromBoolean(true)
};
fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font
{
FontSize = new FontSize() { Val = 11 },
FontName = new FontName() { Val = "Calibri" },
FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 },
FontScheme = new FontScheme()
{
Val = new EnumValue<FontSchemeValues>(FontSchemeValues.Minor)
}
});
fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font
{
FontSize = new FontSize() { Val = 11 },
FontName = new FontName() { Val = "Calibri" },
FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 },
FontScheme = new FontScheme()
{
Val = new EnumValue<FontSchemeValues>(FontSchemeValues.Minor)
},
Bold = new Bold() { Val = true }
});
workbookStylesPart.Stylesheet.Append(fonts);
// Default Fill
var fills = new Fills() { Count = 1 };
fills.Append(new Fill
{
PatternFill = new PatternFill()
{
PatternType = new EnumValue<PatternValues>(PatternValues.None)
}
});
workbookStylesPart.Stylesheet.Append(fills);
// Default Border
var borders = new Borders() { Count = 2 };
borders.Append(new Border
{
LeftBorder = new LeftBorder(),
RightBorder = new RightBorder(),
TopBorder = new TopBorder(),
BottomBorder = new BottomBorder(),
DiagonalBorder = new DiagonalBorder()
});
borders.Append(new Border
{
LeftBorder = new LeftBorder() { Style = BorderStyleValues.Thin },
RightBorder = new RightBorder() { Style = BorderStyleValues.Thin },
TopBorder = new TopBorder() { Style = BorderStyleValues.Thin },
BottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin },
DiagonalBorder = new DiagonalBorder()
});
workbookStylesPart.Stylesheet.Append(borders);
// Default cell format and a date cell format
var cellFormats = new CellFormats() { Count = 4 };
cellFormats.Append(new CellFormat
{
NumberFormatId = 0,
FormatId = 0,
FontId = 0,
BorderId = 0,
FillId = 0,
Alignment = new Alignment()
{
Horizontal = HorizontalAlignmentValues.Left,
Vertical = VerticalAlignmentValues.Center,
WrapText = true
}
});
cellFormats.Append(new CellFormat
{
NumberFormatId = 0,
FormatId = 0,
FontId = 0,
BorderId = 1,
FillId = 0,
Alignment = new Alignment()
{
Horizontal = HorizontalAlignmentValues.Right,
Vertical = VerticalAlignmentValues.Center,
WrapText = true
}
});
cellFormats.Append(new CellFormat
{
NumberFormatId = 0,
FormatId = 0,
FontId = 1,
BorderId = 0,
FillId = 0,
Alignment = new Alignment()
{
Horizontal = HorizontalAlignmentValues.Center,
Vertical = VerticalAlignmentValues.Center,
WrapText = true
}
});
cellFormats.Append(new CellFormat
{
NumberFormatId = 0,
FormatId = 0,
FontId = 1,
BorderId = 1,
FillId = 0,
Alignment = new Alignment()
{
Horizontal = HorizontalAlignmentValues.Center,
Vertical = VerticalAlignmentValues.Center,
WrapText = true
}
});
workbookStylesPart.Stylesheet.Append(cellFormats);
}
private enum StyleIndex
{
SimpleTextWithoutBorder = 0,
SimpleTextWithBorder = 1,
BoldTextWithoutBorder = 2,
BoldTextWithBorder = 3,
}
private void CreateCell(int columnIndex, uint rowIndex, string text, StyleIndex styleIndex)
{
var columnName = GetExcelColumnName(columnIndex);
var cellReference = columnName + rowIndex;
var row = _sheetData.Elements<Row>().FirstOrDefault(r => r.RowIndex! == rowIndex);
if (row == null)
{
row = new Row() { RowIndex = rowIndex };
_sheetData.Append(row);
}
var newCell = row.Elements<Cell>().FirstOrDefault(c => c.CellReference != null &&
c.CellReference.Value == columnName + rowIndex);
if (newCell == null)
{
Cell? refCell = null;
foreach (Cell cell in row.Elements<Cell>())
{
if (cell.CellReference?.Value != null &&
cell.CellReference.Value.Length == cellReference.Length)
{
if (string.Compare(cell.CellReference.Value, cellReference, true) > 0)
{
refCell = cell;
break;
}
}
}
newCell = new Cell() { CellReference = cellReference };
row.InsertBefore(newCell, refCell);
}
newCell.CellValue = new CellValue(text);
newCell.DataType = CellValues.String;
newCell.StyleIndex = (uint)styleIndex;
}
private static string GetExcelColumnName(int columnNumber)
{
columnNumber += 1;
int dividend = columnNumber;
string columnName = string.Empty;
int modulo;
while (dividend > 0)
{
modulo = (dividend - 1) % 26;
columnName = Convert.ToChar(65 + modulo).ToString() + columnName;
dividend = (dividend - modulo) / 26;
}
return columnName;
}
}

View File

@ -0,0 +1,71 @@
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Shapes.Charts;
using MigraDoc.Rendering;
namespace ProjectWorkshop.Reports;
internal class PdfBuilder
{
private readonly string _filePath;
private readonly Document _document;
public PdfBuilder(string filePath)
{
if (string.IsNullOrWhiteSpace(filePath))
{
throw new ArgumentNullException(nameof(filePath));
}
if (File.Exists(filePath))
{
File.Delete(filePath);
}
_filePath = filePath;
_document = new Document();
DefineStyles();
}
public PdfBuilder AddHeader(string header)
{
_document.AddSection().AddParagraph(header, "NormalBold");
return this;
}
public PdfBuilder AddPieChart(string title, List<(string Caption, double
Value)> data)
{
if (data == null || data.Count == 0)
{
return this;
}
var chart = new Chart(ChartType.Pie2D);
var series = chart.SeriesCollection.AddSeries();
series.Add(data.Select(x => x.Value).ToArray());
var xseries = chart.XValues.AddXSeries();
xseries.Add(data.Select(x => x.Caption).ToArray());
chart.DataLabel.Type = DataLabelType.Percent;
chart.DataLabel.Position = DataLabelPosition.OutsideEnd;
chart.Width = Unit.FromCentimeter(16);
chart.Height = Unit.FromCentimeter(12);
chart.TopArea.AddParagraph(title);
chart.XAxis.MajorTickMark = TickMarkType.Outside;
chart.YAxis.MajorTickMark = TickMarkType.Outside;
chart.YAxis.HasMajorGridlines = true;
chart.PlotArea.LineFormat.Width = 1;
chart.PlotArea.LineFormat.Visible = true;
chart.TopArea.AddLegend();
_document.LastSection.Add(chart);
return this;
}
public void Build()
{
var renderer = new PdfDocumentRenderer(true)
{
Document = _document
};
renderer.RenderDocument();
renderer.PdfDocument.Save(_filePath);
}
private void DefineStyles()
{
var headerStyle = _document.Styles.AddStyle("NormalBold", "Normal");
headerStyle.Font.Bold = true;
headerStyle.Font.Size = 14;
}
}

View File

@ -0,0 +1,124 @@
using Microsoft.Extensions.Logging;
using ProjectLibrary.Reports;
using ProjectWorkshop.Repositories;
using ProjectWorkshop.Repositories.Implementations;
using System;
using System.Collections.Generic;
using System.Linq;
namespace ProjectWorkshop.Reports
{
internal class TableReport
{
private readonly IAssemblerRepository _assemblerRepository;
private readonly IAssemblerShiftRepository _assemblerShiftRepository;
private readonly IAssemblyRepository _assemblyRepository;
private readonly ILogger<TableReport> _logger;
internal static readonly string[] Headers = { "Сборщик", "Стаж", "Разряд", "Кол-во сборок", "Собрано изделий", "Смены" };
public TableReport(IAssemblerRepository assemblerRepository,
IAssemblerShiftRepository assemblerShiftRepository,
ILogger<TableReport> logger,
IAssemblyRepository assemblyRepository)
{
_assemblerRepository = assemblerRepository ?? throw new ArgumentNullException(nameof(assemblerRepository));
_assemblerShiftRepository = assemblerShiftRepository ?? throw new ArgumentNullException(nameof(assemblerShiftRepository));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_assemblyRepository = assemblyRepository ?? throw new ArgumentNullException(nameof(assemblyRepository));
}
public bool CreateTable(string filePath, int assemblerID, DateTime startDate, DateTime endDate)
{
try
{
var data = GetData(assemblerID, startDate, endDate);
new ExcelBuilder(filePath)
.AddHeader("Сводка по сборкам", 0, Headers.Length)
.AddParagraph($"за период с {startDate:dd.MM.yyyy} по {endDate:dd.MM.yyyy}", 0)
.AddTable(new[] { 25, 15, 15, 20, 20, 20 }, data)
.Build();
return true;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при формировании документа");
return false;
}
}
private List<string[]> GetData(int assemblerID, DateTime startDate, DateTime endDate)
{
var assembler = _assemblerRepository.ReadAssemblers().FirstOrDefault(a => a.ID == assemblerID);
if (assembler == null)
throw new Exception($"Сборщик с ID {assemblerID} не найден.");
var shiftData = _assemblerShiftRepository
.ReadAssemblerShifts()
.Where(x => x.AssemblerShiftDate >= startDate && x.AssemblerShiftDate <= endDate && x.AssemblerID_Assembler == assemblerID)
.OrderBy(x => x.AssemblerShiftDate)
.ToList();
var result = new List<string[]>
{
Headers
};
int totalAssemblies = 0;
int totalProducts = 0;
foreach (var shift in shiftData)
{
var assemblyDataForDay = _assemblyRepository
.ReadAssemblies()
.Where(x => x.AssemblyDate.Date == shift.AssemblerShiftDate.Date && x.AssemblerID_Assembler == assemblerID)
.ToList();
int totalAssembliesForDay = assemblyDataForDay.Count();
int totalProductsForDay = assemblyDataForDay.Sum(x => x.Count);
result.Add(new[]
{
assembler.FullName,
assembler.WorkExperience.ToString("F"),
assembler.AssemblerRank.ToString("G"),
totalAssembliesForDay.ToString("N0"),
totalProductsForDay.ToString("N0"),
shift.AssemblerShiftDate.ToString("dd.MM.yyyy")
});
totalAssemblies += totalAssembliesForDay;
totalProducts += totalProductsForDay;
}
if (!shiftData.Any())
{
result.Add(new[]
{
assembler.FullName,
assembler.WorkExperience.ToString("F"),
assembler.AssemblerRank.ToString("G"),
"0",
"0",
"Нет смен"
});
}
result.Add(new[]
{
"ИТОГО",
"",
"",
totalAssemblies.ToString("N0"),
totalProducts.ToString("N0"),
""
});
return result;
}
}
}

View File

@ -0,0 +1,106 @@
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Wordprocessing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWorkshop.Reports;
internal class WordBuilder
{
private readonly string _filePath;
private readonly Document _document;
private readonly Body _body;
public WordBuilder(string filePath)
{
if (string.IsNullOrWhiteSpace(filePath))
{
throw new ArgumentNullException(nameof(filePath));
}
if (File.Exists(filePath))
{
File.Delete(filePath);
}
_filePath = filePath;
_document = new Document();
_body = _document.AppendChild(new Body());
}
public WordBuilder AddHeader(string header)
{
var paragraph = _body.AppendChild(new Paragraph());
var run = paragraph.AppendChild(new Run());
var runProperties = run.AppendChild(new RunProperties());
runProperties.AppendChild(new Bold());
run.AppendChild(new Text(header));
return this;
}
public WordBuilder AddParagraph(string text)
{
var paragraph = _body.AppendChild(new Paragraph());
var run = paragraph.AppendChild(new Run());
run.AppendChild(new Text(text));
return this;
}
public WordBuilder AddTable(int[] widths, List<string[]> data)
{
if (widths == null || widths.Length == 0)
{
throw new ArgumentNullException(nameof(widths));
}
if (data == null || data.Count == 0)
{
throw new ArgumentNullException(nameof(data));
}
if (data.Any(x => x.Length != widths.Length))
{
throw new InvalidOperationException("widths.Length != data.Length");
}
var table = new Table();
table.AppendChild(new TableProperties(
new TableBorders(
new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12 },
new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12 },
new LeftBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12 },
new RightBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12 },
new InsideHorizontalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12 },
new InsideVerticalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 12 }
)
));
// заголовок
var tr = new TableRow();
for (var j = 0; j < widths.Length; ++j)
{
tr.Append(new TableCell(
new TableCellProperties(new TableCellWidth()
{
Width =
widths[j].ToString()
}),
new Paragraph(new Run(new RunProperties(new Bold()), new
Text(data.First()[j])))));
}
table.Append(tr);
// данные
table.Append(data.Skip(1).Select(x =>
new TableRow(x.Select(y => new TableCell(new Paragraph(new
Run(new Text(y))))))));
_body.Append(table);
return this;
}
public void Build()
{
using var wordDocument = WordprocessingDocument.Create(_filePath, WordprocessingDocumentType.Document);
var mainPart = wordDocument.AddMainDocumentPart();
mainPart.Document = _document;
}
}

View File

@ -0,0 +1,16 @@
using ProjectWorkshop.Entities;
namespace ProjectWorkshop.Repositories;
public interface IAssemblerRepository
{
IEnumerable<Assembler> ReadAssemblers();
Assembler ReadAssemblerByID(int id);
void CreateAssembler(Assembler assembler);
void UpdateAssembler(Assembler assembler);
void DeleteAssembler(int id);
}

View File

@ -0,0 +1,9 @@
using ProjectWorkshop.Entities;
namespace ProjectWorkshop.Repositories;
public interface IAssemblerShiftRepository
{
IEnumerable<AssemblerShift> ReadAssemblerShifts(int? workHours = null, int? assemblerID = null, int? shiftID = null);
void CreateAssemblerShift(AssemblerShift assemblerShift);
}

View File

@ -0,0 +1,12 @@
using ProjectWorkshop.Entities;
namespace ProjectWorkshop.Repositories;
public interface IAssemblyRepository
{
IEnumerable<Assembly> ReadAssemblies(DateTime? dateFrom = null, DateTime? dateTo = null, int? productID = null, int? assemblyID = null, int? count = null);
void CreateAssembly(Assembly assembly);
void DeleteAssembly(int id);
}

View File

@ -0,0 +1,7 @@
namespace ProjectWorkshop.Repositories;
public interface IConnectionString
{
public string ConnectionString { get; }
}

View File

@ -0,0 +1,15 @@
using ProjectWorkshop.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWorkshop.Repositories;
public interface IProductAssemblyRepository
{
void CreateProductAssembly(ProductAssembly productAssembly);
void DeleteProductAssembly(int id);
}

View File

@ -0,0 +1,15 @@
using ProjectWorkshop.Entities;
namespace ProjectWorkshop.Repositories;
public interface IProductRepository
{
IEnumerable<Product> ReadProducts();
Product ReadProductByID(int id);
void CreateProduct(Product product);
void UpdateProduct(Product product);
void DeleteProduct(int id);
}

View File

@ -0,0 +1,15 @@
using ProjectWorkshop.Entities;
namespace ProjectWorkshop.Repositories;
public interface IShiftRepository
{
IEnumerable<Shift> ReadShifts();
Shift ReadShiftByID(int id);
void CreateShift(Shift shift);
void UpdateShift(Shift shift);
void DeleteShift(int id);
}

View File

@ -0,0 +1,135 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectWorkshop.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWorkshop.Repositories.Implementations;
public class AssemblerRepository : IAssemblerRepository
{
private readonly IConnectionString _connectionString;
private readonly ILogger<AssemblerRepository> _logger;
public AssemblerRepository(IConnectionString connectionString, ILogger<AssemblerRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateAssembler(Assembler assembler)
{
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(assembler));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
connection.Open();
var queryInsert = @"
INSERT INTO Assembler (FullName, AssemblerRank, WorkExperience)
VALUES (@FullName, @AssemblerRank, @WorkExperience)";
connection.Execute(queryInsert, assembler);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
}
public void UpdateAssembler(Assembler assembler)
{
_logger.LogInformation("Редактирование объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(assembler));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"
UPDATE Assembler
SET
FullName=@FullName,
AssemblerRank=@AssemblerRank,
WorkExperience=@WorkExperience
WHERE ID=@id";
connection.Execute(queryUpdate, assembler);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при редактировании объекта");
throw;
}
}
public void DeleteAssembler(int id)
{
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM Assembler
WHERE ID=@id";
connection.Execute(queryDelete, new { id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
}
public Assembler ReadAssemblerByID(int id)
{
_logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT * FROM Assembler
WHERE ID=@id";
var assembler = connection.QueryFirst<Assembler>(querySelect, new
{
id
});
_logger.LogDebug("Найденный объект: {json}", JsonConvert.SerializeObject(assembler));
return assembler;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при поиске объекта");
throw;
}
}
public IEnumerable<Assembler> ReadAssemblers()
{
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Assembler";
var assemblers = connection.Query<Assembler>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(assemblers));
return assemblers;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
}
}

View File

@ -0,0 +1,61 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectWorkshop.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWorkshop.Repositories.Implementations;
public class AssemblerShiftRepository : IAssemblerShiftRepository
{
private readonly IConnectionString _connectionString;
private readonly ILogger<AssemblerShiftRepository> _logger;
public AssemblerShiftRepository(IConnectionString connectionString, ILogger<AssemblerShiftRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateAssemblerShift(AssemblerShift assemblerShift)
{
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(assemblerShift));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"
INSERT INTO AssemblerShift (WorkHours, AssemblerID_Assembler, ShiftID_Shift, AssemblerShiftDate)
VALUES (@WorkHours, @AssemblerID_Assembler, @ShiftID_Shift, @AssemblerShiftDate)";
connection.Execute(queryInsert, assemblerShift);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
}
public IEnumerable<AssemblerShift> ReadAssemblerShifts(int? workHours = null, int? assemblerID = null, int? shiftID = null)
{
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM AssemblerShift";
var assemblerShifts = connection.Query<AssemblerShift>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(assemblerShifts));
return assemblerShifts;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
}
}

View File

@ -0,0 +1,107 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectWorkshop.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWorkshop.Repositories.Implementations;
public class AssemblyRepository : IAssemblyRepository
{
private readonly IConnectionString _connectionString;
private readonly ILogger<AssemblyRepository> _logger;
public AssemblyRepository(IConnectionString connectionString, ILogger<AssemblyRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateAssembly(Assembly assembly)
{
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(assembly));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
connection.Open();
using var transaction = connection.BeginTransaction();
var queryInsert = @"
INSERT INTO Assembly (Count, AssemblerID_Assembler, AssemblyDate)
VALUES (@Count, @AssemblerID_Assembler, @AssemblyDate)
RETURNING ID";
var assemblyId = connection.QueryFirst<int>(queryInsert, new
{
assembly.Count,
assembly.AssemblerID_Assembler,
assembly.AssemblyDate
}, transaction);
var querySubInsert = @"
INSERT INTO ProductAssembly (ProductID_Product, AssemblyID_Assembly, Count)
VALUES (@ProductID_Product, @AssemblyID_Assembly, @Count)";
foreach (var elem in assembly.ProductAssembly)
{
connection.Execute(querySubInsert, new
{
AssemblyID_Assembly = assemblyId,
elem.ProductID_Product,
elem.Count
}, transaction);
}
transaction.Commit();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
}
public void DeleteAssembly(int id)
{
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM Assembly
WHERE ID=@id";
connection.Execute(queryDelete, new { id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
}
public IEnumerable<Assembly> ReadAssemblies(DateTime? dateFrom = null, DateTime? dateTo = null, int? id = null, int? assemblyID = null, int? count = null)
{
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var selectQuery = @"SELECT * FROM Assembly";
var assemblies = connection.Query<Assembly>(selectQuery);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(assemblies));
return assemblies;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWorkshop.Repositories.Implementation;
internal class ConnectionString : IConnectionString
{
string IConnectionString.ConnectionString => "Host=localhost;Port=5432;Database=otp;Username=postgres;Password=admin";
}

View File

@ -0,0 +1,65 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectWorkshop.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWorkshop.Repositories.Implementations;
public class ProductAssemblyRepository : IProductAssemblyRepository
{
private readonly IConnectionString _connectionString;
private readonly ILogger<AssemblerRepository> _logger;
public ProductAssemblyRepository(IConnectionString connectionString, ILogger<AssemblerRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateProductAssembly(ProductAssembly productAssembly)
{
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(productAssembly));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"
INSERT INTO Assembly (Count, ProductType)
VALUES (@Count, @ProductType)
RETURNING ID";
connection.Execute(queryInsert, productAssembly);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
}
public void DeleteProductAssembly(int id)
{
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM Assembly
WHERE ID=@id";
connection.Execute(queryDelete, new { id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
}
}

View File

@ -0,0 +1,129 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectWorkshop.Entities;
using ProjectWorkshop.Entities.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWorkshop.Repositories.Implementations;
public class ProductRepository : IProductRepository
{
private readonly IConnectionString _connectionString;
private readonly ILogger<ProductRepository> _logger;
public ProductRepository(IConnectionString connectionString, ILogger<ProductRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateProduct(Product product)
{
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(product));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"
INSERT INTO Product (ProductName, Price, ProductType)
VALUES (@ProductName, @Price, @ProductType)
RETURNING ID";
connection.Execute(queryInsert, product);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
}
public void UpdateProduct(Product product)
{
_logger.LogInformation("Редактирование объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(product));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"
UPDATE Product
SET ProductName=@ProductName, Price=@Price, ProductType=@ProductType
WHERE ID=@ID";
connection.Execute(queryUpdate, product);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при редактировании объекта");
throw;
}
}
public void DeleteProduct(int id)
{
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM Product
WHERE ID=@id";
connection.Execute(queryDelete, new { id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
}
public Product ReadProductByID(int id)
{
_logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT * FROM Product
WHERE ID=@id";
var product = connection.QueryFirst<Product>(querySelect, new
{
id
});
_logger.LogDebug("Найденный объект: {json}",
JsonConvert.SerializeObject(product));
return product;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при поиске объекта");
throw;
}
}
public IEnumerable<Product> ReadProducts()
{
_logger.LogInformation("Получение всех объектов");
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT * FROM Product";
var products = connection.Query<Product>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(products));
return products;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
}
}

View File

@ -0,0 +1,122 @@
using Dapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Npgsql;
using ProjectWorkshop.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWorkshop.Repositories.Implementations;
public class ShiftRepository : IShiftRepository
{
private readonly IConnectionString _connectionString;
private readonly ILogger<ShiftRepository> _logger;
public ShiftRepository(IConnectionString connectionString, ILogger<ShiftRepository> logger)
{
_connectionString = connectionString;
_logger = logger;
}
public void CreateShift(Shift shift)
{
_logger.LogInformation("Добавление объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(shift));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"
INSERT INTO Shift (ShiftDate)
VALUES (@ShiftDate)";
connection.Execute(queryInsert, shift);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при добавлении объекта");
throw;
}
}
public void UpdateShift(Shift shift)
{
_logger.LogInformation("Редактирование объекта");
_logger.LogDebug("Объект: {json}", JsonConvert.SerializeObject(shift));
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryUpdate = @"
UPDATE Shift
SET ShiftDate=@ShiftDate
WHERE Id=@Id";
connection.Execute(queryUpdate, shift);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при редактировании объекта");
throw;
}
}
public void DeleteShift(int id)
{
_logger.LogInformation("Удаление объекта");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var queryDelete = @"
DELETE FROM Shift
WHERE ID=@id";
connection.Execute(queryDelete, new { id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при удалении объекта");
throw;
}
}
public Shift ReadShiftByID(int id)
{
_logger.LogInformation("Получение объекта по идентификатору");
_logger.LogDebug("Объект: {id}", id);
try
{
using var connection = new
NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT * FROM Shift
WHERE ID=@id";
var shift = connection.QueryFirst<Shift>(querySelect, new
{
id
});
_logger.LogDebug("Найденный объект: {json}",
JsonConvert.SerializeObject(shift));
return shift;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при поиске объекта");
throw;
}
}
public IEnumerable<Shift> ReadShifts()
{
_logger.LogInformation("Получение всех смен");
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = "SELECT ID, ShiftDate FROM Shift";
return connection.Query<Shift>(querySelect);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при получении смен");
throw;
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View File

@ -0,0 +1,15 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "Logs.txt",
"rollingInterval": "Day"
}
}
]
}
}