ПИбд-23. Кадышев М.И. Лабораторная работа 3 #3

Closed
nezui wants to merge 6 commits from LabWork_3 into LabWork_2
32 changed files with 1942 additions and 108 deletions

View File

@ -8,14 +8,16 @@ namespace ProjectCompRepair.Entities;
public class AccessoiresOrder
{
public int Id { get; private set; }
public int OrderId { get; private set; }
public int AccessoriesId { get; private set; }
public int Count { get; private set; }
public static AccessoiresOrder CreateElement(int id, int orderId, int count)
public static AccessoiresOrder CreateElement(int orderId, int count, int accessoriesId)
{
return new AccessoiresOrder { Id = id, OrderId = orderId, Count = count};
return new AccessoiresOrder { OrderId = orderId, Count = count, AccessoriesId = accessoriesId };
}
}

View File

@ -17,14 +17,17 @@ public class Accessories
public float Price { get; private set; }
public static Accessories CreateEntity(int id, AccessoriesType accessoriesType, int count, float price)
public DateTime Date { get; private set; }
public static Accessories CreateEntity(int id, AccessoriesType accessoriesType, int count, float price, DateTime date)
{
return new Accessories
{
Id = id,
AccessoriesType = accessoriesType,
Count = count,
Price = price
Price = price,
Date = date
};
}
}

View File

@ -37,4 +37,18 @@ public class Order
};
}
public static Order CreateElement(TempAccessoriesOrder tempAccessoriesOrder, IEnumerable<AccessoiresOrder> accessoiresOrder)
{
return new Order
{
Id = tempAccessoriesOrder.Id,
Name = tempAccessoriesOrder.Name,
Coment = tempAccessoriesOrder.Coment,
Date = tempAccessoriesOrder.Date,
MasterID = tempAccessoriesOrder.MasterID,
AccessoiresOrders = accessoiresOrder,
ServicesOrders = tempAccessoriesOrder.ServicesOrders
};
}
}

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCompRepair.Entities;
public class TempAccessoriesOrder
{
public int Id { get; private set; }
public string Name { get; private set; }
public string Coment { get; private set; }
public DateTime Date { get; private set; }
public int MasterID { get; private set; }
public int AccessoriesId { get; private set; }
public int Count { get; private set; }
public IEnumerable<AccessoiresOrder> AccessoiresOrders { get; private set; }
public IEnumerable<ServicesOrder> ServicesOrders { get; private set; }
}

View File

@ -36,6 +36,9 @@
операцииToolStripMenuItem = new ToolStripMenuItem();
OrderToolStripMenuItem = new ToolStripMenuItem();
отчетыToolStripMenuItem = new ToolStripMenuItem();
документСоСправочникамиToolStripMenuItem = new ToolStripMenuItem();
excelToolStripMenuItem = new ToolStripMenuItem();
TypeOfAccessoriesToolStripMenuItem = new ToolStripMenuItem();
menuStrip.SuspendLayout();
SuspendLayout();
//
@ -60,21 +63,21 @@
// AccossoriesToolStripMenuItem
//
AccossoriesToolStripMenuItem.Name = "AccossoriesToolStripMenuItem";
AccossoriesToolStripMenuItem.Size = new Size(224, 26);
AccossoriesToolStripMenuItem.Size = new Size(207, 26);
AccossoriesToolStripMenuItem.Text = "Комплектующие";
AccossoriesToolStripMenuItem.Click += AccossoriesToolStripMenuItem_Click;
//
// MasterToolStripMenuItem
//
MasterToolStripMenuItem.Name = "MasterToolStripMenuItem";
MasterToolStripMenuItem.Size = new Size(224, 26);
MasterToolStripMenuItem.Size = new Size(207, 26);
MasterToolStripMenuItem.Text = "Мастер";
MasterToolStripMenuItem.Click += MasterToolStripMenuItem_Click;
//
// ServiceToolStripMenuItem
//
ServiceToolStripMenuItem.Name = "ServiceToolStripMenuItem";
ServiceToolStripMenuItem.Size = new Size(224, 26);
ServiceToolStripMenuItem.Size = new Size(207, 26);
ServiceToolStripMenuItem.Text = "Услуга";
ServiceToolStripMenuItem.Click += ServiceToolStripMenuItem_Click;
//
@ -88,16 +91,38 @@
// OrderToolStripMenuItem
//
OrderToolStripMenuItem.Name = "OrderToolStripMenuItem";
OrderToolStripMenuItem.Size = new Size(224, 26);
OrderToolStripMenuItem.Size = new Size(130, 26);
OrderToolStripMenuItem.Text = "Заказ";
OrderToolStripMenuItem.Click += OrderToolStripMenuItem_Click;
//
// отчетыToolStripMenuItem
//
отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { документСоСправочникамиToolStripMenuItem, excelToolStripMenuItem, TypeOfAccessoriesToolStripMenuItem });
отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
отчетыToolStripMenuItem.Size = new Size(73, 24);
отчетыToolStripMenuItem.Text = "Отчеты";
//
// документСоСправочникамиToolStripMenuItem
//
документСоСправочникамиToolStripMenuItem.Name = окументСоСправочникамиToolStripMenuItem";
документСоСправочникамиToolStripMenuItem.Size = new Size(348, 26);
документСоСправочникамиToolStripMenuItem.Text = "Документ со справочниками";
документСоСправочникамиToolStripMenuItem.Click += DirecotryReportToolStripMenuItem_Click;
//
// excelToolStripMenuItem
//
excelToolStripMenuItem.Name = "excelToolStripMenuItem";
excelToolStripMenuItem.Size = new Size(348, 26);
excelToolStripMenuItem.Text = "Поток комплектующих";
excelToolStripMenuItem.Click += excelToolStripMenuItem_Click;
//
// TypeOfAccessoriesToolStripMenuItem
//
TypeOfAccessoriesToolStripMenuItem.Name = "TypeOfAccessoriesToolStripMenuItem";
TypeOfAccessoriesToolStripMenuItem.Size = new Size(348, 26);
TypeOfAccessoriesToolStripMenuItem.Text = "Отчет о потраченых комплектующих";
TypeOfAccessoriesToolStripMenuItem.Click += TypeOfAccessoriesToolStripMenuItem_Click_1;
//
// FormCompRepair
//
AutoScaleDimensions = new SizeF(8F, 20F);
@ -127,5 +152,8 @@
private ToolStripMenuItem OrderToolStripMenuItem;
private ToolStripMenuItem MasterToolStripMenuItem;
private ToolStripMenuItem ServiceToolStripMenuItem;
private ToolStripMenuItem документСоСправочникамиToolStripMenuItem;
private ToolStripMenuItem excelToolStripMenuItem;
private ToolStripMenuItem TypeOfAccessoriesToolStripMenuItem;
}
}

