diff --git a/VisEl/BusinessLogic/BusinessLogic.csproj b/VisEl/BusinessLogic/BusinessLogic.csproj new file mode 100644 index 0000000..6b60c23 --- /dev/null +++ b/VisEl/BusinessLogic/BusinessLogic.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/VisEl/BusinessLogic/ClientBL.cs b/VisEl/BusinessLogic/ClientBL.cs new file mode 100644 index 0000000..3d808ea --- /dev/null +++ b/VisEl/BusinessLogic/ClientBL.cs @@ -0,0 +1,117 @@ +using DatabaseImplement.Implements; +using DataContracts.bindingModels; +using DataContracts.BLs; +using DataContracts.searchModels; +using DataContracts.storages; +using DataContracts.viewModels; + +namespace BusinessLogic +{ + public class ClientBL : IClientBL + { + private readonly ClientStorage _clientStorage; + private readonly ProductBL productBL; + public ClientBL() + { + _clientStorage = new(); + productBL = new ProductBL(); + } + public bool Create(ClientBindingModel model) + { + CheckModel(model); + if (_clientStorage.Insert(model) == null) + { + return false; + } + return true; + } + public List<(string title, int count)> FindDataDiagram() + { + List<(string, int)> list = new List<(string, int)>(); + List clients = ReadList(); + List products = productBL.ReadList(); + foreach(ProductViewModel product in products) + { + int count = 0; + + foreach(ClientViewModel client in clients) + { + if(client.products.Contains(product.title)) + count++; + } + list.Add((product.title, count)); + } + return list; + } + public bool Delete(ClientBindingModel model) + { + CheckModel(model, false); + if (_clientStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public ClientViewModel? ReadElement(ClientSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + var element = _clientStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public List? ReadList() + { + var list = _clientStorage.GetFullList(); + if (list == null) + { + return null; + } + return list; + } + + public bool Update(ClientBindingModel model) + { + CheckModel(model); + if (_clientStorage.Update(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(ClientBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.FIO)) + { + throw new ArgumentNullException("Нет имени клиента", nameof(model.FIO)); + } + if (string.IsNullOrEmpty(model.email)) + { + throw new ArgumentNullException("Нет почты клиента", nameof(model.email)); + } + if (string.IsNullOrEmpty(model.products)) + { + throw new ArgumentNullException("Нет продуктов клиента", nameof(model.products)); + } + + } + + } +} \ No newline at end of file diff --git a/VisEl/BusinessLogic/ProductBL.cs b/VisEl/BusinessLogic/ProductBL.cs new file mode 100644 index 0000000..d4cc650 --- /dev/null +++ b/VisEl/BusinessLogic/ProductBL.cs @@ -0,0 +1,90 @@ +using DatabaseImplement.Implements; +using DataContracts.bindingModels; +using DataContracts.BLs; +using DataContracts.searchModels; +using DataContracts.viewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BusinessLogic +{ + public class ProductBL : IProductBL + { + private readonly ProductStorage _productStorage = new(); + public bool Create(ProductBindingModel model) + { + CheckModel(model); + if (_productStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Delete(ProductBindingModel model) + { + CheckModel(model, false); + if (_productStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public ProductViewModel? ReadElement(ProductSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + var element = _productStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public List? ReadList() + { + var list = _productStorage.GetFullList(); + if (list == null) + { + return null; + } + return list; + } + + public bool Update(ProductBindingModel model) + { + CheckModel(model); + if (_productStorage.Update(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(ProductBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.title)) + { + throw new ArgumentNullException("Нет имени клиента", nameof(model.title)); + } + + } + + } +} diff --git a/VisEl/ClientForms/Client.Designer.cs b/VisEl/ClientForms/Client.Designer.cs new file mode 100644 index 0000000..248f56d --- /dev/null +++ b/VisEl/ClientForms/Client.Designer.cs @@ -0,0 +1,145 @@ +namespace ClientForms +{ + partial class Client + { + /// + /// 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.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + this.textBoxFIO = new System.Windows.Forms.TextBox(); + this.myEmailTextBox = new VisualCompLib.MyEmailTextBox(); + this.buttonPhoto = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.myCheckListProducts = new VisableComponents.MyCheckList(); + this.openFileDialogPath = new System.Windows.Forms.OpenFileDialog(); + this.tableLayoutPanel.SuspendLayout(); + this.SuspendLayout(); + // + // tableLayoutPanel + // + this.tableLayoutPanel.ColumnCount = 1; + this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel.Controls.Add(this.textBoxFIO, 0, 0); + this.tableLayoutPanel.Controls.Add(this.myEmailTextBox, 0, 1); + this.tableLayoutPanel.Controls.Add(this.buttonPhoto, 0, 2); + this.tableLayoutPanel.Controls.Add(this.buttonSave, 0, 4); + this.tableLayoutPanel.Controls.Add(this.myCheckListProducts, 0, 3); + this.tableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanel.Name = "tableLayoutPanel"; + this.tableLayoutPanel.Padding = new System.Windows.Forms.Padding(3); + this.tableLayoutPanel.RowCount = 5; + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 47.05882F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 52.94118F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 56F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 310F)); + this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 48F)); + this.tableLayoutPanel.Size = new System.Drawing.Size(363, 517); + this.tableLayoutPanel.TabIndex = 0; + // + // textBoxFIO + // + this.textBoxFIO.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBoxFIO.Location = new System.Drawing.Point(6, 6); + this.textBoxFIO.Name = "textBoxFIO"; + this.textBoxFIO.Size = new System.Drawing.Size(351, 27); + this.textBoxFIO.TabIndex = 0; + this.textBoxFIO.TextChanged += new System.EventHandler(this.textBoxFIO_TextChanged); + // + // myEmailTextBox + // + this.myEmailTextBox.Location = new System.Drawing.Point(6, 52); + this.myEmailTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.myEmailTextBox.Name = "myEmailTextBox"; + this.myEmailTextBox.Pattern = null; + this.myEmailTextBox.Size = new System.Drawing.Size(221, 43); + this.myEmailTextBox.TabIndex = 1; + // + // buttonPhoto + // + this.buttonPhoto.Dock = System.Windows.Forms.DockStyle.Fill; + this.buttonPhoto.Location = new System.Drawing.Point(6, 102); + this.buttonPhoto.Name = "buttonPhoto"; + this.buttonPhoto.Size = new System.Drawing.Size(351, 50); + this.buttonPhoto.TabIndex = 2; + this.buttonPhoto.Text = "Выбрать фото"; + this.buttonPhoto.UseVisualStyleBackColor = true; + this.buttonPhoto.Click += new System.EventHandler(this.buttonPhoto_Click); + // + // buttonSave + // + this.buttonSave.Dock = System.Windows.Forms.DockStyle.Fill; + this.buttonSave.Location = new System.Drawing.Point(6, 468); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(351, 43); + this.buttonSave.TabIndex = 3; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // myCheckListProducts + // + this.myCheckListProducts.AutoSize = true; + this.myCheckListProducts.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.myCheckListProducts.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); + this.myCheckListProducts.Location = new System.Drawing.Point(6, 159); + this.myCheckListProducts.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.myCheckListProducts.Name = "myCheckListProducts"; + this.myCheckListProducts.selectedValue = ""; + this.myCheckListProducts.Size = new System.Drawing.Size(285, 298); + this.myCheckListProducts.TabIndex = 4; + // + // openFileDialogPath + // + this.openFileDialogPath.FileName = "openFileDialog1"; + // + // Client + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(363, 517); + this.Controls.Add(this.tableLayoutPanel); + this.Name = "Client"; + this.Text = "Client"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Client_FormClosing); + this.Load += new System.EventHandler(this.Client_Load); + this.tableLayoutPanel.ResumeLayout(false); + this.tableLayoutPanel.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private TableLayoutPanel tableLayoutPanel; + private TextBox textBoxFIO; + private VisualCompLib.MyEmailTextBox myEmailTextBox; + private Button buttonPhoto; + private Button buttonSave; + private OpenFileDialog openFileDialogPath; + private VisableComponents.MyCheckList myCheckListProducts; + } +} \ No newline at end of file diff --git a/VisEl/ClientForms/Client.cs b/VisEl/ClientForms/Client.cs new file mode 100644 index 0000000..fa102ef --- /dev/null +++ b/VisEl/ClientForms/Client.cs @@ -0,0 +1,173 @@ +using BusinessLogic; +using DataContracts.bindingModels; +using DataContracts.searchModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ClientForms +{ + public partial class Client : Form + { + private readonly ClientBL clientBL = new ClientBL(); + private readonly ProductBL productBL = new ProductBL(); + private int? _id; + private bool fioFlag = false; + private bool emailFlag = false; + private bool photoFlag = false; + private bool EditfioFlag = false; + private bool EditemailFlag = false; + private bool EditphotoFlag = false; + private bool close = false; + private byte[] image; + private List oldProducts = new List(); + public int? Id { get { return _id; } set { _id = value; } } + public Client() + { + InitializeComponent(); + myEmailTextBox.ValueChanged += EmailTextBox_TextChanged; + myEmailTextBox.Pattern = "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$"; + } + + private void Client_Load(object sender, EventArgs e) + { + LoadData(); + if (Id.HasValue) + { + var current_client = clientBL.ReadElement(new ClientSearchModel { Id = Id }); + if(current_client != null) + { + textBoxFIO.Text = current_client.FIO; + myEmailTextBox.TextBoxValue = current_client.email; + image = current_client.photo; + oldProducts = current_client.products.Split(',').ToList(); + buttonPhoto.BackColor = Color.DarkOliveGreen; + myCheckListProducts.setValues(current_client.products.Split(',').ToList()); + EditfioFlag = false; + EditemailFlag = false; + EditphotoFlag = false; + fioFlag = true; + emailFlag = true; + photoFlag = true; + } + } + } + private bool checkProducts() + { + if(oldProducts.Count != myCheckListProducts.getSelectedItems().Count) + return true; + foreach(var oldProd in oldProducts) + { + if(!myCheckListProducts.getSelectedItems().Contains(oldProd)) + return true; + } + return false; + } + private void LoadData() + { + myCheckListProducts.LoadValues(productBL.ReadList().Select(x => x.title).ToList()); + } + private void textBoxFIO_TextChanged(object sender, EventArgs e) + { + EditfioFlag = true; + if (textBoxFIO.Text.Length != 0) + { + fioFlag = true; + textBoxFIO.BackColor = Color.DarkOliveGreen; + } + else + { + fioFlag = false; + textBoxFIO.BackColor = Color.IndianRed; + } + + } + private void EmailTextBox_TextChanged(object sender, EventArgs e) + { + EditemailFlag = true; + if (myEmailTextBox.TextBoxValue != null) + { + emailFlag = true; + myEmailTextBox.BackColor = Color.DarkOliveGreen; + } + else + { + emailFlag = false; + myEmailTextBox.BackColor = Color.IndianRed; + } + } + + private void buttonPhoto_Click(object sender, EventArgs e) + { + EditphotoFlag = true; + if (openFileDialogPath.ShowDialog() == DialogResult.Cancel) + return; + string filename = openFileDialogPath.FileName; + Image img = Image.FromFile(filename); + byte[] bA; + using (MemoryStream mStream = new MemoryStream()) + { + img.Save(mStream, img.RawFormat); + bA = mStream.ToArray(); + } + image = bA; + photoFlag = true; + buttonPhoto.BackColor = Color.DarkOliveGreen; + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if(fioFlag & emailFlag & photoFlag & myCheckListProducts.selectedValuesCount != 0) + { + if(!Id.HasValue) + clientBL.Create(new ClientBindingModel { + FIO = textBoxFIO.Text, + email = myEmailTextBox.TextBoxValue, + photo = image, + products = string.Join(",", myCheckListProducts.getSelectedItems().ToArray()) + }); + else + clientBL.Update(new ClientBindingModel + { + Id = (int)Id, + FIO = textBoxFIO.Text, + email = myEmailTextBox.TextBoxValue, + photo = image, + products = string.Join(",", myCheckListProducts.getSelectedItems()) + }); + close = true; + this.Close(); + } + else + { + MessageBox.Show("Не заполнены поля"); + } + } + + private void Client_FormClosing(object sender, FormClosingEventArgs e) + { + if (close) + { + e.Cancel = false; + return; + } + + if ((EditfioFlag || EditemailFlag || EditphotoFlag || checkProducts())) + { + DialogResult dialogResult = MessageBox.Show("Вы забыли сохранить изменения! Желаете выйти?", "Важно", MessageBoxButtons.YesNo); + if (dialogResult == DialogResult.Yes) + e.Cancel = false; + else + e.Cancel = true; + } + + } + } +} diff --git a/VisEl/ClientForms/Client.resx b/VisEl/ClientForms/Client.resx new file mode 100644 index 0000000..2d70db7 --- /dev/null +++ b/VisEl/ClientForms/Client.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/VisEl/ClientForms/ClientForms.csproj b/VisEl/ClientForms/ClientForms.csproj new file mode 100644 index 0000000..8ed8997 --- /dev/null +++ b/VisEl/ClientForms/ClientForms.csproj @@ -0,0 +1,33 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + \ No newline at end of file diff --git a/VisEl/ClientForms/Main.Designer.cs b/VisEl/ClientForms/Main.Designer.cs new file mode 100644 index 0000000..04b264d --- /dev/null +++ b/VisEl/ClientForms/Main.Designer.cs @@ -0,0 +1,157 @@ +namespace ClientForms +{ + partial class Main + { + /// + /// 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.components = new System.ComponentModel.Container(); + this.controlDataTableTable = new ControlsLibraryNet60.Data.ControlDataTableTable(); + this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); + this.добавитьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.редактироватьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.удалитьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.сохранитьВВордToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.сохранитьВЭксельToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.сохранитьВПдфToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.обновитьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.imageExcel1 = new UnvisableComponents.ImageExcel(this.components); + this.wordTable1 = new VisualCompLib.Components.WordTable(this.components); + this.componentDocumentWithChartBarPdf1 = new ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarPdf(this.components); + this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); + this.contextMenuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // controlDataTableTable + // + this.controlDataTableTable.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.controlDataTableTable.Dock = System.Windows.Forms.DockStyle.Fill; + this.controlDataTableTable.Location = new System.Drawing.Point(0, 0); + this.controlDataTableTable.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.controlDataTableTable.Name = "controlDataTableTable"; + this.controlDataTableTable.SelectedRowIndex = -1; + this.controlDataTableTable.Size = new System.Drawing.Size(800, 450); + this.controlDataTableTable.TabIndex = 0; + // + // contextMenuStrip1 + // + this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); + this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.добавитьToolStripMenuItem, + this.редактироватьToolStripMenuItem, + this.удалитьToolStripMenuItem, + this.сохранитьВВордToolStripMenuItem, + this.сохранитьВЭксельToolStripMenuItem, + this.сохранитьВПдфToolStripMenuItem, + this.обновитьToolStripMenuItem}); + this.contextMenuStrip1.Name = "contextMenuStrip1"; + this.contextMenuStrip1.Size = new System.Drawing.Size(216, 172); + // + // добавитьToolStripMenuItem + // + this.добавитьToolStripMenuItem.Name = "добавитьToolStripMenuItem"; + this.добавитьToolStripMenuItem.Size = new System.Drawing.Size(215, 24); + this.добавитьToolStripMenuItem.Text = "Добавить"; + this.добавитьToolStripMenuItem.Click += new System.EventHandler(this.добавитьToolStripMenuItem_Click); + // + // редактироватьToolStripMenuItem + // + this.редактироватьToolStripMenuItem.Name = "редактироватьToolStripMenuItem"; + this.редактироватьToolStripMenuItem.Size = new System.Drawing.Size(215, 24); + this.редактироватьToolStripMenuItem.Text = "Редактировать"; + this.редактироватьToolStripMenuItem.Click += new System.EventHandler(this.редактироватьToolStripMenuItem_Click); + // + // удалитьToolStripMenuItem + // + this.удалитьToolStripMenuItem.Name = "удалитьToolStripMenuItem"; + this.удалитьToolStripMenuItem.Size = new System.Drawing.Size(215, 24); + this.удалитьToolStripMenuItem.Text = "Удалить"; + this.удалитьToolStripMenuItem.Click += new System.EventHandler(this.удалитьToolStripMenuItem_Click); + // + // сохранитьВВордToolStripMenuItem + // + this.сохранитьВВордToolStripMenuItem.Name = "сохранитьВВордToolStripMenuItem"; + this.сохранитьВВордToolStripMenuItem.Size = new System.Drawing.Size(215, 24); + this.сохранитьВВордToolStripMenuItem.Text = "Сохранить в Ворд"; + this.сохранитьВВордToolStripMenuItem.Click += new System.EventHandler(this.сохранитьВВордToolStripMenuItem_Click); + // + // сохранитьВЭксельToolStripMenuItem + // + this.сохранитьВЭксельToolStripMenuItem.Name = "сохранитьВЭксельToolStripMenuItem"; + this.сохранитьВЭксельToolStripMenuItem.Size = new System.Drawing.Size(215, 24); + this.сохранитьВЭксельToolStripMenuItem.Text = "Сохранить в Эксель"; + this.сохранитьВЭксельToolStripMenuItem.Click += new System.EventHandler(this.сохранитьВЭксельToolStripMenuItem_Click); + // + // сохранитьВПдфToolStripMenuItem + // + this.сохранитьВПдфToolStripMenuItem.Name = "сохранитьВПдфToolStripMenuItem"; + this.сохранитьВПдфToolStripMenuItem.Size = new System.Drawing.Size(215, 24); + this.сохранитьВПдфToolStripMenuItem.Text = "Сохранить в пдф"; + this.сохранитьВПдфToolStripMenuItem.Click += new System.EventHandler(this.сохранитьВПдфToolStripMenuItem_Click); + // + // обновитьToolStripMenuItem + // + this.обновитьToolStripMenuItem.Name = "обновитьToolStripMenuItem"; + this.обновитьToolStripMenuItem.Size = new System.Drawing.Size(215, 24); + this.обновитьToolStripMenuItem.Text = "Обновить"; + this.обновитьToolStripMenuItem.Click += new System.EventHandler(this.обновитьToolStripMenuItem_Click); + // + // openFileDialog1 + // + this.openFileDialog1.FileName = "openFileDialog1"; + // + // Main + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.controlDataTableTable); + this.Name = "Main"; + this.Text = "Main"; + this.Load += new System.EventHandler(this.Main_Load); + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Main_KeyDown); + this.contextMenuStrip1.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private ControlsLibraryNet60.Data.ControlDataTableTable controlDataTableTable; + private ContextMenuStrip contextMenuStrip1; + private ToolStripMenuItem добавитьToolStripMenuItem; + private ToolStripMenuItem редактироватьToolStripMenuItem; + private ToolStripMenuItem удалитьToolStripMenuItem; + private ToolStripMenuItem сохранитьВВордToolStripMenuItem; + private ToolStripMenuItem сохранитьВЭксельToolStripMenuItem; + private ToolStripMenuItem сохранитьВПдфToolStripMenuItem; + private ToolStripMenuItem обновитьToolStripMenuItem; + private UnvisableComponents.ImageExcel imageExcel1; + private VisualCompLib.Components.WordTable wordTable1; + private ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarPdf componentDocumentWithChartBarPdf1; + private OpenFileDialog openFileDialog1; + } +} \ No newline at end of file diff --git a/VisEl/ClientForms/Main.cs b/VisEl/ClientForms/Main.cs new file mode 100644 index 0000000..e5fd76a --- /dev/null +++ b/VisEl/ClientForms/Main.cs @@ -0,0 +1,227 @@ +using BusinessLogic; +using ControlsLibraryNet60.Data; +using ControlsLibraryNet60.Models; +using DataContracts.bindingModels; +using DataContracts.viewModels; +using OfficeOpenXml.LoadFunctions.Params; +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; +using UnvisableComponents; +using VisualCompLib.Components; +using VisualCompLib.Components.SupportClasses; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window; +using VisualCompLib.Object; +using ComponentsLibraryNet60.DocumentWithChart; +using ComponentsLibraryNet60.Models; + +namespace ClientForms +{ + public partial class Main : Form + { + private readonly ClientBL clientBl = new(); + + public Main() + { + InitializeComponent(); + this.KeyPreview = true; + controlDataTableTable.ContextMenuStrip = contextMenuStrip1; + } + + private void Main_Load(object sender, EventArgs e) + { + List columns = new List(); + columns.Add(new DataTableColumnConfig + { + ColumnHeader = "Id", + PropertyName = "Id", + Visible = false + }); + columns.Add(new DataTableColumnConfig + { + ColumnHeader = "ФИО", + PropertyName = "FIO", + Visible = true + }); + columns.Add(new DataTableColumnConfig + { + ColumnHeader = "Почта", + PropertyName = "email", + Visible = true + }); + columns.Add(new DataTableColumnConfig + { + ColumnHeader = "Продукты", + PropertyName = "products", + Visible = true + }); + controlDataTableTable.LoadColumns(columns); + controlDataTableTable.AddTable(clientBl.ReadList()); + + + + } + + private void добавитьToolStripMenuItem_Click(object sender, EventArgs e) + { + Client client = new Client(); + client.Show(); + } + + private void обновитьToolStripMenuItem_Click(object sender, EventArgs e) + { + UpdateTable(); + } + + private void редактироватьToolStripMenuItem_Click(object sender, EventArgs e) + { + var client = controlDataTableTable.GetSelectedObject(); + if (client != null) + { + Client clientForm = new Client(); + clientForm.Id = client.Id; + clientForm.Show(); + } + else + MessageBox.Show("Выберите запись!!"); + UpdateTable(); + } + private void UpdateTable() + { + controlDataTableTable.Clear(); + controlDataTableTable.AddTable(clientBl.ReadList()); + } + + private void удалитьToolStripMenuItem_Click(object sender, EventArgs e) + { + + + var client = controlDataTableTable.GetSelectedObject(); + if (client != null) + { + DialogResult dialogResult = MessageBox.Show("Sure", "Some Title", MessageBoxButtons.YesNo); + if (dialogResult == DialogResult.Yes) + clientBl.Delete(new ClientBindingModel { Id = client.Id }); + } + else + MessageBox.Show("Выберите запись!!"); + UpdateTable(); + + } + + private void сохранитьВВордToolStripMenuItem_Click(object sender, EventArgs e) + { + openFileDialog1.Filter = "Word files (*.docx)|*.docx"; + if (openFileDialog1.ShowDialog() == DialogResult.Cancel) + return; + string filename = openFileDialog1.FileName; + string titleTable = "Клиенты"; + List columnDefinitionsUp = new List { + new ColumnDefinition{Header = "#", PropertyName = "Id", Weight = 30}, + new ColumnDefinition{Header = "Личные данные", PropertyName = "FioEmail", Weight = 30}, + new ColumnDefinition{Header = "", PropertyName = "FioEmail", Weight = 30}, + new ColumnDefinition{Header = "Продукты", PropertyName = "products", Weight = 30}, + }; + List columnDefinitionsDown = new List { + new ColumnDefinition{Header = "#", PropertyName = "Id", Weight = 30}, + new ColumnDefinition{Header = "ФИО", PropertyName = "FIO", Weight = 30}, + new ColumnDefinition{Header = "Почта", PropertyName = "email", Weight = 30}, + new ColumnDefinition{Header = "Продукты", PropertyName = "products", Weight = 30}, + }; + List mergedColums = new() { new int[] { 1, 2 } }; + List clients = clientBl.ReadList(); + BigTable bigTable = new(filename, titleTable, columnDefinitionsUp, columnDefinitionsDown, clients, mergedColums); + wordTable1.CreateTable(bigTable); + MessageBox.Show("Готово"); + } + + private void сохранитьВЭксельToolStripMenuItem_Click(object sender, EventArgs e) + { + openFileDialog1.Filter = "Excel files (*.xlsx)|*.xlsx"; + if (openFileDialog1.ShowDialog() == DialogResult.Cancel) + return; + string filename = openFileDialog1.FileName; + string title = "Отчет о клиентах"; + List bytes = clientBl.ReadList().Select(x => x.photo).ToList(); + ImageInfo info = new ImageInfo(); + info.Title = title; + info.Path = filename; + info.Files = bytes; + imageExcel1.Load(info); + MessageBox.Show("Готово"); + } + + private void сохранитьВПдфToolStripMenuItem_Click(object sender, EventArgs e) + { + System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); + openFileDialog1.Filter = "Pdf files (*.pdf)|*.pdf"; + if (openFileDialog1.ShowDialog() == DialogResult.Cancel) + return; + string filename = openFileDialog1.FileName; + Dictionary> data = new Dictionary>(); + foreach(var item in clientBl.FindDataDiagram()) + { + data.Add( + item.title, + new List<(int Date, double Value)> { (1, item.count) } + ); + + } + componentDocumentWithChartBarPdf1.CreateDoc(new ComponentDocumentWithChartConfig + { + FilePath = filename, + Header = "Категории и клиенты", + ChartTitle = "Соотношение", + LegendLocation = ComponentsLibraryNet60.Models.Location.Bottom, + Data = data + }); + MessageBox.Show("Готово"); + } + + private void Main_KeyDown(object sender, KeyEventArgs e) + { + + if (e.Control && e.KeyCode == Keys.A) + { + добавитьToolStripMenuItem_Click(sender, e); + } + if (e.Control && e.KeyCode == Keys.U) + { + редактироватьToolStripMenuItem_Click(sender, e); + } + if (e.Control && e.KeyCode == Keys.Z) + { + UpdateTable(); + } + if (e.Control && e.KeyCode == Keys.D) + { + удалитьToolStripMenuItem_Click(sender, e); + } + if (e.Control && e.KeyCode == Keys.S) + { + сохранитьВЭксельToolStripMenuItem_Click(sender,e); + } + if (e.Control && e.KeyCode == Keys.T) + { + сохранитьВВордToolStripMenuItem_Click(sender, e); + } + if (e.Control && e.KeyCode == Keys.C) + { + сохранитьВПдфToolStripMenuItem_Click(sender, e); + } + if (e.KeyCode == Keys.Tab) + { + Products products = new(); + products.Show(); + } + + + } + } +} diff --git a/VisEl/ClientForms/Main.resx b/VisEl/ClientForms/Main.resx new file mode 100644 index 0000000..f69c3ab --- /dev/null +++ b/VisEl/ClientForms/Main.resx @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + + 203, 17 + + + 340, 17 + + + 472, 17 + + + 796, 17 + + \ No newline at end of file diff --git a/VisEl/ClientForms/Products.Designer.cs b/VisEl/ClientForms/Products.Designer.cs new file mode 100644 index 0000000..a6d9038 --- /dev/null +++ b/VisEl/ClientForms/Products.Designer.cs @@ -0,0 +1,68 @@ +namespace ClientForms +{ + partial class Products + { + /// + /// 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(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Fill; + this.dataGridView.Location = new System.Drawing.Point(5, 5); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(317, 268); + this.dataGridView.TabIndex = 0; + this.dataGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellEndEdit); + this.dataGridView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Products_KeyDown); + // + // Products + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.ClientSize = new System.Drawing.Size(327, 278); + this.Controls.Add(this.dataGridView); + this.Name = "Products"; + this.Padding = new System.Windows.Forms.Padding(5); + this.Text = "Products"; + this.Load += new System.EventHandler(this.Products_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/VisEl/ClientForms/Products.cs b/VisEl/ClientForms/Products.cs new file mode 100644 index 0000000..d42487e --- /dev/null +++ b/VisEl/ClientForms/Products.cs @@ -0,0 +1,96 @@ +using BusinessLogic; +using DatabaseImplement.models; +using DataContracts.bindingModels; +using DataContracts.viewModels; +using DocumentFormat.OpenXml.Bibliography; +using Microsoft.EntityFrameworkCore.ChangeTracking.Internal; +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 ClientForms +{ + + public partial class Products : Form + { + private readonly ProductBL productBl = new(); + BindingList list ; + public Products() + { + InitializeComponent(); + + + } + public void LoadData() + { + + list = productBl.ReadList() != null ? new BindingList(productBl.ReadList()) : new BindingList(); + dataGridView.DataSource = list; + dataGridView.MultiSelect = false; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["title"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + } + + private void Products_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void Products_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Insert) + { + + dataGridView.Rows[^1].Cells["title"].Selected = true; + dataGridView.BeginEdit(true); + } + if (e.KeyCode == Keys.Delete) + { + if(dataGridView.CurrentCell != null) + { + DialogResult dialogResult = MessageBox.Show("Sure", "Some Title", MessageBoxButtons.YesNo); + if (dialogResult == DialogResult.Yes) + productBl.Delete(new ProductBindingModel { Id = (int)dataGridView.Rows[dataGridView.CurrentCell.RowIndex].Cells["Id"].Value }); + LoadData(); + } + } + } + + private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) + { + if (dataGridView.Rows[e.RowIndex].Cells["title"].Value == null || string.IsNullOrEmpty(dataGridView.Rows[e.RowIndex].Cells["title"].Value.ToString()) ) + { + + return; + } + else + { + if((int)dataGridView.Rows[e.RowIndex].Cells["Id"].Value != 0) + { + productBl.Update(new ProductBindingModel + { + Id = (int)dataGridView.Rows[e.RowIndex].Cells["Id"].Value, + title = dataGridView.Rows[e.RowIndex].Cells["title"].Value.ToString() + }); + } + else + { + productBl.Create(new ProductBindingModel + { + title = dataGridView.Rows[e.RowIndex].Cells["title"].Value.ToString() + }); + + } + LoadData(); + } + + } + } +} diff --git a/VisEl/ClientForms/Products.resx b/VisEl/ClientForms/Products.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/VisEl/ClientForms/Products.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/VisEl/ClientForms/Program.cs b/VisEl/ClientForms/Program.cs new file mode 100644 index 0000000..3797e0d --- /dev/null +++ b/VisEl/ClientForms/Program.cs @@ -0,0 +1,17 @@ +namespace ClientForms +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new Main()); + } + } +} \ No newline at end of file diff --git a/VisEl/DataContracts/BLs/IClientBL.cs b/VisEl/DataContracts/BLs/IClientBL.cs new file mode 100644 index 0000000..751f36e --- /dev/null +++ b/VisEl/DataContracts/BLs/IClientBL.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DataContracts.bindingModels; +using DataContracts.searchModels; +using DataContracts.viewModels; + +namespace DataContracts.BLs +{ + public interface IClientBL + { + List? ReadList(); + ClientViewModel? ReadElement(ClientSearchModel model); + List<(string title, int count)> FindDataDiagram(); + bool Create(ClientBindingModel model); + bool Update(ClientBindingModel model); + bool Delete(ClientBindingModel model); + } +} diff --git a/VisEl/DataContracts/BLs/IProductBL.cs b/VisEl/DataContracts/BLs/IProductBL.cs new file mode 100644 index 0000000..b20af07 --- /dev/null +++ b/VisEl/DataContracts/BLs/IProductBL.cs @@ -0,0 +1,21 @@ + +using DataContracts.bindingModels; +using DataContracts.searchModels; +using DataContracts.viewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataContracts.BLs +{ + public interface IProductBL + { + List? ReadList(); + ProductViewModel? ReadElement(ProductSearchModel model); + bool Create(ProductBindingModel model); + bool Update(ProductBindingModel model); + bool Delete(ProductBindingModel model); + } +} diff --git a/VisEl/DataContracts/DataContracts.csproj b/VisEl/DataContracts/DataContracts.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/VisEl/DataContracts/DataContracts.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/VisEl/DataContracts/bindingModels/ClientBindingModel.cs b/VisEl/DataContracts/bindingModels/ClientBindingModel.cs new file mode 100644 index 0000000..677947b --- /dev/null +++ b/VisEl/DataContracts/bindingModels/ClientBindingModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DataContracts.models; + +namespace DataContracts.bindingModels +{ + public class ClientBindingModel : IClient + { + public int Id { get; set; } + public string FIO { get; set; } = string.Empty; + public byte[] photo { get; set; } + public string email { get; set; } = string.Empty; + public string products { get; set; } = string.Empty; + } +} diff --git a/VisEl/DataContracts/bindingModels/ProductBindingModel.cs b/VisEl/DataContracts/bindingModels/ProductBindingModel.cs new file mode 100644 index 0000000..6b20b7e --- /dev/null +++ b/VisEl/DataContracts/bindingModels/ProductBindingModel.cs @@ -0,0 +1,16 @@ +using DataContracts.models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataContracts.bindingModels +{ + public class ProductBindingModel : IProduct + { + public int Id { get; set; } + + public string title {get; set; } = string.Empty; + } +} diff --git a/VisEl/DataContracts/models/IClient.cs b/VisEl/DataContracts/models/IClient.cs new file mode 100644 index 0000000..8ff039e --- /dev/null +++ b/VisEl/DataContracts/models/IClient.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataContracts.models +{ + public interface IClient + { + public int Id { get; } + public string FIO { get; set; } + public byte[] photo { get; set; } + public string email { get; set; } + public string products { get; set; } + } +} diff --git a/VisEl/DataContracts/models/IProduct.cs b/VisEl/DataContracts/models/IProduct.cs new file mode 100644 index 0000000..06b73bb --- /dev/null +++ b/VisEl/DataContracts/models/IProduct.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataContracts.models +{ + public interface IProduct + { + int Id { get; } + string title { get; set; } + } +} diff --git a/VisEl/DataContracts/searchModels/ClientSearchModel.cs b/VisEl/DataContracts/searchModels/ClientSearchModel.cs new file mode 100644 index 0000000..b46ebe3 --- /dev/null +++ b/VisEl/DataContracts/searchModels/ClientSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataContracts.searchModels +{ + public class ClientSearchModel + { + public int? Id { get; set; } + } +} diff --git a/VisEl/DataContracts/searchModels/ProductSearchModel.cs b/VisEl/DataContracts/searchModels/ProductSearchModel.cs new file mode 100644 index 0000000..e2b8334 --- /dev/null +++ b/VisEl/DataContracts/searchModels/ProductSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataContracts.searchModels +{ + public class ProductSearchModel + { + public int? Id { get; set; } + } +} diff --git a/VisEl/DataContracts/storages/IClientStorage.cs b/VisEl/DataContracts/storages/IClientStorage.cs new file mode 100644 index 0000000..6ccfd46 --- /dev/null +++ b/VisEl/DataContracts/storages/IClientStorage.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DataContracts.bindingModels; +using DataContracts.searchModels; +using DataContracts.viewModels; + +namespace DataContracts.storages +{ + public interface IClientStorage + { + List GetFullList(); + ClientViewModel? GetElement(ClientSearchModel model); + ClientViewModel? Insert(ClientBindingModel model); + ClientViewModel? Update(ClientBindingModel model); + ClientViewModel? Delete(ClientBindingModel model); + } +} diff --git a/VisEl/DataContracts/storages/IProductStorage.cs b/VisEl/DataContracts/storages/IProductStorage.cs new file mode 100644 index 0000000..3ef41fc --- /dev/null +++ b/VisEl/DataContracts/storages/IProductStorage.cs @@ -0,0 +1,20 @@ +using DataContracts.bindingModels; +using DataContracts.searchModels; +using DataContracts.viewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataContracts.storages +{ + public interface IProductStorage + { + List GetFullList(); + ProductViewModel? GetElement(ProductSearchModel model); + ProductViewModel? Insert(ProductBindingModel model); + ProductViewModel? Update(ProductBindingModel model); + ProductViewModel? Delete(ProductBindingModel model); + } +} diff --git a/VisEl/DataContracts/viewModels/ClientViewModel.cs b/VisEl/DataContracts/viewModels/ClientViewModel.cs new file mode 100644 index 0000000..f0b502c --- /dev/null +++ b/VisEl/DataContracts/viewModels/ClientViewModel.cs @@ -0,0 +1,22 @@ +using DataContracts.models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataContracts.viewModels +{ + public class ClientViewModel : IClient + { + public int Id { get; set; } + [DisplayName("ФИО")] + public string FIO { get; set; } = string.Empty; + public byte[] photo { get; set; } + [DisplayName("Почта")] + public string email { get; set; } = string.Empty; + [DisplayName("Категории продуктов")] + public string products { get; set; } = string.Empty; + } +} diff --git a/VisEl/DataContracts/viewModels/ProductViewModel.cs b/VisEl/DataContracts/viewModels/ProductViewModel.cs new file mode 100644 index 0000000..8c57cd1 --- /dev/null +++ b/VisEl/DataContracts/viewModels/ProductViewModel.cs @@ -0,0 +1,18 @@ +using DataContracts.models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataContracts.viewModels +{ + public class ProductViewModel : IProduct + { + public int Id { get; set; } + [DisplayName("Название")] + public string title { get; set; } = string.Empty; + } +} diff --git a/VisEl/DatabaseImplement/AppDataBase.cs b/VisEl/DatabaseImplement/AppDataBase.cs new file mode 100644 index 0000000..7f9f511 --- /dev/null +++ b/VisEl/DatabaseImplement/AppDataBase.cs @@ -0,0 +1,28 @@ +using DatabaseImplement.models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Runtime.ConstrainedExecution; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplement +{ + public class AppDataBase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseNpgsql("Server=PostgreSQL;Host=localhost;Port=5432;Database=ClientsAndProducts;Username=postgres;Password=123456"); + } + base.OnConfiguring(optionsBuilder); + } + + public virtual DbSet Clients { set; get; } + + public virtual DbSet Products { set; get; } + } +} diff --git a/VisEl/DatabaseImplement/DatabaseImplement.csproj b/VisEl/DatabaseImplement/DatabaseImplement.csproj new file mode 100644 index 0000000..fd2564b --- /dev/null +++ b/VisEl/DatabaseImplement/DatabaseImplement.csproj @@ -0,0 +1,22 @@ + + + + net6.0 + enable + enable + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/VisEl/DatabaseImplement/Implements/ClientStorage.cs b/VisEl/DatabaseImplement/Implements/ClientStorage.cs new file mode 100644 index 0000000..29d65c9 --- /dev/null +++ b/VisEl/DatabaseImplement/Implements/ClientStorage.cs @@ -0,0 +1,75 @@ +using DatabaseImplement.models; +using DataContracts.bindingModels; +using DataContracts.searchModels; +using DataContracts.storages; +using DataContracts.viewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplement.Implements +{ + public class ClientStorage : IClientStorage + { + public ClientViewModel? Delete(ClientBindingModel model) + { + using var context = new AppDataBase(); + var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Clients.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public ClientViewModel? GetElement(ClientSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new AppDataBase(); + return context.Clients + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + + public List GetFullList() + { + using var context = new AppDataBase(); + return context.Clients + .Select(x => x.GetViewModel) + .ToList(); + } + + public ClientViewModel? Insert(ClientBindingModel model) + { + var newClient = Client.Create(model); + if (newClient == null) + { + return null; + } + using var context = new AppDataBase(); + context.Clients.Add(newClient); + context.SaveChanges(); + return newClient.GetViewModel; + } + + public ClientViewModel? Update(ClientBindingModel model) + { + using var context = new AppDataBase(); + var client = context.Clients.FirstOrDefault(x => x.Id == model.Id); + if (client == null) + { + return null; + } + client.Update(model); + context.SaveChanges(); + return client.GetViewModel; + } + } +} diff --git a/VisEl/DatabaseImplement/Implements/ProductStorage.cs b/VisEl/DatabaseImplement/Implements/ProductStorage.cs new file mode 100644 index 0000000..bb610c5 --- /dev/null +++ b/VisEl/DatabaseImplement/Implements/ProductStorage.cs @@ -0,0 +1,75 @@ +using DatabaseImplement.models; +using DataContracts.bindingModels; +using DataContracts.searchModels; +using DataContracts.storages; +using DataContracts.viewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplement.Implements +{ + public class ProductStorage : IProductStorage + { + public ProductViewModel? Delete(ProductBindingModel model) + { + using var context = new AppDataBase(); + var element = context.Products.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Products.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public ProductViewModel? GetElement(ProductSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new AppDataBase(); + return context.Products + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + + public List GetFullList() + { + using var context = new AppDataBase(); + return context.Products + .Select(x => x.GetViewModel) + .ToList(); + } + + public ProductViewModel? Insert(ProductBindingModel model) + { + var newProduct = Product.Create(model); + if (newProduct == null) + { + return null; + } + using var context = new AppDataBase(); + context.Products.Add(newProduct); + context.SaveChanges(); + return newProduct.GetViewModel; + } + + public ProductViewModel? Update(ProductBindingModel model) + { + using var context = new AppDataBase(); + var product = context.Products.FirstOrDefault(x => x.Id == model.Id); + if (product == null) + { + return null; + } + product.Update(model); + context.SaveChanges(); + return product.GetViewModel; + } + } +} diff --git a/VisEl/DatabaseImplement/Migrations/20231025110458_initial.Designer.cs b/VisEl/DatabaseImplement/Migrations/20231025110458_initial.Designer.cs new file mode 100644 index 0000000..16ddeb6 --- /dev/null +++ b/VisEl/DatabaseImplement/Migrations/20231025110458_initial.Designer.cs @@ -0,0 +1,75 @@ +// +using DatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + [DbContext(typeof(AppDataBase))] + [Migration("20231025110458_initial")] + partial class initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.13") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("DatabaseImplement.models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("FIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("email") + .IsRequired() + .HasColumnType("text"); + + b.Property("photo") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("products") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("DatabaseImplement.models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("title") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Products"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/VisEl/DatabaseImplement/Migrations/20231025110458_initial.cs b/VisEl/DatabaseImplement/Migrations/20231025110458_initial.cs new file mode 100644 index 0000000..961fa73 --- /dev/null +++ b/VisEl/DatabaseImplement/Migrations/20231025110458_initial.cs @@ -0,0 +1,54 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + /// + public partial class initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + FIO = table.Column(type: "text", nullable: false), + photo = table.Column(type: "bytea", nullable: false), + email = table.Column(type: "text", nullable: false), + products = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Products", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + title = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Products", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropTable( + name: "Products"); + } + } +} diff --git a/VisEl/DatabaseImplement/Migrations/20231025152005_initial2.Designer.cs b/VisEl/DatabaseImplement/Migrations/20231025152005_initial2.Designer.cs new file mode 100644 index 0000000..2b5bd1f --- /dev/null +++ b/VisEl/DatabaseImplement/Migrations/20231025152005_initial2.Designer.cs @@ -0,0 +1,75 @@ +// +using DatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + [DbContext(typeof(AppDataBase))] + [Migration("20231025152005_initial2")] + partial class initial2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.13") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("DatabaseImplement.models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("FIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("email") + .IsRequired() + .HasColumnType("text"); + + b.Property("photo") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("products") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("DatabaseImplement.models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("title") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Products"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/VisEl/DatabaseImplement/Migrations/20231025152005_initial2.cs b/VisEl/DatabaseImplement/Migrations/20231025152005_initial2.cs new file mode 100644 index 0000000..c893877 --- /dev/null +++ b/VisEl/DatabaseImplement/Migrations/20231025152005_initial2.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + /// + public partial class initial2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/VisEl/DatabaseImplement/Migrations/AppDataBaseModelSnapshot.cs b/VisEl/DatabaseImplement/Migrations/AppDataBaseModelSnapshot.cs new file mode 100644 index 0000000..9ba383e --- /dev/null +++ b/VisEl/DatabaseImplement/Migrations/AppDataBaseModelSnapshot.cs @@ -0,0 +1,72 @@ +// +using DatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + [DbContext(typeof(AppDataBase))] + partial class AppDataBaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.13") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("DatabaseImplement.models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("FIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("email") + .IsRequired() + .HasColumnType("text"); + + b.Property("photo") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("products") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("DatabaseImplement.models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("title") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Products"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/VisEl/DatabaseImplement/models/Client.cs b/VisEl/DatabaseImplement/models/Client.cs new file mode 100644 index 0000000..48d2132 --- /dev/null +++ b/VisEl/DatabaseImplement/models/Client.cs @@ -0,0 +1,51 @@ +using DataContracts.bindingModels; +using DataContracts.models; +using DataContracts.viewModels; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Reflection; + +namespace DatabaseImplement.models +{ + public class Client : IClient + { + public int Id { get; set; } + [Required] + public string FIO { get; set; } = string.Empty; + [Required] + public byte[] photo { get; set; } = new byte[0]; + [Required] + public string email { get; set; } = string.Empty; + public string products { get; set; } = string.Empty; + + public static Client Create(ClientBindingModel model) + { + return new Client() + { + Id = model.Id, + FIO = model.FIO, + photo = model.photo, + email = model.email, + products = model.products + }; + } + + public void Update(ClientBindingModel model) + { + FIO = model.FIO; + email = model.email; + photo = model.photo; + products = model.products; + } + + public ClientViewModel GetViewModel => new() + { + Id = Id, + FIO = FIO, + photo = photo, + email = email, + products = products + }; + + } +} \ No newline at end of file diff --git a/VisEl/DatabaseImplement/models/Product.cs b/VisEl/DatabaseImplement/models/Product.cs new file mode 100644 index 0000000..d4f86eb --- /dev/null +++ b/VisEl/DatabaseImplement/models/Product.cs @@ -0,0 +1,40 @@ +using DataContracts.bindingModels; +using DataContracts.models; +using DataContracts.viewModels; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplement.models +{ + public class Product : IProduct + { + public int Id { get; set; } + [Required] + public string title { get; set; } = string.Empty; + public static Product Create(ProductBindingModel model) + { + return new Product() + { + Id = model.Id, + title = model.title + }; + } + + public void Update(ProductBindingModel model) + { + title = model.title; + } + + public ProductViewModel GetViewModel => new() + { + Id = Id, + title = title, + + }; + + } +} diff --git a/VisEl/KOP.sln b/VisEl/KOP.sln index 992dd22..83700b1 100644 --- a/VisEl/KOP.sln +++ b/VisEl/KOP.sln @@ -3,11 +3,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32825.248 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnvisableComponents", "UnvisableComponents\UnvisableComponents.csproj", "{B720A881-1A22-48BB-B0C6-23F616E6D10D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnvisableComponents", "UnvisableComponents\UnvisableComponents.csproj", "{B720A881-1A22-48BB-B0C6-23F616E6D10D}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestForm", "TestForm\TestForm.csproj", "{53DEA306-E3B4-4662-A337-7076CF636F6A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VisableComponents", "VisableComponents\VisableComponents.csproj", "{B0E42147-22BB-4B22-AB76-3C7DB2BF5353}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VisableComponents", "VisableComponents\VisableComponents.csproj", "{B0E42147-22BB-4B22-AB76-3C7DB2BF5353}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataContracts", "DataContracts\DataContracts.csproj", "{F0B8E9FD-AAEF-4F1A-87E5-4361F22BA00A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DatabaseImplement", "DatabaseImplement\DatabaseImplement.csproj", "{AE492748-D76A-40D0-B3B0-FAE321F6DA91}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BusinessLogic", "BusinessLogic\BusinessLogic.csproj", "{5CA23F59-94F6-4A49-B114-F9B1A3D147CB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientForms", "ClientForms\ClientForms.csproj", "{A1EE2F68-9359-4377-AFDB-3223F6DF5F40}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -27,6 +35,22 @@ Global {B0E42147-22BB-4B22-AB76-3C7DB2BF5353}.Debug|Any CPU.Build.0 = Debug|Any CPU {B0E42147-22BB-4B22-AB76-3C7DB2BF5353}.Release|Any CPU.ActiveCfg = Release|Any CPU {B0E42147-22BB-4B22-AB76-3C7DB2BF5353}.Release|Any CPU.Build.0 = Release|Any CPU + {F0B8E9FD-AAEF-4F1A-87E5-4361F22BA00A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F0B8E9FD-AAEF-4F1A-87E5-4361F22BA00A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F0B8E9FD-AAEF-4F1A-87E5-4361F22BA00A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F0B8E9FD-AAEF-4F1A-87E5-4361F22BA00A}.Release|Any CPU.Build.0 = Release|Any CPU + {AE492748-D76A-40D0-B3B0-FAE321F6DA91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AE492748-D76A-40D0-B3B0-FAE321F6DA91}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AE492748-D76A-40D0-B3B0-FAE321F6DA91}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AE492748-D76A-40D0-B3B0-FAE321F6DA91}.Release|Any CPU.Build.0 = Release|Any CPU + {5CA23F59-94F6-4A49-B114-F9B1A3D147CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5CA23F59-94F6-4A49-B114-F9B1A3D147CB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5CA23F59-94F6-4A49-B114-F9B1A3D147CB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5CA23F59-94F6-4A49-B114-F9B1A3D147CB}.Release|Any CPU.Build.0 = Release|Any CPU + {A1EE2F68-9359-4377-AFDB-3223F6DF5F40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A1EE2F68-9359-4377-AFDB-3223F6DF5F40}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A1EE2F68-9359-4377-AFDB-3223F6DF5F40}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A1EE2F68-9359-4377-AFDB-3223F6DF5F40}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/VisEl/TestForm/Form1.cs b/VisEl/TestForm/Form1.cs index 673b415..3f1dcd6 100644 --- a/VisEl/TestForm/Form1.cs +++ b/VisEl/TestForm/Form1.cs @@ -31,7 +31,6 @@ namespace TestForm comboBox1.Items.AddRange(typeof(Sportsmen).GetProperties().Select(x => x.Name).ToArray()); myTextBoxDate.DateMax = new DateTime(2019, 12, 1); myTextBoxDate.DateMin = new DateTime(2012, 12, 1); - newCheckList1.ValueChanged += CustomEvent_Handler; myTextBoxDate.ValueChanged += CustomEvent_HandlerDate; } diff --git a/VisEl/TestForm/Lab2.cs b/VisEl/TestForm/Lab2.cs index 184219b..3a53ff7 100644 --- a/VisEl/TestForm/Lab2.cs +++ b/VisEl/TestForm/Lab2.cs @@ -17,7 +17,7 @@ namespace TestForm { ImageInfo info; - List files; + List files; string[] names = { "Vova M", "Sasha A", "Dima D", "Danila L" }; string[] sports = { "Run", "Swim", "Cycle", "Race", "Box" }; string[] cities = { "Moskow", "Samara", "Piter", "Kazan", "Kyrsk" }; @@ -28,7 +28,7 @@ namespace TestForm { InitializeComponent(); info = new ImageInfo(); - files = new List(); + files = new List(); } private void buttonOne_Click(object sender, EventArgs e) @@ -57,7 +57,14 @@ namespace TestForm if (openFileDialogPath.ShowDialog() == DialogResult.Cancel) return; string filename = openFileDialogPath.FileName; - files.Add(filename); + Image img = Image.FromFile(filename); + byte[] bA; + using (MemoryStream mStream = new MemoryStream()) + { + img.Save(mStream, img.RawFormat); + bA = mStream.ToArray(); + } + files.Add(bA); labelTakenImages.Text +=" " + openFileDialogPath.FileName; MessageBox.Show("Файл открыт"); } diff --git a/VisEl/UnvisableComponents/ImageExcel.cs b/VisEl/UnvisableComponents/ImageExcel.cs index b18cef6..e7a3551 100644 --- a/VisEl/UnvisableComponents/ImageExcel.cs +++ b/VisEl/UnvisableComponents/ImageExcel.cs @@ -47,8 +47,8 @@ namespace UnvisableComponents foreach(var image in info.Files) { ExcelPicture excelImage = null; - - excelImage = worksheet.Drawings.AddPicture("image" + i, image); + Stream stream = new MemoryStream(image); + excelImage = worksheet.Drawings.AddPicture("image" + i, stream); excelImage.SetPosition(posString, 0, posColumn, 0); excelImage.SetSize(100, 100); i++; diff --git a/VisEl/UnvisableComponents/ImageInfo.cs b/VisEl/UnvisableComponents/ImageInfo.cs index ab9c28e..5baf974 100644 --- a/VisEl/UnvisableComponents/ImageInfo.cs +++ b/VisEl/UnvisableComponents/ImageInfo.cs @@ -10,10 +10,10 @@ namespace UnvisableComponents { private string path; private string title; - private List files; + private List files; public string Path { get { return path; } set { path = value; } } public string Title { get { return title; } set { title = value; } } - public List Files { get { return files; } set { files = value; } } + public List Files { get { return files; } set { files = value; } } public ImageInfo() { } } } diff --git a/VisEl/UnvisableComponents/UnvisableComponents.csproj b/VisEl/UnvisableComponents/UnvisableComponents.csproj index c1bcc13..495d326 100644 --- a/VisEl/UnvisableComponents/UnvisableComponents.csproj +++ b/VisEl/UnvisableComponents/UnvisableComponents.csproj @@ -5,6 +5,7 @@ enable true enable + True @@ -16,7 +17,7 @@ - + diff --git a/VisEl/VisableComponents/MyCheckList.cs b/VisEl/VisableComponents/MyCheckList.cs index 8c071e6..d451cb1 100644 --- a/VisEl/VisableComponents/MyCheckList.cs +++ b/VisEl/VisableComponents/MyCheckList.cs @@ -50,6 +50,33 @@ namespace VisableComponents checkedList.Items[checkedList.SelectedIndex] = value; } } + public int selectedValuesCount + { + get + { + if (checkedList.CheckedItems != null) + return checkedList.CheckedItems.Count; + return 0; + } + + } + public void setValues(List Values) + { + foreach(string Value in Values) + if(checkedList.Items.Contains(Value)) + checkedList.SetItemCheckState(checkedList.Items.IndexOf(Value), CheckState.Checked); + } + public List getSelectedItems() + { + List values = new List(); + if (checkedList.CheckedItems != null) + { + foreach(var item in checkedList.CheckedItems) + values.Add(item.ToString()); + return values; + } + return null; + } private void checkedList_ItemCheck(object sender, ItemCheckEventArgs e) { diff --git a/VisEl/VisableComponents/MyTreeView.Designer.cs b/VisEl/VisableComponents/MyTreeView.Designer.cs index 1fb9ca5..31bb335 100644 --- a/VisEl/VisableComponents/MyTreeView.Designer.cs +++ b/VisEl/VisableComponents/MyTreeView.Designer.cs @@ -33,21 +33,24 @@ // // treeView // - this.treeView.Location = new System.Drawing.Point(3, 3); + this.treeView.Dock = System.Windows.Forms.DockStyle.Fill; + this.treeView.Location = new System.Drawing.Point(0, 0); + this.treeView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.treeView.Name = "treeView"; - this.treeView.Size = new System.Drawing.Size(421, 397); + this.treeView.Size = new System.Drawing.Size(600, 600); this.treeView.TabIndex = 0; // // MyTreeView // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.AutoSize = true; this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.BackColor = System.Drawing.SystemColors.ControlDark; this.Controls.Add(this.treeView); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.MinimumSize = new System.Drawing.Size(200, 200); this.Name = "MyTreeView"; - this.Size = new System.Drawing.Size(427, 403); + this.Size = new System.Drawing.Size(600, 600); this.ResumeLayout(false); } diff --git a/VisEl/VisableComponents/MyTreeView.resx b/VisEl/VisableComponents/MyTreeView.resx index 1af7de1..f298a7b 100644 --- a/VisEl/VisableComponents/MyTreeView.resx +++ b/VisEl/VisableComponents/MyTreeView.resx @@ -1,64 +1,4 @@ - - - + diff --git a/VisEl/VisableComponents/VisableComponents.csproj b/VisEl/VisableComponents/VisableComponents.csproj index 13138fe..141ec7e 100644 --- a/VisEl/VisableComponents/VisableComponents.csproj +++ b/VisEl/VisableComponents/VisableComponents.csproj @@ -1,10 +1,12 @@  + 1.0.8 net6.0-windows enable true enable + True