From c65bcbb7921994f8a9f25f7e97b75f6f3c9cf79a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=90=D0=BB=D0=B5=D0=B9?= =?UTF-8?q?=D0=BA=D0=B8=D0=BD?= Date: Thu, 30 Nov 2023 00:36:01 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9E=D1=81=D1=82=D0=B0=D0=BB=D1=81=D1=8F=20pd?= =?UTF-8?q?f=20=D0=B8=20excel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WinFormsProject/AppView/AppView.csproj | 4 + WinFormsProject/AppView/Form1.Designer.cs | 39 ---- WinFormsProject/AppView/Form1.cs | 10 - WinFormsProject/AppView/Form1.resx | 120 ---------- WinFormsProject/AppView/FormMain.Designer.cs | 142 ++++++++++++ WinFormsProject/AppView/FormMain.cs | 154 +++++++++++++ WinFormsProject/AppView/FormMain.resx | 66 ++++++ .../AppView/FormProvider.Designer.cs | 207 ++++++++++++++++++ WinFormsProject/AppView/FormProvider.cs | 186 ++++++++++++++++ WinFormsProject/AppView/FormProvider.resx | 63 ++++++ WinFormsProject/AppView/FormType.Designer.cs | 65 ++++++ WinFormsProject/AppView/FormType.cs | 138 ++++++++++++ WinFormsProject/AppView/FormType.resx | 60 +++++ WinFormsProject/AppView/Program.cs | 20 +- .../WinFormsLibrary/DocumentWithImage.cs | 142 ++++++------ .../SupportClasses/ImageClass.cs | 6 +- 16 files changed, 1175 insertions(+), 247 deletions(-) delete mode 100644 WinFormsProject/AppView/Form1.Designer.cs delete mode 100644 WinFormsProject/AppView/Form1.cs delete mode 100644 WinFormsProject/AppView/Form1.resx create mode 100644 WinFormsProject/AppView/FormMain.Designer.cs create mode 100644 WinFormsProject/AppView/FormMain.cs create mode 100644 WinFormsProject/AppView/FormMain.resx create mode 100644 WinFormsProject/AppView/FormProvider.Designer.cs create mode 100644 WinFormsProject/AppView/FormProvider.cs create mode 100644 WinFormsProject/AppView/FormProvider.resx create mode 100644 WinFormsProject/AppView/FormType.Designer.cs create mode 100644 WinFormsProject/AppView/FormType.cs create mode 100644 WinFormsProject/AppView/FormType.resx diff --git a/WinFormsProject/AppView/AppView.csproj b/WinFormsProject/AppView/AppView.csproj index b85039e..ec28f5f 100644 --- a/WinFormsProject/AppView/AppView.csproj +++ b/WinFormsProject/AppView/AppView.csproj @@ -9,14 +9,18 @@ + + all runtime; build; native; contentfiles; analyzers; buildtransitive + + \ No newline at end of file diff --git a/WinFormsProject/AppView/Form1.Designer.cs b/WinFormsProject/AppView/Form1.Designer.cs deleted file mode 100644 index 1b9a8ab..0000000 --- a/WinFormsProject/AppView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace AppView -{ - partial class Form1 - { - /// - /// 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.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/WinFormsProject/AppView/Form1.cs b/WinFormsProject/AppView/Form1.cs deleted file mode 100644 index c023e9d..0000000 --- a/WinFormsProject/AppView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace AppView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/WinFormsProject/AppView/Form1.resx b/WinFormsProject/AppView/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/WinFormsProject/AppView/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/WinFormsProject/AppView/FormMain.Designer.cs b/WinFormsProject/AppView/FormMain.Designer.cs new file mode 100644 index 0000000..4db6094 --- /dev/null +++ b/WinFormsProject/AppView/FormMain.Designer.cs @@ -0,0 +1,142 @@ +namespace AppView +{ + partial class FormMain + { + /// + /// 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.dataTable = 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.сформирироватьWordToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.сформироватьPdfToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.сформироватьExcelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.documentWithImage1 = new WinFormsLibrary.DocumentWithImage(this.components); + this.contextMenuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // dataTable + // + this.dataTable.Location = new System.Drawing.Point(13, 12); + this.dataTable.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.dataTable.Name = "dataTable"; + this.dataTable.SelectedRowIndex = -1; + this.dataTable.Size = new System.Drawing.Size(774, 426); + this.dataTable.TabIndex = 0; + // + // contextMenuStrip1 + // + this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.создатьToolStripMenuItem, + this.изменитьToolStripMenuItem, + this.удалитьToolStripMenuItem, + this.справочникToolStripMenuItem, + this.сформирироватьWordToolStripMenuItem, + this.сформироватьPdfToolStripMenuItem, + this.сформироватьExcelToolStripMenuItem}); + this.contextMenuStrip1.Name = "contextMenuStrip1"; + this.contextMenuStrip1.Size = new System.Drawing.Size(205, 180); + // + // создатьToolStripMenuItem + // + this.создатьToolStripMenuItem.Name = "создатьToolStripMenuItem"; + this.создатьToolStripMenuItem.Size = new System.Drawing.Size(204, 22); + this.создатьToolStripMenuItem.Text = "Создать"; + this.создатьToolStripMenuItem.Click += new System.EventHandler(this.создатьToolStripMenuItem_Click); + // + // изменитьToolStripMenuItem + // + this.изменитьToolStripMenuItem.Name = "изменитьToolStripMenuItem"; + this.изменитьToolStripMenuItem.Size = new System.Drawing.Size(204, 22); + this.изменитьToolStripMenuItem.Text = "Изменить"; + this.изменитьToolStripMenuItem.Click += new System.EventHandler(this.изменитьToolStripMenuItem_Click); + // + // удалитьToolStripMenuItem + // + this.удалитьToolStripMenuItem.Name = "удалитьToolStripMenuItem"; + this.удалитьToolStripMenuItem.Size = new System.Drawing.Size(204, 22); + this.удалитьToolStripMenuItem.Text = "Удалить"; + this.удалитьToolStripMenuItem.Click += new System.EventHandler(this.удалитьToolStripMenuItem_Click); + // + // справочникToolStripMenuItem + // + this.справочникToolStripMenuItem.Name = "справочникToolStripMenuItem"; + this.справочникToolStripMenuItem.Size = new System.Drawing.Size(204, 22); + this.справочникToolStripMenuItem.Text = "Справочник"; + this.справочникToolStripMenuItem.Click += new System.EventHandler(this.справочникToolStripMenuItem_Click); + // + // сформирироватьWordToolStripMenuItem + // + this.сформирироватьWordToolStripMenuItem.Name = "сформирироватьWordToolStripMenuItem"; + this.сформирироватьWordToolStripMenuItem.Size = new System.Drawing.Size(204, 22); + this.сформирироватьWordToolStripMenuItem.Text = "Сформирировать Word"; + this.сформирироватьWordToolStripMenuItem.Click += new System.EventHandler(this.сформирироватьWordToolStripMenuItem_Click); + // + // сформироватьPdfToolStripMenuItem + // + this.сформироватьPdfToolStripMenuItem.Name = "сформироватьPdfToolStripMenuItem"; + this.сформироватьPdfToolStripMenuItem.Size = new System.Drawing.Size(204, 22); + this.сформироватьPdfToolStripMenuItem.Text = "Сформировать Pdf"; + this.сформироватьPdfToolStripMenuItem.Click += new System.EventHandler(this.сформироватьPdfToolStripMenuItem_Click); + // + // сформироватьExcelToolStripMenuItem + // + this.сформироватьExcelToolStripMenuItem.Name = "сформироватьExcelToolStripMenuItem"; + this.сформироватьExcelToolStripMenuItem.Size = new System.Drawing.Size(204, 22); + this.сформироватьExcelToolStripMenuItem.Text = "Сформировать Excel"; + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.dataTable); + this.Name = "FormMain"; + this.Text = "Главная форма"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.contextMenuStrip1.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private ControlsLibraryNet60.Data.ControlDataTableTable dataTable; + private ContextMenuStrip contextMenuStrip1; + private ToolStripMenuItem создатьToolStripMenuItem; + private ToolStripMenuItem изменитьToolStripMenuItem; + private ToolStripMenuItem удалитьToolStripMenuItem; + private ToolStripMenuItem справочникToolStripMenuItem; + private ToolStripMenuItem сформирироватьWordToolStripMenuItem; + private ToolStripMenuItem сформироватьPdfToolStripMenuItem; + private ToolStripMenuItem сформироватьExcelToolStripMenuItem; + private WinFormsLibrary.DocumentWithImage documentWithImage1; + } +} \ No newline at end of file diff --git a/WinFormsProject/AppView/FormMain.cs b/WinFormsProject/AppView/FormMain.cs new file mode 100644 index 0000000..6d1142e --- /dev/null +++ b/WinFormsProject/AppView/FormMain.cs @@ -0,0 +1,154 @@ +using Contracts.StorageContracts; +using Contracts.ViewModels; +using ControlsLibraryNet60.Data; +using ControlsLibraryNet60.Models; +using DocumentFormat.OpenXml.Drawing.Charts; +using System.ComponentModel; +using WinFormsLibrary; +using WinFormsLibrary.SupportClasses; + +namespace AppView +{ + public partial class FormMain : Form + { + private readonly IProviderStorage _providerStorage; + private readonly ITypeStorage _typeStorage; + + public FormMain(IProviderStorage providerStorage, ITypeStorage typeStorage) + { + InitializeComponent(); + + _providerStorage = providerStorage; + _typeStorage = typeStorage; + + ContextMenuStrip = contextMenuStrip1; + + List columns = new List() + { + new DataTableColumnConfig + { + ColumnHeader = "Id", + PropertyName = "Id", + Visible = false + }, + new DataTableColumnConfig + { + ColumnHeader = "", + PropertyName = "Name", + Visible = true + }, + new DataTableColumnConfig + { + ColumnHeader = " ", + PropertyName = "Type", + Visible = true + }, + new DataTableColumnConfig + { + ColumnHeader = "", + PropertyName = "Number", + Visible = true + } + }; + dataTable.LoadColumns(columns); + } + + private void LoadData() + { + var list = _providerStorage.GetFullList(); + dataTable.Clear(); + dataTable.AddTable(list); + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormProvider)); + if (!(service is FormProvider form)) return; + if (form.ShowDialog() == DialogResult.OK) LoadData(); + } + + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + if (dataTable.GetSelectedObject() == null) + { + return; + } + else + { + var service = Program.ServiceProvider?.GetService(typeof(FormProvider)); + if (service is FormProvider form) + { + form.Id = Convert.ToInt32(dataTable.GetSelectedObject()?.Id); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + + if (dataTable.GetSelectedObject() == null) return; + if (MessageBox.Show( + " ?", + "", + MessageBoxButtons.YesNo, + MessageBoxIcon.Question) == DialogResult.Yes) + { + _providerStorage.Delete(new(dataTable.GetSelectedObject())); + LoadData(); + } + } + + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormType)); + if (service is FormType form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void toolStripButton1_Click(object sender, EventArgs e) + { + + } + + private void WordToolStripMenuItem_Click(object sender, EventArgs e) + { + string fileName = ""; + using (var dialog = new SaveFileDialog { Filter = "docx|*.docx" }) + { + if (dialog.ShowDialog() == DialogResult.OK) + { + fileName = dialog.FileName.ToString(); + MessageBox.Show("", "", MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + } + + ImageClass info = new ImageClass(); + + var images = _providerStorage.GetFullList().Select(x => x.Logo).ToList(); + + info.Title = "Images"; + info.Path = fileName; + info.Files = images; + + documentWithImage1.CreateDocument(info); + } + + private void PdfToolStripMenuItem_Click(object sender, EventArgs e) + { + + } + } +} \ No newline at end of file diff --git a/WinFormsProject/AppView/FormMain.resx b/WinFormsProject/AppView/FormMain.resx new file mode 100644 index 0000000..f8d595d --- /dev/null +++ b/WinFormsProject/AppView/FormMain.resx @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 172, 17 + + \ No newline at end of file diff --git a/WinFormsProject/AppView/FormProvider.Designer.cs b/WinFormsProject/AppView/FormProvider.Designer.cs new file mode 100644 index 0000000..233e8e5 --- /dev/null +++ b/WinFormsProject/AppView/FormProvider.Designer.cs @@ -0,0 +1,207 @@ +namespace AppView +{ + partial class FormProvider + { + /// + /// 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.labelName = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelLogo = new System.Windows.Forms.Label(); + this.textBoxNumber = new System.Windows.Forms.TextBox(); + this.labelType = new System.Windows.Forms.Label(); + this.labelNumber = new System.Windows.Forms.Label(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.dropDownList1 = new WinForm.DropDownList(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonType = new System.Windows.Forms.Button(); + this.buttonImage = new System.Windows.Forms.Button(); + this.ImgFile = new System.Windows.Forms.OpenFileDialog(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 9); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(59, 15); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(12, 27); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(239, 23); + this.textBoxName.TabIndex = 1; + this.textBoxName.TabStop = false; + this.textBoxName.TextChanged += new System.EventHandler(this.OnInputChange); + // + // labelLogo + // + this.labelLogo.AutoSize = true; + this.labelLogo.Location = new System.Drawing.Point(12, 59); + this.labelLogo.Name = "labelLogo"; + this.labelLogo.Size = new System.Drawing.Size(53, 15); + this.labelLogo.TabIndex = 2; + this.labelLogo.Text = "Логотип"; + // + // textBoxNumber + // + this.textBoxNumber.Location = new System.Drawing.Point(12, 424); + this.textBoxNumber.Name = "textBoxNumber"; + this.textBoxNumber.Size = new System.Drawing.Size(239, 23); + this.textBoxNumber.TabIndex = 4; + this.textBoxNumber.TabStop = false; + this.textBoxNumber.TextChanged += new System.EventHandler(this.OnInputChange); + // + // labelType + // + this.labelType.AutoSize = true; + this.labelType.Location = new System.Drawing.Point(12, 307); + this.labelType.Name = "labelType"; + this.labelType.Size = new System.Drawing.Size(75, 15); + this.labelType.TabIndex = 5; + this.labelType.Text = "Тип изделий"; + // + // labelNumber + // + this.labelNumber.AutoSize = true; + this.labelNumber.Location = new System.Drawing.Point(12, 406); + this.labelNumber.Name = "labelNumber"; + this.labelNumber.Size = new System.Drawing.Size(101, 15); + this.labelNumber.TabIndex = 6; + this.labelNumber.Text = "Номер телефона"; + // + // pictureBox1 + // + this.pictureBox1.Location = new System.Drawing.Point(12, 77); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(239, 159); + this.pictureBox1.TabIndex = 7; + this.pictureBox1.TabStop = false; + // + // dropDownList1 + // + this.dropDownList1.Location = new System.Drawing.Point(12, 325); + this.dropDownList1.Name = "dropDownList1"; + this.dropDownList1.Selected = ""; + this.dropDownList1.Size = new System.Drawing.Size(239, 30); + this.dropDownList1.TabIndex = 8; + this.dropDownList1.TabStop = false; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(38, 471); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 9; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(146, 471); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 10; + this.buttonCancel.Text = "Отменить"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // buttonType + // + this.buttonType.Location = new System.Drawing.Point(109, 361); + this.buttonType.Name = "buttonType"; + this.buttonType.Size = new System.Drawing.Size(142, 23); + this.buttonType.TabIndex = 11; + this.buttonType.TabStop = false; + this.buttonType.Text = "Редактировать типы"; + this.buttonType.UseVisualStyleBackColor = true; + this.buttonType.Click += new System.EventHandler(this.buttonType_Click); + // + // buttonImage + // + this.buttonImage.Location = new System.Drawing.Point(109, 242); + this.buttonImage.Name = "buttonImage"; + this.buttonImage.Size = new System.Drawing.Size(142, 23); + this.buttonImage.TabIndex = 12; + this.buttonImage.TabStop = false; + this.buttonImage.Text = "Загрузить картинку"; + this.buttonImage.UseVisualStyleBackColor = true; + this.buttonImage.Click += new System.EventHandler(this.buttonImage_Click); + // + // ImgFile + // + this.ImgFile.FileName = "openFileDialog1"; + // + // FormProvider + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(263, 509); + this.Controls.Add(this.buttonImage); + this.Controls.Add(this.buttonType); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.dropDownList1); + this.Controls.Add(this.pictureBox1); + this.Controls.Add(this.labelNumber); + this.Controls.Add(this.labelType); + this.Controls.Add(this.textBoxNumber); + this.Controls.Add(this.labelLogo); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Name = "FormProvider"; + this.Text = "FormProvider"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormProvider_FormClosing); + this.Load += new System.EventHandler(this.FormProvider_Load); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private Label labelLogo; + private TextBox textBoxNumber; + private Label labelType; + private Label labelNumber; + private PictureBox pictureBox1; + private WinForm.DropDownList dropDownList1; + private Button buttonSave; + private Button buttonCancel; + private Button buttonType; + private Button buttonImage; + private OpenFileDialog ImgFile; + } +} \ No newline at end of file diff --git a/WinFormsProject/AppView/FormProvider.cs b/WinFormsProject/AppView/FormProvider.cs new file mode 100644 index 0000000..0564c83 --- /dev/null +++ b/WinFormsProject/AppView/FormProvider.cs @@ -0,0 +1,186 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.StorageContracts; +using DocumentFormat.OpenXml.Vml; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Windows.Forms; +using WinForm; + +namespace AppView +{ + public partial class FormProvider : Form + { + private int? _id; + public int Id { set { _id = value; } } + public readonly IProviderStorage _providerStorage; + public readonly ITypeStorage _typeStorage; + private bool isEdited; + private byte[] _logo = new byte[0]; + + public FormProvider(IProviderStorage providerStorage, ITypeStorage typeStorage) + { + _providerStorage = providerStorage; + _typeStorage = typeStorage; + isEdited = false; + + InitializeComponent(); + } + + private Image byteArrayToImage(byte[] byteArrayIn) + { + Image res = null; + try + { + MemoryStream ms = new MemoryStream(byteArrayIn, 0, byteArrayIn.Length); + ms.Write(byteArrayIn, 0, byteArrayIn.Length); + res = Image.FromStream(ms, true);//Exception occurs here + } + catch { } + return res; + } + + private void FormProvider_Load(object sender, EventArgs e) + { + dropDownList1.ExplicitEvent += OnInputChange; + LoadData(); + if (_id.HasValue) + { + try + { + var element = _providerStorage.GetElement(new ProviderSearchModel { Id = _id!.Value }); + if (element != null) + { + textBoxName.Text = element.Name; + _logo = element.Logo; + dropDownList1.Selected = element.Type; + textBoxNumber.Text = element.Number; + + pictureBox1.Image = byteArrayToImage(_logo); + } + } + catch(Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении записи", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + var list = _typeStorage.GetFullList().Select(item => item.Name).ToList(); + dropDownList1.Clear(); + foreach (var item in list) + { + dropDownList1.ComboBoxItems.Add(item); + } + + if (_id != null) + { + var provider = _providerStorage.GetElement(new ProviderSearchModel() { Id = _id!.Value }); + dropDownList1.Selected = provider!.Type; + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Название не указано."); + return; + } + if (_logo.Length == 0) + { + MessageBox.Show("Выберите фото", "Ошибка"); + return; + } + if (string.IsNullOrEmpty(dropDownList1.Selected)) + { + MessageBox.Show("Не выбран тип изделий."); + return; + } + if (!Regex.IsMatch(textBoxNumber.Text, @"^\d-\d{3}-\d{3}-\d{2}-\d{2}$")) + { + MessageBox.Show("Неправильный формат номера телефона."); + return; + } + + isEdited = false; + + try + { + var model = new ProviderBindingModel + { + Id = _id ?? 0, + Name = textBoxName.Text, + Logo = _logo, + Type = dropDownList1.Selected, + Number = textBoxNumber.Text + }; + var action = _id.HasValue ? _providerStorage.Update(model) : _providerStorage.Insert(model); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + Close(); + } + + private void buttonType_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormType)); + if (service is FormType form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void FormProvider_FormClosing(object sender, FormClosingEventArgs e) + { + if (!isEdited) return; + + var confirmResult = MessageBox.Show( + "Имеются незафиксированные изменения." + + "\n" + + "Вы действительно хотите закрыть форму?", + "Подтвердите действие", + MessageBoxButtons.YesNo, + MessageBoxIcon.Question + ); + if (confirmResult == DialogResult.No) e.Cancel = true; + } + + private void buttonImage_Click(object sender, EventArgs e) + { + if (ImgFile.ShowDialog() != DialogResult.OK) return; + + Image img = Image.FromFile(ImgFile.FileName); + using (MemoryStream mStream = new MemoryStream()) + { + img.Save(mStream, img.RawFormat); + _logo = mStream.ToArray(); + } + + pictureBox1.Image = img; + } + + private void OnInputChange(object sender, EventArgs e) + { + isEdited = true; + } + } +} diff --git a/WinFormsProject/AppView/FormProvider.resx b/WinFormsProject/AppView/FormProvider.resx new file mode 100644 index 0000000..741ab82 --- /dev/null +++ b/WinFormsProject/AppView/FormProvider.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/WinFormsProject/AppView/FormType.Designer.cs b/WinFormsProject/AppView/FormType.Designer.cs new file mode 100644 index 0000000..bbf9c76 --- /dev/null +++ b/WinFormsProject/AppView/FormType.Designer.cs @@ -0,0 +1,65 @@ +namespace AppView +{ + partial class FormType + { + /// + /// 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(0, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(367, 447); + this.dataGridView.TabIndex = 0; + this.dataGridView.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellValueChanged); + this.dataGridView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dataGridView_KeyDown); + // + // FormType + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(367, 447); + this.Controls.Add(this.dataGridView); + this.Name = "FormType"; + this.Text = "FormType"; + this.Load += new System.EventHandler(this.FormType_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/WinFormsProject/AppView/FormType.cs b/WinFormsProject/AppView/FormType.cs new file mode 100644 index 0000000..dd69082 --- /dev/null +++ b/WinFormsProject/AppView/FormType.cs @@ -0,0 +1,138 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.StorageContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Linq.Expressions; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AppView +{ + public partial class FormType : Form + { + private readonly ITypeStorage _typeStorage; + + public FormType(ITypeStorage typeStorage) + { + _typeStorage = typeStorage; + + InitializeComponent(); + } + + private void FormType_Load(object sender, EventArgs e) + { + LoadData(); + } + + public void LoadData() + { + try + { + var types = _typeStorage.GetFullList(); + if (types != null) + { + dataGridView.DataSource = types; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Name"].Tag = "Название"; + } + } + catch(Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка загрузки типов.", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void dataGridView_KeyDown(object sender, KeyEventArgs e) + { + switch (e.KeyCode) + { + case Keys.Insert: + AddType(); + e.Handled = true; + break; + case Keys.Delete: + RemoveType(); + e.Handled = true; + break; + } + } + + private void AddType() + { + var list = _typeStorage.GetFullList(); + list.Add(new()); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + + private void RemoveType() + { + if (dataGridView.SelectedRows.Count > 0) + { + DialogResult result = MessageBox.Show( + "Вы уверены, что хотите удалить выбранные записи?", + "Подтверждение удаления", + MessageBoxButtons.YesNo, + MessageBoxIcon.Question); + if (result == DialogResult.Yes) + { + foreach (DataGridViewRow row in dataGridView.SelectedRows) + { + if (!row.IsNewRow) + { + int id = Convert.ToInt32(row.Cells["Id"].Value); + var view = _typeStorage.GetElement(new TypeSearchModel { Id = id }); + _typeStorage.Delete(new(view!)); + } + } + LoadData(); + } + } + } + + private void dataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e) + { + if (e.RowIndex >= 0) + { + DataGridViewRow row = dataGridView.Rows[e.RowIndex]; + int id = Convert.ToInt32(row.Cells["Id"].Value); + string? name = row.Cells["Name"].Value?.ToString(); + + if (string.IsNullOrWhiteSpace(name)) + { + MessageBox.Show( + "Нельзя сохранить запись с пустым именем!", + "Ошибка", + MessageBoxButtons.OK, + MessageBoxIcon.Error + ); + LoadData(); + } + else + { + var model = new TypeBindingModel + { + Id = id, + Name = name + }; + if (model.Id == 0) _typeStorage.Insert(model); + else _typeStorage.Update(model); + LoadData(); + } + } + } + } +} diff --git a/WinFormsProject/AppView/FormType.resx b/WinFormsProject/AppView/FormType.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/WinFormsProject/AppView/FormType.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/WinFormsProject/AppView/Program.cs b/WinFormsProject/AppView/Program.cs index 5561de2..e2a04d9 100644 --- a/WinFormsProject/AppView/Program.cs +++ b/WinFormsProject/AppView/Program.cs @@ -1,7 +1,13 @@ +using Contracts.StorageContracts; +using DateBaseImplement.Implements; +using Microsoft.Extensions.DependencyInjection; + namespace AppView { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -11,7 +17,19 @@ namespace AppView // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureService(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + + private static void ConfigureService(IServiceCollection services) + { + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/WinFormsProject/WinFormsLibrary/DocumentWithImage.cs b/WinFormsProject/WinFormsLibrary/DocumentWithImage.cs index eb50850..eb6495b 100644 --- a/WinFormsProject/WinFormsLibrary/DocumentWithImage.cs +++ b/WinFormsProject/WinFormsLibrary/DocumentWithImage.cs @@ -39,7 +39,6 @@ namespace WinFormsLibrary public void CreateDocument(ImageClass imageClass) { - // Проверка наличия данных if (string.IsNullOrEmpty(imageClass.Path) || string.IsNullOrEmpty(imageClass.Title) || imageClass.Files.Count == 0) { throw new Exception("Не все данные заполнены"); @@ -58,22 +57,16 @@ namespace WinFormsLibrary // Добавляем изображения mainPart.Document.Append(body); - foreach (string imagePath in imageClass.Files) - { - if (File.Exists(imagePath)) - { - ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); - using (FileStream stream = new FileStream(imagePath, FileMode.Open)) - { - imagePart.FeedData(stream); - } - AddImageToBody(wordDocument, mainPart.GetIdOfPart(imagePart)); - } - else + foreach (byte[] imageData in imageClass.Files) + { + ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); + using (MemoryStream stream = new MemoryStream(imageData)) { - Console.WriteLine($"Изображение '{imagePath}' не найдено."); + imagePart.FeedData(stream); } + + AddImageToBody(wordDocument, mainPart.GetIdOfPart(imagePart)); } Console.WriteLine($"Word-документ успешно создан в файле '{imageClass.Path}'."); @@ -82,66 +75,67 @@ namespace WinFormsLibrary private void AddImageToBody(WordprocessingDocument wordDoc, string relationshipId) { - var element = - new Drawing( - new DW.Inline( - new DW.Extent() { Cx = 1990000L, Cy = 1792000L }, - new DW.EffectExtent() - { - LeftEdge = 0L, - TopEdge = 0L, - RightEdge = 0L, - BottomEdge = 0L - }, - new DW.DocProperties() - { - Id = (UInt32Value)1U, - Name = "Picture 1" - }, - new DW.NonVisualGraphicFrameDrawingProperties( - new A.GraphicFrameLocks() { NoChangeAspect = true }), - new A.Graphic( - new A.GraphicData( - new PIC.Picture( - new PIC.NonVisualPictureProperties( - new PIC.NonVisualDrawingProperties() - { - Id = (UInt32Value)0U, - Name = "New Bitmap Image.jpg" - }, - new PIC.NonVisualPictureDrawingProperties()), - new PIC.BlipFill( - new A.Blip( - new A.BlipExtensionList( - new A.BlipExtension() - { - Uri = - "{28A0092B-C50C-407E-A947-70E740481C1C}" - }) - ) - { - Embed = relationshipId, - CompressionState = - A.BlipCompressionValues.Print - }, - new A.Stretch( - new A.FillRectangle())), - new PIC.ShapeProperties( - new A.Transform2D( - new A.Offset() { X = 0L, Y = 0L }, - new A.Extents() { Cx = 990000L, Cy = 792000L }), - new A.PresetGeometry( - new A.AdjustValueList() - ) { Preset = A.ShapeTypeValues.Rectangle })) - ) { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" }) - ) - { - DistanceFromTop = (UInt32Value)0U, - DistanceFromBottom = (UInt32Value)0U, - DistanceFromLeft = (UInt32Value)0U, - DistanceFromRight = (UInt32Value)0U, - EditId = "50D07946" - }); + var element = new Drawing( + new DW.Inline( + new DW.Extent() { Cx = 1990000L, Cy = 1792000L }, + new DW.EffectExtent() + { + LeftEdge = 0L, + TopEdge = 0L, + RightEdge = 0L, + BottomEdge = 0L + }, + new DW.DocProperties() + { + Id = (UInt32Value)1U, + Name = "Picture 1" + }, + new DW.NonVisualGraphicFrameDrawingProperties( + new A.GraphicFrameLocks() { NoChangeAspect = true }), + new A.Graphic( + new A.GraphicData( + new PIC.Picture( + new PIC.NonVisualPictureProperties( + new PIC.NonVisualDrawingProperties() + { + Id = (UInt32Value)0U, + Name = "New Bitmap Image.jpg" + }, + new PIC.NonVisualPictureDrawingProperties()), + new PIC.BlipFill( + new A.Blip( + new A.BlipExtensionList( + new A.BlipExtension() + { + Uri = + "{28A0092B-C50C-407E-A947-70E740481C1C}" + }) + ) + { + Embed = relationshipId, + CompressionState = + A.BlipCompressionValues.Print + }, + new A.Stretch( + new A.FillRectangle())), + new PIC.ShapeProperties( + new A.Transform2D( + new A.Offset() { X = 0L, Y = 0L }, + new A.Extents() { Cx = 990000L, Cy = 792000L }), + new A.PresetGeometry( + new A.AdjustValueList() + ) + { Preset = A.ShapeTypeValues.Rectangle })) + ) + { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" }) + ) + { + DistanceFromTop = (UInt32Value)0U, + DistanceFromBottom = (UInt32Value)0U, + DistanceFromLeft = (UInt32Value)0U, + DistanceFromRight = (UInt32Value)0U, + EditId = "50D07946" + }); // Append the reference to the body. The element should be in // a DocumentFormat.OpenXml.Wordprocessing.Run. diff --git a/WinFormsProject/WinFormsLibrary/SupportClasses/ImageClass.cs b/WinFormsProject/WinFormsLibrary/SupportClasses/ImageClass.cs index af0af8c..70b3944 100644 --- a/WinFormsProject/WinFormsLibrary/SupportClasses/ImageClass.cs +++ b/WinFormsProject/WinFormsLibrary/SupportClasses/ImageClass.cs @@ -10,13 +10,13 @@ namespace WinFormsLibrary.SupportClasses { 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 ImageClass() { } - public ImageClass(string filePath, string documentTitle, List textData) + public ImageClass(string filePath, string documentTitle, List textData) { Path = filePath; Title = documentTitle;