Compare commits

..

No commits in common. "d43780c207629df283d2f50997bd9fcf40a6e095" and "9e58d661cf1df5de28361ecd64c4fa8dc29cf939" have entirely different histories.

48 changed files with 100 additions and 2798 deletions

View File

@ -15,13 +15,11 @@ namespace PrecastConcretePlantFileImplement
private readonly string OrderFileName = "Order.xml";
private readonly string ReinforcedFileName = "Reinforced.xml";
private readonly string ClientFileName = "Client.xml";
private readonly string ImplementerFileName = "Implementer.xml";
private readonly string ShopFileName = "Shop.xml";
public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; }
public List<Reinforced> Reinforceds { get; private set; }
public List<Client> Clients { get; private set; }
public List<Implementer> Implementers { get; private set; }
public List<Shop> Shops { get; private set; }
public static DataFileSingleton GetInstance()
{
@ -39,8 +37,6 @@ namespace PrecastConcretePlantFileImplement
=> x.GetXElement);
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x
=> x.GetXElement);
public void SaveImplementers() => SaveData(Implementers, OrderFileName, "Implementers", x
=> x.GetXElement);
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
private DataFileSingleton()
{
@ -50,7 +46,6 @@ namespace PrecastConcretePlantFileImplement
Reinforced.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
Implementers=LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!;
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName,

View File

@ -1,110 +0,0 @@
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.StoragesContracts;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantFileImplement.Implements
{
public class ImplementerStorage : IImplementerStorage
{
private readonly DataFileSingleton _source;
public ImplementerStorage()
{
_source = DataFileSingleton.GetInstance();
}
public ImplementerViewModel? Delete(ImplementerBindingModel model)
{
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
if (res != null)
{
_source.Implementers.Remove(res);
_source.SaveImplementers();
}
return res?.GetViewModel;
}
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
{
if (model.Id.HasValue)
return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
if (model.ImplementerFIO != null && model.Password != null)
return _source.Implementers
.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)
&& x.Password.Equals(model.Password))
?.GetViewModel;
if (model.ImplementerFIO != null)
return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel;
return null;
}
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
{
if (model == null)
{
return new();
}
if (model.Id.HasValue)
{
var res = GetElement(model);
return res != null ? new() { res } : new();
}
if (model.ImplementerFIO != null)
{
return _source.Implementers
.Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public List<ImplementerViewModel> GetFullList()
{
return _source.Implementers
.Select(x => x.GetViewModel)
.ToList();
}
public ImplementerViewModel? Insert(ImplementerBindingModel model)
{
model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1;
var res = Implementer.Create(model);
if (res != null)
{
_source.Implementers.Add(res);
_source.SaveImplementers();
}
return res?.GetViewModel;
}
public ImplementerViewModel? Update(ImplementerBindingModel model)
{
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
if (res != null)
{
res.Update(model);
_source.SaveImplementers();
}
return res?.GetViewModel;
}
}
}

View File

@ -37,20 +37,6 @@ namespace PrecastConcretePlantFileImplement.Implements
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (model.ImplementerId.HasValue && model.Statuses != null)
{
return source.Orders
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId &&
model.Statuses.Contains(x.Status))
?.GetViewModel;
}
if (model.ImplementerId.HasValue)
{
return source.Orders
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)
?.GetViewModel;
}
if (!model.Id.HasValue)
{
return null;

View File

@ -1,86 +0,0 @@
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace PrecastConcretePlantFileImplement.Models
{
public class Implementer : IImplementerModel
{
public string ImplementerFIO { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty;
public int WorkExperience { get; private set; }
public int Qualification { get; private set; }
public int Id { get; private set; }
public static Implementer? Create(XElement element)
{
if (element == null)
{
return null;
}
return new()
{
ImplementerFIO = element.Element("FIO")!.Value,
Password = element.Element("Password")!.Value,
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
Qualification = Convert.ToInt32(element.Element("Qualification")!.Value),
WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value),
};
}
public static Implementer? Create(ImplementerBindingModel model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
Password = model.Password,
Qualification = model.Qualification,
ImplementerFIO = model.ImplementerFIO,
WorkExperience = model.WorkExperience,
};
}
public void Update(ImplementerBindingModel model)
{
if (model == null)
{
return;
}
Password = model.Password;
Qualification = model.Qualification;
ImplementerFIO = model.ImplementerFIO;
WorkExperience = model.WorkExperience;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
Password = Password,
Qualification = Qualification,
ImplementerFIO = ImplementerFIO,
WorkExperience = WorkExperience
};
public XElement GetXElement => new("Client",
new XAttribute("Id", Id),
new XElement("Password", Password),
new XElement("FIO", ImplementerFIO),
new XElement("Qualification", Qualification),
new XElement("WorkExperience", WorkExperience)
);
}
}

View File