View File

@ -19,7 +19,7 @@ namespace ProjectCompRepair
{
_container.Resolve<FormAccessories>().ShowDialog();
}
catch(Exception ex)
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
@ -32,7 +32,7 @@ namespace ProjectCompRepair
{
_container.Resolve<FormMasters>().ShowDialog();
}
catch(Exception ex)
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
@ -61,5 +61,42 @@ namespace ProjectCompRepair
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void DirecotryReportToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormDirectoryReport>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void excelToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormAccessoriesReport>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void TypeOfAccessoriesToolStripMenuItem_Click_1(object sender, EventArgs e)
{
try
{
_container.Resolve<FormAccessoriesOrderReport>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Microsoft ResX Schema
Version 2.0
@ -48,7 +48,7 @@
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

View File

@ -28,6 +28,8 @@
buttonCreate = new Button();
buttonCancel = new Button();
comboBoxType = new ComboBox();
labelDate = new Label();
dateTimePickerAccessories = new DateTimePicker();
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
SuspendLayout();
@ -36,9 +38,9 @@
//
labelType.Anchor = AnchorStyles.Right;
labelType.AutoSize = true;
labelType.Location = new Point(54, 75);
labelType.Location = new Point(47, 56);
labelType.Name = "labelType";
labelType.Size = new Size(158, 20);
labelType.Size = new Size(128, 15);
labelType.TabIndex = 0;
labelType.Text = "Вид комплектующего";
//
@ -46,9 +48,9 @@
//
labelCount.Anchor = AnchorStyles.Right;
labelCount.AutoSize = true;
labelCount.Location = new Point(54, 152);
labelCount.Location = new Point(47, 114);
labelCount.Name = "labelCount";
labelCount.Size = new Size(98, 20);
labelCount.Size = new Size(79, 15);
labelCount.TabIndex = 2;
labelCount.Text = "Колличество";
//
@ -56,9 +58,9 @@
//
labelPrice.Anchor = AnchorStyles.Right;
labelPrice.AutoSize = true;
labelPrice.Location = new Point(54, 231);
labelPrice.Location = new Point(47, 173);
labelPrice.Name = "labelPrice";
labelPrice.Size = new Size(45, 20);
labelPrice.Size = new Size(35, 15);
labelPrice.TabIndex = 4;
labelPrice.Text = "Цена";
//
@ -66,29 +68,26 @@
//
numericUpDownPrice.Anchor = AnchorStyles.Right;
numericUpDownPrice.DecimalPlaces = 2;
numericUpDownPrice.Location = new Point(252, 235);
numericUpDownPrice.Margin = new Padding(3, 4, 3, 4);
numericUpDownPrice.Location = new Point(220, 176);
numericUpDownPrice.Name = "numericUpDownPrice";
numericUpDownPrice.Size = new Size(119, 27);
numericUpDownPrice.Size = new Size(104, 23);
numericUpDownPrice.TabIndex = 5;
//
// numericUpDownCount
//
numericUpDownCount.Anchor = AnchorStyles.Right;
numericUpDownCount.Location = new Point(252, 156);
numericUpDownCount.Margin = new Padding(3, 4, 3, 4);
numericUpDownCount.Location = new Point(220, 117);
numericUpDownCount.Name = "numericUpDownCount";
numericUpDownCount.Size = new Size(119, 27);
numericUpDownCount.Size = new Size(104, 23);
numericUpDownCount.TabIndex = 6;
//
// buttonCreate
//
buttonCreate.AllowDrop = true;
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(53, 417);
buttonCreate.Margin = new Padding(3, 4, 3, 4);
buttonCreate.Location = new Point(46, 313);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(98, 33);
buttonCreate.Size = new Size(86, 25);
buttonCreate.TabIndex = 8;
buttonCreate.Text = "Сохранить";
buttonCreate.UseVisualStyleBackColor = true;
@ -97,10 +96,9 @@
// buttonCancel
//
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Location = new Point(310, 416);
buttonCancel.Margin = new Padding(3, 4, 3, 4);
buttonCancel.Location = new Point(271, 312);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(101, 31);
buttonCancel.Size = new Size(88, 23);
buttonCancel.TabIndex = 10;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
@ -109,19 +107,38 @@
// comboBoxType
//
comboBoxType.FormattingEnabled = true;
comboBoxType.Location = new Point(250, 78);
comboBoxType.Location = new Point(219, 58);
comboBoxType.Margin = new Padding(3, 2, 3, 2);
comboBoxType.Name = "comboBoxType";
comboBoxType.Size = new Size(151, 28);
comboBoxType.Size = new Size(133, 23);
comboBoxType.TabIndex = 11;
//
// labelDate
//
labelDate.AutoSize = true;
labelDate.Location = new Point(47, 234);
labelDate.Name = "labelDate";
labelDate.Size = new Size(68, 15);
labelDate.TabIndex = 12;
labelDate.Text = "Поступили";
//
// dateTimePickerAccessories
//
dateTimePickerAccessories.Location = new Point(220, 234);
dateTimePickerAccessories.Name = "dateTimePickerAccessories";
dateTimePickerAccessories.Size = new Size(132, 23);
dateTimePickerAccessories.TabIndex = 13;
//
// FormAccessorie
//
AllowDrop = true;
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
AutoSizeMode = AutoSizeMode.GrowAndShrink;
AutoValidate = AutoValidate.EnableAllowFocusChange;
ClientSize = new Size(448, 478);
ClientSize = new Size(392, 358);
Controls.Add(dateTimePickerAccessories);
Controls.Add(labelDate);
Controls.Add(comboBoxType);
Controls.Add(buttonCancel);
Controls.Add(buttonCreate);
@ -130,7 +147,6 @@
Controls.Add(labelPrice);
Controls.Add(labelCount);
Controls.Add(labelType);
Margin = new Padding(3, 4, 3, 4);
Name = "FormAccessorie";
Text = "Комплектующое";
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit();
@ -150,5 +166,7 @@
private Button buttonUpdate;
private Button buttonCancel;
private ComboBox comboBoxType;
private Label labelDate;
private DateTimePicker dateTimePickerAccessories;
}
}

