Сохраненка

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,34 +27,25 @@ namespace CreateVisualComponent
{ {
get get
{ {
if (!checkBoxDate.Checked) if (checkBoxDate.Checked)
{ {
if (string.IsNullOrEmpty(textBoxDate.Text)) return null;
{
throw new NotFilledException("The textbox is empty, fill it in or click on the checkbox!");
}
if (DateTime.TryParseExact(textBoxDate.Text, "dd/MM/yyyy", null, DateTimeStyles.None, out DateTime parsedDate))
{
return parsedDate;
}
else
{
throw new IncorrectFillingException(textBoxDate.Text + " incorrect date!");
}
} }
return null; if (string.IsNullOrEmpty(textBoxDate.Text))
{
throw new NotFilledException("The textbox is empty, fill it in or click on the checkbox!");
}
if (DateTime.TryParseExact(textBoxDate.Text, "dd/MM/yyyy", null, DateTimeStyles.None, out DateTime parsedDate))
{
return parsedDate;
}
throw new IncorrectFillingException(textBoxDate.Text + " incorrect date!");
} }
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;