2023-10-26 22:26:41 +04:00
|
|
|
|
using ClientBusinessLogic.BusinessLogics;
|
|
|
|
|
using ClientsContracts.BusinessLogicContracts;
|
|
|
|
|
using ClientsContracts.ViewModels;
|
|
|
|
|
using ClientsContracts.BindingModels;
|
|
|
|
|
using ControlsLibraryNet60.Data;
|
2023-10-27 20:29:38 +04:00
|
|
|
|
using ComponentsLibraryNet60.Models;
|
|
|
|
|
using UnvisableComponents;
|
2023-10-25 23:06:54 +04:00
|
|
|
|
using Unity;
|
2023-10-26 22:26:41 +04:00
|
|
|
|
using DocumentFormat.OpenXml.Spreadsheet;
|
|
|
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
|
2023-10-25 23:06:54 +04:00
|
|
|
|
|
|
|
|
|
namespace WinForms
|
|
|
|
|
{
|
|
|
|
|
public partial class FormMain : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly IClientLogic _clientLogic;
|
|
|
|
|
private readonly IStatusLogic _statusLogic;
|
|
|
|
|
public FormMain(IClientLogic clientLogic, IStatusLogic statusLogic)
|
|
|
|
|
{
|
|
|
|
|
_clientLogic = clientLogic;
|
|
|
|
|
_statusLogic = statusLogic;
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
List<string> stringToHierachy = new List<string>() { "Status", "Amount", "Id", "Name" };
|
|
|
|
|
myTreeView1.addToHierarchy(stringToHierachy);
|
2023-10-26 22:26:41 +04:00
|
|
|
|
myTreeView1.ContextMenuStrip = contextMenuStrip1;
|
2023-10-25 23:06:54 +04:00
|
|
|
|
}
|
|
|
|
|
private void FormMain_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadData()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = _clientLogic.Read(null);
|
2023-10-26 22:26:41 +04:00
|
|
|
|
for (int i = 0; i < list.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (list[i].Amount == null) { list[i].Amount = 0; }
|
|
|
|
|
}
|
2023-10-25 23:06:54 +04:00
|
|
|
|
myTreeView1.LoadTree(list);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddNewElement()
|
|
|
|
|
{
|
|
|
|
|
var form = Program.Container.Resolve<FormClient>();
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-26 22:26:41 +04:00
|
|
|
|
|
|
|
|
|
private void UpdateElement()
|
|
|
|
|
{
|
|
|
|
|
var form = Program.Container.Resolve<FormClient>();
|
|
|
|
|
var selectedClient = myTreeView1.GetNode(typeof(ClientBindingModel));
|
|
|
|
|
if (selectedClient != null)
|
|
|
|
|
{
|
|
|
|
|
form.Id = Convert.ToInt32((selectedClient as ClientBindingModel).Id);
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Выберите клиента для редактирования");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DeleteElement()
|
|
|
|
|
{
|
|
|
|
|
if (MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
var selectedClient = myTreeView1.GetNode(typeof(ClientBindingModel));
|
|
|
|
|
int id = Convert.ToInt32((selectedClient as ClientBindingModel).Id);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_clientLogic.Delete(new ClientBindingModel { Id = id });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreateWord()
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<string> textList = new List<string>();
|
|
|
|
|
var list = _clientLogic.Read(null);
|
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
2023-10-27 20:29:38 +04:00
|
|
|
|
if (item.Amount != null)
|
2023-10-26 22:26:41 +04:00
|
|
|
|
{
|
|
|
|
|
string clients = string.Concat("ФИО: ", item.Name, " Отзывы: ", item.Reviews);
|
|
|
|
|
textList.Add(clients);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
string[] textArray = textList.ToArray();
|
|
|
|
|
wordText1.CreateWordText(new(fileName, "Документ по клиентам, совершавшим покупки (ФИО клиента и его отзывы)", textArray));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-27 20:29:38 +04:00
|
|
|
|
private void createExcel()
|
|
|
|
|
{
|
|
|
|
|
string fileName = "";
|
|
|
|
|
using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" })
|
|
|
|
|
{
|
|
|
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
fileName = dialog.FileName.ToString();
|
|
|
|
|
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var statuses = _statusLogic.Read(null);
|
|
|
|
|
var clients = _clientLogic.Read(null);
|
|
|
|
|
List<(string, int)> dates = new List<(string, int)>();
|
|
|
|
|
for (int i = 0; i < statuses.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
int counter = 0;
|
|
|
|
|
for(int j = 0; j < clients.Count; j++)
|
|
|
|
|
{
|
|
|
|
|
if (clients[j].Status == statuses[i].Name && clients[j].Amount != null) counter++;
|
|
|
|
|
}
|
|
|
|
|
dates.Add((statuses[i].Name, counter));
|
|
|
|
|
}
|
|
|
|
|
excelChart1.Load(new ChartInfo
|
|
|
|
|
{
|
|
|
|
|
Path = fileName,
|
|
|
|
|
Title = "Сколько клиентов какого статуса совершали покупки",
|
|
|
|
|
DiagrammTitle = "Круговая диаграмма",
|
|
|
|
|
Dates = dates,
|
|
|
|
|
DirLegend = DirectionLegend.Right
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreatePdf()
|
|
|
|
|
{
|
|
|
|
|
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
|
|
|
|
string fileName = "";
|
|
|
|
|
using (var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" })
|
|
|
|
|
{
|
|
|
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
fileName = dialog.FileName.ToString();
|
|
|
|
|
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK,
|
|
|
|
|
MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var clients = _clientLogic.Read(null);
|
|
|
|
|
for (int i = 0; i < clients.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (clients[i].Amount == null) { clients[i].Amount = 0; }
|
|
|
|
|
}
|
|
|
|
|
componentDocumentWithTableMultiHeaderPdf1.CreateDoc(new ComponentDocumentWithTableHeaderDataConfig<ClientViewModel>
|
|
|
|
|
{
|
|
|
|
|
FilePath = fileName,
|
|
|
|
|
Header = "Отчет по клиентам",
|
|
|
|
|
ColumnsRowsWidth = new List<(int, int)> { (5, 5), (10, 5), (15, 0), (15, 0) },
|
|
|
|
|
Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)>
|
|
|
|
|
{
|
|
|
|
|
(0, 0, "Id", "Id"),
|
|
|
|
|
(1, 0, "ФИО", "Name"),
|
|
|
|
|
(2, 0, "Статус", "Status"),
|
|
|
|
|
(3, 0, "Сумма покупок", "Amount")
|
|
|
|
|
},
|
|
|
|
|
Data = clients
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-26 22:26:41 +04:00
|
|
|
|
private void статусыToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var form = Program.Container.Resolve<FormStatus>();
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void сохранитьВПдфToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-10-27 20:29:38 +04:00
|
|
|
|
CreatePdf();
|
2023-10-26 22:26:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void сохранитьВЭксельToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-10-27 20:29:38 +04:00
|
|
|
|
createExcel();
|
2023-10-26 22:26:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void сохранитьВВордToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CreateWord();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void удалитьToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DeleteElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void редактироватьToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
UpdateElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void добавитьToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AddNewElement();
|
|
|
|
|
}
|
2023-10-25 23:06:54 +04:00
|
|
|
|
}
|
|
|
|
|
}
|