View File

@ -31,7 +31,8 @@ namespace ProjectCompRepair.Forms
{
throw new InvalidOperationException(nameof(accessorie));
}
dateTimePickerAccessories.Value = accessorie.Date;
numericUpDownCount.Value = accessorie.Count;
numericUpDownPrice.Value = (int)accessorie.Price;
_accessorieId = value;
@ -79,7 +80,7 @@ namespace ProjectCompRepair.Forms
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
private Accessories CreateAccessories(int id) => Accessories.CreateEntity(id, (AccessoriesType)comboBoxType.SelectedItem! , (int)numericUpDownCount.Value, (float)numericUpDownPrice.Value);
private Accessories CreateAccessories(int id) => Accessories.CreateEntity(id, (AccessoriesType)comboBoxType.SelectedItem! , (int)numericUpDownCount.Value, (float)numericUpDownPrice.Value, dateTimePickerAccessories.Value);
}

View File

@ -0,0 +1,130 @@
namespace ProjectCompRepair.Forms
{
partial class FormAccessoriesOrderReport
{
/// <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();
dateTimePicker = new DateTimePicker();
labelDate = new Label();
buttonCreate = new Button();
comboBoxAccessories = new ComboBox();
labelAccessories = new Label();
SuspendLayout();
//
// buttonSelectFileName
//
buttonSelectFileName.Location = new Point(12, 25);
buttonSelectFileName.Name = "buttonSelectFileName";
buttonSelectFileName.Size = new Size(94, 29);
buttonSelectFileName.TabIndex = 0;
buttonSelectFileName.Text = "Выбрать";
buttonSelectFileName.UseVisualStyleBackColor = true;
buttonSelectFileName.Click += ButtonSelectFileName_Click;
//
// labelFileName
//
labelFileName.AutoSize = true;
labelFileName.Location = new Point(136, 29);
labelFileName.Name = "labelFileName";
labelFileName.Size = new Size(45, 20);
labelFileName.TabIndex = 1;
labelFileName.Text = "Файл";
//
// dateTimePicker
//
dateTimePicker.Location = new Point(67, 97);
dateTimePicker.Name = "dateTimePicker";
dateTimePicker.Size = new Size(250, 27);
dateTimePicker.TabIndex = 2;
//
// labelDate
//
labelDate.AutoSize = true;
labelDate.Location = new Point(19, 100);
labelDate.Name = "labelDate";
labelDate.Size = new Size(44, 20);
labelDate.TabIndex = 3;
labelDate.Text = "Дата:";
//
// buttonCreate
//
buttonCreate.Location = new Point(178, 178);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(198, 29);
buttonCreate.TabIndex = 4;
buttonCreate.Text = "Сформировать";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreate_Click;
//
// comboBoxAccessories
//
comboBoxAccessories.FormattingEnabled = true;
comboBoxAccessories.Location = new Point(376, 100);
comboBoxAccessories.Name = "comboBoxAccessories";
comboBoxAccessories.Size = new Size(151, 28);
comboBoxAccessories.TabIndex = 5;
//
// labelAccessories
//
labelAccessories.AutoSize = true;
labelAccessories.Location = new Point(387, 66);
labelAccessories.Name = "labelAccessories";
labelAccessories.Size = new Size(124, 20);
labelAccessories.TabIndex = 6;
labelAccessories.Text = "Комплектующие";
//
// FormAccessoriesOrderReport
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(539, 219);
Controls.Add(labelAccessories);
Controls.Add(comboBoxAccessories);
Controls.Add(buttonCreate);
Controls.Add(labelDate);
Controls.Add(dateTimePicker);
Controls.Add(labelFileName);
Controls.Add(buttonSelectFileName);
Name = "FormAccessoriesOrderReport";
Text = "FormAccessoriesType";
Review

Заголовок формы оформлен неверно

Заголовок формы оформлен неверно
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonSelectFileName;
private Label labelFileName;
private DateTimePicker dateTimePicker;
private Label labelDate;
private Button buttonCreate;
private ComboBox comboBoxAccessories;
private Label labelAccessories;
}
}

View File