@ -13,7 +13,6 @@ namespace PrecastConcretePlantFileImplement.Models
{
public class Order : IOrderModel
{
public int? ImplementerId { get; set; }
public int ClientId { get; private set; }
public int ReinforcedId { get; private set; }
public int Count { get; private set; }
@ -37,7 +36,6 @@ namespace PrecastConcretePlantFileImplement.Models
return new Order()
{
Id = model.Id,
ImplementerId = model.ImplementerId,
ClientId = model.ClientId,
ReinforcedId = model.ReinforcedId,
Count = model.Count,
@ -58,9 +56,8 @@ namespace PrecastConcretePlantFileImplement.Models
var order = new Order()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value),
ReinforcedId = Convert.ToInt32(element.Element("ReinforcedId")!.Value),
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
ClientId=Convert.ToInt32(element.Element("ClientId")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
@ -88,7 +85,6 @@ namespace PrecastConcretePlantFileImplement.Models
{
Id = Id,
ClientId = ClientId,
ImplementerId = ImplementerId,
ReinforcedId = ReinforcedId,
Count = Count,
Sum = Sum,
@ -99,8 +95,7 @@ namespace PrecastConcretePlantFileImplement.Models
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XAttribute("ClientId", ClientId.ToString()),
new XElement("ImplementerId", ImplementerId.ToString()),
new XAttribute("ClientId",ClientId.ToString()),
new XElement("ReinforcedId", ReinforcedId.ToString()),
new XElement("Count", Count.ToString()),
new XElement("Sum", Sum.ToString()),

View File

@ -1,173 +0,0 @@
namespace PrecastConcretePlantView
{
partial class FormImplementer
{
/// <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()
{
buttonSave = new Button();
buttonCancel = new Button();
numericUpDownQualification = new NumericUpDown();
numericUpDownWorkExperience = new NumericUpDown();
textBoxPassword = new TextBox();
textBoxFio = new TextBox();
label4 = new Label();
label3 = new Label();
label2 = new Label();
label1 = new Label();
((System.ComponentModel.ISupportInitialize)numericUpDownQualification).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownWorkExperience).BeginInit();
SuspendLayout();
//
// buttonSave
//
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonSave.Location = new Point(108, 151);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(89, 33);
buttonSave.TabIndex = 19;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Location = new Point(219, 151);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(89, 33);
buttonCancel.TabIndex = 18;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// numericUpDownQualification
//
numericUpDownQualification.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
numericUpDownQualification.Location = new Point(116, 97);
numericUpDownQualification.Name = "numericUpDownQualification";
numericUpDownQualification.Size = new Size(264, 23);
numericUpDownQualification.TabIndex = 17;
//
// numericUpDownWorkExperience
//
numericUpDownWorkExperience.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
numericUpDownWorkExperience.Location = new Point(116, 68);
numericUpDownWorkExperience.Name = "numericUpDownWorkExperience";
numericUpDownWorkExperience.Size = new Size(264, 23);
numericUpDownWorkExperience.TabIndex = 16;
//
// textBoxPassword
//
textBoxPassword.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
textBoxPassword.Location = new Point(116, 40);
textBoxPassword.Name = "textBoxPassword";
textBoxPassword.PasswordChar = '*';
textBoxPassword.Size = new Size(264, 23);
textBoxPassword.TabIndex = 15;
//
// textBoxFio
//
textBoxFio.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
textBoxFio.Location = new Point(116, 11);
textBoxFio.Name = "textBoxFio";
textBoxFio.Size = new Size(264, 23);
textBoxFio.TabIndex = 14;
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(14, 99);
label4.Name = "label4";
label4.Size = new Size(91, 15);
label4.TabIndex = 13;
label4.Text = "Квалификация:";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(67, 70);
label3.Name = "label3";
label3.Size = new Size(38, 15);
label3.TabIndex = 12;
label3.Text = "Стаж:";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(58, 43);
label2.Name = "label2";
label2.Size = new Size(52, 15);
label2.TabIndex = 11;
label2.Text = "Пароль:";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(68, 14);
label1.Name = "label1";
label1.Size = new Size(37, 15);
label1.TabIndex = 10;
label1.Text = "ФИО:";
//
// FormImplementer
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(402, 196);
Controls.Add(buttonSave);
Controls.Add(buttonCancel);
Controls.Add(numericUpDownQualification);
Controls.Add(numericUpDownWorkExperience);
Controls.Add(textBoxPassword);
Controls.Add(textBoxFio);
Controls.Add(label4);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Name = "FormImplementer";
Text = "Исполнитель";
Load += FormImplementer_Load;
((System.ComponentModel.ISupportInitialize)numericUpDownQualification).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownWorkExperience).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonSave;
private Button buttonCancel;
private NumericUpDown numericUpDownQualification;
private NumericUpDown numericUpDownWorkExperience;
private TextBox textBoxPassword;
private TextBox textBoxFio;
private Label label4;
private Label label3;
private Label label2;
private Label label1;
}
}

View File

@ -1,100 +0,0 @@
using Microsoft.Extensions.Logging;
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.BusinessLogicsContracts;
using PrecastConcretePlantContracts.SearchModels;
namespace PrecastConcretePlantView
{
public partial class FormImplementer : Form
{
private readonly ILogger _logger;
private readonly IImplementerLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public FormImplementer(ILogger<FormImplementer> logger, IImplementerLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormImplementer_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
_logger.LogInformation("Получение исполнителя");
var view = _logic.ReadElement(new ImplementerSearchModel
{
Id = _id.Value
});
if (view != null)
{
textBoxFio.Text = view.ImplementerFIO;
textBoxPassword.Text = view.Password;
numericUpDownQualification.Value = view.Qualification;
numericUpDownWorkExperience.Value = view.WorkExperience;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения исполнителя");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxPassword.Text))
{
MessageBox.Show("Заполните пароль", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxFio.Text))
{
MessageBox.Show("Заполните фио", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение исполнителя");
try
{
var model = new ImplementerBindingModel
{
Id = _id ?? 0,
ImplementerFIO = textBoxFio.Text,
Password = textBoxPassword.Text,
Qualification = (int)numericUpDownQualification.Value,
WorkExperience = (int)numericUpDownWorkExperience.Value,
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения исполнителя");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

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

View File

@ -1,118 +0,0 @@
namespace PrecastConcretePlantView
{
partial class FormImplementers
{
/// <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()
{
buttonRef = new Button();
buttonDel = new Button();
buttonUpd = new Button();
buttonAdd = new Button();
dataGridView = new DataGridView();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// buttonRef
//
buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonRef.Location = new Point(532, 149);
buttonRef.Name = "buttonRef";
buttonRef.Size = new Size(90, 37);
buttonRef.TabIndex = 14;
buttonRef.Text = "Обновить";
buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += ButtonRef_Click;
//
// buttonDel
//
buttonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonDel.Location = new Point(532, 110);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(90, 33);
buttonDel.TabIndex = 13;
buttonDel.Text = "Удалить";
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += ButtonDel_Click;
//
// buttonUpd
//
buttonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonUpd.Location = new Point(532, 70);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(90, 34);
buttonUpd.TabIndex = 12;
buttonUpd.Text = "Изменить";
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += ButtonUpd_Click;
//
// buttonAdd
//
buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonAdd.Location = new Point(532, 34);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(90, 30);
buttonAdd.TabIndex = 11;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// dataGridView
//
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(12, 12);
dataGridView.Name = "dataGridView";
dataGridView.RowTemplate.Height = 25;
dataGridView.Size = new Size(469, 290);
dataGridView.TabIndex = 10;
//
// FormImplementers
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(634, 314);
Controls.Add(buttonRef);
Controls.Add(buttonDel);
Controls.Add(buttonUpd);
Controls.Add(buttonAdd);
Controls.Add(dataGridView);
Name = "FormImplementers";
Text = "Исполнители";
Load += FormViewImplementers_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private Button buttonRef;
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
private DataGridView dataGridView;
}
}

View File

@ -1,103 +0,0 @@
using Microsoft.Extensions.Logging;
using PrecastConcretePlant;
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.BusinessLogicsContracts;
namespace PrecastConcretePlantView
{
public partial class FormImplementers : Form
{
private readonly ILogger _logger;
private readonly IImplementerLogic _logic;
public FormImplementers(ILogger<FormImplementers> logger, IImplementerLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormViewImplementers_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка исполнителей");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки исполнителей");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
if (service is FormImplementer form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
if (service is FormImplementer form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление исполнителя");
try
{
if (!_logic.Delete(new ImplementerBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления исполнителя");
MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

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

View File

@ -28,26 +28,6 @@
/// </summary>
private void InitializeComponent()
{
MenuStrip = new MenuStrip();
СправочникиToolStripMenuItem = new ToolStripMenuItem();
ИзделияToolStripMenuItem = new ToolStripMenuItem();
КомпонентыToolStripMenuItem = new ToolStripMenuItem();
клиентыToolStripMenuItem = new ToolStripMenuItem();
исполнителиToolStripMenuItem = new ToolStripMenuItem();
отчетыToolStripMenuItem = new ToolStripMenuItem();
списокЖБИToolStripMenuItem = new ToolStripMenuItem();
компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem();
списокЗаказовToolStripMenuItem = new ToolStripMenuItem();
запускРаботToolStripMenuItem = new ToolStripMenuItem();
DataGridView = new DataGridView();
CreateOrderButton = new Button();
TakeOrderInWorkButton = new Button();
OrderReadyButton = new Button();
IssuedOrderButton = new Button();
UpdateListButton = new Button();
MenuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit();
SuspendLayout();
MenuStrip = new MenuStrip();
СправочникиToolStripMenuItem = new ToolStripMenuItem();
ИзделияToolStripMenuItem = new ToolStripMenuItem();
@ -92,12 +72,6 @@
//
// MenuStrip
//
MenuStrip.Items.AddRange(new ToolStripItem[] { СправочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem });
MenuStrip.Location = new Point(0, 0);
MenuStrip.Name = "MenuStrip";
MenuStrip.Size = new Size(953, 24);
MenuStrip.TabIndex = 0;
MenuStrip.Text = "menuStrip1";
MenuStrip.Items.AddRange(new ToolStripItem[] { СправочникиToolStripMenuItem, отчетыToolStripMenuItem });
MenuStrip.Location = new Point(0, 0);
MenuStrip.Name = "MenuStrip";
@ -107,10 +81,6 @@
//
// СправочникиToolStripMenuItem
//
СправочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ИзделияToolStripMenuItem, КомпонентыToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem });
СправочникиToolStripMenuItem.Name = "СправочникиToolStripMenuItem";
СправочникиToolStripMenuItem.Size = new Size(94, 20);
СправочникиToolStripMenuItem.Text = "Cправочники";
this.СправочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ИзделияToolStripMenuItem,
this.КомпонентыToolStripMenuItem,
@ -126,10 +96,6 @@
// ИзделияToolStripMenuItem
//
ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem";
ИзделияToolStripMenuItem.Size = new Size(180, 22);
ИзделияToolStripMenuItem.Text = "ЖБИ";
ИзделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click;
ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem";
ИзделияToolStripMenuItem.Size = new Size(145, 22);
ИзделияToolStripMenuItem.Text = "ЖБИ";
ИзделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click;
@ -137,28 +103,10 @@
// КомпонентыToolStripMenuItem
//
КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem";
КомпонентыToolStripMenuItem.Size = new Size(180, 22);
КомпонентыToolStripMenuItem.Text = "Компоненты";
КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem";
КомпонентыToolStripMenuItem.Size = new Size(145, 22);
КомпонентыToolStripMenuItem.Text = "Компоненты";
КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
//
// клиентыToolStripMenuItem
//
клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
клиентыToolStripMenuItem.Size = new Size(180, 22);
клиентыToolStripMenuItem.Text = "Клиенты";
клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click;
//
// исполнителиToolStripMenuItem
//
исполнителиToolStripMenuItem.Name = сполнителиToolStripMenuItem";
исполнителиToolStripMenuItem.Size = new Size(180, 22);
исполнителиToolStripMenuItem.Text = "Исполнители";
исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click;
//
// магазиныToolStripMenuItem
//
магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
@ -168,10 +116,6 @@
//
// отчетыToolStripMenuItem
//
отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокЖБИToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem });
отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
отчетыToolStripMenuItem.Size = new Size(60, 20);
отчетыToolStripMenuItem.Text = "Отчеты";
отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокЖБИToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem, списокМагазиновToolStripMenuItem, загруженностьМагазиновToolStripMenuItem, заказыПоДатамToolStripMenuItem });
отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
отчетыToolStripMenuItem.Size = new Size(60, 20);
@ -180,10 +124,6 @@
// списокЖБИToolStripMenuItem
//
списокЖБИToolStripMenuItem.Name = "списокЖБИToolStripMenuItem";
списокЖБИToolStripMenuItem.Size = new Size(197, 22);
списокЖБИToolStripMenuItem.Text = "Список ЖБИ";
списокЖБИToolStripMenuItem.Click += списокИзделийToolStripMenuItem_Click;
списокЖБИToolStripMenuItem.Name = "списокЖБИToolStripMenuItem";
списокЖБИToolStripMenuItem.Size = new Size(219, 22);
списокЖБИToolStripMenuItem.Text = "Список ЖБИ";
списокЖБИToolStripMenuItem.Click += списокИзделийToolStripMenuItem_Click;
@ -191,10 +131,6 @@
// компонентыПоИзделиямToolStripMenuItem
//
компонентыПоИзделиямToolStripMenuItem.Name = омпонентыПоИзделиямToolStripMenuItem";
компонентыПоИзделиямToolStripMenuItem.Size = new Size(197, 22);
компонентыПоИзделиямToolStripMenuItem.Text = "ЖБИ по компонентам";
компонентыПоИзделиямToolStripMenuItem.Click += компонентыПоИзделиямToolStripMenuItem_Click;
компонентыПоИзделиямToolStripMenuItem.Name = омпонентыПоИзделиямToolStripMenuItem";
компонентыПоИзделиямToolStripMenuItem.Size = new Size(219, 22);
компонентыПоИзделиямToolStripMenuItem.Text = "ЖБИ по компонентам";
компонентыПоИзделиямToolStripMenuItem.Click += компонентыПоИзделиямToolStripMenuItem_Click;
@ -202,17 +138,6 @@
// списокЗаказовToolStripMenuItem
//
списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem";
списокЗаказовToolStripMenuItem.Size = new Size(197, 22);
списокЗаказовToolStripMenuItem.Text = "Список заказов";
списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click;
//
// запускРаботToolStripMenuItem
//
запускРаботToolStripMenuItem.Name = апускРаботToolStripMenuItem";
запускРаботToolStripMenuItem.Size = new Size(92, 20);
запускРаботToolStripMenuItem.Text = "Запуск работ";
запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click;
списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem";
списокЗаказовToolStripMenuItem.Size = new Size(219, 22);
списокЗаказовToolStripMenuItem.Text = "Список заказов";
списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click;
@ -275,13 +200,6 @@
UpdateListButton.Text = "Обновить список";
UpdateListButton.UseVisualStyleBackColor = true;
UpdateListButton.Click += UpdateListButton_Click;
UpdateListButton.Location = new Point(825, 189);
UpdateListButton.Name = "UpdateListButton";
UpdateListButton.Size = new Size(104, 33);
UpdateListButton.TabIndex = 6;
UpdateListButton.Text = "Обновить список";
UpdateListButton.UseVisualStyleBackColor = true;
UpdateListButton.Click += UpdateListButton_Click;
//
// AddShopButton
//
@ -336,25 +254,6 @@
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(953, 450);
Controls.Add(UpdateListButton);
Controls.Add(IssuedOrderButton);
Controls.Add(OrderReadyButton);
Controls.Add(TakeOrderInWorkButton);
Controls.Add(CreateOrderButton);
Controls.Add(DataGridView);
Controls.Add(MenuStrip);
MainMenuStrip = MenuStrip;
Name = "FormMain";
Text = "Завод ЖБИ";
Load += FormMain_Load;
MenuStrip.ResumeLayout(false);
MenuStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)DataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(953, 450);
Controls.Add(ButtonSell);
Controls.Add(AddShopButton);
Controls.Add(UpdateListButton);
@ -392,8 +291,6 @@
private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem;
private ToolStripMenuItem списокЗаказовToolStripMenuItem;
private ToolStripMenuItem клиентыToolStripMenuItem;
private ToolStripMenuItem исполнителиToolStripMenuItem;
private ToolStripMenuItem запускРаботToolStripMenuItem;
private ToolStripMenuItem магазиныToolStripMenuItem;
private Button AddShopButton;
private Button ButtonSell;

View File

@ -1,6 +1,5 @@
using Microsoft.Extensions.Logging;
using PrecastConcretePlant;
using PrecastConcretePlantBusinessLogic.BusinessLogic;
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.BusinessLogicsContracts;
using PrecastConcretePlantDataModels.Enums;
@ -22,15 +21,13 @@ namespace PrecastConcretePlantView
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic;
private readonly IWorkProcess _workProcess;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess)
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
_reportLogic = reportLogic;
_workProcess = workProcess;
}
private void FormMain_Load(object sender, EventArgs e)
@ -51,7 +48,6 @@ namespace PrecastConcretePlantView
DataGridView.DataSource = list;
DataGridView.Columns["ReinforcedId"].Visible = false;
DataGridView.Columns["ClientId"].Visible = false;
DataGridView.Columns["ImplementerId"].Visible = false;
DataGridView.Columns["DateImplement"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
@ -225,23 +221,6 @@ namespace PrecastConcretePlantView
}
}
private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e)
{
_workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic
)) as IImplementerLogic)!, _orderLogic);
MessageBox.Show("Процесс обработки запущен", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
if (service is FormImplementers form)
{
form.ShowDialog();
}
}
private void магазиныToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));

View File

@ -45,9 +45,6 @@ namespace PrecastConcretePlant
services.AddTransient<IReinforcedLogic, ReinforcedLogic>();
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<IImplementerStorage, ImplementerStorage>();
services.AddTransient<IImplementerLogic, ImplementerLogic>();
services.AddTransient<IWorkProcess, WorkModeling>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<AbstractSaveToWord, SaveToWord>();
@ -64,8 +61,6 @@ namespace PrecastConcretePlant
services.AddTransient<FormReportReinforcedComponents>();
services.AddTransient<FormReportOrders>();
services.AddTransient<FormClients>();
services.AddTransient<FormImplementers>();
services.AddTransient<FormImplementer>();
services.AddTransient<FormShopReinforced>();
services.AddTransient<FormShops>();

View File

@ -1,127 +0,0 @@
using Microsoft.Extensions.Logging;
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.BusinessLogicsContracts;
using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.StoragesContracts;
using PrecastConcretePlantContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantBusinessLogic.BusinessLogic
{
public class ImplementerLogic : IImplementerLogic
{
private readonly ILogger _logger;
private readonly IImplementerStorage _implementerStorage;
public ImplementerLogic(ILogger<ImplementerLogic> logger, IImplementerStorage implementerStorage)
{
_logger = logger;
_implementerStorage = implementerStorage;
}
public ImplementerViewModel? ReadElement(ImplementerSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ImplementerFIO:{ImplementerFIO}. Id:{Id}", model.ImplementerFIO, model.Id);
var element = _implementerStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model)
{
_logger.LogInformation("ReadList. ImplementerFIO:{ImplementerFIO}. Id:{Id}", model?.ImplementerFIO, model?.Id);
var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Create(ImplementerBindingModel model)
{
CheckModel(model);
if (_implementerStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ImplementerBindingModel model)
{
CheckModel(model);
if (_implementerStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ImplementerBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_implementerStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ImplementerBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ImplementerFIO))
{
throw new ArgumentNullException("Нет ФИО", nameof(model.ImplementerFIO));
}
if (model.Qualification <= 0)
{
throw new ArgumentNullException("Квалификация должна быть больше 0", nameof(model.Qualification));
}
if (model.WorkExperience < 0)
{
throw new ArgumentNullException("Стаж должен быть не меньше 0", nameof(model.WorkExperience));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет пароля", nameof(model.Password));
}
_logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}. Password:{Password}. Qualification:{Qualification}. WorkExperience:{WorkExperience}. Id:{Id}",
model.ImplementerFIO, model.Password, model.Qualification, model.WorkExperience, model.Id);
var element = _implementerStorage.GetElement(new ImplementerSearchModel
{
ImplementerFIO = model.ImplementerFIO
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Исполнитель с таким ФИО уже есть");
}
}
}
}

View File

@ -50,23 +50,6 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
return true;
}
public OrderViewModel? ReadElement(OrderSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. DateFrom:{DateFrom}. DateTo:{DateTo}. Id:{Id}", model.DateFrom, model.DateTo, model.Id);
var element = _orderStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
private bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
{
var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
@ -74,47 +57,37 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
{
throw new ArgumentNullException(nameof(model));
}
if (viewModel.Status + 1 != newStatus && viewModel.Status != OrderStatus.Ожидание)
if (viewModel.Status + 1 != newStatus)
{
_logger.LogWarning("Change status operation failed");
throw new InvalidOperationException();
return false;
}
model.Status = newStatus;
if (model.Status == OrderStatus.Готов || viewModel.Status == OrderStatus.Ожидание)
{
if (model.Status == OrderStatus.Готов)
{
model.DateImplement = DateTime.Now;
var reinforced = _reinforcedStorage.GetElement(new() { Id = viewModel.ReinforcedId });
if (reinforced == null)
{
throw new ArgumentNullException(nameof(reinforced));
}
if (!_shopLogic.AddReinforced(reinforced, viewModel.Count))
{
model.Status = OrderStatus.Ожидание;
_logger.LogWarning($"AddReinforced operation failed");
}
else
{
model.DateImplement = DateTime.Now;
}
}
else
{
model.DateImplement = viewModel.DateImplement;
}
if (viewModel.ImplementerId.HasValue)
{
model.ImplementerId = viewModel.ImplementerId.Value;
}
CheckModel(model, false);
if (_orderStorage.Update(model) == null)
{
_logger.LogWarning("Change status operation failed");
return false;
}
return true;
}
var reinforced = _reinforcedStorage.GetElement(new() { Id = viewModel.ReinforcedId });
if (reinforced == null)
{
throw new ArgumentNullException(nameof(reinforced));
}
if (!_shopLogic.AddReinforced(reinforced, viewModel.Count))
{
throw new Exception($"AddReinforced operation failed");
}
}
else
{
model.DateImplement = viewModel.DateImplement;
}
CheckModel(model, false);
if (_orderStorage.Update(model) == null)
{
_logger.LogWarning("Change status operation failed");
return false;
}
return true;
}
public bool TakeOrderInWork(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Выполняется);
@ -126,7 +99,6 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
public bool FinishOrder(OrderBindingModel model)
{
model.DateImplement=DateTime.Now;
return StatusUpdate(model, OrderStatus.Выдан);
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)

View File

@ -173,11 +173,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
foreach (var shop in _shopStorage.GetFullList())
{
int freeQuantity = shop.Capacity - shop.ShopReinforceds.Select(x => x.Value.Item2).Sum();
if (freeQuantity == 0)
{
continue;
}
if (freeQuantity < count)
if (freeQuantity < count)
{
if (!AddReinforcedInShop(new() { Id = shop.Id }, model, freeQuantity))
{

View File

@ -1,158 +0,0 @@
using Microsoft.Extensions.Logging;
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.BusinessLogicsContracts;
using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantDataModels.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantBusinessLogic.BusinessLogic
{
public class WorkModeling : IWorkProcess
{
private readonly ILogger _logger;
private readonly Random _rnd;
private IOrderLogic? _orderLogic;
public WorkModeling(ILogger<WorkModeling> logger)
{
_logger = logger;
_rnd = new Random(1000);
}
public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic)
{
_orderLogic = orderLogic;
var implementers = implementerLogic.ReadList(null);
if (implementers == null)
{
_logger.LogWarning("DoWork. Implementers is null");
return;
}
var orders = _orderLogic.ReadList(new OrderSearchModel { Statuses = new() { OrderStatus.Принят, OrderStatus.Выполняется,OrderStatus.Ожидание } });
if (orders == null || orders.Count == 0)
{
_logger.LogWarning("DoWork. Orders is null or empty");
return;
}
_logger.LogDebug("DoWork for {Count} orders", orders.Count);
foreach (var implementer in implementers)
{
Task.Run(() => WorkerWorkAsync(implementer, orders));
}
}
private async Task WorkerWorkAsync(ImplementerViewModel implementer, List<OrderViewModel> orders)
{
if (_orderLogic == null || implementer == null)
{
return;
}
await RunOrderInWork(implementer, orders);
await Task.Run(() =>
{
foreach (var order in orders.Where(x => x.Status == OrderStatus.Ожидание && x.ImplementerId == implementer.Id))
{
try
{
_orderLogic.DeliveryOrder(new OrderBindingModel
{
Id = order.Id
});
}
catch (InvalidOperationException ex)
{
_logger.LogWarning(ex, "Error try get work");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error while do work");
throw;
}
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
}
});
await RunOrderInWork(implementer, orders);
await Task.Run(() =>
{
foreach (var order in orders.Where(x => x.Status == OrderStatus.Принят))
{
try
{
_logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id);
_orderLogic.TakeOrderInWork(new OrderBindingModel
{
Id = order.Id,
ImplementerId = implementer.Id
});
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count);
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
_orderLogic.DeliveryOrder(new OrderBindingModel
{
Id = order.Id
});
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
}
catch (InvalidOperationException ex)
{
_logger.LogWarning(ex, "Error try get work");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error while do work");
throw;
}
}
});
}
private async Task RunOrderInWork(ImplementerViewModel implementer, List<OrderViewModel> allOrders)
{
if (_orderLogic == null || implementer == null || allOrders == null || allOrders.Count == 0)
{
return;
}
try
{
var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.ImplementerId == implementer.Id && x.Status == OrderStatus.Выполняется));
if (runOrder == null)
{
return;
}
_logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id);
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count);
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id);
_orderLogic.DeliveryOrder(new OrderBindingModel
{
Id = runOrder.Id
});
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
}
catch (InvalidOperationException ex)
{
_logger.LogWarning(ex, "Error try get work");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error while do work");
throw;
}
}
}
}

