Мы сидим у разбитых корыт

И гадаем на розе ветров
А, когда приходит время вставать
Мы сидим, мы ждём
Играй
Невесёлая песня моя
(Почти готово, осталось с таблицей и диаграммой разобраться. Я на ушел на передышку)
This commit is contained in:
Никита Волков 2024-10-28 23:29:48 +04:00
parent 0bf36059e1
commit 36513dcb02
11 changed files with 666 additions and 103 deletions

View File

@ -28,12 +28,146 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "FormMain";
components = new System.ComponentModel.Container();
menuStrip = new MenuStrip();
заказыToolStripMenuItem = new ToolStripMenuItem();
создатьToolStripMenuItem = new ToolStripMenuItem();
редактироватьToolStripMenuItem = new ToolStripMenuItem();
удалитьToolStripMenuItem = new ToolStripMenuItem();
отчётыToolStripMenuItem = new ToolStripMenuItem();
документToolStripMenuItem = new ToolStripMenuItem();
документСТаблицейToolStripMenuItem = new ToolStripMenuItem();
документСДиаграммойToolStripMenuItem = new ToolStripMenuItem();
выбранныеТоварыToolStripMenuItem = new ToolStripMenuItem();
controlDataTable = new ControlsLibraryNet60.Data.ControlDataTableTable();
excelImagesComponent = new WinFormsLibraryVolkov.NonVisualComponents.ExcelImagesComponent(components);
componentHistogramToPdf = new FormLibrary.ComponentHistogramToPdf(components);
componentDocumentWithTableMultiHeaderWord = new ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableMultiHeaderWord(components);
menuStrip.SuspendLayout();
SuspendLayout();
//
// menuStrip
//
menuStrip.ImageScalingSize = new Size(18, 18);
menuStrip.Items.AddRange(new ToolStripItem[] { заказыToolStripMenuItem, отчётыToolStripMenuItem, выбранныеТоварыToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(800, 27);
menuStrip.TabIndex = 0;
menuStrip.Text = "menuStrip";
//
// заказыToolStripMenuItem
//
заказыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { создатьToolStripMenuItem, редактироватьToolStripMenuItem, удалитьToolStripMenuItem });
заказыToolStripMenuItem.Name = аказыToolStripMenuItem";
заказыToolStripMenuItem.Size = new Size(68, 23);
заказыToolStripMenuItem.Text = "Заказы";
//
// создатьToolStripMenuItem
//
создатьToolStripMenuItem.Name = "создатьToolStripMenuItem";
создатьToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.A;
создатьToolStripMenuItem.Size = new Size(231, 24);
создатьToolStripMenuItem.Text = "Создать";
создатьToolStripMenuItem.Click += создатьToolStripMenuItem_Click;
//
// редактироватьToolStripMenuItem
//
редактироватьToolStripMenuItem.Name = "редактироватьToolStripMenuItem";
редактироватьToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.U;
редактироватьToolStripMenuItem.Size = new Size(231, 24);
редактироватьToolStripMenuItem.Text = "Редактировать";
редактироватьToolStripMenuItem.Click += редактироватьToolStripMenuItem_Click;
//
// удалитьToolStripMenuItem
//
удалитьToolStripMenuItem.Name = "удалитьToolStripMenuItem";
удалитьToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.D;
удалитьToolStripMenuItem.Size = new Size(231, 24);
удалитьToolStripMenuItem.Text = "Удалить";
удалитьToolStripMenuItem.Click += удалитьToolStripMenuItem_Click;
//
// отчётыToolStripMenuItem
//
отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { документToolStripMenuItem, документСТаблицейToolStripMenuItem, документСДиаграммойToolStripMenuItem });
отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem";
отчётыToolStripMenuItem.Size = new Size(71, 23);
отчётыToolStripMenuItem.Text = "Отчёты";
//
// документToolStripMenuItem
//
документToolStripMenuItem.Name = окументToolStripMenuItem";
документToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
документToolStripMenuItem.Size = new Size(358, 24);
документToolStripMenuItem.Text = "Документ с простой таблицей";
документToolStripMenuItem.Click += документToolStripMenuItem_Click;
//
// документСТаблицейToolStripMenuItem
//
документСТаблицейToolStripMenuItem.Name = окументСТаблицейToolStripMenuItem";
документСТаблицейToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.T;
документСТаблицейToolStripMenuItem.Size = new Size(358, 24);
документСТаблицейToolStripMenuItem.Text = "Отчет по всем заказам";
документСТаблицейToolStripMenuItem.Click += документСТаблицейToolStripMenuItem_Click;
//
// документСДиаграммойToolStripMenuItem
//
документСДиаграммойToolStripMenuItem.Name = окументСДиаграммойToolStripMenuItem";
документСДиаграммойToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.C;
документСДиаграммойToolStripMenuItem.Size = new Size(358, 24);
документСДиаграммойToolStripMenuItem.Text = "Документ с линейной диаграммой";
документСДиаграммойToolStripMenuItem.Click += документСДиаграммойToolStripMenuItem_Click;
//
// выбранныеТоварыToolStripMenuItem
//
выбранныеТоварыToolStripMenuItem.Name = "выбранныеТоварыToolStripMenuItem";
выбранныеТоварыToolStripMenuItem.Size = new Size(147, 23);
выбранныеТоварыToolStripMenuItem.Text = "Выбранные товары";
выбранныеТоварыToolStripMenuItem.Click += выбранныеТоварыToolStripMenuItem_Click;
//
// controlDataTable
//
controlDataTable.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
controlDataTable.AutoSize = true;
controlDataTable.Location = new Point(0, 31);
controlDataTable.Margin = new Padding(4, 4, 4, 4);
controlDataTable.Name = "controlDataTable";
controlDataTable.SelectedRowIndex = -1;
controlDataTable.Size = new Size(800, 420);
controlDataTable.TabIndex = 1;
//
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 19F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(controlDataTable);
Controls.Add(menuStrip);
MainMenuStrip = menuStrip;
Name = "FormMain";
Text = "Заказы";
Load += FormMain_Load;
menuStrip.ResumeLayout(false);
menuStrip.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
private MenuStrip menuStrip;
private ToolStripMenuItem заказыToolStripMenuItem;
private ToolStripMenuItem создатьToolStripMenuItem;
private ToolStripMenuItem редактироватьToolStripMenuItem;
private ToolStripMenuItem удалитьToolStripMenuItem;
private ToolStripMenuItem отчётыToolStripMenuItem;
private ToolStripMenuItem документToolStripMenuItem;
private ToolStripMenuItem документСТаблицейToolStripMenuItem;
private ToolStripMenuItem выбранныеТоварыToolStripMenuItem;
private ToolStripMenuItem документСДиаграммойToolStripMenuItem;
private ControlsLibraryNet60.Data.ControlDataTableTable controlDataTable;
private WinFormsLibraryVolkov.NonVisualComponents.ExcelImagesComponent excelImagesComponent;
private FormLibrary.ComponentHistogramToPdf componentHistogramToPdf;
private ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableMultiHeaderWord componentDocumentWithTableMultiHeaderWord;
}
}

