Сохраненка

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
{
if (!checkBoxDate.Checked)
if (checkBoxDate.Checked)
{
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;
}
else
{
throw new IncorrectFillingException(textBoxDate.Text + " incorrect date!");
}
return null;
}
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
{
if (value is null)
{
checkBoxDate.Checked = true;
}
else
{
textBoxDate.Text = value?.ToString("dd/MM/yyyy");
checkBoxDate.Checked = false;
}
checkBoxDate.Checked = value is null;
textBoxDate.Text = value?.ToString("dd/MM/yyyy") ?? string.Empty;
}
}

View File

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

View File

@ -55,7 +55,7 @@ namespace WinFormsTest
{
if (InputComponent.Value == null)
{
MessageBox.Show($"Pressed Checkbox");
MessageBox.Show($"Pressed Checkbox");
}
else
{