barebones медиафайлы
This commit is contained in:
parent
93abfa5de5
commit
3c0bfa50ef
110
BusinessLogic/BusinessLogic/MediaFileLogic.cs
Normal file
110
BusinessLogic/BusinessLogic/MediaFileLogic.cs
Normal file
@ -0,0 +1,110 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.BusinessLogicContracts;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.StorageContracts;
|
||||
using Contracts.ViewModels;
|
||||
using DatabaseImplement.Implements;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BusinessLogic.BusinessLogic
|
||||
{
|
||||
public class MediaFileLogic : IMediaFileLogic
|
||||
{
|
||||
private readonly IMediaFileStorage _mediafileStorage;
|
||||
private readonly ILogger _logger;
|
||||
public MediaFileLogic(IMediaFileStorage mediafileStorage, ILogger<MediaFileLogic> logger)
|
||||
{
|
||||
_mediafileStorage = mediafileStorage;
|
||||
_logger = logger;
|
||||
}
|
||||
public bool Create(MediaFileBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_mediafileStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(MediaFileBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_mediafileStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public MediaFileViewModel? ReadElement(MediaFileSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement .Id:{ Id}", model.Id);
|
||||
var element = _mediafileStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<MediaFileViewModel>? ReadList(MediaFileSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
|
||||
var list = model == null ? _mediafileStorage.GetFullList() : _mediafileStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(MediaFileBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_mediafileStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(MediaFileBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия", nameof(model.Name));
|
||||
}
|
||||
if (model.Location == null)
|
||||
{
|
||||
throw new ArgumentNullException("Нет пути", nameof(model.Name));
|
||||
}
|
||||
_logger.LogError("Проверка модели медиа файла выдала ошибку.");
|
||||
}
|
||||
}
|
||||
}
|
20
Contracts/BusinessLogicContracts/IMediaFileLogic.cs
Normal file
20
Contracts/BusinessLogicContracts/IMediaFileLogic.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IMediaFileLogic
|
||||
{
|
||||
bool Create(MediaFileBindingModel model);
|
||||
bool Update(MediaFileBindingModel model);
|
||||
bool Delete(MediaFileBindingModel model);
|
||||
List<MediaFileViewModel>? ReadList(MediaFileSearchModel? model);
|
||||
MediaFileViewModel? ReadElement(MediaFileSearchModel model);
|
||||
}
|
||||
}
|
91
WinFormsApp/FormMediaFiles.Designer.cs
generated
91
WinFormsApp/FormMediaFiles.Designer.cs
generated
@ -28,15 +28,86 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
groupBoxFiles = new GroupBox();
|
||||
panelFiles = new Panel();
|
||||
comboBoxProduct = new ComboBox();
|
||||
buttonAdd = new Button();
|
||||
buttonSelectFile = new Button();
|
||||
labelFile = new Label();
|
||||
groupBox1 = new GroupBox();
|
||||
groupBoxFiles.SuspendLayout();
|
||||
groupBox1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxFiles
|
||||
//
|
||||
groupBoxFiles.Controls.Add(panelFiles);
|
||||
groupBoxFiles.Dock = DockStyle.Left;
|
||||
groupBoxFiles.Location = new Point(0, 0);
|
||||
groupBoxFiles.Name = "groupBoxFiles";
|
||||
groupBoxFiles.Size = new Size(282, 439);
|
||||
groupBoxFiles.TabIndex = 0;
|
||||
groupBoxFiles.TabStop = false;
|
||||
groupBoxFiles.Text = "Файлы";
|
||||
//
|
||||
// panelFiles
|
||||
//
|
||||
panelFiles.AutoScroll = true;
|
||||
panelFiles.Dock = DockStyle.Fill;
|
||||
panelFiles.Location = new Point(3, 19);
|
||||
panelFiles.Name = "panelFiles";
|
||||
panelFiles.Size = new Size(276, 417);
|
||||
panelFiles.TabIndex = 0;
|
||||
//
|
||||
// comboBoxProduct
|
||||
//
|
||||
comboBoxProduct.FormattingEnabled = true;
|
||||
comboBoxProduct.Location = new Point(19, 43);
|
||||
comboBoxProduct.Name = "comboBoxProduct";
|
||||
comboBoxProduct.Size = new Size(121, 23);
|
||||
comboBoxProduct.TabIndex = 1;
|
||||
comboBoxProduct.SelectedIndexChanged += comboBoxProduct_SelectedIndexChanged;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.Location = new Point(19, 92);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(75, 23);
|
||||
buttonAdd.TabIndex = 2;
|
||||
buttonAdd.Text = "Добавить";
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += buttonAdd_Click;
|
||||
//
|
||||
// buttonSelectFile
|
||||
//
|
||||
buttonSelectFile.Location = new Point(19, 237);
|
||||
buttonSelectFile.Name = "buttonSelectFile";
|
||||
buttonSelectFile.Size = new Size(109, 27);
|
||||
buttonSelectFile.TabIndex = 3;
|
||||
buttonSelectFile.Text = "Выбрать файл...";
|
||||
buttonSelectFile.UseVisualStyleBackColor = true;
|
||||
buttonSelectFile.Click += buttonSelectFile_Click;
|
||||
//
|
||||
// labelFile
|
||||
//
|
||||
labelFile.AutoSize = true;
|
||||
labelFile.Location = new Point(19, 267);
|
||||
labelFile.Name = "labelFile";
|
||||
labelFile.Size = new Size(40, 15);
|
||||
labelFile.TabIndex = 4;
|
||||
labelFile.Text = "Пусто";
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
groupBox1.Location = new Point(12, 12);
|
||||
groupBox1.Controls.Add(comboBoxProduct);
|
||||
groupBox1.Controls.Add(labelFile);
|
||||
groupBox1.Controls.Add(buttonAdd);
|
||||
groupBox1.Controls.Add(buttonSelectFile);
|
||||
groupBox1.Dock = DockStyle.Right;
|
||||
groupBox1.Location = new Point(466, 0);
|
||||
groupBox1.Name = "groupBox1";
|
||||
groupBox1.Size = new Size(271, 434);
|
||||
groupBox1.TabIndex = 0;
|
||||
groupBox1.Size = new Size(200, 439);
|
||||
groupBox1.TabIndex = 5;
|
||||
groupBox1.TabStop = false;
|
||||
groupBox1.Text = "groupBox1";
|
||||
//
|
||||
@ -44,15 +115,27 @@
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
ClientSize = new Size(666, 439);
|
||||
Controls.Add(groupBox1);
|
||||
Controls.Add(groupBoxFiles);
|
||||
Name = "FormMediaFiles";
|
||||
Text = "FormMediaFiles";
|
||||
Load += FormMediaFiles_Load;
|
||||
Resize += FormMediaFiles_Resize;
|
||||
groupBoxFiles.ResumeLayout(false);
|
||||
groupBox1.ResumeLayout(false);
|
||||
groupBox1.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxFiles;
|
||||
private ComboBox comboBoxProduct;
|
||||
private Button buttonAdd;
|
||||
private Button buttonSelectFile;
|
||||
private Label labelFile;
|
||||
private GroupBox groupBox1;
|
||||
private Panel panelFiles;
|
||||
}
|
||||
}
|
@ -1,4 +1,9 @@
|
||||
using System;
|
||||
using BusinessLogic.BusinessLogic;
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.BusinessLogicContracts;
|
||||
using Contracts.SearchModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@ -12,9 +17,101 @@ namespace WinFormsApp
|
||||
{
|
||||
public partial class FormMediaFiles : Form
|
||||
{
|
||||
public FormMediaFiles()
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMediaFileLogic _mediafileLogic;
|
||||
private readonly IProductLogic _productLogic;
|
||||
private string? _filename;
|
||||
public FormMediaFiles(ILogger<FormMediaFiles> logger, IMediaFileLogic mediaFileLogic, IProductLogic productLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_mediafileLogic = mediaFileLogic;
|
||||
_productLogic = productLogic;
|
||||
_filename = null;
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
if (comboBoxProduct.SelectedIndex < 0) return;
|
||||
var list = _mediafileLogic.ReadList(new MediaFileSearchModel()
|
||||
{
|
||||
ProductId = (Guid?)comboBoxProduct.SelectedValue ?? Guid.Empty,
|
||||
});
|
||||
panelFiles.Controls.Clear();
|
||||
foreach (var item in list)
|
||||
{
|
||||
var imageBox = new PictureBox();
|
||||
imageBox.Dock = DockStyle.Top;
|
||||
imageBox.Image = new Bitmap(item.Location);
|
||||
imageBox.Width = groupBox1.Width;
|
||||
panelFiles.Controls.Add(imageBox);
|
||||
imageBox.SizeMode = PictureBoxSizeMode.Zoom;
|
||||
imageBox.Height = 400;
|
||||
panelFiles.Refresh();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void FormMediaFiles_Load(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _productLogic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
comboBoxProduct.DisplayMember = "Name";
|
||||
comboBoxProduct.ValueMember = "Id";
|
||||
comboBoxProduct.DataSource = list;
|
||||
comboBoxProduct.SelectedItem = null;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки списка продуктов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void comboBoxProduct_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (comboBoxProduct.SelectedIndex != -1 && !string.IsNullOrEmpty(_filename))
|
||||
{
|
||||
_mediafileLogic.Create(new MediaFileBindingModel()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Name = System.IO.Path.GetFileNameWithoutExtension(_filename),
|
||||
Location = _filename,
|
||||
ProductId = (Guid)comboBoxProduct.SelectedValue,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSelectFile_Click(object sender, EventArgs e)
|
||||
{
|
||||
var dialog = new OpenFileDialog();
|
||||
dialog.Filter = "Image Files(*.jpg; *.png; *.jpeg; *.gif; *.bmp)|*.jpg;*.png;*.jpeg;*.gif;*.bmp";
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
_filename = dialog.FileName;
|
||||
labelFile.Text = System.IO.Path.GetDirectoryName(_filename);
|
||||
}
|
||||
}
|
||||
|
||||
private void FormMediaFiles_Resize(object sender, EventArgs e)
|
||||
{
|
||||
panelFiles.Width = Convert.ToInt32(this.Width * 0.5);
|
||||
panelFiles.Height = this.Height;
|
||||
foreach (var control in this.Controls.OfType<PictureBox>())
|
||||
{
|
||||
control.Width = panelFiles.Width;
|
||||
control.Height = Convert.ToInt32(panelFiles.Height * 0.3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
38
WinFormsApp/FormProducts.Designer.cs
generated
38
WinFormsApp/FormProducts.Designer.cs
generated
@ -43,21 +43,24 @@
|
||||
buttonSaveProduct = new Button();
|
||||
checkBoxIsSold = new CheckBox();
|
||||
textBoxName = new TextBox();
|
||||
menuStrip1 = new MenuStrip();
|
||||
медиаФайлыToolStripMenuItem = new ToolStripMenuItem();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
groupBoxControls.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
||||
groupBoxCreateProduct.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownAmount).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit();
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Dock = DockStyle.Left;
|
||||
dataGridView.Location = new Point(0, 0);
|
||||
dataGridView.Location = new Point(0, 24);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.Size = new Size(602, 646);
|
||||
dataGridView.Size = new Size(602, 622);
|
||||
dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonCreateProduct
|
||||
@ -80,9 +83,9 @@
|
||||
groupBoxControls.Controls.Add(buttonUpdateProduct);
|
||||
groupBoxControls.Controls.Add(buttonCreateProduct);
|
||||
groupBoxControls.Dock = DockStyle.Right;
|
||||
groupBoxControls.Location = new Point(617, 0);
|
||||
groupBoxControls.Location = new Point(617, 24);
|
||||
groupBoxControls.Name = "groupBoxControls";
|
||||
groupBoxControls.Size = new Size(308, 646);
|
||||
groupBoxControls.Size = new Size(308, 622);
|
||||
groupBoxControls.TabIndex = 2;
|
||||
groupBoxControls.TabStop = false;
|
||||
groupBoxControls.Text = "Действия";
|
||||
@ -145,9 +148,9 @@
|
||||
groupBoxCreateProduct.Controls.Add(checkBoxIsSold);
|
||||
groupBoxCreateProduct.Controls.Add(textBoxName);
|
||||
groupBoxCreateProduct.Dock = DockStyle.Right;
|
||||
groupBoxCreateProduct.Location = new Point(383, 0);
|
||||
groupBoxCreateProduct.Location = new Point(383, 24);
|
||||
groupBoxCreateProduct.Name = "groupBoxCreateProduct";
|
||||
groupBoxCreateProduct.Size = new Size(234, 646);
|
||||
groupBoxCreateProduct.Size = new Size(234, 622);
|
||||
groupBoxCreateProduct.TabIndex = 3;
|
||||
groupBoxCreateProduct.TabStop = false;
|
||||
groupBoxCreateProduct.Text = "Создание/изменение продукта";
|
||||
@ -206,6 +209,22 @@
|
||||
textBoxName.Size = new Size(100, 23);
|
||||
textBoxName.TabIndex = 0;
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
menuStrip1.Items.AddRange(new ToolStripItem[] { медиаФайлыToolStripMenuItem });
|
||||
menuStrip1.Location = new Point(0, 0);
|
||||
menuStrip1.Name = "menuStrip1";
|
||||
menuStrip1.Size = new Size(925, 24);
|
||||
menuStrip1.TabIndex = 4;
|
||||
menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
// медиаФайлыToolStripMenuItem
|
||||
//
|
||||
медиаФайлыToolStripMenuItem.Name = "медиаФайлыToolStripMenuItem";
|
||||
медиаФайлыToolStripMenuItem.Size = new Size(96, 20);
|
||||
медиаФайлыToolStripMenuItem.Text = "Медиа файлы";
|
||||
медиаФайлыToolStripMenuItem.Click += медиаФайлыToolStripMenuItem_Click;
|
||||
//
|
||||
// FormProducts
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
@ -214,6 +233,8 @@
|
||||
Controls.Add(groupBoxCreateProduct);
|
||||
Controls.Add(groupBoxControls);
|
||||
Controls.Add(dataGridView);
|
||||
Controls.Add(menuStrip1);
|
||||
MainMenuStrip = menuStrip1;
|
||||
Name = "FormProducts";
|
||||
Text = "FormProducts";
|
||||
Load += FormProducts_Load;
|
||||
@ -224,7 +245,10 @@
|
||||
groupBoxCreateProduct.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownAmount).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit();
|
||||
menuStrip1.ResumeLayout(false);
|
||||
menuStrip1.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -244,5 +268,7 @@
|
||||
private Button buttonGenerateBarCode;
|
||||
private PictureBox pictureBox1;
|
||||
private Button buttonReadBarCode;
|
||||
private MenuStrip menuStrip1;
|
||||
private ToolStripMenuItem медиаФайлыToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -206,7 +206,7 @@ namespace WinFormsApp
|
||||
{
|
||||
var dialog = new OpenFileDialog();
|
||||
dialog.Filter = "Image Files(*.jpg; *.png; *.jpeg; *.gif; *.bmp)|*.jpg;*.png;*.jpeg;*.gif;*.bmp";
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
pictureBox1.Image = new Bitmap(dialog.FileName);
|
||||
_barcode = BarcodeReader.Read(dialog.FileName);
|
||||
@ -231,5 +231,14 @@ namespace WinFormsApp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void медиаФайлыToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormMediaFiles));
|
||||
if (service is FormMediaFiles form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
@ -38,10 +38,12 @@ namespace WinFormsApp
|
||||
//services.AddTransient<ISupplyDocStorage, SupplyDocStorage>();
|
||||
services.AddTransient<IProductStorage, ProductStorage>();
|
||||
services.AddTransient<ISupplierStorage, SupplierStorage>();
|
||||
services.AddTransient<IMediaFileStorage, MediaFileStorage>();
|
||||
|
||||
services.AddTransient<ISupplyLogic, SupplyLogic>();
|
||||
services.AddTransient<ISupplierLogic, SupplierLogic>();
|
||||
services.AddTransient<IProductLogic, ProductLogic>();
|
||||
services.AddTransient<IMediaFileLogic, MediaFileLogic>();
|
||||
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormProducts>();
|
||||
|
Loading…
Reference in New Issue
Block a user