View File

@ -12,31 +12,112 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ControlsLibraryNet60.Models;
using Microsoft.EntityFrameworkCore.Diagnostics;
using WinFormsLibraryVolkov.NonVisualComponents;
using ComponentsLibraryNet60.Core;
using ComponentsLibraryNet60.DocumentWithTable;
using ComponentsLibraryNet60.Models;
namespace InternetShopOrdersApp
{
public partial class FormMain : Form
{
private int? _id;
private readonly IOrderLogic _logic;
private readonly ISelectedItemLogic _selectedItemLogic;
private List<SelectedItemViewModel> _selectedItems;
private string? orderImage = null;
private IOrderLogic _logic;
public int Id { set { Id = value; } }
public FormMain(IOrderLogic logic, ISelectedItemLogic selectedItemLogic)
public FormMain(IOrderLogic logic)
{
InitializeComponent();
_logic = logic;
_selectedItemLogic = selectedItemLogic;
_selectedItems = new List<SelectedItemViewModel>();
}
private void FormOrder_Load(object sender, EventArgs e)
controlDataTable.LoadColumns(new List<DataTableColumnConfig>
{
_selectedItems = _selectedItemLogic.ReadList(null);
new DataTableColumnConfig { ColumnHeader = "", PropertyName = "Id", Visible = false, Width = 10 },
new DataTableColumnConfig { ColumnHeader = "ФИО заказчика", PropertyName = "Fullname", Visible = true, Width = 200 },
new DataTableColumnConfig { ColumnHeader = "Выбранный товар", PropertyName = "SelectedItemName", Visible = true, Width = 200 },
new DataTableColumnConfig { ColumnHeader = "Электронная почта", PropertyName = "Email", Visible = true, Width = 200 },
});
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
}
private void LoadData()
{
controlDataTable.Clear();
var orders = _logic.ReadList(null);
if (orders != null)
{
controlDataTable.AddTable(orders);
}
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void создатьToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormOrder));
if (service is FormOrder form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void редактироватьToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormOrder));
if (service is FormOrder form)
{
form.Id = controlDataTable.GetSelectedObject<OrderViewModel>().Id;
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void удалитьToolStripMenuItem_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Удалить запись?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
if (_logic.Delete(new OrderBindingModel { Id = controlDataTable.GetSelectedObject<OrderViewModel>().Id }))
{
LoadData();
}
}
}
private void документToolStripMenuItem_Click(object sender, EventArgs e)
{
List<string> orderImages = new List<string>();
foreach (var order in _logic.ReadList(null))
{
orderImages.Add(order.OrderImage);
}
string path = AppDomain.CurrentDomain.BaseDirectory + "Фотокарточки заказов с интернет-магазина.xlsx";
if (excelImagesComponent.createWithImages(new ExcelImageInfo(path, "Фотокарточки заказов", orderImages.ToArray()))) MessageBox.Show("Документ был создан");
}
private void документСТаблицейToolStripMenuItem_Click(object sender, EventArgs e)
{
string path = AppDomain.CurrentDomain.BaseDirectory + "Отчет по всем заказам.docx";
}
private void документСДиаграммойToolStripMenuItem_Click(object sender, EventArgs e)
{
string path = AppDomain.CurrentDomain.BaseDirectory + "Гистограмма товаров.pdf";
}
private void выбранныеТоварыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSelectedItems));
if (service is FormSelectedItems form)
{
form.ShowDialog();
}
}
}
}