@ -0,0 +1,80 @@
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 ProjectCompRepair.Entities;
using ProjectCompRepair.Reports;
using ProjectCompRepair.Repositories;
using Unity;
namespace ProjectCompRepair.Forms
{
public partial class FormAccessoriesOrderReport : Form
{
private string _fileName = string.Empty;
private readonly IUnityContainer _container;
public FormAccessoriesOrderReport(IUnityContainer container, IAccessoriesRepository accessoriesRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
comboBoxAccessories.DataSource = accessoriesRepository.ReadAccessories();
comboBoxAccessories.ValueMember = "Id";
comboBoxAccessories.DisplayMember = "AccessoriesType";
}
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, dateTimePicker.Value, (int)comboBoxAccessories.SelectedValue!))
{
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,169 @@
namespace ProjectCompRepair.Forms
{
partial class FormAccessoriesReport
{
/// <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()
{
dateTimePickerDateEnd = new DateTimePicker();
dateTimePickerDateBegin = new DateTimePicker();
textBoxFilePath = new TextBox();
buttonSelectFilePath = new Button();
comboBoxAccessories = new ComboBox();
labelFile = new Label();
labelNameAccessories = new Label();
labelBeginTime = new Label();
labelEndTime = new Label();
buttonMakeReport = new Button();
SuspendLayout();
//
// dateTimePickerDateEnd
//
dateTimePickerDateEnd.Location = new Point(198, 309);
dateTimePickerDateEnd.Margin = new Padding(3, 4, 3, 4);
dateTimePickerDateEnd.Name = "dateTimePickerDateEnd";
dateTimePickerDateEnd.Size = new Size(228, 27);
dateTimePickerDateEnd.TabIndex = 0;
//
// dateTimePickerDateBegin
//
dateTimePickerDateBegin.Location = new Point(198, 256);
dateTimePickerDateBegin.Margin = new Padding(3, 4, 3, 4);
dateTimePickerDateBegin.Name = "dateTimePickerDateBegin";
dateTimePickerDateBegin.Size = new Size(228, 27);
dateTimePickerDateBegin.TabIndex = 1;
//
// textBoxFilePath
//
textBoxFilePath.Location = new Point(198, 108);
textBoxFilePath.Margin = new Padding(3, 4, 3, 4);
textBoxFilePath.Name = "textBoxFilePath";
textBoxFilePath.Size = new Size(191, 27);
textBoxFilePath.TabIndex = 2;
//
// buttonSelectFilePath
//
buttonSelectFilePath.Location = new Point(397, 108);
buttonSelectFilePath.Margin = new Padding(3, 4, 3, 4);
buttonSelectFilePath.Name = "buttonSelectFilePath";
buttonSelectFilePath.Size = new Size(30, 31);
buttonSelectFilePath.TabIndex = 3;
buttonSelectFilePath.Text = "...";
buttonSelectFilePath.UseVisualStyleBackColor = true;
buttonSelectFilePath.Click += ButtonSelectFilePath_Click;
//
// comboBoxAccessories
//
comboBoxAccessories.FormattingEnabled = true;
comboBoxAccessories.Location = new Point(198, 184);
comboBoxAccessories.Margin = new Padding(3, 4, 3, 4);
comboBoxAccessories.Name = "comboBoxAccessories";
comboBoxAccessories.Size = new Size(228, 28);
comboBoxAccessories.TabIndex = 4;
//
// labelFile
//
labelFile.AutoSize = true;
labelFile.Location = new Point(69, 112);
labelFile.Name = "labelFile";
labelFile.Size = new Size(41, 20);
labelFile.TabIndex = 5;
labelFile.Text = "Путь";
//
// labelNameAccessories
//
labelNameAccessories.AutoSize = true;
labelNameAccessories.Location = new Point(47, 187);
labelNameAccessories.Name = "labelNameAccessories";
labelNameAccessories.Size = new Size(145, 20);
labelNameAccessories.TabIndex = 6;
labelNameAccessories.Text = "id комплектующего";
//
// labelBeginTime
//
labelBeginTime.AutoSize = true;
labelBeginTime.Location = new Point(47, 261);
labelBeginTime.Name = "labelBeginTime";
labelBeginTime.Size = new Size(134, 20);
labelBeginTime.TabIndex = 7;
labelBeginTime.Text = "Начальное время";
//
// labelEndTime
//
labelEndTime.AutoSize = true;
labelEndTime.Location = new Point(47, 314);
labelEndTime.Name = "labelEndTime";
labelEndTime.Size = new Size(126, 20);
labelEndTime.TabIndex = 8;
labelEndTime.Text = "Конечное время";
//
// buttonMakeReport
//
buttonMakeReport.Location = new Point(175, 423);
buttonMakeReport.Margin = new Padding(3, 4, 3, 4);
buttonMakeReport.Name = "buttonMakeReport";
buttonMakeReport.Size = new Size(134, 31);
buttonMakeReport.TabIndex = 9;
buttonMakeReport.Text = "Сформировать";
buttonMakeReport.UseVisualStyleBackColor = true;
buttonMakeReport.Click += ButtonMakeReport_Click;
//
// FormAccessoriesReport
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(535, 600);
Controls.Add(buttonMakeReport);
Controls.Add(labelEndTime);
Controls.Add(labelBeginTime);
Controls.Add(labelNameAccessories);
Controls.Add(labelFile);
Controls.Add(comboBoxAccessories);
Controls.Add(buttonSelectFilePath);
Controls.Add(textBoxFilePath);
Controls.Add(dateTimePickerDateBegin);
Controls.Add(dateTimePickerDateEnd);
Margin = new Padding(3, 4, 3, 4);
Name = "FormAccessoriesReport";
Text = "FormAccessoriesReport";
ResumeLayout(false);
PerformLayout();
}
#endregion
private DateTimePicker dateTimePickerDateEnd;
private DateTimePicker dateTimePickerDateBegin;
private TextBox textBoxFilePath;
private Button buttonSelectFilePath;
private ComboBox comboBoxAccessories;
private Label labelFile;
private Label labelNameAccessories;
private Label labelBeginTime;
private Label labelEndTime;
private Button buttonMakeReport;
}
}

View File

@ -0,0 +1,76 @@
using ProjectCompRepair.Reports;
using ProjectCompRepair.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 ProjectCompRepair.Forms;
public partial class FormAccessoriesReport : Form
{
private readonly IUnityContainer _container;
public FormAccessoriesReport(IUnityContainer container, IAccessoriesRepository accessoriesRepository)
{
InitializeComponent();
_container = container ?? throw new ArgumentNullException(nameof(container));
comboBoxAccessories.DataSource = accessoriesRepository.ReadAccessories();
comboBoxAccessories.DisplayMember = "Name";
comboBoxAccessories.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 ButtonMakeReport_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(textBoxFilePath.Text))
{
throw new Exception("Отсутствует имя файла для отчета");
}
if (comboBoxAccessories.SelectedIndex < 0)
{
throw new Exception("Не выбран корм");
}
if (dateTimePickerDateEnd.Value <= dateTimePickerDateBegin.Value)
{
throw new Exception("Дата начала должна быть раньше даты окончания");
}
if (_container.Resolve<TableReport>().CreateTable(textBoxFilePath.Text, (int)comboBoxAccessories.SelectedValue!, dateTimePickerDateBegin.Value, dateTimePickerDateEnd.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 ProjectCompRepair.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()
{
checkBoxMasters = new CheckBox();
checkBoxServices = new CheckBox();
checkBoxAccessories = new CheckBox();
buttonBuild = new Button();
SuspendLayout();
//
// checkBoxMasters
//
checkBoxMasters.AutoSize = true;
checkBoxMasters.Location = new Point(15, 24);
checkBoxMasters.Name = "checkBoxMasters";
checkBoxMasters.Size = new Size(73, 19);
checkBoxMasters.TabIndex = 0;
checkBoxMasters.Text = "Мастера";
checkBoxMasters.UseVisualStyleBackColor = true;
//
// checkBoxServices
//
checkBoxServices.AutoSize = true;
checkBoxServices.Location = new Point(15, 70);
checkBoxServices.Name = "checkBoxServices";
checkBoxServices.Size = new Size(64, 19);
checkBoxServices.TabIndex = 1;
checkBoxServices.Text = "Услуги";
checkBoxServices.UseVisualStyleBackColor = true;
//
// checkBoxAccessories
//
checkBoxAccessories.AutoSize = true;
checkBoxAccessories.Location = new Point(15, 118);
checkBoxAccessories.Name = "checkBoxAccessories";
checkBoxAccessories.Size = new Size(120, 19);
checkBoxAccessories.TabIndex = 2;
checkBoxAccessories.Text = "Комплектующие";
checkBoxAccessories.UseVisualStyleBackColor = true;
//
// buttonBuild
//
buttonBuild.Location = new Point(155, 66);
buttonBuild.Name = "buttonBuild";
buttonBuild.Size = new Size(101, 23);
buttonBuild.TabIndex = 3;
buttonBuild.Text = "Сформировать";
buttonBuild.UseVisualStyleBackColor = true;
buttonBuild.Click += ButtonBuild_Click;
//
// FormDirectoryReport
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(290, 166);
Controls.Add(buttonBuild);
Controls.Add(checkBoxAccessories);
Controls.Add(checkBoxServices);
Controls.Add(checkBoxMasters);
Name = "FormDirectoryReport";
Text = "FormDirectoryReport";
ResumeLayout(false);
PerformLayout();
}
#endregion
private CheckBox checkBoxMasters;
private CheckBox checkBoxServices;
private CheckBox checkBoxAccessories;
private Button buttonBuild;
}
}

View File

@ -0,0 +1,60 @@
using ProjectCompRepair.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 ProjectCompRepair.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 (!checkBoxMasters.Checked && !checkBoxServices.Checked && !checkBoxAccessories.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, checkBoxMasters.Checked, checkBoxServices.Checked, checkBoxAccessories.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

@ -55,74 +55,79 @@
// labelName
//
labelName.AutoSize = true;
labelName.Location = new Point(19, 35);
labelName.Location = new Point(17, 26);
labelName.Name = "labelName";
labelName.Size = new Size(77, 20);
labelName.Size = new Size(59, 15);
labelName.TabIndex = 0;
labelName.Text = "Название";
//
// labelComent
//
labelComent.AutoSize = true;
labelComent.Location = new Point(19, 109);
labelComent.Location = new Point(17, 82);
labelComent.Name = "labelComent";
labelComent.Size = new Size(79, 20);
labelComent.Size = new Size(62, 15);
labelComent.TabIndex = 1;
labelComent.Text = "Описание";
//
// textBoxComent
//
textBoxComent.Location = new Point(208, 81);
textBoxComent.Location = new Point(182, 61);
textBoxComent.Margin = new Padding(3, 2, 3, 2);
textBoxComent.Multiline = true;
textBoxComent.Name = "textBoxComent";
textBoxComent.Size = new Size(125, 72);
textBoxComent.Size = new Size(110, 55);
textBoxComent.TabIndex = 2;
//
// textBoxName
//
textBoxName.Location = new Point(208, 28);
textBoxName.Location = new Point(182, 21);
textBoxName.Margin = new Padding(3, 2, 3, 2);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(125, 27);
textBoxName.Size = new Size(110, 23);
textBoxName.TabIndex = 3;
//
// labelDate
//
labelDate.AutoSize = true;
labelDate.Location = new Point(19, 192);
labelDate.Location = new Point(17, 144);
labelDate.Name = "labelDate";
labelDate.Size = new Size(183, 20);
labelDate.Size = new Size(142, 15);
labelDate.TabIndex = 4;
labelDate.Text = "Дата регистрации заказа";
//
// dateTimePicker
//
dateTimePicker.Location = new Point(208, 192);
dateTimePicker.Location = new Point(182, 144);
dateTimePicker.Margin = new Padding(3, 2, 3, 2);
dateTimePicker.Name = "dateTimePicker";
dateTimePicker.Size = new Size(192, 27);
dateTimePicker.Size = new Size(168, 23);
dateTimePicker.TabIndex = 5;
//
// comboBoxMaster
//
comboBoxMaster.FormattingEnabled = true;
comboBoxMaster.Location = new Point(208, 254);
comboBoxMaster.Location = new Point(182, 190);
comboBoxMaster.Margin = new Padding(3, 2, 3, 2);
comboBoxMaster.Name = "comboBoxMaster";
comboBoxMaster.Size = new Size(151, 28);
comboBoxMaster.Size = new Size(133, 23);
comboBoxMaster.TabIndex = 6;
//
// labelMaster
//
labelMaster.AutoSize = true;
labelMaster.Location = new Point(21, 262);
labelMaster.Location = new Point(18, 196);
labelMaster.Name = "labelMaster";
labelMaster.Size = new Size(60, 20);
labelMaster.Size = new Size(48, 15);
labelMaster.TabIndex = 7;
labelMaster.Text = "Мастер";
//
// buttonSave
//
buttonSave.Location = new Point(35, 389);
buttonSave.Location = new Point(31, 292);
buttonSave.Margin = new Padding(3, 2, 3, 2);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(94, 29);
buttonSave.Size = new Size(82, 22);
buttonSave.TabIndex = 8;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
@ -130,9 +135,10 @@
//
// buttonCancel
//
buttonCancel.Location = new Point(1077, 389);
buttonCancel.Location = new Point(942, 292);
buttonCancel.Margin = new Padding(3, 2, 3, 2);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29);
buttonCancel.Size = new Size(82, 22);
buttonCancel.TabIndex = 9;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
@ -141,9 +147,11 @@
// groupBox1
//
groupBox1.Controls.Add(dataGridViewAccessories);
groupBox1.Location = new Point(449, 35);
groupBox1.Location = new Point(393, 26);
groupBox1.Margin = new Padding(3, 2, 3, 2);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(309, 247);
groupBox1.Padding = new Padding(3, 2, 3, 2);
groupBox1.Size = new Size(270, 183);
groupBox1.TabIndex = 10;
groupBox1.TabStop = false;
groupBox1.Text = "Комплектующие";
@ -153,10 +161,11 @@
dataGridViewAccessories.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewAccessories.Columns.AddRange(new DataGridViewColumn[] { ColumnAccessories, ColumnCount });
dataGridViewAccessories.Dock = DockStyle.Fill;
dataGridViewAccessories.Location = new Point(3, 23);
dataGridViewAccessories.Location = new Point(3, 18);
dataGridViewAccessories.Margin = new Padding(3, 2, 3, 2);
dataGridViewAccessories.Name = "dataGridViewAccessories";
dataGridViewAccessories.RowHeadersWidth = 51;
dataGridViewAccessories.Size = new Size(303, 221);
dataGridViewAccessories.Size = new Size(264, 163);
dataGridViewAccessories.TabIndex = 0;
//
// ColumnAccessories
@ -176,9 +185,11 @@
// groupBoxServices
//
groupBoxServices.Controls.Add(dataGridViewServices);
groupBoxServices.Location = new Point(789, 35);
groupBoxServices.Location = new Point(690, 26);
groupBoxServices.Margin = new Padding(3, 2, 3, 2);
groupBoxServices.Name = "groupBoxServices";
groupBoxServices.Size = new Size(310, 247);
groupBoxServices.Padding = new Padding(3, 2, 3, 2);
groupBoxServices.Size = new Size(271, 185);
groupBoxServices.TabIndex = 11;
groupBoxServices.TabStop = false;
groupBoxServices.Text = "Услуги";
@ -188,10 +199,11 @@
dataGridViewServices.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewServices.Columns.AddRange(new DataGridViewColumn[] { ColumnService, ColumnCountServ });
dataGridViewServices.Dock = DockStyle.Fill;
dataGridViewServices.Location = new Point(3, 23);
dataGridViewServices.Location = new Point(3, 18);
dataGridViewServices.Margin = new Padding(3, 2, 3, 2);
dataGridViewServices.Name = "dataGridViewServices";
dataGridViewServices.RowHeadersWidth = 51;
dataGridViewServices.Size = new Size(304, 221);
dataGridViewServices.Size = new Size(265, 165);
dataGridViewServices.TabIndex = 0;
//
// ColumnService
@ -210,9 +222,9 @@
//
// FormOrder
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1183, 430);
ClientSize = new Size(1035, 322);
Controls.Add(groupBoxServices);
Controls.Add(groupBox1);
Controls.Add(buttonCancel);
@ -225,6 +237,7 @@
Controls.Add(textBoxComent);
Controls.Add(labelComent);
Controls.Add(labelName);
Margin = new Padding(3, 2, 3, 2);
Name = "FormOrder";
Text = "Заказ";
groupBox1.ResumeLayout(false);

View File

@ -16,7 +16,7 @@ public partial class FormOrder : Form
{
private readonly IOrderRepository _orderRepository;
private int? _orderId;
private int _orderId;
public int Id
{
@ -92,9 +92,9 @@ public partial class FormOrder : Form
{
continue;
}
list.Add(AccessoiresOrder.CreateElement(0,
Convert.ToInt32(row.Cells["ColumnAccessories"].Value),
Convert.ToInt32(row.Cells["ColumnCount"].Value)));
list.Add(AccessoiresOrder.CreateElement(
0,
Convert.ToInt32(row.Cells["ColumnCount"].Value), Convert.ToInt32(row.Cells["ColumnAccessories"].Value)));
}
return list;
}

View File

@ -7,6 +7,7 @@ using Unity;
using Microsoft.Extensions.Configuration;
using Unity.Microsoft.Logging;
using Unity.Lifetime;
using System.Text;
@ -24,6 +25,7 @@ namespace ProjectCompRepair
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(CreateContainer().Resolve<FormCompRepair>());
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
}
private static IUnityContainer CreateContainer()

