Сохраненка

This commit is contained in:
Extrimal 2024-09-14 18:15:23 +04:00
parent cd207e87e6
commit 9bdc5819b3
3 changed files with 19 additions and 36 deletions

View File

@ -27,8 +27,10 @@ namespace CreateVisualComponent
{ {
get get
{ {
if (!checkBoxDate.Checked) if (checkBoxDate.Checked)
{ {
return null;
}
if (string.IsNullOrEmpty(textBoxDate.Text)) if (string.IsNullOrEmpty(textBoxDate.Text))
{ {
throw new NotFilledException("The textbox is empty, fill it in or click on the checkbox!"); throw new NotFilledException("The textbox is empty, fill it in or click on the checkbox!");
@ -37,24 +39,13 @@ namespace CreateVisualComponent
{ {
return parsedDate; return parsedDate;
} }
else
{
throw new IncorrectFillingException(textBoxDate.Text + " incorrect date!"); throw new IncorrectFillingException(textBoxDate.Text + " incorrect date!");
}
}
return null;
} }
set set
{ {
if (value is null) checkBoxDate.Checked = value is null;
{ textBoxDate.Text = value?.ToString("dd/MM/yyyy") ?? string.Empty;
checkBoxDate.Checked = true;
}
else
{
textBoxDate.Text = value?.ToString("dd/MM/yyyy");
checkBoxDate.Checked = false;
}
} }
} }

View File

@ -51,21 +51,13 @@ namespace CreateVisualComponent
T val = new(); T val = new();
var propertiesObj = typeof(T).GetProperties(); var propertiesObj = typeof(T).GetProperties();
var columns = dataGridViewTable.Columns.Cast<DataGridViewColumn>().ToList();
foreach (var property in propertiesObj) foreach (var property in propertiesObj)
{ {
bool propIsExist = false; var column = columns.FirstOrDefault(c => c.DataPropertyName == property.Name);
int columnIndex = 0; if (column != null)
for (; columnIndex < dataGridViewTable.Columns.Count; columnIndex++)
{ {
if (dataGridViewTable.Columns[columnIndex].DataPropertyName.ToString() == property.Name) object value = dataGridViewTable.SelectedRows[0].Cells[column.Index].Value;
{
propIsExist = true;
break;
}
}
if (propIsExist)
{
object value = dataGridViewTable.SelectedRows[0].Cells[columnIndex].Value;
Type propertyType = property.PropertyType; Type propertyType = property.PropertyType;
bool isNullable = Nullable.GetUnderlyingType(propertyType) != null; bool isNullable = Nullable.GetUnderlyingType(propertyType) != null;