View File

@ -1,21 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantContracts.BindingModels
{
public class ImplementerBindingModel
{
public int Id { get; set; }
public string ImplementerFIO { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public int WorkExperience { get; set; }
public int Qualification { get; set; }
}
}

View File

@ -18,6 +18,5 @@ namespace PrecastConcretePlantContracts.BindingModels
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; set; } = DateTime.Now;
public DateTime? DateImplement { get; set; }
public int? ImplementerId { get; set; }
}
}

View File

@ -1,24 +0,0 @@
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantContracts.BusinessLogicsContracts
{
public interface IImplementerLogic
{
List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model);
ImplementerViewModel? ReadElement(ImplementerSearchModel model);
bool Create(ImplementerBindingModel model);
bool Update(ImplementerBindingModel model);
bool Delete(ImplementerBindingModel model);
}
}

View File

@ -12,7 +12,6 @@ namespace PrecastConcretePlantContracts.BusinessLogicsContracts
public interface IOrderLogic
{
List<OrderViewModel>? ReadList(OrderSearchModel? model);
OrderViewModel? ReadElement(OrderSearchModel? model);
bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model);
bool FinishOrder(OrderBindingModel model);

View File

@ -1,17 +0,0 @@
using PrecastConcretePlantContracts.BusinessLogicsContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantBusinessLogic.BusinessLogic
{
public interface IWorkProcess
{
/// <summary>
/// Запуск работ
/// </summary>
void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic);
}
}

