From d6fd160b2798ba5b2b8a8abec7c24a3e23e56453 Mon Sep 17 00:00:00 2001 From: ElEgEv <112943269+ElEgEv@users.noreply.github.com> Date: Tue, 24 Oct 2023 21:40:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D1=81?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=BA=D1=83=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D0=BC?= =?UTF-8?q?=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VisualComponentsForm/FormCreateLabWork.cs | 6 +- .../VisualComponentsForm/FormMain.Designer.cs | 129 +++------------ .../VisualComponentsForm/FormMain.cs | 154 ++++++++---------- .../VisualComponentsForm.csproj | 2 +- VisualComponentsLib/MyListBox.Designer.cs | 2 +- 5 files changed, 106 insertions(+), 187 deletions(-) diff --git a/VisualComponentsForm/VisualComponentsForm/FormCreateLabWork.cs b/VisualComponentsForm/VisualComponentsForm/FormCreateLabWork.cs index 5ff5a77..76c5978 100644 --- a/VisualComponentsForm/VisualComponentsForm/FormCreateLabWork.cs +++ b/VisualComponentsForm/VisualComponentsForm/FormCreateLabWork.cs @@ -62,6 +62,8 @@ namespace VisualComponentsForm { _labWorkStorage.Update(model); } + + Close(); } //загрузка данных для комбобокса @@ -81,6 +83,8 @@ namespace VisualComponentsForm if (_id.HasValue) { + buttonCreate.Text = "Сохранить"; + var model = _labWorkStorage.GetElement(new LabWorkSearchModel { Id = _id.Value, @@ -88,7 +92,7 @@ namespace VisualComponentsForm if (model != null) { - inputInRange.Value = model.Theme; + inputInRange.SetStartText(model.Theme); dropDownList.Selected = model.Discipline; textBoxStudents.Text = model.FCs; textBoxQuestions.Text = model.Questions; diff --git a/VisualComponentsForm/VisualComponentsForm/FormMain.Designer.cs b/VisualComponentsForm/VisualComponentsForm/FormMain.Designer.cs index 87becab..f4bf282 100644 --- a/VisualComponentsForm/VisualComponentsForm/FormMain.Designer.cs +++ b/VisualComponentsForm/VisualComponentsForm/FormMain.Designer.cs @@ -29,140 +29,65 @@ private void InitializeComponent() { components = new System.ComponentModel.Container(); - labelCheck = new Label(); - buttonCheck = new Button(); - myListBox = new VisualComponentsLib.CustomListBox.MyListBox(); - textBoxInput = new TextBox(); - buttonAddList = new Button(); - buttonClear = new Button(); - groupBox = new GroupBox(); lineChartExcel = new NonVisualComponents.LineChartExcel(components); pdfTable = new NonVisualComponents.PdfTable(components); componentWord = new VisualComponentsLib.Components.ComponentWord(components); - button1 = new Button(); + buttonCreateDiscipline = new Button(); contextMenuStrip = new ContextMenuStrip(components); - groupBox.SuspendLayout(); + myListBox = new VisualComponentsLib.CustomListBox.MyListBox(); SuspendLayout(); // - // labelCheck - // - labelCheck.AutoSize = true; - labelCheck.BorderStyle = BorderStyle.FixedSingle; - labelCheck.Location = new Point(292, 192); - labelCheck.Name = "labelCheck"; - labelCheck.Size = new Size(62, 17); - labelCheck.TabIndex = 1; - labelCheck.Text = "Значение"; - // - // buttonCheck - // - buttonCheck.Location = new Point(279, 224); - buttonCheck.Name = "buttonCheck"; - buttonCheck.Size = new Size(75, 23); - buttonCheck.TabIndex = 2; - buttonCheck.Text = "Проверка"; - buttonCheck.UseVisualStyleBackColor = true; - buttonCheck.Click += ButtonCheck_Click; - // - // myListBox - // - myListBox.Location = new Point(6, 83); - myListBox.MinimumSize = new Size(84, 53); - myListBox.Name = "myListBox"; - myListBox.SelectedString = null; - myListBox.Size = new Size(242, 240); - myListBox.TabIndex = 3; - // - // textBoxInput - // - textBoxInput.Location = new Point(254, 83); - textBoxInput.Name = "textBoxInput"; - textBoxInput.Size = new Size(100, 23); - textBoxInput.TabIndex = 4; - // - // buttonAddList - // - buttonAddList.Location = new Point(279, 112); - buttonAddList.Name = "buttonAddList"; - buttonAddList.Size = new Size(75, 23); - buttonAddList.TabIndex = 5; - buttonAddList.Text = "Добавить"; - buttonAddList.UseVisualStyleBackColor = true; - buttonAddList.Click += ButtonAddList_Click; - // - // buttonClear - // - buttonClear.Location = new Point(279, 141); - buttonClear.Name = "buttonClear"; - buttonClear.Size = new Size(75, 23); - buttonClear.TabIndex = 6; - buttonClear.Text = "Очистить"; - buttonClear.UseVisualStyleBackColor = true; - buttonClear.Click += ButtonClear_Click; - // - // groupBox - // - groupBox.Controls.Add(myListBox); - groupBox.Controls.Add(buttonClear); - groupBox.Controls.Add(labelCheck); - groupBox.Controls.Add(buttonAddList); - groupBox.Controls.Add(buttonCheck); - groupBox.Controls.Add(textBoxInput); - groupBox.Location = new Point(12, 71); - groupBox.Name = "groupBox"; - groupBox.Size = new Size(368, 329); - groupBox.TabIndex = 7; - groupBox.TabStop = false; - groupBox.Text = "Первый компонент"; - // // pdfTable // pdfTable.Error = null; // - // button1 + // buttonCreateDiscipline // - button1.Location = new Point(411, 71); - button1.Name = "button1"; - button1.Size = new Size(75, 23); - button1.TabIndex = 8; - button1.Text = "button1"; - button1.UseVisualStyleBackColor = true; - button1.Click += Button1_Click; + buttonCreateDiscipline.Location = new Point(369, 12); + buttonCreateDiscipline.Name = "buttonCreateDiscipline"; + buttonCreateDiscipline.Size = new Size(158, 25); + buttonCreateDiscipline.TabIndex = 8; + buttonCreateDiscipline.Text = "Создать дисциплину"; + buttonCreateDiscipline.UseVisualStyleBackColor = true; + buttonCreateDiscipline.Click += ButtonCreateDiscipline_Click; // // contextMenuStrip // contextMenuStrip.Name = "contextMenuStrip"; - contextMenuStrip.Size = new Size(181, 26); + contextMenuStrip.Size = new Size(61, 4); contextMenuStrip.Text = "Меню"; // + // myListBox + // + myListBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + myListBox.Location = new Point(12, 12); + myListBox.MinimumSize = new Size(84, 53); + myListBox.Name = "myListBox"; + myListBox.SelectedString = null; + myListBox.Size = new Size(351, 300); + myListBox.TabIndex = 3; + // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(529, 412); + ClientSize = new Size(539, 316); ContextMenuStrip = contextMenuStrip; - Controls.Add(button1); - Controls.Add(groupBox); + Controls.Add(myListBox); + Controls.Add(buttonCreateDiscipline); + KeyPreview = true; Name = "FormMain"; Text = "Главная"; KeyDown += FormMain_KeyDown; - groupBox.ResumeLayout(false); - groupBox.PerformLayout(); ResumeLayout(false); } #endregion - private Label labelCheck; - private Button buttonCheck; - private VisualComponentsLib.CustomListBox.MyListBox myListBox; - private TextBox textBoxInput; - private Button buttonAddList; - private Button buttonClear; - private GroupBox groupBox; private NonVisualComponents.LineChartExcel lineChartExcel; private NonVisualComponents.PdfTable pdfTable; private VisualComponentsLib.Components.ComponentWord componentWord; - private Button button1; + private Button buttonCreateDiscipline; private ContextMenuStrip contextMenuStrip; + private VisualComponentsLib.CustomListBox.MyListBox myListBox; } } \ No newline at end of file diff --git a/VisualComponentsForm/VisualComponentsForm/FormMain.cs b/VisualComponentsForm/VisualComponentsForm/FormMain.cs index 74b159b..0d16a5b 100644 --- a/VisualComponentsForm/VisualComponentsForm/FormMain.cs +++ b/VisualComponentsForm/VisualComponentsForm/FormMain.cs @@ -1,4 +1,5 @@ -using Contracts.SearchModel; +using Contracts.BindingModel; +using Contracts.SearchModel; using Contracts.StorageContracts; using DatabaseImplement.Implements; using System; @@ -13,33 +14,8 @@ namespace VisualComponentsForm { private readonly ILabWorkStorage _labWorkStorage; - private int numberObject; - - private List peoples; - - private List info; - public FormMain(ILabWorkStorage labWorkStorage) { - numberObject = 0; - - peoples = new List - { - new People(0, "Никита", "Сергеев", 20), - new People(1, "Дарья", "Балберова", 19), - new People(2, "Данил", "Малин", 25), - new People(3, "Николай", "Распаев", 23) - }; - - info = new List - { - new DataGridViewInfoCol("Номер", "Id", 60, true), - new DataGridViewInfoCol("Имя", "Name", 60, true), - new DataGridViewInfoCol("Фамилия", "Surname", 60, true), - new DataGridViewInfoCol("Возраст", "Age", 60, true) - }; - - InitializeComponent(); ToolStripMenuItem createLabWork = new("Создать лаб. раб."); @@ -49,39 +25,22 @@ namespace VisualComponentsForm ToolStripMenuItem createTableDocEntityItem = new("Создать Excel"); ToolStripMenuItem createChartDocEntityItem = new("Создать Pdf"); - contextMenuStrip.Items.AddRange(new[] { createLabWork, updateLabWork, deleteLabWork }); + contextMenuStrip.Items.AddRange(new[] { createLabWork, updateLabWork, deleteLabWork, + createSimpleDocItem, createTableDocEntityItem, createChartDocEntityItem}); myListBox.ContextMenuStrip = contextMenuStrip; - //valueTree.ContextMenuStrip = contextMenuStrip; createLabWork.Click += CreateLabWork_Click; updateLabWork.Click += UpdateLabWork_Click; deleteLabWork.Click += DeleteLabWork_Click; - //createSimpleDocItem.Click += createSimpleDocItem_Click; - //createTableDocEntityItem.Click += createTableDocEntityItem_Click; - //createChartDocEntityItem.Click += createChartDocEntityItem_Click; + createSimpleDocItem.Click += CreateSimpleDocItem_Click; + createTableDocEntityItem.Click += CreateTableDocEntityItem_Click; + createChartDocEntityItem.Click += CreateChartDocEntityItem_Click; _labWorkStorage = labWorkStorage; LoadData(); } - private void ButtonCheck_Click(object sender, EventArgs e) - { - labelCheck.Text = myListBox.SelectedString; - } - - private void ButtonAddList_Click(object sender, EventArgs e) - { - myListBox.AddItem(textBoxInput.Text); - - textBoxInput.Text = string.Empty; - } - - private void ButtonClear_Click(object sender, EventArgs e) - { - myListBox.ClearAll(); - } - public void CreateLabWork_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateLabWork)); @@ -96,48 +55,64 @@ namespace VisualComponentsForm public void UpdateLabWork_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateLabWork)); - - if (service is FormCreateLabWork form) + try { - form.Id = 1; + int Id = GetSelectedId(); - form.ShowDialog(); + var service = Program.ServiceProvider?.GetService(typeof(FormCreateLabWork)); - LoadData(); + if (service is FormCreateLabWork form) + { + form.Id = Id; + + form.ShowDialog(); + + LoadData(); + } + } + catch (Exception ex) + { + MessageBox.Show("Ошибка операции", "Необходимо выбрать элемент списка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } public void DeleteLabWork_Click(object sender, EventArgs e) { - // Удаление выбранных строк при нажатии на клавишу Delete - /* - if (dataGridView.SelectedRows.Count > 0) + try { - DialogResult result = MessageBox.Show("Вы уверены, что хотите удалить выбранные записи?", "Подтверждение удаления", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + int Id = GetSelectedId(); + + DialogResult result = MessageBox.Show("Вы уверены, что хотите удалить выбранную запись?", "Подтверждение удаления", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { - foreach (DataGridViewRow row in dataGridView.SelectedRows) + _labWorkStorage.Delete(new LabWorkBindingModel { - if (!row.IsNewRow) - { - int id = Convert.ToInt32(row.Cells["Id"].Value); + Id = Id + }); - var view = _disciplineStorage.GetElement(new DisciplineSearchModel - { - Id = id - }); - - _disciplineStorage.Delete(new(view!)); - - } - } - - //LoadData(); + LoadData(); } } - */ + catch(Exception ex) + { + MessageBox.Show("Ошибка операции", "Необходимо выбрать элемент списка!", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + public void CreateSimpleDocItem_Click(object sender, EventArgs e) + { + + } + + public void CreateTableDocEntityItem_Click(object sender, EventArgs e) + { + + } + + public void CreateChartDocEntityItem_Click(object sender, EventArgs e) + { + } private void FormMain_KeyDown(object sender, KeyEventArgs e) @@ -154,24 +129,27 @@ namespace VisualComponentsForm } if (e.KeyCode == Keys.D) { - //deleteOrderEntityItem_Click(sender, e); + DeleteLabWork_Click(sender, e); } if (e.KeyCode == Keys.S) { - //createSimpleDocItem_Click(sender, e); + //Word + CreateSimpleDocItem_Click(sender, e); } if (e.KeyCode == Keys.T) { - //createTableDocEntityItem_Click(sender, e); + //Excel + CreateTableDocEntityItem_Click(sender, e); } if (e.KeyCode == Keys.C) { - //createChartDocEntityItem_Click(sender, e); + //Pdf + CreateChartDocEntityItem_Click(sender, e); } } } - private void Button1_Click(object sender, EventArgs e) + private void ButtonCreateDiscipline_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateDiscipline)); @@ -179,19 +157,31 @@ namespace VisualComponentsForm { form.ShowDialog(); - //LoadData(); + LoadData(); } } + //загрузка данных из бд public void LoadData() { var labWorks = _labWorkStorage.GetFullList(); - foreach(var labWork in labWorks) + myListBox.ClearAll(); + + foreach (var labWork in labWorks) { - myListBox.AddItem(labWork.Discipline + " | " + labWork.Id.ToString() + " | " + myListBox.AddItem(labWork.Discipline + " | " + labWork.Id.ToString() + " | " + labWork.Theme + " | " + labWork.Questions); } } + + public int GetSelectedId() + { + char dilimiterSimbol = '|'; + + var _id = myListBox.SelectedString.SkipWhile(z => z != dilimiterSimbol).Skip(1).ToList()[1]; + + return int.Parse(_id.ToString()); + } } } \ No newline at end of file diff --git a/VisualComponentsForm/VisualComponentsForm/VisualComponentsForm.csproj b/VisualComponentsForm/VisualComponentsForm/VisualComponentsForm.csproj index f8749dd..57a0ba1 100644 --- a/VisualComponentsForm/VisualComponentsForm/VisualComponentsForm.csproj +++ b/VisualComponentsForm/VisualComponentsForm/VisualComponentsForm.csproj @@ -11,7 +11,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/VisualComponentsLib/MyListBox.Designer.cs b/VisualComponentsLib/MyListBox.Designer.cs index e3833fb..beb5c95 100644 --- a/VisualComponentsLib/MyListBox.Designer.cs +++ b/VisualComponentsLib/MyListBox.Designer.cs @@ -33,7 +33,7 @@ // // listBox // - listBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left; + listBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; listBox.FormattingEnabled = true; listBox.ItemHeight = 15; listBox.Location = new Point(3, 3);