From 913ea75594ce5cabcfdd8f46c29843d92b0a44db Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 29 Jan 2023 22:17:17 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D0=B0=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirm/FormCreateOrder.Designer.cs | 143 ++++++++++++++++++++ LawFirm/LawFirm/FormCreateOrder.cs | 142 +++++++++++++++++++ LawFirm/LawFirm/FormCreateOrder.resx | 60 ++++++++ LawFirm/LawFirm/Program.cs | 2 +- 4 files changed, 346 insertions(+), 1 deletion(-) create mode 100644 LawFirm/LawFirm/FormCreateOrder.Designer.cs create mode 100644 LawFirm/LawFirm/FormCreateOrder.cs create mode 100644 LawFirm/LawFirm/FormCreateOrder.resx diff --git a/LawFirm/LawFirm/FormCreateOrder.Designer.cs b/LawFirm/LawFirm/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..fdf911b --- /dev/null +++ b/LawFirm/LawFirm/FormCreateOrder.Designer.cs @@ -0,0 +1,143 @@ +namespace LawFirmView +{ + 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() + { + this.labelName = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelSum = new System.Windows.Forms.Label(); + this.comboBoxDocument = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(30, 20); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(79, 20); + this.labelName.TabIndex = 0; + this.labelName.Text = "Документ:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(30, 70); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(30, 119); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(58, 20); + this.labelSum.TabIndex = 2; + this.labelSum.Text = "Сумма:"; + // + // comboBoxDocument + // + this.comboBoxDocument.FormattingEnabled = true; + this.comboBoxDocument.Location = new System.Drawing.Point(171, 20); + this.comboBoxDocument.Name = "comboBoxDocument"; + this.comboBoxDocument.Size = new System.Drawing.Size(262, 28); + this.comboBoxDocument.TabIndex = 3; + this.comboBoxDocument.SelectedIndexChanged += new System.EventHandler(this.comboBoxDocument_SelectedIndexChanged); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(171, 67); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(262, 27); + this.textBoxCount.TabIndex = 4; + this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxCount_TextChanged); + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(171, 112); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.Size = new System.Drawing.Size(262, 27); + this.textBoxSum.TabIndex = 5; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(239, 164); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(339, 164); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(450, 212); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxDocument); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelName); + this.Name = "FormCreateOrder"; + this.Text = "Создание заказа"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private Label labelCount; + private Label labelSum; + private ComboBox comboBoxDocument; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirm/FormCreateOrder.cs b/LawFirm/LawFirm/FormCreateOrder.cs new file mode 100644 index 0000000..335e88b --- /dev/null +++ b/LawFirm/LawFirm/FormCreateOrder.cs @@ -0,0 +1,142 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; +using LawFirmContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace LawFirmView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IDocumentLogic _logicD; + private readonly IOrderLogic _logicO; + + public FormCreateOrder(ILogger logger, IDocumentLogic logicD, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicD = logicD; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка документов для заказа"); + // прописать логику + // + // + // !!!!!!!!!!!!!!!!!! + + // + // + // прописал, теперь проверить еще надо + // вдруг не работает + // скорее всего не работает + // нужно повышать самооценку + // может записаться на тренинг какой-нибудь + try + { + var list = _logicD.ReadList(null); + if (list != null) + { + comboBoxDocument.DisplayMember = "DocumentName"; + comboBoxDocument.ValueMember = "Id"; + comboBoxDocument.DataSource = list; + comboBoxDocument.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка документов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CalcSum() + { + if (comboBoxDocument.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxDocument.SelectedValue); + var product = _logicD.ReadElement(new DocumentSearchModel + { + 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 textBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void comboBoxDocument_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка",MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxDocument.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка",MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + DocumentId = Convert.ToInt32(comboBoxDocument.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 buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/LawFirm/LawFirm/FormCreateOrder.resx b/LawFirm/LawFirm/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LawFirm/LawFirm/FormCreateOrder.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/LawFirm/LawFirm/Program.cs b/LawFirm/LawFirm/Program.cs index 16a6567..7bf99f4 100644 --- a/LawFirm/LawFirm/Program.cs +++ b/LawFirm/LawFirm/Program.cs @@ -50,7 +50,7 @@ namespace LawFirm //services.AddTransient(); services.AddTransient(); services.AddTransient(); - //services.AddTransient(); + services.AddTransient(); } }