Работа с документами.

This commit is contained in:
ElEgEv 2023-10-24 21:40:42 +04:00
parent 3ec2154684
commit d6fd160b27
5 changed files with 106 additions and 187 deletions

View File

@ -62,6 +62,8 @@ namespace VisualComponentsForm
{ {
_labWorkStorage.Update(model); _labWorkStorage.Update(model);
} }
Close();
} }
//загрузка данных для комбобокса //загрузка данных для комбобокса
@ -81,6 +83,8 @@ namespace VisualComponentsForm
if (_id.HasValue) if (_id.HasValue)
{ {
buttonCreate.Text = "Сохранить";
var model = _labWorkStorage.GetElement(new LabWorkSearchModel var model = _labWorkStorage.GetElement(new LabWorkSearchModel
{ {
Id = _id.Value, Id = _id.Value,
@ -88,7 +92,7 @@ namespace VisualComponentsForm
if (model != null) if (model != null)
{ {
inputInRange.Value = model.Theme; inputInRange.SetStartText(model.Theme);
dropDownList.Selected = model.Discipline; dropDownList.Selected = model.Discipline;
textBoxStudents.Text = model.FCs; textBoxStudents.Text = model.FCs;
textBoxQuestions.Text = model.Questions; textBoxQuestions.Text = model.Questions;

View File

@ -29,140 +29,65 @@
private void InitializeComponent() private void InitializeComponent()
{ {
components = new System.ComponentModel.Container(); 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); lineChartExcel = new NonVisualComponents.LineChartExcel(components);
pdfTable = new NonVisualComponents.PdfTable(components); pdfTable = new NonVisualComponents.PdfTable(components);
componentWord = new VisualComponentsLib.Components.ComponentWord(components); componentWord = new VisualComponentsLib.Components.ComponentWord(components);
button1 = new Button(); buttonCreateDiscipline = new Button();
contextMenuStrip = new ContextMenuStrip(components); contextMenuStrip = new ContextMenuStrip(components);
groupBox.SuspendLayout(); myListBox = new VisualComponentsLib.CustomListBox.MyListBox();
SuspendLayout(); 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
// //
pdfTable.Error = null; pdfTable.Error = null;
// //
// button1 // buttonCreateDiscipline
// //
button1.Location = new Point(411, 71); buttonCreateDiscipline.Location = new Point(369, 12);
button1.Name = "button1"; buttonCreateDiscipline.Name = "buttonCreateDiscipline";
button1.Size = new Size(75, 23); buttonCreateDiscipline.Size = new Size(158, 25);
button1.TabIndex = 8; buttonCreateDiscipline.TabIndex = 8;
button1.Text = "button1"; buttonCreateDiscipline.Text = "Создать дисциплину";
button1.UseVisualStyleBackColor = true; buttonCreateDiscipline.UseVisualStyleBackColor = true;
button1.Click += Button1_Click; buttonCreateDiscipline.Click += ButtonCreateDiscipline_Click;
// //
// contextMenuStrip // contextMenuStrip
// //
contextMenuStrip.Name = "contextMenuStrip"; contextMenuStrip.Name = "contextMenuStrip";
contextMenuStrip.Size = new Size(181, 26); contextMenuStrip.Size = new Size(61, 4);
contextMenuStrip.Text = "Меню"; 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 // FormMain
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(529, 412); ClientSize = new Size(539, 316);
ContextMenuStrip = contextMenuStrip; ContextMenuStrip = contextMenuStrip;
Controls.Add(button1); Controls.Add(myListBox);
Controls.Add(groupBox); Controls.Add(buttonCreateDiscipline);
KeyPreview = true;
Name = "FormMain"; Name = "FormMain";
Text = "Главная"; Text = "Главная";
KeyDown += FormMain_KeyDown; KeyDown += FormMain_KeyDown;
groupBox.ResumeLayout(false);
groupBox.PerformLayout();
ResumeLayout(false); ResumeLayout(false);
} }
#endregion #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.LineChartExcel lineChartExcel;
private NonVisualComponents.PdfTable pdfTable; private NonVisualComponents.PdfTable pdfTable;
private VisualComponentsLib.Components.ComponentWord componentWord; private VisualComponentsLib.Components.ComponentWord componentWord;
private Button button1; private Button buttonCreateDiscipline;
private ContextMenuStrip contextMenuStrip; private ContextMenuStrip contextMenuStrip;
private VisualComponentsLib.CustomListBox.MyListBox myListBox;
} }
} }

View File

@ -1,4 +1,5 @@
using Contracts.SearchModel; using Contracts.BindingModel;
using Contracts.SearchModel;
using Contracts.StorageContracts; using Contracts.StorageContracts;
using DatabaseImplement.Implements; using DatabaseImplement.Implements;
using System; using System;
@ -13,33 +14,8 @@ namespace VisualComponentsForm
{ {
private readonly ILabWorkStorage _labWorkStorage; private readonly ILabWorkStorage _labWorkStorage;
private int numberObject;
private List<People> peoples;
private List<DataGridViewInfoCol> info;
public FormMain(ILabWorkStorage labWorkStorage) public FormMain(ILabWorkStorage labWorkStorage)
{ {
numberObject = 0;
peoples = new List<People>
{
new People(0, "Никита", "Сергеев", 20),
new People(1, "Дарья", "Балберова", 19),
new People(2, "Данил", "Малин", 25),
new People(3, "Николай", "Распаев", 23)
};
info = new List<DataGridViewInfoCol>
{
new DataGridViewInfoCol("Номер", "Id", 60, true),
new DataGridViewInfoCol("Имя", "Name", 60, true),
new DataGridViewInfoCol("Фамилия", "Surname", 60, true),
new DataGridViewInfoCol("Возраст", "Age", 60, true)
};
InitializeComponent(); InitializeComponent();
ToolStripMenuItem createLabWork = new("Создать лаб. раб."); ToolStripMenuItem createLabWork = new("Создать лаб. раб.");
@ -49,39 +25,22 @@ namespace VisualComponentsForm
ToolStripMenuItem createTableDocEntityItem = new("Создать Excel"); ToolStripMenuItem createTableDocEntityItem = new("Создать Excel");
ToolStripMenuItem createChartDocEntityItem = new("Создать Pdf"); ToolStripMenuItem createChartDocEntityItem = new("Создать Pdf");
contextMenuStrip.Items.AddRange(new[] { createLabWork, updateLabWork, deleteLabWork }); contextMenuStrip.Items.AddRange(new[] { createLabWork, updateLabWork, deleteLabWork,
createSimpleDocItem, createTableDocEntityItem, createChartDocEntityItem});
myListBox.ContextMenuStrip = contextMenuStrip; myListBox.ContextMenuStrip = contextMenuStrip;
//valueTree.ContextMenuStrip = contextMenuStrip;
createLabWork.Click += CreateLabWork_Click; createLabWork.Click += CreateLabWork_Click;
updateLabWork.Click += UpdateLabWork_Click; updateLabWork.Click += UpdateLabWork_Click;
deleteLabWork.Click += DeleteLabWork_Click; deleteLabWork.Click += DeleteLabWork_Click;
//createSimpleDocItem.Click += createSimpleDocItem_Click; createSimpleDocItem.Click += CreateSimpleDocItem_Click;
//createTableDocEntityItem.Click += createTableDocEntityItem_Click; createTableDocEntityItem.Click += CreateTableDocEntityItem_Click;
//createChartDocEntityItem.Click += createChartDocEntityItem_Click; createChartDocEntityItem.Click += CreateChartDocEntityItem_Click;
_labWorkStorage = labWorkStorage; _labWorkStorage = labWorkStorage;
LoadData(); 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) public void CreateLabWork_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormCreateLabWork)); var service = Program.ServiceProvider?.GetService(typeof(FormCreateLabWork));
@ -96,48 +55,64 @@ namespace VisualComponentsForm
public void UpdateLabWork_Click(object sender, EventArgs e) public void UpdateLabWork_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormCreateLabWork)); try
if (service is FormCreateLabWork form)
{ {
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) public void DeleteLabWork_Click(object sender, EventArgs e)
{ {
// Удаление выбранных строк при нажатии на клавишу Delete try
/*
if (dataGridView.SelectedRows.Count > 0)
{ {
DialogResult result = MessageBox.Show("Вы уверены, что хотите удалить выбранные записи?", "Подтверждение удаления", MessageBoxButtons.YesNo, MessageBoxIcon.Question); int Id = GetSelectedId();
DialogResult result = MessageBox.Show("Вы уверены, что хотите удалить выбранную запись?", "Подтверждение удаления", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes) if (result == DialogResult.Yes)
{ {
foreach (DataGridViewRow row in dataGridView.SelectedRows) _labWorkStorage.Delete(new LabWorkBindingModel
{ {
if (!row.IsNewRow) Id = Id
{ });
int id = Convert.ToInt32(row.Cells["Id"].Value);
var view = _disciplineStorage.GetElement(new DisciplineSearchModel LoadData();
{
Id = id
});
_disciplineStorage.Delete(new(view!));
}
}
//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) private void FormMain_KeyDown(object sender, KeyEventArgs e)
@ -154,24 +129,27 @@ namespace VisualComponentsForm
} }
if (e.KeyCode == Keys.D) if (e.KeyCode == Keys.D)
{ {
//deleteOrderEntityItem_Click(sender, e); DeleteLabWork_Click(sender, e);
} }
if (e.KeyCode == Keys.S) if (e.KeyCode == Keys.S)
{ {
//createSimpleDocItem_Click(sender, e); //Word
CreateSimpleDocItem_Click(sender, e);
} }
if (e.KeyCode == Keys.T) if (e.KeyCode == Keys.T)
{ {
//createTableDocEntityItem_Click(sender, e); //Excel
CreateTableDocEntityItem_Click(sender, e);
} }
if (e.KeyCode == Keys.C) 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)); var service = Program.ServiceProvider?.GetService(typeof(FormCreateDiscipline));
@ -179,19 +157,31 @@ namespace VisualComponentsForm
{ {
form.ShowDialog(); form.ShowDialog();
//LoadData(); LoadData();
} }
} }
//загрузка данных из бд
public void LoadData() public void LoadData()
{ {
var labWorks = _labWorkStorage.GetFullList(); 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); + 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());
}
} }
} }

View File

@ -11,7 +11,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Aspose.Words" Version="23.10.0" /> <PackageReference Include="Aspose.Words" Version="23.10.0" />
<PackageReference Include="MarkNoVisual" Version="1.2.0" /> <PackageReference Include="MarkNoVisual" Version="1.2.0" />
<PackageReference Include="MarkVisual" Version="1.2.0" /> <PackageReference Include="MarkVisual" Version="1.4.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.12"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.12">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@ -33,7 +33,7 @@
// //
// listBox // listBox
// //
listBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left; listBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
listBox.FormattingEnabled = true; listBox.FormattingEnabled = true;
listBox.ItemHeight = 15; listBox.ItemHeight = 15;
listBox.Location = new Point(3, 3); listBox.Location = new Point(3, 3);