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-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)
|
|
|
|
|
{
|
|
|
|
|
if(item.Amount != null)
|
|
|
|
|
{
|
|
|
|
|
string clients = string.Concat("ФИО: ", item.Name, " Отзывы: ", item.Reviews);
|
|
|
|
|
textList.Add(clients);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
string[] textArray = textList.ToArray();
|
|
|
|
|
wordText1.CreateWordText(new(fileName, "Документ по клиентам, совершавшим покупки (ФИО клиента и его отзывы)", textArray));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void статусыToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var form = Program.Container.Resolve<FormStatus>();
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void сохранитьВПдфToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void сохранитьВЭксельToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|