View File

@ -10,11 +10,13 @@
<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.1" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
<PackageReference Include="Serilog" Version="4.1.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />

View File

@ -0,0 +1,55 @@
using Microsoft.Extensions.Logging;
using ProjectCompRepair.Entities;
using ProjectCompRepair.Repositories;
using ProjectCompRepair.Repositories.Implemantations;
using RegistrationOfPatients.Reports;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCompRepair.Reports;
internal class ChartReport
{
private readonly IOrderRepository _orderRepository;
private readonly ILogger<ChartReport> _logger;
public ChartReport(IOrderRepository orderRepository, ILogger<ChartReport> logger)
{
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public bool CreateChart(string filePath, DateTime dateTime, int accessoriesId)
{
try
{
new PdfBuilder(filePath)
.AddHeader("Комплектующие")
.AddPieChart("потраченные комплектующие", GetData(dateTime, accessoriesId))
.Build();
return true;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при формировании документа");
return false;
}
}
private List<(string Caption, double Value)> GetData(DateTime dateTime, int accessoriesId)
{
return _orderRepository
.ReadOrder()
.Where(x => x.Date.Date == dateTime.Date && x.AccessoiresOrders.Any(y => y.AccessoriesId == accessoriesId))
.GroupBy(x => x.Id, (key, group) => new
{
Id = key,
Count = group.Sum(x => x.AccessoiresOrders.FirstOrDefault(y => y.AccessoriesId == accessoriesId)?.Count ?? 0)
})
.Select(x => (x.Id.ToString(), (double)x.Count))
.ToList();
}
}

View File

@ -0,0 +1,79 @@
using Microsoft.Extensions.Logging;
using ProjectCompRepair.Repositories;
using ProjectCompRepair.Repositories.Implemantations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCompRepair.Reports;
internal class DocReport
{
private readonly IMasterRepository _masterRepository;
private readonly IServiceRepository _serviceRepository;
private readonly IAccessoriesRepository _accessoriesRepository;
private readonly ILogger<DocReport> _logger;
public DocReport(IMasterRepository masterRepository, IServiceRepository serviceRepository, IAccessoriesRepository accessoriesRepository, ILogger<DocReport> logger)
{
_masterRepository = masterRepository ??
throw new ArgumentNullException(nameof(masterRepository));
_serviceRepository = serviceRepository ??
throw new ArgumentNullException(nameof(serviceRepository));
_accessoriesRepository = accessoriesRepository ??
throw new ArgumentNullException(nameof(accessoriesRepository));
_logger = logger ??
throw new ArgumentNullException(nameof(logger));
}
public bool CreateDoc(string filePath, bool includeMaster, bool includeService, bool includeAccessories)
{
try
{
var builder = new WordBuilder(filePath).AddHeader("Документ со справочниками");
if (includeMaster)
{
builder.AddParagraph("Мастера").AddTable([2400], GetMaster());
}
if (includeService)
{
builder.AddParagraph("Услуги").AddTable([2400,2400], GetService());
}
if (includeAccessories)
{
builder.AddParagraph("Комплектующие").AddTable([2400,2400,2400], AccessoriesGet());
}
builder.Build();
return true;
}
catch(Exception ex)
{
_logger.LogError(ex, "Ошибка при формировании документа");
return false;
}
}
private List<string[]> GetMaster()
{
return [
["Имя мастера"], .. _masterRepository.ReadMaster().Select(x => new string[] {x.Name}),
];
}
private List<string[]> GetService()
{
return [
["Тип услуги", "Цена"], .. _serviceRepository.ReadService().Select(x => new string[] {x.ServiceType.ToString(), x.Price.ToString()}),
];
}
private List<string[]> AccessoriesGet()
{
return [
["Тип комплектующего", "Кол-во", "Цена"], .. _accessoriesRepository.ReadAccessories().Select
(x => new string[] {x.AccessoriesType.ToString(), x.Count.ToString(), x.Price.ToString()})
];
}
}

View File

@ -0,0 +1,332 @@
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RegistrationOfPatients.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)
}
});
// TODO добавить шрифт с жирным
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()
});
// TODO добавить настройку с границами
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
}
});
// TODO дополнить форматы
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,
// TODO дополнить стили
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,91 @@
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Shapes.Charts;
using MigraDoc.Rendering;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RegistrationOfPatients.Reports;
public 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()
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var renderer = new PdfDocumentRenderer(true)
{
Document = _document
};
renderer.RenderDocument();
renderer.PdfDocument.Save(_filePath);
}
private void DefineStyles()
{
var style = _document.Styles.AddStyle("NormalBold", "Normal");
style.Font.Bold = true;
style.Font.Size = 14;
style.ParagraphFormat.Alignment = ParagraphAlignment.Center;
}
}

