270 lines
10 KiB
C#
Raw Normal View History

2024-11-27 23:43:53 +04:00
using Components;
using Contracts.BindingModels;
using Contracts.BusinessLogicContracts;
2024-12-13 00:01:45 +03:00
using DocumentFormat.OpenXml.Drawing.Diagrams;
using UserComponentsOption19;
using WinFormsLibrary1.HelperClasses;
2024-11-27 23:43:53 +04:00
namespace COP3_
{
public partial class FormMain : Form
{
private readonly IOrderLogic _orderLogic;
2024-12-13 00:01:45 +03:00
private readonly ICityStatusLogic _cityLogic;
public FormMain(IOrderLogic orderLogic, ICityStatusLogic cityStatusLogic)
2024-11-27 23:43:53 +04:00
{
InitializeComponent();
_orderLogic = orderLogic;
2024-12-13 00:01:45 +03:00
_cityLogic = cityStatusLogic;
2024-11-27 23:43:53 +04:00
this.KeyPreview = true;
2024-12-13 00:01:45 +03:00
2024-11-27 23:43:53 +04:00
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var orders = _orderLogic.ReadList(null);
2024-12-13 00:01:45 +03:00
listComponent1.ClearRows();
listComponent1.FillTemplateString("<22><><EFBFBD><EFBFBD><EFBFBD>: (OrderDestination), <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: (Id), <20><><EFBFBD>: (FIO), <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: (OrderDeliveryTime)", "(", ")");
foreach (var order in orders)
{
listComponent1.AddObjectToListBox(order);
}
2024-11-27 23:43:53 +04:00
}
catch (Exception ex)
{
MessageBox.Show($"{ex.Message}");
}
}
private void Create(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormEdit));
if (!(service is FormEdit form))
{
return;
}
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
private void Open(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormEdit));
if (!(service is FormEdit form))
{
return;
}
var selectedOrder = listComponent1.GetObjectFromSelectedRow<OrderBindingModel>();
form.Id = Convert.ToInt32(selectedOrder.Id);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
private void Delete(object sender, EventArgs e)
{
try
{
var selectedOrder = listComponent1.GetObjectFromSelectedRow<OrderBindingModel>();
if (selectedOrder != null)
{
var result = MessageBox.Show(
"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question
);
if (result == DialogResult.Yes)
{
_orderLogic.Delete(new OrderBindingModel { Id = selectedOrder.Id });
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
LoadData();
}
else if (result == DialogResult.No)
{
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
LoadData();
}
LoadData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void CreateDoc(object sender, EventArgs e)
{
using (SaveFileDialog saveFileDialog = new SaveFileDialog())
{
2024-12-13 00:01:45 +03:00
saveFileDialog.Filter = "PDF Documents (*.pdf)|*.pdf";
2024-11-27 23:43:53 +04:00
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
string filePath = saveFileDialog.FileName;
2024-12-13 00:01:45 +03:00
string title = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
2024-11-27 23:43:53 +04:00
try
{
var orders = _orderLogic.ReadList(null);
2024-12-13 00:01:45 +03:00
var cities = _cityLogic.ReadList(null);
2024-11-27 23:43:53 +04:00
if (orders != null)
{
2024-12-13 00:01:45 +03:00
List<string[,]> tables = new List<string[,]>();
string[,] var = new string[7, orders.Count];
for (int i = 0; i < orders.Count; i++)
2024-11-27 23:43:53 +04:00
{
2024-12-13 00:01:45 +03:00
var[0,i] = orders[i].Id.ToString();
for(int j = 1; j < 7; j++)
{
if(j <= orders[i].OrderPath.Length)
var[j,i] = orders[i].OrderPath[j-1];
else var[j,i] = string.Empty;
}
2024-11-27 23:43:53 +04:00
}
2024-12-13 00:01:45 +03:00
tables.Add(var);
PdfDocumentData pdfdata = new PdfDocumentData(filePath, title, tables);
pdfTable1.GeneratePdf(pdfdata);
2024-11-27 23:43:53 +04:00
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
private void CreateTableDoc(object sender, EventArgs e)
{
using (SaveFileDialog saveFileDialog = new SaveFileDialog())
{
saveFileDialog.Filter = "Excel Files (*.xlsx)|*.xlsx";
2024-12-13 00:01:45 +03:00
saveFileDialog.Title = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> Excel";
2024-11-27 23:43:53 +04:00
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
string filePath = saveFileDialog.FileName;
try
{
var orders = _orderLogic.ReadList(null);
if (orders == null || !orders.Any())
{
2024-12-13 00:01:45 +03:00
MessageBox.Show("<22><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
2024-11-27 23:43:53 +04:00
return;
}
2024-12-13 00:01:45 +03:00
List<(string title, string propertyName, float height)> headers = new List<(string title, string propertyName, float height)>
2024-11-27 23:43:53 +04:00
{
2024-12-13 00:01:45 +03:00
("ID","Id",20),
("<22><><EFBFBD>", "FIO",40),
("<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "OrderDestination",40),
("<22><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "OrderDeliveryTime",40)
};
List<(int StartRow, int EndRow, int StartCol, int EndCol, string title)> mergeCellsInfo = new List<(int StartRow, int EndRow, int StartCol, int EndCol, string title)>
{
(3, 4, 1, 1, "<22><><EFBFBD><EFBFBD><EFBFBD>")
};
componentExcelTableWithColumnHeader1.GenerateExcelFile(filePath,"Excel",mergeCellsInfo,orders,headers);
2024-11-27 23:43:53 +04:00
MessageBox.Show("<22><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>: {ex.Message}", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void CreateDiagramDoc(object sender, EventArgs e)
{
using (SaveFileDialog fileDialog = new SaveFileDialog())
{
2024-12-13 00:01:45 +03:00
fileDialog.Filter = "Word Files (*.docx)|*.docx";
fileDialog.Title = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> Word";
2024-11-27 23:43:53 +04:00
if (fileDialog.ShowDialog() == DialogResult.OK)
{
string filePath = fileDialog.FileName;
string fileTitle = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
try
{
var orders = _orderLogic.ReadList(null);
2024-12-13 00:01:45 +03:00
if (orders == null || !orders.Any())
{
MessageBox.Show("<22><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
return;
}
List<UserComponentsOption19.DiagramWordNoVisibleComponent.ChartSeries> tables = new List<DiagramWordNoVisibleComponent.ChartSeries>();
//var destinations = (from order in orders group order.OrderDeliveryTime by order.OrderDestination).Distinct().ToList() ;
var deliveryTime = (from order in orders select order.OrderDeliveryTime).Distinct().ToArray();
var destinations = (from order in orders select order.OrderDestination).Distinct().ToList();
foreach(var item in destinations)
{
double[] ints = new double[deliveryTime.Length];
for (int i = 0; i < deliveryTime.Length; i++)
2024-12-13 00:01:45 +03:00
{
ints[i] = (from order in orders where order.OrderDeliveryTime == deliveryTime[i] && order.OrderDestination == item select order).Count();
2024-12-13 00:01:45 +03:00
}
tables.Add(
new DiagramWordNoVisibleComponent.ChartSeries
{
Name = item,
Data = ints.ToList(),
}
);
2024-11-27 23:43:53 +04:00
}
diagramWordNoVisibleComponent1.CreateDocumentWithChart(filePath, fileTitle, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", UserComponentsOption19.DiagramWordNoVisibleComponent.LegendPosition.Bottom, tables);
2024-12-13 00:01:45 +03:00
2024-11-27 23:43:53 +04:00
MessageBox.Show("<22><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>: {ex.Message}", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void contextMenuStrip1_Opening(object sender, System.ComponentModel.CancelEventArgs e)
{
}
private void <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormGuide));
if (!(service is FormGuide form))
{
return;
}
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}