there is a need to check the data entered by the user and display a notification on the screen in case of incorrect input. I used the following method, but it seems to me that it don't quite fit into the principle of "don't repeat yourself". Does anyone have any ideas for simplification?
int productid = 0;
string errorMessage = "Неправильный формат данных:\n",
productName = "", productGroup = "", productType = "";
if (!int.TryParse(ProductIdTB.Text, out productId))
{
errorMessage += "+ Номер продукта\n";
}
if (string.IsNullOrEmpty(ProductNameTB.Text))
{
errorMessage += "+ Название продукта\n";
}
else
{
productName = ProductNameTB.Text;
}
if (string.IsNullOrEmpty(ProductGroupTB.Text))
{
errorMessage += "+ Группа продукта\n";
}
else
{
productGroup = ProductGroupTB.Text;
}
if (string.IsNullOrEmpty(ProductType.Text))
{
errorMessage += "+ Вид продукта";
}
else
{
productType = ProductType.Text;
}
if (errorMessage.Split(' ').Length > 1)
{
MessageBox.Show(errorMessage);
return;
}