View File

@ -117,4 +117,19 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="excelImagesComponent.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>138, 17</value>
</metadata>
<metadata name="componentHistogramToPdf.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>734, 22</value>
</metadata>
<metadata name="componentDocumentWithTableMultiHeaderWord.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>347, 18</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>177</value>
</metadata>
</root>

View File

@ -28,12 +28,136 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "FormOrder";
labelFIO = new Label();
textBoxFIO = new TextBox();
labelMail = new Label();
labelSelectedItem = new Label();
customSelectedCheckedListBox = new WinFormsLibraryVolkov.CustomSelectedCheckedListBox();
buttonOrderPic = new Button();
buttonCancel = new Button();
buttonSave = new Button();
openFileDialog = new OpenFileDialog();
controlInputRegexEmail = new ControlsLibraryNet60.Input.ControlInputRegexEmail();
SuspendLayout();
//
// labelFIO
//
labelFIO.AutoSize = true;
labelFIO.Location = new Point(12, 9);
labelFIO.Name = "labelFIO";
labelFIO.Size = new Size(107, 19);
labelFIO.TabIndex = 0;
labelFIO.Text = "ФИО заказчика";
//
// textBoxFIO
//
textBoxFIO.Location = new Point(12, 31);
textBoxFIO.Name = "textBoxFIO";
textBoxFIO.Size = new Size(471, 26);
textBoxFIO.TabIndex = 1;
//
// labelMail
//
labelMail.AutoSize = true;
labelMail.Location = new Point(12, 228);
labelMail.Name = "labelMail";
labelMail.Size = new Size(132, 19);
labelMail.TabIndex = 2;
labelMail.Text = "Электронная почта";
//
// labelSelectedItem
//
labelSelectedItem.AutoSize = true;
labelSelectedItem.Location = new Point(12, 79);
labelSelectedItem.Name = "labelSelectedItem";
labelSelectedItem.Size = new Size(124, 19);
labelSelectedItem.TabIndex = 4;
labelSelectedItem.Text = "Выбранный товар";
//
// customSelectedCheckedListBox
//
customSelectedCheckedListBox.Location = new Point(12, 102);
customSelectedCheckedListBox.Margin = new Padding(3, 4, 3, 4);
customSelectedCheckedListBox.Name = "customSelectedCheckedListBox";
customSelectedCheckedListBox.SelectedElement = "";
customSelectedCheckedListBox.Size = new Size(196, 122);
customSelectedCheckedListBox.TabIndex = 5;
//
// buttonOrderPic
//
buttonOrderPic.Location = new Point(12, 331);
buttonOrderPic.Name = "buttonOrderPic";
buttonOrderPic.Size = new Size(471, 26);
buttonOrderPic.TabIndex = 6;
buttonOrderPic.Text = "Выбрать фото заказа";
buttonOrderPic.UseVisualStyleBackColor = true;
buttonOrderPic.Click += buttonOrderPic_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(388, 412);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(95, 26);
buttonCancel.TabIndex = 7;
buttonCancel.Text = "Отменить";
buttonCancel.UseVisualStyleBackColor = true;
//
// buttonSave
//
buttonSave.Location = new Point(12, 412);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(107, 26);
buttonSave.TabIndex = 8;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// openFileDialog
//
openFileDialog.FileName = "openFileDialog";
openFileDialog.Multiselect = true;
//
// controlInputRegexEmail
//
controlInputRegexEmail.Location = new Point(12, 253);
controlInputRegexEmail.Margin = new Padding(5, 6, 5, 6);
controlInputRegexEmail.Name = "controlInputRegexEmail";
controlInputRegexEmail.Pattern = "^([\\w\\d\\.\\-]+)@([\\w\\-]+)((\\.(\\w){2,3})+)$";
controlInputRegexEmail.Size = new Size(458, 33);
controlInputRegexEmail.TabIndex = 9;
controlInputRegexEmail.Value = "";
//
// FormOrder
//
AutoScaleDimensions = new SizeF(8F, 19F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(495, 450);
Controls.Add(controlInputRegexEmail);
Controls.Add(buttonSave);
Controls.Add(buttonCancel);
Controls.Add(buttonOrderPic);
Controls.Add(customSelectedCheckedListBox);
Controls.Add(labelSelectedItem);
Controls.Add(labelMail);
Controls.Add(textBoxFIO);
Controls.Add(labelFIO);
Name = "FormOrder";
Text = "Заказ";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label labelFIO;
private TextBox textBoxFIO;
private Label labelMail;
private Label labelSelectedItem;
private WinFormsLibraryVolkov.CustomSelectedCheckedListBox customSelectedCheckedListBox;
private Button buttonOrderPic;
private Button buttonCancel;
private Button buttonSave;
private OpenFileDialog openFileDialog;
private ControlsLibraryNet60.Input.ControlInputRegexEmail controlInputRegexEmail;
}
}

