diff --git a/LawFirm/LawFirm/FormClients.Designer.cs b/LawFirm/LawFirm/FormClients.Designer.cs new file mode 100644 index 0000000..4493397 --- /dev/null +++ b/LawFirm/LawFirm/FormClients.Designer.cs @@ -0,0 +1,76 @@ +namespace LawFirmView +{ + partial class FormClients + { + /// + /// 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonDelete = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 55); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(610, 383); + this.dataGridView.TabIndex = 0; + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(352, 12); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(270, 29); + this.buttonDelete.TabIndex = 1; + this.buttonDelete.Text = "Удалить выбранного клиента"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click); + // + // FormClients + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(635, 450); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.dataGridView); + this.Name = "FormClients"; + this.Text = "Клиенты"; + this.Load += new System.EventHandler(this.FormClients_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonDelete; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirm/FormClients.cs b/LawFirm/LawFirm/FormClients.cs new file mode 100644 index 0000000..9baab71 --- /dev/null +++ b/LawFirm/LawFirm/FormClients.cs @@ -0,0 +1,80 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace LawFirmView +{ + public partial class FormClients : Form + { + private readonly ILogger _logger; + private readonly IClientLogic _logic; + public FormClients(ILogger logger, IClientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormClients_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка клиентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить клиента?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление клиента"); + try + { + if (!_logic.Delete(new ClientBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении клиента. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления клиента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + } +} diff --git a/LawFirm/LawFirm/FormClients.resx b/LawFirm/LawFirm/FormClients.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LawFirm/LawFirm/FormClients.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/FormCreateOrder.Designer.cs b/LawFirm/LawFirm/FormCreateOrder.Designer.cs index ef16dfb..ea177ce 100644 --- a/LawFirm/LawFirm/FormCreateOrder.Designer.cs +++ b/LawFirm/LawFirm/FormCreateOrder.Designer.cs @@ -36,6 +36,8 @@ this.textBoxSum = new System.Windows.Forms.TextBox(); this.buttonSave = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); + this.labelClient = new System.Windows.Forms.Label(); + this.comboBoxClient = new System.Windows.Forms.ComboBox(); this.SuspendLayout(); // // labelName @@ -50,7 +52,7 @@ // labelCount // this.labelCount.AutoSize = true; - this.labelCount.Location = new System.Drawing.Point(30, 70); + this.labelCount.Location = new System.Drawing.Point(30, 103); this.labelCount.Name = "labelCount"; this.labelCount.Size = new System.Drawing.Size(93, 20); this.labelCount.TabIndex = 1; @@ -59,7 +61,7 @@ // labelSum // this.labelSum.AutoSize = true; - this.labelSum.Location = new System.Drawing.Point(30, 119); + this.labelSum.Location = new System.Drawing.Point(30, 148); this.labelSum.Name = "labelSum"; this.labelSum.Size = new System.Drawing.Size(58, 20); this.labelSum.TabIndex = 2; @@ -76,7 +78,7 @@ // // textBoxCount // - this.textBoxCount.Location = new System.Drawing.Point(171, 67); + this.textBoxCount.Location = new System.Drawing.Point(171, 103); this.textBoxCount.Name = "textBoxCount"; this.textBoxCount.Size = new System.Drawing.Size(262, 27); this.textBoxCount.TabIndex = 4; @@ -84,14 +86,14 @@ // // textBoxSum // - this.textBoxSum.Location = new System.Drawing.Point(171, 112); + this.textBoxSum.Location = new System.Drawing.Point(171, 145); 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.Location = new System.Drawing.Point(244, 239); this.buttonSave.Name = "buttonSave"; this.buttonSave.Size = new System.Drawing.Size(94, 29); this.buttonSave.TabIndex = 6; @@ -101,7 +103,7 @@ // // buttonCancel // - this.buttonCancel.Location = new System.Drawing.Point(339, 164); + this.buttonCancel.Location = new System.Drawing.Point(344, 239); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(94, 29); this.buttonCancel.TabIndex = 7; @@ -109,11 +111,30 @@ this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); // + // labelClient + // + this.labelClient.AutoSize = true; + this.labelClient.Location = new System.Drawing.Point(30, 61); + this.labelClient.Name = "labelClient"; + this.labelClient.Size = new System.Drawing.Size(61, 20); + this.labelClient.TabIndex = 8; + this.labelClient.Text = "Клиент:"; + // + // comboBoxClient + // + this.comboBoxClient.FormattingEnabled = true; + this.comboBoxClient.Location = new System.Drawing.Point(171, 61); + this.comboBoxClient.Name = "comboBoxClient"; + this.comboBoxClient.Size = new System.Drawing.Size(262, 28); + this.comboBoxClient.TabIndex = 9; + // // 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.ClientSize = new System.Drawing.Size(450, 286); + this.Controls.Add(this.comboBoxClient); + this.Controls.Add(this.labelClient); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonSave); this.Controls.Add(this.textBoxSum); @@ -140,5 +161,7 @@ private TextBox textBoxSum; private Button buttonSave; private Button buttonCancel; + private Label labelClient; + private ComboBox comboBoxClient; } } \ No newline at end of file diff --git a/LawFirm/LawFirm/FormCreateOrder.cs b/LawFirm/LawFirm/FormCreateOrder.cs index d1c66e1..01b5666 100644 --- a/LawFirm/LawFirm/FormCreateOrder.cs +++ b/LawFirm/LawFirm/FormCreateOrder.cs @@ -20,13 +20,15 @@ namespace LawFirmView private readonly ILogger _logger; private readonly IDocumentLogic _logicD; private readonly IOrderLogic _logicO; + private readonly IClientLogic _logicC; - public FormCreateOrder(ILogger logger, IDocumentLogic logicD, IOrderLogic logicO) + public FormCreateOrder(ILogger logger, IDocumentLogic logicD, IOrderLogic logicO, IClientLogic logicC) { InitializeComponent(); _logger = logger; _logicD = logicD; _logicO = logicO; + _logicC = logicC; } private void FormCreateOrder_Load(object sender, EventArgs e) @@ -49,6 +51,25 @@ namespace LawFirmView _logger.LogError(ex, "Ошибка загрузки списка документов"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } + + _logger.LogInformation("Загрузка клиентов для заказа"); + try + { + var list = _logicC.ReadList(null); + if (list != null) + { + comboBoxClient.DisplayMember = "ClientFIO"; + comboBoxClient.ValueMember = "Id"; + comboBoxClient.DataSource = list; + comboBoxClient.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private void CalcSum() @@ -97,12 +118,18 @@ namespace LawFirmView MessageBox.Show("Выберите изделие", "Ошибка",MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + if (comboBoxClient.SelectedValue == null) + { + MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } _logger.LogInformation("Создание заказа"); try { var operationResult = _logicO.CreateOrder(new OrderBindingModel { DocumentId = Convert.ToInt32(comboBoxDocument.SelectedValue), + ClientId = Convert.ToInt32(comboBoxClient.SelectedValue), Count = Convert.ToInt32(textBoxCount.Text), Sum = Convert.ToDouble(textBoxSum.Text) }); diff --git a/LawFirm/LawFirm/FormMain.Designer.cs b/LawFirm/LawFirm/FormMain.Designer.cs index 1f1e25f..70c2693 100644 --- a/LawFirm/LawFirm/FormMain.Designer.cs +++ b/LawFirm/LawFirm/FormMain.Designer.cs @@ -42,6 +42,7 @@ this.buttonSetToDone = new System.Windows.Forms.Button(); this.buttonSetToFinish = new System.Windows.Forms.Button(); this.buttonUpdate = new System.Windows.Forms.Button(); + this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -62,7 +63,8 @@ // this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.бланкиToolStripMenuItem, - this.документыToolStripMenuItem}); + this.документыToolStripMenuItem, + this.клиентыToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -70,14 +72,14 @@ // бланкиToolStripMenuItem // this.бланкиToolStripMenuItem.Name = "бланкиToolStripMenuItem"; - this.бланкиToolStripMenuItem.Size = new System.Drawing.Size(170, 26); + this.бланкиToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.бланкиToolStripMenuItem.Text = "Бланки"; this.бланкиToolStripMenuItem.Click += new System.EventHandler(this.бланкиToolStripMenuItem_Click); // // документыToolStripMenuItem // this.документыToolStripMenuItem.Name = "документыToolStripMenuItem"; - this.документыToolStripMenuItem.Size = new System.Drawing.Size(170, 26); + this.документыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.документыToolStripMenuItem.Text = "Документы"; this.документыToolStripMenuItem.Click += new System.EventHandler(this.документыToolStripMenuItem_Click); // @@ -172,6 +174,13 @@ this.buttonUpdate.UseVisualStyleBackColor = true; this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); // + // клиентыToolStripMenuItem + // + this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.клиентыToolStripMenuItem.Text = "Клиенты"; + this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); @@ -212,5 +221,6 @@ private ToolStripMenuItem списокДокументовToolStripMenuItem; private ToolStripMenuItem бланкиПоДокументамToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; + private ToolStripMenuItem клиентыToolStripMenuItem; } } \ No newline at end of file diff --git a/LawFirm/LawFirm/FormMain.cs b/LawFirm/LawFirm/FormMain.cs index e2cf85a..91bff9a 100644 --- a/LawFirm/LawFirm/FormMain.cs +++ b/LawFirm/LawFirm/FormMain.cs @@ -44,6 +44,7 @@ namespace LawFirmView { dataGridView.DataSource = list; dataGridView.Columns["DocumentId"].Visible = false; + dataGridView.Columns["ClientId"].Visible = false; } _logger.LogInformation("Загрузка заказов"); } @@ -72,6 +73,15 @@ namespace LawFirmView } } + private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + if (service is FormClients form) + { + form.ShowDialog(); + } + } + private void бланкиПоДокументамToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormReportDocumentBlanks)); diff --git a/LawFirm/LawFirm/Program.cs b/LawFirm/LawFirm/Program.cs index 1b5ecce..1cd6118 100644 --- a/LawFirm/LawFirm/Program.cs +++ b/LawFirm/LawFirm/Program.cs @@ -43,11 +43,13 @@ namespace LawFirm services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -62,6 +64,7 @@ namespace LawFirm services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } diff --git a/LawFirm/LawFirmContracts/ViewModels/ClientViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/ClientViewModel.cs index 26b88ce..0175f67 100644 --- a/LawFirm/LawFirmContracts/ViewModels/ClientViewModel.cs +++ b/LawFirm/LawFirmContracts/ViewModels/ClientViewModel.cs @@ -13,7 +13,7 @@ namespace LawFirmContracts.ViewModels public int Id { get; set; } [DisplayName("ФИО клиента")] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Логин (эл. почта)")] + [DisplayName("Логин (почта)")] public string Email { get; set; } = string.Empty; [DisplayName("Пароль")] public string Password { get; set; } = string.Empty;