View File

@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantContracts.SearchModels
{
public class ImplementerSearchModel
{
public int? Id { get; set; }
public string? ImplementerFIO { get; set; }
public string? Password { get; set; }
}
}

View File

@ -1,5 +1,4 @@
using PrecastConcretePlantDataModels.Enums;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -11,10 +10,8 @@ namespace PrecastConcretePlantContracts.SearchModels
{
public int? Id { get; set; }
public int? ClientId { get; set; }
public int? ImplementerId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public List<OrderStatus>? Statuses { get; set; }
}
}

View File

@ -1,26 +0,0 @@
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantContracts.StoragesContracts
{
public interface IImplementerStorage
{
List<ImplementerViewModel> GetFullList();
List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model);
ImplementerViewModel? GetElement(ImplementerSearchModel model);
ImplementerViewModel? Insert(ImplementerBindingModel model);
ImplementerViewModel? Update(ImplementerBindingModel model);
ImplementerViewModel? Delete(ImplementerBindingModel model);
}
}

View File

@ -1,27 +0,0 @@
using PrecastConcretePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantContracts.ViewModels
{
public class ImplementerViewModel : IImplementerModel
{
public int Id { get; set; }
[DisplayName("ФИО исполнителя")]
public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("Пароль")]
public string Password { get; set; } = string.Empty;
[DisplayName("Стаж работы")]
public int WorkExperience { get; set; }
[DisplayName("Квалификация")]
public int Qualification { get; set; }
}
}