View File

@ -0,0 +1,66 @@
using Microsoft.Extensions.Logging;
using ProjectCompRepair.Entities;
using ProjectCompRepair.Repositories;
using RegistrationOfPatients.Reports;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCompRepair.Reports;
internal class TableReport
{
private readonly IOrderRepository _orderRepository;
private readonly IAccessoriesRepository _accessoriesRepository;
private readonly ILogger<TableReport> _logger;
internal static readonly string[] item = ["Дата", "вход", "выход"];
public TableReport(IOrderRepository orderRepository, IAccessoriesRepository accessoriesRepository, ILogger<TableReport> logger)
{
_orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
_accessoriesRepository = accessoriesRepository ?? throw new ArgumentNullException(nameof(accessoriesRepository));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public bool CreateTable(string filePath, int accessoriesId, DateTime startDate, DateTime endDate)
{
try
{
new ExcelBuilder(filePath)
.AddHeader("Поставка комплектующих", 0, 3)
.AddParagraph("за период", 0)
.AddTable([10, 15, 15], GetData(accessoriesId, startDate, endDate))
.Build();
return true;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при формировании документа");
return false;
}
}
private List<string[]> GetData(int accessoriesId, DateTime startDate, DateTime endDate)
{
var data = _orderRepository.ReadOrder()
.Where(x => x.Date >= startDate && x.Date <= endDate && x.AccessoiresOrders.Any(y => y.AccessoriesId == accessoriesId))
.Select(x => new {Date = x.Date, CountIn = (int?)null, CountOut = x.AccessoiresOrders.FirstOrDefault(y => y.AccessoriesId == accessoriesId)?.Count, })
.Union(
_accessoriesRepository
.ReadAccessories()
.Where(x => x.Date >= startDate && x.Date <= endDate && x.Id == accessoriesId)
.Select(x => new {Date = x.Date, CountIn = (int?)x.Count, CountOut = (int?)null }))
.OrderBy(x => x.Date);
return new List<string[]>() { item }
.Union(
data
.Select(x => new string[] { x.Date.ToString("yyyy-MM-dd"), x.CountIn?.ToString() ?? string.Empty, x.CountOut?.ToString() ?? string.Empty }))
.Union(
[["Всего", data.Sum(x => x.CountIn ?? 0).ToString(), data.Sum(x => x.CountOut ?? 0).ToString()]])
.ToList();
}
}

View File

@ -0,0 +1,100 @@
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using Document = DocumentFormat.OpenXml.Wordprocessing.Document;
namespace ProjectCompRepair.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());
run.AppendChild(new RunProperties(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

@ -1,19 +0,0 @@
using ProjectCompRepair.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCompRepair.Repositories;
public interface IAccessoriesOrder
{
void CreateAccessoriesOrder(AccessoiresOrder accessoriesOrder);
void DeleteAccessoriesOrder(int id);
IEnumerable<AccessoiresOrder> ReadAccessoiresOrder(int? Id = 0, int? orderId = 0, int? count = 0);
}

View File

@ -11,7 +11,7 @@ namespace ProjectCompRepair.Repositories;
public interface IOrderRepository
{
IEnumerable<Order> ReadOrder();
IEnumerable<Order> ReadOrder(DateTime? dateForm = null, DateTime? dateTo = null, int? masterId = null, int? accessoriesId = null, int? serviceId = null);
Order ReadOrderById(int id);

View File

@ -35,8 +35,8 @@ public class AccessoriesRepository : IAccessoriesRepository
connection.Open();
var queryInsert = @"
INSERT INTO Accessories (AccessoriesType, Count, Price)
VALUES (@AccessoriesType, @Count, @Price)";
INSERT INTO Accessories (AccessoriesType, Count, Price, Date)
VALUES (@AccessoriesType, @Count, @Price, @Date)";
connection.Execute(queryInsert, accessories);
}
catch (Exception ex)
@ -58,7 +58,8 @@ VALUES (@AccessoriesType, @Count, @Price)";
SET
AccessoriesType = @AccessoriesType,
Count = @Count,
Price = @Price
Price = @Price,
Date = @Date
WHERE ID = @Id;";
connection.Execute(queryUpdate, accessories);
}

View File

@ -41,14 +41,15 @@
var orderId = connection.QueryFirst<int>(queryInsert, order, transaction);
var querySubInsertAccessories = @"
INSERT INTO AccessoriesOrder (OrderId, Count)
VALUES (@OrderId, @Count)";
INSERT INTO AccessoriesOrder (AccessoriesId, OrderId, Count)
VALUES (@AccessoriesId,@OrderId, @Count)";
foreach (var elem in order.AccessoiresOrders)
{
connection.Execute(querySubInsertAccessories, new
{
OrderId = orderId,
{
elem.AccessoriesId,
orderId,
elem.Count
}, transaction);
}
@ -121,7 +122,7 @@
}
}
public IEnumerable<Order> ReadOrder()
public IEnumerable<Order> ReadOrder(DateTime? dateForm = null, DateTime? dateTo = null, int? masterId = null, int? accessoriesId = null, int? serviceId = null)
{
_logger.LogInformation("Получение всех объектов");
try
@ -129,20 +130,25 @@
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
connection.Open();
var querySelect = @"SELECT * FROM Orderl";
var order = connection.Query<Order>(querySelect);
var querySelect = @"SELECT o.*, ao.AccessoriesId, ao.Count
FROM Orderl o
INNER JOIN AccessoriesOrder ao ON ao.OrderId = o.ID;";
var order = connection.Query<TempAccessoriesOrder>(querySelect);
_logger.LogDebug("Полученные объекты : {json}", JsonConvert.SerializeObject(order));
return order;
}
return order.GroupBy(x => x.Id, y => y,
(key, value) => Order.CreateElement(value.First(),
value.Select(z => AccessoiresOrder.CreateElement(0, z.Count, z.AccessoriesId)))).ToList();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при чтении объектов");
throw;
}
}
}
}