View File

@ -1,4 +1,7 @@
using System;
using InternetShopOrdersContracts.BindingModels;
using InternetShopOrdersContracts.BusinessLogicContracts;
using InternetShopOrdersContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@ -12,9 +15,72 @@ namespace InternetShopOrdersApp
{
public partial class FormOrder : Form
{
public FormOrder()
private int? _id;
private readonly IOrderLogic _logic;
private readonly ISelectedItemLogic _selectedItemLogic;
private List<SelectedItemViewModel> _selectedItems;
private string? orderImage = null;
public int Id { set { Id = value; } }
public FormOrder(IOrderLogic logic, ISelectedItemLogic selectedItemLogic)
{
InitializeComponent();
_logic = logic;
_selectedItemLogic = selectedItemLogic;
_selectedItems = new List<SelectedItemViewModel>();
}
private void FormOrder_Load(object sender, EventArgs e)
{
_selectedItems = _selectedItemLogic.ReadList(null);
customSelectedCheckedListBox.PopulateList(_selectedItems.Select(x => x.Name).ToList());
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxFIO.Text))
{
MessageBox.Show("Заполните ФИО заказчика", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
if (customSelectedCheckedListBox.SelectedElement == null)
{
MessageBox.Show("Укажите выбранные товары", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
if (orderImage == null)
{
MessageBox.Show("Выберите фото заказа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
try
{
var model = new OrderBindingModel
{
Id = _id ?? 0,
Fullname = textBoxFIO.Text,
OrderImage = orderImage,
SelectedItemId = _selectedItems.First(x => x.Name == customSelectedCheckedListBox.SelectedElement).Id,
Email = controlInputRegexEmail.Value,
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Возникла ошибка при сохранении. Дополнительная информация в логах");
}
MessageBox.Show("Сохранение прошло успешно", "Успешное сохранение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonOrderPic_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() != DialogResult.Cancel)
{
orderImage = openFileDialog.FileName;
}
}
}
}

View File

@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -28,12 +28,57 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "FormSelectedItems";
dataGridView = new DataGridView();
NameCol = new DataGridViewTextBoxColumn();
Id = new DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { NameCol, Id });
dataGridView.Location = new Point(0, 0);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 47;
dataGridView.Size = new Size(800, 356);
dataGridView.TabIndex = 0;
dataGridView.CellValueChanged += dataGridView_CellValueChanged;
dataGridView.UserDeletingRow += dataGridView_UserDeletingRow;
dataGridView.KeyUp += dataGridView_KeyUp;
//
// NameCol
//
NameCol.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
NameCol.HeaderText = "Название товара";
NameCol.MinimumWidth = 6;
NameCol.Name = "NameCol";
//
// Id
//
Id.HeaderText = "Id";
Id.MinimumWidth = 6;
Id.Name = "Id";
Id.Visible = false;
Id.Width = 125;
//
// FormSelectedItems
//
AutoScaleDimensions = new SizeF(8F, 19F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 356);
Controls.Add(dataGridView);
Name = "FormSelectedItems";
Text = "Выбранные товары";
Load += FormSelectedItems_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private DataGridViewTextBoxColumn NameCol;
private DataGridViewTextBoxColumn Id;
}
}

View File

@ -1,4 +1,7 @@
using System;
using InternetShopOrdersContracts.BindingModels;
using InternetShopOrdersContracts.BusinessLogicContracts;
using Microsoft.EntityFrameworkCore.Diagnostics;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@ -12,9 +15,90 @@ namespace InternetShopOrdersApp
{
public partial class FormSelectedItems : Form
{
public FormSelectedItems()
private readonly ISelectedItemLogic _logic;
private bool loading = false;
public FormSelectedItems(ISelectedItemLogic logic)
{
InitializeComponent();
_logic = logic;
}
private void LoadData()
{
loading = true;
try
{
var list = _logic.ReadList(null);
if (list != null)
{
foreach (var selectedItem in list)
{
int rowIndex = dataGridView.Rows.Add();
dataGridView.Rows[rowIndex].Cells[0].Value = selectedItem.Name;
dataGridView.Rows[rowIndex].Cells[1].Value = selectedItem.Id;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
loading = false;
}
}
private void FormSelectedItems_Load(object sender, EventArgs e)
{
LoadData();
}
private void dataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (loading || e.RowIndex < 0 || e.ColumnIndex != 0) return;
if (dataGridView.Rows[e.RowIndex].Cells[1].Value != null && !string.IsNullOrEmpty(dataGridView.Rows[e.RowIndex].Cells[1].Value.ToString()))
{
var name = dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
if (name is null) return;
_logic.Update(new SelectedItemBindingModel { Id = Convert.ToInt32(dataGridView.Rows[e.RowIndex].Cells[1].Value), Name = name.ToString() });
}
else
{
var name = dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
if (name is null) return;
_logic.Create(new SelectedItemBindingModel { Id = 0, Name = name.ToString() });
int newInterestId = _logic.ReadList(null).ToList().Last().Id;
dataGridView.Rows[e.RowIndex].Cells[1].Value = newInterestId;
}
}
private void dataGridView_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Insert:
dataGridView.Rows.Add();
break;
}
}
private void deleteRows(DataGridViewSelectedRowCollection rows)
{
for (int i = 0; i < rows.Count; i++)
{
DataGridViewRow row = rows[i];
if (!_logic.Delete(new SelectedItemBindingModel { Id = Convert.ToInt32(row.Cells[1].Value) })) continue;
}
}
private void dataGridView_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
{
e.Cancel = true;
if (dataGridView.SelectedRows == null) return;
if (MessageBox.Show("Удалить записи?", "Подтвердите действие", MessageBoxButtons.YesNo) == DialogResult.No) return;
deleteRows(dataGridView.SelectedRows);
}
}
}

View File

@ -117,4 +117,10 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="NameCol.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Id.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -9,6 +9,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ComponentsLibraryNet60" Version="1.0.0" />
<PackageReference Include="ControlsLibraryNet60" Version="1.0.0" />
<PackageReference Include="FormLibrary" Version="1.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@ -20,6 +23,7 @@
<ProjectReference Include="..\InternetShopOrdersBusinessLogic\InternetShopOrdersBusinessLogic.csproj" />
<ProjectReference Include="..\InternetShopOrdersContracts\InternetShopOrdersContracts.csproj" />
<ProjectReference Include="..\InternetShopOrdersDatabaseImplement\InternetShopOrdersDatabaseImplement.csproj" />
<ProjectReference Include="..\WinFormsLibraryVolkov\WinFormsLibraryVolkov.csproj" />
</ItemGroup>
</Project>

View File

@ -5,6 +5,7 @@
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>