View File

@ -16,9 +16,6 @@ namespace PrecastConcretePlantContracts.ViewModels
public int ClientId { get; set; }
[DisplayName("Клиент")]
public string ClientFIO { get; set; } = string.Empty;
public int? ImplementerId { get; set; }
[DisplayName("ФИО исполнителя")]
public string? ImplementerFIO { get; set; } = string.Empty;
public int ReinforcedId { get; set; }
[DisplayName("ЖБИ")]
public string ReinforcedName { get; set; } = string.Empty;

View File

@ -1,116 +0,0 @@
using Microsoft.EntityFrameworkCore;
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.StoragesContracts;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantDatabaseImplement.Implements
{
public class ImplementerStorage : IImplementerStorage
{
public List<ImplementerViewModel> GetFullList()
{
using var context = new PrecastConcretePlantDatabase();
return context.Implementers
.Select(x => x.GetViewModel)
.ToList();
}
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
{
if (model == null)
{
return new();
}
if (model.Id.HasValue)
{
var implementer = GetElement(model);
return implementer != null ? new() { implementer } : new();
}
if (model.ImplementerFIO != null)
{
using var context = new PrecastConcretePlantDatabase();
return context.Implementers
.Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
{
using var context = new PrecastConcretePlantDatabase();
if (model.Id.HasValue)
return context.Implementers
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
if (model.ImplementerFIO != null && model.Password != null)
return context.Implementers
.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)
&& x.Password.Equals(model.Password))
?.GetViewModel;
if (model.ImplementerFIO != null)
return context.Implementers
.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
?.GetViewModel;
return null;
}
public ImplementerViewModel? Insert(ImplementerBindingModel model)
{
using var context = new PrecastConcretePlantDatabase();
var implementer = Implementer.Create(model);
if (implementer != null)
{
context.Implementers.Add(implementer);
context.SaveChanges();
}
return implementer?.GetViewModel;
}
public ImplementerViewModel? Update(ImplementerBindingModel model)
{
using var context = new PrecastConcretePlantDatabase();
var implementer = context.Implementers
.FirstOrDefault(x => x.Id == model.Id);
if (implementer != null)
{
implementer.Update(model);
context.SaveChanges();
}
return implementer?.GetViewModel;
}
public ImplementerViewModel? Delete(ImplementerBindingModel model)
{
using var context = new PrecastConcretePlantDatabase();
var implementer = context.Implementers
.FirstOrDefault(rec => rec.Id == model.Id);
if (implementer != null)
{
context.Implementers.Remove(implementer);
context.SaveChanges();
}
return implementer?.GetViewModel;
}
}
}

