diff --git a/Typography/Typography.sln b/Typography/Typography.sln index b1ad27b..4851cdc 100644 --- a/Typography/Typography.sln +++ b/Typography/Typography.sln @@ -7,6 +7,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypographyView", "Typograph EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypographyDataModels", "TypographyDataModels\TypographyDataModels.csproj", "{26341B8F-7525-47AC-80FE-247A6E80B0FC}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypographyContracts", "TypographyContracts\TypographyContracts.csproj", "{A706678C-8F0C-4B84-8DF3-B98371E7EC40}" + ProjectSection(ProjectDependencies) = postProject + {26341B8F-7525-47AC-80FE-247A6E80B0FC} = {26341B8F-7525-47AC-80FE-247A6E80B0FC} + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypographyBusinessLogic", "TypographyBusinessLogic\TypographyBusinessLogic.csproj", "{98C01343-67A8-4133-AB89-352CEB4B55B1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypographyListImplement", "TypographyListImplement\TypographyListImplement.csproj", "{3580034D-775E-4332-9406-3A89BEFE8256}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +30,18 @@ Global {26341B8F-7525-47AC-80FE-247A6E80B0FC}.Debug|Any CPU.Build.0 = Debug|Any CPU {26341B8F-7525-47AC-80FE-247A6E80B0FC}.Release|Any CPU.ActiveCfg = Release|Any CPU {26341B8F-7525-47AC-80FE-247A6E80B0FC}.Release|Any CPU.Build.0 = Release|Any CPU + {A706678C-8F0C-4B84-8DF3-B98371E7EC40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A706678C-8F0C-4B84-8DF3-B98371E7EC40}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A706678C-8F0C-4B84-8DF3-B98371E7EC40}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A706678C-8F0C-4B84-8DF3-B98371E7EC40}.Release|Any CPU.Build.0 = Release|Any CPU + {98C01343-67A8-4133-AB89-352CEB4B55B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {98C01343-67A8-4133-AB89-352CEB4B55B1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {98C01343-67A8-4133-AB89-352CEB4B55B1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {98C01343-67A8-4133-AB89-352CEB4B55B1}.Release|Any CPU.Build.0 = Release|Any CPU + {3580034D-775E-4332-9406-3A89BEFE8256}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3580034D-775E-4332-9406-3A89BEFE8256}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3580034D-775E-4332-9406-3A89BEFE8256}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3580034D-775E-4332-9406-3A89BEFE8256}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Typography/Typography/FormComponent.Designer.cs b/Typography/Typography/FormComponent.Designer.cs new file mode 100644 index 0000000..3ed07c9 --- /dev/null +++ b/Typography/Typography/FormComponent.Designer.cs @@ -0,0 +1,117 @@ +namespace TypographyView +{ + partial class FormComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + labelName = new Label(); + labelCost = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // textBoxName + // + textBoxName.Location = new Point(118, 24); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(354, 27); + textBoxName.TabIndex = 0; + // + // textBoxCost + // + textBoxCost.Location = new Point(118, 76); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(354, 27); + textBoxCost.TabIndex = 1; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 27); + labelName.Name = "labelName"; + labelName.Size = new Size(77, 20); + labelName.TabIndex = 2; + labelName.Text = "Название"; + // + // labelCost + // + labelCost.AutoSize = true; + labelCost.Location = new Point(12, 79); + labelCost.Name = "labelCost"; + labelCost.Size = new Size(45, 20); + labelCost.TabIndex = 3; + labelCost.Text = "Цена"; + // + // buttonSave + // + buttonSave.Location = new Point(118, 132); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(378, 132); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(484, 189); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelCost); + Controls.Add(labelName); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Name = "FormComponent"; + Text = "Компонент"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxName; + private TextBox textBoxCost; + private Label labelName; + private Label labelCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Typography/Typography/FormComponent.cs b/Typography/Typography/FormComponent.cs new file mode 100644 index 0000000..dc6b30c --- /dev/null +++ b/Typography/Typography/FormComponent.cs @@ -0,0 +1,79 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace TypographyView +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение компонента"); + var view = _logic.ReadElement(new ComponentSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + 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(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + 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(); + } + } +} diff --git a/Typography/Typography/FormComponent.resx b/Typography/Typography/FormComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Typography/Typography/FormComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Typography/Typography/FormComponents.Designer.cs b/Typography/Typography/FormComponents.Designer.cs new file mode 100644 index 0000000..b090a4d --- /dev/null +++ b/Typography/Typography/FormComponents.Designer.cs @@ -0,0 +1,116 @@ +namespace TypographyView +{ + partial class FormComponents + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridViewComponents = new DataGridView(); + buttonAdd = new Button(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridViewComponents).BeginInit(); + SuspendLayout(); + // + // dataGridViewComponents + // + dataGridViewComponents.BackgroundColor = Color.White; + dataGridViewComponents.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewComponents.Location = new Point(0, 0); + dataGridViewComponents.Name = "dataGridViewComponents"; + dataGridViewComponents.RowHeadersVisible = false; + dataGridViewComponents.RowHeadersWidth = 51; + dataGridViewComponents.RowTemplate.Height = 29; + dataGridViewComponents.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewComponents.Size = new Size(655, 430); + dataGridViewComponents.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(681, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 29); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(681, 59); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(94, 29); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(681, 106); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(94, 29); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonRef + // + buttonRef.Location = new Point(681, 153); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(94, 29); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(804, 431); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridViewComponents); + Name = "FormComponents"; + Text = "Компоненты"; + ((System.ComponentModel.ISupportInitialize)dataGridViewComponents).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridViewComponents; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/Typography/Typography/FormComponents.cs b/Typography/Typography/FormComponents.cs new file mode 100644 index 0000000..6d31fe7 --- /dev/null +++ b/Typography/Typography/FormComponents.cs @@ -0,0 +1,96 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace TypographyView +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridViewComponents.DataSource = list; + dataGridViewComponents.Columns["Id"].Visible = false; + dataGridViewComponents.Columns["ComponentName"].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(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridViewComponents.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridViewComponents.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == + DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ComponentBindingModel { 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(); + } + } +} diff --git a/Typography/Typography/FormComponents.resx b/Typography/Typography/FormComponents.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Typography/Typography/FormComponents.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Typography/Typography/FormCreateOrder.Designer.cs b/Typography/Typography/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..ddd3e8c --- /dev/null +++ b/Typography/Typography/FormCreateOrder.Designer.cs @@ -0,0 +1,142 @@ +namespace TypographyView +{ + partial class FormCreateOrder + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelPrinted = new Label(); + labelCount = new Label(); + labelSum = new Label(); + comboBoxPrinted = new ComboBox(); + textBoxCount = new TextBox(); + textBoxSum = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelPrinted + // + labelPrinted.AutoSize = true; + labelPrinted.Location = new Point(28, 29); + labelPrinted.Name = "labelPrinted"; + labelPrinted.Size = new Size(154, 20); + labelPrinted.TabIndex = 0; + labelPrinted.Text = "Печатная продукция"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(28, 61); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(90, 20); + labelCount.TabIndex = 1; + labelCount.Text = "Количество"; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(28, 90); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(55, 20); + labelSum.TabIndex = 2; + labelSum.Text = "Сумма"; + // + // comboBoxPrinted + // + comboBoxPrinted.FormattingEnabled = true; + comboBoxPrinted.Location = new Point(188, 26); + comboBoxPrinted.Name = "comboBoxPrinted"; + comboBoxPrinted.Size = new Size(286, 28); + comboBoxPrinted.TabIndex = 3; + comboBoxPrinted.SelectedIndexChanged += comboBoxPrinted_SelectedIndexChanged; + // + // textBoxCount + // + textBoxCount.Location = new Point(188, 61); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(286, 27); + textBoxCount.TabIndex = 4; + textBoxCount.TextChanged += textBoxCount_TextChanged; + // + // textBoxSum + // + textBoxSum.Location = new Point(188, 94); + textBoxSum.Name = "textBoxSum"; + textBoxSum.Size = new Size(286, 27); + textBoxSum.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(188, 139); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(380, 139); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(486, 180); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxSum); + Controls.Add(textBoxCount); + Controls.Add(comboBoxPrinted); + Controls.Add(labelSum); + Controls.Add(labelCount); + Controls.Add(labelPrinted); + Name = "FormCreateOrder"; + Text = "Заказ"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelPrinted; + private Label labelCount; + private Label labelSum; + private ComboBox comboBoxPrinted; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Typography/Typography/FormCreateOrder.cs b/Typography/Typography/FormCreateOrder.cs new file mode 100644 index 0000000..5758927 --- /dev/null +++ b/Typography/Typography/FormCreateOrder.cs @@ -0,0 +1,103 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace TypographyView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IPrintedLogic _logicP; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, IPrintedLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + var _list = _logicP.ReadList(null); + if (_list != null) + { + comboBoxPrinted.DisplayMember = "PrintedName"; + comboBoxPrinted.ValueMember = "Id"; + comboBoxPrinted.DataSource = _list; + comboBoxPrinted.SelectedItem = null; + } + } + private void CalcSum() + { + if (comboBoxPrinted.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxPrinted.SelectedValue); + var product = _logicP.ReadElement(new PrintedSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + 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(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxPrinted.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + PrintedId = Convert.ToInt32(comboBoxPrinted.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + 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 comboBoxPrinted_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void textBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Typography/Typography/FormCreateOrder.resx b/Typography/Typography/FormCreateOrder.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Typography/Typography/FormCreateOrder.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Typography/Typography/FormMain.Designer.cs b/Typography/Typography/FormMain.Designer.cs new file mode 100644 index 0000000..7a0710e --- /dev/null +++ b/Typography/Typography/FormMain.Designer.cs @@ -0,0 +1,173 @@ +namespace TypographyView +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridViewOrders = new DataGridView(); + menuStrip1 = new MenuStrip(); + directoriesToolStripMenuItem = new ToolStripMenuItem(); + componentsToolStripMenuItem = new ToolStripMenuItem(); + printedsToolStripMenuItem = new ToolStripMenuItem(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridViewOrders).BeginInit(); + menuStrip1.SuspendLayout(); + SuspendLayout(); + // + // dataGridViewOrders + // + dataGridViewOrders.BackgroundColor = Color.White; + dataGridViewOrders.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewOrders.Location = new Point(0, 31); + dataGridViewOrders.Name = "dataGridViewOrders"; + dataGridViewOrders.RowHeadersVisible = false; + dataGridViewOrders.RowHeadersWidth = 51; + dataGridViewOrders.RowTemplate.Height = 29; + dataGridViewOrders.Size = new Size(1080, 424); + dataGridViewOrders.TabIndex = 3; + // + // menuStrip1 + // + menuStrip1.ImageScalingSize = new Size(20, 20); + menuStrip1.Items.AddRange(new ToolStripItem[] { directoriesToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(1331, 28); + menuStrip1.TabIndex = 4; + menuStrip1.Text = "menuStrip1"; + // + // directoriesToolStripMenuItem + // + directoriesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, printedsToolStripMenuItem }); + directoriesToolStripMenuItem.Name = "directoriesToolStripMenuItem"; + directoriesToolStripMenuItem.Size = new Size(117, 24); + directoriesToolStripMenuItem.Text = "Справочники"; + // + // componentsToolStripMenuItem + // + componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; + componentsToolStripMenuItem.Size = new Size(237, 26); + componentsToolStripMenuItem.Text = "Компоненты"; + componentsToolStripMenuItem.Click += componentsToolStripMenuItem_Click; + // + // printedsToolStripMenuItem + // + printedsToolStripMenuItem.Name = "printedsToolStripMenuItem"; + printedsToolStripMenuItem.Size = new Size(237, 26); + printedsToolStripMenuItem.Text = "Печатная продукция"; + printedsToolStripMenuItem.Click += printedsToolStripMenuItem_Click; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(1109, 42); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(195, 29); + buttonCreateOrder.TabIndex = 5; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += buttonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(1109, 96); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(195, 29); + buttonTakeOrderInWork.TabIndex = 6; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(1109, 149); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(195, 29); + buttonOrderReady.TabIndex = 7; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += buttonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(1109, 202); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(195, 29); + buttonIssuedOrder.TabIndex = 8; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += buttonIssuedOrder_Click; + // + // buttonRef + // + buttonRef.Location = new Point(1109, 255); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(195, 29); + buttonRef.TabIndex = 9; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1331, 453); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridViewOrders); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormMain"; + Text = "Типография"; + ((System.ComponentModel.ISupportInitialize)dataGridViewOrders).EndInit(); + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DataGridView dataGridViewOrders; + private MenuStrip menuStrip1; + private ToolStripMenuItem directoriesToolStripMenuItem; + private ToolStripMenuItem componentsToolStripMenuItem; + private ToolStripMenuItem printedsToolStripMenuItem; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/Typography/Typography/FormMain.cs b/Typography/Typography/FormMain.cs new file mode 100644 index 0000000..5c50ebe --- /dev/null +++ b/Typography/Typography/FormMain.cs @@ -0,0 +1,138 @@ +using TypographyDataModels.Enums; +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace TypographyView +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridViewOrders.DataSource = list; + dataGridViewOrders.Columns["PrintedId"].Visible = false; + dataGridViewOrders.Columns["PrintedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void componentsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void printedsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPrinteds)); + if (service is FormPrinteds form) + { + form.ShowDialog(); + } + } + private void buttonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void buttonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridViewOrders.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridViewOrders.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void buttonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridViewOrders.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridViewOrders.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void buttonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridViewOrders.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridViewOrders.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Typography/Typography/FormMain.resx b/Typography/Typography/FormMain.resx new file mode 100644 index 0000000..a0623c8 --- /dev/null +++ b/Typography/Typography/FormMain.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Typography/Typography/FormPrinted.Designer.cs b/Typography/Typography/FormPrinted.Designer.cs new file mode 100644 index 0000000..09c609b --- /dev/null +++ b/Typography/Typography/FormPrinted.Designer.cs @@ -0,0 +1,231 @@ +namespace TypographyView +{ + partial class FormPrinted + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + groupBoxComponents = new GroupBox(); + buttonRef = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridViewComponents = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnComponentName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + labelName = new Label(); + labelPrice = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewComponents).BeginInit(); + SuspendLayout(); + // + // groupBoxComponents + // + groupBoxComponents.Controls.Add(buttonRef); + groupBoxComponents.Controls.Add(buttonDel); + groupBoxComponents.Controls.Add(buttonUpd); + groupBoxComponents.Controls.Add(buttonAdd); + groupBoxComponents.Controls.Add(dataGridViewComponents); + groupBoxComponents.Location = new Point(12, 85); + groupBoxComponents.Name = "groupBoxComponents"; + groupBoxComponents.Size = new Size(790, 490); + groupBoxComponents.TabIndex = 0; + groupBoxComponents.TabStop = false; + groupBoxComponents.Text = "Компоненты"; + // + // buttonRef + // + buttonRef.Location = new Point(679, 131); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(94, 29); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // buttonDel + // + buttonDel.Location = new Point(679, 96); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(94, 29); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(679, 61); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(94, 29); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(679, 26); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 29); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridViewComponents + // + dataGridViewComponents.BackgroundColor = Color.White; + dataGridViewComponents.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewComponents.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnComponentName, ColumnCount }); + dataGridViewComponents.GridColor = Color.White; + dataGridViewComponents.Location = new Point(6, 26); + dataGridViewComponents.Name = "dataGridViewComponents"; + dataGridViewComponents.RowHeadersVisible = false; + dataGridViewComponents.RowHeadersWidth = 51; + dataGridViewComponents.RowTemplate.Height = 29; + dataGridViewComponents.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewComponents.Size = new Size(657, 461); + dataGridViewComponents.TabIndex = 0; + // + // ColumnId + // + ColumnId.HeaderText = "ID"; + ColumnId.MinimumWidth = 6; + ColumnId.Name = "ColumnId"; + ColumnId.Visible = false; + ColumnId.Width = 125; + // + // ColumnComponentName + // + ColumnComponentName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnComponentName.HeaderText = "Компонент"; + ColumnComponentName.MinimumWidth = 6; + ColumnComponentName.Name = "ColumnComponentName"; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.Width = 327; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(18, 19); + labelName.Name = "labelName"; + labelName.Size = new Size(77, 20); + labelName.TabIndex = 1; + labelName.Text = "Название"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(18, 52); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(83, 20); + labelPrice.TabIndex = 2; + labelPrice.Text = "Стоимость"; + // + // textBoxName + // + textBoxName.Location = new Point(143, 16); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(214, 27); + textBoxName.TabIndex = 3; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(143, 49); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(214, 27); + textBoxPrice.TabIndex = 4; + // + // buttonSave + // + buttonSave.Location = new Point(568, 581); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(691, 581); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormPrinted + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(814, 618); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Controls.Add(groupBoxComponents); + Name = "FormPrinted"; + Text = "FormPrinted"; + groupBoxComponents.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewComponents).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private GroupBox groupBoxComponents; + private DataGridView dataGridViewComponents; + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnComponentName; + private DataGridViewTextBoxColumn ColumnCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Typography/Typography/FormPrinted.cs b/Typography/Typography/FormPrinted.cs new file mode 100644 index 0000000..9921572 --- /dev/null +++ b/Typography/Typography/FormPrinted.cs @@ -0,0 +1,199 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.SearchModels; +using TypographyDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace TypographyView +{ + public partial class FormPrinted : Form + { + private readonly ILogger _logger; + private readonly IPrintedLogic _logic; + private int? _id; + private Dictionary _printedComponents; + public int Id { set { _id = value; } } + public FormPrinted(ILogger logger, IPrintedLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _printedComponents = new Dictionary(); + } + private void FormPrinted_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new PrintedSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.PrintedName; + textBoxPrice.Text = view.Price.ToString(); + _printedComponents = view.PrintedComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_printedComponents != null) + { + dataGridViewComponents.Rows.Clear(); + foreach (var pc in _printedComponents) + { + dataGridViewComponents.Rows.Add(new object[] { pc.Key, + pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private double CalcPrice() + { + double price = 0; + foreach (var elem in _printedComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPrintedComponent)); + if (service is FormPrintedComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", + form.ComponentModel.ComponentName, form.Count); + if (_printedComponents.ContainsKey(form.Id)) + { + _printedComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _printedComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + } + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridViewComponents.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPrintedComponent)); + if (service is FormPrintedComponent form) + { + int id = Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _printedComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", + form.ComponentModel.ComponentName, form.Count); + _printedComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridViewComponents.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == + DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", + dataGridViewComponents.SelectedRows[0].Cells[1].Value); + _printedComponents?.Remove(Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_printedComponents == null || _printedComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new PrintedBindingModel + { + Id = _id ?? 0, + PrintedName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + PrintedComponents = _printedComponents + }; + 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(); + } + } +} diff --git a/Typography/Typography/FormPrinted.resx b/Typography/Typography/FormPrinted.resx new file mode 100644 index 0000000..552902d --- /dev/null +++ b/Typography/Typography/FormPrinted.resx @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/Typography/Typography/FormPrintedComponent.Designer.cs b/Typography/Typography/FormPrintedComponent.Designer.cs new file mode 100644 index 0000000..34f6189 --- /dev/null +++ b/Typography/Typography/FormPrintedComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace TypographyView +{ + partial class FormPrintedComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelComponent = new Label(); + labelCount = new Label(); + comboBoxComponent = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(12, 18); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(88, 20); + labelComponent.TabIndex = 0; + labelComponent.Text = "Компонент"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 63); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(90, 20); + labelCount.TabIndex = 1; + labelCount.Text = "Количество"; + // + // comboBoxComponent + // + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(133, 15); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(301, 28); + comboBoxComponent.TabIndex = 2; + // + // textBoxCount + // + textBoxCount.Location = new Point(133, 56); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(301, 27); + textBoxCount.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(211, 108); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(340, 108); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormPrintedComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(468, 163); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Name = "FormPrintedComponent"; + Text = "Компонент печатной продукции"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelComponent; + private Label labelCount; + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Typography/Typography/FormPrintedComponent.cs b/Typography/Typography/FormPrintedComponent.cs new file mode 100644 index 0000000..4748bb6 --- /dev/null +++ b/Typography/Typography/FormPrintedComponent.cs @@ -0,0 +1,71 @@ +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.ViewModels; +using TypographyDataModels.Models; + +namespace TypographyView +{ + public partial class FormPrintedComponent : Form + { + private readonly List? _list; + public int Id + { + get { return Convert.ToInt32(comboBoxComponent.SelectedValue); } + set { comboBoxComponent.SelectedValue = value; } + } + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set { textBoxCount.Text = value.ToString(); } + } + public FormPrintedComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Typography/Typography/FormPrintedComponent.resx b/Typography/Typography/FormPrintedComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Typography/Typography/FormPrintedComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Typography/Typography/FormPrinteds.Designer.cs b/Typography/Typography/FormPrinteds.Designer.cs new file mode 100644 index 0000000..15d9741 --- /dev/null +++ b/Typography/Typography/FormPrinteds.Designer.cs @@ -0,0 +1,116 @@ +namespace TypographyView +{ + partial class FormPrinteds + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridViewPrinteds = new DataGridView(); + buttonAdd = new Button(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridViewPrinteds).BeginInit(); + SuspendLayout(); + // + // dataGridViewPrinteds + // + dataGridViewPrinteds.BackgroundColor = Color.White; + dataGridViewPrinteds.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewPrinteds.Location = new Point(1, 1); + dataGridViewPrinteds.Name = "dataGridViewPrinteds"; + dataGridViewPrinteds.RowHeadersVisible = false; + dataGridViewPrinteds.RowHeadersWidth = 51; + dataGridViewPrinteds.RowTemplate.Height = 29; + dataGridViewPrinteds.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewPrinteds.Size = new Size(648, 450); + dataGridViewPrinteds.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(675, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 29); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(675, 47); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(94, 29); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(675, 82); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(94, 29); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonRef + // + buttonRef.Location = new Point(675, 117); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(94, 29); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // FormPrinteds + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridViewPrinteds); + Name = "FormPrinteds"; + Text = "Печатная продукция"; + ((System.ComponentModel.ISupportInitialize)dataGridViewPrinteds).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridViewPrinteds; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/Typography/Typography/FormPrinteds.cs b/Typography/Typography/FormPrinteds.cs new file mode 100644 index 0000000..155262c --- /dev/null +++ b/Typography/Typography/FormPrinteds.cs @@ -0,0 +1,98 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace TypographyView +{ + public partial class FormPrinteds : Form + { + private readonly ILogger _logger; + private readonly IPrintedLogic _logic; + + public FormPrinteds(ILogger logger, IPrintedLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormPrinteds_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridViewPrinteds.DataSource = list; + dataGridViewPrinteds.Columns["Id"].Visible = false; + dataGridViewPrinteds.Columns["PrintedComponents"].Visible = false; + dataGridViewPrinteds.Columns["PrintedName"].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(FormPrinted)); + if (service is FormPrinted form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridViewPrinteds.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPrinted)); + if (service is FormPrinted form) + { + form.Id = Convert.ToInt32(dataGridViewPrinteds.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridViewPrinteds.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == + DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridViewPrinteds.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new PrintedBindingModel { 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(); + } + } +} diff --git a/Typography/Typography/FormPrinteds.resx b/Typography/Typography/FormPrinteds.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Typography/Typography/FormPrinteds.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Typography/Typography/Program.cs b/Typography/Typography/Program.cs index 16c105f..16ddba9 100644 --- a/Typography/Typography/Program.cs +++ b/Typography/Typography/Program.cs @@ -1,7 +1,19 @@ -namespace Typography +using TypographyBusinessLogic.BusinessLogics; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.StoragesContracts; +using TypographyListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using System; + +namespace TypographyView { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// /// The main entry point for the application. /// @@ -11,7 +23,31 @@ namespace Typography // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/Typography/Typography/TypographyView.csproj b/Typography/Typography/TypographyView.csproj index b57c89e..6906947 100644 --- a/Typography/Typography/TypographyView.csproj +++ b/Typography/Typography/TypographyView.csproj @@ -8,4 +8,16 @@ enable + + + + + + + + + + + + \ No newline at end of file diff --git a/Typography/Typography/nlog.config b/Typography/Typography/nlog.config new file mode 100644 index 0000000..6b2ff40 --- /dev/null +++ b/Typography/Typography/nlog.config @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Typography/TypographyBusinessLogic/BusinessLogics/ComponentLogic.cs b/Typography/TypographyBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..fa07e94 --- /dev/null +++ b/Typography/TypographyBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,105 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace TypographyBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName: {ComponentName}. Id:{Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName: {ComponentName}. Id: {Id}", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName: {ComponentName}. Cost: {Cost}. Id: {Id}", + model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel { ComponentName = model.ComponentName }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/Typography/TypographyBusinessLogic/BusinessLogics/OrderLogic.cs b/Typography/TypographyBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..e16e12c --- /dev/null +++ b/Typography/TypographyBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,105 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; +using Microsoft.Extensions.Logging; +using TypographyDataModels.Enums; + +namespace TypographyBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Order status change failed"); + return false; + } + model.Status = OrderStatus.Принят; + + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Order creation failed"); + return false; + } + return true; + } + public bool TakeOrderInWork(OrderBindingModel model) + { + return ChangeOrderStatus(model, OrderStatus.Выполняется); + } + public bool FinishOrder(OrderBindingModel model) + { + return ChangeOrderStatus(model, OrderStatus.Готов); + } + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeOrderStatus(model, OrderStatus.Выдан); + } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Кол-во печатных изделий в заказе должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. Count: {Count}. Sum: {Sum} Id: {Id}", model.Count, model.Sum, model.Id); + } + private bool ChangeOrderStatus(OrderBindingModel model, OrderStatus newStatus) + { + CheckModel(model, false); + var orderView = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + + if (orderView == null || newStatus - orderView.Status != 1) + { + _logger.LogWarning("Order status change failed"); + return false; + } + model.Status = newStatus; + if (newStatus == OrderStatus.Выдан) + { + model.DateImplement = DateTime.Now; + } + + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Order status change failed"); + return false; + } + return true; + } + } +} \ No newline at end of file diff --git a/Typography/TypographyBusinessLogic/BusinessLogics/PrintedLogic.cs b/Typography/TypographyBusinessLogic/BusinessLogics/PrintedLogic.cs new file mode 100644 index 0000000..e779a4a --- /dev/null +++ b/Typography/TypographyBusinessLogic/BusinessLogics/PrintedLogic.cs @@ -0,0 +1,105 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace TypographyBusinessLogic.BusinessLogics +{ + public class PrintedLogic : IPrintedLogic + { + private readonly ILogger _logger; + private readonly IPrintedStorage _printedStorage; + public PrintedLogic(ILogger logger, IPrintedStorage printedStorage) + { + _logger = logger; + _printedStorage = printedStorage; + } + public List? ReadList(PrintedSearchModel? model) + { + _logger.LogInformation("ReadList. PrintedName: {PrintedName}. Id:{Id}", model?.PrintedName, model?.Id); + var list = model == null ? _printedStorage.GetFullList() : _printedStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + public PrintedViewModel? ReadElement(PrintedSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. PrintedName: {PrintedName}. Id: {Id}", model.PrintedName, model.Id); + var element = _printedStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + public bool Create(PrintedBindingModel model) + { + CheckModel(model); + if (_printedStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(PrintedBindingModel model) + { + CheckModel(model); + if (_printedStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(PrintedBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_printedStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(PrintedBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.PrintedName)) + { + throw new ArgumentNullException("Нет названия печатного изделия", nameof(model.PrintedName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена печатного изделия должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Printed. PrintedName: {PrintedName}. Price: {Price}. Id: {Id}", + model.PrintedName, model.Price, model.Id); + var element = _printedStorage.GetElement(new PrintedSearchModel { PrintedName = model.PrintedName }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Печатное изделие с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/Typography/TypographyBusinessLogic/TypographyBusinessLogic.csproj b/Typography/TypographyBusinessLogic/TypographyBusinessLogic.csproj new file mode 100644 index 0000000..15ec9e0 --- /dev/null +++ b/Typography/TypographyBusinessLogic/TypographyBusinessLogic.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/Typography/TypographyContracts/BindingModels/ComponentBindingModel.cs b/Typography/TypographyContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..d1ec2ca --- /dev/null +++ b/Typography/TypographyContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,11 @@ +using TypographyDataModels.Models; + +namespace TypographyContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/BindingModels/OrderBindingModel.cs b/Typography/TypographyContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..4d492f1 --- /dev/null +++ b/Typography/TypographyContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,16 @@ +using TypographyDataModels.Models; +using TypographyDataModels.Enums; + +namespace TypographyContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int PrintedId { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/BindingModels/PrintedBindingModel.cs b/Typography/TypographyContracts/BindingModels/PrintedBindingModel.cs new file mode 100644 index 0000000..bd331ca --- /dev/null +++ b/Typography/TypographyContracts/BindingModels/PrintedBindingModel.cs @@ -0,0 +1,12 @@ +using TypographyDataModels.Models; + +namespace TypographyContracts.BindingModels +{ + public class PrintedBindingModel : IPrintedModel + { + public int Id { get; set; } + public string PrintedName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary PrintedComponents { get; set; } = new(); + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/BusinessLogicsContracts/IComponentLogic.cs b/Typography/TypographyContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..18cf6e3 --- /dev/null +++ b/Typography/TypographyContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,15 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.ViewModels; + +namespace TypographyContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/BusinessLogicsContracts/IOrderLogic.cs b/Typography/TypographyContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..60c0caf --- /dev/null +++ b/Typography/TypographyContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,15 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.ViewModels; + +namespace TypographyContracts.BusinessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/BusinessLogicsContracts/IPrintedLogic.cs b/Typography/TypographyContracts/BusinessLogicsContracts/IPrintedLogic.cs new file mode 100644 index 0000000..11e6b4c --- /dev/null +++ b/Typography/TypographyContracts/BusinessLogicsContracts/IPrintedLogic.cs @@ -0,0 +1,15 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.ViewModels; + +namespace TypographyContracts.BusinessLogicsContracts +{ + public interface IPrintedLogic + { + List? ReadList(PrintedSearchModel? model); + PrintedViewModel? ReadElement(PrintedSearchModel model); + bool Create(PrintedBindingModel model); + bool Update(PrintedBindingModel model); + bool Delete(PrintedBindingModel model); + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/SearchModels/ComponentSearchModel.cs b/Typography/TypographyContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..7373f15 --- /dev/null +++ b/Typography/TypographyContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,8 @@ +namespace TypographyContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/SearchModels/OrderSearchModel.cs b/Typography/TypographyContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..3e14de6 --- /dev/null +++ b/Typography/TypographyContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,7 @@ +namespace TypographyContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/SearchModels/PrintedSearchModel.cs b/Typography/TypographyContracts/SearchModels/PrintedSearchModel.cs new file mode 100644 index 0000000..9ed15ad --- /dev/null +++ b/Typography/TypographyContracts/SearchModels/PrintedSearchModel.cs @@ -0,0 +1,8 @@ +namespace TypographyContracts.SearchModels +{ + public class PrintedSearchModel + { + public int? Id { get; set; } + public string? PrintedName { get; set; } + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/StoragesContracts/IComponentStorage.cs b/Typography/TypographyContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..2bdde29 --- /dev/null +++ b/Typography/TypographyContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,16 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.ViewModels; + +namespace TypographyContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/StoragesContracts/IOrderStorage.cs b/Typography/TypographyContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..d54583b --- /dev/null +++ b/Typography/TypographyContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,16 @@ +using TypographyContracts.ViewModels; +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; + +namespace TypographyContracts.StoragesContracts +{ + public interface IOrderStorage + { + List GetFullList(); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/StoragesContracts/IPrintedStorage.cs b/Typography/TypographyContracts/StoragesContracts/IPrintedStorage.cs new file mode 100644 index 0000000..a3b3c6e --- /dev/null +++ b/Typography/TypographyContracts/StoragesContracts/IPrintedStorage.cs @@ -0,0 +1,16 @@ +using TypographyContracts.ViewModels; +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; + +namespace TypographyContracts.StoragesContracts +{ + public interface IPrintedStorage + { + List GetFullList(); + List GetFilteredList(PrintedSearchModel model); + PrintedViewModel? GetElement(PrintedSearchModel model); + PrintedViewModel? Insert(PrintedBindingModel model); + PrintedViewModel? Update(PrintedBindingModel model); + PrintedViewModel? Delete(PrintedBindingModel model); + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/TypographyContracts.csproj b/Typography/TypographyContracts/TypographyContracts.csproj new file mode 100644 index 0000000..1e83ad8 --- /dev/null +++ b/Typography/TypographyContracts/TypographyContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Typography/TypographyContracts/ViewModels/ComponentViewModel.cs b/Typography/TypographyContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..41c5070 --- /dev/null +++ b/Typography/TypographyContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,16 @@ +using System.ComponentModel; +using TypographyDataModels.Models; + +namespace TypographyContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Cost { get; set; } + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/ViewModels/OrderViewModel.cs b/Typography/TypographyContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..69e43fc --- /dev/null +++ b/Typography/TypographyContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,32 @@ +using System.ComponentModel; +using TypographyDataModels.Enums; +using TypographyDataModels.Models; + +namespace TypographyContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + + public int PrintedId { get; set; } + + [DisplayName("Изделие")] + public string PrintedName { get; set; } = string.Empty; + + [DisplayName("Количество")] + public int Count { get; set; } + + [DisplayName("Сумма")] + public double Sum { get; set; } + + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } +} \ No newline at end of file diff --git a/Typography/TypographyContracts/ViewModels/PrintedViewModel.cs b/Typography/TypographyContracts/ViewModels/PrintedViewModel.cs new file mode 100644 index 0000000..bee3caa --- /dev/null +++ b/Typography/TypographyContracts/ViewModels/PrintedViewModel.cs @@ -0,0 +1,17 @@ +using System.ComponentModel; +using TypographyDataModels.Models; + +namespace TypographyContracts.ViewModels +{ + public class PrintedViewModel : IPrintedModel + { + public int Id { get; set; } + + [DisplayName("Название изделия")] + public string PrintedName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary PrintedComponents { get; set; } = new(); + } +} \ No newline at end of file diff --git a/Typography/TypographyDataModels/Models/IComponentModel.cs b/Typography/TypographyDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..5bf6b08 --- /dev/null +++ b/Typography/TypographyDataModels/Models/IComponentModel.cs @@ -0,0 +1,8 @@ +namespace TypographyDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} \ No newline at end of file diff --git a/Typography/TypographyDataModels/Models/IOrderModel.cs b/Typography/TypographyDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..6e54659 --- /dev/null +++ b/Typography/TypographyDataModels/Models/IOrderModel.cs @@ -0,0 +1,14 @@ +using TypographyDataModels.Enums; + +namespace TypographyDataModels.Models +{ + public interface IOrderModel : IId + { + int PrintedId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} \ No newline at end of file diff --git a/Typography/TypographyDataModels/Models/IPrintedModel.cs b/Typography/TypographyDataModels/Models/IPrintedModel.cs new file mode 100644 index 0000000..c6a7d68 --- /dev/null +++ b/Typography/TypographyDataModels/Models/IPrintedModel.cs @@ -0,0 +1,9 @@ +namespace TypographyDataModels.Models +{ + public interface IPrintedModel : IId + { + string PrintedName { get; } + double Price { get; } + Dictionary PrintedComponents { get; } + } +} \ No newline at end of file diff --git a/Typography/TypographyDataModels/TypographyDataModels.csproj b/Typography/TypographyDataModels/TypographyDataModels.csproj index c68ed43..132c02c 100644 --- a/Typography/TypographyDataModels/TypographyDataModels.csproj +++ b/Typography/TypographyDataModels/TypographyDataModels.csproj @@ -6,8 +6,4 @@ enable - - - - diff --git a/Typography/TypographyListImplement/DataListSingleton.cs b/Typography/TypographyListImplement/DataListSingleton.cs new file mode 100644 index 0000000..160ab2d --- /dev/null +++ b/Typography/TypographyListImplement/DataListSingleton.cs @@ -0,0 +1,26 @@ +using TypographyListImplement.Models; + +namespace TypographyListImplement +{ + internal class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Printeds { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Printeds = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} \ No newline at end of file diff --git a/Typography/TypographyListImplement/Implements/ComponentStorage.cs b/Typography/TypographyListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..fec7598 --- /dev/null +++ b/Typography/TypographyListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,102 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; +using TypographyListImplement.Models; + +namespace TypographyListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/Typography/TypographyListImplement/Implements/OrderStorage.cs b/Typography/TypographyListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..704bfc4 --- /dev/null +++ b/Typography/TypographyListImplement/Implements/OrderStorage.cs @@ -0,0 +1,113 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; +using TypographyListImplement.Models; + +namespace TypographyListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(DefinePrintedName(order)); + } + return result; + } + private OrderViewModel DefinePrintedName(Order model) + { + OrderViewModel result = model.GetViewModel; + foreach (var order in _source.Printeds) + { + if (result.PrintedId == order.Id) + { + result.PrintedName = order.PrintedName; + break; + } + } + return result; + } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (model.Id == null) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(DefinePrintedName(order)); + } + } + return result; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return DefinePrintedName(order); + } + } + return null; + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return DefinePrintedName(newOrder); + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return DefinePrintedName(order); + } + } + return null; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return DefinePrintedName(element); + } + } + return null; + } + } +} \ No newline at end of file diff --git a/Typography/TypographyListImplement/Implements/PrintedStorage.cs b/Typography/TypographyListImplement/Implements/PrintedStorage.cs new file mode 100644 index 0000000..3f43737 --- /dev/null +++ b/Typography/TypographyListImplement/Implements/PrintedStorage.cs @@ -0,0 +1,101 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; +using TypographyListImplement.Models; + +namespace TypographyListImplement.Implements +{ + public class PrintedStorage : IPrintedStorage + { + private readonly DataListSingleton _source; + public PrintedStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var printed in _source.Printeds) + { + result.Add(printed.GetViewModel); + } + return result; + } + public List GetFilteredList(PrintedSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.PrintedName)) + { + return result; + } + foreach (var printed in _source.Printeds) + { + if (printed.PrintedName.Contains(model.PrintedName)) + { + result.Add(printed.GetViewModel); + } + } + return result; + } + public PrintedViewModel? GetElement(PrintedSearchModel model) + { + if (string.IsNullOrEmpty(model.PrintedName) && !model.Id.HasValue) + { + return null; + } + foreach (var printed in _source.Printeds) + { + if ((!string.IsNullOrEmpty(model.PrintedName) && printed.PrintedName == model.PrintedName) || + (model.Id.HasValue && printed.Id == model.Id)) + { + return printed.GetViewModel; + } + } + return null; + } + public PrintedViewModel? Insert(PrintedBindingModel model) + { + model.Id = 1; + foreach (var printed in _source.Printeds) + { + if (model.Id <= printed.Id) + { + model.Id = printed.Id + 1; + } + } + var newPrinted = Printed.Create(model); + if (newPrinted == null) + { + return null; + } + _source.Printeds.Add(newPrinted); + return newPrinted.GetViewModel; + } + public PrintedViewModel? Update(PrintedBindingModel model) + { + foreach (var printed in _source.Printeds) + { + if (printed.Id == model.Id) + { + printed.Update(model); + return printed.GetViewModel; + } + } + return null; + } + public PrintedViewModel? Delete(PrintedBindingModel model) + { + for (int i = 0; i < _source.Printeds.Count; ++i) + { + if (_source.Printeds[i].Id == model.Id) + { + var element = _source.Printeds[i]; + _source.Printeds.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/Typography/TypographyListImplement/Models/Component.cs b/Typography/TypographyListImplement/Models/Component.cs new file mode 100644 index 0000000..3e50608 --- /dev/null +++ b/Typography/TypographyListImplement/Models/Component.cs @@ -0,0 +1,41 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.ViewModels; +using TypographyDataModels.Models; + +namespace TypographyListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} \ No newline at end of file diff --git a/Typography/TypographyListImplement/Models/Order.cs b/Typography/TypographyListImplement/Models/Order.cs new file mode 100644 index 0000000..80cda52 --- /dev/null +++ b/Typography/TypographyListImplement/Models/Order.cs @@ -0,0 +1,54 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.ViewModels; +using TypographyDataModels.Enums; +using TypographyDataModels.Models; + +namespace TypographyListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int PrintedId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + PrintedId = model.PrintedId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + PrintedId = PrintedId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} \ No newline at end of file diff --git a/Typography/TypographyListImplement/Models/Printed.cs b/Typography/TypographyListImplement/Models/Printed.cs new file mode 100644 index 0000000..79a5ca8 --- /dev/null +++ b/Typography/TypographyListImplement/Models/Printed.cs @@ -0,0 +1,45 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.ViewModels; +using TypographyDataModels.Models; + +namespace TypographyListImplement.Models +{ + public class Printed : IPrintedModel + { + public int Id { get; private set; } + public string PrintedName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary PrintedComponents { get; private set; } = new(); + public static Printed? Create(PrintedBindingModel? model) + { + if (model == null) + { + return null; + } + return new Printed() + { + Id = model.Id, + PrintedName = model.PrintedName, + Price = model.Price, + PrintedComponents = model.PrintedComponents + }; + } + public void Update(PrintedBindingModel? model) + { + if (model == null) + { + return; + } + PrintedName = model.PrintedName; + Price = model.Price; + PrintedComponents = model.PrintedComponents; + } + public PrintedViewModel GetViewModel => new() + { + Id = Id, + PrintedName = PrintedName, + Price = Price, + PrintedComponents = PrintedComponents + }; + } +} \ No newline at end of file diff --git a/Typography/TypographyListImplement/TypographyListImplement.csproj b/Typography/TypographyListImplement/TypographyListImplement.csproj new file mode 100644 index 0000000..db73c6b --- /dev/null +++ b/Typography/TypographyListImplement/TypographyListImplement.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + +