228 lines
8.6 KiB
C#
228 lines
8.6 KiB
C#
using BusinessLogic;
|
||
using ControlsLibraryNet60.Data;
|
||
using ControlsLibraryNet60.Models;
|
||
using DataContracts.bindingModels;
|
||
using DataContracts.viewModels;
|
||
using OfficeOpenXml.LoadFunctions.Params;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using UnvisableComponents;
|
||
using VisualCompLib.Components;
|
||
using VisualCompLib.Components.SupportClasses;
|
||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
|
||
using VisualCompLib.Object;
|
||
using ComponentsLibraryNet60.DocumentWithChart;
|
||
using ComponentsLibraryNet60.Models;
|
||
|
||
namespace ClientForms
|
||
{
|
||
public partial class Main : Form
|
||
{
|
||
private readonly ClientBL clientBl = new();
|
||
|
||
public Main()
|
||
{
|
||
InitializeComponent();
|
||
this.KeyPreview = true;
|
||
controlDataTableTable.ContextMenuStrip = contextMenuStrip1;
|
||
}
|
||
|
||
private void Main_Load(object sender, EventArgs e)
|
||
{
|
||
List<DataTableColumnConfig> columns = new List<DataTableColumnConfig>();
|
||
columns.Add(new DataTableColumnConfig
|
||
{
|
||
ColumnHeader = "Id",
|
||
PropertyName = "Id",
|
||
Visible = false
|
||
});
|
||
columns.Add(new DataTableColumnConfig
|
||
{
|
||
ColumnHeader = "ФИО",
|
||
PropertyName = "FIO",
|
||
Visible = true
|
||
});
|
||
columns.Add(new DataTableColumnConfig
|
||
{
|
||
ColumnHeader = "Почта",
|
||
PropertyName = "email",
|
||
Visible = true
|
||
});
|
||
columns.Add(new DataTableColumnConfig
|
||
{
|
||
ColumnHeader = "Продукты",
|
||
PropertyName = "products",
|
||
Visible = true
|
||
});
|
||
controlDataTableTable.LoadColumns(columns);
|
||
controlDataTableTable.AddTable<ClientViewModel>(clientBl.ReadList());
|
||
|
||
|
||
|
||
}
|
||
|
||
private void добавитьToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
Client client = new Client();
|
||
client.Show();
|
||
}
|
||
|
||
private void обновитьToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
UpdateTable();
|
||
}
|
||
|
||
private void редактироватьToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var client = controlDataTableTable.GetSelectedObject<ClientViewModel>();
|
||
if (client != null)
|
||
{
|
||
Client clientForm = new Client();
|
||
clientForm.Id = client.Id;
|
||
clientForm.Show();
|
||
}
|
||
else
|
||
MessageBox.Show("Выберите запись!!");
|
||
UpdateTable();
|
||
}
|
||
private void UpdateTable()
|
||
{
|
||
controlDataTableTable.Clear();
|
||
controlDataTableTable.AddTable<ClientViewModel>(clientBl.ReadList());
|
||
}
|
||
|
||
private void удалитьToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
|
||
var client = controlDataTableTable.GetSelectedObject<ClientViewModel>();
|
||
if (client != null)
|
||
{
|
||
DialogResult dialogResult = MessageBox.Show("Sure", "Some Title", MessageBoxButtons.YesNo);
|
||
if (dialogResult == DialogResult.Yes)
|
||
clientBl.Delete(new ClientBindingModel { Id = client.Id });
|
||
}
|
||
else
|
||
MessageBox.Show("Выберите запись!!");
|
||
UpdateTable();
|
||
|
||
}
|
||
|
||
private void сохранитьВВордToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
openFileDialog1.Filter = "Word files (*.docx)|*.docx";
|
||
if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
|
||
return;
|
||
string filename = openFileDialog1.FileName;
|
||
string titleTable = "Клиенты";
|
||
List<ColumnDefinition> columnDefinitionsUp = new List<ColumnDefinition> {
|
||
new ColumnDefinition{Header = "#", PropertyName = "Id", Weight = 30},
|
||
new ColumnDefinition{Header = "Личные данные", PropertyName = "FioEmail", Weight = 30},
|
||
new ColumnDefinition{Header = "", PropertyName = "FioEmail", Weight = 30},
|
||
new ColumnDefinition{Header = "Продукты", PropertyName = "products", Weight = 30},
|
||
};
|
||
List<ColumnDefinition> columnDefinitionsDown = new List<ColumnDefinition> {
|
||
new ColumnDefinition{Header = "#", PropertyName = "Id", Weight = 30},
|
||
new ColumnDefinition{Header = "ФИО", PropertyName = "FIO", Weight = 30},
|
||
new ColumnDefinition{Header = "Почта", PropertyName = "email", Weight = 30},
|
||
new ColumnDefinition{Header = "Продукты", PropertyName = "products", Weight = 30},
|
||
};
|
||
List<int[]> mergedColums = new() { new int[] { 1, 2 } };
|
||
List<ClientViewModel> clients = clientBl.ReadList();
|
||
BigTable<ClientViewModel> bigTable = new(filename, titleTable, columnDefinitionsUp, columnDefinitionsDown, clients, mergedColums);
|
||
wordTable1.CreateTable(bigTable);
|
||
MessageBox.Show("Готово");
|
||
}
|
||
|
||
private void сохранитьВЭксельToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
openFileDialog1.Filter = "Excel files (*.xlsx)|*.xlsx";
|
||
if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
|
||
return;
|
||
string filename = openFileDialog1.FileName;
|
||
string title = "Отчет о клиентах";
|
||
List<byte[]> bytes = clientBl.ReadList().Select(x => x.photo).ToList();
|
||
ImageInfo info = new ImageInfo();
|
||
info.Title = title;
|
||
info.Path = filename;
|
||
info.Files = bytes;
|
||
imageExcel1.Load(info);
|
||
MessageBox.Show("Готово");
|
||
}
|
||
|
||
private void сохранитьВПдфToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||
openFileDialog1.Filter = "Pdf files (*.pdf)|*.pdf";
|
||
if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
|
||
return;
|
||
string filename = openFileDialog1.FileName;
|
||
Dictionary<string, List<(int Date, double Value)>> data = new Dictionary<string, List<(int Date, double Value)>>();
|
||
foreach(var item in clientBl.FindDataDiagram())
|
||
{
|
||
data.Add(
|
||
item.title,
|
||
new List<(int Date, double Value)> { (1, item.count) }
|
||
);
|
||
|
||
}
|
||
componentDocumentWithChartBarPdf1.CreateDoc(new ComponentDocumentWithChartConfig
|
||
{
|
||
FilePath = filename,
|
||
Header = "Категории и клиенты",
|
||
ChartTitle = "Соотношение",
|
||
LegendLocation = ComponentsLibraryNet60.Models.Location.Bottom,
|
||
Data = data
|
||
});
|
||
MessageBox.Show("Готово");
|
||
}
|
||
|
||
private void Main_KeyDown(object sender, KeyEventArgs e)
|
||
{
|
||
|
||
if (e.Control && e.KeyCode == Keys.A)
|
||
{
|
||
добавитьToolStripMenuItem_Click(sender, e);
|
||
}
|
||
if (e.Control && e.KeyCode == Keys.U)
|
||
{
|
||
редактироватьToolStripMenuItem_Click(sender, e);
|
||
}
|
||
if (e.Control && e.KeyCode == Keys.Z)
|
||
{
|
||
UpdateTable();
|
||
}
|
||
if (e.Control && e.KeyCode == Keys.D)
|
||
{
|
||
удалитьToolStripMenuItem_Click(sender, e);
|
||
}
|
||
if (e.Control && e.KeyCode == Keys.S)
|
||
{
|
||
сохранитьВЭксельToolStripMenuItem_Click(sender,e);
|
||
}
|
||
if (e.Control && e.KeyCode == Keys.T)
|
||
{
|
||
сохранитьВВордToolStripMenuItem_Click(sender, e);
|
||
}
|
||
if (e.Control && e.KeyCode == Keys.C)
|
||
{
|
||
сохранитьВПдфToolStripMenuItem_Click(sender, e);
|
||
}
|
||
if (e.KeyCode == Keys.Tab)
|
||
{
|
||
Products products = new();
|
||
products.Show();
|
||
}
|
||
|
||
|
||
}
|
||
}
|
||
}
|