View File

@ -17,21 +17,19 @@ namespace PrecastConcretePlantDatabaseImplement.Implements
public OrderViewModel? Delete(OrderBindingModel model)
{
using var context = new PrecastConcretePlantDatabase();
var element = context.Orders
.Include(x => x.Reinforced)
.Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
var deletedElement = context.Orders
.Include(x => x.Reinforced)
.Include(x => x.Client)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
context.Orders.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
@ -41,103 +39,90 @@ namespace PrecastConcretePlantDatabaseImplement.Implements
{
return null;
}
using var context = new PrecastConcretePlantDatabase();
return context.Orders.Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x =>
(model.Statuses == null || model.Statuses != null && model.Statuses.Contains(x.Status)) &&
model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId ||
model.Id.HasValue && x.Id == model.Id
)?.GetViewModel;
return context.Orders.Include(x => x.Reinforced).Include(x => x.Client)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
?.GetViewModel;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
using var context = new PrecastConcretePlantDatabase();
if (model.Id.HasValue)
{
var result = GetElement(model);
return result != null ? new() { result } : new();
return context.Orders
.Include(x => x.Reinforced)
.Include(x => x.Client)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
using var context = new PrecastConcretePlantDatabase();
IQueryable<Order>? queryWhere = null;
if (model.DateFrom.HasValue && model.DateTo.HasValue)
else if (model.DateFrom != null && model.DateTo != null)
{
queryWhere = context.Orders
.Where(x => model.DateFrom <= x.DateCreate.Date &&
x.DateCreate.Date <= model.DateTo);
return context.Orders
.Include(x => x.Reinforced)
.Include(x => x.Client)
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
}
else if (model.Statuses != null)
{
queryWhere = context.Orders.Where(x => model.Statuses.Contains(x.Status));
}
else if (model.ClientId.HasValue)
{
queryWhere = context.Orders.Where(x => x.ClientId == model.ClientId);
return context.Orders
.Include(x => x.Reinforced)
.Include(x => x.Client)
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
else
{
return new();
}
return queryWhere
.Include(x => x.Client)
.Include(x => x.Implementer)
.Select(x => x.GetViewModel)
.ToList();
}
public List<OrderViewModel> GetFullList()
{
using var context = new PrecastConcretePlantDatabase();
return context.Orders
.Include(x => x.Reinforced)
.Include(x => x.Client)
.Include(x => x.Implementer)
.Select(x => x.GetViewModel).ToList();
.Select(x => x.GetViewModel)
.ToList();
}
public OrderViewModel? Insert(OrderBindingModel model)
{
var newOrder = Order.Create(model);
if (newOrder == null)
{
return null;
}
using var context = new PrecastConcretePlantDatabase();
context.Orders.Add(newOrder);
context.SaveChanges();
return newOrder.GetViewModel;
return context.Orders
.Include(x => x.Reinforced)
.Include(x => x.Client)
.FirstOrDefault(x => x.Id == newOrder.Id)
?.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
{
using var context = new PrecastConcretePlantDatabase();
var order = context.Orders
.Include(x => x.Reinforced)
.Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(x => x.Id == model.Id);
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
}
order.Update(model);
context.SaveChanges();
return order.GetViewModel;
return context.Orders
.Include(x => x.Reinforced)
.Include(x => x.Client)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
}
}
}

View File

