diff --git a/VolkovLabs/InternetShopOrdersApp/FormMain.Designer.cs b/VolkovLabs/InternetShopOrdersApp/FormMain.Designer.cs index feb3228..f4caa22 100644 --- a/VolkovLabs/InternetShopOrdersApp/FormMain.Designer.cs +++ b/VolkovLabs/InternetShopOrdersApp/FormMain.Designer.cs @@ -28,12 +28,146 @@ /// 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; } } \ No newline at end of file diff --git a/VolkovLabs/InternetShopOrdersApp/FormMain.cs b/VolkovLabs/InternetShopOrdersApp/FormMain.cs index bbd8688..e14df7d 100644 --- a/VolkovLabs/InternetShopOrdersApp/FormMain.cs +++ b/VolkovLabs/InternetShopOrdersApp/FormMain.cs @@ -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 _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(); + controlDataTable.LoadColumns(new List + { + 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 FormOrder_Load(object sender, EventArgs e) + private void LoadData() { - _selectedItems = _selectedItemLogic.ReadList(null); + 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().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().Id })) + { + LoadData(); + } + } + } + + private void документToolStripMenuItem_Click(object sender, EventArgs e) + { + List orderImages = new List(); + 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(); + } } } } diff --git a/VolkovLabs/InternetShopOrdersApp/FormMain.resx b/VolkovLabs/InternetShopOrdersApp/FormMain.resx index 1af7de1..c4d345e 100644 --- a/VolkovLabs/InternetShopOrdersApp/FormMain.resx +++ b/VolkovLabs/InternetShopOrdersApp/FormMain.resx @@ -1,17 +1,17 @@  - @@ -117,4 +117,19 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 138, 17 + + + 734, 22 + + + 347, 18 + + + 177 + \ No newline at end of file diff --git a/VolkovLabs/InternetShopOrdersApp/FormOrder.Designer.cs b/VolkovLabs/InternetShopOrdersApp/FormOrder.Designer.cs index aa2c7a1..56f51ce 100644 --- a/VolkovLabs/InternetShopOrdersApp/FormOrder.Designer.cs +++ b/VolkovLabs/InternetShopOrdersApp/FormOrder.Designer.cs @@ -28,12 +28,136 @@ /// 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; } } \ No newline at end of file diff --git a/VolkovLabs/InternetShopOrdersApp/FormOrder.cs b/VolkovLabs/InternetShopOrdersApp/FormOrder.cs index 7e1816a..14202a7 100644 --- a/VolkovLabs/InternetShopOrdersApp/FormOrder.cs +++ b/VolkovLabs/InternetShopOrdersApp/FormOrder.cs @@ -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 _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(); + } + + 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; + } } } } diff --git a/VolkovLabs/InternetShopOrdersApp/FormOrder.resx b/VolkovLabs/InternetShopOrdersApp/FormOrder.resx index 1af7de1..a85462d 100644 --- a/VolkovLabs/InternetShopOrdersApp/FormOrder.resx +++ b/VolkovLabs/InternetShopOrdersApp/FormOrder.resx @@ -1,17 +1,17 @@  - @@ -117,4 +117,7 @@ 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/VolkovLabs/InternetShopOrdersApp/FormSelectedItems.Designer.cs b/VolkovLabs/InternetShopOrdersApp/FormSelectedItems.Designer.cs index ca1d57c..d7e2cc3 100644 --- a/VolkovLabs/InternetShopOrdersApp/FormSelectedItems.Designer.cs +++ b/VolkovLabs/InternetShopOrdersApp/FormSelectedItems.Designer.cs @@ -28,12 +28,57 @@ /// 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; } } \ No newline at end of file diff --git a/VolkovLabs/InternetShopOrdersApp/FormSelectedItems.cs b/VolkovLabs/InternetShopOrdersApp/FormSelectedItems.cs index 4b291df..f8e320a 100644 --- a/VolkovLabs/InternetShopOrdersApp/FormSelectedItems.cs +++ b/VolkovLabs/InternetShopOrdersApp/FormSelectedItems.cs @@ -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); } } } diff --git a/VolkovLabs/InternetShopOrdersApp/FormSelectedItems.resx b/VolkovLabs/InternetShopOrdersApp/FormSelectedItems.resx index 1af7de1..d012256 100644 --- a/VolkovLabs/InternetShopOrdersApp/FormSelectedItems.resx +++ b/VolkovLabs/InternetShopOrdersApp/FormSelectedItems.resx @@ -1,17 +1,17 @@  - @@ -117,4 +117,10 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + + + True + \ No newline at end of file diff --git a/VolkovLabs/InternetShopOrdersApp/InternetShopOrdersApp.csproj b/VolkovLabs/InternetShopOrdersApp/InternetShopOrdersApp.csproj index dc97df1..06ddae6 100644 --- a/VolkovLabs/InternetShopOrdersApp/InternetShopOrdersApp.csproj +++ b/VolkovLabs/InternetShopOrdersApp/InternetShopOrdersApp.csproj @@ -9,6 +9,9 @@ + + + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -20,6 +23,7 @@ + diff --git a/VolkovLabs/WinFormsLibraryVolkov/WinFormsLibraryVolkov.csproj b/VolkovLabs/WinFormsLibraryVolkov/WinFormsLibraryVolkov.csproj index 4a91ed0..f3170e9 100644 --- a/VolkovLabs/WinFormsLibraryVolkov/WinFormsLibraryVolkov.csproj +++ b/VolkovLabs/WinFormsLibraryVolkov/WinFormsLibraryVolkov.csproj @@ -5,6 +5,7 @@ enable true enable + True