Hello, I need to search for items from a list, I have a Client class
public class Cliente
{
public int ClienteId { get; set; }
public string RazonSocial { get; set; }
public EnumDocumentoEdentidad DocumentoIdentidad { get; set; }
public string NumeroDocumento { get; set; }
public string Direccion { get; set; }
public string Telefono { get; set; }
public virtual ICollection<Venta> Ventas { get; set; }
}
I have controls in a Windows Forms form which are called as follows txtClienteId
, txtRazonSocial
, txtDocumentoIdentidad
. So what I want to look for is the following:
As you will see the controls are called the same as the properties except they have txt, cbo, etc in front of them at the beginning. I need to do a search on behalf of the control if the property is called SocialResearch that searches all controls RazonSocial
and if it finds it put the content of txtRazonSocial
to the property RazonSocial
, in other words assign the value to the attribute.
public void Guardar(Form frm)
{
ObtenerValorControles(frm);
List<ControlEntity> result = ObtenerNameControles(frm);
Control obj = new Control();
obj.GetAllControls();
var controles = from b in frm.GetAllControls()
where b is TextBox || b is ComboBox || b is CheckBox
select b;
if (nameForm == "Cliente")
{
var prop = new Cliente();
foreach (var propertyInfo in prop.GetType().GetProperties())
{
if (propertyInfo.Name = result.Contains(prop))
{
}
}
}
I get the name of the controls
public List<ControlEntity> ObtenerNameControles(Form frm)
{
nameForm = Convert.ToString(frm.Tag);
Control obj = new Control();
obj.GetAllControls();
var controles = from b in frm.GetAllControls()
where b is TextBox || b is ComboBox || b is CheckBox || b is Form
select b;
foreach (var control in controles)
{
if (control is CheckBox)
{
nameCheck = ((CheckBox) control).Name;
}
if (control is ComboBox)
{
nameCombo = ((ComboBox) control).Name;
}
if (control is TextBox)
{
nameTextBox = ((TextBox) control).Name;
}
if (!string.IsNullOrEmpty(nameCheck))
{
var n = new ControlEntity() {Name = nameCheck};
listNombreControles.Add(n);
}
if (!string.IsNullOrEmpty(nameCombo))
{
var n = new ControlEntity() {Name = nameCombo};
listNombreControles.Add(n);
}
if (!string.IsNullOrEmpty(nameTextBox))
{
var n = new ControlEntity() {Name = nameTextBox};
listNombreControles.Add(n);
}
}
return listNombreControles();
}