@ -1,257 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using PrecastConcretePlantDatabaseImplement;
#nullable disable
namespace PrecastConcretePlantDatabaseImplement.Migrations
{
[DbContext(typeof(PrecastConcretePlantDatabase))]
[Migration("20230419193952_implementeradd")]
partial class implementeradd
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Implementer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ImplementerFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Qualification")
.HasColumnType("int");
b.Property<int>("WorkExperience")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Implementers");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int?>("ImplementerId")
.HasColumnType("int");
b.Property<int>("ReinforcedId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("ImplementerId");
b.HasIndex("ReinforcedId");
b.ToTable("Orders");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<double>("Price")
.HasColumnType("float");
b.Property<string>("ReinforcedName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Reinforceds");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("ReinforcedId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("ReinforcedId");
b.ToTable("ReinforcedComponents");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
{
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Client", "Client")
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Implementer", "Implementer")
.WithMany("Orders")
.HasForeignKey("ImplementerId");
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
.WithMany("Orders")
.HasForeignKey("ReinforcedId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Implementer");
b.Navigation("Reinforced");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b =>
{
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Component", "Component")
.WithMany("ReinforcedComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
.WithMany("Components")
.HasForeignKey("ReinforcedId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Reinforced");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Client", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
{
b.Navigation("ReinforcedComponents");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Implementer", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,67 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PrecastConcretePlantDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class implementeradd : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "ImplementerId",
table: "Orders",
type: "int",
nullable: true);
migrationBuilder.CreateTable(
name: "Implementers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ImplementerFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
WorkExperience = table.Column<int>(type: "int", nullable: false),
Qualification = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Implementers", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_Orders_ImplementerId",
table: "Orders",
column: "ImplementerId");
migrationBuilder.AddForeignKey(
name: "FK_Orders_Implementers_ImplementerId",
table: "Orders",
column: "ImplementerId",
principalTable: "Implementers",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Orders_Implementers_ImplementerId",
table: "Orders");
migrationBuilder.DropTable(
name: "Implementers");
migrationBuilder.DropIndex(
name: "IX_Orders_ImplementerId",
table: "Orders");
migrationBuilder.DropColumn(
name: "ImplementerId",
table: "Orders");
}
}
}

View File

@ -1,334 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using PrecastConcretePlantDatabaseImplement;
#nullable disable
namespace PrecastConcretePlantDatabaseImplement.Migrations
{
[DbContext(typeof(PrecastConcretePlantDatabase))]
[Migration("20230613193850_lab6h")]
partial class lab6h
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ComponentName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Cost")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Components");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Implementer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ImplementerFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Qualification")
.HasColumnType("int");
b.Property<int>("WorkExperience")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Implementers");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int?>("ImplementerId")
.HasColumnType("int");
b.Property<int>("ReinforcedId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("ImplementerId");
b.HasIndex("ReinforcedId");
b.ToTable("Orders");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<double>("Price")
.HasColumnType("float");
b.Property<string>("ReinforcedName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Reinforceds");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ComponentId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("ReinforcedId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("ReinforcedId");
b.ToTable("ReinforcedComponents");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ShopReinforced", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("ReinforcedId")
.HasColumnType("int");
b.Property<int>("ShopId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ReinforcedId");
b.HasIndex("ShopId");
b.ToTable("ShopReinforceds");
});
modelBuilder.Entity("Shop", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Capacity")
.HasColumnType("int");
b.Property<DateTime>("DateOpening")
.HasColumnType("datetime2");
b.Property<string>("ShopName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Shops");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
{
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Client", "Client")
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Implementer", "Implementer")
.WithMany("Orders")
.HasForeignKey("ImplementerId");
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
.WithMany("Orders")
.HasForeignKey("ReinforcedId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Implementer");
b.Navigation("Reinforced");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b =>
{
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Component", "Component")
.WithMany("ReinforcedComponents")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
.WithMany("Components")
.HasForeignKey("ReinforcedId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Reinforced");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ShopReinforced", b =>
{
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
.WithMany()
.HasForeignKey("ReinforcedId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Shop", "Shop")
.WithMany("Reinforceds")
.HasForeignKey("ShopId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Reinforced");
b.Navigation("Shop");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Client", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
{
b.Navigation("ReinforcedComponents");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Implementer", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
});
modelBuilder.Entity("Shop", b =>
{
b.Navigation("Reinforceds");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,22 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PrecastConcretePlantDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class lab6h : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

View File

@ -67,33 +67,6 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
b.ToTable("Components");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Implementer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ImplementerFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Qualification")
.HasColumnType("int");
b.Property<int>("WorkExperience")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Implementers");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
@ -114,9 +87,6 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int?>("ImplementerId")
.HasColumnType("int");
b.Property<int>("ReinforcedId")
.HasColumnType("int");
@ -130,8 +100,6 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
b.HasIndex("ClientId");
b.HasIndex("ImplementerId");
b.HasIndex("ReinforcedId");
b.ToTable("Orders");
@ -244,10 +212,6 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Implementer", "Implementer")
.WithMany("Orders")
.HasForeignKey("ImplementerId");
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
.WithMany("Orders")
.HasForeignKey("ReinforcedId")
@ -256,8 +220,6 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
b.Navigation("Client");
b.Navigation("Implementer");
b.Navigation("Reinforced");
});
@ -309,11 +271,6 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
b.Navigation("ReinforcedComponents");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Implementer", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b =>
{
b.Navigation("Components");

View File

@ -1,70 +0,0 @@
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantDatabaseImplement.Models
{
public class Implementer : IImplementerModel
{
public int Id { get; private set; }
[Required]
public string ImplementerFIO { get; private set; } = string.Empty;
[Required]
public string Password { get; private set; } = string.Empty;
[Required]
public int WorkExperience { get; private set; }
[Required]
public int Qualification { get; private set; }
[ForeignKey("ImplementerId")]
public virtual List<Order> Orders { get; set; } = new();
public static Implementer? Create(ImplementerBindingModel model)
{
if (model == null)
{
return null;
}
return new Implementer()
{
Id = model.Id,
ImplementerFIO = model.ImplementerFIO,
Password = model.Password,
WorkExperience = model.WorkExperience,
Qualification = model.Qualification,
};
}
public void Update(ImplementerBindingModel model)
{
if (model == null)
{
return;
}
ImplementerFIO = model.ImplementerFIO;
Password = model.Password;
WorkExperience = model.WorkExperience;
Qualification = model.Qualification;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
ImplementerFIO = ImplementerFIO,
Password = Password,
WorkExperience = WorkExperience,
Qualification = Qualification,
};
}
}

View File

@ -20,8 +20,6 @@ namespace PrecastConcretePlantDatabaseImplement.Models
public int ReinforcedId { get; private set; }
[Required]
public int Count { get; private set; }
public int? ImplementerId { get; set; }
[Required]
public double Sum { get; private set; }
[Required]
@ -31,8 +29,8 @@ namespace PrecastConcretePlantDatabaseImplement.Models
public DateTime? DateImplement { get; private set; }
public virtual Reinforced Reinforced { get; set; }
public virtual Client Client { get; set; }
public virtual Implementer? Implementer { get; set; }
public static Order? Create(OrderBindingModel? model)
public static Order? Create(OrderBindingModel model)
{
if (model == null)
{
@ -43,7 +41,6 @@ namespace PrecastConcretePlantDatabaseImplement.Models
Id = model.Id,
ClientId=model.ClientId,
ReinforcedId = model.ReinforcedId,
ImplementerId = model.ImplementerId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
@ -60,30 +57,20 @@ namespace PrecastConcretePlantDatabaseImplement.Models
}
Status = model.Status;
DateImplement = model.DateImplement;
ImplementerId = model.ImplementerId;
}
public OrderViewModel GetViewModel
public OrderViewModel GetViewModel => new()
{
get
{
using var context = new PrecastConcretePlantDatabase();
return new OrderViewModel
{
Id = Id,
ReinforcedId = ReinforcedId,
ClientId = ClientId,
ImplementerId = ImplementerId,
ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty,
ReinforcedName = context.Reinforceds.FirstOrDefault(x => x.Id == ReinforcedId)?.ReinforcedName ?? string.Empty,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty
};
}
}
Id = Id,
ClientId=ClientId,
ClientFIO=Client.ClientFIO,
ReinforcedId = ReinforcedId,
ReinforcedName = Reinforced.ReinforcedName,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
};
}
}

View File

@ -5,7 +5,6 @@ using PrecastConcretePlantDatabaseImplement.Models;
using PrecastConcretePlantDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Security.Cryptography.X509Certificates;
public class Shop : IShopModel
{
@ -28,10 +27,7 @@ public class Shop : IShopModel
{
if (_shopReinforceds == null)
{
using var context = new PrecastConcretePlantDatabase();
_shopReinforceds = Reinforceds
.ToDictionary(rec => rec.ReinforcedId, rec => (context.Reinforceds
.FirstOrDefault(rec1 => rec1.Id == rec.ReinforcedId)! as IReinforcedModel, rec.Count));
_shopReinforceds = Reinforceds.ToDictionary(rec => rec.ReinforcedId, rec => (rec.Reinforced as IReinforcedModel, rec.Count));
}
return _shopReinforceds;
}

View File

@ -24,7 +24,6 @@ namespace PrecastConcretePlantDatabaseImplement
public virtual DbSet<ReinforcedComponent> ReinforcedComponents { set; get; }
public virtual DbSet<Order> Orders { set; get; }
public virtual DbSet<Client> Clients { set; get; }
public virtual DbSet<Implementer> Implementers { set; get; }
public virtual DbSet<Shop> Shops { set; get; }
public virtual DbSet<ShopReinforced> ShopReinforceds { set; get; }
}

View File

@ -12,8 +12,7 @@ namespace PrecastConcretePlantDataModels.Enums
Принят = 0,
Выполняется = 1,
Готов = 2,
Выдан = 3,
Ожидание=4
Выдан = 3
}
}

View File

@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantDataModels.Models
{
public interface IImplementerModel : IId
{
string ImplementerFIO { get; }
string Password { get; }
int WorkExperience { get; }
int Qualification { get; }
}
}

View File

@ -11,7 +11,6 @@ namespace PrecastConcretePlantDataModels.Models
{
int ReinforcedId { get; }
int ClientId { get; }
int? ImplementerId { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }

View File

@ -14,7 +14,6 @@ namespace PrecastConcretePlantListImplement
public List<Order> Orders { get; set; }
public List<Reinforced> Reinforceds { get; set; }
public List<Client> Clients { get; set; }
public List<Implementer> Implementers { get; set; }
public List<Shop> Shops { get; set; }
private DataListSingleton()
{
@ -22,7 +21,6 @@ namespace PrecastConcretePlantListImplement
Orders = new List<Order>();
Reinforceds = new List<Reinforced>();
Clients = new List<Client>();
Implementers = new List<Implementer>();
Shops = new List<Shop>();
}
public static DataListSingleton GetInstance()

View File

@ -1,131 +0,0 @@
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.StoragesContracts;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantListImplement.Implements
{
public class ImplementerStorage : IImplementerStorage
{
private readonly DataListSingleton _source;
public ImplementerStorage()
{
_source = DataListSingleton.GetInstance();
}
public ImplementerViewModel? Delete(ImplementerBindingModel model)
{
for (int i = 0; i < _source.Implementers.Count; ++i)
{
if (_source.Implementers[i].Id == model.Id)
{
var element = _source.Implementers[i];
_source.Implementers.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
{
foreach (var x in _source.Implementers)
{
if (model.Id.HasValue && x.Id == model.Id)
return x.GetViewModel;
if (model.ImplementerFIO != null && model.Password != null &&
x.ImplementerFIO.Equals(model.ImplementerFIO) &&
x.Password.Equals(model.Password))
return x.GetViewModel;
if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO))
return x.GetViewModel;
}
return null;
}
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
{
if (model == null)
{
return new();
}
if (model.Id.HasValue)
{
var res = GetElement(model);
return res != null ? new() { res } : new();
}
List<ImplementerViewModel> result = new();
if (model.ImplementerFIO != null)
{
foreach (var implementer in _source.Implementers)
{
if (implementer.ImplementerFIO.Equals(model.ImplementerFIO))
{
result.Add(implementer.GetViewModel);
}
}
}
return result;
}
public List<ImplementerViewModel> GetFullList()
{
var result = new List<ImplementerViewModel>();
foreach (var implementer in _source.Implementers)
{
result.Add(implementer.GetViewModel);
}
return result;
}
public ImplementerViewModel? Insert(ImplementerBindingModel model)
{
model.Id = 1;
foreach (var implementer in _source.Implementers)
{
if (model.Id <= implementer.Id)
{
model.Id = implementer.Id + 1;
}
}
var res = Implementer.Create(model);
if (res != null)
{
_source.Implementers.Add(res);
}
return res?.GetViewModel;
}
public ImplementerViewModel? Update(ImplementerBindingModel model)
{
foreach (var implementer in _source.Implementers)
{
if (implementer.Id == model.Id)
{
implementer.Update(model);
return implementer.GetViewModel;
}
}
return null;
}
}
}

View File

@ -36,26 +36,19 @@ namespace PrecastConcretePlantListImplement.Implements
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (model.Id.HasValue)
if (!model.Id.HasValue)
{
foreach (var order in _source.Orders)
return null;
}
foreach (var order in _source.Orders)
{
if (model.Id.HasValue && order.Id == model.Id)
{
if (model.Id.HasValue && order.Id == model.Id)
{
return order.GetViewModel;
}
}
}
else if (model.ImplementerId.HasValue && model.Statuses!=null)
{
foreach (var order in _source.Orders)
{
if (model.ImplementerId == order.ImplementerId && model.Statuses.Contains(order.Status))
{
return order.GetViewModel;
}
return order.GetViewModel;
}
}
return null;
}
@ -76,15 +69,6 @@ namespace PrecastConcretePlantListImplement.Implements
{
result.Add(order.GetViewModel);
}
else if (model.ImplementerId.HasValue && order.ImplementerId == model.ImplementerId)
{
result.Add(order.GetViewModel);
}
else if (model.Statuses != null && model.Statuses.Contains(order.Status))
{
result.Add(order.GetViewModel);
}
}
}
else if (model.DateFrom != null && model.DateTo != null)

View File

@ -1,61 +0,0 @@
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrecastConcretePlantListImplement.Models
{
public class Implementer : IImplementerModel
{
public int Id { get; private set; }
public string ImplementerFIO { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty;
public int WorkExperience { get; private set; }
public int Qualification { get; private set; }
public static Implementer? Create(ImplementerBindingModel model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
Password = model.Password,
Qualification = model.Qualification,
ImplementerFIO = model.ImplementerFIO,
WorkExperience = model.WorkExperience,
};
}
public void Update(ImplementerBindingModel model)
{
if (model == null)
{
return;
}
Password = model.Password;
Qualification = model.Qualification;
ImplementerFIO = model.ImplementerFIO;
WorkExperience = model.WorkExperience;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
Password = Password,
Qualification = Qualification,
WorkExperience=WorkExperience,
ImplementerFIO = ImplementerFIO,
};
}
}

View File

@ -14,7 +14,6 @@ namespace PrecastConcretePlantListImplement.Models
{
public int ClientId { get; private set; }
public int ReinforcedId { get; private set; }
public int? ImplementerId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
@ -42,8 +41,7 @@ namespace PrecastConcretePlantListImplement.Models
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
ImplementerId = model.ImplementerId
DateImplement = model.DateImplement
};
}
@ -55,7 +53,6 @@ namespace PrecastConcretePlantListImplement.Models
}
Status = model.Status;
DateImplement = model.DateImplement;
ImplementerId = model.ImplementerId;
}
public OrderViewModel GetViewModel => new()
@ -67,7 +64,6 @@ namespace PrecastConcretePlantListImplement.Models
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
ImplementerId = ImplementerId,
DateImplement = DateImplement
};
}

