laba2 сданная
This commit is contained in:
parent
ea308d86f2
commit
8aa6aee9f2
@ -8,10 +8,17 @@ namespace CreateVisualComponent
|
||||
{
|
||||
public class ColumnsConfiguratoin
|
||||
{
|
||||
public int ColumnsCount { get; set; }
|
||||
public string[] ColumnName { get; set; }
|
||||
public int[] Width { get; set; }
|
||||
public bool[] Visible { get; set; }
|
||||
public string[] PropertiesObject { get; set; }
|
||||
public List<ColumnConfig> Columns { get; set; }
|
||||
public ColumnsConfiguratoin()
|
||||
{
|
||||
Columns = new List<ColumnConfig>();
|
||||
}
|
||||
}
|
||||
public class ColumnConfig
|
||||
{
|
||||
public string ColumnName { get; set; }
|
||||
public int Width { get; set; }
|
||||
public bool Visible { get; set; }
|
||||
public string PropertyObject { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ namespace CreateVisualComponent
|
||||
{
|
||||
public EventHandler? _changeEvent;
|
||||
public EventHandler? _checkBoxEvent;
|
||||
public Exception? Error;
|
||||
|
||||
public InputComponent()
|
||||
{
|
||||
@ -51,8 +50,8 @@ namespace CreateVisualComponent
|
||||
|
||||
public event EventHandler CheckBoxEvent
|
||||
{
|
||||
add { _checkBoxEvent += value; }
|
||||
remove { _checkBoxEvent += value; }
|
||||
add { _changeEvent += value; }
|
||||
remove { _changeEvent -= value; }
|
||||
}
|
||||
|
||||
private void TextBoxDate_TextChanged(object sender, EventArgs e)
|
||||
@ -63,7 +62,7 @@ namespace CreateVisualComponent
|
||||
private void CheckBoxDate_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
textBoxDate.Enabled = !checkBoxDate.Checked;
|
||||
_checkBoxEvent?.Invoke(sender, e);
|
||||
_changeEvent?.Invoke(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,10 @@ namespace CreateVisualComponent
|
||||
}
|
||||
public int SelectedRow
|
||||
{
|
||||
get { return dataGridViewTable.SelectedRows[0].Index; }
|
||||
get
|
||||
{
|
||||
return dataGridViewTable.SelectedRows[0].Index;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (dataGridViewTable.SelectedRows.Count <= value || value < 0)
|
||||
@ -37,43 +40,38 @@ namespace CreateVisualComponent
|
||||
}
|
||||
public void ConfigColumn(ColumnsConfiguratoin columnsData)
|
||||
{
|
||||
dataGridViewTable.ColumnCount = columnsData.ColumnsCount;
|
||||
for (int i = 0; i < columnsData.ColumnsCount; i++)
|
||||
dataGridViewTable.ColumnCount = columnsData.Columns.Count;
|
||||
for (int i = 0; i < columnsData.Columns.Count; i++)
|
||||
{
|
||||
dataGridViewTable.Columns[i].Name = columnsData.ColumnName[i];
|
||||
dataGridViewTable.Columns[i].Width = columnsData.Width[i];
|
||||
dataGridViewTable.Columns[i].Visible = columnsData.Visible[i];
|
||||
dataGridViewTable.Columns[i].DataPropertyName = columnsData.PropertiesObject[i];
|
||||
var column = columnsData.Columns[i];
|
||||
dataGridViewTable.Columns[i].Name = column.ColumnName;
|
||||
dataGridViewTable.Columns[i].Width = column.Width;
|
||||
dataGridViewTable.Columns[i].Visible = column.Visible;
|
||||
dataGridViewTable.Columns[i].DataPropertyName = column.PropertyObject;
|
||||
}
|
||||
}
|
||||
public T GetSelectedObjectInRow<T>() where T : class, new()
|
||||
{
|
||||
T val = new();
|
||||
if (dataGridViewTable.SelectedRows.Count == 0) return null;
|
||||
|
||||
var val = new T();
|
||||
var propertiesObj = typeof(T).GetProperties();
|
||||
var columns = dataGridViewTable.Columns.Cast<DataGridViewColumn>().ToList();
|
||||
var selectedRow = dataGridViewTable.SelectedRows[0];
|
||||
|
||||
foreach (var property in propertiesObj)
|
||||
{
|
||||
var column = columns.FirstOrDefault(c => c.DataPropertyName == property.Name);
|
||||
var column = dataGridViewTable.Columns
|
||||
.Cast<DataGridViewColumn>()
|
||||
.FirstOrDefault(c => c.DataPropertyName == property.Name);
|
||||
|
||||
if (column != null)
|
||||
{
|
||||
object value = dataGridViewTable.SelectedRows[0].Cells[column.Index].Value;
|
||||
var cellValue = selectedRow.Cells[column.Index].Value;
|
||||
|
||||
Type propertyType = property.PropertyType;
|
||||
bool isNullable = Nullable.GetUnderlyingType(propertyType) != null;
|
||||
|
||||
if (isNullable)
|
||||
if (cellValue != DBNull.Value)
|
||||
{
|
||||
propertyType = Nullable.GetUnderlyingType(propertyType);
|
||||
}
|
||||
|
||||
if (value != DBNull.Value)
|
||||
{
|
||||
property.SetValue(val, Convert.ChangeType(value, propertyType));
|
||||
}
|
||||
else if (isNullable)
|
||||
{
|
||||
property.SetValue(val, null);
|
||||
var convertedValue = Convert.ChangeType(cellValue, Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType);
|
||||
property.SetValue(val, convertedValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,18 +33,11 @@ namespace CreateVisualComponent
|
||||
{
|
||||
get
|
||||
{
|
||||
return (listBoxSimple.SelectedIndex != -1 && listBoxSimple.SelectedItem != null)
|
||||
? listBoxSimple.SelectedItem.ToString()
|
||||
: string.Empty;
|
||||
return listBoxSimple.SelectedItem?.ToString() ?? string.Empty;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
int index = listBoxSimple.FindString(value);
|
||||
if (index == -1) return;
|
||||
listBoxSimple.SetSelected(index, true);
|
||||
}
|
||||
listBoxSimple.SelectedIndex = listBoxSimple.FindString(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,13 +24,16 @@ namespace NotVisualComponent
|
||||
}
|
||||
public void CreateDoc<T>(TableWithHeaderConfig<T> config)
|
||||
{
|
||||
string NullReplace = "null";
|
||||
config.CheckFields();
|
||||
config.ColumnsRowsDataCount = (config.ColumnsRowsWidth.Count, config.Data.Count + 1);
|
||||
IContext creator = new WorkWithExcel();
|
||||
creator.CreateHeader(config.Header);
|
||||
creator.CreateTableWithHeader();
|
||||
creator.CreateMultiHeader(config);
|
||||
|
||||
var array = new string[config.Data.Count, config.Headers.Count];
|
||||
|
||||
for (var j = 0; j < config.Data.Count; j++)
|
||||
{
|
||||
for (var i = 0; i < config.Headers.Count; i++)
|
||||
@ -50,17 +53,17 @@ namespace NotVisualComponent
|
||||
{
|
||||
object? value = propertyInfo.GetValue(config.Data[j], null);
|
||||
array[j, i] = value == null
|
||||
? config.NullReplace
|
||||
? NullReplace
|
||||
: value.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
array[j, i] = config.NullReplace;
|
||||
array[j, i] = NullReplace;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
array[j, i] = config.NullReplace;
|
||||
array[j, i] = NullReplace;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ namespace NotVisualComponent.Helpers
|
||||
Location legendLocation)
|
||||
{
|
||||
var chart = new DocumentFormat.OpenXml.Drawing.Charts.Chart();
|
||||
if (IsNullOrWhiteSpace(titleText))
|
||||
if (!IsNullOrWhiteSpace(titleText))
|
||||
{
|
||||
chart.Append(GenerateTitle(titleText));
|
||||
}
|
||||
|
@ -7,11 +7,14 @@ using NotVisualComponent.Models;
|
||||
|
||||
namespace NotVisualComponent.Helpers
|
||||
{
|
||||
public interface IContext : ICreator
|
||||
public interface IContext
|
||||
{
|
||||
void CreateTable(string[,] data);
|
||||
void CreateTableWithHeader();
|
||||
void CreateMultiHeader<T>(TableWithHeaderConfig<T> config);
|
||||
void LoadDataToTableWithMultiHeader(string[,] data, int rowHeight);
|
||||
void CreateHeader(string header);
|
||||
void SaveDoc(string filepath);
|
||||
void CreateBarChart(ChartConfig config);
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NotVisualComponent.Models;
|
||||
|
||||
namespace NotVisualComponent.Helpers
|
||||
{
|
||||
public interface ICreator
|
||||
{
|
||||
void CreateHeader(string header);
|
||||
void SaveDoc(string filepath);
|
||||
void CreateBarChart(ChartConfig config);
|
||||
}
|
||||
}
|
@ -223,7 +223,7 @@ namespace NotVisualComponent.Helpers
|
||||
for (var j = 0; j < data.GetLength(1); j++)
|
||||
CreateCell(j, (uint)(i + _index), data[i, j], 2u);
|
||||
|
||||
_index += (uint)data.GetLength(0);
|
||||
_index += (uint)data.GetLength(0) +1;
|
||||
}
|
||||
private Cell CreateCell(string columnName, uint rowIndex)
|
||||
{
|
||||
|
@ -12,7 +12,6 @@ namespace NotVisualComponent.Models
|
||||
public List<(int Column, int Row)>? ColumnsRowsWidth { get; set; }
|
||||
public List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)>? Headers { get; set; }
|
||||
public List<T>? Data { get; set; }
|
||||
public string NullReplace { get; set; } = "null";
|
||||
|
||||
public void CheckFields()
|
||||
{
|
||||
|
@ -94,23 +94,47 @@ namespace WinFormsTest
|
||||
|
||||
private void CreateTable()
|
||||
{
|
||||
ListOutputComponent.ConfigColumn(new()
|
||||
var config = new ColumnsConfiguratoin();
|
||||
|
||||
config.Columns.Add(new ColumnConfig
|
||||
{
|
||||
ColumnsCount = 4,
|
||||
ColumnName = new string[] { "Id", "Name", "DeliveryStatus", "CountProduct" },
|
||||
Width = new int[] { 10, 150, 250, 200 },
|
||||
Visible = new bool[] { false, true, true, true, true },
|
||||
PropertiesObject = new string[] { "Id", "Name", "DeliveryStatus", "CountProduct" }
|
||||
ColumnName = "Id",
|
||||
Width = 10,
|
||||
Visible = false,
|
||||
PropertyObject = "Id"
|
||||
});
|
||||
config.Columns.Add(new ColumnConfig
|
||||
{
|
||||
ColumnName = "Name",
|
||||
Width = 150,
|
||||
Visible = true,
|
||||
PropertyObject = "Name"
|
||||
});
|
||||
config.Columns.Add(new ColumnConfig
|
||||
{
|
||||
ColumnName = "DeliveryStatus",
|
||||
Width = 250,
|
||||
Visible = true,
|
||||
PropertyObject = "DeliveryStatus"
|
||||
});
|
||||
config.Columns.Add(new ColumnConfig
|
||||
{
|
||||
ColumnName = "CountProduct",
|
||||
Width = 200,
|
||||
Visible = true,
|
||||
PropertyObject = "CountProduct"
|
||||
});
|
||||
|
||||
ListOutputComponent.ConfigColumn(config);
|
||||
|
||||
foreach (Delivery delivery in delivers)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
ListOutputComponent.AddItem(delivery, delivery.Id, i);
|
||||
ListOutputComponent.Update();
|
||||
}
|
||||
}
|
||||
ListOutputComponent.Update();
|
||||
}
|
||||
|
||||
private void ButtonShowTable_Click(object sender, EventArgs e)
|
||||
@ -140,6 +164,11 @@ namespace WinFormsTest
|
||||
{ "1", "1", "1" },
|
||||
{ "1", "2", "2" },
|
||||
{ "1", "3", "3" }
|
||||
},
|
||||
new string[,] {
|
||||
{ "2", "1", "1" },
|
||||
{ "2", "2", "2" },
|
||||
{ "2", "3", "3" }
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -149,31 +178,29 @@ namespace WinFormsTest
|
||||
excelHardTable.CreateDoc(new TableWithHeaderConfig<Delivery>
|
||||
{
|
||||
FilePath = "C:\\Users\\sshan\\OneDrive\\Desktop\\PathKOP\\Excel2.xlsx",
|
||||
Header = "Computers",
|
||||
Header = "Delivers",
|
||||
ColumnsRowsWidth = new List<(int Column, int Row)> { (5, 5), (10, 5), (10, 0), (5, 0), (7, 0) },
|
||||
Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)>
|
||||
{
|
||||
(0, 0, "Id", "Id"),
|
||||
(1, 0, "CPU", "CPU"),
|
||||
(2, 0, "GPU", "GPU"),
|
||||
(3, 0, "RAM", "RAM"),
|
||||
(1, 0, "Name", "Name"),
|
||||
(2, 0, "DeliveryStatus", "DeliveryStatus"),
|
||||
(3, 0, "CountProduct", "CountProduct"),
|
||||
},
|
||||
Data = delivers,
|
||||
NullReplace = "Çàëóïêà)"
|
||||
Data = delivers
|
||||
});
|
||||
}
|
||||
private void buttonDiagramSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
var rnd = new Random();
|
||||
excelDiagram.CreateDoc(new ChartConfig
|
||||
{
|
||||
FilePath = "C:\\Users\\sshan\\OneDrive\\Desktop\\PathKOP\\Excel3.xlsx",
|
||||
Header = "Chart",
|
||||
ChartTitle = "BarChart",
|
||||
LegendLocation = NotVisualComponent.Models.Location.Top,
|
||||
ChartTitle = "Gistogram",
|
||||
LegendLocation = NotVisualComponent.Models.Location.Bottom,
|
||||
Data = new Dictionary<string, List<(string Name, double Value)>>
|
||||
{
|
||||
{ "Series 1", new() { ("GOVNO", rnd.Next()), ("ZALUPA", rnd.Next()), ("PENIS", rnd.Next()) } }
|
||||
{ "Series 1", new() { ("Orange", 150), ("Apple", 200), ("Lime", 300) } }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user