View File

@ -1,104 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.BusinessLogicsContracts;
using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantDataModels.Enums;
namespace PrecastConcretePlantRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ImplementerController : Controller
{
private readonly ILogger _logger;
private readonly IOrderLogic _order;
private readonly IImplementerLogic _logic;
public ImplementerController(IOrderLogic order, IImplementerLogic logic, ILogger<ImplementerController> logger)
{
_logger = logger;
_order = order;
_logic = logic;
}
[HttpGet]
public ImplementerViewModel? Login(string login, string password)
{
try
{
return _logic.ReadElement(new ImplementerSearchModel
{
ImplementerFIO = login,
Password = password
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка авторизации сотрудника");
throw;
}
}
[HttpGet]
public List<OrderViewModel>? GetNewOrders()
{
try
{
return _order.ReadList(new OrderSearchModel
{
Statuses = new() { OrderStatus.Принят }
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения новых заказов");
throw;
}
}
[HttpGet]
public OrderViewModel? GetImplementerOrder(int implementerId)
{
try
{
return _order.ReadElement(new OrderSearchModel
{
ImplementerId = implementerId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения текущего заказа исполнителя");
throw;
}
}
[HttpPost]
public void TakeOrderInWork(OrderBindingModel model)
{
try
{
_order.TakeOrderInWork(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", model.Id);
throw;
}
}
[HttpPost]
public void FinishOrder(OrderBindingModel model)
{
try
{
_order.FinishOrder(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", model.Id);
throw;
}
}
}
}